/* ================= Weft — dark, sleek, parametric ================= */

:root {
  /* design tokens — locked in Figma 2026-07-13 (docs/DESIGN.md) */
  --dark-100: #0a0d13;
  --dark-150: #121724;
  --dark-200: #151b29;
  --dark-300: #1e2533;
  --dark-400: #232b3c;
  --white-100: #ffffff;
  --white-80: rgba(255, 255, 255, 0.8);
  --white-40: rgba(255, 255, 255, 0.4);
  --primary: #2dd4bf;
  --eye-on: #14c50e;
  /* wire-type colours surfaced as tokens (must match TYPE_COLORS in nodes.js) —
   * value widgets wear the colour of the type they output */
  --type-number: #3e9aff;
  --type-bool: #ff3b41;
  --font-ui: "Neue Kabel", Inter, "Segoe UI", system-ui, sans-serif;
  --font-val: Consolas, ui-monospace, "Cascadia Mono", monospace;

  /* app chrome (pre-design tokens, mapped where the design reaches) */
  --bg: var(--dark-100);
  --panel: #10151f;
  --panel2: #151b28;
  --line: var(--dark-400);
  --line2: #2c3550;
  --text: #dbe2ee;
  --dim: #828da3;
  --faint: #5a6478;
  --accent: var(--primary);
  --accent-dim: var(--primary);
  --danger: #ff3b41;
  --palette-w: 208px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 13px/1.45 var(--font-ui);
  overflow: hidden;
}

body { display: flex; flex-direction: column; }

