/* ========================================
   DARK MATTER EXPLORER — Design System
   Mobile-first, Space Theme
   ======================================== */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- CSS Custom Properties --- */
:root {
  /* Colors — Space Palette */
  --bg-primary: #060a14;
  --bg-secondary: #0c1221;
  --bg-panel: rgba(12, 18, 33, 0.88);
  --bg-panel-hover: rgba(18, 26, 48, 0.92);
  --bg-glass: rgba(15, 22, 42, 0.65);

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #c4b5fd;

  --accent-primary: #7c3aed;
  --accent-primary-glow: rgba(124, 58, 237, 0.4);
  --accent-secondary: #06b6d4;
  --accent-secondary-glow: rgba(6, 182, 212, 0.35);

  --keplerian-color: #f97316;
  --keplerian-glow: rgba(249, 115, 22, 0.35);
  --galaxy-color: #10b981;
  --galaxy-glow: rgba(16, 185, 129, 0.35);
  --dark-matter-color: #a78bfa;
  --dark-matter-glow: rgba(167, 139, 250, 0.4);

  --sun-color: #fbbf24;
  --sun-glow: rgba(251, 191, 36, 0.5);

  --border-subtle: rgba(148, 163, 184, 0.1);
  --border-active: rgba(124, 58, 237, 0.5);

  /* Typography */
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Space Grotesk', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow-purple: 0 0 20px var(--accent-primary-glow);
  --shadow-glow-cyan: 0 0 20px var(--accent-secondary-glow);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-index layers */
  --z-canvas: 1;
  --z-panel: 10;
  --z-controls: 20;
  --z-tabs: 30;
  --z-tooltip: 40;
  --z-overlay: 50;
}

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

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  width: 100vw;
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* --- Background Stars --- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 60%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 50% 10%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 80%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 85% 30%, rgba(200,200,255,0.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 15% 90%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 95% 55%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 40% 45%, rgba(200,220,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 35%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 25% 75%, rgba(180,200,255,0.5) 0%, transparent 100%);
  z-index: 0;
  pointer-events: none;
}

/* --- App Container --- */
#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  z-index: var(--z-canvas);
}

/* --- Tab Navigation --- */
.tab-nav {
  white-space: nowrap;
  padding: var(--space-sm) var(--space-md);
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: var(--z-tabs);
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Hide scrollbar for Firefox */
  -ms-overflow-style: none; /* Hide scrollbar for IE/Edge */
  touch-action: auto; 
}

.tab-nav::-webkit-scrollbar {
  display: none; /* Hide scrollbar for Chrome/Safari */
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  margin-right: var(--space-xs);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  padding: var(--space-xs) var(--space-md);
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
  letter-spacing: 0.02em;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(124, 58, 237, 0.1);
}

.tab-btn.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-primary), rgba(124, 58, 237, 0.7));
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow-purple);
}

/* --- Tab Content Area --- */
.tab-content-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.tab-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-slow), visibility var(--transition-slow);
}

.tab-panel.active {
  opacity: 1;
  visibility: visible;
}

/* --- Simulation + Chart Layout (Mobile: stacked) --- */
.sim-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sim-canvas-container {
  position: relative;
  flex: 1;
  min-height: 0;
}

.sim-canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* --- Chart Panel --- */
.chart-panel {
  position: relative;
  height: 200px;
  flex-shrink: 0;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-subtle);
}

.chart-panel canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-title {
  position: absolute;
  top: var(--space-sm);
  left: var(--space-md);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  pointer-events: none;
  z-index: 2;
}

/* --- Controls Bar --- */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: var(--z-controls);
}

.speed-btn {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  background: rgba(124, 58, 237, 0.15);
  border: 1px solid rgba(124, 58, 237, 0.3);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  min-width: 48px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.speed-btn:hover {
  background: rgba(124, 58, 237, 0.25);
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow-purple);
}

.speed-btn:active {
  transform: scale(0.95);
}

.speed-display {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--accent-secondary);
  min-width: 60px;
  text-align: center;
}

.time-display {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: var(--space-sm);
}

