/* Bible Memory — phone-first styles
   Layout: single column, max 640px, fixed bottom tab bar, full-screen practice view.
   Tokens: paper + ink with a deep green accent; gold reserved for streaks.
*/
:root {
  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-2: #eceae3;
  --fg: #1d222b;
  --muted: #697182;
  --line: #dcd9d0;
  --accent: #2d6a5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe5;
  --gold: #b7860b;
  --good: #2e7d4f;
  --good-soft: #d9efe0;
  --close: #8a5408;
  --close-soft: #f6e7c8;
  --bad: #b23a2f;
  --bad-soft: #f5d9d5;
  --blank: #d8d5cc;
  --shadow: 0 1px 2px rgba(20, 24, 32, 0.06), 0 6px 20px rgba(20, 24, 32, 0.06);
  --font-ui: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-text: "Literata", Georgia, "Times New Roman", serif;
  --radius: 14px;
  --tabbar-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121519; --surface: #1a1f26; --surface-2: #232a33; --fg: #e8e6e0; --muted: #9aa1ab;
    --line: #2b323c; --accent: #5fb39a; --accent-ink: #0f1a16; --accent-soft: #1f3a33;
    --gold: #d9a63a; --good: #5bc08a; --good-soft: #1f3a2b; --close: #e0a030; --close-soft: #3b2f14;
    --bad: #e06a5e; --bad-soft: #3d1f1c; --blank: #343b46;
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 6px 20px rgba(0,0,0,0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121519; --surface: #1a1f26; --surface-2: #232a33; --fg: #e8e6e0; --muted: #9aa1ab;
  --line: #2b323c; --accent: #5fb39a; --accent-ink: #0f1a16; --accent-soft: #1f3a33;
  --gold: #d9a63a; --good: #5bc08a; --good-soft: #1f3a2b; --close: #e0a030; --close-soft: #3b2f14;
  --bad: #e06a5e; --bad-soft: #3d1f1c; --blank: #343b46;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 6px 20px rgba(0,0,0,0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; text-wrap: balance; line-height: 1.2; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.num { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }

/* ---- App frame ---- */
#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.screen {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.screen-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex; justify-content: center;
  z-index: 20;
}
.tabbar-inner { width: 100%; max-width: 640px; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.tab {
  background: none; border: 0; padding: 8px 4px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent); }

/* ---- Cards & lists ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card.flat { box-shadow: none; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; text-align: left; width: 100%;
}
.item .ref { font-weight: 700; }
.item .preview { color: var(--muted); font-family: var(--font-text); font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 0.8rem; color: var(--muted); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.new { background: var(--surface-2); }
.chip.learning { background: var(--close-soft); color: var(--close); }
.chip.reviewing { background: var(--accent-soft); color: var(--accent); }
.chip.memorized { background: var(--good-soft); color: var(--good); }
.chip.due { background: var(--bad-soft); color: var(--bad); }
.chip.tag { background: var(--surface-2); color: var(--muted); font-weight: 500; }
.chip.on { background: var(--accent); color: var(--accent-ink); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); font-weight: 600; font-size: 1rem;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; color: var(--fg);
}
.iconbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; font-weight: 600; font-size: 0.9rem; color: var(--muted); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

/* ---- Forms ---- */
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9rem; }
.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 400; font-size: 1rem;
}
textarea.input { min-height: 120px; resize: vertical; font-family: var(--font-text); line-height: 1.5; }
select.input { appearance: auto; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }
.switch input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---- Today ---- */
.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.streak { display: flex; align-items: baseline; gap: 6px; }
.streak .n { font-size: 2.4rem; font-weight: 800; line-height: 1; color: var(--gold); }
.ring { width: 84px; height: 84px; }
.ring circle { fill: none; stroke-width: 8; }
.ring .track { stroke: var(--surface-2); }
.ring .fill { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dasharray 0.4s ease; }
.ring text { font-size: 15px; font-weight: 700; fill: var(--fg); font-family: var(--font-ui); }
.empty { padding: 20px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---- Library ---- */
.searchbar { display: flex; gap: 8px; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .chip { flex: 0 0 auto; border: 0; min-height: 34px; padding: 6px 12px; font-size: 0.82rem; }
.book-head { margin-top: 6px; }

/* ---- Progress ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 10px; text-align: center; }
.stat .v { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.stat .l { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.heatcal { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; }
.heatcal .d { width: 100%; aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); }
.heatcal .d.l1 { background: #c3d7cf; background: color-mix(in srgb, var(--accent) 30%, var(--surface-2)); }
.heatcal .d.l2 { background: #8fbcae; background: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); }
.heatcal .d.l3 { background: #5a9a88; background: color-mix(in srgb, var(--accent) 80%, var(--surface-2)); }
.heatcal .d.l4 { background: var(--accent); }
.weak { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.weak .word { font-family: var(--font-text); font-size: 1.05rem; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--bad); border-radius: 3px; }

/* ---- Quiz ---- */
.qsuggest { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.qsuggest .btn { flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; padding: 12px 14px; min-height: 0; }
.qsuggest .btn b { font-size: 1rem; }
.qsuggest .btn span { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.qtypes { display: flex; gap: 6px; flex-wrap: wrap; }
.qtypes .chip { border: 1px solid var(--line); min-height: 36px; padding: 6px 12px; font-size: 0.85rem; }
.qtypes .chip.on { border-color: var(--accent); }
.quiz .practice-body-inner { display: flex; flex-direction: column; gap: 12px; }
.qcard {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 10px; transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.qcard.pass { border-color: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.qcard.fail { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.qref { font-size: 1.5rem; }
.w.s-shown { color: var(--accent); font-weight: 600; }
.qchoices { display: grid; gap: 8px; }
.qchoices .btn { justify-content: flex-start; }
.qchoices .btn.good { background: var(--good-soft); border-color: var(--good); color: var(--good); opacity: 1; }
.qchoices .btn.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); opacity: 1; }
.qresult { font-weight: 600; }
.qresult.pass { color: var(--good); }
.qresult.fail { color: var(--bad); }
.qscore { display: flex; gap: 6px; align-items: center; }
.chip.low { background: var(--bad-soft); color: var(--bad); }
.qlist { display: flex; flex-direction: column; }
.qrow { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.qrow:last-child { border-bottom: 0; }
.qrow .n { color: var(--muted); font-size: 0.85rem; min-width: 1.4em; }
.qrow .ms { font-size: 0.9rem; color: var(--bad); font-family: var(--font-text); }

/* ---- Season (league material) ---- */
.seasonbar { display: flex; height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.seasonbar span { display: block; height: 100%; }
.seasonbar .solid { background: var(--good); }
.seasonbar .pass { background: var(--accent); }
.seasonbar .shaky { background: var(--close); }
.vgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 4px; }
.vgrid .v {
  min-height: 34px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--muted); font-size: 0.8rem; font-weight: 600; font-variant-numeric: tabular-nums; padding: 0;
}
.vgrid .v.shaky { background: var(--close-soft); color: var(--close); border-color: transparent; }
.vgrid .v.pass { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.vgrid .v.solid { background: var(--good); color: #fff; border-color: transparent; }
.season-card .ref { font-weight: 700; font-size: 1.05rem; }
.practice-ranges { padding: 0 12px 8px; max-width: 640px; width: 100%; margin: 0 auto; }

/* ---- Practice (full screen) ---- */
.practice {
  position: fixed; top: 0; left: 0; right: 0; height: 100%; height: 100dvh; z-index: 30;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
}
.practice-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  max-width: 640px; width: 100%; margin: 0 auto;
}
.practice-head .title { flex: 1; min-width: 0; }
.practice-head .title h2 { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.practice-modes { padding: 0 12px 8px; max-width: 640px; width: 100%; margin: 0 auto; display: flex; justify-content: center; }
.practice-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 8px 18px 24px;
}
.practice-body-inner { max-width: 640px; margin: 0 auto; }
.text {
  font-family: var(--font-text);
  font-size: 1.3rem;
  line-height: 1.75;
}
.text .verse { margin: 0 0 0.6em; }
.text sup { font-size: 0.6em; color: var(--muted); margin-right: 0.35em; font-family: var(--font-ui); font-weight: 600; vertical-align: top; line-height: 1; }
.w {
  display: inline; padding: 0.04em 0.12em; margin: 0 -0.02em; border-radius: 5px;
  transition: background-color 0.18s ease, color 0.18s ease;
}
.w.s-correct { color: var(--good); }
.w.s-close { color: var(--close); background: var(--close-soft); }
.w.s-missed, .w.s-wrong { color: var(--bad); background: var(--bad-soft); text-decoration: underline; text-decoration-color: var(--bad); text-decoration-thickness: 2px; }
.w.s-hint { color: var(--close); border-bottom: 2px dotted var(--close); }
.w.s-current { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent); }
.w.peek { color: var(--fg) !important; background: var(--surface-2) !important; }

/* hiding modes apply to pending + current words */
.hide-all .w.s-pending, .hide-all .w.s-current,
.hide-keywords .w.s-pending.kw, .hide-keywords .w.s-current.kw,
.hide-letters .w.s-pending, .hide-letters .w.s-current {
  color: transparent;
  background-color: var(--blank);
}
.hide-all .w.s-current, .hide-keywords .w.s-current.kw, .hide-letters .w.s-current { background-color: var(--accent-soft); }
.hide-letters .w.s-pending, .hide-letters .w.s-current { position: relative; }
.hide-letters .w.s-pending::before, .hide-letters .w.s-current::before {
  content: attr(data-first);
  position: absolute; left: 0.12em; top: 0;
  color: var(--fg);
}
.hide-all.no-length .w.s-pending, .hide-all.no-length .w.s-current,
.hide-letters.no-length .w.s-pending, .hide-letters.no-length .w.s-current,
.hide-keywords.no-length .w.s-pending.kw, .hide-keywords.no-length .w.s-current.kw { background-color: transparent; }
.hide-all.no-length .w.s-current, .hide-letters.no-length .w.s-current, .hide-keywords.no-length .w.s-current.kw { box-shadow: 0 0 0 2px var(--accent); }

.verse.verse-hidden .w { color: transparent; background: var(--blank); }

.transcript {
  min-height: 1.6em; font-size: 0.95rem; color: var(--muted); font-style: italic;
  padding: 8px 0 0; border-top: 1px dashed var(--line); margin-top: 14px;
}
.transcript .interim { opacity: 0.6; }

.practice-foot {
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
}
.practice-foot-inner { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.controls .left, .controls .right { display: flex; gap: 8px; }
.controls .left { justify-content: flex-start; }
.controls .right { justify-content: flex-end; }
.mic {
  width: 72px; height: 72px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(45, 106, 92, 0.45);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
  position: relative;
}
.mic svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mic.on { background: var(--bad); box-shadow: 0 6px 18px rgba(178, 58, 47, 0.45); box-shadow: 0 6px 18px color-mix(in srgb, var(--bad) 45%, transparent); }
.mic.on::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid var(--bad); opacity: 0.6;
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(0.9); opacity: 0.7; } 100% { transform: scale(1.25); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .mic.on::after { animation: none; } .w { transition: none; } }
.status-line { font-size: 0.85rem; color: var(--muted); text-align: center; min-height: 1.2em; }
.typed-row { display: flex; gap: 8px; }
.typed-row .input { flex: 1; }

.progressbar { height: 4px; background: var(--surface-2); }
.progressbar > span { display: block; height: 100%; background: var(--accent); transition: width 0.2s ease; }

/* ---- Result sheet ---- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 640px; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh; max-height: 88dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
}
.score { display: flex; align-items: baseline; gap: 8px; }
.score .pct { font-size: 3rem; font-weight: 800; line-height: 1; }
.score .pct.g5, .score .pct.g4 { color: var(--good); }
.score .pct.g3 { color: var(--close); }
.score .pct.g2, .score .pct.g1, .score .pct.g0 { color: var(--bad); }
.breakdown { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.breakdown div { background: var(--surface-2); border-radius: 10px; padding: 8px 6px; text-align: center; }
.breakdown b { display: block; font-size: 1.2rem; }
.breakdown span { font-size: 0.72rem; color: var(--muted); }
.mistakes { display: flex; flex-wrap: wrap; gap: 6px; }
.mistakes .m { font-family: var(--font-text); padding: 3px 9px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); font-size: 0.95rem; }
.mistakes .m.hint { background: var(--close-soft); color: var(--close); }
.mistakes .m.close { background: var(--close-soft); color: var(--close); }
.mistakes .m small { color: var(--muted); font-family: var(--font-ui); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  transform: translateX(-50%); background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 0.9rem; z-index: 60; max-width: calc(100% - 32px);
}

@media (min-width: 640px) {
  body { font-size: 16px; }
  .text { font-size: 1.35rem; }
}
