/**
 * AstroEd Demos - Shared Theme
 * Dark space theme for interactive astronomy visualizations
 */

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */
:root {
  /* Space colors */
  --space-black: #0a0a14;
  --space-deep: #12121f;
  --space-medium: #1a1a2e;
  --space-light: #252538;

  /* Celestial colors */
  --sun-core: #fff5cc;
  --sun-glow: #ffcc00;
  --sun-corona: #ff8c00;
  --moon-light: #e8e8f0;
  --moon-dark: #3a3a4a;
  --earth-blue: #4a90d9;
  --earth-green: #4a9d4a;
  --mars-red: #d9534f;
  --jupiter-tan: #d4a574;

  /* UI colors - Cosmic Nebula Palette */
  --text-primary: #F8F8F2;
  --text-secondary: #BFBFBF;
  --text-muted: #6272A4;

  /* Accent colors */
  --cosmic-teal: #4ECDC4;
  --soft-magenta: #C792EA;
  --stellar-amber: #FFB86C;
  --nebula-green: #50FA7B;
  --nova-pink: #FF79C6;
  --ice-blue: #8BE9FD;

  /* Legacy aliases (backwards compatibility) */
  --accent-blue: var(--cosmic-teal);
  --accent-green: var(--nebula-green);
  --accent-red: var(--nova-pink);
  --accent-gold: var(--stellar-amber);

  /* Glow effects - Cosmic Nebula */
  --glow-teal: 0 0 20px rgba(78, 205, 196, 0.4);
  --glow-magenta: 0 0 20px rgba(199, 146, 234, 0.4);
  --glow-amber: 0 0 30px rgba(255, 184, 108, 0.5);
  --glow-sun: 0 0 60px rgba(255, 184, 108, 0.6), 0 0 120px rgba(255, 184, 108, 0.3);
  --glow-moon: 0 0 20px rgba(232, 232, 240, 0.3);
  --glow-earth: 0 0 30px rgba(74, 144, 217, 0.4);
  --glow-accent: 0 0 15px var(--cosmic-teal);

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

  /* Typography - Improved sizes */
  --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  --font-size-xs: 0.75rem;   /* 12px - tick values */
  --font-size-sm: 0.875rem;  /* 14px - labels, controls */
  --font-size-md: 1rem;      /* 16px - body text */
  --font-size-lg: 1.25rem;   /* 20px - emphasis */
  --font-size-xl: 1.5rem;    /* 24px - values */
  --font-size-2xl: 1.75rem;  /* 28px - titles */

  /* Line heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;

  /* Animation */
  --transition-fast: 150ms ease;
  --transition-medium: 300ms ease;
  --transition-slow: 500ms ease;

  /* Borders */
  --border-radius-sm: 4px;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
  --border-color: rgba(255, 255, 255, 0.1);
}

/* ============================================
   Base Styles
   ============================================ */
.astro-demo {
  font-family: var(--font-main);
  background: var(--space-black);
  color: var(--text-primary);
  min-height: 100vh;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  position: relative;
}

.astro-demo *,
.astro-demo *::before,
.astro-demo *::after {
  box-sizing: border-box;
}

/* Container for demo content */
.demo-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-lg);
  position: relative;
  z-index: 1;
}

/* ============================================
   Typography - Enhanced
   ============================================ */
.demo-title {
  font-size: var(--font-size-2xl);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 var(--space-sm) 0;
  letter-spacing: 0.02em;
  line-height: var(--line-height-tight);
}

.demo-subtitle {
  font-size: var(--font-size-md);
  color: var(--text-secondary);
  margin: 0 0 var(--space-lg) 0;
  line-height: var(--line-height-normal);
}

.demo-label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
  line-height: var(--line-height-tight);
}

.demo-value {
  font-family: var(--font-mono);
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--stellar-amber);
  line-height: var(--line-height-tight);
}

