:root {
  --bg: #101715;
  --panel: #16211e;
  --panel-strong: #1c2d27;
  --line: #2f463e;
  --text: #f1f7ee;
  --muted: #a8b9ad;
  --snake: #7ee787;
  --snake-dark: #35b963;
  --food: #ff6b6b;
  --gold: #f7c948;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 20% 15%, rgba(126, 231, 135, 0.12), transparent 28rem),
    linear-gradient(135deg, #0d1211 0%, var(--bg) 50%, #1b1711 100%);
}

button {
  color: inherit;
  font: inherit;
}

.game-shell {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 720px) minmax(220px, 300px);
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 28px 0;
}

.stage-wrap {
  position: relative;
  display: grid;
  gap: 12px;
}

.top-hud,
.side-panel {
  border: 1px solid var(--line);
  background: rgba(22, 33, 30, 0.84);
  box-shadow: 0 18px 46px var(--shadow);
  backdrop-filter: blur(12px);
}

.top-hud {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 8px;
}

.hud-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.top-hud strong {
  display: block;
  font-size: clamp(1.25rem, 4vw, 2rem);
  line-height: 1;
}

.icon-button,
.primary-action,
.touch-pad button,
#startBtn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.icon-button:hover,
.primary-action:hover,
.touch-pad button:hover,
#startBtn:hover {
  transform: translateY(-1px);
  border-color: var(--snake);
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--gold);
  font-weight: 800;
}

canvas {
  width: min(100%, 72vh);
  aspect-ratio: 1;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b1110;
  box-shadow: 0 22px 62px var(--shadow);
  touch-action: none;
}

.message {
  position: absolute;
  inset: 84px 16px 16px;
  display: none;
  place-items: center;
  align-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  border: 1px solid rgba(126, 231, 135, 0.28);
  border-radius: 8px;
  background: rgba(12, 17, 16, 0.82);
  backdrop-filter: blur(10px);
}

.message.is-visible {
  display: grid;
}

.message h1 {
  margin: 0;
  font-size: clamp(2.4rem, 9vw, 5.5rem);
  line-height: 1;
}

.message p {
  margin: 0;
  color: var(--muted);
}

#startBtn,
.primary-action {
  min-height: 44px;
  padding: 0 18px;
  background: linear-gradient(180deg, #3bcf73, #269952);
  border-color: #65e58f;
  color: #07120d;
  font-weight: 800;
}

.side-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: 8px;
}

.stat-row {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
  border-bottom: 1px solid rgba(168, 185, 173, 0.2);
}

.stat-row span {
  color: var(--muted);
}

.stat-row strong {
  font-size: 1.35rem;
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 52px);
  place-content: center;
  gap: 8px;
  margin-top: 6px;
}

.touch-pad button {
  min-width: 0;
  background: #22342e;
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 800;
}

.touch-pad [data-dir="up"] {
  grid-column: 2;
}

.touch-pad [data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.touch-pad [data-dir="down"] {
  grid-column: 2;
  grid-row: 2;
}

.touch-pad [data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

@media (max-width: 780px) {
  .game-shell {
    width: min(100vw - 20px, 620px);
    grid-template-columns: 1fr;
    align-content: center;
    gap: 12px;
    padding: 10px 0 18px;
  }

  canvas {
    width: 100%;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
  }

  .primary-action,
  .touch-pad {
    grid-column: 1 / -1;
  }

  .message {
    inset: 82px 10px 10px;
  }
}
