/* daniel.homegh.com - MOTION LAYER. Design: Designer (2026-11-14), spec section 5 in the redo brief; production port: Fullstack.
   Principle: motion explains structure or state (what is connected, what is live, what comes next).
   Rules: transform and opacity only (one small SVG stroke draw excepted); every moment plays once;
   hidden start states exist only under html.motion (set by site.js), so without JS everything shows;
   prefers-reduced-motion: nothing below applies. */

:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);       /* UI: hover, press, small changes */
  --ease-expo: cubic-bezier(0.16, 1, 0.3, 1);       /* reveals: masks, rises */
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);   /* wipes and line draws */
  --t-press: 120ms;
  --t-fast: 200ms;
  --t-base: 450ms;
  --t-slow: 700ms;
  --t-draw: 900ms;
  --t-long: 1200ms;
  --st-text: 50ms;    /* stagger between text lines or words */
  --st-item: 80ms;    /* stagger between list items */
  --st-step: 120ms;   /* stagger between diagram steps */
}

/* Static helpers that exist with or without motion */
.mask { display: inline-block; overflow: hidden; vertical-align: top; padding-bottom: .14em; margin-bottom: -.14em; padding-inline-end: .12em; margin-inline-end: -.12em; }  /* inline padding: the y's arm overhangs its box (Qa m5) */
.mask > .w { display: inline-block; }
.jobs { position: relative; border-top: 0; }
.jobs::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--ink); transform-origin: 0 50%; }
.job .n { display: inline-block; }
.job .n-mask { overflow: hidden; display: block; grid-row: 1 / span 3; align-self: start; }
.flow { position: relative; }
.pulse-track { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 8px; }
.pulse { position: absolute; top: 50%; left: 0; width: 100%; height: 0; transform: translateX(-100%); opacity: 0; }
.pulse::after { content: ""; position: absolute; right: -5px; top: -5px; width: 10px; height: 10px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 4px color-mix(in srgb, var(--signal) 25%, transparent); }
.case.wide .pulse::after { background: #8ea0ff; }
.board { position: relative; }
.board-sweep { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: inherit; }
.board-sweep::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 40%; background: linear-gradient(90deg, transparent, rgba(142, 160, 255, .10), transparent); transform: translateX(-100%); }
.count b, .svc .lat, [data-live-time] { font-variant-numeric: tabular-nums; }
.svc li { position: relative; }
.svc li::before { content: ""; position: absolute; inset: 0; background: rgba(142, 160, 255, .12); opacity: 0; pointer-events: none; }
.topo::before { transform-origin: 0 50%; }

