:root {
  --bg: #050816;
  --panel: rgba(7, 14, 34, 0.76);
  --panel-strong: rgba(10, 19, 46, 0.92);
  --cyan: #35f6ff;
  --mint: #45ffb4;
  --pink: #ff3df2;
  --gold: #ffd76d;
  --violet: #8a5cff;
  --danger: #ff3864;
  --text: #eff8ff;
  --muted: #9cb8cd;
  --line: rgba(53, 246, 255, 0.24);
  --shadow-cyan: 0 0 24px rgba(53, 246, 255, 0.42);
  --shadow-pink: 0 0 26px rgba(255, 61, 242, 0.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
}

.app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 520px;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(53, 246, 255, 0.18), transparent 34%),
    radial-gradient(circle at 84% 22%, rgba(255, 61, 242, 0.14), transparent 36%),
    linear-gradient(180deg, #060a1a 0%, #040713 100%);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

.ambient {
  position: absolute;
  inset: auto;
  pointer-events: none;
  z-index: 2;
  opacity: 0.4;
  filter: blur(1px);
}

.ambient-a {
  top: 12%;
  left: 5%;
  width: 26vw;
  height: 1px;
  background: var(--cyan);
  box-shadow: 0 0 42px 18px rgba(53, 246, 255, 0.13);
  animation: driftLine 8s linear infinite;
}

.ambient-b {
  right: 8%;
  bottom: 24%;
  width: 22vw;
  height: 1px;
  background: var(--pink);
  box-shadow: 0 0 38px 16px rgba(255, 61, 242, 0.1);
  animation: driftLine 10s linear infinite reverse;
}

@keyframes driftLine {
  from { transform: translateX(-20px); opacity: 0.16; }
  50% { opacity: 0.48; }
  to { transform: translateX(20px); opacity: 0.16; }
}

.hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  z-index: 5;
  display: none;
  gap: 8px;
  pointer-events: none;
}

.state-playing .hud,
.state-paused .hud,
.state-gameOver .hud {
  display: grid;
}

.hud-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-pill,
.player-chip,
.powerup-timers span {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 11, 28, 0.74);
  box-shadow: inset 0 0 20px rgba(53, 246, 255, 0.04), 0 0 18px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
}

.hud-pill span {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hud-pill strong {
  min-width: 24px;
  text-align: right;
  color: var(--cyan);
  text-shadow: var(--shadow-cyan);
}

.player-chip {
  color: var(--mint);
  font-size: 0.82rem;
  pointer-events: auto;
}

.powerup-timers {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.powerup-timers span {
  color: var(--gold);
  font-size: 0.78rem;
  min-height: 30px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 11, 28, 0.8);
  color: var(--cyan);
  box-shadow: var(--shadow-cyan);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.icon-btn:active,
.dpad-btn:active,
.primary-btn:active,
.secondary-btn:active,
.mode-card:active {
  transform: scale(0.96);
}

.screens {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(112px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 220ms ease, transform 220ms ease, visibility 220ms ease;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.state-playing .screens {
  pointer-events: none;
}

#introScreen {
  text-align: center;
  background: radial-gradient(circle at center, rgba(53, 246, 255, 0.08), transparent 48%);
}

.brand-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border: 2px solid rgba(53, 246, 255, 0.6);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--cyan);
  font-weight: 900;
  box-shadow: var(--shadow-cyan);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.65rem, 9vw, 6.5rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-shadow: 0 0 20px rgba(53, 246, 255, 0.72), 0 0 42px rgba(255, 61, 242, 0.28);
}

h2 {
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 1;
  text-shadow: var(--shadow-cyan);
}

.tagline {
  max-width: 640px;
  margin: 14px auto 0;
  color: var(--muted);
  line-height: 1.5;
}

.eyebrow {
  color: var(--mint);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
}

.snake-preview {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 28px 0;
}

.snake-preview span {
  width: 20px;
  height: 20px;
  border-radius: 7px;
  background: var(--cyan);
  box-shadow: var(--shadow-cyan);
  animation: snakePulse 1.2s ease-in-out infinite;
}

.snake-preview span:nth-child(1) { background: var(--mint); animation-delay: -0.4s; }
.snake-preview span:nth-child(2) { animation-delay: -0.3s; }
.snake-preview span:nth-child(3) { animation-delay: -0.2s; }
.snake-preview span:nth-child(4) { animation-delay: -0.1s; }

@keyframes snakePulse {
  0%, 100% { transform: translateY(0) scale(0.92); opacity: 0.62; }
  50% { transform: translateY(-10px) scale(1); opacity: 1; }
}

.screen-panel {
  width: min(96vw, 720px);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  border: 1px solid rgba(53, 246, 255, 0.28);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(8, 17, 43, 0.88), rgba(5, 9, 24, 0.84));
  box-shadow: 0 0 48px rgba(53, 246, 255, 0.12), 0 0 48px rgba(255, 61, 242, 0.08);
  backdrop-filter: blur(18px);
  padding: clamp(18px, 4vw, 34px);
  text-align: center;
}

