/* ========================================
   3D Particle Model Viewer - Dark Theme
   ======================================== */

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

/* CSS Variables */
:root {
  --bg-primary: #06060f;
  --bg-secondary: #0d0d1a;
  --bg-glass: rgba(12, 12, 30, 0.65);
  --bg-glass-hover: rgba(20, 20, 45, 0.75);
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-glass-hover: rgba(255, 255, 255, 0.15);

  --accent-cyan: #00f5d4;
  --accent-blue: #00bbf9;
  --accent-purple: #9b5de5;
  --accent-pink: #f15bb5;

  --glow-cyan: 0 0 20px rgba(0, 245, 212, 0.3), 0 0 60px rgba(0, 245, 212, 0.1);
  --glow-blue: 0 0 20px rgba(0, 187, 249, 0.3), 0 0 60px rgba(0, 187, 249, 0.1);
  --glow-purple: 0 0 20px rgba(155, 93, 229, 0.3);

  --text-primary: #f0f0f5;
  --text-secondary: rgba(240, 240, 245, 0.6);
  --text-muted: rgba(240, 240, 245, 0.35);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Container */
.app-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(ellipse at 20% 50%, rgba(155, 93, 229, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(0, 187, 249, 0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(0, 245, 212, 0.04) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, #0a0518 100%);
}

/* Canvas Container */
#canvas-container {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ========================================
   Toolbar
   ======================================== */
.toolbar {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: var(--transition-smooth);
  max-width: 90vw;
}

.toolbar:hover {
  border-color: var(--border-glass-hover);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* URL Input */
.url-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 280px;
}

.url-input {
  width: 100%;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.01em;
  outline: none;
  transition: var(--transition-fast);
}

.url-input::placeholder {
  color: var(--text-muted);
}

.url-input:focus {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(0, 245, 212, 0.3);
  box-shadow: 0 0 0 3px rgba(0, 245, 212, 0.08);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  color: #06060f;
  font-weight: 600;
  box-shadow: var(--glow-cyan);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 30px rgba(0, 245, 212, 0.4), 0 0 80px rgba(0, 245, 212, 0.15);
}

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

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

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

.btn-secondary.active {
  background: rgba(0, 245, 212, 0.12);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  box-shadow: 0 0 15px rgba(0, 245, 212, 0.2);
}

.btn-secondary.active:hover {
  background: rgba(0, 245, 212, 0.18);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 20px rgba(0, 245, 212, 0.3);
}

.btn-icon {
  padding: 10px;
  border-radius: var(--radius-md);
}

/* Divider */
.toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

/* File Input Hidden */
.file-input-hidden {
  display: none;
}

/* ========================================
   Webcam Preview
   ======================================== */
.webcam-container {
  position: absolute;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  transition: bottom var(--transition-smooth);
}

.webcam-container:not(.hidden) {
  bottom: 140px;
}

.webcam-preview {
  width: 220px;
  height: 165px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border-glass);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  position: relative;
  transition: var(--transition-smooth);
}

.webcam-preview:hover {
  border-color: var(--border-glass-hover);
  transform: scale(1.02);
}

.webcam-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.webcam-preview .webcam-label {
  position: absolute;
  top: 8px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  border-radius: 6px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.webcam-label .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ef4444;
  animation: pulse-dot 2s ease-in-out infinite;
}

.webcam-label .dot.active {
  background: var(--accent-cyan);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ========================================
   Gesture Status
   ======================================== */
.gesture-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition-smooth);
}

.gesture-status.active {
  border-color: rgba(0, 245, 212, 0.2);
  color: var(--accent-cyan);
}

.gesture-status .gesture-icon {
  font-size: 18px;
  transition: var(--transition-spring);
}

.gesture-status .gesture-text {
  min-width: 80px;
}

/* ========================================
   Stats Panel
   ======================================== */
.stats-panel {
  position: absolute;
  bottom: 24px;
  left: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity var(--transition-smooth), bottom var(--transition-smooth);
}

.stats-panel.visible {
  opacity: 1;
}

.stats-panel .stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stats-panel .stat-label {
  color: var(--text-muted);
}

.stats-panel .stat-value {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ========================================
   Progress Control
   ======================================== */
.progress-control {
  position: absolute;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 18px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  opacity: 0;
  transition: opacity var(--transition-smooth), bottom var(--transition-smooth);
}

.progress-control.visible {
  opacity: 1;
}

.progress-control .progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.progress-control .progress-value {
  color: var(--accent-cyan);
  font-variant-numeric: tabular-nums;
}

/* Custom Range Slider */
.progress-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 200px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  outline: none;
  cursor: pointer;
}

.progress-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  box-shadow: 0 0 10px rgba(0, 245, 212, 0.4);
  cursor: pointer;
  transition: var(--transition-fast);
}

.progress-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 16px rgba(0, 245, 212, 0.6);
}

.progress-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  box-shadow: 0 0 10px rgba(0, 245, 212, 0.4);
  cursor: pointer;
}

/* ========================================
   Loading Overlay
   ======================================== */
.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: rgba(6, 6, 15, 0.85);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

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

/* Pulse Ring Loader */
.loading-ring {
  position: relative;
  width: 80px;
  height: 80px;
}

.loading-ring .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  animation: spin-ring 1.5s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.loading-ring .ring:nth-child(1) {
  border-top-color: var(--accent-cyan);
  animation-delay: -0.45s;
}

