:root {
  --bg: #14161a;
  --panel: #1a1d23;
  --panel-2: #21252c;
  --ink: #e8e6e1;
  --muted: #9aa0a8;
  --line: #2b2f37;
  --accent: #e6b277;        /* warm amber */
  --accent-ink: #f0c896;
  --xref: #7fb0d8;
  --fn: #d79b6e;
  --woj: #e06b5c;           /* words of Jesus (red-letter), tuned for dark bg */
  --sel: rgba(230, 178, 119, .16);
  --hover: #262b33;
  --sidebar-w: 320px;
  --word-panel-w: 400px;
  --topbar-h: 54px;
  --reading-size: 19.5px;
  /* ratio of the chosen reading size to the default — scales chrome (sidebar /
     tabs) alongside the reading text. Updated by the A-/A/A+ control. */
  --ui-scale: 1;
  --float-shadow: 0 6px 22px rgba(0, 0, 0, .45);
  --serif: "Iowan Old Style", "Palatino Linotype", "Source Serif 4", Georgia, serif;
  --sans: "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* padding-top leaves room for the floating top bar; the safe-area inset keeps
   content clear of a phone status bar / notch (viewport-fit=cover). */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  padding-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
}

/* ---------- Floating top controls (no banner) ---------- */
#topbar {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px)); left: 0; right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  pointer-events: none;            /* gaps let the reading show/scroll through */
  transition: right .24s cubic-bezier(.4, 0, .2, 1);
}
#topbar > * { pointer-events: auto; }
/* on desktop, keep the controls clear of the word panel */
body.word-panel-open #topbar { right: var(--word-panel-w); }

.topbar-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.topbar-btn:hover { background: var(--hover); }

#sidebar-toggle { box-shadow: var(--float-shadow); }

/* text size as one floating pill */
#textsize {
  flex: 0 0 auto;                  /* always full size — search yields space, not this */
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--float-shadow);
}
#textsize .topbar-btn {
  width: 34px; height: 30px;
  border: 0;
  background: none;
  box-shadow: none;
  font-size: 15px;
}
#text-reset { font-size: 13px; }

/* ---------- Search ---------- */
#search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;                    /* allow the bar to shrink past its content */
  max-width: 620px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--float-shadow);
}
#search:focus-within { border-color: var(--accent); }
#search-scope {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 9px 6px 9px 11px;
  border-right: 1px solid var(--line);
  border-radius: 10px 0 0 10px;
  cursor: pointer;
  outline: none;
}
#search-scope option { background: var(--panel-2); color: var(--ink); }
#search-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 9px 10px;
  outline: none;
}
#search-input::placeholder { color: var(--muted); }
#search-input::-webkit-search-cancel-button,
#search-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.search-clear {
  flex: 0 0 auto;
  border: 0; background: none;
  color: var(--muted);
  font-size: 18px; line-height: 1;
  cursor: pointer;
  padding: 0 10px;
}
.search-clear:hover { color: var(--ink); }

#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  max-height: min(70vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .55);
  padding: 6px;
  z-index: 1;
}
.sr-status {
  padding: 9px 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.sr-group {
  padding: 10px 12px 4px;
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.sr-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  padding: 9px 12px;
  border-radius: 8px;
}
.sr-item:hover, .sr-item.active { background: var(--hover); }
.sr-ref {
  font-weight: 700;
  color: var(--accent-ink);
  font-size: 13.5px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.sr-tag {
  font-size: 9.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1px 6px;
  font-weight: 600;
}
.sr-tag.sil { color: var(--accent); border-color: rgba(230,178,119,.4); }
.sr-tag.word { color: var(--xref); border-color: rgba(127,176,216,.4); }
/* word search results: original-language word + gloss, opens its meaning tab */
.sr-word-translit { font-weight: 700; color: var(--accent-ink); }
.sr-word-lemma { font-family: var(--serif); font-size: 16px; color: var(--ink); margin-left: 8px; }
.sr-gloss { font-family: var(--sans); font-size: 13px; font-style: italic; }
.sr-snippet {
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
  margin-top: 3px;
}
.sr-snippet mark { background: var(--sel); color: var(--accent-ink); border-radius: 3px; padding: 0 1px; }

/* ---------- Sidebar ---------- */
/* The table of contents is a left-side OVERLAY (like the word panel on the right):
   it floats above the reading and the chat instead of pushing them aside, sliding
   in/out from the edge. z-index sits above the chat (48) but below the top bar (50)
   so the toggle stays reachable to close it. */
#sidebar {
  position: fixed;
  left: 0; bottom: 0;
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  z-index: 49;
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 16px 0 48px rgba(0, 0, 0, .5);
  display: flex;
  flex-direction: column;
  transition: margin-left .26s cubic-bezier(.4, 0, .2, 1);
}
body.sidebar-collapsed #sidebar { margin-left: calc(-1 * var(--sidebar-w) - 24px); }

.side-head {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.side-head h1 {
  font-family: var(--serif);
  font-size: calc(19px * var(--ui-scale));
  font-weight: 600;
  letter-spacing: .2px;
  margin: 0 0 12px;
  color: var(--accent-ink);
}
#filter {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: calc(14px * var(--ui-scale));
  background: var(--bg);
  color: var(--ink);
  outline: none;
}
#filter::placeholder { color: var(--muted); }
#filter:focus { border-color: var(--accent); }

#tree { overflow-y: auto; flex: 1; padding: 8px 8px 48px; }
.side-foot { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 10px 14px; }
.side-foot a {
  display: block; font-family: var(--sans); font-size: 13px; font-weight: 600;
  color: var(--accent-ink); text-decoration: none;
}
.side-foot a:hover { text-decoration: underline; }

.testament {
  font-size: calc(11px * var(--ui-scale));
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 12px 6px;
  font-weight: 600;
}

.book { margin-bottom: 1px; }
.row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 9px 11px;
  border-radius: 9px;
  color: var(--ink);
  line-height: 1.2;
}
.row:hover { background: var(--hover); }
.row.active { background: var(--sel); color: var(--accent-ink); font-weight: 600; }
.row .twisty {
  width: 12px;
  flex: 0 0 12px;
  color: var(--muted);
  transition: transform .16s ease;
  font-size: calc(10px * var(--ui-scale));
}
.row.open .twisty { transform: rotate(90deg); color: var(--accent); }
.book-row { font-size: calc(15px * var(--ui-scale)); }

/* chapter chip grid (replaces the old chapter rows + verse chips) */
.chapters {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 6px;
  padding: 8px 12px 14px 30px;
}
.chapters.open { display: grid; }
.chip {
  text-align: center;
  padding: 7px 4px;
  font-size: calc(13px * var(--ui-scale));
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  cursor: pointer;
  color: var(--ink);
  transition: background .12s, border-color .12s;
}
.chip:hover { background: var(--hover); border-color: var(--accent); }
.chip.active { background: var(--accent); color: #1a1208; border-color: var(--accent); font-weight: 700; }
/* the book's "Introduction" entry — spans the chip grid, above the chapter numbers */
.chip-intro {
  grid-column: 1 / -1; text-align: left; padding: 7px 10px;
  font-family: var(--sans); font-weight: 600; color: var(--accent-ink);
  background: var(--panel-2);
}
.chip-intro.active { background: var(--accent); color: #1a1208; }

/* ---------- Reader ---------- */
#reader { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
/* While the chat is a takeover (keyboard-pinned or full-window), freeze the reading
   underneath so swiping inside the chat can't scroll the page behind it — which was
   revealing the text above/below the panel and the black bar under the input. The
   chat log keeps its own internal scroll (overscroll-behavior:contain). */
body.chat-locked #reader { overflow: hidden; }
body.chat-locked { overflow: hidden; }
#welcome, #chapter, #book-intro { max-width: 760px; margin: 0 auto; padding: 30px 36px 140px; }
#book-intro-head { margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
#book-intro-title {
  font-family: var(--serif); font-weight: 600; letter-spacing: .2px;
  font-size: calc(28px * var(--ui-scale)); color: var(--accent-ink); margin: 0;
}
#welcome h2 { font-family: var(--serif); color: var(--accent-ink); font-weight: 600; }
#welcome p { color: var(--muted); line-height: 1.8; max-width: 52ch; }

#chapter-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}
#chapter-title {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
  margin: 0;
  flex: 1;
  color: var(--accent-ink);
  letter-spacing: .3px;
}
.navbtn {
  border: 1px solid var(--line);
  background: var(--panel);
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--accent-ink);
  transition: background .15s;
}
.navbtn:hover:not(:disabled) { background: var(--hover); }
.navbtn:disabled { opacity: .28; cursor: default; }

