/*
 * DMC motion system, v1.0 (approved at Gate 4: D28 native engine, D36 refined timings)
 *
 * Two kinds of motion, one rhythm:
 *   1. Reveals   [data-reveal]  play once, eased, when an element scrolls into view.
 *                Driven by motion.js (IntersectionObserver) in every browser.
 *   2. Scrubs    [data-scrub]   follow the scroll position.
 *                "native":   CSS scroll-driven animations, run off the main thread.
 *                "fallback": motion.js writes --p (0 to 1); the same look, computed in CSS.
 *
 * Rules: only transform and opacity move (no clip-path or backdrop-filter on scrolling elements). Nothing is hidden unless motion.js
 * has armed the system (html.m-ready), so content is readable without JavaScript.
 * Reduced motion (or data-motion="off") shows everything at rest.
 */

/* Timings and easing live in tokens.css (--m-*). */

/* ---------- Load sequence (CSS only, first paint) ---------- */
@keyframes m-line-in {
  from { transform: translate3d(0, 108%, 0); }
  to   { transform: none; }
}
@keyframes m-fade-up {
  from { opacity: 0; transform: translate3d(0, 1rem, 0); }
  to   { opacity: 1; transform: none; }
}
.m-mask { display: inline-block; overflow: clip; vertical-align: top; padding-block-end: 0.06em; margin-block-end: -0.06em; }
.m-mask > span { display: inline-block; }
@media (prefers-reduced-motion: no-preference) {
  .m-load-line { animation: m-line-in 0.9s var(--m-ease-out) both; animation-delay: var(--ld, 0ms); }
  .m-load-fade { animation: m-fade-up 0.75s var(--m-ease-out) both; animation-delay: var(--ld, 0ms); }
}
html[data-motion="off"] .m-load-line,
html[data-motion="off"] .m-load-fade { animation: none; }

