:root {
  --bg: #15171c;
  --panel: #1c1f26;
  --panel-2: #232731;
  --border: #2e333e;
  --text: #d9dde5;
  --muted: #8a93a3;
  --accent: #5aa9ff;
  --error: #ff5d5d;
  --warning: #f5b942;
  --info: #6cb6ff;
  --node-bg: #252a33f0;
  --node-border: #3a404d;
  --exec: #e8ebf0;
  --field: #14161b;          /* inputs, segmented control */
  --hover-bg: #2a2f3b;
  --hover-border: #46506a;
  --primary: #2d6fd6;
  --primary-hover: #3a7ce4;
  --on-primary: #fff;
  --code-bg: #111317;        /* code, trace, run output, active tab */
  --code-inline: #0f1115;
  --line-num: #4b5261;
  --row-hover: #ffffff08;
  --row-line: #ffffff08;
  --node-divider: #ffffff10;
  --canvas: #121418;
  --grid-dot: #2a2f3a;
  --node-selected: #e9eef7;
  --pin-label: #c8cfdb;
  --pin-hole: #1b1e25;
  --pin-exec-off: #555b66;
  --pin-drop: #ffffff44;
  --unresolved: #ffd38a;
  --wire-glow: #fff;
  --overlay-border: #3c4352; /* menus, dialogs */
  --backdrop: #0008;
  --shadow: #000a;
  --shadow-soft: #0007;
  --handle: #4a5265;
  --ok: #4cc38a;
  --ok-text: #7bd389;
  --bind-bg: #2a3a2f;
  --bind-text: #a8e6b8;
  --tok-kw: #c792ea;
  --tok-type: #82aaff;
  --tok-str: #c3e88d;
  --tok-num: #f78c6c;
  --tok-com: #5c6577;
  --tok-pre: #89ddff;
  --tok-fn: #ffcb6b;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--sans); overflow: hidden; display: flex; flex-direction: column; }
button, select, input, textarea { font: inherit; color: inherit; }
button, select {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:not(:disabled):hover, select:hover { border-color: var(--hover-border); background: var(--hover-bg); }
button.primary { background: var(--primary); border-color: var(--primary-hover); color: var(--on-primary); }
button.primary:not(:disabled):hover { background: var(--primary-hover); }
/* pressed: the button dips and darkens a little while the pointer (or Space/Enter) holds it */
button { transition: transform .08s ease, filter .1s ease; }
button:not(:disabled):active { transform: scale(.96); filter: brightness(.88); }
/* rows, tabs and the language switch already answer a click by becoming selected: no dip */
:is(.segmented button, .tab, .cl-item, .nm-item, .tstep, .problem, .dbg-val, .palette-item, .link-btn):active { transform: none; }
/* disabled: faded, and no hover or press reaction */
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; }
button.small { padding: 6px 12px; }
input[type=text], input[type=search], input:not([type]), textarea {
  background: var(--field); border: 1px solid var(--border); border-radius: 5px; padding: 6px 8px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
code { font-family: var(--mono); font-size: 12px; background: var(--code-inline); padding: 1px 4px; border-radius: 4px; }

/* ---------------------------------------------------------------- top bar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel); flex: none; }
.brand { font-weight: 700; letter-spacing: .2px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
/* a divider after the name, so the first toolbar label doesn't read as part of it */
.brand { padding-right: 18px; margin-right: 2px; border-right: 1px solid var(--border); align-self: stretch; }
.brand img { display: block; flex: none; }
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tb { display: inline-flex; align-items: center; gap: 6px; }
.tb .ico { color: var(--muted); }
.tb:hover .ico { color: var(--text); }
.tb.icon-only { padding: 6px 9px; }
.target { display: inline-flex; align-items: center; gap: 8px; }
.target-label { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
.target-label .ico { color: var(--accent); }
.select-ico { position: relative; display: inline-flex; align-items: center; }
.select-ico .ico { position: absolute; left: 11px; color: var(--muted); pointer-events: none; }
.select-ico select { padding-left: 33px; max-width: 210px; text-overflow: ellipsis; }

/* Target language: the first thing in the toolbar, as a segmented control */
.segmented { position: relative; display: inline-flex; padding: 2px; gap: 2px; background: var(--field); border: 1px solid var(--border); border-radius: 8px; }
.segmented button { border: none; background: transparent; border-radius: 6px; padding: 5px 14px; color: var(--muted); font-weight: 600; }
.segmented button:hover { background: var(--panel-2); color: var(--text); }
.segmented button { position: relative; z-index: 1; transition: color .18s ease, background-color .12s ease; }
.segmented button[aria-checked="true"] { color: var(--on-primary); }
.segmented button[aria-checked="true"]:hover { background: transparent; }
/* the selected highlight is one element that slides to the checked option (positioned by showLang) */
.seg-thumb {
  position: absolute; left: 0; top: 2px; bottom: 2px; width: 0; border-radius: 6px;
  background: var(--primary); box-shadow: 0 1px 2px #0006; pointer-events: none;
}
.segmented.animate .seg-thumb { transition: transform var(--dur) var(--ease-out), width var(--dur) var(--ease-out); }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); cursor: pointer; white-space: nowrap; }

/* ---------------------------------------------------------------- layout */
.layout {
  --pal-w: 210px; --side-w: 440px;
  flex: 1; display: grid; grid-template-columns: var(--pal-col, var(--pal-w)) 1fr var(--side-w); min-height: 0;
}
:root { --ease-out: cubic-bezier(.3, .8, .3, 1); --dur: .22s; }
.anim-ready .layout { transition: grid-template-columns var(--dur) var(--ease-out); }
.palette { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
/* contents keep their width while the column slides open or closed */
.palette > * { width: calc(var(--pal-w) - 1px); flex-shrink: 0; }
.palette > #palette-list { flex-shrink: 1; }
.palette-head { display: flex; align-items: center; gap: 6px; padding: 10px; }
.palette-head input { flex: 1; min-width: 0; }
#palette-list { overflow: auto; flex: 1; padding: 0 6px 10px; }
.palette-add { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 0 10px 6px; width: auto !important;
  padding: 7px 10px; border: 1px dashed var(--hover-border); border-radius: 7px; background: transparent; color: var(--muted); font-size: 12px; }
.palette-add:hover { color: var(--text); border-color: var(--accent); background: var(--hover-bg); }
.palette-add .ico { width: 14px; height: 14px; }
.palette-cat { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; margin: 10px 6px 4px; }
.palette-item { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 5px; cursor: grab; user-select: none; }
.palette-item:hover { background: var(--panel-2); }
.palette-item .swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.palette-item .tag { margin-left: auto; font-size: 10px; color: var(--muted); }
.palette-hint { color: var(--muted); font-size: 11px; padding: 8px 12px; border-top: 1px solid var(--border); }
.palette-credit { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; padding: 0 12px 10px; font-size: 11px; color: var(--muted); }
.palette-credit a, .link-btn { color: var(--muted); text-decoration: none; }
.palette-credit a:hover, .link-btn:hover { color: var(--accent); text-decoration: underline; }
.link-btn { background: none; border: none; padding: 0; font: inherit; cursor: pointer; }
.link-btn:hover { background: none; }
.help a { color: var(--accent); }

.side { position: relative; border-left: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
/* desktop: drag the panel's left edge to make it wider or narrower (the width is remembered) */
.side-resize { position: absolute; z-index: 6; left: -5px; top: 0; bottom: 0; width: 9px; cursor: ew-resize; touch-action: none; outline: none; }
.side-resize::before { content: ''; position: absolute; left: 3px; top: 0; bottom: 0; width: 3px; background: transparent; transition: background-color .12s ease .08s; }
.side-resize:hover::before, .side-resize:focus-visible::before, .side-resize.dragging::before { background: var(--accent); }
.anim-ready .layout.resizing { transition: none; }
body.resizing-side { cursor: ew-resize; user-select: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; flex: none; }
.code-panel { flex: 1; display: flex; flex-direction: column; min-height: 120px; border-top: 1px solid var(--border); }
.sheet-handle { display: none; }
.problems-panel { flex: none; max-height: 30%; display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.count { background: var(--panel-2); padding: 0 6px; border-radius: 8px; }

/* ---------------------------------------------------------------- canvas */
.canvas-wrap { position: relative; min-width: 0; min-height: 0; }
.viewport { position: absolute; inset: 0; overflow: hidden; outline: none; cursor: default; background: var(--canvas);
  /* the editor handles every touch gesture itself; without this the browser scrolls/zooms and cancels the pan */
  touch-action: none; -webkit-touch-callout: none; }
.viewport.panning { cursor: grabbing; }
.grid { position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1.2px); }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.wires { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; }
.wires path { fill: none; stroke-width: 2.5; }
.wires path.hit { stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.wires path.vis { pointer-events: none; }
.wires path.exec { stroke: var(--exec); stroke-width: 3; }
.wires path.error { stroke: var(--error) !important; stroke-dasharray: 6 4; }
.wires path.narrowing { stroke-dasharray: 2 4; stroke-linecap: round; stroke-width: 3; }
.wires path.selected { filter: drop-shadow(0 0 4px var(--wire-glow)); stroke-width: 4; }
.wires path.temp { stroke: var(--wire-glow); stroke-dasharray: 5 5; opacity: .8; }
.boxsel { position: absolute; border: 1px solid var(--accent); background: #5aa9ff22; pointer-events: none; }
.canvas-status { position: absolute; left: 12px; bottom: 10px; color: var(--muted); font-size: 12px; pointer-events: none; }
.zoom-controls { position: absolute; right: 12px; bottom: 10px; display: flex; gap: 4px; }
.zoom-controls button { padding: 5px 12px; min-width: 34px; }
.zoom-controls .tidy-btn { display: inline-flex; align-items: center; gap: 6px; margin-right: 6px; }
.zoom-controls .tidy-btn .ico { width: 14px; height: 14px; color: var(--muted); }
@media (max-width: 800px) { .zoom-controls .tidy-btn { font-size: 0; gap: 0; } }

/* ---------------------------------------------------------------- nodes */
.node {
  position: absolute; min-width: 150px; background: var(--node-bg); border: 1px solid var(--node-border);
  border-radius: 8px; box-shadow: 0 4px 16px var(--shadow-soft); user-select: none; font-size: 12px;
}
/* breakpoints: a red dot at the start of the node's title */
.bp-mark { width: 9px; height: 9px; border-radius: 50%; background: var(--error); box-shadow: 0 0 0 2px color-mix(in srgb, var(--error) 30%, transparent); flex: none; }
.bp-mark.inline { display: inline-block; margin-right: 6px; vertical-align: 0; }
.dbg-bp .bp-dot { fill: var(--error); stroke: none; }
/* comment boxes: a titled frame under the nodes; only its title bar and corner take the pointer */
.comments { position: absolute; left: 0; top: 0; }
.comment { position: absolute; border: 1.5px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 6%, transparent); pointer-events: none; }
.comment.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.comment-head { pointer-events: auto; cursor: grab; height: 30px; display: flex; align-items: center; padding: 0 12px;
  border-radius: 8px 8px 0 0; background: color-mix(in srgb, var(--accent) 16%, transparent); font-weight: 600; font-size: 14px; color: var(--text); user-select: none; }
.comment-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comment-input { font: inherit; font-weight: 600; width: 100%; padding: 2px 6px; }
.comment-resize { pointer-events: auto; position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, color-mix(in srgb, var(--accent) 45%, transparent) 50%); border-radius: 0 0 8px 0; }
/* reroute points: just their pins, on a small rounded body */
.node.node-reroute { min-width: 0; border-radius: 10px; }
.node-reroute .node-head, .node-reroute .node-props, .node-reroute .label, .node-reroute .type, .node-reroute .val, .node-reroute .dbg-note { display: none; }
.node-reroute .node-body { padding: 3px 0; gap: 10px; }
.node-reroute .pin-row { height: 14px; }
.node.selected { border-color: var(--node-selected); box-shadow: 0 0 0 1px var(--node-selected), 0 4px 18px var(--shadow); }
.node.has-error { border-color: var(--error); }
.node.has-error.selected { box-shadow: 0 0 0 1px var(--error), 0 4px 18px var(--shadow); }
.node.hl { box-shadow: 0 0 0 2px var(--accent), 0 4px 18px var(--shadow); }
.node-head {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 7px 7px 0 0;
  cursor: grab; font-weight: 600; color: #fff; white-space: nowrap;
  background: linear-gradient(90deg, var(--head), color-mix(in srgb, var(--head) 60%, transparent));
}
.node-head .title { overflow: hidden; text-overflow: ellipsis; }
.node-head .badge { font: 11px var(--mono); font-weight: 400; background: #0005; padding: 0 5px; border-radius: 4px; color: #e6ecf5; }
.node-head .badge.unresolved { color: #ffd38a; }
.node-head .badge.amb { background: var(--error); color: #fff; }
.node-head .err { margin-left: auto; background: var(--error); color: #fff; border-radius: 8px; padding: 0 6px; font-size: 11px; }
.node-head .warn { margin-left: auto; background: var(--warning); color: #222; border-radius: 8px; padding: 0 6px; font-size: 11px; }
.node-body { display: flex; justify-content: space-between; gap: 14px; padding: 6px 0; }
.node-col { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.node-col.outs { align-items: flex-end; }
.pin-row { display: flex; align-items: center; gap: 6px; height: 20px; white-space: nowrap; }
.pin-row.in { padding-left: 0; }
.pin-row .label { color: var(--pin-label); }
.pin-row .type { font: 10.5px var(--mono); color: var(--muted); }
.pin-row .type.unresolved { color: var(--unresolved); font-style: italic; }
.pin-row .val { width: 64px; padding: 1px 4px; font: 11px var(--mono); height: 18px; }
.pin { width: 12px; height: 12px; flex: none; cursor: crosshair; position: relative; }
.pin.in { margin-left: -6px; }
.pin.out { margin-right: -6px; }
.pin.data { border-radius: 50%; border: 2px solid var(--c, #888); background: var(--pin-hole); }
.pin.data.connected { background: var(--c, #888); }
.pin.exec { width: 13px; height: 13px; clip-path: polygon(0 0, 55% 0, 100% 50%, 55% 100%, 0 100%); background: var(--pin-exec-off); }
.pin.exec::after { content: ''; position: absolute; inset: 2px; clip-path: polygon(0 0, 55% 0, 100% 50%, 55% 100%, 0 100%); background: var(--pin-hole); }
.pin.exec.connected { background: var(--exec); }
.pin.exec.connected::after { display: none; }
.pin:hover { transform: scale(1.3); }
.pin.drop-ok { transform: scale(1.4); box-shadow: 0 0 0 3px var(--pin-drop); }
/* a Function node: + under its parameters, and renaming one on its label */
.add-param { height: 18px; width: 22px; padding: 0; margin-right: 2px; font-size: 13px; line-height: 1; opacity: .55; }
.node:hover .add-param, .node.selected .add-param, .add-param:focus-visible { opacity: 1; }
.pin-rename { font: 11px var(--mono); padding: 0 4px; height: 18px; min-width: 4ch; }
.node-props { border-top: 1px solid var(--node-divider); padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 4px; }
.node-props label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.node-props input { flex: 1; min-width: 60px; font: 11px var(--mono); }
.node-props .prop-check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.node-props .prop-check input { margin: 0; flex: none; width: auto; }
.node-props textarea { flex: 1; font: 11px var(--mono); min-height: 40px; resize: vertical; }
.node-props input, .node-props textarea { padding: 3px 6px; }

/* ---------------------------------------------------------------- menu */
/* right-click / long-press menu on nodes */
.node-menu { position: fixed; z-index: 55; min-width: 210px; max-width: min(300px, calc(100vw - 16px)); padding: 4px; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--overlay-border); border-radius: 9px; box-shadow: 0 10px 30px var(--shadow); outline: none; }
.nm-head { padding: 5px 9px 4px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nm-item { display: flex; align-items: center; gap: 16px; width: 100%; text-align: left; padding: 6px 9px; border: none; border-radius: 6px; background: transparent; color: var(--text); font-size: 13px; cursor: pointer; }
.nm-item:hover, .nm-item.active, .nm-item:focus-visible { background: var(--hover-bg); outline: none; }
.nm-item.danger { color: var(--error); }
.nm-key { margin-left: auto; color: var(--muted); font-size: 11px; font-family: var(--mono); }
.nm-sep { height: 1px; background: var(--border); margin: 4px 6px; }
@media (max-width: 800px) { .nm-item { padding: 10px 10px; font-size: 14px; } .nm-key { display: none; } }
.menu { position: fixed; z-index: 50; width: 280px; max-height: 380px; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--overlay-border); border-radius: 8px; box-shadow: 0 10px 30px var(--shadow); }
.menu input { margin: 8px; }
.menu-list { overflow: auto; padding: 0 4px 6px; }
.menu-item { padding: 4px 8px; border-radius: 5px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.menu-item .cat { margin-left: auto; color: var(--muted); font-size: 11px; }
.menu-item.active { background: var(--primary); color: var(--on-primary); }
.menu-item.active .cat { color: inherit; opacity: .8; }
.menu-item .swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }

/* ---------------------------------------------------------------- code view */
.code { flex: 1; overflow: auto; font: 12.5px/1.55 var(--mono); padding: 8px 0; background: var(--code-bg); }
.code .ln { display: flex; padding-right: 12px; cursor: pointer; white-space: pre; }
.code .ln:hover { background: var(--row-hover); }
.code .ln.hl { background: #2d6fd633; }
.code .ln.sel { background: #2d6fd655; }
.code .ln.dbg-line { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.code .ln.dbg-line:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.code .tok-dbg { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 3px; }
.code-dbg-note { padding: 6px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--panel-2); }
.code-dbg-note code { font-size: 11px; color: var(--accent); }
/* the code tab's own bar: settings for the code shown, and Copy */
.code-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.code-pane[hidden] { display: none; }
.code-bar { display: flex; align-items: center; gap: 10px; padding: 4px 8px 4px 12px; min-height: 34px; border-bottom: 1px solid var(--border); background: var(--panel); font-size: 12px; flex: none; }
.code-bar { align-items: center; flex-wrap: wrap; row-gap: 6px; padding-top: 6px; padding-bottom: 6px; }
/* first row: the language and Copy; the options get a row of their own */
.code-opts { order: 3; flex: 1 1 100%; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.code-copy { margin-left: auto; }
.segmented.small button { padding: 3px 10px; font-size: 12px; }
.code-bar .check { color: var(--muted); }
.code-copy { flex: none; display: inline-flex; align-items: center; gap: 5px; }
.code-copy .ico { width: 14px; height: 14px; }
.code .num { width: 36px; flex: none; text-align: right; padding-right: 12px; color: var(--line-num); user-select: none; }
.tok-kw { color: var(--tok-kw); }
.tok-type { color: var(--tok-type); }
.tok-str { color: var(--tok-str); }
.tok-num { color: var(--tok-num); }
.tok-com { color: var(--tok-com); font-style: italic; }
.tok-pre { color: var(--tok-pre); }
.tok-fn { color: var(--tok-fn); }

/* ---------------------------------------------------------------- tabs + trace */
/* A tab strip: the active tab joins the content below it (same background, no border between). */
.tab-head { align-items: flex-end; padding: 8px 12px 0; gap: 8px; text-transform: none; letter-spacing: normal; }
.tab-head > .small { margin-bottom: 6px; }
.icon-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; color: var(--muted); }
.icon-btn:hover { color: var(--text); }
.tabs { position: relative; display: flex; gap: 2px; min-width: 0; margin-bottom: -1px; }
/* the accent line over the active tab; slides between tabs (positioned by slidingIndicator) */
.tab-ink { position: absolute; left: 0; top: 0; width: 0; height: 2px; border-radius: 6px 6px 0 0; background: var(--accent); z-index: 2; pointer-events: none; }
.tabs.animate .tab-ink { transition: transform var(--dur) var(--ease-out), width var(--dur) var(--ease-out); }
.anim-ready .tab { transition: background-color .15s ease, color .15s ease, border-color .15s ease; }
.anim-ready .tab .tab-icon { transition: color .15s ease; }
.tab-enter { animation: tab-enter .18s ease-out; }
@keyframes tab-enter { from { opacity: 0; transform: translateY(3px); } }
.tab {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: transparent; border: 1px solid transparent; border-bottom: none; border-radius: 6px 6px 0 0;
  padding: 9px 14px 10px; color: var(--muted); font-size: 13px; font-weight: 500; position: relative;
}
.tab:hover { background: var(--panel-2); color: var(--text); border-color: transparent; }
.tab.active { color: var(--text); background: var(--code-bg); border-color: var(--border); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-icon { width: 16px; height: 16px; flex: none; }
/* When the side panel is narrow, inactive tabs show only their icon (the title says what they are). */
.code-panel { container-type: inline-size; }
@container (max-width: 390px) {
  .tab:not(.active) > span { display: none; }
  .tab:not(.active) { padding-left: 12px; padding-right: 12px; }
}
.tab.active .tab-icon { color: var(--accent); }
.tab[data-tab="run"] .tab-icon { color: var(--ok); }
.trace { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; background: var(--code-bg); }
.trace > :not(.trace-list) { flex: none; }
.trace-bar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.trace-bar input[type=range] { flex: 1; min-width: 60px; accent-color: var(--accent); }
.trace-pos { font: 11px var(--mono); color: var(--muted); min-width: 64px; text-align: right; }
.trace-scope { display: flex; align-items: center; gap: 8px; padding: 6px 12px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); }
.trace-scope b { color: var(--text); font-weight: 600; }
.trace-scope button { margin-left: auto; }
.trace-list { flex: 1; min-height: 120px; overflow: auto; padding: 4px 0 12px; }
.trace-group { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; padding: 10px 12px 3px; }
.tstep { display: flex; gap: 8px; padding: 4px 12px 4px 9px; cursor: pointer; border-left: 3px solid transparent; }
.tstep:hover { background: var(--row-hover); }
.tstep.current { background: #2d6fd633; border-left-color: var(--accent); }
.tstep.future { opacity: .45; }
.tstep .num { font: 11px var(--mono); color: var(--line-num); width: 22px; text-align: right; flex: none; padding-top: 1px; }
.tstep .body { min-width: 0; flex: 1; }
.tstep .msg { font: 11.5px/1.45 var(--mono); color: var(--text); word-break: break-word; }
.tstep.error .msg { color: var(--error); }
.tstep.warn .msg { color: var(--warning); }
.tstep .binds { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.tstep .bind { font: 10.5px var(--mono); background: var(--bind-bg); color: var(--bind-text); padding: 0 6px; border-radius: 4px; }
.phase { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 1px 5px; border-radius: 3px; height: fit-content; flex: none; width: 66px; text-align: center; margin-top: 1px; }
.phase-overload { background: #5b3f8c; color: #e6dcff; }
.phase-explicit { background: #6b4b1f; color: #ffe2b5; }
.phase-return { background: #7a2f2f; color: #ffd6d6; }
.phase-deduce { background: #1f4f7a; color: #d2e9ff; }
.phase-convert { background: #2b3d4f; color: #b9cde0; }
.phase-infer { background: #1e5e57; color: #c7f5ee; }
.phase-literal { background: #4a4a1e; color: #f3f3b8; }
.phase-default { background: #4a3a2a; color: #f0dcc2; }
.phase-concept { background: #3a3f4a; color: #d0d6e0; }
.phase-unresolved { background: #6a5320; color: #ffe7a8; }
.trace-empty { color: var(--muted); padding: 10px 12px; }
.node.trace-hl { box-shadow: 0 0 0 2px var(--warning), 0 4px 18px var(--shadow); }
.wires path.vis.trace { stroke-width: 4.5; filter: drop-shadow(0 0 4px #f5b942); }
/* ---------------------------------------------------------------- debug runs */
.debug-bar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 20px));
  display: flex; flex-direction: column; gap: 4px; padding: 6px 8px 7px; z-index: 5;
  background: var(--panel); border: 1px solid var(--overlay-border); border-radius: 10px; box-shadow: 0 6px 20px var(--shadow-soft); }
.dbg-controls { display: flex; align-items: center; gap: 4px; }
.dbg-controls input[type=range] { flex: 1; min-width: 60px; accent-color: var(--accent); margin: 0 6px; }
.dbg-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 28px; padding: 0; flex: none;
  border: 1px solid transparent; background: transparent; border-radius: 6px; color: var(--text); }
.dbg-btn:hover:not(:disabled) { background: var(--hover-bg); border-color: var(--hover-border); }
.dbg-btn:disabled { opacity: .35; }
.dbg-btn svg { width: 14px; height: 14px; fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#dbg-exit svg { fill: none; }
#dbg-exit { margin-left: 2px; }
.dbg-pos { font: 11px var(--mono); color: var(--muted); min-width: 64px; text-align: right; flex: none; }
.dbg-text { font-size: 12px; color: var(--muted); padding: 0 4px; overflow-wrap: anywhere; }
.dbg-text b { color: var(--text); }
.dbg-end { font-family: var(--mono); margin-left: 6px; }
.dbg-end.ok { color: var(--ok-text); }
.dbg-end.bad { color: var(--error); }

/* the canvas during a debug run: what has run stands out, the rest steps back */
.node { transition: opacity .15s, box-shadow .15s; }
.node.dbg-idle { opacity: .4; }
.node.dbg-current { box-shadow: 0 0 0 2px var(--accent), 0 0 18px color-mix(in srgb, var(--accent) 45%, transparent), 0 4px 18px var(--shadow); }
.node.dbg-current.selected { box-shadow: 0 0 0 2px var(--accent), 0 0 0 4px var(--node-selected), 0 4px 18px var(--shadow); }
.dbg-note { margin-left: auto; font: 600 10.5px var(--mono); background: var(--accent); color: var(--on-primary); padding: 0 6px; border-radius: 4px;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.wires path.vis.dbg-idle { opacity: .18; }
.wires path.vis.exec.dbg-flow { stroke: var(--accent); }
.wires path.vis.dbg-live { stroke-dasharray: 7 5; animation: dbg-flow .6s linear infinite; }
.wires path.vis.dbg-fresh { stroke-width: 4; filter: drop-shadow(0 0 3px color-mix(in srgb, var(--accent) 60%, transparent)); }
@keyframes dbg-flow { to { stroke-dashoffset: -12; } }
@media (prefers-reduced-motion: reduce) { .wires path.vis.dbg-live { animation: none; } }
.wire-values { position: absolute; left: 0; top: 0; pointer-events: none; }
.wire-val { position: absolute; transform: translate(-50%, -50%) scale(var(--label-scale, 1)); white-space: nowrap; font: 10.5px/16px var(--mono); padding: 0 6px; border-radius: 5px;
  background: var(--panel); color: var(--text); border: 1px solid color-mix(in srgb, var(--c, var(--muted)) 70%, transparent); box-shadow: 0 1px 4px var(--shadow-soft); }
.wire-val.fresh { border: 1.5px solid var(--accent); font-weight: 600; z-index: 1; }

#run-debug { display: inline-flex; align-items: center; gap: 5px; }
#run-debug .ico { width: 13px; height: 13px; }

/* run output printed after the current debug step */
.run-out .future { opacity: .35; }

/* inspector: every value a wire carried in the debug run */
.dbg-hist { display: flex; flex-direction: column; gap: 2px; margin: 8px 0 6px; max-height: 220px; overflow: auto; }
.dbg-hist-head { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 2px; }
.dbg-val { display: flex; gap: 8px; align-items: baseline; text-align: left; padding: 2px 6px; border: 1px solid transparent; border-radius: 5px; background: transparent; font: 11px var(--mono); color: var(--text); }
.dbg-val:hover { background: var(--hover-bg); }
.dbg-val .num { color: var(--muted); min-width: 28px; text-align: right; flex: none; }
.dbg-val .v { overflow-wrap: anywhere; }
.dbg-val.future { opacity: .4; }
.dbg-val.now { border-color: var(--accent); }

.replay-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: #2b2412ee; border: 1px solid #6b5520; color: #ffe7a8; padding: 5px 6px 5px 12px; border-radius: 8px; font-size: 12px; box-shadow: 0 6px 20px #0008; white-space: nowrap; }

/* ---------------------------------------------------------------- problems */
.problems { overflow: auto; padding: 4px 0; }
.problem { display: flex; gap: 8px; padding: 3px 12px; cursor: pointer; align-items: baseline; }
.problem:hover { background: var(--row-hover); }
.problem .lvl { font-size: 10px; font-weight: 700; text-transform: uppercase; width: 52px; flex: none; }
.problem .lvl.error { color: var(--error); }
.problem .lvl.warning { color: var(--warning); }
.problem .lvl.info { color: var(--info); }
.problems .empty { color: var(--muted); padding: 6px 12px; }

/* ---------------------------------------------------------------- inspector */
.inspector { flex: none; max-height: 45%; overflow: auto; }
.inspector:empty { display: none; }
/* on a phone the inspector lives inside the tab panel and fills it while its tab is active */
.code-panel > .inspector { flex: 1; max-height: none; min-height: 0; background: var(--panel); }
.inspector.tab-hidden { display: none; }
.insp { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.insp h3 { margin: 0; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.insp .desc { color: var(--muted); }
.insp table { width: 100%; border-collapse: collapse; font-size: 12px; }
.insp th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 4px; border-bottom: 1px solid var(--border); }
.insp td { padding: 3px 4px; border-bottom: 1px solid var(--row-line); vertical-align: middle; }
.insp td.mono, .insp .mono { font-family: var(--mono); font-size: 11.5px; }
.insp td input { width: 100%; font: 11.5px var(--mono); }
.insp .row { display: flex; align-items: center; gap: 8px; }
.insp .status { font-size: 11px; color: var(--muted); }
.insp .status.bad { color: var(--error); }
.insp .msgs { margin: 0; padding-left: 16px; color: var(--error); }
.insp .msgs li.warning { color: var(--warning); }
/* a Function node's parameters: one row per parameter (grip, type, name, remove) */
.params-edit { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.pe-title { font-size: 12px; color: var(--muted); font-weight: 500; }
.pe-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; align-self: stretch; }
.pe-row { display: flex; align-items: center; gap: 6px; border-radius: 6px; }
.pe-row.dragging { background: var(--row-line); box-shadow: 0 2px 8px var(--shadow); }
.pe-grip { flex: none; width: 14px; color: var(--muted); cursor: grab; user-select: none; touch-action: none; text-align: center; letter-spacing: -3px; }
.pe-row.dragging .pe-grip { cursor: grabbing; }
.pe-row input { min-width: 0; font: 11.5px var(--mono); padding: 3px 6px; }
.pe-row .pe-type { flex: 3 1 0; }
.pe-row .pe-name { flex: 2 1 0; }
.pe-row input.bad, .pin-rename.bad { border-color: var(--error); outline-color: var(--error); }
.pe-del { flex: none; padding: 2px 7px; font-size: 11px; line-height: 1.4; }
/* the Classes dialog: name and colour, then a field table like the parameter list (plus a default) */
.class-dialog .dsl-wrap { grid-template-columns: 200px minmax(0, 1fr) minmax(0, 340px); }
/* one height for both tabs, so switching between Visual and Text doesn't resize the dialog (its buttons stay put) */
.class-dialog .dsl-wrap { height: 470px; grid-template-rows: minmax(0, 1fr); }
.class-dialog .custom-side, .class-dialog .dsl-ref { max-height: none; min-height: 0; }
.class-dialog #class-edit { overflow: auto; min-height: 0; }
.class-dialog .custom-edit { gap: 10px; }
.ce-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ce-head label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.ce-name input { width: 200px; font: 13px var(--mono); padding: 4px 8px; }
.ce-name input.bad { border-color: var(--error); }
.ce-color input { width: 34px; height: 26px; padding: 1px; border-radius: 5px; cursor: pointer; }
.ce-uses { font-size: 12px; }
.class-dialog .params-edit { align-self: stretch; }
.ce-cols { display: grid; grid-template-columns: 14px 3fr 2fr 2fr 28px; gap: 6px; align-self: stretch; }
.ce-row .ce-default { flex: 2 1 0; }
.class-head { display: flex; align-items: center; gap: 14px; }
.class-intro { margin: 0; font-size: 13px; }
/* one line that changes with the tab (what to do / the syntax): the same height in both, so nothing moves */
.class-hint { margin: -4px 0 0; font-size: 12px; min-height: 1.6em; }
.class-hint code { font: 11.5px var(--mono); padding: 1px 5px; border-radius: 4px; background: var(--field); color: var(--text); }
/* Text: every class in one editor, across the list and form columns */
.class-dialog.text-mode .class-text { grid-column: 1 / span 2; }
.class-text { min-height: 0; }
.class-text .dsl-editor { flex: 1; min-height: 0; }
#class-src { height: 100%; resize: none; }
.class-text .custom-errors { flex: none; max-height: 6.5em; overflow: auto; }
.dsl-bad-line { text-decoration: wavy underline var(--error); text-underline-offset: 3px; }
/* the line keeps its space while empty: the buttons under it don't move when it appears */
.class-changes { font-size: 12px; color: var(--muted); min-height: 1.5em; }
.class-changes .warn { color: var(--error); }
.class-preview { max-height: 400px; overflow: auto; border-radius: 6px; background: var(--code-bg); font-size: 11.5px; }
.class-preview .empty { padding: 10px; color: var(--muted); }
.cl-none { padding: 8px; font-size: 12px; }
.pe-msg { font-size: 11px; color: var(--error); }
.pe-msg:empty { display: none; }

/* ---------------------------------------------------------------- dialogs */
.dialog { background: var(--panel); color: var(--text); border: 1px solid var(--overlay-border); border-radius: 10px; padding: 0; width: min(1000px, 94vw); box-shadow: 0 20px 60px var(--shadow); }
.dialog::backdrop { background: var(--backdrop); }
.dialog-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.dialog h2 { margin: 0; font-size: 16px; }
.dialog h3 { margin: 6px 0 2px; font-size: 13px; }
.muted { color: var(--muted); margin: 0; }
.dsl-wrap { display: grid; grid-template-columns: 1fr 300px; gap: 12px; }
#custom-src { height: 420px; font: 12px/1.5 var(--mono); resize: vertical; white-space: pre; tab-size: 2; }
/* custom nodes: the list of nodes | the selected one's definition | the syntax reference */
.custom-dialog { width: min(1180px, 96vw); }
.custom-dialog .dsl-wrap { grid-template-columns: 220px minmax(0, 1fr) 280px; }
.custom-side { display: flex; flex-direction: column; gap: 6px; min-height: 0; max-height: 470px; }
.custom-new { justify-content: center; }
.custom-list { display: flex; flex-direction: column; gap: 2px; overflow: auto; border: 1px solid var(--border); border-radius: 7px; padding: 4px; flex: 1; min-height: 80px; background: var(--code-bg); }
.cl-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 6px 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; }
.cl-item:hover { background: var(--hover-bg); }
.cl-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.cl-item .swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.cl-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.cl-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl-sub { font: 10.5px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cl-flag { flex: none; color: var(--accent); font-size: 10px; }
/* unsaved: a filled dot, like an editor tab with changes */
.cl-flag.unsaved { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.cl-flag.bad { color: var(--error); font-weight: 700; font-size: 12px; }
.custom-edit { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
/* the definition: a transparent textarea over its highlighted copy (same font, padding and scroll) */
.dsl-editor { position: relative; background: var(--field); border: 1px solid var(--border); border-radius: 5px; }
.dsl-editor:focus-within { border-color: var(--accent); }
.dsl-editor[hidden] { display: none; }
.dsl-hl, .dsl-editor textarea { margin: 0; padding: 8px 10px; font: 12px/1.5 var(--mono); tab-size: 2; white-space: pre; letter-spacing: 0; word-spacing: 0; }
.dsl-hl { position: absolute; inset: 0; overflow: hidden; pointer-events: none; color: var(--text); }
.dsl-editor textarea { position: relative; display: block; width: 100%; border: none; background: transparent; color: transparent; caret-color: var(--text); }
.dsl-editor textarea::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); color: transparent; }
.dsl-ph { color: var(--tok-fn); }
.dsl-code { color: var(--text); }
.dsl-bad { color: var(--error); text-decoration: wavy underline; text-underline-offset: 3px; }
.dsl-color { box-shadow: inset 0 -2px 0 var(--swatch); }
/* a live preview of the node being edited */
.custom-preview { position: relative; height: 170px; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; margin-bottom: 4px; }
.custom-preview .pv-viewport { position: absolute; inset: 0; pointer-events: none; }
/* an unwired node is fine here: no error state */
.custom-preview .diag, .custom-preview .node-head .err, .custom-preview .node-head .warn, .custom-preview .node-head .badge.ovl { display: none; }
.custom-preview .node.has-error { border-color: var(--node-border); }
.custom-preview .node { cursor: default; }
.pv-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 12px; color: var(--muted); font-size: 12px; background: var(--canvas); }
.custom-empty { color: var(--muted); font-size: 13px; padding: 24px 12px; border: 1px dashed var(--border); border-radius: 8px; line-height: 1.6; }
.custom-empty .link-btn { border: none; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.custom-status { font-size: 12px; }
.danger-text { color: var(--error); }
.dsl-ref { font-size: 12px; color: var(--muted); overflow: auto; max-height: 440px; }
.dsl-ref pre { font: 11px/1.5 var(--mono); background: var(--code-bg); padding: 8px; border-radius: 6px; color: var(--text); overflow: auto; }
.dsl-ref p { margin: 4px 0; }
.dsl-ref select { max-width: 180px; }
.custom-errors { color: var(--error); font: 12px var(--mono); white-space: pre-wrap; }
.custom-errors.ok { color: var(--ok-text); }
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }
/* questions and messages (ask.js), in place of the browser's confirm() / alert() / prompt() */
.ask-dialog { width: min(440px, calc(100vw - 32px)); }
.ask { padding: 18px 20px 16px; display: flex; flex-direction: column; gap: 10px; }
.ask-body { display: flex; flex-direction: column; gap: 8px; line-height: 1.5; }
.ask-body p { margin: 0; overflow-wrap: anywhere; }
.ask-body .ask-more { color: var(--muted); }
.ask-actions { justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.ask-copy { display: flex; gap: 6px; }
.ask-copy input { flex: 1; min-width: 0; font: 12px var(--mono); }
button.primary.danger { background: var(--error); border-color: color-mix(in srgb, var(--error) 80%, #000); color: #fff; }
button.primary.danger:not(:disabled):hover { background: color-mix(in srgb, var(--error) 88%, #000); }
.ask-dialog[open] { animation: ask-in .14s ease-out; }
.ask-dialog[open]::backdrop { animation: ask-fade .14s ease-out; }
@keyframes ask-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes ask-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ask-dialog[open], .ask-dialog[open]::backdrop { animation: none; } }
/* Help: topics down the side, one at a time; a fixed height so the box doesn't jump between topics */
.help-dialog { width: min(760px, 94vw); }
.help { display: flex; flex-direction: column; height: min(540px, 86vh); }
.help-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 10px 18px; border-bottom: 1px solid var(--border); flex: none; }
.help-x { padding: 6px; color: var(--muted); }
.help-x:hover { color: var(--text); }
.help-main { display: flex; flex: 1; min-height: 0; }
.help-nav { display: flex; flex-direction: column; gap: 2px; padding: 10px 8px; border-right: 1px solid var(--border); flex: none; width: 170px; background: var(--panel-2); }
.help-tab { text-align: left; border: none; background: transparent; color: var(--muted); padding: 8px 10px; border-radius: 6px; font-weight: 500; position: relative; }
.help-tab:not(:disabled):hover { background: var(--hover-bg); color: var(--text); }
.help-tab[aria-selected="true"], .help-tab[aria-selected="true"]:not(:disabled):hover { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); }
.help-tab[aria-selected="true"]::before { content: ''; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 2px; background: var(--accent); }
.help-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.help-pane { flex: 1; min-width: 0; overflow: auto; padding: 16px 20px 20px; line-height: 1.55; }
.anim-ready .help-pane:not([hidden]) { animation: tab-enter .18s ease-out; }
.help-pane > :first-child { margin-top: 0; }
.help-lead { margin: 0 0 14px; color: var(--muted); }
.help-pane p { margin: 0 0 12px; }
.help-pane h3 { margin: 16px 0 6px; font-size: 13px; }
.help-pane h3:first-child { margin-top: 0; }
.help ul { margin: 0; padding-left: 18px; }
.help li { margin: 5px 0; }
.help-list { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; }
.help-list dt { font-weight: 600; }
.help-list dd { margin: 0; color: var(--text); }
.help-keys { border-collapse: collapse; width: 100%; }
.help-keys th { text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 14px 0 6px; }
.help-keys tr:first-child th { padding-top: 0; }
.help-keys td { padding: 5px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.help-keys td:first-child { white-space: nowrap; padding-right: 24px; color: var(--muted); width: 1%; }
kbd { display: inline-block; min-width: 1.6em; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--panel-2); color: var(--text); font: 11.5px/1.5 var(--mono); text-align: center; }
/* phone: the topics become a scrolling row above the text */
@media (max-width: 640px) {
  .help { height: min(640px, 88vh); }
  .help-main { flex-direction: column; }
  .help-nav { flex-direction: row; width: auto; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 6px 8px; scrollbar-width: none; }
  .help-tab { white-space: nowrap; flex: none; }
  .help-tab[aria-selected="true"]::before { left: 10px; right: 10px; top: auto; bottom: 2px; width: auto; height: 2px; }
  .help-list { grid-template-columns: 1fr; gap: 2px; }
  .help-list dd { margin-bottom: 10px; }
  .help-pane { padding: 14px 16px 18px; }
}

/* The palette can be closed (Nodes button); the canvas then takes its column. */
.layout.no-palette { --pal-col: 0px; }
/* closed: hidden (not focusable) once the column has slid shut */
.layout.no-palette .palette { visibility: hidden; border-right-color: transparent; }
.anim-ready .layout.no-palette .palette { transition: visibility 0s var(--dur), border-color 0s var(--dur); }
/* shown on the canvas only while the palette is closed */
/* go to a function: top right of the canvas */
.fn-nav { position: absolute; right: 12px; top: 10px; z-index: 5; box-shadow: 0 4px 14px var(--shadow-soft); background: var(--panel); }
.fn-nav .ico { color: var(--accent); }
.canvas-wrap:has(#debug-bar:not([hidden])) .fn-nav { display: none; }
.palette-open { position: absolute; left: 12px; top: 10px; z-index: 5; box-shadow: 0 4px 14px var(--shadow-soft); background: var(--panel); }
.layout:not(.no-palette) .palette-open { opacity: 0; transform: translateX(-10px) scale(.96); visibility: hidden; pointer-events: none; }
/* the button fades in just after the panel has closed, and out quickly when it opens */
.anim-ready .palette-open { transition: opacity .18s ease .1s, transform var(--dur) var(--ease-out) .1s, visibility 0s .1s; }
.anim-ready .layout:not(.no-palette) .palette-open { transition: opacity .1s ease, transform .1s ease, visibility 0s .1s; }
.hint-touch { display: none; }
@media (max-width: 1100px) {
  .layout { --pal-w: 170px; --side-w: 360px; }
}
/* Phones: the palette is a drawer over the canvas, closed by default */
@media (max-width: 800px) {
  .layout, .layout.no-palette { grid-template-columns: 1fr; grid-template-rows: 1fr var(--sheet, 45%); position: relative; }
  /* the bottom panel is a sheet: drag its handle to resize, tap it to expand or shrink */
  .sheet-handle {
    display: flex; justify-content: center; align-items: center; flex: none; height: 22px; margin-bottom: -6px;
    cursor: ns-resize; touch-action: none; user-select: none; outline: none;
  }
  .sheet-handle::before { content: ''; width: 40px; height: 4px; border-radius: 2px; background: var(--handle); }
  .sheet-handle:hover::before, .sheet-handle:focus-visible::before, .sheet-handle.dragging::before { background: var(--accent); }
  .problems-panel { max-height: 25%; }
  .palette {
    position: absolute; z-index: 20; left: 0; top: 0; bottom: 0; width: min(300px, 85vw);
    box-shadow: 4px 0 24px var(--shadow);
  }
  .palette > * { width: auto; }
  /* the drawer slides out when closed, and back in when opened */
  .layout.no-palette .palette { transform: translateX(-100%); box-shadow: none; }
  .anim-ready .palette { transition: transform var(--dur) var(--ease-out), visibility 0s; }
  .anim-ready .layout.no-palette .palette { transition: transform var(--dur) var(--ease-out), visibility 0s var(--dur), box-shadow 0s var(--dur); }
  .palette-item { padding: 9px 10px; cursor: pointer; }
  .hint-desktop { display: none; }
  .hint-touch { display: inline; }
  .side { border-left: none; border-top: 1px solid var(--border); }
  .side-resize { display: none; }
  .dsl-wrap, .custom-dialog .dsl-wrap { grid-template-columns: 1fr; }
  .class-dialog.text-mode .class-text { grid-column: auto; }
  .class-dialog .dsl-wrap { height: auto; grid-template-rows: none; }
  #class-src { height: 300px; }
  .custom-side { max-height: 200px; }
  #custom-src { height: 300px; }
  /* compact toolbar: buttons show only their icon and the rows wrap, so every control stays reachable */
  .topbar { gap: 10px; padding: 6px 8px; align-items: flex-start; }
  .brand { font-size: 0; gap: 0; margin-top: 6px; padding-right: 0; margin-right: 0; border-right: none; align-self: flex-start; }
  .toolbar { flex-wrap: wrap; min-width: 0; row-gap: 6px; }
  .toolbar .sep { display: none; }
  .toolbar .tb { font-size: 0; gap: 0; padding: 7px 10px; }
  .target-label { display: none; }
  /* phones have the language switch in the header; the code panel doesn't repeat it */
  #code-lang { display: none; }
  .select-ico select { width: 50px; padding-right: 4px; color: transparent; }
  .select-ico select option { color: var(--text); }
}
@media (prefers-reduced-motion: reduce) { :root { --dur: 0s; } .tab-enter { animation: none !important; } }

/* nodes the current target language can't generate */
.palette-item.unsupported, .menu-item.unsupported { opacity: .45; }
.palette-item.unsupported .tag { color: var(--warning); }

/* ---------------------------------------------------------------- run (JavaScript) */
/* in a short panel the whole run view scrolls; the output keeps a usable minimum height */
.run { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; background: var(--code-bg); }
.run-form { flex: none; }
.run-form { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.run-row { display: flex; align-items: center; gap: 8px; }
.run-row label { width: 132px; flex: none; color: var(--muted); font: 11.5px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-row label .ty { color: var(--tok-type); }
.run-row input, .run-row select, .run-row textarea { flex: 1; min-width: 0; font: 12px var(--mono); }
.run-row textarea { resize: vertical; }
.run-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.run-hint { color: var(--muted); font-size: 11px; }
.run-unsupported { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 20px 16px; max-width: 420px; }
.run-unsupported p { margin: 0; color: var(--text); line-height: 1.5; }
.run-unsupported .run-hint { color: var(--muted); }
.run-ce { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.run-ce[hidden] { display: none; }
.run-ce code { font-family: var(--mono); font-size: 0.92em; }
#btn-godbolt { display: inline-flex; align-items: center; gap: 6px; }
#btn-godbolt .ico { width: 14px; height: 14px; }
.run-unsupported-icon { width: 28px; height: 28px; color: var(--muted); }
.tab.unavailable:not(.active) .tab-icon { color: var(--muted); }
.run-out { flex: 1; min-height: 120px; overflow: auto; padding: 8px 12px; font: 12px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; }
.run-out .empty { color: var(--muted); font-family: var(--sans); }
.run-out .call { color: var(--muted); margin-top: 6px; }
.run-out .call:first-child { margin-top: 0; }
.run-out .warn { color: var(--warning); }
.run-out .error { color: var(--error); }
.run-out .meta { color: var(--muted); font-style: italic; }
.run-out .ret { color: var(--ok-text); }

/* ---------------------------------------------------------------- light theme
   html[data-theme] is set before the page draws (inline script in index.html):
   the saved choice, or the system setting when the choice is "system". */
:root[data-theme="light"] {
  --bg: #eceef2;
  --panel: #f7f8fa;
  --panel-2: #eef0f4;
  --border: #d3d8e0;
  --text: #1e2430;
  --muted: #5d6676;
  --accent: #1f6fd6;
  --error: #d42f2f;
  --warning: #a86a00;
  --info: #1f72c4;
  --node-bg: #fffffff2;
  --node-border: #c6ccd6;
  --exec: #4a5263;
  --field: #ffffff;
  --hover-bg: #e3e7ed;
  --hover-border: #b4bccb;
  --primary: #2367d1;
  --primary-hover: #1c5bbd;
  --code-bg: #ffffff;
  --code-inline: #e9ecf1;
  --line-num: #a3aab6;
  --row-hover: #1e243008;
  --row-line: #1e24300d;
  --node-divider: #1e243014;
  --canvas: #e6e9ee;
  --grid-dot: #c4cad4;
  --node-selected: #1f6fd6;
  --pin-label: #3a4252;
  --pin-hole: #ffffff;
  --pin-exec-off: #a3aab6;
  --pin-drop: #1f6fd655;
  --unresolved: #a55d00;
  --wire-glow: #1f6fd6;
  --overlay-border: #c6ccd6;
  --backdrop: #1e243055;
  --shadow: #1e243033;
  --shadow-soft: #1e243022;
  --handle: #b4bccb;
  --ok: #1f9d5c;
  --ok-text: #1b8049;
  --bind-bg: #dcf1e2;
  --bind-text: #1d6b37;
  --tok-kw: #8a2fc4;
  --tok-type: #2456c2;
  --tok-str: #2e7a1e;
  --tok-num: #c04d16;
  --tok-com: #8a929f;
  --tok-pre: #0b7894;
  --tok-fn: #94600a;
  color-scheme: light;
}
/* node headers: a flat pastel of the node's colour with dark text in the same hue
   (dark mode keeps the strong gradient) */
:root[data-theme="light"] .node-head {
  --head-ink: color-mix(in oklab, var(--head) 50%, #0d1118);
  background: color-mix(in oklab, var(--head) 45%, #fff);
  color: var(--head-ink);
}
:root[data-theme="light"] .node-head .badge { background: #ffffffb3; color: var(--head-ink); }
:root[data-theme="light"] .node-head .badge.unresolved { color: var(--unresolved); }
:root[data-theme="light"] .node-head .badge.amb { background: var(--error); color: #fff; }
/* resolution-step phases and the replay banner: light chips with dark text */
:root[data-theme="light"] .phase-overload { background: #ece4fb; color: #5b2fa6; }
:root[data-theme="light"] .phase-explicit { background: #fbecd6; color: #7a4a0c; }
:root[data-theme="light"] .phase-return { background: #fbe1e1; color: #8f2626; }
:root[data-theme="light"] .phase-deduce { background: #dcebfb; color: #1c4f86; }
:root[data-theme="light"] .phase-convert { background: #e3e9f0; color: #34495e; }
:root[data-theme="light"] .phase-infer { background: #d8f2ee; color: #16645b; }
:root[data-theme="light"] .phase-literal { background: #f2f2cf; color: #5f5f12; }
:root[data-theme="light"] .phase-default { background: #f1e6da; color: #6b4b2a; }
:root[data-theme="light"] .phase-concept { background: #e6e9ee; color: #3d4452; }
:root[data-theme="light"] .phase-unresolved { background: #fbedc9; color: #7a5a0c; }
:root[data-theme="light"] .replay-banner { background: #fff6dfee; border-color: #e5c573; color: #6b4d05; }
/* theme button: shows the icon of the current choice */
#btn-theme .ico { display: none; }
#btn-theme[data-pref="system"] .theme-system,
#btn-theme[data-pref="light"] .theme-light,
#btn-theme[data-pref="dark"] .theme-dark { display: block; }

/* short status messages (link copied, shared graph opened) */
.toast {
  position: fixed; left: 50%; bottom: 20px; z-index: 100; max-width: min(520px, calc(100vw - 32px));
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--overlay-border); border-radius: 8px;
  padding: 9px 14px; box-shadow: 0 8px 24px var(--shadow); font-size: 13px; text-align: center;
  transition: opacity .18s ease, transform var(--dur) var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
