/* ==========================================================================
   CHAOS DYNAMICS & ADVANCED RESEARCH LAB - SCIENTIFIC HUD SYSTEM
   Theme: Deep Obsidian Space, Laser Amber, Quantum Cyan, Phase Emerald, Laser Ruby
   ========================================================================== */

:root {
  --bg-space: #06070a;
  --bg-hud: rgba(12, 15, 24, 0.82);
  --bg-hud-hover: rgba(18, 23, 35, 0.95);
  --glass-border: rgba(245, 158, 11, 0.22);
  --glass-border-cyan: rgba(56, 189, 248, 0.28);
  
  --accent-amber: #f59e0b;
  --accent-gold: #fbbf24;
  --accent-cyan: #38bdf8;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-purple: #818cf8;
  --accent-orange: #fb923c;

  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --text-muted: #64748b;
  --text-gold: #fde68a;

  --font-sans: 'Plus Jakarta Sans', -apple-system, sans-serif;
  --font-fa: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Fira Code', monospace;
  --font-serif: 'Cinzel', serif;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --glow-amber: 0 0 25px rgba(245, 158, 11, 0.28);
  --glow-cyan: 0 0 25px rgba(56, 189, 248, 0.28);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14.5px;
  background-color: var(--bg-space);
  overflow: hidden;
  height: 100vh;
}

body {
  font-family: var(--font-fa);
  color: var(--text-main);
  background-color: var(--bg-space);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

html[dir="ltr"] body {
  font-family: var(--font-sans);
}

/* Monospace Utilities */
.mono {
  font-family: var(--font-mono) !important;
}

/* ==========================================================================
   STAGE CANVAS (FULLSCREEN 3D SIMULATOR)
   ========================================================================== */
#stage-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  overflow: hidden;
  background: radial-gradient(circle at center, #0a0d16 0%, #06070a 85%);
}

#chaos-stage {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#chaos-stage:active {
  cursor: grabbing;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 40%, rgba(6, 7, 10, 0.45) 75%, rgba(6, 7, 10, 0.96) 100%);
  pointer-events: none;
}

/* ==========================================================================
   TOP SCIENTIFIC HUD BAR
   ========================================================================== */
.chaos-top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  padding: 0 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  z-index: 50;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  background: linear-gradient(180deg, rgba(8, 10, 16, 0.95) 0%, rgba(8, 10, 16, 0.4) 85%, transparent 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-zone {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-shrink: 0;
}

.chaos-glyph {
  font-size: 1.7rem;
  color: var(--accent-gold);
  text-shadow: 0 0 18px rgba(245, 158, 11, 0.7);
  animation: spinSlow 35s linear infinite;
}

@keyframes spinSlow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.brand-titles {
  display: flex;
  flex-direction: column;
}

.brand-en {
  font-family: var(--font-serif);
  font-size: 0.58rem;
  letter-spacing: 0.22em;
  color: var(--accent-gold);
}

.brand-fa {
  font-size: 0.95rem;
  font-weight: 800;
  color: #fff;
}

/* Scrollable Model Selector Bar */
.model-selection-bar {
  flex: 1;
  max-width: 780px;
  overflow: hidden;
}

.model-nav-scroll {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow-x: auto;
  padding: 0.25rem 0.4rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.model-nav-scroll::-webkit-scrollbar {
  display: none;
}

.nav-pill {
  background: rgba(14, 18, 28, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.07);
  color: var(--text-dim);
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.25s ease;
}

.pill-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.25s ease;
}

.nav-pill:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
}

.nav-pill.active {
  background: rgba(245, 158, 11, 0.18);
  color: var(--accent-gold);
  border-color: var(--accent-amber);
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.25);
}

.nav-pill.active .pill-dot {
  background: var(--accent-gold);
  box-shadow: 0 0 8px var(--accent-gold);
}

/* Top Bar Action Buttons */
.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.hud-pill-btn {
  background: rgba(14, 18, 28, 0.75);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.25s ease;
}

