/* AISOC in-a-box — motion system for "Signal in the Dark" (design language v1).
   Pairs with packages/ui-kit/motion.js (the JS primitives). Copied into
   dist/ by docs-site/build.py; the showcase page (design-language.html)
   and any future marketing section pull from here.

   Doctrine:
   - transform + opacity only (no layout-property animation)
   - springs for user-touchable motion (JS, in motion.js); keyframes here
     are for one-shot entrances, ambient loops, and scroll choreography
   - scroll reveals ride `animation-timeline: view()` / `scroll()` where
     supported — zero JS scroll listeners; content is statically visible
     without JS (hidden states are opt-in classes)
   - the reduced-motion matrix at the bottom neutralizes everything:
     the settled frame is the reduced-motion render, never content loss */

:root {
  /* shared easings — the only curves the motion system uses */
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);   /* decelerate: entrances, exits */
  --ease-snap: cubic-bezier(0.32, 0.72, 0, 1);     /* sharper settle: chips, rows */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1); /* CSS approximation for one-shot bounces (JS springs own the rest) */
}

/* ── keyframes ──────────────────────────────────────────────────────── */

/* scroll reveal (driven by view() timeline or the .rv--on transition) */
@keyframes rv-in {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: none; }
}

/* hero signature: per-word clip reveal (word sits in an overflow-hidden
   span; the inner span rides up under the clip — mask, not slide) */
@keyframes word-up {
  from { transform: translateY(115%); }
  to   { transform: none; }
}
/* tracking tightens from -0.03em to the final --tracking-display */
@keyframes tracking-in {
  from { letter-spacing: -0.03em; }
  to   { letter-spacing: var(--tracking-display, -0.022em); }
}

@keyframes caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* packet flow marquee (dashed line = the tunnel; offset drifts so the
   dashes read as movement in the direction of travel) */
@keyframes flow-dash {
  to { stroke-dashoffset: -150; }
}

/* approve ripple from pointer position (.ripple-dot is a span placed by JS) */
@keyframes ripple {
  from { transform: scale(0); opacity: 0.5; }
  to   { transform: scale(2.8); opacity: 0; }
}

/* copy-button morph: label slides up out, check slides in (same path) */
@keyframes morph-out { to { transform: translateY(-110%); opacity: 0; } }
@keyframes morph-in  { from { transform: translateY(110%); opacity: 0; } }

/* triage burst (one-shot; JS springs own anything interactive) */
@keyframes burst {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* status-light breathing (live indicators: hero eyebrow dot, box-art LED) —
   migrated in at the retirement of the ui-kit keyframe sheet (aiso-16d.1);
   the reduced-motion matrix below settles the loop fully lit */
@keyframes breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* docs-shell tab panel fade (usage in styles.css .tabs-panel.is-active) —
   moved here so styles.css carries no @keyframes of its own (gate §4) */
@keyframes tab-fade { from { opacity: 0; } to { opacity: 1; } }

/* one-shot entrance (portal: .timeline li.transition in globals.css) —
   revived from the retired ui-kit keyframe sheet (aiso-8w0); the portal
   never linked animations.css, so its transition rows were static until
   the keyframe moved here with the rest (aiso-kdz); opacity only */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ── scroll choreography (2026 baseline CSS) ──────────────────────────
   `.rv` = reveal-on-scroll utility. Base hidden state applies only once
   JS adds the class (motion.js revealOnScroll) — no-JS readers see static
   content. Where view() timelines exist, the reveal is pure CSS: no JS
   scroll listeners at all. */
/* Hidden-until-reveal base — gated on html.js so no-JS readers see the page.
   The pure-CSS view() animation owns its own hidden pre-entry state in
   supporting browsers (the @supports block below), so this rule is only
   needed for the IO-fallback path in supporting-and-unsupported browsers. */
html.js .rv {
  opacity: 0;
  transform: translateY(18px);
}
.rv--on {
  opacity: 1;
  transform: none;
  transition: opacity 520ms var(--ease-out), transform 520ms var(--ease-out);
  transition-delay: var(--rv-delay, 0ms);
}
@supports (animation-timeline: view()) {
  .rv {
    /* the animation (both-fill) overrides the hidden base above */
    opacity: 1;
    transform: none;
    animation: rv-in linear both;
    animation-timeline: view();
    animation-range: entry 5% entry 60%;
  }
}

/* progress indicator as pure CSS scroll-timeline (no JS) */
.scroll-progress {
  height: 3px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  transform: scaleX(0);
  transform-origin: 0 50%;
}
@supports (animation-timeline: scroll()) {
  .scroll-progress {
    animation: progress-grow linear both;
    animation-timeline: scroll(root);
  }
}
@keyframes progress-grow {
  to { transform: scaleX(1); }
}
/* fallback (no scroll() support): JS-free static rule, no growth */

/* section-side progress rail (the showcase's tab sections use it) */
.section-rail {
  position: relative;
}
.section-rail::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--line-soft);
}
.section-rail::after {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--accent-interactive);
  transform: scaleY(0);
  transform-origin: 0 50%;
}
@supports (animation-timeline: view()) {
  .section-rail::after {
    animation: rail-grow linear both;
    animation-timeline: view();
    animation-range: entry 0% exit 100%;
  }
}
@keyframes rail-grow {
  from { transform: scaleY(0); }
  to   { transform: scaleY(1); }
}

