:root {
  color-scheme: light;
  --bg: #eef3ef;
  --ink: #202720;
  --muted: #5f6861;
  --panel: #fffdf8;
  --line: rgba(32, 39, 32, 0.12);
  --board: #17352d;
  --snake: #61d394;
  --snake-head: #f7d046;
  --food: #e85d75;
  --accent: #2f7f73;
  --accent-dark: #24665c;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(47, 127, 115, 0.18), transparent 32%),
    linear-gradient(315deg, rgba(139, 111, 71, 0.16), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button {
  height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

.game-shell {
  width: min(100%, 560px);
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  margin-bottom: 12px;
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.game-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(40px, 9vw, 64px);
  line-height: 1;
  letter-spacing: 0;
}

.game-header p,
.hint {
  margin-top: 10px;
  color: var(--muted);
}

.score-box {
  min-width: 92px;
  padding: 12px;
  border-radius: 8px;
  background: #25564d;
  color: #fff;
  text-align: center;
}

.score-box span {
  display: block;
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
}

.score-box strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  line-height: 1;
}

.board-wrap {
  position: relative;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--board);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: 8px;
  background: rgba(238, 243, 239, 0.78);
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(100%, 280px);
  padding: 22px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(32, 39, 32, 0.18);
  text-align: center;
}

.panel p {
  margin: 8px 0 16px;
  color: var(--muted);
}

.panel button {
  width: 100%;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.hint {
  text-align: center;
}

@media (max-width: 520px) {
  body {
    align-items: start;
    padding: 16px;
  }

  .game-header {
    align-items: stretch;
    flex-direction: column;
  }

  .score-box {
    min-width: 0;
  }
}
