:root {
  --bg: #101a26;
  --card: #1f2f45;
  --card-soft: #243851;
  --text: #f6f9ff;
  --muted: #bfd0eb;
  --accent: #67f5a8;
  --danger: #ff6a80;
  --warn: #ffd66f;
  --tile: 46px;
  --player-color: #ffd43f;
  --player-border: #deb21b;
  --player-size: 46px;
  --growth-scale: 1;
  --enemy-color: #ed4c68;
  --enemy-border: #ff95a8;
  --enemy-size: 46px;
  --dino-color: #5b9cf5;
  --dino-border: #ffce62;
  --dino-size: 46px;
}

* {
  box-sizing: border-box;
}

/* === CORNER EXIT BUTTONS === */
.exit-btn {
  position: fixed;
  z-index: 9998;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 12px currentColor, 0 2px 6px rgba(0,0,0,0.4);
  transition: transform 0.2s, box-shadow 0.3s;
  animation: exitColorCycle 5s linear infinite;
  line-height: 1;
}

.exit-btn:hover {
  transform: scale(1.2);
  box-shadow: 0 0 20px currentColor, 0 0 40px currentColor;
}

.exit-btn:active {
  transform: scale(0.9);
}

.exit-tl { top: 10px; left: 10px; }
.exit-tr { top: 10px; right: 10px; }
.exit-bl { bottom: 10px; left: 10px; }
.exit-br { bottom: 10px; right: 10px; }

/* Stagger the cycle so each corner is a different colour */
.exit-tr { animation-delay: -1.25s; }
.exit-bl { animation-delay: -2.5s; }
.exit-br { animation-delay: -3.75s; }

