/* =========================================================
   ANTIPHON — Verses of New Covenant Strength
   A reading room in code. Editorial illuminated manuscript.
   ========================================================= */

:root {
  /* Parchment (default) — illuminated codex on a reading desk */
  --paper:        #efe4cb;
  --paper-deep:   #dcc89e;
  --paper-edge:   #b89856;
  --ink:          #20140c;
  --ink-faint:    #5a4326;
  --ink-soft:     #816038;
  --gold:         #a87a23;
  --gold-bright:  #c89a3a;
  --gold-leaf:    #d9b057;
  --crimson:      #8c1a17;
  --crimson-deep: #5b0f0d;
  --rule:         rgba(32, 20, 12, 0.18);
  --grain:        0.045;

  --serif-display: "Cinzel", "Trajan Pro", serif;
  --serif-body:    "Cormorant Garamond", "EB Garamond", "Adobe Garamond Pro", Georgia, serif;
  --serif-margin:  "EB Garamond", "Cormorant Garamond", Georgia, serif;
  --black-letter:  "UnifrakturCook", "UnifrakturMaguntia", "Cormorant Garamond", serif;

  --ease: cubic-bezier(.22, .61, .36, 1);
  --slow: 1400ms;
  --med:  720ms;
  --fast: 280ms;
}

[data-theme="vellum"] {
  /* Vellum-under-candlelight — night mode */
  --paper:        #1a140e;
  --paper-deep:   #0b0805;
  --paper-edge:   #050302;
  --ink:          #ecdfbf;
  --ink-faint:    #c1a778;
  --ink-soft:     #8f7a4b;
  --gold:         #d2a23a;
  --gold-bright:  #ecc35a;
  --gold-leaf:    #f1cf69;
  --crimson:      #c93030;
  --crimson-deep: #6e0f10;
  --rule:         rgba(236, 223, 191, 0.18);
  --grain:        0.07;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  font-family: var(--serif-body);
  color: var(--ink);
  background: var(--paper);
  font-size: 18px;
  line-height: 1.55;
  letter-spacing: 0.005em;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  cursor: default;
  /* parchment atmosphere: warm radial centre + cool darkened corners */
  background:
    radial-gradient(ellipse at 50% 38%,
       color-mix(in srgb, var(--paper) 100%, white 6%) 0%,
       var(--paper) 38%,
       color-mix(in srgb, var(--paper-deep) 70%, var(--paper) 30%) 78%,
       var(--paper-edge) 130%);
  background-attachment: fixed;
}

/* Grain overlay — fine paper noise. SVG turbulence inlined as a data URI. */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 200;
  opacity: var(--grain);
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='7' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0   0 0 0 0 0   0 0 0 0 0   0 0 0 0.7 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

[data-theme="vellum"] body::before { mix-blend-mode: screen; }

/* Foxing — those amber ageing spots on old paper */
body::after {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.5;
  background:
    radial-gradient(circle at 12% 18%, rgba(168, 122, 35, 0.10) 0 0.6%, transparent 1.2%),
    radial-gradient(circle at 88% 14%, rgba(168, 122, 35, 0.08) 0 0.5%, transparent 1%),
    radial-gradient(circle at 22% 88%, rgba(140, 26, 23, 0.06) 0 0.3%, transparent 0.8%),
    radial-gradient(circle at 78% 82%, rgba(168, 122, 35, 0.07) 0 0.4%, transparent 1%),
    radial-gradient(circle at 50% 8%,  rgba(168, 122, 35, 0.05) 0 0.3%, transparent 0.6%);
}

/* ============== HEADER / WORDMARK ============== */
.page {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: clamp(20px, 3.6vw, 48px) clamp(22px, 5vw, 80px);
  z-index: 2;
}

header.masthead {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 32px;
  padding-bottom: clamp(20px, 3vw, 36px);
  border-bottom: 1px solid var(--rule);
  position: relative;
}

header.masthead::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  bottom: -3px;
  height: 1px;
  background: var(--rule);
}

