/* ==========================================================================
   Digital Electronics Virtual Laboratory - 16:1 Multiplexer Stylesheet
   Design Language: Modern Engineering Light Mode, Technical Grid, Glassmorphism
   ========================================================================== */

:root {
    /* Color Palette - Global Theme Token Integration */
    --bg-main: var(--app-bg, #f1f5f9);
    --bg-grid-color: var(--prayog-border-subtle, rgba(148, 163, 184, 0.15));
    
    --card-bg: var(--surface, rgba(255, 255, 255, 0.94));
    --card-border: var(--border, #e2e8f0);
    --card-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.05), 0 8px 10px -6px rgba(15, 23, 42, 0.03);
    
    --primary-blue: var(--prayog-blue, #1e3a8a);
    --primary-blue-hover: #1e40af;
    --accent-blue: #2563eb;
    --accent-blue-light: #eff6ff;
    
    --text-heading: var(--text-heading, #0f172a);
    --text-body: var(--text-primary, #334155);
    --text-muted: var(--text-secondary, #64748b);
    
    /* Logic Signals */
    --logic-high: #10b981;       /* Emerald Green */
    --logic-high-glow: rgba(16, 185, 129, 0.4);
    --logic-low: #06b6d4;        /* Electric Cyan */
    --logic-low-glow: rgba(6, 182, 212, 0.3);
    --logic-inactive: var(--switch-track-off, #cbd5e1);   /* Slate Muted */
    
    --active-path-stroke: #2563eb; /* Royal Blue */
    --active-path-glow: rgba(37, 99, 235, 0.5);
    
    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-norm: 0.25s ease;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(var(--bg-grid-color) 1px, transparent 1px),
        radial-gradient(var(--bg-grid-color) 1px, var(--bg-main) 1px);
    background-size: 24px 24px;
    background-position: 0 0, 12px 12px;
    color: var(--text-body);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Engineering Header */
.lab-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 0.85rem 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03);
}

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

.brand {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.lab-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--accent-blue);
    text-transform: uppercase;
}

.brand h1 {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-heading);
    letter-spacing: -0.02em;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: #059669;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse 1.6s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Main Container Layout */
.lab-container {
    max-width: 1700px;
    width: 100%;
    margin: 1.25rem auto;
    padding: 0 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    flex: 1;
}

/* Common Card Base Styling */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    box-shadow: var(--card-shadow);
    padding: 1.25rem;
    backdrop-filter: blur(8px);
    transition: box-shadow var(--transition-norm);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid #f1f5f9;
}

.card-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary-blue);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.card-badge {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: #e2e8f0;
    color: var(--text-muted);
}

/* Toolbar Card */
.toolbar-card {
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 0.85rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    box-shadow: var(--card-shadow);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-group-toggle {
    display: inline-flex;
    background: #f1f5f9;
    padding: 3px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.btn-primary {
    background: var(--primary-blue);
    color: #ffffff;
}
.btn-primary:hover {
    background: var(--primary-blue-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: var(--text-heading);
}
.btn-secondary:hover {
    background: #f1f5f9;
}

.btn-outline {
    background: transparent;
    border-color: #cbd5e1;
    color: var(--text-heading);
}
.btn-outline:hover {
    background: #f8fafc;
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.btn-tab {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    font-size: 0.82rem;
}
.btn-tab.active {
    background: #ffffff;
    color: var(--primary-blue);
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.speed-control-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #f8fafc;
    padding: 0.35rem 0.85rem;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.speed-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    gap: 0.4rem;
}
.speed-label #speed-val {
    color: var(--primary-blue);
    font-family: var(--font-mono);
}

input[type="range"] {
    accent-color: var(--accent-blue);
    cursor: pointer;
}

/* Grid Layouts */
.workspace-grid {
    display: grid;
    grid-template-columns: 420px 1fr;
    gap: 1.25rem;
    align-items: start;
}

.panel-column {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Readout Box Card */
.readout-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.readout-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.readout-box.highlight-box {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.readout-box.output-box {
    background: #faf5ff;
    border-color: #e9d5ff;
}

.readout-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.readout-value-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.binary-display {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-blue);
    letter-spacing: 0.15em;
}

.decimal-badge {
    background: var(--primary-blue);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-family: var(--font-mono);
}

.input-name {
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--accent-blue);
}

.logic-state-pill {
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: var(--font-mono);
    background: #e2e8f0;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.logic-state-pill.high {
    background: #d1fae5;
    color: #047857;
    border: 1px solid #6ee7b7;
}

.logic-state-pill.low {
    background: #cff4fc;
    color: #087990;
    border: 1px solid #9eeaf9;
}

.output-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-top: 0.2rem;
}

.output-value {
    font-family: var(--font-mono);
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-heading);
}

/* LED Indicator Styling */
.led-indicator {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #94a3b8;
    position: relative;
    border: 2px solid #64748b;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
    transition: all 0.2s ease;
}

.led-indicator.on {
    background: #10b981;
    border-color: #059669;
    box-shadow: 0 0 12px #10b981, inset 0 2px 4px rgba(255,255,255,0.6);
}

.led-indicator.off {
    background: #334155;
    border-color: #1e293b;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

/* Select Lines Grid */
.select-switches-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.select-switch-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 0.6rem 0.4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    text-align: center;
}

.select-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.1;
}

.bit-tag {
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.select-label strong {
    font-size: 0.95rem;
    color: var(--primary-blue);
    font-family: var(--font-mono);
}

.select-label small {
    font-size: 0.62rem;
    color: var(--text-muted);
}

.toggle-btn {
    width: 100%;
    max-width: 60px;
    height: 38px;
    border-radius: 8px;
    border: 2px solid #cbd5e1;
    background: #ffffff;
    color: var(--text-heading);
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toggle-btn.active-high {
    background: var(--primary-blue);
    color: #ffffff;
    border-color: var(--primary-blue);
    box-shadow: 0 4px 8px rgba(30, 58, 138, 0.25);
}

/* 16 Inputs Grid */
.inputs-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 2px;
}

.input-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.45rem 0.35rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.input-item:hover {
    border-color: #94a3b8;
    background: #ffffff;
}

.input-item.selected {
    background: #eff6ff;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.input-tag {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-heading);
}

.input-item.selected .input-tag {
    color: var(--accent-blue);
}

.input-val-btn {
    width: 100%;
    height: 28px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    font-family: var(--font-mono);
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.input-val-btn.is-high {
    background: #10b981;
    color: #ffffff;
    border-color: #059669;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

/* Presets Dropdown */
.presets-dropdown {
    position: relative;
}

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 4px;
    background: #ffffff;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    z-index: 50;
    min-width: 160px;
    overflow: hidden;
}

.dropdown-menu.show {
    display: flex;
    flex-direction: column;
}

.dropdown-menu button {
    background: transparent;
    border: none;
    padding: 0.5rem 0.85rem;
    font-size: 0.78rem;
    text-align: left;
    color: var(--text-body);
    cursor: pointer;
}

.dropdown-menu button:hover {
    background: #f1f5f9;
    color: var(--primary-blue);
    font-weight: 600;
}

/* Circuit Workspace Panel */
.circuit-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 700px;
}

.view-legend {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-dot.active-path {
    background: var(--active-path-stroke);
    box-shadow: 0 0 6px var(--active-path-glow);
}
.legend-dot.logic-high { background: var(--logic-high); }
.legend-dot.logic-low { background: var(--logic-low); }

/* SVG Canvas Styling */
.svg-container {
    flex: 1;
    width: 100%;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    overflow: auto;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
}

#circuit-svg {
    width: 100%;
    height: 100%;
    min-width: 800px;
    min-height: 650px;
    display: block;
}

/* SVG Circuit Internal Styles */
.svg-mux-block {
    fill: #ffffff;
    stroke: #64748b;
    stroke-width: 2;
    rx: 6;
    ry: 6;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.05));
    transition: all 0.2s ease;
}

.svg-mux-block.active-mux {
    fill: #eff6ff;
    stroke: var(--accent-blue);
    stroke-width: 2.5;
    filter: drop-shadow(0 4px 10px rgba(37, 99, 235, 0.2));
}

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

.svg-mux-sublabel {
    font-family: var(--font-mono);
    font-size: 9px;
    fill: var(--text-muted);
    text-anchor: middle;
}

.svg-wire {
    fill: none;
    stroke: var(--logic-inactive);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke 0.25s ease, stroke-width 0.25s ease;
}

.svg-wire.active {
    stroke: var(--active-path-stroke);
    stroke-width: 3.5;
    filter: drop-shadow(0 0 6px var(--active-path-glow));
    stroke-dasharray: 8 4;
    animation: flowPulse 1s linear infinite;
}

.svg-wire.active.high {
    stroke: var(--logic-high);
    filter: drop-shadow(0 0 8px var(--logic-high-glow));
}

.svg-wire.active.low {
    stroke: var(--logic-low);
    filter: drop-shadow(0 0 8px var(--logic-low-glow));
}

.svg-select-wire {
    fill: none;
    stroke: #94a3b8;
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
}

.svg-select-wire.active {
    stroke: #8b5cf6;
    stroke-width: 2.5;
    stroke-dasharray: none;
    filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.4));
}

