/* WIRE — Logic Gate Sandbox
   The Lab — retro-arcade / CRT-era, dark only.
   Pixel type (Press Start 2P) drives the wordmark, HUD labels and headings;
   the working board and controls stay legible and utilitarian.
   Shares tokens + the self-hosted pixel font with the lab root. */

/* ---------- fonts (self-hosted, shared with the lab root) ---------- */

@font-face {
  font-family: "Press Start 2P";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/press-start-2p.woff2") format("woff2");
}
@font-face {
  font-family: "Press Start 2P Fallback";
  src: local("Courier New");
  size-adjust: 166.64%;
  ascent-override: 60%;
  descent-override: 0%;
  line-gap-override: 0%;
}

/* ---------- tokens ---------- */

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --surface-3: #20203250;
  --line: #28283c;
  --line-2: #353550;
  /* >=3:1 against surfaces for form-field boundaries */
  --control-line: #5e5e80;
  --text: #e9e9f2;
  --dim: #9aa0b5;

  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --sans: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 8px;
  --radius-sm: 4px;

  --duration-fast: 140ms;
  --duration-normal: 280ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.4);
  --glow-green: 0 0 14px rgba(65, 255, 139, 0.45);
  --glow-magenta: 0 0 14px rgba(255, 61, 139, 0.4);

  --space-gutter: clamp(0.9rem, 3.5vw, 2.5rem);

  /* signal palette — low = dim slate, high = neon green */
  --wire-low: #3a3a52;
  --wire-high: var(--green);

  --grid-fade: rgba(69, 240, 255, 0.045);
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

* { margin: 0; }

html {
  color-scheme: dark;
  scroll-behavior: smooth;
}

body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 480px at 50% -8%, rgba(69, 240, 255, 0.06), transparent 70%),
    radial-gradient(900px 500px at 100% 100%, rgba(255, 61, 139, 0.04), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: clamp(0.9rem, 0.86rem + 0.2vw, 0.95rem);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* faint global scanline texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.16) 0 1px,
    transparent 1px 3px
  );
  opacity: 0.4;
}

body > * { position: relative; z-index: 1; }

::selection { background: rgba(69, 240, 255, 0.3); color: var(--text); }

a { color: var(--cyan); }

button,
select,
input { font: inherit; }

button { cursor: pointer; color: inherit; }

button:disabled { cursor: not-allowed; }

h1, h2 { line-height: 1.2; }

:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(69, 240, 255, 0.2);
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 200;
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--bg);
  background: var(--cyan);
  padding: 0.7rem 1rem;
  text-decoration: none;
  transition: top var(--duration-fast) var(--ease-out);
}
.skip-link:focus { top: 0.5rem; }

/* ---------- header ---------- */

.app-header {
  width: min(100%, 104rem);
  margin-inline: auto;
  padding: clamp(1rem, 3vw, 1.6rem) var(--space-gutter) 0.4rem;
  display: flex;
  flex-direction: column;
  gap: clamp(0.9rem, 2.5vw, 1.4rem);
}

.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
  transition: color var(--duration-fast) ease, text-shadow var(--duration-fast) ease;
}
.lab-link:hover,
.lab-link:focus-visible { color: var(--cyan); text-shadow: var(--glow-cyan); }

.header-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: clamp(1rem, 3vw, 2rem);
}

.title-block { display: grid; gap: 0.4rem; }

.eyebrow {
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 200, 87, 0.3);
}

.wordmark {
  font-family: var(--pixel);
  font-weight: 400;
  font-size: clamp(1.9rem, 1rem + 5vw, 3.4rem);
  letter-spacing: 0.04em;
  color: var(--text);
  text-shadow: 0 0 18px rgba(69, 240, 255, 0.5), 3px 3px 0 var(--magenta);
}

