* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; overscroll-behavior: none;
  background: #0a4d68;
  font-family: 'Baloo 2', 'Comic Sans MS', 'Trebuchet MS', system-ui, sans-serif;
  touch-action: none;
  user-select: none;
}

#stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #06344a;
}

#game {
  display: block;
  background: #7fd8e8;
  touch-action: none;
  border-radius: 0;
  box-shadow: 0 0 40px rgba(0,0,0,0.35);
}

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px 18px;
  pointer-events: none;
  z-index: 5;
}
#hearts { display: flex; gap: 6px; }
#hearts .heart {
  font-size: clamp(20px, 4vw, 30px);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35));
}
#hearts .heart.lost { opacity: 0.25; filter: none; }

#scoreWrap { text-align: right; color: #fff; }
#score {
  font-size: clamp(26px, 6vw, 40px);
  font-weight: 800;
  text-shadow: 0 3px 0 rgba(0,0,0,0.25);
  line-height: 1;
}
#level {
  font-size: clamp(13px, 2.6vw, 17px);
  font-weight: 700;
  background: rgba(0,0,0,0.28);
  border-radius: 999px;
  padding: 3px 12px;
  margin-top: 4px;
  display: inline-block;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10,60,80,0.55), rgba(4,30,45,0.85));
  z-index: 20;
  transition: opacity 0.25s ease;
}
.overlay.hidden { display: none; }

.panel {
  background: linear-gradient(180deg, #ffffff, #eafcff);
  border-radius: 28px;
  padding: clamp(20px, 4vw, 36px) clamp(24px, 5vw, 48px);
  text-align: center;
  max-width: 90vw;
  box-shadow: 0 12px 0 rgba(0,0,0,0.15), 0 20px 40px rgba(0,0,0,0.35);
  border: 5px solid #ff9ecf;
}
.panel h1 {
  margin: 0 0 6px;
  font-size: clamp(28px, 6vw, 44px);
  color: #0f8bb5;
  text-shadow: 2px 3px 0 #ffe38a;
}
.subtitle {
  margin: 4px 0 14px;
  color: #16607e;
  font-size: clamp(14px, 3vw, 18px);
  font-weight: 700;
}
.howto {
  background: #eafcff;
  border: 3px dashed #7fd8e8;
  border-radius: 16px;
  padding: 10px 16px;
  margin-bottom: 18px;
  color: #0f5570;
  font-weight: 700;
  font-size: clamp(13px, 2.8vw, 16px);
  display: flex; flex-direction: column; gap: 6px;
}
.howto .key {
  display: inline-block;
  background: #0f8bb5;
  color: #fff;
  border-radius: 8px;
  padding: 2px 8px;
  margin-right: 6px;
  font-size: 0.9em;
}

.bigBtn {
  font-family: inherit;
  font-size: clamp(18px, 4vw, 26px);
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #ffb347, #ff8a3d);
  border: none;
  border-radius: 999px;
  padding: 14px 38px;
  box-shadow: 0 6px 0 #d9631b;
  cursor: pointer;
  touch-action: manipulation;
}
.bigBtn:active { transform: translateY(4px); box-shadow: 0 2px 0 #d9631b; }

/* ---------- Touch controls ---------- */
#controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 14px clamp(10px, 3vw, 26px) calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  pointer-events: none;
}
#dpad, .jumpBtn { pointer-events: auto; }

#dpad {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.dpadRow { display: flex; gap: 6px; }

.ctrlBtn {
  width: clamp(52px, 12vw, 68px);
  height: clamp(52px, 12vw, 68px);
  border-radius: 16px;
  border: none;
  background: rgba(255,255,255,0.85);
  color: #0f5570;
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 900;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25);
  touch-action: none;
}
.ctrlBtn:active, .ctrlBtn.pressed {
  background: #ffe38a;
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.25);
}

.jumpBtn {
  width: clamp(84px, 20vw, 110px);
  height: clamp(84px, 20vw, 110px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff9ecf, #ef5da8);
  color: #fff;
  font-size: clamp(14px, 3.2vw, 18px);
  font-weight: 900;
  box-shadow: 0 6px 0 #c53d84;
  letter-spacing: 1px;
}
.jumpBtn:active, .jumpBtn.pressed {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #c53d84;
}

#controls.playHidden, #hud.playHidden { display: none; }

@media (orientation: portrait) and (max-height: 480px) {
  .panel { padding: 14px 18px; }
}