.demo-value-large {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.demo-unit {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin-left: var(--space-xs);
}

.demo-secondary {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ============================================
   Value Cards (numeric readouts)
   ============================================ */
.value-card {
  background: var(--space-deep);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: var(--space-md);
  text-align: center;
}

.value-card__label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.value-card__value {
  font-family: var(--font-mono);
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.value-card__unit {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin-left: 0.25em;
}

.value-card__secondary {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

.value-card--highlight .value-card__value {
  color: var(--cosmic-teal);
}

.value-card--warn .value-card__value {
  color: var(--stellar-amber);
}

.value-card--success .value-card__value {
  color: var(--nebula-green);
}

/* ============================================
   Visualization Canvas
   ============================================ */
.viz-container {
  background: var(--space-deep);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  position: relative;
}

.viz-canvas {
  display: block;
  width: 100%;
  height: auto;
}

.viz-svg {
  display: block;
  width: 100%;
  height: auto;
}

/* ============================================
   Controls Panel
   ============================================ */
.controls-panel {
  background: var(--space-medium);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: var(--space-lg);
  margin-top: var(--space-lg);
}

.control-group {
  margin-bottom: var(--space-lg);
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
}

.control-label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 120px;
  line-height: var(--line-height-normal);
}

/* ============================================
   Sliders - Cosmic Nebula
   ============================================ */
.astro-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--space-light);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.astro-slider:hover {
  background: var(--space-medium);
}

.astro-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--space-deep);
  border: 2px solid var(--cosmic-teal);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--glow-teal);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.astro-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 25px rgba(78, 205, 196, 0.6);
}

.astro-slider::-webkit-slider-thumb:active {
  transform: scale(1.2);
  background: var(--cosmic-teal);
}

.astro-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--space-deep);
  border: 2px solid var(--cosmic-teal);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--glow-teal);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.astro-slider::-moz-range-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 25px rgba(78, 205, 196, 0.6);
}

/* Firefox: Track fill (left of thumb) */
.astro-slider::-moz-range-progress {
  background: var(--cosmic-teal);
  border-radius: 3px;
  height: 6px;
}

/* WebKit: Use linear-gradient via JS to show progress
   Set --slider-progress custom property (0-100) via JavaScript:
   slider.style.setProperty('--slider-progress', percentage + '%');
*/
.astro-slider {
  --slider-progress: 50%;
}

.astro-slider::-webkit-slider-runnable-track {
  background: linear-gradient(
    to right,
    var(--cosmic-teal) 0%,
    var(--cosmic-teal) var(--slider-progress),
    var(--space-light) var(--slider-progress),
    var(--space-light) 100%
  );
  border-radius: 3px;
  height: 6px;
}

.astro-slider:hover::-webkit-slider-runnable-track {
  background: linear-gradient(
    to right,
    var(--cosmic-teal) 0%,
    var(--cosmic-teal) var(--slider-progress),
    var(--space-medium) var(--slider-progress),
    var(--space-medium) 100%
  );
}

/* Slider value display */
.slider-with-value {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex: 1;
}

.slider-value {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--stellar-amber);
  min-width: 90px;
  text-align: right;
  background: var(--space-deep);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-color);
}

/* ============================================
   Buttons - Cosmic Nebula
   ============================================ */