.brand {
  display: flex; flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.brand .mark {
  font-family: var(--serif-display);
  font-weight: 600;
  font-size: clamp(13px, 1.05vw, 15px);
  letter-spacing: 0.42em;
  color: var(--ink);
  text-transform: uppercase;
}

.brand .established {
  font-family: var(--serif-margin);
  font-style: italic;
  font-size: 11.5px;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}

.title-block {
  text-align: center;
  display: flex; flex-direction: column;
  align-items: center;
  gap: 10px;
}

.title-block .kicker {
  font-family: var(--serif-margin);
  font-size: 11.5px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.title-block h1 {
  font-family: var(--serif-display);
  font-weight: 700;
  font-size: clamp(22px, 2.2vw, 30px);
  letter-spacing: 0.22em;
  color: var(--crimson-deep);
  text-transform: uppercase;
  white-space: nowrap;
}

[data-theme="vellum"] .title-block h1 { color: var(--gold-leaf); }

.title-block .lede {
  font-family: var(--serif-body);
  font-style: italic;
  font-size: 14.5px;
  color: var(--ink-faint);
  max-width: 460px;
}

.meta {
  text-align: right;
  display: flex; flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  font-family: var(--serif-margin);
  font-size: 11.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.meta .folio-num {
  font-family: var(--serif-display);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0.28em;
}

.meta .date {
  font-style: italic;
  text-transform: none;
  letter-spacing: 0.04em;
  font-size: 12px;
}

/* ============== ORNAMENTAL DIVIDER ============== */
.fleuron {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--gold);
  margin: clamp(18px, 2vw, 28px) auto;
  width: min(540px, 70%);
  font-family: var(--serif-display);
  user-select: none;
}

.fleuron::before, .fleuron::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--gold) 30%, var(--gold) 70%, transparent);
}

.fleuron .glyph {
  font-size: 16px;
  letter-spacing: 0.4em;
  transform: translateY(-1px);
  color: var(--gold-bright);
}

/* ============== MAIN VERSE STAGE ============== */
main.scriptorium {
  position: relative;
  display: grid;
  place-items: center;
  padding: clamp(28px, 5vw, 80px) clamp(8px, 2vw, 32px);
  min-height: 62vh;
}

/* Decorative side bands — manuscript-style margin rule */
main.scriptorium::before,
main.scriptorium::after {
  content: "";
  position: absolute;
  top: 8%;
  bottom: 8%;
  width: 1px;
  background: linear-gradient(to bottom, transparent, var(--rule) 12%, var(--rule) 88%, transparent);
}
main.scriptorium::before { left: clamp(20px, 6vw, 90px); }
main.scriptorium::after  { right: clamp(20px, 6vw, 90px); }

.codex {
  width: min(820px, 100%);
  text-align: center;
  position: relative;
}

.verse-stage {
  position: relative;
  display: grid;
}

/* Verses are stacked; current is visible, others 0-opacity */
.verse {
  grid-area: 1 / 1;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity var(--slow) var(--ease),
              transform var(--slow) var(--ease);
  pointer-events: none;
  will-change: opacity, transform;
}

.verse.is-current {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.verse.is-exiting {
  opacity: 0;
  transform: translateY(-14px);
}

/* Marginalia / reference */
.verse .ascription {
  font-family: var(--serif-margin);
  font-variant: small-caps;
  letter-spacing: 0.18em;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: clamp(18px, 2.4vw, 28px);
  display: inline-flex; align-items: center; gap: 14px;
}

.verse .ascription::before,
.verse .ascription::after {
  content: "✦";
  font-family: var(--serif-display);
  font-size: 9px;
  color: var(--gold);
}

/* The verse body with illuminated drop cap */
.verse-text {
  font-family: var(--serif-body);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(22px, 2.85vw, 36px);
  line-height: 1.42;
  letter-spacing: 0.005em;
  color: var(--ink);
  text-wrap: balance;
  hanging-punctuation: first last;
  position: relative;
}

/* Drop cap — illuminated initial, painted in crimson with gold ornament */
.verse-text .initial {
  float: left;
  font-family: var(--black-letter);
  font-style: normal;
  font-weight: 700;
  font-size: clamp(72px, 8.5vw, 116px);
  line-height: 0.82;
  padding: 8px 14px 4px 0;
  color: var(--crimson);
  text-shadow:
    0 1px 0 rgba(255,255,255,0.25),
    1px 2px 0 rgba(30, 12, 6, 0.05);
  position: relative;
}

[data-theme="vellum"] .verse-text .initial {
  color: var(--crimson);
  text-shadow:
    0 0 18px rgba(201, 48, 48, 0.35),
    0 1px 0 rgba(0,0,0,0.5);
}

.verse-text .initial::after {
  /* gold leaf flourish behind initial */
  content: "";
  position: absolute;
  left: -8px; right: 22px;
  top: 8px; bottom: 14px;
  background:
    radial-gradient(ellipse at center,
      color-mix(in srgb, var(--gold-leaf) 55%, transparent) 0%,
      transparent 65%);
  z-index: -1;
  filter: blur(2px);
  opacity: 0.7;
}

.verse-text .opening-quote {
  font-family: var(--serif-display);
  color: var(--gold);
  font-size: 0.7em;
  vertical-align: 0.4em;
  margin-right: 0.05em;
}

.verse-note {
  margin-top: clamp(28px, 4vw, 46px);
  font-family: var(--serif-margin);
  font-style: italic;
  font-size: clamp(14px, 1.2vw, 16.5px);
  color: var(--ink-faint);
  max-width: 560px;
  margin-left: auto; margin-right: auto;
  line-height: 1.65;
  text-wrap: balance;
  position: relative;
  padding-top: 22px;
}

.verse-note::before {
  content: "—";
  position: absolute;
  left: 50%; top: 0;
  transform: translateX(-50%);
  color: var(--gold);
  font-family: var(--serif-display);
  font-size: 14px;
  letter-spacing: 0.6em;
}

/* ============== READING PROGRESS / DWELL BAR ============== */
.dwell {
  margin-top: clamp(34px, 4vw, 56px);
  height: 1px;
  width: min(420px, 70%);
  margin-inline: auto;
  background: var(--rule);
  position: relative;
  overflow: hidden;
}

.dwell::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, var(--gold-bright), var(--gold));
  transform-origin: left;
  transform: scaleX(0);
  animation: dwell var(--dwell-duration, 16s) linear forwards;
}

