/* Prologue · The passage. A tall section with a sticky full-screen frame: scrolling through the
   540svh of height moves the 3D camera, while the frame itself never moves. The overlay text and
   bars read CSS variables that js/sections/passage.js writes from the walk's progress. */

.passage {
  position: relative;
  height: 540svh; /* the length of the walk: more height = a slower walk */
  z-index: 31;
  pointer-events: none;
}
.passage-frame {
  position: sticky;
  top: 0;
  height: 100svh;
  min-height: 360px;
  overflow: clip;
  pointer-events: auto;
  background: var(--surface-passage);
  --journey: 0; /* walk progress, 0 to 1 */
  --welcome: 1; /* the opening line */
  --whisper-out: 0; /* the mid-walk line: shown, then walked through */
  --ui: 1; /* top and bottom bars */
  --arrival: 0; /* the hero copy fading in */
  --scene: 1; /* the 3D canvas */
  --asset: 0; /* loading progress */
}
/* The page starts under the passage's last screen, so the walk ends exactly on the hero. */
main {
  margin-top: -100svh;
}
.passage-detached .passage-frame {
  position: fixed;
  inset: 0;
  z-index: 31;
}
.passage-detached .passage-frame .hero-frame {
  top: 0;
}
.passage-finished .passage-frame {
  visibility: hidden;
  pointer-events: none;
}

/* ---------- Layers, back to front ---------- */
.passage-fallback,
#forest-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.passage-fallback {
  z-index: 0;
}
.passage-fallback-gate {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  width: min(74vw, 1200px);
  height: auto;
  filter: brightness(0.8);
}
/* The still image and gate show until the 3D scene is ready, and again if WebGL fails. */
.passage-frame.ready :is(.passage-fallback, .passage-fallback-gate) {
  visibility: hidden;
}
.passage-fallback-mode :is(.passage-fallback, .passage-fallback-gate) {
  visibility: visible;
}
.passage-fallback-mode #forest-canvas {
  display: none;
}
#forest-canvas {
  z-index: 1;
  opacity: var(--scene);
}
.passage-shade {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: var(--ui);
  background:
    linear-gradient(180deg, #0a1a1499, transparent 150px),
    linear-gradient(0deg, #07171077, transparent 37%, transparent 77%, #102c2555),
    linear-gradient(90deg, #071d1744, transparent 43%);
}
/* A copy of the hero, faded in over the forest as the walk ends: the hand-over has no cut. */
.arrival-scene {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: var(--arrival);
  pointer-events: none;
}
.arrival-scene .hero-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100svh;
}
.arrival-scene :is(.hero-title, .hero-art, .hero-story, .sun) {
  transform: none !important;
  opacity: 1 !important;
}
.arrival-scene :is(.motion-letter, .motion-glyph) {
  transform: none !important;
}
.arrival-scene .chapter-incoming {
  display: none;
}
/* The copy shows the hero at rest, with the same grade as the real one, so the hand-over has no jump. */
.arrival-scene .hero-city {
  transform: none;
}
.arrival-scene .hero-title {
  perspective: none;
}
.arrival-scene :is(.hero-title, .hero-art, .hero-story) {
  will-change: auto;
}

/* ---------- Top bar: the same brand and bell as the page chrome, in the same place ---------- */
.passage-top {
  position: absolute;
  left: var(--pad);
  right: var(--pad);
  top: var(--chrome-top);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #f1ecdd;
  opacity: var(--ui);
  text-shadow: 0 1px 12px #0b1d1688;
}
.passage-actions {
  display: flex;
  gap: 18px;
  align-items: center;
}

/* ---------- Copy ---------- */
.passage-copy {
  position: absolute;
  left: var(--pad);
  bottom: 136px;
  z-index: 4;
  max-width: 560px;
  opacity: var(--welcome);
  color: #f4efe0;
  transform: translateY(calc((1 - var(--welcome)) * -18px));
  text-shadow: 0 2px 24px #07191088;
}
.passage-copy .chapter-mark {
  margin-bottom: 22px;
}
.passage-lede {
  margin-top: 18px;
  font-size: var(--text-body);
  color: #dde3d6;
}
/* The mid-walk line, in the middle of the path. Its words surface one by one out of a blur as you
   walk (js/sections/passage.js writes --w on each word), then the line grows and dissolves as you walk
   through it. The middle of the walk is the brightest part (the mist), so the words are ink, a deep
   forest green, like a brush line on rice paper, with a faint glow of mist around them. */
.passage-whisper {
  position: absolute;
  left: 50%;
  top: 44%;
  z-index: 4;
  width: max-content;
  max-width: calc(100% - 2 * var(--pad));
  text-align: center;
  color: #18291f;
  text-shadow:
    0 0 18px #e6efe9b3,
    0 0 3px #e6efe966;
  opacity: var(--whisper-out, 0);
  filter: blur(calc((1 - var(--whisper-out, 0)) * 6px));
  transform: translate(-50%, -50%) scale(var(--whisper-scale, 1));
}
.passage-whisper .motion-glyph {
  opacity: var(--w, 0);
  filter: blur(calc((1 - var(--w, 0)) * 10px));
  transform: translateY(calc((1 - var(--w, 0)) * 0.45em));
}

/* ---------- Bottom bar: the scroll cue and the walk's progress ---------- */
.passage-bottom {
  position: absolute;
  bottom: 34px;
  left: var(--pad);
  right: var(--pad);
  z-index: 5;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 40px;
  color: #f2edda;
  opacity: var(--ui);
  text-shadow: 0 1px 10px #0b1d16aa;
}
.passage-scroll {
  display: flex;
  align-items: center;
  gap: 16px;
}
/* A petal sliding down a thread: the scroll cue */
.petal-stem {
  position: relative;
  width: 1px;
  height: 40px;
  background: linear-gradient(#f2edda, transparent);
}
.petal-stem::after {
  content: "";
  position: absolute;
  left: -3px;
  top: 0;
  width: 7px;
  height: 7px;
  border-radius: 70% 0;
  background: #f4b7b0;
  animation: petal-fall 2.4s cubic-bezier(0.5, 0, 0.4, 1) infinite;
}
@keyframes petal-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translateY(36px) rotate(160deg);
    opacity: 0;
  }
}
/* The walk's progress: the same red sun as the chapter rail, travelling along a line */
.passage-track {
  display: grid;
  gap: 12px;
  justify-items: center;
  width: min(300px, 30vw);
}
.passage-progress {
  position: relative;
  width: 100%;
  height: 1px;
  background: #ece6d33d;
}
.passage-progress i {
  position: absolute;
  inset: 0;
  background: var(--shu);
  transform: scaleX(var(--journey));
  transform-origin: left;
}
.passage-progress::after {
  content: "";
  position: absolute;
  top: -4px;
  left: calc(var(--journey) * 100% - 4.5px);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--shu);
  box-shadow: 0 0 12px 2px #d9442f88;
}
.passage-look {
  color: #e6e1d0cc;
  opacity: var(--welcome);
}

