:root {
  --bg: #f7f2ea;
  --surface: #fffdf9;
  --surface-2: #f0e8db;
  --text: #2a2118;
  --muted: #7a6c5c;
  --line: #e4d9c8;
  --accent: #7a4b1e;
  --accent-2: #b8862f;
  --accent-soft: #f1e2c8;
  --ok: #2f7d4f;
  --bad: #b23b3b;
  --shadow: 0 1px 2px rgba(60,40,20,.06), 0 6px 20px rgba(60,40,20,.07);
  --radius: 16px;
  --reader-size: 19px;
  --hl-yellow: #fbe7a1; --hl-green: #cdebc4; --hl-blue: #c9def5; --hl-pink: #f6cfdc; --hl-orange: #f8d6b3;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171f; --surface: #1c2029; --surface-2: #252a35; --text: #ece6dc; --muted: #9a9384; --line: #2e3442;
    --accent: #e0b36a; --accent-2: #e0b36a; --accent-soft: #3a3226; --ok: #6cc28d; --bad: #ef7f7f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    --hl-yellow: #5c4f1e; --hl-green: #284a2e; --hl-blue: #23405e; --hl-pink: #5a2a3a; --hl-orange: #5e3a1c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171f; --surface: #1c2029; --surface-2: #252a35; --text: #ece6dc; --muted: #9a9384; --line: #2e3442;
  --accent: #e0b36a; --accent-2: #e0b36a; --accent-soft: #3a3226; --ok: #6cc28d; --bad: #ef7f7f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  --hl-yellow: #5c4f1e; --hl-green: #284a2e; --hl-blue: #23405e; --hl-pink: #5a2a3a; --hl-orange: #5e3a1c;
  color-scheme: dark;
}
:root[data-theme="sepia"] {
  --bg: #efe2c6; --surface: #f6ecd6; --surface-2: #e7d6b4; --text: #3b2c18; --line: #dcc8a2; --accent-soft: #e6cfa4;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 16px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent; min-height: 100dvh;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-size: 20px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 12px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }
.pill { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; letter-spacing: .3px; }
.score-chip { font-size: 13px; background: var(--accent-soft); padding: 5px 10px; border-radius: 999px; white-space: nowrap; }

/* Tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 10.5px; color: var(--muted); text-decoration: none; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 2.2; }

/* Layout */
main { max-width: 760px; margin: 0 auto; padding: 16px; outline: none; }
.section-title { font-family: var(--serif); font-size: 22px; margin: 26px 0 12px; }
.section-title:first-child { margin-top: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 640px) { .grid2.wide { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.grid2 > .card, .grid3 > .card { margin-top: 0; }
.card.link { text-decoration: none; color: inherit; display: block; transition: transform .15s; }
.card.link:active { transform: scale(.98); }
button.card { display: flex; flex-direction: column; justify-content: flex-start; text-align: left; width: 100%; font: inherit; color: inherit; }
.card h3 { margin: 0 0 4px; font-size: 17px; }
.card p { margin: 0; }

.hero {
  background: linear-gradient(135deg, #6b3f17, #a8742c 60%, #d0a24f); color: #fff8ec; border: 0;
  position: relative; overflow: hidden;
}
:root[data-theme="dark"] .hero { background: linear-gradient(135deg, #3b2a15, #6e5126 60%, #94713a); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero { background: linear-gradient(135deg, #3b2a15, #6e5126 60%, #94713a); } }
.hero .eyebrow { text-transform: uppercase; letter-spacing: 1.5px; font-size: 11px; opacity: .85; }
.hero blockquote { font-family: var(--serif); font-size: 21px; line-height: 1.45; margin: 10px 0 12px; }
.hero cite { font-style: normal; font-weight: 600; opacity: .95; }
.hero .row { margin-top: 14px; }
.hero .btn { background: rgba(255,255,255,.18); color: #fff; border-color: rgba(255,255,255,.3); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: 14px; text-decoration: none; color: inherit;
}
.btn.primary { background: var(--accent); color: var(--surface); border-color: var(--accent); }
:root[data-theme="dark"] .btn.primary { color: #1b1408; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #1b1408; } }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }

.stat { text-align: center; padding: 14px 8px; }
.stat b { display: block; font-size: 24px; font-family: var(--serif); }
.stat span { font-size: 12px; color: var(--muted); }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width .4s; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.list-item:last-child { border-bottom: 0; }
.list-item .ico { font-size: 22px; width: 40px; height: 40px; display: grid; place-items: center; background: var(--accent-soft); border-radius: 12px; flex: none; }
.chev { color: var(--muted); }

/* Reader */
.reader-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.reader-head .chapter-btn { font-family: var(--serif); font-size: 24px; font-weight: 700; background: none; border: 0; padding: 4px 0; display: flex; align-items: center; gap: 6px; }
.reader-head .chapter-btn svg { width: 18px; height: 18px; }
.reader {
  font-family: var(--serif); font-size: var(--reader-size); line-height: 1.75; padding-bottom: 20px;
}
.verse { border-radius: 6px; padding: 1px 2px; cursor: pointer; transition: background .15s; }
.verse sup { font-family: var(--sans); font-size: .58em; color: var(--accent); font-weight: 700; margin-right: 3px; vertical-align: .55em; }
.verse.sel { text-decoration: underline dotted var(--accent); text-underline-offset: 5px; background: var(--accent-soft); }
.verse.hl-yellow { background: var(--hl-yellow); } .verse.hl-green { background: var(--hl-green); } .verse.hl-blue { background: var(--hl-blue); }
.verse.hl-pink { background: var(--hl-pink); } .verse.hl-orange { background: var(--hl-orange); }
.verse.speaking { outline: 2px solid var(--accent-2); }
.verse .note-dot, .verse .fav-dot { font-family: var(--sans); font-size: .62em; vertical-align: .4em; margin-left: 2px; }
.reader-nav { display: flex; gap: 10px; margin-top: 14px; }
.reader-nav .btn { flex: 1; }
.read-done { margin-top: 12px; }
.read-done.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.reader.paragraph .verse { display: inline; }
.reader.lines .verse { display: block; margin-bottom: 6px; }

/* Pickers */
.tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.book-grid button, .ch-grid button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 6px; font-size: 13px; text-align: center;
}
.book-grid button small { display: block; color: var(--muted); font-size: 11px; }
.book-grid button.on, .ch-grid button.on { border-color: var(--accent); background: var(--accent-soft); }
.ch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; }
.ch-grid button.read { position: relative; }
.ch-grid button.read::after { content: ""; position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.cat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 14px 0 6px; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 86dvh; overflow: auto; background: var(--bg);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .22s ease-out;
  max-width: 760px; margin: 0 auto;
}
.sheet.peek { pointer-events: none; }
.sheet.peek .sheet-backdrop { display: none; }
.sheet.peek .sheet-panel { pointer-events: auto; box-shadow: 0 -8px 30px rgba(0,0,0,.18); border-top: 1px solid var(--line); }
.sheet-grip { width: 40px; height: 5px; background: var(--line); border-radius: 9px; margin: 4px auto 12px; }
.sheet h2 { font-family: var(--serif); margin: 0 0 12px; font-size: 20px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.colors { display: flex; gap: 10px; margin: 6px 0 14px; }
.colors button { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); }
.colors button.none { background: var(--surface); position: relative; }
.colors button.none::after { content: ""; position: absolute; left: 6px; right: 6px; top: 50%; height: 2px; background: var(--bad); transform: rotate(-45deg); }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.actions button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; font-size: 12px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; }

textarea, input[type=text], input[type=search], select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
textarea { min-height: 100px; resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* Search */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; position: sticky; top: 62px; z-index: 5; background: var(--bg); padding: 6px 0; }
.result { padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.result b { color: var(--accent); font-size: 13px; }
.result p { margin: 2px 0 0; font-family: var(--serif); }
mark { background: var(--hl-yellow); color: inherit; border-radius: 3px; padding: 0 1px; }

/* Quiz */
.q-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.q-text { font-family: var(--serif); font-size: 22px; margin: 4px 0 16px; line-height: 1.35; }
.opt { display: block; width: 100%; text-align: left; padding: 14px 16px; margin-bottom: 10px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); font-size: 16px; }
.opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, var(--surface)); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 15%, var(--surface)); }
.opt:disabled { cursor: default; color: var(--text); }
.combo { display: inline-block; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 99px; font-weight: 700; }
.big-score { font-family: var(--serif); font-size: 56px; text-align: center; margin: 10px 0 0; }

/* Facts */
.fact-card { min-height: 230px; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 28px 22px; }
.fact-card .bulb { font-size: 40px; }
.fact-card h3 { font-family: var(--serif); font-size: 21px; margin: 10px 0; }

/* Studies */
.study-sec { margin-bottom: 20px; }
.study-sec h3 { font-family: var(--serif); font-size: 19px; margin: 0 0 6px; }
.vref { border-left: 3px solid var(--accent-2); padding: 6px 12px; margin: 8px 0; background: var(--surface); border-radius: 0 10px 10px 0; font-family: var(--serif); }
.vref b { font-family: var(--sans); font-size: 12px; color: var(--accent); display: block; }

/* Achievements */
.ach { text-align: center; padding: 12px 6px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); }
.ach .e { font-size: 28px; display: block; }
.ach b { font-size: 12px; display: block; margin-top: 4px; }
.ach small { font-size: 11px; color: var(--muted); display: block; line-height: 1.3; }
.ach.locked { opacity: .45; filter: grayscale(1); }

/* Compare */
.cmp { padding: 10px 0; border-bottom: 1px solid var(--line); }
.cmp b { font-size: 12px; color: var(--accent); }
.cmp p { margin: 2px 0 0; font-family: var(--serif); }

/* Toasts */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(80px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); animation: up2 .25s ease-out; max-width: 90vw; }
.toast.gold { background: linear-gradient(135deg, #a8742c, #d9ae5c); color: #fff; font-weight: 600; }
@keyframes up2 { from { transform: translateY(20px); opacity: 0; } }

.switch { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 12px; font-size: 14px; }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.loader { text-align: center; padding: 50px; color: var(--muted); }
.day-check { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 4px 10px; border-radius: 99px; font-size: 13px; text-decoration: none; color: inherit; }
