:root {
  --yellow: #ffd93b;
  --yellow-dark: #d9a800;
  --blue: #1e8fd5;
  --blue-deep: #0f5f9c;
  --pink: #ff7ad9;
  --green: #6ccf3f;
  --ink: #1c2a3a;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --font: "Arial Rounded MT Bold", "Helvetica Rounded", ui-rounded, "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background: var(--blue);
  color: #fff;
  font-family: var(--font);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#touch-layer {
  position: fixed;
  inset: 0;
  touch-action: none;
  z-index: 2;
}

/* HUD */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.hud-top {
  position: absolute;
  top: calc(var(--sat) + 8px);
  left: calc(var(--sal) + 10px);
  right: calc(var(--sar) + 10px);
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.hud-pill {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 14px;
  background: rgba(10, 40, 70, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  min-width: 72px;
  line-height: 1.1;
}

.hud-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.8;
}

.hud-value {
  font-size: clamp(18px, 4.5vw, 24px);
  font-weight: 800;
  color: var(--yellow);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}

.hud-dim { opacity: 0.55; font-size: 0.7em; }
.hud-sub { font-size: 11px; opacity: 0.85; }
.hud-wave { margin-right: auto; }

.hud-hearts {
  flex-direction: row;
  gap: 4px;
  align-items: center;
  padding: 6px 10px;
}

.heart {
  width: 22px;
  height: 22px;
  display: inline-block;
  background: #ff4d6d;
  clip-path: path("M11 20 L2.5 11.5 A5 5 0 0 1 11 5 A5 5 0 0 1 19.5 11.5 Z");
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35));
  transition: transform 0.2s, opacity 0.2s;
}

.heart.lost {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0.8);
}

.hud-btn {
  pointer-events: auto;
  width: 44px;
  border-radius: 14px;
  background: rgba(10, 40, 70, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: none;
}

.hud-btn:active { background: rgba(255, 255, 255, 0.25); }

.icon-pause {
  width: 14px;
  height: 16px;
  background:
    linear-gradient(#fff, #fff) left / 5px 100% no-repeat,
    linear-gradient(#fff, #fff) right / 5px 100% no-repeat;
}

/* Crosshair: a tiny yellow sponge with pores */
#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 5px;
  background: var(--yellow);
  border: 2px solid var(--ink);
  pointer-events: none;
  z-index: 4;
  opacity: 0.9;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--yellow-dark);
}

#crosshair::before { left: 3px; top: 4px; }
#crosshair::after { right: 4px; bottom: 3px; }

/* Joystick */
#joystick {
  position: fixed;
  width: 130px;
  height: 130px;
  margin: -65px 0 0 -65px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 3px solid rgba(255, 255, 255, 0.45);
  pointer-events: none;
  z-index: 4;
}

#joystick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 14px;
  background: var(--yellow);
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  transform: translate(var(--kx, 0px), var(--ky, 0px));
}

/* Fire button */
#fire-btn {
  position: fixed;
  right: calc(var(--sar) + 22px);
  bottom: calc(var(--sab) + 26px);
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: 4px solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #fff3a8, var(--yellow) 55%, #f0b400);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.08em;
  display: grid;
  place-items: center;
  gap: 2px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.35), 0 0 0 6px rgba(255, 255, 255, 0.18);
  z-index: 6;
  touch-action: none;
  cursor: pointer;
  transition: transform 0.08s;
}

#fire-btn:active,
#fire-btn.pressed {
  transform: translateY(5px) scale(0.97);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 0 0 6px rgba(255, 255, 255, 0.3);
}

.fire-bubble {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--blue-deep);
  background: radial-gradient(circle at 30% 30%, #fff, #a9e4ff 60%, #5cc5ff);
}

/* Damage flash */
#damage-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(255, 60, 60, 0) 40%, rgba(255, 40, 40, 0.75) 100%);
  transition: opacity 0.35s ease-out;
}

#damage-flash.on { opacity: 1; transition: opacity 0.05s; }

/* Wave banner */
#banner {
  position: fixed;
  left: 0;
  right: 0;
  top: 28%;
  text-align: center;
  pointer-events: none;
  z-index: 5;
  padding: 0 16px;
  animation: banner-in 2.4s ease-out forwards;
}

.banner-title {
  font-size: clamp(34px, 9vw, 64px);
  font-weight: 900;
  color: var(--yellow);
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 5px 0 var(--ink), 0 8px 18px rgba(0, 0, 0, 0.35);
  letter-spacing: 0.02em;
}

