/* ==========================================================================
   Damped Spring-Mass Oscillator Simulation - Modern Dark Theme
   ========================================================================== */

:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #0f172a;
  --card-bg: rgba(30, 41, 59, 0.72);
  --card-header-bg: rgba(15, 23, 42, 0.6);
  --card-border: rgba(148, 163, 184, 0.12);
  --card-border-hover: rgba(56, 189, 248, 0.3);

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

  --accent-cyan: #38bdf8;
  --accent-cyan-dark: #0284c7;
  --accent-cyan-glow: rgba(56, 189, 248, 0.35);

  --accent-indigo: #818cf8;
  --accent-purple: #a855f7;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 9999px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--card-border);
  --shadow-glow: 0 0 20px -3px var(--accent-cyan-glow);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(56, 189, 248, 0.04) 0%, transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(129, 140, 248, 0.04) 0%, transparent 45%);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Header Bar
   ========================================================================== */
.app-header {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-border);
  padding: 14px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  max-width: 1560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #0284c7 0%, #6366f1 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.4);
}

.brand-icon svg {
  width: 22px;
  height: 22px;
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #f8fafc 40%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-text p {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--card-border);
  transition: var(--transition-normal);
}

.status-badge .regime-title {
  text-transform: uppercase;
}

.status-badge .regime-zeta {
  text-transform: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 500;
  opacity: 0.9;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* Regime Color Themes */
.status-badge.underdamped {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.4);
  color: #38bdf8;
}
.status-badge.underdamped .status-dot { background: #38bdf8; box-shadow: 0 0 8px #38bdf8; }

.status-badge.critical {
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.4);
  color: #c084fc;
}
.status-badge.critical .status-dot { background: #c084fc; box-shadow: 0 0 8px #c084fc; }

.status-badge.overdamped {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}
.status-badge.overdamped .status-dot { background: #fbbf24; box-shadow: 0 0 8px #fbbf24; }

.status-badge.undamped {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}
.status-badge.undamped .status-dot { background: #34d399; box-shadow: 0 0 8px #34d399; }

/* ==========================================================================
   Main Dashboard Layout
   ========================================================================== */
.main-dashboard {
  max-width: 1560px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
  flex: 1;
  width: 100%;
}

@media (max-width: 1180px) {
  .main-dashboard {
    grid-template-columns: 1fr 360px;
  }
}

@media (max-width: 960px) {
  .main-dashboard {
    grid-template-columns: 1fr;
    padding: 14px;
    gap: 16px;
  }
}

.sim-stage-column,
.controls-sidebar-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   Card System
   ========================================================================== */
.dashboard-card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition-fast);
}

.dashboard-card:hover {
  border-color: var(--card-border-hover);
}

.card-header {
  padding: 12px 18px;
  background: var(--card-header-bg);
  border-bottom: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.card-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title svg {
  color: var(--accent-cyan);
}

.card-body {
  padding: 16px;
}

/* ==========================================================================
   Simulation Canvas Viewport
   ========================================================================== */
.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 440px;
  background: #090e1a;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.6);
  cursor: default;
}

@media (max-width: 600px) {
  .canvas-wrapper {
    height: 380px;
  }
}

#oscillatorCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* Crucial for smooth touch-drag on mobile without page scroll */
}

/* Overlay hint for drag & drop */
.canvas-overlay-hint {
  position: absolute;
  top: 10px;
  right: 12px;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.canvas-overlay-hint span {
  display: inline-block;
  color: var(--accent-cyan);
}

/* Vector Toggles Toolbar */
.vector-toggles-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.5);
  border-top: 1px solid var(--card-border);
}

.toggle-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-item input[type="checkbox"] {
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

.toggle-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.swatch-vel { background: #06b6d4; }
.swatch-fs { background: #f59e0b; }
.swatch-fd { background: #f43f5e; }

/* ==========================================================================
   Real-Time Graph Canvas & Controls
   ========================================================================== */
.graph-wrapper {
  position: relative;
  width: 100%;
  height: 190px;
  background: #090e1a;
  border-radius: var(--radius-md);
  overflow: hidden;
}

#graphCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.graph-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab-btn-group {
  display: inline-flex;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition-fast);
}

.tab-btn.active {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent-cyan);
  font-weight: 600;
}

.tab-btn:hover:not(.active) {
  color: var(--text-main);
}

.btn-icon-sm {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition-fast);
}

.btn-icon-sm:hover {
  background: rgba(30, 41, 59, 0.9);
  color: var(--text-main);
}

/* ==========================================================================
   Live Energy HUD Meters
   ========================================================================== */
.energy-hud-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.energy-meter-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.meter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.meter-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: var(--text-muted);
}

