/* VBK-1932 — Light builder motion primitives, CSS half.
   Pairs with motion.js (GSAP + ScrollTrigger + SplitText + Lenis).

   DIVISION OF LABOUR, and it matters:
   - CSS owns STATE-DRIVEN micro-interaction — :hover, :focus-visible, :active.
     These are interruptible by nature, need no frame loop, and a transition
     expresses them better and cheaper than JS ever will.
   - JS owns everything with a TIMELINE or a SIMULATION — reveals, scrubbed
     scroll, springs, masked text, pinned sequences.

   Nothing below transitions `transform` on an element motion.js drives
   (magnetic, tilt, parallax, mask, pin, horizontal, marquee). A CSS transition
   on those would re-interpolate every inline transform GSAP writes each frame,
   which reads as lag and fights the spring — that conflict is the single
   easiest way to make a good engine feel broken. Hover scale for magnetic
   buttons is therefore applied to an INNER element, never the tracked one. */

:root {
  /* --- tokens consumed by CSS --- */
  --motion-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --motion-ease-overshoot: cubic-bezier(0.34, 1.56, 0.64, 1);
  --motion-duration-fast: 200ms;
  --motion-duration-base: 550ms;
  --motion-scale-hover: 1.03;

  /* VBK-1976 — the Z axis. A single perspective on :root rather than per
     character: the DEPTH knobs below (spread/rotate/float range, etc.)
     already carry the character's feel, and a second perspective value per
     character would just be one more number to keep in sync for no visible
     gain at these depths. */
  --motion-perspective: 1200px;

  /* --- tokens consumed by motion.js (seconds + GSAP ease names) ---
     Kept in CSS so ONE attribute on <html> retunes both halves at once. */
  --motion-duration-s: 0.9;
  --motion-distance: 28;
  --motion-stagger-step-s: 0.08;
  --motion-ease-js: power3.out;
  --motion-scroll-duration-s: 1.05;

  /* VBK-1976 — depth primitives (deck/scatter/float/pop). Unitless numbers
     read via motion.js's token(), same convention as --motion-distance. */
  --motion-deck-spread: 120;
  --motion-deck-rotate: 8;
  --motion-deck-depth: 70;
  --motion-scatter-rotate: 18;
  --motion-float-range: 8;
  --motion-float-speed-s: 3.2;
}

/* ---------------------------------------------------------------------------
   MOTION CHARACTER — one attribute on <html>, set from the art direction.
   --------------------------------------------------------------------------- */

[data-motion-character="mechanical"] {
  --motion-ease: cubic-bezier(0.4, 0, 0.6, 1);
  --motion-duration-fast: 120ms; --motion-duration-base: 220ms;
  --motion-scale-hover: 1;
  --motion-duration-s: 0.34; --motion-distance: 10; --motion-stagger-step-s: 0.04;
  --motion-ease-js: power1.inOut; --motion-scroll-duration-s: 0.8;
  --motion-deck-spread: 50; --motion-deck-rotate: 2; --motion-deck-depth: 20;
  --motion-scatter-rotate: 6; --motion-float-range: 3; --motion-float-speed-s: 1.6;
}

[data-motion-character="organic"] {
  --motion-ease: cubic-bezier(0.16, 0.84, 0.44, 1);
  --motion-duration-fast: 320ms; --motion-duration-base: 800ms;
  --motion-scale-hover: 1.05;
  --motion-duration-s: 1.1; --motion-distance: 32; --motion-stagger-step-s: 0.1;
  --motion-ease-js: power2.out; --motion-scroll-duration-s: 1.25;
  --motion-deck-spread: 150; --motion-deck-rotate: 11; --motion-deck-depth: 100;
  --motion-scatter-rotate: 22; --motion-float-range: 12; --motion-float-speed-s: 4.4;
}

[data-motion-character="precise"] {
  --motion-ease: cubic-bezier(0.2, 0, 0.2, 1);
  --motion-duration-fast: 140ms; --motion-duration-base: 320ms;
  --motion-scale-hover: 1.01;
  --motion-duration-s: 0.5; --motion-distance: 14; --motion-stagger-step-s: 0.05;
  --motion-ease-js: power3.out; --motion-scroll-duration-s: 0.9;
  --motion-deck-spread: 60; --motion-deck-rotate: 3; --motion-deck-depth: 26;
  --motion-scatter-rotate: 8; --motion-float-range: 4; --motion-float-speed-s: 2;
}

