:root {
  --paper: #f6f1e7;
  --paper-2: #ece2cd;
  --paper-3: #e2d5b9;
  --ink: #24211b;
  --ink-soft: #57503f;
  --rule: #d8c9a3;
  --gold: #93672a;
  --gold-strong: #7a5420;
  --rubric: #a3402c;
  --rubric-bg: #f4e2da;
  --choir-bg: #e2ebe1;
  --choir: #3c5a4a;
  --clergy: #7d7565;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Serif", serif;
  --sans: "Avenir Next", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  --font-scale: 1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17140f;
    --paper-2: #1f1b14;
    --paper-3: #29231a;
    --ink: #ece3d1;
    --ink-soft: #b8ab8e;
    --rule: #3a3323;
    --gold: #d1a24f;
    --gold-strong: #e2b768;
    --rubric: #e07456;
    --rubric-bg: #35211a;
    --choir-bg: #1f2b23;
    --choir: #8fbfa3;
    --clergy: #9b9077;
  }
}
:root[data-theme="dark"] {
  --paper: #17140f; --paper-2: #1f1b14; --paper-3: #29231a;
  --ink: #ece3d1; --ink-soft: #b8ab8e; --rule: #3a3323;
  --gold: #d1a24f; --gold-strong: #e2b768; --rubric: #e07456; --rubric-bg: #35211a;
  --choir-bg: #1f2b23; --choir: #8fbfa3; --clergy: #9b9077;
}
:root[data-theme="light"] {
  --paper: #f6f1e7; --paper-2: #ece2cd; --paper-3: #e2d5b9;
  --ink: #24211b; --ink-soft: #57503f; --rule: #d8c9a3;
  --gold: #93672a; --gold-strong: #7a5420; --rubric: #a3402c; --rubric-bg: #f4e2da;
  --choir-bg: #e2ebe1; --choir: #3c5a4a; --clergy: #7d7565;
}

* { box-sizing: border-box; }
html { font-size: calc(16px * var(--font-scale)); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.65;
}
a { color: var(--gold-strong); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1.2rem;
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); font-size: 1rem; }
.brand-sub { color: var(--ink-soft); font-weight: 400; }
.controls { display: flex; gap: 0.5rem; }
.ctrl-btn {
  font-family: var(--sans);
  font-size: 0.8rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  color: var(--ink);
  padding: 0.4rem 0.7rem;
  border-radius: 5px;
  cursor: pointer;
}
.ctrl-btn:hover { border-color: var(--gold); }
a.ctrl-btn { text-decoration: none; display: inline-block; }
.ctrl-btn[aria-pressed="true"] { background: var(--choir-bg); border-color: var(--choir); color: var(--choir); }
.ctrl-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.sticky-context {
  position: sticky; top: 52px; z-index: 15;
  background: var(--paper-3);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  color: var(--gold-strong);
  padding: 0.45rem 1.2rem;
  text-transform: uppercase;
  font-weight: 600;
}

.page { max-width: 42rem; margin: 0 auto; padding: 2rem 1.2rem 5rem; }

.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.daynav-title { font-size: 1.4rem; margin: 0; text-align: center; flex: 1; text-wrap: balance; }
.daynav-arrow {
  font-family: var(--sans); text-decoration: none; color: var(--ink);
  border: 1px solid var(--rule); border-radius: 5px; padding: 0.4rem 0.8rem;
}
.daynav-arrow:hover { border-color: var(--gold); color: var(--gold-strong); }

.service-list { display: flex; flex-direction: column; gap: 0.6rem; }
.service-card {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.9rem 1.1rem; background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: 6px; text-decoration: none; color: var(--ink); font-family: var(--sans);
}
.service-card:hover { border-color: var(--gold); }
.sc-name { font-weight: 600; }
.sc-go { color: var(--gold-strong); font-size: 0.85rem; }
.empty { color: var(--ink-soft); font-family: var(--sans); }

