/* ============================================================
   De Morgan's Theorems Virtual Laboratory — Style Sheet
   Virtual Instrumentation Labs Interactive Learning Platform
   ============================================================ */

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

:root {
  /* Laboratory Colour Palette */
  --lab-bg: #ffffff;
  --panel-bg: #f4f5f7;
  --panel-border: #d0d4da;
  --header-bg: #1a2744;
  --header-text: #ffffff;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --success: #16a34a;
  --danger: #dc2626;
  --wire-off: #9ca3af;
  --wire-on: #22c55e;
  --led-off: #6b7280;
  --led-on: #22c55e;
  --led-glow: rgba(34, 197, 94, 0.5);
  --switch-track-off: #cbd5e1;
  --switch-track-on: #22c55e;
  --switch-knob: #ffffff;
  --gate-fill: #e8ecf1;
  --gate-stroke: #1a2744;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.10);
  --radius: 6px;
  --radius-lg: 10px;
  --font-sans: 'Segoe UI', 'Inter', -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Mono', 'Consolas', monospace;
}

html {
  font-size: 15px;
}

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

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

.lab-title-bar h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

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

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

/* ── Theorem Navigation Tabs ──────────────────────────────── */
.theorem-nav {
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
  padding: 10px 24px;
  display: flex;
  gap: 10px;
  position: sticky;
  top: 57px;
  z-index: 99;
}

.theorem-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1.5px solid #334155;
  color: #94a3b8;
  padding: 8px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.25s ease;
}

.theorem-tab:hover {
  background: rgba(37, 99, 235, 0.08);
  border-color: var(--accent);
  color: #e2e8f0;
}

.theorem-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.theorem-tab__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  font-size: 0.75rem;
  font-weight: 700;
}

.theorem-tab.active .theorem-tab__num {
  background: rgba(255, 255, 255, 0.25);
}

.theorem-tab__text {
  white-space: nowrap;
}

.theorem-tab__text .expr {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

/* ── Main Layout ──────────────────────────────────────────── */
.lab-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.lab-panel__header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 10px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.lab-panel__body {
  padding: 16px 18px;
}

.circuit-header .expr-header {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: #93c5fd;
}

/* ── Input Controls Panel ─────────────────────────────────── */
.input-controls-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.input-control-group {
  display: flex;
  gap: 32px;
}

.input-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.input-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 56px;
}

/* Toggle Button */
.toggle-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  -webkit-tap-highlight-color: transparent;
}

.toggle-btn__track {
  position: relative;
  width: 52px;
  height: 28px;
  background: var(--switch-track-off);
  border-radius: 14px;
  transition: background 0.3s ease;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

.toggle-btn.high .toggle-btn__track {
  background: var(--switch-track-on);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(34, 197, 94, 0.3);
}

.toggle-btn__knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: var(--switch-knob);
  border-radius: 50%;
  transition: transform 0.3s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

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

.toggle-btn__state {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--danger);
  min-width: 20px;
  text-align: center;
  transition: color 0.3s ease;
}

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

/* Lab Controls Row */
.lab-controls-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 16px;
  border: 1.5px solid var(--panel-border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn--danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn--primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

.btn--outline {
  background: #fff;
  color: var(--text-secondary);
}

/* ── Theorem Sections ─────────────────────────────────────── */
.theorem-section {
  display: none;
}

.theorem-section.active {
  display: block;
}

/* ── Circuits Row ─────────────────────────────────────────── */
.circuits-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.circuit-panel {
  min-width: 0;
}

/* ── Circuit Canvas ───────────────────────────────────────── */
.circuit-canvas {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 8px;
  overflow: hidden;
}

.circuit-canvas svg {
  width: 100%;
  height: auto;
  display: block;
}

/* ── SVG Elements ─────────────────────────────────────────── */
.svg-label {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 700;
  fill: var(--text-primary);
}

.svg-value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  transition: fill 0.3s ease;
}

.svg-value.low {
  fill: var(--danger);
}

.svg-value.high {
  fill: var(--success);
}

.svg-caption {
  font-family: var(--font-sans);
  font-size: 10px;
  fill: var(--text-muted);
}

/* Gate Bodies */
.gate-body {
  fill: var(--gate-fill);
  stroke: var(--gate-stroke);
  stroke-width: 2;
  transition: fill 0.3s ease;
}

.gate-body-bubble {
  fill: #ffffff;
  stroke: var(--gate-stroke);
  stroke-width: 2;
}

.gate-body.active {
  fill: #d1fae5;
}