.wordmark-cursor {
  color: var(--cyan);
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.tagline {
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

/* ---------- top controls ---------- */

.top-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.7rem 0.9rem;
}

.field { display: grid; gap: 0.3rem; }

.field-label {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--dim);
  text-transform: uppercase;
}

.select-input {
  min-height: 2.75rem;
  min-width: 11rem;
  padding: 0 2.2rem 0 0.85rem;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(45deg, transparent 50%, var(--cyan) 50%) calc(100% - 1.05rem) center / 0.45rem 0.45rem no-repeat,
    linear-gradient(135deg, var(--cyan) 50%, transparent 50%) calc(100% - 0.6rem) center / 0.45rem 0.45rem no-repeat,
    var(--surface-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
.select-input:hover { border-color: var(--cyan); }
.select-input:focus-visible { border-color: var(--cyan); }
.select-input option { background: var(--surface-2); color: var(--text); }

.control-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.control-button {
  min-height: 2.75rem;
  padding: 0 0.95rem;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition:
    transform var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}
.control-button:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  transform: translateY(-2px);
  box-shadow: var(--glow-cyan);
}
.control-button:active { transform: translateY(0); }

.control-button--danger:hover {
  border-color: var(--red);
  color: var(--red);
  box-shadow: 0 0 14px rgba(255, 85, 96, 0.4);
}

.control-button:disabled {
  opacity: 0.4;
  transform: none;
  box-shadow: none;
  border-color: var(--line);
  color: var(--dim);
}

/* ---------- layout ---------- */

.app-layout {
  flex: 1;
  width: min(100%, 104rem);
  margin-inline: auto;
  padding: clamp(0.75rem, 2vw, 1.25rem) var(--space-gutter) 1.5rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(0.9rem, 2vw, 1.25rem);
}

.tool-panel,
.board-section,
.truth-panel,
.panel-section { min-width: 0; }

.tool-panel,
.truth-panel {
  display: grid;
  gap: clamp(0.9rem, 2vw, 1.1rem);
  align-content: start;
}

.panel-section,
.truth-panel,
.board-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, var(--surface-2), var(--surface) 70%);
  box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.45);
}

.panel-section,
.truth-panel { padding: clamp(0.9rem, 2vw, 1.15rem); }

.panel-section {
  display: grid;
  gap: 0.7rem;
  position: relative;
}

/* notched corner accent on panels */
.panel-section::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  width: 14px;
  height: 14px;
  border-top: 2px solid var(--line-2);
  border-left: 2px solid var(--line-2);
  border-top-left-radius: var(--radius);
  pointer-events: none;
}

.panel-section--target {
  border-color: rgba(255, 200, 87, 0.28);
  background:
    linear-gradient(180deg, rgba(255, 200, 87, 0.05), transparent 55%),
    linear-gradient(180deg, var(--surface-2), var(--surface) 70%);
}

.panel-heading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--pixel);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text);
}

.panel-heading-mark {
  font-size: 7px;
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
}

.panel-hint {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--dim);
  letter-spacing: 0.02em;
}

.section-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: clamp(0.9rem, 2vw, 1.15rem) clamp(0.9rem, 2vw, 1.15rem) 0;
}

/* ---------- gate palette ---------- */

.gate-palette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.palette-button {
  position: relative;
  min-height: 3rem;
  padding: 0.6rem 0.4rem;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 0.04em;
  user-select: none;
  overflow: hidden;
  transition:
    transform var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}
/* tiny pin marks evoke a chip */
.palette-button::before,
.palette-button::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 5px;
  height: 2px;
  background: var(--line-2);
  transform: translateY(-50%);
  transition: background var(--duration-fast) ease;
}
.palette-button::before { left: 0; }
.palette-button::after { right: 0; }

.palette-button:hover,
.palette-button:focus-visible {
  border-color: var(--cyan);
  color: var(--cyan);
  transform: translateY(-3px);
  box-shadow: var(--glow-cyan);
  cursor: grab;
}
.palette-button:hover::before,
.palette-button:hover::after { background: var(--cyan); }
.palette-button:active { transform: translateY(-1px); cursor: grabbing; }

