/*
  BashoClip motion system. Loaded on every page right after styles.css (scripts/build.mjs).
  Modelled on Apple's minimalist motion: one curve, one distance, one stagger. Text arrives once,
  quietly, and then stays; larger moves are reserved for product imagery.

  Rules (README › Motion):
  - Animate only transform, opacity, clip-path and filter. Never width/height/top/left/margin/padding.
  - Every hidden starting state is scoped to html.motion, which motion.js adds only when motion is
    allowed. Without JS, or with prefers-reduced-motion: reduce, nothing is hidden and nothing moves.
  - Markup carries only declarative opt-ins (data-reveal, data-reveal-group, data-reveal-delay,
    data-progress, data-scrub, data-observe). The state attributes (data-reveal-state, data-inview,
    data-step, data-pinned) are written by motion.js and never ship in the HTML.
  The API for other modules is documented in motion.js and in README › Motion.
*/
:root {
  /* Easing */
  --ease-standard: cubic-bezier(.4, 0, .6, 1);     /* reveals, state changes (Apple fit) */
  --ease-out: cubic-bezier(0, 0, .5, 1);           /* hover/press, small UI responses */
  --ease-out-soft: cubic-bezier(.33, 1, .68, 1);   /* crossfades of captions and labels */
  --ease-media: cubic-bezier(.165, .84, .44, 1);   /* media entrances (easeOutQuart) */
  --ease-scrub: linear;                            /* scroll-linked values are never eased twice */

  /* Durations */
  --dur-micro: 160ms;        /* hover, press */
  --dur-ui: 240ms;           /* nav state, toggles, header hairline */
  --dur-fade: 320ms;         /* crossfade between demo states or panels */
  --dur-reveal: 640ms;       /* transform part of a reveal */
  --dur-reveal-fade: 840ms;  /* opacity part of a reveal (about 1.3 x the transform) */
  --dur-media: 1100ms;       /* media entrances (story images, windows) */
  --dur-sweep: 1100ms;       /* a playhead or light sweeping a timeline once */

  /* Distances */
  --reveal-y: 30px;          /* Apple's value; 20px on phones */
  --scrub-y: 10px;           /* text inside pinned stories */
  --media-scale-from: .94;   /* scrubbed media scale-in start; never below .9 */

  /* Rhythm */
  --stagger: 150ms;          /* lines, cards, steps */
  --stagger-fine: 40ms;      /* bars, words, chips inside one object; cap the total at 600ms */
}
@media (max-width: 640px) {
  :root { --reveal-y: 20px; --stagger: 110ms; }
}

/* P1/P2 reveal: fade up once, when the element's top crosses 88% of the viewport height.
   --i is the position inside a reveal group (or data-reveal-delay), set by motion.js. */
.motion [data-reveal] {
  --reveal-delay: calc(var(--i, 0) * var(--stagger));
  transition: transform var(--dur-reveal) var(--ease-standard) var(--reveal-delay), opacity var(--dur-reveal-fade) var(--ease-standard) var(--reveal-delay);
}
.motion [data-reveal][data-reveal-state=pending] { opacity: 0; transform: translate3d(0, var(--reveal-y), 0); }
.motion [data-reveal=fade][data-reveal-state=pending] { transform: none; }
/* Media blocks (demo frames, windows): a slightly longer, softer arrival with a hint of scale. */
.motion [data-reveal=media] { transition: transform var(--dur-media) var(--ease-media) var(--reveal-delay), opacity var(--dur-reveal-fade) var(--ease-standard) var(--reveal-delay); }
.motion [data-reveal=media][data-reveal-state=pending] { transform: translate3d(0, calc(var(--reveal-y) * 1.33), 0) scale(.97); }
/* Promote only while the reveal runs (about 1s); pending elements can wait the whole session. */
.motion [data-reveal][data-reveal-state=in] { will-change: transform, opacity; }
/* Keyboard focus landed inside a pending block (motion.js): show it at once, no fade. */
.motion [data-reveal][data-reveal-instant] { transition: none; }

/* Two-line headings: each line is its own block so it can be staggered. A space between the
   spans keeps the text readable when copied; between blocks it does not render. */
.h-line { display: block; }
h1 .h-line, h2 .h-line { color: inherit; }

/* P3 scrubbed media scale-in: --progress goes 0 -> 1 while the element's top moves from the
   bottom of the viewport to 45% of its height (motion.js, data-progress="enter").
   The default of 1 means full size without JS, with reduced motion and on phones. */
.motion [data-scrub=media] {
  transform: scale(calc(var(--media-scale-from) + (1 - var(--media-scale-from)) * var(--progress, 1)));
  transform-origin: 50% 100%;
}
@media (max-width: 640px) {
  .motion [data-scrub=media] { transform: none; }
}

/* P5 crossfade helper for modules: remove and re-add .caption-in to replay it on changed text. */
@keyframes motion-caption-in { from { opacity: 0; transform: translate3d(0, 6px, 0); } }
.motion .caption-in { animation: motion-caption-in var(--dur-ui) var(--ease-out-soft) both; }

/* P9 header: translucent with backdrop blur; the hairline appears once the page has scrolled.
   motion.js sets data-scrolled on <html> from a sentinel (no scroll handler). Without JS the
   hairline stays visible, as before. The header itself never hides. */
.site-header::after { content: ''; position: absolute; inset-inline: 0; bottom: -1px; height: 1px; background: var(--line); pointer-events: none; transition: opacity var(--dur-ui) var(--ease-standard); }
/* With scripting the hairline starts hidden (no flash before motion.js runs); without JS it stays. */
@media (scripting: enabled) {
  html[data-scrolled=false] .site-header::after { opacity: 0; }
  /* Before motion.js runs; if it never does, the hairline comes back after 3s. */
  html:not([data-scrolled]) .site-header::after { opacity: 0; animation: motion-fallback-show 1ms 3s forwards; }
}
@keyframes motion-fallback-show { to { opacity: 1; } }
.motion-sentinel { position: absolute; top: 0; left: 0; width: 1px; height: 8px; pointer-events: none; visibility: hidden; }

/* P10 micro-interactions */
.button { transition: background-color var(--dur-micro) var(--ease-out), transform var(--dur-micro) var(--ease-out); }
.button:active { transform: scale(.98); }
.text-link svg { transition: transform var(--dur-micro) var(--ease-out); }
.site-header nav > a, .lang-switch a, .footer nav a, .help-jump a { transition: color var(--dur-ui) var(--ease-standard); }

/* Opening an FAQ fades its answer in; the height is never animated. */
@keyframes motion-details-in { from { opacity: 0; transform: translate3d(0, -4px, 0); } }
.motion details[open] > p { animation: motion-details-in var(--dur-fade) var(--ease-out-soft); }

/* Print / PDF: everything visible, whatever has been scrolled to. motion.js also settles the page
   modules on beforeprint; these rules cover browsers that print without that event. */
@media print {
  .motion [data-reveal] { opacity: 1 !important; transform: none !important; transition: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  /* motion.js never adds .motion here; this is a second line of defence for the header. */
  .site-header::after { transition: none; }
}