.gate-label-text {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  fill: var(--text-primary);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.led-label {
  font-family: var(--font-sans);
  font-size: 9px;
  font-weight: 600;
  fill: #fff;
  pointer-events: none;
}

/* ── Wires ────────────────────────────────────────────────── */
.wire {
  fill: none;
  stroke: var(--wire-off);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.35s ease;
}

.wire.high {
  stroke: var(--wire-on);
  filter: drop-shadow(0 0 3px rgba(34, 197, 94, 0.4));
}

/* ── LED ──────────────────────────────────────────────────── */
.led-body {
  transition: fill 0.35s ease, filter 0.35s ease;
}

.led-body.off {
  fill: var(--led-off);
}

.led-body.on {
  fill: var(--led-on);
  filter: drop-shadow(0 0 8px var(--led-glow));
}

/* ── Signal Pulse ─────────────────────────────────────────── */
.signal-pulse {
  r: 5;
  fill: var(--wire-on);
  opacity: 0;
  filter: drop-shadow(0 0 4px rgba(34, 197, 94, 0.6));
}

.signal-pulse.active {
  opacity: 1;
}

/* ── Verification Banner ──────────────────────────────────── */
.verification-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  background: #f0fdf4;
  border: 2px solid #86efac;
  border-radius: var(--radius-lg);
  margin-top: 12px;
  transition: all 0.35s ease;
}

.verification-banner.verified {
  background: #f0fdf4;
  border-color: #22c55e;
}

.verify-icon {
  font-size: 1.4rem;
  color: var(--success);
  font-weight: 700;
}

.verify-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--success);
  letter-spacing: 0.3px;
}

/* ── Live Display ─────────────────────────────────────────── */
.live-display {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.live-cell {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 10px 18px;
  text-align: center;
  min-width: 80px;
  transition: border-color 0.3s ease;
}

.live-cell__label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.live-cell__value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  transition: color 0.3s ease;
}

.live-cell__value.low {
  color: var(--danger);
}

.live-cell__value.high {
  color: var(--success);
}

.live-cell__value.match {
  color: var(--success);
  font-size: 1.3rem;
}

.verify-cell {
  border-color: #86efac;
  background: #f0fdf4;
}

/* ── Truth Table ──────────────────────────────────────────── */
.truth-table-wrapper {
  overflow-x: auto;
}

.truth-table-wrapper.hidden {
  display: none;
}

.truth-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.truth-table th {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 10px 14px;
  font-weight: 600;
  text-align: center;
  border: 1px solid #334155;
  font-size: 0.82rem;
}

.truth-table td {
  padding: 9px 14px;
  text-align: center;
  border: 1px solid var(--panel-border);
  font-family: var(--font-mono);
  font-weight: 500;
  transition: all 0.3s ease;
}

.truth-table tbody tr {
  background: #fff;
  transition: background 0.3s ease;
}

.truth-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.truth-table tbody tr.highlight {
  background: var(--accent-light);
  box-shadow: inset 3px 0 0 var(--accent);
}

.truth-table tbody tr.highlight td {
  font-weight: 700;
}

.verify-col {
  color: var(--success);
  font-weight: 600;
}

/* ── Explanation / Working Principle ───────────────────────── */
.explanation-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.info-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 4px;
}

.info-section p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 6px;
}

.info-section ul {
  padding-left: 20px;
  margin-top: 4px;
}

.info-section li {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 5px;
}

.theorem-box {
  background: #f8fafc;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 20px;
  text-align: center;
  margin: 10px 0;
}

.theorem-formula {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}

/* ── Utility ──────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .circuits-row {
    grid-template-columns: 1fr;
  }

  .theorem-nav {
    flex-direction: column;
    gap: 6px;
    padding: 8px 16px;
  }

  .theorem-tab {
    width: 100%;
    justify-content: center;
  }

  .input-controls-body {
    flex-direction: column;
    align-items: stretch;
  }

  .input-control-group {
    justify-content: center;
  }

  .lab-controls-row {
    justify-content: center;
  }

  .lab-title-bar {
    padding: 10px 16px;
  }

  .lab-title-bar h1 {
    font-size: 0.98rem;
  }

  .lab-main {
    padding: 12px 12px 30px;
  }
}

@media (max-width: 500px) {
  .input-control-group {
    flex-direction: column;
    gap: 14px;
    align-items: center;
  }

  .live-display {
    gap: 8px;
  }

  .live-cell {
    min-width: 60px;
    padding: 8px 10px;
  }

  .live-cell__value {
    font-size: 1.2rem;
  }

  .lab-controls-row {
    flex-direction: column;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ── Smooth scrolling ─────────────────────────────────────── */
html {
  scroll-behavior: smooth;
}

