:root {
  --bg: #0d1117;
  --panel: #161b22;
  --grid-1: #12171f;
  --grid-2: #161d27;
  --snake: #3fb950;
  --snake-head: #56d364;
  --food: #f85149;
  --text: #e6edf3;
  --muted: #8b949e;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(900px 500px at 50% -20%, #182030, transparent), var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 20px;
  min-height: 100vh;
  touch-action: none;
}

.app {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.stat {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid #23303f;
  border-radius: 10px;
  padding: 6px 14px;
  min-width: 72px;
}

.stat .label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
}

.stat .value {
  font-size: 22px;
  font-weight: 800;
}

.hud .stat:first-child {
  margin-right: 0;
}

.icon-btn {
  margin-left: auto;
  width: 44px;
  height: 44px;
  font-size: 18px;
  border-radius: 10px;
  border: 1px solid #23303f;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.icon-btn:nth-of-type(2) {
  margin-left: 0;
}

.icon-btn:hover {
  background: #1d2531;
}

.stage {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--grid-1);
  border: 1px solid #23303f;
  border-radius: 14px;
  overflow: hidden;
}

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

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 15, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  margin: 0;
  font-size: 30px;
}

.overlay p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.btn {
  background: var(--snake);
  color: #05210d;
  border: none;
  border-radius: 10px;
  padding: 12px 30px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.08);
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  gap: 10px;
  max-width: 260px;
  width: 100%;
  align-self: center;
}

.dpad {
  height: 58px;
  font-size: 20px;
  border-radius: 12px;
  border: 1px solid #23303f;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.dpad:active {
  background: #223041;
}

.dpad.up { grid-area: up; }
.dpad.left { grid-area: left; }
.dpad.right { grid-area: right; }
.dpad.down { grid-area: down; }

@media (hover: hover) and (pointer: fine) {
  .pad {
    display: none;
  }
}
