/* A manuscript leaf: vellum, iron-gall ink, rubrics in vermilion, a gilt wash for the verse in hand.
   Light only, whatever the system theme. */
:root {
  color-scheme: light;
  --paper: #f3ebdb;
  --panel: #f8f2e5;
  --ink: #2b2118;
  --muted: #6e5a44;
  --rule: #d6c6a6;
  --accent: #9a2b1b;
  --hl: rgba(190, 140, 50, 0.18);
  --hover: rgba(110, 75, 25, 0.05);
  --scrim: rgba(40, 25, 10, 0.32);
  --edge: rgba(150, 105, 40, 0.10);
  --gutter: rgba(90, 60, 20, 0.10);
  --display: "Fraunces", Georgia, serif;
  --text: "Literata", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --panel-w: 34rem;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  /* the leaf darkens toward its edges */
  background: radial-gradient(ellipse 120% 90% at 50% 40%, transparent 55%, var(--edge)) fixed, var(--paper);
  color: var(--ink);
  font-family: var(--text);
  font-size: 1.125rem;
  line-height: 1.65;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
}
.sc { font-variant-caps: small-caps; letter-spacing: 0.03em; }
::selection { background: var(--hl); }

.page {
  max-width: 38rem;
  margin: 0 auto;
  padding: 3.5rem 1rem 5rem;
  transition: transform 0.3s ease;
}

.site {
  font-family: var(--display);
  font-variation-settings: "SOFT" 100;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
}

.folio-head { margin: 3rem 0 3.5rem; }
h1 {
  font-family: var(--display);
  font-weight: 400;
  font-variation-settings: "opsz" 144, "SOFT" 50;
  font-size: clamp(2.8rem, 9vw, 4.25rem);
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
}
.subtitle {
  font-family: var(--display);
  font-style: italic;
  font-variation-settings: "opsz" 24;
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0;
}

/* Folio verses */
ol.verses { list-style: none; margin: 0; padding: 0; }
.verses li { position: relative; margin: 0 0 1.25rem; }
.verse {
  display: block;
  width: 100%;
  margin: 0 -0.85rem;
  width: calc(100% + 1.7rem);
  padding: 0.75rem 0.85rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: inset 2px 0 0 transparent;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.verses li:hover .verse { background: var(--hover); }
.verse:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.verses li.is-open .verse { background: var(--hl); box-shadow: inset 2px 0 0 var(--accent); }
.ref {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--display);
  font-weight: 600;
  font-variation-settings: "opsz" 14, "SOFT" 100;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.3rem;
}
/* Chapter / Related labels: sans-serif capitals, apart from the scripture */
.hint, .acts {
  font-family: var(--sans);
  font-weight: 500;
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.66rem;
}
.hint {
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.verse .text { display: block; }
/* Chapter · Related, at the end of the reference line */
.acts {
  position: absolute;
  top: 0.75rem;
  right: 0;
  display: flex;
  gap: 1rem;
  line-height: 1.35rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.verses li:hover .acts, .verses li:focus-within .acts, .verses li.is-open .acts { opacity: 1; }
.act {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  color: var(--muted);
  cursor: pointer;
}
.act:hover, .act.is-current { color: var(--accent); }
.act:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
/* No hover on touch screens, so the labels stay out */
@media (hover: none) {
  .hint { display: none; }
  .acts { opacity: 1; }
}

.section {
  font-family: var(--display);
  font-weight: 400;
  font-style: italic;
  font-variation-settings: "opsz" 36, "SOFT" 50;
  font-size: 1.3rem;
  color: var(--ink);
  margin: 3rem 0 1.25rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}
.folio-head + .section { margin-top: 0; padding-top: 0; border-top: 0; }

.divider {
  border: 0;
  text-align: center;
  margin: 3rem 0 2.5rem;
  color: var(--accent);
  font-family: var(--display);
}
.divider::before { content: "❧"; font-size: 1.4rem; }
.commentary p { margin: 0 0 1em; }
.commentary p:last-child { margin-bottom: 0; }

/* Index */
ol.index { list-style: none; margin: 0; padding: 0; }
.index li { border-top: 1px solid var(--rule); }
.index li:last-child { border-bottom: 1px solid var(--rule); }
.index a { display: block; padding: 1.25rem 0; color: inherit; text-decoration: none; }
.index .t {
  display: block;
  font-family: var(--display);
  font-variation-settings: "opsz" 48, "SOFT" 50;
  font-size: 1.6rem;
  line-height: 1.2;
}
.index .s { display: block; font-style: italic; color: var(--muted); font-size: 1rem; margin-top: 0.25rem; }
.index a:hover .t { color: var(--accent); }

.site-foot {
  margin-top: 4rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-size: 0.85rem;
  color: var(--muted);
}
.site-foot a { color: inherit; }

/* Context panel — bottom sheet on small screens */
.scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
  z-index: 10;
}
.panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 86vh;
  height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  transform: translateY(100%);
  visibility: hidden;
  transition: transform 0.3s ease, visibility 0.3s;
  z-index: 11;
}
.is-panel-open .scrim { opacity: 1; visibility: visible; }
.is-panel-open .panel { transform: none; visibility: visible; }
.is-panel-open { overflow: hidden; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.25rem 0.9rem;
  border-bottom: 1px solid var(--rule);
}
.panel-head h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-variation-settings: "opsz" 72, "SOFT" 50;
  font-size: 1.9rem;
  line-height: 1.1;
}
.panel-tr {
  margin: 0.2rem 0 0;
  font-family: var(--display);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--muted);
}
.panel-tr a { color: inherit; }
.panel-tr a:hover { color: var(--accent); }
.panel-close {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.8rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  cursor: pointer;
}
.panel-close:hover { color: var(--ink); background: var(--hover); }
.panel-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 1.25rem 2rem;
  outline: none;
}
ol.chapter { list-style: none; margin: 0; padding: 0; font-size: 1.02rem; line-height: 1.7; }
.chapter li {
  position: relative;
  padding: 0.2rem 0.6rem 0.2rem 2.2rem;
  margin: 0 -0.6rem;
  border-radius: 5px;
}
.chapter .n {
  position: absolute;
  left: 0.6rem;
  top: 0.48rem;
  font-family: var(--display);
  font-variation-settings: "opsz" 9;
  font-size: 0.72rem;
  color: var(--muted);
}
.chapter li.hl { background: var(--hl); }
.chapter li.hl .n { color: var(--accent); font-weight: 600; }
.chapter.is-loading, .related.is-loading { opacity: 0.4; }
.panel-msg { color: var(--muted); font-style: italic; }