/* ---------- live readout ---------- */

.live-readout { display: grid; gap: 0.4rem; }

.signal-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.1rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: var(--dim);
  transition: border-color var(--duration-fast) ease, color var(--duration-fast) ease;
}
.signal-row.is-high {
  border-color: rgba(65, 255, 139, 0.4);
  color: var(--text);
}
.signal-row strong {
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
}
.signal-row.is-high strong { color: var(--green); text-shadow: var(--glow-green); }

.signal-lamp {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border: 1px solid var(--line-2);
  border-radius: 50%;
  background: #2a2a3e;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.6);
  transition: background var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
.is-high .signal-lamp,
.signal-lamp.is-high {
  border-color: rgba(65, 255, 139, 0.6);
  background: var(--green);
  box-shadow: 0 0 0.5rem rgba(65, 255, 139, 0.7), inset 0 0 2px rgba(255, 255, 255, 0.5);
}

/* ---------- objective / target ---------- */

.formula-text {
  min-height: 1.4rem;
  font-family: var(--mono);
  font-size: 0.88rem;
  letter-spacing: 0.03em;
  color: var(--gold);
}

.status-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--surface);
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}
.status-pill::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}
.status-pill.is-solved {
  border-color: rgba(65, 255, 139, 0.55);
  color: var(--green);
  box-shadow: var(--glow-green);
}
.status-pill.is-open {
  border-color: rgba(255, 200, 87, 0.5);
  color: var(--gold);
}

.wire-status {
  min-height: 1.3rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  color: var(--dim);
}
.wire-status.is-error { color: var(--red); }
.wire-status.is-good { color: var(--green); }

/* ---------- board ---------- */

.board-section { overflow: hidden; display: flex; flex-direction: column; }

.output-readout {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.3rem 0.85rem;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--dim);
  transition: border-color var(--duration-fast) ease, color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
.output-readout[data-state="high"] {
  border-color: rgba(65, 255, 139, 0.6);
  color: var(--green);
  box-shadow: var(--glow-green);
}

.circuit-board {
  position: relative;
  flex: 1;
  width: calc(100% - 2rem);
  min-height: 30rem;
  margin: clamp(0.75rem, 2vw, 1rem);
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background:
    linear-gradient(var(--grid-fade) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-fade) 1px, transparent 1px),
    radial-gradient(circle at 50% 0%, rgba(69, 240, 255, 0.04), transparent 60%),
    #0c0c16;
  background-size: 1.5rem 1.5rem, 1.5rem 1.5rem, 100% 100%, 100% 100%;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.55);
  touch-action: none;
}

.wire-layer,
.board-nodes,
.gate-layer {
  position: absolute;
  inset: 0;
}

.wire-layer { z-index: 1; width: 100%; height: 100%; }
.board-nodes { z-index: 3; pointer-events: none; }
.gate-layer { z-index: 2; pointer-events: none; }

/* ---------- nodes (inputs / output) ---------- */

