/* ============ Tokens ============ */
:root {
  --bg: #f7f3ec;
  --surface: #fffdf8;
  --surface-2: #f1ebe0;
  --text: #2a241d;
  --text-soft: #6b6155;
  --border: #e4dccd;
  --accent: #8a2b2b;          /* deep hymnal red */
  --accent-soft: #f3e3df;
  --gold: #a57a2c;
  --congregation: #f4ecdc;
  --congregation-edge: #d9b977;
  --all: #efe0de;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 8px 24px rgba(60, 40, 20, .06);
  --radius: 14px;
  --font-body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --reading-size: 1.125rem;
  --sidebar-w: 300px;
  --topbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140f;
    --surface: #211d17;
    --surface-2: #2a251d;
    --text: #ece5d8;
    --text-soft: #a99f90;
    --border: #3a3329;
    --accent: #e39a8c;
    --accent-soft: #3a2522;
    --gold: #d4b06a;
    --congregation: #2c261b;
    --congregation-edge: #9b7c3d;
    --all: #34221f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17140f;
  --surface: #211d17;
  --surface-2: #2a251d;
  --text: #ece5d8;
  --text-soft: #a99f90;
  --border: #3a3329;
  --accent: #e39a8c;
  --accent-soft: #3a2522;
  --gold: #d4b06a;
  --congregation: #2c261b;
  --congregation-edge: #9b7c3d;
  --all: #34221f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
mark { background: color-mix(in srgb, var(--gold) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ============ Top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--surface); font-size: 18px;
}
.brand-text { font-family: var(--font-body); font-weight: 700; font-size: 1.1rem; }
.brand-text small { font-family: var(--font-ui); font-weight: 500; font-size: .75rem; color: var(--text-soft); margin-left: 4px; text-transform: uppercase; letter-spacing: .08em; }
.search {
  flex: 1; max-width: 460px; margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 0 14px; height: 40px;
}
.search svg { color: var(--text-soft); flex: none; width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); font: inherit; font-size: .95rem; outline: none; }
.tools { display: flex; gap: 4px; }
.icon-btn {
  display: grid; place-items: center; min-width: 40px; height: 40px; padding: 0 8px;
  border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer;
  font-size: .85rem; font-weight: 600; color: var(--text-soft);
}
a.icon-btn { text-decoration: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.menu-btn { display: none; }
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: block; }
  :root:not([data-theme="light"]) .i-moon { display: none; }
}

/* ============ Layout ============ */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky; top: var(--topbar-h);
  width: var(--sidebar-w); flex: none;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 20px 12px 40px 16px;
  border-right: 1px solid var(--border);
}
main { flex: 1; min-width: 0; }
main:focus, main:focus-visible { outline: none; }
.view { max-width: 780px; margin: 0 auto; padding: 32px 24px 96px; }
.loading { color: var(--text-soft); }
.site-footer { padding: 0 24px 32px; color: var(--text-soft); font-size: .85rem; text-align: center; }
.site-footer a { color: inherit; }

/* ============ Sidebar nav ============ */
.nav-group { margin-bottom: 18px; }
.nav-group-title {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .72rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-soft); padding: 6px 10px;
}
.nav-group-title span { font-weight: 400; text-transform: none; letter-spacing: 0; }
.nav-link {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: .92rem;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link .pg { color: var(--text-soft); font-size: .75rem; font-variant-numeric: tabular-nums; }

/* ============ Home ============ */
.hero { margin-bottom: 28px; }
.eyebrow { font-size: .75rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; }
.hero h1, .page-head h1 {
  font-family: var(--font-body); font-weight: 700; font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.15; margin: 0 0 10px;
}
.hero p { color: var(--text-soft); max-width: 56ch; margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  text-decoration: none; color: var(--text);
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--congregation-edge); }
.card h2 { font-family: var(--font-body); font-size: 1.25rem; margin: 0; }
.card p { margin: 0; color: var(--text-soft); font-size: .88rem; }
.card .count { margin-top: auto; padding-top: 8px; font-size: .8rem; color: var(--accent); font-weight: 600; }

