/* Digital instruments share the scene player's type, surfaces and transport.
   Signal labels remain explicit: colour never carries a value by itself. */
.logic-widget { min-width: 0; max-width: 100%; margin: 30px 0; overflow: hidden; border: 1px solid var(--rule-strong); border-radius: var(--r-case); background: var(--card); color: var(--ink); }
.logic-widget > .figure-title { margin: 0; padding: 18px 20px; border-bottom: 1px solid var(--rule); font: 650 24px/1.2 var(--display); }
.logic-widget [data-logic-body] { padding: 20px; min-width: 0; }
.logic-widget p { margin: 12px 0; font: 400 15px/1.55 var(--sans); max-width: 75ch; }
.logic-widget .figure-caption, .logic-status { padding: 0 20px; }
.logic-widget .logic-notes { margin: 12px 0; padding: 0 20px 0 44px; font: 400 15px/1.55 var(--sans); }
.logic-widget .logic-notes li + li { margin-top: 4px; }
.logic-widget .logic-status:empty { display: none; }
.logic-widget .logic-status[data-good="true"] { color: var(--good); }
.logic-widget .logic-formula { font: 600 clamp(18px, 3vw, 25px)/1.5 var(--mono); overflow-wrap: anywhere; }
.logic-scroll { max-width: 100%; min-width: 0; overflow: auto; overscroll-behavior-inline: contain; background: var(--paper); border-radius: 8px; }
.logic-widget svg { display: block; max-width: none; }
.logic-widget svg text { fill: var(--ink); stroke: none; font: 12px var(--mono); }
/* Net names sit on a halo of the figure ground, so a wire passing behind never strikes them through. */
.logic-widget svg text.logic-net-label { stroke: var(--paper); stroke-width: 4px; stroke-linejoin: round; paint-order: stroke; }
/* Circuits and state diagrams shrink to the column like the datapath figures, then scroll below a readable size. */
.logic-widget .logic-circuit { width: 100%; max-width: var(--w); min-width: 0; margin-inline: auto; height: auto; }
.logic-widget .logic-fsm { width: 100%; max-width: var(--w); min-width: min(var(--w), 340px); height: auto; margin: 0 auto; }
.logic-widget table { border-collapse: collapse; width: 100%; font: 14px/1.4 var(--mono); }
.logic-widget th, .logic-widget td { padding: 9px 12px; text-align: center; border-bottom: 1px solid var(--rule); color: var(--ink); }
.logic-widget th { background: var(--paper-2); font-weight: 600; }
.logic-widget caption { padding: 10px; text-align: left; font: 14px/1.5 var(--sans); }
.logic-widget tr.logic-selected { background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: -2px; }
.logic-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px 20px; border-top: 1px solid var(--rule); background: var(--paper-2); }
.logic-controls[hidden] { display: none; }
.logic-controls form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; width: 100%; }
.logic-controls label { display: grid; gap: 5px; min-width: 0; max-width: 100%; font: 500 14px/1.4 var(--sans); }
.logic-controls input, .logic-controls select, .logic-controls textarea { box-sizing: border-box; width: 100%; min-width: 0; max-width: 100%; border: 1px solid var(--rule-strong); border-radius: 8px; padding: 9px; background: var(--card); color: var(--ink); font: 14px/1.4 var(--mono); }
.logic-controls textarea { flex-basis: 100%; min-height: 100px; }
.logic-widget button:not(.diagram-action) { min-height: 40px; padding: 8px 14px; border: 1px solid var(--rule-strong); border-radius: var(--r-pill); background: var(--card); color: var(--ink); font: 550 14px/1.3 var(--sans); cursor: pointer; }
.logic-widget button:disabled { opacity: 1; cursor: default; }
.logic-widget button:not(.diagram-action):hover:not(:disabled), .logic-widget button[aria-pressed="true"] { background: var(--accent-soft); }
.logic-widget :focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.logic-widget [data-pin] { cursor: pointer; }
.logic-widget [data-pin]:focus-visible .logic-pin { stroke: var(--focus); stroke-width: 4px; }
.logic-widget .diagram-transport { flex: 1 1 100%; flex-wrap: wrap; }
.logic-lab { display: grid; grid-template-columns: minmax(140px, .65fr) minmax(0, 2fr); gap: 20px; align-items: start; }
.logic-lab.logic-lab-multi { grid-template-columns: minmax(0, max-content) minmax(0, 1fr); }
.logic-lab > *, .logic-fsm-layout > * { min-width: 0; }
.logic-text { margin-top: 12px; font: 14px/1.5 var(--sans); }
.logic-text summary { cursor: pointer; padding: 8px 0; }
.logic-symbol { fill: var(--card); stroke: var(--ink); stroke-width: 1.8; }
.logic-wire, .logic-wave path { fill: none; stroke: var(--ink-2); stroke-width: 1.8; }
.logic-widget [data-value="1"] { stroke: var(--good); stroke-width: 3; }
.logic-widget [data-value="x"] { stroke: var(--warn); stroke-dasharray: 4 3; }
.logic-pin { fill: var(--card); stroke: var(--ink-2); stroke-width: 2; }
.logic-changed .logic-symbol { stroke: var(--accent); stroke-width: 3; }
.logic-widget[data-logic-ready] .logic-changed { animation: logic-flash .4s ease-out; }
@keyframes logic-flash { from { opacity: .45; } to { opacity: 1; } }
.logic-future { visibility: hidden; }
.logic-kmaps { display: flex; flex-wrap: wrap; gap: 20px; }
.logic-map { flex: 1 1 260px; min-width: 0; max-width: 420px; }
.logic-map table { table-layout: fixed; }
.logic-map td, .logic-map th { padding: 3px; }
.logic-map th { font-size: 12px; overflow-wrap: anywhere; vertical-align: middle; }
.logic-map button { display: grid; gap: 3px; width: 100%; padding: 7px 2px !important; border-radius: 8px !important; }
.logic-map button strong { font: 650 22px/1 var(--mono); }
.logic-map button small { font: 11px/1.2 var(--mono); }
.logic-map .logic-group-cell button { border: 2px solid var(--accent); background: var(--accent-soft); }
.logic-widget .logic-map-name { margin: 0 0 6px; font: 650 18px/1.3 var(--mono); }
.logic-outputs { margin: 8px 0; padding: 0; list-style: none; }
.logic-outputs li { margin: 4px 0; }
.logic-outputs .logic-formula { font-size: clamp(16px, 2.6vw, 21px); }
.logic-groups { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }
.logic-fsm-layout { display: grid; grid-template-columns: minmax(0, 1fr) max-content; gap: 16px; }
.logic-fsm-layout th { white-space: nowrap; }
.logic-widget .logic-fsm-wave th:first-child { width: 1%; text-align: left; white-space: nowrap; }
.logic-arc { fill: none; stroke: var(--ink-2); stroke-width: 1.6; }
.logic-arrow { fill: var(--ink-2); stroke: none; }
.logic-state circle, .logic-wheel circle { fill: var(--card); stroke: var(--ink-2); stroke-width: 1.8; }
.logic-active .logic-arrow, .logic-state .logic-token { fill: var(--accent); }
.logic-active > path, .logic-active > circle { stroke: var(--accent); stroke-width: 3; }
.logic-state.logic-active > circle:first-child, .logic-wheel .logic-active circle { fill: var(--accent-soft); }
.logic-bit-row { display: flex; gap: 6px; overflow-x: auto; padding: 4px; }
.logic-bit-row > div { display: grid; gap: 6px; text-align: center; flex: 1 0 34px; max-width: 68px; }
.logic-bit-row button { border-radius: 8px !important; padding: 10px 2px !important; font: 650 22px/1 var(--mono) !important; }
.logic-bit-row small { font: 12px var(--mono); color: var(--ink-2); }
.logic-bit-views { display: flex; flex-wrap: wrap; gap: 18px 28px; margin: 20px 0; }
.logic-bit-views dt { font: 14px var(--sans); color: var(--ink-2); }
.logic-bit-views dd { margin: 6px 0 0; font: 600 26px/1.15 var(--mono); }
.logic-flag { display: inline-block; padding: 6px 10px; border-radius: 8px; background: var(--paper-2); }
.logic-flag[data-value="1"] { color: var(--good); background: var(--good-soft); }
.logic-bit-extra { display: flex; align-items: start; flex-wrap: wrap; gap: 18px; }
.logic-bit-extra > div { flex: 1 1 260px; min-width: 0; }
.logic-bit-views dd { overflow-wrap: anywhere; }
.logic-widget .logic-wheel { width: 380px; max-width: 100%; height: auto; }
.logic-wheel .logic-wheel-ring { fill: none; stroke: var(--rule-strong); }
.logic-parity { padding-left: 0; list-style: none; }
.logic-parity li { padding: 4px 10px; }
.logic-parity li:nth-child(1) { border-left: 4px solid var(--flow-call); }
.logic-parity li:nth-child(2) { border-left: 4px solid var(--flow-data); }
.logic-parity li:nth-child(3) { border-left: 4px solid var(--flow-return); }
/* Fault view: D and D' labels where the faulty circuit differs, the stuck net dashed, a detecting output ringed. */
.logic-widget svg text.logic-diff { fill: var(--accent); font-weight: 700; }
.logic-widget .logic-wire.logic-diff { stroke: var(--accent); stroke-width: 3; }
.logic-widget .logic-wire.logic-fault-net, .logic-widget .logic-pin.logic-fault-net { stroke: var(--bad); stroke-dasharray: 6 3; stroke-width: 3; }
.logic-widget svg text.logic-detected { fill: var(--bad); text-decoration: underline; }
.logic-widget [data-fault-net] { cursor: pointer; }
.logic-widget [data-fault-net]:focus-visible text { fill: var(--focus); text-decoration: underline; }
.logic-fault { margin-top: 12px; padding-top: 4px; border-top: 1px solid var(--rule); }
/* PLA, PAL and ROM planes: input and output lines, product-term rows, crosspoint dots. */
.logic-widget .pla-svg { width: 100%; max-width: var(--w); min-width: min(var(--w), 340px); height: auto; }
.pla-line { stroke: var(--rule-strong); stroke-width: 1.5; }
.pla-term { stroke: var(--ink-2); stroke-width: 1.5; }
.pla-term.pla-unused { stroke-dasharray: 3 4; }
.pla-dot { fill: var(--card); stroke: var(--ink-2); stroke-width: 1.2; }
.pla-dot.pla-on { fill: var(--accent); stroke: var(--accent); }
.pla-hit { fill: transparent; stroke: none; }
.logic-widget [data-xp] { cursor: pointer; }
.logic-widget [data-xp]:focus-visible .pla-hit { stroke: var(--focus); stroke-width: 3; }
.pla-verdict[data-good="true"] strong { color: var(--good); }
.pla-verdict[data-good="false"] strong { color: var(--bad); }
.logic-pla { margin-top: 16px; }
/* Flow tables: a stable entry is circled; the present cell is ringed; cells on the path are tinted. */
.logic-flow td span { display: inline-grid; place-items: center; min-width: 30px; height: 30px; border-radius: 50%; }
.logic-flow td.logic-stable span { border: 2px solid var(--ink); font-weight: 700; }
.logic-flow td.logic-path { background: var(--accent-soft); }
.logic-flow td.logic-now { outline: 3px solid var(--accent); outline-offset: -3px; }
.logic-flow tr.logic-race th { box-shadow: inset 4px 0 0 var(--bad); }
.logic-race-orders { font: 14px/1.6 var(--mono); }
/* W6 setup and hold window. The keep-out band and the jitter band are tinted; text labels name them too. */
.logic-widget .window-svg { width: 100%; max-width: var(--w); min-width: min(var(--w), 330px); height: auto; touch-action: none; cursor: ew-resize; }
.logic-widget .window-svg text { font-size: 15px; }
.window-setup { fill: var(--accent-soft); stroke: var(--warn); stroke-dasharray: 4 3; }
.window-hold { fill: var(--accent-soft); stroke: var(--accent); stroke-dasharray: 8 3; }
.window-jitter { fill: var(--paper-2); stroke: var(--ink-2); stroke-dasharray: 2 3; }
.window-wave, .window-bus { fill: none; stroke: var(--ink); stroke-width: 2; }
.window-axis, .window-tick, .window-nominal { stroke: var(--ink-2); stroke-width: 1.2; }
.window-nominal { stroke-dasharray: 3 3; }
.window-meta { fill: var(--bad-soft); stroke: var(--bad); stroke-dasharray: 4 3; }
.window-handle line { stroke: var(--accent); stroke-width: 3; }
.window-handle circle { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.logic-widget svg text.window-label { font: 600 14px var(--sans); }
.window-result[data-result="metastable"] strong { color: var(--bad); }
.window-result[data-result="new"] strong { color: var(--good); }
.logic-controls input[type="range"] { padding: 0; accent-color: var(--accent); min-width: 180px; }
.logic-controls output { font: 14px var(--mono); }
/* Float fields: sign, exponent and fraction carry a coloured rule and their names in text. */
.logic-float-row { gap: 4px; }
.logic-float-row > div { flex: 1 0 30px; border-top: 4px solid var(--rule-strong); padding-top: 4px; }
.logic-widget [data-field="sign"] { border-color: var(--flow-call); }
.logic-widget [data-field="exp"] { border-color: var(--flow-data); }
.logic-widget [data-field="frac"] { border-color: var(--flow-return); }
.logic-float-fields { display: flex; flex-wrap: wrap; gap: 8px 16px; font: 14px/1.5 var(--mono); }
.logic-float-fields span { border-top: 0; border-left: 4px solid; padding: 2px 8px; overflow-wrap: anywhere; }
.logic-float-presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.logic-exact code { overflow-wrap: anywhere; word-break: break-all; }
.logic-widget .logic-round table th[scope="row"] { text-align: left; font-weight: 500; }
.logic-widget table.logic-crc { width: auto; font: 15px/1.2 var(--mono); }
.logic-widget table.logic-crc td { padding: 3px 5px; border: 0; }
.logic-widget table.logic-crc th { text-align: left; font: 13px/1.3 var(--sans); background: none; white-space: nowrap; border: 0; }
.logic-widget table.logic-crc tr:nth-child(2n) td:not(:empty) { color: var(--accent); }
.logic-widget table.logic-crc tr:nth-child(2n+1):not(:first-child) td:not(:empty) { border-top: 1px solid var(--rule-strong); }
.logic-widget table.logic-crc .logic-crc-tail { background: var(--paper-2); }
.logic-widget table.logic-crc tr.logic-future td { border-color: transparent !important; background: none; }
@media (max-width: 650px) {
  .logic-lab, .logic-lab.logic-lab-multi, .logic-fsm-layout { grid-template-columns: minmax(0, 1fr); }
  .logic-widget [data-logic-body], .logic-controls { padding: 12px; }
  .logic-widget > .figure-title { padding: 16px 12px; font-size: 21px; }
  .logic-widget .figure-caption, .logic-status { padding-inline: 12px; }
  .logic-widget .logic-notes { padding: 0 12px 0 34px; }
}
@media (prefers-reduced-motion: reduce) {
  .logic-widget *, .logic-widget[data-logic-ready] .logic-changed { animation: none; transition: none; scroll-behavior: auto; }
}

.lane-pins { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.flow-lane > .logic-gate + .logic-gate { margin-top: 6px; }