/* --- Info Panel --- */
.info-panel {
  position: absolute;
  top: var(--space-sm);
  left: var(--space-sm);
  right: var(--space-sm);
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.5;
  z-index: var(--z-panel);
  pointer-events: none;
  max-width: 400px;
}

.info-panel .info-icon {
  color: var(--accent-secondary);
  margin-right: var(--space-xs);
}

/* --- Tooltip --- */
.tooltip {
  position: fixed;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-active);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--text-primary);
  z-index: var(--z-tooltip);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  max-width: 220px;
  box-shadow: var(--shadow-md);
}

.tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.tooltip .tooltip-name {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--accent-secondary);
  margin-bottom: 2px;
}

.tooltip .tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-md);
}

.tooltip .tooltip-label {
  color: var(--text-muted);
}

.tooltip .tooltip-value {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-primary);
}

/* --- Slider --- */
.slider-container {
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-panel);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.slider-label {
  font-family: var(--font-heading);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.slider-value {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--dark-matter-color);
}

.mass-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(124,58,237,0.2), rgba(167,139,250,0.3));
  outline: none;
  cursor: pointer;
}

.mass-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--dark-matter-color));
  border: 2px solid rgba(255,255,255,0.3);
  cursor: pointer;
  box-shadow: var(--shadow-glow-purple);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.mass-slider::-webkit-slider-thumb:hover,
.mass-slider::-webkit-slider-thumb:active {
  transform: scale(1.15);
  box-shadow: 0 0 30px var(--accent-primary-glow);
}

.mass-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--dark-matter-color));
  border: 2px solid rgba(255,255,255,0.3);
  cursor: pointer;
  box-shadow: var(--shadow-glow-purple);
}

.percentage-display {
  text-align: center;
  margin-top: var(--space-sm);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--dark-matter-color);
  opacity: 0.8;
  min-height: 1.5em;
}

/* --- Comparison Miniatures --- */
.miniatures {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  justify-content: center;
  flex-shrink: 0;
}

.miniature {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  background: var(--bg-secondary);
}

.miniature canvas {
  width: 100%;
  height: 100%;
}

/* --- Chart Legend --- */
.chart-legend {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 2;
  pointer-events: none;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.65rem;
  font-family: var(--font-body);
  color: var(--text-muted);
}

.legend-swatch {
  width: 16px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
}

.legend-swatch.dashed {
  background: repeating-linear-gradient(
    90deg,
    currentColor 0px,
    currentColor 4px,
    transparent 4px,
    transparent 8px
  );
  height: 2px;
}

/* --- Dark matter halo toggle --- */
.halo-toggle {
  position: absolute;
  bottom: var(--space-md);
  right: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: var(--space-xs) var(--space-md);
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--text-secondary);
  z-index: var(--z-panel);
  transition: all var(--transition-base);
  -webkit-tap-highlight-color: transparent;
}

.halo-toggle:hover {
  border-color: var(--dark-matter-color);
  color: var(--dark-matter-color);
}

.halo-toggle.active {
  border-color: var(--dark-matter-color);
  color: var(--dark-matter-color);
  background: rgba(167, 139, 250, 0.12);
}

.halo-toggle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-base), box-shadow var(--transition-base);
}

.halo-toggle.active .halo-toggle-dot {
  background: var(--dark-matter-color);
  box-shadow: 0 0 8px var(--dark-matter-glow);
}

/* --- Planet Selection Indicator --- */
.planet-hint {
  position: absolute;
  bottom: var(--space-sm);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
  pointer-events: none;
  z-index: var(--z-panel);
  opacity: 0.7;
}

