/* motion.css — lightweight CSS-only motion variants.
   All animation is gated by a root data-motion attribute of
   "subtle" or "lively". Default and data-motion="still" are static.
   No transitions, no blinking, no position/top/left animations. */

:root {
  --delivery-duration: 6.6s;
  --flow-duration: 8s;
  --rail-duration: 6s;
  --delivery-amp: 30;
}

:root[data-motion="lively"] {
  --delivery-duration: 3.6s;
  --flow-duration: 4.8s;
  --rail-duration: 3s;
  --delivery-amp: 34; /* slightly stronger signal, same geometry */
}

/* ----- Scene in-view plumbing: common play-state via inherited var ----- */
.motion-element {
  /* Keep scene suspension authoritative over the mode's animation shorthand. */
  animation-play-state: var(--scene-play, paused) !important;
}
.motion-scene {
  --scene-play: paused;
}
.motion-scene[data-in-view="true"] {
  --scene-play: running;
}

/* Transforms on SVG shapes */
.delivery-dot {
  transform-box: fill-box;
  transform-origin: center;
}

/* ----- Delivery dots: continuous vertical relay, fade at boundaries ----- */
@keyframes delivery-relay {
  0%   { transform: translateY(calc(var(--direction) * calc(var(--delivery-amp) * -1px))); opacity: 0; }
  12%  { opacity: 1; }
  50%  { transform: translateY(0); opacity: 1; }
  88%  { opacity: 1; }
  100% { transform: translateY(calc(var(--direction) * calc(var(--delivery-amp) * 1px))); opacity: 0; }
}

/* ----- Flow beads & rail beads: travel along existing path ----- */
@keyframes flow-travel {
  0%   { stroke-dashoffset: 100; }
  100% { stroke-dashoffset: 0; }
}

/* Only arm animations and show moving overlays under subtle/lively. */
:root[data-motion="subtle"] .delivery-dot,
:root[data-motion="lively"] .delivery-dot {
  animation: delivery-relay var(--delivery-duration) linear infinite;
  animation-duration: var(--delivery-duration) !important;
  animation-delay: calc(var(--phase, 0) * var(--delivery-duration) / -3);
}

.flow-trace,
.motion-rail .rail-trace {
  /* Hidden by default (Still, no-attribute) so static shows original image */
  opacity: 0;
}
.motion-rail .rail-trace {
  stroke-dasharray: 1.4 98.6;
}

:root[data-motion="subtle"] .flow-trace,
:root[data-motion="lively"] .flow-trace {
  opacity: 1;
  animation: flow-travel var(--flow-duration) linear infinite;
  animation-duration: var(--flow-duration) !important;
  animation-delay: calc(var(--phase, 0) * var(--flow-duration) / -3);
}

:root[data-motion="subtle"] .motion-rail .rail-trace,
:root[data-motion="lively"] .motion-rail .rail-trace {
  opacity: 1;
  animation: flow-travel var(--rail-duration) linear infinite;
  animation-duration: var(--rail-duration) !important;
  animation-delay: calc(var(--phase, 0) * var(--rail-duration) / -3);
}

/* ----- Explicit Still: static, fixed pip positions at full opacity ----- */
:root[data-motion="still"] .motion-element {
  animation: none !important;
}
:root[data-motion="still"] .delivery-dot {
  transform: none !important;
  opacity: 1 !important;
}
:root[data-motion="still"] .flow-trace,
:root[data-motion="still"] .motion-rail .rail-trace {
  opacity: 0 !important;
}

/* ----- Global pause switches (page/preview/cookie panel) ----- */
html[data-motion-paused="true"] .motion-element,
html[data-page-visible="false"] .motion-element {
  animation-play-state: paused !important;
}

body:has(.cookie-panel:not([hidden])) .motion-rail .motion-element {
  animation-play-state: paused !important;
}

/* ----- Reduced motion: no animation, static final presentation ----- */
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion-override="true"]) .motion-element { animation: none !important; }
  :root:not([data-motion-override="true"]) .delivery-dot {
    transform: none !important;
    opacity: 1 !important;
  }
  :root:not([data-motion-override="true"]) .flow-trace,
  :root:not([data-motion-override="true"]) .motion-rail .rail-trace {
    opacity: 0 !important;
  }
}

/* insight-banner.css
 * Additive motion rules for the Insight scene and the top-of-nav banner stream.
 * Relies on existing plumbing: --scene-play, data-in-view, data-motion-paused,
 * data-page-visible, data-preview, and rail cookie-panel pausing.
 */

/* ---- Mode duration tokens at root ---- */
:root[data-motion="subtle"] {
  --insight-scan-dur: 11s;
  --insight-dot-dur: 6s;
  --banner-signal-dur: 9s;
}
:root[data-motion="lively"] {
  --insight-scan-dur: 6s;
  --insight-dot-dur: 3.6s;
  --banner-signal-dur: 5s;
}

