/*
 * How it works page: one shot entrance motion for the pictures. Each picture
 * mounts once it is on screen (LazyVisual), so the animation plays where it
 * is seen, then holds the final state. Short steps, staggered, decelerating
 * (motion tokens, design-system.md 8): transform and opacity only (plus the
 * color of the strike line), no bounce or overshoot, distances scaled by --motion-scale.
 * Everything sits behind prefers-reduced-motion: with reduced motion the
 * final picture shows at once. Classes only add motion to the real
 * components inside, they never change layout. The keyframes use the
 * individual translate and scale properties, so they compose with any
 * transform the real components set themselves (marker centering, the
 * rhythm bars' -translate-x-1/2).
 *
 * Two shared values (owner decision 3 Nov 2026, design-system.md 8.2):
 * --hiw-stagger is the one per item stagger of every list like entrance
 * (rows, plan rows, step frames, rhythm bars, checkout rows, compare marks,
 * growth boards); scripted sequences (step 1 taps, step 3 marking, the
 * training build, the checkout route beats, the marker details) keep their
 * own timing. --hiw-rise is the fade up distance, the same 8px as the hero
 * picture (MOTION_RISE_PX in HowItWorksParts.js).
 */

:root {
  --hiw-stagger: 90ms;
  --hiw-rise: 8px;
}

@keyframes hiw-fade-up {
  from { opacity: 0; translate: 0 calc(var(--hiw-rise) * var(--motion-scale)); }
}

@keyframes hiw-fade {
  from { opacity: 0; }
}

@keyframes hiw-level-pop {
  35% { scale: calc(1 + 0.06 * var(--motion-scale)); }
}

@keyframes hiw-slide-in {
  from { opacity: 0; translate: calc(-8px * var(--motion-scale)) 0; }
}

/* A dart lands: comes in larger and settles, no overshoot. */
@keyframes hiw-land {
  from { opacity: 0; scale: calc(1 + 0.6 * var(--motion-scale)); }
}

/* Gain chip: fades up a little, like the Recap delta chips. */
@keyframes hiw-stamp {
  from { opacity: 0; translate: 0 calc(4px * var(--motion-scale)); }
}

/* The hit pattern ring appears: fades and scales from .75. */
@keyframes hiw-ring-in {
  from { opacity: 0; scale: calc(1 - 0.25 * var(--motion-scale)); }
}

/* A small mark appears: fades and scales from .6 (like the chip check). */
@keyframes hiw-pop {
  from { opacity: 0; scale: calc(1 - 0.4 * var(--motion-scale)); }
}

/* Scale marker: fades in with a short slide toward its own spot. */
@keyframes hiw-marker {
  from { opacity: 0; translate: calc(-12px * var(--motion-scale)) 0; }
}

/* Bars grow from the centre line to their own height. */
@keyframes hiw-bar {
  from { scale: 1 0; }
}

/* The strike line appears on the standard route. */
@keyframes hiw-strike {
  from { -webkit-text-decoration-color: transparent; text-decoration-color: transparent; }
}

