:root {
  --bg: #FAF6EE;
  --text: #2B2825;
  --muted: #7A7064;
  --verse-no: #5C5348;
  --spoken: rgba(234, 219, 185, 0.55);
  --hairline: #E4DCCB;
  --play: #3E5A45;
  --sidebar: #F1ECE2;
  --accent: #0D57B8;
  --accent-tint: rgba(13, 87, 184, 0.12);
  --card: rgba(40, 36, 32, 0.92);
  --card-text: #F4EEE4;
  --toolbar-h: 52px;
  --audio-h: 86px;
  --inset: 14px;
  --col-max: 640px;
  --hl-yellow: rgba(255, 214, 10, 0.45);
  --hl-green: rgba(48, 209, 88, 0.45);
  --hl-blue: rgba(10, 132, 255, 0.45);
  --hl-pink: rgba(255, 92, 154, 0.45);
  --hl-purple: rgba(191, 90, 242, 0.45);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1C1A17;
    --text: #E8E2D6;
    --muted: #A79E90;
    --verse-no: #C4BBAE;
    --spoken: rgba(74, 63, 44, 0.55);
    --hairline: #34302A;
    --play: #6F8F76;
    --sidebar: #23201C;
    --card: rgba(28, 26, 23, 0.94);
    --card-text: #E8E2D6;
  }
}
@media (min-width: 600px) {
  :root { --inset: 20px; }
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
#app { display: flex; flex-direction: column; height: 100%; }

/* Toolbar */
.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: var(--toolbar-h);
  padding: calc(4px + env(safe-area-inset-top)) 6px 8px;
  border-bottom: 0.5px solid var(--hairline);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  position: relative;
  z-index: 5;
}
.tool-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: var(--accent);
  border-radius: 10px;
  flex: 0 0 auto;
}
.tool-btn:active { background: var(--accent-tint); }
.tool-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-pill {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 34px;
  padding: 0 10px;
  border-radius: 17px;
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 17px;
}
.nav-pill:active { background: var(--accent-tint); }
.nav-pill .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70%; }
.nav-pill .chevron { width: 11px; height: 11px; opacity: 0.7; }

/* Reader */
.reader-wrap {
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  overscroll-behavior: contain;
}
.reader {
  max-width: var(--col-max);
  margin: 0 auto;
  padding: 12px var(--inset) calc(var(--audio-h) + 28px + env(safe-area-inset-bottom));
  font-size: calc(17px * var(--text-scale, 1));
  line-height: 1.5;
}
.reader.script-latin-iowan {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}
.reader.script-latin, .reader.script-cyrillic {
  font-family: "New York", "Iowan Old Style", Palatino, Charter, "Times New Roman", "Noto Serif", Georgia, serif;
}
.reader.script-arabic {
  font-family: "Geeza Pro", "Noto Naskh Arabic", "Noto Sans Arabic", "SF Arabic", "Arial Unicode MS", sans-serif;
  direction: rtl;
}
.reader.script-cjk { font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Songti SC", sans-serif; }
.reader.script-korean { font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif; }
.reader.script-devanagari { font-family: "Devanagari Sangam MN", "Noto Sans Devanagari", "Kohinoor Devanagari", sans-serif; }
.reader.script-thai { font-family: "Thonburi", "Sarabun", "Noto Sans Thai", sans-serif; }
.heading {
  color: var(--muted);
  font-size: 82%;
  font-variant: small-caps;
  letter-spacing: 1.2px;
  font-weight: 600;
  margin: 1.15em 0 0.55em;
  text-align: start;
}
.verse {
  position: relative;
  padding: 0.12em 0;
  border-radius: 4px;
}
.verse.spoken { background: var(--spoken); }
.verse .vnum {
  color: var(--verse-no);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", "SF Pro Text", Menlo, Consolas, monospace;
  font-size: 74%;
  vertical-align: super;
  position: relative;
  top: -0.15em;
  padding-inline-end: 0.4em;
  line-height: 0;
  letter-spacing: -0.02em;
}
.layout-lines .verse { display: block; }
.layout-paragraphs .verse {
  display: inline;
  padding: 0;
}
.layout-paragraphs .para {
  margin: 0 0 0.85em;
}
.layout-paragraphs .para .verse.spoken { border-radius: 3px; }
.poetry-line {
  display: block;
  padding-inline-start: 28px;
  position: relative;
  margin: 0;
  padding-top: 1.5px;
  padding-bottom: 1.5px; /* ~3pt line gap total */
}
.poetry-line .vnum {
  position: absolute;
  inset-inline-start: 0;
  top: 0.15em;
  width: 26px;
  text-align: end;
  padding-inline-end: 0;
}
.poetry-line.indent-1 { padding-inline-start: calc(28px + 18px * var(--text-scale, 1)); }
.poetry-line.indent-2 { padding-inline-start: calc(28px + 36px * var(--text-scale, 1)); }
.poetry-line.stanza { margin-top: 8px; }
.poetry-line.mid-para { margin-top: 9px; }
.hl {
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.hl.yellow { background: var(--hl-yellow); }
.hl.green { background: var(--hl-green); }
.hl.blue { background: var(--hl-blue); }
.hl.pink { background: var(--hl-pink); }
.hl.purple { background: var(--hl-purple); }
.markers { display: inline-flex; gap: 3px; margin-inline-start: 4px; vertical-align: middle; }
.markers svg { width: 12px; height: 12px; color: var(--accent); }

.progress-rail {
  position: fixed;
  top: 0;
  right: 0;
  width: 2.5px;
  height: 0%;
  background: var(--play);
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.progress-rail.on { opacity: 1; }

/* Audio bar */
.audio-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 6;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 0.5px solid var(--hairline);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.audio-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  max-width: 720px;
  margin: 0 auto;
}
.audio-top {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 720px;
  margin: 0 auto 2px;
}
.audio-ref {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  line-height: 1.25;
  color: var(--muted);
}
.audio-ref strong { color: var(--text); font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.audio-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: var(--text);
  border-radius: 20px;
  flex: 0 0 auto;
}
.audio-btn:active { background: var(--accent-tint); }
.audio-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.audio-btn.play {
  width: 36px; height: 36px;
  background: var(--play);
  color: #fff;
}
.audio-bar.expanded .audio-btn.play { width: 50px; height: 50px; }
.audio-btn.play svg { fill: #fff; stroke: none; width: 18px; height: 18px; }
.audio-bar.expanded { padding-top: 8px; }
.audio-extra { display: none; }
.audio-bar.expanded .audio-extra { display: inline-grid; }

/* Sheets / overlays */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.32);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .28s ease, visibility .28s;
}
.overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 720px;
  max-height: 92%;
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(110%);
  transition: transform .38s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -8px 40px rgba(0,0,0,.18);
}
.overlay.open .sheet { transform: translateY(0); }
.sheet-grabber {
  width: 36px; height: 5px; border-radius: 3px;
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  margin: 6px auto 0;
  flex: 0 0 auto;
}
.sheet.full { max-height: 100%; height: 100%; border-radius: 0; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--hairline);
  min-height: 48px;
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.sheet-head .done { color: var(--accent); font-weight: 600; padding: 8px; }
.sheet-body { overflow: auto; padding: 12px var(--inset) 24px; flex: 1; }
.search-box {
  width: 100%;
  border: 0;
  background: color-mix(in srgb, var(--muted) 14%, var(--bg));
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 12px;
  outline: none;
}

