/* ---------- Themes ---------- */
:root {
  --bg: #f4eddc;
  --text: #2c261e;
  --muted: #8a7f6c;
  --rule: #d9ceb5;
  --accent: #8b2a1f;        /* ribbon red */
  --bar: #f4eddc;
  --panel: #fbf7ec;
  --hover: rgba(0, 0, 0, 0.05);
  --flash: rgba(196, 140, 40, 0.28);
  --read: rgba(196, 140, 40, 0.08);
  --serif: "Literata", Georgia, "Times New Roman", serif;
  --size: 20px;
  --measure: 34em;
  --top: calc(52px + env(safe-area-inset-top));
}
body.theme-white {
  --bg: #ffffff; --text: #1d1d1d; --muted: #8a8a8a; --rule: #e2e2e2;
  --bar: #ffffff; --panel: #ffffff; --flash: rgba(230, 180, 60, 0.3); --read: rgba(230, 180, 60, 0.1);
}
body.theme-night {
  --bg: #161412; --text: #cfc5b1; --muted: #857b6a; --rule: #3a342c;
  --accent: #c0503f; --bar: #161412; --panel: #211e1a;
  --hover: rgba(255, 255, 255, 0.06); --flash: rgba(200, 150, 60, 0.25); --read: rgba(200, 150, 60, 0.08);
}
body.font-garamond { --serif: "EB Garamond", Garamond, Georgia, serif; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: var(--top);
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bar);
  border-bottom: 1px solid var(--rule);
  transition: transform .25s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
body.bars-hidden .bar { transform: translateY(-100%); }
.title-btn {
  font-family: var(--serif); font-size: 18px; padding: 8px 10px; border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw;
}
.title-btn .caret { font-size: 12px; margin-left: 6px; color: var(--muted); }
.bar-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center; font-size: 16px;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.icon-btn.aa { font-family: var(--serif); font-size: 19px; }
.vn-btn { font-family: var(--serif); font-size: 17px; letter-spacing: 1px; }
.vn-btn[aria-pressed="true"], .vn-btn[aria-pressed="true"]:hover { background: var(--text); color: var(--bg); }
.title-btn:hover, .icon-btn:hover { background: var(--hover); }

/* ---------- Scroll reader ---------- */
#reader {
  padding: calc(var(--top) + 28px) max(22px, env(safe-area-inset-right)) 120px max(22px, env(safe-area-inset-left));
}
#loading { text-align: center; color: var(--muted); margin-top: 30vh; font-style: italic; }
#book, #flow {
  font-size: var(--size);
  line-height: 1.62;
  hyphens: auto; -webkit-hyphens: auto;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
}
#book { max-width: var(--measure); margin: 0 auto; }

.book-title {
  text-align: center; font-weight: 400;
  font-variant: small-caps; letter-spacing: .08em;
  font-size: 1.6em; margin: .4em 0 1em;
}

.chapter { margin: 0 0 1.6em; }
.chapter p { margin: 0; text-align: left; text-wrap: pretty; }
/* Justified is optional: on narrow screens it stretches the gaps between words. */
body.justify .chapter:not(.poetry) p { text-align: justify; }
.chapter p.para { text-indent: 1.4em; }
.dropcap {
  float: left;
  font-size: 3.3em; line-height: .82;
  padding: .06em .12em 0 0;
  margin-top: .02em;
  color: var(--accent);
  font-weight: 400;
}
body.theme-night .dropcap { color: var(--text); }

/* Poetry: one verse per line with a hanging indent */
.poetry p { text-align: left; }
.poetry .v { display: block; padding-inline-start: 1.2em; text-indent: -1.2em; margin-bottom: .15em; }
.poetry .v.first { padding-inline-start: 0; text-indent: 0; }

.vn {
  font-size: .55em; vertical-align: .6em; line-height: 0;
  color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0 .15em 0 .1em; user-select: none;
}
body.hide-vn .vn, .v.first .vn { display: none; }
/* Without chapter numbers: no drop cap, verse 1 gets its number, and a little space marks the new chapter */
body.hide-cn .dropcap { display: none; }
body.hide-cn:not(.hide-vn) .v.first .vn { display: inline; }
body.hide-cn .chapter + .chapter { margin-top: 1em; }
.v.flash { background: var(--flash); border-radius: 3px; transition: background 1.5s; }

.book-end { margin: 0 0 3em; }

