/**
 * Experimental Pages — Phase 5
 *
 * Shared styles that retheme all experimental/3D pages to use the
 * Night Trail design system tokens. These override the inline styles
 * on control panels, HUDs, buttons, sliders, and canvas containers
 * without touching page-specific layout logic.
 *
 * Targets common class patterns found across:
 *   energy-terrain, mountain-climb, pace-tunnel, race-replay,
 *   body-systems, lap-clock, analytics-lab, race-time-machine, catlap-vr
 */

/* ============================================================
   Labs Badge — shown next to page title on experimental pages
   ============================================================ */

.labs-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 10px;
  font-size: 11px;
  font-weight: var(--font-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-subtle);
  border: 1px solid rgba(155, 61, 230, 0.2);
  border-radius: var(--radius-pill);
  vertical-align: middle;
  margin-left: var(--space-2);
}

.labs-badge::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* ============================================================
   Experimental Page Layout
   ============================================================ */

/* Full-viewport canvas mode — 3D canvas fills available space */
.exp-layout {
  display: flex;
  gap: var(--space-4);
  min-height: calc(100vh - 52px - var(--space-6) * 2);
}

.exp-layout--fullscreen {
  position: relative;
  margin: calc(var(--space-6) * -1);
  min-height: calc(100vh - 52px);
}

/* Canvas area */
.exp-layout__canvas {
  flex: 1;
  min-width: 0;
  position: relative;
}

/* Side panel for controls */
.exp-layout__panel {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow-y: auto;
  max-height: calc(100vh - 52px - var(--space-6) * 2);
}

@media (max-width: 1023px) {
  .exp-layout {
    flex-direction: column;
  }
  .exp-layout__panel {
    width: 100%;
    max-height: none;
  }
}

/* ============================================================
   Canvas/Viewer Containers — restyle existing classes
   ============================================================ */

.terrain-viewer,
.mountain-viewer,
.visualization-panel,
.theater-panel,
.tunnel-viewer,
.clock-viewer {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}

/* ============================================================
   Control Panels — restyle .sidebar, .control-panel, .panel
   ============================================================ */

/* Sidebar-style control panels (energy-terrain, mountain-climb) */
.sidebar:not(.sidebar--expanded):not(.sidebar--collapsed) {
  /* Only target page-level .sidebar, not the nav sidebar */
}

/* Panel cards used inside control sections */
.panel,
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  transition: border-color var(--transition-fast) ease;
}

.panel:hover,
.panel-card:hover {
  border-color: var(--border-strong);
}

/* Panel titles */
.panel-title,
.panel-card h3,
.panel h3,
.section-title {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-3);
}

/* Panel labels */
.panel-card label,
.panel label,
.control-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: var(--font-medium);
}

/* Panel values */
.panel-card .value,
.stat-value,
.metric-value {
  font-family: var(--font-condensed);
  font-weight: var(--font-bold);
  color: var(--text);
}

/* ============================================================
   HUD Overlays — floating info on canvas
   ============================================================ */

.hud-overlay,
.speed-hud,
.lap-hud,
.time-hud,
.terrain-info-bar,
.mountain-info-bar {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  color: var(--text);
  font-family: var(--font-condensed);
  z-index: 20;
}

.hud-overlay .label,
.speed-hud .label,
.lap-hud .label,
.time-hud .label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hud-overlay .value,
.speed-hud .value,
.lap-hud .value,
.time-hud .value {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--text);
  letter-spacing: var(--tracking-tight);
}

/* Info bars below canvas */
.terrain-info-bar,
.mountain-info-bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  border-top: none;
}

/* ============================================================
   Control Buttons — restyle to token system
   ============================================================ */

.control-btn,
.timer-btn,
.preset-btn,
.speed-btn,
.camera-btn,
.play-btn,
.reset-btn,
.demo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast) ease,
              border-color var(--transition-fast) ease,
              color var(--transition-fast) ease,
              box-shadow var(--transition-fast) ease;
  white-space: nowrap;
}

.control-btn:hover,
.timer-btn:hover,
.preset-btn:hover,
.speed-btn:hover,
.camera-btn:hover,
.play-btn:hover,
.reset-btn:hover,
.demo-btn:hover {
  background: var(--surface-raised);
  border-color: var(--border-strong);
  color: var(--text);
}

.control-btn:focus-visible,
.timer-btn:focus-visible,
.preset-btn:focus-visible,
.speed-btn:focus-visible,
.camera-btn:focus-visible,
.play-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Active/selected state */
.control-btn.active,
.timer-btn.active,
.preset-btn.active,
.speed-btn.active,
.camera-btn.active {
  background: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: var(--shadow-glow-cyan);
}

