/* ============================================
   NEON SNAKE - Design System & Styles
   ============================================ */

/* === CSS Variables / Design Tokens === */
:root {
  /* Colors */
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-card: rgba(18, 18, 42, 0.85);

  --neon-green: #39ff14;
  --neon-green-glow: rgba(57, 255, 20, 0.4);
  --neon-cyan: #00f0ff;
  --neon-cyan-glow: rgba(0, 240, 255, 0.35);
  --neon-pink: #ff2d95;
  --neon-pink-glow: rgba(255, 45, 149, 0.4);
  --neon-purple: #b84dff;
  --neon-yellow: #ffe156;
  --neon-orange: #ff6b35;

  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --text-muted: #555577;

  /* Grid */
  --grid-line: rgba(57, 255, 20, 0.06);
  --grid-border: rgba(57, 255, 20, 0.15);

  /* Spacing */
  --gap-xs: 4px;
  --gap-sm: 8px;
  --gap-md: 16px;
  --gap-lg: 24px;
  --gap-xl: 40px;

  /* Typography */
  --font-display: 'Orbitron', monospace, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;

  /* Borders */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 300ms ease;
  --transition-slow: 500ms ease;
}

/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* === Animated Background === */
#particles {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

#particles::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(57, 255, 20, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(0, 240, 255, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(255, 45, 149, 0.03) 0%, transparent 50%);
  animation: bgDrift 20s ease-in-out infinite alternate;
}

@keyframes bgDrift {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(-5%, 3%) rotate(3deg); }
}

/* === Game Container === */
#game-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-md);
  padding: var(--gap-md);
  max-width: 100vw;
}

/* === Header === */
#game-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-md);
  width: 100%;
}

#game-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0.15em;
  background: linear-gradient(135deg, var(--neon-green), var(--neon-cyan));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 0 20px var(--neon-green-glow));
  animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {
  0%, 100% { filter: drop-shadow(0 0 20px var(--neon-green-glow)); }
  50% { filter: drop-shadow(0 0 35px var(--neon-cyan-glow)); }
}

/* === Stats Bar === */
#stats-bar {
  display: flex;
  gap: var(--gap-lg);
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--grid-border);
  border-radius: var(--radius-lg);
  padding: var(--gap-sm) var(--gap-lg);
  box-shadow:
    0 0 20px rgba(57, 255, 20, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 70px;
}

.stat-label {
  font-family: var(--font-display);
  font-size: 0.6rem;
  font-weight: 400;
  letter-spacing: 0.2em;
  color: var(--text-secondary);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--neon-green);
  text-shadow: 0 0 10px var(--neon-green-glow);
  transition: transform var(--transition-fast), color var(--transition-fast);
}

.stat-value.pop {
  transform: scale(1.3);
  color: var(--neon-yellow);
}

#best-display .stat-value {
  color: var(--neon-cyan);
  text-shadow: 0 0 10px var(--neon-cyan-glow);
}

#level-display .stat-value {
  color: var(--neon-purple);
  text-shadow: 0 0 10px rgba(184, 77, 255, 0.4);
}

/* === Game Area === */
#game-area {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 2px solid var(--grid-border);
  box-shadow:
    0 0 40px rgba(57, 255, 20, 0.08),
    0 0 80px rgba(57, 255, 20, 0.04),
    inset 0 0 60px rgba(0, 0, 0, 0.3);
  background: var(--bg-secondary);
}

#game-canvas {
  display: block;
}

/* === Overlays === */
.overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(5, 5, 15, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
  animation: fadeIn 0.3s ease;
}

.overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-md);
}

.overlay-content h2 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  background: linear-gradient(135deg, var(--neon-green), var(--neon-cyan));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 15px var(--neon-green-glow));
}

.overlay-content p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.8;
}

.snake-icon {
  font-size: 3.5rem;
  animation: snakeBounce 2s ease-in-out infinite;
}

@keyframes snakeBounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-8px) rotate(-5deg); }
  75% { transform: translateY(-4px) rotate(5deg); }
}

kbd {
  display: inline-block;
  background: rgba(57, 255, 20, 0.1);
  border: 1px solid rgba(57, 255, 20, 0.25);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-family: var(--font-display);
  font-size: 0.75rem;
  color: var(--neon-green);
  margin: 0 2px;
}

