/* =====================================================================
   General Access · motion.css            owner: design-motion
   Transitions between component looks, every @keyframes, and the
   reduced-motion fallbacks. Loaded last. Never sets a resting look.

   One job: say at a glance what is happening, never look busy.
   Each signal has its own home, so nothing competes:
     call is live / mic on  -> .status-dot   slow breath
     camera trouble         -> .status-chip  one soft swell, dot quickens
     the person is talking  -> .heard-icon   uneven "voice level" pulse
     Claude is thinking     -> .thinking-mark three-dot wave
     Claude is speaking     -> .caption-mark amber bar breathes like a voice
     screen found / lost    -> .box-corner   corners lock in / let go

   SIGNATURE: the viewfinder has a temperament.
     ready    the dot breathes (alive, waiting)
     starting the corners hunt, each on its own period (working)
     call     the same corners lock onto the TV screen (found)
     ended    the lamp dims from amber to grey (off)

   #call budget: only transform, opacity (and the four #box geometry
   properties JS sets) are animated. No blur, no shadows, no gradients.
   Loop periods are literal (no token exists for multi-second loops) and
   deliberately unequal, so living elements never repeat identically.
   ===================================================================== */


/* ---------- 0. Corner directions (used by enter / hunt / lose) ------- */

.finder-corner:nth-child(1), .box-corner:nth-child(1) { --mx: -1; --my: -1; --i: 0; --hunt: 2.2s;  }
.finder-corner:nth-child(2), .box-corner:nth-child(2) { --mx:  1; --my: -1; --i: 1; --hunt: 2.65s; }
.finder-corner:nth-child(3), .box-corner:nth-child(3) { --mx:  1; --my:  1; --i: 2; --hunt: 2.4s;  }
.finder-corner:nth-child(4), .box-corner:nth-child(4) { --mx: -1; --my:  1; --i: 3; --hunt: 2.9s;  }


/* ---------- 1. Keyframes --------------------------------------------- */

@keyframes ga-fade     { from { opacity: 0; } }
@keyframes ga-rise     { from { opacity: 0; transform: translateY(12px); } }
@keyframes ga-rise-sm  { from { opacity: 0; transform: translateY(8px); } }
@keyframes ga-drop     { from { opacity: 0; transform: translateY(-8px); } }

/* Corners arrive from outside and close in (--open set per context). */
@keyframes ga-corner-in {
  from { opacity: 0; transform: translate(calc(var(--mx) * var(--open)), calc(var(--my) * var(--open))); }
}
/* Ended: corners relax outward from a tight grip. */
@keyframes ga-corner-release {
  from { transform: translate(calc(var(--mx) * -6px), calc(var(--my) * -6px)); }
}
@keyframes ga-dot-in { from { opacity: 0; transform: scale(.4); } }

/* Ready: the dot breathes. Two periods (4.8s scale, 6.4s light) drift apart. */
@keyframes ga-breathe-scale { 50% { scale: .8; } }
@keyframes ga-breathe-light { 50% { opacity: .55; } }

/* Starting: each corner widens 5px and returns, on its own period. */
@keyframes ga-hunt { 50% { translate: calc(var(--mx) * 5px) calc(var(--my) * 5px); } }
@keyframes ga-hunt-dot { 50% { opacity: .35; scale: .78; } }
@keyframes ga-working { 50% { opacity: .62; } }

/* Ended: the lamp goes off. */
@keyframes ga-lamp-off { from { color: var(--accent); } }

/* Call: mic on (slow), trouble (a little quicker, still soft). */
@keyframes ga-live      { 50% { opacity: .38; } }
@keyframes ga-attention { 50% { opacity: .5; scale: .8; } }
@keyframes ga-nudge {
  0%, 100% { transform: none; }
  22%      { transform: scale(1.04); }
  44%      { transform: none; }
  66%      { transform: scale(1.025); }
}

/* Hearing: an uneven envelope, like syllables. 1.6s scale + 1.15s light. */
@keyframes ga-voice {
  0%, 100% { scale: 1; }
  17% { scale: 1.16; }
  31% { scale: 1.04; }
  52% { scale: 1.22; }
  69% { scale: 1.06; }
  84% { scale: 1.14; }
}
@keyframes ga-voice-light { 50% { opacity: .7; } }

/* Thinking: a soft wave across the three dots. Swells, never bounces. */
@keyframes ga-think {
  0%, 62%, 100% { opacity: .6; transform: scale(.72); }
  28%           { opacity: 1;   transform: scale(1); }
}

/* Speaking: the amber bar moves like a quiet voice. 2.3s + 3.1s drift. */
@keyframes ga-mark-in { from { transform: scaleY(0); } }
@keyframes ga-voice-bar {
  0%, 100% { scale: 1 1; }
  21% { scale: 1 .84; }
  38% { scale: 1 .97; }
  57% { scale: 1 .78; }
  76% { scale: 1 .93; }
}
@keyframes ga-voice-bar-light { 50% { opacity: .72; } }

