/* ============================================
   SNAKE NEON — Premium Dark Neon Theme
   ============================================ */

/* --- CSS Variables / Design Tokens --- */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #111118;
  --bg-card: rgba(17, 17, 24, 0.85);

  --neon-cyan: #00f0ff;
  --neon-magenta: #ff00aa;
  --neon-green: #39ff14;
  --neon-yellow: #ffe600;
  --neon-orange: #ff6a00;
  --neon-purple: #b347ff;
  --neon-red: #ff3131;

  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-dim: #555570;

  --glow-cyan: 0 0 10px rgba(0, 240, 255, 0.5), 0 0 40px rgba(0, 240, 255, 0.15);
  --glow-magenta: 0 0 10px rgba(255, 0, 170, 0.5), 0 0 40px rgba(255, 0, 170, 0.15);
  --glow-green: 0 0 10px rgba(57, 255, 20, 0.5), 0 0 40px rgba(57, 255, 20, 0.15);
  --glow-red: 0 0 10px rgba(255, 49, 49, 0.5), 0 0 40px rgba(255, 49, 49, 0.15);
  --glow-orange: 0 0 10px rgba(255, 106, 0, 0.5), 0 0 40px rgba(255, 106, 0, 0.15);
  --glow-purple: 0 0 10px rgba(179, 71, 255, 0.5), 0 0 40px rgba(179, 71, 255, 0.15);

  --border-radius: 12px;
  --transition-speed: 0.3s;

  --font-display: 'Orbitron', sans-serif;
  --font-body: 'Rajdhani', sans-serif;
}

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

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  position: relative;
}

/* --- Background Particles --- */
#bg-particles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

#bg-particles::before {
  content: '';
  position: absolute;
  width: 200%;
  height: 200%;
  top: -50%;
  left: -50%;
  background: 
    radial-gradient(circle at 20% 20%, rgba(0, 240, 255, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(255, 0, 170, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(57, 255, 20, 0.02) 0%, transparent 50%);
  animation: bgFloat 20s ease-in-out infinite;
}

@keyframes bgFloat {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(-2%, -1%) rotate(1deg); }
  66% { transform: translate(1%, 2%) rotate(-1deg); }
}

/* --- App Container --- */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 12px 16px;
  gap: 10px;
}

/* --- Header --- */
#game-header {
  text-align: center;
}

#game-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-icon {
  font-size: 1.4rem;
  filter: drop-shadow(0 0 8px rgba(57, 255, 20, 0.6));
  animation: iconPulse 2s ease-in-out infinite;
}

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

.title-text {
  color: var(--text-primary);
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}

.title-neon {
  background: linear-gradient(135deg, var(--neon-cyan), var(--neon-magenta));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 12px rgba(0, 240, 255, 0.4));
}

/* --- Score Panel --- */
#score-panel {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 480px;
  justify-content: center;
}

.score-item {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid rgba(0, 240, 255, 0.12);
  border-radius: var(--border-radius);
  padding: 8px 12px;
  text-align: center;
  backdrop-filter: blur(10px);
  transition: border-color var(--transition-speed);
}

.score-item:hover {
  border-color: rgba(0, 240, 255, 0.3);
}

#score-display {
  border-color: rgba(57, 255, 20, 0.25);
}

#score-display .score-value {
  color: var(--neon-green);
  text-shadow: var(--glow-green);
}

#level-display {
  border-color: rgba(0, 240, 255, 0.25);
}

#level-display .score-value {
  color: var(--neon-cyan);
  text-shadow: var(--glow-cyan);
}

#highscore-display {
  border-color: rgba(255, 0, 170, 0.25);
}

#highscore-display .score-value {
  color: var(--neon-magenta);
  text-shadow: var(--glow-magenta);
}

.score-label {
  font-family: var(--font-display);
  font-size: 0.6rem;
  letter-spacing: 2px;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 2px;
}

.score-value {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  display: block;
  transition: transform 0.2s;
}

.score-value.bump {
  animation: scoreBump 0.3s ease-out;
}

@keyframes scoreBump {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* --- Game Container --- */
#game-container {
  position: relative;
  background: var(--bg-secondary);
  border: 2px solid rgba(0, 240, 255, 0.15);
  border-radius: var(--border-radius);
  box-shadow: 
    0 0 30px rgba(0, 240, 255, 0.05),
    inset 0 0 30px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

#game-canvas {
  display: block;
  border-radius: calc(var(--border-radius) - 2px);
}