/* ---------- Page mode ---------- */
body.mode-page { overflow: hidden; }
body.mode-page #reader { display: none; }
#pager {
  position: fixed; inset: 0; overflow: hidden; background: var(--bg);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#flow {
  position: absolute;
  column-fill: auto;
  transition: transform .28s ease;
  will-change: transform;
}
#flow.no-anim { transition: none; }
#flow .chapter { margin-bottom: 0; }
#pagefoot {
  position: absolute; left: 0; right: 0; bottom: calc(10px + env(safe-area-inset-bottom));
  text-align: center; font-size: 13px; color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ---------- Plan pill ---------- */
#planpill {
  position: fixed; z-index: 15; left: 50%; transform: translateX(-50%);
  bottom: calc(40px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--rule); border-radius: 999px;
  padding: 6px 6px 6px 16px; box-shadow: 0 4px 18px rgba(0,0,0,.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px;
  max-width: calc(100vw - 24px); white-space: nowrap;
}
#planpill-text { overflow: hidden; text-overflow: ellipsis; }
#planpill-done { background: var(--accent); color: #fff; border-radius: 999px; padding: 7px 12px; }
#planpill-x { padding: 6px 8px; color: var(--muted); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Panels ---------- */
#scrim { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.28); }
.panel {
  position: fixed; z-index: 40;
  top: calc(env(safe-area-inset-top) + 12px);
  max-height: calc(100% - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
  left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100vw - 20px));
  background: var(--panel); color: var(--text);
  border: 1px solid var(--rule); border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
  display: flex; flex-direction: column; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--rule);
}
.panel-head h2 { flex: 1; margin: 0; font-family: var(--serif); font-weight: 500; font-size: 20px; }
.panel-head .close, .panel-head .back { padding: 8px 10px; border-radius: 8px; color: var(--muted); font-size: 16px; }
.panel-head .back { color: var(--accent); }
.panel-body { padding: 14px 18px 22px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small-note { font-size: 13px; line-height: 1.5; margin: 14px 0 0; }

.primary { background: var(--accent); color: #fff; border-radius: 10px; padding: 11px 16px; font-weight: 500; }
.secondary { border: 1px solid var(--rule); border-radius: 10px; padding: 10px 14px; }
.wide { width: 100%; }

/* Nav */
.testament { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 6px 0 8px; font-weight: 600; }
.testament.tanakh { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--rule); }
.book-group { margin: 0 0 14px; }
.group-name { font-family: var(--serif); font-style: italic; color: var(--accent); font-size: 15px; margin: 0 0 2px 10px; }
/* Books run down a single column, in reading order. */
.book-list { columns: 1; }
.book-list button { display: block; width: 100%; break-inside: avoid; text-align: left; padding: 6px 10px; border-radius: 8px; font-family: var(--serif); font-size: 16px; }
.book-list button.current { color: var(--accent); font-weight: 600; }
.chap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.chap-grid button { aspect-ratio: 1; border: 1px solid var(--rule); border-radius: 8px; font-family: var(--serif); font-size: 17px; }
.chap-grid button.current { background: var(--accent); color: #fff; border-color: var(--accent); }
.book-list button:hover, .chap-grid button:hover, .list li:hover { background: var(--hover); }

/* Bookmarks */
.ribbon-card { display: flex; gap: 14px; align-items: center; padding: 6px 0 16px; cursor: pointer; }
.ribbon-mark {
  width: 18px; height: 40px; background: var(--accent); flex: none;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
}
.ribbon-card .label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ribbon-card .ref { font-family: var(--serif); font-size: 20px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--rule); border-radius: 6px; }
.list .go { flex: 1; text-align: left; padding: 11px 6px; min-width: 0; }
.list .go .ref { font-family: var(--serif); font-size: 17px; }
.list .go .snip { font-family: var(--serif); font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .del { color: var(--muted); padding: 10px; }

/* Settings */
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; }
.seg button { padding: 8px 12px; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button.on { background: var(--text); color: var(--bg); }

/* Plan */
.plan-progress { height: 8px; background: var(--rule); border-radius: 99px; overflow: hidden; margin: 6px 0 6px; }
.plan-progress > div { height: 100%; background: var(--accent); }
.plan-stats { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.today-card { border: 1px solid var(--rule); border-radius: 12px; padding: 14px; margin: 16px 0 6px; }
.today-card .kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.today-card .reading { font-family: var(--serif); font-size: 21px; margin: 4px 0 12px; }
.today-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.status { font-size: 14px; margin: 8px 0 0; }
.day-list li { gap: 4px; }
.day-list li.today { background: var(--hover); }
.day-list .chk {
  width: 26px; height: 26px; flex: none; margin-left: 4px;
  border: 1.5px solid var(--muted); border-radius: 7px; display: grid; place-items: center; font-size: 15px;
}
.day-list li.done .chk { background: var(--accent); border-color: var(--accent); color: #fff; }
.day-list li.done .ref { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--rule); }
.day-list .go { display: flex; gap: 10px; align-items: baseline; }
.day-list .dn { font-size: 12px; color: var(--muted); width: 52px; flex: none; }
.day-list .date { margin-left: auto; font-size: 12px; color: var(--muted); flex: none; }
.plan-start label { display: block; margin: 12px 0 6px; font-size: 14px; }
.plan-start input { font: inherit; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--bg); color: var(--text); width: 100%; margin-bottom: 12px; }
.plan-foot { margin-top: 20px; text-align: center; }
.plan-foot button { color: var(--muted); font-size: 13px; text-decoration: underline; }
.sync-status { font-size: 14px; margin: 0 0 10px; line-height: 1.45; }

/* ---------- Read aloud ---------- */
.v.reading { background: var(--read); border-radius: 3px; }
.w.now { background: var(--flash); border-radius: 3px; box-shadow: 0 0 0 1px var(--flash); }
#player {
  position: fixed; z-index: 16; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 2px;
  width: min(520px, calc(100vw - 16px));
  background: var(--panel); border: 1px solid var(--rule); border-radius: 16px;
  padding: 6px 8px; box-shadow: 0 6px 24px rgba(0,0,0,.16);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.pbtn { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; color: var(--text); }
.pbtn svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.pbtn.main { background: var(--accent); color: #fff; width: 48px; height: 48px; border-radius: 50%; }
.pbtn.main svg { stroke: none; }
.pbtn.rate { font-size: 14px; width: auto; padding: 0 8px; font-variant-numeric: tabular-nums; }
.pbtn:hover { background: var(--hover); }
.pbtn.main:hover { background: var(--accent); filter: brightness(1.08); }
#player-ref { flex: 1; min-width: 0; text-align: center; font-family: var(--serif); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.playing #reader { padding-bottom: 200px; }
body.playing #planpill { bottom: calc(80px + env(safe-area-inset-bottom)); }
body.playing #pagefoot { display: none; }
.voice-pick { display: flex; gap: 6px; min-width: 0; }
.voice-pick select { min-width: 0; max-width: 190px; font: inherit; font-size: 14px; padding: 7px 8px; border: 1px solid var(--rule); border-radius: 10px; background: var(--bg); color: var(--text); }
.voice-pick .secondary { padding: 7px 10px; font-size: 14px; }
@media (max-width: 380px) {
  .icon-btn { width: 38px; }
  .title-btn { font-size: 17px; padding: 8px 6px; max-width: 40vw; }
  .bar-actions { gap: 0; }
  .pbtn { width: 38px; }
  .pbtn.main { width: 44px; height: 44px; }
}
/* "Verse only" highlighting: keep the verse shaded, don't mark each word. */
body.follow-verse .w.now { background: none; box-shadow: none; }
body.follow-verse .v.reading { background: var(--flash); }

/* ---------- Septuagint / other texts ---------- */
.with-under .v { display: block; }
.with-under p.para { text-indent: 0; }
.kjv-under {
  display: block; font-size: .74em; line-height: 1.45; color: var(--muted);
  margin: .2em 0 .85em; padding-left: .7em; border-left: 2px solid var(--rule);
}
.kjv-under .kref { font-size: .85em; margin-right: .35em; font-variant-numeric: tabular-nums; }
.kjv-under.none { font-style: italic; }

/* Hebrew: right to left, in a typeface made for pointed Hebrew */
.chapter[lang="he"] { font-family: "Noto Serif Hebrew", var(--serif); font-size: 1.12em; line-height: 1.9; }
.chapter[lang="he"] p { text-align: right; hyphens: manual; }
.chapter[dir="rtl"] .dropcap { float: right; padding: .06em 0 0 .14em; font-family: var(--serif); }
.chapter[dir="rtl"] .vn { margin: 0 .1em 0 .15em; }
.chapter[lang="he"] .kjv-under { font-family: var(--serif); font-size: .66em; line-height: 1.45; text-align: left; }
.chapter[lang="el"] p { hyphens: manual; }

/* ---------- Account ---------- */
.account-row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 12px; margin: 0 0 10px; border: 1px solid var(--rule); border-radius: 12px; font-size: 15px;
}
.account-row .chev { margin-left: auto; color: var(--muted); font-size: 20px; }
.account-row:hover { background: var(--hover); }
.install-row b { display: block; font-weight: 500; }
.install-row small { display: block; color: var(--muted); font-size: 13px; margin-top: 1px; }
.install-row .acct-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.install-help { margin: -4px 0 10px; }
#panel-account input {
  display: block; width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; margin: 0 0 8px;
  border: 1px solid var(--rule); border-radius: 10px; background: var(--bg); color: var(--text);
}
.acct-actions { display: flex; gap: 8px; margin-top: 4px; }
.acct-actions button { flex: 1; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 14px 0; }
.or::before, .or::after { content: ''; flex: 1; border-top: 1px solid var(--rule); }
button.link { color: var(--accent); text-decoration: underline; padding: 8px 0; font-size: 14px; }
.notice { background: var(--hover); border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.5; }
.google { font-weight: 500; }

/* ---------- ESV (owner's account) ---------- */
.acct-esv { margin: 0 0 14px; padding: 0 0 14px; border-bottom: 1px solid var(--rule); }
.acct-esv h3 { font-size: 15px; font-weight: 600; margin: 0; }
.acct-esv .small-note { margin: 6px 0 10px; }
.esv-note { color: var(--muted); font-style: italic; }
.chapter .esv-credit {
  margin: 1.4em 0 0; text-indent: 0; font-size: 12px; line-height: 1.5; color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.esv-credit a { color: inherit; }
.esv-nav { display: flex; justify-content: space-between; gap: 12px; margin: 1.6em 0 3em; font-size: 15px; }
.esv-nav button { max-width: 48%; }

/* ---------- Saved verses ---------- */
:root { --hl-yellow: rgba(255, 204, 0, .32); --hl-green: rgba(76, 175, 80, .26); --hl-blue: rgba(66, 133, 244, .22); --hl-pink: rgba(233, 30, 99, .2); }
body.theme-night { --hl-yellow: rgba(255, 204, 0, .25); --hl-green: rgba(76, 175, 80, .25); --hl-blue: rgba(66, 133, 244, .28); --hl-pink: rgba(233, 30, 99, .26); }
.hl-yellow { background-color: var(--hl-yellow); }
.hl-green { background-color: var(--hl-green); }
.hl-blue { background-color: var(--hl-blue); }
.hl-pink { background-color: var(--hl-pink); }
.v.hl { border-radius: 3px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.v.selected { text-decoration: underline dotted var(--accent); text-underline-offset: .25em; }
#versebar {
  position: fixed; z-index: 25; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: min(520px, calc(100vw - 16px));
  background: var(--panel); border: 1px solid var(--rule); border-radius: 16px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: 10px 12px;
  display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#versebar-ref { font-family: var(--serif); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatches { display: flex; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--rule); }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }
.vb-actions { grid-column: 1 / -1; display: flex; gap: 4px; }
.vb-actions button { flex: 1; padding: 8px 6px; border-radius: 10px; font-size: 14px; border: 1px solid var(--rule); }
.vb-actions #vb-close { flex: 0 0 44px; }
body.playing #versebar { bottom: calc(84px + env(safe-area-inset-bottom)); }
.hl-list .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; margin-left: 6px; border: 1px solid var(--rule); }
.swatch.hl-yellow, .dot.hl-yellow { background: #f2c94c; } .swatch.hl-green, .dot.hl-green { background: #6fbf73; } .swatch.hl-blue, .dot.hl-blue { background: #6fa3ef; } .swatch.hl-pink, .dot.hl-pink { background: #ec7aa0; }

.pbtn.mute svg { fill: none; stroke-width: 1.6; }
.pbtn.mute svg path:first-child { fill: currentColor; }
.pbtn.mute.on { color: var(--accent); background: var(--hover); }
.text-pick { min-width: 0; max-width: 230px; font: inherit; font-size: 14px; padding: 7px 8px; border: 1px solid var(--rule); border-radius: 10px; background: var(--bg); color: var(--text); }
.text-choose { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; min-width: 0; }
#text-search { width: 230px; max-width: 100%; font: inherit; font-size: 14px; padding: 7px 8px; border: 1px solid var(--rule); border-radius: 10px; background: var(--bg); color: var(--text); }