@media (prefers-reduced-motion: no-preference) {

  /* ---------- 0. Hero entrance (CSS only, starts on first paint, about 1.1 s in total) ---------- */
  .motion .hero-top { animation: fade var(--t-base) var(--ease-out) both; }
  .motion .hero .mask > .w { animation: rise var(--t-slow) var(--ease-expo) both; animation-delay: calc(60ms + var(--li, 0) * 90ms); }

  /* ---------- 1. What I do: the rule draws, the numbers tick up ---------- */
  .motion-io [data-motion="jobs"]::before { transform: scaleX(0); }
  .motion-io [data-motion="jobs"] .n { transform: translateY(110%); }
  .motion-io [data-motion="jobs"].in::before { transform: none; transition: transform var(--t-draw) var(--ease-in-out); }
  .motion-io [data-motion="jobs"].in .n { transform: none; transition: transform var(--t-base) var(--ease-expo); transition-delay: calc(300ms + var(--i, 0) * var(--st-item)); }

  /* ---------- 2. Case diagrams: wires draw node to node, one pulse runs the route ---------- */
  .motion-io [data-motion="case"] .wire { transform: scaleX(0); transform-origin: 0 50%; }
  .motion-io [data-motion="case"].in .wire { transform: none; transition: transform 260ms var(--ease-out); transition-delay: calc(150ms + var(--i, 0) * var(--st-step)); }
  .motion-io [data-motion="case"] .node.hot { transition: transform 300ms var(--ease-expo), box-shadow 300ms var(--ease-out); }
  .motion-io [data-motion="case"].in .node.hot { animation: hot 600ms var(--ease-expo) 520ms both; }
  .motion-io [data-motion="case"].in .pulse,
  .motion-io [data-motion="case"].replay .pulse { animation: run 1400ms var(--ease-in-out) 700ms both; }
  .motion-io [data-motion="case"].replay .pulse { animation-delay: 0ms; }
  .motion-io [data-motion="case"] .minimap .wire-path { stroke-dasharray: 1; stroke-dashoffset: 1; }
  .motion-io [data-motion="case"].in .minimap .wire-path { stroke-dashoffset: 0; transition: stroke-dashoffset 700ms var(--ease-in-out); transition-delay: calc(150ms + var(--i, 0) * 90ms); }

  /* ---------- 3. Live lab: line sweeps, nodes settle, counts tick (JS), one light pass ---------- */
  .motion-io [data-motion="live"] .topo::before { transform: scaleX(0); }
  .motion-io [data-motion="live"] .tn .ring { transform: scale(.6); opacity: 0; }
  .motion-io [data-motion="live"].in .topo::before { transform: none; transition: transform var(--t-draw) var(--ease-in-out) 100ms; }
  .motion-io [data-motion="live"].in .tn .ring { transform: none; opacity: 1; transition: transform var(--t-base) var(--ease-expo), opacity 250ms var(--ease-out); transition-delay: calc(200ms + var(--i, 0) * var(--st-item)); }
  .motion-io [data-motion="live"].in .board-sweep::before { animation: sweep 1600ms var(--ease-in-out) 500ms both; }
  /* In-place refresh (every 30 s): colours cross-fade, a changed row glows once */
  .dot, .tn .ring { transition: background-color 400ms var(--ease-out), border-color 400ms var(--ease-out); }
  .svc li.changed::before { animation: glow 1200ms var(--ease-out) both; }
  .dot[data-s="healthy"]::after { animation: ping 2.8s var(--ease-out) infinite; }

  /* ---------- 4. How I work: the route draws, the steps pop in order ---------- */
  .motion-io [data-motion="route"]::before { transform: scaleX(0); }
  .motion-io [data-motion="route"] li::before { transform: scale(.4); opacity: 0; }
  .motion-io [data-motion="route"].in::before { transform: none; transition: transform 1100ms var(--ease-in-out); }
  .motion-io [data-motion="route"].in li::before { transform: none; opacity: 1; transition: transform 380ms var(--ease-expo), opacity 200ms var(--ease-out); transition-delay: calc(120ms + var(--i, 0) * 260ms); }

  /* ---------- 5. Contact: the closing line rises word by word (bookends the hero) ---------- */
  .motion-io [data-motion="contact"] .mask > .w { transform: translateY(125%); }
  .motion-io [data-motion="contact"].in .mask > .w { transform: none; transition: transform var(--t-slow) var(--ease-expo); transition-delay: calc(var(--i, 0) * 40ms); }

  /* ---------- Interaction ---------- */
  a.case .node.hot { transition: transform var(--t-fast) var(--ease-out); }
  @media (hover: hover) and (pointer: fine) {
    a.case:hover .node.hot { transform: scale(1.06); }
    .live-chip:hover .dot::after { animation-duration: 1.2s; }
    .nav a .dot { transition: transform var(--t-fast) var(--ease-out); }
    .nav a:hover .dot { transform: scale(1.3); }
  }

  /* ---------- Page transition (cross-document View Transitions; browsers without it navigate normally) ---------- */
  @view-transition { navigation: auto; }
  ::view-transition-old(root) { animation: 140ms var(--ease-out) both vt-out; }
  ::view-transition-new(root) { animation: 300ms var(--ease-expo) 120ms both vt-in; }
  /* shared title: the card title grows into the case headline; the old image leaves at once so text never doubles */
  ::view-transition-group(homegh-title) { animation-duration: 500ms; animation-timing-function: var(--ease-expo); }
  ::view-transition-old(homegh-title) { animation: 90ms linear both vt-out; }
  ::view-transition-new(homegh-title) { animation: none; }
  .case.wide h3 { view-transition-name: homegh-title; }
  #cs-title { view-transition-name: homegh-title; }
  /* When a page arrives by a view transition, its own entrance does not play again. */
  .vt-arrived .motion-enter, .vt-arrived .motion-enter > *, .vt-arrived .hero .mask > .w, .vt-arrived .hero-top { animation: none !important; }
}

/* Case-study entrance (same vocabulary as the home hero) */
@media (prefers-reduced-motion: no-preference) {
  .motion .motion-enter > * { animation: lift var(--t-base) var(--ease-expo) both; animation-delay: calc(60ms + var(--i, 0) * var(--st-text)); }
  .motion .motion-enter .mask > .w { animation: rise var(--t-slow) var(--ease-expo) both; animation-delay: calc(80ms + var(--li, 0) * 90ms); }
  .motion .motion-enter > h1 { animation: none; }
}

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(125%); } }
@keyframes lift { from { opacity: 0; transform: translateY(12px); } }
@keyframes uncover { to { transform: scaleY(0); } }
@keyframes settle { from { transform: scale(1.12); } }
@keyframes pop { from { transform: scale(0); } }
@keyframes hot { 50% { transform: scale(1.08); } }
@keyframes run { 0% { transform: translateX(-100%); opacity: 0; } 12% { opacity: 1; } 88% { opacity: 1; } 100% { transform: translateX(0); opacity: 0; } }
@keyframes sweep { to { transform: translateX(250%); } }
@keyframes glow { 0% { opacity: 0; } 20% { opacity: 1; } 100% { opacity: 0; } }
@keyframes ping { 0% { transform: scale(.6); opacity: .8; } 70%, 100% { transform: scale(1.6); opacity: 0; } }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(16px); } }

