* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: #eef7e8;
  background:
    linear-gradient(rgba(8, 16, 11, 0.78), rgba(8, 16, 11, 0.9)),
    url("snake.jpg") center / cover no-repeat,
    #101711;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  min-height: 100vh;
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.topbar {
  width: min(100%, 700px);
  display: grid;
  grid-template-columns: 96px 1fr 96px;
  align-items: center;
  gap: 16px;
}

.title-block {
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4rem);
}

#status {
  min-height: 24px;
  margin: 6px 0 0;
  color: #cde2c4;
  font-weight: 700;
}

.back-link,
button {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  color: #eef7e8;
  background: rgba(18, 39, 22, 0.78);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.back-link:hover,
button:hover {
  background: rgba(48, 91, 45, 0.9);
}

.score-row {
  width: min(100%, 700px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#score {
  font-size: 1.15rem;
  font-weight: 800;
  color: #f0ffd5;
}

#pauseBtn {
  width: 96px;
}

#game-board {
  width: min(88vw, 72vh, 640px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  grid-template-rows: repeat(20, 1fr);
  gap: 1px;
  padding: 10px;
  border-radius: 8px;
  border: 3px solid rgba(214, 236, 196, 0.34);
  background: linear-gradient(135deg, #1b2b1d, #071107);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
  touch-action: none;
  user-select: none;
}

.cell {
  border-radius: 2px;
  background: rgba(20, 36, 22, 0.94);
}

.snake,
.snake-head {
  background: linear-gradient(135deg, #64b957, #2d7d32);
  box-shadow: inset 0 0 8px rgba(255, 255, 255, 0.24);
}

.snake-head {
  background: radial-gradient(circle at 35% 30%, #b4f07a, #2f8f32 70%);
}

.food {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #ffd1c8, #c82424 68%);
  box-shadow: 0 0 14px rgba(255, 68, 68, 0.62);
}

.touch-controls {
  width: min(76vw, 260px);
  display: none;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 58px);
  gap: 10px;
}

.direction-btn {
  min-height: 58px;
  font-size: 1.55rem;
  line-height: 1;
}

.direction-btn.up {
  grid-column: 2;
}

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

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

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

@media (max-width: 620px) {
  .game-shell {
    padding: 14px;
    justify-content: start;
  }

  .topbar {
    grid-template-columns: 1fr 1fr;
  }

  .title-block {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .back-link,
  #restartBtn {
    grid-row: 2;
  }

  #game-board {
    width: min(92vw, 54vh);
    padding: 7px;
  }

  .touch-controls {
    display: grid;
  }
}

@media (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}
