/* ---------- Tokens ---------- */
:root {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #f0eadf;
  --ink: #1f1b16;
  --muted: #6b6257;
  --faint: #a59a8b;
  --border: #e3dbcd;
  --focus: #2f6b8a;
  --shadow: 0 1px 2px rgb(40 30 20 / .06), 0 8px 24px rgb(40 30 20 / .08);

  /* Section hues: OT warm, NT cool */
  --law: #9a5b2e;
  --history: #a0781f;
  --wisdom: #6c7d27;
  --major: #8a3b3b;
  --minor: #a8554b;
  --gospels: #2f6b8a;
  --acts: #2d7d71;
  --pauline: #3f5a9a;
  --general: #5d4f97;
  --prophecy: #7c3f7c;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
  --spotify: #1db954;
  --apple-podcasts: #8c3fd0;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120f;
    --surface: #1d1a16;
    --surface-2: #26221d;
    --ink: #eee7db;
    --muted: #a99f90;
    --faint: #6f675c;
    --border: #332e27;
    --focus: #7cb6d4;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 10px 30px rgb(0 0 0 / .35);

    --law: #d39466;
    --history: #d6ae55;
    --wisdom: #a8ba5f;
    --major: #d27a7a;
    --minor: #e0907f;
    --gospels: #6fb1d3;
    --acts: #69c2b3;
    --pauline: #8ea6e3;
    --general: #a99be0;
    --prophecy: #cc8bcc;
    --spotify: #1ed760;
    --apple-podcasts: #b77cf0;
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
/* Modal sheet open (phones): app.js pins the page at its scroll offset so swipes can't move it behind the sheet. */
body.locked { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
html:has(body.locked) { overscroll-behavior: none; }
a, button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.short { display: none; }
h1, h2, h3 { margin: 0; font-weight: 650; }
p { margin: 0; }
button { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.label { font: 600 12px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }

/* ---------- Masthead ---------- */
.masthead { padding: 40px 0 20px; }
.brand h1 { font-family: var(--serif); font-size: clamp(30px, 5vw, 44px); line-height: 1.1; letter-spacing: -.01em; margin: 4px 0 8px; }
.lede { color: var(--muted); max-width: 52ch; }

/* ---------- Sticky search bar ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  padding: 10px 0;
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.search {
  position: relative; display: flex; align-items: center; gap: 10px;
  max-width: 640px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 0 14px; box-shadow: var(--shadow);
}
.search:focus-within { border-color: var(--focus); }
.search svg { color: var(--muted); }
.search input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; padding: 12px 0; outline: none;
}
.search input::placeholder { color: var(--faint); }
/* Native clear button is inconsistent (missing on iOS), so we draw our own */
.search input::-webkit-search-cancel-button, .search input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.search .clear {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px; margin-right: -6px; padding: 0;
  border: 0; border-radius: 50%; cursor: pointer;
  background: var(--surface-2); color: var(--muted);
}
.search .clear svg { width: 15px; height: 15px; stroke-width: 2.5; }
.search .clear:active { background: var(--border); color: var(--ink); }
.search.has-value kbd { display: none; }

.search kbd {
  font: 500 12px var(--sans); color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px;
}
.hint { font-size: 13px; color: var(--muted); }
.hint:not(:empty) { margin-top: 8px; }
.hint button {
  border: 0; background: none; padding: 0; color: var(--focus);
  font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}

/* Jump to section */
.jump { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.jump::-webkit-scrollbar { display: none; }
.jump button {
  flex: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  min-height: 30px; padding: 4px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 12.5px; font-weight: 500;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.jump button[aria-current="true"] { background: var(--c); border-color: var(--c); color: var(--surface); }
.jump button[aria-current="true"] .dot { background: var(--surface); }
.section { scroll-margin-top: calc(var(--bar-h, 64px) + 10px); }

/* ---------- Filters ---------- */
.filters-inner { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 16px; padding-top: 14px; }

.seg { display: inline-flex; flex: none; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 7px;
  font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .1); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex: none;
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; color: var(--muted);
}
.chip[aria-pressed="true"] { color: var(--ink); border-color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cc, var(--faint)); flex: none; }

/* ---------- Main ---------- */
main { padding-top: 20px; padding-bottom: 40px; }
.stats { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.stats strong { color: var(--ink); font-weight: 600; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 28px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { font-family: var(--serif); font-size: 20px; }

/* Sections + book tiles */
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.section-head h2 { font-family: var(--serif); font-size: 19px; }
.section-head h2::before {
  content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px;
  background: var(--c); margin-right: 9px; vertical-align: 1px;
}
.section-head span { font-size: 13px; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }

.tile {
  position: relative; display: flex; flex-direction: column; align-items: flex-start;
  text-align: left; min-height: 92px; padding: 10px 12px 14px; min-width: 0;
  background: color-mix(in srgb, var(--c) 7%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c) 22%, var(--border));
  border-left: 3px solid var(--c);
  border-radius: 8px; cursor: pointer; overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.tile:active { transform: scale(.97); }
.tile .abbr { font: 650 18px/1.1 var(--serif); color: var(--c); }
.tile .name { font-size: 13px; font-weight: 500; margin-top: 2px; line-height: 1.25; max-width: 100%; }
.tile .meta { font-size: 12px; color: var(--muted); margin-top: auto; padding-top: 6px; }
.tile .count {
  position: absolute; top: 9px; right: 9px; min-width: 22px; height: 22px; padding: 0 6px;
  display: grid; place-items: center; border-radius: 999px;
  background: var(--c); color: var(--surface); font-size: 12px; font-weight: 600;
}
.tile .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: color-mix(in srgb, var(--c) 14%, transparent); }
.tile .bar i { display: block; height: 100%; background: var(--c); }
.tile.empty { background: var(--surface); border-color: var(--border); border-left-color: color-mix(in srgb, var(--c) 35%, var(--border)); }
.tile.empty .abbr { color: color-mix(in srgb, var(--c) 55%, var(--faint)); }
.tile.empty .name { color: var(--muted); }
.tile.empty .count { display: none; }

/* Sermon cards (shared by drawer, results, recent) */
.sermons { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sermons.cols { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.sermon {
  position: relative;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; align-items: start;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); text-decoration: none;
  transition: border-color .12s ease, background .12s ease;
}
.sermon:active { background: var(--surface-2); }
.sermon .ref { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; min-width: 0; font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--c, var(--muted)); }
.sermon .ref .pass { display: flex; gap: 4px; min-width: 0; overflow: hidden; white-space: nowrap; margin-left: -7px; }
.sermon .ref .pass:not(:has(+ .study-mark)) { margin-right: auto; }
.sermon .ref .study-mark { margin-left: -4px; align-self: center; }
.sermon .ref time { font-weight: 400; letter-spacing: 0; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sermon .title { font-family: var(--serif); font-size: 17px; font-weight: 650; line-height: 1.3; grid-column: 1; color: inherit; text-decoration: none; }
/* The whole card opens the sermon: the title link's hit area is stretched over the card,
   and the pills/links below sit above it so they get their own clicks. */
.sermon .title::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.sermon .title:focus-visible { outline: none; }
.sermon:has(.title:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.sermon .pill, .sermon .facet, .sermon .ico { position: relative; z-index: 1; cursor: pointer; }
:is(.sermon, .facts) .pill {
  flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  border: 0; border-radius: 999px; padding: 1px 7px;
  font: inherit; letter-spacing: inherit; color: var(--pc);
  background: color-mix(in srgb, var(--pc) 10%, transparent);
  transition: background .12s ease;
}
:is(.sermon, .facts) .pill:active { background: color-mix(in srgb, var(--pc) 22%, transparent); }
:is(.sermon, .facts, .s-sub) .facet {
  border: 0; background: none; padding: 0; font: inherit; color: inherit; text-align: left;
  text-decoration: underline dotted; text-decoration-color: var(--faint); text-underline-offset: 3px;
}
:is(.sermon, .facts, .s-sub) .facet { cursor: pointer; }
:is(.sermon, .facts, .s-sub) .facet.series { font-style: italic; }
.sermon .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; font-size: 13px; color: var(--muted); grid-column: 1; min-width: 0; }
.sermon .meta .who { display: inline-flex; align-items: center; gap: 6px; }
.sermon .meta .series { font-style: italic; }
.sermon .hit { grid-column: 1; font-size: 12.5px; line-height: 1.45; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
.sermon .hit mark { background: color-mix(in srgb, var(--c, var(--muted)) 18%, transparent); color: var(--ink); border-radius: 3px; padding: 0 2px; }
.more-btn {
  display: block; margin: 14px auto 2px; padding: 9px 18px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: inherit; font: inherit; font-size: 14px; font-weight: 500;
}
.more-btn:hover { background: var(--surface-2); }
.more-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* "Study": sits on the passage line (card) or after the passage (sermon page), never on its own row */
.study-mark {
  flex: none; margin-right: auto; font-size: 10.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
  line-height: 1; padding: 3px 6px; border-radius: 4px;
  color: var(--pc, var(--c)); background: color-mix(in srgb, var(--pc, var(--c)) 10%, transparent);
}
.facts .study-mark { align-self: center; margin-left: 2px; }
.facts .tags { display: flex; flex-wrap: wrap; gap: 4px; }
:is(#d-list, #d-group) .long { display: none; }
:is(#d-list, #d-group) .short { display: inline; }
:is(#d-list, #d-group) .sermon .meta { flex-wrap: nowrap; white-space: nowrap; overflow: hidden; column-gap: 0; }
:is(#d-list, #d-group) .sermon .meta > * { flex: none; }
:is(#d-list, #d-group) .sermon .meta > * + *::before { content: "·"; margin: 0 6px; color: var(--faint); }
:is(#d-list, #d-group) .sermon .meta .series { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.fit-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; }
.fit-bar .chip .n { color: var(--faint); font-variant-numeric: tabular-nums; }
.fit-bar .chip[aria-pressed="true"] { color: var(--surface); background: var(--c); border-color: var(--c); }
.fit-bar .chip[aria-pressed="true"] .n { color: inherit; opacity: .8; }
.fit-bar .hint { font-size: 12px; color: var(--muted); }
.facts .tag { font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.sermon .listen { grid-column: 2; grid-row: 1 / span 3; align-self: center; display: flex; flex-direction: column; gap: 4px; }

/* Listen icons: brand marks are CSS masks over the SVG files, so they take a color */
.brand-ico { display: block; width: 22px; height: 22px; background: currentColor; flex: none; }
.brand-ico.spotify { -webkit-mask: url("spotify.svg") center / contain no-repeat; mask: url("spotify.svg") center / contain no-repeat; }
.brand-ico.apple { -webkit-mask: url("apple-podcasts.svg") center / contain no-repeat; mask: url("apple-podcasts.svg") center / contain no-repeat; }
.spotify { color: var(--spotify); }
.apple { color: var(--apple-podcasts); }
.web, .audio { color: var(--muted); }
.sermon .ico {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 9px; text-decoration: none;
  transition: background .12s ease, border-color .12s ease;
}
.sermon .ico svg { width: 20px; height: 20px; }
.sermon .ico:active { background: var(--surface-2); border-color: var(--border); }
.sermon .ico:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.group-label { font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.group-label:first-child { margin-top: 0; }

/* Equal-height cards in a row; meta pinned to the bottom so rows line up */
.sermons.cols > li { display: flex; min-width: 0; }
.sermons.cols .sermon { flex: 1; grid-template-rows: auto auto 1fr auto; }
.sermons.cols .sermon .meta { align-self: end; }

.empty-state { padding: 24px 8px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; font-family: var(--serif); font-size: 18px; color: var(--ink); margin-bottom: 4px; }

/* Hover effects only where hover exists (stops "stuck" hover after a tap on phones) */
@media (hover: hover) {
  .tile:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--c); }
  .sermon:hover { border-color: var(--muted); background: var(--surface-2); }
  .sermon .ico:hover { background: var(--surface); border-color: var(--border); }
  :is(.sermon, .facts) .pill:hover { background: color-mix(in srgb, var(--pc) 22%, transparent); }
  :is(.sermon, .facts, .s-sub) .facet:hover { color: var(--ink); text-decoration-style: solid; text-decoration-color: currentColor; }
  .listen-btn:hover { border-color: currentColor; }
  a.s-row:hover { background: var(--surface-2); }
  .icon-btn:hover { color: var(--ink); border-color: var(--muted); }
  .fchip:hover { border-color: var(--muted); }
  .fchip:hover svg { color: var(--ink); }
}


/* ---------- Search: "go to" rows, matches by book ---------- */
.goto { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.goto-row {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "kind arrow" "name arrow" "sub arrow";
  align-items: center; column-gap: 10px; text-align: left; cursor: pointer;
  padding: 9px 12px 9px 14px; border-radius: 8px; color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--gc) 35%, var(--border));
  border-left: 3px solid var(--gc);
  background: color-mix(in srgb, var(--gc) 7%, var(--surface));
}
.goto-row .g-kind { grid-area: kind; font-size: 10.5px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: color-mix(in srgb, var(--gc) 75%, var(--ink)); }
.goto-row .g-name { grid-area: name; font: 650 16px/1.25 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goto-row .g-sub { grid-area: sub; font-size: 12.5px; color: var(--muted); }
.goto-row svg { grid-area: arrow; color: var(--gc); }
.goto-row:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.inbooks { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 12px; }
.inbooks .ib-label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-right: 2px; }
.inbooks .ib {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer;
  padding: 4px 6px 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--c) 35%, var(--border)); background: color-mix(in srgb, var(--c) 7%, var(--surface));
}
.inbooks .ib .n { min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--c); color: var(--surface); font-size: 11.5px; font-weight: 600; text-align: center; }
.inbooks .ib:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* Text search: books with no matches go quiet */
#library.searching .tile.empty { opacity: .55; }

/* ---------- Filters that are on, next to the counts they change ---------- */
.panel-head .fchips { margin-left: auto; align-self: center; }
.panel-head .fchips + .ph-count { margin-left: 0; }
.fchips { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.fchip {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; cursor: pointer;
  padding: 2px 6px 2px 9px; border-radius: 999px; font: 500 12px/1.4 var(--sans); color: var(--ink);
  border: 1px solid var(--border); background: var(--surface-2);
}
.fchip svg { width: 12px; height: 12px; stroke-width: 2.5; color: var(--muted); }
.fchip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
#d-filters:empty { display: none; }

/* One-time "Study" explainer */
.study-note { display: flex; align-items: center; gap: 8px; margin: -4px 0 12px; font-size: 13px; color: var(--muted); --c: var(--focus); }
.study-note .study-mark { margin: 0; }
.study-note .sn-close {
  margin-left: auto; flex: none; cursor: pointer; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); font: 500 12px var(--sans);
}

/* ---------- Panel extras ---------- */
.q-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  margin: 0 0 12px; padding: 8px 10px 8px 12px; border-radius: 8px;
  background: color-mix(in srgb, var(--c) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c) 30%, var(--border));
  font-size: 13px; color: var(--muted);
}
.q-bar strong { color: var(--ink); }
.q-bar .chip { color: var(--ink); }
/* Series page: the sermon you came from */
.sermon.is-here { border-color: var(--sc, var(--c)); box-shadow: inset 3px 0 0 var(--c); background: color-mix(in srgb, var(--c) 6%, var(--surface)); }
.here-mark {
  flex: none; margin-right: auto; align-self: center; font-size: 10.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
  line-height: 1; padding: 3px 6px; border-radius: 4px; color: var(--surface); background: var(--c);
}
.sermon .ref .pass:has(+ .here-mark) { margin-right: 0; }
#d-group .more-btn { margin-top: 12px; }
/* The card or tile whose page is open beside the list (wide screens) */
main .sermon.is-open { border-color: var(--c); background: color-mix(in srgb, var(--c) 7%, var(--surface)); box-shadow: inset 3px 0 0 var(--c); }
main .tile.is-open { outline: 2px solid var(--c); outline-offset: 1px; }

/* ---------- Drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgb(20 15 10 / .35); z-index: 40; animation: fade .15s ease; touch-action: none; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(520px, 100%); display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  animation: slide-in .2s ease;
}
.drawer-head {
  position: relative;
  display: flex; justify-content: space-between; gap: 16px; align-items: flex-start;
  padding: 22px 20px 16px; border-bottom: 1px solid var(--border);
  border-top: 4px solid var(--c);
}
.grabber { display: none; }
.drawer-head .eyebrow { color: var(--c); }
.drawer-head h2 { font-family: var(--serif); font-size: 30px; line-height: 1.15; margin: 2px 0 4px; }
.drawer-head .muted { font-size: 14px; }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.bp-pill {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; font-weight: 500; color: var(--c); text-decoration: none;
}
.bp-pill:hover { border-color: var(--c); }
.bp-pill:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.bp-pill svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bp-pill[hidden] { display: none; }
.read-row { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.read-row[hidden] { display: none; }
.chapter-read { display: flex; margin: -12px 0 20px; }
.read-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ver-pick { position: relative; display: inline-flex; align-items: center; vertical-align: middle; color: var(--muted); }
.ver-pick select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  font: 600 10px/1.4 var(--sans); letter-spacing: .04em; color: inherit;
  background: transparent; border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 15px 1px 5px; margin: 0;
}
.ver-pick select:hover { border-color: var(--c); color: var(--c); }
.ver-pick select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.ver-pick svg { position: absolute; right: 3px; width: 10px; height: 10px; pointer-events: none; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.ver-pick:hover svg { color: var(--c); }
.read-link {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 2px 9px; font-size: 12px; font-weight: 500; color: var(--c); text-decoration: none;
}
.read-link:hover { border-color: var(--c); }
.read-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.read-link svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.drawer-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; color: var(--muted);
}
.drawer:focus { outline: none; }
.icon-btn[hidden] { display: none; }
.drawer-titles { flex: 1; min-width: 0; }
.icon-btn.back { margin: 2px -6px 0 -4px; }
.drawer.is-sermon .drawer-head h2 { font-size: 24px; line-height: 1.2; }
.drawer.is-sermon .drawer-head .eyebrow { display: flex; align-items: center; gap: 6px; }

.listen-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.listen-btn {
  flex: 1 1 150px; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); text-decoration: none;
  transition: border-color .12s ease, background .12s ease;
}
.listen-btn .brand-ico, .listen-btn svg { width: 26px; height: 26px; }
.listen-btn .lb-text { display: flex; flex-direction: column; line-height: 1.2; color: var(--ink); font-weight: 600; font-size: 15px; min-width: 0; overflow-wrap: break-word; }
.listen-btn small { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.listen-btn.primary { border-color: color-mix(in srgb, currentColor 55%, var(--border)); background: color-mix(in srgb, currentColor 9%, var(--surface)); }
.listen-btn:active { background: var(--surface-2); }
.listen-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 14px; margin: 0 0 22px; font-size: 14px; align-items: baseline; }
.facts dt { font: 600 11.5px/1.6 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 0; min-width: 0; }
.facts .pass { display: flex; flex-wrap: wrap; gap: 4px; margin-left: -7px; font-size: 13px; font-weight: 600; }
.facts .pill { position: static; }
.s-block { margin: 0 0 22px; }
.notes p { margin: 0; font-size: 14.5px; line-height: 1.6; white-space: pre-line; }
.s-sub { margin: -4px 0 10px; font-size: 13.5px; color: var(--muted); }
.series-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); overflow: hidden; }
.series-list li + li { border-top: 1px solid var(--border); }
.s-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; color: inherit; text-decoration: none; }
a.s-row:active { background: var(--surface-2); }
a.s-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.s-row .n {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); font-variant-numeric: tabular-nums;
}
.s-row .t { flex: 1; min-width: 0; font-family: var(--serif); font-size: 15.5px; font-weight: 650; line-height: 1.3; }
.s-row small { display: block; margin-top: 2px; font: 400 12.5px/1.35 var(--sans); color: var(--muted); }
.s-row.current { background: color-mix(in srgb, var(--c) 11%, var(--surface)); box-shadow: inset 3px 0 0 var(--c); }
.s-row.current .n { background: var(--c); color: var(--surface); }
.s-row .here { flex: none; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--c); }
.drawer-body { overflow-y: auto; padding: 18px 20px 32px; flex: 1; overscroll-behavior: contain; }

.chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 4px; margin-bottom: 24px; }
.chapters button {
  height: 34px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  font-size: 13px; color: var(--faint); cursor: pointer; font-variant-numeric: tabular-nums;
}
.chapters button.has { color: var(--ink); font-weight: 600; border-color: color-mix(in srgb, var(--c) 45%, var(--border)); background: color-mix(in srgb, var(--c) 12%, var(--surface)); }
.chapters button[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: var(--surface); }
.chapters button.all { grid-column: span 2; color: var(--muted); }
.chapters button.all[aria-pressed="true"] { color: var(--surface); }
.chapters button:disabled { cursor: default; opacity: .55; }

.toast {
  position: absolute; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px;
}

/* ---------- Footer / errors ---------- */
.foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); font-size: 13px; color: var(--muted); }
.error { padding: 16px; border: 1px solid var(--major); border-radius: var(--radius); color: var(--major); background: var(--surface); }
.error code { font-size: 13px; }

/* ---------- Motion ---------- */
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }


/* ============================================================
   Wide screens: the panel is a pane beside the page, not a modal.
   The list stays visible and clickable; picking another sermon swaps the pane.
   (Breakpoint matches `wide` in app.js.)
   ============================================================ */
@media (min-width: 1100px) {
  :root { --pane-w: min(480px, 40vw); }
  .drawer { width: var(--pane-w); }
  body.panel-open { padding-right: var(--pane-w); }
  /* Narrower page: two wider cards per row keep passage pills readable */
  body.panel-open .sermons.cols { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
}

/* ============================================================
   Phones
   Goal: more on screen per scroll. Compact header, sticky search,
   4-up book tiles, 3-line sermon cards, chapter strip in the sheet.
   ============================================================ */
@media (max-width: 720px) {
  .sermon .hit { -webkit-line-clamp: 1; }
  body { font-size: 14px; }
  .long { display: none; }
  .short { display: inline; }
  .wrap { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }

  /* Header: one compact line instead of ~200px of hero */
  .masthead { padding: calc(14px + env(safe-area-inset-top)) 0 10px; }
  /* Title centered on the screen; eyebrow sits in the left gutter (equal 1fr columns keep the center true) */
  .brand { display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline; column-gap: 8px; }
  .brand .eyebrow { grid-column: 1; justify-self: start; white-space: nowrap; }
  .brand h1 { grid-column: 2; text-align: center; white-space: nowrap; }
  .brand .eyebrow { font-size: 11px; }
  .brand h1 { font-size: 22px; margin: 0; }
  .lede { display: none; }
  .search .clear { width: 32px; height: 32px; margin-right: -8px; }

  /* Sticky search: always reachable while scrolling the books */
  .toolbar { padding: 8px 0; background: var(--bg); }
  .search { border-radius: 10px; padding: 0 12px; gap: 8px; box-shadow: none; }
  .search input { padding: 10px 0; }
  .search kbd { display: none; }
  /* The "Open Romans" hint becomes the first result on phones, so the sticky bar stays one line */
  #q-hint { display: none; }
  .jump { margin-top: 8px; gap: 5px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
  .jump::-webkit-scrollbar { display: none; }
  .jump button { min-height: 30px; padding: 4px 10px; font-size: 12px; }

  /* Filters: testament + churches share one swipeable row */
  .filters-inner { flex-wrap: nowrap; gap: 8px; padding-top: 10px; overflow-x: auto; scrollbar-width: none; }
  .filters-inner::-webkit-scrollbar { display: none; }
  .chips { overflow: visible; flex: none; flex-wrap: nowrap; }
  .seg button { padding: 6px 11px; }
  .seg button, .chip { min-height: 32px; }
  .chip { padding: 5px 11px; }

  main { padding-top: 12px; padding-bottom: 24px; }
  html, body { overflow-x: clip; }
  .stats { font-size: 12px; margin-bottom: 12px; }

  /* Panels lose their box so cards get the full width */
  .panel { background: none; border: 0; padding: 0; margin-bottom: 20px; }
  .panel-head { margin-bottom: 8px; }
  .panel-head h2 { font-size: 17px; }
  /* Filter chips drop to their own line under the heading + count */
  .panel-head { flex-wrap: wrap; row-gap: 6px; }
  .panel-head .fchips { order: 3; flex: 1 1 100%; margin-left: 0; justify-content: flex-start; }

  /* Text search: the "In" row of books replaces the 66-tile grid */
  body.searching-text #library { display: none; }
  /* Go-to rows: one swipeable line so results still start near the top */
  .goto { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 78%;
    overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin: 0 -14px 12px; padding: 0 14px; scroll-padding: 0 14px; }
  .goto:has(> li:only-child) { grid-auto-columns: 100%; }
  .goto::-webkit-scrollbar { display: none; }
  .goto > li { scroll-snap-align: start; min-width: 0; }
  .inbooks { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px 10px; padding: 0 14px; }
  .inbooks::-webkit-scrollbar { display: none; }
  .inbooks .ib { flex: none; }

  /* Book grid: 4 across, ~half the height */
  .section { margin-bottom: 16px; }
  .section-head { margin-bottom: 6px; gap: 8px; }
  .section-head h2 { font-size: 16px; }
  .section-head h2::before { width: 8px; height: 8px; margin-right: 7px; }
  .section-head span { font-size: 12px; }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .tile { min-height: 0; padding: 6px 7px 9px; border-radius: 7px; }
  .tile .abbr { font-size: 15px; }
  .tile .name { font-size: 10.5px; margin-top: 1px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tile .meta { display: none; }
  .tile .count { top: 5px; right: 5px; min-width: 18px; height: 18px; padding: 0 5px; font-size: 10.5px; }
  .tile .bar { height: 3px; }

  /* Sermon cards: ref/date, title, one meta line */
  .sermons { gap: 6px; }
  .sermons.cols { grid-template-columns: 1fr; }
  .sermon { gap: 2px 6px; padding: 9px 6px 9px 12px; }
  .sermon .ico { width: 38px; height: 36px; }
  .sermon .ref { font-size: 11.5px; }
  .sermon .title { font-size: 15.5px; line-height: 1.25;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .sermon .meta { flex-wrap: nowrap; font-size: 12.5px; white-space: nowrap; overflow: hidden; }
  .sermon .meta > * { flex: none; }
  .sermon .meta { column-gap: 0; }
  .sermon .meta > * + *::before { content: "·"; margin: 0 5px; color: var(--faint); }
  .sermon .meta .series { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .group-label { margin: 12px 0 5px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }

  /* Recently added: swipe row, next card peeking */
  .sermons.scroller { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 84%;
    overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; scroll-padding: 0 14px; }
  .sermons.scroller::-webkit-scrollbar { display: none; }
  .sermons.scroller > li { scroll-snap-align: start; }

  /* Book sheet */
  .drawer {
    top: auto; left: 0; width: 100%; height: 92vh; height: 92dvh;
    border-left: 0; border-radius: 16px 16px 0 0; animation-name: slide-up;
  }
  .drawer-head { border-radius: 16px 16px 0 0; padding: 18px 14px 10px; border-top-width: 3px; align-items: center; touch-action: none; }
  .grabber { display: block; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--border); }
  .drawer-head .eyebrow { font-size: 10.5px; }
  .drawer-head h2 { font-size: 24px; margin: 1px 0 0; }
  .drawer-head .muted { font-size: 12.5px; }
  .icon-btn { width: 40px; height: 40px; border-radius: 10px; }
  .drawer-body { padding: 0 14px calc(24px + env(safe-area-inset-bottom)); }

  /* Chapters: sticky one-line strip of only the chapters that have sermons */
  #d-book > .label:first-child { display: none; }
  #d-sermon, #d-group { padding-top: 14px; }
  .drawer.is-sermon .drawer-head h2 { font-size: 20px; }
  .chapters {
    position: sticky; top: 0; z-index: 2;
    display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none;
    margin: 0 -14px 4px; padding: 10px 14px;
    background: var(--bg); border-bottom: 1px solid var(--border);
  }
  .chapters::-webkit-scrollbar { display: none; }
  .chapters button { flex: none; min-width: 38px; height: 34px; padding: 0 8px; }
  .chapters button:disabled { display: none; }
  .chapters button.all { padding: 0 14px; }
  #d-list-label { display: none; }
  .chapter-read { margin: 8px 0 10px; }
  .fit-bar { margin: 8px 0 4px; }
  .fit-bar .hint { display: none; }
  .chapters + .label + .sermons { padding-top: 6px; }
}

/* Very narrow phones: stack eyebrow over the centered title so they never collide */
@media (max-width: 359px) {
  .brand { grid-template-columns: 1fr; row-gap: 2px; justify-items: center; }
  .brand .eyebrow, .brand h1 { grid-column: 1; justify-self: center; }
}
