:root {
  --bg-primary: #07111f;
  --bg-secondary: #0f1b33;
  --panel: rgba(8, 18, 33, 0.84);
  --panel-border: rgba(120, 226, 255, 0.16);
  --text-primary: #e9f7ff;
  --text-muted: #91aac4;
  --accent: #68f6b4;
  --accent-strong: #18d2ff;
  --danger: #ff6f91;
  --food: #ffd166;
  --snake-head: #90ffdc;
  --snake-body: #30c89b;
  --grid-line: rgba(104, 246, 180, 0.08);
  --glow: 0 0 24px rgba(24, 210, 255, 0.24);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --transition: 180ms ease;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text-primary);
  touch-action: manipulation;
  background:
    radial-gradient(circle at top, rgba(24, 210, 255, 0.2), transparent 32%),
    radial-gradient(circle at bottom right, rgba(104, 246, 180, 0.14), transparent 26%),
    linear-gradient(145deg, #050914 0%, #091221 45%, #050814 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    repeating-linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.015) 0,
      rgba(255, 255, 255, 0.015) 1px,
      transparent 1px,
      transparent 4px
    );
  opacity: 0.35;
  pointer-events: none;
  animation: scanlineDrift 10s linear infinite;
}

body::after {
  content: "";
  position: fixed;
  inset: -20%;
  background:
    radial-gradient(circle at 20% 20%, rgba(24, 210, 255, 0.12), transparent 20%),
    radial-gradient(circle at 80% 30%, rgba(255, 209, 102, 0.08), transparent 18%),
    radial-gradient(circle at 60% 80%, rgba(104, 246, 180, 0.1), transparent 24%);
  filter: blur(24px);
  opacity: 0.9;
  pointer-events: none;
  animation: glowShift 14s ease-in-out infinite alternate;
}

button,
canvas {
  font: inherit;
}

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

.game-card {
  width: min(100%, 980px);
  padding: 28px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--glow);
  backdrop-filter: blur(10px);
}

.hero {
  text-align: center;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-strong);
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 0.74rem;
}

.hero h1 {
  margin: 0;
  font-family: "Press Start 2P", cursive;
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  line-height: 1.2;
}

.subtitle {
  margin: 16px auto 0;
  max-width: 640px;
  color: var(--text-muted);
  font-size: 1rem;
}

