/* ==========================================================================
   NEON SNAKE — PREMIUM ARCADE STYLESHEET
   Pure Vanilla CSS with Design System Tokens, Glassmorphism, & Themes
   ========================================================================== */

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

/* ============= Reset & Variables ============= */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

:root {
  --bg-deep: #070913;
  --bg-card: rgba(15, 23, 42, 0.75);
  --bg-glass: rgba(255, 255, 255, 0.04);
  --border-glass: rgba(255, 255, 255, 0.1);
  --border-glass-hover: rgba(255, 255, 255, 0.22);

  --accent-neon: #22c55e;
  --accent-glow: rgba(34, 197, 94, 0.35);
  --accent-cyan: #06b6d4;
  --accent-purple: #a855f7;
  --accent-gold: #facc15;
  --accent-pink: #ec4899;

  --text-main: #f0eaff;
  --text-dim: rgba(240, 234, 255, 0.65);
  --text-muted: rgba(240, 234, 255, 0.35);

  --font-main: 'Outfit', sans-serif;
  --font-display: 'Orbitron', monospace;
  --font-badge: 'Fredoka', sans-serif;

  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Themes */
body[data-theme="synthwave"] {
  --bg-deep: #140924;
  --accent-neon: #ec4899;
  --accent-glow: rgba(236, 72, 153, 0.4);
  --accent-cyan: #8b5cf6;
}

body[data-theme="crt"] {
  --bg-deep: #030d06;
  --accent-neon: #22c55e;
  --accent-glow: rgba(34, 197, 94, 0.45);
  --accent-cyan: #4ade80;
}

body[data-theme="ember"] {
  --bg-deep: #120803;
  --accent-neon: #f97316;
  --accent-glow: rgba(249, 115, 22, 0.4);
  --accent-cyan: #ea580c;
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
}

/* Ambient dynamic background lighting */
.ambient-lighting {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.16;
  animation: orbDrift 20s infinite alternate ease-in-out;
}

.orb-left {
  width: 500px;
  height: 500px;
  background: var(--accent-neon);
  top: -100px;
  left: -120px;
}

.orb-right {
  width: 480px;
  height: 480px;
  background: var(--accent-cyan);
  bottom: -100px;
  right: -120px;
  animation-delay: -10s;
}

@keyframes orbDrift {
  0% { transform: scale(1) translate(0, 0); }
  50% { transform: scale(1.1) translate(25px, 20px); }
  100% { transform: scale(0.95) translate(-20px, -20px); }
}

/* CRT Scanline Overlay */
#crt-overlay {
  display: none;
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.35) 50%),
              linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
  background-size: 100% 4px, 6px 100%;
  box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.85);
}

/* ============= App Viewport ============= */
.app-viewport {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  max-width: 900px;
  margin: 0 auto;
}

/* ============= Top Navigation Bar ============= */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-arcade-back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  transition: all 0.2s var(--ease-smooth);
}

.btn-arcade-back:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-glass-hover);
  transform: translateX(-2px);
}

.btn-arcade-back svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
}

.logo-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: 1px;
  color: #ffffff;
  text-shadow: 0 0 10px var(--accent-glow);
}

.logo-icon {
  font-size: 1.1rem;
}

.theme-dropdown, .mode-dropdown {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-glass);
  border-radius: 8px;
  color: var(--text-main);
  padding: 5px 8px;
  font-size: 0.78rem;
  font-family: var(--font-main);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.theme-dropdown:hover, .mode-dropdown:hover {
  border-color: var(--border-glass-hover);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--border-glass-hover);
  transform: scale(1.05);
}

.icon-btn.active {
  background: rgba(34, 197, 94, 0.2);
  border-color: var(--accent-neon);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ============= HUD Bar ============= */
.hud-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.hud-val {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.1;
}

#hud-score {
  color: var(--accent-neon);
  text-shadow: 0 0 10px var(--accent-glow);
}

/* Dedicated HUD Pause Button */
.btn-hud-pause {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  border-radius: 20px;
  color: var(--text-main);
  padding: 5px 12px;
  font-family: var(--font-display);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
}

.btn-hud-pause:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: var(--border-glass-hover);
  transform: scale(1.04);
}

.btn-hud-pause.paused {
  background: rgba(34, 197, 94, 0.25);
  border-color: var(--accent-neon);
  color: var(--accent-neon);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* Combo badge */
.combo-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(236, 72, 153, 0.25), rgba(168, 85, 247, 0.25));
  border: 1px solid rgba(236, 72, 153, 0.5);
  box-shadow: 0 0 12px rgba(236, 72, 153, 0.4);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  color: #f472b6;
  animation: pulseCombo 0.8s infinite alternate;
}

@keyframes pulseCombo {
  0% { transform: scale(0.96); }
  100% { transform: scale(1.04); }
}

/* Time attack hud */
.timeattack-hud {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: #f59e0b;
}

/* Power-up banner */
.powerup-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 12px;
  background: rgba(168, 85, 247, 0.15);
  border: 1px solid rgba(168, 85, 247, 0.35);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #e9d5ff;
  flex-shrink: 0;
}

.powerup-bar {
  flex: 1;
  height: 5px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.powerup-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #a855f7, #ec4899);
  transition: width 0.1s linear;
}

/* ============= Game Canvas Container ============= */
.game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  position: relative;
}

