:root {
  --bg: #120f0c;
  --bg-raised: #1c1814;
  --bg-sunk: #0c0a08;
  --line: #2f2923;
  --text: #ece4d6;
  --text-dim: #a89c8a;
  --text-faint: #7a6f60;
  --gold: #d9a441;
  --gold-soft: rgba(217, 164, 65, 0.14);
  --ember: #c2562f;
  --ok: #7fa66a;
  --focus: #f1c46b;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03), 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --scale: 1;
  --nav-h: 64px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f1e7;
  --bg-raised: #fffdf8;
  --bg-sunk: #ece5d6;
  --line: #ddd3c1;
  --text: #2a231b;
  --text-dim: #6b5f4f;
  --text-faint: #8f8372;
  --gold: #9a6a12;
  --gold-soft: rgba(154, 106, 18, 0.1);
  --ember: #a8431f;
  --ok: #4f7a3c;
  --focus: #9a6a12;
  --shadow: 0 1px 2px rgba(60, 40, 10, 0.06), 0 6px 18px rgba(60, 40, 10, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="light"]) {
    --bg: #f6f1e7;
    --bg-raised: #fffdf8;
    --bg-sunk: #ece5d6;
    --line: #ddd3c1;
    --text: #2a231b;
    --text-dim: #6b5f4f;
    --text-faint: #8f8372;
    --gold: #9a6a12;
    --gold-soft: rgba(154, 106, 18, 0.1);
    --ember: #a8431f;
    --ok: #4f7a3c;
    --focus: #9a6a12;
    --shadow: 0 1px 2px rgba(60, 40, 10, 0.06), 0 6px 18px rgba(60, 40, 10, 0.08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: calc(16px * var(--scale));
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--gold); }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- layout ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
  font-family: var(--serif); font-size: 1.15rem; letter-spacing: 0.02em;
}
.topbar .brand svg { width: 26px; height: 26px; }
.topbar .spacer { flex: 1; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 10px;
  background: transparent; border: 1px solid transparent; cursor: pointer;
  color: var(--text-dim);
}
.icon-btn:hover { background: var(--bg-raised); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn[aria-pressed="true"] { color: var(--gold); }

main {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg-sunk) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--text-faint); font-size: 0.72rem; letter-spacing: 0.02em;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--gold); }
.tabbar a.now {
  color: var(--bg);
}
.tabbar a.now .now-pill {
  display: grid; place-items: center;
  width: 52px; height: 52px; margin-top: -22px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 6px 18px rgba(217, 164, 65, 0.35), 0 0 0 4px var(--bg-sunk);
}
.tabbar a.now span.label { color: var(--text-faint); }
.tabbar a.now[aria-current="page"] span.label { color: var(--gold); }

/* ---------- typography ---------- */

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; letter-spacing: 0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.8em; }
.eyebrow {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--gold); font-weight: 600;
}
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 0.85rem; }

.page-head { margin: 8px 0 18px; }
.page-head h1 { margin-top: 4px; }
.page-head p { margin-top: 8px; color: var(--text-dim); }

.section { margin: 26px 0; }
.section > h2 { margin-bottom: 12px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-raised); color: var(--text);
  cursor: pointer; text-decoration: none; font-weight: 500;
}
.btn:hover { border-color: var(--text-faint); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.primary { background: var(--gold); color: #1a1208; border-color: transparent; font-weight: 650; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 1.05rem; border-radius: 14px; }
.btn[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.search {
  position: relative;
}
.search input {
  width: 100%; min-height: 48px; padding: 12px 14px 12px 42px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-raised);
}
.search input::placeholder { color: var(--text-faint); }
.search svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--text-faint); pointer-events: none;
}

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; cursor: pointer;
  color: var(--text-dim); font-size: 0.88rem;
}
.chip[aria-pressed="true"] { background: var(--gold-soft); color: var(--gold); border-color: var(--gold); }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg-raised);
}
.field textarea { min-height: 96px; resize: vertical; line-height: 1.45; }

/* ---------- cards ---------- */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.hero {
  position: relative; overflow: hidden;
  padding: 22px 18px;
  background:
    radial-gradient(120% 140% at 100% 0%, var(--gold-soft), transparent 60%),
    var(--bg-raised);
}
.hero h1 { font-size: 1.9rem; }
.hero p { color: var(--text-dim); margin: 10px 0 18px; max-width: 34em; }

.thought-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .thought-grid { grid-template-columns: repeat(4, 1fr); } }
.thought-tile {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px; min-height: 104px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg-raised); text-decoration: none; color: var(--text);
  cursor: pointer; text-align: left;
}
.thought-tile:hover { border-color: var(--tile, var(--gold)); }
.thought-tile .numeral {
  font-family: var(--serif); font-size: 0.85rem; color: var(--tile, var(--gold));
  letter-spacing: 0.08em;
}
.thought-tile .name { font-family: var(--serif); font-size: 1.12rem; font-weight: 600; }
.thought-tile .gk { font-size: 0.78rem; color: var(--text-faint); font-style: italic; }
.thought-tile .count { margin-top: auto; font-size: 0.78rem; color: var(--text-faint); }

