:root {
  --bg: #f4f6f1;
  --surface: #ffffff;
  --text: #1d2420;
  --muted: #5b6660;
  --border: #d5ddd7;
  --board: #e6ece6;
  --grid: #d9e1da;
  --head: #1f7a3a;
  --body: #58b96f;
  --food: #e0463c;
  --accent: #1f7a3a;
  --accent-text: #ffffff;
  --overlay: rgba(20, 26, 22, 0.55);
  --radius: 14px;
  --space: 16px;
  --focus: #2b6cb0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111613;
    --surface: #1a211d;
    --text: #e8efe9;
    --muted: #9aa8a0;
    --border: #2c3731;
    --board: #141b17;
    --grid: #1d2620;
    --head: #7ee39a;
    --body: #3fa35a;
    --food: #ff6b5e;
    --accent: #7ee39a;
    --accent-text: #0f1512;
    --overlay: rgba(0, 0, 0, 0.6);
    --focus: #90cdf4;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: var(--space);
}

.app {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
}

.scores { display: flex; gap: 8px; }

.score-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.score-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.score-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--board);
}

#board {
  width: 100%;
  height: 100%;
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space);
}

.overlay[hidden] { display: none; }

.overlay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  width: min(300px, 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.overlay-card h2 { margin: 0 0 8px; font-size: 22px; }
.overlay-card p { margin: 0 0 16px; color: var(--muted); }

.controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hint { margin: 0; font-size: 13px; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.btn:hover { filter: brightness(0.97); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.btn-ghost { background: transparent; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 56px);
  gap: 8px;
  justify-content: center;
}

.dpad-btn { min-width: 56px; min-height: 56px; font-size: 22px; padding: 0; }
.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; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  max-width: calc(100% - 32px);
}

.toast[hidden] { display: none; }

@media (min-width: 900px) {
  .dpad { display: none; }
}
