:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --panel: #fffdf8;
  --border: #b8c2b5;
  --text: #222821;
  --muted: #647064;
  --snake: #18734c;
  --snake-head: #0d432d;
  --food: #e3442d;
  --rock: #697476;
  --cell: #dfe6dc;
  --cell-size: clamp(16px, min(5.2vw, calc((100vw - 70px) / 16)), 24px);
  --cell-gap: 2px;
  --board-padding: 12px;
  --play-width: calc((16 * var(--cell-size)) + (15 * var(--cell-gap)) + (2 * var(--board-padding)) + 4px);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(24, 115, 76, 0.08), transparent 35%),
    linear-gradient(315deg, rgba(227, 68, 45, 0.08), transparent 35%),
    var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

button {
  font: inherit;
  cursor: pointer;
}

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

.screen {
  width: min(100%, 560px);
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 12px 30px rgba(35, 40, 35, 0.08);
}

.screen[hidden] {
  display: none;
}

.game-screen {
  display: grid;
  justify-items: center;
}

.brand {
  min-height: 280px;
  display: grid;
  align-content: center;
  gap: 12px;
}

.eyebrow,
.label,
.value,
.menu-copy,
.overlay-title,
.overlay-text,
h1,
h2 {
  margin: 0;
}

.eyebrow,
.label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.8rem, 14vw, 4.8rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.5rem;
  line-height: 1;
}

.menu-copy {
  max-width: 320px;
  color: var(--muted);
  line-height: 1.45;
}

.menu-actions,
.actions,
.overlay-actions {
  display: flex;
  gap: 12px;
}

.menu-actions {
  margin-top: 10px;
}

.menu-stats,
.status-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.menu-stats {
  grid-template-columns: repeat(2, 1fr);
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px solid #e5eadf;
}

.value {
  font-size: 1.2rem;
  font-weight: 700;
}

.lives-value {
  color: #c73d36;
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.combo-value {
  color: #8a5a16;
  white-space: nowrap;
}

.combo-value.is-active {
  color: #d9781f;
  text-shadow: 0 0 12px rgba(240, 179, 47, 0.42);
}

.primary-button,
.secondary-button,
.turn-button,
.icon-button,
.level-node {
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.primary-button,
.secondary-button {
  flex: 1;
  padding: 11px 14px;
}

.primary-button {
  background: var(--snake);
  color: #fff;
  border-color: var(--snake-head);
}

.secondary-button:disabled,
.level-node:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.top-bar,
.game-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.game-header {
  width: var(--play-width);
  max-width: 100%;
}

.icon-button {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  font-size: 1.25rem;
  font-weight: 800;
  touch-action: none;
}

.map-path {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.map-path::before {
  content: "";
  position: absolute;
  left: 25%;
  right: 25%;
  top: 26px;
  bottom: 26px;
  border-left: 4px dashed #d5ddcf;
  border-right: 4px dashed #d5ddcf;
  pointer-events: none;
}

.level-node {
  position: relative;
  z-index: 1;
  min-height: 76px;
  padding: 10px;
  display: grid;
  align-content: center;
  gap: 3px;
  text-align: left;
}

.level-node:nth-child(even) {
  transform: translateY(26px);
}

.level-node.complete {
  border-color: var(--snake);
  background: #edf8f0;
}

.level-node.locked {
  background: #f1f1ee;
}

.level-number {
  font-weight: 800;
  font-size: 1.2rem;
}

.level-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.level-stars {
  color: #d69a1d;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 1px;
  line-height: 1;
}

.level-node.locked .level-stars {
  color: #aeb5aa;
}

.status-bar {
  margin-bottom: 12px;
  width: var(--play-width);
  max-width: 100%;
}

.board-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--play-width);
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding: var(--board-padding);
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #eef3eb;
  overflow: hidden;
}

.board {
  display: grid;
  grid-template-columns: repeat(16, var(--cell-size));
  grid-template-rows: repeat(16, var(--cell-size));
  gap: var(--cell-gap);
  touch-action: none;
  user-select: none;
  transition: filter 160ms ease, transform 160ms ease;
}

.score-popups {
  position: absolute;
  inset: var(--board-padding);
  pointer-events: none;
  z-index: 4;
}

.score-popup {
  position: absolute;
  color: #f0b32f;
  font-size: clamp(1.2rem, 7vw, 2rem);
  font-weight: 900;
  line-height: 1;
  text-shadow:
    0 2px 0 rgba(96, 46, 13, 0.45),
    0 6px 14px rgba(28, 28, 16, 0.24);
  transform: translate(-50%, calc(-50% - var(--popup-rise))) scale(var(--popup-scale));
}

.board.is-ready-blurred {
  filter: blur(1.5px) saturate(0.95);
  transform: scale(0.992);
}

.cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 5px;
  background: var(--cell);
}

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