.wide-panel {
  width: min(96vw, 980px);
}

.small-panel {
  width: min(94vw, 440px);
}

.best-grid,
.result-grid,
.guide-grid,
.mode-grid {
  display: grid;
  gap: 10px;
  margin: 24px 0;
}

.best-grid {
  grid-template-columns: repeat(3, 1fr);
}

.best-grid div,
.result-grid div,
.guide-grid div {
  min-height: 72px;
  border: 1px solid rgba(53, 246, 255, 0.18);
  border-radius: 8px;
  background: rgba(5, 11, 28, 0.68);
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 12px;
}

.best-grid span,
.result-grid span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.best-grid strong,
.result-grid strong {
  color: var(--cyan);
  font-size: 1.3rem;
}

.menu-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.menu-actions.horizontal {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.primary-btn,
.secondary-btn,
.mode-card {
  min-height: 48px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background 150ms ease;
}

.primary-btn {
  border: 1px solid rgba(53, 246, 255, 0.76);
  background: linear-gradient(135deg, rgba(53, 246, 255, 0.26), rgba(69, 255, 180, 0.16));
  color: #f6feff;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  box-shadow: var(--shadow-cyan);
  padding: 0 20px;
}

.secondary-btn {
  border: 1px solid rgba(255, 61, 242, 0.26);
  background: rgba(5, 11, 28, 0.74);
  color: var(--text);
  padding: 0 16px;
}

.primary-btn:hover,
.secondary-btn:hover,
.mode-card:hover,
.icon-btn:hover {
  border-color: rgba(53, 246, 255, 0.86);
  box-shadow: 0 0 24px rgba(53, 246, 255, 0.22);
}

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

.mode-card {
  border: 1px solid rgba(53, 246, 255, 0.22);
  background: rgba(5, 11, 28, 0.72);
  padding: 18px;
  text-align: left;
  display: grid;
  gap: 10px;
}

.mode-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--cyan);
  border: 1px solid rgba(53, 246, 255, 0.28);
  box-shadow: var(--shadow-cyan);
}

.mode-card strong {
  font-size: 1.25rem;
}

.mode-card small,
.guide-grid span {
  color: var(--muted);
  line-height: 1.4;
}

.mode-card em {
  width: fit-content;
  padding: 5px 9px;
  border: 1px solid rgba(255, 215, 109, 0.34);
  border-radius: 8px;
  color: var(--gold);
  font-style: normal;
  font-size: 0.78rem;
}

.guide-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  text-align: left;
}

.guide-grid strong {
  color: var(--cyan);
}

.submission-status {
  color: var(--gold);
  margin: 4px 0 12px;
}

.mobile-controls {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 6;
  width: 174px;
  height: 126px;
  display: none;
  transform: translateX(-50%);
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 42px);
  pointer-events: none;
}

.state-playing .mobile-controls,
.state-paused .mobile-controls {
  display: grid;
}

.dpad-btn {
  width: 52px;
  height: 38px;
  border: 1px solid rgba(53, 246, 255, 0.42);
  border-radius: 8px;
  background: rgba(5, 11, 28, 0.82);
  color: var(--cyan);
  box-shadow: var(--shadow-cyan);
  pointer-events: auto;
}

.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 3; }

.pop {
  animation: hudPop 260ms ease;
}

@keyframes hudPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@media (max-width: 720px) {
  .app {
    min-height: 560px;
  }

  .hud {
    top: max(8px, env(safe-area-inset-top));
    left: 8px;
    right: 8px;
  }

  .hud-row {
    gap: 5px;
  }

  .hud-pill {
    min-height: 30px;
    padding: 5px 7px;
    gap: 5px;
  }

  .hud-pill span {
    font-size: 0.58rem;
  }

  .hud-pill strong,
  .player-chip,
  .powerup-timers span {
    font-size: 0.72rem;
  }

  .hide-small {
    display: none;
  }

  .screen {
    padding-bottom: max(148px, env(safe-area-inset-bottom));
  }

  .screen-panel {
    padding: 18px;
  }

  .best-grid,
  .mode-grid,
  .result-grid,
  .guide-grid,
  .menu-actions.horizontal {
    grid-template-columns: 1fr;
  }

  .mode-card {
    padding: 14px;
  }
}

@media (min-width: 900px) and (pointer: fine) {
  .mobile-controls {
    display: none !important;
  }
}
