:root {
  --bone: #efe9dc;
  --bone-dim: rgba(239, 233, 220, 0.62);
  --bone-faint: rgba(239, 233, 220, 0.28);
  --ember: #f0a04b;
  --tuoni: #9fc3cf;
  --ink: #000;
  --serif: "Spectral", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Manrope", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --bar: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--bone);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

#gl {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  z-index: 0;
}

#scroller { height: 1400vh; }

/* intro */
#veil {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 55% at 50% 48%, rgba(4, 6, 10, 0.72) 0%, rgba(4, 6, 10, 0.5) 45%, rgba(4, 6, 10, 0.18) 100%);
  transition: opacity 1.6s ease;
}
#intro {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -54%);
  width: min(92vw, 40rem);
  text-align: center;
  z-index: 3;
  pointer-events: none;
  transition: opacity 1.6s ease;
  text-shadow: 0 2px 30px rgba(40, 14, 0, 0.45);
}
#intro h1 {
  margin: 0 0 1.4rem;
  font-family: var(--serif);
  font-weight: 200;
  font-style: italic;
  font-size: clamp(3.2rem, 11vw, 8.5rem);
  line-height: 0.92;
  letter-spacing: -0.02em;
}
#intro .lede {
  margin: 0 auto 0.6rem;
  max-width: 32rem;
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(1rem, 2vw, 1.2rem);
  line-height: 1.55;
  color: var(--bone);
}
#intro .lede.en {
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--bone-dim);
}
#intro.leaving, #veil.leaving { opacity: 0 !important; transition: opacity 0.35s ease !important; }
#intro.leaving #btn-start { pointer-events: none; }

#btn-start {
  pointer-events: auto;
  margin-top: 2.6rem;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--bone);
  background: rgba(239, 233, 220, 0.04);
  border: 1px solid rgba(239, 233, 220, 0.55);
  border-radius: 999px;
  padding: 0.95rem 2.6rem 0.95rem 2.92rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.35s ease, color 0.35s ease, border-color 0.35s ease, letter-spacing 0.35s ease;
}
#btn-start:hover { background: var(--bone); color: #0b0c10; border-color: var(--bone); letter-spacing: 0.36em; }
#btn-start:focus-visible { outline: 2px solid var(--bone); outline-offset: 4px; }
kbd {
  font-family: var(--sans);
  font-size: 0.72rem;
  padding: 0.1em 0.5em;
  border: 1px solid var(--bone-faint);
  border-radius: 3px;
}
@keyframes breathe { 50% { opacity: 0.35; } }

/* verses */
#verse {
  position: fixed;
  left: clamp(1.25rem, 6vw, 5.5rem);
  bottom: calc(var(--bar) + clamp(1.5rem, 6vh, 4rem) + 3.4rem);
  margin: 0;
  max-width: min(86vw, 34rem);
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 1px 24px rgba(0, 0, 0, 0.7);
}
#verse blockquote {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(1.35rem, 3vw, 2.15rem);
  line-height: 1.32;
  white-space: pre-line;
}
#verse figcaption {
  margin-top: 0.8rem;
  font-size: clamp(0.95rem, 1.5vw, 1.15rem);
  line-height: 1.6;
  color: var(--bone-dim);
  white-space: pre-line;
}

/* chapter rail — a real sequence, so numbered */
#rail {
  position: fixed;
  right: clamp(0.9rem, 2.6vw, 2.2rem);
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
}
#rail ol {
  list-style: none;
  margin: 0;
  padding: 0 0 0 14px;
  border-left: 1px solid var(--bone-faint);
  position: relative;
}
#rail li { margin: 0.95rem 0; }
#rail button {
  all: unset;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-family: var(--serif);
  font-size: 0.78rem;
  color: var(--bone-faint);
  transition: color 0.5s ease;
}
#rail button .n { width: 1.8em; text-align: right; font-style: italic; }
#rail button .t {
  font-family: var(--sans);
  font-size: 0.7rem;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
#rail:hover button .t, #rail button:focus-visible .t, #rail li.on button .t { opacity: 1; transform: none; }
#rail li.on button { color: var(--bone); }
#rail li.on.late button { color: var(--tuoni); }
#rail button:focus-visible { outline: 1px solid var(--bone-dim); outline-offset: 4px; }
#rail .mark {
  position: absolute;
  left: -2px;
  top: 0;
  width: 3px;
  height: 0;
  background: var(--ember);
  transition: background 1s ease;
}
#rail.late .mark { background: var(--tuoni); }

