/* Max, MaxiaPulse's guide (assets/gather/max.js mounts him).
   .max__stage screens the rendered loops' black ground onto the page
   (mix-blend-mode), so nothing between Max and the page's background may
   isolate: no transform, opacity or z-index on his ancestors unless that
   ancestor paints its own background. He is moved with left/top for the
   same reason. */
.max {
  position: relative; left: 0; top: 0;
  display: block; flex: none;
  width: var(--max-size, 160px); aspect-ratio: 1;
}
.max__glow {
  position: absolute; inset: 10%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, rgb(228 63 251 / .5), rgb(143 60 250 / .3) 60%, transparent 100%);
  filter: blur(calc(var(--max-size, 160px) / 7)); opacity: .5;
  transition: opacity 500ms ease;
}
.max__stage {
  position: absolute; inset: 0; display: block;
  mix-blend-mode: screen;
  transform-origin: 50% 88%;
  transition: transform 520ms cubic-bezier(.34, 1.4, .5, 1);
}
.max__poster, .max__vids {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none;
  /* a soft round edge: no square ever shows where the render's glow reaches the frame */
  -webkit-mask-image: radial-gradient(circle closest-side, #000 80%, transparent 100%);
          mask-image: radial-gradient(circle closest-side, #000 80%, transparent 100%);
}
.max__poster { object-fit: cover; filter: contrast(1.08); }
/* The pose (a roll, a squash) is a transform on the media themselves, never on a parent: a transform on an
   ancestor would isolate the screen blend. --max-rot, --max-sx and --max-sy come from max.pose(). The squash
   keeps his bottom on the floor. 1.14: the render frames the orb smaller than the box. */
.max__poster, .max__vids video {
  transform: translateY(calc((1 - var(--max-sy, 1)) * 50%)) scale(calc(1.14 * var(--max-sx, 1)), calc(1.14 * var(--max-sy, 1))) rotate(var(--max-rot, 0deg));
}
.max__vids video {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: cover;
  opacity: 0; transition: opacity 250ms ease; background: #000;
  filter: contrast(1.08);  /* crush the near-black ground to true black */
}
.max__vids video.is-on { opacity: 1; }
.max.is-still .max__vids { display: none; }

/* poses on top of the loops */
.max[data-state="listening"] .max__stage { transform: translateY(4%) rotate(var(--max-lean, 0deg)) scale(1.03); }
.max[data-state="listening"] .max__glow, .max[data-state="talking"] .max__glow { opacity: .72; }
.max[data-state="thinking"] .max__stage, .max[data-state="working"] .max__stage { transform: translateY(-3%); }
.max[data-state="thinking"] .max__glow, .max[data-state="working"] .max__glow { animation: max-glow-hot 1.15s ease-in-out infinite; }
.max[data-state="happy"] .max__glow, .max[data-state="celebrate"] .max__glow, .max[data-state="greet"] .max__glow { opacity: .9; }
@media (prefers-reduced-motion: no-preference) {
  .max__glow { animation: max-glow 4.2s ease-in-out infinite; }
}
@keyframes max-glow { 0%, 100% { transform: scale(.92); opacity: .42; } 50% { transform: scale(1.08); opacity: .68; } }
@keyframes max-glow-hot { 0%, 100% { transform: scale(1); opacity: .8; } 18% { transform: scale(1.16); opacity: 1; } 34% { transform: scale(1.04); opacity: .9; } 48% { transform: scale(1.12); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .max, .max__stage { transition: none !important; }
  .max[data-state] .max__stage { transform: none; }
  .max[data-state] .max__glow { animation: none; }
}