/* ---------- 1. Reveals ---------- */
html.m-ready [data-reveal] {
  transition-property: opacity, transform;
  transition-duration: var(--m-dur);
  transition-timing-function: var(--m-ease-out);
  transition-delay: var(--d, 0ms);
}
html.m-arming [data-reveal] { transition: none !important; }
html.m-ready [data-reveal]:not(.is-in) { opacity: 0; transform: translate3d(0, var(--m-rise), 0); }
html.m-ready [data-reveal="fade"]:not(.is-in) { transform: none; }
html.m-ready [data-reveal="left"]:not(.is-in) { transform: translate3d(calc(var(--m-rise) * -1), 0, 0); }
html.m-ready [data-reveal="scale"]:not(.is-in) { transform: scale(0.94); }
/* Wipe: a curtain in the surrounding colour slides away (transform only, so it never repaints while scrolling). */
html.m-ready [data-reveal="wipe"]::before { content: ""; position: absolute; inset: 0; z-index: 4; background: var(--wipe-cover, #00152E); transform-origin: 50% 100%; transform: scaleY(0); transition: transform var(--m-dur) var(--m-ease-out); transition-delay: var(--d, 0ms); pointer-events: none; }
html.m-ready [data-reveal="wipe"]:not(.is-in) { opacity: 1; transform: none; }
html.m-ready [data-reveal="wipe"]:not(.is-in)::before { transform: scaleY(1); }
html.m-arming [data-reveal="wipe"]::before { transition: none !important; }

/* ---------- 2. Scrubs: resting state (no JS, reduced motion, off) ---------- */
[data-scrub="parallax"] { transform: scale(1.18); }
[data-scrub="line"]     { transform-origin: 50% 0; }
[data-scrub="bar"]      { transform-origin: 0 50%; }

/* Scrub roots expose one named view timeline to their descendants. */
[data-timeline] { view-timeline: --m-root block; }

/* ---------- 2a. Scrubs: native scroll-driven animations ---------- */
@keyframes m-lift     { to   { transform: translate3d(0, -14vh, 0); opacity: 0.15; } }
@keyframes m-parallax { from { transform: translate3d(0, -7%, 0) scale(1.18); } to { transform: translate3d(0, 7%, 0) scale(1.18); } }
@keyframes m-drift    { to   { transform: translate3d(8vw, -22vh, 0) rotate(8deg); } }
@keyframes m-grow-y   { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes m-grow-x   { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes m-moon     { from { transform: translate3d(-18%, 45%, 0); } to { transform: translate3d(22%, -55%, 0); } }
@keyframes m-word     { from { opacity: 0.16; } to { opacity: 1; } }
@keyframes m-step     { from { opacity: 0.28; transform: translate3d(0, 0.5rem, 0); } to { opacity: 1; transform: none; } }

@supports (animation-timeline: view()) and (animation-range: entry 0% exit 100%) {
  html[data-motion="native"] [data-scrub] { animation-timing-function: linear; animation-fill-mode: both; animation-duration: auto; }

  html[data-motion="native"] [data-scrub="lift"]     { animation-name: m-lift;     animation-timeline: view();   animation-range: exit 0% exit 100%; }
  html[data-motion="native"] [data-scrub="parallax"] { animation-name: m-parallax; animation-timeline: --m-root; animation-range: cover 0% cover 100%; }
  html[data-motion="native"] [data-scrub="drift"]    { animation-name: m-drift;    animation-timeline: --m-root; animation-range: exit 0% exit 100%; }
  html[data-motion="native"] [data-scrub="line"]     { animation-name: m-grow-y;   animation-timeline: --m-root; animation-range: cover 0% cover 100%; }
  html[data-motion="native"] [data-scrub="bar"]      { animation-name: m-grow-x;   animation-timeline: --m-root; animation-range: contain 0% contain 100%; }
  html[data-motion="native"] [data-scrub="moon"]     { animation-name: m-moon;     animation-timeline: --m-root; animation-range: cover 0% cover 100%; }

  /* Word light-up: one timeline for the whole block; each word takes its own slice of it. */
  html[data-motion="native"] [data-split="words"] { view-timeline: --m-words block; }
  html[data-motion="native"] [data-split="words"] .m-w {
    --at: calc(var(--i, 0) / var(--n, 1) * 34%);
    animation: m-word linear both; animation-timeline: --m-words;
    animation-range: cover calc(16% + var(--at)) cover calc(22% + var(--at));
  }

  /* Four-step approach: each step lights at its quarter of the pinned section. */
  html[data-motion="native"] [data-scrub="steps"] > * { animation: m-step linear both; animation-timeline: --m-root; }
  html[data-motion="native"] [data-scrub="steps"] > :nth-child(1) { animation-range: entry 100% contain 4%; }
  html[data-motion="native"] [data-scrub="steps"] > :nth-child(2) { animation-range: contain 25% contain 31%; }
  html[data-motion="native"] [data-scrub="steps"] > :nth-child(3) { animation-range: contain 50% contain 56%; }
  html[data-motion="native"] [data-scrub="steps"] > :nth-child(4) { animation-range: contain 75% contain 81%; }
}

/* ---------- 2b. Scrubs: fallback (motion.js writes --p) ---------- */
html[data-motion="fallback"] [data-scrub="lift"]     { transform: translate3d(0, calc(var(--p, 0) * -14vh), 0); opacity: calc(1 - var(--p, 0) * 0.85); }
html[data-motion="fallback"] [data-scrub="parallax"] { transform: translate3d(0, calc((var(--p, 0.5) * 14 - 7) * 1%), 0) scale(1.18); }
html[data-motion="fallback"] [data-scrub="drift"]    { transform: translate3d(calc(var(--p, 0) * 8vw), calc(var(--p, 0) * -22vh), 0) rotate(calc(var(--p, 0) * 8deg)); }
html[data-motion="fallback"] [data-scrub="line"]     { transform: scaleY(var(--p, 0)); }
html[data-motion="fallback"] [data-scrub="bar"]      { transform: scaleX(var(--p, 0)); }
html[data-motion="fallback"] [data-scrub="moon"]     { transform: translate3d(calc(-18% + var(--p, 0) * 40%), calc(45% - var(--p, 0) * 100%), 0); }
html[data-motion="fallback"] [data-scrub="steps"] > * {
  --on: clamp(0, calc((var(--p, 0) - var(--t, 0) + 0.04) * 16), 1);
  opacity: calc(0.28 + var(--on) * 0.72);
  transform: translate3d(0, calc((1 - var(--on)) * 0.5rem), 0);
}
html[data-motion="fallback"] [data-scrub="steps"] > :nth-child(2) { --t: 0.25; }
html[data-motion="fallback"] [data-scrub="steps"] > :nth-child(3) { --t: 0.5; }
html[data-motion="fallback"] [data-scrub="steps"] > :nth-child(4) { --t: 0.75; }

/* ---------- Header: always on screen (D34). Its compact .is-stuck look lives in the page CSS. ---------- */

/* ---------- Belt and braces ---------- */
@media (prefers-reduced-motion: reduce) {
  [data-reveal], [data-scrub], [data-split="words"] .m-w, [data-header] { animation: none !important; transition: none !important; }
}