.hud-pill-btn:hover {
  border-color: var(--accent-amber);
  background: rgba(22, 28, 44, 0.9);
  transform: translateY(-1px);
}

.hud-pill-btn.active {
  background: rgba(245, 158, 11, 0.22);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* ==========================================================================
   GLASS HUD PANELS FOUNDATION
   ========================================================================== */
.glass-hud {
  position: fixed;
  z-index: 40;
  background: var(--bg-hud);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 15px 45px -10px rgba(0, 0, 0, 0.8);
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.hud-section-header {
  padding: 0.9rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 13, 20, 0.6);
}

.hud-icon {
  font-size: 1.1rem;
}

.hud-section-header h3 {
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
  flex: 1;
}

.minimize-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  transition: color 0.2s;
}

.minimize-btn:hover {
  color: #fff;
}

/* ==========================================================================
   LEFT HUD: MATHEMATICAL EQUATIONS, PRESETS & TELEMETRY
   ========================================================================== */
.math-hud-panel {
  top: 76px;
  right: 1.5rem;
  width: 340px;
}

html[dir="ltr"] .math-hud-panel {
  right: auto;
  left: 1.5rem;
}

.math-body {
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.formula-box {
  background: rgba(8, 10, 16, 0.88);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--accent-gold);
  box-shadow: inset 0 0 15px rgba(245, 158, 11, 0.06);
}

.eq-line {
  line-height: 1.4;
  letter-spacing: 0.03em;
}

.theory-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.65;
}

/* Presets Chips */
.presets-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0.75rem;
}

.preset-label {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
}

.preset-chips-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.preset-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: var(--text-dim);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-chip:hover {
  color: #fff;
  border-color: var(--accent-gold);
  background: rgba(245, 158, 11, 0.12);
}

.preset-chip.active {
  background: rgba(245, 158, 11, 0.2);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  font-weight: 700;
}

/* Telemetry Box */
.telemetry-box {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0.9rem 1.2rem;
  background: rgba(9, 11, 17, 0.65);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tel-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
}

.tel-k {
  color: var(--text-muted);
}

.tel-v {
  color: var(--accent-cyan);
  font-weight: 600;
}

.lyapunov-val {
  color: var(--accent-emerald) !important;
}

/* ==========================================================================
   RIGHT HUD: CHAOS CONTROL DECK
   ========================================================================== */
.control-deck-panel {
  top: 76px;
  left: 1.5rem;
  width: 360px;
  max-height: calc(100vh - 175px);
  display: flex;
  flex-direction: column;
}

html[dir="ltr"] .control-deck-panel {
  left: auto;
  right: 1.5rem;
}

.controls-body {
  overflow-y: auto;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.controls-body::-webkit-scrollbar {
  width: 4px;
}

.controls-body::-webkit-scrollbar-thumb {
  background: rgba(245, 158, 11, 0.3);
  border-radius: 2px;
}

.control-group-box {
  background: rgba(10, 13, 20, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  padding: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.control-group-box h4 {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-gold);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 0.35rem;
}

.ctrl-slider-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ctrl-label-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-dim);
}

.val-badge {
  color: var(--accent-gold);
  font-weight: 700;
}

/* Toggle Switches */
.toggle-switches-grid {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.hud-switch-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  cursor: pointer;
}

.hud-switch-row input {
  display: none;
}

.switch-slider {
  width: 32px;
  height: 18px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-full);
  position: relative;
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.switch-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: all 0.25s ease;
}

.hud-switch-row input:checked + .switch-slider {
  background: var(--accent-amber);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.4);
}

.hud-switch-row input:checked + .switch-slider::before {
  transform: translateX(14px);
}

/* Sliders */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-gold);
  box-shadow: 0 0 10px var(--accent-gold);
  cursor: pointer;
  transition: transform 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.3);
}