/* ---------- Floating lab hero (Phase 1): parallax, drift, entrance, ping ----------
   --p (0 at the top, 1 when the hero has scrolled out) comes from a CSS scroll timeline where supported, else
   from site.js (passive scroll + rAF). --mx/--my come from site.js on fine pointers only. Transform and opacity
   only. Nothing here applies under reduced motion: the hero then shows the final still composition. */
@keyframes lab-p { to { --p: 1; } }
@keyframes lab-bob { 50% { transform: translateY(var(--bob, 4px)); } }
@keyframes lab-settle { from { transform: translateY(24px); opacity: 0; } }
@keyframes lab-pop { from { transform: scale(.4); opacity: 0; } }
@keyframes lab-ping { 0% { transform: scale(.6); opacity: .8; } 70%, 100% { transform: scale(1.6); opacity: 0; } }
@keyframes lab-blink { 0%, 60% { opacity: 1; } 61%, 100% { opacity: .25; } }
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: scroll()) {
    .motion .hero.lab { animation: lab-p linear both; animation-timeline: scroll(root block); animation-range: 0 max(100svh, 640px); }
  }
  .motion .lab-far, .motion .lab-name, .motion .lab-main, .motion .lab-near { will-change: transform; }
  .motion .lab-far { transform: translate3d(0, calc(var(--p) * var(--k) * -0.10 * max(100svh, 640px)), 0); }
  .motion .lab-name { transform: translate3d(0, calc(var(--p) * var(--k) * -0.18 * max(100svh, 640px)), 0); }
  .motion .lab-main { transform: translate3d(0, calc(var(--p) * var(--k) * -0.30 * max(100svh, 640px)), 0) scale(calc(1 + .06 * var(--p) * var(--k))); }
  .motion .lab-near { transform: translate3d(0, calc(var(--p) * var(--k) * -0.55 * max(100svh, 640px)), 0); }
  .motion .lab-foot { transform: translate3d(0, calc(var(--p) * var(--k) * -0.22 * max(100svh, 640px)), 0); }
  /* pointer parallax (site.js sets --mx/--my in -1..1 for fine pointers), eased toward the target */
  .motion .lab-ptr { transition: transform 600ms var(--ease-out); }
  .motion .lab-far .lab-ptr { transform: translate3d(calc(var(--mx) * 6px), calc(var(--my) * 6px), 0); }
  .motion .lab-main .lab-ptr { transform: translate3d(calc(var(--mx) * 12px), calc(var(--my) * 12px), 0); }
  .motion .lab-near .lab-ptr { transform: translate3d(calc(var(--mx) * 20px), calc(var(--my) * 20px), 0); }
  /* idle drift: rocks ±4 px on 6-9 s cycles, the island ±3 px on 8 s */
  .motion .lab .rk { transform-box: fill-box; animation: lab-bob 7s ease-in-out infinite; }
  .motion .lab .r1 { animation-duration: 6s; } .motion .lab .r2 { animation-duration: 8.5s; animation-delay: -2s; }
  .motion .lab .r3 { animation-duration: 7.4s; animation-delay: -4s; } .motion .lab .r4 { animation-duration: 9s; animation-delay: -1s; }
  .motion .lab .n1 { animation-duration: 8s; animation-delay: -3s; } .motion .lab .n2 { animation-duration: 6.6s; animation-delay: -5s; }
  .motion .lab-bob { --bob: 3px; animation: lab-bob 8s ease-in-out infinite; }
  /* entrance: the name rises (existing mask rise), then the island settles from 24 px lower, then the hotspots pop */
  .motion .lab-island { animation: lab-settle 900ms var(--ease-expo) 220ms both; }
  .motion .lab-hot { animation: lab-pop 400ms var(--ease-expo) both; animation-delay: calc(280ms + var(--hi, 0) * 60ms); }
  .motion .lab-hot:nth-child(2) { --hi: 1; } .motion .lab-hot:nth-child(3) { --hi: 2; } .motion .lab-hot:nth-child(4) { --hi: 3; }
  .motion .lab-hot:nth-child(5) { --hi: 4; } .motion .lab-hot:nth-child(6) { --hi: 5; }
  .motion .lab[data-state="live"] .lab-hot[data-s="healthy"] .lab-hot-d::after { animation: lab-ping 2.8s var(--ease-out) infinite; }
  .motion .lab .led-web { animation: lab-blink 1.6s steps(1) infinite; }
  .motion .lab-hot-pop { transition: opacity var(--t-fast) var(--ease-out), visibility var(--t-fast); }
  /* out of view: stop all hero work */
  .motion .lab.off *, .motion .lab.off { animation-play-state: paused !important; }
  .vt-arrived .lab-island, .vt-arrived .lab-hot { animation: none; }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 720px) {
  .motion .lab-bob, .motion .lab .n1, .motion .lab .n2 { animation: none; }   /* phone: drift only on the far rocks */
}