.meter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot-kinetic { background: #06b6d4; box-shadow: 0 0 6px rgba(6, 182, 212, 0.6); }
.dot-potential { background: #818cf8; box-shadow: 0 0 6px rgba(129, 140, 248, 0.6); }
.dot-total { background: #10b981; box-shadow: 0 0 6px rgba(16, 185, 129, 0.6); }

.meter-val {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.meter-track {
  width: 100%;
  height: 8px;
  background: rgba(15, 23, 42, 0.8);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-pill);
  transition: width 60ms linear;
}

.meter-fill.kinetic {
  background: linear-gradient(90deg, #0284c7, #06b6d4);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.5);
}
.meter-fill.potential {
  background: linear-gradient(90deg, #6366f1, #818cf8);
  box-shadow: 0 0 10px rgba(129, 140, 248, 0.5);
}
.meter-fill.total {
  background: linear-gradient(90deg, #059669, #10b981);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

/* ==========================================================================
   Simulation Playback Controls
   ========================================================================== */
.playback-controls-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.btn-primary, .btn-secondary, .btn-preset {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  border: none;
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7 0%, #06b6d4 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(6, 182, 212, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0369a1 0%, #0891b2 100%);
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.45);
  transform: translateY(-1px);
}

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

.btn-primary.paused {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.9);
  color: var(--text-main);
  border: 1px solid var(--card-border);
}

.btn-secondary:hover {
  background: rgba(51, 65, 85, 0.9);
  border-color: rgba(148, 163, 184, 0.3);
}

.sim-speed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.5);
  padding: 6px 12px;
  border-radius: var(--radius-md);
}

.speed-buttons {
  display: flex;
  gap: 4px;
}

.btn-speed {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-speed.active {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent-cyan);
  border-color: rgba(56, 189, 248, 0.4);
}

.btn-speed:hover:not(.active) {
  color: var(--text-main);
}

/* ==========================================================================
   Presets Grid
   ========================================================================== */
.presets-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-preset {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 10px;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
}

.btn-preset:hover {
  background: rgba(30, 41, 59, 0.85);
  border-color: rgba(56, 189, 248, 0.4);
  transform: translateY(-1px);
}

.preset-title {
  font-size: 0.82rem;
  font-weight: 600;
}

.preset-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
}

/* ==========================================================================
   Sliders & Parameter Controls
   ========================================================================== */
.controls-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-label {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-symbol {
  color: var(--accent-cyan);
  font-family: ui-monospace, monospace;
  font-weight: 600;
}

.control-value-badge {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--card-border);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent-cyan);
  font-variant-numeric: tabular-nums;
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Range input styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: #1e293b;
  border-radius: var(--radius-pill);
  outline: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: background var(--transition-fast);
}

input[type="range"]:hover {
  background: #334155;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #38bdf8;
  border: 2px solid #0f172a;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.6);
  cursor: grab;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.18);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.9);
}

input[type="range"]::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.05);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #38bdf8;
  border: 2px solid #0f172a;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.6);
  cursor: grab;
}

/* Step Buttons (- / +) */
.btn-step {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.btn-step:hover {
  background: rgba(51, 65, 85, 0.9);
  color: var(--text-main);
  border-color: rgba(56, 189, 248, 0.4);
}

.btn-auto-crit {
  margin-top: 4px;
  align-self: flex-start;
  font-size: 0.72rem;
  padding: 3px 8px;
  background: rgba(168, 85, 247, 0.15);
  border: 1px solid rgba(168, 85, 247, 0.3);
  color: #c084fc;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition-fast);
}

.btn-auto-crit:hover {
  background: rgba(168, 85, 247, 0.25);
  border-color: rgba(168, 85, 247, 0.5);
}

/* ==========================================================================
   Damping Regime Card & Analysis
   ========================================================================== */
.regime-card-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.regime-hero-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--card-border);
}

.regime-name {
  font-size: 0.95rem;
  font-weight: 700;
}

.discriminant-tag {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 8px;
  border-radius: 4px;
}

.regime-explanation {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
  background: rgba(15, 23, 42, 0.4);
  padding: 10px;
  border-radius: var(--radius-md);
  border-left: 3px solid var(--accent-cyan);
}

/* ==========================================================================
   Metrics HUD Grid
   ========================================================================== */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-item {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--card-border);
  padding: 10px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.metric-title span {
  font-family: ui-monospace, monospace;
}

.metric-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.metric-value small {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 3px;
}

/* ==========================================================================
   Educational Formulas & Help Details
   ========================================================================== */
details.formulas-card {
  cursor: pointer;
}

details.formulas-card summary {
  list-style: none;
  user-select: none;
}

details.formulas-card summary::-webkit-details-marker {
  display: none;
}

.summary-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.details-body {
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.formula-block {
  background: #090e1a;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: ui-monospace, monospace;
  color: var(--accent-cyan);
  font-size: 0.82rem;
  overflow-x: auto;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 0.75rem;
  color: var(--text-dim);
  border-top: 1px solid rgba(148, 163, 184, 0.08);
  margin-top: auto;
}

.app-footer a {
  color: var(--accent-cyan);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}