.board-node {
  position: absolute;
  width: 9rem;
  min-height: 4.5rem;
  padding: 0.6rem 0.7rem;
  display: grid;
  gap: 0.4rem;
  align-content: center;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  box-shadow: 0 0.4rem 1.2rem rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  transform: translateY(-50%);
  transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
.board-node.is-high {
  border-color: rgba(65, 255, 139, 0.55);
  box-shadow: 0 0.4rem 1.2rem rgba(0, 0, 0, 0.5), 0 0 18px rgba(65, 255, 139, 0.22);
}

.input-node { left: 0.85rem; }
.output-node { right: 0.85rem; }

.output-node.is-high { border-color: rgba(65, 255, 139, 0.7); }

.node-title {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.08em;
  color: var(--cyan);
}
.output-node .node-title { color: var(--magenta); }

.node-signal {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  color: var(--dim);
}
.board-node.is-high .node-signal { color: var(--green); }

/* ---------- input switch ---------- */

.input-switch {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.4rem;
  cursor: pointer;
}

.input-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 2.9rem;
  height: 1.5rem;
  border: 1px solid var(--control-line);
  border-radius: 999px;
  background: #23233a;
  transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 0.15rem;
  left: 0.18rem;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  background: #cfd3e4;
  box-shadow: 0 0.1rem 0.2rem rgba(0, 0, 0, 0.5);
  transition: transform var(--duration-fast) var(--ease-out), background var(--duration-fast) ease;
}
.input-toggle:checked + .switch-track {
  border-color: rgba(65, 255, 139, 0.7);
  background: rgba(65, 255, 139, 0.22);
  box-shadow: 0 0 12px rgba(65, 255, 139, 0.4);
}
.input-toggle:checked + .switch-track::after {
  transform: translateX(1.35rem);
  background: var(--green);
}
.input-toggle:focus-visible + .switch-track {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

/* ---------- gates ---------- */

.gate-node {
  position: absolute;
  display: grid;
  grid-template-columns: 2.4rem 1fr 2.4rem;
  align-items: center;
  gap: 0.3rem;
  width: 10rem;
  height: 6.6rem;
  padding: 0.4rem;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, var(--surface-2), #15151f);
  box-shadow: 0 0.5rem 1.4rem rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  cursor: grab;
  user-select: none;
  transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
.gate-node:active { cursor: grabbing; }

.gate-node.is-selected {
  border-color: var(--cyan);
  box-shadow: 0 0.5rem 1.4rem rgba(0, 0, 0, 0.55), 0 0 0 1px var(--cyan), var(--glow-cyan);
}

.gate-label {
  display: grid;
  gap: 0.25rem;
  justify-items: center;
  text-align: center;
}

.gate-name {
  font-family: var(--pixel);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--text);
}

.gate-value {
  display: inline-grid;
  place-items: center;
  min-width: 1.5rem;
  padding: 0.1rem 0.3rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--dim);
}

/* per-gate accent on the name */
.gate-and .gate-name { color: var(--cyan); }
.gate-or .gate-name { color: var(--green); }
.gate-not .gate-name { color: var(--magenta); }
.gate-xor .gate-name { color: var(--gold); }
.gate-nand .gate-name { color: #c79bff; }
.gate-xnor .gate-name { color: #ff9d57; }

.gate-port-column {
  display: grid;
  gap: 0.3rem;
  align-content: center;
  justify-items: center;
}

/* ---------- ports ---------- */

.port-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  min-width: 2.4rem;
  min-height: 2.4rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  padding: 0;
}
/* outer ring */
.port-button::before {
  content: "";
  position: absolute;
  width: 1.05rem;
  height: 1.05rem;
  border: 2px solid var(--control-line);
  border-radius: 50%;
  background: #16161f;
  transition: border-color var(--duration-fast) ease, background var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}
/* inner dot */
.port-button::after {
  content: "";
  position: absolute;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--wire-low);
  transition: background var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.port-out { cursor: crosshair; }
.gate-node .port-button.port-in { cursor: pointer; }

.port-button:hover::before { border-color: var(--cyan); box-shadow: 0 0 8px rgba(69, 240, 255, 0.5); }
.port-button:hover::after { background: var(--cyan); }

.port-button.is-connected::before { border-color: var(--cyan); }

.port-button.is-high::before {
  border-color: rgba(65, 255, 139, 0.7);
  background: rgba(65, 255, 139, 0.12);
}
.port-button.is-high::after {
  background: var(--wire-high);
  box-shadow: 0 0 0.5rem rgba(65, 255, 139, 0.8);
}

.board-node .port-out {
  position: absolute;
  top: 50%;
  right: -1.3rem;
  transform: translateY(-50%);
}
.board-node .port-in {
  position: absolute;
  top: 50%;
  left: -1.3rem;
  transform: translateY(-50%);
}

/* ---------- wires ---------- */

.wire-visible,
.wire-hit { fill: none; }

.wire-visible {
  stroke: var(--wire-low);
  stroke-linecap: round;
  stroke-width: 3.5;
  transition: stroke 120ms ease;
}
.wire-visible.is-high {
  stroke: var(--wire-high);
  filter: drop-shadow(0 0 4px rgba(65, 255, 139, 0.65));
}
.wire-visible.is-selected {
  stroke: var(--cyan);
  filter: drop-shadow(0 0 5px rgba(69, 240, 255, 0.7));
}
.wire-visible.is-preview {
  stroke: var(--gold);
  stroke-dasharray: 6 7;
  filter: drop-shadow(0 0 4px rgba(255, 200, 87, 0.55));
}

.wire-hit {
  cursor: pointer;
  pointer-events: stroke;
  stroke: rgba(0, 0, 0, 0);
  stroke-linecap: round;
  stroke-width: 18;
}

/* ---------- truth table ---------- */

.truth-panel { overflow: hidden; padding-bottom: clamp(0.9rem, 2vw, 1.15rem); }

.truth-summary {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.06em;
  color: var(--gold);
}

.truth-table-wrap {
  width: 100%;
  overflow-x: auto;
  padding: 0.85rem clamp(0.9rem, 2vw, 1.15rem) 0;
}

.truth-table {
  width: 100%;
  min-width: 15rem;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.82rem;
}

.truth-table th,
.truth-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.5rem 0.45rem;
  text-align: center;
}

