/* Layout: one manuscript column, a slim lapis header, rubric-red verse numbers and a gold illuminated chapter numeral. */
:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --ink: #14213d;
  --muted: #5b6680;
  --faint: #959eb4;
  --line: #d6dbe6;
  --gold: #9c7413;
  --gold-soft: #f4ead0;
  --rubric: #b3261e;
  --rubric-soft: #fbe3e0;
  --ok: #2f6b4f;
  --bar: #14213d;
  --bar-ink: #e8ecf5;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 8px 28px rgba(20, 33, 61, .08);
  --done-bg: rgba(47, 140, 90, .16);
  --done-line: rgba(47, 140, 90, .5);
  --prog-bg: rgba(230, 180, 30, .28);
  --prog-line: rgba(190, 140, 10, .75);

  --f-text: "Alegreya", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --f-ui: "Alegreya Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-sc: "Alegreya SC", "Alegreya", Georgia, serif;
  --f-initial: "UnifrakturMaguntia", "Alegreya", Georgia, serif;

  --s-1: .8125rem; --s0: 1rem; --s1: 1.25rem; --s2: 1.6rem; --s3: 2.25rem; --s4: 4.5rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1530; --surface: #131d3f; --ink: #e8ecf5; --muted: #9aa6c4; --faint: #6a789e; --line: #24325c;
    --gold: #d9b44a; --gold-soft: #3a3220; --rubric: #ff7a66; --rubric-soft: #4a1e22; --ok: #7fc9a2;
    --bar: #0a1026; --bar-ink: #e8ecf5; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
    --done-bg: rgba(127, 201, 162, .18); --done-line: rgba(127, 201, 162, .5); --prog-bg: rgba(217, 180, 74, .25); --prog-line: rgba(217, 180, 74, .75);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1530; --surface: #131d3f; --ink: #e8ecf5; --muted: #9aa6c4; --faint: #6a789e; --line: #24325c;
  --gold: #d9b44a; --gold-soft: #3a3220; --rubric: #ff7a66; --rubric-soft: #4a1e22; --ok: #7fc9a2;
  --bar: #0a1026; --bar-ink: #e8ecf5; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  --done-bg: rgba(127, 201, 162, .18); --done-line: rgba(127, 201, 162, .5); --prog-bg: rgba(217, 180, 74, .25); --prog-line: rgba(217, 180, 74, .75);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink); font: 400 var(--s0)/1.5 var(--f-ui);
  -webkit-font-smoothing: antialiased; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
a { color: var(--gold); text-underline-offset: 3px; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- wordmark ---------- */
.wordmark { display: inline-flex; align-items: baseline; font-family: var(--f-sc); font-size: var(--s1); letter-spacing: .04em; user-select: none; }
.wm-initial { font-family: var(--f-initial); color: var(--gold); font-size: 1.55em; line-height: 1; margin-right: 1px; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 20px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; font-weight: 500;
}
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn:disabled { opacity: .6; cursor: progress; }
.link { background: none; border: 0; padding: 0; color: var(--gold); text-decoration: underline; text-underline-offset: 3px; font-weight: 500; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; }
.icon-btn:hover { background: color-mix(in srgb, currentColor 12%, transparent); }
.ic { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 0; }
.icon-btn .ic path[d^="M6 6"] { fill: none; stroke-width: 2; stroke-linecap: round; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 4px 14px; font-size: var(--s-1); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.field { display: grid; gap: 6px; }
.field > span { font-size: var(--s-1); font-weight: 500; color: var(--muted); letter-spacing: .02em; }
input, select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  min-height: 44px; padding: 8px 12px; width: 100%; max-width: 100%;
}
input:focus, select:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px var(--gold-soft); }
.form-msg { min-height: 1.4em; margin: 0; color: var(--rubric); font-size: var(--s-1); }

/* ---------- auth ---------- */
.auth {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 420px); gap: clamp(32px, 6vw, 96px);
  align-items: center; max-width: 1040px; width: 100%; margin: 0 auto;
  padding-block: clamp(32px, 8vh, 96px); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.auth-intro .wordmark { font-size: clamp(2.5rem, 6vw, 4rem); }