button, input, select, textarea { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #263048; border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }

/* ================= toolbar ================= */

#toolbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 48px; padding: 0 14px;
  background: linear-gradient(180deg, #121826, #0e1420);
  border-bottom: 1px solid var(--line);
  flex: none; z-index: 20;
}

.brand {
  display: flex; align-items: center;
  font-weight: 800; font-size: 16px; letter-spacing: 0.35em;
  background: linear-gradient(90deg, #5eead4, #818cf8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  user-select: none;
}
.brand-mark { width: 24px; height: 24px; flex: none; margin-right: 10px; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand span {
  margin-left: 14px; font-weight: 400; font-size: 11px; letter-spacing: 0.02em;
  color: var(--faint); -webkit-text-fill-color: var(--faint);
}

.tools { display: flex; gap: 8px; align-items: center; }

.tools button, .tools select {
  background: var(--panel2); border: 1px solid var(--line2);
  border-radius: 7px; padding: 5px 13px; cursor: pointer;
  color: var(--text); transition: border-color .15s, background .15s;
}
.tools button:hover, .tools select:hover { border-color: var(--accent-dim); background: #1a2233; }

.tools button.accent {
  background: linear-gradient(135deg, #134e4a, #115e59);
  border-color: var(--accent-dim); color: var(--accent); font-weight: 600;
}
.tools button.accent:hover { background: linear-gradient(135deg, #115e59, #0f766e); }

/* global nav — brand + tagline, then About · Nodes · Loom; loom tools stay right */
.nav-links { display: flex; gap: 2px; margin-left: 18px; margin-right: auto; }
.nav-links a {
  padding: 5px 10px; font-size: 12px; border-radius: 7px;
  color: var(--dim); text-decoration: none;
  transition: color .15s, background .15s;
}
.nav-links a:hover { color: var(--accent); background: #1a2233; }
.nav-links a.here { color: var(--text); background: var(--panel2); }

/* ================= layout ================= */

main { display: flex; flex: 1; min-height: 0; position: relative; }

/* merged view — one canvas: the cloth fills the stage, the loom floats on top.
 * #editor gets z-index 1 (its own stacking context); the cloth's interactive
 * layers (#domLayer, #viewHud) ride above it at z-index 2 so buttons stay live. */
main.merged #splitter { display: none; }
main.merged #editor { z-index: 1; background: none; }
main.merged #preview {
  position: absolute; top: 0; bottom: 0; right: 0; left: var(--palette-w);
  min-width: 0;
}
main.merged #domLayer { z-index: 2; }
main.merged #viewHud { z-index: 2; top: 50px; right: 12px; } /* below the loom tools — no overlap */

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

#palette {
  width: var(--palette-w); flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line);
}

#paletteSearch {
  margin: 10px; padding: 6px 10px;
  background: var(--bg); border: 1px solid var(--line2); border-radius: 7px;
  outline: none;
}
#paletteSearch:focus { border-color: var(--accent-dim); }

#paletteList { flex: 1; overflow-y: auto; padding: 0 8px 20px; }

.pal-cat {
  margin: 12px 4px 4px; font-size: 10px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--c, var(--dim));
}

.pal-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 6px; cursor: pointer;
  color: #b9c2d4; user-select: none;
}
.pal-item:hover { background: #1b2334; color: var(--text); }
.pal-item { touch-action: none; }
.pal-gap { height: 7px; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* node glyph in the palette + quick-add (falls back to .dot when a def has none) */
.pal-icon {
  width: 16px; height: 16px; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.pal-icon svg { width: 100%; height: 100%; display: block; }
.pal-icon .icon-swatch { width: 14px; height: 14px; }

/* ---------------- editor ---------------- */

#editor {
  flex: 1; position: relative; overflow: hidden; min-width: 200px;
  background-color: var(--bg);
  background-image: radial-gradient(circle, #1b2334 1px, transparent 1.4px);
  background-size: 26px 26px;
  cursor: default;
}
#editor.panning { cursor: grabbing; }

#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

#wires { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }

.wire { fill: none; stroke-width: 2; opacity: 0.9; }
.wire.selected { stroke: var(--accent) !important; stroke-width: 3; filter: drop-shadow(0 0 4px rgba(94, 234, 212, 0.6)); }
.wire.temp { stroke-dasharray: 6 5; opacity: 0.8; }
/* dead branch: reaches no sink (and no inspector) — a whisper, not an alarm.
 * Deliberately NOT the .disabled look: bypass and dead-end are different facts. */
.wire.dead { filter: saturate(0.25); opacity: 0.4; }

/* colour picker popover — hand-rolled, one for every colour in the app */
.cp {
  position: fixed; z-index: 80; width: 196px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 9px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55); padding: 9px;
}
.cp-sv { position: relative; height: 128px; border-radius: 6px; cursor: crosshair; touch-action: none; }
.cp-dot {
  position: absolute; width: 11px; height: 11px; margin: -5.5px;
  border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55); pointer-events: none;
}
.cp-hue, .cp-alpha { position: relative; height: 12px; border-radius: 6px; cursor: ew-resize; touch-action: none; }
.cp-hue {
  background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
.cp-alpha {
  background:
    linear-gradient(90deg, transparent, var(--cp, #fff)),
    repeating-conic-gradient(rgba(255, 255, 255, 0.22) 0% 25%, transparent 0% 50%) 0 0 / 10px 10px;
}
.cp-pin {
  position: absolute; top: -2px; bottom: -2px; width: 4px; margin-left: -2px;
  border-radius: 2px; background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55); pointer-events: none;
}
.cp-row { display: flex; gap: 6px; }
.cp-hex {
  flex: 1; min-width: 0; padding: 3px 6px;
  background: var(--dark-150); border: 1px solid var(--dark-400); border-radius: 5px;
  color: var(--text); font: 11px var(--font-val); outline: none;
}
.cp-a {
  width: 46px; padding: 3px 4px;
  background: var(--dark-150); border: 1px solid var(--dark-400); border-radius: 5px;
  color: var(--text); font: 11px var(--font-val); outline: none;
}
.cp-recent { display: flex; gap: 5px; min-height: 0; }
.cp-recent:empty { display: none; }
.cp-chip {
  width: 16px; height: 16px; border-radius: 50%; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.cp-chip:hover { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5); }

/* colour port literal: a chip that opens the picker */
.lit-swatch {
  display: inline-block; width: 15px; height: 15px; border-radius: 50%;
  cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}
.lit-swatch:hover { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6); }

/* settings popover (⚙ in loom tools) */
#settingsPop {
  position: absolute; top: 46px; right: 12px; z-index: 30;
  display: flex; flex-direction: column; gap: 2px; min-width: 172px;
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 9px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55); padding: 7px;
}
.set-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 7px; border-radius: 6px; cursor: pointer;
  font: 11.5px var(--font-ui); color: var(--text);
}
.set-row:hover { background: var(--dark-150); }

/* ---------------- canvas annotations (graph format 2) ---------------- */

/* sticky note — text on the canvas itself; never evaluated, never exported */
.cnote {
  position: absolute; left: 0; top: 0;
  background: color-mix(in srgb, #c9a86a 9%, var(--panel2));
  border: 1px solid color-mix(in srgb, #c9a86a 28%, transparent);
  border-radius: 7px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  cursor: grab;
}
.cnote.editing { cursor: auto; border-color: color-mix(in srgb, #c9a86a 55%, transparent); }
.cnote.selected {
  outline: 1px solid var(--accent); outline-offset: 2px;
  box-shadow: 0 0 7.5px rgba(94, 234, 212, 0.33), 0 6px 18px rgba(0, 0, 0, 0.3);
}
.cnote textarea {
  width: 100%; height: 100%; resize: none;
  background: none; border: none; outline: none;
  padding: 9px 11px;
  font: 12.5px/1.5 var(--font-ui);
  color: color-mix(in srgb, #e8d5ac 75%, var(--text));
  pointer-events: none; /* click the note once to start editing */
}
.cnote textarea::placeholder { color: var(--faint); }
.cnote-grip {
  position: absolute; right: 0; bottom: 0; width: 14px; height: 14px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 50%, color-mix(in srgb, #c9a86a 40%, transparent) 50%);
  border-radius: 0 0 6px 0;
}

/* group frame — a label drawn around nodes that stay where they are;
 * a cluster changes evaluation, a group changes only reading */
.gframe {
  position: absolute; left: 0; top: 0;
  border: 1px solid var(--line2);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.02);
  pointer-events: none; /* the interior is canvas — only the bar is solid */
}
.gframe.folded {
  height: auto;
  background: var(--panel2);
  border-style: solid;
}
.gframe-bar {
  pointer-events: auto;
  display: flex; align-items: center; gap: 7px;
  height: 26px; padding: 0 9px;
  border-bottom: 1px solid var(--line);
  border-radius: 9px 9px 0 0;
  background: color-mix(in srgb, var(--panel2) 82%, transparent);
  color: var(--dim);
  font: 600 11.5px/1 var(--font-ui);
  letter-spacing: 0.02em;
  cursor: grab;
  user-select: none;
}
.gframe.folded .gframe-bar { border-bottom: none; border-radius: 9px; }
.gf-fold { cursor: pointer; color: var(--faint); font-size: 10px; }
.gf-fold:hover { color: var(--text); }
.gf-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gf-title[contenteditable="true"] { outline: none; color: var(--text); }
.gf-x { cursor: pointer; color: var(--faint); font-size: 13px; }
.gf-x:hover { color: var(--danger); }
.wire.hover { stroke-width: 3.5; opacity: 1; filter: brightness(1.3); }
.wire-hit { fill: none; stroke: transparent; stroke-width: 22; pointer-events: stroke; cursor: pointer; }

#nodes { position: absolute; left: 0; top: 0; }

/* ---------------- nodes (card design: Figma, 2026-07-13) ---------------- */

.node {
  position: absolute; left: 0; top: 0; min-width: 150px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--cat, #6b7891) 40%, transparent) 0%, rgba(20, 26, 40, 0) 50%),
    var(--dark-200);
  border: 1px solid var(--dark-300); border-radius: 13px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
  font-size: 12px; user-select: none;
}
.node.selected {
  border-color: var(--primary);
  box-shadow: 0 0 7.5px rgba(94, 234, 212, 0.33), 0 10px 26px rgba(0, 0, 0, 0.5);
}
.node.error {
  border-color: var(--danger);
  box-shadow: 0 0 7.5px rgba(255, 59, 65, 0.4), 0 10px 26px rgba(0, 0, 0, 0.5);
}

.node-head {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 9px 5px 5px; font-weight: 500; letter-spacing: 0.01em;
  border-bottom: 1px solid var(--dark-300);
  border-radius: 12px 12px 0 0;
  cursor: grab;
}
.node-head:active { cursor: grabbing; }
.node-head .title { white-space: nowrap; font-size: 15px; color: var(--white-100); }
.node-head .head-gap { flex: 1; min-width: 4px; }

.node-head .icon {
  width: 27px; height: 27px; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--cat, var(--dim));
}
.node-head .icon svg { width: 100%; height: 100%; display: block; }
.node-head .icon .dot { background: var(--cat, var(--dim)); }

.node-rows {
  padding: 8px 0 5px;
  background: rgba(21, 27, 41, 0.7);
  border-radius: 0 0 12px 12px;
}
.node.bare .node-rows { background: none; }

/* inputs left, outputs right — outputs settle to the card's bottom edge */
.node-cols { display: flex; align-items: stretch; }
.col-ins { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.col-outs {
  display: flex; flex-direction: column; gap: 4px;
  justify-content: flex-end; align-items: flex-end;
  margin-left: auto;
}

.row {
  position: relative; display: flex; align-items: center; gap: 4px;
  min-height: 19px;
}
.row.in { padding: 0 8px 0 11px; }
.row.out { padding: 0 11px 0 8px; justify-content: flex-end; }
.row .label { color: var(--white-100); font-size: 12px; min-width: 14px; }
.row.out .label { text-align: right; }

/* dim live readout beside each output */
.row.out .rd {
  color: var(--white-40); font: 11px var(--font-val);
  max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-align: right;
}

.port {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--t, #999); border: 2px solid var(--bg);
  cursor: crosshair; z-index: 2;
}
.row.in .port { left: -7px; }
.row.out .port { right: -7px; }
.port:hover, .port.hot { box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.35), 0 0 10px var(--t); }

/* literal editors — 42px value fields */
.lit { display: flex; gap: 4px; align-items: center; margin-left: auto; }
.row.connected .lit { display: none; }

.lit input[type="number"], .lit input[type="text"] {
  width: 42px; padding: 1px 4px;
  background: var(--dark-150); border: 1px solid var(--dark-400); border-radius: 3px;
  color: var(--white-80); font: 11px var(--font-val); outline: none;
}
.lit input[type="text"] { width: 56px; }
.lit input.pt { width: 42px; }
/* point3 literals fit three components in the two-field slot */
.lit input.pt3 { width: 29px; }
.lit input.alpha { width: 36px; }
.lit input:focus { border-color: var(--accent-dim); }
.lit input[type="color"] {
  width: 26px; height: 17px; padding: 0; border: 1px solid var(--dark-400);
  border-radius: 3px; background: none; cursor: pointer;
}
/* checkboxes are drawn, not native: a quiet rounded square that fills with its
 * context colour when checked — bool literals wear the bool wire colour,
 * settings wear the accent */
.lit input[type="checkbox"], .set-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  width: 15px; height: 15px; cursor: pointer; position: relative;
  border: 1px solid var(--dark-400); border-radius: 4px; background: var(--dark-150);
  transition: background 0.12s, border-color 0.12s;
}
.lit input[type="checkbox"]:hover, .set-row input[type="checkbox"]:hover { border-color: var(--white-40); }
.lit input[type="checkbox"]::after, .set-row input[type="checkbox"]::after {
  content: ''; position: absolute; left: 3.5px; top: 3.5px; width: 7px; height: 4px;
  border-left: 1.5px solid var(--bg); border-bottom: 1.5px solid var(--bg);
  transform: rotate(-45deg); opacity: 0;
}
.lit input[type="checkbox"]:checked { background: var(--type-bool); border-color: var(--type-bool); }
.set-row input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.lit input[type="checkbox"]:checked::after, .set-row input[type="checkbox"]:checked::after { opacity: 1; }

/* hide number input spinners inside nodes */
.node input[type="number"]::-webkit-outer-spin-button,
.node input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* custom bodies */
.node-body { padding: 4px 12px 2px; }

/* --- Number Slider "Hairline" (design doc 1a, 2026-08-09) ---
 * the number is the widget: big mono value, 2px rule + ticks, faint end marks.
 * The widget wears the wire colour of its output type (number). */
/* border-radius here rounds the selection outline too (outlines follow it) */
.sl { width: 100%; padding: 3px 11px 4px; position: relative; border-radius: 8px; }
.sl-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 0 2px; }
.sl-label {
  min-height: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--white-40); font: 10px var(--font-ui); letter-spacing: 0.14em; text-transform: uppercase;
}
.sl-val {
  flex: 1; min-width: 0; text-align: right;
  background: transparent; border: 1px solid transparent; border-radius: 3px;
  color: var(--type-number); font: 18px/1 var(--font-val); letter-spacing: -0.02em;
  outline: none;
}
.sl-track { position: relative; margin-top: 8px; height: 16px; display: flex; align-items: center; cursor: ew-resize; touch-action: none; }
.sl-rule { position: relative; width: 100%; height: 2px; border-radius: 1px; background: var(--dark-400); }
/* ticks are value-aligned, painted by the node (--tkg/--tko minor gap/offset,
 * --tkG/--tkO major) — a 1px line at the left edge of a tile, repeated */
.sl-rule::before {  /* minor ticks, hanging under the rule */
  content: ''; position: absolute; left: 0; right: 0; top: 3px; height: 4px;
  background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.20) 0 1px, transparent 1px);
  background-size: var(--tkg, 10px) 100%; background-position: var(--tko, 0px) 0;
}
.sl-rule::after {   /* major ticks */
  content: ''; position: absolute; left: 0; right: 0; top: 3px; height: 7px;
  background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.34) 0 1px, transparent 1px);
  background-size: var(--tkG, 50px) 100%; background-position: var(--tkO, 0px) 0;
}
.sl-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 1px; background: var(--type-number); }
.sl-zero { position: absolute; top: -3px; width: 1px; height: 9px; background: rgba(255, 255, 255, 0.55); }
.sl-zero::after {
  content: attr(data-n); position: absolute; top: 9px; left: -2px;
  font: 8px var(--font-val); color: rgba(255, 255, 255, 0.38);
}
.sl-thumb {
  position: absolute; top: 50%; width: 9px; height: 9px; margin-left: -4.5px;
  transform: translateY(-50%); border-radius: 50%;
  background: var(--type-number); box-shadow: 0 0 8px rgba(62, 154, 255, 0.7);
}
.sl-ends { display: flex; justify-content: space-between; margin-top: 7px; padding: 0 2px; }
.sl-ends input {
  width: 52px; padding: 0 2px; background: transparent; border: 1px solid transparent;
  border-radius: 3px; color: rgba(255, 255, 255, 0.22); font: 9px var(--font-val); outline: none;
}
.sl-ends input:last-child { text-align: right; }
.sl-ends input:hover, .sl-ends input:focus { border-color: var(--dark-400); background: var(--dark-150); color: var(--white-80); }

