/* ── Reset & Base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0 }

:root {
  --bg: #0c0c0e;
  --surface: #1a1a1f;
  --border: rgba(255,255,255,0.08);
  --text: #f0eff0;
  --text-muted: #888;
  --accent: #e8c547;
  --accent-dim: rgba(232,197,71,0.15);
  --radius: 16px;
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ── Scene base ──────────────────────────────────────────────────────────────── */
.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.scene--active { opacity: 1; transform: scale(1) }
.scene--exit   { opacity: 0; transform: scale(1.03); pointer-events: none }

/* ── Cover ───────────────────────────────────────────────────────────────────── */
.scene-cover {
  background: var(--bg);
  cursor: pointer;
}
.cover-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
  text-align: center;
}
.cover-icon { font-size: 64px; line-height: 1; margin-bottom: 8px }
.cover-title {
  font-size: clamp(28px, 7vw, 52px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.cover-subtitle {
  font-size: clamp(15px, 3.5vw, 20px);
  color: var(--text-muted);
  max-width: 360px;
}
.cover-hint {
  margin-top: 24px;
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.cover--tapped { animation: coverTap 0.6s forwards }
@keyframes coverTap {
  0%   { transform: scale(1); opacity: 1 }
  40%  { transform: scale(1.04) }
  100% { transform: scale(0.92); opacity: 0 }
}

/* ── Reveal ──────────────────────────────────────────────────────────────────── */
.scene-reveal {
  background: var(--bg);
  padding: 40px 32px;
  gap: 0;
}
.reveal-line {
  font-size: clamp(20px, 5vw, 36px);
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.55s ease, transform 0.55s ease;
  margin-bottom: 16px;
}
.reveal-line--visible { opacity: 1; transform: translateY(0) }

/* ── Scratch ─────────────────────────────────────────────────────────────────── */
.scene-scratch {
  background: #111108;
  padding: 24px;
  gap: 20px;
}
.scratch-wrap {
  position: relative;
  width: min(340px, 90vw);
  height: min(340px, 90vw);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 0 0 3px var(--accent), 0 16px 48px rgba(0,0,0,0.6);
}
.scratch-hidden {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
  background: #1a1a0e;
  gap: 12px;
}
.scratch-canvas {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  touch-action: none;
}
.scratch-hint {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: opacity 0.4s;
}

/* ── Glitch ──────────────────────────────────────────────────────────────────── */
.scene-glitch { background: #0a0003 }
.glitch-state {
  width: 100%;
  max-width: 520px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}
.glitch-state.hidden { display: none }

/* Error state — looks like an OS alert */
.glitch-error-box {
  background: #1c0005;
  border: 1.5px solid #ff2040;
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 400px;
  width: 100%;
}
.glitch-error-icon { font-size: 40px; margin-bottom: 12px }
.glitch-error-title {
  font-size: 18px;
  font-weight: 800;
  color: #ff2040;
  margin-bottom: 8px;
  font-family: 'Courier New', monospace;
}
.glitch-error-msg {
  font-size: 14px;
  color: #ff8090;
  font-family: 'Courier New', monospace;
  line-height: 1.5;
}
.glitch-error-code {
  font-size: 11px;
  color: #ff4060;
  margin-top: 16px;
  opacity: 0.7;
  font-family: 'Courier New', monospace;
}
.glitch-tap-hint {
  margin-top: 16px;
  font-size: 13px;
  color: rgba(255,32,64,0.6);
  font-family: 'Courier New', monospace;
}

.glitching { animation: glitch 0.12s infinite }
@keyframes glitch {
  0%   { transform: translate(0); filter: none }
  20%  { transform: translate(-3px, 1px); filter: hue-rotate(90deg) }
  40%  { transform: translate(3px, -1px); filter: hue-rotate(-90deg) brightness(1.2) }
  60%  { transform: translate(-2px, 2px) skewX(2deg) }
  80%  { transform: translate(2px, -2px) }
  100% { transform: translate(0) }
}
.rebooting { animation: reboot 0.7s forwards }
@keyframes reboot {
  0%   { opacity: 1 }
  30%  { opacity: 0; transform: scaleY(0.02) }
  100% { opacity: 0; transform: scaleY(0) }
}

/* Resolve state — birthday reveal */
.glitch-resolve { animation: none }
.resolving { animation: resolveIn 0.8s ease forwards }
@keyframes resolveIn {
  from { opacity: 0; transform: scale(0.9) }
  to   { opacity: 1; transform: scale(1) }
}

/* ── Stats ───────────────────────────────────────────────────────────────────── */
.scene-stats {
  background: var(--bg);
  padding: 0;
  gap: 0;
}
.stats-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 32px;
  text-align: center;
  gap: 12px;
  opacity: 0;
  transform: translateX(60px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.stats-card--in { opacity: 1; transform: translateX(0) }
.stat-eyebrow {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.7;
}
.stat-value {
  font-size: clamp(36px, 10vw, 72px);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  max-width: 480px;
  text-align: center;
}
.stat-sub {
  font-size: clamp(14px, 3vw, 19px);
  font-weight: 600;
  opacity: 0.75;
  max-width: 320px;
  text-align: center;
  line-height: 1.4;
}
.stats-dots {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 10;
}
.stats-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  transition: background 0.3s, transform 0.3s;
}
.stats-dot--active { background: #fff; transform: scale(1.3) }

/* ── Finale ──────────────────────────────────────────────────────────────────── */
.scene-finale { background: var(--bg) }
.finale-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.finale-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 40px 32px;
  text-align: center;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.finale-inner--visible { opacity: 1; transform: translateY(0) }
.finale-msg {
  font-size: clamp(26px, 7vw, 52px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  max-width: 480px;
}
.finale-cta {
  display: inline-block;
  margin-top: 8px;
  padding: 14px 28px;
  background: var(--accent);
  color: #000;
  font-size: 15px;
  font-weight: 700;
  border-radius: 100px;
  text-decoration: none;
  letter-spacing: 0.01em;
  transition: transform 0.2s, opacity 0.2s;
}
.finale-cta:hover { transform: scale(1.04); opacity: 0.9 }

/* ── Balloon ─────────────────────────────────────────────────────────────────── */
.scene-balloon {
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
.balloon-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.balloon-area {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  cursor: pointer;
  padding: 32px;
  width: 100%;
}
.balloon-hint {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: opacity 0.5s;
}
.balloon-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  user-select: none;
}
.balloon-body {
  width: 120px;
  height: 148px;
  background: var(--bcolor, #ff6b9d);
  border-radius: 50% 50% 46% 46% / 50% 50% 52% 52%;
  position: relative;
  transform-origin: center bottom;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow:
    inset -22px -18px 0 rgba(0,0,0,0.14),
    inset 10px 10px 0 rgba(255,255,255,0.2),
    0 8px 32px rgba(0,0,0,0.35);
}
.balloon-shine {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 26px;
  height: 34px;
  background: rgba(255,255,255,0.38);
  border-radius: 50%;
  transform: rotate(-28deg);
  filter: blur(3px);
}
.balloon-knot {
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 13px solid var(--bcolor, #ff6b9d);
  margin-top: -1px;
}
.balloon-string {
  width: 1.5px;
  height: 72px;
  background: rgba(255,255,255,0.35);
  border-radius: 0 0 20px 20px;
}
.balloon-counter {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  transition: opacity 0.3s;
  min-height: 22px;
}
@keyframes balloonPop {
  0%   { transform: scale(var(--pop-scale, 1.9)); opacity: 1 }
  55%  { transform: scale(calc(var(--pop-scale, 1.9) * 1.18)); opacity: 0.7 }
  100% { transform: scale(0); opacity: 0 }
}
.balloon-pop { animation: balloonPop 0.35s ease forwards }

/* ── Countdown ───────────────────────────────────────────────────────────────── */
.scene-countdown {
  background: var(--bg);
  flex-direction: column;
  gap: 16px;
}
.countdown-label {
  font-size: clamp(13px, 3vw, 17px);
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-align: center;
}
.countdown-num {
  font-size: clamp(110px, 32vw, 240px);
  font-weight: 900;
  letter-spacing: -0.06em;
  line-height: 0.9;
  color: var(--accent);
  opacity: 0;
  transform: scale(1.9);
  will-change: transform, opacity;
}
.countdown-num.count-in {
  animation: countIn 0.92s ease forwards;
}
@keyframes countIn {
  0%   { opacity: 0; transform: scale(1.9) }
  18%  { opacity: 1; transform: scale(1) }
  78%  { opacity: 1; transform: scale(1) }
  100% { opacity: 0; transform: scale(0.55) }
}
.countdown-num.count-burst {
  animation: countBurst 0.7s ease forwards;
}
@keyframes countBurst {
  0%   { opacity: 1; transform: scale(1) }
  45%  { opacity: 1; transform: scale(2.8); filter: brightness(1.6) }
  100% { opacity: 0; transform: scale(3.2) }
}

/* ── Self-destruct ───────────────────────────────────────────────────────────── */
.scene-destruct {
  background: #0a0003;
  border: 3px solid #ff2040;
  animation: destructPulse 0.6s ease-in-out infinite alternate;
}
@keyframes destructPulse {
  from { border-color: #cc0020; box-shadow: inset 0 0 30px rgba(255,32,64,0.08) }
  to   { border-color: #ff4060; box-shadow: inset 0 0 70px rgba(255,32,64,0.22) }
}
.destruct-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 32px;
  text-align: center;
}
.destruct-icon { font-size: 44px }
.destruct-warning {
  font-size: clamp(12px, 2.8vw, 16px);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ff4060;
  font-family: 'Courier New', monospace;
}
.destruct-num {
  font-size: clamp(36px, 10vw, 72px);
  font-weight: 900;
  color: #ff2040;
  font-family: 'Courier New', monospace;
  letter-spacing: -0.03em;
  transition: transform 0.1s;
}
.destruct-tick { transform: scale(1.12) }
.destruct-progress {
  width: min(300px, 80vw);
  height: 6px;
  background: rgba(255,32,64,0.18);
  border-radius: 3px;
  overflow: hidden;
}
.destruct-bar {
  height: 100%;
  background: #ff2040;
  border-radius: 3px;
  width: 0;
  transition: width 0.9s linear;
}
.destruct-flash {
  animation: none !important;
  background: #fff !important;
  border-color: #fff !important;
  transition: background 0.3s, border-color 0.3s;
}

/* ── Back button (always-visible escape hatch) ───────────────────────────────── */
.scene-back {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1000;
  color: rgba(255,255,255,0.42);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 100px;
  background: rgba(0,0,0,0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  transition: color 0.2s, background 0.2s;
  letter-spacing: 0.01em;
  user-select: none;
}
.scene-back:hover {
  color: rgba(255,255,255,0.88);
  background: rgba(0,0,0,0.5);
}

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.pulse {
  animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1 }
  50% { opacity: 0.45 }
}
