/* ============================================================
   8:1 Multiplexer Virtual Laboratory — Style Sheet
   Virtual Instrumentation Labs Interactive Learning Platform
   ============================================================ */

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

:root {
  /* Laboratory Colour Palette */
  --lab-bg: #ffffff;
  --panel-bg: #f8fafc;
  --panel-border: #cbd5e1;
  --header-bg: #0f172a;
  --header-text: #ffffff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  /* Signal & Wire Colors */
  --wire-off: #94a3b8;
  --wire-on: #2563eb;
  --wire-on-glow: rgba(37, 99, 235, 0.4);
  --signal-high: #2563eb;
  --signal-low: #64748b;

  /* Select line color distinction */
  --select-line-bg: #f1f5f9;
  --select-accent: #8b5cf6;
  --select-accent-bg: #f3e8ff;

  /* LED Colors */
  --led-off-bg: #475569;
  --led-off-border: #334155;
  --led-on-bg: #10b981;
  --led-on-border: #059669;
  --led-on-glow: 0 0 16px rgba(16, 185, 129, 0.8);

  --success: #16a34a;
  --success-bg: #dcfce7;
  --success-border: #86efac;

  --gate-fill: #f1f5f9;
  --gate-stroke: #1e293b;
  --gate-active-fill: #eff6ff;
  --gate-active-stroke: #2563eb;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --font-sans: 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--lab-bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Laboratory Title Bar ──────────────────────────────────── */
.lab-title-bar {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.lab-title-container h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.lab-title-bar .lab-subtitle {
  font-size: 0.82rem;
  color: #94a3b8;
  font-weight: 400;
  display: block;
}

.lab-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  padding: 4px 12px;
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ── Main Layout Container ─────────────────────────────────── */
.lab-main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  flex: 1;
}

/* ── Toolbar & Control Bar ─────────────────────────────────── */
.lab-toolbar {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.toolbar-divider {
  width: 1px;
  height: 28px;
  background: var(--panel-border);
}

/* Button Component Styles */
.btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  user-select: none;
}

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

.btn--mode {
  background: #ffffff;
  border-color: var(--panel-border);
  color: var(--text-secondary);
}

.btn--mode:hover {
  background: #f1f5f9;
  color: var(--text-primary);
}

.btn--mode.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn--secondary {
  background: #ffffff;
  border-color: var(--panel-border);
  color: var(--text-primary);
}

.btn--secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn--outline {
  background: transparent;
  border-color: var(--panel-border);
  color: var(--text-secondary);
}

.btn--outline:hover {
  background: #f1f5f9;
  color: var(--text-primary);
}

.btn--accent {
  background: var(--select-accent);
  border-color: var(--select-accent);
  color: #ffffff;
}

.btn--accent:hover {
  background: #7c3aed;
}

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

/* ── Panel Cards Base ──────────────────────────────────────── */
.lab-panel {
  background: #ffffff;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.lab-panel__header {
  background: var(--panel-bg);
  padding: 12px 20px;
  border-bottom: 1px solid var(--panel-border);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lab-panel__body {
  padding: 20px;
}

/* ── Top Grid (Input Controls + Output Display) ────────────── */
.lab-top-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

/* Section Subheadings inside panels */
.input-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Input Control Groups */
.input-controls-grid-8 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.select-controls-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

/* Input Control Card */
.input-control-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
}

.input-control-card.active-selected {
  background: var(--accent-light);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.input-control-card.select-card {
  background: var(--select-line-bg);
  border-color: #ddd6fe;
}

.input-control-card.select-card.active-selected-select {
  background: var(--select-accent-bg);
  border-color: var(--select-accent);
}

.input-meta {
  display: flex;
  flex-direction: column;
}

.input-symbol {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 1rem;
  color: var(--text-primary);
}

.input-role {
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Toggle Switch Component */
.toggle-btn {
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  width: 54px;
  height: 28px;
  padding: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.25s ease;
}

.toggle-btn__track {
  width: 100%;
  display: flex;
  align-items: center;
  position: relative;
}

.toggle-btn__knob {
  width: 20px;
  height: 20px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.25s ease;
  position: absolute;
  left: 0;
}

.toggle-btn__state {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.78rem;
  width: 100%;
  text-anchor: middle;
  text-align: right;
  padding-right: 4px;
  color: var(--text-secondary);
}

.toggle-btn.high {
  background: var(--accent);
  border-color: var(--accent-hover);
}

.toggle-btn.high .toggle-btn__knob {
  transform: translateX(26px);
}

.toggle-btn.high .toggle-btn__state {
  text-align: left;
  padding-left: 6px;
  padding-right: 0;
  color: #ffffff;
}

.toggle-btn.select-high {
  background: var(--select-accent);
  border-color: #7c3aed;
}

.toggle-btn.select-high .toggle-btn__knob {
  transform: translateX(26px);
}

.toggle-btn.select-high .toggle-btn__state {
  text-align: left;
  padding-left: 6px;
  padding-right: 0;
  color: #ffffff;
}

/* ── Output & Indicator Cards ─────────────────────────────── */
.output-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
}

.indicator-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.indicator-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.indicator-card__label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.indicator-card__val {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
}

.indicator-card__val.selected-channel {
  color: var(--accent);
}

.indicator-card__val.select-bits {
  color: var(--select-accent);
}

/* LED Component */
.led-container {
  display: flex;
  align-items: center;
  gap: 14px;
}

.led {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--led-off-bg);
  border: 3px solid var(--led-off-border);
  transition: all 0.3s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

.led.active {
  background: var(--led-on-bg);
  border-color: var(--led-on-border);
  box-shadow: var(--led-on-glow);
}

.led-status-text {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.led-status-text.high {
  color: var(--success);
}

.badge-row-active {
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
}

/* ── Schematic Viewport & SVG ──────────────────────────────── */
.schematic-viewport {
  width: 100%;
  overflow-x: auto;
  background: #ffffff;
  border-radius: var(--radius-md);
  display: flex;
  justify-content: center;
  padding: 10px 0;
}

.circuit-svg {
  width: 100%;
  max-width: 1100px;
  height: auto;
  display: block;
}

/* SVG Wires & Gates Styling */
.circuit-svg .wire {
  stroke: var(--wire-off);
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.2s ease;
}

.circuit-svg .wire.select-wire {
  stroke: #a7f3d0;
  stroke: #cbd5e1;
}

.circuit-svg .wire.active {
  stroke: var(--wire-on);
  stroke-width: 3.2;
  filter: drop-shadow(0 0 4px var(--wire-on-glow));
}

.circuit-svg .wire.select-active {
  stroke: var(--select-accent);
  stroke-width: 3.2;
  filter: drop-shadow(0 0 4px rgba(139, 92, 246, 0.4));
}

.circuit-svg .wire.animated-active {
  stroke: var(--wire-on);
  stroke-width: 3.8;
  stroke-dasharray: 8 4;
  animation: dash 0.8s linear infinite;
  filter: drop-shadow(0 0 6px var(--wire-on-glow));
}

@keyframes dash {
  to {
    stroke-dashoffset: -24;
  }
}

.circuit-svg .gate-body {
  fill: var(--gate-fill);
  stroke: var(--gate-stroke);
  stroke-width: 2;
  transition: all 0.2s ease;
}

.circuit-svg .gate-body.active {
  fill: var(--gate-active-fill);
  stroke: var(--gate-active-stroke);
  stroke-width: 2.5;
}

.circuit-svg .junction-dot {
  fill: #64748b;
  transition: fill 0.2s ease;
}

.circuit-svg .junction-dot.active {
  fill: var(--accent);
}

.circuit-svg .junction-dot.select-active {
  fill: var(--select-accent);
}

.circuit-svg .gate-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  fill: var(--text-primary);
  text-anchor: middle;
  dominant-baseline: central;
}

.circuit-svg .gate-sublabel {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  fill: var(--text-secondary);
  text-anchor: middle;
  dominant-baseline: central;
}

.circuit-svg .svg-switch rect {
  transition: all 0.2s ease;
}

/* ── Evaluation Terms Panel ────────────────────────────────── */
.eval-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.eval-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s ease;
}

.eval-card.active-term {
  background: var(--accent-light);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.eval-card__title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.eval-card__eq {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.eval-card.active-term .eval-card__eq {
  color: var(--accent);
  font-weight: 700;
}

.eval-card__result {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  align-self: flex-end;
}

.eval-summary-box {
  background: #f1f5f9;
  border-left: 4px solid var(--accent);
  padding: 10px 14px;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.eval-summary-box .hl {
  font-weight: 700;
  color: var(--accent);
}

.eval-summary-box .hl-val {
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--success);
}

/* ── Truth Table Panel ─────────────────────────────────────── */
.table-responsive {
  overflow-x: auto;
}

.lab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: center;
}

.lab-table th,
.lab-table td {
  padding: 10px 14px;
  border: 1px solid var(--panel-border);
}

.lab-table th {
  background: var(--panel-bg);
  color: var(--text-secondary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.lab-table tr {
  transition: background-color 0.2s ease;
}

.lab-table tr:hover {
  background: #f8fafc;
}

.lab-table tr.active-row {
  background: var(--accent-light) !important;
  font-weight: 700;
}

.lab-table tr.active-row td {
  border-color: #93c5fd;
  color: var(--accent-hover);
}

.lab-table td.col-mono {
  font-family: var(--font-mono);
}

/* ── Educational Theory & Scaling Panel ─────────────────────── */
.theory-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.theory-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.theory-card h3 {
  font-size: 1rem;
  color: var(--text-primary);
  border-bottom: 2px solid var(--panel-border);
  padding-bottom: 6px;
}

.theory-card p,
.theory-card ul {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.theory-card ul {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.formula-box {
  background: var(--panel-bg);
  border: 1px dashed var(--panel-border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  text-align: center;
}

.scaling-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 0.82rem;
}

.scaling-table th,
.scaling-table td {
  border: 1px solid var(--panel-border);
  padding: 6px 10px;
  text-align: center;
}

.scaling-table tr.highlight-scaling {
  background: var(--select-accent-bg);
  font-weight: 700;
  color: var(--select-accent);
}

/* ── Footer ────────────────────────────────────────────────── */
.lab-footer {
  margin-top: auto;
  background: var(--header-bg);
  color: #94a3b8;
  text-align: center;
  padding: 16px;
  font-size: 0.78rem;
  border-top: 1px solid #1e293b;
}

/* ── Responsive Design Adjustments ──────────────────────────── */
@media (max-width: 1024px) {
  .lab-top-grid {
    grid-template-columns: 1fr;
  }

  .eval-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .theory-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .lab-title-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .input-controls-grid-8 {
    grid-template-columns: repeat(2, 1fr);
  }

  .select-controls-grid-3 {
    grid-template-columns: 1fr;
  }

  .eval-grid {
    grid-template-columns: 1fr;
  }

  .lab-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-group {
    justify-content: center;
  }

  .toolbar-divider {
    display: none;
  }
}


/* -- Dark Theme Overrides (Black Theme) --------------------- */
[data-theme="dark"],
html.dark {
  --lab-bg: #080d18;
  --panel-bg: #0f172a;
  --panel-border: #1e293b;
  --header-bg: #0b1120;
  --header-text: #f8fafc;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --accent-light: #1e3a5f;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --wire-off: #475569;
  --wire-on: #38bdf8;
  --wire-on-glow: rgba(56, 189, 248, 0.4);
  --signal-high: #38bdf8;
  --signal-low: #475569;
  --select-accent: #a78bfa;
  --select-accent-bg: #2e1065;
  --select-border: #7c3aed;
  --input-accent-bg: #162036;
  --input-accent: #38bdf8;
  --led-off-bg: #1e293b;
  --led-off-border: #334155;
  --led-on-bg: #22c55e;
  --led-on-border: #16a34a;
  --led-on-glow: 0 0 16px rgba(34, 197, 94, 0.75);
  --success: #22c55e;
  --success-bg: #062d1f;
  --success-border: #065f46;
  --danger: #ef4444;
  --danger-bg: #450a0a;
  --danger-border: #991b1b;
  --danger-text: #f87171;
  --gate-fill: #162036;
  --gate-stroke: #38bdf8;
  --gate-active-fill: #0c2d48;
  --gate-active-stroke: #38bdf8;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.55);
}

[data-theme="dark"] body,
html.dark body {
  background-color: #070b14 !important;
  color: #f8fafc !important;
}

/* Header & Title Bar */
[data-theme="dark"] .lab-title-bar,
html.dark .lab-title-bar {
  background: #080d1a !important;
  border-bottom: 1px solid #1e293b !important;
  color: #f8fafc !important;
}

[data-theme="dark"] .lab-title-container h1,
html.dark .lab-title-container h1 {
  color: #f8fafc !important;
}

[data-theme="dark"] .lab-badge,
html.dark .lab-badge {
  background: rgba(56, 189, 248, 0.15) !important;
  border: 1px solid #38bdf8 !important;
  color: #38bdf8 !important;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.3) !important;
}

/* Toolbar & Buttons */
[data-theme="dark"] .lab-toolbar,
html.dark .lab-toolbar {
  background: #0d1424 !important;
  border-color: #1e293b !important;
}

[data-theme="dark"] .toolbar-label,
html.dark .toolbar-label {
  color: #94a3b8 !important;
}

[data-theme="dark"] .toolbar-divider,
html.dark .toolbar-divider {
  background: #1e293b !important;
}

[data-theme="dark"] .btn--mode,
html.dark .btn--mode {
  background: #162036 !important;
  border-color: #334155 !important;
  color: #cbd5e1 !important;
}

[data-theme="dark"] .btn--mode:hover,
html.dark .btn--mode:hover {
  background: #1e293b !important;
  border-color: #38bdf8 !important;
  color: #38bdf8 !important;
}

[data-theme="dark"] .btn--mode.active,
html.dark .btn--mode.active {
  background: #0284c7 !important;
  border-color: #38bdf8 !important;
  color: #ffffff !important;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.4) !important;
}

[data-theme="dark"] .btn,
html.dark .btn {
  background: #162036 !important;
  border-color: #334155 !important;
  color: #f1f5f9 !important;
}

[data-theme="dark"] .btn:hover,
html.dark .btn:hover {
  background: #1e293b !important;
  border-color: #38bdf8 !important;
  color: #38bdf8 !important;
}

[data-theme="dark"] .btn--primary,
html.dark .btn--primary {
  background: #0284c7 !important;
  border-color: #0284c7 !important;
  color: #ffffff !important;
}

[data-theme="dark"] .btn--primary:hover,
html.dark .btn--primary:hover {
  background: #0369a1 !important;
  border-color: #38bdf8 !important;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4) !important;
}

[data-theme="dark"] .btn--secondary,
html.dark .btn--secondary {
  background: #162036 !important;
  border-color: #334155 !important;
  color: #f1f5f9 !important;
}

[data-theme="dark"] .btn--secondary:hover,
html.dark .btn--secondary:hover {
  background: #1e293b !important;
  border-color: #38bdf8 !important;
  color: #38bdf8 !important;
}

[data-theme="dark"] .btn--outline,
html.dark .btn--outline {
  background: #162036 !important;
  border-color: #334155 !important;
  color: #cbd5e1 !important;
}

[data-theme="dark"] .btn--accent,
html.dark .btn--accent {
  background: #0284c7 !important;
  border-color: #0284c7 !important;
  color: #ffffff !important;
}

/* Panels */
[data-theme="dark"] .lab-panel,
html.dark .lab-panel {
  background: #0d1424 !important;
  border-color: #1e293b !important;
}

[data-theme="dark"] .lab-panel__header,
html.dark .lab-panel__header {
  background: #080d1a !important;
  color: #f8fafc !important;
  border-bottom-color: #1e293b !important;
}

/* Input Control Cards */
[data-theme="dark"] .input-control-card,
html.dark .input-control-card {
  background: #111a2e !important;
  border-color: #1e293b !important;
}

[data-theme="dark"] .input-control-card:hover,
html.dark .input-control-card:hover {
  border-color: #38bdf8 !important;
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.25) !important;
}

[data-theme="dark"] .input-control-card.select-card,
html.dark .input-control-card.select-card {
  background: #18132b !important;
  border-color: #3b1d6e !important;
}

[data-theme="dark"] .input-control-card.select-card:hover,
html.dark .input-control-card.select-card:hover {
  border-color: #a78bfa !important;
  box-shadow: 0 4px 16px rgba(167, 139, 250, 0.25) !important;
}

[data-theme="dark"] .input-symbol,
html.dark .input-symbol {
  color: #f8fafc !important;
}

[data-theme="dark"] .input-role,
html.dark .input-role {
  color: #94a3b8 !important;
}

[data-theme="dark"] .input-section-title span,
html.dark .input-section-title span {
  color: #cbd5e1 !important;
}

/* Toggles */
[data-theme="dark"] .toggle-btn__track,
html.dark .toggle-btn__track {
  background: #1e293b !important;
  border: 1px solid #334155 !important;
}

[data-theme="dark"] .toggle-btn__knob,
html.dark .toggle-btn__knob {
  background: #f8fafc !important;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5) !important;
}

[data-theme="dark"] .toggle-btn__state,
html.dark .toggle-btn__state {
  color: #94a3b8 !important;
}

[data-theme="dark"] .toggle-btn.high .toggle-btn__track,
html.dark .toggle-btn.high .toggle-btn__track,
[data-theme="dark"] .toggle-btn.active .toggle-btn__track,
html.dark .toggle-btn.active .toggle-btn__track {
  background: #0284c7 !important;
  border-color: #38bdf8 !important;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.6) !important;
}

[data-theme="dark"] .toggle-btn.high .toggle-btn__state,
html.dark .toggle-btn.high .toggle-btn__state {
  color: #38bdf8 !important;
  font-weight: 800 !important;
}

[data-theme="dark"] .toggle-btn.select-high .toggle-btn__track,
html.dark .toggle-btn.select-high .toggle-btn__track {
  background: #7c3aed !important;
  border-color: #a78bfa !important;
  box-shadow: 0 0 12px rgba(167, 139, 250, 0.6) !important;
}

[data-theme="dark"] .toggle-btn.select-high .toggle-btn__state,
html.dark .toggle-btn.select-high .toggle-btn__state {
  color: #a78bfa !important;
  font-weight: 800 !important;
}

/* Output Indicator Cards */
[data-theme="dark"] .indicator-card,
html.dark .indicator-card {
  background: #111a2e !important;
  border-color: #1e293b !important;
}

[data-theme="dark"] .indicator-card__label,
html.dark .indicator-card__label {
  color: #94a3b8 !important;
}

[data-theme="dark"] .indicator-card__val,
html.dark .indicator-card__val {
  background: rgba(56, 189, 248, 0.15) !important;
  color: #38bdf8 !important;
}

[data-theme="dark"] .indicator-card__val.selected-channel,
html.dark .indicator-card__val.selected-channel {
  background: rgba(167, 139, 250, 0.2) !important;
  color: #a78bfa !important;
}

[data-theme="dark"] .indicator-card__val.select-bits,
html.dark .indicator-card__val.select-bits {
  background: rgba(167, 139, 250, 0.2) !important;
  color: #a78bfa !important;
}

[data-theme="dark"] .badge-row-active,
html.dark .badge-row-active {
  background: rgba(56, 189, 248, 0.15) !important;
  border: 1px solid #38bdf8 !important;
  color: #38bdf8 !important;
}

[data-theme="dark"] .badge-row-active.auto,
html.dark .badge-row-active.auto {
  background: rgba(167, 139, 250, 0.18) !important;
  border: 1px solid #a78bfa !important;
  color: #a78bfa !important;
}

/* ── Schematic Panel & SVG Canvas ── */
[data-theme="dark"] .schematic-panel__body,
html.dark .schematic-panel__body {
  background: #060a14 !important;
}

[data-theme="dark"] .schematic-viewport,
html.dark .schematic-viewport {
  background: transparent !important;
}

[data-theme="dark"] .circuit-svg,
html.dark .circuit-svg {
  background: transparent !important;
}

/* Hardcoded white SVG background rects override */
[data-theme="dark"] #view-gate-level>rect:first-child,
html.dark #view-gate-level>rect:first-child,
[data-theme="dark"] #view-functional>rect:first-child,
html.dark #view-functional>rect:first-child {
  fill: #0b1120 !important;
}

/* SVG Data Switch buttons */
[data-theme="dark"] #view-gate-level .svg-switch rect,
html.dark #view-gate-level .svg-switch rect {
  fill: #111a2e !important;
  stroke: #2563eb !important;
}

[data-theme="dark"] #view-gate-level .svg-switch text,
html.dark #view-gate-level .svg-switch text {
  fill: #93c5fd !important;
}

/* SVG Select Switch buttons (S2, S1, S0) */
[data-theme="dark"] #svg-sw-s2 rect,
html.dark #svg-sw-s2 rect,
[data-theme="dark"] #svg-sw-s1 rect,
html.dark #svg-sw-s1 rect,
[data-theme="dark"] #svg-sw-s0 rect,
html.dark #svg-sw-s0 rect {
  fill: #1a1230 !important;
  stroke: #8b5cf6 !important;
}

[data-theme="dark"] #svg-sw-s2 text,
html.dark #svg-sw-s2 text,
[data-theme="dark"] #svg-sw-s1 text,
html.dark #svg-sw-s1 text,
[data-theme="dark"] #svg-sw-s0 text,
html.dark #svg-sw-s0 text {
  fill: #c4b5fd !important;
}

