/* CSS Variables & Theme Setup */
:root {
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  
  /* Color Palette */
  --bg-dark: #08090f;
  --panel-bg: rgba(13, 15, 27, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-neon-cyan: rgba(0, 240, 255, 0.3);
  --border-neon-pink: rgba(255, 0, 127, 0.3);
  
  --neon-cyan: #00f0ff;
  --neon-pink: #ff007f;
  --neon-green: #39ff14;
  --neon-yellow: #fff01f;
  --text-primary: #ffffff;
  --text-secondary: #a4b3c6;
  
  /* Blurs & Shadows */
  --glass-blur: 16px;
  --shadow-neon-cyan: 0 0 15px rgba(0, 240, 255, 0.4);
  --shadow-neon-pink: 0 0 15px rgba(255, 0, 127, 0.4);
  --shadow-neon-green: 0 0 15px rgba(57, 255, 20, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

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

#app {
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* Glassmorphism Styles */
.glass-card {
  background: var(--panel-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  padding: 2.5rem;
  transition: all 0.3s ease;
}

/* Screens */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 10;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
}

/* Lobby / Start Screen styling */
#lobby-screen {
  background: radial-gradient(circle at center, #1b1130 0%, #08090f 100%);
}

.main-lobby {
  width: 90%;
  max-width: 580px;
  text-align: center;
  border-color: var(--border-neon-cyan);
  box-shadow: var(--shadow-neon-cyan);
}

.logo {
  font-size: 3.5rem;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--neon-cyan), var(--neon-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 2rem;
  line-height: 1.5;
}

/* Loading Widget */
.loading-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 1.5rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--neon-cyan);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

#loading-status {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Premium Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0.85rem 1.8rem;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  outline: none;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn.primary {
  background: var(--neon-cyan);
  color: #000;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}

.btn.primary:hover:not(.disabled) {
  background: #ffffff;
  box-shadow: var(--shadow-neon-cyan);
  transform: translateY(-2px);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

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

.btn.primary-outline {
  background: transparent;
  color: var(--neon-cyan);
  border: 1px dashed var(--neon-cyan);
}

.btn.primary-outline:hover {
  background: rgba(0, 240, 255, 0.1);
}

.btn.disabled, .btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.lobby-controls {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* Game Screen Layout */
#game-screen {
  background-color: #030407;
  position: relative;
}

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

/* Heads-Up Display (HUD) */
.hud {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 20;
}

.hud-player-panel {
  display: flex;
  gap: 12px;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.hud-player-panel.standby {
  opacity: 0.4;
}

.hud-item {
  background: rgba(8, 9, 15, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  padding: 0.8rem 1.5rem;
  border-radius: 12px;
  min-width: 120px;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.hud-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

.hud-val {
  font-size: 1.8rem;
  font-weight: 900;
  font-family: monospace;
}

.hud-lives-container {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.life-heart {
  width: 22px;
  height: 22px;
  color: var(--neon-pink);
  fill: var(--neon-pink);
  filter: drop-shadow(0 0 4px var(--neon-pink));
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.life-heart.lost {
  opacity: 0.2;
  fill: transparent;
  transform: scale(0.85);
  filter: none;
}

.neon-green {
  color: var(--neon-green);
  text-shadow: 0 0 10px rgba(57, 255, 20, 0.5);
}

.neon-blue {
  color: var(--neon-cyan);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.neon-yellow {
  color: var(--neon-yellow);
  text-shadow: 0 0 10px rgba(255, 240, 31, 0.5);
}

.game-hud-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 12px;
  z-index: 20;
}

.hud-icon-btn {
  background: rgba(8, 9, 15, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
}

.hud-icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
}

.hud-icon-btn.critical:hover {
  border-color: var(--neon-pink);
  color: var(--neon-pink);
}

/* Drag/Floating Debug Camera Window */
.debug-window {
  position: absolute;
  top: 80px;
  right: 20px;
  width: 260px;
  background: rgba(8, 9, 15, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid var(--neon-pink);
  border-radius: 12px;
  overflow: hidden;
  z-index: 100;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  display: none; /* Toggled on/off */
  flex-direction: column;
}

.debug-window.active {
  display: flex;
}

.debug-header {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: move;
}

.debug-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}

.debug-close-btn:hover {
  color: var(--neon-pink);
}

.debug-body {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
}

#webcam {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror camera */
  display: none; /* Keep element rendering but hide visuals, debug canvas shows output */
}

#debug-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  transform: scaleX(-1); /* Mirror render as well */
}

.debug-stats {
  padding: 8px 12px;
  font-size: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.05);
  background: rgba(0,0,0,0.4);
}

.neon-red {
  color: var(--neon-pink);
  font-weight: bold;
}

/* Config & Setting Overlays */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 4, 7, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 200;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.config-card {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border: none;
  border-radius: 0;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* Two-column layout for full-screen config panel */
.config-columns-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  margin-top: 1rem;
}

.config-column {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

@media (max-width: 768px) {
  .config-columns-layout {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

.config-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 0.8rem;
}

.config-header h2 {
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover {
  color: var(--neon-pink);
}

.config-body {
  overflow-y: auto;
  flex: 1;
  padding-right: 8px;
}

/* Config Tabs */
.config-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  padding-bottom: 10px;
}

.tab-btn {
  background: none;
  border: none;
  outline: none;
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
  position: relative;
  transition: color 0.2s ease;
}

.tab-btn.active {
  color: var(--neon-cyan);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -11px;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--neon-cyan);
  box-shadow: 0 0 8px var(--neon-cyan);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Forms styling */
.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.form-group input, .form-group select {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.75rem;
  border-radius: 8px;
  color: #fff;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.2);
}

.help-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Themes Manager inside Config */
.add-theme-form {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.add-theme-form h3 {
  font-size: 0.95rem;
  margin-bottom: 0.8rem;
}

.form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.form-row input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  color: #fff;
  font-size: 0.85rem;
  outline: none;
}

.form-row input:focus {
  border-color: var(--neon-pink);
}

.themes-list-container h3 {
  font-size: 1rem;
  margin-bottom: 0.8rem;
}

.themes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.themes-table th, .themes-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.themes-table th {
  font-weight: 700;
  color: var(--text-secondary);
}

.status-badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}

.status-badge.downloaded {
  background: rgba(57, 255, 20, 0.15);
  color: var(--neon-green);
  border: 1px solid rgba(57, 255, 20, 0.2);
}

.status-badge.listed {
  background: rgba(255, 240, 31, 0.15);
  color: var(--neon-yellow);
  border: 1px solid rgba(255, 240, 31, 0.2);
}

.sync-btn {
  background: transparent;
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: bold;
}

.sync-btn:hover {
  background: rgba(0, 240, 255, 0.1);
}

.config-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  justify-content: flex-end;
}

/* HUD level up / warnings */
.game-overlay-message {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  pointer-events: none;
  z-index: 30;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.game-overlay-message.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.1);
}

#overlay-text {
  font-size: 4rem;
  font-weight: 900;
  letter-spacing: 5px;
  color: #fff;
  text-shadow: 0 0 20px var(--neon-cyan), 0 0 40px var(--neon-cyan);
  text-align: center;
  animation: pulse 1.5s infinite alternate;
}

/* Game Over Card */
#game-over-screen {
  background: rgba(8, 9, 15, 0.9);
}

.game-over-card {
  width: 90%;
  max-width: 480px;
  text-align: center;
  border-color: var(--border-neon-pink);
  box-shadow: var(--shadow-neon-pink);
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.critical-text {
  color: var(--neon-pink);
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: 2px;
  text-shadow: 0 0 10px rgba(255, 0, 127, 0.4);
}

.game-over-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.final-score-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 1.2rem;
  margin: 10px 0;
}

.final-score-box .label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: bold;
}

.final-score-box .val {
  font-size: 2.5rem;
  font-weight: 900;
}

/* Animations */
@keyframes spin {
  100% { transform: rotate(360deg); }
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.05); opacity: 1; }
}
