/* The avatar stage, shared by the website and the Windows app (whose
   src/renderer/app.css imports this file): the sprite, its effects, the moves
   player.js puts on .stage__body, and the companion's strip. Size a stage by
   setting its width; it stays square. */

.stage {
  position: relative;
  aspect-ratio: 1 / 1;
}

.stage__body {
  position: absolute;
  inset: 0;
  transform-origin: 50% 92%;
}

.stage__sprite {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.stage__fx {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--fade, 200ms ease);
}

.stage__fx.is-on {
  opacity: 1;
}

.stage__fx--shadow {
  opacity: 0.7;
  left: 25%;
  width: 50%;
  bottom: 3%;
}

/* Three Z's that grow as they float up and away from the head, then fade, as
   AvatarEffects.emitZzz: one every 0.4 s, again every 3.2 s while they're on.
   Each .stage__z fills the stage, so its rise is in shares of the stage. */
.stage__fx--zzz {
  inset: 0;
}

.stage__z {
  position: absolute;
  inset: 0;
}

.stage__z img {
  position: absolute;
  left: 67%;
  top: 34%;
  width: 9%;
  translate: -50% -50%;
  opacity: 0;
}

.stage__z:nth-child(2) img {
  width: 11%;
}

.stage__z:nth-child(3) img {
  width: 13%;
}

.stage__fx--zzz.is-on .stage__z {
  animation: z-rise 3.2s infinite both;
}

.stage__fx--zzz.is-on .stage__z img {
  animation: z-fade 3.2s infinite both;
}

.stage__fx--zzz.is-on .stage__z:nth-child(2),
.stage__fx--zzz.is-on .stage__z:nth-child(2) img {
  animation-delay: 0.4s;
}

.stage__fx--zzz.is-on .stage__z:nth-child(3),
.stage__fx--zzz.is-on .stage__z:nth-child(3) img {
  animation-delay: 0.8s;
}

/* Two mirrored bursts beside the head; the middle of the drawing is empty. */
.stage__fx--jolt {
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage__fx--jolt.is-on {
  animation: burst 260ms cubic-bezier(0.3, 1.6, 0.5, 1);
}

.stage__fx--sparkle {
  width: 13%;
  right: 12%;
  top: 46%;
}

.stage__fx--sparkle.is-on {
  animation: twinkle 700ms ease-out;
}

/* The companion (companion.js): it stands at the bottom of its strip, as
   tall as the strip, and walks across it. */
.companion {
  position: relative;
  overflow: hidden;
}

.companion__walker {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 100%;
  aspect-ratio: 1 / 1;
}

/* Held off the ground, it casts no shadow. */
.companion__walker.is-held .stage__fx--shadow {
  opacity: 0;
}

.companion__walker > .stage {
  width: 100%;
  /* companion.js sets --lean while walking: a slight lean toward where it's
     going, eased in and out. */
  rotate: var(--lean, 0deg);
  transform-origin: 50% 94%;
  transition: rotate 200ms ease-in-out;
}

/* Moves, applied to .stage__body by player.js. */
.move-breathe {
  animation: breathe 2s ease-in-out infinite;
}

.move-lean {
  animation: lean 600ms ease-in-out forwards;
}

/* Back upright from .move-lean as the cup comes down. */
.move-unlean {
  animation: unlean 180ms ease-in-out;
}

.move-hop {
  animation: hop 480ms cubic-bezier(0.3, 0, 0.4, 1);
}

.move-hop-left {
  animation: hop-left 480ms cubic-bezier(0.3, 0, 0.4, 1);
}

.move-stretch {
  animation: stretch 1s ease-in-out;
}

/* One rock and bob per step, two steps per cycle, in time with the walk
   clip's frames: it rises onto the planted foot while walkA or walkB lifts the
   other, and comes down with a small squash as walkLand lands on both. */
.move-waddle {
  animation: waddle 480ms ease-in-out infinite;
}

/* The stretch: rises tall and narrow over the first half of the stretch pose
   and holds it, then settles with a small squash as the eyes open. */
.move-reach {
  animation: reach 700ms forwards;
}

.move-settle {
  animation: settle 300ms forwards;
}

/* The cheer: a crouch, a spring up about 9% of the stage with a stretch, a
   hold at the top and a fall, then a squash on landing that eases away. */
.move-crouch {
  animation: crouch 100ms ease-out forwards;
}

.move-cheer {
  animation: cheer 700ms forwards;
}

.move-land {
  animation: land 380ms forwards;
}

/* Carried by the collar (the held clip): a sway from the grab point, toward
   the viewer's left on heldA and the right on heldB. */
.move-dangle {
  transform-origin: 50% 15%;
  animation: dangle 700ms ease-in-out infinite;
}

/* Let go (the drop clip): the landing squash, across both frames. */
.move-drop {
  animation: land 380ms forwards;
}

/* A gentle sway in time with the wave's frames, leaning toward the raised
   hand: three swings, one per waveA and waveB pair, then back upright. */
.move-wave {
  animation: wave 1020ms ease-in-out forwards;
}

.move-unwave {
  animation: unwave 150ms ease-in-out forwards;
}

/* Looking around: leans a touch toward the side it looks at, then back. */
.move-tilt-left {
  animation: tilt-left 200ms ease-in-out forwards;
}

.move-tilt-right {
  animation: tilt-right 200ms ease-in-out forwards;
}

.move-untilt {
  animation: untilt 200ms ease-in-out forwards;
}

/* Zen's float: rises to 8% of the stage, then bobs between 8% and 5.5% for
   as long as the float clip loops. The bob takes over once the rise ends. */
.move-levitate {
  animation:
    levitate 400ms ease-in-out forwards,
    bob 800ms ease-in-out 400ms infinite;
}

/* The end of a float: down from --lift (where the bob had got to, set by
   player.js) over 350 ms, then a small squash that eases away. */
.move-float-down {
  animation: float-down 550ms forwards;
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(1, 1) rotate(0deg);
  }
  50% {
    transform: scale(1.015, 0.985) rotate(-1deg);
  }
}