/* Vertical Bus Labels */
[data-theme="dark"] text.gate-sublabel,
html.dark text.gate-sublabel {
  fill: #c4b5fd !important;
}

/* Logic Gates */
[data-theme="dark"] .gate-body,
html.dark .gate-body {
  fill: #162036 !important;
  stroke: #38bdf8 !important;
  stroke-width: 2.5;
}

[data-theme="dark"] .gate-body.active,
html.dark .gate-body.active {
  fill: #0c2d48 !important;
  stroke: #38bdf8 !important;
  stroke-width: 3;
  filter: drop-shadow(0 0 12px rgba(56, 189, 248, 0.75)) !important;
}

[data-theme="dark"] .gate-label,
html.dark .gate-label {
  fill: #f8fafc !important;
}

/* NOT gates inside SVG */
[data-theme="dark"] #gate-not2,
html.dark #gate-not2,
[data-theme="dark"] #gate-not1,
html.dark #gate-not1,
[data-theme="dark"] #gate-not0,
html.dark #gate-not0 {
  fill: #162036 !important;
  stroke: #8b5cf6 !important;
}

[data-theme="dark"] #gate-not2.active,
html.dark #gate-not2.active,
[data-theme="dark"] #gate-not1.active,
html.dark #gate-not1.active,
[data-theme="dark"] #gate-not0.active,
html.dark #gate-not0.active {
  fill: #22123d !important;
  stroke: #a78bfa !important;
  filter: drop-shadow(0 0 10px rgba(167, 139, 250, 0.75)) !important;
}