.section-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 14px 0 8px;
}

.book-grid, .chapter-grid {
  display: grid;
  gap: 8px;
}
.book-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
.chapter-grid { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); }
.book-cell, .ch-cell {
  min-height: 48px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--muted) 10%, var(--bg));
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  padding: 4px 3px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--text);
}
.ch-cell { min-height: 42px; font-variant-numeric: tabular-nums; font-size: 15px; }
.book-cell.current, .ch-cell.current { background: var(--accent-tint); color: var(--accent); }
.book-cell:active, .ch-cell:active { transform: scale(0.98); }
.collapse-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0 12px;
  color: var(--accent);
  font-weight: 600;
}

.lang-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px;
  border-bottom: 0.5px solid var(--hairline);
  width: 100%;
  text-align: start;
}
.lang-row .meta { flex: 1; min-width: 0; }
.lang-row .endonym { font-weight: 600; display: block; }
.lang-row .english { color: var(--muted); font-size: 13px; }
.lang-row .check { width: 20px; color: var(--accent); opacity: 0; }
.lang-row.selected .check { opacity: 1; }

/* Menus */
.menu-list { padding: 6px 0 16px; }
.menu-item {
  width: 100%;
  text-align: start;
  padding: 13px 4px;
  border-bottom: 0.5px solid var(--hairline);
  display: flex; align-items: center; gap: 10px;
}
.menu-item:disabled, .menu-item.soon { color: var(--muted); }
.menu-sep { height: 8px; background: color-mix(in srgb, var(--muted) 10%, var(--bg)); margin: 4px -var(--inset); }

