/* Core Theme Variables */
:root {
  --bg-dark: #09090c;
  --bg-gradient: radial-gradient(circle at center, #1b1929 0%, #08080c 100%);
  --panel-bg: rgba(18, 17, 26, 0.65);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-glow: rgba(0, 0, 0, 0.5);
  
  --text-main: #f3f2f8;
  --text-muted: #8e8b9e;
  
  /* Neon Accents */
  --neon-cyan: #00f2fe;
  --neon-cyan-glow: rgba(0, 242, 254, 0.4);
  --neon-pink: #ff007f;
  --neon-pink-glow: rgba(255, 0, 127, 0.4);
  --neon-gold: #ffb800;
  --neon-gold-glow: rgba(255, 184, 0, 0.4);
  --neon-green: #39ff14;
  --neon-green-glow: rgba(57, 255, 20, 0.4);
  
  --font-display: 'Fredoka', sans-serif;
  --font-sans: 'Outfit', sans-serif;
}

/* Reset and Layout */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: var(--font-sans);
  color: var(--text-main);
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-gradient);
}

/* Canvases */
#bg-canvas, #game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#bg-canvas {
  z-index: 1;
}

#game-canvas {
  z-index: 2;
  cursor: none; /* Hide default cursor when in canvas */
}

/* Glassmorphism Panel Setup */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  box-shadow: 0 24px 48px var(--panel-glow), 
              inset 0 1px 1px rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 40px;
}

/* Screens Overlay */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  opacity: 1;
  transition: opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Main Menu */
.menu-content {
  width: 90%;
  max-width: 520px;
  text-align: center;
  transform: translateY(0);
  transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.screen.hidden .menu-content {
  transform: translateY(20px);
}

.title-container {
  margin-bottom: 8px;
}

.game-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 4rem;
  line-height: 0.95;
  letter-spacing: -2px;
  color: #ffffff;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
  animation: titleFloat 4s ease-in-out infinite;
}

.glow-text {
  color: var(--neon-cyan);
  text-shadow: 0 0 15px var(--neon-cyan-glow), 0 0 30px var(--neon-cyan-glow);
  background: linear-gradient(135deg, var(--neon-cyan) 0%, #0099ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

.subtitle {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-top: 16px;
  letter-spacing: 0.5px;
}

/* Controls Selection Panel */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 24px;
  border-radius: 16px;
}

.controls-panel h3 {
  font-size: 0.9rem;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.mode-buttons {
  display: flex;
  gap: 12px;
}

.mode-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 16px 12px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.mode-btn .icon {
  font-size: 1.8rem;
  filter: grayscale(100%) opacity(0.6);
  transition: all 0.3s ease;
}

.mode-btn .btn-text {
  font-weight: 700;
  font-size: 0.95rem;
}

.mode-btn .btn-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-main);
}

.mode-btn.active {
  background: rgba(0, 242, 254, 0.08);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 15px rgba(0, 242, 254, 0.2);
  color: var(--text-main);
}

.mode-btn.active .icon {
  filter: none;
  transform: scale(1.1);
}

.mode-btn#mode-camera-btn.active {
  background: rgba(255, 0, 127, 0.08);
  border-color: var(--neon-pink);
  box-shadow: 0 0 15px rgba(255, 0, 127, 0.2);
}

/* Camera loading indicator */
.camera-loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-top: 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.camera-loading-box p {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.camera-loading-box .tip {
  font-size: 0.75rem;
  color: var(--neon-pink);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--neon-pink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Action Buttons */
.action-btn {
  width: 100%;
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 1.25rem;
  padding: 18px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  text-transform: uppercase;
}

.play-btn {
  background: linear-gradient(135deg, var(--neon-cyan) 0%, #0072ff 100%);
  color: #000;
  font-weight: 900;
  box-shadow: 0 8px 24px rgba(0, 242, 254, 0.3);
}

.play-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 242, 254, 0.5), 0 0 10px var(--neon-cyan);
}

.play-btn:active {
  transform: translateY(1px);
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.setting-icon-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.1rem;
  transition: all 0.2s ease;
}

.setting-icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(1.05);
}

.high-score-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.high-score-label span {
  color: var(--neon-gold);
  font-size: 1.1rem;
}

/* Gameplay HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 24px 40px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#hud.hidden {
  opacity: 0;
}

.score-container {
  display: flex;
  flex-direction: column;
}

.hud-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.label {
  font-size: 0.8rem;
  letter-spacing: 2px;
  color: var(--text-muted);
  font-weight: 700;
}

.value {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
}

#score-val {
  color: var(--text-main);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

/* Mode Badges */
.mode-badge {
  background: rgba(255, 0, 127, 0.12);
  border: 1px solid var(--neon-pink);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--neon-pink);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 0 10px rgba(255, 0, 127, 0.2);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: var(--neon-pink);
  border-radius: 50%;
  animation: beaconPulse 1.2s infinite;
}