@media (prefers-reduced-motion: no-preference) {
  /* Hold every entrance on its first frame until the picture is well on
     screen (useMotionStart in HowItWorksParts.js). */
  [data-hiw-motion='wait'] [class*='hiw-'],
  [data-hiw-motion='wait'] [class*='hiw-'] * {
    animation-play-state: paused !important;
  }

  /* The three step pictures: frames first, left to right (step 1, 2, 3),
     then the details in each (darts, markers, reason line). */
  .hiw-step {
    animation-name: hiw-fade-up;
    animation-timing-function: var(--ease-enter);
    animation-fill-mode: both;
    animation-duration: var(--dur-4);
  }
  [data-testid='how-it-works-step-frame-see'] { animation-delay: var(--hiw-stagger); --hiw-start: 800ms; }
  [data-testid='how-it-works-step-frame-train'] { animation-delay: calc(2 * var(--hiw-stagger)); }

  /* Step 1: each dart lands as the finger releases it. The darts mount one
     by one (THROW_TAP_SEQUENCE in StepVisuals.js), so the landing plays on
     mount; r 4 picks the couch board's dart markers. */
  .hiw-darts svg > circle[r='4'] {
    transform-box: fill-box;
    transform-origin: center;
    animation-name: hiw-land;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 450ms;
  }

  /* Rows of a "Your throw" list. Structure first, details later: the rows
     (label, scale track) are there almost at once, then each marker slides
     to its spot and its value follows. --hiw-start offsets the details. */
  :is(.hiw-rows, .hiw-throw:not([data-hiw-story='still']) [data-testid='weak-spots-rows']) > * { --hiw-i: 0; }
  :is(.hiw-rows, .hiw-throw:not([data-hiw-story='still']) [data-testid='weak-spots-rows']) > :nth-child(2) { --hiw-i: 1; }
  :is(.hiw-rows, .hiw-throw:not([data-hiw-story='still']) [data-testid='weak-spots-rows']) > :nth-child(3) { --hiw-i: 2; }
  :is(.hiw-rows, .hiw-throw:not([data-hiw-story='still']) [data-testid='weak-spots-rows']) > :nth-child(4) { --hiw-i: 3; }
  :is(.hiw-rows, .hiw-throw:not([data-hiw-story='still']) [data-testid='weak-spots-rows']) > :nth-child(5) { --hiw-i: 4; }
  :is(.hiw-rows, .hiw-throw:not([data-hiw-story='still']) [data-testid='weak-spots-rows']) > :nth-child(6) { --hiw-i: 5; }
  :is(.hiw-rows, .hiw-throw:not([data-hiw-story='still']) [data-testid='weak-spots-rows']) > * {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 250ms;
    animation-delay: calc(var(--hiw-i) * var(--hiw-stagger));
  }
  :is(.hiw-rows, .hiw-throw:not([data-hiw-story='still']) [data-testid='weak-spots-rows']) [data-testid$='-scale-dot'] {
    animation-name: hiw-marker;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 700ms;
    animation-delay: calc(var(--hiw-start, 350ms) + var(--hiw-i) * 300ms);
  }
  :is(.hiw-rows, .hiw-throw:not([data-hiw-story='still']) [data-testid='weak-spots-rows']) .justify-between > span:last-child {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 350ms;
    animation-delay: calc(var(--hiw-start, 350ms) + var(--hiw-i) * 300ms + 500ms);
  }

  .hiw-throw { --hiw-start: 900ms; }

  /* Hit pattern pictures (ThrowVisual: home hero, the ad page throw
     picture, the Premium page steps). Board and aim cross are there from
     the start; the ring fades and scales in (the hit pattern overlay
     entrance vocabulary, 8.2), then the mean pops and its offset arrow
     fades, done by about 0.7 s. Replaces the old ellipse trace, whose
     selectors stopped matching when the overlay marks moved into groups
     (hit pattern redesign). The ring sits in its own <g>, so the scale never
     touches the ellipse's rotate transform. */
  .hiw-throw:not([data-hiw-story='still']) [data-overlay-group='today-ring'] {
    transform-box: fill-box;
    transform-origin: center;
    animation-name: hiw-ring-in;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 450ms;
    animation-delay: 200ms;
  }
  .hiw-throw:not([data-hiw-story='still']) [data-testid='hit-pattern-mean'] {
    transform-box: fill-box;
    transform-origin: center;
    animation-name: hiw-pop;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 300ms;
    animation-delay: 400ms;
  }
  .hiw-throw:not([data-hiw-story='still']) [data-testid='displacement-line'] {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 300ms;
    animation-delay: 400ms;
  }

  /* Home hero plan card (ThrowVisual heroStory): its header and two rows
     enter like the Throw Analysis rows above (fade, 250ms, --hiw-stagger),
     at the same time, nothing chained. Cards and step numbers are there
     from the start. data-hiw-story="still" (reduced motion, prerender)
     gets none of it. */
  .hiw-story:not([data-hiw-story='still']) [data-testid='how-it-works-throw-train-card'] > * {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 250ms;
  }
  .hiw-story:not([data-hiw-story='still']) [data-testid='how-it-works-throw-train-card'] > :nth-child(2) { animation-delay: var(--hiw-stagger); }
  .hiw-story:not([data-hiw-story='still']) [data-testid='how-it-works-throw-train-card'] > :nth-child(3) { animation-delay: calc(2 * var(--hiw-stagger)); }

  /* Step 3: the card is there almost at once, then its reason line. */
  .hiw-card > * {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 250ms;
  }
  .hiw-card [data-testid='exercise-selection-card-reason'] {
    animation-name: hiw-slide-in;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 450ms;
    animation-delay: 1100ms;
  }

  /* Rhythm: bars grow left to right, value labels follow, then the pace
     zone and the tip. */
  .hiw-rhythm [data-testid^='rhythm-routine-chart-bar-'] {
    transform-origin: top center;
    animation-name: hiw-bar;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 400ms;
    animation-delay: calc(200ms + var(--hiw-i, 0) * var(--hiw-stagger));
  }
  .hiw-rhythm [data-testid^='rhythm-routine-chart-pct-'] {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 300ms;
    animation-delay: calc(450ms + var(--hiw-i, 0) * var(--hiw-stagger));
  }
  /* Slower visits sit above the centre line (bottom: 50%) and grow up. */
  .hiw-rhythm [data-testid^='rhythm-routine-chart-bar-'][style*='bottom'] {
    transform-origin: bottom center;
  }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-0'], [data-testid='rhythm-routine-chart-pct-0']) { --hiw-i: 0; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-1'], [data-testid='rhythm-routine-chart-pct-1']) { --hiw-i: 1; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-2'], [data-testid='rhythm-routine-chart-pct-2']) { --hiw-i: 2; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-3'], [data-testid='rhythm-routine-chart-pct-3']) { --hiw-i: 3; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-4'], [data-testid='rhythm-routine-chart-pct-4']) { --hiw-i: 4; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-5'], [data-testid='rhythm-routine-chart-pct-5']) { --hiw-i: 5; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-6'], [data-testid='rhythm-routine-chart-pct-6']) { --hiw-i: 6; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-7'], [data-testid='rhythm-routine-chart-pct-7']) { --hiw-i: 7; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-8'], [data-testid='rhythm-routine-chart-pct-8']) { --hiw-i: 8; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-9'], [data-testid='rhythm-routine-chart-pct-9']) { --hiw-i: 9; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-10'], [data-testid='rhythm-routine-chart-pct-10']) { --hiw-i: 10; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-11'], [data-testid='rhythm-routine-chart-pct-11']) { --hiw-i: 11; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-12'], [data-testid='rhythm-routine-chart-pct-12']) { --hiw-i: 12; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-13'], [data-testid='rhythm-routine-chart-pct-13']) { --hiw-i: 13; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-14'], [data-testid='rhythm-routine-chart-pct-14']) { --hiw-i: 14; }
  .hiw-rhythm :is([data-testid='rhythm-routine-chart-bar-15'], [data-testid='rhythm-routine-chart-pct-15']) { --hiw-i: 15; }
  .hiw-rhythm [data-testid='rhythm-routine-chart-zone'] {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 500ms;
    animation-delay: 1400ms;
  }
  .hiw-rhythm [data-testid='rhythm-routine-tip'] {
    animation-name: hiw-fade-up;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 400ms;
    animation-delay: 1700ms;
  }

  /* Checkouts: all rows are there almost at once (--hiw-ri, the list
     stagger), then row by row the standard route gets struck, your route
     slides in, the gain stamps in (--hiw-row: a scripted story beat every
     450ms, not a list stagger). */
  .hiw-checkouts [data-testid='checkout-strategy-mobile-row']:nth-of-type(1) { --hiw-ri: 0ms; --hiw-row: 450ms; }
  .hiw-checkouts [data-testid='checkout-strategy-mobile-row']:nth-of-type(2) { --hiw-ri: var(--hiw-stagger); --hiw-row: 900ms; }
  .hiw-checkouts [data-testid='checkout-strategy-mobile-row']:nth-of-type(3) { --hiw-ri: calc(2 * var(--hiw-stagger)); --hiw-row: 1350ms; }
  .hiw-checkouts [data-testid='checkout-strategy-mobile-row']:nth-of-type(4) { --hiw-ri: calc(3 * var(--hiw-stagger)); --hiw-row: 1800ms; }
  .hiw-checkouts [data-testid='checkout-strategy-mobile-row']:nth-of-type(5) { --hiw-ri: calc(4 * var(--hiw-stagger)); --hiw-row: 2250ms; }
  .hiw-checkouts [data-testid='checkout-strategy-mobile-row']:nth-of-type(6) { --hiw-ri: calc(5 * var(--hiw-stagger)); --hiw-row: 2700ms; }
  .hiw-checkouts [data-testid='checkout-strategy-mobile-row'] {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 250ms;
    animation-delay: var(--hiw-ri, 0ms);
  }
  .hiw-checkouts [data-testid='checkout-strategy-mobile-paths'] > :first-child {
    animation-name: hiw-strike;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 400ms;
    animation-delay: var(--hiw-row, 0ms);
  }
  .hiw-checkouts [data-testid='checkout-strategy-mobile-paths'] > :not(:first-child) {
    animation-name: hiw-slide-in;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 400ms;
    animation-delay: calc(var(--hiw-row, 0ms) + 250ms);
  }
  .hiw-checkouts [data-testid='checkout-strategy-mobile-meta'] > span:last-child {
    animation-name: hiw-stamp;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 450ms;
    animation-delay: calc(var(--hiw-row, 0ms) + 500ms);
  }
  /* Same sequence on the one line layout (wide picture card). */
  .hiw-checkouts [data-testid='checkout-strategy-desktop-row']:nth-of-type(1) { --hiw-ri: 0ms; --hiw-row: 450ms; }
  .hiw-checkouts [data-testid='checkout-strategy-desktop-row']:nth-of-type(2) { --hiw-ri: var(--hiw-stagger); --hiw-row: 900ms; }
  .hiw-checkouts [data-testid='checkout-strategy-desktop-row']:nth-of-type(3) { --hiw-ri: calc(2 * var(--hiw-stagger)); --hiw-row: 1350ms; }
  .hiw-checkouts [data-testid='checkout-strategy-desktop-row']:nth-of-type(4) { --hiw-ri: calc(3 * var(--hiw-stagger)); --hiw-row: 1800ms; }
  .hiw-checkouts [data-testid='checkout-strategy-desktop-row']:nth-of-type(5) { --hiw-ri: calc(4 * var(--hiw-stagger)); --hiw-row: 2250ms; }
  .hiw-checkouts [data-testid='checkout-strategy-desktop-row']:nth-of-type(6) { --hiw-ri: calc(5 * var(--hiw-stagger)); --hiw-row: 2700ms; }
  .hiw-checkouts [data-testid='checkout-strategy-desktop-row'] {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 250ms;
    animation-delay: var(--hiw-ri, 0ms);
  }
  .hiw-checkouts [data-testid='checkout-strategy-desktop-paths'] > :first-child {
    animation-name: hiw-strike;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 400ms;
    animation-delay: var(--hiw-row, 0ms);
  }
  .hiw-checkouts [data-testid='checkout-strategy-desktop-paths'] > :not(:first-child) {
    animation-name: hiw-slide-in;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 400ms;
    animation-delay: calc(var(--hiw-row, 0ms) + 250ms);
  }
  .hiw-checkouts [data-testid='checkout-strategy-desktop-row'] > td:last-child span {
    animation-name: hiw-stamp;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 450ms;
    animation-delay: calc(var(--hiw-row, 0ms) + 500ms);
  }

  /* Beginner growth row: the boards are there almost at once; their scores
     then count up one after another (useCountUp, GROWTH_COUNT_DELAYS_MS). */
  .hiw-growth > * {
    animation-name: hiw-fade;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 250ms;
  }
  .hiw-growth > :nth-child(2) { animation-delay: var(--hiw-stagger); }
  .hiw-growth > :nth-child(3) { animation-delay: calc(2 * var(--hiw-stagger)); }
  .hiw-growth > :nth-child(4) { animation-delay: calc(3 * var(--hiw-stagger)); }
  .hiw-growth > :nth-child(5) { animation-delay: calc(4 * var(--hiw-stagger)); }

  /* Beginner level loop: the board that becomes active pops once (a short
     scale up and back, ease data, owner approved), while its brand ring
     fades in and the previous board dims (transitions in BeginnerVisual).
     Added with the class, so it plays on every level change. */
  .hiw-level-pop {
    animation: hiw-level-pop var(--dur-data) var(--ease-data) both;
  }

  /* Compare table: the text is there from the start; the marks pop in row
     by row (--hiw-i inline per row, the list stagger), the 99darts check
     60ms after the other apps mark (a scripted beat inside the row).
     'still' (reduced motion, prerender) gets no animation; 'wait' holds
     the first frame until the picture is seen. */
  .hiw-compare:not([data-hiw-marks='still']) .hiw-mark {
    transform-box: fill-box;
    transform-origin: center;
    animation-name: hiw-pop;
    animation-timing-function: var(--ease-data);
    animation-fill-mode: both;
    animation-duration: 300ms;
    animation-delay: calc(var(--hiw-i, 0) * var(--hiw-stagger));
  }
  .hiw-compare:not([data-hiw-marks='still']) .hiw-mark-us {
    animation-delay: calc(var(--hiw-i, 0) * var(--hiw-stagger) + 60ms);
  }
  .hiw-compare[data-hiw-marks='wait'] .hiw-mark {
    animation-play-state: paused;
  }
}