/* Floating chapter switcher — hidden by default, slides down from under the
   top bar when the reader is flicked upward (see app.js). */
#chapter-jump {
  position: fixed;
  top: calc(var(--topbar-h) + 8px + env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  box-shadow: var(--float-shadow);
  transform: translate(-50%, -14px);
  opacity: 0;
  pointer-events: none;                /* invisible state can't be clicked */
  transition: opacity .22s ease, transform .22s cubic-bezier(.4, 0, .2, 1);
}
#chapter-jump.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}
/* ride alongside the open word panel, like the top bar does */
body.word-panel-open #chapter-jump { left: calc(50% - var(--word-panel-w) / 2); }
#chapter-jump .navbtn { width: 34px; height: 34px; font-size: 19px; background: var(--panel); }
#jump-title {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-ink);
  white-space: nowrap;
  min-width: 6ch;
  text-align: center;
}

/* scripture text */
#chapter-body { font-family: var(--serif); font-size: var(--reading-size); line-height: 1.85; color: var(--ink); }
#chapter-body .heading {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 15.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--xref);
  margin: 30px 0 10px;
}
#chapter-body .subheading {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13.5px;
  font-style: italic;
  letter-spacing: .02em;
  color: var(--muted);
  margin: 20px 0 8px;
}
#chapter-body p { margin: 0 0 16px; }
#chapter-body p.poetry { margin: 0; padding-left: 2.4em; text-indent: -1em; }
#chapter-body p.poetry.indent2 { padding-left: 3.8em; }

/* words of Jesus (red-letter) */
.woj { color: var(--woj); }
.woj .kw { color: inherit; }   /* keyword stays red inside Jesus's words, just underlined */
.sil-verse .woj { color: var(--woj); }         /* body of Jesus's words: normal red */
.sil-verse .woj .kw { color: #ec9c93; }        /* highlighted keywords: paler red */

/* parallel-passage reference line (sits under a section heading) */
#chapter-body p.parallel {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  margin: -4px 0 16px;
  letter-spacing: .01em;
}
#chapter-body p.parallel .reflink { color: var(--xref); }

.vnum {
  font-family: var(--sans);
  font-size: .58em;
  font-weight: 700;
  color: var(--accent);
  vertical-align: super;
  cursor: pointer;
  margin-right: 3px;
  /* enlarge tap target without shifting layout (see .noteref::after) */
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.vnum::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: max(150%, 1.9em);
  height: 2.1em;
}
.verse { scroll-margin-top: 96px; border-radius: 4px; transition: background-color 1.4s, box-shadow 1.4s; }
.verse-hl {
  background: var(--sel);
  box-shadow: 0 0 0 4px var(--sel);
  transition: none;
}

.sc { font-variant: small-caps; letter-spacing: .02em; }

/* clickable scripture references inside notes / popover */
.reflink {
  color: var(--xref);
  text-decoration: none;
  cursor: pointer;
  border-bottom: 1px dotted rgba(127, 176, 216, .5);
}
.reflink:hover { color: var(--accent-ink); border-bottom-color: var(--accent); }

.noteref {
  font-family: var(--sans);
  font-size: .58em;
  cursor: pointer;
  vertical-align: super;
  font-weight: 700;
  padding: 0 1px;
  /* Enlarge the tap target without affecting layout: an invisible, absolutely
     positioned overlay gives even narrow letters (i, f) a wide, tall hitbox.
     min width via max() guarantees a usable target regardless of glyph width. */
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.noteref::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: max(150%, 1.8em);
  height: 2.1em;
}
.noteref.xref { color: var(--xref); }
.noteref.fn { color: var(--fn); }
.noteref:hover { text-decoration: underline; }

/* notes section */
#notes {
  margin-top: 46px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted);
}
#notes h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.note-item { margin: 0 0 8px; line-height: 1.6; }
.note-item .note-verse {
  display: inline-block;
  min-width: 2.1em;
  margin-right: 8px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}
.note-item .note-verse:hover { color: var(--accent-ink); }
.note-item .nlabel { font-weight: 700; margin-right: 7px; }
.note-item.xref .nlabel { color: var(--xref); }
.note-item.fn .nlabel { color: var(--fn); }
.note-item i { color: var(--ink); }

/* popover */
#popover {
  position: fixed;
  max-width: 340px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 11px 14px;
  border-radius: 10px;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.55;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .55);
  z-index: 50;
}
#popover .pop-label { font-weight: 700; color: var(--accent-ink); margin-right: 7px; }
#popover i { color: var(--accent-ink); }

/* word panel: live-reading rotation renderings, a comma-separated line */
.wp-rots { line-height: 1.6; color: var(--ink); }
.wp-rot-orig { color: var(--accent-ink); font-weight: 600; }

/* ---------- Semantic Interlinear: reading-mode bar ---------- */
/* floating reading-mode switcher, pinned to the bottom-right of the reader */
#sil-bar {
  position: fixed;
  right: 24px;
  /* clear the bottom safe area / browser toolbar (exposed via the inset under
     viewport-fit=cover) so the reading-mode pill isn't hidden behind it */
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  font-family: var(--sans);
  transition: right .24s cubic-bezier(.4, 0, .2, 1), bottom .24s cubic-bezier(.4, 0, .2, 1);
}
#sil-bar[hidden] { display: none; }   /* keep hidden beating display:flex */
/* slide clear of the word-detail panel so it's never covered */
body.word-panel-open #sil-bar { right: calc(var(--word-panel-w) + 24px); }
.sil-modes {
  display: inline-flex;
  gap: 4px;
  padding: 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.sil-mode {
  border: 0;
  background: none;
  color: var(--muted);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  cursor: pointer;
  transition: background .14s, color .14s;
}
.sil-mode svg { width: 20px; height: 20px; }
.sil-mode:hover { color: var(--ink); background: var(--hover); }
.sil-mode:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sil-mode.active { background: var(--accent); color: #1a1208; }

/* Speaker toggle + its divider inside the reading-mode menu. Mobile only — on
   desktop the audio bar floats on its own, so these stay hidden (revealed in the
   narrow-screen media query when the chapter has audio). */
.sil-sep, .sil-audio-toggle { display: none; }
.sil-sep { width: 1px; align-self: stretch; margin: 3px 2px; background: var(--line); }
body.audio-open .sil-audio-toggle { background: var(--accent); color: #1a1208; }

/* chat toggle: always shown in the reading-mode pill */
.sil-chat-toggle { color: var(--accent-ink); }
body.chat-open .sil-chat-toggle { background: var(--accent); color: #1a1208; }

/* ---------- Grounded study chat panel ---------- */
#chat-panel {
  position: fixed; z-index: 48;
  right: 24px; bottom: 92px; top: auto;      /* sits above the reading-mode pill */
  /* --chat-w / --chat-h are set by dragging the left / top edges (persisted). */
  width: var(--chat-w, min(540px, calc(100vw - 36px)));
  height: var(--chat-h, min(64vh, 560px));
  min-width: 340px; min-height: 240px;
  max-width: calc(100vw - 36px);
  /* never reach above the header/search bar — shrinks if the window is short,
     grows back to the chosen height when there's room again */
  max-height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top, 0px) - 106px);
  display: flex; flex-direction: row;        /* history sidebar + chat main */
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  overflow: hidden; font-family: var(--sans);
  transition: bottom .24s cubic-bezier(.4, 0, .2, 1), max-height .24s cubic-bezier(.4, 0, .2, 1);
}
#chat-panel[hidden] { display: none; }
body.word-panel-open #chat-panel { right: calc(var(--word-panel-w) + 24px); }

/* resize grips — thin strips along the draggable edges (kept inside the panel so
   its overflow:hidden / rounded corners don't clip the grab area) */
.chat-rs { position: absolute; z-index: 6; touch-action: none; }
.chat-rs-t  { top: 0; left: 16px; right: 16px; height: 8px; cursor: ns-resize; }
.chat-rs-l  { left: 0; top: 16px; bottom: 16px; width: 8px; cursor: ew-resize; }
.chat-rs-tl { top: 0; left: 0; width: 16px; height: 16px; cursor: nwse-resize; z-index: 7; }
body.chat-resizing { user-select: none; }
body.chat-resizing #chat-panel { transition: none; }   /* follow the pointer 1:1 */

/* local chat-history sidebar */
.chat-history { flex: 0 0 134px; display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); background: rgba(0,0,0,.13); }
.chat-new {
  margin: 10px 10px 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel-2); color: var(--accent-ink); font: inherit; font-size: calc(12.5px * var(--ui-scale)); font-weight: 600;
  cursor: pointer; text-align: left;
}
.chat-new:hover { background: var(--hover); border-color: var(--accent); }
.chat-history-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 2px 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.chat-hist-item { display: flex; align-items: center; gap: 4px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.chat-hist-item:hover { background: var(--hover); }
.chat-hist-item.active { background: var(--sel); }
.chat-hist-main { flex: 1; min-width: 0; }
/* wrap the whole (≤5-word) title; clamp to 3 lines so an outlier never grows the row */
.chat-hist-title {
  font-size: calc(12px * var(--ui-scale)); line-height: 1.25; color: var(--ink); overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
}
.chat-hist-time { font-size: calc(10px * var(--ui-scale)); color: var(--muted); margin-top: 1px; }
.chat-hist-del { flex: 0 0 auto; border: 0; background: none; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px; opacity: 0; }
.chat-hist-item:hover .chat-hist-del { opacity: 1; }
.chat-hist-del:hover { color: var(--woj); }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.chat-title { font-weight: 600; font-size: calc(14px * var(--ui-scale)); color: var(--accent-ink); }
.chat-sub { font-size: calc(11px * var(--ui-scale)); color: var(--muted); margin-top: 2px; max-width: 280px; }
.chat-close { border: 0; background: none; color: var(--muted); font-size: 21px; line-height: 1; cursor: pointer; padding: 0 4px; }
.chat-close:hover { color: var(--ink); }
.chat-head-actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.chat-expand { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px; display: flex; align-items: center; }
.chat-expand svg { width: 16px; height: 16px; display: block; }
.chat-expand:hover { color: var(--ink); }
.chat-expand .ic-collapse { display: none; }
#chat-panel.fullscreen .chat-expand .ic-expand { display: none; }
#chat-panel.fullscreen .chat-expand .ic-collapse { display: block; }

/* full-window mode: the panel fills the area BELOW the header bar (so the table of
   contents / search controls stay reachable). Resize grips are pointless here, and
   the context selector bar appears so the user can ground (or unground) the chat. */
#chat-panel.fullscreen {
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)) !important;
  left: 0 !important; right: 0 !important; bottom: 0 !important;
  width: auto !important; height: auto !important; max-width: none; max-height: none;
  min-width: 0; min-height: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0;
}
#chat-panel.fullscreen .chat-rs { display: none; }
/* a wider history rail, and the conversation itself held to the reading column
   width (centered) so lines stay comfortably short like the scripture text */
