/* ===== Memories of Ida — Book Style (light, print-like) ===== */

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Base scale controlled by --reader-scale (user setting) */
:root {
  --reader-scale: 1;

  --primary-bg: #f8f5ee;
  --secondary-bg: #fbfaf6;
  --card-bg: #ffffff;
  --text-primary: #1f2328;
  --text-secondary: #3f4750;
  --text-muted: #6b7280;
  --accent: #1f2328;
  --accent-hover: #2b3138;
  --border: #e3e0d7;
  --verse-hover: rgba(31,35,40,.06);

  /* Loader color (spinner) */
  --loader-color: #2C251D;

  /* Combobox palette */
  --combo-bg: #fff;
  --combo-ring: rgba(201,194,178,.45);
  --combo-border: #dfdbcf;
  --combo-hover: #f3efe6;

  /* Native select */
  --select-bg: var(--secondary-bg);
  --select-border: var(--combo-border);
  --select-ring: var(--combo-ring);
  --select-arrow: #6b6f76;
}

/* Root scaling (story text grows/shrinks with reader control) */
html {
  --root-step: clamp(18px, 1.8vw, 20px);
  font-size: calc(var(--root-step) * var(--reader-scale));
}

/* Dark tokens */
html[data-theme="dark"] {
  --primary-bg: #0f1115;
  --secondary-bg: #12161b;
  --card-bg: #181c22;
  --text-primary: #e5e7eb;
  --text-secondary: #c5cbd6;
  --text-muted: #9aa3b2;
  --accent: #f3f4f6;
  --accent-hover: #ffffff;
  --border: #2a2f37;
  --verse-hover: rgba(255,255,255,.06);

  --combo-bg: #1a1f25;
  --combo-ring: rgba(82, 94, 113, .5);
  --combo-border: #2a2f37;
  --combo-hover: #222832;

  --loader-color: #e5e7eb;

  --select-bg: #151a20;
  --select-border: #2a2f37;
  --select-ring: rgba(82,94,113,.5);
  --select-arrow: #a3acba;
}

