/* ============================================================
   SPIRAL READER
   The reader's side of the universe. Everything on screen comes
   from data/reader.json. Nothing here names a world.
   ============================================================ */

@font-face { font-family: "Cinzel"; src: url("fonts/cinzel-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Cinzel"; src: url("fonts/cinzel-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Spectral"; src: url("fonts/spectral-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Spectral"; src: url("fonts/spectral-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --void-deep: #030208;
  --void: #0d0a16;
  --bone: #e6dfd0;
  --dusk: #958ea3;
  --ash: #5f5a6b;
  --moon: #b9a7e8;
  --veil: rgba(13, 10, 22, 0.72);

  --display: "Cinzel", "Trajan Pro", serif;
  --text: "Spectral", Georgia, serif;

  --gutter: clamp(16px, 4vw, 56px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--void-deep);
  color: var(--bone);
  font-family: var(--text);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--moon); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { color: var(--bone); }
:focus-visible { outline: 2px solid var(--moon); outline-offset: 4px; border-radius: 2px; }

.skip {
  position: absolute; left: var(--gutter); top: -60px; z-index: 50;
  background: var(--void); color: var(--bone); padding: 8px 14px;
}
.skip:focus { top: 12px; }

/* ------------------------------------------------------------
   THE JOURNEY
   ------------------------------------------------------------ */

.journey { overflow-x: hidden; }

#stage {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh;
  display: block; z-index: 0;
  background: radial-gradient(120% 90% at 50% 40%, var(--void) 0%, var(--void-deep) 70%);
}

/* Painted scenes and clips sit between the void and the words. Their edges
   dissolve so a painted chapter and an unpainted one feel like one journey. */
#scenes { position: fixed; inset: 0; z-index: 1; pointer-events: none; }
.scene {
  position: absolute; inset: 0; opacity: 0;
  -webkit-mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, #000 40%, transparent 92%);
          mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, #000 40%, transparent 92%);
}
.scene img, .scene video { width: 100%; height: 100%; object-fit: cover; display: block; }

#chapters { position: relative; z-index: 2; }

.chapter { position: relative; height: 180vh; }
.chapter.opening { height: 140vh; }
.chapter.finale { height: 160vh; }

.panel {
  position: sticky; top: 0;
  height: 100vh; height: 100dvh;
  display: flex; align-items: center;
  padding: 0 var(--gutter);
  opacity: 0;
  pointer-events: none;
}
.panel.on { pointer-events: auto; }
.panel .inner { max-width: 34rem; }

/* A soft shade behind the words of a painted chapter, so the text stays
   readable over a bright scene. It fades to nothing at its edges, and it
   sits behind the text, so it changes no layout. */
.chapter:not(.sealed):not(.opening):not(.finale) .panel .inner { position: relative; isolation: isolate; }
.chapter:not(.sealed):not(.opening):not(.finale) .panel .inner::before {
  content: ""; position: absolute; z-index: -1; pointer-events: none;
  inset: -3.5rem -4.5rem;
  background: radial-gradient(ellipse closest-side at center, rgba(3, 2, 8, 0.78) 0%, rgba(3, 2, 8, 0.6) 50%, rgba(3, 2, 8, 0) 100%);
}
.chapter[data-side="right"] .panel { justify-content: flex-end; padding-right: calc(var(--gutter) + 170px); }
.chapter[data-side="right"] .panel .inner { text-align: left; }

.world-name {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.6rem, 7.4vw, 6.6rem);
  line-height: 0.95;
  letter-spacing: 0.04em;
  margin: 0 0 0.45em;
  color: var(--bone);
  text-wrap: balance;
  text-shadow: 0 2px 24px rgba(3, 2, 8, 0.85);
}
.sealed .world-name { color: var(--ash); }

.world-line {
  font-size: clamp(1.08rem, 1.5vw, 1.32rem);
  line-height: 1.62;
  margin: 0 0 1.6rem;
  color: var(--bone);
  max-width: 32rem;
  text-shadow: 0 1px 18px rgba(3, 2, 8, 0.9);
}
.world-line.quoted { color: #cfc8d8; }
.sealed .world-line { color: var(--dusk); }

.read {
  display: inline-block;
  font-family: var(--text);
  font-size: 1.02rem;
  color: var(--void-deep);
  background: var(--bone);
  padding: 0.55em 1.25em;
  border-radius: 999px;
  text-decoration: none;
  transition: background 0.2s ease;
}
.read:hover { background: var(--moon); color: var(--void-deep); }

.opening .panel { justify-content: flex-start; }
.opening-line {
  font-size: clamp(1.3rem, 2.4vw, 2rem);
  line-height: 1.45;
  max-width: 26ch;
  margin: 0;
  color: var(--bone);
}
.cue {
  position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-size: 0.86rem; color: var(--dusk);
}
.cue::after {
  content: ""; width: 1px; height: 46px;
  background: linear-gradient(var(--dusk), transparent);
  animation: cue 2.6s ease-in-out infinite;
  transform-origin: top;
}
@keyframes cue { 0%, 100% { transform: scaleY(0.35); opacity: 0.4; } 50% { transform: scaleY(1); opacity: 1; } }

.finale .panel { align-items: flex-end; padding-bottom: 9vh; justify-content: center; }
.finale-text { color: var(--dusk); margin: 0; text-align: center; }

/* The map at the end. Positions come from the canvas each frame. */
#marks { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.mark {
  position: absolute; transform: translate(-50%, 0);
  font-family: var(--display); font-size: 0.95rem; letter-spacing: 0.06em;
  color: var(--bone); text-decoration: none; white-space: nowrap;
  padding: 6px 8px; opacity: 0;
}
.mark.sealed { color: var(--ash); }
.mark.on { pointer-events: auto; }
a.mark:hover { color: var(--moon); }

/* The way-finder down the right edge. World names, not numbers. */
.rail {
  position: fixed; right: var(--gutter); top: 50%; transform: translateY(-50%);
  z-index: 4; margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 4px; text-align: right;
}
.rail a {
  display: block; font-size: 0.84rem; color: var(--ash); text-decoration: none;
  padding: 3px 0; transition: color 0.25s ease;
}
.rail a:hover, .rail a.here { color: var(--bone); }
.rail a.here::before { content: ""; display: inline-block; width: 18px; height: 1px; background: var(--moon); vertical-align: middle; margin-right: 10px; }

.notice {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  padding: var(--gutter); color: var(--dusk); text-align: center;
}

@media (max-width: 760px) {
  .chapter .panel, .chapter[data-side="right"] .panel {
    align-items: flex-end; justify-content: flex-start;
    padding-bottom: 12vh;
  }
  .world-name { font-size: clamp(2.2rem, 11vw, 3.4rem); }
  .chapter:not(.sealed):not(.opening):not(.finale) .panel .inner::before { inset: -3rem -1rem; }
  .rail { display: none; }
  .opening .panel { align-items: center; }
  .chapter.finale .panel { justify-content: center; align-items: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  .cue::after { animation: none; }
  html { scroll-behavior: auto; }
}

/* ------------------------------------------------------------
   READING
   ------------------------------------------------------------ */

.reading {
  background: radial-gradient(140% 60% at 0% 0%, var(--void) 0%, var(--void-deep) 60%) fixed;
}
.reading .frame {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: clamp(24px, 5vw, 80px);
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}
.reading aside {
  position: sticky; top: 0; align-self: start;
  max-height: 100vh; overflow-y: auto;
  padding: 40px 0 40px;
  scrollbar-width: thin;
}
.back { display: inline-block; font-size: 0.9rem; color: var(--dusk); text-decoration: none; margin-bottom: 28px; }
.back:hover { color: var(--bone); }
.reading aside .world-name { font-size: clamp(2rem, 3vw, 2.6rem); margin-bottom: 1.2rem; }

.toc summary { display: none; }
.toc h2 { font-size: 0.95rem; font-weight: 600; color: var(--dusk); margin: 1.4rem 0 0.4rem; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li a {
  display: block; padding: 5px 0 5px 14px; font-size: 0.95rem; line-height: 1.35;
  color: var(--dusk); text-decoration: none; border-left: 1px solid rgba(149, 142, 163, 0.22);
}
.toc li a:hover { color: var(--bone); }
.toc li a[aria-current="page"] { color: var(--bone); border-left-color: var(--moon); }
.toc .subs a { padding-left: 28px; font-size: 0.86rem; }

.reading main { padding: 64px 0 120px; min-width: 0; }
.prose { max-width: 68ch; font-size: 1.12rem; line-height: 1.7; }
.prose > h1.section-title {
  font-family: var(--display); font-weight: 400; letter-spacing: 0.03em;
  font-size: clamp(1.8rem, 3.6vw, 2.8rem); line-height: 1.1; margin: 0 0 1.6rem;
}
.prose h2 { font-weight: 600; font-size: 1.36rem; line-height: 1.3; margin: 2.6rem 0 0.8rem; scroll-margin-top: 24px; }
.prose h3 { font-weight: 600; font-size: 1.14rem; margin: 2rem 0 0.6rem; scroll-margin-top: 24px; }
.prose h4 { font-weight: 600; font-size: 1rem; margin: 1.6rem 0 0.4rem; color: var(--dusk); }
.prose p { margin: 0 0 1.05em; }
.prose strong { font-weight: 600; color: #f1ebdf; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 1.1em; }
.prose li { margin-bottom: 0.35em; }
.prose hr { border: 0; height: 1px; background: rgba(149, 142, 163, 0.25); margin: 2.4rem 0; }
.prose blockquote {
  margin: 1.6rem 0; padding: 0.2rem 0 0.2rem 1.2rem;
  border-left: 2px solid var(--moon); color: #d6cfde;
}
.prose .table-wrap { overflow-x: auto; margin: 1.4rem 0 1.8rem; }
.prose table { border-collapse: collapse; width: 100%; font-size: 0.95rem; line-height: 1.45; }
.prose th { text-align: left; font-weight: 600; color: var(--dusk); padding: 8px 14px 8px 0; border-bottom: 1px solid rgba(149, 142, 163, 0.35); }
.prose td { padding: 8px 14px 8px 0; border-bottom: 1px solid rgba(149, 142, 163, 0.12); vertical-align: top; }
.prose img { max-width: 100%; height: auto; }

.turn {
  display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap;
  max-width: 68ch; margin-top: 4rem; padding-top: 1.6rem;
  border-top: 1px solid rgba(149, 142, 163, 0.2);
}
.turn a { text-decoration: none; color: var(--dusk); font-size: 0.98rem; max-width: 45%; }
.turn a span { display: block; color: var(--bone); font-size: 1.08rem; }
.turn a:hover span { color: var(--moon); }
.turn .next { margin-left: auto; text-align: right; }

@media (max-width: 860px) {
  .reading .frame { grid-template-columns: 1fr; gap: 0; }
  .reading aside { position: static; max-height: none; padding: 28px 0 0; }
  .toc { border-top: 1px solid rgba(149, 142, 163, 0.2); border-bottom: 1px solid rgba(149, 142, 163, 0.2); }
  .toc summary {
    display: block; cursor: pointer; padding: 12px 0; color: var(--dusk); list-style: none;
  }
  .toc summary::-webkit-details-marker { display: none; }
  .toc summary::after { content: " +"; }
  .toc[open] summary::after { content: " \2212"; }
  .reading main { padding-top: 36px; }
  .turn a { max-width: 100%; }
}
