/* ── GATE GRID ────────────────────────────────────── */
  .gates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
  }
  .gate-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    transition: border-color .25s, transform .2s;
    position: relative;
  }
  .gate-card:hover {
    border-color: var(--border2);
    transform: translateY(-2px);
  }
  .gate-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--gcolor, var(--accent)), transparent);
    opacity: 0; transition: opacity .3s;
  }
  .gate-card:hover::before { opacity: 1; }

  .gate-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
  }
  .gate-title-row { display: flex; align-items: center; gap: 12px; }
  .gate-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--gcolor, var(--accent));
    box-shadow: 0 0 8px var(--gcolor, var(--accent));
  }
  .gate-name {
    font-size: 16px; font-weight: 700; letter-spacing: .02em;
    color: var(--text);
  }
  .gate-type-badge {
    font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
    padding: 3px 10px; border-radius: 20px;
    background: rgba(255,255,255,0.05); color: var(--muted);
    border: 1px solid var(--border2);
  }

  .gate-body { display: flex; gap: 0; }

  /* Left: symbol + circuit */
  .gate-visual {
    width: 240px; flex-shrink: 0;
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
  }
  .visual-tab-row {
    display: flex; border-bottom: 1px solid var(--border);
  }
  .vtab {
    flex: 1; padding: 8px 0; text-align: center; font-size: 11px; font-weight: 600;
    color: var(--muted); cursor: pointer; letter-spacing: .04em;
    border-bottom: 2px solid transparent; transition: color .2s, border-color .2s;
    background: none; border-top: none; border-left: none; border-right: none;
    font-family: var(--font); text-transform: uppercase;
  }
  .vtab.active { color: var(--gcolor, var(--accent)); border-bottom-color: var(--gcolor, var(--accent)); }
  .gate-svg-area {
    flex: 1; display: flex; align-items: center; justify-content: center;
    padding: 12px 10px; min-height: 200px;
    background: var(--bg2);
  }
  .gate-svg-area svg { width: 100%; max-width: 220px; height: auto; }

  /* Right: controls + truth table */
  .gate-right { flex: 1; display: flex; flex-direction: column; }

  .io-panel {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 10px;
  }
  .io-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
  .io-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .io-btn {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg3); border: 1px solid var(--border2);
    border-radius: 8px; padding: 8px 14px; cursor: pointer;
    font-family: var(--font); transition: all .15s;
    color: var(--muted); font-size: 13px; font-weight: 500;
  }
  .io-btn:hover { border-color: var(--dim); color: var(--text); }
  .io-btn .bit-indicator {
    width: 22px; height: 22px; border-radius: 5px;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; font-family: var(--mono);
    background: var(--bg2); border: 1px solid var(--border2);
    transition: all .15s;
  }
  .io-btn.on { border-color: rgba(79,142,247,0.4); color: var(--text); }
  .io-btn.on .bit-indicator {
    background: var(--gcolor, var(--accent));
    border-color: var(--gcolor, var(--accent));
    color: #fff;
    box-shadow: 0 0 8px var(--gcolor, var(--accent));
  }
  .arrow-sep { color: var(--dim); font-size: 18px; }
  .output-display {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px; border-radius: 8px;
    background: var(--bg3); border: 1px solid var(--border2);
  }
  .output-label { font-size: 12px; color: var(--muted); font-weight: 500; }
  .output-val {
    width: 28px; height: 28px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700; font-family: var(--mono);
    background: var(--bg2); border: 1px solid var(--border2);
    color: var(--muted); transition: all .2s;
  }
  .output-val.on {
    background: var(--green); border-color: var(--green); color: #fff;
    box-shadow: 0 0 12px rgba(34,211,110,0.4);
  }
  .output-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--dim); transition: all .2s;
  }
  .output-dot.on { background: var(--green); box-shadow: 0 0 8px var(--green); }

  /* Truth table */
  .truth-table-wrap { flex: 1; padding: 0 18px 16px; padding-top: 12px; }
  .tt-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
  table.tt {
    width: 100%; border-collapse: collapse; font-size: 12px; font-family: var(--mono);
  }
  table.tt th {
    color: var(--muted); font-weight: 600; text-align: center;
    padding: 5px 8px; border-bottom: 1px solid var(--border);
    letter-spacing: .04em; font-size: 11px;
  }
  table.tt td {
    text-align: center; padding: 5px 8px; color: var(--dim);
    transition: color .15s, background .15s;
    border-radius: 4px;
  }
  table.tt tr.active td { color: var(--text); }
  table.tt tr.active td:last-child { color: var(--green); font-weight: 700; }
  table.tt tr.active { background: rgba(34,211,110,0.06); }

  /* Gate description */
  .gate-desc {
    padding: 10px 18px 14px; font-size: 12px; color: var(--muted);
    line-height: 1.5; border-top: 1px solid var(--border);
  }
  .expr {
    font-family: var(--mono); color: var(--accent);
    background: rgba(79,142,247,0.1); padding: 1px 6px; border-radius: 4px;
    font-size: 11px;
  }

  /* ── CIRCUIT SVG STYLES ───────────────────────────── */
  .circuit-svg { color: currentColor; }
  .wire { stroke: #3d4a6a; stroke-width: 1.5; fill: none; }
  .wire-hot { stroke: var(--accent); stroke-width: 2; fill: none; }
  .wire-out { stroke: var(--green); stroke-width: 2; fill: none; }
  .gate-shape { fill: #1a2235; stroke: #3d4a6a; stroke-width: 1.5; }
  .gate-shape-hot { fill: #1a2235; stroke: var(--accent); stroke-width: 1.5; }
  .bubble { fill: #1a2235; stroke: #3d4a6a; stroke-width: 1.5; }
  .node { fill: var(--accent); }
  .node-out { fill: var(--green); }
  .sig-label { font-family: 'JetBrains Mono', monospace; font-size: 9px; fill: #7b859a; }
  .sig-val { font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 700; }
  .transistor-b { fill: none; stroke: #3d4a6a; stroke-width: 1.5; }
  .transistor-c { fill: none; stroke: #3d4a6a; stroke-width: 1.5; }
  .vcc-line { stroke: #f5a623; stroke-width: 1.5; stroke-dasharray: 3 2; }
  .gnd-line { stroke: #7b859a; stroke-width: 1.5; }

  /* ── STATS BAND ───────────────────────────────────── */
  .stats-band {
    background: var(--bg2);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 28px 2rem;
  }
  .stats-inner {
    max-width: 1280px; margin: 0 auto;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0;
  }
  .stat-item {
    text-align: center; padding: 16px;
    border-right: 1px solid var(--border);
  }
  .stat-item:last-child { border-right: none; }
  .stat-num {
    font-size: 1.8rem; font-weight: 700; letter-spacing: -.02em;
    background: linear-gradient(135deg, var(--accent), var(--teal));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  }
  .stat-lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

  /* ── FORMULA SECTION ──────────────────────────────── */
  .formula-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px;
  }
  .formula-card {
    background: var(--card2); border: 1px solid var(--border);
    border-radius: 12px; padding: 16px 20px;
    display: flex; flex-direction: column; gap: 8px;
  }
  .formula-name { font-size: 13px; font-weight: 600; color: var(--text); }
  .formula-expr {
    font-family: var(--mono); font-size: 15px; font-weight: 600;
    color: var(--accent);
    background: rgba(79,142,247,0.08); border: 1px solid rgba(79,142,247,0.15);
    padding: 8px 12px; border-radius: 8px; text-align: center;
  }
  .formula-desc { font-size: 12px; color: var(--muted); }

  /* ── FOOTER ───────────────────────────────────────── */
  footer {
    background: var(--bg2); border-top: 1px solid var(--border);
    text-align: center; padding: 24px 2rem; color: var(--muted); font-size: 13px;
  }
  footer a { color: var(--accent); text-decoration: none; }

  /* ── RESPONSIVE ───────────────────────────────────── */
  @media (max-width: 600px) {
    .gates-grid { grid-template-columns: 1fr; }
    .gate-body { flex-direction: column; }
    .gate-visual { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
    .nav-links { display: none; }
  }