/* Agent figures (decision #35): the drawing, how it walks, and what it does
   when it comes to rest. The scenes that move figures around a page are in
   css/agent-scenes.css; the set pieces they act on are in
   css/agent-acts.css.
   Figures are drawn by js/agents/agent-figure.js and run by
   js/agents/agent-scenes.js:
     host:   agent-scene--armed (waiting) -> --playing -> --done
     figure: is-walking while its actor moves, then is-resting
   An actor (.agent-actor) is the element whose animation moves a figure. */

/* ── Pace and size defaults, per scene host ──────────── */
[data-agent-scene] {
  --agent-walk-time: 2.6s;  /* one walk, start to stop */
  --agent-step-time: 0.34s; /* one leg swing */
  --agent-size: 56px;       /* height of the figure's box; the drawing fills about 60% of it */
}

/* ── Ink, shared by figures, set pieces and extras ───── */
.agent-figure,
.agent-set,
.agent-extra {
  --agent-line: #262626;
  --agent-accent: #2350A8;
  --agent-mark: #FFE36E;
  --agent-paper: #FFFFFF;
  display: block;
  color: var(--agent-line);
  overflow: visible;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
  /* A hard paper-coloured outline, so the drawing still reads in front of
     dark letters. Four offset copies, no blur: not a shadow. */
  filter:
    drop-shadow(1.5px 0 0 var(--agent-paper))
    drop-shadow(-1.5px 0 0 var(--agent-paper))
    drop-shadow(0 1.5px 0 var(--agent-paper))
    drop-shadow(0 -1.5px 0 var(--agent-paper));
}

/* Hidden until its actor starts moving */
.agent-scene--armed .agent-figure,
.agent-scene--playing .agent-figure { opacity: 0; }
.agent-scene--playing .agent-figure.is-walking,
.agent-scene--playing .agent-figure.is-resting { opacity: 1; }

