:root {
  --bg: #0b1014;
  --bg-2: #10181f;
  --panel: #141c24;
  --line: #24313c;
  --text: #e7eef3;
  --muted: #8a9aa8;
  --accent: #2dd4bf;
  --accent-2: #22d3ee;
  --danger: #fb7185;
  --warn: #fbbf24;
  --ok: #4ade80;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "DM Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-rows: auto 1fr 220px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #151e26, #10171d);
  min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 280px; }
.mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: #134e4a; color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
}
.eyebrow { margin: 0; font-size: 9px; letter-spacing: 0.18em; color: var(--accent); }
.brand h1 { margin: 0; font-size: 16px; letter-spacing: 0.04em; }
.sub { color: var(--muted); font-size: 12px; }
.ver { color: #5b6b78; font-size: 11px; }

.transport, .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.transport { flex: 1; }
.transport label {
  font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px;
}
select, input, textarea, button {
  font-family: inherit; color: var(--text);
}
select, input[type="number"], input[type="text"], input[type="search"] {
  background: #0d141a; border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font-size: 12px;
}
.btn {
  background: #1b2731; border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 10px; font-size: 12px; cursor: pointer;
}
.btn:hover { border-color: #3b5162; }
.btn.primary { background: #115e59; border-color: #0f766e; }
.btn.accent { background: #0e3a4a; border-color: #155e75; color: var(--accent-2); }
.btn.danger { background: #3f1d24; border-color: #7f1d1d; color: var(--danger); }
.btn.ghost { background: transparent; }
.sim-readout {
  font-family: var(--mono); font-size: 12px; color: var(--accent-2);
  display: flex; gap: 12px; margin-left: 8px;
}

.workspace {
  display: grid;
  grid-template-columns: 220px 1fr 260px;
  min-height: 0;
}
.palette, .inspector-col {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px;
  overflow: auto;
}
.inspector-col { border-right: 0; border-left: 1px solid var(--line); }
.palette h2, .inspector-col h2 {
  margin: 0 0 8px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}
.hint, .muted, .keys { color: var(--muted); font-size: 11px; line-height: 1.45; }
.palette-list h3 {
  margin: 14px 0 6px; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: #6d7f8c;
}
.pal-item {
  display: block; width: 100%; text-align: left;
  background: #0f171e; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 9px; margin-bottom: 6px; cursor: grab;
}
.pal-item strong { display: block; font-size: 12px; }
.pal-item span { display: block; font-size: 10px; color: var(--muted); margin-top: 2px; }
.pal-item.cat-source { border-left: 3px solid #22d3ee; }
.pal-item.cat-math { border-left: 3px solid #fbbf24; }
.pal-item.cat-logic { border-left: 3px solid #4ade80; }
.pal-item.cat-custom { border-left: 3px solid #c084fc; }
.pal-item.cat-sink { border-left: 3px solid #fb7185; }

.canvas-col { min-width: 0; min-height: 0; }
.canvas-wrap {
  height: 100%;
  overflow: scroll;
  scrollbar-gutter: stable;
  position: relative;
  background: var(--bg-2);
  cursor: default;
  scrollbar-color: #3a5162 #0a1218;
  scrollbar-width: auto;
}
.canvas-wrap.can-pan, .canvas-wrap.panning { cursor: grab; }
.canvas-sizer {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}
.canvas-stage {
  position: absolute;
  left: 0; top: 0;
  width: 4000px; height: 3000px;
  transform-origin: 0 0;
  background:
    linear-gradient(90deg, rgba(36, 49, 60, 0.45) 1px, transparent 1px),
    linear-gradient(rgba(36, 49, 60, 0.45) 1px, transparent 1px),
    var(--bg-2);
  background-size: 20px 20px;
}
.canvas-wrap::-webkit-scrollbar { width: 12px; height: 12px; }
.canvas-wrap::-webkit-scrollbar-track { background: #0a1218; }
.canvas-wrap::-webkit-scrollbar-thumb {
  background: #3a5162;
  border: 2px solid #0a1218;
  border-radius: 8px;
}
.canvas-wrap::-webkit-scrollbar-thumb:hover { background: #547086; }
.canvas-wrap::-webkit-scrollbar-corner { background: #0a1218; }
.wires {
  position: absolute; inset: 0;
  width: 4000px; height: 3000px;
  overflow: visible;
  pointer-events: none;
}
.wires path.wire {
  fill: none; stroke-width: 2.2; pointer-events: none;
}
.wires path.wire.selected { stroke-width: 3.2; filter: drop-shadow(0 0 4px currentColor); }
.wires path.wire.draft { stroke-dasharray: 6 4; }
.wires path.wire.converted { stroke-dasharray: 7 4; stroke-width: 2.4; }
.wires path.wire.stepped { stroke-width: 3; filter: drop-shadow(0 0 3px #fbbf24); }
.wires text.wire-cast {
  fill: #fbbf24; font-size: 10px; font-family: "IBM Plex Mono", monospace;
  pointer-events: none;
}
.wires path.wire-hit {
  fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer;
}
.nodes-layer { position: absolute; inset: 0; }

.vnode {
  position: absolute;
  width: 168px;
  background: #18222b;
  border: 1px solid #2b3c4a;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.28);
  user-select: none;
}
.vnode.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.vnode.step-fired {
  border-color: #fbbf24;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.55), 0 0 18px rgba(251, 191, 36, 0.25);
  background: #241c10;
}
.vnode.cat-source { border-top: 3px solid #22d3ee; }
.vnode.cat-math { border-top: 3px solid #fbbf24; }
.vnode.cat-logic { border-top: 3px solid #4ade80; }
.vnode.cat-custom { border-top: 3px solid #c084fc; }
.vnode.cat-sink { border-top: 3px solid #fb7185; }
.vnode-head {
  padding: 7px 10px 4px; cursor: grab;
}
.vnode-kind {
  display: block; font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: #7d8f9c;
}
.vnode-head strong { font-size: 13px; }
.vnode-body { display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px 6px; }
.pins { display: flex; flex-direction: column; gap: 4px; }
.pin {
  display: flex; align-items: center; gap: 5px; font-size: 10px; color: #b7c4ce; cursor: crosshair;
}
.pin.out { flex-direction: row-reverse; }
.pin i {
  width: 10px; height: 10px; border-radius: 50%;
  box-shadow: 0 0 0 2px #0b1014; display: inline-block;
}
.pin.ok i { box-shadow: 0 0 0 2px var(--ok); }
.pin.bad i { box-shadow: 0 0 0 2px var(--danger); opacity: 0.45; }
.vnode-foot {
  min-height: 16px; padding: 0 10px 7px;
  font-family: var(--mono); font-size: 10px; color: var(--accent-2);
  white-space: pre-wrap;
}
.vnode-foot.err { color: var(--danger); }
.vnode-foot.warn { color: var(--warn); }

.inspector-col .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 12px; }
.inspector-col textarea {
  background: #0d141a; border: 1px solid var(--line); border-radius: 6px;
  padding: 8px; font-family: var(--mono); font-size: 11px; resize: vertical; min-height: 140px;
}
.insp-meta { font-size: 11px; color: var(--muted); }
.lint-box {
  margin: 6px 0 0; padding: 8px;
  border-radius: 6px; font-family: var(--mono); font-size: 10px;
  white-space: pre-wrap; line-height: 1.4; color: var(--muted);
  border: 1px solid var(--line); background: #0d141a;
}
.lint-box.ok { color: #86efac; border-color: #14532d; }
.lint-box.bad { color: #fecaca; border-color: #7f1d1d; background: #2a1214; }
.lint-box.warn { color: #fde68a; border-color: #854d0e; background: #1c1508; }
.sig-block { margin: 12px 0; padding-top: 8px; border-top: 1px solid var(--line); }
.sig-block h3 {
  margin: 0 0 8px; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}
.err { color: var(--danger); }
.warn { color: var(--warn); }

.bottom {
  border-top: 1px solid var(--line);
  background: #0d141a;
  display: grid;
  grid-template-rows: 32px 1fr;
  min-height: 0;
}
.bottom-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); }
.tab {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 8px 14px; font-size: 12px; cursor: pointer;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.scope-pane, .console-pane { min-height: 0; height: 100%; }
.scope-pane { position: relative; }
.scope-pane canvas { display: block; width: 100%; height: 100%; min-height: 140px; }
.console-pane { overflow: auto; }
#consoleOut {
  margin: 0; padding: 10px 14px;
  font-family: var(--mono); font-size: 11px; color: #c5d0d8; white-space: pre;
}

.wire-tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: #0f1720; border: 1px solid #334155; border-radius: 8px;
  padding: 8px 10px; min-width: 180px; font-size: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.tip-row { display: flex; justify-content: space-between; gap: 12px; margin: 2px 0; }
.tip-row span { color: var(--muted); }
.tip-meta { font-size: 11px; color: #e2e8f0; margin-bottom: 6px; max-width: 320px; line-height: 1.35; }
.tip-conv { margin-top: 6px; color: #fbbf24; font-size: 11px; max-width: 320px; }

.transport.step-mode {
  box-shadow: inset 0 -2px 0 #fbbf24;
}
.btn.step-hot { border-color: #fbbf24; color: #fde68a; background: #3a2a0a; }

#toastHost { position: fixed; right: 16px; top: 64px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1e293b; border: 1px solid #334155; border-radius: 8px;
  padding: 8px 12px; font-size: 12px; max-width: 360px;
}
.toast.success { border-color: #0f766e; }
.toast.error { border-color: #9f1239; color: #fecdd3; }

kbd {
  font-family: var(--mono); font-size: 10px;
  background: #0d141a; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 4px;
}

.sample-pick {
  font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px;
}

.modal {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(4, 8, 12, 0.62);
  display: grid; place-items: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(640px, 100%);
  background: #151e26; border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 18px 14px; box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.modal-card h2 { margin: 0 0 8px; font-size: 16px; }
.modal-card textarea {
  width: 100%; margin: 10px 0 6px;
  background: #0d141a; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; font-family: var(--mono); font-size: 11px; color: var(--text);
  resize: vertical;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 180px 1fr 220px; }
  .sub { display: none; }
}