.astro-btn {
  font-family: var(--font-main);
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: var(--space-sm) var(--space-lg);
  min-height: 44px;
  border: 1px solid var(--cosmic-teal);
  border-radius: 9999px; /* Pill shape */
  background: transparent;
  color: var(--cosmic-teal);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.astro-btn:hover {
  background: rgba(78, 205, 196, 0.15);
  box-shadow: var(--glow-teal);
}

.astro-btn:active {
  transform: scale(0.98);
  background: rgba(78, 205, 196, 0.25);
}

.astro-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.astro-btn.active,
.astro-btn.primary {
  background: var(--cosmic-teal);
  color: var(--space-black);
  border-color: var(--cosmic-teal);
}

.astro-btn.active:hover,
.astro-btn.primary:hover {
  background: #6ad4cc;
  box-shadow: 0 0 20px rgba(78, 205, 196, 0.5);
}

/* Secondary button variant */
.astro-btn.secondary {
  border-color: var(--soft-magenta);
  color: var(--soft-magenta);
}

.astro-btn.secondary:hover {
  background: rgba(199, 146, 234, 0.15);
  box-shadow: var(--glow-magenta);
}

.astro-btn.secondary.active {
  background: var(--soft-magenta);
  color: var(--space-black);
}

/* Button group */
.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

/* ============================================
   Presets - Cosmic Nebula
   ============================================ */
.presets-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.preset-btn {
  font-family: var(--font-main);
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: var(--space-sm) var(--space-md);
  min-height: 44px;
  background: var(--space-light);
  border: 1px solid var(--border-color);
  border-radius: 9999px; /* Pill shape */
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.preset-btn:hover {
  background: var(--space-medium);
  color: var(--text-primary);
  border-color: var(--cosmic-teal);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.preset-btn:active {
  transform: scale(0.98);
}

.preset-btn.active {
  background: var(--cosmic-teal);
  color: var(--space-black);
  border-color: var(--cosmic-teal);
  font-weight: 600;
}

.preset-btn.easter-egg {
  border-style: dashed;
  border-color: var(--soft-magenta);
}

.preset-btn.easter-egg:hover {
  border-color: var(--soft-magenta);
  box-shadow: var(--glow-magenta);
}

.preset-btn.easter-egg.active {
  background: var(--soft-magenta);
  border-style: solid;
}

/* ============================================
   Toggle Switches
   ============================================ */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
}

.toggle-switch__track {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--space-light);
  border-radius: 12px;
  transition: background var(--transition-fast);
}

.toggle-switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--transition-fast);
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch input:checked + .toggle-switch__track {
  background: var(--nebula-green);
}

.toggle-switch input:checked + .toggle-switch__track .toggle-switch__thumb {
  left: 22px;
  background: var(--space-black);
}

.toggle-switch input:focus-visible + .toggle-switch__track {
  outline: 2px solid var(--cosmic-teal);
  outline-offset: 2px;
}

.toggle-switch__label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* ============================================
   Info Displays
   ============================================ */
.info-panel {
  background: var(--space-deep);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: var(--space-md);
}

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

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

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

.info-value {
  font-family: var(--font-mono);
  color: var(--accent-gold);
}

/* Status indicators - Cosmic Nebula */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border-radius: 9999px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  transition: all var(--transition-fast);
}

.status-indicator.success {
  background: rgba(80, 250, 123, 0.15);
  color: var(--nebula-green);
  border: 1px solid rgba(80, 250, 123, 0.3);
}

.status-indicator.error {
  background: rgba(255, 121, 198, 0.15);
  color: var(--nova-pink);
  border: 1px solid rgba(255, 121, 198, 0.3);
}

.status-indicator.warning {
  background: rgba(255, 184, 108, 0.15);
  color: var(--stellar-amber);
  border: 1px solid rgba(255, 184, 108, 0.3);
}

.status-indicator.info {
  background: rgba(78, 205, 196, 0.15);
  color: var(--cosmic-teal);
  border: 1px solid rgba(78, 205, 196, 0.3);
}

/* ============================================
   Chart & Graph Styling
   ============================================ */
.chart-axis {
  stroke: var(--text-secondary);
  stroke-width: 2;
}

.chart-axis-label {
  font-family: var(--font-main);
  font-size: var(--font-size-sm);
  font-weight: 600;
  fill: var(--text-secondary);
}

.chart-tick {
  stroke: var(--text-secondary);
  stroke-width: 1;
}

.chart-tick-label {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  fill: var(--text-muted);
}