/* --- Overlays --- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 10, 0.92);
  backdrop-filter: blur(8px);
  z-index: 10;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s, visibility 0.4s;
}

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

.overlay-content {
  text-align: center;
  padding: 32px;
  animation: overlayIn 0.5s ease-out;
}

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

.overlay-content h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 3px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--neon-cyan), var(--neon-green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px rgba(0, 240, 255, 0.3));
}

#gameover-screen .overlay-content h2 {
  background: linear-gradient(135deg, var(--neon-magenta), var(--neon-orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px rgba(255, 0, 170, 0.3));
}

.snake-art {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: snakeFloat 3s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(57, 255, 20, 0.5));
}

@keyframes snakeFloat {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-10px) rotate(5deg); }
}

.subtitle {
  font-family: var(--font-body);
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
  letter-spacing: 2px;
}

/* --- Neon Buttons --- */
.btn-neon {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 3px;
  padding: 14px 40px;
  border: 2px solid var(--neon-cyan);
  border-radius: 50px;
  background: transparent;
  color: var(--neon-cyan);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-speed);
  display: block;
  margin: 10px auto;
  text-transform: uppercase;
}

.btn-neon::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--neon-cyan), var(--neon-green));
  opacity: 0;
  transition: opacity var(--transition-speed);
  z-index: -1;
}

.btn-neon:hover {
  color: var(--bg-primary);
  box-shadow: var(--glow-cyan);
  transform: translateY(-2px);
}

.btn-neon:hover::before {
  opacity: 1;
}

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

.btn-secondary {
  border-color: var(--text-dim);
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 10px 30px;
}

.btn-secondary::before {
  background: rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  box-shadow: none;
}

/* --- Controls Hint --- */
.controls-hint {
  margin-top: 20px;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.8;
}

/* --- Final Score --- */
#final-score-container {
  margin: 16px 0;
}

.final-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.final-score {
  font-family: var(--font-display);
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--neon-magenta);
  text-shadow: var(--glow-magenta);
  line-height: 1.2;
}

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

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

/* --- Stats --- */
#stats-container {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 16px 0 20px;
}

.stat {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px 18px;
  min-width: 75px;
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-transform: uppercase;
  font-family: var(--font-display);
}

.stat-value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--neon-cyan);
  margin-top: 2px;
}

/* --- Mobile Controls --- */
#mobile-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.mobile-row {
  display: flex;
  gap: 6px;
}

.mobile-btn {
  width: 60px;
  height: 60px;
  border: 2px solid rgba(0, 240, 255, 0.25);
  border-radius: 14px;
  background: var(--bg-card);
  color: var(--neon-cyan);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
  transition: all 0.15s;
  -webkit-user-select: none;
  user-select: none;
}

.mobile-btn:active {
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-cyan);
  transform: scale(0.92);
}

#btn-pause.visible, #btn-fullscreen.visible {
  display: flex;
  align-items: center;
  justify-content: center;
}

#btn-fullscreen {
  right: 64px;
}

/* --- Landscape Warning --- */
#landscape-warning {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.warning-icon {
  font-size: 4rem;
  margin-bottom: 20px;
  animation: rotateHint 2s ease-in-out infinite;
}

@keyframes rotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

@media (max-width: 900px) and (orientation: landscape) {
  #landscape-warning {
    display: flex;
  }
}

/* --- Responsive --- */
@media (max-width: 600px) {
  #game-title {
    font-size: 1.2rem;
  }

  #mobile-controls {
    display: flex;
  }

  #app {
    padding: 8px 8px;
    gap: 6px;
  }

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

  .score-label {
    font-size: 0.5rem;
  }

  .score-item {
    padding: 6px 8px;
  }

  .overlay-content h2 {
    font-size: 1.5rem;
  }

  .final-score {
    font-size: 2.5rem;
  }

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

@media (min-width: 601px) {
  #app {
    padding: 16px;
    gap: 14px;
  }

  #game-title {
    font-size: 2rem;
  }
}

/* --- Utility Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.grid-flash {
  animation: gridFlash 0.15s ease-out;
}

@keyframes gridFlash {
  0% { filter: brightness(2); }
  100% { filter: brightness(1); }
}
