/* ============================================================
   logica.css — Logic Gate Simulator
   Logica booleana & circuiti. Usa base.css + lab.css.
   ============================================================ */

.lg-sec { position: relative; z-index: 2; }

code { font-family: var(--font-mono); font-size: 0.92em; }
.tool-hero code,
.lg-expr-hint code,
.lg-gates-legend code {
  background: var(--bg-sunk);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 0.05em 0.35em;
  color: var(--ink);
}

/* ---------- Pannello espressione ---------- */
.lg-expr-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
}
.lg-expr-row .control-label { flex: 0 0 auto; }
.lg-expr-field { flex: 1 1 320px; min-width: 0; }
.lg-expr-field input { font-size: 1.08rem; }

.run-btn {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  padding: 0.62rem 1.1rem;
  border: 1px solid var(--accent);
  border-radius: 100px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s var(--ease), opacity 0.2s var(--ease);
}
.run-btn:hover { transform: translateY(-1px); }
.run-btn:active { transform: translateY(1px); }

.lg-expr-err {
  min-height: 1.1rem;
  margin-top: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: #e0533d;
}
.lg-expr-hint {
  margin-top: 0.35rem;
  font-size: 0.86rem;
  color: var(--ink-soft);
  line-height: 1.7;
}

/* ---------- Banco di lavoro ---------- */
.lg-board-panel { padding: clamp(1rem, 2.5vw, 1.4rem); }

.lg-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.lg-toolbar .control-label { margin-right: 0.2rem; }
.lg-toolbar-spacer { flex: 1 1 auto; }
.lg-add {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.42rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 100px;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s var(--ease), color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.lg-add:hover { border-color: var(--accent); color: var(--accent); }

.lg-board {
  position: relative;
  width: 100%;
  height: clamp(360px, 56vh, 520px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    radial-gradient(circle at 1px 1px, var(--line-soft) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg-sunk);
  background-attachment: local;     /* la griglia segue lo scroll del contenuto */
  overflow: auto;                   /* scorrevole in orizzontale e verticale */
  overscroll-behavior: contain;
}
/* nodi e fili vivono su un canvas virtuale dimensionato da JS (può eccedere il box) */
.lg-wires { position: absolute; top: 0; left: 0; pointer-events: none; }
.lg-wires path.wire { pointer-events: stroke; cursor: pointer; }
/* il layer dei nodi copre tutto il canvas: NON deve intercettare i click,
   altrimenti i cavi (sotto) non si possono cliccare per rimuoverli. Riabilito solo i nodi. */
.lg-nodes { position: absolute; top: 0; left: 0; pointer-events: none; }
.lg-node { pointer-events: auto; }

.lg-board-hint {
  position: absolute;
  left: 50%; bottom: 12px;
  transform: translateX(-50%);
  max-width: 90%;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-faint);
  pointer-events: none;
  transition: opacity 0.3s var(--ease);
}
.lg-board-hint em { font-style: normal; color: var(--accent); }

/* ---------- Nodi ---------- */
.lg-node {
  position: absolute;
  user-select: none;
  touch-action: none;
}
.lg-gate {
  width: 92px;
  min-height: 56px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: grab;
  box-shadow: 0 4px 14px -10px rgba(0,0,0,0.5);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.lg-node.dragging .lg-gate { cursor: grabbing; box-shadow: 0 12px 26px -14px rgba(0,0,0,0.55); }
.lg-gate-sym { font-family: var(--font-display); font-style: italic; font-weight: 600; font-size: 1.15rem; letter-spacing: -0.01em; }
.lg-gate-sub { font-family: var(--font-mono); font-size: 0.62rem; color: var(--ink-faint); margin-top: 1px; }

/* interruttore (input) */
.lg-node.t-in .lg-gate {
  width: 84px;
  border-style: solid;
  cursor: pointer;
  gap: 2px;
  padding: 0.4rem;
}
.lg-in-name { font-family: var(--font-display); font-style: italic; font-weight: 600; font-size: 1.25rem; line-height: 1; }
.lg-switch {
  width: 40px; height: 20px;
  border-radius: 100px;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  position: relative;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.lg-switch::after {
  content: "";
  position: absolute; top: 50%; left: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--ink-faint);
  transform: translateY(-50%);
  transition: left 0.2s var(--ease), background-color 0.2s var(--ease);
}
.lg-node.on .lg-switch { background: var(--accent); border-color: var(--accent); }
.lg-node.on .lg-switch::after { left: 22px; background: var(--accent-ink); }
.lg-node.on.t-in .lg-gate { border-color: var(--accent); }
.lg-in-val { font-family: var(--font-mono); font-size: 0.66rem; color: var(--ink-faint); }
.lg-node.on .lg-in-val { color: var(--accent); }

/* lampadina (output) */
.lg-node.t-out .lg-gate {
  width: 76px; height: 76px;
  border-radius: 50%;
  cursor: grab;
  gap: 0;
}
.lg-bulb { font-size: 1.6rem; line-height: 1; filter: grayscale(1) opacity(0.45); transition: filter 0.25s var(--ease); }
.lg-node.on.t-out .lg-gate {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--bg-elev));
  box-shadow: 0 0 0 6px var(--accent-wash), 0 8px 24px -12px var(--accent);
}
.lg-node.on .lg-bulb { filter: none; }
.lg-out-lbl { font-family: var(--font-mono); font-size: 0.6rem; color: var(--ink-faint); margin-top: 1px; }

