/* ============================================================
   Kit v1 motion pack (skills-plan section 2, "Motion kit")
   Opt-in by attribute; motion.js adds the few classes below.

   Presets: <html data-motion-preset="still|calm|lively"> (render.mjs
   writes it from brand.json "motion"). Values come from the 2026-11-16
   design scan of the reference sites; sources in kit/CHANGELOG.md.
     still   hover only
     calm    + headline rise, scroll reveal, stagger
     lively  + longer moves, count-up, progress line, parallax, a lane
               that drifts with the scroll (data-marquee)
   No endless loops by default (2026-11-19): a lane moves only while the
   page scrolls. A brand that keeps a loop (data-marquee="loop") puts the
   pause control on the lane itself (partials/motion-toggle.html).
   Paused: <html data-motion="off">, set by [data-motion-toggle] and
   saved in localStorage ("kit-motion"); head.html applies it before
   first paint.

   Rules (kit/RULES.md 9 and the plan's "Rules in the kit"):
   - only opacity and transform animate; each one-shot effect runs once
   - hidden states exist only under html.js AND
     prefers-reduced-motion: no-preference AND not data-motion="off"
   - motion.js marks only elements below the first screen as waiting,
     so nothing on screen at load is ever hidden
   - reduced motion sets the duration tokens to 0 (no blanket rule)
   - nothing moves on its own for more than 5 s without a pause control
     on the moving element (WCAG 2.2.2); a kept loop also pauses in
     hidden tabs (html[data-motion-idle]) and on hover
   ============================================================ */

/* ---- presets: tokens only ---- */
html[data-motion-preset="still"] {
  --t-fast: 200ms;
  --t-reveal: 0ms; --reveal-shift: 0px; --stagger: 0ms;
  --t-rise: 0ms; --rise-shift: 0px;
}
html[data-motion-preset="calm"] {
  --t-fast: 300ms;
  --t-reveal: 700ms; --reveal-shift: 28px; --stagger: 120ms;
  --t-rise: 700ms; --rise-shift: 0.3em;
}
html[data-motion-preset="lively"] {
  --t-fast: 300ms;
  --t-reveal: 900ms; --reveal-shift: 56px; --stagger: 180ms;
  --t-rise: 900ms; --rise-shift: 0.5em;
  --t-count: 1200ms; --parallax-shift: 8%; --t-marquee: 40s; /* --t-marquee: only a kept loop */
}

/* reduced motion: every duration and distance to 0 (same specificity as
   the presets, declared later, so it wins). base.css does the same for
   :root, which covers pages without a preset. */
@media (prefers-reduced-motion: reduce) {
  :root, html[data-motion-preset] {
    --t-fast: 0ms; --t-reveal: 0ms; --reveal-shift: 0px; --stagger: 0ms;
    --t-rise: 0ms; --rise-shift: 0px; --t-count: 0ms; --parallax-shift: 0px;
  }
}
/* paused (html[data-motion="off"]): one-shot moves off; hover feedback stays */
html[data-motion="off"] {
  --t-reveal: 0ms; --reveal-shift: 0px; --stagger: 0ms;
  --t-rise: 0ms; --rise-shift: 0px; --t-count: 0ms; --parallax-shift: 0px;
}

/* ---- hover set (all presets): colour, border and the 4px arrow nudge
   live in base.css / parts.css on --t-fast; lively adds a 2px lift ---- */
.btn, .pill { transition-property: background-color, color, border-color, transform; }
@media (prefers-reduced-motion: no-preference) {
  html[data-motion-preset="lively"]:not([data-motion="off"]) :is(.btn, .pill):hover { transform: translateY(-2px); }
}

/* ---- data-rise: headline lines rise on load, staggered (calm, lively).
   Transform only: the words never fade, so the first screen is never
   hidden. motion.js sets --i on each line. ---- */
@media (prefers-reduced-motion: no-preference) {
  html.js:is([data-motion-preset="calm"], [data-motion-preset="lively"]):not([data-motion="off"]) [data-rise] > * {
    animation: kit-rise var(--t-rise) var(--ease) calc(var(--i, 0) * var(--stagger)) both;
  }
}
@keyframes kit-rise { from { transform: translateY(var(--rise-shift)); } to { transform: none; } }

/* ---- data-reveal (+ data-stagger on the parent): fade and rise once,
   on scroll (calm, lively). .is-waiting is set by motion.js only on
   elements below the first screen; .is-going only while moving. ---- */
@media (prefers-reduced-motion: no-preference) {
  html.js:is([data-motion-preset="calm"], [data-motion-preset="lively"]):not([data-motion="off"]) [data-reveal].is-waiting {
    opacity: 0;
    transform: translateY(var(--reveal-shift));
  }
  html.js:not([data-motion="off"]) [data-reveal].is-going {
    transition: opacity var(--t-reveal) var(--ease) var(--delay, 0ms), transform var(--t-reveal) var(--ease) var(--delay, 0ms);
  }
}

/* ---- data-count: plain numbers count up (lively; motion.js) ---- */
[data-count] { font-variant-numeric: tabular-nums; }

