:root {
  color-scheme: dark;
  --ink: #0b0b0d;
  --paper: #f2eee8;
  --muted: #aaa59f;
  --faint: rgba(242, 238, 232, 0.16);
  --accent: #e0876a;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--ink);
  scroll-behavior: smooth;
  scrollbar-color: var(--accent) var(--ink);
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 72% 45%, rgba(224, 135, 106, 0.045), transparent 32rem),
    var(--ink);
  color: var(--paper);
  font-family: "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: pan-y;
}

button,
a {
  font: inherit;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 5px;
}

.skip-link {
  position: fixed;
  top: 0;
  left: 1rem;
  z-index: 100;
  padding: 0.8rem 1rem;
  transform: translateY(-120%);
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: fixed;
  top: max(1.5rem, env(safe-area-inset-top));
  right: clamp(1.25rem, 4vw, 4.5rem);
  left: clamp(1.25rem, 4vw, 4.5rem);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.site-header p {
  margin: 0;
  color: var(--muted);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  pointer-events: auto;
  text-decoration: none;
}

.wordmark-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(224, 135, 106, 0.11);
}

.scene-shell,
.fallback {
  position: fixed;
  inset: 0;
  z-index: 0;
  margin: 0;
  pointer-events: none;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
}

.scene-vignette {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(11, 11, 13, 0.76) 0%, rgba(11, 11, 13, 0.07) 50%, rgba(11, 11, 13, 0.22) 100%),
    linear-gradient(180deg, rgba(11, 11, 13, 0.45), transparent 20%, transparent 75%, rgba(11, 11, 13, 0.55));
}

.fallback {
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 60% 40%, #1b1717, var(--ink) 55%);
}

.fallback[hidden] {
  display: none;
}

.fallback svg {
  width: min(72vw, 42rem);
  height: min(72vw, 42rem);
  overflow: visible;
}

.fallback-lines path {
  fill: none;
  stroke: rgba(242, 238, 232, 0.24);
  stroke-width: 2;
}

.fallback-nodes circle {
  fill: #181719;
  stroke: var(--accent);
  stroke-width: 4;
}

.fallback-signals circle {
  fill: var(--accent);
}

