:root {
  --bg: #0b0b0c;
  --bg-soft: #141417;
  --bg-softer: #1a1a1f;
  --fg: #ededed;
  --fg-muted: #9a9a9f;
  --fg-dim: #6b6b70;
  --accent: #d4a64a;          /* warm lantern gold */
  --accent-deep: #8c6d2a;
  --accent-glow: rgba(212, 166, 74, 0.2);
  --active: rgba(212, 166, 74, 0.15);
  --border: #26262b;
  --border-strong: #34343a;
  --radius: 14px;
  --radius-lg: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Serif stack for big editorial titles (book names, etc). ui-serif lands on
   New York on Apple, Charter on e-ink readers, and falls back to Georgia
   everywhere else — zero network dependency. */
.serif {
  font-family: ui-serif, "New York", "Charter", "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); min-height: 100%; }
body { padding-bottom: env(safe-area-inset-bottom); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: rgba(11,11,12,0.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; }
.icon-btn {
  background: transparent; color: var(--fg); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 10px; cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--bg-soft); }

main { padding: 16px; max-width: 720px; margin: 0 auto; }

/* ---------- Book search ---------- */

.book-search {
  width: 100%; margin: 0 0 14px;
  background: var(--bg-soft); color: var(--fg);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px 10px 40px; font-size: 15px;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a9a9f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 18px;
}
.book-search:focus { outline: none; border-color: var(--accent); }
.book-search::placeholder { color: var(--fg-muted); }
.book-empty { color: var(--fg-muted); padding: 24px 0; text-align: center; }

/* ---------- Continue card (home) ---------- */

.continue-card {
  display: flex; align-items: center; gap: 14px;
  margin: 14px 0 22px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(212,166,74,0.12), rgba(212,166,74,0.04));
  border: 1px solid var(--accent-deep);
  border-radius: var(--radius-lg);
  cursor: pointer;
  color: inherit;
  text-decoration: none;
  transition: transform 0.1s, border-color 0.1s, background 0.15s;
}
.continue-card:hover { border-color: var(--accent); background: linear-gradient(135deg, rgba(212,166,74,0.18), rgba(212,166,74,0.06)); }
.continue-card:active { transform: translateY(1px); }
.continue-card .play-square {
  flex-shrink: 0;
  width: 56px; height: 56px;
  display: grid; place-items: center;
  background: var(--accent); color: #111;
  border-radius: 14px;
  font-size: 22px; line-height: 1;
}
.continue-card .body { flex: 1; min-width: 0; }
.continue-card .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--accent); font-weight: 700;
}
.continue-card .title {
  margin-top: 4px; font-size: 17px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.continue-card .sub {
  margin-top: 3px; color: var(--fg-muted); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.continue-card .chev { color: var(--fg-muted); font-size: 20px; margin-left: 4px; }

/* ---------- Testament headings + section labels ---------- */

.testament-title {
  margin: 22px 0 6px;
  font-size: 28px;
  line-height: 1.1;
}
.testament-title:first-of-type { margin-top: 8px; }
.section-label {
  margin: 14px 0 8px;
  font-size: 11px; letter-spacing: 0.2em;
  color: var(--fg-dim); text-transform: uppercase; font-weight: 600;
}

/* ---------- Book grid ---------- */

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.book-card {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer;
  transition: transform 0.1s, border-color 0.1s, background 0.15s;
  position: relative;
}
.book-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.book-card.has-story { background: var(--bg-softer); }
.book-card .name { font-weight: 700; font-size: 17px; }
.book-card .meta { color: var(--fg-muted); font-size: 12px; margin-top: 4px; }
.book-card.unavailable { opacity: 0.55; }
.book-card .badge-dot {
  position: absolute; top: 12px; right: 12px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ---------- Chapter view header ---------- */

.chapter-header { margin: 4px 0 16px; }
.chapter-header .crumbs {
  font-size: 11px; letter-spacing: 0.18em;
  color: var(--fg-dim); text-transform: uppercase; font-weight: 600;
}
.chapter-header .book-name {
  margin: 6px 0 10px;
  font-size: 44px;
  line-height: 1;
}
.chapter-header .counts {
  color: var(--fg-muted); font-size: 14px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.chapter-header .counts .dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-right: 5px; vertical-align: middle;
  box-shadow: 0 0 8px var(--accent-glow);
}
.chapter-header .counts .with-story { color: var(--accent); font-weight: 600; }
.chapter-header .divider { color: var(--fg-dim); }

.continue-pill {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 14px;
  padding: 8px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border-strong); border-radius: 999px;
  color: var(--fg); font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}
.continue-pill:hover { border-color: var(--accent); background: var(--bg-softer); }
.continue-pill .bookmark { color: var(--accent); font-size: 14px; }

/* ---------- Chapter grid ---------- */

.chapter-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
@media (min-width: 640px) {
  .chapter-grid { grid-template-columns: repeat(8, 1fr); }
}
.chapter-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid; place-items: center;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px;
  color: var(--fg);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.1s, background 0.15s, transform 0.1s;
}
.chapter-cell:hover { border-color: var(--accent); }
.chapter-cell:active { transform: translateY(1px); }
.chapter-cell .has-story-dot {
  position: absolute; top: 6px; right: 6px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}
.chapter-cell.unavailable { color: var(--fg-dim); opacity: 0.55; cursor: not-allowed; }
.chapter-cell.unavailable:hover { border-color: var(--border); }
.chapter-cell.current {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}
.chapter-cell.current .has-story-dot { display: none; }

/* ---------- Story mode segments ---------- */

.segment {
  padding: 10px 12px; border-radius: 10px; margin: 6px 0;
  border: 1px solid transparent; transition: background 0.2s, border-color 0.2s;
}
.segment.active { background: var(--active); border-color: var(--accent-deep); }
.segment .speaker {
  display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--accent); margin-right: 8px;
}
.segment .verses { color: var(--fg-muted); font-size: 11px; margin-left: 8px; }
.segment .text { display: inline; }

.lex { border-bottom: 1px dashed var(--accent-deep); cursor: help; }
.lex-popover {
  position: absolute; background: var(--bg-softer); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; max-width: 280px; z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.lex-popover .orig { color: var(--accent); font-size: 18px; }
.lex-popover .translit { color: var(--fg-muted); font-style: italic; font-size: 12px; }
.lex-popover .gloss { margin-top: 6px; font-size: 13px; line-height: 1.4; }

/* ---------- Player ---------- */

#player {
  position: sticky; bottom: 0; background: rgba(11,11,12,0.95); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); padding: 10px 16px 14px;
}
.player-row { display: flex; align-items: center; gap: 12px; }
#scrubber { flex: 1; }
#timestamp { font-variant-numeric: tabular-nums; color: var(--fg-muted); font-size: 12px; }
.autoplay-btn {
  background: transparent; color: var(--fg-muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 10px; font-size: 12px; cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.autoplay-btn[aria-pressed="true"] {
  background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600;
}
.now-speaker { margin-top: 6px; color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }

.loading { color: var(--fg-muted); padding: 24px; text-align: center; }
.error { color: #ff6b6b; padding: 12px; border: 1px solid #ff6b6b44; border-radius: 10px; }
