:root {
  --bg-1: #20104a;
  --bg-2: #4821a7;
  --bg-3: #8e53ff;
  --panel: rgba(20, 12, 52, 0.78);
  --panel-strong: rgba(25, 14, 58, 0.92);
  --text: #fff9ff;
  --muted: #d8ccff;
  --gold: #ffd45d;
  --xp: #71f7ff;
  --glim: #ff8df4;
  --danger: #ff596e;
  --success: #78ffb7;
  --shadow: 0 24px 80px rgba(6, 2, 24, 0.48);
  --radius: 28px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 12%, rgba(255, 141, 244, 0.35), transparent 28%),
    radial-gradient(circle at 78% 18%, rgba(113, 247, 255, 0.22), transparent 26%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2) 54%, var(--bg-3));
  color: var(--text);
  font-family: Inter, ui-rounded, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
}

.game-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.game-card {
  width: min(100%, 1100px);
  display: grid;
  gap: 12px;
}

.hud,
.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.controls {
  grid-template-columns: 0.9fr 1.4fr;
}

.hud-pill,
.control-button,
.overlay-card {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.hud-pill {
  min-height: 58px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 8px 10px;
}

.hud-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hud-pill strong {
  margin-top: 1px;
  font-size: clamp(18px, 3.8vw, 30px);
  line-height: 1;
  font-weight: 950;
  text-shadow: 0 3px 16px rgba(255, 255, 255, 0.16);
}

.timer-pill strong {
  color: var(--gold);
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 280px;
  max-height: calc(100vh - 168px);
  border-radius: var(--radius);
  background: #120a34;
  box-shadow: var(--shadow);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at center, rgba(72, 33, 167, 0.12), rgba(7, 3, 29, 0.58)),
    rgba(7, 3, 29, 0.18);
  transition: opacity 160ms ease, visibility 160ms ease;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-card {
  width: min(92%, 560px);
  border-radius: 30px;
  padding: clamp(20px, 5vw, 36px);
  text-align: center;
  background: var(--panel-strong);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--xp);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 8vw, 64px);
  line-height: 0.95;
  letter-spacing: -0.06em;
}

#overlayText {
  margin: 14px auto 0;
  max-width: 45ch;
  color: var(--muted);
  font-size: clamp(14px, 2.4vw, 17px);
  line-height: 1.55;
}

.legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px auto 0;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 16px currentColor;
}

.dot.gold { color: var(--gold); background: var(--gold); }
.dot.xp { color: var(--xp); background: var(--xp); }
.dot.glim { color: var(--glim); background: var(--glim); }
.dot.bomb { color: var(--danger); background: var(--danger); }

.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 24px;
}

.primary-button,
.ghost-button,
.control-button {
  border: 0;
  border-radius: 999px;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

.primary-button,
.ghost-button {
  min-width: 146px;
  min-height: 48px;
  padding: 0 18px;
}

.primary-button {
  background: linear-gradient(135deg, #ffdf72, #ff8df4 52%, #71f7ff);
  color: #1c0b34;
  box-shadow: 0 14px 34px rgba(255, 141, 244, 0.24);
}

.ghost-button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
}

.control-button {
  min-height: 54px;
  background: var(--panel);
  padding: 8px 16px;
}

.control-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.control-button.slow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background:
    linear-gradient(90deg, rgba(113, 247, 255, 0.18), rgba(255, 141, 244, 0.16)),
    var(--panel);
}

.control-button.slow.ready {
  animation: glowPulse 1s ease-in-out infinite alternate;
}

.control-button small {
  color: var(--xp);
  font-weight: 950;
}

@keyframes glowPulse {
  from { box-shadow: 0 10px 40px rgba(113, 247, 255, 0.16); }
  to { box-shadow: 0 10px 54px rgba(255, 141, 244, 0.42); }
}

@media (max-width: 700px) {
  .game-shell {
    padding: 8px;
  }

  .hud {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .hud-pill {
    min-height: 46px;
    border-radius: 15px;
  }

  .hud-label {
    font-size: 9px;
  }

  .canvas-wrap {
    max-height: calc(100vh - 168px);
    border-radius: 20px;
  }

  .controls {
    grid-template-columns: 0.85fr 1.15fr;
    gap: 8px;
  }

  .control-button {
    min-height: 48px;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .game-shell {
    padding: 6px;
  }

  .game-card {
    grid-template-columns: 128px 1fr 138px;
    align-items: stretch;
    gap: 8px;
  }

  .hud,
  .controls {
    grid-template-columns: 1fr;
  }

  .canvas-wrap {
    max-height: calc(100vh - 12px);
  }

  .hud-pill,
  .control-button {
    min-height: auto;
  }
}