/* ---------- Loading: no card, just the walk's own red sun crossing a line in the gate's opening ----------
   It sits on the bright mist, so it's written in the same ink as the mid-walk line. */
.passage-loading {
  position: absolute;
  left: 50%;
  top: 46%;
  z-index: 6;
  display: grid;
  justify-items: center;
  gap: 16px;
  width: 220px;
  color: #18291f;
  text-shadow:
    0 0 14px #e6efe9cc,
    0 0 3px #e6efe980;
  transform: translate(-50%, -50%);
  transition: opacity 0.8s;
}
.passage-loading.done {
  opacity: 0;
}
.passage-loading[hidden] {
  display: none;
}
#intro-meter {
  position: relative;
  width: 100%;
  height: 1px;
  background: #18291f40;
}
#intro-meter i {
  position: absolute;
  inset: 0;
  background: var(--shu);
  transform: scaleX(var(--asset));
  transform-origin: left;
  transition: transform 0.4s;
}
#intro-meter::after {
  content: "";
  position: absolute;
  top: -4px;
  left: calc(var(--asset) * 100% - 4.5px);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--shu);
  box-shadow: 0 0 12px 2px #d9442f88;
  transition: left 0.4s;
}

/* ---------- Smaller screens ---------- */
@media (max-width: 760px) {
  .passage {
    height: 390svh;
  }
  .passage-fallback-gate {
    width: 96vw;
  }
  .passage-actions {
    gap: 4px;
  }
  .passage-copy {
    bottom: 128px;
    right: var(--pad);
  }
  .passage-bottom {
    bottom: 28px;
    gap: 20px;
  }
  .passage-scroll span:last-child {
    max-width: 130px;
  }
  .passage-track {
    width: 120px;
  }
  .passage-look {
    display: none;
  }
  .passage-loading {
    top: 31%; /* the gate's opening is too narrow on phones: the open mist above the gate instead */
  }
}
@media (max-height: 560px) {
  .passage-copy {
    bottom: 96px;
  }
  .passage-lede,
  .passage-copy .chapter-mark {
    display: none;
  }
}

/* ---------- Reduced motion: a short passage, no whisper, no mouse look ---------- */
html.reduced .passage {
  height: 145svh;
}
html.reduced :is(.passage-copy, .passage-whisper) {
  transform: none;
}
html.reduced :is(.passage-whisper, .passage-look) {
  display: none;
}
@media (prefers-reduced-motion: reduce) {
  .passage {
    height: 145svh;
  }
}
@media (pointer: coarse), (prefers-reduced-motion: reduce) {
  .passage-look {
    display: none;
  }
  .passage-loading {
    top: 31%; /* the gate's opening is too narrow on phones: the open mist above the gate instead */
  }
}