.mobile-hint {
  font-size: 0.8rem !important;
  color: var(--text-muted) !important;
}

/* === Neon Button === */
.neon-btn {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--bg-primary);
  background: linear-gradient(135deg, var(--neon-green), var(--neon-cyan));
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 40px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-normal);
  box-shadow:
    0 0 20px var(--neon-green-glow),
    0 0 40px rgba(57, 255, 20, 0.15);
  text-transform: uppercase;
}

.neon-btn:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow:
    0 0 30px var(--neon-green-glow),
    0 0 60px rgba(57, 255, 20, 0.2),
    0 5px 20px rgba(0, 0, 0, 0.3);
}

.neon-btn:active {
  transform: translateY(0) scale(0.98);
}

.neon-btn::after {
  content: '';
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: linear-gradient(
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transform: rotate(45deg);
  transition: all 0.6s;
  opacity: 0;
}

.neon-btn:hover::after {
  opacity: 1;
  animation: btnShine 0.6s ease;
}

@keyframes btnShine {
  from { transform: rotate(45deg) translateY(100%); }
  to { transform: rotate(45deg) translateY(-100%); }
}

/* === Game Over specific === */
.final-score-label {
  font-size: 0.8rem !important;
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

.final-score {
  font-family: var(--font-display);
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--neon-green);
  text-shadow: 0 0 30px var(--neon-green-glow);
  animation: scoreReveal 0.6s ease-out;
}

@keyframes scoreReveal {
  from {
    transform: scale(0.5);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.new-record {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--neon-yellow);
  text-shadow: 0 0 15px rgba(255, 225, 86, 0.5);
  animation: recordPulse 1s ease-in-out infinite;
}

.new-record.hidden {
  display: none;
}

@keyframes recordPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.05); }
}

/* === Footer === */
#game-footer {
  display: flex;
  gap: var(--gap-lg);
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

#speed-indicator {
  font-family: var(--font-display);
  font-size: 0.7rem;
  color: var(--text-secondary);
  letter-spacing: 0.1em;
}

/* === Canvas Food Particle Effect (managed via JS) === */

/* === Responsive === */
@media (max-width: 600px) {
  #game-container {
    padding: var(--gap-sm);
    gap: var(--gap-sm);
  }

  #stats-bar {
    gap: var(--gap-md);
    padding: var(--gap-sm) var(--gap-md);
  }

  .stat-value {
    font-size: 1.1rem;
  }

  .stat-item {
    min-width: 55px;
  }

  #game-footer {
    font-size: 0.65rem;
    gap: var(--gap-md);
  }

  .overlay-content p {
    font-size: 0.8rem;
    padding: 0 var(--gap-md);
  }

  .neon-btn {
    padding: 12px 32px;
    font-size: 0.85rem;
  }

  .mobile-hint {
    display: block;
  }
}

@media (min-width: 601px) {
  .mobile-hint {
    display: none;
  }
}

/* === Screen-shake animation for game over === */
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-4px, -2px); }
  20% { transform: translate(4px, 2px); }
  30% { transform: translate(-3px, 3px); }
  40% { transform: translate(3px, -3px); }
  50% { transform: translate(-2px, 2px); }
  60% { transform: translate(2px, -1px); }
  70% { transform: translate(-1px, 1px); }
  80% { transform: translate(1px, -1px); }
  90% { transform: translate(-1px, 0px); }
}

.shake {
  animation: shake 0.4s ease-in-out;
}

/* === Floating Back to Portal Button === */
.back-home-btn {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(10, 10, 26, 0.75);
  border: 1px solid var(--neon-cyan, #00d4ff);
  border-radius: 20px;
  color: var(--neon-cyan, #00d4ff);
  font-family: var(--font-display, 'Orbitron'), monospace;
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.1em;
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.2), inset 0 0 4px rgba(0, 212, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.25s ease;
  cursor: pointer;
}

.back-home-btn:hover {
  background: var(--neon-cyan, #00d4ff);
  color: #050510;
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.45);
  transform: translateY(-1.5px);
}

.back-home-btn:active {
  transform: translateY(0);
}

@media (max-width: 600px) {
  .back-home-btn {
    top: 12px;
    left: 12px;
    padding: 6px 12px;
    font-size: 0.65rem;
  }
}