.banner-sub {
  margin-top: 6px;
  font-size: clamp(15px, 3.5vw, 22px);
  font-weight: 700;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

@keyframes banner-in {
  0% { opacity: 0; transform: translateY(20px) scale(0.85); }
  12% { opacity: 1; transform: translateY(0) scale(1.03); }
  20% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* Screens */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px);
  background: radial-gradient(ellipse at top, rgba(30, 143, 213, 0.55), rgba(8, 40, 80, 0.85));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.card {
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  overflow: auto;
  background: rgba(12, 50, 90, 0.82);
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-radius: 26px;
  padding: 22px 22px 18px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.card-small { max-width: 360px; }

.card h2 {
  margin: 0 0 6px;
  font-size: 36px;
  color: var(--yellow);
  -webkit-text-stroke: 1.5px var(--ink);
  text-shadow: 0 4px 0 var(--ink);
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.95;
  margin-bottom: 12px;
}

.logo-sponge {
  font-size: clamp(40px, 12vw, 58px);
  font-weight: 900;
  color: var(--yellow);
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 5px 0 var(--ink), 0 8px 0 rgba(0, 0, 0, 0.25);
  letter-spacing: 0.02em;
  transform: rotate(-3deg);
}

.logo-shot {
  font-size: clamp(44px, 14vw, 68px);
  font-weight: 900;
  color: #8fe3ff;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 5px 0 var(--ink), 0 8px 0 rgba(0, 0, 0, 0.25);
  transform: rotate(2deg);
}

.tagline {
  margin: 0 0 16px;
  font-size: 15px;
  line-height: 1.4;
  opacity: 0.95;
}

.muted { opacity: 0.85; margin: 0 0 14px; }

.btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 14px 18px;
  border-radius: 16px;
  border: 3px solid var(--ink);
  font-family: var(--font);
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s;
}

.btn:active { transform: translateY(3px); }

.btn-primary {
  background: linear-gradient(#fff3a8, var(--yellow) 60%, #f0b400);
  color: var(--ink);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: progress;
  filter: saturate(0.6);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
  font-size: 16px;
  padding: 11px 16px;
}

.error {
  color: #ffb3b3;
  font-weight: 700;
  margin: 8px 0;
}

.controls-help {
  list-style: none;
  padding: 0;
  margin: 12px 0 6px;
  font-size: 14px;
  line-height: 1.6;
  text-align: left;
  opacity: 0.95;
}

.controls-help b { color: var(--yellow); }

.hint {
  font-size: 13px;
  margin: 8px 0 0;
  padding: 8px 10px;
  background: rgba(255, 217, 59, 0.15);
  border: 1.5px dashed rgba(255, 217, 59, 0.5);
  border-radius: 10px;
}

.bestiary {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  text-align: left;
  font-size: 12.5px;
  line-height: 1.3;
}

.beast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}

.beast b { color: var(--yellow); }

.beast-icon {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  position: relative;
}

.beast-icon::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  box-shadow: inset -2px -1px 0 3px var(--ink);
}

.beast-icon.glooper { background: var(--green); }
.beast-icon.grump { background: #3f9e2a; }
.beast-icon.jelly {
  background: var(--pink);
  border-radius: 50% 50% 30% 30%;
}

.beast-icon.jelly::after {
  width: 5px;
  height: 5px;
  background: var(--ink);
  border: 0;
  box-shadow: 9px 0 0 var(--ink);
  left: 35%;
  top: 45%;
}

.score-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0 14px;
}

.big-score {
  font-size: 44px;
  font-weight: 900;
  color: var(--yellow);
  -webkit-text-stroke: 1.5px var(--ink);
  text-shadow: 0 4px 0 var(--ink);
}

/* Short landscape phones: tighten the menu card */
@media (max-height: 460px) {
  .card { padding: 12px 16px; }
  .logo { flex-direction: row; gap: 10px; margin-bottom: 6px; }
  .tagline { margin-bottom: 8px; font-size: 13px; }
  .bestiary { display: none; }
  .controls-help { margin: 6px 0; font-size: 12px; line-height: 1.4; }
  .btn { padding: 10px 16px; font-size: 18px; margin: 6px 0; }
  #fire-btn { width: 86px; height: 86px; font-size: 16px; }
}
