* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(180deg, #1b1b3a 0%, #2f3a6e 45%, #4d7ea8 100%);
  color: #1d1b34;
  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, 246, 224, 0.92);
  color: #2a2350;
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 8px 24px rgba(10, 12, 40, 0.4);
  display: flex;
  gap: 8px;
  align-items: baseline;
  border: 2px solid rgba(230, 160, 60, 0.35);
}
.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; }

.hearts {
  pointer-events: none;
  background: rgba(255, 246, 224, 0.92);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 17px;
  letter-spacing: 2px;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(10, 12, 40, 0.4);
  border: 2px solid rgba(230, 160, 60, 0.35);
}

.powers {
  pointer-events: none;
  display: flex;
  gap: 6px;
}
.power {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 246, 224, 0.92);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 17px;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(10, 12, 40, 0.4);
  border: 2px solid rgba(230, 160, 60, 0.35);
  transition: opacity 160ms ease, transform 160ms ease;
}
.power .power-time {
  font-size: 13px;
  font-weight: 700;
  color: #7a4a12;
}
.power.is-off { opacity: 0.32; transform: scale(0.94); filter: grayscale(0.8); }
.power.is-off .power-time { display: none; }

#controls { pointer-events: auto; display: flex; gap: 8px; align-items: center; }
#restart, #play, #homeBtn, #mute, #music, .home-link {
  cursor: pointer;
  border: none;
  background: linear-gradient(180deg, #ff9f43, #e0632a);
  color: #fff6e0;
  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(120, 40, 10, 0.45);
}
#mute, #music { padding: 10px 12px; }
#music.is-off { opacity: 0.45; filter: grayscale(0.7); }
#restart:hover, #play:hover, #homeBtn:hover, #mute:hover, #music:hover, .home-link:hover { filter: brightness(1.08); }
#restart:active, #play:active, #homeBtn:active, #mute:active, #music:active, .home-link:active { filter: brightness(0.94); }

#stageBar {
  position: absolute;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  padding: 10px 18px;
  border-radius: 16px;
  background: rgba(255, 246, 224, 0.9);
  box-shadow: 0 10px 28px rgba(10, 12, 40, 0.4);
  border: 2px solid rgba(230, 160, 60, 0.35);
  pointer-events: none;
}
#stageBar.hidden { display: none; }
#stageLabel { font-size: 14px; font-weight: 700; color: #2a2350; white-space: nowrap; }
.bar-track {
  display: block;
  width: min(46vw, 320px);
  height: 12px;
  border-radius: 999px;
  background: rgba(42, 35, 80, 0.18);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd166, #ff9f43);
  transition: width 120ms linear;
}
#stageBar.is-boss .bar-fill { background: linear-gradient(90deg, #ff5d5d, #a4133c); }
#stageBar.is-boss { animation: bossPulse 900ms ease-in-out infinite; }
@keyframes bossPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.02); }
}

#toast {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 246, 224, 0.95);
  color: #2a2350;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 10px 28px rgba(10, 12, 40, 0.4);
  pointer-events: none;
  transition: opacity 180ms ease;
}
#toast.hidden { opacity: 0; }

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(14, 14, 40, 0.6);
  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: #fff6e0;
  color: #2a2350;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 24px 70px rgba(8, 10, 34, 0.55);
  border: 3px solid rgba(230, 160, 60, 0.45);
}
#overlay h1 { margin: 0 0 8px; font-size: 32px; color: #b5451b; }
#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) {
  .score-item { padding: 6px 10px; }
  .score-item span:last-child { font-size: 17px; }
  .power { padding: 6px 9px; font-size: 15px; }
  .hearts { font-size: 15px; padding: 6px 10px; }
  #stageBar { top: auto; bottom: 76px; padding: 8px 14px; }
  .bar-track { width: min(64vw, 260px); }
  #toast { bottom: 18px; font-size: 14px; }
  #restart, #play, #homeBtn, #mute, #music, .home-link { padding: 9px 12px; font-size: 14px; }
  #overlay h1 { font-size: 26px; }
}