/* controls */
#controls {
  position: fixed;
  left: 50%;
  bottom: max(1.4rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  z-index: 4;
}
#controls button {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--bone);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--bone-faint);
  border-radius: 999px;
  padding: 0.5rem 1.05rem;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: border-color 0.3s ease, background 0.3s ease, color 0.3s ease;
}
#controls button:hover { border-color: var(--bone-dim); }
#controls button:focus-visible { outline: 2px solid var(--bone); outline-offset: 2px; }
#btn-play { width: 2.5rem; height: 2.5rem; padding: 0 !important; display: grid; place-items: center; }
#btn-play svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
#btn-play .play-i path { fill: currentColor; stroke: none; }
#btn-play .pause-i { display: none; }
#btn-play[aria-pressed="true"] .pause-i { display: block; }
#btn-play[aria-pressed="true"] .play-i { display: none; }
.seg { display: flex; padding: 3px; gap: 2px; border: 1px solid var(--bone-faint); border-radius: 999px; background: rgba(0, 0, 0, 0.28); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#controls .seg button { border: none; background: transparent; padding: 0.42rem 0.95rem; color: var(--bone-dim); backdrop-filter: none; -webkit-backdrop-filter: none; }
#controls .seg button[aria-pressed="true"] { background: rgba(239, 233, 220, 0.14); color: var(--bone); }
#controls .seg button:hover { color: var(--bone); }

#credit {
  position: fixed;
  right: clamp(1rem, 2.6vw, 2.2rem);
  bottom: max(1.35rem, env(safe-area-inset-bottom));
  z-index: 4;
  font-family: var(--sans);
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--bone-dim);
  text-decoration: none;
  transition: color 0.3s ease;
}
#credit:hover, #credit:focus-visible { color: var(--bone); }
#credit:focus-visible { outline: 1px solid var(--bone-dim); outline-offset: 4px; }

#hint-explore {
  position: fixed;
  left: 50%;
  bottom: 4.6rem;
  transform: translateX(-50%);
  margin: 0;
  z-index: 3;
  font-size: 0.74rem;
  color: var(--bone-dim);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
  white-space: nowrap;
}
body.explore #hint-explore { opacity: 1; }
#controls, #rail { transition: opacity 0.8s ease; }
body.intro #controls, body.intro #rail, body.intro #hint-explore { opacity: 0; pointer-events: none; }
body.explore #gl { cursor: grab; touch-action: none; }
body.explore #gl:active { cursor: grabbing; }

#controls select {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--bone);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--bone-faint);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  appearance: none;
  -webkit-appearance: none;
}
#controls select option { color: #111; }
#controls select:focus-visible { outline: 2px solid var(--bone); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#endscreen {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: #000;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2.2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 3.2s ease;
}
#endscreen.show { opacity: 1; pointer-events: auto; }
#endscreen .end-title-unused {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 200;
  font-size: clamp(2.2rem, 7vw, 5rem);
  color: var(--bone);
  opacity: 0;
  transition: opacity 2s ease 2.6s;
}
#endscreen button {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--bone);
  background: transparent;
  border: 1px solid var(--bone-dim);
  border-radius: 999px;
  padding: 0.95rem 2.6rem 0.95rem 2.92rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 1.6s ease 5.6s, border-color 0.3s ease, background 0.3s ease;
}
#endscreen button:hover { border-color: var(--bone); background: rgba(255, 255, 255, 0.06); }
#endscreen button:focus-visible { outline: 2px solid var(--bone); outline-offset: 3px; }
#endscreen .end-fi, #endscreen .end-en { margin: 0; text-align: center; opacity: 0; transform: translateY(6px); }
#endscreen .end-fi {
  font-family: var(--serif); font-style: italic; font-weight: 300;
  font-size: clamp(1.35rem, 3vw, 2.2rem); line-height: 1.4; color: var(--bone);
  transition: opacity 2.2s ease 2.2s, transform 2.2s ease 2.2s;
}
#endscreen .end-en {
  margin-top: -1.2rem;
  font-family: var(--sans); font-size: clamp(0.85rem, 1.3vw, 1rem); line-height: 1.7; color: var(--bone-dim);
  transition: opacity 2s ease 3.8s, transform 2s ease 3.8s;
}
#endscreen.show .end-fi, #endscreen.show .end-en { opacity: 1; transform: none; }
#endscreen.leaving .end-fi, #endscreen.leaving .end-en { opacity: 0; transition: opacity 0.35s ease 0s; }
#endscreen.show button { opacity: 1; }
#endscreen.leaving button { opacity: 0; transition: opacity 0.35s ease 0s; pointer-events: none; }
#endscreen:not(.show) { transition: opacity 1.6s ease; }
#controls select { max-width: 13rem; }

