:root {
  --bg-deep: #0b0f1a;
  --bg-panel: #121a2b;
  --neon-green: #39ff88;
  --neon-green-dim: #1fae5c;
  --neon-pink: #ff4d94;
  --ice: #cfe8ff;
  --muted: #7d8aa8;
  --danger: #ff5c5c;
  --grid-line: rgba(207, 232, 255, 0.06);
  --radius: 16px;
  --font-display: "Press Start 2P", "Courier New", monospace;
  --font-body: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at 50% -10%, #16233d 0%, var(--bg-deep) 60%);
  color: var(--ice);
  font-family: var(--font-body);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 560px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0.75rem) env(safe-area-inset-right, 0.75rem)
    env(safe-area-inset-bottom, 0.75rem) env(safe-area-inset-left, 0.75rem);
  gap: 0.75rem;
}

/* ---------- HUD ---------- */

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-panel);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.title {
  font-family: var(--font-display);
  font-size: clamp(0.85rem, 3vw, 1.1rem);
  color: var(--neon-green);
  text-shadow: 0 0 10px rgba(57, 255, 136, 0.6);
  margin: 0;
  white-space: nowrap;
}

.scoreboard {
  display: flex;
  gap: 1.25rem;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.5rem;
}

.stat-label {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

.stat-value {
  font-family: var(--font-display);
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  color: var(--ice);
}

.icon-btn {
  border: none;
  background: rgba(207, 232, 255, 0.08);
  color: var(--ice);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:hover {
  background: rgba(207, 232, 255, 0.16);
}

.icon-btn:active {
  transform: scale(0.92);
}

/* ---------- Board ---------- */

.board-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.board {
  position: relative;
  width: min(100%, 92vh - 200px, 560px);
  aspect-ratio: 1 / 1;
  background: var(--bg-panel);
  border-radius: var(--radius);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(207, 232, 255, 0.06);
  overflow: hidden;
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 15, 26, 0.86);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.6rem;
  padding: 1.5rem;
}

.overlay[hidden] {
  display: none;
}

.overlay h2 {
  font-family: var(--font-display);
  font-size: clamp(1rem, 4vw, 1.4rem);
  color: var(--neon-green);
  margin: 0 0 0.25rem;
  text-shadow: 0 0 12px rgba(57, 255, 136, 0.5);
}

.overlay p {
  margin: 0;
  max-width: 22rem;
  color: var(--ice);
  font-size: 0.95rem;
}

.overlay .hint {
  color: var(--muted);
  font-size: 0.8rem;
}

.new-record {
  color: gold;
  font-weight: 700;
}

.primary-btn {
  margin-top: 0.75rem;
  border: none;
  background: linear-gradient(135deg, var(--neon-green), var(--neon-green-dim));
  color: #04140b;
  font-weight: 800;
  font-size: 1rem;
  padding: 0.75rem 2rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(57, 255, 136, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary-btn:hover {
  box-shadow: 0 8px 26px rgba(57, 255, 136, 0.5);
}

.primary-btn:active {
  transform: scale(0.96);
}

.primary-btn:focus-visible,
.icon-btn:focus-visible,
.dpad-btn:focus-visible {
  outline: 3px solid var(--neon-pink);
  outline-offset: 2px;
}

/* ---------- Controls (D-pad) ---------- */

.controls {
  display: grid;
  grid-template-columns: repeat(3, 3.2rem);
  grid-template-rows: repeat(2, 3.2rem);
  gap: 0.4rem;
  justify-content: center;
  margin: 0 auto;
}

.dpad-btn {
  border: none;
  border-radius: 14px;
  background: var(--bg-panel);
  color: var(--ice);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(207, 232, 255, 0.08);
  transition: transform 0.1s ease, background 0.1s ease;
}

.dpad-btn:hover {
  background: #17233a;
}

.dpad-btn:active {
  transform: scale(0.9);
  background: rgba(57, 255, 136, 0.25);
}

.dpad-up {
  grid-column: 2;
  grid-row: 1;
}

.dpad-left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-down {
  grid-column: 2;
  grid-row: 2;
}

.dpad-right {
  grid-column: 3;
  grid-row: 2;
}

/* ---------- Footer ---------- */

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.7rem;
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (min-width: 720px) {
  .controls {
    grid-template-columns: repeat(3, 3.6rem);
    grid-template-rows: repeat(2, 3.6rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