/* selected sliders resize from either edge (1a spec: 140–300px) — one pill per
 * side, riding ON the selection outline so it doesn't read as a second line */
.sl-grip-l, .sl-grip-r { position: absolute; top: 0; bottom: 0; width: 11px; display: none; cursor: ew-resize; z-index: 3; }
.sl-grip-l { left: -9px; }
.sl-grip-r { right: -9px; }
.node.selected .sl-grip-l, .node.selected .sl-grip-r { display: block; }
.node.selected .sl-grip-l::after, .node.selected .sl-grip-r::after {
  content: ''; position: absolute; top: calc(50% - 15px); width: 3px; height: 14px;
  border-radius: 2px; background: var(--accent);
}
.sl-grip-l::after { left: 4px; }
.sl-grip-r::after { right: 4px; }

/* the slider's output dot leaves the card's vertical centre and sits level
 * with the hairline itself, clear of the track's end */
.node.bare:has(.sl) .col-outs { justify-content: flex-start; }
.node.bare:has(.sl) .col-outs .row.out { margin-top: 36px; }

/* slider options popover (double-click): label, rounding mode, precision */
.sl-opts {
  position: absolute; left: -2px; right: -2px; top: calc(100% + 6px); z-index: 30;
  display: flex; flex-direction: column; gap: 5px;
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 9px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55); padding: 8px;
}
.sl-opt-row { display: flex; align-items: center; gap: 7px; }
.sl-opt-cap { flex: none; width: 52px; font-size: 10px; color: var(--dim); }
.sl-opt-row input { flex: 1; min-width: 0; }
.sl-val:hover, .sl-val:focus { border-color: var(--dark-400); background: var(--dark-150); }