@keyframes flowPulse {
    from { stroke-dashoffset: 24; }
    to { stroke-dashoffset: 0; }
}

.svg-text-node {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    fill: var(--text-body);
}

.svg-text-node.selected-text {
    fill: var(--accent-blue);
    font-weight: 800;
    font-size: 12px;
}

.circuit-footer-note {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    background: #f8fafc;
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

/* Secondary Grid: Truth Table & Theory */
.secondary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

/* Truth Table Card */
.table-card {
    display: flex;
    flex-direction: column;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 420px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

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

.truth-table th {
    background: #f1f5f9;
    color: var(--text-heading);
    font-weight: 700;
    padding: 0.6rem 0.5rem;
    position: sticky;
    top: 0;
    border-bottom: 2px solid #cbd5e1;
    z-index: 10;
}

.truth-table td {
    padding: 0.5rem 0.4rem;
    border-bottom: 1px solid #f1f5f9;
    font-family: var(--font-mono);
    color: var(--text-body);
}

.truth-table tbody tr {
    cursor: pointer;
    transition: background var(--transition-fast);
}

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

.truth-table tbody tr.active-row {
    background: #eff6ff !important;
    font-weight: 700;
}

.truth-table tbody tr.active-row td {
    color: var(--primary-blue);
}

.truth-table tbody tr.active-row td:nth-child(6) {
    background: var(--accent-blue);
    color: #ffffff;
    border-radius: 4px;
}

.info-badge {
    background: #e0f2fe;
    color: #0369a1;
    font-size: 0.72rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

/* Theory & Principles Card */
.theory-card {
    display: flex;
    flex-direction: column;
}

.theory-tabs {
    display: flex;
    gap: 0.4rem;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 1rem;
    overflow-x: auto;
}

.theory-tab-btn {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 0.5rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.theory-tab-btn:hover {
    color: var(--primary-blue);
}

.theory-tab-btn.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
    font-weight: 700;
}

.tab-pane {
    display: none;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text-body);
}

.tab-pane.active {
    display: block;
}

.tab-pane h4 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-blue);
    margin-top: 0.5rem;
    margin-bottom: 0.4rem;
}