.fallback figcaption {
  position: absolute;
  right: 8vw;
  bottom: 8vh;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.story {
  position: relative;
  z-index: 5;
}

.chapter {
  position: relative;
  display: flex;
  min-height: 100vh;
  min-height: 100svh;
  align-items: center;
  padding: 7rem clamp(1.25rem, 8vw, 9rem);
}

.chapter-copy {
  width: min(35rem, 42vw);
  transform: translate3d(0, var(--copy-shift, 0), 0);
  opacity: var(--copy-opacity, 1);
  will-change: transform, opacity;
}

.chapter-index {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 0 0 1.35rem;
  color: var(--accent);
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.2em;
}

.chapter-index::after {
  width: 2.6rem;
  height: 1px;
  background: rgba(224, 135, 106, 0.55);
  content: "";
}

.chapter h1,
.chapter h2 {
  margin: 0;
  font-family: Didot, "Bodoni 72", "Times New Roman", serif;
  font-size: clamp(4.7rem, 10vw, 10.5rem);
  font-weight: 400;
  letter-spacing: -0.07em;
  line-height: 0.82;
}

.chapter-line {
  max-width: 29rem;
  margin: clamp(2rem, 4vh, 3.2rem) 0 0;
  font-size: clamp(1.05rem, 1.45vw, 1.36rem);
  font-weight: 450;
  letter-spacing: -0.018em;
  line-height: 1.45;
}

.chapter-note {
  margin: 0.8rem 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
}

.scroll-cue {
  position: absolute;
  bottom: max(2rem, env(safe-area-inset-bottom));
  left: clamp(1.25rem, 8vw, 9rem);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.scroll-cue span {
  position: relative;
  width: 1px;
  height: 2.7rem;
  overflow: hidden;
  background: var(--faint);
}

.scroll-cue span::after {
  position: absolute;
  inset: 0;
  transform: translateY(-100%);
  animation: cue 2.2s var(--ease) infinite;
  background: var(--accent);
  content: "";
}

@keyframes cue {
  55%, 100% { transform: translateY(100%); }
}

.end-mark {
  position: absolute;
  right: clamp(1.25rem, 5vw, 5rem);
  bottom: max(2rem, env(safe-area-inset-bottom));
  margin: 0;
  color: rgba(242, 238, 232, 0.42);
  font-size: 0.62rem;
  letter-spacing: 0.22em;
}

.chapter-nav {
  position: fixed;
  top: 50%;
  right: clamp(1.15rem, 2.8vw, 3rem);
  z-index: 30;
  display: flex;
  align-items: stretch;
  gap: 0.8rem;
  transform: translateY(-50%);
}

.chapter-nav ol {
  display: grid;
  gap: 0.85rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chapter-nav a {
  display: grid;
  width: 2rem;
  height: 1.35rem;
  place-items: center;
  color: rgba(242, 238, 232, 0.36);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-decoration: none;
  transition: color 250ms ease;
}

.chapter-nav a[aria-current="step"] {
  color: var(--paper);
}

.chapter-track {
  position: relative;
  width: 1px;
  background: var(--faint);
}

.chapter-track span {
  position: absolute;
  inset: 0;
  transform: scaleY(0);
  transform-origin: top;
  background: var(--accent);
}

.fps-panel,
.fps-show {
  position: fixed;
  z-index: 40;
  right: clamp(1.25rem, 4vw, 4.5rem);
  bottom: max(1.35rem, env(safe-area-inset-bottom));
  border: 1px solid rgba(242, 238, 232, 0.14);
  border-radius: 999px;
  background: rgba(15, 15, 17, 0.78);
  color: var(--muted);
  backdrop-filter: blur(12px);
  font-size: 0.61rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.fps-panel {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.48rem 0.55rem 0.48rem 0.7rem;
}

.fps-panel strong {
  min-width: 1.4rem;
  color: var(--paper);
  font-variant-numeric: tabular-nums;
}

.fps-light {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 50%;
  background: #8caf87;
}

.fps-panel button,
.fps-show {
  border: 0;
  color: var(--muted);
  cursor: pointer;
}

.fps-panel button {
  display: grid;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  place-items: center;
  border-radius: 50%;
  background: rgba(242, 238, 232, 0.08);
  font-size: 0.9rem;
  line-height: 1;
}

.fps-show {
  padding: 0.55rem 0.75rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

body.is-fallback .scene-shell,
body.is-fallback .fps-panel,
body.is-fallback .fps-show {
  display: none !important;
}

body.is-fallback .fallback {
  opacity: 0.68;
}

@media (max-width: 700px) {
  .site-header {
    top: max(1rem, env(safe-area-inset-top));
  }

  .site-header p,
  .chapter-nav {
    display: none;
  }

  .scene-vignette {
    background:
      linear-gradient(180deg, rgba(11, 11, 13, 0.35), transparent 34%, rgba(11, 11, 13, 0.16) 54%, rgba(11, 11, 13, 0.94) 78%),
      linear-gradient(90deg, rgba(11, 11, 13, 0.2), transparent 50%, rgba(11, 11, 13, 0.15));
  }

  .chapter {
    align-items: flex-end;
    padding: 7rem 1.25rem max(5.5rem, calc(3rem + env(safe-area-inset-bottom)));
  }

  .chapter-copy {
    width: 100%;
    padding: 1.35rem 1.25rem 1.25rem;
    border: 1px solid rgba(242, 238, 232, 0.11);
    background: rgba(11, 11, 13, 0.56);
    backdrop-filter: blur(14px);
  }

  .chapter-index {
    margin-bottom: 0.8rem;
  }

  .chapter h1,
  .chapter h2 {
    font-size: clamp(4.1rem, 23vw, 6.3rem);
  }

  .chapter-line {
    margin-top: 1.4rem;
    font-size: 1rem;
  }

  .chapter-note {
    font-size: 0.68rem;
  }

  .scroll-cue,
  .end-mark {
    display: none;
  }

  .fps-panel,
  .fps-show {
    right: 1.25rem;
    bottom: max(1.1rem, env(safe-area-inset-bottom));
  }

  .fps-panel {
    gap: 0.45rem;
  }

  #quality-value {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  .chapter-copy {
    transform: none !important;
    transition: opacity 120ms linear !important;
  }
}

@media (forced-colors: active) {
  .wordmark-dot,
  .fps-light,
  .chapter-track span {
    forced-color-adjust: none;
  }
}