[data-theme="dark"] #gate-not2-bubble,
html.dark #gate-not2-bubble,
[data-theme="dark"] #gate-not1-bubble,
html.dark #gate-not1-bubble,
[data-theme="dark"] #gate-not0-bubble,
html.dark #gate-not0-bubble {
  fill: #162036 !important;
  stroke: #8b5cf6 !important;
}

/* Wires */
[data-theme="dark"] .wire,
html.dark .wire {
  stroke: #475569 !important;
}

[data-theme="dark"] .wire.active,
html.dark .wire.active {
  stroke: #38bdf8 !important;
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.85)) !important;
}

[data-theme="dark"] .wire.select-wire,
html.dark .wire.select-wire {
  stroke: #475569 !important;
}

[data-theme="dark"] .wire.select-active,
html.dark .wire.select-active,
[data-theme="dark"] .wire.select-wire.active,
html.dark .wire.select-wire.active {
  stroke: #a78bfa !important;
  filter: drop-shadow(0 0 6px rgba(167, 139, 250, 0.85)) !important;
}

[data-theme="dark"] .wire.animated-active,
html.dark .wire.animated-active {
  stroke: #38bdf8 !important;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.95)) !important;
}

/* Junction dots */
[data-theme="dark"] .junction-dot,
html.dark .junction-dot {
  fill: #475569 !important;
}