/* Pseudo-element animations don't restart cleanly when style is mutated on
   the parent in every browser; we toggle a class that nulls the animation,
   force a reflow, then remove the class to reliably re-trigger it. */
.dwell.is-resetting::before { animation: none; transform: scaleX(0); }
.dwell.is-paused::before    { animation-play-state: paused; }

@keyframes dwell {
  to { transform: scaleX(1); }
}

/* ============== CONTROL BAR (bottom) ============== */
footer.bench {
  padding-top: clamp(20px, 2.5vw, 36px);
  border-top: 1px solid var(--rule);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 32px;
  position: relative;
}

footer.bench::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 3px;
  height: 1px;
  background: var(--rule);
}

.col-left {
  display: flex; align-items: center; gap: 26px;
  font-family: var(--serif-margin);
  font-size: 12px; letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.col-right {
  display: flex; align-items: center; justify-content: flex-end; gap: 22px;
  font-family: var(--serif-margin);
  font-size: 12px; letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.controls {
  display: inline-flex; align-items: center; gap: 18px;
  padding: 14px 28px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(2px);
  box-shadow:
    0 1px 0 color-mix(in srgb, white 30%, transparent) inset,
    0 12px 30px -18px rgba(32, 20, 12, 0.5);
}

.ctrl {
  background: none;
  border: 0;
  cursor: pointer;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink);
  border-radius: 50%;
  transition: color var(--fast) var(--ease),
              background var(--fast) var(--ease),
              transform var(--fast) var(--ease);
  font-family: var(--serif-display);
}

.ctrl:hover { color: var(--crimson); transform: translateY(-1px); }
.ctrl:active { transform: translateY(0); }
.ctrl svg { width: 16px; height: 16px; fill: currentColor; }

.ctrl.play { width: 44px; height: 44px; border: 1px solid var(--gold); }
.ctrl.play svg { width: 14px; height: 14px; }
.ctrl.play:hover { background: color-mix(in srgb, var(--gold-leaf) 22%, transparent); color: var(--crimson-deep); }

.ctrl.is-on { color: var(--crimson); }

.button-link {
  background: none;
  border: 0;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  cursor: pointer;
  position: relative;
  padding-bottom: 3px;
  transition: color var(--fast) var(--ease);
}

.button-link::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: currentColor;
  opacity: 0.25;
  transition: opacity var(--fast) var(--ease);
}

.button-link:hover { color: var(--ink); }
.button-link:hover::after { opacity: 1; }

/* ============== INDEX DRAWER ============== */
.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(420px, 92vw);
  background: var(--paper);
  border-right: 1px solid var(--rule);
  box-shadow: 30px 0 60px -40px rgba(0,0,0,0.4);
  transform: translateX(-101%);
  transition: transform 520ms var(--ease);
  z-index: 30;
  overflow-y: auto;
  padding: 40px 36px 60px;
  display: flex; flex-direction: column;
  gap: 22px;
}