[data-motion-character="cinematic"] {
  --motion-ease: cubic-bezier(0.19, 1, 0.22, 1);
  --motion-duration-fast: 400ms; --motion-duration-base: 900ms;
  --motion-scale-hover: 1.04;
  --motion-duration-s: 1.4; --motion-distance: 40; --motion-stagger-step-s: 0.12;
  --motion-ease-js: expo.out; --motion-scroll-duration-s: 1.4;
  --motion-deck-spread: 180; --motion-deck-rotate: 13; --motion-deck-depth: 130;
  --motion-scatter-rotate: 24; --motion-float-range: 14; --motion-float-speed-s: 5.2;
}

[data-motion-character="bouncy"] {
  --motion-ease: var(--motion-ease-overshoot);
  --motion-duration-fast: 220ms; --motion-duration-base: 480ms;
  --motion-scale-hover: 1.08;
  --motion-duration-s: 0.8; --motion-distance: 30; --motion-stagger-step-s: 0.07;
  --motion-ease-js: back.out(1.7); --motion-scroll-duration-s: 1;
  --motion-deck-spread: 140; --motion-deck-rotate: 12; --motion-deck-depth: 85;
  --motion-scatter-rotate: 22; --motion-float-range: 11; --motion-float-speed-s: 2.8;
}

[data-motion-character="editorial"] {
  --motion-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --motion-duration-base: 650ms;
  --motion-duration-s: 1; --motion-distance: 26; --motion-stagger-step-s: 0.09;
  --motion-ease-js: power3.out; --motion-scroll-duration-s: 1.1;
  --motion-deck-spread: 110; --motion-deck-rotate: 7; --motion-deck-depth: 60;
  --motion-scatter-rotate: 16; --motion-float-range: 7; --motion-float-speed-s: 3.4;
}

[data-motion-character="quiet"] {
  --motion-duration-fast: 140ms; --motion-duration-base: 260ms;
  --motion-scale-hover: 1.01;
  --motion-duration-s: 0.45; --motion-distance: 8; --motion-stagger-step-s: 0.03;
  --motion-ease-js: power1.out; --motion-scroll-duration-s: 0.7;
  --motion-deck-spread: 30; --motion-deck-rotate: 1.5; --motion-deck-depth: 12;
  --motion-scatter-rotate: 4; --motion-float-range: 2; --motion-float-speed-s: 2.2;
}

/* ---------------------------------------------------------------------------
   ANTI-FOUC GATE. `js` is added by motion.js ONLY once GSAP is confirmed
   loaded — so if the engine 404s, none of this applies and the page renders
   as ordinary visible content. motion.js then immediately takes ownership of
   the start state with gsap.set(), which is why these rules must never also
   specify a transform: two sources for one property is how reveals end up
   animating 0 -> 0.
   --------------------------------------------------------------------------- */

.js .reveal,
.js [data-motion~="reveal"],
.js .stagger-children > * {
  opacity: 0;
}

/* VBK-1977 — the segment indicator has nothing correct to show until JS has
   measured the active option and positioned it; a JS-dead page instead shows
   the plainly-styled active option below (see CHROME) and no floating pill
   at all, which is a legitimate resting state, not a broken one. */
.js [data-motion~="segment"] [data-segment-indicator] {
  opacity: 0;
}

/* ...and the matching un-hide. segmentControl() adds `is-positioned` the moment
   it has measured the active option (motion.js), which is the ONLY correct
   point to reveal the pill — before that it would flash at left:0 with no
   width. Kept adjacent to the gate above on purpose: this pair is the whole
   lifecycle, and splitting them is how the indicator shipped permanently
   invisible in the first place (the class was added by JS, no rule ever
   matched it, so opacity stayed 0 on every real page).

   The `.js` prefix is not decoration — it makes this rule (0,4,0) beat the
   gate (0,3,0) on specificity rather than on source order, so the reveal
   survives any later reordering of this file. `is-positioned` is only ever set
   by motion.js, which also sets `.js` on <html>, so the two always agree.

   Deliberately outside prefers-reduced-motion's reach: the segment control is
   functional UI, and segmentControl() runs ahead of the reduced-motion early
   return. A user who asked for less motion still needs to see which tab is
   selected — only the transition duration collapses (see the reduced-motion
   block at the bottom), never the visibility. */
