/* R22 motion language (M1, 1 November 2026): the tokens and primitives every section moves with. Prefix m-.
   Docs and measurements: docs/R22_MOTION.md (the Awwwards Motion study, recorded with reanimate under .reanimate/aww-*).
   Script: src/r22/motion.js (loaded bare, one instance). Calm, premium, Apple-restrained: things settle, they never
   bounce unless a gesture threw them; transform and opacity only; nothing waits for an animation to finish.
   Pre-states apply only when scripting is on and motion is welcome, so text is readable without JS, a failed module
   never hides content (failsafe below) and reduced motion always gets the finished layout. */

:root {
  /* Curves (measured; see R22_MOTION.md › Naalai motion language) */
  --m-settle: cubic-bezier(.16, 1, .3, 1);   /* entrances, hover-in: expo-out (sensiq headline, rmse 0.0009) */
  --m-glide: cubic-bezier(.22, 1, .36, 1);   /* long distances and chrome, 1 s and longer: quint-out (sensiq nav, declared) */
  --m-scene: cubic-bezier(.65, .05, 0, 1);   /* one big media moment a page: slow start, decisive middle (Quaker, rmse 0.0001) */
  --m-swap: cubic-bezier(.65, 0, .35, 1);    /* loops and place swaps: cubic in-out */
  --m-scrub: cubic-bezier(.42, 0, .58, 1);   /* scroll-scrubbed scenes: progress to value (Quaker hero scrub, in-out) */
  --m-exit: cubic-bezier(.7, 0, .84, 0);     /* leaving along the entry path: the settle curve mirrored */
  /* A critically damped spring (damping 1) sampled over twice its response: response .5 s over 1 s, or .4 s over 800 ms. */
  --m-spring: linear(0, .0974, .2816, .4656, .6189, .7361, .821, .8806, .9213, .9487, .9668, .9787, .9864, .9914, .9945, .9966, .9978, .9987, .9992, .9995, .9997, .9998, .9999, .9999, 1);

  /* Durations */
  --m-press: 100ms;   /* pointer-down feedback */
  --m-quick: 200ms;   /* hover fills and colour (sensiq 200 ms) */
  --m-fade: 450ms;    /* the opacity part of an entrance (sensiq 440 ms) */
  --m-small: 400ms;   /* small pieces settling (sensiq chips 360 ms) */
  --m-base: 700ms;    /* copy rising into place (sensiq headline 700 ms) */
  --m-line: 800ms;    /* masked line reveals (swsh line wipe; verified round 3) */
  --m-long: 1100ms;   /* media and window moments (Quaker 1200 ms, Prime 1100 ms) */
  --m-drift: 2000ms;  /* large art settling from afar (sensiq photo 2000 ms; verified round 3) */

  /* Distances */
  --m-rise-sm: 12px;  /* small copy and controls (sensiq 12 px) */
  --m-rise: 24px;     /* headline blocks (sensiq 24 px) */
  --m-drift-y: 32px;  /* art and photos (sensiq 48 px, calmer here) */
  --m-settle-y: 8px;  /* UI pieces (sensiq chips 8 px with scale .96) */
  --m-settle-s: .96;
  --m-mask-from: 118%; /* a masked word starts below its own padded mask */

  /* Staggers */
  --m-step-char: 30ms;  /* characters and digits (unlumen 25 ms) */
  --m-step-word: 40ms;
  --m-step-line: 90ms;
  --m-step-item: 60ms;
}

/* ---------- Entrances: [data-m="rise|rise-lg|settle|drift|fade|lines|roll"], started by motion.js (adds .m-in). */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  html:not(.m-ready) [data-m] { opacity: 0; animation: m-failsafe 1ms 2.6s forwards; } /* motion.js never ran: show it */
  html.m-ready [data-m]:not(.m-in):not([data-m="lines"]):not([data-m="roll"]) { opacity: 0; }
  html.m-ready [data-m="rise"]:not(.m-in) { transform: translateY(var(--m-rise-sm)); }
  html.m-ready [data-m="rise-lg"]:not(.m-in) { transform: translateY(var(--m-rise)); }
  html.m-ready [data-m="settle"]:not(.m-in) { transform: translateY(var(--m-settle-y)) scale(var(--m-settle-s)); }
  html.m-ready [data-m="drift"]:not(.m-in) { transform: translateY(var(--m-drift-y)); }
  html.m-ready [data-m="lines"]:not(.m-split), html.m-ready [data-m="roll"]:not(.m-split) { opacity: 0; }
  /* Transitions exist only while it enters (.m-in), so taking up the pre-state is instant; .m-done (added by motion.js
     once it has arrived) hands the element's own hover and press transitions back. */
  html.m-ready [data-m].m-in:not([data-m="lines"]):not([data-m="roll"]):not(.m-done) {
    transition: opacity var(--m-fade) var(--m-settle) var(--m-at, 0ms), transform var(--m-dur, var(--m-base)) var(--m-settle) var(--m-at, 0ms); }
  html.m-ready [data-m="settle"] { --m-dur: var(--m-small); }
  html.m-ready [data-m="drift"] { --m-dur: var(--m-drift); }
}
@keyframes m-failsafe { to { opacity: 1; transform: none; } }

/* Masks for words, lines and digits (motion.js split()). Each piece clips itself; the padding keeps descenders and
   accents inside the mask and the negative margin keeps the line box exactly as tall as the plain text. */
