:root {
  color-scheme: light dark;
  --bg: #f7f4ef;
  --surface: #fffefa;
  --ink: #2b2521;
  --muted: #716961;
  --line: #e6ddd1;
  --accent: #641f27;
  --accent-soft: #f4e8e5;
  --gold: #a77e38;
  --shadow: 0 16px 42px rgb(60 39 28 / 8%);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412;
    --surface: #211d1a;
    --ink: #f5eee5;
    --muted: #b7aaa0;
    --line: #403832;
    --accent: #e4a4a2;
    --accent-soft: #382625;
    --gold: #e1bd78;
    --shadow: 0 16px 42px rgb(0 0 0 / 24%);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--ink); line-height: 1.5; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.topbar {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(12px, env(safe-area-inset-top)) max(18px, calc((100vw - 760px) / 2)) 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand img { border-radius: 12px; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Georgia, serif; font-size: 17px; font-weight: 700; }
.brand small { color: var(--muted); font-size: 12px; }
.install-help { position: relative; }
.install-help summary { padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; color: var(--accent); cursor: pointer; font-size: 14px; font-weight: 700; list-style: none; }
.install-help summary::-webkit-details-marker { display: none; }
.install-help summary::after { content: "⌄"; margin-left: 8px; }
.install-panel { position: absolute; top: calc(100% + 10px); right: 0; width: min(320px, calc(100vw - 32px)); padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.install-panel p { margin: 9px 0 0; color: var(--muted); font-size: 13px; }
.install-button { width: 100%; padding: 10px 12px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 700; }

.page { width: min(100% - 32px, 760px); margin: 0 auto; padding: 44px 0 36px; }
.intro { margin: 0 0 25px; }
.eyebrow { margin: 0 0 8px; color: var(--gold); font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; letter-spacing: -.025em; }
h1 { max-width: 680px; margin-bottom: 13px; font-size: clamp(32px, 7vw, 48px); line-height: 1.1; }
.lead { max-width: 620px; margin-bottom: 0; color: var(--muted); font-size: 17px; }

.search-card { padding: clamp(18px, 4vw, 26px); border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.book-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 22px; padding: 5px; border-radius: 15px; background: var(--bg); }
.book-picker button { min-height: 42px; padding: 8px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; font-weight: 700; }
.book-picker button[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: 0 3px 10px rgb(75 27 31 / 18%); }
#search-form label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 750; }
.search-row { display: flex; gap: 9px; }
.search-row input { width: 100%; min-width: 0; height: 52px; padding: 0 15px; border: 1px solid var(--line); border-radius: 13px; background: var(--bg); color: var(--ink); font-size: 17px; }
.search-row input::placeholder { color: var(--muted); opacity: .8; }
.search-button { flex: 0 0 auto; min-width: 95px; padding: 0 18px; border: 0; border-radius: 13px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 750; }
.hint { margin: 9px 0 0; color: var(--muted); font-size: 12px; }
.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 19px; color: var(--muted); font-size: 12px; }
.examples button { padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--accent); cursor: pointer; font-size: 12px; font-weight: 700; }

.results-section { padding-top: 38px; }
.results-heading { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.results-heading .eyebrow { margin-bottom: 5px; }
h2 { margin-bottom: 0; font-size: clamp(22px, 5vw, 29px); }
.result-count { margin: 0 0 3px; color: var(--muted); font-size: 13px; text-align: right; }
.results { display: grid; gap: 12px; }
.empty-state { display: grid; justify-items: center; gap: 10px; padding: 32px 20px; border: 1px dashed var(--line); border-radius: 18px; color: var(--muted); text-align: center; }
.empty-state p { max-width: 400px; margin: 0; }
.empty-icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 25px; }
.error-state { padding: 16px; border: 1px solid #b75a4c; border-radius: 14px; background: var(--accent-soft); color: var(--ink); }
.reading-card { padding: 19px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.reading-card h3 { margin: 4px 0 8px; font-family: Georgia, "Times New Roman", serif; font-size: 21px; font-weight: 500; line-height: 1.25; }
.reading-source { margin: 0 0 9px; color: var(--muted); font-size: 14px; }
.reading-meta { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 13px; color: var(--muted); font-size: 12px; }
.reading-meta span { padding: 4px 8px; border-radius: 999px; background: var(--bg); }
.reference-list { display: flex; flex-wrap: wrap; gap: 6px; }
.ref-chip { padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 12px; }
.ref-chip.matched { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 16%, var(--surface)); color: var(--ink); font-weight: 800; }
.more-button { display: block; width: 100%; margin-top: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--accent); cursor: pointer; font-weight: 750; }

.source-note { margin-top: 32px; padding: 17px 18px; border-left: 3px solid var(--gold); border-radius: 0 12px 12px 0; background: var(--accent-soft); }
.source-note strong { display: block; margin-bottom: 5px; }
.source-note p { margin: 0 0 5px; color: var(--muted); font-size: 13px; }
.source-note .index-stats { margin-top: 9px; font-weight: 700; }
.footer { padding: 0 16px max(22px, env(safe-area-inset-bottom)); color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 480px) {
  .topbar { padding-right: 16px; padding-left: 16px; }
  .page { padding-top: 32px; }
  .search-row { flex-direction: column; }
  .search-button { min-height: 48px; }
  .results-heading { align-items: start; flex-direction: column; }
  .result-count { text-align: left; }
}