.cell.head {
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.28) 0 10%, transparent 11%),
    var(--snake-head);
  border-radius: 55% 55% 48% 48%;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.22),
    0 0 0 1px rgba(5, 34, 20, 0.4);
  z-index: 3;
}

.cell.head::before {
  content: "";
  position: absolute;
  width: 16%;
  height: 16%;
  border-radius: 50%;
  background: #f8fff6;
  box-shadow: 0 0 0 1px rgba(5, 34, 20, 0.38);
}

.cell.head::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 8%;
  border-radius: 999px;
  background: #d9ffd1;
  box-shadow: 0 0 0 1px rgba(4, 28, 16, 0.28);
}

.cell.head.head-right::before {
  top: 22%;
  right: 18%;
  box-shadow:
    0 calc(var(--cell-size) * 0.34) 0 #f8fff6,
    0 0 0 1px rgba(5, 34, 20, 0.3);
}

.cell.head.head-right::after {
  right: 3%;
  top: 46%;
}

.cell.head.head-left::before {
  top: 22%;
  left: 18%;
  box-shadow:
    0 calc(var(--cell-size) * 0.34) 0 #f8fff6,
    0 0 0 1px rgba(5, 34, 20, 0.3);
}

.cell.head.head-left::after {
  left: 3%;
  top: 46%;
}

.cell.head.head-up::before {
  top: 16%;
  left: 24%;
  box-shadow:
    calc(var(--cell-size) * 0.35) 0 0 #f8fff6,
    0 0 0 1px rgba(5, 34, 20, 0.3);
}

.cell.head.head-up::after {
  left: 36%;
  top: 4%;
  transform: rotate(90deg);
}

.cell.head.head-down::before {
  bottom: 16%;
  left: 24%;
  box-shadow:
    calc(var(--cell-size) * 0.35) 0 0 #f8fff6,
    0 0 0 1px rgba(5, 34, 20, 0.3);
}

.cell.head.head-down::after {
  left: 36%;
  bottom: 4%;
  transform: rotate(90deg);
}

.cell.head.mouth-open::after {
  width: 42%;
  height: 34%;
  border-radius: 50%;
  background: #020b06;
  box-shadow:
    inset 0 0 0 2px rgba(255, 130, 130, 0.35),
    0 0 6px rgba(0, 0, 0, 0.18);
}

.cell.head.mouth-open {
  animation: headChomp 0.16s ease-in-out 2;
}

.cell.head.head-right.mouth-open::after {
  right: -7%;
  top: 33%;
}

.cell.head.head-right.mouth-open {
  clip-path: polygon(0 0, 70% 0, 100% 20%, 72% 50%, 100% 80%, 70% 100%, 0 100%);
}

.cell.head.head-left.mouth-open::after {
  left: -7%;
  top: 33%;
}

.cell.head.head-left.mouth-open {
  clip-path: polygon(100% 0, 30% 0, 0 20%, 28% 50%, 0 80%, 30% 100%, 100% 100%);
}

.cell.head.head-up.mouth-open::after {
  left: 29%;
  top: -8%;
  transform: rotate(90deg);
}

.cell.head.head-up.mouth-open {
  clip-path: polygon(0 100%, 0 30%, 20% 0, 50% 28%, 80% 0, 100% 30%, 100% 100%);
}

.cell.head.head-down.mouth-open::after {
  left: 29%;
  bottom: -8%;
  transform: rotate(90deg);
}

.cell.head.head-down.mouth-open {
  clip-path: polygon(0 0, 0 70%, 20% 100%, 50% 72%, 80% 100%, 100% 70%, 100% 0);
}

@keyframes headChomp {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.12);
  }
}

.cell.snake.digestion-food.digestion-1 {
  background: #8f7f39;
}

.cell.snake.digestion-food.digestion-2 {
  background: #c25b2f;
}

.cell.snake.digestion-food.digestion-3 {
  background: #e3442d;
}

.cell.snake.digestion-bonus.digestion-1 {
  background: #8e8d35;
}

.cell.snake.digestion-bonus.digestion-2 {
  background: #c9a92d;
}

.cell.snake.digestion-bonus.digestion-3 {
  background: #f7c948;
}

.cell.snake.digestion-speed.digestion-1 {
  background: #24806f;
}

.cell.snake.digestion-speed.digestion-2 {
  background: #1d8ed0;
}

.cell.snake.digestion-speed.digestion-3 {
  background: #28a4ff;
}

.cell.snake.digestion-slow.digestion-1 {
  background: #4b6b68;
}