.drawer.is-open { transform: translateX(0); }

.drawer-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
}

.drawer-head h2 {
  font-family: var(--serif-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--ink);
}

.drawer-head .closer {
  font-family: var(--serif-margin);
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
  cursor: pointer;
  background: none; border: 0;
}
.drawer-head .closer:hover { color: var(--crimson); }

.drawer-list {
  list-style: none;
  display: flex; flex-direction: column;
  gap: 2px;
}

.drawer-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: baseline;
  gap: 14px;
  padding: 12px 4px;
  cursor: pointer;
  border-bottom: 1px dotted var(--rule);
  font-family: var(--serif-body);
  font-size: 16px;
  color: var(--ink);
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}

.drawer-item:hover { color: var(--crimson); background: color-mix(in srgb, var(--gold-leaf) 8%, transparent); }
.drawer-item.is-current { color: var(--crimson); }
.drawer-item.is-current .num { color: var(--crimson); }

.drawer-item .num {
  font-family: var(--serif-display);
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.12em;
}

.drawer-item .ref {
  font-variant: small-caps;
  letter-spacing: 0.1em;
}

.drawer-item .star {
  width: 16px; height: 16px;
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 1.2;
  transition: fill var(--fast) var(--ease);
}

.drawer-item.is-favourited .star {
  fill: var(--crimson);
  stroke: var(--crimson);
}

.drawer-foot {
  margin-top: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  display: flex; flex-direction: column; gap: 16px;
}

.drawer-row {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--serif-margin);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.seg {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
}

.seg button {
  background: none;
  border: 0;
  padding: 6px 12px;
  font-family: var(--serif-margin);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  cursor: pointer;
  border-right: 1px solid var(--rule);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.seg button:last-child { border-right: 0; }
.seg button.is-active {
  background: var(--ink);
  color: var(--paper);
}

/* Scrim behind drawer */
.scrim {
  position: fixed; inset: 0;
  background: rgba(10, 6, 2, 0.42);
  opacity: 0; pointer-events: none;
  transition: opacity 420ms var(--ease);
  z-index: 20;
  backdrop-filter: blur(1px);
}
.scrim.is-on { opacity: 1; pointer-events: auto; }

/* ============== ENTRY ANIMATIONS ============== */
@keyframes reveal-up {
  from { opacity: 0; transform: translateY(18px); filter: blur(2px); }
  to   { opacity: 1; transform: translateY(0);    filter: blur(0); }
}
@keyframes reveal-soft {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes draw-rule {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.intro > * { opacity: 0; animation: reveal-up 1100ms var(--ease) forwards; }
.intro > *:nth-child(1) { animation-delay: 80ms; }
.intro > *:nth-child(2) { animation-delay: 220ms; }
.intro > *:nth-child(3) { animation-delay: 360ms; }
.intro > *:nth-child(4) { animation-delay: 500ms; }

header.masthead { animation: reveal-soft 800ms var(--ease) both; }
footer.bench    { animation: reveal-soft 1100ms var(--ease) 280ms both; }
.fleuron        { animation: reveal-soft 1200ms var(--ease) 360ms both; }

/* ============== TOAST / RESPONSIVE ============== */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  font-family: var(--serif-margin);
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms var(--ease), transform 280ms var(--ease);
  z-index: 40;
  box-shadow: 0 16px 40px -22px rgba(0,0,0,0.6);
}
.toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px) {
  header.masthead {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 14px;
  }
  .brand, .meta { align-items: center; text-align: center; }
  .meta { flex-direction: row; gap: 14px; justify-content: center; }
  .title-block h1 { font-size: 18px; letter-spacing: 0.18em; white-space: normal; }
  .title-block .lede { font-size: 13px; }
  footer.bench { grid-template-columns: 1fr; gap: 16px; text-align: center; }
  .col-left, .col-right { justify-content: center; }
  main.scriptorium::before, main.scriptorium::after { display: none; }
  .controls { padding: 12px 18px; gap: 12px; }
  .verse-text { font-size: 22px; }
  .verse-text .initial { font-size: 64px; padding: 4px 10px 2px 0; }
  body { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .dwell::before { animation: none; transform: scaleX(0); }
}