#chat-panel.fullscreen .chat-history { flex: 0 0 260px; }
/* hold the log / input / context content to the reading column, centered — but
   keep their separators (borders, backgrounds) spanning the full width */
#chat-panel.fullscreen .chat-log,
#chat-panel.fullscreen .chat-input,
#chat-panel.fullscreen .chat-suggest,
#chat-panel.fullscreen .chat-context {
  padding-left: max(14px, calc((100% - 760px) / 2));
  padding-right: max(14px, calc((100% - 760px) / 2));
}
/* the bar carries the hidden attr by default; only fullscreen reveals it (this
   selector outweighs the UA [hidden] rule, so no JS toggling of hidden is needed) */
.chat-context { align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: rgba(0,0,0,.1); flex-wrap: wrap; }
#chat-panel.fullscreen .chat-context { display: flex; }
.chat-context-label { font-size: calc(11px * var(--ui-scale)); font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }
.chat-ctx-sel {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 8px; padding: 5px 8px; font: inherit; font-size: calc(13px * var(--ui-scale)); max-width: 60%; cursor: pointer;
}
.chat-ctx-sel:focus { border-color: var(--accent); outline: none; }

/* history drawer toggle + backdrop: mobile-only (the sidebar is always visible on
   desktop, so these are hidden there) */
.chat-history-toggle { display: none; flex: 0 0 auto; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px; margin: -2px 2px -2px -2px; }
.chat-history-toggle svg { width: 20px; height: 20px; display: block; }
.chat-history-toggle:hover { color: var(--ink); }
.chat-history-backdrop { display: none; }
.chat-log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
/* full conversation title pinned at the top of the log — so it's readable even
   when the sidebar entry is clipped */
.chat-conv-title {
  font-weight: 600; font-size: calc(13px * var(--ui-scale)); color: var(--accent-ink); text-align: center;
  overflow-wrap: anywhere; padding: 0 6px 10px; margin-bottom: 2px;
  border-bottom: 1px solid var(--line);
}
.chat-msg { display: flex; }
.chat-msg.chat-user { justify-content: flex-end; }
.chat-bubble {
  max-width: 90%; padding: 9px 13px; border-radius: 14px;
  font-size: calc(14px * var(--ui-scale)); line-height: 1.62; white-space: pre-wrap; word-wrap: break-word;
}
.chat-user .chat-bubble { background: var(--sel); color: var(--ink); border-bottom-right-radius: 4px; }
.chat-assistant .chat-bubble { background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-ref { color: var(--xref); text-decoration: none; border-bottom: 1px solid rgba(127,176,216,.45); white-space: nowrap; cursor: pointer; margin: 0 .2em; }
.chat-ref:hover { color: var(--accent-ink); }
.chat-word { color: var(--accent-ink); text-decoration: none; border-bottom: 1px dotted var(--accent); cursor: pointer; }
.chat-word:hover { background: var(--sel); }
.chat-quote { margin: 0 .12em; }
.chat-quote-text { font-family: var(--serif); font-style: italic; color: var(--accent-ink); }
.chat-quote .chat-ref { font-style: normal; font-size: calc(12px * var(--ui-scale)); margin-left: 0; }   /* ref sits at the quote's start */
.chat-think { color: var(--muted); font-style: italic; }
.chat-err { color: var(--woj); }
/* rate-limit notices: a centered pill — solid when blocked, softer as a heads-up */
.chat-limit {
  align-self: center; max-width: 92%; text-align: center;
  font-size: calc(12.5px * var(--ui-scale)); line-height: 1.5; color: var(--accent-ink);
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: 12px;
  padding: 8px 14px;
}
.chat-limit.warn { color: var(--muted); border-color: var(--line); border-style: dashed; }
.chat-bubble.streaming::after {
  content: "▍"; color: var(--accent); margin-left: 1px;
  animation: chat-caret 1s steps(1) infinite;
}
@keyframes chat-caret { 50% { opacity: 0; } }
/* starter-prompt chips above the input; collapse smoothly once a chat begins */
.chat-suggest {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 14px 10px;
  overflow: hidden; max-height: 260px; opacity: 1;
  transition: max-height .32s cubic-bezier(.4, 0, .2, 1), opacity .22s ease,
              padding-top .32s cubic-bezier(.4, 0, .2, 1), padding-bottom .32s cubic-bezier(.4, 0, .2, 1);
}
.chat-suggest.hide { max-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0; pointer-events: none; }
.chat-suggest-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--accent-ink);
  border-radius: 14px; padding: 7px 12px; font: inherit; font-size: calc(12.5px * var(--ui-scale));
  line-height: 1.35; text-align: left; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.chat-suggest-btn:hover { background: var(--hover); border-color: var(--accent); }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-input textarea {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 10px; padding: 8px 11px; font: inherit; font-size: calc(14px * var(--ui-scale)); line-height: 1.4;
  max-height: 120px; outline: none;
}
.chat-input textarea:focus { border-color: var(--accent); }
.chat-send {
  flex: 0 0 auto; width: 38px; height: 38px; border: 0; border-radius: 10px;
  background: var(--accent); color: #1a1208; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.chat-send:disabled { opacity: .5; cursor: default; }
.chat-send svg { width: 18px; height: 18px; }

/* ---------- Audio reading bar (bottom-left, opposite the mode switcher) ---------- */
#audio-bar {
  position: fixed;
  left: 24px;                 /* the sidebar overlays now, so no need to clear it */
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));   /* clear the bottom toolbar/safe area */
  z-index: 45;
  font-family: var(--sans);
  transition: left .26s cubic-bezier(.4, 0, .2, 1), bottom .24s cubic-bezier(.4, 0, .2, 1);
}
#audio-bar[hidden] { display: none; }
/* Desktop: the contents overlay sits on the left, so slide the audio bubble clear of
   it while it's open (mirrors how the reading-mode bubble slides clear of the word
   panel on the right). On phones the TOC is full-screen, so this doesn't apply. */