/* Selection card */
.select-card {
  background: var(--card);
  color: var(--card-text);
  width: min(340px, calc(100% - 24px));
  border-radius: 22px;
  padding: 14px 12px 12px;
  margin: auto auto 24px;
  box-shadow: 0 16px 40px rgba(0,0,0,.28);
}
.select-card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; text-align: center; opacity: 0.9; }
.select-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px 4px;
}
.select-grid button {
  color: var(--card-text);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 11px;
  padding: 6px 2px;
}
.select-grid svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.swatches { display: flex; justify-content: center; gap: 10px; padding: 8px 0 2px; }
.swatch {
  width: 28px; height: 28px; border-radius: 14px;
  border: 2px solid transparent;
}
.swatch.on { border-color: #fff; }
.swatch.yellow { background: #FFD60A; }
.swatch.green { background: #30D158; }
.swatch.blue { background: #0A84FF; }
.swatch.pink { background: #FF5C9A; }
.swatch.purple { background: #BF5AF2; }

/* Settings */
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--hairline);
}
.setting-row label { flex: 1; }
.setting-row .value { color: var(--muted); font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.stepper { display: flex; gap: 16px; justify-content: space-between; padding: 8px 0 16px; }
.stepper button { color: var(--accent); font-size: 20px; min-width: 44px; }
.footer-note { color: var(--muted); font-size: 13px; margin: 8px 0 16px; }
select.plain {
  background: color-mix(in srgb, var(--muted) 12%, var(--bg));
  border: 0; border-radius: 8px; padding: 6px 8px; max-width: 60%;
}

/* About */
.about {
  background: var(--bg);
  width: 100%; height: 100%;
  overflow: auto;
  padding: calc(24px + env(safe-area-inset-top)) 22px 40px;
  display: flex; flex-direction: column;
}
.about-hero { text-align: center; margin: 28px 0 24px; }
.about-hero h1 { font-size: 34px; margin: 0 0 8px; letter-spacing: -0.03em; }
.about-hero p { margin: 0; color: var(--muted); font-weight: 600; font-size: 17px; }
.group {
  background: color-mix(in srgb, var(--muted) 10%, var(--bg));
  border-radius: 12px;
  padding: 12px 14px 14px;
  margin-bottom: 16px;
}
.group h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 650; }
.group p { margin: 0; }
.warn { font-weight: 650; display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.warn svg { flex: 0 0 auto; width: 18px; height: 18px; color: #C48A16; margin-top: 1px; }
.continue {
  margin-top: auto;
  align-self: flex-end;
  color: var(--accent);
  font-weight: 650;
  padding: 12px 4px;
  font-size: 17px;
}

/* Library */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.chip {
  border-radius: 14px;
  padding: 5px 10px;
  font-size: 13px;
  background: color-mix(in srgb, var(--muted) 12%, var(--bg));
}
.chip.on { background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.saved-item {
  width: 100%;
  text-align: start;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--hairline);
}
.saved-item .ref { font-weight: 650; }
.saved-item .snippet { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Search results */
.result { width: 100%; text-align: start; padding: 10px 0; border-bottom: 0.5px solid var(--hairline); }
.result .ref { color: var(--accent); font-weight: 600; font-size: 13px; }
.note-editor textarea {
  width: 100%; min-height: 140px;
  border: 0.5px solid color-mix(in srgb, var(--muted) 35%, transparent);
  border-radius: 10px;
  padding: 8px;
  background: transparent;
  resize: vertical;
}
.hidden { display: none !important; }

.group-list {
  background: color-mix(in srgb, var(--muted) 9%, var(--bg));
  border-radius: 12px;
  margin: 0 0 18px;
  overflow: hidden;
}
.group-list .setting-row,
.group-list .menu-item {
  padding-left: 14px;
  padding-right: 14px;
  margin: 0;
  border-bottom: 0.5px solid var(--hairline);
}
.group-list .setting-row:last-child,
.group-list .menu-item:last-child { border-bottom: 0; }
.ios-footer { color: var(--muted); font-size: 13px; line-height: 1.35; margin: -8px 4px 18px; padding: 0 8px; }

.book-card {
  width: 100%;
  text-align: start;
  background: color-mix(in srgb, var(--muted) 9%, var(--bg));
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.book-card h3 { margin: 0 0 4px; font-size: 17px; font-weight: 650; }
.book-card p { margin: 0; color: var(--muted); font-size: 13px; }
.book-reader { font-family: "Iowan Old Style", Palatino, Georgia, serif; font-size: 17px; line-height: 1.5; max-width: 640px; margin: 0 auto; }
.book-reader h1, .book-reader h2 { letter-spacing: -0.02em; }
.book-reader p { margin: 0 0 0.85em; }
.book-reader img { max-width: 100%; height: auto; border-radius: 8px; margin: 8px 0 16px; display: block; }
.book-reader .entry { margin: 0 0 1.2em; }
.voice-banner {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px 0;
  text-align: center;
}
.voice-banner strong { color: var(--text); }


/* Public build: languages without a web-licensed voice */
.audio-bar.listening-off .audio-btn.play,
.audio-bar.listening-off #btnPrevVerse,
.audio-bar.listening-off #btnNextVerse {
  opacity: 0.38;
  pointer-events: none;
}
.audio-bar.listening-off #audioStatus {
  font-size: 13px;
  color: var(--muted, #8A8276);
}
.credits-body p { margin: 0 0 14px; line-height: 1.45; }
.credits-body a { color: var(--accent, #0A84FF); }
.credits-body .mono { font-family: ui-monospace, Menlo, monospace; font-size: 0.92em; }