@keyframes exitColorCycle {
  0%   { background: #ff4757; color: #ff4757; } /* red */
  20%  { background: #ffa502; color: #ffa502; } /* orange */
  40%  { background: #2ed573; color: #2ed573; } /* green */
  60%  { background: #1e90ff; color: #1e90ff; } /* blue */
  80%  { background: #c56cf0; color: #c56cf0; } /* purple */
  100% { background: #ff4757; color: #ff4757; } /* back to red */
}

/* The ✕ glyph stays white */
.exit-btn::after {
  content: "✕";
  position: absolute;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* === COLOURFUL BUTTONS === */
.btn-play {
  background: linear-gradient(135deg, #2ed573, #17a058);
  color: #fff;
}
.btn-pause {
  background: linear-gradient(135deg, #ffa502, #e87800);
  color: #fff;
}
.btn-restart {
  background: linear-gradient(135deg, #ff6b81, #e8415f);
  color: #fff;
}

/* === SPEED SELECTOR === */
.speed-selector {
  position: absolute;
  right: 0;
  top: -52px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 5;
}

.speed-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: #bfd0eb;
  white-space: nowrap;
}

.speed-buttons {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.speed-btn {
  padding: 4px 8px !important;
  font-size: 0.72rem !important;
  background: rgba(36, 56, 81, 0.8) !important;
  border: 1.5px solid rgba(206, 227, 255, 0.25) !important;
  color: #bfd0eb !important;
  border-radius: 8px !important;
  min-width: auto !important;
  transition: all 0.2s;
}

.speed-btn.active {
  background: linear-gradient(135deg, #1e90ff, #0d5cad) !important;
  border-color: #1e90ff !important;
  color: #fff !important;
  box-shadow: 0 0 10px rgba(30, 144, 255, 0.5);
}

.speed-btn:hover:not(.active) {
  background: rgba(30, 144, 255, 0.25) !important;
  border-color: rgba(30, 144, 255, 0.5) !important;
  color: #fff !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", "Segoe UI", Arial, sans-serif;
  background: radial-gradient(circle at 20% 20%, #20466e, var(--bg) 55%);
  color: var(--text);
}

.app {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px 14px 30px;
  text-align: center;
}

.title-wrap h1 {
  margin: 0;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 4px 0 14px;
  color: var(--muted);
  font-weight: 700;
}

.hud {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 8px;
}

.hud-card {
  background: linear-gradient(180deg, var(--card-soft), var(--card));
  border: 2px solid rgba(183, 214, 255, 0.25);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 72px;
  justify-content: center;
}

.hud-card span {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hud-card strong {
  font-size: 1.02rem;
}

.progress-wrap {
  margin: 10px 0;
}

.progress-track {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(183, 214, 255, 0.35);
  background: #16253a;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #5fd4ff, #7aff9f);
  transition: width 0.25s ease;
}

.controls-bar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.btn,
.touch-btn {
  border: none;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
  color: #142236;
  background: #dde8f8;
  padding: 10px 16px;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:hover,
.touch-btn:hover {
  transform: translateY(-1px) scale(1.01);
  filter: brightness(1.05);
}

.btn:focus-visible,
.touch-btn:focus-visible,
#overlay-action:focus-visible {
  outline: 3px solid #fff36c;
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(180deg, #8aff95, #51dd6e);
}

.btn-ai {
  background: linear-gradient(180deg, #c79bff, #9b5cff);
  color: #fff;
}

.btn-ai.active {
  background: linear-gradient(180deg, #9b5cff, #6b1fff);
  animation: aiPulse 0.8s ease-in-out infinite alternate;
  color: #fff;
}

@keyframes aiPulse {
  from { box-shadow: 0 0 4px rgba(155,92,255,0.5); }
  to { box-shadow: 0 0 16px rgba(155,92,255,0.9); }
}

.btn-ai2 {
  background: linear-gradient(180deg, #7fdfff, #3bb5e8);
  color: #142236;
}

.btn-ai2.active {
  background: linear-gradient(180deg, #3bb5e8, #1f8fc8);
  animation: aiVsAiPulse 0.8s ease-in-out infinite alternate;
  color: #fff;
}

@keyframes aiVsAiPulse {
  from { box-shadow: 0 0 4px rgba(59,181,232,0.5); }
  to { box-shadow: 0 0 16px rgba(59,181,232,0.9); }
}

.chaser-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 6px 0;
}

.chaser-controls .chaser-label {
  font-weight: 800;
  color: #c5d8ef;
  font-size: 14px;
}

.btn-chaser {
  padding: 6px 12px !important;
  font-size: 18px !important;
  background: linear-gradient(180deg, #ffe066, #ffb733) !important;
  border: 2px solid rgba(255, 200, 50, 0.6) !important;
  min-width: 40px;
}

#chaser-count {
  color: #ffd43f;
  font-size: 18px;
  min-width: 20px;
  text-align: center;
}

.status-message {
  min-height: 22px;
  margin-bottom: 6px;
  font-weight: 800;
  color: #ffe89a;
}

.board-wrap {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  gap: 10px;
}

/* === SCREEN SHAKE === */
.board-wrap.shake {
  animation: screenShake 0.4s ease-in-out;
}

@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-6px, -3px) rotate(-0.5deg); }
  30% { transform: translate(5px, 4px) rotate(0.5deg); }
  45% { transform: translate(-4px, 3px) rotate(-0.3deg); }
  60% { transform: translate(3px, -3px) rotate(0.3deg); }
  75% { transform: translate(-2px, 1px); }
  90% { transform: translate(1px, -1px); }
}

/* Harder shake for damage */
.board-wrap.shake-hard {
  animation: screenShakeHard 0.5s ease-in-out;
}

@keyframes screenShakeHard {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-10px, -5px) rotate(-1deg); }
  20% { transform: translate(8px, 6px) rotate(1deg); }
  35% { transform: translate(-7px, 4px) rotate(-0.7deg); }
  50% { transform: translate(5px, -5px) rotate(0.5deg); }
  65% { transform: translate(-4px, 3px) rotate(-0.3deg); }
  80% { transform: translate(2px, -2px); }
}

/* === COMBO FLOATING TEXT === */
.combo-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
  font-weight: 900;
  color: #ffe363;
  text-shadow: 0 0 8px rgba(255,200,0,0.8), 0 2px 4px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 20;
  animation: comboFloat 0.8s ease-out forwards;
  white-space: nowrap;
}

@keyframes comboFloat {
  0% {
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 0;
  }
  20% {
    transform: translate(-50%, -80%) scale(1.3);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -150%) scale(1);
    opacity: 0;
  }
}

/* === LEVEL START BANNER === */
.level-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.5rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 12px rgba(103,245,168,0.8), 0 0 24px rgba(103,245,168,0.4), 0 2px 6px rgba(0,0,0,0.6);
  pointer-events: none;
  z-index: 25;
  text-align: center;
  animation: bannerSweep 1.5s ease-in-out forwards;
  white-space: nowrap;
}

.level-banner .banner-sub {
  display: block;
  font-size: 1rem;
  color: var(--accent);
  margin-top: 4px;
}

@keyframes bannerSweep {
  0% {
    transform: translate(-200%, -50%) scale(0.8);
    opacity: 0;
    clip-path: inset(0 100% 0 0);
  }
  25% {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 1;
    clip-path: inset(0 0 0 0);
  }
  75% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    clip-path: inset(0 0 0 0);
  }
  100% {
    transform: translate(200%, -50%) scale(0.8);
    opacity: 0;
    clip-path: inset(0 0 0 100%);
  }
}

/* === CHOMP RIPPLE === */
.chomp-ripple {
  position: absolute;
  border-radius: 50%;
  border: 3px solid #ffe363;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.3);
  opacity: 1;
  z-index: 11;
  animation: ripple 500ms ease-out forwards;
}

@keyframes ripple {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 0.9;
    border-width: 4px;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.2);
    opacity: 0;
    border-width: 1px;
  }
}

.zap-btn {
  width: 56px;
  border: 3px solid rgba(255, 221, 87, 0.8);
  border-radius: 14px;
  font-size: 28px;
  font-weight: 900;
  cursor: pointer;
  color: #142236;
  background: linear-gradient(180deg, #ffe666, #ffb733);
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  padding: 8px 4px;
  box-shadow: 0 0 12px rgba(255, 200, 50, 0.4);
}

.zap-btn span {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
}

.zap-btn:hover {
  transform: scale(1.08);
  filter: brightness(1.1);
  box-shadow: 0 0 20px rgba(255, 200, 50, 0.7);
}

.zap-btn:active {
  transform: scale(0.95);
}

.zap-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.grid {
  position: relative;
  border: 3px solid rgba(194, 224, 255, 0.8);
  border-radius: 10px;
  overflow: visible;
}

.row {
  display: flex;
}

/* === SPRITE OVERLAY SYSTEM === */
/* Player, enemies, and rivals are rendered as sprites that slide smoothly */
.sprite-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 10;
}

/* Disable transitions for instant teleport (damage resets, level loads) */
.sprite-layer.no-transition .sprite {
  transition: none !important;
}

.sprite {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--tile);
  height: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  transition: transform 0.12s linear;
  will-change: transform;
}

/* Player sprite — contains the .player div with all its visual styles */
.sprite-player {
  transition: transform 0.1s ease-out;
  z-index: 15;
}

.sprite-player .player {
  width: var(--player-size);
  height: var(--player-size);
  position: relative;
}

/* Enemy sprite */
.sprite-enemy {
  background: radial-gradient(circle at 40% 30%, color-mix(in srgb, var(--enemy-color) 40%, #fff), var(--enemy-color) 60%, color-mix(in srgb, var(--enemy-color) 60%, #6b1530) 100%);
  border: 2px solid var(--enemy-border);
  border-radius: 50%;
  font-size: calc(var(--enemy-size) * 0.7);
  z-index: 12;
}

/* Rival sprite */
.sprite-rival {
  background: radial-gradient(circle at 35% 35%, #6be5ff, #2a9fd6 60%, #1a5f8a 100%);
  border: 2px solid #8ff0ff;
  border-radius: 50%;
  font-size: 1.2rem;
  box-shadow: 0 0 8px rgba(107, 229, 255, 0.6);
  animation: bob 1s ease-in-out infinite alternate;
  z-index: 13;
}

.cell {
  width: var(--tile);
  height: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}

.path {
  background: #173152;
  border: 1px solid #213f61;
}

.wall {
  background: linear-gradient(135deg, #2d6cb2, #204f89);
  border: 1px solid #67beff;
}

.dino {
  background: radial-gradient(circle at 35% 35%, var(--dino-color), color-mix(in srgb, var(--dino-color) 60%, #ff9f3f) 100%);
  border: 2px solid var(--dino-border);
  font-size: calc(var(--dino-size) * 0.7);
  animation: bob 1s ease-in-out infinite alternate;
}

/* Rainbow dino variants */
.dino-blue {
  --dino-color: #5b9cf5;
  --dino-border: #3d7fd9;
}
.dino-purple {
  --dino-color: #a96bf5;
  --dino-border: #8a4fd9;
}
.dino-teal {
  --dino-color: #3fd9c4;
  --dino-border: #28b8a5;
}
.dino-pink {
  --dino-color: #f56bc9;
  --dino-border: #d94fa8;
}
.dino-cyan {
  --dino-color: #4fd9f5;
  --dino-border: #34b8d9;
}
.dino-violet {
  --dino-color: #7d6bf5;
  --dino-border: #5d4fd9;
}
.dino-mint {
  --dino-color: #6bf5a9;
  --dino-border: #4fd98a;
}
.dino-coral {
  --dino-color: #f56b8a;
  --dino-border: #d94f6e;
}
.dino-sky {
  --dino-color: #6bb5f5;
  --dino-border: #4f95d9;
}
.dino-lavender {
  --dino-color: #c96bf5;
  --dino-border: #a84fd9;
}

.entrance {
  background: radial-gradient(circle at 50% 50%, #2a6e4f, #184a33);
  border: 2px solid #4fd49f;
  animation: bob 1.4s ease-in-out infinite alternate;
}

.exit {
  background: radial-gradient(circle at 50% 50%, #6b3fa0, #3d1f6b);
  border: 2px solid #b67ff0;
  animation: exitPulse 0.7s ease-in-out infinite alternate;
}

.entrance2 {
  background: radial-gradient(circle at 50% 50%, #1d5a8a, #0e3a5e);
  border: 2px solid #5fb8f0;
  animation: bob 1.4s ease-in-out infinite alternate;
}

.exit2 {
  background: radial-gradient(circle at 50% 50%, #c47a1a, #8a4e0e);
  border: 2px solid #ffd966;
  animation: exitPulse 0.7s ease-in-out infinite alternate;
}

.player {
  background: radial-gradient(circle at 35% 35%, color-mix(in srgb, var(--player-color) 50%, #fff), var(--player-color) 60%, color-mix(in srgb, var(--player-color) 70%, #b8841f) 100%);
  border: 2px solid var(--player-border);
  border-radius: 50%;
  box-shadow: 0 0 10px color-mix(in srgb, var(--player-color) 90%, transparent);
  font-size: calc(var(--player-size) * 0.7);
  width: var(--player-size);
  height: var(--player-size);
  position: relative;
  overflow: visible;
  transform: scale(var(--growth-scale));
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Dino spikes along the top */
.player::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 10px solid #f6b41f;
  filter: drop-shadow(2px 0 0 #deb21b) drop-shadow(-2px 0 0 #deb21b);
}

/* Chomping mouth — the Pac-Man-style wedge */
.player::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 2px;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
  border-right: 16px solid #173152;
  animation: chompMouth 0.4s ease-in-out infinite alternate;
  z-index: 2;
}

@keyframes chompMouth {
  from {
    border-top-width: 3px;
    border-bottom-width: 3px;
  }
  to {
    border-top-width: 14px;
    border-bottom-width: 14px;
  }
}

/* === GROWTH TIERS — the chomper gets bigger, buffer, and stronger === */

/* Tier 1: Bulky — subtle glow boost */
body.growth-1 .player {
  box-shadow: 0 0 14px color-mix(in srgb, var(--player-color) 100%, #ff8c00 30%);
  border-width: 3px;
}
body.growth-1 .player::before {
  border-bottom-width: 13px;
  border-left-width: 8px;
  border-right-width: 8px;
  top: -10px;
}

/* Tier 2: Beefy — stronger aura, bigger spike, orange tint */
body.growth-2 .player {
  box-shadow: 0 0 18px color-mix(in srgb, var(--player-color) 90%, #ff6a00 40%), 0 0 6px #fff3 inset;
  border-width: 3px;
  border-color: color-mix(in srgb, var(--player-border) 50%, #ff8c00);
}
body.growth-2 .player::before {
  border-bottom-width: 16px;
  border-left-width: 9px;
  border-right-width: 9px;
  top: -12px;
  filter: drop-shadow(2px 0 0 #deb21b) drop-shadow(-2px 0 0 #deb21b) drop-shadow(0 2px 3px rgba(255,140,0,0.5));
}

/* Tier 3: Mega — fiery aura, double spikes, pulsing glow */
body.growth-3 .player {
  box-shadow: 0 0 22px color-mix(in srgb, var(--player-color) 80%, #ff4500 50%), 0 0 10px rgba(255,200,0,0.4);
  border-width: 4px;
  border-color: color-mix(in srgb, var(--player-border) 30%, #ff6500);
  animation: megaPulse 0.8s ease-in-out infinite alternate;
}
body.growth-3 .player::before {
  border-bottom-width: 20px;
  border-left-width: 11px;
  border-right-width: 11px;
  top: -15px;
  filter: drop-shadow(2px 0 0 #deb21b) drop-shadow(-2px 0 0 #deb21b) drop-shadow(0 2px 4px rgba(255,100,0,0.6));
}

/* Tier 4: Colossus — blazing aura, massive spikes, rainbow shimmer */
body.growth-4 .player {
  box-shadow: 0 0 28px color-mix(in srgb, var(--player-color) 70%, #ff2000 60%), 0 0 14px rgba(255,215,0,0.5), 0 0 4px #fff inset;
  border-width: 5px;
  border-color: #ff8c00;
  animation: colossusPulse 0.6s ease-in-out infinite alternate;
}
body.growth-4 .player::before {
  border-bottom-width: 24px;
  border-left-width: 13px;
  border-right-width: 13px;
  top: -18px;
  border-bottom-color: #ff6a00;
  filter: drop-shadow(2px 0 0 #deb21b) drop-shadow(-2px 0 0 #deb21b) drop-shadow(0 3px 5px rgba(255,80,0,0.7));
}

@keyframes megaPulse {
  from { filter: brightness(1) saturate(1); }
  to { filter: brightness(1.15) saturate(1.3); }
}

@keyframes colossusPulse {
  from { filter: brightness(1) saturate(1.1) hue-rotate(0deg); }
  to { filter: brightness(1.25) saturate(1.5) hue-rotate(10deg); }
}

/* Stunned: chomper gets dizzy and wobbles after being caught */
body.stunned .player {
  animation: dizzyWobble 0.25s ease-in-out infinite !important;
  filter: saturate(0.5) brightness(0.85);
}

@keyframes dizzyWobble {
  0% { transform: scale(var(--growth-scale)) rotate(-8deg) translateY(0); }
  25% { transform: scale(var(--growth-scale)) rotate(6deg) translateY(-2px); }
  50% { transform: scale(var(--growth-scale)) rotate(-6deg) translateY(1px); }
  75% { transform: scale(var(--growth-scale)) rotate(8deg) translateY(-1px); }
  100% { transform: scale(var(--growth-scale)) rotate(-8deg) translateY(0); }
}

.enemy {
  background: radial-gradient(circle at 40% 30%, color-mix(in srgb, var(--enemy-color) 40%, #fff), var(--enemy-color) 60%, color-mix(in srgb, var(--enemy-color) 60%, #6b1530) 100%);
  border: 2px solid var(--enemy-border);
  font-size: calc(var(--enemy-size) * 0.7);
}

/* Rival chompers — AI competitors that also eat dinos */
.rival {
  background: radial-gradient(circle at 35% 35%, #6be5ff, #2a9fd6 60%, #1a5f8a 100%);
  border: 2px solid #8ff0ff;
  border-radius: 50%;
  font-size: 1.2rem;
  box-shadow: 0 0 8px rgba(107, 229, 255, 0.6);
  animation: bob 1s ease-in-out infinite alternate;
}

.cell.hit {
  animation: hitPulse 0.24s ease;
}

.effects-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.spark {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  animation: sparkle 450ms ease-out forwards;
  transform: translate(-50%, -50%);
}

.spark.chomp {
  background: #ffe363;
}

.spark.damage {
  background: #ff6f87;
}

.spark.celebrate {
  background: #8dffbb;
}

.spark.implosion {
  background: #7ad6ff;
  width: 6px;
  height: 6px;
  animation: implode 320ms ease-in forwards;
}

.spark.explosion {
  background: #ffd76b;
  width: 14px;
  height: 14px;
  animation: explode 500ms ease-out forwards;
  box-shadow: 0 0 8px rgba(255,200,0,0.6);
}

/* Big boom ring — expanding shockwave for portal explosions */
.boom-ring {
  position: absolute;
  border-radius: 50%;
  border: 4px solid #ffd76b;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.1);
  opacity: 1;
  z-index: 11;
  animation: boomRing 600ms ease-out forwards;
}

@keyframes boomRing {
  0% {
    transform: translate(-50%, -50%) scale(0.1);
    opacity: 1;
    border-width: 6px;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.5);
    opacity: 0;
    border-width: 1px;
  }
}

.touch-controls {
  margin: 10px auto 6px;
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 90px));
  gap: 7px;
  justify-content: center;
}

.touch-btn {
  font-size: 1.1rem;
  min-height: 46px;
}

.touch-chomp {
  background: linear-gradient(180deg, #ffe27f, #ffbf47);
}

.help-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 12, 20, 0.74);
  padding: 16px;
  z-index: 20;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  max-width: 420px;
  width: 100%;
  background: linear-gradient(180deg, #274569, #1a2f4a);
  border: 2px solid rgba(206, 227, 255, 0.65);
  border-radius: 16px;
  padding: 20px;
}

.overlay-card h2 {
  margin-top: 0;
}

.overlay-card p {
  font-size: 1.04rem;
  line-height: 1.35;
}

/* === FIREWORK CANVAS === */
.firework-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9999;
}

.firework-canvas.hidden {
  display: none;
}

/* === STAR RATING — colourful & varied === */
.overlay-stars {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin: 8px 0 4px;
  font-size: 3rem;
}

.overlay-stars.hidden {
  display: none;
}

/* Overlay button row */
.overlay-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin-top: 8px;
}

.overlay-restart-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1.5px solid rgba(206, 227, 255, 0.4);
  color: #cee3ff;
}

.overlay-restart-btn.hidden {
  display: none;
}

.overlay-restart-btn:hover {
  background: rgba(255, 71, 87, 0.25);
  border-color: #ff4757;
  color: #fff;
}

/* Super Endless button */
.btn-super {
  background: linear-gradient(135deg, #ff4757, #c56cf0) !important;
  color: #fff !important;
  border: 2px solid rgba(255, 255, 255, 0.4) !important;
  animation: superGlow 2s ease-in-out infinite alternate;
}

.btn-super.hidden {
  display: none;
}

@keyframes superGlow {
  from { box-shadow: 0 0 8px rgba(255, 71, 87, 0.5); }
  to { box-shadow: 0 0 20px rgba(197, 108, 240, 0.7); }
}

.btn-super:hover {
  transform: scale(1.05);
  filter: brightness(1.15);
}

/* Base star — hidden until earned */
.overlay-stars .star {
  opacity: 0;
  transform: scale(0);
  transition: none;
  display: inline-block;
  line-height: 1;
}

/* Empty (unearned) star — dim grey outline */
.overlay-stars .star.empty {
  opacity: 0.22;
  transform: scale(1);
  filter: grayscale(1);
}

/* Each earned star gets its own colour glow + unique pop animation */
.overlay-stars .star.earned.c1 {
  color: #ff4757; /* red */
  filter: drop-shadow(0 0 6px #ff4757) drop-shadow(0 0 14px #ff4757) drop-shadow(0 0 28px rgba(255,71,87,0.6));
  text-shadow: 0 0 4px #fff, 0 0 10px #fff;
  animation: starPopRed 0.55s ease-out forwards;
}
.overlay-stars .star.earned.c2 {
  color: #ffa502; /* orange */
  filter: drop-shadow(0 0 6px #ffa502) drop-shadow(0 0 14px #ffa502) drop-shadow(0 0 28px rgba(255,165,2,0.6));
  text-shadow: 0 0 4px #fff, 0 0 10px #fff;
  animation: starPopOrange 0.55s ease-out forwards;
}
.overlay-stars .star.earned.c3 {
  color: #2ed573; /* green */
  filter: drop-shadow(0 0 6px #2ed573) drop-shadow(0 0 14px #2ed573) drop-shadow(0 0 28px rgba(46,213,115,0.6));
  text-shadow: 0 0 4px #fff, 0 0 10px #fff;
  animation: starPopGreen 0.55s ease-out forwards;
}
.overlay-stars .star.earned.c4 {
  color: #1e90ff; /* blue */
  filter: drop-shadow(0 0 6px #1e90ff) drop-shadow(0 0 14px #1e90ff) drop-shadow(0 0 28px rgba(30,144,255,0.6));
  text-shadow: 0 0 4px #fff, 0 0 10px #fff;
  animation: starPopBlue 0.55s ease-out forwards;
}
.overlay-stars .star.earned.c5 {
  color: #c56cf0; /* purple */
  filter: drop-shadow(0 0 8px #c56cf0) drop-shadow(0 0 18px #c56cf0) drop-shadow(0 0 36px rgba(197,108,240,0.7));
  text-shadow: 0 0 5px #fff, 0 0 14px #fff;
  animation: starPopPurple 0.6s ease-out forwards;
}

/* Star 1 — RED: pops in with a left spin */
@keyframes starPopRed {
  0% { opacity: 0; transform: scale(0) rotate(-180deg) translateX(-20px); }
  50% { opacity: 1; transform: scale(1.4) rotate(15deg) translateX(0); }
  75% { transform: scale(0.9) rotate(-5deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* Star 2 — ORANGE: pops in with a bounce */
@keyframes starPopOrange {
  0% { opacity: 0; transform: scale(0) translateY(-30px); }
  40% { opacity: 1; transform: scale(1.35) translateY(0); }
  55% { transform: scale(0.9) translateY(-8px); }
  70% { transform: scale(1.1) translateY(0); }
  85% { transform: scale(0.97) translateY(-3px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* Star 3 — GREEN: pops in with a right spin */
@keyframes starPopGreen {
  0% { opacity: 0; transform: scale(0) rotate(180deg) translateX(20px); }
  50% { opacity: 1; transform: scale(1.4) rotate(-15deg) translateX(0); }
  75% { transform: scale(0.9) rotate(5deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* Star 4 — BLUE: pops in from above with a wobble */
@keyframes starPopBlue {
  0% { opacity: 0; transform: scale(0) translateY(-40px) rotate(-90deg); }
  50% { opacity: 1; transform: scale(1.3) translateY(0) rotate(10deg); }
  65% { transform: scale(1.05) rotate(-8deg) translateY(-5px); }
  80% { transform: scale(1) rotate(4deg) translateY(0); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* Star 5 — PURPLE: big finale pop with sparkly overshoot */
@keyframes starPopPurple {
  0% { opacity: 0; transform: scale(0) rotate(0deg); }
  30% { opacity: 0.5; transform: scale(0.8) rotate(45deg); }
  55% { opacity: 1; transform: scale(1.5) rotate(-20deg); }
  70% { transform: scale(0.85) rotate(15deg); }
  85% { transform: scale(1.12) rotate(-5deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* Rainbow shimmer on the star row after all stars appear */
.overlay-stars.shimmer .star.earned {
  animation: starShimmer 2s ease-in-out infinite;
}
.overlay-stars.shimmer .star.earned.c1 { animation: starPopRed 0.55s ease-out forwards, starShimmer 2s ease-in-out 1s infinite; }
.overlay-stars.shimmer .star.earned.c2 { animation: starPopOrange 0.55s ease-out forwards, starShimmer 2s ease-in-out 1s infinite; }
.overlay-stars.shimmer .star.earned.c3 { animation: starPopGreen 0.55s ease-out forwards, starShimmer 2s ease-in-out 1s infinite; }
.overlay-stars.shimmer .star.earned.c4 { animation: starPopBlue 0.55s ease-out forwards, starShimmer 2s ease-in-out 1s infinite; }
.overlay-stars.shimmer .star.earned.c5 { animation: starPopPurple 0.6s ease-out forwards, starShimmer 2s ease-in-out 1s infinite; }

@keyframes starShimmer {
  0%, 100% {
    filter: drop-shadow(0 0 8px currentColor) drop-shadow(0 0 18px currentColor) brightness(1);
  }
  50% {
    filter: drop-shadow(0 0 12px currentColor) drop-shadow(0 0 30px currentColor) drop-shadow(0 0 50px currentColor) brightness(1.5);
  }
}

@keyframes bob {
  from { transform: translateY(-1px) scale(1); }
  to { transform: translateY(2px) scale(1.04); }
}

@keyframes exitPulse {
  from { transform: scale(1); filter: brightness(1); }
  to { transform: scale(1.06); filter: brightness(1.3); }
}

@keyframes hitPulse {
  from { transform: scale(1); }
  to { transform: scale(1.18); }
}

@keyframes sparkle {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}

@keyframes implode {
  0% {
    transform: translate(var(--ix, 30px), var(--iy, 30px)) scale(1.2);
    opacity: 0;
  }
  40% {
    opacity: 1;
  }
  100% {
    transform: translate(0, 0) scale(0.1);
    opacity: 0;
  }
}

@keyframes explode {
  0% {
    transform: translate(0, 0) scale(0.3);
    opacity: 1;
  }
  60% {
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) scale(1.4);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 620px) {
  :root {
    --tile: 38px;
  }

  .hud-card strong {
    font-size: 0.94rem;
  }

  .help-text {
    font-size: 0.9rem;
  }
}

.customizer {
  margin-top: 16px;
  padding: 20px;
  background: linear-gradient(180deg, #274569, #1a2f4a);
  border: 2px solid rgba(206, 227, 255, 0.65);
  border-radius: 16px;
}

.customizer.hidden {
  display: none;
}

.customizer h2 {
  margin: 0 0 4px;
}

.customizer-sub {
  color: var(--muted);
  margin: 0 0 14px;
}

.custom-group {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(183, 214, 255, 0.2);
}

.custom-group:last-of-type {
  border-bottom: none;
}

.custom-group h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: #ffe89a;
}

.custom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.custom-row label {
  width: 50px;
  text-align: right;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.custom-row input[type="color"] {
  width: 40px;
  height: 30px;
  border: 2px solid rgba(183, 214, 255, 0.4);
  border-radius: 6px;
  cursor: pointer;
  background: none;
  padding: 0;
}

.custom-row input[type="range"] {
  flex: 1;
  cursor: pointer;
  accent-color: #67f5a8;
}

.custom-row span {
  width: 28px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 700;
}

.custom-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}