.cell.snake.digestion-slow.digestion-2 {
  background: #6556b6;
}

.cell.snake.digestion-slow.digestion-3 {
  background: #7f63d9;
}

.cell.head.digestion-3 {
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.28),
    0 0 12px rgba(255, 255, 255, 0.35);
}

.cell.food {
  background: transparent;
  border-radius: 5px;
  box-shadow: none;
}

.cell.food::before {
  content: "";
  position: absolute;
  left: 9%;
  top: 30%;
  width: 82%;
  height: 54%;
  border-radius: 50% 50% 45% 45%;
  background: #58a849;
  box-shadow:
    inset -2px -3px 0 rgba(34, 88, 31, 0.25),
    0 -4px 0 -1px #74bf5e;
}

.cell.food::after {
  content: "";
  position: absolute;
  left: 19%;
  top: 16%;
  width: 15%;
  height: 15%;
  border-radius: 50%;
  background: #172416;
  box-shadow:
    calc(var(--cell-size) * 0.42) 0 0 #172416,
    calc(var(--cell-size) * 0.21) calc(var(--cell-size) * 0.24) 0 -1px #dff4d2;
}

.cell.bonus-food {
  background: radial-gradient(circle at 38% 34%, #fff7b8 0 16%, #f6d15f 17% 45%, #b9791c 46% 100%);
  background-size: 170% 170%;
  border-radius: 50% 50% 46% 46%;
  box-shadow:
    inset -2px -3px 0 rgba(116, 75, 10, 0.24),
    0 0 0 2px rgba(240, 180, 41, 0.18);
  animation: bonusPulse 0.9s ease-in-out infinite;
  z-index: 2;
}

.cell.bonus-food.bonus-tier-5 {
  filter: saturate(1.25) brightness(1.12);
  box-shadow:
    inset -2px -3px 0 rgba(116, 75, 10, 0.2),
    0 0 0 2px rgba(240, 180, 41, 0.22),
    0 0 10px rgba(247, 201, 72, 0.42);
}

.cell.bonus-food.bonus-tier-4 {
  filter: saturate(1.12) brightness(1.04);
}

.cell.bonus-food.bonus-tier-3 {
  filter: saturate(0.95) brightness(0.96);
}

.cell.bonus-food.bonus-tier-2 {
  filter: saturate(0.78) brightness(0.9);
}

.cell.bonus-food::before {
  content: "";
  position: absolute;
  left: 32%;
  top: -8%;
  width: 36%;
  height: 20%;
  border-radius: 50% 50% 20% 20%;
  background: #80521a;
}

.cell.bonus-food::after {
  content: "";
  position: absolute;
  left: 39%;
  top: 18%;
  width: 22%;
  height: 42%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  transform: rotate(28deg);
}

.cell.speed-up {
  background: linear-gradient(135deg, #7fd8ff 0%, #28a4ff 48%, #0a63d8 100%);
  background-size: 180% 180%;
  border-radius: 45% 55% 45% 55%;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28);
  animation: speedPulse 0.72s ease-in-out infinite;
}

.cell.speed-up::after {
  content: "⚡";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff8b8;
  font-size: calc(var(--cell-size) * 0.72);
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 45, 90, 0.45);
}

.cell.slow-down {
  background: linear-gradient(135deg, #b7a5ff 0%, #6c55d8 48%, #342582 100%);
  background-size: 180% 180%;
  border-radius: 55% 45% 55% 45%;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.32),
    0 0 0 1px rgba(38, 27, 94, 0.35);
  animation: slowPulse 1.15s ease-in-out infinite;
}

.cell.slow-down::after {
  content: "⏱";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: calc(var(--cell-size) * 0.74);
  line-height: 1;
  text-shadow: 0 1px 2px rgba(21, 13, 68, 0.6);
}

.cell.portal {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.98) 0 14%, rgba(83, 218, 214, 0.86) 15% 28%, transparent 29%),
    conic-gradient(from 0deg, #1f8fff, #6f4df5, #34d4a8, #f0d35a, #1f8fff);
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.58),
    0 0 10px rgba(56, 167, 224, 0.58);
  animation: portalSpin 1200ms linear infinite, portalPulse 900ms ease-in-out infinite;
}

.cell.portal::after {
  content: "";
  position: absolute;
  inset: 27%;
  border-radius: 50%;
  background: rgba(238, 243, 235, 0.92);
  box-shadow: inset 0 0 8px rgba(27, 92, 116, 0.35);
}

@keyframes bonusPulse {
  0%,
  100% {
    background-position: 20% 20%;
    transform: scale(0.92);
  }

  50% {
    background-position: 80% 80%;
    transform: scale(1.08);
  }
}

