@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Inter:wght@300;400;600&display=swap');

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --neon-green: #00ff88;
  --neon-blue: #00d4ff;
  --neon-purple: #a855f7;
  --bg-dark: #050a0e;
  --bg-mid: #0a1628;
  --bg-card: rgba(0,255,136,0.06);
  --border-glow: rgba(0,255,136,0.3);
  --text-primary: #e2f8ef;
  --text-muted: #7aada0;
}

body, html {
  height: 100%;
  background: var(--bg-dark);
  font-family: 'Inter', sans-serif;
  overflow: hidden;
}

/* Background grid lines */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,255,136,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,255,136,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.background {
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 0;
  position: relative;
  z-index: 1;
  padding: 10px;
}

/* ── Game wrapper ── */
.game_template {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(90vw, 480px);
  max-height: 98vh;
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from { opacity:0; transform:translateY(16px); }
  to   { opacity:1; transform:translateY(0); }
}

/* ── Scoreboard ── */
.score_board {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  padding: 8px 16px;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 20px rgba(0,255,136,0.1), inset 0 1px 0 rgba(255,255,255,0.05);
}

.score_board img { width: 28px; height: 28px; border-radius: 4px; }

.score_, .highScore_ {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Orbitron', monospace;
  font-weight: 700;
  color: var(--neon-green);
  text-shadow: 0 0 10px rgba(0,255,136,0.6);
  font-size: 1.1rem;
  transition: text-shadow 0.3s;
}

.highScore.hs-glow {
  color: #ffd700;
  text-shadow: 0 0 16px rgba(255,215,0,0.9);
  animation: hsPulse 0.6s ease;
}

@keyframes hsPulse {
  0%,100%{transform:scale(1);}
  50%{transform:scale(1.25);}
}

.score_label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: 'Orbitron', monospace;
}

.mid-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.brand-logo {
  font-family: 'Orbitron', monospace;
  font-size: 0.7rem;
  font-weight: 900;
  color: var(--neon-purple);
  text-shadow: 0 0 12px rgba(168,85,247,0.6);
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ── Streak badge ── */
.streak-badge {
  font-family: 'Orbitron', monospace;
  font-size: 0.6rem;
  font-weight: 900;
  color: #f59e0b;
  text-shadow: 0 0 8px rgba(245,158,11,0.8);
  letter-spacing: 1px;
  opacity: 0;
  transition: opacity 0.3s;
}

.streak-badge.pop {
  animation: popAnim 0.25s ease;
}

@keyframes popAnim {
  0%  { transform: scale(1); }
  50% { transform: scale(1.5); }
  100%{ transform: scale(1); }
}

/* ── Game canvas/grid ── */
.main {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: rgba(0,20,10,0.85);
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  grid-template-rows: repeat(20, 1fr);
  box-shadow: 0 0 40px rgba(0,255,136,0.12), inset 0 0 60px rgba(0,0,0,0.5);
  position: relative;
  overflow: hidden;
}

.main::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,255,136,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,255,136,0.015) 1px, transparent 1px);
  background-size: 5% 5%;
  pointer-events: none;
}

/* ── Snake segments ── */
.head {
  background: var(--neon-green);
  border-radius: 30%;
  box-shadow: 0 0 8px var(--neon-green), 0 0 20px rgba(0,255,136,0.5);
  position: relative;
  z-index: 2;
}