[data-theme="dark"] .junction-dot.active,
html.dark .junction-dot.active {
  fill: #38bdf8 !important;
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.9)) !important;
}

[data-theme="dark"] .junction-dot.select-active,
html.dark .junction-dot.select-active {
  fill: #a78bfa !important;
  filter: drop-shadow(0 0 6px rgba(167, 139, 250, 0.9)) !important;
}

/* Functional IC Block View */
[data-theme="dark"] #ic-mux-box,
html.dark #ic-mux-box {
  fill: #111a2e !important;
  stroke: #38bdf8 !important;
}

[data-theme="dark"] #view-functional text,
html.dark #view-functional text {
  fill: #f8fafc !important;
}

[data-theme="dark"] #ic-selected-text,
html.dark #ic-selected-text {
  fill: #38bdf8 !important;
}

[data-theme="dark"] #view-functional rect,
html.dark #view-functional rect {
  fill: #162036 !important;
  stroke: #334155 !important;
}

/* Evaluation Panel */
[data-theme="dark"] .eval-card,
html.dark .eval-card {
  background: #111a2e !important;
  border-color: #1e293b !important;
}

[data-theme="dark"] .eval-card__title,
html.dark .eval-card__title {
  color: #94a3b8 !important;
}

[data-theme="dark"] .eval-card__eq,
html.dark .eval-card__eq {
  color: #cbd5e1 !important;
}