.truth-table thead th {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.04em;
  color: var(--cyan);
  border-bottom-color: var(--line-2);
}

.truth-table td { font-weight: 700; color: var(--dim); }

.truth-table tbody tr { transition: background 120ms ease; }
.truth-table tbody tr.is-pass {
  background: linear-gradient(90deg, rgba(65, 255, 139, 0.1), transparent);
}
.truth-table tbody tr.is-pass td { color: var(--text); }
.truth-table tbody tr.is-pass td:last-child { color: var(--green); }
.truth-table tbody tr.is-fail {
  background: linear-gradient(90deg, rgba(255, 85, 96, 0.1), transparent);
}
.truth-table tbody tr.is-fail td:last-child { color: var(--red); }

/* ---------- footer ---------- */

.app-footer {
  width: min(100%, 104rem);
  margin-inline: auto;
  padding: 0.5rem var(--space-gutter) 2rem;
  display: grid;
  gap: 0.6rem;
  text-align: center;
  color: var(--dim);
  font-size: 0.8rem;
}

.app-footer p { overflow-wrap: anywhere; }

.footer-flavor {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.12em;
  line-height: 1.9;
  color: var(--gold);
}

/* ---------- utility ---------- */

.is-hidden { display: none !important; }

/* ---------- responsive ---------- */

@media (max-width: 600px) {
  .top-controls { width: 100%; }
  .field { flex: 1 1 9rem; }
  .select-input { min-width: 0; width: 100%; }
  .control-cluster { width: 100%; }
  .control-button { flex: 1 1 7rem; justify-content: center; text-align: center; }
  .board-node { width: 7.6rem; }
  .gate-node { width: 9rem; }
  .wordmark { text-shadow: 0 0 14px rgba(69, 240, 255, 0.5), 2px 2px 0 var(--magenta); }
}

@media (min-width: 768px) {
  .gate-palette { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .circuit-board { min-height: 33rem; }
}

@media (min-width: 1024px) {
  .app-layout {
    grid-template-columns: minmax(15rem, 18rem) minmax(0, 1fr) minmax(17rem, 23rem);
    align-items: start;
  }
  .gate-palette { grid-template-columns: 1fr; }
}

@media (min-width: 1400px) {
  .gate-palette { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .wordmark-cursor { animation: none; }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