/* Caption arrival. Three identical copies so a changing attribute restarts it. */
@keyframes ga-caption-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes ga-caption-a  { from { opacity: 0; transform: translateY(8px); } }
@keyframes ga-caption-b  { from { opacity: 0; transform: translateY(8px); } }


/* ---------- 2. Transitions between component looks ------------------- */

.btn {
  transition:
    transform var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    opacity var(--dur-base) var(--ease-out);
}
/* Press: zero specificity, so a pressed look in components.css wins. */
:where(.btn:active:not(:disabled)) { transform: scale(.97); }

.field {
  transition:
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
}


/* ---------- 3. Screen entrances (gate, ready, ended) ----------------- */
/* Sections switch with display, so the old one simply leaves and the new
   one assembles. Same background colour, so it reads as a soft crossfade.
   Animations replay each time a section is shown, never on ready->starting
   (the section stays displayed). Fill is "backwards" so states can still
   change opacity afterwards. */

.panel .panel-top { animation: ga-fade var(--dur-reveal) var(--ease-out) backwards; }

.panel .panel-body > * { animation: ga-rise var(--dur-reveal) var(--ease-out) backwards; }
.panel .panel-body > :nth-child(2) { animation-delay: 60ms; }
.panel .panel-body > :nth-child(3) { animation-delay: 120ms; }
.panel .panel-body > :nth-child(4) { animation-delay: 180ms; }
.panel .panel-body > :nth-child(5) { animation-delay: 240ms; }
.panel .panel-body > :nth-child(n+6) { animation-delay: 300ms; }

.panel .panel-actions { animation: ga-rise var(--dur-reveal) var(--ease-out) 240ms backwards; }

/* Messages that appear later fade in where they stand. */
.form-status:not(:empty) { animation: ga-fade var(--dur-base) var(--ease-out) backwards; }
.starting-hint { animation: ga-rise-sm var(--dur-base) var(--ease-out) backwards; }


/* ---------- 4. Signature: the viewfinder ------------------------------ */

/* The big finder does not slide as a block; its corners close in. */
.panel .panel-body > .finder { animation: none; }

.finder-lg .finder-corner {
  --open: 10px;
  animation: ga-corner-in var(--dur-reveal) var(--ease-out) calc(var(--i) * 40ms) backwards;
}
.finder-lg .finder-dot {
  animation: ga-dot-in var(--dur-reveal) var(--ease-out) 260ms backwards;
}

/* Ready: alive but calm. Starts after the entrance has settled. */
body[data-state="ready"] #ready .finder-dot {
  animation:
    ga-dot-in var(--dur-reveal) var(--ease-out) 260ms backwards,
    ga-breathe-scale 4.8s ease-in-out 1.2s infinite,
    ga-breathe-light 6.4s ease-in-out 1.2s infinite;
}

/* Starting: clearly working. Entrance names stay first in each list so
   switching ready <-> starting never replays the entrance. */
body[data-state="starting"] #ready .finder-lg .finder-corner {
  animation:
    ga-corner-in var(--dur-reveal) var(--ease-out) calc(var(--i) * 40ms) backwards,
    ga-hunt var(--hunt) ease-in-out infinite;
}
body[data-state="starting"] #ready .finder-dot {
  animation:
    ga-dot-in var(--dur-reveal) var(--ease-out) 260ms backwards,
    ga-hunt-dot 1.5s ease-in-out infinite;
}
body[data-state="starting"] .btn-label-starting {
  animation:
    ga-fade var(--dur-base) var(--ease-out) backwards,
    ga-working 1.8s ease-in-out var(--dur-base) infinite;
}

/* Ended: corners let go and the lamp dims to grey. */
.finder-lg.is-resting { animation: ga-lamp-off calc(var(--dur-reveal) * 2) var(--ease-out) 450ms backwards; }
.finder-lg.is-resting .finder-corner {
  animation: ga-corner-release var(--dur-reveal) var(--ease-out) calc(200ms + var(--i) * 40ms) backwards;
}
.finder-lg.is-resting .finder-dot { animation: none; }


/* ---------- 5. Call: arriving ------------------------------------------ */

#video          { animation: ga-fade var(--dur-reveal) var(--ease-out) backwards; }
#call .scrim    { animation: ga-fade var(--dur-slow) var(--ease-out) backwards; }
.hud-top        { animation: ga-drop var(--dur-slow) var(--ease-out) 120ms backwards; }
.hud-bottom     { animation: ga-rise var(--dur-slow) var(--ease-out) 60ms backwards; }

.heard-row      { animation: ga-rise-sm var(--dur-base) var(--ease-out) backwards; }
.type-form      { animation: ga-rise-sm var(--dur-base) var(--ease-out) backwards; }