@media (min-width: 761px) {
  body:not(.sidebar-collapsed) #audio-bar { left: calc(var(--sidebar-w) + 24px); }
}
.audio-controls {
  display: flex; flex-direction: column; gap: 6px;
  padding: 6px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.audio-main { display: flex; align-items: center; gap: 2px; }
.audio-btn {
  border: 0; background: none; color: var(--muted);
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 9px; cursor: pointer; transition: background .14s, color .14s;
}
.audio-btn:hover { color: var(--ink); background: var(--hover); }
.audio-btn svg { width: 22px; height: 22px; }
#audio-play .ic-pause { display: none; }
body.audio-playing #audio-play { color: var(--accent); }
body.audio-playing #audio-play .ic-play { display: none; }
body.audio-playing #audio-play .ic-pause { display: block; }
/* on-demand audio is being generated: spinner in place of the play/pause icon */
body.audio-loading #audio-play svg { display: none; }
body.audio-loading #audio-play::after {
  content: ""; width: 16px; height: 16px;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: audio-spin .7s linear infinite;
}
@keyframes audio-spin { to { transform: rotate(360deg); } }
/* "Fetching audio…" label, only while an on-demand clip is being generated */
.audio-status { display: none; margin-left: 8px; font-size: 12px; color: var(--muted); white-space: nowrap; }
body.audio-loading .audio-status { display: inline; }
.audio-versebtn {
  margin-left: 4px; border: 1px solid var(--line); background: none;
  color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 700;
  padding: 6px 10px; border-radius: 8px; cursor: pointer; transition: background .14s, color .14s;
}
.audio-versebtn:hover { color: var(--ink); background: var(--hover); }

/* seek + volume row — only while a track is active */
.audio-track { display: none; align-items: center; gap: 8px; padding: 0 6px 2px; }
body.audio-active .audio-track { display: flex; }
.audio-time {
  font-size: 10.5px; color: var(--muted);
  font-variant-numeric: tabular-nums; min-width: 28px;
}
.audio-vol-ic { width: 16px; height: 16px; color: var(--muted); flex: 0 0 auto; margin-left: 4px; }
.audio-range {
  -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 3px; background: var(--line);
  cursor: pointer; outline: none;
}
.audio-seek { flex: 1 1 auto; min-width: 96px; }
.audio-vol { flex: 0 0 56px; width: 56px; }
.audio-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; border-radius: 50%; background: var(--accent); border: 0; cursor: pointer;
}
.audio-range::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; background: var(--accent); border: 0; cursor: pointer;
}