/* Lives Display */
.lives-display {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.heart {
  font-size: 1.8rem;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  opacity: 0.25;
  filter: grayscale(100%);
  transform: scale(0.85);
}

.heart.active {
  opacity: 1;
  filter: none;
  transform: scale(1);
  text-shadow: 0 0 10px rgba(255, 0, 0, 0.3);
}

/* Combos Popup */
.combo-popup {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.8rem;
  text-transform: uppercase;
  font-style: italic;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-20px) scale(0.9);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.combo-popup.show {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.combo-3 {
  color: var(--neon-cyan);
  text-shadow: 0 0 10px var(--neon-cyan-glow);
}
.combo-4 {
  color: var(--neon-gold);
  text-shadow: 0 0 10px var(--neon-gold-glow);
}
.combo-5 {
  color: var(--neon-green);
  text-shadow: 0 0 10px var(--neon-green-glow);
}
.combo-multi {
  color: var(--neon-pink);
  text-shadow: 0 0 10px var(--neon-pink-glow);
}

/* Webcam Preview Box */
#webcam-container {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 160px;
  height: 120px;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--neon-pink);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 15px var(--neon-pink-glow);
  z-index: 4;
  transform: scaleX(-1); /* Mirror camera preview naturally */
  transition: opacity 0.3s ease;
  pointer-events: none;
}

#webcam-container.hidden {
  opacity: 0;
}

#webcam {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.webcam-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, transparent 40%, rgba(0,0,0,0.4) 100%);
}

.tracking-status {
  position: absolute;
  bottom: 6px;
  left: 6px;
  transform: scaleX(-1); /* Correct the mirroring text */
  background: rgba(0, 0, 0, 0.7);
  color: var(--neon-cyan);
  font-size: 0.6rem;
  font-weight: 800;
  padding: 3px 6px;
  border-radius: 6px;
  letter-spacing: 0.5px;
  border: 1px solid var(--neon-cyan-glow);
}

/* Game Over Screen Customizations */
.game-over-panel {
  max-width: 440px;
  border-color: rgba(255, 0, 127, 0.2);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.7), 0 0 30px rgba(255, 0, 127, 0.1);
}

.game-over-title {
  font-family: var(--font-display);
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -1px;
}

.glow-red {
  color: #ff3b30;
  text-shadow: 0 0 15px rgba(255, 59, 48, 0.4), 0 0 30px rgba(255, 59, 48, 0.2);
  background: linear-gradient(135deg, #ff0055 0%, #ff3b30 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

.score-summary {
  display: flex;
  gap: 24px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 20px;
  border-radius: 16px;
}

.summary-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.summary-item .value {
  font-size: 2.2rem;
  margin-top: 4px;
}

.new-high-score {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--neon-gold);
  text-shadow: 0 0 10px var(--neon-gold-glow);
  animation: pulseScale 1s ease-in-out infinite alternate;
}

.restart-btn {
  background: linear-gradient(135deg, var(--neon-green) 0%, #00cc44 100%);
  color: #000;
  font-weight: 900;
  box-shadow: 0 8px 24px rgba(57, 255, 20, 0.3);
}

.restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(57, 255, 20, 0.5), 0 0 10px var(--neon-green);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  font-size: 1rem;
  padding: 14px;
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Utility Hidden Class */
.hidden {
  display: none !important;
}

/* Animations */
@keyframes titleFloat {
  0%, 100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-8px) rotate(1deg);
  }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes beaconPulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(255, 0, 127, 0.7);
  }
  70% {
    transform: scale(1.1);
    box-shadow: 0 0 0 8px rgba(255, 0, 127, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(255, 0, 127, 0);
  }
}

@keyframes pulseScale {
  0% {
    transform: scale(0.95);
  }
  100% {
    transform: scale(1.05);
  }
}

/* Responsive Scaling */
@media (max-width: 600px) {
  .game-title {
    font-size: 3rem;
  }
  .menu-content {
    padding: 24px;
    gap: 20px;
  }
  #hud {
    padding: 16px 20px;
  }
  #webcam-container {
    width: 120px;
    height: 90px;
    top: 16px;
    right: 16px;
  }
}

/* Custom Cursor Follower for Mouse/Touch Controls */
#custom-cursor {
  position: fixed;
  width: 48px;
  height: 48px;
  font-size: 2.8rem;
  pointer-events: none;
  z-index: 10000;
  transform: translate(-30%, -70%) rotate(-45deg);
  text-shadow: 0 0 12px var(--neon-cyan-glow), 0 0 25px var(--neon-cyan-glow);
  filter: drop-shadow(0 0 8px var(--neon-cyan-glow));
  user-select: none;
  -webkit-user-select: none;
}

/* Hide cursor when Mouse controls are active */
.mouse-controls-active,
.mouse-controls-active * {
  cursor: none !important;
}
