/* ============================================================
   4: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 14px rgba(16, 185, 129, 0.7);

  --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-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.circuit-canvas-bg {
  fill: #ffffff;
  transition: fill 0.3s ease;
}

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

.lab-title-bar .lab-subtitle {
  font-size: 0.8rem;
  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: 1280px;
  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;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

.btn--secondary {
  background: #1e293b;
  color: #ffffff;
}

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

.btn--secondary:disabled {
  background: #e2e8f0;
  color: #94a3b8;
  cursor: not-allowed;
  border-color: #cbd5e1;
}

.btn--outline {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #334155;
}

.btn--outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn--accent {
  background: #2563eb;
  color: #ffffff;
}

.btn--accent:hover {
  background: #1d4ed8;
}

/* ── Lab Panel Component ───────────────────────────────────── */
.lab-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  display: flex;
  flex-direction: column;
}

.lab-panel:hover {
  box-shadow: var(--shadow-md);
}

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

.lab-panel__header .icon {
  font-size: 1.1rem;
}

.lab-panel__body {
  padding: 18px;
  flex: 1;
}

/* ── Top Grid Layout (Inputs & Outputs) ────────────────────── */
.lab-top-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .lab-top-grid {
    grid-template-columns: 1fr;
  }
}

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

.input-controls-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

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

@media (max-width: 600px) {
  .input-controls-group {
    grid-template-columns: repeat(2, 1fr);
  }
}

.input-control-card {
  background: #ffffff;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.input-control-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

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

.input-control-card.select-card:hover {
  border-color: var(--select-accent);
}

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

.input-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

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

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

/* Toggle Switch Styling */
.toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.toggle-btn__track {
  width: 52px;
  height: 28px;
  background: #cbd5e1;
  border-radius: 14px;
  padding: 3px;
  display: flex;
  align-items: center;
  transition: background-color 0.25s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
}

.toggle-btn__knob {
  width: 22px;
  height: 22px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.25s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-btn.high .toggle-btn__track {
  background: var(--accent);
}

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

.toggle-btn.select-high .toggle-btn__track {
  background: var(--select-accent);
}

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

.toggle-btn__state {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.toggle-btn.high .toggle-btn__state {
  color: var(--accent);
}

.toggle-btn.select-high .toggle-btn__state {
  color: var(--select-accent);
}

/* Output Display Panel & Indicator Cards */
.output-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  justify-content: center;
  height: 100%;
}

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

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

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

.indicator-card__val {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-light);
  padding: 4px 16px;
  border-radius: 20px;
}

.indicator-card__val.selected-channel {
  color: #6d28d9;
  background: #f3e8ff;
  border: 1px solid #d8b4fe;
}

/* LED Indicator Styling */
.led-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.led {
  width: 32px;
  height: 32px;
  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);
  animation: led-pulse 1.8s infinite alternate;
}

@keyframes led-pulse {
  from {
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
  }

  to {
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.95);
  }
}

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

.led-status-text.high {
  color: #059669;
}

/* ── Schematic View Panel & SVG Circuit ────────────────────── */
.schematic-panel__body {
  padding: 12px;
  position: relative;
  overflow-x: auto;
  background: #ffffff;
}

