/* ==========================================================================
   Chi Ventures website: motion. Everything that moves, in one file.

   Linked after site.css with media="(prefers-reduced-motion: no-preference)", and every rule sits
   inside :root:not(.motion-off). So:
   - devices that ask for reduced motion don't apply this file (unless the visitor turns motion on
     with the header switch: motion.js then sets the link's media to "all");
   - the header switch turns motion off by adding .motion-off to <html>, and nothing here applies.
   Off and reduced motion are therefore the same code path: the page as site.css alone draws it,
   every element in its final state.
   The two loops that run longer than 5 s (the hero's light pulses and the capability band) also
   need .js, which motion.js adds, so they only run where the header switch exists to stop them
   (WCAG 2.2.2). Keyframes and @property rules stay in site.css. CSS nesting: Chrome 112, Safari
   16.5, Firefox 117 and later; older browsers drop this file and show the still page.
   ========================================================================== */

/* Page transitions between the site's pages. When motion is off, motion.js skips the transition
   as the page is left (pageswap). */
@view-transition { navigation: auto; }

:root:not(.motion-off) {
  /* ---- block 1 (from site.css) ---- */
  /* Smooth only after something has focus (a clicked or tabbed-to link), so opening the page at
     a #fragment jumps straight there instead of gliding down the whole page. */
  &:focus-within { scroll-behavior: smooth; }
  /* only while hovered, so nothing animates as the page loads */
  a:hover, .button:hover { transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease; }

  /* ---- block 2 (from site.css) ---- */

  /* Hero opening sequence: plays once, about 2.4 s. The headline is fully in by 0.85 s. */
  .tagline { isolation: isolate; }
  .tagline-word { position: relative; animation: rise-in 0.55s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .tagline-word:nth-child(1) { animation-delay: 0.05s; }
  .tagline-word:nth-child(2) { animation-delay: 0.17s; }
  .tagline-word:nth-child(3) { animation-delay: 0.29s; }
  .tagline-word::after {                 /* C, H, I light up in turn, spelling CHI */
    content: "";
    position: absolute;
    z-index: -1;
    left: -0.22em;
    top: 50%;
    width: 1.25em;
    height: 1.25em;
    translate: 0 -50%;
    border-radius: 50%;
    background: radial-gradient(closest-side, color-mix(in srgb, var(--initial) 45%, transparent), transparent);
    opacity: 0;
    pointer-events: none;
    animation: initial-glow 0.8s ease-out both;
  }
  .tagline-word:nth-child(1)::after { animation-delay: 0.95s; }
  .tagline-word:nth-child(2)::after { animation-delay: 1.2s; }
  .tagline-word:nth-child(3)::after { animation-delay: 1.45s; }
  .hero .lead { animation: rise-in 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) 0.4s both; }
  .hero .button-row { animation: rise-in 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) 0.55s both; }

  .hero-panel::before { animation: fade-in 0.7s ease-out both; }
  .hero-panel::after {                   /* scan line sweeps the grid once */
    content: "";
    position: absolute;
    z-index: 2;
    inset: 0 0 auto 0;
    height: 32%;
    background: linear-gradient(to bottom, transparent,
      color-mix(in srgb, var(--chi-accent) 14%, transparent) 80%,
      color-mix(in srgb, var(--chi-accent) 65%, transparent) 99%, transparent);
    opacity: 0;
    pointer-events: none;
    animation: scan 1s cubic-bezier(0.45, 0, 0.55, 1) 0.25s both;
  }
  .ring-draw { animation: draw 1s cubic-bezier(0.6, 0.05, 0.3, 1) 0.4s both; }
  .mark-v { animation: v-drop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 1s both; }
  .mark-arrow { animation: arrow-launch 0.55s cubic-bezier(0.15, 0.8, 0.25, 1) 1.35s both; }
  .mark-trail { animation: trail 1.05s ease-out 1.3s both; }

  /* Ambient: light pulses along the traces. Loops, so it has a pause switch (WCAG 2.2.2),
     and it pauses while the hero is off screen (motion.js). */
  &.js .pulse { animation: pulse-run 3.6s linear 2.3s infinite; }
  .pulse:nth-child(2) { animation-duration: 4.4s; animation-delay: 3s; }
  .pulse:nth-child(3) { animation-duration: 3.2s; animation-delay: 2.6s; }
  .pulse:nth-child(4) { animation-duration: 4.8s; animation-delay: 3.6s; }
  .pulse:nth-child(5) { animation-duration: 3.9s; animation-delay: 2.9s; }
  .pulse:nth-child(6) { animation-duration: 4.2s; animation-delay: 3.3s; }
  .hero-panel.is-offscreen .pulse { animation-play-state: paused; }

  /* Pointer light on the grid (fine pointers only; motion.js sets --sx/--sy), and the key light
     leaning toward the pointer by up to 4% (v5; motion.js sets --kx/--ky on the hero). */
  .hero-spot { transition: opacity 0.3s ease; }
  .hero-panel.is-lit .hero-spot { opacity: 1; }
  @media (hover: hover) and (pointer: fine) {
    .hero { transition: --kx 0.6s cubic-bezier(0.2, 0.7, 0.2, 1), --ky 0.6s cubic-bezier(0.2, 0.7, 0.2, 1); }
  }

  /* Card edge light (v5, review S10): near the pointer, a card's own border lights up, with a soft
     pool from its top edge. Replaces v3's tilt, rise and light sweep (these cards are not links).
     Fine pointers only; motion.js sets --px/--py and .is-lit. */
  @media (hover: hover) and (pointer: fine) {
    .service::after,
    .step-panel::after,
    .contact .picker::after {
      content: "";
      position: absolute;
      inset: -1px;
      z-index: 1;
      border: 1px solid transparent;
      border-radius: inherit;
      background: radial-gradient(16rem 10rem at var(--px, 50%) var(--py, 0%), color-mix(in srgb, var(--chi-blue-light) 80%, transparent), transparent 70%) border-box;
      -webkit-mask: linear-gradient(var(--chi-ink) 0 0) padding-box, linear-gradient(var(--chi-ink) 0 0);
      -webkit-mask-composite: xor;
      mask: linear-gradient(var(--chi-ink) 0 0) padding-box exclude, linear-gradient(var(--chi-ink) 0 0);
      opacity: 0;
      transition: opacity 0.3s ease;
      pointer-events: none;
    }
    .pitch-tiles > .pitch-tile::after { inset: 0; }   /* cells of the strip draw the light inside their own edges */
    .service.is-lit::after,
    .step-panel.is-lit::after,
    .contact .picker.is-lit::after { opacity: 1; }
    .service.is-lit,
    .step-panel.is-lit,
    .contact .picker.is-lit { background-image: radial-gradient(18rem 10rem at var(--px, 50%) 0, color-mix(in srgb, var(--light) 10%, transparent), transparent 70%); }
    .service.is-lit .service-icon { filter: drop-shadow(0 0 6px color-mix(in srgb, var(--chi-blue-bright) 50%, transparent)); }
  }

  /* Card icons: one short motion each, started when the card comes into view (motion.js adds
     .in-view) and replayed on hover. Each stops by itself within 5 s. No flashing: the LED and
     cursor blink once a second, in a few pixels. */
  .service.in-view .ic-dim { stroke-dasharray: 1; animation: draw 0.9s ease-out 0.5s both; }
  .service.in-view .ic-layer { animation: fade-in 0.3s ease-out both; }
  .service.in-view .ic-layer:nth-child(2) { animation-delay: 0.2s; }
  .service.in-view .ic-layer:nth-child(3) { animation-delay: 0.6s; }
  .service.in-view .ic-layer:nth-child(4) { animation-delay: 1s; }
  .service.in-view .ic-layer:nth-child(5) { animation-delay: 1.4s; }
  .service.in-view .ic-layer:nth-child(6) { animation-delay: 1.8s; }
  .service.in-view .ic-nozzle { animation: nozzle-rise 2.1s linear both; }
  .service.in-view .ic-pulse { animation: ic-pulse 1.1s linear 0.6s 3 both; }
  .service.in-view .ic-type { stroke-dasharray: 1; animation: draw 1.4s steps(6, end) 0.4s both; }
  .service.in-view .ic-cursor { animation: ic-cursor-move 1.4s steps(6, end) 0.4s both, ic-blink 1s step-end 1.8s 3; }
  .service.in-view .ic-led { animation: ic-led 1s ease-in-out 0.6s 3; }
  .ic-focus { transform-box: view-box; transform-origin: 24px 24px; }
  .service.in-view .ic-focus { animation: ic-focus 0.7s cubic-bezier(0.3, 0.6, 0.3, 1) 0.5s 2; }

  /* Scroll-linked effects */
  @supports (animation-timeline: view()) {
    /* Sections reveal as they enter the screen */
    .split > *,
    .section > .wrap > .section-title,
    .service,
    .step,
    .numbered > li,
    .after-steps {
      animation: reveal linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 22%;
    }
    /* Never leave something faded while it holds keyboard focus (focus scrolls it in at the edge). */
    .split > *:focus-within,
    .service:focus-within,
    .step:focus-within,
    .numbered > li:focus-within,
    .after-steps:focus-within { animation: none; }

    /* Card icons draw their lines as the card scrolls in */
    .service { view-timeline: --card block; }
    .ic-draw { stroke-dasharray: 1; animation: draw linear both; animation-timeline: --card; animation-range: entry 0% cover 30%; }
    .ic-late { animation-range: entry 40% cover 40%; }

    /* How we work: Create, Harmonize, Innovate joined by a trace that fills as you scroll */
    .steps { view-timeline: --steps block; }
    .steps::after {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: 2px;
      height: 100%;
      background: var(--chi-accent);
      transform-origin: top left;
      animation: fill-y linear both;
      animation-timeline: --steps;
      animation-range: cover 20% cover 50%;
    }
    .step::before { animation: node-on linear both; animation-timeline: --steps; }
    .step:nth-child(1)::before { animation-range: cover 19% cover 23%; }
    .step:nth-child(2)::before { animation-range: cover 30% cover 34%; }
    .step:nth-child(3)::before { animation-range: cover 40% cover 44%; }
    @media (min-width: 960px) {
      .steps::after { width: 100%; height: 2px; animation-name: fill-x; }
    }
  }

  /* ---- block 3 (from site.css) ---- */
  /* 3D hero: without the poster, the live canvas crossfades in over the drawn SVG mark once its first
     frame is ready (motion.js, after the opening sequence). With the poster the swap is instant. */
  .hero-panel:not(:has(.hero-poster)) .hero-canvas,
  .hero-art .mark { transition: opacity 0.9s cubic-bezier(0.4, 0, 0.2, 1); }   /* only the no-poster fallback fades */
  .hero-poster-wrap { animation: poster-reveal 0.42s linear 0.45s both; }   /* revealed top to bottom as the scan line passes */

  /* Decoding headings: motion.js lays an aria-hidden copy over the real text while it settles. */
  .decode { position: relative; }
  .decode.is-decoding { -webkit-text-fill-color: transparent; }
  .decode-fx {
    position: absolute;
    inset: 0;
    -webkit-text-fill-color: currentColor;
    pointer-events: none;
    user-select: none;
  }
  .decode:not(.is-decoding) .decode-fx { display: none; }
  .decode-glyph { -webkit-text-fill-color: var(--chi-accent); }

  /* Magnetic primary buttons (fine pointers; motion.js sets --mx and --my, at most 6 px) */
  @media (hover: hover) and (pointer: fine) {
    .button.is-magnetic,
    .button.is-magnetic:hover {
      translate: var(--mx, 0px) var(--my, 0px);
      transition: translate 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
    }
    .button.is-magnetic.is-pulling { transition-duration: 0.14s, 0.15s, 0.15s, 0.15s; }
  }

  /* From idea to prototype, pinned (motion.js adds .is-pinned; .is-js-scrub when it also has to
     drive --p itself). The track is tall; the frame inside it sticks under the header while the
     five stages wipe across one another, each with a scan line at its edge. */
  .story.is-pinned .story-track {
    height: 380svh;
    view-timeline: --story block;
    view-timeline-inset: var(--header-h) 0px;
  }
  .story.is-pinned .story-pin {
    position: sticky;
    top: var(--header-h);
    height: calc(100svh - var(--header-h));
    overflow: hidden;
  }
  /* Phones and tablets: image on top, words under it, the rail under both, all centred. Every
     stage's image sits in the same place, so the wipes line up. */
  .story.is-pinned .story-area {
    display: grid;
    grid-template-rows: minmax(0, 31rem) auto;
    align-content: center;
    gap: var(--space-5);
    height: 100%;
    padding-block: var(--space-5);
  }
  .story.is-pinned .story-stages { position: relative; min-height: 0; }
  .story.is-pinned .story-stage {
    --i: 0;
    --r: clamp(0, (var(--p) - var(--i) + 0.2) / 0.4, 1);                  /* how far this stage's image is wiped in */
    --a: clamp(0, (0.46 - max(var(--p) - var(--i) - 0.5, var(--i) + 0.5 - var(--p))) / 0.12, 1);   /* its words: out, then in */
    position: absolute;
    inset: 0;
    grid-template-rows: auto auto;
    align-content: start;
    align-items: start;
    gap: var(--space-4);
  }
  .story.is-pinned .story-stage:nth-child(2) { --i: 1; }
  .story.is-pinned .story-stage:nth-child(3) { --i: 2; }
  .story.is-pinned .story-stage:nth-child(4) { --i: 3; }
  .story.is-pinned .story-stage:nth-child(5) { --i: 4; }
  .story.is-pinned .story-stage:first-child { --r: 1; }
  .story.is-pinned .story-copy {
    grid-row: 2;
    opacity: var(--a);
    translate: 0 calc(clamp(-1, (var(--i) + 0.5 - var(--p)) * 1.5, 1) * 1rem);
  }
  .story.is-pinned .story-media {
    grid-row: 1;
    width: 100%;
    max-height: 100%;
    container-type: inline-size;
  }
  .story.is-pinned .story-stage:not(:first-child) .story-media { border-color: transparent; background: none; }
  .story.is-pinned .story-reveal { clip-path: inset(0 calc((1 - var(--r)) * 100%) 0 0); }
  .story.is-pinned .story-media::after {   /* the scan line on the wipe's edge */
    content: "";
    position: absolute;
    z-index: 3;
    top: 0;
    bottom: 0;
    left: 0;
    width: 2px;
    margin-left: -1px;
    background: var(--chi-accent);
    box-shadow: 0 0 18px 3px var(--glow);
    translate: calc(var(--r) * 100cqw) 0;
    opacity: clamp(0, min(var(--r), 1 - var(--r)) * 14, 1);
    pointer-events: none;
  }
  .story.is-pinned .story-stage:first-child .story-media::after { content: none; }
  .story.is-pinned .story-tag { opacity: var(--a); }
  /* Code: an editor window over the board image. On phones it covers the image; from 960 px it
     sits to the right on the same frame, with the board dimmed behind it. */
  .story.is-pinned .story-stage-code .story-media {
    aspect-ratio: auto;
    overflow: hidden;
    border-radius: 8px;
    opacity: calc(1 - clamp(0, (var(--p) - 3.8) / 0.4, 1));   /* steps aside as the render wipes in */
  }
  .story.is-pinned .story-stage-code .story-reveal { position: relative; }
  .story.is-pinned .story-stage-code .story-tag { position: absolute; top: auto; right: auto; bottom: 0.75rem; left: 0.75rem; margin: 0; }   /* v5 (M8): where the other stages' tags are, off the editor bar */
  @media (max-width: 959px) {             /* v5 (M8): the code card stays inside its 16:10 frame during the wipe */
    .story.is-pinned .story-stage-code .story-media { aspect-ratio: 16 / 10; overflow: hidden; }
    .story.is-pinned .story-stage-code .story-reveal { position: absolute; inset: 0; }   /* fills the frame, so the card's 100% is the frame's height */
    .story.is-pinned .story-stage-code .code-card {
      height: 100%;
      -webkit-mask-image: linear-gradient(var(--chi-ink) 78%, transparent);
      mask-image: linear-gradient(var(--chi-ink) 78%, transparent);
    }
  }
  .story.is-pinned .code { font-size: 0.625rem; padding: var(--space-3); }
  /* Progress rail */
  .story.is-pinned .story-rail {
    position: relative;
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
    padding-top: var(--space-3);
    border-top: 2px solid var(--chi-border);
    color: var(--chi-text);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    line-height: 1.4;
    text-transform: uppercase;
  }
  .story-rail-fill {
    position: absolute;
    top: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--chi-accent);
    transform-origin: 0 50%;
    scale: clamp(0, (var(--p) - 0.5) / 4, 1) 1;
  }
  .story-tick { --i: 0; opacity: calc(0.5 + 0.5 * clamp(0, (var(--p) - var(--i) + 0.1) / 0.2, 1)); }
  /* v5 (N1): five ticks on the rail; each label centred on its tick (the first left-aligned, the last right-aligned) */
  .story.is-pinned .story-rail { display: block; height: calc(var(--space-3) + 1.4em); }
  .story.is-pinned .story-rail::before {
    content: "";
    position: absolute;
    top: -3px;
    left: 0;
    right: 0;
    height: 4px;
    --t: color-mix(in srgb, var(--chi-mist) 45%, transparent);
    background:
      radial-gradient(circle, var(--t) 2px, transparent 2.5px) 0 50% / 4px 4px no-repeat,
      radial-gradient(circle, var(--t) 2px, transparent 2.5px) 25% 50% / 4px 4px no-repeat,
      radial-gradient(circle, var(--t) 2px, transparent 2.5px) 50% 50% / 4px 4px no-repeat,
      radial-gradient(circle, var(--t) 2px, transparent 2.5px) 75% 50% / 4px 4px no-repeat,
      radial-gradient(circle, var(--t) 2px, transparent 2.5px) 100% 50% / 4px 4px no-repeat;
    pointer-events: none;
  }
  .story.is-pinned .story-tick { position: absolute; top: var(--space-3); left: calc(var(--i) * 25%); translate: calc(var(--i) * -25%) 0; white-space: nowrap; }
  .story-tick:nth-child(3) { --i: 1; }
  .story-tick:nth-child(4) { --i: 2; }
  .story-tick:nth-child(5) { --i: 3; }
  .story-tick:nth-child(6) { --i: 4; }
  @media (min-width: 600px) {
    .story.is-pinned .code { font-size: 0.75rem; padding: var(--space-4); }
  }
  /* From 960 px: words left, frame right, the frame filling the height it can. */
  @media (min-width: 960px) {
    .story.is-pinned .story-area { grid-template-rows: minmax(0, 1fr) auto; align-content: stretch; }
    .story.is-pinned .story-stage { grid-template-columns: minmax(0, 3fr) minmax(0, 5fr); grid-template-rows: minmax(0, 1fr); align-content: stretch; align-items: center; column-gap: 0; }   /* v5: media from 560 to 1360 at 1440 */
    .story.is-pinned .story-copy { padding-right: 4rem; }
    .story.is-pinned .story-copy { grid-row: 1; grid-column: 1; }
    .story.is-pinned .story-media { grid-row: 1; grid-column: 2; }
    .story.is-pinned .story-stage-code .story-media { aspect-ratio: 16 / 10; overflow: visible; border-radius: var(--radius-card); }
    .story.is-pinned .story-stage-code .story-reveal {
      position: absolute;
      inset: 0;
      display: grid;
      justify-items: end;
      align-items: center;
      padding: 0 var(--space-5);
      background: color-mix(in srgb, var(--chi-night) 50%, transparent);
      clip-path: inset(-15% calc((1 - var(--r)) * 100%) -15% 0);
    }
    .story.is-pinned .story-stage-code .code-card { max-width: 34rem; margin-inline: auto 0; }
    .story.is-pinned .code { font-size: 0.8125rem; }
  }
  /* Where the browser has scroll-driven animations, CSS does the scrubbing. */
  @supports (animation-timeline: view()) and (view-timeline-inset: 1px 0px) {
    .story.is-pinned:not(.is-js-scrub) .story-pin {
      animation: story-scrub linear both;
      animation-timeline: --story;
      animation-range: contain 0% contain 100%;
    }
  }

  /* Page transitions between the site's pages: the page fades and rises; the sticky header
     (768 px and up) stays put. Browsers without cross-document view transitions just navigate. */
  &::view-transition-old(root) { animation: vt-out 0.2s cubic-bezier(0.4, 0, 1, 1) both; }
  &::view-transition-new(root) { animation: vt-in 0.36s cubic-bezier(0, 0, 0.2, 1) 0.14s both; }
  @media (min-width: 768px) {
    .site-header { view-transition-name: site-header; }
  }

  /* ---- block 4 (from site.css) ---- */

  /* Capability band (v4.1): loops at about 50 px a second (motion.js sets --ticker-dur from the
     band's width). The row holds the list twice, so moving it by half its width joins up exactly.
     Stops with the header's motion switch (with everything else), and also, quietly, on hover, with
     keyboard focus inside the band, and while it is off screen. */
  &.js .ticker-row { animation: ticker-loop var(--ticker-dur, 70s) linear infinite; }
  .ticker:hover .ticker-row,
  .ticker:has(:focus-visible) .ticker-row,
  .ticker.is-offscreen .ticker-row { animation-play-state: paused; }

  @supports (animation-timeline: view()) {
    /* the grid drifts a little slower than the page: depth */
    body.night::before { animation: grid-drift linear both; animation-timeline: scroll(root); }
    /* a light runs along each section's trace as the section arrives */
    main > .section::after {
      content: "";
      position: absolute;
      top: -1px;
      left: max(var(--gutter), 50% - var(--max) / 2);
      width: 9rem;
      height: 3px;
      border-radius: 2px;
      background: linear-gradient(90deg, transparent, var(--chi-blue-light), transparent);
      filter: blur(0.5px);
      pointer-events: none;
      animation: trace-run linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 100%;
    }
    /* How we work: the outlined words fill as they reach the middle of the screen */
    .how .step-title {
      color: transparent;
      -webkit-text-stroke: 1.25px color-mix(in srgb, var(--chi-mist) 45%, transparent);
      paint-order: stroke fill;
      background: linear-gradient(90deg, var(--chi-text) var(--fill), transparent var(--fill));
      -webkit-background-clip: text;
      background-clip: text;
      animation: word-fill linear both;
      animation-timeline: view();
      animation-range: entry 70% cover 48%;
    }
    .how .step-title::first-letter { -webkit-text-fill-color: var(--chi-blue-bright); -webkit-text-stroke-color: var(--chi-blue-bright); }
    .how .steps::after {
      top: 0.5rem;
      left: calc(var(--node) / 2 - 1px);
      width: 2px;
      height: calc(100% - 0.5rem);
      background: linear-gradient(var(--chi-blue-bright), var(--chi-blue-light));
      box-shadow: 0 0 6px color-mix(in srgb, var(--chi-blue-bright) 60%, transparent);
      animation: fill-y linear both;
      animation-timeline: view();
      animation-range: cover 50vh cover calc(100% - 50vh);
    }
    .how .step::before { animation: node-on linear both; animation-timeline: view(); animation-range: cover 50vh cover calc(50vh + 60px); }
  }
  /* Designs hero traces draw in once (about 2 s), then stay still */
  .designs-hero-art path { stroke-dasharray: 1; animation: draw 1.8s cubic-bezier(0.5, 0, 0.3, 1) 0.3s both; }
  .designs-hero-art path:nth-child(2n) { animation-delay: 0.55s; }
  .designs-hero-art .node { animation: fade-in 0.5s ease 1.6s both; }

  /* the header switch's knob slides (v4.1) */
  .motion-switch-track::after { transition: translate 0.2s ease; }
}
