/* Dinged motion kit (styles). Behaviour: /js/motion.js. Contract and recipes: web/MOTION.md.
   Loaded on every page after styles.css and nav.css, before the page stylesheet.

   Rules the kit keeps, and every page should too:
   - Only transform, opacity, clip-path, filter and stroke-dashoffset move. Never width/height/top/left/margin.
   - Start states exist only with JS on (html.js, set before first paint by boot.js) and motion allowed. Without JS,
     or with reduced motion, everything is simply there. If motion.js never arrives, the failsafe below shows it all.
   - Entrances are CSS animations with fill "backwards": once they end they leave nothing behind, so the element's
     own transitions (hover, press, tilt) behave exactly as written. */

:root{
  --ease-out-soft: cubic-bezier(.16,1,.3,1);      /* long arrivals */
  --ease-in: cubic-bezier(.5,0,.75,0);            /* exits: quicker than entrances */
  --ease-spring: cubic-bezier(.34,1.56,.64,1);    /* things you touched: one small overshoot */
  --ease-spring-soft: cubic-bezier(.3,1.25,.5,1);
  --dur-micro: .16s;   /* press, hover */
  --dur-ui: .28s;      /* menus, toggles, tabs */
  --dur-move: .5s;     /* something travels */
  --dur-reveal: .9s;   /* a section arrives */
}
@supports (transition-timing-function: linear(0, 1)){
  :root{
    --ease-spring: linear(0, .009, .035 2.1%, .141, .281 6.7%, .723 12.9%, .938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, .991, .977 51%, .974 53.8%, .975 57.1%, .997 69.8%, 1.003 76.9%, 1.004 83.8%, 1);
    --ease-spring-soft: linear(0, .006, .025 2.8%, .101 6.1%, .539 18.9%, .721 25.3%, .849 31.5%, .937 38.1%, .968 41.8%, .991 45.7%, 1.006 50.1%, 1.015 55%, 1.017 63.9%, 1.001 85.9%, 1);
  }
}

/* The shared stagger/delay clock: data-delay="<ms>" sets --delay, motion.js sets --i on staggered items. */
[data-rise], [data-stagger] > *, .sw-i, [data-draw]{
  animation-delay:calc(var(--delay, 0ms) + var(--i, 0) * var(--stagger, 80ms));
}

@media (prefers-reduced-motion: no-preference){
  /* ---------- data-rise: arrive on scroll (default: up) ---------- */
  .js [data-rise]:not(.is-in), .js [data-stagger]:not(.is-in) > *{ opacity:0; }
  .js [data-rise="clip"]:not(.is-in){ opacity:1; clip-path:inset(0 0 100% 0); }
  .js [data-rise].is-in, .js [data-stagger].is-in > *{
    animation-name:dg-rise; animation-duration:var(--rise-dur, var(--dur-reveal)); animation-timing-function:var(--ease-out); animation-fill-mode:backwards;
  }
  [data-rise="left"]{ --rise-x:-40px; --rise-y:0px; }
  [data-rise="right"]{ --rise-x:40px; --rise-y:0px; }
  [data-rise="scale"]{ --rise-y:0px; --rise-s:.92; }
  [data-rise="fade"]{ --rise-y:0px; }
  .js [data-rise="blur"].is-in{ animation-name:dg-rise-blur; }
  .js [data-rise="clip"].is-in{ animation-name:dg-rise-clip; animation-timing-function:var(--ease-in-out); }

  /* ---------- data-split: a heading arrives word by word, each word rising out of its own line box ---------- */
  .js [data-split]:not(.is-split){ opacity:0; }
  .js [data-split].is-split:not(.is-in) .sw-i{ transform:translate3d(0,115%,0); }
  .js [data-split].is-in .sw-i{ animation:dg-word var(--split-dur, 1s) var(--ease-out-soft) backwards; animation-delay:calc(var(--delay, 0ms) + var(--i, 0) * var(--stagger, 55ms)); }

  /* ---------- data-draw: an SVG stroke draws itself (motion.js sets pathLength="1") ---------- */
  .js [data-draw]{ stroke-dasharray:1; }
  .js [data-draw]:not(.is-in){ stroke-dashoffset:1; }
  .js [data-draw].is-in{ animation-name:dg-draw; animation-duration:var(--draw-dur, 1.2s); animation-timing-function:var(--ease-in-out); animation-fill-mode:backwards; }

  /* motion.js never arrived (blocked, offline, an error before it ran): show everything after a beat. */
  .js:not(.motion) :is([data-rise], [data-stagger] > *, [data-split], [data-draw]){ animation:dg-failsafe 1ms linear 3s forwards; }
}
@keyframes dg-rise{ from{ opacity:0; transform:translate3d(var(--rise-x, 0px), var(--rise-y, 28px), 0) scale(var(--rise-s, 1)); } }
@keyframes dg-rise-blur{ from{ opacity:0; filter:blur(14px); transform:translate3d(0, var(--rise-y, 28px), 0); } }
@keyframes dg-rise-clip{ from{ clip-path:inset(0 0 100% 0); } to{ clip-path:inset(0 0 0 0); } }
@keyframes dg-word{ from{ transform:translate3d(0,115%,0); } }
@keyframes dg-draw{ from{ stroke-dashoffset:1; } }
@keyframes dg-failsafe{ to{ opacity:1; transform:none; clip-path:none; stroke-dashoffset:0; } }

/* Split words: the outer box clips, the inner one moves. The padding/negative margin pair gives descenders and
   tight display tracking room inside the clip without changing the line's metrics. */
.sw{ display:inline-block; overflow:clip; padding:.12em .06em .2em; margin:-.12em -.06em -.2em; }
.sw-i{ display:inline-block; will-change:transform; }
@supports not (overflow: clip){ .sw{ overflow:hidden; vertical-align:bottom; } }

/* ---------- data-tilt: follows the pointer in 3D (motion.js springs --rx/--ry, sets --gx/--gy 0..1) ----------
   Put no other transform on a tilt element; wrap it instead. */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference){
  .motion [data-tilt]{ transform:perspective(var(--tilt-perspective, 1100px)) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transform-style:preserve-3d; }
}

/* ---------- data-parallax / data-magnet: the individual translate property, so transform stays yours ---------- */
@media (prefers-reduced-motion: no-preference){
  .motion [data-parallax]{ translate:0 var(--py, 0px); will-change:translate; }
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference){
  .motion [data-magnet]{ translate:var(--mx, 0px) var(--my, 0px); }
}

/* ---------- data-count: numbers hold their column while they run ---------- */
[data-count]{ font-variant-numeric:tabular-nums; }

@media print{
  [data-rise], [data-stagger] > *, [data-split], .sw-i, [data-draw]{ opacity:1 !important; transform:none !important; clip-path:none !important; stroke-dashoffset:0 !important; animation:none !important; }
}
