/* ==========================================================================
   Pico — motion system
   Every phase gets a distinct body loop, halo behaviour and face expression.
   Timings are deliberately slow: this thing sits on the desktop all day.
   ========================================================================== */

:root {
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out:    cubic-bezier(.16, 1, .3, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
}

/* ==========================================================================
   Companion shell
   ========================================================================== */
.pet {
  position: relative;
  width: var(--pet-size, 190px);
  height: var(--pet-size, 190px);
  flex: none;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: 50% 88%;
}

/* The stack: halo rings behind, body png, face svg on top of the screen */
.pet__halo,
.pet__body,
.pet__face { position: absolute; pointer-events: none; }

.pet__halo { inset: -18%; }
.pet__body { inset: 0; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(var(--shadow-pet)); }

.pet__face {
  left: var(--pet-screen-left);
  top: var(--pet-screen-top);
  width: var(--pet-screen-width);
  height: var(--pet-screen-height);
  overflow: visible;
}

/* The body itself carries the per-phase loop */
.pet__rig {
  position: absolute;
  inset: 0;
  transform-origin: 50% 88%;
  animation: pet-breathe 4.6s var(--ease-in-out) infinite;
}

/* ==========================================================================
   Body loops, one per phase
   ========================================================================== */
@keyframes pet-breathe {
  0%, 100% { transform: translateY(0)      scale(1,     1);     }
  50%      { transform: translateY(-2.5%)  scale(1.015, .985);  }
}

/* Observing — leans in toward the desktop it is reading */
@keyframes pet-lean {
  0%, 100% { transform: translateY(-1%) rotate(-3.2deg) scale(1.02); }
  50%      { transform: translateY(-3%) rotate(-1.4deg) scale(1.035); }
}

/* Thinking — hovers, drifting side to side */
@keyframes pet-ponder {
  0%, 100% { transform: translate(-1.5%, -2%) rotate(-1.6deg); }
  50%      { transform: translate( 1.5%, -4%) rotate( 1.6deg); }
}

/* Acting — small purposeful bob, quicker cadence */
@keyframes pet-work {
  0%, 100% { transform: translateY(0)    scale(1,    1);    }
  40%      { transform: translateY(-4%)  scale(.985, 1.02); }
  70%      { transform: translateY(.6%)  scale(1.02, .985); }
}

/* Approval — upright, then two sharp attention shakes */
@keyframes pet-alert {
  0%, 62%, 100% { transform: translateY(-3%) rotate(0deg) scale(1.05); }
  68%  { transform: translateY(-3%) rotate(-6deg) scale(1.05); }
  74%  { transform: translateY(-3%) rotate( 5deg) scale(1.05); }
  80%  { transform: translateY(-3%) rotate(-3deg) scale(1.05); }
  86%  { transform: translateY(-3%) rotate( 1.5deg) scale(1.05); }
}

/* Takeover — turns to face you and waits, patiently */
@keyframes pet-turn {
  0%, 100% { transform: translateY(-2%) scale(1.06, 1.04) rotate(0deg); }
  50%      { transform: translateY(-3.4%) scale(1.075, 1.05) rotate(0deg); }
}

/* Completed — settle then a single satisfied bounce */
@keyframes pet-cheer {
  0%   { transform: translateY(0)    scale(1,     1);    }
  22%  { transform: translateY(2%)   scale(1.08,  .92);  }
  48%  { transform: translateY(-13%) scale(.94,  1.08);  }
  72%  { transform: translateY(1.5%) scale(1.05,  .95);  }
  100% { transform: translateY(0)    scale(1,     1);    }
}

/* Failed — slumps and stays down */
@keyframes pet-slump {
  0%   { transform: translateY(0)   rotate(0deg)   scale(1,     1);    }
  100% { transform: translateY(3.5%) rotate(-5deg) scale(1.035, .955); }
}

.pet[data-phase="Idle"]             .pet__rig { animation: pet-breathe 4.6s var(--ease-in-out) infinite; }
.pet[data-phase="Starting"]         .pet__rig { animation: pet-work    1.5s var(--ease-in-out) infinite; }
.pet[data-phase="Observing"]        .pet__rig { animation: pet-lean    3.2s var(--ease-in-out) infinite; }
.pet[data-phase="Thinking"]         .pet__rig { animation: pet-ponder  3.6s var(--ease-in-out) infinite; }
.pet[data-phase="Acting"]           .pet__rig { animation: pet-work    1.15s var(--ease-in-out) infinite; }
.pet[data-phase="AwaitingApproval"] .pet__rig { animation: pet-alert   3.4s var(--ease-in-out) infinite; }
.pet[data-phase="AwaitingTakeover"] .pet__rig { animation: pet-turn    2.6s var(--ease-in-out) infinite; }
.pet[data-phase="Completed"]        .pet__rig { animation: pet-cheer   1.1s var(--ease-spring) 1 both; }
.pet[data-phase="Failed"]           .pet__rig { animation: pet-slump    .7s var(--ease-out) 1 both; }
.pet[data-phase="Stopped"]          .pet__rig { animation: pet-slump    .6s var(--ease-out) 1 both; }

/* Paused freezes the loop exactly where it stands — the strongest possible
   signal that nothing is moving. */
.pet[data-phase="Paused"] .pet__rig { animation-play-state: paused; }

/* ==========================================================================
   Halo rings
   ========================================================================== */
.halo__ring {
  fill: none;
  stroke: var(--accent);
  transform-origin: 50% 50%;
  transition: stroke .5s var(--ease-out), opacity .5s var(--ease-out);
}

/* Base ring — always breathing gently */
.halo__base {
  stroke-width: 1.5;
  opacity: .3;
  animation: halo-breathe 4.6s var(--ease-in-out) infinite;
}
@keyframes halo-breathe {
  0%, 100% { transform: scale(.96); opacity: .22; }
  50%      { transform: scale(1.02); opacity: .42; }
}

/* Sweep arc — a rotating dash, used while the agent is doing something */
.halo__sweep {
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0;
  transition: opacity .45s var(--ease-out);
  animation: halo-spin 2.4s linear infinite;
}
@keyframes halo-spin { to { transform: rotate(360deg); } }

.pet[data-phase="Observing"] .halo__sweep,
.pet[data-phase="Thinking"]  .halo__sweep,
.pet[data-phase="Starting"]  .halo__sweep,
.pet[data-phase="Acting"]    .halo__sweep { opacity: .95; }

.pet[data-phase="Observing"] .halo__sweep { animation-duration: 1.8s; }
.pet[data-phase="Thinking"]  .halo__sweep { animation-duration: 3.2s; }
.pet[data-phase="Acting"]    .halo__sweep { animation-duration: 1.1s; }
.pet[data-phase="Paused"]    .halo__sweep { animation-play-state: paused; opacity: .3; }

/* Pulse ring — fired imperatively once per action event */
.halo__pulse {
  stroke-width: 2;
  opacity: 0;
  transform-origin: 50% 50%;
}
.halo__pulse.is-pulsing { animation: halo-pulse .85s var(--ease-out) 1; }
@keyframes halo-pulse {
  0%   { transform: scale(.82); opacity: .85; stroke-width: 3; }
  100% { transform: scale(1.25); opacity: 0;   stroke-width: .5; }
}

/* Attention ring for the two states that need a human */
.pet[data-phase="AwaitingApproval"] .halo__base,
.pet[data-phase="AwaitingTakeover"] .halo__base {
  opacity: .75;
  stroke-width: 2.5;
  animation: halo-attention 1.5s var(--ease-in-out) infinite;
}
@keyframes halo-attention {
  0%, 100% { transform: scale(.97); opacity: .5; }
  50%      { transform: scale(1.06); opacity: .95; }
}

/* Failure — the ring breaks open */
.pet[data-phase="Failed"] .halo__base { opacity: .5; stroke-dasharray: 14 26; animation: none; }

/* ==========================================================================
   Face — the mascot's screen is repainted so it can carry colour + emotion
   ========================================================================== */
.face__screen {
  fill: url(#faceGradient);
  transition: opacity .4s var(--ease-out);
}
.face__glow { filter: blur(9px); opacity: .55; }

.face__feature {
  fill: #fdfff5;
  transition:
    d      .32s var(--ease-spring),
    rx     .32s var(--ease-spring),
    ry     .32s var(--ease-spring),
    x      .32s var(--ease-spring),
    y      .32s var(--ease-spring),
    height .32s var(--ease-spring),
    width  .32s var(--ease-spring),
    opacity .2s linear;
}

/* Eyes track together via a group transform (look direction) */
.face__eyes {
  transition: transform .45s var(--ease-out);
  transform-box: fill-box;
}

/* Blink is a fast scaleY on each eye, driven by a class toggle */
.face__eye { transform-origin: center; transform-box: fill-box; }
.face__eye.is-blinking { animation: eye-blink .16s ease-in-out 1; }
@keyframes eye-blink {
  0%, 100% { transform: scaleY(1); }
  50%      { transform: scaleY(.06); }
}

/* Thinking — eyes drift left/right on their own */
.pet[data-phase="Thinking"] .face__eyes { animation: eyes-drift 3.6s var(--ease-in-out) infinite; }
@keyframes eyes-drift {
  0%, 100% { transform: translateX(-7px); }
  50%      { transform: translateX(7px); }
}

/* Observing — a scanline crosses the screen */
.face__scan { opacity: 0; }
.pet[data-phase="Observing"] .face__scan {
  opacity: .5;
  animation: face-scan 1.8s var(--ease-in-out) infinite;
}
@keyframes face-scan {
  0%   { transform: translateY(-150px); opacity: 0; }
  15%  { opacity: .55; }
  85%  { opacity: .55; }
  100% { transform: translateY(150px);  opacity: 0; }
}

/* Paused — the screen dims like a sleeping monitor */
.pet[data-phase="Paused"] .face__screen { opacity: .55; }

/* Forehead status dot picks up the accent and throbs when a human is needed */
.pet__dot {
  position: absolute;
  left: 49.64%;
  top: 32.06%;
  width: 3.99%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px 2px var(--accent-glow);
  transition: background .5s var(--ease-out), box-shadow .5s var(--ease-out);
  pointer-events: none;
}
.pet[data-phase="AwaitingApproval"] .pet__dot,
.pet[data-phase="AwaitingTakeover"] .pet__dot { animation: dot-throb 1.5s var(--ease-in-out) infinite; }
@keyframes dot-throb {
  0%, 100% { transform: translate(-50%, -50%) scale(1);   box-shadow: 0 0 8px 2px var(--accent-glow); }
  50%      { transform: translate(-50%, -50%) scale(1.5); box-shadow: 0 0 18px 6px var(--accent-glow); }
}

/* ==========================================================================
   Panels
   ========================================================================== */
@keyframes panel-in {
  0%   { opacity: 0; transform: translateY(10px) scale(.965); filter: blur(8px); }
  100% { opacity: 1; transform: translateY(0)    scale(1);    filter: blur(0);   }
}
@keyframes panel-out {
  0%   { opacity: 1; transform: translateY(0)   scale(1);    filter: blur(0);   }
  100% { opacity: 0; transform: translateY(6px) scale(.975); filter: blur(6px); }
}
.panel-in  { animation: panel-in  .34s var(--ease-out) 1 both; }
.panel-out { animation: panel-out .18s var(--ease-in-out) 1 both; }

@keyframes row-in {
  0%   { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}
.row-in { animation: row-in .3s var(--ease-out) 1 both; }

/* Cards that demand a decision get a slow accent breathing border */
@keyframes card-attention {
  0%, 100% { box-shadow: var(--shadow-lift), 0 0 0 1px color-mix(in oklab, var(--accent) 30%, transparent); }
  50%      { box-shadow: var(--shadow-lift), 0 0 0 1px color-mix(in oklab, var(--accent) 70%, transparent), 0 0 26px -4px var(--accent-glow); }
}
.card-attention { animation: card-attention 2.4s var(--ease-in-out) infinite; }

/* Shake used when a blocked action is attempted */
@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  45%      { transform: translateX(5px); }
  70%      { transform: translateX(-3px); }
}
.nudge { animation: nudge .38s var(--ease-in-out) 1; }

/* Progress worm for indeterminate work */
@keyframes worm {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
.worm {
  position: relative;
  height: 2px;
  border-radius: 2px;
  overflow: hidden;
  background: color-mix(in oklab, var(--ink-5) 70%, transparent);
}
.worm::after {
  content: "";
  position: absolute;
  inset-block: 0;
  width: 25%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: worm 1.5s var(--ease-in-out) infinite;
}

/* ==========================================================================
   Reduced motion — keep meaning, drop movement
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  /* Phase must still be readable without motion, so hold the states that
     normally rely on an animation loop. */
  .pet[data-phase="AwaitingApproval"] .halo__base,
  .pet[data-phase="AwaitingTakeover"] .halo__base { opacity: .9; stroke-width: 3; }
  .halo__sweep { opacity: 0 !important; }
  .worm::after { animation: none; width: 100%; opacity: .5; }
}
