/* Agent acts: the set pieces an agent works on and how each one reacts.
   Drawn by js/agents/agent-set-pieces.js in the figure's units (80 make the
   figure's height), placed by the ledge scene (css/agent-scenes.css).
   A piece appears when its scene starts playing and reacts when the scene is
   done, which is the moment its agent arrives. Lengths inside a drawing are
   in its own units. */

/* ── Placement ───────────────────────────────────────── */
/* --set-offset: units from the near edge of the agent's box at its stop. */
.agent-set {
  position: absolute;
  inset-inline-start: calc(var(--agent-to) + var(--agent-size) * var(--set-offset) / 80);
  bottom: var(--agent-ledge-lift, 0px);
  width: calc(var(--agent-size) * var(--set-width) / 80);
  height: calc(var(--agent-size) * var(--set-height) / 80);
}
.agent-scene--armed .agent-set { opacity: 0; }
.agent-scene--mirrored .agent-set { scale: -1 1; }

/* ── Parts that wait for the agent ───────────────────── */
/* --act-delay: when the first part reacts. --part-gap: the beat between one
   part and the next. */
.agent-set {
  --act-delay: 0.45s;
  --part-gap: 0.25s;
}
.agent-set__stroke {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.5s ease-in-out calc(var(--act-delay) + var(--stroke-order) * var(--part-gap));
}
.agent-scene--done .agent-set__stroke { stroke-dashoffset: 0; }
.agent-set__pop {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  transform: scale(0);
  transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1) calc(var(--act-delay) + var(--pop-order) * var(--part-gap));
}
.agent-scene--done .agent-set__pop { transform: scale(1); }

/* ── Phone: buzzes until it is tapped ────────────────── */
.agent-set__phone-body { transform-origin: 14px 41px; }
.agent-scene--playing .agent-set__phone-body { animation: agent-buzz 0.9s linear infinite; }
.agent-scene--playing .agent-set__buzz-lines { animation: agent-buzz-lines 0.9s linear infinite; }
.agent-scene--done .agent-set__phone-body { animation: agent-buzz-last 0.6s linear 1; }
.agent-scene--done .agent-set__buzz-lines {
  opacity: 0; /* where it ends when nothing is animated */
  animation: agent-buzz-lines-last 0.6s linear 1 both;
}
.agent-set__alert { transition: opacity 0.2s ease 0.6s; }
.agent-scene--done .agent-set__alert { opacity: 0; }
.agent-set--phone { --act-delay: 0.5s; }

@keyframes agent-buzz {
  0%, 10%, 20%, 30%, 40%, 50% { transform: rotate(-7deg); }
  5%, 15%, 25%, 35%, 45% { transform: rotate(7deg); }
  55%, 100% { transform: rotate(0deg); }
}
@keyframes agent-buzz-lines {
  0%, 52% { opacity: 1; }
  56%, 100% { opacity: 0; }
}
@keyframes agent-buzz-last {
  0%, 16%, 32%, 48%, 64% { transform: rotate(-9deg); }
  8%, 24%, 40%, 56% { transform: rotate(9deg); }
  72%, 100% { transform: rotate(0deg); }
}
@keyframes agent-buzz-lines-last {
  0%, 68% { opacity: 1; }
  74%, 100% { opacity: 0; }
}

/* ── Goal: the net gives when the ball arrives ───────── */
.agent-scene--done .agent-set__net { animation: agent-net-give 0.45s ease-out 1.05s 1; }
@keyframes agent-net-give {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(3px); }
  70% { transform: translateX(-1px); }
}

/* ── Computer: a cursor waits, then the screen fills ─── */
.agent-scene--playing .agent-set__cursor { animation: agent-blink-cursor 0.8s steps(1) infinite; }
.agent-scene--done .agent-set__cursor { opacity: 0; }
.agent-set--computer .agent-set__stroke { transition-duration: 1.2s; }
.agent-set--computer { --part-gap: 0.6s; }
@keyframes agent-blink-cursor {
  0% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ── Eye: follows the agent across, then blinks ──────── */
.agent-set__pupil { transform: translateX(-6px); }
.agent-scene--playing .agent-set__pupil {
  animation: agent-eye-follow var(--agent-walk-time) cubic-bezier(0.45, 0, 0.4, 1) both;
}
.agent-scene--done .agent-set__pupil { transform: translateX(6px); }
.agent-set__eyeball { transform-origin: 22px 20px; }
.agent-scene--done .agent-set__eyeball { animation: agent-blink 0.28s ease-in-out 0.6s 2; }
@keyframes agent-eye-follow {
  from { transform: translateX(-6px); }
  to { transform: translateX(6px); }
}
@keyframes agent-blink {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.08); }
}