/* ── Moving parts ────────────────────────────────────── */
.agent-figure__leg,
.agent-figure__arm,
.agent-figure__raised-arm,
.agent-figure__marker-arm,
.agent-figure__gear,
.agent-figure__eyes,
.agent-figure__head,
.agent-figure__question,
.agent-glyph {
  transform-box: fill-box;
}
/* Legs swing from the hip, arms from the shoulder */
.agent-figure__leg--left,
.agent-figure__arm--left { transform-origin: 100% 0; }
.agent-figure__leg--right,
.agent-figure__arm--right { transform-origin: 0 0; }
.agent-figure__arm { transition: transform 0.3s ease-out; }
/* The arm that holds something turns about the shoulder, at (35, 23) */
.agent-figure__holding-arm {
  transform-origin: 35px 23px;
  transition: transform 0.3s ease-out;
}
.agent-figure__marker-arm {
  transform-origin: 100% 0;
  transition: transform 0.4s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.agent-figure__eyes { transition: transform 0.25s ease; }
.agent-figure__mouth { transition: opacity 0.2s ease; }
.agent-figure__mouth--smile { opacity: 0; }
/* Reads the same way round in a mirrored scene */
.agent-glyph { transform-origin: 50% 50%; }
.agent-scene--mirrored .agent-glyph { scale: -1 1; }

/* ── Walking ─────────────────────────────────────────── */
.agent-figure.is-walking .agent-figure__leg--left {
  animation: agent-step var(--agent-step-time) ease-in-out infinite alternate;
}
.agent-figure.is-walking .agent-figure__leg--right {
  animation: agent-step var(--agent-step-time) ease-in-out infinite alternate-reverse;
}
.agent-figure.is-walking .agent-figure__head {
  animation: agent-bob var(--agent-step-time) ease-in-out infinite alternate;
}
.agent-figure.is-walking .agent-figure__eyes { transform: translateX(2px); }
.agent-actor--leftward .agent-figure.is-walking .agent-figure__eyes { transform: translateX(-2px); }

/* ── Resting: a smile and one small hop ──────────────── */
.agent-figure.is-resting { animation: agent-hop 0.45s ease-out; }
.agent-figure.is-resting .agent-figure__marker-arm { transform: rotate(136deg); }
.agent-figure.is-resting .agent-figure__mouth--busy { opacity: 0; }
.agent-figure.is-resting .agent-figure__mouth--smile { opacity: 1; }

/* ── End poses: what a figure does once, on arriving ─── */
/* wave: waves and puts its arm down again */
.agent-figure--ends-wave.is-resting .agent-figure__arm--right {
  animation: agent-wave 1.6s ease-in-out 0.35s 1;
}
/* tap: one poke at what stands beside it. type: a run of them. */
.agent-figure--ends-tap.is-resting .agent-figure__arm--right { animation: agent-poke 0.5s ease-in-out 0.35s 1; }
.agent-figure--ends-tap.is-resting .agent-figure__holding-arm { animation: agent-swing 0.5s ease-in-out 0.35s 1; }
.agent-figure--ends-type.is-resting .agent-figure__arm--right { animation: agent-poke 0.3s ease-in-out 0.3s 7; }
.agent-figure--ends-type.is-resting .agent-figure__holding-arm { animation: agent-swing 0.36s ease-in-out 0.3s 6; }
/* cheer: arms up, three hops */
.agent-figure--ends-cheer.is-resting { animation: agent-hop 0.45s ease-out 3; }
.agent-figure--ends-cheer.is-resting .agent-figure__arm--left { transform: rotate(75deg); }
.agent-figure--ends-cheer.is-resting .agent-figure__arm--right { transform: rotate(-75deg); }
.agent-figure--ends-cheer.is-resting .agent-figure__holding-arm { transform: rotate(-24deg); }
/* kick: the right leg swings, and once the ball is in, it cheers */
.agent-figure--ends-kick.is-resting { animation: agent-hop 0.45s ease-out 1.15s 2; }
.agent-figure--ends-kick.is-resting .agent-figure__leg--right { animation: agent-kick 0.45s ease-out 0.15s 1; }
.agent-figure--ends-kick.is-resting .agent-figure__arm--left { transform: rotate(75deg); transition-delay: 1.1s; }
.agent-figure--ends-kick.is-resting .agent-figure__arm--right { transform: rotate(-75deg); transition-delay: 1.1s; }
/* slip: feet go forward, it lands on its back, then gets up again. The
   figure turns about its feet and is lifted by half its width so it lies on
   the line. It smiles only once it is back up. */
.agent-figure--ends-slip.is-resting {
  transform-origin: 50% 82.8%;
  animation: agent-slip 2.8s ease-in-out both;
}
.agent-figure--ends-slip.is-resting .agent-figure__mouth { transition-delay: 2.5s; }
.agent-figure--ends-slip.is-resting .agent-figure__leg--left { animation: agent-step 0.2s ease-in-out 0.5s 6 alternate; }
.agent-figure--ends-slip.is-resting .agent-figure__leg--right { animation: agent-step 0.2s ease-in-out 0.5s 6 alternate-reverse; }
/* conduct: beats time with what it holds */
.agent-figure--ends-conduct.is-resting .agent-figure__holding-arm {
  animation: agent-conduct 0.45s ease-in-out 0.4s 8 alternate;
}
/* throw: three throws with the free right arm */
.agent-figure--ends-throw.is-resting .agent-figure__arm--right { animation: agent-throw 0.5s ease-out 0.3s 3; }
/* puzzled: looks both ways under a question mark, and does not smile */
.agent-figure__question {
  transform-origin: 50% 100%;
  opacity: 0;
  transition: opacity 0.2s ease 0.5s;
}
.agent-figure--ends-puzzled.is-resting .agent-figure__question {
  opacity: 1;
  animation: agent-pop-in 0.35s cubic-bezier(0.3, 1.5, 0.5, 1) 0.5s backwards;
}
.agent-figure--ends-puzzled.is-resting .agent-figure__eyes { animation: agent-look 2s ease-in-out 0.7s 1; }
.agent-figure--ends-puzzled.is-resting .agent-figure__mouth--busy { opacity: 1; }
.agent-figure--ends-puzzled.is-resting .agent-figure__mouth--smile { opacity: 0; }

/* ── What they hold and wear ─────────────────────────── */
/* The gear turns while its agent walks; the clipboard's check mark is drawn
   and the bulb lights a moment after their agent has stopped; raised arms
   come down once the load they carried overhead has been let go; the notes
   of a pair of headphones drift up while there is something to do. */
.agent-figure__gear { transform-origin: 50% 50%; }
.agent-figure.is-walking .agent-figure__gear { animation: agent-spin 1.6s linear infinite; }
.agent-figure__check {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.35s ease-out 0.6s;
}
.agent-figure.is-resting .agent-figure__check { stroke-dashoffset: 0; }
.agent-figure__bulb-glass { transition: fill 0.2s ease 0.55s; }
.agent-figure__bulb-rays { opacity: 0; transition: opacity 0.2s ease 0.55s; }
.agent-figure.is-resting .agent-figure__bulb-glass { fill: var(--agent-mark); }
.agent-figure.is-resting .agent-figure__bulb-rays { opacity: 1; }
.agent-figure__raised-arm { transition: transform 0.35s ease-in-out; }
.agent-figure__raised-arm--left { transform-origin: 100% 100%; }
.agent-figure__raised-arm--right { transform-origin: 0 100%; }
/* Lowered and shortened: an arm long enough to reach overhead would hang
   past the feet */
.agent-figure.has-delivered .agent-figure__raised-arm--left { transform: rotate(-135deg) scaleY(0.45); }
.agent-figure.has-delivered .agent-figure__raised-arm--right { transform: rotate(135deg) scaleY(0.45); }
.agent-figure__notes { opacity: 0; }
.agent-figure.is-walking .agent-figure__notes { animation: agent-notes 1.3s ease-in-out infinite; }
.agent-figure.is-resting .agent-figure__notes { animation: agent-notes 1.3s ease-in-out 3; }

@keyframes agent-spin {
  to { transform: rotate(360deg); }
}
@keyframes agent-step {
  from { transform: rotate(-24deg); }
  to { transform: rotate(24deg); }
}
@keyframes agent-bob {
  from { transform: translateY(0); }
  to { transform: translateY(-1.5px); }
}
@keyframes agent-hop {
  0% { transform: translateY(0); }
  40% { transform: translateY(calc(var(--agent-size) * -0.12)); }
  100% { transform: translateY(0); }
}
@keyframes agent-wave {
  0%, 100% { transform: rotate(0deg); }
  20%, 50%, 80% { transform: rotate(-80deg); }
  35%, 65% { transform: rotate(-55deg); }
}
@keyframes agent-poke {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-42deg); }
}
@keyframes agent-swing {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(24deg); }
}
@keyframes agent-kick {
  0%, 100% { transform: rotate(0deg); }
  40% { transform: rotate(-55deg); }
}
@keyframes agent-slip {
  0% { transform: translateY(0) rotate(0deg); animation-timing-function: ease-in; }
  9% { transform: translateY(-16%) rotate(-40deg); animation-timing-function: ease-in; }
  20% { transform: translateY(-21%) rotate(-90deg); animation-timing-function: ease-out; }
  26% { transform: translateY(-27%) rotate(-90deg); animation-timing-function: ease-in; }
  32%, 66% { transform: translateY(-21%) rotate(-90deg); }
  86% { transform: translateY(-5%) rotate(-10deg); }
  100% { transform: translateY(0) rotate(0deg); }
}
@keyframes agent-conduct {
  from { transform: rotate(-20deg); }
  to { transform: rotate(16deg); }
}
@keyframes agent-throw {
  0% { transform: rotate(-115deg); }
  45% { transform: rotate(-25deg); }
  100% { transform: rotate(0deg); }
}
@keyframes agent-look {
  0%, 100% { transform: translateX(0); }
  20%, 40% { transform: translateX(-2.5px); }
  60%, 80% { transform: translateX(2.5px); }
}
@keyframes agent-notes {
  0% { opacity: 0; transform: translateY(3px); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}
@keyframes agent-pop-in {
  from { transform: scale(0); }
  to { transform: scale(1); }
}