.chart-grid {
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line--primary {
  stroke: var(--cosmic-teal);
}

.chart-line--secondary {
  stroke: var(--soft-magenta);
}

.chart-line--warm {
  stroke: var(--stellar-amber);
}

.chart-area {
  opacity: 0.2;
}

.chart-area--primary {
  fill: var(--cosmic-teal);
}

/* Peak/reference markers */
.chart-marker {
  stroke-width: 2;
  stroke-dasharray: 4 2;
}

.chart-marker--reference {
  stroke: var(--stellar-amber);
}

.chart-marker-label {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  fill: var(--stellar-amber);
}

/* Visible spectrum band highlight */
.spectrum-visible-band {
  fill: url(#visible-spectrum-gradient);
  opacity: 0.3;
}

/* ============================================
   Celestial Objects (SVG)
   ============================================ */
.celestial-sun {
  fill: var(--sun-core);
  filter: drop-shadow(0 0 20px var(--sun-glow))
          drop-shadow(0 0 40px var(--sun-corona));
}

.celestial-moon-lit {
  fill: var(--moon-light);
  filter: drop-shadow(0 0 8px rgba(232, 232, 240, 0.3));
}

.celestial-moon-dark {
  fill: var(--moon-dark);
}

.celestial-earth {
  fill: var(--earth-blue);
  filter: drop-shadow(0 0 15px rgba(74, 144, 217, 0.4));
}

.orbit-path {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0.5;
}

.node-marker {
  fill: var(--accent-gold);
  filter: drop-shadow(0 0 6px var(--accent-gold));
}

.ecliptic-plane {
  stroke: var(--accent-blue);
  stroke-width: 2;
  opacity: 0.6;
}

/* ============================================
   Angle Arc (for angular size)
   ============================================ */
.angle-arc {
  fill: none;
  stroke: var(--accent-gold);
  stroke-width: 2;
}

.angle-lines {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 4 2;
}

/* ============================================
   Reference Guides
   ============================================ */
.reference-guide {
  background: var(--space-medium);
  border-left: 3px solid var(--accent-blue);
  padding: var(--space-md);
  margin: var(--space-lg) 0;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.reference-guide strong {
  color: var(--text-primary);
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
  .demo-container {
    padding: var(--space-md);
  }

  .control-row {
    flex-direction: column;
    align-items: stretch;
  }

  .control-label {
    min-width: auto;
    margin-bottom: var(--space-xs);
  }

  .slider-with-value {
    flex-direction: column;
    align-items: stretch;
  }

  .slider-value {
    min-width: auto;
    text-align: center;
  }

  .presets-container {
    justify-content: center;
  }
}

/* ============================================
   Accessibility
   ============================================ */

/* Focus styles */
.astro-btn:focus-visible,
.astro-slider:focus-visible,
.preset-btn:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   Animation Utilities - Enhanced
   ============================================ */

/* Fade animations */
.fade-in {
  animation: fadeIn var(--transition-medium) ease-out;
}

.fade-out {
  animation: fadeOut var(--transition-medium) ease-out forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Pulse animations */
.pulse {
  animation: pulse 2s ease-in-out infinite;
}

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

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

@keyframes pulse-subtle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.02); }
}

/* Glow pulse (for celestial objects) */
.glow-pulse {
  animation: glow-pulse 4s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% { filter: drop-shadow(0 0 20px currentColor); }
  50% { filter: drop-shadow(0 0 30px currentColor); }
}

/* Twinkle (for stars) */
.twinkle {
  animation: twinkle 2s ease-in-out infinite;
  animation-delay: calc(var(--twinkle-delay, 0) * 1s);
}

@keyframes twinkle {
  0%, 100% { opacity: var(--star-opacity, 0.8); }
  50% { opacity: calc(var(--star-opacity, 0.8) * 0.4); }
}

/* Scale animations */
.pop-in {
  animation: pop-in 0.3s ease-out;
}

@keyframes pop-in {
  0% { transform: scale(0.8); opacity: 0; }
  70% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

/* Slide animations */
.slide-up {
  animation: slide-up var(--transition-medium) ease-out;
}

@keyframes slide-up {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Value change highlight */
.value-flash {
  animation: value-flash 0.3s ease-out;
}

@keyframes value-flash {
  0% { color: var(--cosmic-teal); transform: scale(1.05); }
  100% { color: inherit; transform: scale(1); }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .fade-in,
  .fade-out,
  .pulse,
  .pulse-subtle,
  .glow-pulse,
  .twinkle,
  .pop-in,
  .slide-up,
  .value-flash {
    animation: none;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   Layout Utilities
   ============================================ */
.flex-row {
  display: flex;
  flex-direction: row;
  gap: var(--space-md);
}

.flex-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-2col {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-lg);
}

@media (max-width: 768px) {
  .grid-2col {
    grid-template-columns: 1fr;
  }
}
