/* Simulador de puertas lógicas (se carga después de styles.css) */
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.content ul { padding-left: 22px; }

.lg-editor { gap: 12px; }
.lg-palette { display: flex; flex-wrap: wrap; gap: 10px 22px; }
.lg-pgroup { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lg-prow { display: flex; flex-wrap: wrap; gap: 6px; }
.lg-tool {
  display: inline-flex; flex-direction: column; align-items: center; gap: 2px; min-width: 58px;
  font: inherit; font-size: .78rem; font-weight: 600; color: var(--text); cursor: pointer;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 5px 6px 4px;
}
.lg-tool:hover { border-color: var(--accent); background: var(--accent-soft); }
.lg-ticon { width: 46px; height: 26px; display: block; overflow: visible; }
.lg-ticon * { vector-effect: non-scaling-stroke; }
.lg-ticon .lg-pinl { display: none; }
.lg-xor { font-family: system-ui, sans-serif; font-size: .8em; font-weight: 400; }

.lg-bar { align-items: flex-end; }
.lg-select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; max-width: 100%;
}
.lg-select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.lg-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn:disabled { opacity: .45; cursor: default; border-color: var(--border); }

/* Lienzo */
.lg-canvas-wrap { position: relative; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg); }
.lg-canvas { display: block; width: 100%; height: clamp(340px, 62vh, 560px); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; cursor: grab; }
.lg-griddot { fill: var(--border); }
.lg-zoom { position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; gap: 4px; }
.lg-zoom button {
  width: 34px; height: 34px; font: inherit; font-size: 1.15rem; line-height: 1; cursor: pointer;
  color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
}
.lg-zoom button:hover { border-color: var(--accent); }
.lg-osc { position: absolute; left: 8px; bottom: 8px; right: 52px; background: #fee2e2; color: #991b1b; border-radius: 8px; padding: 6px 10px; font-size: .88rem; font-weight: 600; }

.lg-comp { cursor: move; }
.lg-comp.lg-toggle { cursor: pointer; }
.lg-hit { fill: transparent; }
.lg-selbox { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; }
.lg-body { fill: var(--panel); stroke: var(--wire); stroke-width: 2; stroke-linejoin: round; }
.lg-body.bad { stroke: #dc2626; stroke-width: 3; }
.lg-lead { stroke: var(--wire); stroke-width: 2; fill: none; }
.lg-iec { font: 700 15px system-ui, sans-serif; fill: var(--text); text-anchor: middle; dominant-baseline: central; }
.lg-pinl { font: 600 12px system-ui, sans-serif; fill: var(--text); dominant-baseline: central; }
.lg-pinl.end { text-anchor: end; }
.lg-clktri { fill: none; stroke: var(--wire); stroke-width: 1.6; }
.lg-label { font: 700 14px Georgia, "Times New Roman", serif; fill: var(--text); dominant-baseline: central; }
.lg-label { paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }
.lg-label.end { text-anchor: end; }
.lg-label.mid { text-anchor: middle; }
.lg-label.small { font: 600 11px system-ui, sans-serif; fill: var(--muted); }
.lg-sw { fill: var(--cell-zero); stroke: var(--wire); stroke-width: 1.5; opacity: .9; }
.lg-sw.on { fill: var(--accent); opacity: 1; }
.lg-knob { fill: #fff; stroke: rgba(0, 0, 0, .2); }
.lg-swv { font: 700 13px system-ui, sans-serif; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.lg-clk { fill: var(--panel); }
.lg-clk.on { fill: var(--accent-soft); }
.lg-clkwave { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.lg-led { fill: var(--panel); stroke: var(--wire); stroke-width: 2; }
.lg-led.on { fill: #ef4444; stroke: #b91c1c; filter: drop-shadow(0 0 6px rgba(239, 68, 68, .85)); }
.lg-pin { fill: var(--panel); stroke: var(--wire); stroke-width: 1.5; }
.lg-pin.conn { fill: var(--wire); }
.lg-pin.out { fill: var(--wire); }
.lg-pin.out.on { fill: var(--accent); stroke: var(--accent); }
.lg-pin.pend { fill: var(--accent); stroke: var(--accent); stroke-width: 3; }
.lg-wire { fill: none; stroke: var(--cell-zero); stroke-width: 2.2; stroke-linecap: round; pointer-events: none; }
.lg-wire.on { stroke: var(--accent); stroke-width: 3.2; }
.lg-wire.sel { stroke-dasharray: 7 5; stroke-width: 4; }
.lg-wire.temp { stroke: var(--accent); stroke-dasharray: 6 5; stroke-width: 2.5; }
.lg-whit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }

/* Barra de selección y reloj */
.lg-selbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; min-height: 40px; }
.lg-selbar .hint { margin: 0; }
.lg-seltitle { font-weight: 700; }
.lg-name { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.lg-name input { width: 96px !important; padding: 6px 10px !important; }
.lg-nins { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); }
.lg-nins .btn { padding: 4px 11px; }
.lg-nins b { color: var(--text); min-width: 1ch; text-align: center; }
.lg-del { color: #dc2626; }
.lg-clock { border-top: 1px solid var(--border); padding-top: 12px; }
.lg-clock.lg-off { opacity: .55; }

/* Cronograma */
.lg-timing { overflow-x: auto; }
.lg-timing svg { display: block; max-width: 100%; height: auto; }
.lg-tl { font: 700 13px Georgia, serif; fill: var(--text); text-anchor: end; dominant-baseline: central; }
.lg-tbase { stroke: var(--border); stroke-width: 1; }
.lg-twave { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; }
.lg-twave.clk { stroke: var(--muted); }
.lg-twave.in { stroke: #0d9488; }
.lg-tarea { fill: var(--accent-soft); }
.lg-tarea.clk { fill: none; }
.lg-edge { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; opacity: .55; }

/* Tablas y expresiones */
.lg-exprs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.lg-expr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.lg-exprtxt { font: 700 1.2rem Georgia, "Times New Roman", serif; word-break: break-word; }
.lg-klink { font-size: .9rem; }
.lg-tscroll { max-height: 460px; }
.lg-truth { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.lg-truth thead th { font-family: Georgia, serif; font-size: .95rem; color: var(--text); }
.lg-truth tbody tr { cursor: pointer; }
.lg-truth td.lg-1 { font-weight: 700; color: var(--text); }
.lg-truth td.lg-0 { color: var(--cell-zero); }
.lg-truth td.lg-badc { color: #dc2626; }
.lg-truth td.lg-badc::after { content: " ⚠"; font-size: .8em; }
.lg-truth tr.cur td { background: var(--accent-soft); box-shadow: inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
.lg-bad { color: #dc2626; }
.lg-gates-table td, .lg-gates-table th { text-align: center !important; font-family: ui-monospace, Menlo, Consolas, monospace !important; font-weight: 400 !important; }
.lg-gates-table th { font-family: system-ui, sans-serif !important; font-weight: 700 !important; }
.lg-gates-table small { font-weight: 400; color: var(--muted); }
.lg-ff-table td:first-child { font-family: system-ui, sans-serif !important; }

@media (prefers-color-scheme: dark) {
  .lg-osc { background: #451a1a; color: #fecaca; }
  .lg-twave.in { stroke: #2dd4bf; }
  .lg-knob { stroke: rgba(0, 0, 0, .5); }
}
@media (max-width: 640px) {
  .lg-palette { gap: 8px 14px; }
  .lg-tool { min-width: 50px; padding: 4px; font-size: .72rem; }
  .lg-ticon { width: 40px; height: 22px; }
  .lg-canvas { height: clamp(320px, 52vh, 440px); }
}