.hero-tags {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.hero-tag {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

.feature-bar {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 14px;
  margin-bottom: 22px;
}

.challenge-card,
.theme-switcher {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(8, 16, 30, 0.74);
}

.feature-label {
  display: block;
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.challenge-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1rem;
}

.challenge-card p {
  margin: 0 0 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

.challenge-status {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(104, 246, 180, 0.12);
  border: 1px solid rgba(104, 246, 180, 0.18);
  color: var(--text-primary);
  font-size: 0.82rem;
}

.theme-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.theme-chip {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), border-color var(--transition);
}

.theme-chip.active {
  border-color: rgba(24, 210, 255, 0.32);
  background: linear-gradient(135deg, rgba(24, 210, 255, 0.24), rgba(104, 246, 180, 0.18));
}

.theme-chip:hover {
  transform: translateY(-1px);
}

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

.stat {
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  background: rgba(8, 16, 30, 0.78);
}

.stat.accent {
  border-color: rgba(104, 246, 180, 0.22);
}

.stat-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat strong {
  font-size: clamp(1.1rem, 2vw, 1.5rem);
}

.board-section {
  display: flex;
  justify-content: center;
}

.board-frame {
  position: relative;
  width: min(100%, 640px);
  aspect-ratio: 1 / 1;
  padding: 16px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(104, 246, 180, 0.06), rgba(0, 0, 0, 0)),
    rgba(4, 10, 19, 0.96);
  border: 1px solid rgba(104, 246, 180, 0.12);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 18px 48px rgba(0, 0, 0, 0.32);
  overflow: hidden;
}

#gameBoard {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background:
    linear-gradient(rgba(104, 246, 180, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(104, 246, 180, 0.03) 1px, transparent 1px),
    linear-gradient(180deg, #06111c 0%, #081522 100%);
  background-size: 32px 32px, 32px 32px, auto;
}

.overlay {
  position: absolute;
  inset: 16px;
  display: grid;
  place-items: center;
  padding: 24px;
  border-radius: 18px;
  background: rgba(2, 8, 16, 0.7);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.overlay.active {
  opacity: 1;
  visibility: visible;
}

.overlay-card {
  max-width: 360px;
  padding: 28px;
  border-radius: 22px;
  border: 1px solid rgba(104, 246, 180, 0.18);
  background: rgba(7, 18, 32, 0.9);
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
}

.overlay-tag {
  display: inline-block;
  margin-bottom: 14px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(24, 210, 255, 0.14);
  color: var(--accent-strong);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.overlay-tag.danger {
  background: rgba(255, 111, 145, 0.16);
  color: #ff95aa;
}

.overlay-card h2 {
  margin: 0 0 12px;
}

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

.final-stats {
  margin: 16px 0;
  display: grid;
  gap: 8px;
}

.final-stats p {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.overlay-note {
  font-size: 0.94rem;
}

.level-up-toast {
  position: absolute;
  top: 30px;
  left: 50%;
  transform: translate(-50%, -16px);
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(104, 246, 180, 0.15);
  border: 1px solid rgba(104, 246, 180, 0.24);
  color: var(--text-primary);
  font-weight: 700;
  letter-spacing: 0.06em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}

.level-up-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.combo-toast {
  position: absolute;
  right: 24px;
  top: 28px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.14);
  border: 1px solid rgba(255, 209, 102, 0.22);
  color: #ffe3a0;
  font-weight: 700;
  letter-spacing: 0.05em;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.combo-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.board-frame.level-flash {
  animation: pulseBorder 850ms ease;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.mobile-controls {
  display: none;
  margin-top: 14px;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.mobile-actions {
  display: grid;
  gap: 10px;
  width: min(120px, 32%);
}

.mobile-dpad {
  display: grid;
  gap: 8px;
  width: min(164px, 44%);
}

.touch-middle {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.touch-button {
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(104, 246, 180, 0.12), rgba(24, 210, 255, 0.08)),
    rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
  -webkit-tap-highlight-color: transparent;
}

.touch-button:active {
  transform: scale(0.98);
}

.touch-up,
.touch-down {
  width: 44%;
  justify-self: center;
}

.touch-action {
  background:
    linear-gradient(180deg, rgba(255, 209, 102, 0.18), rgba(255, 111, 145, 0.08)),
    rgba(255, 255, 255, 0.05);
}

.touch-center {
  opacity: 0.3;
  pointer-events: none;
}

.theme-glow {
  animation: themeGlow 1.1s ease;
}

.control-button {
  min-width: 148px;
  padding: 14px 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), border-color var(--transition);
}

.control-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.08);
}

.control-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.control-button.primary {
  border-color: rgba(24, 210, 255, 0.3);
  background: linear-gradient(135deg, rgba(24, 210, 255, 0.3), rgba(104, 246, 180, 0.24));
}

.footer-note {
  margin-top: 18px;
  text-align: center;
  color: var(--text-muted);
}

.footer-note span {
  color: var(--text-primary);
}

@keyframes pulseBorder {
  0% {
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.03),
      0 18px 48px rgba(0, 0, 0, 0.32);
  }
  50% {
    box-shadow:
      inset 0 0 0 1px rgba(104, 246, 180, 0.22),
      0 0 36px rgba(104, 246, 180, 0.26);
  }
  100% {
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.03),
      0 18px 48px rgba(0, 0, 0, 0.32);
  }
}

@keyframes scanlineDrift {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(12px);
  }
}

@keyframes glowShift {
  from {
    transform: translate3d(-1%, -1%, 0) scale(1);
  }
  to {
    transform: translate3d(1%, 2%, 0) scale(1.04);
  }
}

@keyframes themeGlow {
  0% {
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.03),
      0 18px 48px rgba(0, 0, 0, 0.32);
  }
  50% {
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.06),
      0 0 44px rgba(255, 209, 102, 0.22);
  }
  100% {
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.03),
      0 18px 48px rgba(0, 0, 0, 0.32);
  }
}

@media (max-width: 820px) {
  .game-card {
    padding: 20px;
  }

  .feature-bar {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 560px) {
  .app-shell {
    padding: 14px;
  }

  .game-card {
    padding: 16px;
    border-radius: 20px;
  }

  .board-frame {
    padding: 10px;
    border-radius: 22px;
  }

  .overlay {
    inset: 10px;
    padding: 16px;
  }

  .overlay-card {
    padding: 20px;
  }

  .hero-tag {
    font-size: 0.78rem;
  }

  .challenge-card,
  .theme-switcher {
    padding: 14px;
  }

  .control-button {
    width: 100%;
  }

  .controls {
    display: none;
  }

  .mobile-controls {
    display: flex;
    width: min(100%, 640px);
    margin-left: auto;
    margin-right: auto;
  }

  .footer-note {
    font-size: 0.94rem;
    line-height: 1.5;
  }

  .combo-toast {
    top: 22px;
    right: 18px;
    font-size: 0.8rem;
  }
}