.loading-ring .ring:nth-child(2) {
  inset: 6px;
  border-right-color: var(--accent-blue);
  animation-delay: -0.3s;
  animation-direction: reverse;
}

.loading-ring .ring:nth-child(3) {
  inset: 12px;
  border-bottom-color: var(--accent-purple);
  animation-delay: -0.15s;
}

@keyframes spin-ring {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.loading-progress {
  width: 200px;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}

.loading-progress .bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-blue), var(--accent-purple));
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
  animation: shimmer 2s linear infinite;
  background-size: 200% 100%;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ========================================
   Welcome / Intro
   ======================================== */
.welcome-hint {
  position: absolute;
  bottom: 50%;
  left: 50%;
  transform: translate(-50%, 50%);
  z-index: 50;
  text-align: center;
  pointer-events: none;
  opacity: 0.6;
  transition: opacity 1s ease;
}

.welcome-hint.hidden {
  opacity: 0;
}

.welcome-hint h2 {
  font-size: 22px;
  font-weight: 300;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.welcome-hint p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ========================================
   Notifications / Toast
   ======================================== */
.toast-container {
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toast {
  padding: 10px 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.4s var(--transition-spring) forwards;
  max-width: 400px;
  text-align: center;
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.toast.success {
  border-color: rgba(0, 245, 212, 0.3);
  color: var(--accent-cyan);
}

.toast.fade-out {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  0% { opacity: 0; transform: translateY(-10px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 1200px) {
  .toolbar {
    max-width: 95vw;
  }
  .url-input-wrapper {
    min-width: 200px;
  }
}

@media (max-width: 1024px) {
  .btn-text {
    display: none;
  }
  .btn {
    padding: 10px 12px;
  }
  .url-input-wrapper {
    min-width: 160px;
  }
  .toolbar {
    gap: 6px;
    padding: 8px 12px;
  }
}

@media (max-width: 768px) {
  .url-input-wrapper {
    min-width: 140px;
  }
  .btn {
    padding: 8px 10px;
  }
  .toolbar-divider {
    height: 16px;
  }
  .webcam-preview {
    width: 160px;
    height: 120px;
  }
  .progress-control {
    bottom: 16px;
    right: 16px;
    left: auto;
  }
  .progress-slider {
    width: 150px;
  }
  .webcam-container {
    bottom: 16px;
    right: 16px;
  }
  .webcam-container:not(.hidden) {
    bottom: 120px;
  }
}

@media (max-width: 600px) {
  .toolbar {
    top: 10px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 95vw;
    padding: 8px 10px;
    gap: 4px;
  }
  .url-input-wrapper {
    min-width: 100%;
    margin-bottom: 2px;
  }
  .toolbar-divider {
    display: none;
  }
  .settings-panel, .camera-path-panel {
    top: auto !important;
    bottom: 20px !important;
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-height: 50vh;
    overflow-y: auto;
    z-index: 150;
  }
  .stats-panel {
    bottom: 16px !important;
    left: 16px !important;
    top: auto !important;
  }
  .progress-control {
    bottom: 16px !important;
    right: 16px !important;
    left: auto !important;
  }
  .webcam-container {
    bottom: 16px !important;
    right: 16px !important;
  }
  .webcam-container:not(.hidden) {
    bottom: 120px !important;
  }
}

/* ========================================
   Scrollbar (for any overflow elements)
   ======================================== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

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

.no-select {
  user-select: none;
  -webkit-user-select: none;
}

/* ========================================
   Settings Panel
   ======================================== */
.settings-panel {
  position: absolute;
  top: 80px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: var(--bg-glass);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  width: 280px;
  transition: opacity var(--transition-smooth), transform var(--transition-smooth);
}

.settings-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
}

.settings-panel h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-item label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.setting-item select {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  transition: var(--transition-fast);
}

.setting-item select:focus {
  border-color: rgba(0, 245, 212, 0.3);
  background: rgba(20, 20, 45, 0.8);
}

.setting-item select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.setting-row-val {
  display: flex;
  justify-content: space-between;
  align-items: center;
}


.setting-val-display {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-cyan);
  font-variant-numeric: tabular-nums;
}

.settings-panel .btn {
  width: 100%;
}

/* ========================================
   Camera Path Panel
   ======================================== */
.camera-path-panel {
  position: absolute;
  top: 80px;
  left: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: var(--bg-glass);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  width: 280px;
  transition: opacity var(--transition-smooth), transform var(--transition-smooth);
}

.camera-path-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
}

.camera-path-panel h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.keyframe-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 4px;
  padding-right: 4px;
}

.keyframe-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.keyframe-item span {
  font-weight: 500;
  color: var(--text-primary);
}

.keyframe-item .btn-remove {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 12px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.keyframe-item .btn-remove:hover {
  opacity: 1;
}

/* Language Toggle Button (Top Right Plain Text) */
.lang-toggle-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  background: none;
  border: none;
  padding: 4px 0;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-smooth);
  display: flex;
  align-items: center;
  gap: 2px;
}

.lang-toggle-btn:hover {
  color: var(--text-primary);
}

.lang-toggle-btn .lang-sep {
  opacity: 0.5;
  margin: 0 1px;
}

.lang-toggle-btn .active-lang {
  color: var(--accent-cyan);
  font-weight: 600;
  text-shadow: 0 0 10px rgba(0, 245, 212, 0.5);
}

