/* swarm.css: the crew floor's creatures and the stage's children (DESIGN-R3 §4.2, §6, §7; R6 §2.1; R7 §1).
   base.css owns the boxes (.swarm, .stage, .hw, .fx) and the glow; this file places and plays what
   swarm.js puts in them: lobsters, slips, the fan flash, the release, the crab.
   States sit outside the no-preference block at the end, so reduced motion shows end states, still. */

[data-swarm] { --swarm-css: 1; }

/* Fallbacks only (zero specificity): base.css's :root wins whenever it is there. */
:where(:root) { --deep: #0b1035; --foam: #f6f2e8; --coral: #ff5a3d; --sea: #2fe0c2; --lamp: #ffc531; --lob-live-hi: #ff9a80; }

/* ---------- hero ---------- */
.swarm .lob, .swarm .commit, .swarm .shadow, .swarm .defs, .swarm .ring {
  position: absolute;
  top: 0;
  left: 0;
}
.swarm .defs { width: 0; height: 0; overflow: hidden; }
.swarm svg { display: block; overflow: visible; }
/* Sizes move in step with swarm.js's [lw, pw]: lobsters 64 / 92 / 112 px, slips 12 / 17 / 20 px. */
.swarm .lob { width: 64px; aspect-ratio: 3 / 2; will-change: transform; z-index: 3; }
.swarm .commit { width: 12px; aspect-ratio: 4 / 3; z-index: 2; visibility: hidden; }
.swarm .commit.is-on { visibility: visible; }
.swarm .commit svg { transform: scale(.3); }
.swarm .commit.is-on svg { transform: none; }
.swarm [hidden], .stage [hidden] { display: none; }
@media (min-width: 721px) {
  .swarm .lob { width: 92px; }
  .swarm .commit { width: 17px; }
}
@media (min-width: 1280px) {
  .swarm .lob { width: 112px; }
  .swarm .commit { width: 20px; }
}
/* The release slip is lamp gold, in its carrier's claws up the lane and in flight; its folded corner a
   shade deeper; an amber edge keeps it on the dock. */
:is(.slip, .agent).is-gold .pp { fill: var(--lamp); }
:is(.slip, .agent).is-gold .pf { fill: #d99a12; }
:is(.slip, .agent).is-gold :is(.pp, .pf) { stroke: #7a4a00; stroke-width: 1; }
/* The visitor's torch: a soft foam pool where the pointer is. */
.swarm .shadow {
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(246, 242, 232, .09), rgba(246, 242, 232, 0) 68%);
  opacity: 0;
  z-index: 4;
  will-change: transform;
}
.swarm .shadow.is-on { opacity: 1; }

/* ---------- the stage ---------- */
.stage .hw-workstation { right: 0; bottom: 35%; width: 100%; }
.stage .hw-clawbox { left: 0; bottom: 0; width: 52%; }
/* One caption row on the stage's bottom edge, 12 px under the small box: ClawBox left, Workstation right. */
.stage .hw-workstation .hw-name { position: absolute; right: 0; bottom: -61.3%; margin: 0; white-space: nowrap; }
.stage .hw-clawbox .hw-name { margin-top: 12px; white-space: nowrap; }
.stage .hw-name small { display: none; }
@media (min-width: 1280px) and (min-height: 801px) { .stage .hw-name small { display: block; } }
/* the small box steps left: machines and labels stay apart (base.css's --cb-over: the same shares) */
@media (max-width: 720px) { .stage .hw-clawbox { left: -48%; } }
@media (min-width: 721px) and (max-width: 1279px) { .stage .hw-clawbox { left: -24%; } }
@media (min-width: 1280px) { .stage .hw-clawbox { left: -12%; } }
/* The crab stands on the Workstation's lid, feet 18 % of the image behind its front edge and clear of
   the right edge (lid measured from the hw.py corners); its contact shadow is base.css's. */
.stage .crab-perch { position: absolute; display: block; pointer-events: none; left: 47%; bottom: 66%; width: 20%; aspect-ratio: 1; }
.crab-perch img { position: relative; display: block; width: 100%; height: 100%; transform-origin: 50% 90%; }

/* The dock, the contact shadows and the fx layer's boxes and colours are base.css's; this file plays
   the fx (motion block). */

/* ---------- the agent: one drawing (sprites-v4, 120x80, facing +x), several poses ---------- */
.agent svg { transform-origin: 50% 50%; }
.agent .claw-l, .agent .claw-r, .agent .ant-l, .agent .ant-r { transform-origin: 0 0; }
.agent .legs-l { transform-origin: 65px 32px; }
.agent .legs-r { transform-origin: 65px 48px; }
/* the tail hinges where it meets the carapace: a flick tucks it under, pride fans it out */
.agent .tail { transform-origin: 48px 40px; }
.agent .carry { visibility: hidden; transform-origin: 115px 40px; }
/* three individuals: small, standard, big and left-handed */
.agent .lobster { transform-origin: 60px 40px; }
.agent.v1 .lobster { transform: scale(.92); }
.agent.v3 .lobster { transform: scale(1.06, -1.06); }
.agent:is(.is-carrying, .pose-carry) .carry { visibility: visible; }
.agent:is(.is-carrying, .pose-carry) .claw-l { transform: rotate(11deg); }
.agent:is(.is-carrying, .pose-carry) .claw-r { transform: rotate(-11deg); }
.agent.is-grabbing .claw-l { transform: rotate(10deg); }
.agent.is-grabbing .claw-r { transform: rotate(-10deg); }
.agent:is(.is-proud, .pose-celebrate) .claw-l { transform: rotate(-60deg); }
.agent:is(.is-proud, .pose-celebrate) .claw-r { transform: rotate(60deg); }
.agent:is(.is-proud, .pose-celebrate) .tail { transform: scale(1.15); }
.agent:is(.is-queued, .pose-queue) .claw-l { transform: rotate(8deg); }
.agent:is(.is-queued, .pose-queue) .claw-r { transform: rotate(-8deg); }
.agent:is(.is-queued, .pose-queue) .ant-l { transform: rotate(-10deg); }
.agent:is(.is-queued, .pose-queue) .ant-r { transform: rotate(10deg); }
/* idle: a claw ajar; the antennae twitch */
.agent:is(.is-idle, .pose-idle) .claw-l { transform: rotate(-7deg); }
.agent.is-startled .claw-l { transform: rotate(-28deg); }
.agent.is-startled .claw-r { transform: rotate(28deg); }
.agent.is-flipping .tail { transform: scaleX(.45); }

/* Paused with the rAF loop (off screen, hidden tab). */
.swarm.is-paused *, .swarm.is-paused ~ .stage * { animation-play-state: paused !important; }

/* ---------- the brand's K-claw, turned up once the reader is past the hero ---------- */
.brand-mark svg { display: block; overflow: visible; color: var(--coral); }
header.is-scrolled .brand-mark svg { transform: rotate(-90deg); }
.brand:is(:hover, :focus-visible) .brand-mark svg { color: var(--lob-live-hi); }

/* ---------- motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  .agent .legs-l { animation: scuttle .36s ease-in-out infinite alternate paused; }
  .agent .legs-r { animation: scuttle .36s ease-in-out -.18s infinite alternate-reverse paused; }
  .agent.is-walking .legs-l, .agent.is-walking .legs-r { animation-play-state: running; }
  .agent .claw-l, .agent .claw-r, .agent .ant-l, .agent .ant-r { transition: transform .2s cubic-bezier(.2, .7, .2, 1); }
  .agent svg { transition: transform .3s cubic-bezier(.2, .7, .2, 1); }
  .agent .tail { transition: transform .26s cubic-bezier(.3, 1.8, .5, 1); }
  .agent.is-flipping .tail { transition: transform .08s ease-in; }
  .agent.is-proud svg { animation: hop .18s ease-out 2; }
  .agent:is(.is-idle, .pose-idle) .ant-l { animation: twitch 2s ease-in-out infinite; }
  .agent:is(.is-idle, .pose-idle) .ant-r { animation: twitch-r 2s ease-in-out -.7s infinite; }
  .agent.is-idle:nth-child(3n) .ant-l, .agent.is-idle:nth-child(3n) .ant-r { animation-delay: -1.3s; }
  .agent.is-idle:nth-child(3n + 1) .ant-l { animation-delay: -.4s; }
  .agent .carry { transition: transform .3s cubic-bezier(.2, .7, .2, 1), opacity .3s; }
  .agent.is-carrying .carry { transition: none; }
  .swarm .shadow { transition: opacity .3s; }
  .swarm .commit svg { transition: transform .3s cubic-bezier(.2, .7, .2, 1); }
  .fx .fan.is-in { animation: fan-in .45s ease-in-out; }
  .fx .fan.is-release { animation: fan-in .75s ease-in-out; --s: 1.5; }
  .fx .is-in ~ .tick { animation: tick .7s ease-out; }
  .fx .is-release ~ .spark { animation: spark .75s ease-out; }
  .swarm .ring.is-on { animation: ring .9s ease-out; }

  /* the crab: idle bob on the host, one-shots on the img */
  .crab-perch:not(:empty) { animation: crab-idle 3s ease-in-out infinite; }
  .crab-perch.is-looking img { animation: crab-look .8s ease-in-out 1; }
  .crab-perch.is-celebrating img { animation: crab-celebrate 1.2s cubic-bezier(.2, .7, .2, 1) 1; }
  .crab-perch.is-sassing img { animation: crab-sass .6s ease-in-out 1; }
  .brand-mark svg { transition: transform .3s cubic-bezier(.2, .7, .2, 1), color .15s; }
}

@keyframes scuttle { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
@keyframes hop { 50% { scale: 1.18; translate: 0 -2px; } }
@keyframes twitch { 0%, 70%, 100% { transform: rotate(0); } 78% { transform: rotate(9deg); } 86% { transform: rotate(-4deg); } }
@keyframes twitch-r { 0%, 70%, 100% { transform: rotate(0); } 78% { transform: rotate(-9deg); } 86% { transform: rotate(4deg); } }
@keyframes fan-in { from { opacity: 0; scale: .6; } 30% { opacity: 1; scale: var(--s, 1); } to { opacity: 0; scale: calc(var(--s, 1) * 1.1); } }
@keyframes tick { from { scale: .6; } 30% { opacity: 1; scale: 1; translate: 0 calc(var(--rise) * .35); } to { opacity: 0; translate: 0 var(--rise); } }
@keyframes spark { from { opacity: 1; scale: .5; } 55% { opacity: 1; scale: 1; translate: calc(var(--dx) * .8) calc(var(--dy) * .8); } to { opacity: 0; scale: .4; translate: var(--dx) calc(var(--dy) + 10px); } }
@keyframes ring { from { opacity: .9; scale: .25; } to { scale: 1; } }
@keyframes crab-idle { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-2px) rotate(1deg); } }
@keyframes crab-look { 0%, 100% { transform: translateX(0) rotate(0); } 40% { transform: translateX(-4px) rotate(-4deg); } }
@keyframes crab-celebrate { 0%, 100% { transform: translateY(0) rotate(0) scale(1); } 25% { transform: translateY(-12px) rotate(-12deg) scale(1.15); } 50% { transform: translateY(-18px) rotate(0) scale(1.2); } 75% { transform: translateY(-12px) rotate(12deg) scale(1.15); } }
@keyframes crab-sass { 0%, 100% { transform: rotate(0) scale(1); } 20% { transform: rotate(-8deg) scale(1.05); } 40% { transform: rotate(6deg); } 60% { transform: rotate(-3deg); } }
