/* Cartoon adventurers (js/figures.js): idle, cheer and walk motion.
   Transforms run on wrapper groups that carry no transform attribute of their
   own (.fig-rig, .fig-eyes, .fig-shadow), so CSS never fights the drawing.
   .fig-rig scales and moves around the feet (100, 250 in the figure's user
   units). .fig-d0..4 spread the blinks so a row of figures doesn't wink in
   step. All motion is off under prefers-reduced-motion (bottom). */

.fig {
  display: block;
}

/* A whole figure may lift a staff a little past its box; a bust is a framed
   portrait and stays inside it. */
.fig-full {
  overflow: visible;
}

.fig-bust {
  overflow: hidden;
}

.fig .fig-rig {
  transform-origin: 100px 250px;
}

.fig .fig-eyes {
  transform-box: fill-box;
  transform-origin: center;
  animation: fig-blink 5.6s infinite;
}

.fig.fig-d1 .fig-eyes { animation-delay: -1.1s; }
.fig.fig-d2 .fig-eyes { animation-delay: -2.3s; }
.fig.fig-d3 .fig-eyes { animation-delay: -3.4s; }
.fig.fig-d4 .fig-eyes { animation-delay: -4.6s; }

/* Standing: a slow breath. */
.fig-pose-idle .fig-rig {
  animation: fig-breathe 3.4s ease-in-out infinite;
}

.fig.fig-d1 .fig-rig { animation-delay: -0.7s; }
.fig.fig-d2 .fig-rig { animation-delay: -1.4s; }
.fig.fig-d3 .fig-rig { animation-delay: -2.1s; }
.fig.fig-d4 .fig-rig { animation-delay: -2.8s; }

/* Cheering: a happy hop, the shadow shrinking under it. */
.fig-pose-cheer .fig-rig {
  animation: fig-hop 0.95s cubic-bezier(0.33, 0, 0.4, 1) infinite;
}

.fig-pose-cheer .fig-shadow {
  transform-box: fill-box;
  transform-origin: center;
  animation: fig-shadow 0.95s cubic-bezier(0.33, 0, 0.4, 1) infinite;
}

/* Walking: a bouncy step. */
.fig-pose-walk .fig-rig {
  animation: fig-walk 0.62s ease-in-out infinite;
}

/* The happy closed eyes of a cheer don't blink. */
.fig-pose-cheer .fig-eyes {
  animation: none;
}

@keyframes fig-breathe {
  0%,
  100% { transform: scale(1, 1); }
  50% { transform: scale(1.012, 0.982); }
}

@keyframes fig-blink {
  0%,
  92%,
  100% { transform: scaleY(1); }
  95% { transform: scaleY(0.12); }
}

@keyframes fig-hop {
  0%,
  100% { transform: translateY(0) scale(1.04, 0.95); }
  18% { transform: translateY(0) scale(0.97, 1.04); }
  50% { transform: translateY(-16px) scale(1, 1); }
  82% { transform: translateY(0) scale(1.02, 0.98); }
}

@keyframes fig-shadow {
  0%,
  18%,
  82%,
  100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.72); opacity: 0.6; }
}

@keyframes fig-walk {
  0%,
  100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-4px) rotate(-1.5deg); }
  50% { transform: translateY(0) rotate(0deg); }
  75% { transform: translateY(-4px) rotate(1.5deg); }
}

/* A panel out of view (js/app.js pauseOffscreen) holds its figures and
   shimmers still: they only cost while someone can see them. */
[data-off] .fig .fig-rig,
[data-off] .fig .fig-eyes,
[data-off] .fig .fig-shadow,
[data-off] .xpbar-spark::after {
  animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
  .fig .fig-rig,
  .fig .fig-eyes,
  .fig .fig-shadow,
  .fig.fig-pose-idle .fig-rig,
  .fig.fig-pose-cheer .fig-rig,
  .fig.fig-pose-cheer .fig-shadow,
  .fig.fig-pose-walk .fig-rig {
    animation: none;
  }
}