/* ============ Reading page ============ */
.page-head { margin-bottom: 26px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.page-head .subtitle { font-family: var(--font-body); font-style: italic; color: var(--text-soft); font-size: 1.1rem; margin: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 500;
  background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border);
}
.chip.ref { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0 0 18px; font-size: .8rem; color: var(--text-soft); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface); border: 1px solid var(--border); }
.legend i.c { background: var(--congregation); border-color: var(--congregation-edge); }
.legend i.a { background: var(--all); border-color: var(--accent); }

.dialogue { display: flex; flex-direction: column; gap: 4px; font-family: var(--font-body); font-size: var(--reading-size); }
.line {
  display: grid; grid-template-columns: 150px 1fr; gap: 16px;
  padding: 12px 16px; border-radius: 10px; border-left: 3px solid transparent;
  line-height: 1.65;
}
.line .who {
  font-family: var(--font-ui); font-size: .75rem; font-weight: 600; letter-spacing: .04em;
  color: var(--text-soft); padding-top: .3em;
}
.line .who small { display: block; font-weight: 400; letter-spacing: 0; opacity: .8; }
.line.zawpi { background: var(--congregation); border-left-color: var(--congregation-edge); font-weight: 600; }
.line.zawpi .who { color: var(--gold); }
.line.zydua { background: var(--all); border-left-color: var(--accent); font-weight: 600; }
.line.zydua .who { color: var(--accent); }
.line p { margin: 0; }

.prose { font-family: var(--font-body); font-size: var(--reading-size); line-height: 1.8; }
.prose p { margin: 0 0 1.1em; text-indent: 1.5em; }
.prose p.salutation { text-indent: 0; font-style: italic; }
.prose.verse p { text-indent: 0; margin: 0; }
.prose.verse { padding: 8px 0 8px 22px; border-left: 3px solid var(--congregation-edge); font-weight: 600; }
.prose.verse p:last-child { margin-top: 0; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 48px; }
.pager a {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text);
}
.pager a:hover { border-color: var(--congregation-edge); }
.pager a.next { text-align: right; grid-column: 2; }
.pager small { color: var(--text-soft); font-size: .75rem; }
.pager span { font-family: var(--font-body); font-weight: 600; }