@keyframes speedPulse {
  0%,
  100% {
    background-position: 0% 50%;
    transform: scale(0.94);
  }

  50% {
    background-position: 100% 50%;
    transform: scale(1.08);
  }
}

@keyframes slowPulse {
  0%,
  100% {
    background-position: 20% 20%;
    transform: scale(0.94);
  }

  50% {
    background-position: 80% 80%;
    transform: scale(1.06);
  }
}

@keyframes portalSpin {
  0% {
    transform: rotate(0deg) scale(0.92);
  }

  100% {
    transform: rotate(360deg) scale(0.92);
  }
}

@keyframes portalPulse {
  0%,
  100% {
    filter: brightness(1);
  }

  50% {
    filter: brightness(1.22);
  }
}

.cell.obstacle {
  background: var(--rock);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.cell.moving-obstacle {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.2), transparent 42%),
    #5f6a67;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.16),
    0 0 0 2px rgba(49, 57, 54, 0.18);
  animation: movingRockPulse 950ms ease-in-out infinite;
}

.cell.moving-obstacle::after {
  content: "";
  position: absolute;
  inset: 24%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
}

@keyframes movingRockPulse {
  0%,
  100% {
    transform: scale(0.96);
  }

  50% {
    transform: scale(1.05);
  }
}

.overlay {
  position: absolute;
  inset: 12px;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  background: rgba(255, 253, 248, 0.94);
  border-radius: 8px;
  z-index: 6;
}

.overlay[hidden] {
  display: none;
}

.ready-overlay {
  position: absolute;
  inset: 12px;
  display: grid;
  place-content: center;
  gap: 6px;
  text-align: center;
  background: rgba(238, 243, 235, 0.28);
  border-radius: 8px;
  backdrop-filter: blur(1px);
  z-index: 5;
}

.ready-overlay[hidden] {
  display: none;
}

.ready-title,
.ready-count {
  margin: 0;
}

.ready-title {
  color: #126c49;
  font-size: 1rem;
  font-weight: 800;
  text-transform: uppercase;
  text-shadow: 0 2px 10px rgba(255, 253, 248, 0.9);
}

.ready-count {
  background: linear-gradient(135deg, #147a50, #f0b32f 45%, #cf4b49 78%, #216fba);
  background-size: 220% 220%;
  color: transparent;
  background-clip: text;
  -webkit-background-clip: text;
  font-size: clamp(3.2rem, 16vw, 5.5rem);
  font-weight: 900;
  line-height: 0.95;
  text-shadow: 0 10px 22px rgba(9, 54, 34, 0.18);
  animation: readyPulse 900ms ease-in-out infinite, readyColor 1800ms linear infinite;
}

@keyframes readyPulse {
  0%,
  100% {
    transform: scale(1);
  }

  35% {
    transform: scale(1.15);
  }

  55% {
    transform: scale(0.96);
  }
}

@keyframes readyColor {
  0% {
    background-position: 0% 50%;
  }

  100% {
    background-position: 100% 50%;
  }
}

.overlay-title {
  font-size: 1.45rem;
  font-weight: 800;
}

.overlay-text {
  color: var(--muted);
}

.actions {
  width: var(--play-width);
  max-width: 100%;
  margin-top: 10px;
  margin-left: auto;
  margin-right: auto;
}

.controls {
  width: var(--play-width);
  max-width: 100%;
  margin-top: 16px;
  display: grid;
  justify-content: stretch;
  gap: 10px;
  margin-left: auto;
  margin-right: auto;
}

.turn-controls {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  margin-top: 0;
}

.turn-button {
  min-width: 0;
  min-height: 66px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 2px;
  font-weight: 800;
}

.turn-button:first-child {
  border-radius: 8px 0 0 8px;
  border-right-width: 1px;
}

.turn-button:last-child {
  border-radius: 0 8px 8px 0;
  border-left-width: 1px;
}

.key-number {
  font-size: 1.25rem;
  line-height: 1;
}

.turn-button:active,
.primary-button:active,
.secondary-button:active,
.icon-button:active,
.level-node:active {
  transform: translateY(1px);
}

@media (max-width: 520px) {
  :root {
    --board-padding: 8px;
    --cell-size: clamp(14px, calc((100vw - 82px) / 16), 22px);
  }

  .app {
    align-items: start;
    padding: 6px;
  }

  .screen {
    width: 100%;
    padding: 8px;
  }

  .brand {
    min-height: 240px;
  }

  .status-bar {
    gap: 8px;
    margin-bottom: 10px;
  }

  .board-frame {
    padding: var(--board-padding);
  }

  .primary-button,
  .secondary-button {
    padding: 11px 8px;
    font-size: 0.95rem;
  }

  .level-node {
    min-height: 70px;
  }
}
