/* ------------------------------------------------------------------
   PackSort — motion
   The site moves the way the brand film moves (film/ANIMATION_GUIDE.md):
   arrive decelerates into place, move eases both ends, snap is the app's
   UI locking on. Cyan moves only when PackSort is reading or routing;
   amber is the package. Nothing loops for decoration.
   Everything here is opt-in: with reduced motion the page is static.
------------------------------------------------------------------ */
:root {
  --ease-arrive: cubic-bezier(.16, 1, .3, 1);
  --ease-move: cubic-bezier(.65, 0, .35, 1);
  --ease-snap: cubic-bezier(.19, 1, .22, 1);
}

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

  /* ---- The mark draws itself: the package, the stroke climbing the stem,
          a held beat at the junction, then the fork to both routes ---- */
  .site-header .brand-mark .package-node,
  .site-header .brand-mark .route-node { transform-box: fill-box; transform-origin: center; }
  .site-header .brand-mark .package-node { animation: mark-pop 260ms var(--ease-snap) 100ms both; }
  .site-header .brand-mark .stem { stroke-dasharray: 1 1; animation: mark-draw 440ms var(--ease-move) 200ms both; }
  .site-header .brand-mark .arm { stroke-dasharray: 1 1; animation: mark-draw 200ms var(--ease-snap) 780ms both; }
  .site-header .brand-mark .route-node { animation: mark-pop 240ms var(--ease-snap) 860ms both; }

  /* ---- Hero: the phone arrives, then each callout locks on like the
          app's reading rectangle before it resolves into its card ---- */
  .hero-visual .phone { animation: phone-arrive 900ms var(--ease-arrive) 150ms both; }
  .hero-visual .callout {
    outline: 2px dashed transparent;
    outline-offset: 4px;
    animation: callout-lock 620ms var(--ease-snap) var(--lock-at, 900ms) both;
  }
  .hero-visual .callout > * { animation: callout-fill 380ms var(--ease-arrive) calc(var(--lock-at, 900ms) + 150ms) both; }
  .hero-visual .callout-a { --lock-at: 900ms; }
  .hero-visual .callout-b { --lock-at: 1040ms; }
  .hero-visual .callout-c { --lock-at: 1180ms; }
  /* below the fold at load (phones): wait on the first frame until the panel is on screen (motion.js) */
  .hero-visual[data-hold="pending"] .phone,
  .hero-visual[data-hold="pending"] .callout,
  .hero-visual[data-hold="pending"] .callout > * { animation-play-state: paused; }

  /* ---- Blocks rise into place as the reader reaches them (motion.js) ---- */
  [data-reveal="pending"] { opacity: 0; }
  [data-reveal="in"] { animation: reveal-rise 820ms var(--ease-arrive) var(--stagger, 0ms) backwards; }

  /* ---- The film's still takes the film's own slow push while it waits (once, then it holds) ---- */
  .film-frame[data-reveal="in"] .film-poster { animation: poster-push 14s cubic-bezier(.25, .1, .25, 1) 300ms both; }

  /* ---- How it works: step 1 is read, step 2 is routed ---- */
  .step-shot[data-motion] { position: relative; }
  .step-shot[data-motion="read"] { --l: 21.1%; --t: 43.9%; --w: 37%; --h: 10.5%; --lock-at: 1050ms; }
  .step-shot[data-motion="answer"] { --l: 18%; --t: 26%; --w: 64%; --h: 10.5%; --lock-at: 1320ms; } /* after step 1 locks */
  .step-shot[data-motion]::before,
  .step-shot[data-motion="read"]::after { content: ""; position: absolute; opacity: 0; pointer-events: none; }
  /* the lock: snaps onto what PackSort has read (the app's own rectangle), holds, lets go */
  .step-shot[data-motion]::before {
    left: var(--l); top: var(--t); width: var(--w); height: var(--h);
    border: 2px solid var(--cyan); border-radius: 8px;
    box-shadow: 0 0 18px rgba(79, 195, 247, .55), inset 0 0 12px rgba(79, 195, 247, .22);
  }
  [data-reveal="in"] .step-shot[data-motion]::before {
    animation: lock-on 950ms var(--ease-snap) calc(var(--stagger, 0ms) + var(--lock-at)) both;
  }
  /* the reading line: sweeps the camera view and settles on the address block */
  .step-shot[data-motion="read"]::after {
    left: 5.5%; right: 5.6%; top: 27%; height: 2px; border-radius: 2px; background: var(--cyan);
    box-shadow: 0 0 10px 1px rgba(79, 195, 247, .85), 0 0 26px 6px rgba(79, 195, 247, .35);
  }
  [data-reveal="in"] .step-shot[data-motion="read"]::after {
    animation: read-sweep 1000ms var(--ease-move) calc(var(--stagger, 0ms) + 300ms) both;
  }

  /* ---- The closing mark draws itself when the reader gets there ---- */
  .cta-mark circle { transform-box: fill-box; transform-origin: center; }
  [data-draw="pending"] .cta-mark .stem,
  [data-draw="pending"] .cta-mark .arm { stroke-dasharray: 1 1; stroke-dashoffset: 1; }
  [data-draw="pending"] .cta-mark circle { opacity: 0; }
  [data-draw="in"] .cta-mark .package-node { animation: mark-pop 320ms var(--ease-snap) 150ms both; }
  [data-draw="in"] .cta-mark .stem { stroke-dasharray: 1 1; animation: mark-draw 900ms var(--ease-move) 300ms both; }
  [data-draw="in"] .cta-mark .arm { stroke-dasharray: 1 1; animation: mark-draw 260ms var(--ease-snap) 1420ms both; }
  [data-draw="in"] .cta-mark .route-node { animation: mark-pop 300ms var(--ease-snap) 1520ms both; }

  /* ---- Two-character demo: the key snaps in, the answer rises into its card (a flag never shakes) ---- */
  .try-code .typed { display: inline-block; animation: typed-in 280ms var(--ease-snap) both; }
  .try-keys button { animation: key-in 320ms var(--ease-arrive) calc(var(--i, 0) * 22ms) backwards; }
  .try-answer .try-driver { animation: answer-in 480ms var(--ease-arrive) 60ms backwards; }
  .try-answer .try-bay { animation: answer-in 480ms var(--ease-arrive) 140ms backwards; }
  .try-answer .try-sub { animation: answer-in 480ms var(--ease-arrive) 220ms backwards; }
}

