@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&display=swap');

:root {
  --bg: #0d1117;
  --panel: rgba(22, 27, 34, 0.72);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3fb950;
  --accent-soft: #2ea04326;
  --food: #f85149;
  --radius: 14px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  display: grid;
  place-items: center;
  padding: clamp(0.75rem, 3vw, 2rem);
  background:
    radial-gradient(900px 500px at 50% -5%, #1d2b3a 0%, transparent 65%),
    radial-gradient(700px 400px at 85% 100%, #16281c 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.shell {
  width: min(94vmin, 42rem);
  display: flex;
  flex-direction: column;
  gap: clamp(0.6rem, 2vw, 1rem);
}

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

.hud {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}

.title {
  font-size: clamp(1rem, 3.4vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: clamp(0.75rem, 3vw, 1.5rem);
  margin-left: auto;
}

.stat {
  text-align: right;
}

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

.stat dd {
  font-size: clamp(1rem, 3.2vw, 1.25rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.mute {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  font-size: 1rem;
  color: inherit;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.mute:hover,
.mute:focus-visible {
  background: var(--accent-soft);
  border-color: var(--accent);
}

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

.stage {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 18), 1fr);
  grid-template-rows: repeat(var(--rows, 18), 1fr);
  gap: 1px;
  aspect-ratio: 1;
  width: 100%;
  padding: 6px;
  background: rgba(1, 4, 9, 0.66);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.55);
  touch-action: none; /* let swipes drive the snake, not scroll the page */
}

.cell {
  border-radius: 2px;
}

.snake {
  background: var(--accent);
  border-radius: 3px;
}

.head {
  background: #56d364;
  border-radius: 4px;
  box-shadow: 0 0 8px rgba(63, 185, 80, 0.8);
}

.food {
  background: var(--food);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(248, 81, 73, 0.75);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(0.78);
  }
}

/* --- Overlay ------------------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.5rem;
  text-align: center;
  background: rgba(13, 17, 23, 0.86);
  border-radius: var(--radius);
  backdrop-filter: blur(4px);
}

.overlay[hidden] {
  display: none;
}

.overlay h2 {
  font-size: clamp(1.4rem, 5vw, 2rem);
  letter-spacing: -0.02em;
}

.overlay p {
  max-width: 24rem;
  color: var(--muted);
  line-height: 1.5;
}

.btn {
  margin-top: 0.25rem;
  padding: 0.6rem 1.6rem;
  font: inherit;
  font-weight: 700;
  color: #04150a;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:hover,
.btn:focus-visible {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* --- Legend -------------------------------------------------------------- */

.legend {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.8;
}

kbd {
  display: inline-block;
  min-width: 1.5rem;
  padding: 0.1rem 0.35rem;
  font: inherit;
  font-size: 0.75rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
}

@media (prefers-reduced-motion: reduce) {
  .food {
    animation: none;
  }
  .btn {
    transition: none;
  }
}