/* --- Knob / Angle: rotary dials in the number wire colour --- */
.kn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 10px 8px; border-radius: 8px; }
.kn-label { text-align: center; align-self: stretch; }
.dial { width: 64px; height: 64px; flex: none; touch-action: none; cursor: crosshair; overflow: visible; }
.dial-track { fill: none; stroke: var(--dark-400); stroke-width: 2; stroke-linecap: round; }
.dial-fill { fill: none; stroke: var(--type-number); stroke-width: 2; stroke-linecap: round; }
.dial-ind { fill: var(--type-number); filter: drop-shadow(0 0 4px rgba(62, 154, 255, 0.7)); }
.dial-tick { stroke: rgba(255, 255, 255, 0.30); stroke-width: 1; }
.dial-needle { stroke: var(--type-number); stroke-width: 2; stroke-linecap: round; filter: drop-shadow(0 0 4px rgba(62, 154, 255, 0.5)); }
.dial-hub { fill: var(--type-number); }
.node-body input.sl-val.kn-val { width: 100%; flex: none; text-align: center; font-size: 15px; }
.an-foot { display: flex; align-items: baseline; justify-content: center; }
.node-body input.sl-val.an-val { width: 46px; flex: none; text-align: right; font-size: 15px; }
.an-deg { color: var(--white-40); font: 12px var(--font-val); }
.an-seg { margin-top: 3px; }
.an-seg .seg-b { padding: 2px 9px; font-size: 10px; }

/* --- Boolean Toggle: vertical pill in the bool wire colour (Figma 2026-07-15) —
 * off: outlined pill, light knob resting at the bottom
 * on:  solid pill, dark knob risen to the top --- */
.tg {
  width: 31px; height: 52px; position: relative; cursor: pointer;
  border: 2px solid var(--type-bool); border-radius: 999px;
  background: var(--dark-200);
  transition: background 0.15s ease;
}
.tg-knob {
  position: absolute; left: 2px; top: 23px; width: 23px; height: 23px;
  border-radius: 50%; background: var(--type-bool);
  transition: top 0.15s ease, background 0.15s ease;
}
.tg.on { background: var(--type-bool); box-shadow: 0 0 8px rgba(255, 59, 65, 0.45); }
.tg.on .tg-knob { top: 2px; background: var(--dark-100); }

/* --- Button (params): momentary push — solid while pressed --- */
.pbtn {
  width: 40px; height: 40px; position: relative; cursor: pointer;
  border: 2px solid var(--type-bool); border-radius: 50%;
  background: var(--dark-200);
  transition: background 0.1s ease;
  touch-action: none; user-select: none;
}
.pbtn-core {
  position: absolute; inset: 5px; border-radius: 50%;
  background: var(--type-bool); opacity: 0.35;
  transition: opacity 0.1s ease, background 0.1s ease;
}
.pbtn:hover .pbtn-core { opacity: 0.55; }
.pbtn.down { background: var(--type-bool); box-shadow: 0 0 8px rgba(255, 59, 65, 0.45); }
.pbtn.down .pbtn-core { background: var(--dark-100); opacity: 1; }

