:root {
  --bg-top: #8ad0ff;
  --bg-bottom: #fef8d8;
  --ink: #0f2142;
  --panel: rgba(255, 255, 255, 0.84);
  --accent: #ff7a29;
  --danger: #ef2d56;
  --good: #17b978;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 20% 20%, var(--bg-top), var(--bg-bottom));
  font-family: "Chakra Petch", sans-serif;
  color: var(--ink);
}

#game-root {
  width: 100%;
  height: 100%;
}

canvas {
  display: block;
}

#hud {
  position: fixed;
  top: 14px;
  left: 14px;
  width: min(420px, calc(100% - 28px));
  max-height: min(62vh, 520px);
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(4px);
  border: 2px solid rgba(15, 33, 66, 0.14);
  box-shadow: 0 12px 35px rgba(15, 33, 66, 0.2);
  overflow: auto;
  z-index: 10;
}

#hud .label {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  color: rgba(15, 33, 66, 0.78);
}

#hud h1 {
  margin: 4px 0 8px;
  line-height: 1;
  letter-spacing: 0.03em;
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-family: "Luckiest Guy", cursive;
  color: var(--accent);
  text-shadow: 2px 2px 0 #fff;
}

#hud p {
  margin: 7px 0;
  font-size: clamp(0.95rem, 2.7vw, 1.02rem);
  font-weight: 600;
  line-height: 1.2;
}

#touch-toggle {
  border: 0;
  border-radius: 999px;
  margin: 4px 0 2px;
  padding: 8px 14px;
  background: linear-gradient(135deg, #6bd4ff, #4d96ff);
  color: #06214a;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 700;
  cursor: pointer;
}

#hud-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  border-radius: 999px;
  padding: 6px 11px;
  background: rgba(15, 33, 66, 0.12);
  color: #0f2142;
  font-family: "Chakra Petch", sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

body.hud-collapsed #hud {
  width: fit-content;
  max-width: calc(100% - 16px);
  max-height: none;
  padding: 10px 70px 10px 12px;
}

body.hud-collapsed #hud h1,
body.hud-collapsed #objective,
body.hud-collapsed #count,
body.hud-collapsed #controls,
body.hud-collapsed #touch-toggle,
body.hud-collapsed #prompt {
  display: none;
}

body.hud-collapsed #hud .label {
  margin: 0;
  font-size: 0.82rem;
}

#count {
  color: var(--good);
}

#prompt {
  min-height: 20px;
  color: #193463;
}

#bang-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: "Luckiest Guy", cursive;
  font-size: clamp(3.2rem, 12vw, 8rem);
  color: #fff;
  background: rgba(239, 45, 86, 0.8);
  letter-spacing: 0.14em;
  text-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  z-index: 15;
  animation: pulse 0.26s infinite alternate;
}

.hidden {
  display: none !important;
}

#video-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at center, rgba(15, 33, 66, 0.9), rgba(3, 7, 15, 0.96));
  z-index: 20;
  padding: 18px;
}

.video-shell {
  width: min(900px, 100%);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  padding: 14px;
  text-align: center;
  color: #eff4ff;
}

.video-shell h2 {
  margin: 2px 0 10px;
  font-family: "Luckiest Guy", cursive;
  font-size: clamp(1.7rem, 6vw, 2.6rem);
  letter-spacing: 0.05em;
}

#ending-video {
  width: 100%;
  max-height: 60vh;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: #000;
}

#video-note {
  min-height: 22px;
  margin: 8px 0;
  color: #d8e5ff;
}

#restart-btn {
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffb703, #ff7a29);
  color: #0f2142;
  font-weight: 700;
  font-family: "Chakra Petch", sans-serif;
  font-size: 1rem;
  padding: 10px 22px;
  cursor: pointer;
}

#mobile-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 14px;
  z-index: 11;
  pointer-events: none;
}

body.touch-controls-visible #mobile-controls {
  display: flex;
}

body.touch-controls-hidden #mobile-controls {
  display: none !important;
}

#mobile-controls .cluster {
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

#mobile-controls .movement {
  justify-content: flex-end;
}

#move-joystick {
  position: relative;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 30%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.02) 70%),
    rgba(10, 24, 48, 0.36);
  border: 2px solid rgba(255, 255, 255, 0.42);
  box-shadow: inset 0 0 24px rgba(255, 255, 255, 0.18), 0 8px 20px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(2px);
  touch-action: none;
}

#move-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin-left: -25px;
  margin-top: -25px;
  border-radius: 50%;
  background: linear-gradient(150deg, #fff, #a2d9ff);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  border: 2px solid rgba(255, 255, 255, 0.8);
  pointer-events: none;
}

#mobile-controls .actions {
  align-items: flex-end;
}

#mobile-controls button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  font-weight: 700;
  font-size: 1rem;
  color: #0f2142;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.26);
  touch-action: manipulation;
}

#action-btn {
  width: 78px !important;
  height: 78px !important;
  font-size: 1.3rem !important;
  background: linear-gradient(135deg, #17b978, #5fe0a9) !important;
}

@keyframes pulse {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.74;
  }
}

@media (hover: none), (pointer: coarse) {
  #mobile-controls {
    display: flex;
  }

  #hud {
    width: min(390px, calc(100% - 16px));
    max-height: min(54vh, 360px);
    left: 8px;
    top: 8px;
    padding: 10px 12px;
  }

  body.hud-collapsed #hud {
    width: fit-content;
    max-height: none;
    padding: 8px 62px 8px 10px;
  }

  #hud h1 {
    font-size: clamp(1.45rem, 7.2vw, 2rem);
  }

  #hud p {
    font-size: clamp(0.88rem, 3.8vw, 0.98rem);
    margin: 6px 0;
  }

  #touch-toggle {
    padding: 7px 12px;
    font-size: 0.9rem;
  }

  #hud-toggle {
    top: 8px;
    right: 8px;
    font-size: 0.76rem;
    padding: 6px 10px;
  }

  #move-joystick {
    width: 118px;
    height: 118px;
  }

  #move-knob {
    width: 46px;
    height: 46px;
    margin-left: -23px;
    margin-top: -23px;
  }

  #mobile-controls button {
    width: 56px;
    height: 56px;
  }

  #action-btn {
    width: 72px !important;
    height: 72px !important;
    font-size: 1.15rem !important;
  }
}
