:root {
  --bg-top: #09111f;
  --bg-bottom: #05070d;
  --card-top: #111a2f;
  --card-bottom: #0a1020;
  --line: #294066;
  --text: #e7efff;
  --muted: #9db2d7;
  --snake: #3bf78f;
  --snake-head: #a6ffd0;
  --food: #ff8a33;
  --gold: #ffd447;
  --poison: #ef4e6d;
  --obstacle: #5d6f9a;
  --accent: #5bc4ff;
  --board-border: rgba(141, 174, 255, 0.4);
  --board-shadow: rgba(11, 27, 58, 0.8);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 15%, rgba(60, 110, 255, 0.25), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(11, 210, 180, 0.2), transparent 35%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  transition: background 240ms ease;
}

.game-shell {
  width: min(94vw, 560px);
  padding: 18px;
  border-radius: 20px;
  background: linear-gradient(180deg, var(--card-top), var(--card-bottom));
  border: 1px solid rgba(127, 166, 255, 0.28);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transition: background 240ms ease, border-color 240ms ease;
}

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

h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 1px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.hud p {
  margin: 0;
  text-align: center;
  padding: 8px 6px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid rgba(133, 167, 239, 0.25);
  background: rgba(13, 23, 45, 0.65);
}

.hud span {
  color: var(--text);
}

.play-area {
  position: relative;
}

#board {
  width: 100%;
  max-width: 420px;
  display: block;
  margin: 0 auto;
  border-radius: 12px;
  border: 1px solid var(--board-border);
  background: linear-gradient(180deg, #040915, #02050d);
  box-shadow:
    inset 0 0 40px var(--board-shadow),
    0 10px 25px rgba(0, 0, 0, 0.45);
  touch-action: none;
  transition: border-color 240ms ease, box-shadow 240ms ease;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  gap: 10px;
  padding: 24px;
  border-radius: 12px;
  background: rgba(2, 8, 20, 0.78);
  backdrop-filter: blur(4px);
  animation: fade-in 260ms ease;
}

.overlay.show {
  display: flex;
}

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

.overlay p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.primary-btn,
.ghost-btn,
.dir-btn {
  border: 0;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, background-color 120ms ease;
}

.primary-btn {
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  color: #081b12;
  background: linear-gradient(180deg, #6bf8ae, #32d279);
}

.primary-btn:hover,
.ghost-btn:hover,
.dir-btn:hover {
  filter: brightness(1.08);
}

.primary-btn:active,
.ghost-btn:active,
.dir-btn:active {
  transform: translateY(1px) scale(0.98);
}

.controls {
  margin-top: 14px;
}

.action-buttons {
  display: flex;
  gap: 10px;
}

.ghost-btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  font-weight: 700;
  border: 1px solid rgba(144, 175, 245, 0.35);
  background: linear-gradient(180deg, #162443, #101b33);
}

.dpad {
  margin: 16px auto 0;
  width: min(240px, 85vw);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 54px);
  gap: 8px;
  touch-action: none;
}

.dir-btn {
  border-radius: 12px;
  font-size: 22px;
  color: #dbf0ff;
  border: 1px solid rgba(136, 175, 255, 0.4);
  background: linear-gradient(180deg, #203764, #14223f);
}

.dir-btn.holding {
  background: linear-gradient(180deg, #335a97, #1d3560);
  box-shadow: 0 0 0 2px rgba(91, 196, 255, 0.24);
  filter: brightness(1.12);
}

.up {
  grid-column: 2;
  grid-row: 1;
}

.left {
  grid-column: 1;
  grid-row: 2;
}

.down {
  grid-column: 2;
  grid-row: 2;
}

.right {
  grid-column: 3;
  grid-row: 2;
}

.tips {
  margin: 14px 4px 2px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.gold-flash {
  animation: pulse 500ms infinite alternate;
}

@keyframes pulse {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.35);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 680px) {
  .game-shell {
    padding: 14px;
    border-radius: 14px;
  }

  h1 {
    font-size: 22px;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dpad {
    grid-template-rows: repeat(3, 50px);
  }
}