@keyframes lean {
  to {
    transform: rotate(-3deg) translateY(1%);
  }
}

@keyframes unlean {
  from {
    transform: rotate(-3deg) translateY(1%);
  }
  to {
    transform: none;
  }
}

@keyframes hop {
  0% {
    transform: scale(1.06, 0.92);
  }
  35% {
    transform: translateY(-12%) scale(0.96, 1.05) rotate(3deg);
  }
  70% {
    transform: translateY(0) scale(1.05, 0.95);
  }
  100% {
    transform: none;
  }
}

@keyframes hop-left {
  0% {
    transform: scale(1.06, 0.92);
  }
  35% {
    transform: translateY(-12%) scale(0.96, 1.05) rotate(-3deg);
  }
  70% {
    transform: translateY(0) scale(1.05, 0.95);
  }
  100% {
    transform: none;
  }
}

@keyframes stretch {
  0%,
  100% {
    transform: none;
  }
  45% {
    transform: scale(0.97, 1.05);
  }
}

@keyframes waddle {
  0%,
  50%,
  100% {
    transform: scale(1.03, 0.97);
    animation-timing-function: ease-out;
  }
  25% {
    transform: translateY(-3%) rotate(3deg);
    animation-timing-function: ease-in;
  }
  75% {
    transform: translateY(-3%) rotate(-3deg);
    animation-timing-function: ease-in;
  }
}

@keyframes reach {
  0% {
    transform: none;
    animation-timing-function: ease-out;
  }
  50%,
  100% {
    transform: scale(0.95, 1.09);
  }
}

@keyframes settle {
  0% {
    transform: scale(0.95, 1.09);
    animation-timing-function: ease-in;
  }
  50% {
    transform: scale(1.04, 0.96);
    animation-timing-function: ease-in-out;
  }
  100% {
    transform: none;
  }
}

@keyframes crouch {
  to {
    transform: scale(1.07, 0.92);
  }
}

/* 260 ms up, 220 ms at the top, 220 ms down. */
@keyframes cheer {
  0% {
    transform: scale(1.07, 0.92);
    animation-timing-function: ease-out;
  }
  37%,
  69% {
    transform: translateY(-9%) scale(0.95, 1.07);
    animation-timing-function: ease-in;
  }
  100% {
    transform: none;
  }
}

/* 70 ms into the squash, 160 ms back out of it, then still. */
@keyframes land {
  0% {
    transform: none;
    animation-timing-function: ease-out;
  }
  18% {
    transform: scale(1.08, 0.91);
    animation-timing-function: ease-in-out;
  }
  61%,
  100% {
    transform: none;
  }
}

/* Clockwise swings the hanging legs to the viewer's left. */
@keyframes dangle {
  0%,
  100% {
    transform: rotate(-3deg);
  }
  50% {
    transform: rotate(3deg);
  }
}

/* Each sixth is one 170 ms frame: left on waveA, right on waveB. */
@keyframes wave {
  0% {
    transform: none;
  }
  16.7%,
  50%,
  83.3% {
    transform: rotate(-1.1deg);
  }
  33.3%,
  66.7%,
  100% {
    transform: rotate(1.1deg);
  }
}

@keyframes unwave {
  from {
    transform: rotate(1.1deg);
  }
  to {
    transform: none;
  }
}

@keyframes tilt-left {
  to {
    transform: rotate(-0.9deg);
  }
}

@keyframes tilt-right {
  from {
    transform: rotate(-0.9deg);
  }
  to {
    transform: rotate(0.9deg);
  }
}

@keyframes untilt {
  from {
    transform: rotate(0.9deg);
  }
  to {
    transform: none;
  }
}

@keyframes levitate {
  to {
    transform: translateY(-8%);
  }
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(-8%);
  }
  50% {
    transform: translateY(-5.5%);
  }
}

/* 350 ms down, 60 ms into the squash, 140 ms back out of it. */
@keyframes float-down {
  0% {
    transform: translateY(var(--lift, -8%));
    animation-timing-function: ease-in;
  }
  64% {
    transform: none;
    animation-timing-function: ease-out;
  }
  75% {
    transform: scale(1.04, 0.96);
    animation-timing-function: ease-in-out;
  }
  100% {
    transform: none;
  }
}

/* Each Z's 1.5 s flight takes the first 47% of the 3.2 s cycle. */
@keyframes z-rise {
  0% {
    transform: none;
    animation-timing-function: ease-out;
  }
  47%,
  100% {
    transform: translate(13%, -20%);
  }
}

@keyframes z-fade {
  0% {
    opacity: 0;
    scale: 0.6;
    rotate: 6deg;
  }
  8%,
  30% {
    opacity: 1;
  }
  23% {
    rotate: -7deg;
  }
  47%,
  100% {
    opacity: 0;
    scale: 1.1;
    rotate: 3deg;
  }
}

@keyframes burst {
  from {
    transform: scale(0.75);
  }
  to {
    transform: none;
  }
}

@keyframes twinkle {
  from {
    transform: scale(0.4) rotate(-40deg);
  }
  to {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage,
  .stage * {
    animation: none !important;
    transition: none !important;
  }
}
