/* Stage — styles for stage.js. Every class is prefixed stage-. No images, no fonts. */

/* ── the scene with a stage on it ──
   `stage-on` is the one class stage.js leaves on the scene. It makes the scene a stacking
   context, so the backdrop at z-index -1 sits under everything else in it — the sprites (no
   z-index), the weather overlay (0), the move layer (1) — whatever the DOM order. */
.scene.stage-on { isolation: isolate; background: none; }

.stage-root {
  position: absolute; inset: 0; z-index: -1; overflow: hidden; pointer-events: none;
  container-type: size;                              /* particles are sized in cqw / cqh */
  background: #1b2233;
}
.stage-bg, .stage-layer, .stage-motes, .stage-shadows { position: absolute; inset: 0; }
.stage-layer svg, .stage-plat svg { display: block; width: 100%; height: 100%; }

/* ── slow loops: at most a few per backdrop, all compositor-only (transform / opacity) ── */
/* A layer drawn twice side by side that slides one copy's width, for ever. */
.stage-drift { right: auto; width: 200%; will-change: transform; animation: stage-drift var(--dur, 120s) linear infinite; }
.stage-drift.stage-rev { animation-direction: reverse; }
@keyframes stage-drift { to { transform: translateX(-50%); } }
/* Torches, screens, lava: a few hard brightness steps. */
.stage-flick { animation: stage-flick var(--dur, 1.6s) steps(1, end) var(--dl, 0s) infinite; }
@keyframes stage-flick { 0%, 100% { opacity: 1; } 22% { opacity: .7; } 40% { opacity: .92; } 63% { opacity: .58; } 81% { opacity: .85; } }
/* Light shafts, glows: a slow breath. */
.stage-pulse { animation: stage-pulse var(--dur, 7s) ease-in-out infinite alternate; }
@keyframes stage-pulse { from { opacity: .45; } to { opacity: 1; } }

/* ── particles (dust, bubbles, embers, stars) ──
   Per particle, set by stage.js: --a / --b 0–1 where it starts, --k 0–1 variety, --dl phase.
   Per group: --c colour, --o opacity, --sz size in cqh, --sec loop length, --rise how far it
   climbs in cqh (negative: falls), --sway sideways wander in cqw. */
