/* Snake — matches the games hub palette. Dark by default, light via prefers-color-scheme.
   Canvas colors are read from the --board/--snake/--food tokens below by game.js. */

:root {
  color-scheme: dark;
  --font-display: 'Bricolage Grotesque', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --bg: #0d0d10;
  --surface: #17171c;
  --surface-2: #222229;
  --text: #f5f5f7;
  --muted: #a1a1aa;
  --line: #2a2a31;
  --accent: #2fbf71;
  --warn: #ffd23f;
  --danger: #ff5d5d;
  --focus: #ffd23f;

  /* Canvas */
  --board: #141418;
  --cell-a: #18181d;
  --cell-b: #1c1c22;
  --snake: #2fbf71;
  --snake-hi: #5fd895;
  --snake-dead: #57534e;
  --eye: #f5f5f7;
  --pupil: #0d0d10;
  --food: #ff5d5d;
  --food-hi: #ffb0b0;
  --leaf: #ffd23f;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f6f3;
    --surface: #ffffff;
    --surface-2: #ececea;
    --text: #141416;
    --muted: #55555e;
    --line: #dcdcd6;
    --accent: #1d8a50;
    --danger: #d63c3c;
    --focus: #141416;

    --board: #fbfbf9;
    --cell-a: #fbfbf9;
    --cell-b: #f1f1ec;
    --snake: #1d8a50;
    --snake-hi: #3fb375;
    --snake-dead: #a8a8a0;
    --eye: #ffffff;
    --pupil: #141416;
    --food: #e04848;
    --food-hi: #ffc2c2;
    --leaf: #c89200;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(60rem 30rem at 15% -10%, rgba(47, 191, 113, 0.14), transparent 60%),
    radial-gradient(50rem 28rem at 110% 0%, rgba(255, 93, 93, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.topbar {
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.back {
  justify-self: start;
  display: inline-flex; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  padding: 6px 8px 6px 2px; border-radius: 10px;
}
.back:hover { color: var(--text); }
.back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 6vw, 2rem);
  letter-spacing: -0.03em;
  margin: 0;
}

.levels {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.levels button {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 16px; border-radius: 999px;
  font-weight: 700; font-size: 0.92rem; color: var(--muted);
}
.levels button:hover { color: var(--text); }
.levels button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }

.hud {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: min(100%, 360px);
}
.stat {
  display: inline-flex; align-items: center; gap: 8px;
  min-width: 92px;
  padding: 8px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  font: 800 1.15rem var(--font-display);
  font-variant-numeric: tabular-nums;
}
.stat:last-child { justify-content: flex-end; }
.stat svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.reset {
  width: 52px; height: 52px; border-radius: 16px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center;
  transition: transform 120ms ease;
}
.reset svg { width: 24px; height: 24px; fill: none; stroke: var(--text); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.reset:hover { border-color: var(--muted); }
.reset:active { transform: scale(0.94); }

.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 4px 0;
}
.board {
  padding: 0;
  border-radius: 14px;
  background: var(--board);
  border: 1px solid var(--line);
  overflow: hidden;
  line-height: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.board.over { border-color: color-mix(in srgb, var(--danger) 60%, var(--line)); }
.board.won { border-color: var(--accent); }
.board canvas { display: block; }

/* On-screen d-pad: only for touch / coarse pointers. */
.pad {
  display: none;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  grid-template-areas: ". up ." "left mid right" ". down .";
}
.pad button {
  border-radius: 16px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  display: grid; place-items: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
.pad button:active { background: var(--surface-2); }
.pad svg { width: 28px; height: 28px; fill: none; stroke: var(--text); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.pad .pad-mid { background: transparent; border-style: dashed; }
.pad .pad-mid svg { width: 22px; height: 22px; stroke: var(--muted); }
.pad-up { grid-area: up; } .pad-left { grid-area: left; } .pad-mid { grid-area: mid; }
.pad-right { grid-area: right; } .pad-down { grid-area: down; }

.controls {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: 420px; text-align: center;
}
.hint { margin: 0; color: var(--muted); font-size: 0.9rem; }
.hint-touch { display: none; }

@media (pointer: coarse) {
  .pad { display: grid; }
  .hint-keys { display: none; }
  .hint-touch { display: block; }
}

.status {
  margin: 0; min-height: 1.6em;
  font: 800 1.25rem var(--font-display); letter-spacing: -0.01em;
  text-align: center;
}
.status.win { color: var(--accent); }
.status.lose { color: var(--danger); }
.best { margin: -10px 0 0; color: var(--muted); font-size: 0.9rem; min-height: 1.4em; }

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