/* verse picker popover (replaces the dropdown) */
.audio-verses {
  position: absolute; bottom: calc(100% + 8px); left: 0;
  max-width: 260px; max-height: 232px; overflow-y: auto;
  display: flex; flex-wrap: wrap; gap: 5px; padding: 9px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--float-shadow);
}
.audio-verses[hidden] { display: none; }
.audio-vchip {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: inherit; font-size: 12px; font-weight: 600;
  padding: 4px 9px; border-radius: 7px; cursor: pointer;
}
.audio-vchip:hover { background: var(--hover); border-color: var(--accent); color: var(--accent-ink); }
.audio-vchip.on { background: var(--accent); border-color: var(--accent); color: #1a1208; }

/* the verse currently being read aloud */
.verse.audio-on {
  background: var(--sel);
  border-radius: 3px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* mode-name label that pops above the switcher, then fades (persists in Expanded) */
.sil-label {
  max-width: 260px;
  padding: 7px 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
}
.sil-label.show { opacity: 1; transform: none; }
.sil-label.disclaimer {
  white-space: normal;
  text-align: right;
  font-weight: 500;
  font-style: italic;
  color: var(--accent-ink);
}

/* ---------- SIL inline markers ---------- */
/* Word Context: aligned keyword in the base verse */
.kw {
  cursor: pointer;
  color: var(--accent-ink);
  border-bottom: 1.5px dotted rgba(230, 178, 119, .55);
  border-radius: 2px;
  transition: background .12s, border-color .12s;
}
.kw:hover, .kw:focus-visible {
  background: var(--sel);
  border-bottom-color: var(--accent);
  outline: none;
}

/* Live / Expanded: semantic phrase */
.sem {
  cursor: pointer;
  color: var(--accent-ink);
  border-bottom: 1.5px dotted rgba(230, 178, 119, .5);
  border-radius: 2px;
  transition: opacity .2s ease, background .12s;
}
.sem:hover, .sem:focus-visible { background: var(--sel); outline: none; }
.sem.rotating {
  font-style: italic;
  display: inline-block;       /* a fixed reserved slot (width set in JS) so the word
                                  morphs in place without reflow… */
  text-align: center;          /* …and sits centered within that reserved area */
  text-indent: 0;              /* poetry verses set text-indent:-1em (hanging indent),
                                  which inherits and shrinks these slots — cancel it */
  white-space: nowrap;
  vertical-align: baseline;
  overflow: visible;
}

/* ---------- Word detail panel ---------- */
#word-panel {
  position: fixed;
  top: 0; right: 0;
  width: var(--word-panel-w);
  max-width: 92vw;
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 48px rgba(0, 0, 0, .5);
  z-index: 60;
  overflow-y: auto;
  font-family: var(--sans);
  padding: 26px 24px 60px;
  animation: wp-in .22s cubic-bezier(.4, 0, .2, 1);
}
@keyframes wp-in { from { transform: translateX(28px); opacity: 0; } to { transform: none; opacity: 1; } }
#word-panel-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
#word-panel-close:hover { background: var(--hover); color: var(--ink); }
/* Back button: sits just left of the × — shown only when the word was opened from a
   verse summary, so the reader can return to it. */
#word-panel-back {
  position: absolute;
  top: 14px; right: 54px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
#word-panel-back[hidden] { display: none; }
#word-panel-back svg { width: 18px; height: 18px; display: block; }
#word-panel-back:hover { background: var(--hover); color: var(--ink); }

#word-panel-handle { display: none; }   /* only used as a drag grip on phones */

/* Scale the whole word-detail panel with the A-/A/A+ text-size control, the same
   as the reading text and the sidebar. zoom keeps the panel's size hierarchy
   (word, glosses, notes) proportional in one rule. */
#word-panel-body { zoom: var(--ui-scale); }

.wp-head { margin-bottom: 20px; padding-right: 36px; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.wp-eyebrow { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.wp-word {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  margin: 5px 0 4px;
  color: var(--accent-ink);
}
.wp-role { font-size: 13px; color: var(--muted); font-style: italic; }

.wp-sec { margin-bottom: 22px; }
.wp-h {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 9px;
  font-weight: 700;
}

.wp-token {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 13px;
  margin-bottom: 8px;
}
.wp-surface { font-size: 26px; font-family: var(--serif); color: var(--ink); }
.wp-token-meta { display: flex; gap: 10px; align-items: baseline; margin-top: 2px; }
.wp-translit { font-style: italic; color: var(--accent-ink); font-size: 14px; }
.wp-strongs {
  font-size: 11px; font-weight: 700;
  color: var(--xref);
  background: rgba(127, 176, 216, .12);
  padding: 1px 7px; border-radius: 20px;
}
.wp-morph { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.wp-token-note { font-size: 12.5px; line-height: 1.5; color: var(--accent-ink); margin-top: 3px; font-style: italic; }

/* ---------- Verse summary panel ---------- */
.vs-base {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  margin: 0 0 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.vs-explainer { font-size: 14.5px; line-height: 1.65; color: var(--ink); margin: 0; }

/* one-time "is this summary helpful?" feedback prompt */
.vs-feedback {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255,255,255,.02);
}
.vsfb-q { font-family: var(--sans); font-size: 13px; color: var(--muted); }
.vsfb-btns { display: flex; gap: 8px; margin-left: auto; }
.vsfb-btn {
  font: inherit; font-family: var(--sans); font-size: 13px; font-weight: 600;
  padding: 5px 16px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--accent-ink);
}
.vsfb-btn:hover { background: var(--hover); border-color: var(--accent); }
.vsfb-no { color: var(--muted); }
.vsfb-thanks { font-family: var(--sans); font-size: 13px; color: var(--accent-ink); }
/* compact word list: one header line (surface · translit · Strong's) + a short
   description, separated by hairline rules instead of bulky cards */
.vs-words {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  overflow: hidden;
}
/* "Original words" header row + Research-all button */
.vs-words-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.vs-words-head .wp-h { margin-bottom: 9px; }
.vs-research-all {                                   /* subtle, like .conn-find */
  flex: 0 0 auto; font: inherit; font-size: 11.5px; font-weight: 600;
  color: var(--muted); background: none; border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 10px; cursor: pointer; white-space: nowrap;
  transition: background .14s, color .14s, border-color .14s;
}
.vs-research-all:hover:not(:disabled) { background: var(--hover); color: var(--ink); border-color: var(--muted); }
.vs-research-all:disabled { cursor: default; }
.vs-research-all.err { color: var(--woj); border-color: var(--woj); }
.vs-word { padding: 8px 13px; border-top: 1px solid var(--line); }
.vs-word-researched .vs-desc { color: var(--ink); }   /* freshly researched → fuller definition */

/* Cross-reference info: subtle inline button under a section's parallel refs, and
   the explanation shown in the word panel */
.xref-info-btn {
  font: inherit; font-family: var(--sans); font-size: 11.5px; font-weight: 600;
  color: var(--muted); background: none; border: 1px solid var(--line);
  border-radius: 7px; padding: 2px 8px; cursor: pointer; vertical-align: middle; white-space: nowrap;
  transition: background .14s, color .14s, border-color .14s;
}
.xref-info-btn:hover { background: var(--hover); color: var(--ink); border-color: var(--muted); }
.xref-links { display: flex; flex-wrap: wrap; gap: 2px 6px; font-family: var(--sans); font-size: 13px; margin-bottom: 12px; }
.xref-explain { font-family: var(--serif); font-size: 14.5px; line-height: 1.62; color: var(--ink); margin: 0; }
/* per-reference sections: each parallel's explanation, headed by its (clickable)
   reference and set off with an accent rail so it's clear which is which */
.xref-body { display: flex; flex-direction: column; gap: 18px; }
.xref-section { border-left: 2px solid rgba(127, 176, 216, .28); padding-left: 13px; }
.xref-section-ref {
  display: inline-block; margin-bottom: 6px;
  font-family: var(--sans); font-size: calc(13px * var(--ui-scale)); font-weight: 700; letter-spacing: .01em;
  color: var(--accent-ink); text-decoration: none;
}
.xref-section-ref:hover { color: var(--accent); text-decoration: underline; }
.xref-section .xref-explain { font-size: calc(14.5px * var(--ui-scale)); }

/* book introduction (rendered in the word panel) */
.bi-body { display: flex; flex-direction: column; gap: 20px; }
.bi-summary { font-family: var(--serif); font-size: calc(15px * var(--ui-scale)); line-height: 1.62; color: var(--ink); margin: 0; }
.bi-facts { display: flex; flex-direction: column; gap: 11px; }
.bi-fact { display: grid; grid-template-columns: 104px 1fr; gap: 12px; align-items: start; }
.bi-fact-label { font-family: var(--sans); font-size: calc(11px * var(--ui-scale)); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding-top: 2px; }
.bi-fact-val { font-family: var(--sans); font-size: calc(13.5px * var(--ui-scale)); line-height: 1.55; color: var(--ink); }
.bi-sec { display: flex; flex-direction: column; gap: 9px; }
.bi-sec-h { font-family: var(--sans); font-size: calc(12px * var(--ui-scale)); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--accent-ink); }
.bi-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.bi-chip { font-family: var(--sans); font-size: calc(12.5px * var(--ui-scale)); color: var(--accent-ink); background: var(--sel, rgba(230,178,119,.14)); border: 1px solid var(--line); border-radius: 999px; padding: 3px 11px; }
.bi-verse { font-family: var(--sans); font-size: calc(13.5px * var(--ui-scale)); line-height: 1.5; color: var(--ink); padding: 1px 0; }
.bi-verse .reflink { font-weight: 600; }
.bi-verse-why { color: var(--muted); }

@media (max-width: 460px) {
  .bi-fact { grid-template-columns: 1fr; gap: 2px; }
  .bi-fact-label { padding-top: 0; }
}
.vs-word:first-child { border-top: 0; }
.vs-word-link { cursor: pointer; transition: background .14s; }
.vs-word-link:hover, .vs-word-link:focus-visible { background: var(--hover); outline: none; }
.vs-word-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.vs-surface { font-family: var(--serif); font-size: 19px; color: var(--ink); line-height: 1.2; }
.vs-translit { font-style: italic; color: var(--accent-ink); font-size: 13px; }
.vs-strongs {
  font-size: 10px; font-weight: 700; color: var(--xref);
  background: rgba(127, 176, 216, .12); padding: 1px 6px; border-radius: 20px;
}
.vs-desc { font-size: 12.5px; line-height: 1.45; color: var(--muted); margin-top: 2px; }

/* ---------- Connected themes (semantic cross-references) ---------- */
.conn-lead { font-size: 12.5px; line-height: 1.5; color: var(--muted); margin: 0 0 9px; }
.conn-find {
  display: block; width: 100%;
  padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 9px;
  background: none; color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .14s, color .14s, border-color .14s;
}
.conn-find:hover { background: var(--hover); color: var(--ink); border-color: var(--muted); }
.conn-evidence { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.conn-evi {
  font-size: 12px; color: var(--muted);
  padding-left: 14px; position: relative; line-height: 1.45;
}
.conn-evi::before { content: "·"; position: absolute; left: 4px; color: var(--accent); }
.conn-list { display: flex; flex-direction: column; gap: 9px; }
/* "Search again" spinner is appended after existing cards — keep it clear of them. */
.conn-list + .gp-stage { margin-top: 14px; }
.conn-card {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 13px;
}
.conn-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.conn-ref { font-weight: 700; font-size: 13.5px; color: var(--accent-ink); text-decoration: none; }
a.conn-ref { border-bottom: 1px dotted rgba(230, 178, 119, .4); }
a.conn-ref:hover { color: var(--accent); border-bottom-color: var(--accent); }
.conn-type {
  font-size: 9.5px; letter-spacing: .07em; text-transform: uppercase; font-weight: 700;
  color: var(--accent); border: 1px solid rgba(230, 178, 119, .4);
  border-radius: 10px; padding: 1px 7px;
}
.conn-text { font-family: var(--serif); font-size: 14px; line-height: 1.5; color: var(--ink); margin: 7px 0 0; }
.conn-note { font-size: 12.5px; line-height: 1.55; color: var(--muted); margin: 6px 0 0; }
.conn-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.conn-badge {
  font-size: 10px; color: var(--xref);
  background: rgba(127, 176, 216, .12); border-radius: 10px; padding: 1px 7px;
}
.conn-refresh {
  margin-top: 10px; border: 0; background: none; color: var(--xref);
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; padding: 4px 0;
}
.conn-refresh:hover { color: var(--accent-ink); }
.conn-empty { font-size: 12.5px; color: var(--muted); margin: 0 0 8px; }

.wp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-bottom: 14px; }
.wp-fact { display: flex; flex-direction: column; gap: 2px; }
.wp-fact-label { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.wp-fact-val { font-size: 15px; color: var(--ink); }

.wp-def { font-size: 14px; line-height: 1.6; color: var(--ink); margin: 0 0 10px; }
.wp-note { font-size: 13px; line-height: 1.55; color: var(--muted); margin: 0 0 12px; }

/* Copy button (verse summary text + word definition). Floats top-right so the
   text wraps around it; flashes a check on copy. */
.vs-textblock, .wp-defblock { display: flow-root; }
.wp-copy {
  float: right;
  margin: 0 0 6px 10px;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel-2); color: var(--muted);
  cursor: pointer; transition: background .14s, color .14s, border-color .14s;
}
.wp-copy:hover { color: var(--ink); background: var(--hover); }
.wp-copy svg { width: 15px; height: 15px; }
.wp-copy .ic-check { display: none; }
.wp-copy.copied { color: var(--accent); border-color: var(--accent); }
.wp-copy.copied .ic-copy { display: none; }
.wp-copy.copied .ic-check { display: block; }

.vs-label {
  font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 5px;
}
.vs-exp { font-style: italic; color: var(--accent-ink); }
.wp-aln-note {
  border-left: 2px solid var(--accent);
  padding-left: 11px;
  font-style: italic;
}

.wp-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.wp-chip {
  font-size: 12.5px;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
}
/* Stack the (often long) category label above its chips so the chips get
   the full panel width to wrap across, instead of being squeezed into a
   narrow column beside the label. */
.wp-facet { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.wp-facet-label {
  font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); font-weight: 700;
}
.wp-facet .wp-chips { margin-bottom: 0; }

.wp-links { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.wp-link { color: var(--xref); text-decoration: none; font-size: 13px; border-bottom: 1px dotted rgba(127,176,216,.4); align-self: flex-start; }
.wp-link:hover { color: var(--accent-ink); }

.wp-usage {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  margin-bottom: 9px;
}
.wp-usage-ref { font-weight: 700; font-size: 13px; color: var(--accent-ink); margin-bottom: 4px; display: block; }
a.wp-usage-link { text-decoration: none; cursor: pointer; border-bottom: 1px dotted rgba(230, 178, 119, .4); }
a.wp-usage-link:hover { color: var(--accent); border-bottom-color: var(--accent); }
.wp-snippet { font-family: var(--serif); font-size: 14.5px; line-height: 1.55; color: var(--ink); margin: 0; }
.wp-match { background: var(--sel); color: var(--accent-ink); border-radius: 3px; padding: 0 2px; }
.wp-usage-note { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }

.wp-more-usages {
  width: 100%;
  margin-top: 2px;
  padding: 9px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: none;
  color: var(--accent-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.wp-more-usages:hover:not(:disabled) { background: var(--hover); border-color: var(--accent); }
.wp-more-usages:disabled { cursor: default; color: var(--muted); }
.wp-more-usages.loading { color: var(--muted); border-style: solid; }

/* "See more" reveals already-stored usages — a quieter text toggle */
.wp-see-usages {
  display: block;
  width: 100%;
  margin: 0 0 9px;
  padding: 7px 12px;
  border: 0;
  background: none;
  color: var(--xref);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.wp-see-usages:hover { color: var(--accent-ink); }
.wp-see-usages[hidden], .wp-more-usages[hidden] { display: none; }

/* ---------- Per-verse generate (LLM) control ---------- */
.gen-btn { display: none; }              /* only when the backend API is present */
body.has-api .gen-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: inherit;                /* so em-based sizing scales with --reading-size */
  width: 1.5em; height: 1.5em;
  vertical-align: middle;            /* baseline anchor; `top` fine-tunes to cap-height center */
  top: -.12em;                       /* nudge up so the icon centers on the text, not the x-height */
  margin: 0 .12em 0 .04em;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  opacity: .55;
  transition: opacity .14s, color .14s;
  -webkit-tap-highlight-color: transparent;
}
.gen-btn svg { width: 80%; height: 80%; }
/* invisible overlay enlarges the tap target beyond the visible icon */
.gen-btn::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2em; height: 2em;
}
.gen-btn:focus-visible { opacity: .8; }
.gen-btn:hover { opacity: 1; color: var(--accent); }
.gen-btn.has-sil { opacity: .9; color: var(--accent); }
/* Generated verses are locked in the cloud — remove their generate icon. Locally
   (body.sil-local) it stays so the verse can be regenerated or removed. */
body:not(.sil-local) .gen-btn.has-sil { display: none; }
.gen-btn.loading {
  opacity: 1; color: var(--accent);
  animation: gen-spin 1s linear infinite;
  pointer-events: none;
}
@keyframes gen-spin { to { transform: rotate(360deg); } }

#gen-toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  z-index: 70;
  max-width: min(540px, 92vw);
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: var(--float-shadow);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 11px;
}
#gen-toast[hidden] { display: none; }
#gen-toast.loading::before {
  content: "";
  flex: 0 0 auto;
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: gen-spin .8s linear infinite;
}
#gen-toast.ok { border-color: rgba(120, 190, 120, .45); color: var(--ink); }
#gen-toast.err { border-color: #b5524a; color: #e3a097; }

#gen-menu {
  position: fixed;
  z-index: 70;
  min-width: 132px;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--float-shadow);
  font-family: var(--sans);
}
#gen-menu[hidden] { display: none; }
.gen-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.gen-menu-item:hover { background: var(--hover); }