.rel-h {
  margin: 0.25rem 0 0.5rem;
  font-family: var(--display);
  font-weight: 400;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--muted);
}
ol.rel { list-style: none; margin: 0 0 1.75rem; padding: 0; }
.rel-verse {
  display: block;
  width: calc(100% + 1.2rem);
  margin: 0 -0.6rem;
  padding: 0.55rem 0.6rem;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 1.02rem;
  line-height: 1.6;
  text-align: left;
  cursor: pointer;
}
.rel-verse:hover { background: var(--hover); }
.rel-verse .ref { font-size: 0.75rem; margin-bottom: 0.15rem; }
.rel-verse .text { display: block; }
.rel-verse:hover .hint, .rel-verse:focus-visible .hint { opacity: 1; }
.rel-note { margin: 0; font-size: 0.82rem; font-style: italic; color: var(--muted); }
.rel-note a { color: inherit; }
.panel[data-view="related"] .panel-nav { display: none; }

.panel-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem calc(0.7rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
}
.panel-nav button {
  border: 0;
  background: none;
  color: var(--accent);
  font-family: var(--display);
  font-size: 0.95rem;
  padding: 0.35rem 0.5rem;
  margin: 0 -0.5rem;
  border-radius: 6px;
  cursor: pointer;
}
.panel-nav button:hover { background: var(--hover); }
.panel-nav button[hidden] { display: block; visibility: hidden; }
.panel button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Wide screens — a side panel beside the folio, no scrim, page stays live */
@media (min-width: 1200px) {
  .scrim { display: none; }
  .panel {
    left: auto;
    top: 0;
    width: var(--panel-w);
    height: 100vh;
    border-radius: 0;
    border-left: 1px solid var(--rule);
    /* the facing leaf, shaded at the gutter */
    background: linear-gradient(to right, var(--gutter), transparent 2.5rem), var(--panel);
    box-shadow: -10px 0 40px rgba(60, 40, 15, 0.08);
    transform: translateX(100%);
  }
  .is-panel-open { overflow: auto; }
  .panel-head { padding: 1.75rem 1.75rem 1rem; }
  .panel-body { padding: 1.25rem 1.75rem 3rem; }
  .panel-nav { padding: 0.8rem 1.75rem; }
  /* slide the folio left just enough to clear the panel */
  .is-panel-open .page { transform: translateX(max(calc(var(--panel-w) / -2), calc((100vw - 40rem) / -2))); }
}

@media (max-width: 480px) {
  body { font-size: 1.0625rem; }
  .page { padding-top: 2rem; }
  .folio-head { margin: 2rem 0 2.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .page, .panel, .scrim, .verse, .hint, .acts { transition: none; }
}