.schematic-viewport {
  min-width: 840px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.circuit-svg {
  width: 100%;
  max-width: 960px;
  height: auto;
  user-select: none;
}

/* SVG Circuit Element Styles */
.wire {
  stroke: var(--wire-off);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  transition: stroke 0.25s ease, stroke-width 0.25s ease;
}

.wire.active {
  stroke: var(--wire-on);
  stroke-width: 3.5;
  filter: drop-shadow(0 0 3px var(--wire-on-glow));
}

.wire.select-wire {
  stroke: #94a3b8;
}

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

.wire.selected-data-path {
  stroke: #2563eb;
  stroke-width: 4;
}

/* Animated flow dash for active wires */
.wire-flow {
  stroke-dasharray: 8 6;
  animation: dash-flow 0.8s linear infinite;
}

@keyframes dash-flow {
  from {
    stroke-dashoffset: 28;
  }

  to {
    stroke-dashoffset: 0;
  }
}

/* Gate Styling */
.gate-body {
  fill: var(--gate-fill);
  stroke: var(--gate-stroke);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: all 0.25s ease;
}

.gate-body.active {
  fill: var(--gate-active-fill);
  stroke: var(--gate-active-stroke);
  stroke-width: 3;
  filter: drop-shadow(0 2px 8px rgba(37, 99, 235, 0.25));
}

.gate-label {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  fill: #334155;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.gate-sublabel {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  fill: #64748b;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.junction-dot {
  fill: #1e293b;
  transition: fill 0.2s ease;
}

.junction-dot.active {
  fill: var(--wire-on);
}

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

/* SVG Switch Interactive Elements */
.svg-switch {
  cursor: pointer;
}

.svg-switch:hover rect {
  stroke: var(--accent);
}

/* ── Binary Data Demonstration Panel ───────────────────────── */
.eval-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

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

.eval-card {
  background: #ffffff;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  transition: all 0.2s ease;
}

.eval-card.active-term {
  background: #eff6ff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.15);
}

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

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

.eval-card__result {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
}

.eval-card.active-term .eval-card__result {
  color: var(--accent);
}

.eval-summary-box {
  background: #0f172a;
  color: #f8fafc;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.eval-summary-text span.hl {
  color: #60a5fa;
  font-weight: 700;
}

.eval-summary-text span.hl-val {
  color: #34d399;
  font-weight: 700;
}

/* ── Interactive Truth Table Panel ─────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
}

.truth-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  background: #ffffff;
  text-align: center;
}

.truth-table th {
  background: #1e293b;
  color: #ffffff;
  padding: 12px 14px;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-right: 1px solid #334155;
}

.truth-table th:last-child {
  border-right: none;
}

.truth-table td {
  padding: 11px 14px;
  border-bottom: 1px solid #e2e8f0;
  border-right: 1px solid #f1f5f9;
  font-family: var(--font-mono);
  color: var(--text-primary);
  transition: background-color 0.2s ease;
}

.truth-table td:last-child {
  border-right: none;
}

.truth-table tbody tr {
  cursor: pointer;
  transition: all 0.2s ease;
}

.truth-table tbody tr:hover {
  background-color: #f1f5f9;
}

.truth-table tbody tr.active-row {
  background-color: #dbeafe;
  font-weight: 700;
}

.truth-table tbody tr.active-row td {
  color: #1e40af;
}

.truth-table tbody tr.active-row td:first-child {
  position: relative;
}

.truth-table tbody tr.active-row td:first-child::before {
  content: '▶';
  position: absolute;
  left: 8px;
  color: var(--accent);
  font-size: 0.75rem;
}

.badge-row-active {
  background: var(--accent);
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
}

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

@media (max-width: 900px) {
  .theory-grid {
    grid-template-columns: 1fr;
  }
}

.theory-card {
  background: #ffffff;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.theory-card h3 {
  font-size: 1.05rem;
  color: var(--header-bg);
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 2px solid var(--accent-light);
  padding-bottom: 8px;
}

.theory-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

.theory-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theory-list li {
  font-size: 0.88rem;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #f8fafc;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.theory-list li strong {
  color: var(--text-primary);
}

.math-formula {
  background: #0f172a;
  color: #38bdf8;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  text-align: center;
  margin: 8px 0;
  overflow-x: auto;
}

/* ── Footer ────────────────────────────────────────────────── */
.lab-footer {
  text-align: center;
  padding: 24px 20px;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid var(--panel-border);
  background: #f8fafc;
  margin-top: auto;
}

/* -- Dark Theme Overrides (Black Theme) --------------------- */
[data-theme="dark"],
html.dark,
body.dark,
.dark {
  --lab-bg: #070b14;
  --panel-bg: #0d1424;
  --panel-header-bg: #080d1a;
  --panel-header-text: #f8fafc;
  --panel-border: #1e293b;
  --card-bg: #111a2e;
  --card-bg-subtle: #09101f;
  --header-bg: #080d1a;
  --header-text: #f8fafc;

  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --accent-light: #0c2d48;
  --accent-glow: rgba(56, 189, 248, 0.6);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Signal & Logic Colors */
  --wire-off: #475569;
  --wire-on: #38bdf8;
  --wire-on-glow: rgba(56, 189, 248, 0.8);
  --signal-high: #38bdf8;
  --signal-low: #64748b;

  --select-accent: #a78bfa;
  --select-accent-bg: #2e1065;
  --select-border: #7c3aed;

  --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;

  --circuit-bg: #060a14;
  --circuit-canvas-bg: #0b1120;
  --circuit-border: #1e293b;
  --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);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.7);
}

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

/* Header & Title Bar */
[data-theme="dark"] .lab-title-bar,
html.dark .lab-title-bar,
body.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,
body.dark .lab-title-container h1 {
  color: #f8fafc !important;
}

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