/* Action Buttons Grid */
.action-buttons-grid {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.deck-btn {
  background: rgba(14, 18, 28, 0.8);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  transition: all 0.25s ease;
}

.deck-btn:hover {
  border-color: var(--accent-gold);
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-gold);
  transform: translateX(-2px);
}

html[dir="ltr"] .deck-btn:hover {
  transform: translateX(2px);
}

/* Palette Options */
.palette-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.palette-btn {
  background: rgba(12, 15, 22, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  padding: 0.4rem 0.4rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
}

.palette-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gold-swatch { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.vel-swatch { background: linear-gradient(135deg, #3b82f6, #ef4444); }
.cyan-swatch { background: linear-gradient(135deg, #06b6d4, #38bdf8); }
.neon-swatch { background: linear-gradient(135deg, #ec4899, #8b5cf6); }
.thermal-swatch { background: linear-gradient(135deg, #ef4444, #eab308); }
.height-swatch { background: linear-gradient(135deg, #10b981, #6366f1); }

.palette-btn:hover, .palette-btn.active {
  border-color: var(--accent-gold);
  color: #fff;
  background: rgba(245, 158, 11, 0.16);
}

/* 3D Camera Buttons */
.camera-btn-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
}

.cam-btn {
  background: rgba(12, 15, 22, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  padding: 0.4rem 0.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.cam-btn:hover, .cam-btn.active {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
}

/* ==========================================================================
   BOTTOM LYAPUNOV & POINCARÉ DIAGNOSTIC DRAWER
   ========================================================================== */
.bottom-monitor-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(960px, 94vw);
  background: rgba(10, 13, 20, 0.94);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  z-index: 45;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.75);
  transition: all 0.35s ease;
}

.monitor-header {
  padding: 0.65rem 1.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.monitor-title-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
}

.divergence-metric {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--accent-rose);
  background: rgba(244, 63, 94, 0.14);
  border: 1px solid rgba(244, 63, 94, 0.35);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
}

.btn-toggle-monitor {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.bottom-monitor-bar.collapsed .btn-toggle-monitor {
  transform: rotate(180deg);
}

.monitor-content {
  max-height: 200px;
  overflow: hidden;
  padding: 0 1.2rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  transition: max-height 0.3s ease;
}

.bottom-monitor-bar.collapsed .monitor-content {
  max-height: 0;
  padding-bottom: 0;
}

.diagnostics-grid {
  display: grid;
  grid-template-columns: 1.8fr 1fr;
  gap: 1rem;
}

.diag-chart-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.diag-card-title {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.diag-badge {
  font-family: var(--font-mono);
  color: var(--accent-emerald);
}

#chart-canvas, #poincare-canvas {
  width: 100%;
  height: 95px;
  background: rgba(6, 7, 10, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  display: block;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 1.2rem;
  font-size: 0.7rem;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.leg-color {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.leg-color.gold { background: var(--accent-gold); }
.leg-color.cyan { background: var(--accent-cyan); }
.leg-color.red { background: var(--accent-rose); }
.leg-color.green { background: var(--accent-emerald); }

/* Panels Minimized State */
.glass-hud.minimized {
  width: auto !important;
}

.glass-hud.minimized .math-body,
.glass-hud.minimized .telemetry-box,
.glass-hud.minimized .controls-body {
  display: none !important;
}

/* UI Hidden (Cinematic Mode) */
body.cinematic-mode .chaos-top-bar,
body.cinematic-mode .glass-hud,
body.cinematic-mode .bottom-monitor-bar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-20px);
}

body.cinematic-mode #btn-toggle-ui {
  opacity: 1;
  pointer-events: auto;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  transform: none;
}

/* Responsive Breakpoints */
@media (max-width: 900px) {
  .model-selection-bar {
    display: none;
  }

  .math-hud-panel {
    top: auto;
    bottom: 50px;
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
    max-height: 200px;
  }

  .control-deck-panel {
    top: 65px;
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
    max-height: 250px;
  }

  .bottom-monitor-bar {
    display: none;
  }
}
