/* ============================================================
   Newton's Second Law — Virtual Physics Laboratory
   Premium Dark Engineering Theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ── CSS Custom Properties ─────────────────────────────── */
:root {
  /* Surface palette */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #1a1f35;
  --bg-card-hover: #222845;
  --bg-elevated: #242b45;
  --bg-inset: #0d1225;

  /* Glass */
  --glass-bg: rgba(26, 31, 53, 0.72);
  --glass-border: rgba(99, 120, 255, 0.12);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);

  /* Accent colours */
  --accent-blue: #6378ff;
  --accent-blue-glow: rgba(99, 120, 255, 0.35);
  --accent-cyan: #22d3ee;
  --accent-cyan-glow: rgba(34, 211, 238, 0.30);
  --accent-green: #34d399;
  --accent-green-glow: rgba(52, 211, 153, 0.30);
  --accent-red: #f87171;
  --accent-red-glow: rgba(248, 113, 113, 0.30);
  --accent-orange: #fb923c;
  --accent-orange-glow: rgba(251, 146, 60, 0.30);
  --accent-purple: #a78bfa;
  --accent-purple-glow: rgba(167, 139, 250, 0.30);
  --accent-yellow: #fbbf24;
  --accent-yellow-glow: rgba(251, 191, 36, 0.30);

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: var(--accent-blue);

  /* Borders */
  --border-subtle: rgba(148, 163, 184, 0.08);
  --border-normal: rgba(148, 163, 184, 0.14);
  --border-active: rgba(99, 120, 255, 0.45);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  /* Transitions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --transition-fast: 0.15s var(--ease-out);
  --transition-normal: 0.28s var(--ease-out);
  --transition-slow: 0.45s var(--ease-out);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(99, 120, 255, 0.25); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(99, 120, 255, 0.45); }

/* ── Animated Background ───────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 800px 600px at 15% 20%, rgba(99, 120, 255, 0.06) 0%, transparent 70%),
    radial-gradient(ellipse 600px 500px at 85% 80%, rgba(34, 211, 238, 0.05) 0%, transparent 70%),
    radial-gradient(ellipse 500px 400px at 50% 50%, rgba(167, 139, 250, 0.03) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: bgPulse 12s ease-in-out infinite alternate;
}

@keyframes bgPulse {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* ── Header ────────────────────────────────────────────── */
.lab-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 2px 24px rgba(0, 0, 0, 0.35);
}

.lab-header .logo-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.lab-header .logo-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 0 18px var(--accent-blue-glow);
}

.lab-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.lab-header .subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.header-badge.live {
  border-color: rgba(52, 211, 153, 0.3);
  color: var(--accent-green);
}

.header-badge.live::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: livePulse 1.5s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--accent-green-glow); }
  50% { opacity: 0.5; box-shadow: 0 0 0 6px transparent; }
}

/* Sound toggle */
.btn-sound {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  transition: all var(--transition-fast);
}

.btn-sound:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: var(--bg-card-hover);
}

.btn-sound.muted { color: var(--text-muted); opacity: 0.5; }

/* ── Main Layout ───────────────────────────────────────── */
.lab-container {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1800px;
  margin: 0 auto;
  min-height: calc(100vh - 70px);
}

/* ── Sidebar (Controls) ───────────────────────────────── */
.sidebar {
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: calc(100vh - 90px);
  padding-right: 4px;
}

/* ── Card System ───────────────────────────────────────── */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--glass-shadow);
  transition: all var(--transition-normal);
}