[data-theme="dark"] .eval-card__result,
html.dark .eval-card__result {
  color: #64748b !important;
}

[data-theme="dark"] .eval-card.active-term,
html.dark .eval-card.active-term {
  background: #0c2d48 !important;
  border-color: #38bdf8 !important;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.3) !important;
}

[data-theme="dark"] .eval-card.active-term .eval-card__title,
html.dark .eval-card.active-term .eval-card__title {
  color: #38bdf8 !important;
}

[data-theme="dark"] .eval-card.active-term .eval-card__result,
html.dark .eval-card.active-term .eval-card__result {
  color: #38bdf8 !important;
}

[data-theme="dark"] .eval-summary-box,
html.dark .eval-summary-box {
  background: #0c192e !important;
  border-color: #1e3a5f !important;
  color: #cbd5e1 !important;
}

[data-theme="dark"] .eval-summary-box strong,
html.dark .eval-summary-box strong {
  color: #f8fafc !important;
}

[data-theme="dark"] .eval-summary-text,
html.dark .eval-summary-text {
  color: #e2e8f0 !important;
}

[data-theme="dark"] .eval-summary-text .hl,
html.dark .eval-summary-text .hl {
  color: #38bdf8 !important;
}

[data-theme="dark"] .eval-summary-text .hl-val,
html.dark .eval-summary-text .hl-val {
  color: #4ade80 !important;
}