/* ============ Writers index ============ */
.index-tools { position: sticky; top: var(--topbar-h); z-index: 5; background: var(--bg); padding: 10px 0 12px; margin-bottom: 8px; }
.filter {
  width: 100%; height: 44px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.letters { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.letters a, .letters span {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  font-size: .8rem; font-weight: 600; text-decoration: none;
}
.letters a { color: var(--accent); background: var(--surface); border: 1px solid var(--border); }
.letters a:hover { background: var(--accent-soft); }
.letters span { color: var(--border); }
.hymn-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; margin: 4px 0 16px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500;
}
.hymn-banner button { border: 0; background: transparent; color: inherit; cursor: pointer; text-decoration: underline; }
.letter-group { margin-bottom: 26px; }
.letter-group h2 {
  font-family: var(--font-body); font-size: 1.6rem; color: var(--accent);
  margin: 0 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.person {
  display: grid; grid-template-columns: minmax(0, 1.2fr) 110px minmax(0, 1.5fr); gap: 12px; align-items: start;
  padding: 10px 6px; border-bottom: 1px dashed var(--border);
}
.person .name { font-family: var(--font-body); font-weight: 600; }
.person .years { color: var(--text-soft); font-size: .85rem; font-variant-numeric: tabular-nums; padding-top: 2px; }
.hymns { display: flex; flex-wrap: wrap; gap: 4px; }
.hymn {
  min-width: 36px; padding: 2px 7px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  font-size: .78rem; font-variant-numeric: tabular-nums; color: var(--text);
}
.hymn:hover, .hymn.on { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.hymns .more { border: 0; background: none; color: var(--accent); font-size: .78rem; cursor: pointer; padding: 2px 4px; }
.empty { color: var(--text-soft); padding: 24px 0; }

/* ============ Hla Bie Pipazy (hymns by subject) ============ */
.topic-section { margin-bottom: 28px; }
.topic-section h2 {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  font-family: var(--font-body); font-size: 1.3rem; letter-spacing: .02em;
  margin: 0 0 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.topic-section h2 .badge {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: var(--accent); color: var(--surface); font-size: 1rem;
}
.topic-section h2 small {
  margin-left: auto; font-family: var(--font-ui); font-size: .78rem; font-weight: 500;
  color: var(--text-soft); letter-spacing: 0; font-variant-numeric: tabular-nums;
}
.topics { list-style: none; margin: 0; padding: 0; }
.topic {
  display: grid; grid-template-columns: 2.4em minmax(0, 1fr) auto; column-gap: 10px; row-gap: 6px;
  align-items: baseline; padding: 11px 10px; border-radius: 10px;
}
.topic + .topic { border-top: 1px dashed var(--border); }
.topic .num { color: var(--text-soft); font-size: .85rem; font-variant-numeric: tabular-nums; }
.topic .t { font-family: var(--font-body); font-size: 1.08rem; font-weight: 600; }
.topic .range {
  text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--accent); white-space: nowrap;
}
.topic .range small { display: block; font-weight: 400; font-size: .72rem; color: var(--text-soft); }
.topic .bar {
  grid-column: 2 / -1; position: relative; height: 4px; border-radius: 4px; background: var(--surface-2);
}
.topic .bar i { position: absolute; top: 0; bottom: 0; border-radius: 4px; background: var(--congregation-edge); }
.topic .bar b {
  position: absolute; top: -4px; width: 4px; height: 12px; margin-left: -2px; border-radius: 2px; background: var(--accent);
}
.topic.on { background: var(--accent-soft); border-top-color: transparent; }
.topic.on + .topic { border-top-color: transparent; }
.topic.on .bar i { background: var(--accent); opacity: .45; }

/* ============ Tables (abbreviations, terms) ============ */
.gloss { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); margin-bottom: 26px; }
.gloss th, .gloss td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.gloss tr:last-child td { border-bottom: 0; }
.gloss th { background: var(--surface-2); font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--text-soft); }
.gloss td:first-child { font-weight: 600; white-space: nowrap; width: 34%; }
.gloss td:first-child em { font-family: var(--font-body); }
.gloss td:last-child { font-family: var(--font-body); }
.section-title { font-family: var(--font-body); font-size: 1.3rem; margin: 8px 0 12px; }

/* ============ Search results ============ */
.result {
  display: block; padding: 14px 16px; margin-bottom: 10px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none;
}
.result:hover { border-color: var(--congregation-edge); }
.result .kind { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 600; }
.result h3 { font-family: var(--font-body); margin: 2px 0 4px; font-size: 1.1rem; }
.result p { margin: 0; color: var(--text-soft); font-family: var(--font-body); font-size: .95rem; }

/* ============ Misc ============ */
.to-top {
  position: fixed; right: 20px; bottom: 20px; z-index: 20;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow); cursor: pointer; display: grid; place-items: center;
}
.to-top[hidden] { display: none; }
.error { padding: 18px 20px; border-radius: 12px; background: var(--accent-soft); color: var(--text); }
.error code { background: var(--surface); padding: 1px 6px; border-radius: 4px; }
.fade-in { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============ Responsive ============ */
@media (max-width: 960px) {
  .menu-btn { display: grid; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); z-index: 40;
    background: var(--bg); box-shadow: var(--shadow);
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0, 0, 0, .35); z-index: 35; }
}
@media (max-width: 640px) {
  .topbar { gap: 6px; padding: 0 10px; }
  .brand-text, #fontDown { display: none; }
  .search { height: 38px; padding: 0 10px; }
  .view { padding: 22px 16px 80px; }
  .line { grid-template-columns: 1fr; gap: 2px; padding: 10px 12px; }
  .line .who small { display: inline; margin-left: 4px; }
  .person { grid-template-columns: 1fr auto; }
  .person .hymns { grid-column: 1 / -1; }
  .person .years { text-align: right; }
  .gloss td:first-child { white-space: normal; }
  .pager { grid-template-columns: 1fr; }
  .pager a.next { grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .fade-in { animation: none; }
  .card, .sidebar { transition: none; }
}
@media print {
  .topbar, .sidebar, .pager, .to-top, .legend { display: none !important; }
  .view { max-width: none; padding: 0; }
  body { background: #fff; color: #000; }
}