/* stato logico ON sui blocchi gate */
.lg-node.on .lg-gate { border-color: var(--accent); }

/* ---------- Porte (pallini di connessione) ---------- */
.lg-port {
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 2px solid var(--ink-soft);
  cursor: crosshair;
  transition: transform 0.15s var(--ease), border-color 0.15s var(--ease), background-color 0.15s var(--ease);
  z-index: 3;
}
.lg-port:hover { transform: scale(1.35); border-color: var(--accent); }
.lg-port.out { right: -8px; top: 50%; transform: translateY(-50%); }
.lg-port.out:hover { transform: translateY(-50%) scale(1.35); }
.lg-port.in { left: -8px; }
.lg-port.pending { border-color: var(--accent); background: var(--accent); }
.lg-port.on { border-color: var(--accent); background: var(--accent); }

/* bottone elimina nodo */
.lg-del {
  position: absolute;
  top: -9px; right: -9px;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink-soft);
  font-size: 0.8rem;
  line-height: 1;
  display: none;
  place-items: center;
  cursor: pointer;
  z-index: 4;
}
.lg-node:hover .lg-del { display: grid; }
.lg-del:hover { border-color: #e0533d; color: #e0533d; }

/* fili */
.lg-wires path.lg-wire-hit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: pointer; }
.lg-wires path.wire { fill: none; stroke: var(--ink-soft); stroke-width: 2.4; pointer-events: stroke; cursor: pointer; transition: stroke 0.2s var(--ease); }
.lg-wires path.wire:hover,
.lg-wires path.lg-wire-hit:hover + path.wire { stroke: #e0533d; stroke-width: 3.2; }
.lg-wires path.wire.on { stroke: var(--accent); }
.lg-wires path.temp { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-dasharray: 5 5; }

/* suggerimento sempre visibile sotto il banco */
.lg-tip { margin-top: 0.7rem; font-family: var(--font-mono); font-size: 0.76rem; color: var(--ink-faint); line-height: 1.5; }
.lg-tip b { color: #e0533d; font-weight: 600; }

/* ---------- Esempi ---------- */
.lg-examples { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin-top: 1rem; }
.lg-ex-seg { flex-wrap: wrap; }

/* ---------- Layout parte bassa ---------- */
.lg-bottom {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 820px) { .lg-bottom { grid-template-columns: 1fr; } }

/* ---------- Tabella di verità ---------- */
.lg-truth-wrap { overflow-x: auto; }
.lg-truth {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.92rem;
}
.lg-truth th, .lg-truth td {
  padding: 0.5rem 0.7rem;
  text-align: center;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.lg-truth thead th {
  color: var(--ink-soft);
  font-weight: 500;
  border-bottom: 1px solid var(--line);
}
.lg-truth thead th.out-col { color: var(--accent); }
.lg-truth td.out-col { font-weight: 600; }
.lg-truth .bit-1 { color: var(--accent); }
.lg-truth .bit-0 { color: var(--ink-faint); }
.lg-truth tbody tr.active { background: var(--accent-wash); }
.lg-truth tbody tr.active td { border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.lg-truth-empty { color: var(--ink-faint); font-size: 0.9rem; padding: 1.5rem 0; text-align: center; }

/* ---------- Legenda porte ---------- */
.lg-gates-legend { list-style: none; display: grid; gap: 0.9rem; }
.lg-gates-legend li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.7rem 0.9rem;
  align-items: baseline;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--line-soft);
}
.lg-gates-legend li:last-child { border-bottom: 0; padding-bottom: 0; }
.lg-leg-name {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent);
  font-size: 0.92rem;
}
.lg-leg-op { font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink-faint); }
.lg-leg-desc { grid-column: 1 / -1; font-size: 0.88rem; color: var(--ink-soft); }

@media (max-width: 520px) {
  .lg-expr-row { gap: 0.6rem; }
  .run-btn { flex: 1 1 100%; }
}