/* Truth Table */
[data-theme="dark"] .lab-table,
html.dark .lab-table {
  background: #0d1424 !important;
}

[data-theme="dark"] .lab-table th,
html.dark .lab-table th {
  background: #131d31 !important;
  color: #38bdf8 !important;
  border-bottom: 2px solid #1e293b !important;
  border-color: #1e293b !important;
}

[data-theme="dark"] .lab-table td,
html.dark .lab-table td {
  background: #0d1424 !important;
  color: #cbd5e1 !important;
  border-bottom: 1px solid #1e293b !important;
  border-color: #1e293b !important;
}

[data-theme="dark"] .lab-table tr:hover td,
html.dark .lab-table tr:hover td {
  background: #172338 !important;
}

[data-theme="dark"] .lab-table tr.active-row td,
html.dark .lab-table tr.active-row td {
  background: rgba(56, 189, 248, 0.18) !important;
  color: #38bdf8 !important;
  border-color: #38bdf8 !important;
  font-weight: 700 !important;
}

/* Theory & Education */
[data-theme="dark"] .theory-card,
html.dark .theory-card,
[data-theme="dark"] .step-card,
html.dark .step-card,
[data-theme="dark"] .submodule-box,
html.dark .submodule-box {
  background: #111a2e !important;
  border-color: #1e293b !important;
  color: #cbd5e1 !important;
}