/* ---- data-progress: a line that grows with scroll (lively).
   data-progress="page" follows the whole page, otherwise the line's own
   pass through the screen. Without scroll timelines, reduced motion,
   no JS or the paused state, the line is simply full. ---- */
[data-progress] {
  display: block;
  height: var(--hairline);
  background: var(--accent);
  transform-origin: 0 50%;
}
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    html.js[data-motion-preset="lively"]:not([data-motion="off"]) [data-progress] {
      animation: kit-grow linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 50%;
    }
    html.js[data-motion-preset="lively"]:not([data-motion="off"]) [data-progress="page"] {
      animation-timeline: scroll(root);
      animation-range: normal;
    }
  }
}
@keyframes kit-grow { from { transform: scaleX(0); } to { transform: none; } }

/* ---- data-parallax: what sits inside the .media frame (image, svg or
   placeholder caption) drifts slowly (lively). It is scaled up inside
   the frame so no edge shows. ---- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    html.js[data-motion-preset="lively"]:not([data-motion="off"]) [data-parallax] .media > * {
      animation: kit-drift linear both;
      animation-timeline: view();
      animation-range: cover;
    }
  }
}
@keyframes kit-drift {
  from { transform: scale(1.2) translateY(calc(var(--parallax-shift) * -1)); }
  to { transform: scale(1.2) translateY(var(--parallax-shift)); }
}

/* ---- data-marquee: a lane of items in one row (lively).
   Default: the lane drifts sideways only while the page scrolls, from
   its start to its last item, both ways, and stops when the scroll
   stops (no loop, so no pause control). motion.js marks it .is-drifting
   where scroll timelines exist; without them, and in every still state,
   it is a row that scrolls sideways by hand.
   data-marquee="loop": an endless lane, kept only by a brand that needs
   it; motion.js copies the track once (aria-hidden) and adds
   .is-looping; the section must hold the pause control on the lane
   (render.mjs refuses it otherwise). ---- */
[data-marquee] { display: flex; overflow-x: auto; }
[data-marquee] > * { flex: none; display: flex; gap: var(--gutter); padding-right: var(--gutter); margin: 0; }
[data-marquee].is-looping { overflow: hidden; }
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    html.js[data-motion-preset="lively"]:not([data-motion="off"]) [data-marquee].is-drifting {
      overflow-x: clip;
      container-type: inline-size;
      view-timeline: --kit-lane block;
    }
    html.js[data-motion-preset="lively"]:not([data-motion="off"]) [data-marquee].is-drifting > * {
      animation: kit-drift-x linear both;
      animation-timeline: --kit-lane;
      animation-range: cover 10% cover 90%;
    }
  }
}
/* from the first item to the last one at the lane's end edge (no move when the row fits) */
@keyframes kit-drift-x { from { transform: none; } to { transform: translateX(min(0px, calc(100cqi - 100%))); } }
@media (prefers-reduced-motion: no-preference) {
  /* a kept loop: paused by default; runs only while nothing asks it to stop */
  html.js[data-motion-preset="lively"] [data-marquee="loop"].is-looping > * {
    animation: kit-lane var(--t-marquee) linear infinite paused;
  }
  html.js[data-motion-preset="lively"]:not([data-motion="off"]):not([data-motion-idle]) [data-marquee="loop"].is-looping:not(:hover):not(:focus-within) > * {
    animation-play-state: running;
  }
}
@keyframes kit-lane { to { transform: translateX(-100%); } }

/* ---- data-dock: sticky phone call-to-action bar (any preset).
   Without JS it simply stays at the bottom on phones. With JS it shows
   once the first section has scrolled away and hides at the footer. ---- */
[data-dock] {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--margin);
  background: var(--surface);
  border-top: var(--hairline) solid var(--rule-strong);
}
@media (min-width: 960px) { [data-dock] { display: none; } }
html.js [data-dock] {
  position: fixed;
  left: 0;
  right: 0;
  transition: transform var(--t-fast) var(--ease), visibility 0s linear var(--t-fast);
}
html.js [data-dock]:not(.is-on) { transform: translateY(100%); visibility: hidden; }
html.js [data-dock].is-on { transition-delay: 0s; }

/* ---- pause control on a kept loop (partials/motion-toggle.html).
   A small round button placed on the looping element: its section
   wraps the lane and the button in .motion-frame. The visible label
   (Pause / Play) follows html[data-motion]; aria-pressed too. Shown
   only where it can act: JS on, motion allowed, a lively page. ---- */
.motion-frame { position: relative; }
.motion-toggle {
  position: absolute;
  z-index: 2;
  inset-inline-end: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--tap-min);
  height: var(--tap-min);
  padding: 0;
  border: var(--hairline) solid var(--rule-strong);
  border-radius: 50%;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.motion-toggle:hover { background: var(--fg); color: var(--bg); }
.motion-toggle svg { width: 14px; height: 14px; fill: currentColor; }
.motion-toggle__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) {
  html.js[data-motion-preset="lively"] .motion-toggle { display: inline-flex; }
}
.motion-toggle__play, html[data-motion="off"] .motion-toggle__pause { display: none; }
html[data-motion="off"] .motion-toggle__play { display: inline; }
