/* ==========================================================================
   Place of Padel — Motion

   Lifted out of styles.css so the scroll layer has a file of its own: this is
   where chapters and their choreography will be built, and it was already the
   longest single concern in that file.

   Two things changed in the move, neither of them visible:

   1. The drift rates are tokens now, not numbers typed into keyframes. Every
      rate below is seeded with exactly the value it had before — 9%, -22%,
      ±3%, ±4.5% — so this refactor is provably a no-op. Retuning them is a
      later, deliberate decision, not a side effect of moving the file.
   2. --px is registered, so scroll progress can be interpolated as a number.
      Nothing reads it yet; it is the seam the chapter engine plugs into.

   Everything else — the .js gate, the named timelines and why they are named,
   the reduced-motion end states — is unchanged and documented in README.md
   under "Reveal and the `.js` gate" and "Parallax".
   ========================================================================== */

/* Scroll progress, 0 -> 1. Registered so it interpolates as a number rather
   than a string: an unregistered custom property cannot be animated smoothly,
   which is the whole point of it. A chapter drives this from a scroll timeline
   where the browser supports one, and from a single rAF loop where it doesn't.
   Both write the same property, so the CSS never has to know which backend it
   got — see css/chapters.css.

   It inherits, deliberately. A chapter computes progress once on itself and
   every layer inside reads the same number, so the browser resolves the
   timeline once per chapter rather than once per moving element. */
