/* ============================================================
   POPVERSE — 3D confetti forge
   Aesthetic: deep-space toybox. Off-black plum backdrop, chunky
   display type (Bungee), rounded friendly body (Fredoka), and a
   rail of saturated candy-glass launcher buttons.
   ============================================================ */

:root {
  --bg-0: #0c0a1f;
  --bg-1: #14102e;
  --bg-2: #1d1340;
  --ink: #f4f0ff;
  --ink-dim: #b3a9d6;
  --ink-faint: #6f6796;
  --glass: rgba(28, 22, 58, 0.55);
  --glass-line: rgba(168, 150, 255, 0.18);
  --accent: #ff5e8a;
  --accent-2: #ffd34e;
  --shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.8);
  --r-lg: 26px;
  --r-md: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  /* Live 3D tilt of the control layer, driven from the pointer parallax in
     app.js so every button leans with the moving world. */
  --tx: 0deg;  /* rotateX (vertical lean)   */
  --ty: 0deg;  /* rotateY (horizontal lean) */
  --hx: 0px;   /* specular-highlight shift X */
  --hy: 0px;   /* specular-highlight shift Y */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink);
  font-family: 'Fredoka', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Stage / canvas ---------- */
.stage {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 90% at 50% 8%, #2a1b57 0%, var(--bg-1) 42%, var(--bg-0) 100%),
    radial-gradient(80% 60% at 85% 100%, rgba(255, 94, 138, 0.10), transparent 60%),
    radial-gradient(70% 60% at 12% 92%, rgba(78, 222, 255, 0.09), transparent 60%);
  will-change: transform;
}
.stage.shake { animation: shake 0.45s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake {
  10%, 90% { transform: translate3d(-2px, 1px, 0); }
  20%, 80% { transform: translate3d(4px, -2px, 0); }
  30%, 50%, 70% { transform: translate3d(-7px, 3px, 0); }
  40%, 60% { transform: translate3d(7px, -3px, 0); }
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Fixed, non-scrolling overlays for atmosphere */
.grain {
  position: absolute;
  inset: -50%;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 100% at 50% 42%, transparent 55%, rgba(4, 2, 14, 0.55) 100%);
}

/* ---------- HUD shells ---------- */
.hud {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: calc(16px + var(--safe-t)) 20px 0;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

/* Brand */
.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark {
  width: 38px; height: 38px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  transform: rotate(12deg);
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.45));
}
.brand__mark span { border-radius: 4px; animation: markpulse 3.2s ease-in-out infinite; }
.brand__mark span:nth-child(1){ background: var(--accent); }
.brand__mark span:nth-child(2){ background: var(--accent-2); animation-delay: .25s; }
.brand__mark span:nth-child(3){ background: #4edeff; animation-delay: .5s; }
.brand__mark span:nth-child(4){ background: #8bff6b; animation-delay: .75s; }
@keyframes markpulse { 0%,100%{ transform: scale(1); } 50%{ transform: scale(.82); } }

.brand__text h1 {
  font-family: 'Bungee', sans-serif;
  font-size: clamp(18px, 5vw, 26px);
  letter-spacing: 0.5px;
  line-height: 1;
  background: linear-gradient(92deg, #fff, #ffd9e6 35%, #c9b8ff 70%, #9be7ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand__text p {
  font-size: 11px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 3px;
}

/* Worldwide counter */
.counter { text-align: right; }
.counter__num {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: clamp(16px, 4.4vw, 24px);
  letter-spacing: 1px;
  color: var(--accent-2);
  text-shadow: 0 0 18px rgba(255, 211, 78, 0.4);
  font-variant-numeric: tabular-nums;
}
.counter__label {
  font-size: 10px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 2px;
}

/* ---------- Floating toys ---------- */
.toys {
  position: fixed;
  z-index: 6;
  top: calc(96px + var(--safe-t));
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.toy {
  width: 56px; height: 56px;
  display: grid;
  place-items: center;
  gap: 0;
  border: 1px solid var(--glass-line);
  border-top-color: rgba(255, 255, 255, .3);
  border-radius: 18px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--ink-dim);
  cursor: pointer;
  /* A real tilted tile: top edge leans away, the stacked hard shadows below
     read as the chip's extruded thickness. */
  transform:
    perspective(560px)
    rotateX(calc(8deg + var(--tx)))
    rotateY(var(--ty));
  box-shadow:
    0 2px 0 #1b1340,
    0 4px 0 #160f34,
    0 6px 0 #110b28,
    0 14px 22px -8px rgba(0, 0, 0, .7),
    inset 0 1px 0 rgba(255, 255, 255, .16);
  transition: transform .16s cubic-bezier(.2,.8,.3,1), color .2s ease,
              border-color .2s ease, background .2s ease, box-shadow .16s ease;
}
.toy svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.toy__label {
  position: absolute;
  transform: translateY(20px);
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
}
.toy:active {
  transform:
    perspective(560px)
    rotateX(calc(8deg + var(--tx)))
    rotateY(var(--ty))
    translateZ(-8px) scale(.96);
  box-shadow:
    0 1px 0 #160f34,
    0 2px 0 #110b28,
    0 6px 10px -6px rgba(0, 0, 0, .7),
    inset 0 1px 0 rgba(255, 255, 255, .12);
}
.toy[aria-pressed="true"] {
  color: #fff;
  border-color: rgba(255, 211, 78, .6);
  background: linear-gradient(160deg, rgba(255,94,138,.35), rgba(255,211,78,.22));
}
.toy#toyMute[aria-pressed="true"] .wave { opacity: .25; }

/* ---------- BLAST mega button ---------- */
.blast {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: calc(168px + var(--safe-b));
  transform: translateX(-50%);
  width: 92px; height: 92px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  color: #2a0f1a;
  font-family: 'Bungee', sans-serif;
  font-size: 15px;
  letter-spacing: 0.5px;
  /* A spherical orb: bright crown, deep shaded underside. */
  background: radial-gradient(circle at 34% 26%, #fff6c8, var(--accent-2) 38%, var(--accent) 78%, #c43f6a 100%);
  box-shadow:
    0 18px 34px -8px rgba(255, 94, 138, 0.6),
    0 6px 14px -2px rgba(0, 0, 0, .5),
    inset 0 8px 16px rgba(255, 255, 255, .55),
    inset 0 -10px 20px rgba(150, 40, 70, 0.6),
    inset -6px -4px 12px rgba(120, 30, 60, .4);
  transform: translateX(-50%) perspective(600px) rotateX(calc(var(--tx) * -1)) rotateY(var(--ty));
  transition: transform .14s cubic-bezier(.2,.8,.3,1), box-shadow .14s ease;
}
/* Specular dot — drifts against the parallax so the light feels fixed while
   the orb turns, the classic cue that a circle is actually a sphere. */
.blast::after {
  content: "";
  position: absolute;
  top: 15%;
  left: 25%;
  width: 32%;
  height: 26%;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 40%, rgba(255, 255, 255, .95), rgba(255, 255, 255, 0) 70%);
  transform: translate(var(--hx), var(--hy));
  pointer-events: none;
}
.blast__ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 211, 78, .55);
  animation: ring 2.6s ease-out infinite;
}
@keyframes ring {
  0% { transform: scale(.85); opacity: .9; }
  100% { transform: scale(1.5); opacity: 0; }
}
.blast:active {
  transform: translateX(-50%) perspective(600px) rotateX(calc(var(--tx) * -1)) rotateY(var(--ty)) translateZ(-14px) scale(.92);
}
.blast__label { position: relative; text-shadow: 0 1px 1px rgba(255, 255, 255, .35); }

/* ---------- Launcher dock ---------- */
.dock {
  position: fixed;
  z-index: 6;
  left: 0; right: 0;
  bottom: 0;
  padding: 14px 0 calc(14px + var(--safe-b));
  background: linear-gradient(to top, rgba(8, 6, 22, 0.92), rgba(8, 6, 22, 0.55) 60%, transparent);
}
.dock__hint {
  text-align: center;
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: .3px;
  margin-bottom: 12px;
  padding: 0 24px;
  transition: opacity .4s ease;
}
.dock__hint.gone { opacity: 0; }

.launchers {
  display: flex;
  gap: 12px;
  padding: 4px 20px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  justify-content: center;
}
.launchers::-webkit-scrollbar { display: none; }

.launcher {
  position: relative;
  flex: 0 0 auto;
  scroll-snap-align: center;
  width: 84px;
  padding: 12px 10px 11px;
  border: 1px solid rgba(255,255,255,.12);
  border-top-color: rgba(255,255,255,.3);
  border-radius: var(--r-md);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  overflow: hidden;
  /* A solid 3D chip: tilted back in perspective, with a stack of hard shadows
     standing in for the extruded front wall. */
  transform-origin: center 65%;
  transform:
    perspective(680px)
    rotateX(calc(12deg + var(--tx)))
    rotateY(var(--ty));
  box-shadow:
    0 2px 0 #1b1340,
    0 4px 0 #170f36,
    0 6px 0 #130c2c,
    0 8px 0 #0f0922,
    0 18px 26px -8px rgba(0,0,0,.72),
    inset 0 1px 0 rgba(255,255,255,.16);
  transition: transform .16s cubic-bezier(.2,.8,.3,1), box-shadow .16s ease, border-color .2s ease;
}
.launcher::before {
  /* charge fill rises from the bottom */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: var(--charge, 0%);
  background: linear-gradient(to top, rgba(255,255,255,.34), rgba(255,255,255,.06));
  transition: height .05s linear;
  pointer-events: none;
}
.launcher:active {
  transform:
    perspective(680px)
    rotateX(calc(12deg + var(--tx)))
    rotateY(var(--ty))
    translateZ(-10px) scale(.98);
  box-shadow:
    0 1px 0 #170f36,
    0 2px 0 #130c2c,
    0 6px 12px -6px rgba(0,0,0,.7),
    inset 0 1px 0 rgba(255,255,255,.12);
}
.launcher.pop { animation: launchpop .34s ease; }
@keyframes launchpop {
  0%   { transform: perspective(680px) rotateX(calc(12deg + var(--tx))) rotateY(var(--ty)) translateZ(-10px) scale(.97); }
  45%  { transform: perspective(680px) rotateX(calc(12deg + var(--tx))) rotateY(var(--ty)) translateZ(26px) scale(1.08); }
  100% { transform: perspective(680px) rotateX(calc(12deg + var(--tx))) rotateY(var(--ty)) translateZ(0) scale(1); }
}
.launcher__swatch {
  height: 40px;
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow:
    inset 0 2px 6px rgba(255,255,255,.45),
    inset 0 -5px 12px rgba(0,0,0,.32),
    0 4px 10px -2px rgba(0,0,0,.55);
  position: relative;
  overflow: hidden;
}
.launcher__swatch::before {
  /* curved gloss so the swatch reads as a raised, glassy chip */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(150deg, rgba(255,255,255,.55), rgba(255,255,255,0) 46%);
  z-index: 1;
}
.launcher__swatch::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.9) 18%, transparent 19%);
  background-size: 10px 10px;
  background-position: 0 0;
  opacity: .22;
}
.launcher__name {
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  letter-spacing: .2px;
  white-space: nowrap;
}
.launcher.charging { border-color: rgba(255,211,78,.7); }