.body {
  background: linear-gradient(135deg, #00cc6a, #008844);
  border-radius: 25%;
  margin: 1px;
  box-shadow: 0 0 4px rgba(0,255,136,0.4);
  z-index: 1;
}

.food {
  background: radial-gradient(circle at 35% 35%, #ff6b6b, #e02020);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(255,60,60,0.8), 0 0 20px rgba(255,60,60,0.4);
  animation: foodPulse 1s ease-in-out infinite alternate;
  margin: 1px;
}

/* Bonus golden food */
.bonus-food {
  background: radial-gradient(circle at 35% 35%, #ffd700, #f59e0b) !important;
  box-shadow: 0 0 12px rgba(255,215,0,0.9), 0 0 24px rgba(245,158,11,0.5) !important;
  animation: bonusPulse 0.5s ease-in-out infinite alternate !important;
}

@keyframes bonusPulse {
  from { box-shadow: 0 0 8px rgba(255,215,0,0.7); transform: scale(0.85); }
  to   { box-shadow: 0 0 20px rgba(255,215,0,1); transform: scale(1.15); }
}

@keyframes foodPulse {
  from { box-shadow: 0 0 6px rgba(255,60,60,0.6); transform: scale(0.9); }
  to   { box-shadow: 0 0 14px rgba(255,60,60,1); transform: scale(1.05); }
}

/* ── Speed selector ── */
.speed-selector {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.speed-btn {
  flex: 1;
  min-width: 60px;
  padding: 6px 10px;
  border: 1px solid rgba(0,255,136,0.25);
  border-radius: 8px;
  background: rgba(0,255,136,0.04);
  color: var(--text-muted);
  font-family: 'Orbitron', monospace;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}

.speed-btn:hover, .speed-btn.active {
  background: rgba(0,255,136,0.15);
  border-color: var(--neon-green);
  color: var(--neon-green);
  box-shadow: 0 0 10px rgba(0,255,136,0.3);
}

/* Wrap toggle button */
.wrap-btn {
  border-color: rgba(168,85,247,0.3) !important;
  background: rgba(168,85,247,0.05) !important;
  color: rgba(168,85,247,0.7) !important;
}

.wrap-btn.active {
  background: rgba(168,85,247,0.2) !important;
  border-color: var(--neon-purple) !important;
  color: var(--neon-purple) !important;
  box-shadow: 0 0 10px rgba(168,85,247,0.4) !important;
}

/* ── D-pad (mobile) ── */
.dpad {
  display: none;
  grid-template-areas: '. u .' 'l . r' '. d .';
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  justify-content: center;
  width: 140px;
  margin: 4px auto 0;
}

.dpad-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-glow);
  border-radius: 10px;
  background: rgba(0,255,136,0.08);
  color: var(--neon-green);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.dpad-btn:active {
  background: rgba(0,255,136,0.25);
  box-shadow: 0 0 12px rgba(0,255,136,0.4);
  transform: scale(0.93);
}

.dpad-up    { grid-area: u; }
.dpad-left  { grid-area: l; }
.dpad-right { grid-area: r; }
.dpad-down  { grid-area: d; }

/* ── Pause hint ── */
.pause-hint {
  text-align: center;
  font-size: 0.6rem;
  color: var(--text-muted);
  font-family: 'Orbitron', monospace;
  letter-spacing: 1px;
  opacity: 0.6;
}

/* ── Game over overlay ── */
.game-over-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 10;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.game-over-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.game-over-title {
  font-family: 'Orbitron', monospace;
  font-size: 1.8rem;
  font-weight: 900;
  color: #ff4444;
  text-shadow: 0 0 20px rgba(255,68,68,0.8);
  text-transform: uppercase;
  letter-spacing: 3px;
  animation: glitch 0.4s ease-in-out;
}

@keyframes glitch {
  0%,100% { transform: translate(0); }
  20% { transform: translate(-3px, 1px); }
  40% { transform: translate(3px, -1px); }
  60% { transform: translate(-2px, 2px); }
  80% { transform: translate(2px, -2px); }
}

.game-over-score {
  font-family: 'Orbitron', monospace;
  font-size: 0.9rem;
  color: var(--neon-green);
  text-shadow: 0 0 10px rgba(0,255,136,0.6);
}

.restart-btn {
  padding: 10px 28px;
  border: 1px solid var(--neon-green);
  border-radius: 8px;
  background: rgba(0,255,136,0.1);
  color: var(--neon-green);
  font-family: 'Orbitron', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.2s;
  box-shadow: 0 0 15px rgba(0,255,136,0.2);
}

.restart-btn:hover {
  background: rgba(0,255,136,0.25);
  box-shadow: 0 0 25px rgba(0,255,136,0.5);
  transform: scale(1.05);
}

/* ── Paused state ── */
.paused-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Orbitron', monospace;
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--neon-blue);
  text-shadow: 0 0 20px rgba(0,212,255,0.8);
  text-transform: uppercase;
  letter-spacing: 4px;
  display: none;
  z-index: 9;
}

/* ── Mobile responsiveness ── */
@media (max-width: 600px) {
  .background { padding: 6px; }
  .game_template { width: 100%; gap: 6px; }
  .dpad { display: grid; }
  .pause-hint { display: none; }
  .score_, .highScore_ { font-size: 0.9rem; }
  .brand-logo { font-size: 0.6rem; }
}

@media (hover: none) and (pointer: coarse) {
  .dpad { display: grid; }
}