@keyframes mark-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes mark-pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: none; } }

@keyframes phone-arrive { from { opacity: 0; transform: translateY(26px); } }

@keyframes callout-lock {
  0% {
    outline-color: rgba(79, 195, 247, 0); outline-offset: 16px;
    background-color: rgba(255, 255, 255, 0); box-shadow: 0 18px 36px -18px rgba(0, 0, 0, 0);
  }
  1% { outline-color: rgba(79, 195, 247, 1); }
  30% { outline-offset: 4px; background-color: rgba(255, 255, 255, 0); box-shadow: 0 18px 36px -18px rgba(0, 0, 0, 0); }
  55% { outline-color: rgba(79, 195, 247, 1); background-color: rgba(255, 255, 255, .96); box-shadow: 0 18px 36px -18px rgba(0, 0, 0, .6); }
  100% {
    outline-color: rgba(79, 195, 247, 0); outline-offset: 4px;
    background-color: rgba(255, 255, 255, .96); box-shadow: 0 18px 36px -18px rgba(0, 0, 0, .6);
  }
}
@keyframes callout-fill { from { opacity: 0; transform: translateY(3px); } }

@keyframes reveal-rise { from { opacity: 0; transform: translateY(22px); } }
@keyframes lock-on {
  0% { opacity: 0; transform: scale(1.25); }
  22% { opacity: 1; transform: scale(1); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}
@keyframes read-sweep {
  0% { top: 27%; opacity: 0; }
  8% { opacity: 1; }
  75% { top: 49.1%; opacity: 1; }
  100% { top: 49.1%; opacity: 0; }
}
@keyframes typed-in { from { opacity: 0; transform: translateY(10px) scale(.9); } }
@keyframes key-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes answer-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes poster-push { from { transform: scale(1); } to { transform: scale(1.045); } }