.service-card.featured {
  background: var(--paper-3); border: 1px solid var(--gold);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--gold) 35%, transparent);
  flex-direction: column; align-items: flex-start; gap: 0.25rem;
}
.service-card.featured:hover { border-color: var(--gold); background: var(--paper-2); }
.service-card.featured .sc-name { font-family: var(--serif); font-size: 1.05rem; color: var(--gold-strong); }
.service-card.featured .sc-go { color: var(--ink-soft); font-size: 0.78rem; }
.sc-badge {
  font-family: var(--sans); font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase;
  font-weight: 700; color: var(--paper); background: var(--gold); border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

.svc-head { border-bottom: 1px solid var(--rule); padding-bottom: 1rem; margin-bottom: 1.5rem; }
.back-link { font-family: var(--sans); font-size: 0.8rem; color: var(--ink-soft); text-decoration: none; }
.svc-title { font-size: 1.6rem; margin: 0.4rem 0 0.2rem; text-wrap: balance; }
.svc-mode { font-family: var(--sans); color: var(--gold-strong); font-size: 0.85rem; margin: 0; text-transform: uppercase; letter-spacing: 0.05em; }

.svc-rows { display: flex; flex-direction: column; gap: 0.15rem; }
.row { margin: 0; padding: 0.35rem 0; }
.row-heading {
  font-family: var(--sans); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; font-size: 0.78rem; color: var(--gold-strong);
  margin-top: 1.4rem; padding-top: 0.6rem; border-top: 1px dashed var(--rule);
}
.row-actor { font-family: var(--sans); font-weight: 700; font-size: 0.82rem; letter-spacing: 0.03em; margin-top: 0.6rem; }
.row-actor.is-clergy { color: var(--clergy); }
.row-actor.is-choir { color: var(--choir); }
.rubric-tag { font-weight: 400; font-style: italic; color: var(--rubric); font-size: 0.85em; }
.row-rubric { font-style: italic; color: var(--rubric); background: var(--rubric-bg); padding: 0.4rem 0.7rem; border-radius: 4px; font-size: 0.92rem; }
.row-dialog { padding-left: 0.9rem; border-left: 3px solid transparent; }
.row-dialog.is-choir { border-left-color: var(--choir); }
.row-dialog.is-clergy { border-left-color: var(--clergy); opacity: 0.85; }
/* white-space: pre-line honors the "* " phrase breaks the parser inserts. */
.dialog-text { margin: 0; font-size: 1.02rem; white-space: pre-line; }
/* Everything the choir doesn't say (deacon/priest/reader) reads as clergy —
   set it in italic. Choir body stays regular weight (its green left-border
   already marks it). */
.row-dialog.is-clergy .dialog-text { font-style: italic; }
.media-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.35rem; }
.media-link {
  font-family: var(--sans); font-size: 0.72rem; text-decoration: none;
  color: var(--gold-strong); border: 1px solid var(--rule); border-radius: 999px;
  padding: 0.15rem 0.6rem;
}
.media-link:hover { border-color: var(--gold); }

body.choir-only-mode .row[data-choir="false"] { display: none; }

.site-footer {
  max-width: 42rem; margin: 0 auto; padding: 1.5rem 1.2rem 3rem;
  font-family: var(--sans); font-size: 0.75rem; color: var(--ink-soft);
  border-top: 1px solid var(--rule);
}

.jump-form {
  display: flex; align-items: center; gap: 0.6rem; justify-content: center;
  font-family: var(--sans); font-size: 0.8rem; color: var(--ink-soft);
  margin-bottom: 1.4rem;
}
.jump-form input[type="date"] {
  font-family: var(--sans); font-size: 0.85rem; color: var(--ink);
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 5px;
  padding: 0.3rem 0.5rem;
}

.alt-details { margin-top: 1.3rem; font-family: var(--sans); }
.alt-details summary { cursor: pointer; color: var(--ink-soft); font-size: 0.85rem; margin-bottom: 0.7rem; }
.service-card.alt { opacity: 0.85; }

.print-btn { margin-top: 0.9rem; }

.service-divider {
  margin-top: 2.2rem !important;
  font-size: 0.95rem !important;
  border-top: 2px solid var(--gold) !important;
  color: var(--gold) !important;
}

.error-box {
  text-align: center; padding: 3rem 1rem; font-family: var(--sans);
}
.error-code { font-family: var(--sans); color: var(--ink-soft); letter-spacing: 0.1em; font-size: 0.85rem; }
.error-title { font-family: var(--serif); font-size: 1.6rem; margin: 0.5rem 0; }
.error-message { color: var(--ink-soft); max-width: 30rem; margin: 0 auto 1.5rem; }
.error-back { color: var(--gold-strong); text-decoration: none; font-size: 0.9rem; }

.part-select {
  font-family: var(--sans); font-size: 0.78rem; background: var(--paper);
  border: 1px solid var(--rule); color: var(--ink); border-radius: 5px;
  padding: 0.35rem 0.5rem;
}

.notation-inline {
  margin-top: 0.5rem; padding: 0.7rem 0.8rem; background: var(--paper);
  border: 1px solid var(--rule); border-radius: 6px; max-width: 32rem;
}
.notation-img { max-width: 100%; display: block; border-radius: 3px; background: #fff; min-height: 2.5rem; }
.notation-fallback-note { font-family: var(--sans); font-size: 0.75rem; color: var(--rubric); background: var(--rubric-bg); border-radius: 4px; padding: 0.4rem 0.6rem; margin: 0.5rem 0 0; }

.practice-tracks { display: flex; flex-direction: column; gap: 1rem; }
.practice-track {
  border: 1px solid var(--rule); border-radius: 6px; padding: 1rem 1.1rem;
  background: var(--paper-2); display: flex; flex-direction: column; gap: 0.6rem;
}
.practice-track-full { border-color: var(--gold); background: var(--paper-3); }
.pt-label { font-family: var(--sans); font-weight: 700; font-size: 0.92rem; }
.practice-track audio { width: 100%; }

@media print {
  .topbar, .sticky-context, .site-footer, .daynav, .jump-form, .print-btn, .back-link, .alt-details summary,
  .part-select { display: none !important; }
  body { background: #fff; color: #000; }
  .row-rubric { background: none; border: 1px solid #ccc; }
  .page { max-width: 100%; padding: 0; }

  /* Don't let a printed page cut a hymn line, its notation, or a service
     heading in half across a page break. */
  .row, .row-dialog, .notation-inline, .row-heading, .service-divider,
  .row-actor, .practice-track {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .notation-img { break-inside: avoid; page-break-inside: avoid; }
}
