* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(180deg, #2b1b46 0%, #4a2f6d 60%, #6b3f7a 100%);
  color: #3a2b5a;
  font-family: 'Fredoka', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
  touch-action: none;
  cursor: crosshair;
}

#ui {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  pointer-events: none;
  z-index: 2;
}

#scoreboard {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.score-item {
  pointer-events: auto;
  background: rgba(255,255,255,0.86);
  color: #3a2b5a;
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 8px 24px rgba(20, 5, 40, 0.35);
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.score-item .label { opacity: 0.7; font-size: 13px; }
.score-item span:last-child { font-weight: 700; font-size: 20px; }

#meters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.meter {
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.86);
  border-radius: 999px;
  padding: 7px 14px 7px 10px;
  box-shadow: 0 8px 24px rgba(20, 5, 40, 0.35);
}
.meter-icon { font-size: 18px; line-height: 1; }
.meter-track {
  display: block;
  width: 132px;
  height: 12px;
  border-radius: 999px;
  background: rgba(58, 43, 90, 0.16);
  overflow: hidden;
}
.meter-fill {
  display: block;
  height: 100%;
  width: 80%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffb347, #ff6b3d);
  transition: width 120ms linear;
}
.meter.is-low .meter-fill { background: linear-gradient(90deg, #8f7fd6, #5f4bb0); }
.meter.is-low { animation: meterPanic 620ms ease-in-out infinite; }
@keyframes meterPanic {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.hearts {
  pointer-events: none;
  background: rgba(255,255,255,0.86);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 17px;
  letter-spacing: 2px;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(20, 5, 40, 0.35);
}

#controls { pointer-events: auto; display: flex; gap: 8px; align-items: center; }
#restart, #play, #homeBtn, #mute, .home-link {
  cursor: pointer;
  border: none;
  background: linear-gradient(180deg, #a97bff, #7b4fe0);
  color: white;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 15px;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  box-shadow: 0 8px 24px rgba(60, 20, 120, 0.4);
}
#mute { padding: 10px 12px; }
#restart:hover, #play:hover, #homeBtn:hover, #mute:hover, .home-link:hover { filter: brightness(1.08); }
#restart:active, #play:active, #homeBtn:active, #mute:active, .home-link:active { filter: brightness(0.94); }

#burnAlert {
  position: absolute;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff7a5c, #e03c2f);
  color: #fff;
  font-weight: 700;
  font-size: 19px;
  white-space: nowrap;
  box-shadow: 0 12px 34px rgba(220, 50, 30, 0.5);
  animation: burnPulse 520ms ease-in-out infinite;
  pointer-events: none;
}
#burnAlert.hidden { display: none; }
.burn-emoji { font-size: 22px; }
@keyframes burnPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.06); }
}

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(26, 8, 44, 0.55);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 4;
  padding: 16px;
}
#overlay.show { opacity: 1; pointer-events: auto; }
#overlay .panel {
  background: white;
  color: #3a2b5a;
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 24px 70px rgba(20, 5, 50, 0.5);
}
#overlay h1 { margin: 0 0 8px; font-size: 30px; }
#overlay p { opacity: 0.88; line-height: 1.45; margin: 0 0 10px; }
#overlay .hint { font-size: 14px; opacity: 0.72; margin-bottom: 16px; }
#overlay .legend {
  display: grid;
  gap: 6px;
  margin: 12px 0 16px;
  font-size: 15px;
}
#overlay .legend.hidden { display: none; }
#overlay .legend span { opacity: 0.92; }
.overlay-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

@media (max-width: 560px) {
  #ui { gap: 6px; top: 8px; left: 8px; right: 8px; }
  #meters { gap: 6px; }
  .meter { padding: 5px 10px 5px 8px; gap: 6px; }
  .meter-track { width: 62px; height: 10px; }
  .meter-icon { font-size: 15px; }
  .hearts { padding: 5px 9px; font-size: 14px; letter-spacing: 1px; }
  .score-item { padding: 5px 9px; gap: 5px; }
  .score-item .label { font-size: 11px; }
  .score-item span:last-child { font-size: 15px; }
  #burnAlert { font-size: 15px; padding: 9px 14px; }
  #controls { gap: 6px; }
  #restart, #play, #homeBtn, #mute, .home-link { padding: 8px 11px; font-size: 13px; border-radius: 10px; }
  #overlay .panel { padding: 18px; }
  #overlay h1 { font-size: 24px; }
  #overlay .legend { font-size: 13.5px; }
}