[data-theme="dark"] .theory-card h3,
html.dark .theory-card h3,
[data-theme="dark"] .info-section h3,
html.dark .info-section h3 {
  color: #38bdf8 !important;
  border-bottom-color: #1e293b !important;
}

[data-theme="dark"] .theory-card p,
html.dark .theory-card p,
[data-theme="dark"] .theory-card code,
html.dark .theory-card code,
[data-theme="dark"] .info-section p,
html.dark .info-section p {
  color: #cbd5e1 !important;
}

[data-theme="dark"] .formula-box,
html.dark .formula-box,
[data-theme="dark"] .math-formula,
html.dark .math-formula {
  background: #0c192e !important;
  border-left-color: #38bdf8 !important;
  border-color: #38bdf8 !important;
  color: #f1f5f9 !important;
}

[data-theme="dark"] .scaling-table,
html.dark .scaling-table {
  background: #0d1424 !important;
}

[data-theme="dark"] .scaling-table th,
html.dark .scaling-table th {
  background: #131d31 !important;
  color: #38bdf8 !important;
  border-color: #1e293b !important;
}

[data-theme="dark"] .scaling-table td,
html.dark .scaling-table td {
  background: #0d1424 !important;
  color: #cbd5e1 !important;
  border-color: #1e293b !important;
}

[data-theme="dark"] .scaling-table tr.highlight-scaling td,
html.dark .scaling-table tr.highlight-scaling td {
  background: rgba(167, 139, 250, 0.18) !important;
  color: #c4b5fd !important;
  font-weight: 700 !important;
}

/* Footer */
[data-theme="dark"] .lab-footer,
html.dark .lab-footer {
  background: #080d1a !important;
  border-top-color: #1e293b !important;
  color: #64748b !important;
}