@font-face {
  font-family: "Boogaloo";
  src: local("Boogaloo");
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  height: 100%;
  background: #7a0d10;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  touch-action: none;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

canvas#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* HUD */
#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 14px;
  padding: 10px 16px;
  color: white;
  z-index: 5;
}

#hud-score-label {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.8;
  letter-spacing: 1px;
}

#hud-score {
  font-size: 26px;
  font-weight: 800;
}

#hud-combo {
  font-size: 12px;
  color: #ffd54a;
  font-weight: 700;
}

#hud-lives {
  font-size: 22px;
  letter-spacing: 4px;
}

#swarm-warning {
  position: absolute;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  background: #ff7a00;
  color: white;
  font-weight: 800;
  font-size: 20px;
  white-space: nowrap;
  padding: 8px 18px;
  border-radius: 999px;
  z-index: 6;
  animation: swarm-flash 0.4s ease-in-out infinite alternate;
}

@keyframes swarm-flash {
  from { background: #ff7a00; }
  to { background: #e21b1b; }
}

#wave-banner {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(30, 100, 220, 0.85);
  color: white;
  font-size: 34px;
  font-weight: 800;
  padding: 14px 28px;
  border-radius: 999px;
  z-index: 7;
  box-shadow: 0 8px 20px rgba(0,0,0,0.5);
  animation: wave-pop 0.35s ease-out;
}

@keyframes wave-pop {
  from { transform: translate(-50%, -50%) scale(0.7); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

#menu-high-score {
  font-size: 15px;
  font-weight: 800;
  color: #ffd54a;
  background: rgba(0,0,0,0.35);
  padding: 6px 14px;
  border-radius: 999px;
}

#new-high-score {
  font-size: 14px;
  font-weight: 800;
  color: #ffd54a;
}

#final-best {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  font-weight: 600;
  margin-top: -8px;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-over {
  background: rgba(0, 0, 0, 0.75);
}

#menu {
  overflow: hidden;
}

#menu-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 20px;
  text-align: center;
  position: relative;
  z-index: 2;
}

#title {
  margin: 0;
  display: flex;
  flex-direction: column;
  color: #4dd92e;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.6);
  font-family: "Boogaloo", "Marker Felt", "Chalkboard SE", "Comic Sans MS", cursive;
  line-height: 1.05;
  transform: rotate(-4deg);
}

#title span:first-child { font-size: clamp(34px, 9.5vw, 48px); font-weight: 700; }
#title span:last-child { font-size: clamp(40px, 12vw, 62px); font-weight: 700; }

#instructions {
  list-style: none;
  margin: 0;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  color: white;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

#start-btn {
  font-size: 22px;
  font-weight: 800;
  color: white;
  border: none;
  padding: 14px 54px;
  border-radius: 999px;
  background: conic-gradient(from 0deg, #ef3b3b, #ff9d2f, #f3e34d, #4dd92e, #2f8fff, #a13bff, #ef3b3b);
  background-size: 200% 200%;
  animation: rainbow-spin 1.6s linear infinite, rainbow-pulse 1.6s ease-in-out infinite;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
}

@keyframes rainbow-spin {
  from { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(360deg); }
}

@keyframes rainbow-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

#mute-row {
  display: flex;
  gap: 18px;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.35);
  color: white;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.off {
  opacity: 0.5;
}

#game-over-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: white;
}

#game-over-content h2 {
  font-size: 30px;
  margin: 0;
}

#final-score-label {
  opacity: 0.7;
}

#final-score {
  font-size: 44px;
  font-weight: 800;
  color: #ffd54a;
}

#restart-btn, #menu-btn {
  font-size: 16px;
  font-weight: 700;
  color: white;
  border: none;
  padding: 14px;
  width: 220px;
  border-radius: 14px;
}

#restart-btn { background: #ef3b3b; }
#menu-btn { background: rgba(255,255,255,0.15); }

.splat {
  position: absolute;
  background: radial-gradient(circle at 30% 30%, rgba(120, 60, 20, 0.6), rgba(90, 40, 15, 0.5));
  border-radius: 42% 58% 63% 37% / 41% 44% 56% 59%;
}

.splat-tl-a { width: 70px; height: 70px; top: 90px; left: -10px; }
.splat-tl-b { width: 34px; height: 34px; top: 150px; left: 60px; opacity: 0.7; }
.splat-br-a { width: 54px; height: 54px; bottom: 60px; right: 0px; }
.splat-br-b { width: 26px; height: 26px; bottom: 130px; right: 60px; opacity: 0.7; }

#ambient-bugs {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.ambient-bug {
  position: absolute;
  font-size: 24px;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.ambient-bug.visible {
  opacity: 1;
}