/* ── Signal animation keyframes ───────────────────────────── */
@keyframes pulse-glow {

  0%,
  100% {
    opacity: 0.7;
  }

  50% {
    opacity: 1;
  }
}

.signal-pulse.active {
  animation: pulse-glow 1.2s ease-in-out infinite;
}


/* -- 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-light: #1e3a5f;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --success: #22c55e;
  --danger: #ef4444;
  --wire-off: #475569;
  --wire-on: #22c55e;
  --led-off: #334155;
  --led-on: #22c55e;
  --led-glow: rgba(34, 197, 94, 0.6);
  --switch-track-off: #334155;
  --switch-track-on: #22c55e;
  --switch-knob: #f8fafc;
  --gate-fill: #162036;
  --gate-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: var(--lab-bg);
  color: var(--text-primary);
}

[data-theme="dark"] .circuit-canvas,
html.dark .circuit-canvas {
  background: #0b1222;
  border-color: #1e293b;
}

[data-theme="dark"] .live-cell,
html.dark .live-cell {
  background: #162036;
  border-color: #1e293b;
}

[data-theme="dark"] .bool-expr,
html.dark .bool-expr {
  background: #162036;
  border-color: #1e293b;
}

[data-theme="dark"] .bool-expr__formula,
html.dark .bool-expr__formula {
  color: #38bdf8;
}

[data-theme="dark"] .btn,
html.dark .btn {
  background: #1e293b;
  border-color: #334155;
  color: #f8fafc;
}

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

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

[data-theme="dark"] .btn--danger,
html.dark .btn--danger {
  background: rgba(239, 68, 68, 0.15) !important;
  border-color: rgba(239, 68, 68, 0.4) !important;
  color: #f87171 !important;
}

[data-theme="dark"] .btn--danger:hover,
html.dark .btn--danger:hover {
  background: rgba(239, 68, 68, 0.25) !important;
}

[data-theme="dark"] .gate-body,
html.dark .gate-body {
  fill: #162036;
  stroke: #38bdf8;
}

[data-theme="dark"] .gate-body.active,
html.dark .gate-body.active {
  fill: #064e3b;
  stroke: #22c55e;
}

[data-theme="dark"] .gate-label-text,
html.dark .gate-label-text {
  fill: #38bdf8;
}

[data-theme="dark"] .gate-body-bubble,
html.dark .gate-body-bubble {
  fill: #0f172a;
  stroke: #38bdf8;
}

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

[data-theme="dark"] .svg-label-small,
html.dark .svg-label-small {
  fill: #94a3b8;
}

[data-theme="dark"] .logic-state.low,
html.dark .logic-state.low {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

[data-theme="dark"] .logic-state.high,
html.dark .logic-state.high {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
  color: #4ade80;
}

[data-theme="dark"] .truth-table th,
html.dark .truth-table th {
  background: #0b1120;
  color: #38bdf8;
  border-bottom: 1px solid #1e293b;
}

[data-theme="dark"] .truth-table td,
html.dark .truth-table td {
  border-bottom: 1px solid #1e293b;
  color: #94a3b8;
}

[data-theme="dark"] .truth-table tr.highlight,
html.dark .truth-table tr.highlight {
  background: rgba(56, 189, 248, 0.12);
}

[data-theme="dark"] .truth-table tr.highlight td,
html.dark .truth-table tr.highlight td {
  color: #38bdf8;
  border-color: #0284c7;
}

[data-theme="dark"] .info-section h3,
html.dark .info-section h3 {
  color: #38bdf8;
}

[data-theme="dark"] .motor-status.off,
html.dark .motor-status.off {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

[data-theme="dark"] .motor-status.on,
html.dark .motor-status.on {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
  color: #4ade80;
}

[data-theme="dark"] .quiz-question,
html.dark .quiz-question {
  background: #162036;
  border-color: #1e293b;
}

[data-theme="dark"] .quiz-opt,
html.dark .quiz-opt {
  background: #0f172a;
  border-color: #1e293b;
  color: #f8fafc;
}

[data-theme="dark"] .quiz-opt:hover,
html.dark .quiz-opt:hover {
  background: #1e3a5f;
  border-color: #38bdf8;
}

[data-theme="dark"] .quiz-opt.correct,
html.dark .quiz-opt.correct {
  background: rgba(34, 197, 94, 0.2);
  border-color: #22c55e;
  color: #4ade80;
}

[data-theme="dark"] .quiz-opt.incorrect,
html.dark .quiz-opt.incorrect {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #f87171;
}

[data-theme="dark"] .quiz-feedback.correct,
html.dark .quiz-feedback.correct {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
  color: #4ade80;
}

[data-theme="dark"] .quiz-feedback.incorrect,
html.dark .quiz-feedback.incorrect {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}