@property --px {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */
/* Gated on .js: with scripting off there is nothing to add .is-in, so these
   must not start hidden. */
.js .reveal {
  opacity: 0;
  transform: translateY(20px);
}
.reveal.is-in {
  opacity: 1;
  transform: none;
  transition: opacity var(--dur-slow) var(--ease-out),
              transform var(--dur-slow) var(--ease-out);
}

/* The crest ring draws itself as the section arrives. pathLength="1" normalises
   the circle to a length of 1, so the dashoffset rule needs no measurement. */
.js .crest__ring circle {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}
.crest.is-in .crest__ring circle {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1.2s var(--ease-out-quart);
}
/* The mark fades up once the ring is most of the way round. */
.js .crest__mark { opacity: 0; }
.crest.is-in .crest__mark {
  opacity: 0.92;
  transition: opacity var(--dur-slow) var(--ease-out) 480ms;
}

/* --------------------------------------------------------------------------
   The opening

   One shot, not eight fades. The footage is already drifting in when the
   curtain lifts, the veil clears off it, and the type walks up out of the
   bottom-left corner in the order it is meant to be read. The frame's corners
   arrive last, closing the composition once everything inside it has landed.

   The whole choreography is held while the curtain is up (see the
   .is-loading pause below), so nothing is spent behind it. Before that rule
   existed, a 900ms curtain over a 1.9s sequence meant half the entrance
   happened where nobody could see it.
   -------------------------------------------------------------------------- */

/* The push-in. `scale` rather than `transform`, so it composes with the
   scroll-driven parallax on the same element instead of fighting it for the
   one property. */
@keyframes heroPush { from { scale: 1.14; } to { scale: 1; } }

/* The veil clears while the push-in is still running: the hero fades up out
   of black rather than cutting to a finished frame. */
@keyframes veilOut { from { opacity: 1; } to { opacity: 0; } }

@keyframes lineRise {
  from { transform: translateY(112%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes settleIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
/* The lockup resolves rather than slides. It is the centrepiece and the first
   thing on screen, and a focus pull reads as a camera finding it — a mark that
   slides in from an offset reads as a slide transition instead. */
@keyframes logoIn {
  from { opacity: 0; transform: scale(0.94); filter: blur(12px); }
  to   { opacity: 1; transform: none; filter: blur(0); }
}
/* Tracked caps resolve the same way, at half the strength. */
@keyframes focusIn {
  from { opacity: 0; transform: translateY(8px); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: blur(0); }
}
/* The eyebrow's hairlines draw outward from the type between them. */
@keyframes ruleOut { from { transform: scaleX(0); } to { transform: scaleX(1); } }
/* Corners arrive one at a time, walking round the frame. */
@keyframes tick {
  from { opacity: 0; transform: scale(0.55); }
  to   { opacity: 1; transform: none; }
}

/* The curtain holds the whole sequence at its first frame. It is removed by
   js/preload.js at the same moment the curtain starts to fade, so the two
   cross rather than queue. Outside the media queries deliberately: if there is
   a curtain at all, there is motion to hold. */
.is-loading .hero,
.is-loading .hero *,
.is-loading .hero *::before,
.is-loading .hero *::after { animation-play-state: paused; }

/* The load choreography lives entirely under no-preference, so reduced motion
   simply never runs it and everything is visible from the first frame. */
@media (prefers-reduced-motion: no-preference) {
  .hero__veil { animation: veilOut 1.6s var(--ease-out) both; }

  /* The veil waits for something to reveal. js/preload.js adds .hero-lit when
     the poster has decoded, which on a warm cache is long before the curtain
     lifts — there, this rule never applies and nothing changes. On bad data the
     curtain hits its ceiling first, and without this the one dissolve the
     entrance has would be spent clearing off an empty frame, with the footage
     arriving afterwards as a pop behind a finished composition.

     Only the veil waits. The type, the frame and the waitlist still assemble on
     schedule, over the veil, so a slow connection costs the visitor a late
     background and nothing else.

     Gated on .js because with scripting off nothing would ever add the class,
     and a veil paused at full is a forest panel over the footage forever. */
  html.js:not(.hero-lit) .hero__veil { animation-play-state: paused; }
  .hero__video { animation: heroPush 3.4s var(--ease-out-quart) both; }

  /* The mark lands first and alone. Everything after it is arranged around
     something already on screen, which is the whole point of the composition.

     Only where there was no curtain, though. With one, this lockup has been on
     screen since before the first paint — it IS the curtain's mark, in this
     box — and re-introducing it would make the visitor watch the brand arrive
     twice. Curtained, it is already resolved and everything else assembles
     around it. */
  html:not(.curtained) .hero__logo { animation: logoIn 1.4s var(--ease-out-quart) 0.15s both; }

  .hero__eyebrow,
  .hero__tagline { animation: focusIn 1.1s var(--ease-out) both; }
  .hero__eyebrow::before,
  .hero__eyebrow::after { animation: ruleOut 0.9s var(--ease-out-quart) 0.78s both; }

  .hero__say,
  .rsvp,
  .hero__more { animation: settleIn 1s var(--ease-out) both; }
  .hero__corner { animation: tick 0.9s var(--ease-out) both; }
  .line__in    { animation: lineRise 1.25s var(--ease-out-quart) both; }

  .hero__eyebrow { animation-delay: 0.62s; }
  .hero__tagline { animation-delay: 0.78s; }
  .line:nth-child(1) .line__in { animation-delay: 0.98s; }
  .hero__say   { animation-delay: 1.18s; }
  .rsvp        { animation-delay: 1.38s; }
  .hero__more  { animation-delay: 1.62s; }

  .hero__corner--tl { animation-delay: 1.72s; }
  .hero__corner--tr { animation-delay: 1.83s; }
  .hero__corner--br { animation-delay: 1.94s; }
  .hero__corner--bl { animation-delay: 2.05s; }
}

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; }
  .hero__veil { opacity: 0; }
  .crest__ring circle { stroke-dashoffset: 0; }
  .crest__mark { opacity: 0.92; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* --------------------------------------------------------------------------
   Parallax

   Scroll-driven, via CSS scroll timelines: no scroll listener, no rAF loop,
   nothing on the main thread. Where the browser doesn't support them the page
   is simply still, which is a fine outcome rather than a broken one.

   Three moments only. The hero is the signature: the footage falls behind the
   scroll while the words outrun it, which is what reads as depth. The other two
   are quiet enough to be felt rather than watched.
   -------------------------------------------------------------------------- */

/* Named timelines are declared outside the support query so the names exist
   even where the animations don't. Both are needed because the elements that
   move sit inside containers that would otherwise resolve the wrong scrollport:
   the club's texture and the light band's court lines sit inside bands that
   would otherwise resolve the wrong scrollport. The carousel that needed a
   third name is gone, and its timeline went with it. */
.club   { view-timeline: --club block; }
.social { view-timeline: --social block; }

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {

    /* 1. The hero, ranged over the first viewport of scroll so the whole effect
       is spent by the time the hero has gone. The masthead is left alone: it
       already carries the load-in animation, and a second one would replace it. */
    .hero__body {
      animation: pop-outrun linear both;
      animation-timeline: scroll(root block);
      animation-range: 0 100svh;
      --depth: var(--depth-near);
    }

    /* Two animations, two timelines, one element. The push-in runs on the
       document timeline and drives `scale`; the fall runs on the scroll
       timeline and drives `transform`. Different properties, so neither
       overwrites the other, and the list keeps both animation-names alive
       where a second rule would have replaced the first. */
    .hero__video {
      animation-name: heroPush, pop-fall;
      animation-duration: 3.4s, auto;
      animation-timing-function: var(--ease-out-quart), linear;
      animation-fill-mode: both, both;
      animation-timeline: auto, scroll(root block);
      animation-range: normal, 0 100svh;
      --depth: var(--depth-far);
    }

    /* 2. The progress rule fills across the whole document. */
    .progress {
      animation: fill linear both;
      animation-timeline: scroll(root block);
    }

    /* 3. The club's string-dot texture drifts against the band as it passes. */
    .club__strings {
      animation: pop-sway linear both;
      --depth: var(--depth-hair);
      animation-timeline: --club;
      animation-range: cover 0% cover 100%;
    }

    /* 4. The light band's court lines drift the other way to the club's dots,
       so the two textures don't read as the same effect twice. */
    .social__court {
      animation: pop-sway linear both;
      --depth: calc(var(--depth-hair) * -1);
      animation-timeline: --social;
      animation-range: cover 0% cover 100%;
    }
  }
}

/* Background falls behind the scroll; foreground outruns it.

   Two shapes cover all five of the old keyframes: one that travels from rest to
   a rate, and one that travels symmetrically through rest. The rate itself is
   --depth, set per element from the scale in tokens.css, and its sign is the
   direction. So `drift` and `counterdrift` are no longer two keyframes that
   have to be kept in opposition by hand — they are one keyframe and a sign. */
@keyframes pop-fall  { to { transform: translateY(calc(var(--depth) * 100%)); } }
@keyframes pop-sway  {
  from { transform: translateY(calc(var(--depth) * -100%)); }
  to   { transform: translateY(calc(var(--depth) *  100%)); }
}
@keyframes pop-outrun {
  to { transform: translateY(calc(var(--depth) * 100%)); opacity: 0.3; }
}
@keyframes fill { to { transform: scaleX(1); } }