/* ---------- Enhance chapter (centred grey frame, empty centre) ---------- */
#enhance-chapter {
  display: block;
  width: fit-content;
  margin: 6px auto 22px;
  padding: 11px 26px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .14s, color .14s, border-color .14s;
}
#enhance-chapter:hover:not(:disabled) { background: var(--hover); color: var(--ink); border-color: var(--muted); }
#enhance-chapter:disabled { cursor: default; color: var(--muted); }
#enhance-chapter[hidden], body:not(.has-api) #enhance-chapter { display: none; }

/* ---------- Confirm / cancel modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 22px;
  background: rgba(0, 0, 0, .55);
  animation: modal-fade .16s ease;
}
#modal[hidden] { display: none; }
#modal-box {
  width: 100%; max-width: 430px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  padding: 22px 24px;
  font-family: var(--sans);
  animation: modal-rise .2s cubic-bezier(.4, 0, .2, 1);
}
#modal-box h3 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-size: 18px;
  color: var(--accent-ink);
}
#modal-box p { margin: 0 0 20px; font-size: 14px; line-height: 1.6; color: var(--ink); }
#modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn-ghost, .btn-primary {
  font: inherit; font-weight: 600; font-size: 13.5px;
  padding: 9px 16px; border-radius: 9px; cursor: pointer;
}
.btn-ghost { border: 1px solid var(--line); background: none; color: var(--muted); }
.btn-ghost:hover { background: var(--hover); color: var(--ink); }
.btn-primary { border: 1px solid var(--accent); background: var(--accent); color: var(--bg); }
.btn-primary:hover { filter: brightness(1.07); }
@keyframes modal-fade { from { opacity: 0; } }
@keyframes modal-rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Live generation progress (inside the word panel) ---------- */
.gp-stage {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-ink);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.gp-stage.loading::before {
  content: "";
  flex: 0 0 auto;
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: gen-spin .8s linear infinite;
}
.gp-stage.done { color: #8fce8f; }
.gp-stage.err { color: #e3a097; }
.gp-base {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.55;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 12px;
  margin: 0 0 18px;
}

.gp-keywords { display: flex; flex-wrap: wrap; gap: 6px; }
.gp-chip {
  font-size: 13px;
  font-family: var(--serif);
  padding: 3px 11px;
  border-radius: 20px;
  background: var(--sel);
  color: var(--accent-ink);
  animation: gp-pop .2s ease;
}
@keyframes gp-pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }

.gp-research { display: flex; flex-direction: column; gap: 9px; }
.gp-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  animation: gp-pop .2s ease;
}
.gp-card.loading { opacity: .7; }
.gp-card-phrase {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--accent-ink);
  display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap;
}
.gp-card-meta { font-size: 11px; font-style: italic; color: var(--muted); font-family: var(--sans); }
.gp-card-status { font-size: 12px; color: var(--muted); font-style: italic; margin-top: 3px; }
.gp-card-glosses { display: flex; flex-wrap: wrap; gap: 5px; margin: 7px 0 0; }
.gp-gloss {
  font-size: 11.5px; padding: 2px 8px; border-radius: 14px;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink);
}
.gp-card-def { font-size: 12.5px; line-height: 1.5; color: var(--muted); margin-top: 7px; }
.gp-card-related { font-size: 11.5px; color: var(--xref); margin-top: 6px; }

.gp-expanded {
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--ink);
  margin: 0;
}
.gp-hl { color: var(--accent-ink); border-bottom: 1.5px dotted rgba(230, 178, 119, .5); }
.gp-hl.forming { opacity: .65; border-bottom-style: solid; }