.tagline { font-family: var(--f-text); font-size: clamp(var(--s2), 3.4vw, var(--s3)); line-height: 1.15; margin: 18px 0 12px; text-wrap: balance; }
.pitch { color: var(--muted); max-width: 46ch; margin: 0 0 24px; font-size: var(--s1); line-height: 1.5; }
.auth-lang { display: flex; gap: 8px; flex-wrap: wrap; }
.auth-form { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: grid; gap: 16px; box-shadow: var(--shadow); }
.auth-title { margin: 0; font-family: var(--f-sc); font-weight: 500; font-size: var(--s2); }
.switch { margin: 0; color: var(--muted); font-size: var(--s-1); }
@media (max-width: 760px) { .auth { grid-template-columns: minmax(0, 1fr); } }

/* ---------- header bar ---------- */
.bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bar); color: var(--bar-ink); }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bar); }
.bar-in {
  max-width: 1040px; margin: 0 auto; display: flex; align-items: center; gap: 16px; min-height: 60px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px));
}
.bar .wm-initial { color: #d9b44a; }
.ref-btn {
  display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14);
  color: inherit; border-radius: 999px; min-height: 40px; padding: 0 16px 0 12px; font-weight: 500; min-width: 0;
}
.ref-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ref-btn:hover { border-color: #d9b44a; }
.ref-btn .ic { width: 18px; height: 18px; color: #d9b44a; }
.bar-stats { margin-left: auto; display: flex; gap: 18px; font-size: var(--s-1); color: rgba(232,236,245,.75); font-variant-numeric: tabular-nums; }
.bar-stats b { color: #fff; font-size: var(--s0); }
@media (max-width: 640px) { .hide-sm { display: none; } .bar-stats { gap: 12px; } .bar .wordmark { display: none; } .ref-btn { margin-right: auto; } .bar-in { gap: 8px; } }
@media (max-width: 420px) { .bar-stats .stat:nth-child(2) { display: none; } }
.auth-lang .theme-btn { margin-left: 4px; }

/* ---------- stage & manuscript page ---------- */
.stage {
  flex: 1; width: 100%; max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px;
  padding-block: clamp(20px, 5vh, 48px); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  transition: opacity .2s;
}
.stage.dim { opacity: .45; }
.loading { color: var(--muted); text-align: center; }
.page {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
  padding: clamp(22px, 5vw, 52px) clamp(18px, 5vw, 56px); user-select: none; -webkit-user-select: none; cursor: text;
  max-height: 62vh; overflow-y: auto; scrollbar-width: thin; scroll-padding: 30% 0;
}
.page-head { display: grid; justify-items: start; gap: 2px; margin-bottom: 18px; }
.book-title { margin: 0; font-family: var(--f-sc); font-size: var(--s0); letter-spacing: .08em; color: var(--muted); }
.chap-num { font-family: var(--f-initial); color: var(--gold); font-size: var(--s4); line-height: .95; }
.chap-num.big { font-size: 6rem; }
.section-head { margin: 6px 0 0; font-family: var(--f-text); font-style: italic; color: var(--muted); }

.verses { font-family: var(--f-text); font-size: clamp(1.2rem, 2.3vw, 1.45rem); line-height: 1.75; display: grid; gap: .55em; }
.v { margin: 0; overflow-wrap: anywhere; }
.vn { font-family: var(--f-ui); font-size: .58em; font-weight: 700; color: var(--rubric); margin-right: .35em; vertical-align: .55em; line-height: 0; font-variant-numeric: tabular-nums; }
.v.typed { color: var(--muted); }
.v.typed .vn { color: color-mix(in srgb, var(--rubric) 60%, var(--muted)); }
.v.upcoming { color: var(--faint); filter: blur(.4px); }
.v.current { color: var(--faint); }
.w { white-space: nowrap; display: inline; }
.c { border-radius: 3px; transition: color .08s; }
.c.ok { color: var(--ink); }
.c.cur { color: var(--ink); box-shadow: inset 0 -3px 0 var(--gold); background: var(--gold-soft); animation: blink 1.1s steps(2, jump-none) infinite; }
.c.sp.cur { padding: 0 .12em; }
.c.bad { animation: bad .45s ease-out; color: var(--rubric); background: var(--rubric-soft); box-shadow: inset 0 -3px 0 var(--rubric); }
.c.sp.bad { padding: 0 .12em; }
.live.warn { color: var(--rubric); font-weight: 500; }

/* whole-Bible progress strip under the header */
.bible-strip { display: block; width: 100%; border: 0; padding: 0; background: rgba(255,255,255,.04); color: inherit; text-align: left; font-size: var(--s-1); }
.bible-strip:hover { background: rgba(255,255,255,.08); }
.bible-strip-in {
  max-width: 1040px; margin: 0 auto; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 16px; padding-block: 6px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  font-variant-numeric: tabular-nums; color: rgba(232,236,245,.75);
}
.bible-pct b { color: #d9b44a; font-size: var(--s0); margin-left: 2px; }
.bible-line { display: block; height: 3px; background: rgba(255,255,255,.1); }
.bible-line .fill { display: block; height: 100%; width: 0; background: #d9b44a; transition: width .4s ease; }
.v.current.sealed .c { color: var(--ink); }
@keyframes blink { 50% { box-shadow: inset 0 -3px 0 transparent; } }
@keyframes bad { 0% { transform: translateY(-2px); } 100% { transform: none; } }
.shake { animation: shake .28s ease-in-out; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

.chap-prog { display: grid; gap: 8px; }
.meter { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.meter .fill { display: block; height: 100%; width: 0; background: var(--gold); border-radius: inherit; transition: width .4s ease; }
.chap-prog-label { margin: 0; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: var(--s-1); color: var(--muted); font-variant-numeric: tabular-nums; }
.live { color: var(--ink); }

.focus-hint {
  align-self: center; border: 1px dashed var(--gold); background: var(--gold-soft); color: var(--ink); border-radius: 999px;
  padding: 10px 20px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.focus-hint.show { opacity: 1; pointer-events: auto; }
.trap { position: fixed; left: -100px; bottom: 0; width: 40px; height: 40px; opacity: 0; font-size: 16px; border: 0; padding: 0; resize: none; }

.complete { text-align: center; display: grid; justify-items: center; gap: 6px; padding-block: 24px; }
.complete-title { font-family: var(--f-text); font-weight: 500; font-size: var(--s3); margin: 4px 0; text-wrap: balance; }
.complete-stats { display: flex; gap: 24px; flex-wrap: wrap; justify-content: center; color: var(--muted); margin: 6px 0 18px; font-variant-numeric: tabular-nums; }
.complete-stats b { color: var(--ink); font-size: var(--s1); }
.complete-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.notice { text-align: center; display: grid; gap: 12px; justify-items: center; padding: 40px 0; color: var(--muted); }
.fatal { padding: 40px; text-align: center; }

/* ---------- footer ---------- */
.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: var(--s-1); }
.foot-in {
  max-width: 1040px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between;
  padding-block: 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.foot p { margin: 0; }
.credit b { color: var(--ink); font-weight: 500; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(8, 12, 28, .55); display: flex; justify-content: center; align-items: flex-start;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  overflow-y: auto; animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--bg); border-radius: 20px; width: 100%; max-width: 980px; margin-top: 4vh; box-shadow: var(--shadow); border: 1px solid var(--line); }
.set .sheet { max-width: 620px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 24px; }
.sheet-head h2 { margin: 0; font-family: var(--f-sc); font-weight: 500; font-size: var(--s2); }
.sheet-body { padding: 8px 24px 24px; }
@media (max-width: 520px) { .sheet-body { padding: 8px 16px 20px; } .sheet-head { padding-left: 16px; } }

/* library */
.whole { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; display: grid; gap: 10px; margin-bottom: 20px; }
.whole-label { margin: 0; display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.whole-label span { font-family: var(--f-text); font-size: var(--s1); color: var(--gold); font-weight: 700; }
.whole-sub { margin: 0; color: var(--muted); font-size: var(--s-1); font-variant-numeric: tabular-nums; }
.lib-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; align-items: start; }
@media (max-width: 720px) { .lib-cols { grid-template-columns: minmax(0, 1fr); } }
.book-list { max-height: 60vh; overflow-y: auto; padding-right: 6px; scrollbar-width: thin; }
@media (max-width: 720px) { .book-list { max-height: 40vh; } }
.testament h3, .ch-title, .set-group h3 { font-family: var(--f-sc); font-weight: 500; font-size: var(--s-1); letter-spacing: .1em; color: var(--muted); margin: 14px 0 8px; }
.testament:first-child h3 { margin-top: 0; }
.testament ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.book { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 64px; align-items: center; gap: 12px; text-align: left; background: none; border: 0; border-radius: 8px; padding: 7px 10px; }
.book:hover { background: var(--surface); }
.book.sel { background: var(--surface); box-shadow: inset 3px 0 0 var(--gold); }
.book.here .book-name { font-weight: 700; }
.book-name { font-family: var(--f-text); font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-meter { height: 4px; background: var(--line); border-radius: 9px; overflow: hidden; }
.mini-meter .fill { display: block; height: 100%; background: var(--gold); }
.chapters { position: sticky; top: 0; }
.ch-title { font-size: var(--s0); letter-spacing: .04em; color: var(--ink); margin-top: 0; }
.ch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.ch {
  --p: 0%; position: relative; height: 44px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: var(--surface); font-variant-numeric: tabular-nums; font-weight: 500;
}
.ch:hover { border-color: var(--gold); }
/* done = soft green, started or current = soft yellow with a thin bar showing how far in */
.ch.full { background: var(--done-bg); border-color: var(--done-line); }
.ch.part, .ch.here:not(.full) { background: var(--prog-bg); border-color: var(--prog-line); }
.ch.part::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: var(--p); background: var(--prog-line); }
.ch.here { outline: 2px solid var(--ink); outline-offset: 1px; }
.ch-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 12px 0 0; font-size: var(--s-1); color: var(--muted); }
.ch-legend span { display: inline-flex; align-items: center; gap: 6px; }
.ch-legend i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line); background: var(--surface); }
.ch-legend .lg-done { background: var(--done-bg); border-color: var(--done-line); }
.ch-legend .lg-prog { background: var(--prog-bg); border-color: var(--prog-line); }

/* settings */
.settings { display: grid; gap: 8px; }
.set-group { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px 18px 18px; display: grid; gap: 12px; }
.set-group h3 { margin-bottom: 0; }
.set-group > .link, .set-group > .btn { justify-self: start; }
.help { margin: 0; color: var(--muted); font-size: var(--s-1); }
.toggle-row { display: grid; gap: 6px; }
.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 500; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.knob { flex: none; width: 44px; height: 26px; border-radius: 99px; background: var(--line); position: relative; transition: background .15s; }
.knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.toggle input:checked + .knob { background: var(--gold); }
.toggle input:checked + .knob::after { transform: translateX(18px); }
.toggle input:focus-visible + .knob { outline: 2px solid var(--gold); outline-offset: 2px; }
.accents { display: flex; flex-wrap: wrap; gap: 6px; }
.vol-row { display: grid; grid-template-columns: auto minmax(0, 1fr) 3.5em; align-items: center; gap: 12px; font-size: var(--s-1); color: var(--muted); }
.vol-row input[type=range] { min-height: 32px; padding: 0; border: 0; background: transparent; box-shadow: none; accent-color: var(--gold); }
.vol-out { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.pair { border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; font-family: var(--f-text); font-size: 1rem; color: var(--ink); }
.pair b { color: var(--gold); }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin: 0; }
@media (max-width: 480px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat-grid dt { font-size: var(--s-1); color: var(--muted); }
.stat-grid dd { margin: 0; font-family: var(--f-text); font-size: var(--s1); font-weight: 700; font-variant-numeric: tabular-nums; }
.pw summary { cursor: pointer; color: var(--gold); font-weight: 500; }
.pw-form { display: grid; gap: 10px; margin-top: 10px; }
.danger { display: grid; gap: 8px; }
.danger .row { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-link { color: var(--rubric); justify-self: start; }
.danger-btn { background: var(--rubric); color: #fff; border-color: var(--rubric); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