.stage-motes i {
  position: absolute; display: block; left: calc(var(--a) * 100%); top: calc(var(--b) * 100%);
  width: calc(max(2px, var(--sz, 1) * 1cqh) * (.6 + var(--k) * .8)); aspect-ratio: 1;
  background: var(--c, #fff); opacity: var(--o, .8);
}
.stage-m-rise i { animation: stage-rise calc(var(--sec, 9s) * (.7 + var(--k) * .6)) linear var(--dl) infinite; }
@keyframes stage-rise {
  0% { translate: 0 0; opacity: 0; }
  12% { opacity: var(--o, .8); }
  50% { translate: calc(var(--sway, 2) * 1cqw) calc(var(--rise, 100) * -.5cqh); }
  85% { opacity: var(--o, .8); }
  100% { translate: 0 calc(var(--rise, 100) * -1cqh); opacity: 0; }
}
.stage-m-float i { animation: stage-float calc(var(--sec, 12s) * (.7 + var(--k) * .6)) ease-in-out var(--dl) infinite alternate; }
@keyframes stage-float { to { translate: calc(var(--sway, 4) * 1cqw) calc(var(--rise, 6) * -1cqh); } }
.stage-m-twinkle i { animation: stage-twinkle calc(var(--sec, 3s) * (.6 + var(--k) * .8)) steps(1, end) var(--dl) infinite; }
@keyframes stage-twinkle { 0%, 100% { opacity: var(--o, .8); } 55% { opacity: .08; } 70% { opacity: calc(var(--o, .8) * .5); } }
/* shapes */
.stage-s-ring i { background: none; border: max(1px, .3cqh) solid var(--c, #fff); border-radius: 50%; }
.stage-s-plus i { clip-path: polygon(36% 0, 64% 0, 64% 36%, 100% 36%, 100% 64%, 64% 64%, 64% 100%, 36% 100%, 36% 64%, 0 64%, 0 36%, 36% 36%); }
.stage-s-bolt i { clip-path: polygon(55% 0, 100% 0, 60% 42%, 90% 42%, 20% 100%, 42% 56%, 10% 56%); }
.stage-s-puff i { border-radius: 38%; }
.stage-s-wisp i { border-radius: 50% 50% 38% 38%; }

/* ── platforms and shadows (placed by Stage.sync, in % of the scene) ── */
.stage-plat { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.stage-shadow {
  position: absolute; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(8, 10, 22, .42) 0 62%, rgba(8, 10, 22, .22) 62% 82%, transparent 84%);
  animation: stage-shadow-in .2s ease-out 1;
}
@keyframes stage-shadow-in { from { opacity: 0; transform: scale(.4); } }

/* ── trainers: a full-scene sheet that slides, with the trainers standing by their platform ── */
.stage-trainers {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  transform: translateX(var(--from)); transition: transform var(--dur, .7s) cubic-bezier(.2, .75, .3, 1);
  will-change: transform;
}
.stage-trainers.stage-foe { --from: 100%; }
.stage-trainers.stage-you { --from: -100%; }
.stage-trainers.stage-in { transform: none; }
.stage-trainers.stage-out { transform: translateX(var(--from)); transition-timing-function: cubic-bezier(.6, 0, .9, .45); }
.stage-row {
  position: absolute; left: var(--x, 50%); top: var(--y, 50%); height: var(--u, 96px);
  transform: translate(-50%, -100%); display: flex; align-items: flex-end;
}
.stage-trainer { position: relative; isolation: isolate; height: 100%; flex: none; }
.stage-trainer + .stage-trainer { margin-left: calc(var(--u, 96px) * -.36); }   /* the portraits have wide empty sides */
.stage-trainer > * { display: block; height: 100%; }
.stage-trainer img { display: block; height: 100%; width: auto; max-width: none; image-rendering: pixelated; }
.stage-trainer::before {                             /* their shadow on the platform */
  content: ""; position: absolute; z-index: -1; left: 18%; right: 18%; bottom: 8%; height: 10%;
  border-radius: 50%; background: rgba(8, 10, 22, .32);
}
/* A portrait that failed to load leaves an empty node: it takes no space and casts no shadow. */
.stage-trainer:has(> :empty:not(img)), .stage-trainer:empty { display: none; }

/* ── callout: the name plate of an important opponent ── */
.stage-callout { position: absolute; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; container-type: size; }
.stage-plate {
  position: absolute; left: 0; top: 54%; box-sizing: border-box; min-width: 54%; max-width: 94%;
  padding: 2.4cqh calc(5cqw + 7cqh) 2.6cqh 6cqw; display: grid; gap: .8cqh; color: #fff;
  background:
    linear-gradient(90deg, var(--c) 0 2.4cqw, var(--d) 2.4cqw 3.2cqw, transparent 3.2cqw),
    repeating-linear-gradient(115deg, transparent 0 1.6cqh, rgba(255, 255, 255, .05) 1.6cqh 3.2cqh),
    linear-gradient(#182036 0 50%, #111828 50%);
  border-top: max(2px, .7cqh) solid var(--l); border-bottom: max(2px, .7cqh) solid var(--c);
  clip-path: polygon(0 0, 100% 0, calc(100% - 7cqh) 100%, 0 100%);
  transform: translateX(-102%); transition: transform var(--in, .32s) cubic-bezier(.2, .8, .3, 1);
  will-change: transform;
}
.stage-plate::after {                                /* hard stripes in the type's colour at the slanted end */
  content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 13cqh;
  background: repeating-linear-gradient(115deg, var(--c) 0 1.3cqh, transparent 1.3cqh 2.6cqh);
  clip-path: polygon(46% 0, 100% 0, 100% 100%, 0 100%);
}
.stage-callout.stage-in .stage-plate { transform: none; }
.stage-callout.stage-out .stage-plate { transform: translateX(104cqw); transition: transform var(--out, .28s) cubic-bezier(.6, 0, .9, .45); }
.stage-kicker {
  justify-self: start; font: 700 clamp(8px, 2.7cqh, 13px) / 1 var(--pixel, ui-monospace, monospace);
  letter-spacing: .12em; text-transform: uppercase; color: #10131c; background: var(--l); padding: .5em .7em .45em;
}
.stage-kicker:empty, .stage-sub:empty { display: none; }
.stage-title {
  font: 700 clamp(15px, min(8cqh, 6.4cqw), 38px) / 1.05 var(--pixel, ui-monospace, monospace);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 max(2px, .7cqh) 0 rgba(0, 0, 0, .55);
}
.stage-sub {
  font: 600 clamp(10px, min(3.3cqh, 3.4cqw), 15px) / 1.2 var(--sans, system-ui, sans-serif); color: #d6def0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── reduced motion: still pictures; trainers and the plate appear and vanish in place ── */
@media (prefers-reduced-motion: reduce) {
  .stage-drift, .stage-flick, .stage-pulse, .stage-motes i, .stage-shadow { animation: none !important; }
  .stage-m-rise, .stage-m-float { display: none; }   /* particles that only make sense moving */
  .stage-trainers, .stage-plate { transition: none !important; transform: none !important; visibility: hidden; }
  .stage-trainers.stage-in, .stage-callout.stage-in .stage-plate { visibility: visible; }
  .stage-trainers.stage-out, .stage-callout.stage-out .stage-plate { visibility: hidden; }
}