/* ---- Base layout for the banner inside the family rail ---- */
.family-rail .banner-stream {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 8px;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.family-rail > a, .family-rail > .rail-practices { position: relative; z-index: 1; }

/* ---- Static defaults (no animation until a mode arms them) ---- */
.insight-scan, .banner-signal { visibility: hidden; }
.motion-insight .insight-dot {
  transform-box: fill-box;
  transform-origin: center;
}

/* ---- Keyframes ---- */
@keyframes insight-scan-sweep {
  from { stroke-dashoffset: 100; }
  to   { stroke-dashoffset: 0; }
}

@keyframes insight-dot-drift {
  0%   { transform: translateX(-18px); opacity: 0; }
  12%  { opacity: 1; }
  88%  { transform: translateX(18px); opacity: 1; }
  100% { transform: translateX(18px); opacity: 0; }
}

@keyframes banner-signal-run {
  from { stroke-dashoffset: 100; }
  to   { stroke-dashoffset: 0; }
}

/* ---- Subtle / Lively arm the animations ---- */
:root[data-motion="subtle"] .motion-insight .insight-scan,
:root[data-motion="lively"] .motion-insight .insight-scan {
  visibility: visible;
  animation: insight-scan-sweep var(--insight-scan-dur) linear infinite;
  animation-duration: var(--insight-scan-dur) !important;
}

:root[data-motion="subtle"] .motion-insight .insight-dot,
:root[data-motion="lively"] .motion-insight .insight-dot {
  animation: insight-dot-drift var(--insight-dot-dur) ease-in-out infinite;
  animation-duration: var(--insight-dot-dur) !important;
  animation-delay: calc(var(--phase, 0) * var(--insight-dot-dur) / -3);
}

:root[data-motion="subtle"] .banner-stream .banner-signal,
:root[data-motion="lively"] .banner-stream .banner-signal {
  visibility: visible;
  animation: banner-signal-run var(--banner-signal-dur) linear infinite;
  animation-duration: var(--banner-signal-dur) !important;
  animation-delay: calc(var(--phase, 0) * var(--banner-signal-dur) / -3);
}

/* ---- Banner pause when cookie panel is open (banner is outside .motion-rail) ---- */
body:has(.cookie-panel:not([hidden])) .banner-stream .motion-element {
  animation-play-state: paused !important;
}

/* ---- Still: hide/reset moving marks, keep static shapes ---- */
:root[data-motion="still"] .motion-insight .insight-scan,
:root[data-motion="still"] .banner-stream .banner-signal {
  animation: none !important;
  visibility: hidden;
}
:root[data-motion="still"] .motion-insight .insight-dot {
  animation: none !important;
  transform: none;
  opacity: 1;
}

/* ---- Reduced-motion fallback, bypassable by explicit local preview opt-in ---- */
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion-override="true"]) .motion-insight .insight-scan,
  :root:not([data-motion-override="true"]) .banner-stream .banner-signal {
    animation: none !important;
    visibility: hidden;
  }
  :root:not([data-motion-override="true"]) .motion-insight .insight-dot {
    animation: none !important;
    transform: none;
    opacity: 1;
  }
}

/* footer-motion.css — strictly additive motion layer for the folded ribbon footer scene.
   Parent already provides:
     .motion-element { animation-play-state: var(--scene-play, paused) !important; }
     .motion-scene   { --scene-play: paused; }
     .motion-scene[data-in-view="true"] { --scene-play: running; }
     and a global reduced-motion universal rule setting animation-duration to .01ms.
   We never override animation-play-state here. */

/* ---------- Keyframes ---------- */
@keyframes footer-float {
  0%   { transform: translate3d(0, 0, 0); }
  50%  { transform: translate3d(0, var(--float, 0px), 0); }
  100% { transform: translate3d(0, 0, 0); }
}

@keyframes footer-glint-travel {
  from { stroke-dashoffset: 100; }
  to   { stroke-dashoffset: 0; }
}

/* ---------- Default (no mode / unknown mode): hold static, hide glints ---------- */
.motion-footer .footer-glint { opacity: 0; }

/* Ensure layout transforms originate from the viewBox so SVG maths stay predictable */
.motion-footer .footer-ribbon,
.motion-footer .footer-fold,
.motion-footer .footer-glint {
  transform-box: view-box;
  transform-origin: center;
}

/* ---------- SUBTLE mode ---------- */
:root[data-motion="subtle"] .motion-footer .footer-ribbon,
:root[data-motion="subtle"] .motion-footer .footer-fold {
  animation-name: footer-float;
  animation-duration: 12s !important;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-delay: calc(-12s * var(--phase, 0) / 3);
}

:root[data-motion="subtle"] .motion-footer .footer-glint {
  opacity: 1;
  animation-name: footer-glint-travel;
  animation-duration: 12s !important;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-delay: calc(-12s * var(--phase, 0) / 3);
}

/* ---------- LIVELY mode ---------- */
:root[data-motion="lively"] .motion-footer .footer-ribbon,
:root[data-motion="lively"] .motion-footer .footer-fold {
  animation-name: footer-float;
  animation-duration: 7.2s !important;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-delay: calc(-7.2s * var(--phase, 0) / 3);
}

:root[data-motion="lively"] .motion-footer .footer-glint {
  opacity: 1;
  animation-name: footer-glint-travel;
  animation-duration: 7s !important;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-delay: calc(-7s * var(--phase, 0) / 3);
}

/* ---------- STILL mode: reset everything, keep art exactly static ---------- */
:root[data-motion="still"] .motion-footer .footer-ribbon,
:root[data-motion="still"] .motion-footer .footer-fold,
:root[data-motion="still"] .motion-footer .footer-glint {
  animation: none !important;
  transform: none !important;
}
:root[data-motion="still"] .motion-footer .footer-glint { opacity: 0; }

/* ---------- Reduced motion: honour unless an explicit local preview opt-in is set ---------- */
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion-override="true"]) .motion-footer .footer-ribbon,
  :root:not([data-motion-override="true"]) .motion-footer .footer-fold,
  :root:not([data-motion-override="true"]) .motion-footer .footer-glint {
    animation: none !important;
    transform: none !important;
  }
  :root:not([data-motion-override="true"]) .motion-footer .footer-glint {
    opacity: 0;
  }
}