.canvas-container {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 0, 0, 0.4);
  background: rgba(10, 14, 26, 0.9);
  border: 1px solid var(--border-glass);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Start Overlay */
.overlay-screen {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 20, 0.82);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  z-index: 10;
  transition: opacity 0.25s var(--ease-smooth);
}

.overlay-screen h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: #ffffff;
  text-shadow: 0 0 16px var(--accent-glow);
}

.overlay-screen p {
  color: var(--text-dim);
  font-size: 0.88rem;
  max-width: 320px;
  line-height: 1.4;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: 30px;
  background: linear-gradient(135deg, var(--accent-neon), var(--accent-cyan));
  color: #041d13;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 1px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--accent-glow);
  transition: all 0.2s var(--ease-spring);
}

.btn-primary:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 22px var(--accent-glow);
}

.btn-primary:active {
  transform: scale(0.98);
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.key-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  font-family: monospace;
}

/* ============= Mobile Virtual D-Pad ============= */
.mobile-controls {
  display: none;
  width: 100%;
  max-width: 360px;
  margin-top: 10px;
  flex-shrink: 0;
  justify-content: center;
}

.dpad-container {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 44px);
  gap: 6px;
  justify-content: center;
  align-items: center;
}

.dpad-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  border-radius: 10px;
  color: var(--text-main);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.1s;
}

.dpad-btn:active {
  background: rgba(34, 197, 94, 0.25);
  border-color: var(--accent-neon);
  transform: scale(0.92);
}

#dpad-up { grid-column: 2; grid-row: 1; }
#dpad-left { grid-column: 1; grid-row: 2; }
.dpad-pause-btn {
  grid-column: 2;
  grid-row: 2;
  font-size: 1.1rem;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}
.dpad-pause-btn:active {
  background: rgba(236, 72, 153, 0.35);
  border-color: #ec4899;
}
#dpad-right { grid-column: 3; grid-row: 2; }
#dpad-down { grid-column: 2; grid-row: 3; }

/* Show D-Pad on touch devices or smaller screens */
@media (max-width: 768px), (pointer: coarse) {
  .mobile-controls {
    display: flex;
  }
}

/* ============= Modals ============= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 14, 0.85);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.2s var(--ease-smooth);
}

.modal-overlay.hidden, .hidden {
  display: none !important;
}

.modal-content {
  background: rgba(18, 24, 44, 0.95);
  border: 1px solid var(--border-glass);
  border-radius: 20px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 30px var(--accent-glow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
  animation: modalPop 0.25s var(--ease-spring);
}

@keyframes modalPop {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 800;
  color: #ffffff;
}

.modal-subtitle {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 6px 0;
}

.stat-box {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-box-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

.stat-box-val {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-neon);
}

/* Settings Form */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.setting-item label {
  font-size: 0.85rem;
  font-weight: 500;
}

.setting-item select {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border-glass);
  border-radius: 8px;
  color: var(--text-main);
  padding: 6px 10px;
  font-size: 0.82rem;
  outline: none;
}

/* Checkbox toggle */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.12);
  transition: 0.3s;
  border-radius: 24px;
  border: 1px solid var(--border-glass);
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent-neon);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s var(--ease-spring);
  box-sizing: border-box;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: var(--border-glass-hover);
  transform: translateY(-1px);
  color: #ffffff;
}

.btn-secondary:active {
  transform: scale(0.98);
}

.btn-home-link {
  text-decoration: none;
}

/* Modal action layout containers */
.modal-actions-stacked {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 6px;
}

.modal-actions-stacked > .btn-primary {
  width: 100%;
  justify-content: center;
}

.modal-actions-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.modal-actions-row .btn-primary,
.modal-actions-row .btn-secondary {
  flex: 1;
  text-align: center;
  justify-content: center;
}

.start-actions-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

/* ============= Responsive Adjustments ============= */
@media (max-height: 680px) {
  .app-viewport {
    padding: 6px 10px;
  }
  .top-nav {
    margin-bottom: 4px;
  }
  .hud-bar {
    margin-bottom: 4px;
  }
  .dpad-container {
    grid-template-rows: repeat(3, 38px);
  }
}

@media (max-width: 680px) {
  .top-nav {
    gap: 5px;
    padding: 5px 8px;
  }
  .nav-left, .nav-right {
    gap: 4px;
  }
  .btn-arcade-back .back-text {
    display: none;
  }
  .logo-badge .title {
    font-size: 0.8rem;
    letter-spacing: 0.5px;
  }
  .mode-dropdown {
    max-width: 95px;
    font-size: 0.72rem;
    padding: 4px 6px;
  }
  .theme-dropdown {
    max-width: 82px;
    font-size: 0.72rem;
    padding: 4px 6px;
  }
  .icon-btn {
    width: 29px;
    height: 29px;
    font-size: 0.82rem;
  }
}

@media (max-width: 520px) {
  .logo-badge {
    display: none;
  }
  #btn-fullscreen {
    display: none;
  }
  .mode-dropdown {
    max-width: 86px;
    font-size: 0.7rem;
  }
  .theme-dropdown {
    max-width: 78px;
    font-size: 0.7rem;
  }
  .top-nav {
    gap: 3px;
  }
  .nav-right {
    gap: 3px;
  }
  .btn-hud-pause .pause-text {
    display: none;
  }
  .btn-hud-pause {
    padding: 4px 8px;
  }
}