/* ── hero type motion ─────────────────────────────────────────────────
   .clip-hero h1: words wrapped in <span class="cw"><span>word</span></span>
   with --i index; stagger 40ms. One-shot on load. */
.clip-hero .cw {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
  padding-bottom: 0.08em; /* descenders survive the clip */
  margin-bottom: -0.08em;
}
.clip-hero .cw > span {
  display: inline-block;
  transform: translateY(115%);
  animation: word-up 620ms var(--ease-out) forwards;
  animation-delay: calc(120ms + var(--i, 0) * 40ms);
}
.clip-hero h1 {
  letter-spacing: -0.03em;
  animation: tracking-in 900ms var(--ease-out) 200ms forwards;
}

/* code typewriter (first view only): pre.type-once gets the animation,
   a caret rides the reveal; motion.js strips .type-once when done */
pre.type-once code, pre.type-once {
  clip-path: inset(-10% -2% -10% 0);
}
@keyframes pre-type {
  from { clip-path: inset(-10% 100% -10% 0); }
  to   { clip-path: inset(-10% -2% -10% 0); }
}
html.js pre.type-once {
  animation: pre-type 1.1s steps(36, end) both;
}
html.js pre.type-once .caret {
  display: inline-block;
  width: 0.55ch;
  background: var(--accent-interactive);
  margin-left: 2px;
  animation: caret-blink 1s step-end infinite;
  animation-delay: 1.1s;
}

/* ── micro-delight utilities ────────────────────────────────────────── */

/* ripple host: position:relative; overflow:hidden; .ripple-dot is 1px,
   positioned by JS at the pointer, animated by @keyframes ripple */
.ripple-host { position: relative; overflow: hidden; }
.ripple-dot {
  position: absolute;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--accent-interactive);
  pointer-events: none;
  animation: ripple 520ms var(--ease-out) forwards;
}

/* copy-button morph (label ⇄ check share one path, enter/exit same path) */
.morph-btn { position: relative; overflow: hidden; }
.morph-btn .morph-a, .morph-btn .morph-b {
  display: inline-block;
  transition: transform 260ms var(--ease-snap), opacity 260ms var(--ease-snap);
}
.morph-btn.is-done .morph-a { transform: translateY(-110%); opacity: 0; }
.morph-btn.is-done .morph-b { transform: none; opacity: 1; }
.morph-btn:not(.is-done) .morph-b { transform: translateY(110%); opacity: 0; }

/* packet flow (JS primitive adds the class; see motion.js packetFlow) */
.packet-flow-path {
  stroke-dasharray: 6 9;
  animation: flow-dash var(--flow-speed, 6s) linear infinite;
}
.packet-flow-dot {
  fill: var(--flow-ink, var(--accent-interactive));
  filter: drop-shadow(0 0 4px var(--accent-glow));
}

/* verdict chip settle (JS stampIn drives the transform; this is the
   ambient part: the chip's glow fades to rest after the stamp) */
.stamp-chip {
  box-shadow: var(--inset-highlight);
}
.stamp-chip.stamped {
  animation: chip-settle 900ms var(--ease-snap) forwards;
}
@keyframes chip-settle {
  0%   { box-shadow: var(--inset-highlight), 0 0 0 1px var(--accent-glow); }
  100% { box-shadow: var(--inset-highlight), 0 0 0 0 transparent; }
}

/* triage burst node (one-shot per event) */
.burst-node { animation: burst 700ms var(--ease-spring) 1; }

/* ── reduced-motion matrix ────────────────────────────────────────────
   Three media features, three consequences. The settled state IS the
   reduced render — no content loss, no missing information. */

/* 1 · motion: stop movement; reveals land in the visible state */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .rv, .rv--on { opacity: 1 !important; transform: none !important; }
  .clip-hero .cw > span { transform: none !important; }
  .clip-hero h1 { letter-spacing: var(--tracking-display, -0.022em) !important; }
  html.js pre.type-once { animation: none !important; }
  html.js pre.type-once .caret { display: none !important; }
  .packet-flow-path { animation: none !important; } /* static dashed line */
  /* status-light breathers settle fully lit (settled frame, not content loss) */
  .hero .eyebrow .dot, .box-art .led { animation: none !important; }
  .scroll-progress { transform: scaleX(1) !important; }
  .section-rail::after { transform: scaleY(1) !important; }
}

/* 2 · transparency: drop backdrop blur and translucent depth; use solid
   surface tints from the luminance ladder instead */
@media (prefers-reduced-transparency: reduce) {
  .dl-hero, .dl-hero * { backdrop-filter: none !important; }
  [data-solid-under-reduce] { background: var(--bg-elevated) !important; }
}

/* 3 · data: ambient loops (particles, marquee dashes, breathers) cost
   frames; keep only the static frame. (data-saver: browsers with
   low-data mode) */
@media (prefers-reduced-data: reduce) {
  .ambient, .ambient * { animation: none !important; }
  .packet-flow-path { animation: none !important; }
}
