:root {
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  --bg: #f3f0e8;
  --panel: #fffdf8;
  --border: #3b3a36;
  --grid: #d8d1c3;
  --snake: #2f6f3e;
  --snake-head: #1f4d2a;
  --food: #c7502c;
  --text: #23211d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(100%, 560px);
  background: var(--panel);
  border: 2px solid var(--border);
  padding: 20px;
}

.leaderboard {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: #f7f2e8;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.leaderboard h2 {
  margin: 0;
  font-size: 1.05rem;
}

.leaderboard-status {
  font-size: 0.85rem;
}

.leaderboard-list {
  margin: 10px 0 0;
  padding-left: 22px;
  display: grid;
  gap: 6px;
}

.hud {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: 2rem;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.95rem;
}

.stats {
  display: grid;
  gap: 6px;
  text-align: right;
  font-size: 0.95rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  gap: 2px;
  padding: 2px;
  border: 2px solid var(--border);
  background: var(--border);
}

.cell {
  aspect-ratio: 1;
  background: var(--grid);
}

.cell.inactive {
  background: #050505;
}

.cell.snake {
  background: var(--snake);
}

.cell.head {
  background: var(--snake-head);
}

.cell.npc {
  background: #bc3f3f;
}

.cell.npc-head {
  background: #8e2727;
}

.cell.food {
  background: var(--food);
}

.cell.food.gold-food {
  background: #d9af37;
}

.controls {
  margin-top: 16px;
  display: grid;
  gap: 16px;
  justify-items: center;
}

.credit {
  margin: 16px 0 0;
  text-align: center;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgb(35 33 29 / 45%);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(100%, 340px);
  background: var(--panel);
  border: 2px solid var(--border);
  padding: 18px;
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.modal-copy {
  margin: 0 0 14px;
}

.record-form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field input {
  border: 1px solid var(--border);
  padding: 10px 12px;
  font: inherit;
  background: #fffdf8;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.secondary-button {
  background: #f7f2e8;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 30;
}

.confetti-piece {
  position: absolute;
  top: -24px;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  opacity: 0.95;
  animation: fall linear forwards;
}

@keyframes fall {
  from {
    transform: translateY(0) rotate(0deg);
  }

  to {
    transform: translateY(105vh) rotate(720deg);
  }
}

.direction-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  gap: 10px;
  align-items: center;
  justify-items: center;
}

.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.control-button {
  min-width: 96px;
  min-height: 48px;
}

.direction-button.up {
  grid-area: up;
}

.direction-button.left {
  grid-area: left;
}

.direction-button.right {
  grid-area: right;
}

.direction-button.down {
  grid-area: down;
}

button {
  border: 1px solid var(--border);
  background: #ece5d8;
  color: var(--text);
  padding: 12px 16px;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--snake-head);
  outline-offset: 2px;
}

@media (max-width: 560px) {
  .card {
    padding: 16px;
  }

  .hud {
    flex-direction: column;
  }

  .stats {
    text-align: left;
  }

  .leaderboard-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .controls {
    gap: 18px;
  }

  .direction-pad {
    gap: 12px;
  }

  .action-buttons {
    width: 100%;
    gap: 12px;
  }

  .control-button {
    min-width: 104px;
    min-height: 56px;
  }

  button {
    padding: 14px 18px;
    font-size: 1rem;
  }

  .credit {
    margin-top: 18px;
  }
}