/* ---------- Narrow screens (portrait phones) ---------- */
@media (max-width: 760px) {
  #welcome, #chapter, #book-intro { padding: 26px 22px 140px; }
  #chapter-title { font-size: 25px; }

  /* top bar spans full width; search shrinks, scope/size stay usable */
  body.word-panel-open #topbar { right: 0; }
  /* word detail is a bottom sheet here, so keep the switcher centred */
  body.word-panel-open #chapter-jump { left: 50%; }
  #topbar { gap: 8px; padding: 0 10px; }
  #search-scope { font-size: 12px; padding: 9px 4px 9px 9px; }
  #textsize .topbar-btn { width: 34px; }

  /* Table of contents opens as a full page (overlay), not a side panel. z-index
     stays above the chat (incl. full-window) so it overlays rather than hides. */
  #sidebar {
    position: fixed;
    left: 0; top: var(--topbar-h);
    z-index: 49;
    width: 100vw;
    flex-basis: 100vw;
    height: calc(100% - var(--topbar-h));
    box-shadow: none;
  }
  body.sidebar-collapsed #sidebar { margin-left: -100vw; }

  /* --- Audio on mobile: a bottom-locked panel toggled by the speaker icon in
     the reading-mode menu. Hidden until toggled; the toggle itself only appears
     when the chapter actually has audio (body.has-audio). When open it shows the
     full controls (centered prev/play/next + verse picker, scrub bar, volume) and
     the reading-mode bar lifts above it. --- */
  body.has-audio .sil-sep { display: block; }
  body.has-audio .sil-audio-toggle { display: flex; }

  /* chat on mobile: a bottom sheet that sits ABOVE the reading-mode pill (and so
     above the audio bar too). Drag the top edge to make it taller; it never
     reaches above the header/search bar and shrinks/returns as the audio panel
     opens/closes. */
  #chat-panel {
    left: 8px; right: 8px; top: auto;
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));   /* clear the reading-mode pill */
    width: auto;
    /* a comfortable default, freely draggable taller (the top edge resizes); the
       only ceiling is the header, so the user controls the size */
    height: var(--chat-h, 50dvh);
    min-width: 0;
    max-height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 104px);
  }
  body.audio-open #chat-panel {                  /* lift above the open audio panel */
    bottom: calc(var(--audio-h, 100px) + 76px + env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--audio-h, 100px) - 92px);
  }
  /* word-detail sheet open: sit above the sheet AND the reading-mode pill (--sheet-h
     tracks the sheet's live height). With audio also open, clear all three. */
  body.word-panel-open #chat-panel {
    right: 8px;
    bottom: calc(var(--sheet-h, 50vh) + 78px + env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--sheet-h, 50vh) - 94px);
  }
  body.audio-open.word-panel-open #chat-panel {
    bottom: calc(var(--sheet-h, 46vh) + var(--audio-h, 100px) + 76px + env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--sheet-h, 46vh) - var(--audio-h, 100px) - 92px);
  }

  /* Full-window mode is a special case: instead of FLOATING above a bottom panel
     (which leaves page content peeking through the gap), the chat fills the screen
     and attaches its bottom edge directly to the top of whatever bottom panel is
     open — the word-detail sheet and/or the audio bar — with no lift offset. */
  body.word-panel-open #chat-panel.fullscreen {
    bottom: var(--sheet-h, 50vh) !important;
    max-height: none !important;
  }
  body.audio-open #chat-panel.fullscreen {
    bottom: var(--audio-h, 100px) !important;
    max-height: none !important;
  }
  body.audio-open.word-panel-open #chat-panel.fullscreen {
    bottom: calc(var(--sheet-h, 46vh) + var(--audio-h, 100px)) !important;
    max-height: none !important;
  }

  /* keyboard up (chat input focused): app.js pins the panel to the VISIBLE viewport
     (visualViewport rect) via inline styles, so positioning lives there, not here —
     this avoids window.innerHeight, which jumps as Firefox toggles its URL bar and
     was flinging the panel to the top of the screen. body.kb-up just marks the state. */

  /* history becomes a slide-in drawer toggled from the chat header */
  .chat-history-toggle { display: flex; align-items: center; }
  .chat-history {
    position: absolute; z-index: 9; left: 0; top: 0; bottom: 0;
    flex-basis: auto; width: min(220px, 78%);
    transform: translateX(-100%); transition: transform .22s cubic-bezier(.4, 0, .2, 1);
    background: var(--panel); box-shadow: 6px 0 22px rgba(0, 0, 0, .4);
  }
  #chat-panel.history-open .chat-history { transform: translateX(0); }
  .chat-history-backdrop {
    position: absolute; inset: 0; z-index: 8; display: block;
    background: rgba(0, 0, 0, .42); opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
  }
  #chat-panel.history-open .chat-history-backdrop { opacity: 1; pointer-events: auto; }
  .chat-hist-title { -webkit-line-clamp: 2; }   /* cut off long titles in the drawer */
  .chat-sub { display: none; }   /* save header room on small screens */
  .chat-rs-l, .chat-rs-tl { display: none; }   /* only top-resize on mobile */

  /* On phones the chat opens as its OWN full-screen page: the reading and all its
     chrome are hidden and the chat fills the viewport — no overlay, no layering, no
     fighting the page underneath. The close (×) button returns to reading. JS sizes
     the panel to the visible viewport (visualViewport) so it sits above the keyboard. */
  body.chat-page #topbar,
  body.chat-page #app,
  body.chat-page #sil-bar,
  body.chat-page #audio-bar,
  body.chat-page #chapter-jump { display: none !important; }
  body.chat-page #chat-panel {
    position: fixed !important;
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: auto !important;
    width: auto !important; max-width: none !important;   /* fill the full screen width */
    height: 100dvh;                  /* JS overrides with the exact visualViewport height */
    max-height: none !important; min-height: 0 !important;
    border: 0 !important; border-radius: 0 !important; box-shadow: none !important;
    transition: none !important;     /* don't animate while tracking the keyboard */
  }
  body.chat-page .chat-expand,
  body.chat-page .chat-rs { display: none; }       /* always full page on a phone */
  #chat-suggestions { display: none !important; }  /* the starter chips are too tall here */

  /* roomier input on touch: a taller default box and a 16px font (stops iOS from
     auto-zooming on focus); keep the send button at a solid tap target */
  .chat-input { gap: 8px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .chat-input textarea { min-height: 44px; padding: 11px 13px; font-size: max(16px, calc(14px * var(--ui-scale))); max-height: 140px; }
  .chat-send { flex: 0 0 auto; width: 44px; height: 44px; align-self: flex-end; }
  .chat-send svg { width: 20px; height: 20px; }

  #audio-bar,
  body.sidebar-collapsed #audio-bar {          /* beat the desktop collapse offset */
    left: 0; right: 0; bottom: 0;
    /* animate `bottom` so the panel rides with the word sheet's snap/open
       animation (display none->block doesn't animate, so no slide on first show) */
    transition: bottom .26s cubic-bezier(.4, 0, .2, 1);
    display: none;                             /* shown only when toggled open */
  }
  body.audio-open #audio-bar:not([hidden]) { display: block; }
  .audio-controls {
    border-radius: 16px 16px 0 0;
    gap: 8px;
    padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -14px 48px rgba(0, 0, 0, .5);
  }
  .audio-main { justify-content: center; }            /* centered controls */
  body.audio-open .audio-track { display: flex; }     /* always show scrub + volume */
  .audio-seek { min-width: 0; }
  .audio-verses { left: 16px; right: 16px; max-width: none; }

  /* lift the reading-mode bar above the open panel (--audio-h measured in JS) */
  body.audio-open #sil-bar { bottom: calc(var(--audio-h, 100px) + 12px); }

  /* Word detail opens as a draggable bottom sheet (~half screen) */
  #word-panel {
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%;
    max-width: none;
    height: 50vh;
    /* Never let the sheet (or its drag handle) slide under the status bar when
       pulled up — keep the top a safe distance below the inset. Clamps any
       height, whether from a class or the live drag. */
    max-height: calc(100vh - env(safe-area-inset-top, 0px) - 8px);
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 8px);  /* dvh where supported */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -14px 48px rgba(0, 0, 0, .55);
    animation: sheet-in .26s cubic-bezier(.4, 0, .2, 1);
    transition: height .26s cubic-bezier(.4, 0, .2, 1);
  }
  #word-panel[hidden] { display: none; }        /* keep hidden beating display:flex */
  #word-panel.sheet-half { height: 50vh; }
  #word-panel.sheet-full { height: 94vh; }
  #word-panel.dragging { transition: none; }   /* follow the finger 1:1 */

  #word-panel-handle {
    display: block;
    flex: 0 0 auto;
    height: 26px;
    cursor: grab;
    touch-action: none;       /* let the drag own the gesture */
  }
  #word-panel-handle::before {
    content: "";
    display: block;
    width: 42px; height: 4px;
    margin: 10px auto 0;
    border-radius: 3px;
    background: var(--line);
  }
  #word-panel-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;   /* don't scroll the page behind */
    padding: 4px 22px 44px;
  }
  #word-panel-close { top: 8px; right: 12px; }
  #word-panel-back { top: 8px; right: 52px; }

  /* lift the switcher above the bottom sheet so it stays reachable
     (capped near the top, where the expanded sheet covers it) */
  body.word-panel-open #sil-bar {
    right: 24px;
    bottom: min(calc(var(--sheet-h, 50vh) + 14px), calc(100vh - 78px));
  }
  body.word-panel-open #audio-bar {
    bottom: min(calc(var(--sheet-h, 50vh) + 14px), calc(100vh - 78px));
  }

  /* Audio panel + word sheet both open: drop the sheet a little, attach the audio
     panel flush to its top, and keep the reading-mode bar above the audio panel
     (not behind it). */
  body.audio-open #word-panel.sheet-half { height: 46vh; }
  body.audio-open #word-panel.sheet-full { height: 86vh; }
  body.audio-open.word-panel-open #audio-bar {
    bottom: var(--sheet-h, 46vh);                 /* attach to the word sheet's top */
  }
  body.audio-open.word-panel-open #sil-bar {
    z-index: 46;                                  /* always above the audio panel */
    bottom: min(calc(var(--sheet-h, 46vh) + var(--audio-h, 90px) + 12px), calc(100vh - 58px));
  }

  /* While actively dragging the sheet, the bars follow the finger 1:1 (no easing
     lag); on release the snap animation re-enables the transition above. */
  body.sheet-dragging #sil-bar,
  body.sheet-dragging #audio-bar,
  body.sheet-dragging #chat-panel { transition: none; }
}