.card:hover {
  border-color: rgba(99, 120, 255, 0.2);
  box-shadow: var(--glass-shadow), 0 0 20px rgba(99, 120, 255, 0.05);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.card-title .icon {
  font-size: 1rem;
}

/* ── Slider Controls ───────────────────────────────────── */
.control-group {
  margin-bottom: 16px;
}

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

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.control-label span {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.control-value {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-inset);
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  min-width: 70px;
  text-align: center;
}

/* Custom range slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 99px;
  background: var(--bg-inset);
  outline: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-blue);
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 10px var(--accent-blue-glow);
  cursor: grab;
  transition: all var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 16px var(--accent-blue-glow);
}

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

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-blue);
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 10px var(--accent-blue-glow);
  cursor: grab;
}

/* Slider accent colours */
input[type="range"].slider-mass::-webkit-slider-thumb { background: var(--accent-cyan); box-shadow: 0 0 10px var(--accent-cyan-glow); }
input[type="range"].slider-force::-webkit-slider-thumb { background: var(--accent-red); box-shadow: 0 0 10px var(--accent-red-glow); }
input[type="range"].slider-friction::-webkit-slider-thumb { background: var(--accent-orange); box-shadow: 0 0 10px var(--accent-orange-glow); }

input[type="range"].slider-mass::-moz-range-thumb { background: var(--accent-cyan); box-shadow: 0 0 10px var(--accent-cyan-glow); }
input[type="range"].slider-force::-moz-range-thumb { background: var(--accent-red); box-shadow: 0 0 10px var(--accent-red-glow); }
input[type="range"].slider-friction::-moz-range-thumb { background: var(--accent-orange); box-shadow: 0 0 10px var(--accent-orange-glow); }

/* ── Buttons ───────────────────────────────────────────── */
.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  border-color: var(--accent-blue);
  background: var(--bg-card-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), #4f5fe8);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-blue-glow);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px var(--accent-blue-glow);
  border-color: transparent;
  background: linear-gradient(135deg, #7a8cff, var(--accent-blue));
}

.btn-success {
  background: linear-gradient(135deg, var(--accent-green), #2ab586);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-green-glow);
}

.btn-success:hover {
  box-shadow: 0 6px 20px var(--accent-green-glow);
  border-color: transparent;
}

.btn-danger {
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--accent-red);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.1);
  border-color: var(--accent-red);
}

.btn-warning {
  border-color: rgba(251, 191, 36, 0.3);
  color: var(--accent-yellow);
}

.btn-warning:hover {
  background: rgba(251, 191, 36, 0.1);
  border-color: var(--accent-yellow);
}

.btn .icon {
  font-size: 1rem;
}

.btn-full { flex: 1 1 100%; }

/* ── Gravity Presets ───────────────────────────────────── */
.gravity-presets {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.gravity-btn {
  flex: 1;
  padding: 7px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-inset);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-fast);
  line-height: 1.3;
}

.gravity-btn:hover {
  border-color: var(--accent-purple);
  color: var(--accent-purple);
  background: rgba(167, 139, 250, 0.08);
}

.gravity-btn.active {
  border-color: var(--accent-purple);
  background: rgba(167, 139, 250, 0.15);
  color: var(--accent-purple);
  box-shadow: 0 0 10px var(--accent-purple-glow);
}

/* ── Experiment Presets ────────────────────────────────── */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preset-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-inset);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

.preset-btn:hover {
  border-color: var(--accent-blue);
  background: rgba(99, 120, 255, 0.06);
  color: var(--text-primary);
  transform: translateX(3px);
}

.preset-btn.active {
  border-color: var(--accent-blue);
  background: rgba(99, 120, 255, 0.12);
  color: var(--accent-blue);
}

.preset-btn .preset-icon {
  font-size: 1.15rem;
  flex-shrink: 0;
}

.preset-btn .preset-info {
  display: flex;
  flex-direction: column;
}

.preset-btn .preset-name {
  font-weight: 600;
  font-size: 0.78rem;
}

