/* Motion: what the whole site shares. One idea runs through it: a seam of crystal light sweeps across a picture and
   the world behind it comes in relit (the home page's reel, the chapter stage, every picture marked data-sweep).
   Around it: pages that fade into each other, pictures that drift a little as you scroll, and a thin line under the
   top bar that fills as you read. All of it stays still under prefers-reduced-motion (site.css). */

:root {
  --ease-sweep: cubic-bezier(0.65, 0, 0.35, 1);
}

@keyframes sweep-in { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes relight { from { filter: brightness(1.45) saturate(1.2); } to { filter: none; } }

/* The seam: a bright line with its glow, and the warm light it leaves behind on the side it has passed. */
.reel-sweep, .sweep-seam { position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0; }
.reel-sweep::before, .sweep-seam::before {
  content: ""; position: absolute; top: -10%; bottom: -10%; left: -1px; width: 2px;
  background: linear-gradient(rgb(255 241 201 / 0), var(--crystal-light) 22%, #fff 50%, var(--crystal-light) 78%, rgb(255 241 201 / 0));
  box-shadow: 0 0 22px 6px rgb(255 241 201 / 0.7), 0 0 90px 28px rgb(243 199 106 / 0.32), 0 0 220px 70px rgb(227 154 196 / 0.16);
}
.reel-sweep::after, .sweep-seam::after {
  content: ""; position: absolute; top: 0; bottom: 0; right: 100%; width: 42%;
  background: linear-gradient(90deg, rgb(255 241 201 / 0), rgb(255 241 201 / 0.14));
  mix-blend-mode: screen;
}
.reel-sweep.is-on { animation: seam-pass 1.6s var(--ease-sweep) both; }
.roads-frame .reel-sweep.is-on { animation-duration: 1.25s; }
@keyframes seam-pass { 0% { opacity: 1; translate: 0 0; } 90% { opacity: 1; } 100% { opacity: 0; translate: 100% 0; } }

/* Pictures marked data-sweep come in behind the seam the first time they scroll into view: site.js adds the seam,
   which starts as a cover in the page's colour and slides off to the right, its bright edge uncovering the picture
   (a cover rather than a clip, since a clipped element never counts as on screen). Without script, or with reduced
   motion, the pictures are simply there. */
@media (prefers-reduced-motion: no-preference) {
  .js [data-sweep] > .sweep-seam { opacity: 1; background: var(--sweep-cover, var(--night)); }
  .js [data-sweep].is-in > .sweep-seam { animation: seam-uncover 1.3s var(--ease-sweep) var(--delay, 0ms) both; }
}
@keyframes seam-uncover { 0% { translate: 0 0; opacity: 1; } 90% { opacity: 1; } 100% { translate: 100% 0; opacity: 0; } }

/* Scroll drift: big pictures move a little slower than the page (where scroll-driven animation exists). The drift
   uses transform, so the hover zoom (scale) still adds on top. */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .feature-stack .feature-media img, .region-art img, .next-zone-art img, .join-art img, .zonein-short .zonein-img {
      animation: drift linear both; animation-timeline: view(); animation-range: cover;
    }
    .zonein:not(.zonein-short) { view-timeline: --zonein block; }
    .zonein:not(.zonein-short) .zonein-inner { animation: hero-lift linear both; animation-timeline: --zonein; animation-range: exit 0% exit 60%; }
  }
}
@keyframes drift { from { transform: translate3d(0, -5%, 0) scale(1.12); } to { transform: translate3d(0, 5%, 0) scale(1.12); } }

/* Reading progress: a thin crystal line under the top bar fills as the page scrolls. */
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .topbar::after {
      content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none;
      background: linear-gradient(90deg, rgb(227 154 196 / 0), var(--petal) 30%, var(--crystal));
      transform-origin: left; scale: 0 1;
      animation: read-progress linear both; animation-timeline: scroll(root);
    }
  }
}
@keyframes read-progress { to { scale: 1 1; } }

/* Moving between pages: the old page fades out, the new one fades up, and the top bar stays where it is. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}
.topbar { view-transition-name: topbar; }
::view-transition-old(root) { animation: vt-out 220ms ease both; }
::view-transition-new(root) { animation: vt-in 480ms var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; translate: 0 10px; } }