[data-theme="dark"] .lab-badge,
html.dark .lab-badge,
body.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,
body.dark .lab-toolbar {
  background: #0d1424 !important;
  border-color: #1e293b !important;
}

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

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

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

[data-theme="dark"] .btn--mode:hover,
html.dark .btn--mode:hover,
body.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,
body.dark .btn--mode.active {
  background: #0284c7 !important;
  border-color: #38bdf8 !important;
  color: #ffffff !important;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.45) !important;
}

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

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

[data-theme="dark"] .btn--secondary:disabled,
html.dark .btn--secondary:disabled,
body.dark .btn--secondary:disabled {
  background: #0a0f1d !important;
  border-color: #1e293b !important;
  color: #475569 !important;
  cursor: not-allowed !important;
}

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

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

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

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

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

[data-theme="dark"] .lab-panel:hover,
html.dark .lab-panel:hover,
body.dark .lab-panel:hover {
  border-color: #38bdf8 !important;
}

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

[data-theme="dark"] .lab-panel__header span,
html.dark .lab-panel__header span,
body.dark .lab-panel__header span {
  color: #f8fafc !important;
}

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

[data-theme="dark"] .input-control-card:hover,
html.dark .input-control-card:hover,
body.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,
body.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,
body.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-control-card.active-selected,
html.dark .input-control-card.active-selected,
body.dark .input-control-card.active-selected {
  background: #0c2d48 !important;
  border-color: #38bdf8 !important;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.35) !important;
}

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

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

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

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

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

[data-theme="dark"] .toggle-btn__knob,
html.dark .toggle-btn__knob,
body.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,
body.dark .toggle-btn__state {
  color: #94a3b8 !important;
}

[data-theme="dark"] .toggle-btn.high .toggle-btn__track,
html.dark .toggle-btn.high .toggle-btn__track,
body.dark .toggle-btn.high .toggle-btn__track,
[data-theme="dark"] .toggle-btn.active .toggle-btn__track,
html.dark .toggle-btn.active .toggle-btn__track,
body.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,
body.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,
body.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,
body.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,
body.dark .indicator-card {
  background: #111a2e !important;
  border-color: #1e293b !important;
}

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

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

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

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

[data-theme="dark"] .led,
html.dark .led,
body.dark .led {
  background: #1e293b !important;
  border-color: #334155 !important;
}

[data-theme="dark"] .led.active,
html.dark .led.active,
body.dark .led.active {
  background: #22c55e !important;
  border-color: #16a34a !important;
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.8) !important;
}

[data-theme="dark"] .led-status-text,
html.dark .led-status-text,
body.dark .led-status-text {
  color: #94a3b8 !important;
}

[data-theme="dark"] .led-status-text.high,
html.dark .led-status-text.high,
body.dark .led-status-text.high {
  color: #4ade80 !important;
}

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

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

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

/* SVG Canvas Background Rects */
[data-theme="dark"] .circuit-canvas-bg,
html.dark .circuit-canvas-bg,
body.dark .circuit-canvas-bg,
[data-theme="dark"] #gate-canvas-bg,
html.dark #gate-canvas-bg,
body.dark #gate-canvas-bg,
[data-theme="dark"] #func-canvas-bg,
html.dark #func-canvas-bg,
body.dark #func-canvas-bg,
[data-theme="dark"] #view-gate-level>rect:first-child,
html.dark #view-gate-level>rect:first-child,
body.dark #view-gate-level>rect:first-child,
[data-theme="dark"] #view-functional>rect:first-child,
html.dark #view-functional>rect:first-child,
body.dark #view-functional>rect:first-child,
[data-theme="dark"] #view-gate-level rect[width="960"],
html.dark #view-gate-level rect[width="960"],
body.dark #view-gate-level rect[width="960"],
[data-theme="dark"] #view-functional rect[width="960"],
html.dark #view-functional rect[width="960"],
body.dark #view-functional rect[width="960"] {
  fill: #0b1120 !important;
  stroke: #1e293b !important;
  stroke-width: 1.5;
}

/* SVG Data Switch buttons (I0 - I3) */
[data-theme="dark"] #view-gate-level .svg-switch rect,
html.dark #view-gate-level .svg-switch rect,
body.dark #view-gate-level .svg-switch rect,
[data-theme="dark"] #svg-sw-i0 rect,
html.dark #svg-sw-i0 rect,
[data-theme="dark"] #svg-sw-i1 rect,
html.dark #svg-sw-i1 rect,
[data-theme="dark"] #svg-sw-i2 rect,
html.dark #svg-sw-i2 rect,
[data-theme="dark"] #svg-sw-i3 rect,
html.dark #svg-sw-i3 rect {
  fill: #111a2e !important;
  stroke: #0284c7 !important;
}