.preset-btn .preset-desc {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ── Main Content Area ─────────────────────────────────── */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ── SVG Simulation Canvas ─────────────────────────────── */
.sim-canvas-wrapper {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

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

/* ── Telemetry HUD (overlaid on SVG) ───────────────────── */
.telemetry-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 5;
}

.telem-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  background: rgba(10, 14, 26, 0.82);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.telem-chip .telem-label {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.telem-chip .telem-value {
  min-width: 50px;
  text-align: right;
}

.telem-chip.chip-mass .telem-value { color: var(--accent-cyan); }
.telem-chip.chip-force .telem-value { color: var(--accent-red); }
.telem-chip.chip-accel .telem-value { color: var(--accent-green); }
.telem-chip.chip-vel .telem-value { color: var(--accent-yellow); }
.telem-chip.chip-dist .telem-value { color: var(--accent-purple); }
.telem-chip.chip-net .telem-value { color: var(--accent-orange); }

/* ── Formula Overlay ───────────────────────────────────── */
.formula-overlay {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(10, 14, 26, 0.88);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 14px 22px;
  text-align: center;
  transition: all var(--transition-normal);
  max-width: 90%;
  opacity: 0;
  pointer-events: none;
}

.formula-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.formula-line {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.6;
}

.formula-line:last-child { margin-bottom: 0; }

.formula-line .var-f { color: var(--accent-red); }
.formula-line .var-m { color: var(--accent-cyan); }
.formula-line .var-a { color: var(--accent-green); }
.formula-line .var-fk { color: var(--accent-orange); }
.formula-line .var-fn { color: var(--accent-purple); }
.formula-line .op { color: var(--text-muted); }

/* ── Graph Section ─────────────────────────────────────── */
.graphs-section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.graph-card {
  position: relative;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--glass-shadow);
  min-height: 200px;
  transition: all var(--transition-normal);
}

.graph-card:hover {
  border-color: rgba(99, 120, 255, 0.2);
}

.graph-card .graph-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.graph-card canvas {
  display: block;
  width: 100%;
  height: 170px;
  border-radius: var(--radius-sm);
}

/* ── Status Bar ────────────────────────────────────────── */
.status-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(10, 14, 26, 0.82);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.status-indicator::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-indicator.running {
  color: var(--accent-green);
  border-color: rgba(52, 211, 153, 0.3);
}

.status-indicator.running::before {
  background: var(--accent-green);
  animation: livePulse 1.2s ease-in-out infinite;
}

.status-indicator.paused {
  color: var(--accent-yellow);
  border-color: rgba(251, 191, 36, 0.3);
}

.status-indicator.paused::before {
  background: var(--accent-yellow);
}

.time-display {
  padding: 5px 12px;
  border-radius: 99px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(10, 14, 26, 0.82);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  color: var(--accent-cyan);
}

/* ── Animations ────────────────────────────────────────── */
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulseGlow {
  0%, 100% { filter: drop-shadow(0 0 4px currentColor); }
  50% { filter: drop-shadow(0 0 12px currentColor); }
}

.sidebar { animation: slideInLeft 0.5s var(--ease-out); }
.main-content { animation: fadeIn 0.6s var(--ease-out) 0.1s both; }
.graph-card { animation: slideInUp 0.5s var(--ease-out) both; }
.graph-card:nth-child(1) { animation-delay: 0.15s; }
.graph-card:nth-child(2) { animation-delay: 0.25s; }
.graph-card:nth-child(3) { animation-delay: 0.35s; }

/* ── SVG-specific Styling ──────────────────────────────── */
.track-surface { transition: fill var(--transition-slow); }
.block-body { transition: all var(--transition-fast); }
.force-arrow { transition: opacity var(--transition-fast); }
.accel-arrow { transition: opacity var(--transition-fast); }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 1200px) {
  .graphs-section {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 1024px) {
  .lab-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .sidebar {
    grid-row: auto;
    flex-direction: row;
    flex-wrap: wrap;
    max-height: none;
    overflow-y: visible;
  }

  .sidebar .card {
    flex: 1 1 280px;
    min-width: 260px;
  }
}

@media (max-width: 768px) {
  html { font-size: 13px; }

  .lab-header {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .lab-container {
    padding: 10px;
    gap: 10px;
  }

  .graphs-section {
    grid-template-columns: 1fr;
  }

  .telemetry-hud {
    gap: 4px;
  }

  .telem-chip {
    font-size: 0.68rem;
    padding: 3px 8px;
  }
}

/* ── Data Export Button ────────────────────────────────── */
.btn-export {
  border-color: rgba(34, 211, 238, 0.3);
  color: var(--accent-cyan);
}

.btn-export:hover {
  background: rgba(34, 211, 238, 0.1);
  border-color: var(--accent-cyan);
}

/* ── Tooltip ───────────────────────────────────────────── */
.tooltip {
  position: absolute;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(10, 14, 26, 0.92);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.tooltip.visible {
  opacity: 1;
}

/* ================= RESPONSIVE MEDIA QUERIES ================= */

/* Tablet */
@media screen and (max-width: 1024px) {
  .lab-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    min-height: auto;
  }
  .sidebar {
    grid-row: auto;
    max-height: none;
    overflow-y: visible;
  }
  .graphs-section {
    grid-template-columns: 1fr;
  }
}

/* Mobile Portrait */
@media screen and (max-width: 767px) and (orientation: portrait) {
  .lab-container {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 10px;
    min-height: auto;
  }
  .sidebar {
    max-height: none;
    overflow-y: visible;
    order: 2;
  }
  .sim-viewport, .canvas-area {
    order: 1;
  }
  .graphs-section {
    grid-template-columns: 1fr;
    order: 3;
  }
  canvas {
    width: 100% !important;
    height: auto !important;
    max-height: 50vh;
  }
  /* Touch-friendly targets */
  .btn, button, select, input[type="range"] {
    min-height: 44px;
    font-size: 16px !important;
  }
  .lab-header {
    padding: 8px 12px;
    flex-wrap: wrap;
  }
}

/* Mobile Landscape */
/* Mobile Landscape (kept) */
@media screen and (max-width: 950px) and (orientation: landscape) {
  .lab-container {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: auto;
    padding: 8px;
    gap: 10px;
    min-height: auto;
  }
  .sidebar {
    max-height: calc(100vh - 80px);
    overflow-y: auto;
  }
}
