/*
 * Synthwave kit — a striped retro sun, a perspective grid floor and CRT
 * scanlines. Colors come from the Catppuccin accent channels, so the scene
 * reads in both Latte (light) and Mocha (dark).
 *
 *   <div class="synth-stage">
 *     <div class="synth-sun"></div>
 *     <div class="synth-floor"></div>
 *   </div>
 */

.synth-stage {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

/* Sun: rises just above the horizon, slats cut from its lower half */
.synth-sun {
  position: absolute;
  left: 50%;
  bottom: 38%;
  width: min(64%, 17rem);
  aspect-ratio: 1;
  transform: translate(-50%, 18%);
  border-radius: 9999px;
  background: linear-gradient(
    to bottom,
    rgb(var(--ctp-yellow-rgb)) 0%,
    rgb(var(--ctp-peach-rgb)) 40%,
    rgb(var(--ctp-pink-rgb)) 72%,
    rgb(var(--ctp-mauve-rgb)) 100%
  );
  box-shadow: 0 0 80px rgb(var(--ctp-pink-rgb) / 0.35);
  -webkit-mask-image: linear-gradient(to bottom,
    #000 50%, transparent 50% 53%, #000 53% 59%, transparent 59% 63%,
    #000 63% 68%, transparent 68% 73%, #000 73% 77%, transparent 77% 83%, #000 83%);
  mask-image: linear-gradient(to bottom,
    #000 50%, transparent 50% 53%, #000 53% 59%, transparent 59% 63%,
    #000 63% 68%, transparent 68% 73%, #000 73% 77%, transparent 77% 83%, #000 83%);
  z-index: -1;
}

/* Floor: a grid tilted back to the horizon, scrolling slowly toward you */
.synth-floor {
  position: absolute;
  left: -50%;
  right: -50%;
  bottom: 0;
  height: 38%;
  background-color: rgb(var(--mocha-crust-rgb));
  background-image:
    linear-gradient(to right, rgb(var(--ctp-pink-rgb) / 0.55) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(var(--ctp-pink-rgb) / 0.55) 1px, transparent 1px);
  background-size: 44px 44px;
  transform: perspective(260px) rotateX(58deg);
  transform-origin: center top;
  border-top: 2px solid rgb(var(--ctp-pink-rgb) / 0.8);
  box-shadow: 0 -6px 24px rgb(var(--ctp-pink-rgb) / 0.35);
  animation: synth-floor-scroll 4s linear infinite;
  z-index: -1;
}

@keyframes synth-floor-scroll {
  to { background-position: 0 44px; }
}

/* Night sky: a sparse field of pixel stars (two layers, gently twinkling) */
.synth-stars {
  position: absolute;
  inset: 0 0 38% 0;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, rgb(var(--mocha-text-rgb) / 0.9), transparent 60%),
    radial-gradient(1px 1px at 28% 62%, rgb(var(--mocha-text-rgb) / 0.7), transparent 60%),
    radial-gradient(1.5px 1.5px at 47% 30%, rgb(var(--ctp-pink-rgb)), transparent 60%),
    radial-gradient(1px 1px at 63% 12%, rgb(var(--mocha-text-rgb) / 0.8), transparent 60%),
    radial-gradient(1.5px 1.5px at 78% 48%, rgb(var(--ctp-sky-rgb)), transparent 60%),
    radial-gradient(1px 1px at 88% 22%, rgb(var(--mocha-text-rgb) / 0.7), transparent 60%),
    radial-gradient(1px 1px at 8% 74%, rgb(var(--mocha-text-rgb) / 0.6), transparent 60%),
    radial-gradient(1.5px 1.5px at 94% 70%, rgb(var(--mocha-text-rgb) / 0.8), transparent 60%);
  animation: synth-twinkle 5s ease-in-out infinite alternate;
  z-index: -1;
}

@keyframes synth-twinkle {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

/* Neon outline for arcade elements (level emblem, badges) */
.synth-neon {
  box-shadow:
    0 0 0 2px rgb(var(--ctp-pink-rgb)),
    0 0 18px rgb(var(--ctp-pink-rgb) / 0.55),
    inset 0 0 18px rgb(var(--ctp-pink-rgb) / 0.25);
}

.synth-neon-text {
  text-shadow: 0 0 12px rgb(var(--ctp-pink-rgb) / 0.7);
}

/* Blinking block cursor for "PLAYER 1 READY" style labels */
.synth-blink {
  animation: synth-blink 1.1s steps(1, end) infinite;
}

@keyframes synth-blink {
  50% { opacity: 0; }
}

/* CRT scanlines, for laying over art */
.scanlines {
  background-image: repeating-linear-gradient(to bottom, rgb(0 0 0 / 0.14) 0 1px, transparent 1px 3px);
}

@media (prefers-reduced-motion: reduce) {
  .synth-floor,
  .synth-stars,
  .synth-blink { animation: none; }
}

/*
 * Retro CRT terminal — a bezel, a glowing phosphor screen and lines that type
 * themselves out. Stagger lines with an inline `animation-delay`.
 *
 *   <div class="crt">
 *     <div class="crt-screen"> <p class="crt-line" style="animation-delay: .4s">…</p> </div>
 *   </div>
 */
.crt {
  border-radius: 1.25rem;
  padding: 0.9rem 0.9rem 1.6rem;
  background: rgb(var(--mocha-surface0-rgb));
  box-shadow:
    inset 0 2px 0 rgb(var(--mocha-text-rgb) / 0.08),
    inset 0 -3px 0 rgb(0 0 0 / 0.25),
    0 24px 48px -12px rgb(0 0 0 / 0.5);
  position: relative;
}

/* Power LED on the bezel */
.crt::after {
  content: "";
  position: absolute;
  right: 1.1rem;
  bottom: 0.6rem;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 9999px;
  background: rgb(var(--ctp-green-rgb));
  box-shadow: 0 0 8px rgb(var(--ctp-green-rgb));
}

.crt-screen {
  position: relative;
  overflow: hidden;
  border-radius: 0.75rem;
  background: #11111b;
  color: #a6e3a1;
  box-shadow:
    inset 0 0 40px rgb(0 0 0 / 0.8),
    0 0 24px rgb(166 227 161 / 0.12);
}

/* Scanlines + a soft vignette baked into the glass */
.crt-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgb(0 0 0 / 0.22) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgb(0 0 0 / 0.45));
}

.crt-glow {
  text-shadow: 0 0 6px currentColor;
}

/* Each line "types" in from the left */
.crt-line {
  white-space: nowrap;
  overflow: hidden;
  clip-path: inset(0 100% 0 0);
  animation: crt-type 0.9s steps(28, end) forwards;
}

@keyframes crt-type {
  to { clip-path: inset(0 0 0 0); }
}

@media (prefers-reduced-motion: reduce) {
  .crt-line { clip-path: none; animation: none; }
}

/*
 * Retro gym — a flickering neon sign, a barbell doing reps and an LED rep
 * counter that counts along (CSS-only, via an animated @property integer).
 */
.gym-neon {
  color: rgb(var(--ctp-pink-rgb));
  text-shadow:
    0 0 4px rgb(var(--ctp-pink-rgb) / 0.9),
    0 0 14px rgb(var(--ctp-pink-rgb) / 0.6),
    0 0 32px rgb(var(--ctp-pink-rgb) / 0.35);
  animation: gym-flicker 7s linear infinite;
}

@keyframes gym-flicker {
  0%, 18%, 22%, 62%, 64%, 100% { opacity: 1; }
  20%, 63% { opacity: 0.35; }
}

/* One rep: lift, hold, lower — 2.4s */
.gym-barbell {
  animation: gym-rep 2.4s ease-in-out infinite;
}

@keyframes gym-rep {
  0%, 100% { transform: translateY(0); }
  45%, 55% { transform: translateY(-38px); }
}

.gym-shadow {
  animation: gym-shadow 2.4s ease-in-out infinite;
}

@keyframes gym-shadow {
  0%, 100% { transform: scaleX(1); opacity: 0.55; }
  45%, 55% { transform: scaleX(0.7); opacity: 0.25; }
}

.gym-bar {
  background: linear-gradient(to bottom, #f5f5f5, #9ca0b0 55%, #585b70);
}

/* Weight plates are keycaps */
.gym-plate {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 800;
  color: #11111b;
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / 0.25), inset 0 2px 0 rgb(255 255 255 / 0.35);
}

/* LED rep counter: counts 01 → 12, one number per 2.4s rep, then starts a new set. */
@property --gym-reps {
  syntax: "<integer>";
  initial-value: 0;
  inherits: false;
}

.gym-counter::after {
  counter-reset: reps var(--gym-reps);
  content: counter(reps, decimal-leading-zero);
  animation: gym-count 28.8s steps(12, jump-none) infinite;
}

@keyframes gym-count {
  from { --gym-reps: 1; }
  to { --gym-reps: 12; }
}

.gym-led {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: rgb(var(--ctp-green-rgb));
  text-shadow: 0 0 8px rgb(var(--ctp-green-rgb) / 0.8);
}

@media (prefers-reduced-motion: reduce) {
  .gym-neon,
  .gym-barbell,
  .gym-shadow,
  .gym-counter::after { animation: none; }
  .gym-counter::after { --gym-reps: 12; }
}