/* --- Colour Swatch: the chosen colour as a circle (Figma) --- */
.sw { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 2px; }
.sw-circle {
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.sw input[type="color"] { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
/* alpha strip under the circle — checkerboard shows through as a fades */
.sw-alpha {
  -webkit-appearance: none; appearance: none; display: block;
  width: 36px; height: 8px; margin: 0; padding: 0; cursor: ew-resize;
  border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 4px;
  background:
    linear-gradient(90deg, transparent, var(--sw, #fff)),
    repeating-conic-gradient(rgba(255, 255, 255, 0.25) 0 25%, transparent 0 50%) 0 0 / 6px 6px,
    var(--dark-200);
  outline: none;
}
.sw-alpha::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 6px; height: 12px; border-radius: 3px;
  background: var(--white-80); border: 1px solid var(--dark-300);
}

/* --- Graph Data (params/graph): plot on the node, number-blue marks --- */
.gph { padding: 4px; min-height: 0; }
.gph-cv { display: block; border-radius: 5px; }

/* --- Note Pad (params/panel): quiet dark sheet, corner-grip resizable --- */
.np {
  min-width: 120px; max-width: 420px; min-height: 44px; max-height: 400px;
  background: var(--dark-100); border: 1px solid var(--dark-300); border-radius: 8px;
  padding: 6px 9px;
  display: flex; flex-direction: column;
}
.panel-src {
  width: 100%; resize: none; min-height: 24px;
  background: transparent; border: none;
  color: var(--white-80); font: 11px/1.5 var(--font-val); outline: none;
}
.np.sized .panel-src { flex: 1; }
.panel-out {
  max-height: 150px; overflow: auto;
  font: 11px/1.5 var(--font-val); color: var(--white-80);
  white-space: pre; user-select: text;
}
.np.sized .panel-out { max-height: none; flex: 1; }

/* palette glyph for the swatch (its icon is a colour wheel, CSS-drawn) */
.icon-swatch {
  width: 15px; height: 15px; border-radius: 50%; flex: none;
  background: conic-gradient(from 90deg, #f00, #f5710c, #fdd41f, #15e134, #38dfe1, #390dea, #ff00fa, #f00);
}

/* --- Vector In (params/svg): load button + filename readout --- */
.vin { width: 100%; display: flex; flex-direction: column; gap: 4px; }
.vin-btn {
  text-align: center; padding: 4px 6px; border-radius: 7px; cursor: pointer;
  background: var(--dark-100); border: 1px solid var(--dark-300);
  color: var(--white-40); font: 10px var(--font-ui); user-select: none;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.vin-btn:hover { color: var(--white-80); border-color: var(--white-40); }
.vin-lbl {
  text-align: center; color: var(--white-40);
  font: 10px var(--font-val); user-select: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- segmented mode switch (vec/grid; reusable for any mode-toggle def) --- */
.seg {
  display: flex; gap: 2px; padding: 2px; width: 100%;
  background: var(--dark-100); border: 1px solid var(--dark-300); border-radius: 7px;
}
.seg-b {
  flex: 1; text-align: center; padding: 3px 6px; border-radius: 5px; cursor: pointer;
  color: var(--white-40); font: 10px var(--font-ui); user-select: none;
  transition: color 0.12s ease, background 0.12s ease;
}
.seg-b:hover { color: var(--white-80); }
.seg-b.on { background: var(--dark-300); color: var(--primary); }

.expr-src {
  width: 100%; padding: 3px 7px;
  background: #0c111c; border: 1px solid #26304a; border-radius: 6px;
  color: #e2b7f5; font: 11px ui-monospace, Consolas, monospace; outline: none;
}
.expr-src:focus { border-color: #a855f7; }

/* --- Custom JS (meta/js): code body + port editor --- */
.js-code {
  width: 100%; margin-top: 4px; padding: 4px 7px; display: block;
  background: #0c111c; border: 1px solid #26304a; border-radius: 6px;
  color: #c8d2e4; font: 11px/1.5 ui-monospace, Consolas, monospace;
  outline: none; resize: vertical; tab-size: 2; white-space: pre;
}
.js-code:focus { border-color: var(--accent-dim); }
.js-ports { display: flex; gap: 8px; margin-top: 4px; }
.js-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.js-port { display: flex; gap: 3px; align-items: center; min-width: 0; }
.js-port input.js-name { width: 34px; flex: 0 0 auto; }
.js-port select.js-type {
  flex: 1; min-width: 0; background: var(--dark-150); border: 1px solid var(--dark-400);
  border-radius: 3px; color: var(--white-60); font: 10px var(--font-ui); outline: none; padding: 1px 2px;
}
.js-x {
  flex: 0 0 auto; color: var(--white-40); cursor: pointer; font: 12px var(--font-ui);
  padding: 0 2px; user-select: none;
}
.js-x:hover { color: var(--type-bool); }
.js-add {
  color: var(--white-40); cursor: pointer; font: 10px var(--font-ui);
  padding: 1px 2px; user-select: none;
}
.js-add:hover { color: var(--primary); }

/* ---------------- quick add + context menu ---------------- */

#quickAdd {
  position: absolute; z-index: 30; width: 232px;
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
#quickAdd input {
  width: 100%; padding: 9px 12px; border: none; outline: none;
  background: transparent; border-bottom: 1px solid var(--line);
}
.qa-list { max-height: 264px; overflow-y: auto; padding: 4px; }
.qa-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 9px; border-radius: 6px; cursor: pointer; color: #b9c2d4;
}
.qa-item:hover, .qa-item.active { background: #223049; color: var(--text); }
.qa-cat { margin-left: auto; font-size: 10px; color: var(--faint); }

#marquee {
  position: absolute; z-index: 15; pointer-events: none;
  border: 1px solid #60a5fa;
  background: rgba(96, 165, 250, 0.07);
  border-radius: 2px;
}
#marquee.crossing {
  border: 1px dashed var(--accent-dim);
  background: rgba(94, 234, 212, 0.06);
}

/* palette drag ghost */
.drag-ghost {
  position: fixed; z-index: 90; pointer-events: none;
  background: var(--panel2); border: 1px solid var(--accent-dim);
  border-radius: 7px; padding: 4px 11px; font-size: 12px; color: var(--text);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
}

/* wire color key */
#typeKey {
  position: absolute; right: 12px; bottom: 12px; z-index: 12;
  background: rgba(16, 21, 31, 0.88); border: 1px solid var(--line);
  border-radius: 9px; font-size: 10px; color: var(--dim);
  backdrop-filter: blur(4px); min-width: 108px; overflow: hidden;
  user-select: none;
}
.tk-head {
  padding: 5px 10px; font-weight: 700; letter-spacing: 0.1em; font-size: 9px;
  text-transform: uppercase; color: var(--faint); cursor: pointer;
}
.tk-head:hover { color: var(--dim); }
#typeKey.closed .tk-body { display: none; }
.tk-body { padding: 0 10px 7px; }
.tk-row { display: flex; align-items: center; gap: 7px; padding: 1.5px 0; }
.tk-line { width: 16px; height: 2px; border-radius: 1px; flex: none; }
.tk-note { margin-top: 5px; color: var(--faint); font-size: 9px; max-width: 120px; }

/* loom overlay tools — fit + cloth-preview toggle */
#loomTools {
  position: absolute; top: 12px; right: 12px; z-index: 12;
  display: flex; gap: 6px;
}
#loomTools button {
  width: 30px; height: 30px; padding: 5px; cursor: pointer;
  background: rgba(16, 21, 31, 0.88); border: 1px solid var(--line);
  border-radius: 8px; color: var(--dim); backdrop-filter: blur(4px);
  transition: border-color .15s, color .15s;
}
#loomTools button:hover { border-color: var(--accent-dim); color: var(--text); }
#loomTools button svg { width: 100%; height: 100%; display: block; }
#loomTools button.off { color: var(--faint); }

/* ---------------- weave assistant ---------------- */

#assistant {
  position: absolute; top: 52px; right: 12px; bottom: 12px; width: 340px;
  max-width: calc(100% - 24px); z-index: 12;
  display: flex; flex-direction: column;
  background: rgba(13, 17, 25, 0.94); border: 1px solid var(--line2);
  border-radius: 12px; backdrop-filter: blur(8px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
#assistant.hidden { display: none; }
.as-head {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px 8px 12px; border-bottom: 1px solid var(--line);
}
.as-title { flex: 1; font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.as-head button {
  width: 24px; height: 24px; padding: 0; cursor: pointer;
  background: none; border: 1px solid transparent; border-radius: 6px; color: var(--faint);
}
.as-head button:hover { color: var(--text); border-color: var(--line2); }
.as-setup { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.as-setup p { font-size: 11px; color: var(--dim); margin: 0 0 8px; line-height: 1.45; }
.as-setup input {
  width: 100%; margin: 0 0 6px; padding: 6px 9px;
  background: var(--bg); border: 1px solid var(--line2); border-radius: 7px;
  color: var(--text); font-size: 11px; outline: none;
}
.as-setup input:focus { border-color: var(--accent-dim); }
.as-setrow { display: flex; gap: 6px; }
.as-setrow button {
  padding: 5px 12px; cursor: pointer; font-size: 11px;
  background: var(--bg); border: 1px solid var(--line2); border-radius: 7px; color: var(--dim);
}
.as-setrow button.accent { border-color: var(--accent-dim); color: var(--text); }
.as-setrow button:hover { border-color: var(--accent-dim); color: var(--text); }
.as-msgs { flex: 1; overflow-y: auto; padding: 10px 10px 4px; display: flex; flex-direction: column; gap: 8px; }
.as-msg {
  max-width: 92%; padding: 7px 10px; border-radius: 10px;
  font-size: 12px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.as-msg.user { align-self: flex-end; background: rgba(94, 234, 212, 0.10); border: 1px solid rgba(94, 234, 212, 0.22); }
.as-msg.assistant { align-self: flex-start; background: rgba(16, 21, 31, 0.9); border: 1px solid var(--line2); }
.as-msg.note { align-self: center; font-size: 11px; color: #5eead4; background: none; padding: 2px 6px; }
.as-msg.note.error { color: #f87171; white-space: pre-wrap; }
.as-foot { padding: 8px 10px 10px; border-top: 1px solid var(--line); }
.as-snap { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--faint); margin-bottom: 6px; cursor: pointer; }
.as-inrow { display: flex; gap: 6px; align-items: flex-end; }
.as-in {
  flex: 1; resize: none; padding: 7px 9px; min-height: 40px;
  background: var(--bg); border: 1px solid var(--line2); border-radius: 8px;
  color: var(--text); font: inherit; font-size: 12px; outline: none;
}
.as-in:focus { border-color: var(--accent-dim); }
.as-send {
  width: 34px; height: 34px; cursor: pointer; flex: none;
  background: rgba(94, 234, 212, 0.12); border: 1px solid rgba(94, 234, 212, 0.35);
  border-radius: 8px; color: #5eead4;
}
.as-send:hover { background: rgba(94, 234, 212, 0.2); }
.as-send:disabled { opacity: 0.4; cursor: default; }
#assistant.busy .as-send { animation: as-pulse 1.1s ease-in-out infinite; }
@keyframes as-pulse { 50% { opacity: 0.35; } }

/* preview toggle — the header eye (geometry-producing nodes) */
.prev-toggle {
  width: 13px; height: 13px; flex: none; cursor: pointer;
  color: var(--eye-on); opacity: 0.9;
}
.prev-toggle svg { width: 100%; height: 100%; display: block; }
.prev-toggle:hover { opacity: 1; filter: drop-shadow(0 0 4px rgba(20, 197, 14, 0.6)); }
/* the anchor's eye toggles its cloth handle, and wears the Params colour */
.node.is-anchor .prev-toggle { color: var(--cat); }
.node.is-anchor .prev-toggle:hover { filter: drop-shadow(0 0 4px rgba(45, 212, 191, 0.6)); }
.node.no-prev .prev-toggle { color: var(--white-40); opacity: 0.7; }
.node.no-prev .prev-toggle:hover { filter: none; }

/* disabled node: data passes through untouched */
.node.disabled { opacity: 0.45; }
.node.disabled .node-head { text-decoration: line-through; text-decoration-color: var(--faint); }

/* dead node: its value reaches no sink — desaturated but legible, so a patch
 * mid-construction reads quiet rather than broken (distinct from .disabled) */
.node.dead { filter: saturate(0.25); }
.node.dead:hover, .node.dead.selected { filter: saturate(0.6); }

/* clusters — a folded subgraph; the stacked-card shadow says "there's more inside" */
.node.cluster {
  box-shadow: 3px 5px 0 -1px color-mix(in srgb, var(--dark-300) 75%, var(--cat, #8494ad)),
    6px 10px 0 -2px color-mix(in srgb, var(--dark-300) 45%, transparent),
    0 10px 26px rgba(0, 0, 0, 0.4);
}
.node.cluster.selected {
  box-shadow: 3px 5px 0 -1px color-mix(in srgb, var(--dark-300) 75%, var(--cat, #8494ad)),
    6px 10px 0 -2px color-mix(in srgb, var(--dark-300) 45%, transparent),
    0 0 7.5px rgba(94, 234, 212, 0.33), 0 10px 26px rgba(0, 0, 0, 0.5);
}
.node.cluster .node-head .title[contenteditable="true"] {
  outline: 1px solid var(--primary); outline-offset: 2px; border-radius: 4px; cursor: text;
}

/* compact nodes (small unary ops, constants) */
.node.compact { min-width: 96px; }
.node.compact .node-head { padding: 3px 8px 3px 4px; gap: 5px; }
.node.compact .node-head .title { font-size: 12.5px; }
.node.compact .node-head .icon { width: 18px; height: 18px; }
.node.compact .row { min-height: 17px; }
.node.compact .node-rows { padding: 5px 0 4px; }
.node.compact .row.out .rd { max-width: 56px; }

/* bare nodes — the control IS the node (Toggle, Slider, Swatch, Note Pad);
 * ports overlay the widget's left/right edges, labels and readouts hide */
.node.bare {
  min-width: 0; background: none; border: none; border-radius: 0; box-shadow: none;
}
.node.bare.selected, .node.bare.error { box-shadow: none; }
.node.bare.selected .node-body > * { outline: 1px solid var(--primary); outline-offset: 3px; }
/* …but never the resize grips — outlining those full-height strips paints
 * stray vertical lines beside the real selection box */
.node.bare.selected .node-body > .sl-grip-l, .node.bare.selected .node-body > .sl-grip-r { outline: none; }
.node.bare .node-rows { padding: 0; }
.node.bare .node-cols { position: absolute; inset: 0; pointer-events: none; }
.node.bare .col-ins, .node.bare .col-outs {
  position: absolute; top: 0; bottom: 0; margin: 0;
  display: flex; flex-direction: column; justify-content: center; gap: 12px;
}
.node.bare .col-ins { left: 0; }
.node.bare .col-outs { right: 0; align-items: center; }
.node.bare .row { padding: 0; min-height: 0; }
.node.bare .row .label, .node.bare .rd, .node.bare .lit { display: none; }
.node.bare .port { pointer-events: auto; position: static; transform: none; }
.node.bare .col-ins .port { margin-left: -7px; }
.node.bare .col-outs .port { margin-right: -7px; }
.node.bare .node-body { padding: 0; }

/* collapsed nodes — double-click the head: icon + gradient + ports only.
 * Ports overlay the card edges like bare widgets; everything textual hides. */
.node.collapsed { min-width: 46px; width: 46px; }
.node.collapsed .node-head {
  border-bottom: none; border-radius: 12px; padding: 0;
  position: absolute; inset: 0; justify-content: center; gap: 0;
}
.node.collapsed .node-head .title,
.node.collapsed .node-head .head-gap,
.node.collapsed .prev-toggle { display: none; }
.node.collapsed .node-body,
.node.collapsed .row .label,
.node.collapsed .lit,
.node.collapsed .row.out .rd { display: none; }
.node.collapsed .node-rows {
  position: absolute; inset: 0; padding: 0; background: none; pointer-events: none;
}
.node.collapsed .node-cols { position: absolute; inset: 0; }
.node.collapsed .col-ins, .node.collapsed .col-outs {
  position: absolute; top: 0; bottom: 0; margin: 0;
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
}
.node.collapsed .col-ins { left: 0; }
.node.collapsed .col-outs { right: 0; align-items: center; }
.node.collapsed .row { padding: 0; min-height: 0; }
.node.collapsed .port { pointer-events: auto; position: static; transform: none; }
.node.collapsed .col-ins .port { margin-left: -7px; }
.node.collapsed .col-outs .port { margin-right: -7px; }

/* relay — a pass-through pill dropped onto a wire (double-click the wire);
 * standard card colours, no head, ports at its ends take the wire's colour */
.node.relay { min-width: 40px; width: 40px; height: 24px; border-radius: 999px; }
.node.relay .node-rows {
  position: absolute; inset: 0; padding: 0; background: none;
  border-radius: 999px; pointer-events: none;
}
.node.relay .node-cols { position: absolute; inset: 0; }
.node.relay .col-ins, .node.relay .col-outs {
  position: absolute; top: 0; bottom: 0; margin: 0;
  display: flex; flex-direction: column; justify-content: center;
}
.node.relay .col-ins { left: 0; }
.node.relay .col-outs { right: 0; align-items: center; }
.node.relay .row { padding: 0; min-height: 0; }
.node.relay .row .label, .node.relay .lit, .node.relay .row.out .rd { display: none; }
.node.relay .port { pointer-events: auto; position: static; transform: none; }
.node.relay .col-ins .port { margin-left: -7px; }
.node.relay .col-outs .port { margin-right: -7px; }

.anchor-row { display: flex; gap: 5px; }
.anchor-row input { width: 56px; }

/* any input in a custom node body defaults to the dark style —
   prevents white-on-white fields when a body forgets to style its inputs */
.node-body input[type="number"], .node-body input[type="text"] {
  background: #0c111c; border: 1px solid #26304a; border-radius: 5px;
  color: #c8d2e4; font-size: 11px; padding: 1px 5px; outline: none;
}
.node-body input[type="number"]:focus, .node-body input[type="text"]:focus {
  border-color: var(--accent-dim);
}
/* keep the deliberate ghost styling of bare-widget text fields despite the
   generic rule above */
.node-body .sl-ends input, .node-body input.sl-val {
  background: transparent; border-color: transparent;
}
.node-body .sl-ends input:hover, .node-body .sl-ends input:focus {
  border-color: var(--dark-400); background: var(--dark-150);
}
.node-body input.sl-val:hover, .node-body input.sl-val:focus {
  border-color: var(--dark-400); background: var(--dark-150);
}
.node-body input.sl-val { color: var(--type-number); font: 18px/1 var(--font-val); }
.node-body .sl-ends input { color: rgba(255, 255, 255, 0.22); font: 9px var(--font-val); }

#ctxMenu {
  position: absolute; z-index: 30; min-width: 130px;
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 9px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55); padding: 4px;
}
.ctx-item { padding: 5px 11px; border-radius: 6px; cursor: pointer; }
.ctx-item:hover { background: #223049; }
.ctx-item.danger:hover { background: #3d1d26; color: var(--danger); }

/* ---------------- splitter + preview ---------------- */

#splitter {
  width: 5px; flex: none; cursor: col-resize;
  background: var(--line); transition: background .15s;
}
#splitter:hover { background: var(--accent-dim); }

#preview {
  flex: 0 0 42%; min-width: 240px; position: relative;
  background: var(--bg);
}
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* real DOM elements declared by nodes (Button) — reconciled every frame */
#domLayer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.weft-btn {
  position: absolute; transform: translate(-50%, -50%); pointer-events: auto;
  background: rgba(16, 21, 31, 0.88); color: var(--text);
  border: 1px solid rgba(94, 234, 212, 0.55); border-radius: 999px;
  padding: 7px 16px; font: 500 13px Inter, system-ui, sans-serif;
  cursor: pointer; backdrop-filter: blur(4px); user-select: none;
}
.weft-btn:hover { border-color: #5eead4; background: rgba(24, 32, 45, 0.92); }
.weft-btn:active { transform: translate(-50%, -50%) scale(0.96); background: rgba(94, 234, 212, 0.18); }

/* disp/element — real DOM laid over the cloth where its geometry sits */
.weft-el {
  position: absolute; box-sizing: border-box; pointer-events: auto;
  display: flex; align-items: center; justify-content: center;
  margin: 0; color: var(--text); text-decoration: none;
  background: transparent; border: 0; font: 500 14px Inter, system-ui, sans-serif;
  user-select: none;
}
.weft-el:focus-visible { outline: 2px solid #5eead4; outline-offset: 2px; border-radius: 6px; }

#viewHud {
  position: absolute; top: 10px; right: 12px; display: flex; gap: 8px; align-items: center;
}
#viewHud button {
  background: rgba(16, 21, 31, 0.75); border: 1px solid var(--line2);
  border-radius: 7px; width: 30px; height: 26px; cursor: pointer; color: var(--text);
  backdrop-filter: blur(4px);
}
#viewHud button:hover { border-color: var(--accent-dim); }
#fps {
  font-size: 11px; color: var(--faint);
  background: rgba(16, 21, 31, 0.75); border: 1px solid var(--line);
  border-radius: 7px; padding: 4px 9px; backdrop-filter: blur(4px);
}
#btnMute.muted { color: var(--faint); }
#btnTune { width: auto !important; padding: 0 8px; font-size: 11px; color: var(--faint); }
#btnTune:hover { color: var(--text); }
#btnCam { width: auto !important; padding: 0 8px; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
#btnCam:hover { color: var(--text); }
#btnCam.active { color: #5eead4; border-color: rgba(94, 234, 212, 0.45); }

/* audio node bodies — note / root pickers */
.aud-sel {
  width: 100%; margin: 2px 0;
  background: rgba(16, 21, 31, 0.8); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 11px; padding: 3px 5px; cursor: pointer;
}
.aud-sel:hover { border-color: var(--accent-dim); }

/* ---------------- status bar ---------------- */

#status {
  display: flex; justify-content: space-between; align-items: center;
  height: 26px; padding: 0 14px; flex: none;
  background: var(--panel); border-top: 1px solid var(--line);
  font-size: 11px; color: var(--faint);
}
#statusHint.flash { color: var(--accent); }

/* ---------------- export modal ---------------- */

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 8, 13, 0.72);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}
/* the ask dialog can open over another modal (unsaved-changes over the
 * gallery) — it must always paint on top */
#askModal { z-index: 60;
}
.modal-box {
  width: min(760px, 92vw); max-height: 86vh;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  padding: 18px 20px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.modal-head .ghost {
  background: none; border: none; cursor: pointer; color: var(--dim); font-size: 14px;
}
.modal-head .ghost:hover { color: var(--text); }
.modal-note { margin: 0; color: var(--dim); font-size: 12px; }
.modal-note code { color: var(--accent); background: #0c111c; padding: 1px 5px; border-radius: 4px; }

#exportCode {
  flex: 1; min-height: 280px; resize: none;
  background: #0a0e16; border: 1px solid var(--line); border-radius: 9px;
  color: #a8c7fa; font: 11px/1.5 ui-monospace, Consolas, monospace;
  padding: 10px 12px; outline: none; white-space: pre; overflow: auto;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions button {
  background: var(--panel); border: 1px solid var(--line2); border-radius: 7px;
  padding: 6px 14px; cursor: pointer;
}
.modal-actions button:hover { border-color: var(--accent-dim); color: var(--accent); }
.modal-actions button.accent { border-color: var(--accent-dim); color: var(--accent); font-weight: 600; }

/* ask dialog — small prompt/confirm */
.modal-box.small { width: min(430px, 92vw); }
.ask-input {
  background: var(--bg); border: 1px solid var(--line2); border-radius: 7px;
  padding: 7px 10px; outline: none;
}
.ask-input:focus { border-color: var(--accent-dim); }

/* ---------------- example gallery ----------------
 * Cards wear the loom livery (docs/DESIGN.md): 13px radius, dark/300 border,
 * category gradient washing in from the left — same recipe as nodes.html's
 * .cat-head, so the three surfaces read as one system. */

.modal-box.wide { width: min(1100px, 94vw); height: 86vh; }

/* the category chips reuse .seg / .seg-b / .seg-b.on from the node mode
 * toggles; wrapping + auto width is all a long label row needs */
.seg.wrap { flex-wrap: wrap; gap: 3px; }
.seg.wrap .seg-b { flex: 0 0 auto; padding: 4px 11px; font-size: 11px; }

.gal-scroll { flex: 1; min-height: 0; overflow: auto; padding: 2px 4px 4px 2px; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 10px; }

.gal-card {
  display: flex; flex-direction: column; overflow: hidden;
  padding: 0 0 12px; cursor: pointer; text-align: left;
  font: inherit; color: inherit;
  border: 1px solid var(--dark-300); border-radius: 13px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--cat, #6b7891) 34%, transparent) 0%, rgba(20, 26, 40, 0) 52%),
    var(--dark-200);
  transition: border-color 0.14s ease, transform 0.14s ease;
}
.gal-card:hover, .gal-card:focus-visible {
  border-color: var(--primary); transform: translateY(-1px); outline: none;
}
.gal-card.hide { display: none; }

.gal-thumb {
  width: 100%; aspect-ratio: 16 / 10; flex: none;
  background: var(--dark-100) center / cover no-repeat;
  border-bottom: 1px solid var(--dark-300);
}

.gal-body { display: flex; flex-direction: column; gap: 6px; padding: 11px 13px 0; }
.gal-name { font: 14px var(--font-ui); color: var(--white-100); }
.gal-blurb { font: 12px/1.5 var(--font-ui); color: var(--white-80); }
.gal-teach {
  font: 11.5px/1.5 var(--font-ui); color: var(--white-40);
  border-left: 2px solid var(--dark-400); padding-left: 8px;
}
.gal-foot {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 2px;
  font: 10px var(--font-val); color: var(--white-40);
}
.gal-foot .gal-cat { color: var(--cat, var(--white-80)); font: 10px var(--font-ui); }
.gal-need {
  padding: 1px 6px; border-radius: 5px; font: 10px var(--font-ui);
  border: 1px solid #7a5a1e; color: #f0b429;
}
.gal-empty { margin: 34px 0 0; text-align: center; color: var(--white-40); font-size: 12px; }