/* Primary action buttons */
.play-btn,
.start-btn {
  background: var(--primary);
  color: var(--text-on-primary);
  border-color: var(--primary);
}

.play-btn:hover,
.start-btn:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: var(--text-on-primary);
}

/* Danger/reset buttons */
.reset-btn {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.reset-btn:hover {
  background: var(--danger-subtle);
  border-color: var(--danger);
}

/* Button groups */
.btn-group,
.control-group,
.speed-controls,
.camera-controls {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ============================================================
   Sliders — restyle range inputs
   ============================================================ */

.progress-slider,
.speed-slider,
.lap-slider,
.timeline-track input[type="range"],
input[type="range"].control-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--surface-alt);
  border-radius: var(--radius-pill);
  outline: none;
  cursor: pointer;
}

.progress-slider::-webkit-slider-thumb,
.speed-slider::-webkit-slider-thumb,
.lap-slider::-webkit-slider-thumb,
input[type="range"].control-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--primary);
  transition: box-shadow var(--transition-fast) ease;
}

.progress-slider::-webkit-slider-thumb:hover,
.speed-slider::-webkit-slider-thumb:hover,
.lap-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.25);
}

.progress-slider::-moz-range-thumb,
.speed-slider::-moz-range-thumb,
.lap-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
  cursor: pointer;
}

/* Timeline scrubber (race-replay, race-time-machine) */
.timeline-track,
.timeline-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.timeline-progress {
  background: var(--primary);
  border-radius: var(--radius-pill);
  height: 4px;
  transition: width 0.1s linear;
}

/* ============================================================
   Page Headers — restyle existing inline headers
   ============================================================ */

.page-header {
  margin-bottom: var(--space-6);
}

.page-title {
  font-family: var(--font-sans);
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--text);
  letter-spacing: var(--tracking-tight);
  margin: 0 0 var(--space-2);
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: 0;
  max-width: 50ch;
}

/* ============================================================
   Loading States
   ============================================================ */

.exp-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  gap: var(--space-4);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.exp-loading__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--surface-alt);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Loading screen (catlap-vr pattern) */
.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  color: var(--text);
  z-index: 100;
  transition: opacity var(--transition-slow) ease;
}

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

/* ============================================================
   Back to Dashboard link
   ============================================================ */

.back-link,
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  transition: color var(--transition-fast) ease, background var(--transition-fast) ease;
  margin-bottom: var(--space-4);
}

.back-link:hover,
.back-btn:hover {
  color: var(--text);
  background: var(--surface-alt);
}

/* ============================================================
   Select/Dropdown in experimental pages
   ============================================================ */

.panel select,
.panel-card select,
.control-panel select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: border-color var(--transition-fast) ease;
}

.panel select:hover,
.panel-card select:hover,
.control-panel select:hover {
  border-color: var(--border-strong);
}

.panel select:focus,
.panel-card select:focus,
.control-panel select:focus {
  outline: 2px solid var(--border-focus);
  outline-offset: -2px;
  border-color: var(--primary);
}

/* ============================================================
   Data labels / stats in experimental panels
   ============================================================ */

.stat-row,
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.stat-row:last-child,
.info-row:last-child {
  border-bottom: none;
}

.stat-label,
.info-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.stat-val,
.info-value {
  font-family: var(--font-condensed);
  font-weight: var(--font-semibold);
  color: var(--text);
}

/* ============================================================
   Nutrition-colored data in experimental views
   ============================================================ */

.data-carbs { color: var(--carbs); }
.data-fluids { color: var(--fluids); }
.data-sodium { color: var(--sodium); }
.data-caffeine { color: var(--caffeine); }
.data-protein { color: var(--protein); }
.data-heart-rate { color: var(--heart-rate); }
.data-pace { color: var(--pace); }
.data-elevation { color: var(--elevation); }

/* ============================================================
   Responsive — mobile adjustments
   ============================================================ */

@media (max-width: 767px) {
  .hud-overlay,
  .speed-hud,
  .lap-hud,
  .time-hud {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
  }

  .hud-overlay .value,
  .speed-hud .value,
  .lap-hud .value,
  .time-hud .value {
    font-size: var(--text-lg);
  }

  .panel,
  .panel-card {
    padding: var(--space-3);
  }

  .page-title {
    font-size: var(--text-lg);
  }
}