/* narrow phones — claw back room so the text-size pill never clips.
   #search has min-width:0 and flex-shrink, #textsize is flex:0 0 auto,
   so the search bar gives up as much width as needed to keep A− A A+ on screen. */
@media (max-width: 560px) {
  #topbar { gap: 6px; padding: 0 8px; }
  #search-scope {
    flex: 0 1 auto;                /* let the scope shrink too if space is tight */
    font-size: 11px;
    padding: 9px 2px 9px 7px;
    max-width: 52px;
  }
  #search-input { font-size: 13px; padding: 9px 6px; }
  .search-clear { padding: 0 6px; }
  #textsize { padding: 3px; gap: 1px; }
  #textsize .topbar-btn { width: 28px; height: 28px; font-size: 14px; }
  #text-reset { font-size: 12px; }

  /* Compact the audio panel + reading-mode menu controls for narrow phones. */
  .audio-btn { width: 38px; height: 38px; }
  .audio-btn svg { width: 22px; height: 22px; }
  .audio-versebtn { margin-left: 4px; padding: 6px 10px; font-size: 12px; }
  .audio-track { gap: 8px; }
  .audio-time { min-width: 24px; font-size: 10.5px; }
  .audio-vol { flex: 0 0 64px; width: 64px; }
  .sil-modes { padding: 4px; }
  .sil-mode { width: 36px; height: 36px; }
  .sil-mode svg { width: 18px; height: 18px; }
}

@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }

/* ---------- First-run guided tour ---------- */
#tour { position: fixed; inset: 0; z-index: 300; }   /* captures clicks while shown */
#tour.tour-dim { background: rgba(8, 10, 14, .68); }  /* fallback dim for centered steps */
#tour-spot {
  position: fixed;
  border-radius: 10px;
  border: 2px solid var(--accent);
  /* the huge spread is the page dim; the rect itself stays clear (spotlight) */
  box-shadow: 0 0 0 9999px rgba(8, 10, 14, .68), 0 0 16px rgba(230, 178, 119, .4);
  pointer-events: none;
  transition: left .24s ease, top .24s ease, width .24s ease, height .24s ease;
}
#tour-card {
  position: fixed;
  width: min(320px, calc(100vw - 24px));
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--float-shadow);
  padding: 16px 16px 12px;
  font-family: var(--sans);
  animation: tour-pop .2s ease;
}
#tour-card.tour-center { left: 50% !important; top: 50% !important; transform: translate(-50%, -50%); }
@keyframes tour-pop { from { opacity: 0; } }
.tour-ic {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; margin-bottom: 10px;
  background: var(--accent); color: #1a1208;
}
.tour-ic svg { width: 20px; height: 20px; }
.tour-text { margin: 0; font-size: 14px; line-height: 1.55; color: var(--ink); }
.tour-text b { color: var(--accent-ink); font-weight: 600; }
.tour-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.tour-count { font-size: 11.5px; color: var(--muted); letter-spacing: .04em; }
.tour-acts { display: flex; align-items: center; gap: 6px; }
.tour-skip {
  border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 12.5px; cursor: pointer; padding: 7px 8px; border-radius: 8px;
}
.tour-skip:hover { color: var(--ink); }
.tour-next {
  border: 0; background: var(--accent); color: #1a1208;
  font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
  padding: 7px 16px; border-radius: 8px;
}
.tour-next:hover { filter: brightness(1.05); }

/* ===================== SIL Global Statistics page ===================== */
body.stats-page { overflow: auto; height: auto; }
#stats-head {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
#stats-head h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 600; }
.stats-back {
  font-family: var(--sans); font-size: 13px; color: var(--muted);
  text-decoration: none; padding: 5px 10px; border: 1px solid var(--line); border-radius: 7px;
}
.stats-back:hover { color: var(--accent-ink); border-color: var(--accent); }
#stats { max-width: 1100px; margin: 0 auto; padding: 22px 24px 60px; }
.stats-intro { color: var(--muted); font-family: var(--sans); font-size: 14px; margin: 0 0 26px; max-width: 720px; }
.stats-block { margin: 0 0 40px; }
.stats-block-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.stats-block-head h2 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: .02em; }
.stats-summary { margin: 0; color: var(--muted); font-family: var(--sans); font-size: 13px; }

/* dedicated download page */
#dl-page { max-width: 720px; margin: 0 auto; padding: 0 18px 60px; }
.dl-card {
  margin-top: 18px; padding: 20px 22px; font-family: var(--sans);
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
}
.dl-state { font-size: 14px; line-height: 1.55; color: var(--ink); margin-bottom: 14px; }
.dl-warn-strong {
  font-size: 13px; line-height: 1.55; color: var(--accent-ink);
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: 10px;
  padding: 10px 13px; margin-bottom: 12px;
}
.dl-warn {
  font-size: 12.5px; line-height: 1.6; color: var(--muted);
  border-left: 2px solid var(--line); padding: 2px 0 2px 12px; margin: 0 0 18px;
}
.dl-go-big {
  font: inherit; font-size: 15px; font-weight: 600; color: #1a1208; background: var(--accent);
  border: 0; border-radius: 11px; padding: 12px 22px; cursor: pointer;
}
.dl-go-big:hover { filter: brightness(1.06); }
.dl-go-big:disabled { opacity: .6; cursor: default; }
.dl-note { margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.dl-note.dl-err { color: var(--woj); }
.stats-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-family: var(--sans); font-size: 12px; color: var(--muted); }
.legend-swatch { width: 12px; height: 12px; border-radius: 2px; border: 1px solid var(--line); }
.verse-row-wrap { margin-bottom: 18px; }
.testament-band {
  margin: 0 0 8px; font-family: var(--sans); font-size: 12px;
  font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--xref);
}
/* each testament wraps its (uniform-height) book boxes onto as many lines as needed */
.verse-row {
  display: flex; flex-wrap: wrap; align-items: flex-start; gap: 6px 7px;
}
.book-canvas { display: block; image-rendering: pixelated; cursor: pointer; flex: 0 0 auto; }

/* world map: recoloured world.svg with an additive access-glow overlay */
.worldmap {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); padding: 10px; overflow: hidden;
}
.worldmap-svg { width: 100%; height: auto; display: block; }
.worldmap-svg path { fill: #2c313b; stroke: var(--bg); stroke-width: .5; }
.worldmap-svg .glow-layer { mix-blend-mode: screen; }   /* overlapping glows add up */
.worldmap-svg circle { pointer-events: auto; }

/* word completion: a multi-segment percentage bar */
.pct-bar {
  display: flex; width: 100%; height: 26px; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--line); background: rgba(255,255,255,0.05);
}
.pct-seg { height: 100%; transition: width .4s ease; min-width: 0; }
.pct-breakdown { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; }
.pct-breakdown .legend-item { font-size: 12.5px; }
.stats-foot { color: var(--muted); font-family: var(--sans); font-size: 13px; font-style: italic; margin-top: 36px; }
#stats-tip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font-family: var(--sans); font-size: 12.5px; line-height: 1.45;
  color: var(--ink); box-shadow: 0 8px 28px rgba(0,0,0,.5); max-width: 240px;
}
#stats-tip b { color: var(--accent-ink); }

/* home-page completion strip */
.home-stats { margin: 0 auto; }
.home-stats .verse-maps { justify-content: center; }

/* sidebar link to the statistics page */
.tree-stats-link {
  display: flex; align-items: center; gap: 9px;
  margin: 6px 4px 4px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 9px;
  color: var(--accent-ink); text-decoration: none;
  font-size: calc(13.5px * var(--ui-scale)); font-weight: 600;
}
.tree-stats-link:hover { background: var(--hover); border-color: var(--accent); }
.tree-stats-link svg { width: 16px; height: 16px; flex: 0 0 auto; opacity: .85; }