.formula-box {
    background: #f8fafc;
    border-left: 4px solid var(--accent-blue);
    padding: 0.75rem 1rem;
    border-radius: 0 8px 8px 0;
    font-family: var(--font-mono);
    font-size: 0.88rem;
    color: var(--text-heading);
    margin: 0.85rem 0;
}

.scaling-table-container {
    overflow-x: auto;
    margin-top: 0.75rem;
}

.scaling-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.scaling-table th, .scaling-table td {
    padding: 0.5rem;
    border: 1px solid #e2e8f0;
    text-align: center;
}

.scaling-table th {
    background: #f1f5f9;
    font-weight: 700;
}

.scaling-table tr.highlight-row {
    background: #eff6ff;
    font-weight: 700;
}

.hierarchical-steps-list {
    margin-left: 1.25rem;
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.apps-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.app-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.75rem;
}

.app-card h5 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary-blue);
    margin-bottom: 0.25rem;
}

.app-card p {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Lab Footer */
.lab-footer {
    background: #ffffff;
    border-top: 1px solid var(--card-border);
    padding: 1.25rem 1.5rem;
    margin-top: 2rem;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.footer-container {
    max-width: 1700px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

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

/* Responsive Rules */
@media (max-width: 1200px) {
    .workspace-grid {
        grid-template-columns: 360px 1fr;
    }
    .secondary-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .workspace-grid {
        grid-template-columns: 1fr;
    }
    .circuit-card {
        min-height: 550px;
    }
    .apps-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .lab-container {
        padding: 0 0.75rem;
    }
    .inputs-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .select-switches-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .footer-container {
        flex-direction: column;
        text-align: center;
    }
}

/* ── 16:1 Multiplexer Dark Mode Overrides ───────────────────── */
html[data-theme="dark"],
html.dark {
    --bg-main: #080d18 !important;
    --bg-grid-color: rgba(255, 255, 255, 0.04) !important;
    --card-bg: #111827 !important;
    --card-border: #263550 !important;
    --card-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    --text-heading: #f8fafc !important;
    --text-body: #cbd5e1 !important;
    --text-muted: #94a3b8 !important;
    --logic-inactive: #334155 !important;
    --primary-blue: #60a5fa !important;
    --primary-blue-hover: #93c5fd !important;
    --accent-blue-light: rgba(37, 99, 235, 0.2) !important;
}

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

html[data-theme="dark"] .status-indicator,
html.dark .status-indicator {
    color: #34d399 !important;
    background: rgba(16, 185, 129, 0.15) !important;
    border-color: rgba(16, 185, 129, 0.3) !important;
}

html[data-theme="dark"] .lab-header,
html.dark .lab-header {
    background: rgba(14, 21, 38, 0.95) !important;
    border-bottom: 1px solid #263550 !important;
}

html[data-theme="dark"] .toolbar-card,
html.dark .toolbar-card {
    background: #111827 !important;
    border: 1px solid #263550 !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4) !important;
}

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

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

html[data-theme="dark"] .btn-tab.active,
html.dark .btn-tab.active {
    background: #2563eb !important;
    color: #ffffff !important;
}

html[data-theme="dark"] .btn-secondary,
html.dark .btn-secondary,
html[data-theme="dark"] .btn-outline,
html.dark .btn-outline {
    background: #1e293b !important;
    border: 1px solid #334155 !important;
    color: #e2e8f0 !important;
}

html[data-theme="dark"] .btn-secondary:hover,
html.dark .btn-secondary:hover,
html[data-theme="dark"] .btn-outline:hover,
html.dark .btn-outline:hover {
    background: #334155 !important;
    color: #ffffff !important;
}

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

html[data-theme="dark"] .card,
html.dark .card {
    background: #111827 !important;
    border: 1px solid #263550 !important;
}

html[data-theme="dark"] .card-header,
html.dark .card-header {
    border-bottom: 1px solid #263550 !important;
}

html[data-theme="dark"] .card-header h3,
html.dark .card-header h3 {
    color: #60a5fa !important;
}

html[data-theme="dark"] .readout-box,
html.dark .readout-box {
    background: #1e293b !important;
    border: 1px solid #334155 !important;
}

html[data-theme="dark"] .readout-box.highlight-box,
html.dark .readout-box.highlight-box {
    background: rgba(37, 99, 235, 0.15) !important;
    border-color: #1e40af !important;
}

html[data-theme="dark"] .readout-box.output-box,
html.dark .readout-box.output-box {
    background: rgba(139, 92, 246, 0.15) !important;
    border-color: #6b21a8 !important;
}

html[data-theme="dark"] .binary-display,
html.dark .binary-display {
    color: #60a5fa !important;
}

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

html[data-theme="dark"] .select-switch-item,
html.dark .select-switch-item {
    background: #1e293b !important;
    border: 1px solid #334155 !important;
}

html[data-theme="dark"] .select-label strong,
html.dark .select-label strong {
    color: #60a5fa !important;
}

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

html[data-theme="dark"] .toggle-btn,
html.dark .toggle-btn {
    background: #0f172a !important;
    border: 2px solid #334155 !important;
    color: #f8fafc !important;
}

html[data-theme="dark"] .toggle-btn.active-high,
html.dark .toggle-btn.active-high {
    background: #2563eb !important;
    border-color: #3b82f6 !important;
    color: #ffffff !important;
}

html[data-theme="dark"] .input-item,
html.dark .input-item {
    background: #1e293b !important;
    border: 1px solid #334155 !important;
}

html[data-theme="dark"] .input-item.selected,
html.dark .input-item.selected {
    border-color: #3b82f6 !important;
    background: rgba(37, 99, 235, 0.2) !important;
}

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

html[data-theme="dark"] .input-val-btn,
html.dark .input-val-btn {
    background: #0f172a !important;
    border: 1px solid #334155 !important;
    color: #94a3b8 !important;
}

html[data-theme="dark"] .input-val-btn.is-high,
html.dark .input-val-btn.is-high {
    background: #10b981 !important;
    border-color: #059669 !important;
    color: #ffffff !important;
}

html[data-theme="dark"] .svg-container,
html.dark .svg-container {
    background: #0a0f1d !important;
    border: 1px solid #1e293b !important;
}

html[data-theme="dark"] .svg-mux-block,
html.dark .svg-mux-block {
    fill: #1e293b !important;
    stroke: #475569 !important;
}

html[data-theme="dark"] .svg-mux-block.active-mux,
html.dark .svg-mux-block.active-mux {
    fill: rgba(37, 99, 235, 0.25) !important;
    stroke: #3b82f6 !important;
}

html[data-theme="dark"] .svg-mux-label,
html.dark .svg-mux-label {
    fill: #93c5fd !important;
}

html[data-theme="dark"] .svg-mux-sublabel,
html.dark .svg-mux-sublabel {
    fill: #94a3b8 !important;
}

html[data-theme="dark"] .svg-stage-header-bg,
html.dark .svg-stage-header-bg {
    fill: #1e293b !important;
}

html[data-theme="dark"] .svg-stage-header-text,
html.dark .svg-stage-header-text {
    fill: #93c5fd !important;
}

html[data-theme="dark"] .svg-text-node,
html.dark .svg-text-node {
    fill: #94a3b8 !important;
}

html[data-theme="dark"] .svg-text-node.selected-text,
html.dark .svg-text-node.selected-text {
    fill: #60a5fa !important;
}

html[data-theme="dark"] .circuit-footer-note,
html.dark .circuit-footer-note {
    background: #1e293b !important;
    border: 1px solid #334155 !important;
    color: #94a3b8 !important;
}

html[data-theme="dark"] .table-card,
html.dark .table-card,
html[data-theme="dark"] .theory-card,
html.dark .theory-card,
html[data-theme="dark"] .app-card,
html.dark .app-card {
    background: #111827 !important;
    border: 1px solid #1e293b !important;
}

html[data-theme="dark"] .app-card,
html.dark .app-card {
    background: #1e293b !important;
    border: 1px solid #334155 !important;
}

html[data-theme="dark"] .scaling-table th,
html.dark .scaling-table th,
html[data-theme="dark"] .truth-table th,
html.dark .truth-table th {
    background: #1e293b !important;
    color: #ffffff !important;
    border-color: #334155 !important;
}

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

html[data-theme="dark"] .truth-table tr.active-row,
html.dark .truth-table tr.active-row,
html[data-theme="dark"] .scaling-table tr.highlight-row,
html.dark .scaling-table tr.highlight-row {
    background: rgba(37, 99, 235, 0.2) !important;
}

html[data-theme="dark"] .lab-footer,
html.dark .lab-footer {
    background: #0f172a !important;
    border-color: #1e293b !important;
    color: #64748b !important;
}

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

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

html[data-theme="dark"] .dropdown-menu button:hover,
html.dark .dropdown-menu button:hover {
    background: #334155 !important;
    color: #60a5fa !important;
}