.js [data-motion~="segment"] [data-segment-indicator].is-positioned {
  opacity: 1;
}

.js [data-motion~="hero"] [data-hero-step],
.js [data-motion~="hero-media"] {
  opacity: 0;
}

.is-visible { opacity: 1; }

/* ---------------------------------------------------------------------------
   MASKED TEXT. SplitText builds the wrapper elements; these rules give the
   mask something to clip against.
   --------------------------------------------------------------------------- */

[data-split] .motion-line,
[data-split] .motion-word,
[data-split] .motion-char {
  display: inline-block;
  will-change: transform;
}

/* SplitText's own mask wrappers. overflow:clip beats hidden here — hidden
   establishes a scroll container, which on a heading can trap focus scrolling. */
[data-split] .split-line,
[data-split] .split-word,
[data-split] .split-char {
  overflow: clip;
  display: inline-block;
}

/* ---------------------------------------------------------------------------
   STATE-DRIVEN MICRO-INTERACTION — CSS's half of the job.
   --------------------------------------------------------------------------- */

[data-motion~="magnetic"] {
  /* No transition: motion.js writes x/y here every frame. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  will-change: transform;
}

/* The scale lives on an inner span so it cannot collide with the spring. */
[data-motion~="magnetic"] > * {
  transition: transform var(--motion-duration-fast) var(--motion-ease);
}
[data-motion~="magnetic"]:hover > * {
  transform: scale(var(--motion-scale-hover));
}

[data-motion~="tilt"] {
  will-change: transform;
}

[data-motion~="parallax"],
[data-motion~="mask"] img,
[data-motion~="mask"] video {
  will-change: transform;
}

[data-motion~="mask"] {
  overflow: clip;
}

/* Underline wipe — pure CSS, no JS needed, and a staple of the look. */
[data-motion~="underline"] {
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size var(--motion-duration-base) var(--motion-ease);
  text-decoration: none;
}
[data-motion~="underline"]:hover,
[data-motion~="underline"]:focus-visible {
  background-size: 100% 1px;
}

/* ---------------------------------------------------------------------------
   STRUCTURAL PRIMITIVES.
   --------------------------------------------------------------------------- */

[data-motion~="horizontal"] { overflow: clip; }
[data-motion~="horizontal"] [data-horizontal-track] {
  display: flex;
  flex-wrap: nowrap;
  will-change: transform;
}

[data-motion~="marquee"] { overflow: clip; }
[data-motion~="marquee"] [data-marquee-track] {
  display: flex;
  flex-wrap: nowrap;
  width: max-content;
  will-change: transform;
}

[data-motion~="pin"] [data-pin-step] { will-change: transform, opacity; }

/* ---------------------------------------------------------------------------
   DEPTH — deck / scatter / float / pop. VBK-1976. Every primitive above this
   point moves in the XY plane; these four are the ones that read as depth.
   deck/scatter get `perspective` unconditionally: with no JS, their children
   simply sit in normal document flow (motion.js is the only thing that ever
   writes a transform onto them), so there is nothing here to gate behind
   `.js` or hide before the engine confirms it loaded.
   --------------------------------------------------------------------------- */

[data-motion~="deck"],
[data-motion~="scatter"] {
  perspective: var(--motion-perspective);
  /* VBK-1968 — a deck fans its outer cards WELL past their layout position
     (up to `mid * spread` px each way, so ±360px for five cards at the default
     120), and nothing clipped that. On a 360px-wide phone it is a guaranteed
     horizontal scrollbar and a page that slides sideways under the thumb.
     `overflow-x: clip` rather than `hidden`: `clip` can be applied to one axis
     on its own, so vertical shadows and any `pop` badge sitting proud of the
     section still spill normally, and it creates no scroll container of its
     own the way `hidden` would. The JS additionally clamps the spread to the
     container width — this is the belt to that braces, and it also covers a
     hand-authored `data-deck-spread` that is simply too large. */
  overflow-x: clip;
}
[data-motion~="deck"] > *,
[data-motion~="scatter"] > * {
  will-change: transform, opacity;
}

[data-motion~="float"] { will-change: transform; }

/* pop is a reveal-shaped primitive — hidden only once JS is confirmed alive,
   exactly like [data-motion~="reveal"] above, so a dead engine never hides
   content. */
.js [data-motion~="pop"] {
  opacity: 0;
  will-change: transform, opacity;
}

/* ---------------------------------------------------------------------------
   CHROME — sticky-shell / segment. VBK-1977. Both are functional UI, not
   decoration (a scroll-state header, a real tab switcher), so both are
   STATE-DRIVEN like the micro-interactions above: plain CSS transitions, no
   GSAP timeline, no scrub. motion.js only ever toggles a class or sets
   transform/width directly — never animates layout — matching the
   transform/opacity/filter/clip-path-only rule everywhere else in this file.
   --------------------------------------------------------------------------- */

/* STICKY SHELL — [data-motion~="sticky-shell"], normally the header. Give the
   header its own position: sticky/fixed — this primitive only supplies the
   scroll-state MORPH, not positioning. "Height contracts" is expressed as an
   optical transform rather than an actual height/padding change, which is why
   it stays off the forbidden-properties list while still reading as the bar
   visibly shrinking.

   VBK-2285 — IT MUST BE scaleY, NEVER scale.
   This was `transform: scale(0.94)`, and a uniform scale on a full-bleed bar
   shrinks it HORIZONTALLY too: the header pulled ~3% off each side and left a
   strip of page showing down both edges the moment you scrolled. Reported from
   several published sites, reproduced here at 1600px — 1585px wide normally,
   ~1490px condensed, inset ~55px a side. A header is the one element on a page
   that is always full-bleed, so this was visible on every site that used the
   primitive.

   scaleY alone contracts the height and leaves the width exactly as laid out.
   The children are counter-scaled by 1/0.94 so the contents are not squashed —
   the bar gets shorter, the type does not get shorter. */
[data-motion~="sticky-shell"] {
  transform-origin: top center;
  will-change: transform;
  transition: transform var(--motion-duration-base) var(--motion-ease),
              background-color var(--motion-duration-base) var(--motion-ease);
}
[data-motion~="sticky-shell"] > * {
  transform-origin: top center;
  transition: transform var(--motion-duration-base) var(--motion-ease);
}
[data-motion~="sticky-shell"].is-condensed {
  transform: scaleY(0.94);
  /* VBK-2285 — the old default was a hard-coded dark rgba(10, 10, 14, 0.72).
     On a light site that turned the header charcoal while its links stayed
     ink-black: dark on dark, unreadable, and nothing in the build could see it
     because the colour only appears once a visitor scrolls. The site's own
     surface token is the right answer; the dark constant survives only as the
     fallback for a page with no tokens at all. */
  background-color: var(--motion-shell-bg, rgba(10, 10, 14, 0.72));
  background-color: var(--motion-shell-bg, color-mix(in srgb, var(--surface, #0a0a0e) 86%, transparent));
}
[data-motion~="sticky-shell"].is-condensed > * { transform: scaleY(1.0638); }
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  [data-motion~="sticky-shell"] {
    transition: transform var(--motion-duration-base) var(--motion-ease),
                background-color var(--motion-duration-base) var(--motion-ease),
                backdrop-filter var(--motion-duration-base) var(--motion-ease);
  }
  [data-motion~="sticky-shell"].is-condensed {
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }
}
/* Hairline border — a pseudo-element faded in via opacity rather than an
   animated border-width/box-shadow spread, so the only property in motion is
   the one already on the allowed list. */
[data-motion~="sticky-shell"]::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  /* VBK-2285 — same reasoning as the background above: a white hairline is
     invisible on a light site and the site's own border token is the colour
     that belongs here. */
  border: 1px solid var(--motion-shell-border, var(--border, rgba(255, 255, 255, 0.14)));
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-duration-base) var(--motion-ease);
}
[data-motion~="sticky-shell"].is-condensed::after { opacity: 1; }
/* Optional nested wordmark — contracts an extra notch beyond the shell's own
   scale, which is what makes the logo read as its own, more deliberate move. */
[data-motion~="sticky-shell"] [data-shell-mark] {
  display: inline-block;
  transform-origin: left center;
  transition: transform var(--motion-duration-base) var(--motion-ease);
}
[data-motion~="sticky-shell"].is-condensed [data-shell-mark] { transform: scale(0.86); }

/* SEGMENT — [data-motion~="segment"] containing [data-segment-option] children
   and one [data-segment-indicator]. No-JS fallback: the active option is
   simply styled via [aria-selected="true"] below, and the indicator never
   appears at all — a legitimate resting state, not a broken one. With JS the
   indicator is hidden by the anti-FOUC gate above only until segmentControl()
   has measured the active option, then revealed by the `is-positioned` rule
   that sits directly beneath that gate. */
[data-motion~="segment"] {
  position: relative;
  display: inline-flex;
  gap: 2px;
}
[data-motion~="segment"] [data-segment-option] {
  position: relative;
  z-index: 1;
  background: none;
  border: none;
  cursor: pointer;
  transition: color var(--motion-duration-fast) var(--motion-ease);
}
[data-motion~="segment"] [data-segment-option][aria-selected="true"] {
  color: var(--motion-segment-active-color, inherit);
}
/* Width is SET, never transitioned — only the position (transform) slides.
   Transitioning width is exactly the layout-thrash this file's hard rule
   exists to prevent; snapping it while the position eases is the compliant
   way to get a sliding pill whose options are not all the same width. */
[data-motion~="segment"] [data-segment-indicator] {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  z-index: 0;
  will-change: transform;
  transition: transform var(--motion-duration-base) var(--motion-ease),
              opacity var(--motion-duration-fast) var(--motion-ease);
}

/* ---------------------------------------------------------------------------
   REDUCED MOTION. motion.js returns early and marks everything visible; this
   block is the belt to that braces, covering the CSS-only interactions too.
   --------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }

  .js .reveal,
  .js [data-motion~="reveal"],
  .js .stagger-children > *,
  .js [data-motion~="hero"] [data-hero-step],
  .js [data-motion~="hero-media"],
  .js [data-motion~="pop"] {
    opacity: 1 !important;
    transform: none !important;
  }

  /* VBK-1976 — belt to the braces above: motion.js never starts deck/scatter/
     float under reduced motion (it returns early, see the REDUCED branch), so
     these never carry an inline transform in practice. Neutralised here too,
     the same defence-in-depth as every other selector in this block. */
  [data-motion~="deck"] > *,
  [data-motion~="scatter"] > *,
  [data-motion~="float"] {
    transform: none !important;
  }

  /* VBK-1977 — scroll-scrubbed text: motion.js's own SplitText pass never runs
     under reduced motion (see the REDUCED branch), so a scrub never mutes a
     word's colour in the first place — this is belt to that braces, forcing
     full contrast regardless. Text stuck grey would be an accessibility
     regression, not a graceful degradation, so this is !important like every
     other neutraliser in this block. */
  [data-split-scrub] .motion-word,
  [data-split-scrub] .motion-char,
  [data-split-scrub] .motion-line {
    color: inherit !important;
  }

  /* VBK-1977 — sticky-shell and segment are STATE, not entrance animation:
     under reduced motion they must still track real scroll position / real
     selection (the shell renders in its scrolled state once scrolled, the
     segment indicator jumps to the selected option), so forcing
     transform/opacity to a fixed value here — as the primitives above do —
     would cancel the very state these express, not just its animation. The
     wildcard `transition-duration: 0.01ms` rule at the top of this block
     already makes that state change land instantly; this just says so
     explicitly for every selector these primitives introduce. */
  [data-motion~="sticky-shell"],
  [data-motion~="sticky-shell"]::after,
  [data-motion~="sticky-shell"] [data-shell-mark],
  [data-motion~="segment"] [data-segment-option],
  [data-motion~="segment"] [data-segment-indicator] {
    transition-duration: 0.01ms !important;
  }
}