/* ---------- Combo flash ---------- */
.combo {
  position: fixed;
  z-index: 5;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(.4);
  font-family: 'Bungee', sans-serif;
  display: flex;
  align-items: baseline;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  color: #fff;
  text-shadow: 0 0 24px rgba(255, 94, 138, .9), 0 6px 0 rgba(170, 30, 70, .5);
}
.combo.show { animation: comboPop .7s cubic-bezier(.2,1.3,.4,1) forwards; }
@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3) rotate(-8deg); }
  35% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(3deg); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -56%) scale(1.05); }
}
.combo__x { font-size: 34px; color: var(--accent-2); }
.combo__n { font-size: 64px; }
.combo__label {
  font-size: 16px;
  letter-spacing: 3px;
  margin-left: 8px;
  align-self: center;
  color: var(--accent);
}

/* ---------- Boot veil ---------- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 100% at 50% 30%, #1c1342, #0a0818 90%);
  text-align: center;
  padding: 24px;
  transition: opacity .6s ease, visibility .6s;
}
.boot.hidden { opacity: 0; visibility: hidden; }
.boot__inner { max-width: 360px; position: relative; }
.boot__confetti {
  height: 60px;
  margin: 0 auto 18px;
  width: 60px;
  border-radius: 16px;
  background:
    conic-gradient(from 0deg, #ff5e8a, #ffd34e, #8bff6b, #4edeff, #b07bff, #ff5e8a);
  animation: spin 7s linear infinite;
  box-shadow: 0 0 50px rgba(255,94,138,.5);
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot h2 {
  font-family: 'Bungee', sans-serif;
  font-size: clamp(34px, 11vw, 58px);
  background: linear-gradient(92deg, #fff, #ffd9e6 35%, #c9b8ff 70%, #9be7ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 12px;
}
.boot p { color: var(--ink-dim); line-height: 1.55; margin-bottom: 26px; font-size: 15px; }
.boot__btn {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 17px;
  color: #2a0f1a;
  padding: 15px 34px;
  border: none;
  border-radius: 100px;
  cursor: pointer;
  background: radial-gradient(circle at 35% 28%, #fff2a8, var(--accent-2) 45%, var(--accent) 100%);
  box-shadow:
    0 4px 0 #c43f6a,
    0 8px 0 #9c2f53,
    0 18px 30px -8px rgba(255,94,138,.6),
    inset 0 3px 8px rgba(255,255,255,.6);
  transition: transform .15s ease, box-shadow .15s ease;
}
.boot__btn:active {
  transform: translateY(6px) scale(.98);
  box-shadow:
    0 2px 0 #9c2f53,
    0 6px 14px -6px rgba(255,94,138,.6),
    inset 0 3px 8px rgba(255,255,255,.5);
}

/* ---------- Responsive ---------- */
@media (min-width: 760px) {
  .toy:hover {
    color: #fff;
    transform: perspective(560px) rotateX(calc(5deg + var(--tx))) rotateY(var(--ty)) translateZ(12px);
  }
  .toy:hover .toy__label { opacity: .7; }
  .launcher:hover {
    transform: perspective(680px) rotateX(calc(8deg + var(--tx))) rotateY(var(--ty)) translateZ(16px);
    border-color: rgba(255,255,255,.3);
  }
  .blast:hover {
    transform: translateX(-50%) perspective(600px) rotateX(calc(var(--tx) * -1)) rotateY(var(--ty)) translateZ(16px) scale(1.05);
  }
  .boot__btn:hover { transform: translateZ(8px) scale(1.04); }
  .launchers { gap: 14px; }
  .launcher { width: 92px; }
}

@media (max-width: 420px) {
  .launchers { justify-content: flex-start; }
  .blast { width: 76px; height: 76px; font-size: 13px; bottom: calc(176px + var(--safe-b)); }
  .toys { top: calc(86px + var(--safe-t)); right: 14px; }
  .toy { width: 48px; height: 48px; border-radius: 15px; }
  .toy svg { width: 21px; height: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .blast__ring, .brand__mark span, .boot__confetti { animation: none; }
}