/* ── Machine: whirs, then a finished page comes up ───── */
/* The page starts hidden behind the machine's body */
.agent-set__page-out {
  transform: translateY(19.5px);
  transition: transform 0.7s ease-out 1.15s;
}
.agent-scene--done .agent-set__page-out { transform: translateY(0); }
.agent-set__machine-gear {
  transform-box: fill-box;
  transform-origin: 50% 50%;
}
.agent-scene--done .agent-set__machine-gear { animation: agent-spin 0.9s linear 0.45s 1; }
.agent-scene--done .agent-set__machine-body { animation: agent-whir 0.15s linear 0.45s 6; }
@keyframes agent-whir {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(0.8px); }
}

/* ── Whiteboard: the kanban card moves to "done" ─────── */
.agent-set__card { transition: transform 0.8s ease-in-out 0.5s; }
.agent-scene--done .agent-set__card { transform: translate(30px, -16px); }
.agent-set--whiteboard { --part-gap: 0.45s; }

/* ── Socket: lights up when plugged in ───────────────── */
.agent-set__plate { transition: fill 0.2s ease 0.3s; }
.agent-scene--done .agent-set__plate { fill: var(--agent-mark); }
.agent-set--socket { --act-delay: 0.25s; }

/* ── Server: lights flicker, then settle one by one ──── */
.agent-set__led {
  fill: var(--agent-paper);
  stroke: currentColor;
  stroke-width: 1.4px;
  transition: fill 0.2s ease calc(0.7s + var(--led-order) * 0.3s);
}
.agent-scene--playing .agent-set__led {
  animation: agent-led-flicker 0.6s steps(1) calc(var(--led-order) * -0.22s) infinite;
}
.agent-scene--done .agent-set__led { fill: var(--agent-accent); }
@keyframes agent-led-flicker {
  0% { fill: var(--agent-line); }
  40%, 100% { fill: var(--agent-paper); }
}

/* ── Banana peel: shoots out from under the foot ─────── */
.agent-scene--done .agent-set--banana {
  animation: agent-peel-fly 0.8s linear 0.05s both;
}
@keyframes agent-peel-fly {
  0% { transform: translate(0, 0) rotate(0deg); animation-timing-function: ease-out; }
  45% { transform: translate(calc(var(--agent-size) * 0.45), calc(var(--agent-size) * -0.3)) rotate(200deg); animation-timing-function: ease-in; }
  100% { transform: translate(calc(var(--agent-size) * 0.9), 0) rotate(360deg); }
}

/* ── Target: a dart lands with each throw ────────────── */
.agent-set--target {
  --act-delay: 0.55s;
  --part-gap: 0.25s;
}
.agent-set--target .agent-set__pop { transition-duration: 0.12s; }
.agent-set__board { transform-origin: 18px 33px; }
.agent-scene--done .agent-set__board { animation: agent-thud 0.5s ease-out 0.55s 3; }
@keyframes agent-thud {
  0%, 30%, 100% { transform: rotate(0deg); }
  10% { transform: rotate(4deg); }
  20% { transform: rotate(-2deg); }
}

/* ── Scale: tips back and forth, then settles ────────── */
.agent-set__beam { transform-origin: 23px 9px; }
.agent-scene--done .agent-set__beam { animation: agent-weigh 1.8s ease-in-out 0.4s 1 both; }
@keyframes agent-weigh {
  0% { transform: rotate(0deg); }
  20% { transform: rotate(-11deg); }
  45% { transform: rotate(9deg); }
  65% { transform: rotate(-6deg); }
  82% { transform: rotate(3deg); }
  100% { transform: rotate(-4deg); }
}

/* ── Crew: small agents that pop up beside the lead ──── */
/* 62% of the lead's size, standing one after another past its box. */
.agent-mini {
  position: absolute;
  inset-inline-start: calc(var(--agent-to) + var(--agent-size) * (0.8 + var(--mini-order) * 0.5));
  bottom: calc(var(--agent-ledge-lift, 0px) - var(--agent-size) * 0.62 * 0.172);
  width: calc(var(--agent-size) * 0.62 * 0.9);
  height: calc(var(--agent-size) * 0.62);
  transform-origin: 50% 82.8%;
  transition: opacity 0.2s ease-out;
}
.agent-mini .agent-figure {
  width: 100%;
  height: 100%;
}
.agent-scene--mirrored .agent-mini { scale: -1 1; }
.agent-scene--armed .agent-mini,
.agent-scene--playing .agent-mini { opacity: 0; }
.agent-scene--done .agent-mini {
  animation: agent-pop-in 0.4s cubic-bezier(0.3, 1.5, 0.5, 1) calc(0.6s + var(--mini-order) * 0.3s) both;
}
.agent-scene--done .agent-mini .agent-figure {
  animation: agent-hop 0.5s ease-out calc(1.5s + var(--mini-order) * 0.25s) 3;
}