#topbar {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  right: clamp(1rem, 2.6vw, 2.2rem);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
#topbar button {
  width: 2.5rem; height: 2.5rem;
  display: grid; place-items: center;
  padding: 0;
  color: var(--bone);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--bone-faint);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: border-color 0.3s ease, background 0.3s ease;
}
#topbar button:hover { border-color: var(--bone-dim); background: rgba(0, 0, 0, 0.35); }
#topbar button:focus-visible { outline: 2px solid var(--bone); outline-offset: 2px; }
#topbar svg { width: 1.05rem; height: 1.05rem; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#btn-rec .dot { fill: #d8443a; stroke: none; }
#btn-rec .ring { stroke-width: 1.4; }
#btn-rec.on { border-color: rgba(216, 68, 58, 0.8); }
#btn-rec.on .dot { animation: recpulse 1.2s ease-in-out infinite; }
@keyframes recpulse { 50% { opacity: 0.35; } }
#rec-time { font-size: 0.74rem; letter-spacing: 0.08em; color: var(--bone); font-variant-numeric: tabular-nums; min-width: 2.6em; text-align: right; }
#btn-snd .off-i { display: none; }
#btn-snd.muted .off-i { display: block; }
#btn-snd.muted .on-i { display: none; }
#btn-snd[aria-expanded="true"] { border-color: var(--bone-dim); background: rgba(0, 0, 0, 0.4); }
#snd-panel {
  position: fixed;
  top: calc(max(1rem, env(safe-area-inset-top)) + 3.1rem);
  right: clamp(1rem, 2.6vw, 2.2rem);
  z-index: 7;
  width: min(18.5rem, calc(100vw - 2rem));
  padding: 1.1rem 1.2rem 1.2rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  color: var(--bone);
  background: rgba(10, 12, 16, 0.72);
  border: 1px solid var(--bone-faint);
  border-radius: 14px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  font-size: 0.78rem;
}
#snd-panel[hidden] { display: none; }
#snd-panel .row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; }
#snd-panel .row.col { flex-direction: column; align-items: stretch; gap: 0.5rem; }
#snd-panel .lbl { color: var(--bone-dim); letter-spacing: 0.02em; }
#snd-panel select, #snd-panel input[type=range] { width: 100%; min-width: 0; max-width: 100%; }
#snd-panel .switch { flex: 0 0 auto; }
#snd-panel select {
  font: inherit; color: var(--bone); background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bone-faint); border-radius: 8px; padding: 0.5rem 0.6rem; cursor: pointer;
}
#snd-panel select option { color: #111; }
#snd-panel input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; cursor: pointer; }
#snd-panel input[type=range]::-webkit-slider-runnable-track { height: 2px; background: var(--bone-faint); border-radius: 2px; }
#snd-panel input[type=range]::-moz-range-track { height: 2px; background: var(--bone-faint); border-radius: 2px; }
#snd-panel input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -6px; border-radius: 50%; background: var(--bone); border: none; }
#snd-panel input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--bone); border: none; }
#snd-panel :focus-visible { outline: 2px solid var(--bone); outline-offset: 2px; }
.switch { position: relative; width: 2.4rem; height: 1.35rem; padding: 0; border-radius: 999px; border: 1px solid var(--bone-faint); background: rgba(255, 255, 255, 0.06); cursor: pointer; transition: background 0.25s ease, border-color 0.25s ease; }
.switch span { position: absolute; top: 50%; left: 0.2rem; width: 0.95rem; height: 0.95rem; border-radius: 50%; background: var(--bone-dim); transform: translateY(-50%); transition: transform 0.25s ease, background 0.25s ease; }
.switch[aria-checked="true"] { background: rgba(240, 160, 75, 0.35); border-color: var(--ember); }
.switch[aria-checked="true"] span { transform: translate(1.02rem, -50%); background: var(--bone); }

#rec-time:empty { display: none; }
#btn-fs .shrink { display: none; }
#btn-fs.on .shrink { display: block; }
#btn-fs.on .expand { display: none; }

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #000;
  z-index: 10;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--bone-dim);
  transition: opacity 1.4s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
#loading.error { color: var(--bone); font-style: normal; font-family: var(--sans); font-size: 0.95rem; padding: 2rem; text-align: center; }

@media (max-width: 640px) {
  #rail { display: none; }
  #controls { bottom: 3rem; }
  #credit { left: 50%; right: auto; transform: translateX(-50%); bottom: 1rem; }
  #hint-explore { white-space: normal; width: 90vw; text-align: center; }
  #verse { bottom: 7rem; }
}

@media (prefers-reduced-motion: reduce) {
  #intro .hint { animation: none; }
}