/* The status chip fades in and out with its text instead of popping. */
.status-chip {
  transition:
    opacity var(--dur-base) var(--ease-out),
    visibility var(--dur-base);
}
.status-chip:has(#status:empty) { opacity: 0; }


/* ---------- 6. Call: listening, trouble -------------------------------- */

body[data-listening="true"] .status-dot {
  animation: ga-live 3.4s ease-in-out infinite;
}

body:is([data-trouble="blurry"], [data-trouble="dark"], [data-trouble="no_screen"]) .status-chip {
  animation: ga-nudge calc(var(--dur-reveal) * 2) ease-in-out backwards;
}
body:is([data-trouble="blurry"], [data-trouble="dark"], [data-trouble="no_screen"]) .status-dot {
  animation: ga-attention 1.7s ease-in-out infinite;
}


/* ---------- 7. Call: hearing, thinking, speaking ---------------------- */

body[data-hearing="true"] .heard-icon {
  animation:
    ga-voice 1.6s ease-in-out infinite,
    ga-voice-light 1.15s ease-in-out infinite;
}

/* The last caption steps back while the person talks or Claude thinks. */
#caption, .caption-mark { transition: opacity var(--dur-slow) var(--ease-out); }
body:is([data-hearing="true"], [data-thinking="true"]):not([data-speaking="true"]) :is(#caption, .caption-mark) {
  opacity: .72;
}

/* Thinking: appears after 150ms so a very short wait does not flicker. */
body[data-thinking="true"] .thinking-mark {
  animation: ga-fade var(--dur-base) var(--ease-out) 150ms backwards;
}
.thinking-mark i { animation: ga-think 1.35s ease-in-out infinite backwards; }
.thinking-mark i:nth-child(2) { animation-delay: .17s; }
.thinking-mark i:nth-child(3) { animation-delay: .34s; }

/* Speaking. The bar grows in when a caption first appears, then moves
   with the voice. */
.caption-mark {
  animation: ga-mark-in var(--dur-slow) var(--ease-out) backwards;
}
body[data-speaking="true"] .caption-mark {
  animation:
    ga-mark-in var(--dur-slow) var(--ease-out) backwards,
    ga-voice-bar 2.3s ease-in-out infinite,
    ga-voice-bar-light 3.1s ease-in-out infinite;
}

/* Caption arrival when Claude starts speaking. */
body[data-speaking="true"] #caption {
  animation: ga-caption-in var(--dur-slow) var(--ease-out) backwards;
}
/* Per sentence: needs JS to flip #caption[data-piece] between "a" and "b"
   each time it sets new text. Harmless until then. */
body #caption[data-piece="a"] { animation: ga-caption-a var(--dur-slow) var(--ease-out) backwards; }
body #caption[data-piece="b"] { animation: ga-caption-b var(--dur-slow) var(--ease-out) backwards; }


/* ---------- 8. Call: the screen outline ------------------------------ */
/* JS moves #box every ~400ms; a matching ease-out glide reads as one
   steady hand. Found: corners close in 12px. Lost: they let go outward
   and fade (display stays on for the fade via allow-discrete). */

#box {
  transition:
    left var(--dur-slow) var(--ease-out),
    top var(--dur-slow) var(--ease-out),
    width var(--dur-slow) var(--ease-out),
    height var(--dur-slow) var(--ease-out),
    opacity var(--dur-base) var(--ease-out),
    display var(--dur-base) allow-discrete;
  animation: ga-fade var(--dur-base) var(--ease-out) backwards;
}
#box[hidden] { opacity: 0; }

#box .box-corner {
  --open: 12px;
  transition: translate var(--dur-base) var(--ease-out);
  animation: ga-corner-in var(--dur-slow) var(--ease-out) calc(var(--i) * 30ms) backwards;
}
#box[hidden] .box-corner {
  translate: calc(var(--mx) * 12px) calc(var(--my) * 12px);
}


/* ---------- 9. Reduced motion: still, or opacity only ----------------- */
/* Durations are already 0 via the tokens, so entrances and transitions
   are instant. Keyframes are redefined without movement; loops that carry
   meaning become slow opacity changes, the rest stand still. Every state
   is also stated in words (#status, #heard, #caption, button labels). */

@media (prefers-reduced-motion: reduce) {
  @keyframes ga-rise          { from { opacity: 0; } }
  @keyframes ga-rise-sm       { from { opacity: 0; } }
  @keyframes ga-drop          { from { opacity: 0; } }
  @keyframes ga-corner-in     { from { opacity: 0; } }
  @keyframes ga-corner-release { from { opacity: 1; } }
  @keyframes ga-dot-in        { from { opacity: 0; } }
  @keyframes ga-breathe-scale { from { scale: 1; } }
  @keyframes ga-hunt          { 50% { opacity: .55; } }
  @keyframes ga-hunt-dot      { 50% { opacity: .4; } }
  @keyframes ga-attention     { 50% { opacity: .5; } }
  @keyframes ga-nudge         { from { transform: none; } }
  @keyframes ga-voice         { from { scale: 1; } }
  @keyframes ga-think {
    0%, 62%, 100% { opacity: .6; }
    28%           { opacity: 1; }
  }
  @keyframes ga-mark-in       { from { opacity: 0; } }
  @keyframes ga-voice-bar     { from { scale: 1; } }
  @keyframes ga-caption-in    { from { opacity: 0; } }
  @keyframes ga-caption-a     { from { opacity: 0; } }
  @keyframes ga-caption-b     { from { opacity: 0; } }

  :where(.btn:active:not(:disabled)) { transform: none; }
  #box[hidden] .box-corner { translate: none; }
}