.entry-list { display: grid; gap: 10px; }
.entry {
  display: block; text-decoration: none; color: var(--text);
  padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg-raised);
}
.entry:hover { border-color: var(--text-faint); }
.entry .meta { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 0.75rem; color: var(--text-faint); }
.entry .when { font-size: 0.98rem; }
.entry .ref { margin-top: 8px; font-family: var(--serif); color: var(--gold); font-size: 0.9rem; }
.entry .snippet { color: var(--text-dim); font-family: var(--serif); font-size: 0.95rem; margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- front matter (Letter / Prologue rows above the Books list) ---------- */
/* Quiet on purpose: no --tile colour, no card background, smaller type than the book
   tiles -- these must not read as a ninth demon (D-08b). */
.front-matter {
  display: flex; flex-direction: column;
  margin: 0 0 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line);
}
.front-matter a {
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--text);
  min-height: 44px; padding: 6px 2px;
}
.front-matter .name { font-size: 0.92rem; font-weight: 600; }
.front-matter .hint { font-size: 0.78rem; color: var(--text-dim); }

.voice {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim);
}
.voice.rebuke { color: var(--ember); border-color: color-mix(in srgb, var(--ember) 45%, transparent); }
.voice.soul { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 45%, transparent); }
.voice.prayer { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }

/* ---------- battle card (single entry) ---------- */

.battle { padding: 22px 18px; }
.battle .when-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--text-faint); margin-bottom: 6px; }
.battle .when { font-size: 1.08rem; color: var(--text-dim); margin: 0 0 20px; }
.battle .say-label { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.verse {
  font-family: var(--serif);
  font-size: calc(1.45rem * var(--scale));
  line-height: 1.45;
  margin: 0;
  quotes: "“" "”";
}
.verse + .verse { margin-top: 18px; }
.verse p { margin: 0; }
.verse p::before { content: open-quote; color: var(--gold); }
.verse p::after { content: close-quote; color: var(--gold); }
.verse cite {
  display: block; margin-top: 10px; font-style: normal; font-family: var(--sans);
  font-size: 0.85rem; color: var(--gold); letter-spacing: 0.02em;
}
.verse cite .tr { color: var(--text-faint); }

.battle-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 22px; }
.battle-actions .wide { grid-column: 1 / -1; }

.pager { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%) translateY(20px);
  max-width: min(92vw, 520px);
  padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  z-index: 20; font-size: 0.92rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- now flow ---------- */

.now-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.now-grid .thought-tile { min-height: 84px; }
.step { font-size: 0.8rem; color: var(--text-faint); margin-bottom: 4px; }

.breath {
  margin: 8px 0 18px; padding: 14px 16px; border-left: 3px solid var(--gold);
  background: var(--gold-soft); border-radius: 0 12px 12px 0; color: var(--text-dim);
  font-size: 0.95rem;
}

/* ---------- journal ---------- */

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 7.5em 1fr 2.5em; align-items: center; gap: 10px; font-size: 0.88rem; }
.bar-track { height: 10px; border-radius: 999px; background: var(--bg-sunk); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--tile, var(--gold)); }
.bar-row .n { text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.log li { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-raised); }
.log .time { font-size: 0.78rem; color: var(--text-faint); }
.log .row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-raised); }
.stat .v { font-family: var(--serif); font-size: 1.6rem; }
.stat .k { font-size: 0.78rem; color: var(--text-faint); }

.empty {
  text-align: center; padding: 34px 16px; color: var(--text-dim);
  border: 1px dashed var(--line); border-radius: var(--radius);
}

.prose p, .prose li { color: var(--text-dim); }
.prose h2 { margin: 24px 0 8px; }
.prose strong { color: var(--text); }
.prose blockquote {
  margin: 14px 0; padding: 4px 0 4px 14px; border-left: 3px solid var(--gold);
  font-family: var(--serif); font-size: 1.08rem; color: var(--text);
}

.install-banner { display: none; margin-top: 12px; }
.install-banner.show { display: flex; }

hr.rule { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }

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

/* ---------- translations ---------- */

