/* ===== Stack It Up Game ===== */
#stackGame {
  display: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(135deg, #FFF8E7 0%, #F0E6FF 50%, #E0F7FA 100%);
}

.stack-camera {
  position: absolute;
  inset: 0;
  transform-origin: center bottom;
  z-index: 10;
}

.stack-tower {
  position: absolute;
  inset: 0;
  transform-origin: center bottom;
}

.stack-score {
  position: fixed;
  top: 16px;
  right: 20px;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  color: rgba(124, 92, 252, 0.85);
  z-index: 200;
  pointer-events: none;
}

.stack-block {
  position: absolute;
  border-radius: 10px;
  z-index: 110;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.stack-block.active {
  box-shadow: 0 2px 12px rgba(124, 92, 252, 0.3), 0 0 20px rgba(255, 255, 255, 0.2), inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.stack-block.perfect-flash {
  animation: perfectGlow 0.5s ease-out;
}

@keyframes perfectGlow {
  0%   { box-shadow: 0 0 20px #FFD700, 0 0 40px #FFD700, inset 0 2px 4px rgba(255,255,255,0.3); }
  100% { box-shadow: 0 2px 8px rgba(0,0,0,0.15), inset 0 2px 4px rgba(255,255,255,0.3); }
}

.stack-block.streak-flash {
  animation: streakRainbow 0.6s ease-out;
}

@keyframes streakRainbow {
  0%   { box-shadow: 0 0 20px #FF6B8A, 0 0 40px #FFB347; }
  33%  { box-shadow: 0 0 20px #7C5CFC, 0 0 40px #4ECDC4; }
  66%  { box-shadow: 0 0 20px #FFB347, 0 0 40px #FF6B8A; }
  100% { box-shadow: 0 2px 8px rgba(0,0,0,0.15), inset 0 2px 4px rgba(255,255,255,0.3); }
}

.stack-danger-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  box-shadow: inset 0 0 80px rgba(255, 80, 80, var(--danger-opacity, 0));
  transition: box-shadow 0.3s ease;
}

.stack-crane {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 48px;
  z-index: 120;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.stack-cable {
  position: absolute;
  inset: 0;
  z-index: 109;
  pointer-events: none;
  overflow: visible;
}

.stack-ball {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 50px;
  line-height: 1;
  z-index: 109;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

.stack-celebrate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  background: rgba(255, 248, 231, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.stack-celebrate.show {
  opacity: 1;
  pointer-events: auto;
}

.stack-endcard {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  animation: stackEndcardIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes stackEndcardIn {
  0%   { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.stack-endcard-emoji {
  font-size: clamp(4rem, 15vw, 7rem);
  line-height: 1;
}

.stack-endcard-title {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.8rem, 6vw, 3rem);
  color: #FF6B8A;
}

.stack-endcard-stats {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1rem, 3vw, 1.4rem);
  color: rgba(124, 92, 252, 0.85);
}

.stack-endcard-best {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1rem, 3vw, 1.4rem);
  color: #FFB347;
}

.stack-endcard-hint {
  font-family: 'Quicksand', sans-serif;
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  color: #999;
  font-weight: 600;
}

.stack-confetti {
  position: fixed;
  pointer-events: none;
  z-index: 250;
  animation: confettiFall var(--fall-dur) linear forwards;
}

@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(var(--fall-dist)) rotate(var(--fall-rot)); opacity: 0; }
}

/* ===== Stadium Audience ===== */
.stack-audience {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
  opacity: 0.8;
}

.audience-emoji {
  position: absolute;
  transform: translateX(-50%);
  line-height: 1;
}

/* Ambient rows: always gentle idle, ignore reaction classes */
.audience-emoji.ambient-row {
  animation: audienceIdle 2.5s ease-in-out infinite !important;
  animation-delay: var(--idle-offset) !important;
}

/* --- Idle: gentle staggered bobbing (reactive rows) --- */
.audience-idle .audience-emoji.reactive-row {
  animation: audienceIdle 2s ease-in-out infinite;
  animation-delay: var(--idle-offset);
}
@keyframes audienceIdle {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-4px); }
}

/* --- Cheer: quick bounce --- */
.audience-cheer .audience-emoji.reactive-row {
  animation: audienceCheer 0.35s ease-out;
  animation-delay: var(--audience-delay);
}
@keyframes audienceCheer {
  0%   { transform: translateX(-50%) translateY(0) scale(1); }
  40%  { transform: translateX(-50%) translateY(-14px) scale(1.15); }
  100% { transform: translateX(-50%) translateY(0) scale(1); }
}

/* --- Wild: big bounce + wiggle (perfect placement) --- */
.audience-wild .audience-emoji.reactive-row {
  animation: audienceWild 0.5s ease-out;
  animation-delay: var(--audience-delay);
}
@keyframes audienceWild {
  0%   { transform: translateX(-50%) translateY(0) rotate(0deg) scale(1); }
  25%  { transform: translateX(-50%) translateY(-20px) rotate(-12deg) scale(1.25); }
  50%  { transform: translateX(-50%) translateY(-10px) rotate(12deg) scale(1.15); }
  75%  { transform: translateX(-50%) translateY(-16px) rotate(-6deg) scale(1.2); }
  100% { transform: translateX(-50%) translateY(0) rotate(0deg) scale(1); }
}

/* --- Wave: mexican wave (staggered delays) --- */
.audience-wave .audience-emoji.reactive-row {
  animation: audienceWave 0.6s ease-out;
  animation-delay: var(--audience-delay);
}
@keyframes audienceWave {
  0%   { transform: translateX(-50%) translateY(0) scale(1); }
  30%  { transform: translateX(-50%) translateY(-24px) scale(1.3); }
  60%  { transform: translateX(-50%) translateY(-8px) scale(1.05); }
  100% { transform: translateX(-50%) translateY(0) scale(1); }
}

/* --- Worry: shrink + shake --- */
.audience-worry .audience-emoji.reactive-row {
  animation: audienceWorry 0.4s ease-out infinite;
  animation-delay: var(--audience-delay);
}
@keyframes audienceWorry {
  0%, 100% { transform: translateX(-50%) translateY(4px) scale(0.85); }
  25%      { transform: translateX(-52%) translateY(4px) scale(0.85); }
  75%      { transform: translateX(-48%) translateY(4px) scale(0.85); }
}

/* --- Gasp: jump back + scatter --- */
.audience-gasp .audience-emoji.reactive-row {
  animation: audienceGasp 0.6s ease-out forwards;
}
@keyframes audienceGasp {
  0%   { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
  30%  { transform: translateX(-50%) translateY(-18px) scale(1.3); opacity: 1; }
  100% { transform: translateX(-50%) translateY(12px) scale(0.7); opacity: 0.5; }
}

/* --- Party: continuous bouncing (win) --- */
.audience-party .audience-emoji.reactive-row {
  animation: audienceParty 0.5s ease-in-out infinite;
  animation-delay: var(--audience-delay);
}
@keyframes audienceParty {
  0%, 100% { transform: translateX(-50%) translateY(0) rotate(0deg) scale(1); }
  25%      { transform: translateX(-50%) translateY(-18px) rotate(-15deg) scale(1.2); }
  75%      { transform: translateX(-50%) translateY(-12px) rotate(15deg) scale(1.15); }
}

/* ===== High Score Display ===== */
.stack-best {
  position: fixed;
  top: 52px;
  right: 20px;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(0.8rem, 2vw, 1.1rem);
  color: rgba(124, 92, 252, 0.4);
  z-index: 200;
  pointer-events: none;
}
.stack-best.new-best {
  animation: newBestPulse 0.5s ease-out;
  color: #FFD700;
}
@keyframes newBestPulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.4); color: #FFD700; }
  100% { transform: scale(1); }
}