body {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
               Georgia, "Times New Roman", serif;
  background: var(--primary-bg);
  color: var(--text-primary);
  line-height: 1.9;
  min-height: 100vh;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* Container */
.container { max-width: 720px; margin: 0 auto; padding: .5rem 1rem; }
/* Article page: larger breathing room */
body[data-page="article"] .container { padding: 2.5rem 1rem; }

/* Fixed-px padding wrapper around the chapter selector */
.selector-section { padding: 32px 16px; }

/* Chapter selector (2-col grid with 8px gap) — UN-SCALED UI ZONE */
.chapter-selector {
  position: relative;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin: 0 auto .5rem auto;
  max-width: 720px;

  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: start;

  /* Freeze UI size against reader scaling */
  font-size: calc(1rem / var(--reader-scale));
}

/* Ensure grid children can shrink and not overflow due to long text */
.selector-block {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.selector-label {
  color: var(--text-secondary);
  font-size: .9em;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI";
}

/* Settings icon button */
.settings-btn {
  position: absolute; top: 8px; right: 8px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px; height: 34px; border-radius: 8px;
  display: inline-grid; place-items: center; cursor: pointer;
}
.settings-btn:hover { background: var(--combo-hover); color: var(--accent); }

/* When a settings button is inside the article top bar, we want it inline, not absolute */
.article-top-nav .settings-btn { position: static; }

/* ---- Combobox (age/chapter) ---- */
.visually-hidden { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }

.combo {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.combo-trigger {
  background: var(--secondary-bg);
  color: var(--text-primary);
  border: 1px solid var(--combo-border);
  padding: .55em .8em .55em .8em;
  border-radius: 8px;
  font-size: .95em;
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI";
  width: 100%;
  min-width: 0;
  display: inline-flex; align-items: center; justify-content: space-between;
  text-align: left;
}
.combo-trigger:focus { outline: none; box-shadow: 0 0 0 3px var(--combo-ring); border-color: #c9c2b2; }
.combo-trigger:hover { background: var(--combo-hover); }

/* Truncation: value takes available space, chevron doesn’t shrink */
.combo-value {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
.combo-chevron { margin-left: .65em; opacity: .6; flex: 0 0 auto; }

/* Popover & results */
.combo-popover {
  position: absolute; inset-inline-start: 0; top: calc(100% + 6px); z-index: 40;
  background: var(--combo-bg); border: 1px solid var(--combo-border); border-radius: 10px;
  box-shadow: 0 8px 18px rgba(0,0,0,.08);
  width: 100%;
  max-height: 320px; overflow: hidden; display: none;
}
.combo.open .combo-popover { display: block; }

.combo-search { padding: .5em; border-bottom: 1px solid var(--combo-border); background: #fffdf7; }
html[data-theme="dark"] .combo-search { background: #151a20; }
.combo-input {
  width: 100%; border: 1px solid var(--combo-border); border-radius: 8px; padding: .5em .65em;
  font-size: .95em; font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI";
}
.combo-input:focus { outline: none; box-shadow: 0 0 0 3px var(--combo-ring); border-color: #c9c2b2; }

.combo-list { list-style: none; max-height: 260px; overflow: auto; padding: .25em; }
.combo-item {
  display: flex; align-items: center; gap: .5em;
  padding: .5em .6em; border-radius: 8px; cursor: pointer;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI"; font-size: .95em;
}
.combo-item[aria-selected="true"] { background: #efeade; }
html[data-theme="dark"] .combo-item[aria-selected="true"] { background: #1f2731; }
.combo-item:hover { background: var(--combo-hover); }
.combo-item .check { margin-left: auto; opacity: 0; }
.combo-item[aria-selected="true"] .check { opacity: 1; }

/* Empty state — left padding added; show only when NO <li> are present */
.combo-empty {
  display: none;
  padding: .6em .8em;
  color: var(--text-muted);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI";
  text-align: left;
}
.combo-list:empty + .combo-empty { display: block; }
@supports selector(.combo-popover:has(.combo-list > li)) {
  .combo-popover:has(.combo-list > li) .combo-empty { display: none; }
}

/* ---- Native Select (settings) ---- */
.native-select {
  width: 100%;
  background: var(--select-bg);
  color: var(--text-primary);
  border: 1px solid var(--select-border);
  border-radius: 8px;
  padding: .55em 2.25em .55em .8em;
  font-size: .95em;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI";
  appearance: none;
  background-image:
    url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23a0a6ae' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .6em center;
}
html[data-theme="dark"] .native-select {
  background-image:
    url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%238d98a9' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
}
.native-select:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--select-ring);
  border-color: #c9c2b2;
}
.native-select:hover { background-color: var(--combo-hover); }

/* Settings modal — UN-SCALED UI ZONE */
.modal.hidden { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.modal-panel {
  position: relative;
  width: min(92vw, 520px);
  margin: 10vh auto 0;
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);

  /* Freeze UI size against reader scaling */
  font-size: calc(1rem / var(--reader-scale));
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85em 1em;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI";
  font-size: 1.05em;
  letter-spacing: .02em; font-weight: 600;
}
.modal-close {
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; width: 34px; height: 30px; cursor: pointer; color: var(--text-secondary);
}
.modal-close:hover { background: var(--combo-hover); color: var(--accent); }

.modal-body { padding: 1em; display: grid; gap: 1em; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: .75em; }
.setting-label { color: var(--text-secondary); font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI"; }
.setting-controls { display: inline-flex; align-items: center; gap: .5em; flex: 1; }
.setting-controls .native-select { width: 100%; }

/* Chapter header (content area that DOES scale) */
.chapter-header {
  text-align: left;
  margin-bottom: 2.75rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
}
.age-name {
  color: var(--text-secondary);
  font-size: .85rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  margin-bottom: .35rem;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI";
}
.chapter-title { font-weight: 600; color: var(--text-primary); font-size: clamp(24px, 2.4vw, 32px); line-height: 1.25; margin-bottom: .25rem; }
.chapter-subtitle { color: var(--text-secondary); font-style: italic; font-size: 1.05rem; }

/* Article header (clone of chapter header, no age-name) */
.article-header {
  text-align: left;
  margin-bottom: 2.75rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
}
.article-title { font-weight: 600; color: var(--text-primary); font-size: clamp(24px, 2.4vw, 32px); line-height: 1.25; margin-bottom: .25rem; }
.article-subtitle { color: var(--text-secondary); font-style: italic; font-size: 0.7rem; }
.article-excerpt { color: var(--text-secondary); margin-top: .75rem; font-style: italic; font-size: 0.9rem; line-height: 1.6; }

/* Top bar on articles: spread items to edges */
.article-top-nav {
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

/* Passages & verses (scale with reader size) */
.passage { margin: 0 0 2.5rem 0; }
.passage-heading {
  font-size: 1.05rem;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: .02em;
  margin: 1.5rem 0 .75rem;
}
.passage-number { color: var(--text-muted); font-size: .85rem; font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI"; }

.verse { margin: 0 0 1.15rem 0; padding: 0; border-radius: 0; transition: background .15s ease; }
.verse:hover { background: var(--verse-hover); }
.verse-number { color: var(--text-muted); font-size: .7rem; font-weight: 700; margin-right: .45rem; min-width: 1.25rem; font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI"; vertical-align: super; }
.verse-text { font-size: 1rem; line-height: 1.95; color: var(--text-primary); }
.paragraph-italic { font-style: italic; color: var(--text-secondary); margin-left: 0; }

.covenant-list { margin: 1rem 0 1.5rem 1.5rem; line-height: 1.95; }
.covenant-list li { margin-bottom: .4rem; font-size: 1rem; color: var(--text-primary); }

.passage-image { text-align: center; margin: 2.5rem 0; }
.passage-image img { max-width: 420px; width: 100%; opacity: .96; filter: none; }
.passage-image figcaption { margin-top: .65rem; color: var(--text-muted); font-size: .9rem; font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI"; }

/* Chapter nav */
.chapter-nav { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border); }
.chapter-nav-inner { display: flex; justify-content: space-between; gap: .75rem; }
.nav-button {
  background: transparent; border: none; color: var(--text-secondary);
  padding: .25rem 0; border-radius: 0; text-decoration: none;
  transition: color .15s ease, transform .15s ease;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI";
  font-size: .95rem; display: inline-flex; align-items: center; gap: .4rem;
}
.nav-button:hover:not(.disabled) { color: var(--accent); transform: translateY(-1px); }
.nav-button.disabled { opacity: .35; pointer-events: none; }

/* End-of-chapter sections */
.chapter-section { margin-top: 2.5rem; }
.is-hidden { display: none; }

.section-divider { height: 1px; background: var(--border); margin: 2rem 0 1.25rem 0; }
.section-title {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI";
  font-size: 1rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-secondary); margin-bottom: 1rem;
}

/* Related Articles */
.articles-list { list-style: none; display: grid; grid-template-columns: 1fr; gap: 0; }
.article-link-item a { font-size: 1rem; text-decoration: underline; color: var(--accent); display: block; }
.article-link-item a:hover { color: var(--accent-hover); }

/* External Links */
.links-list { list-style: none; display: grid; grid-template-columns: 1fr; gap: 0; }

/* REVERTED: icon/text vertically centered (previous behavior) */
.external-link-item a {
  font-size: 0.95rem; font-style: italic; text-decoration: underline; color: var(--accent);
  display: inline-flex; align-items: center; gap: .45rem;
}
.external-link-item a:hover { color: var(--accent-hover); }
.links-note { color: var(--text-muted); font-size: .85rem; }

/* Icon sizing + auto invert in dark mode (white-ish) */
.link-icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.15em; flex: 0 0 auto; }
html[data-theme="dark"] .link-icon { filter: invert(1) brightness(1.2); }

/* Feedback */
.loading, .error { text-align: center; padding: 2rem; margin: 1.25rem 0; font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI"; }
.loading { color: var(--text-muted); font-size: 1rem; }
.error  { color: #b42318; background: rgba(180,35,24,.06); border: 1px solid rgba(180,35,24,.25); border-radius: 8px; }

/* Loader */
.loader {
  width: 50px; aspect-ratio: 1;
  --c: no-repeat radial-gradient(farthest-side, var(--loader-color) 92%, #0000);
  background: var(--c) 50% 0, var(--c) 50% 100%, var(--c) 100% 50%, var(--c) 0 50%;
  background-size: 10px 10px;
  animation: l18 1s infinite linear;
  position: relative; margin: 2rem auto;
}
.loader::before {
  content: ""; position: absolute; inset: 0; margin: 3px;
  background: repeating-conic-gradient(#0000 0 35deg, var(--loader-color) 0 90deg);
  -webkit-mask: radial-gradient(farthest-side, #0000 calc(100% - 3px), #000 0);
  mask: radial-gradient(farthest-side, #0000 calc(100% - 3px), #000 0);
  border-radius: 50%;
}
@keyframes l18 { 100% { transform: rotate(.5turn) } }

::selection { background: #fde49c; color: #1f2328; }

/* Mobile */
@media (max-width: 768px) {
  .selector-section { padding: 24px 12px; }
  .chapter-selector { grid-template-columns: 1fr; }
  .combo-popover { width: 100%; }
  .chapter-nav-inner { flex-direction: column; }
  /* Keep only chapter-nav buttons full-width on mobile — Back to Reader stays inline */
  .chapter-nav .nav-button { justify-content: center; width: 100%; }
}
@media print {
  body { background: #fff; color: #000; }
  .selector-section,
  .chapter-selector,
  .chapter-nav,
  .chapter-section,
  .article-top-nav,
  .article-footer-nav,
  .modal { display: none !important; }
  .container { max-width: 700px; padding: 0; }
}

/* ===========================
   Memories of Ida — Global Styles
   =========================== */
