:root {
  --bg: #f4f1ea;
  --fg: #1f2421;
  --muted: #5d655f;
  --board: #e6e0d2;
  --grid: #ded7c7;
  --snake: #3d8a61;
  --head: #2a6446;
  --food: #c8553d;
  --bonus: #d9a21b;
  --veil: rgb(244 241 234 / 0.82);
  --button: #e3ddd0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --fg: #e8e6e1;
    --muted: #9aa39c;
    --board: #212621;
    --grid: #1c201c;
    --snake: #5fb383;
    --head: #86d3a6;
    --food: #e8765e;
    --bonus: #f2c14e;
    --veil: rgb(21 24 22 / 0.82);
    --button: #2a302b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, sans-serif;
}

main {
  width: min(440px, 100vw - 32px);
  padding: 16px 0;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

h1 { margin: 0; font-size: 1.5rem; }

.home {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}
.home:hover, .home:focus-visible { color: var(--fg); }

.scores { display: flex; gap: 16px; margin: 0; font-variant-numeric: tabular-nums; }

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  touch-action: none;
  user-select: none;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

button {
  font: inherit;
  color: var(--fg);
  background: var(--button);
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { opacity: 0.5; cursor: default; }

.dpad {
  display: none;
  grid-template: repeat(3, 52px) / repeat(3, 52px);
  gap: 4px;
}

.dpad button { padding: 0; font-size: 1.1rem; }
.dpad [data-dir="up"] { grid-area: 1 / 2; }
.dpad [data-dir="left"] { grid-area: 2 / 1; }
.dpad [data-dir="right"] { grid-area: 2 / 3; }
.dpad [data-dir="down"] { grid-area: 3 / 2; }

.help { color: var(--muted); font-size: 0.875rem; }

kbd {
  font: inherit;
  font-size: 0.8em;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 4px;
  background: var(--button);
}

@media (pointer: coarse) {
  .dpad { display: grid; }
  .help { display: none; }
}