.greek { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.greek summary {
  cursor: pointer; color: var(--text-dim); font-size: 0.85rem; letter-spacing: 0.02em;
  list-style-position: inside;
}
.greek summary:hover { color: var(--text); }
.greek .verse { margin-top: 12px; }
.verse.small-verse { font-size: calc(1.08rem * var(--scale)); color: var(--text-dim); }
.online-link { margin: 16px 0 0; font-size: 0.9rem; }
.online-link a { text-decoration: none; }
.online-link a:hover { text-decoration: underline; }
.verse:lang(de) { quotes: "„" "“"; }

/* ---------- Septuagint differences ---------- */

.lxx-note {
  margin-top: 18px; padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--gold) 45%, var(--line));
  border-radius: 12px; background: var(--gold-soft);
}
.lxx-title { margin: 0 0 4px; font-weight: 600; color: var(--gold); font-size: 0.92rem; }
.lxx-why { margin: 0 0 12px; color: var(--text-dim); font-size: 0.92rem; }
.lxx-note .verse { margin-top: 14px; }
.lxx-tag {
  padding: 1px 7px; border-radius: 999px; font-size: 0.68rem; letter-spacing: 0.04em;
  color: var(--gold); border: 1px dashed color-mix(in srgb, var(--gold) 60%, transparent);
}

/* ---------- Evagrius's closing prayers ---------- */

.evagrius-prayer {
  margin: 0 0 18px; padding: 16px 18px;
  border-radius: var(--radius); background: var(--bg-raised);
  border: 1px solid var(--line); border-left: 3px solid var(--tile, var(--gold));
}
.evagrius-prayer figcaption {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-faint); margin-bottom: 8px;
}
.evagrius-prayer blockquote { margin: 0; font-family: var(--serif); font-size: 1.12rem; line-height: 1.45; quotes: "“" "”"; }
.evagrius-prayer blockquote p { margin: 0; }
.evagrius-prayer blockquote p::before { content: open-quote; color: var(--gold); }
.evagrius-prayer blockquote p::after { content: close-quote; color: var(--gold); }
.evagrius-prayer .attrib { margin: 10px 0 0; font-size: 0.75rem; color: var(--text-faint); line-height: 1.4; }

/* ---------- Letter 4 / Prologue text pages ---------- */

.evagrius-text .text-section {
  position: relative; margin: 0 0 16px; padding-left: 28px;
}
.evagrius-text .sec-num {
  position: absolute; left: 0; top: 0.15em;
  font-size: 0.7rem; color: var(--text-faint); font-weight: 400;
  font-family: var(--sans, inherit);
}

/* ---------- read-aloud settings ---------- */

.field input[type="range"] { padding: 0; min-height: 32px; border: 0; background: transparent; accent-color: var(--gold); }
.field output { float: right; font-variant-numeric: tabular-nums; color: var(--text); }
.verse cite a { color: inherit; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent); }

/* ---------- naming a temptation ---------- */

.suggest-set { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
.suggest-set legend { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 8px; padding: 0; }
#suggestions { display: grid; gap: 8px; margin-bottom: 8px; }
.suggestion {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  cursor: pointer;
}
.suggestion:has(input:checked) { border-color: var(--gold); background: var(--gold-soft); }
.suggestion input { margin-top: 3px; accent-color: var(--gold); flex: none; }
.sug-body { display: grid; gap: 4px; min-width: 0; }
.sug-ref { font-family: var(--serif); color: var(--gold); font-size: 0.92rem; }
.suggestion.own .sug-ref { font-family: var(--sans); color: var(--text); }
.sug-text {
  font-family: var(--serif); font-size: 0.98rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.sug-used { font-size: 0.78rem; color: var(--text-faint); }
#own-verse { margin-top: 10px; }
.field .suggestion input[type="radio"] {
  width: auto; min-height: 0; padding: 0; border: 0; background: none; margin: 3px 0 0;
  inline-size: 18px; block-size: 18px;
}
.sug-group { display: grid; gap: 8px; }
.sug-group + .sug-group { margin-top: 6px; }
.sug-head { margin: 6px 0 0; font-size: 0.82rem; font-weight: 600; color: var(--text); }
.sug-head .faint { font-weight: 400; }
.sug-ref .voice { margin-right: 4px; vertical-align: 1px; }

/* ---------- AI suggestions ---------- */

.ai-ask { margin: 2px 0 10px; }
.ai-ask .btn svg { width: 18px; height: 18px; }
.ai-consent { margin-top: 10px; padding: 12px; border: 1px dashed var(--line); border-radius: 12px; }
.ai-consent p { margin: 0 0 10px; color: var(--text-dim); }
.ai-insight, .entry-note {
  margin: 2px 0 4px; padding: 10px 12px; border-left: 3px solid var(--gold);
  background: var(--gold-soft); border-radius: 0 10px 10px 0; font-size: 0.95rem;
}
.entry-note { margin: -4px 0 14px; }
.ai-from { margin: 0; }
.sug-why { font-size: 0.86rem; color: var(--text); }
.small-btn { justify-self: start; min-height: 36px; font-size: 0.85rem; }
.none-fit { display: grid; gap: 8px; justify-items: start; margin-top: 8px; }
.crisis {
  padding: 12px 14px; border: 1px solid #c0503a; border-radius: 12px;
  background: color-mix(in srgb, #c0503a 12%, transparent);
}
.crisis p { margin: 6px 0 0; font-size: 0.92rem; }
.crisis a { color: inherit; font-weight: 600; }