.m-w { display: inline-block; overflow: clip; padding-block: .1em .2em; margin-block: -.1em -.2em; }
.m-w__in { display: inline-block; }
.m-word { display: inline-block; white-space: nowrap; } /* char splits keep each word on one line */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  html.m-ready .m-split:not(.m-in) .m-w__in { transform: translateY(var(--m-mask-from)); }
  /* A hand-drawn mark in a masked headline draws when its own line has risen (motion.js adds .m-draw), not before. */
  html.m-ready [data-m="lines"] .n-mark { --mark-delay: 0s; }
  html.m-ready [data-m="lines"] .n-mark:not(.m-draw) .n-mark__svg path { stroke-dashoffset: 1; }
  html.m-ready [data-m="lines"] .n-mark:not(.m-draw) .n-mark__handle { opacity: 0; transform: scale(.4); }
  html.m-ready [data-m="lines"] .n-mark--highlight:not(.m-draw)::before { transform: scaleX(0); }
  html.m-ready .m-split.m-in .m-w__in {
    transition: transform var(--m-dur, var(--m-line)) var(--m-settle) calc(var(--m-at, 0ms) + var(--m-k, 0) * var(--m-step, var(--m-step-line))); }
}

/* ---------- Clip reveal (transform only): the outer box slides one way while the content slides back the other, so
   the content stays put and an edge travels across it. motion.js sets --m-cx/--m-cy on the outer. */
.m-clip { overflow: clip; }
.m-clip__in { display: block; }
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  html.m-ready .m-clip:not(.m-in) { transform: translate(var(--m-cx, 0), var(--m-cy, 100%)); }
  html.m-ready .m-clip:not(.m-in) > .m-clip__in { transform: translate(calc(var(--m-cx, 0) * -1), calc(var(--m-cy, 100%) * -1)); }
  html.m-ready .m-clip.m-in, html.m-ready .m-clip.m-in > .m-clip__in { transition: transform var(--m-dur, var(--m-long)) var(--m-scene) var(--m-at, 0ms); }
}

/* ---------- Magnetic controls with lift and light (pointer magnetism and the lift effect, apple-hig pointing-devices).
   motion.js moves the control with individual translate/scale (they compose with the :active press transform). */
.m-mag { isolation: isolate; }
.m-mag::before { content: ""; position: absolute; inset: 0; z-index: -2; border-radius: inherit; pointer-events: none;
  box-shadow: 0 2px 4px rgba(20, 22, 30, .06), 0 16px 32px -14px rgba(20, 22, 30, .34); opacity: 0;
  transition: opacity var(--m-small) var(--m-settle); }
.m-mag.is-lift::before { opacity: 1; }
.m-mag__in { display: inline-flex; align-items: center; gap: inherit; pointer-events: none; }
.m-light-clip { position: absolute; inset: 0; z-index: -1; border-radius: inherit; overflow: clip; pointer-events: none; }
.m-light-clip--over { z-index: auto; }
.m-light { position: absolute; left: 0; top: 0; width: var(--m-light-size, 140px); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(closest-side, var(--m-light-color, rgba(255, 255, 255, .26)), rgba(255, 255, 255, 0));
  opacity: 0; will-change: transform; transition: opacity var(--m-quick) var(--m-settle); }
.is-lit > .m-light-clip > .m-light { opacity: 1; }

/* ---------- Tilt (large surfaces): the host gets perspective; motion.js writes rotate and scale on the surface. */
.m-tilt-host { perspective: 1600px; }

/* ---------- Count-up without layout shift: the final value reserves the space, the live value sits on top. */
.m-count { display: inline-grid; }
.m-count > * { grid-area: 1 / 1; }
.m-count__ghost { visibility: hidden; }
.m-sr { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---------- Rolling digits (motion.js roll; R2 motion, 3 Nov, additive). Each digit is a wheel: the final digit (the ghost)
   holds the wheel's width and line, the strip of 0-9 rolls over it on Y, clipped above and below only. */
.m-rolls { font-variant-numeric: tabular-nums; }
.m-roll { white-space: nowrap; }
.m-roll__d { position: relative; display: inline-block; overflow-x: visible; overflow-y: clip; } /* clip, not clip-path: the strip's height never adds to the page's scroll area (a tilted card would turn it sideways) */
.m-roll__ghost { visibility: hidden; }
.m-roll__strip { position: absolute; left: 0; right: 0; top: 0; display: block; text-align: center; white-space: pre; will-change: transform; }

/* ---------- Marquee with velocity (needs a pause control nearby: WCAG 2.2.2). */
.m-marquee { overflow: clip; }
.m-marquee__track { display: flex; width: max-content; will-change: transform; }

/* ---------- Preferences */
@media (prefers-reduced-motion: reduce) {
  [data-m], .m-w__in, .m-clip, .m-clip__in, .m-marquee__track { opacity: 1 !important; transform: none !important; transition: none !important; animation: none !important; }
  .m-roll__strip { transition: none !important; }
  .m-mag::before, .m-light { transition: none !important; }
}
@media (prefers-reduced-transparency: reduce) { .m-light-clip { display: none; } }
@media (prefers-contrast: more) { .m-light-clip { display: none; } .m-mag::before { box-shadow: none; } }
@media (forced-colors: active) { .m-light-clip, .m-mag::before { display: none; } }