[data-theme="dark"] #view-gate-level .svg-switch text,
html.dark #view-gate-level .svg-switch text,
body.dark #view-gate-level .svg-switch text,
[data-theme="dark"] #svg-sw-i0 text,
html.dark #svg-sw-i0 text,
[data-theme="dark"] #svg-sw-i1 text,
html.dark #svg-sw-i1 text,
[data-theme="dark"] #svg-sw-i2 text,
html.dark #svg-sw-i2 text,
[data-theme="dark"] #svg-sw-i3 text,
html.dark #svg-sw-i3 text {
  fill: #38bdf8 !important;
}

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

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

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

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

[data-theme="dark"] .gate-body.active,
html.dark .gate-body.active,
body.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,
body.dark .gate-label {
  fill: #f8fafc !important;
}

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

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

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

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

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

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

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

[data-theme="dark"] .wire.selected-data-path,
html.dark .wire.selected-data-path,
body.dark .wire.selected-data-path {
  stroke: #38bdf8 !important;
  stroke-width: 4;
}

[data-theme="dark"] .wire-flow,
html.dark .wire-flow,
body.dark .wire-flow {
  stroke: #38bdf8 !important;
}

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

[data-theme="dark"] .junction-dot.active,
html.dark .junction-dot.active,
body.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,
body.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,
body.dark #ic-mux-box {
  fill: #111a2e !important;
  stroke: #38bdf8 !important;
  stroke-width: 3.5;
  filter: drop-shadow(0 4px 20px rgba(56, 189, 248, 0.2)) !important;
}

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

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

[data-theme="dark"] #view-functional rect[x="50"],
html.dark #view-functional rect[x="50"],
body.dark #view-functional rect[x="50"],
[data-theme="dark"] #view-functional rect[fill="#dbeafe"],
html.dark #view-functional rect[fill="#dbeafe"],
body.dark #view-functional rect[fill="#dbeafe"] {
  fill: #111a2e !important;
  stroke: #0284c7 !important;
}

[data-theme="dark"] #view-functional text[fill="#1e40af"],
html.dark #view-functional text[fill="#1e40af"],
body.dark #view-functional text[fill="#1e40af"] {
  fill: #38bdf8 !important;
}

[data-theme="dark"] #view-functional rect[x="385"],
html.dark #view-functional rect[x="385"],
body.dark #view-functional rect[x="385"],
[data-theme="dark"] #view-functional rect[x="505"],
html.dark #view-functional rect[x="505"],
body.dark #view-functional rect[x="505"],
[data-theme="dark"] #view-functional rect[fill="#f3e8ff"],
html.dark #view-functional rect[fill="#f3e8ff"],
body.dark #view-functional rect[fill="#f3e8ff"] {
  fill: #18132b !important;
  stroke: #8b5cf6 !important;
}

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

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

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

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

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

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

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

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

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

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

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

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

/* Truth Table */
[data-theme="dark"] .table-wrapper,
html.dark .table-wrapper,
body.dark .table-wrapper {
  border-color: #1e293b !important;
}

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

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

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

[data-theme="dark"] .truth-table td strong,
html.dark .truth-table td strong,
body.dark .truth-table td strong {
  color: #f8fafc !important;
}

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

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

[data-theme="dark"] .truth-table tbody tr.active-row td:first-child::before,
html.dark .truth-table tbody tr.active-row td:first-child::before,
body.dark .truth-table tbody tr.active-row td:first-child::before {
  color: #38bdf8 !important;
}

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

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

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

[data-theme="dark"] .theory-card strong,
html.dark .theory-card strong,
body.dark .theory-card strong {
  color: #f8fafc !important;
}

[data-theme="dark"] .theory-list li,
html.dark .theory-list li,
body.dark .theory-list li,
[data-theme="dark"] .info-section li,
html.dark .info-section li,
body.dark .info-section li {
  background: #0c192e !important;
  border-left-color: #38bdf8 !important;
  color: #cbd5e1 !important;
}

[data-theme="dark"] .theory-list li strong,
html.dark .theory-list li strong,
body.dark .theory-list li strong {
  color: #f8fafc !important;
}

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

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

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

[data-theme="dark"] .lab-footer p,
html.dark .lab-footer p,
body.dark .lab-footer p {
  color: #64748b !important;
}