/* --- Full-height sim layout (no chart panel) --- */
.sim-layout--full {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sim-layout--full .sim-canvas-container {
  flex: 1;
}

/* --- Doppler Slider (Tab 4) --- */
.doppler-slider {
  background: linear-gradient(90deg, rgba(248, 113, 113, 0.35), rgba(148,163,184,0.15) 50%, rgba(96, 165, 250, 0.35)) !important;
}

.doppler-slider::-webkit-slider-thumb {
  background: linear-gradient(135deg, #60a5fa, #f87171) !important;
  box-shadow: 0 0 16px rgba(96, 165, 250, 0.4) !important;
}

.doppler-slider::-moz-range-thumb {
  background: linear-gradient(135deg, #60a5fa, #f87171) !important;
  box-shadow: 0 0 16px rgba(96, 165, 250, 0.4) !important;
}

/* --- Redshift Slider (Tab 5) --- */
.redshift-slider {
  background: linear-gradient(90deg, rgba(148,163,184,0.15), rgba(248, 113, 113, 0.4)) !important;
}

.redshift-slider::-webkit-slider-thumb {
  background: linear-gradient(135deg, #fbbf24, #f87171) !important;
  box-shadow: 0 0 16px rgba(248, 113, 113, 0.4) !important;
}

.redshift-slider::-moz-range-thumb {
  background: linear-gradient(135deg, #fbbf24, #f87171) !important;
  box-shadow: 0 0 16px rgba(248, 113, 113, 0.4) !important;
}

/* --- Galaxy Doppler Slider (Tab 6) --- */
.galaxy-doppler-slider {
  background: linear-gradient(90deg, rgba(148,163,184,0.15), rgba(251, 191, 36, 0.4)) !important;
}

.galaxy-doppler-slider::-webkit-slider-thumb {
  background: linear-gradient(135deg, #fbbf24, #f59e0b) !important;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.4) !important;
}

.galaxy-doppler-slider::-moz-range-thumb {
  background: linear-gradient(135deg, #fbbf24, #f59e0b) !important;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.4) !important;
}

/* --- Responsive: Tablet --- */
@media (min-width: 768px) {
  html {
    font-size: 15px;
  }

  .tab-nav {
    justify-content: center;
  }

  .tab-btn {
    font-size: 0.78rem;
    padding: var(--space-sm) var(--space-lg);
  }

  .sim-layout {
    flex-direction: row;
  }

  .chart-panel {
    width: 320px;
    height: auto;
    border-top: none;
    border-left: 1px solid var(--border-subtle);
  }

  .info-panel {
    max-width: 320px;
  }

  .tooltip {
    max-width: 260px;
  }
}

/* --- Responsive: Desktop --- */
@media (min-width: 1200px) {
  html {
    font-size: 16px;
  }

  .chart-panel {
    width: 380px;
  }

  .tab-nav {
    gap: var(--space-sm);
  }

  .tab-btn {
    font-size: 0.82rem;
    padding: var(--space-sm) var(--space-xl);
  }
}

/* --- Utility Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 8px var(--accent-primary-glow); }
  50% { box-shadow: 0 0 20px var(--accent-primary-glow); }
}

.fade-in {
  animation: fadeIn 0.4s ease-out;
}

.pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* --- Zoom Controls --- */
.zoom-controls {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  z-index: var(--z-controls);
}

.zoom-controls button {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.zoom-controls button:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.zoom-controls button:active {
  transform: scale(0.95);
}

/* --- Password Modal --- */
.modal-overlay {
  position: absolute;
  top: 0; left: 0; width: 100vw; height: 100dvh;
  background: rgba(4, 8, 20, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.modal-overlay.visible {
  opacity: 1; pointer-events: all;
}
.keypad-modal {
  background: var(--surface-light);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 1.5rem;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.visible .keypad-modal {
  transform: translateY(0);
}
#keypad-title {
  text-align: center;
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--text-primary);
  margin: 0;
}
.password-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 0.5rem;
}
.password-display .dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  transition: 0.2s;
}
.password-display .dot.filled {
  background: var(--brand-blue);
  border-color: var(--brand-blue);
  box-shadow: 0 0 10px var(--brand-blue);
}
.password-display.error {
  animation: shake 0.4s;
}
.password-display.error .dot.filled {
  background: var(--brand-red);
  border-color: var(--brand-red);
  box-shadow: 0 0 10px var(--brand-red);
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.keypad .key {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: #e2e8f0;
  border-radius: 12px;
  font-size: 1.4rem;
  font-family: var(--font-heading);
  font-weight: 500;
  height: 60px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.keypad .key:active { 
  background: rgba(255,255,255,0.15); 
  transform: scale(0.95);
}
.keypad .key-clear { color: var(--brand-red); font-size: 1.2rem; }
.keypad .key-cancel { color: var(--text-muted); font-size: 1.2rem; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}
