:root {
  --accent: #00979c;
  --accent-strong: #00b3b9;
  --accent-ink: #ffffff;
  --bg: #1e2326;
  --bg-2: #171b1d;
  --bg-3: #262c30;
  --bg-hover: #2f373c;
  --line: #343c41;
  --text: #dfe5e8;
  --text-dim: #93a0a7;
  --error: #ff6b6b;
  --error-bg: rgba(255, 107, 107, 0.13);
  --warn: #f2c14e;
  --warn-bg: rgba(242, 193, 78, 0.10);
  --ok: #4cc38a;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", "Fira Code", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, sans-serif;
  /* syntax */
  --cm-keyword: #c792ea;
  --cm-type: #4fc1ff;
  --cm-builtin: #4ec9b0;
  --cm-atom: #f78c6c;
  --cm-number: #f78c6c;
  --cm-string: #c3e88d;
  --cm-comment: #6a7a83;
  --cm-meta: #d19a66;
  --cm-def: #82aaff;
  --cm-sel: rgba(0, 151, 156, 0.30);
  --cm-activeline: rgba(255, 255, 255, 0.035);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-2: #f3f5f6;
  --bg-3: #e9edef;
  --bg-hover: #dde3e6;
  --line: #d3dade;
  --text: #1f2a30;
  --text-dim: #5d6b73;
  --error: #c62828;
  --error-bg: rgba(198, 40, 40, 0.09);
  --warn: #9a6700;
  --warn-bg: rgba(191, 135, 0, 0.10);
  --ok: #1a7f4b;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  --cm-keyword: #8e24aa;
  --cm-type: #00639a;
  --cm-builtin: #00797d;
  --cm-atom: #b4490b;
  --cm-number: #b4490b;
  --cm-string: #2e7d32;
  --cm-comment: #7d8b92;
  --cm-meta: #9c5a00;
  --cm-def: #1a55c4;
  --cm-sel: rgba(0, 151, 156, 0.22);
  --cm-activeline: rgba(0, 0, 0, 0.035);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--sans);
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
kbd { font: 11px var(--mono); color: var(--text-dim); margin-left: auto; padding-left: 24px; }
.spacer { flex: 1; }
.muted { color: var(--text-dim); font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: 0.2px; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; }
.brand svg rect { fill: var(--accent); stroke: none; }
.brand svg .pins { stroke: var(--accent); }
.brand svg text { fill: #fff; stroke: none; font: bold 12px var(--mono); text-anchor: middle; }
.tool-group { display: flex; align-items: center; gap: 8px; }
.round {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  border: none;
  transition: background 0.15s, transform 0.08s;
}
.round:hover:not(:disabled) { background: var(--accent-strong); }
.round:active:not(:disabled) { transform: scale(0.94); }
.round.busy { animation: pulse 1s ease-in-out infinite; }
#btn-stop { background: var(--bg-3); color: var(--text); border: 1px solid var(--line); }
#btn-stop:hover:not(:disabled) { background: var(--bg-hover); }
@keyframes pulse { 50% { opacity: 0.55; } }

.pill-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px 6px 10px;
  max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pill-btn:hover { background: var(--bg-hover); }
.pill-btn svg { width: 18px; height: 18px; flex: none; }
.text-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; color: var(--text);
}
.text-btn:hover:not(:disabled) { background: var(--bg-hover); }
.text-btn.attention { border-color: var(--accent); color: var(--accent-strong); box-shadow: 0 0 0 2px rgba(0, 151, 156, 0.25); }
.icon-btn { background: none; border: none; color: var(--text-dim); padding: 4px; border-radius: 4px; display: grid; place-items: center; }
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.icon-btn svg { width: 16px; height: 16px; }

.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-dim); flex: none; }
.status-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(76, 195, 138, 0.2); }
.status-dot.warn { background: var(--warn); }
.status-dot.off { background: var(--line); }
.status-dot.busy { background: var(--accent-strong); animation: pulse 0.8s infinite; }

/* menus */
.menus { display: flex; gap: 2px; }
.menu { position: relative; }
.menu-btn { background: none; border: none; padding: 6px 10px; border-radius: 6px; color: var(--text); }
.menu-btn:hover, .menu.open .menu-btn { background: var(--bg-hover); }
.menu-list {
  display: none; position: absolute; right: 0; top: calc(100% + 4px); z-index: 50;
  min-width: 250px; max-height: 70vh; overflow: auto;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 5px;
}
.menu.open .menu-list { display: block; }
.menu-list button {
  display: flex; align-items: center; width: 100%; text-align: left;
  background: none; border: none; padding: 7px 10px; border-radius: 5px; color: var(--text);
}
.menu-list button:hover { background: var(--accent); color: var(--accent-ink); }
.menu-list button:hover kbd { color: inherit; }
.menu-list hr { border: none; border-top: 1px solid var(--line); margin: 5px 4px; }
.menu-list .group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); padding: 8px 10px 3px; }
.menu-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 10px; }
.menu-field select { background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; }

/* progress */
.progress { height: 3px; background: transparent; position: relative; flex: none; }
.progress div { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent-strong); transition: width 0.15s; }
.progress.indeterminate div { width: 30%; animation: indet 1.1s ease-in-out infinite; }
@keyframes indet { from { left: -30%; } to { left: 100%; } }

.banner {
  padding: 9px 16px; background: var(--warn-bg); color: var(--text);
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.banner b { color: var(--warn); }
.banner a { color: var(--accent-strong); }

/* ---------- main layout ---------- */
main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editor-pane { flex: 1; display: flex; flex-direction: column; min-height: 80px; }
.tabs-row { display: flex; align-items: stretch; background: var(--bg-2); border-bottom: 1px solid var(--line); flex: none; }
.tabs {
  display: flex; align-items: stretch; background: var(--bg-2);
  overflow-x: auto; flex: 1; min-width: 0;
  scrollbar-width: thin;
}
.tabs .blocks-label { display: flex; align-items: center; padding: 0 14px; font-size: 13px; color: var(--text-dim); }
.tab {
  display: flex; align-items: center; gap: 6px; padding: 7px 10px 7px 14px;
  border: none; border-right: 1px solid var(--line); background: transparent;
  color: var(--text-dim); white-space: nowrap; font-size: 13px;
  border-top: 2px solid transparent;
}
.tab:hover { background: var(--bg-3); color: var(--text); }
.tab.active { background: var(--bg); color: var(--text); border-top-color: var(--accent); }
.tab .close { opacity: 0; border-radius: 3px; padding: 0 3px; line-height: 1; }
.tab:hover .close, .tab.active .close { opacity: 0.7; }
.tab .close:hover { opacity: 1; background: var(--bg-hover); }
.tab .dirty { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); }
.tab-add { border: none; background: none; color: var(--text-dim); padding: 0 12px; font-size: 18px; }
.tab-add:hover { color: var(--text); background: var(--bg-3); }
.editor-host { flex: 1; min-height: 0; position: relative; }
.editor-host .CodeMirror { position: absolute; inset: 0; height: auto; }

.splitter { height: 5px; cursor: row-resize; background: var(--bg-2); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); flex: none; }
.splitter:hover, .splitter.drag { background: var(--accent); }
.bottom-pane { height: 34%; min-height: 90px; display: flex; flex-direction: column; background: var(--bg); flex: none; }
.panel-tabs { display: flex; align-items: center; gap: 2px; padding: 0 8px; background: var(--bg-2); border-bottom: 1px solid var(--line); flex: none; }
.panel-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 7px 10px 6px; color: var(--text-dim); font-size: 13px;
}
.panel-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.panel-tab:hover { color: var(--text); }
.badge { display: inline-block; min-width: 8px; height: 8px; border-radius: 50%; background: var(--accent-strong); margin-left: 4px; vertical-align: middle; }
.panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.log {
  flex: 1; overflow: auto; padding: 8px 14px; margin: 0;
  font: 13px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word;
  outline: none;
}
.log .entry { padding: 1px 0; }
.log .error { color: var(--error); }
.log .warning { color: var(--warn); }
.log .ok { color: var(--ok); }
.log .info { color: var(--text-dim); }
.log .link { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.log .link:hover { text-decoration-style: solid; }
.log .ts { color: var(--text-dim); user-select: none; }
.log .sys { color: var(--accent-strong); }
.log .rt-error { color: var(--error); font-weight: 600; }
.monitor-input {
  display: flex; gap: 8px; align-items: center; padding: 6px 10px;
  border-top: 1px solid var(--line); background: var(--bg-2); flex-wrap: wrap; flex: none;
}
.monitor-input input[type=text] {
  flex: 1; min-width: 160px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px; font-family: var(--mono); font-size: 13px;
}
.monitor-input input[type=text]:focus { outline: none; border-color: var(--accent); }
.monitor-input select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; font-size: 13px; }
.check { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-dim); user-select: none; }

.statusbar {
  display: flex; gap: 18px; align-items: center; padding: 3px 14px;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; flex: none;
  white-space: nowrap; overflow: hidden;
}
:root[data-theme="light"] .statusbar { background: #007c80; }

/* ---------- CodeMirror theme ---------- */
.CodeMirror { background: var(--bg); color: var(--text); font: 14px/1.5 var(--mono); }
.CodeMirror-gutters { background: var(--bg); border-right: 1px solid var(--line); }
.CodeMirror-linenumber { color: var(--text-dim); opacity: 0.7; padding: 0 8px 0 4px; }
.CodeMirror-cursor { border-left: 2px solid var(--accent-strong); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: var(--cm-sel); }
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: var(--cm-sel); }
.CodeMirror-activeline-background { background: var(--cm-activeline); }
.CodeMirror-matchingbracket { color: var(--accent-strong) !important; outline: 1px solid var(--accent); }
.cm-s-default .cm-keyword { color: var(--cm-keyword); }
.cm-s-default .cm-type, .cm-s-default .cm-variable-3 { color: var(--cm-type); }
.cm-s-default .cm-builtin { color: var(--cm-builtin); }
.cm-s-default .cm-atom { color: var(--cm-atom); }
.cm-s-default .cm-number { color: var(--cm-number); }
.cm-s-default .cm-string, .cm-s-default .cm-string-2 { color: var(--cm-string); }
.cm-s-default .cm-comment { color: var(--cm-comment); font-style: italic; }
.cm-s-default .cm-meta { color: var(--cm-meta); }
.cm-s-default .cm-def { color: var(--cm-def); }
.cm-s-default .cm-variable, .cm-s-default .cm-variable-2, .cm-s-default .cm-property { color: var(--text); }
.cm-s-default .cm-operator { color: var(--text); }
.cm-s-default .cm-bracket { color: var(--text-dim); }
.line-error { background: var(--error-bg); }
.line-warning { background: var(--warn-bg); }
.diag-gutter { width: 14px; }
.diag-marker { display: inline-block; width: 14px; text-align: center; font-weight: bold; cursor: help; }
.diag-marker.error { color: var(--error); }
.diag-marker.warning { color: var(--warn); }
.diag-widget {
  font: 12px var(--sans); color: var(--error); background: var(--error-bg);
  padding: 2px 10px; border-left: 3px solid var(--error); margin: 1px 0 3px;
}
.CodeMirror-foldmarker { color: var(--accent-strong); text-shadow: none; }
.CodeMirror-foldgutter-open:after, .CodeMirror-foldgutter-folded:after { color: var(--text-dim); }
.CodeMirror-dialog { background: var(--bg-3); color: var(--text); }
.CodeMirror-dialog input { color: var(--text); }
.CodeMirror-hints {
  background: var(--bg-3); border: 1px solid var(--line); box-shadow: var(--shadow);
  font: 13px var(--mono); border-radius: 6px; padding: 3px; z-index: 100;
}
.CodeMirror-hint { color: var(--text); padding: 2px 8px; border-radius: 4px; }
li.CodeMirror-hint-active { background: var(--accent); color: var(--accent-ink); }
.hint-kw { color: var(--cm-keyword); }
.hint-const { color: var(--cm-atom); }
.hint-obj { color: var(--cm-type); }
li.CodeMirror-hint-active.hint-kw, li.CodeMirror-hint-active.hint-const, li.CodeMirror-hint-active.hint-obj { color: var(--accent-ink); }

/* ---------- dialog ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0;
  background: var(--bg-3); color: var(--text); box-shadow: var(--shadow);
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 50px); }
.dialog h2 { margin: 0; padding: 16px 20px 10px; font-size: 17px; }
#dlg-body { padding: 0 20px 6px; overflow: auto; }
#dlg-body p { margin: 0 0 10px; }
#dlg-body code, #dlg-body pre { font-family: var(--mono); font-size: 12.5px; }
#dlg-body pre { background: var(--bg); padding: 10px; border-radius: 6px; overflow: auto; user-select: all; }
#dlg-body .install-log { height: 170px; overflow: auto; background: var(--bg); border-radius: 6px; padding: 8px 10px; font: 12px/1.45 var(--mono); white-space: pre-wrap; }
#dlg-body .bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin: 10px 0; }
#dlg-body .bar div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
#dlg-body input[type=text] { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; font-family: var(--mono); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }
.dlg-actions button { border-radius: 6px; padding: 7px 16px; border: 1px solid var(--line); background: var(--bg); }
.dlg-actions button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.dlg-actions button:hover:not(:disabled) { filter: brightness(1.1); }
.ref h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--accent-strong); margin: 16px 0 6px; }
.ref ul { margin: 0; padding-left: 0; list-style: none; columns: 2 260px; column-gap: 24px; }
.ref li { font: 12px/1.7 var(--mono); break-inside: avoid; }
.ref .note { font-size: 13px; color: var(--text-dim); }
.ref table { border-collapse: collapse; font-size: 13px; width: 100%; }
.ref td { padding: 3px 8px 3px 0; vertical-align: top; border-bottom: 1px solid var(--line); }

@media (max-width: 720px) {
  .toolbar { gap: 8px; padding: 6px 10px; }
  .brand span { display: none; }
  #btn-install { display: none; }
  .pill-btn { max-width: 160px; }
  .menu-list { position: fixed; left: 8px; right: 8px; top: 56px; min-width: 0; }
}

/* ================= mode switch (Code / Blocks) ================= */
.mode-switch { display: flex; margin-left: auto; padding: 4px 8px; gap: 0; align-items: center; flex: none; }
.mode-switch button {
  border: 1px solid var(--line); background: var(--bg); color: var(--text-dim);
  padding: 3px 12px; font-size: 12.5px;
}
.mode-switch button:first-child { border-radius: 6px 0 0 6px; }
.mode-switch button:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.mode-switch button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.visual-host { flex: 1; min-height: 0; display: flex; }

/* ================= graphical editor ================= */
.vis { flex: 1; display: flex; min-width: 0; min-height: 0; }
.vis-palette {
  width: 190px; flex: none; overflow-y: auto; background: var(--bg-2);
  border-right: 1px solid var(--line); padding: 8px; scrollbar-width: thin;
}
.vis-search {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 8px; font-size: 12.5px; margin-bottom: 4px;
}
.vis-search:focus { outline: none; border-color: var(--accent); }
.vis-pal-cat {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim);
  margin: 12px 2px 5px; display: flex; align-items: center; gap: 6px;
}
.vis-pal-cat::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--c); }
.vis-pal-item {
  background: var(--bg); border: 1px solid var(--line); border-left: 4px solid var(--c);
  border-radius: 6px; padding: 5px 8px; margin: 3px 0; font-size: 12.5px; cursor: grab;
  user-select: none; touch-action: none;
}
.vis-pal-item:hover { background: var(--bg-hover); }
.vis-pal-item.box { border-style: dashed; border-left-style: solid; }
.vis-ghost { position: fixed; z-index: 1000; pointer-events: none; opacity: 0.85; box-shadow: var(--shadow); width: 170px; }

.vis-canvas {
  flex: 1; position: relative; overflow: hidden; outline: none; touch-action: none;
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--line) 1px, transparent 1.2px);
}
.vis-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.vis-layer { position: absolute; left: 0; top: 0; }
.vis-wires { position: absolute; left: 0; top: 0; overflow: visible; z-index: 3; pointer-events: none; }
.vis-wire { fill: none; stroke: var(--text-dim); stroke-width: 2.2; }
.vis-wire.w-yes { stroke: var(--ok); }
.vis-wire.w-no { stroke: var(--error); }
.vis-wire.w-start { stroke: var(--accent-strong); }
.vis-wire.selected { stroke: var(--accent-strong); stroke-width: 3.5; }
.vis-wire.temp { stroke: var(--accent-strong); stroke-dasharray: 6 4; }
.vis-wire-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.vis-arrowhead { fill: var(--text-dim); }

/* blocks */
.vn {
  position: absolute; z-index: 4; min-width: 90px; max-width: 520px; width: max-content;
  background: var(--bg-3); border: 1px solid var(--line); border-left: 5px solid var(--c);
  border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); cursor: move; user-select: none;
}
.vn.top { border-style: dashed; border-left-style: solid; }
.vn.selected { outline: 2px solid var(--accent-strong); outline-offset: 1px; }
.vn.drop-ok, .vf.drop-ok { outline: 2px dashed var(--ok); outline-offset: 2px; }
.vn.has-error { border-color: var(--error); box-shadow: 0 0 0 2px var(--error-bg), 0 2px 6px rgba(0, 0, 0, 0.25); }
.vn.has-warning { border-color: var(--warn); }
.vn-body { display: flex; flex-wrap: wrap; max-width: 510px; align-items: center; gap: 4px 5px; padding: 6px 9px 7px; font-size: 13px; }
.vn-text { white-space: nowrap; color: var(--text); }
.vn-input, .vn-select, .vn-code {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 5px;
  font: 12.5px var(--mono); padding: 2px 5px; min-width: 0; cursor: text;
}
.vn-input:focus, .vn-select:focus, .vn-code:focus { outline: none; border-color: var(--accent); }
.vn-input.k-text { color: var(--cm-string); }
.vn-select { cursor: pointer; padding: 1px 2px; }
.vn-code { width: 300px; resize: horizontal; line-height: 1.4; }
.vn-issue {
  display: none; position: absolute; left: 0; top: calc(100% + 6px); z-index: 20; width: max-content; max-width: 320px;
  font-size: 12px; line-height: 1.35; padding: 4px 8px; border-radius: 5px; white-space: pre-wrap; pointer-events: none;
}
.has-error > .vn-issue { display: block; background: var(--error); color: #fff; }
.has-warning > .vn-issue { display: block; background: var(--warn); color: #222; }
.vf.has-error > .vn-issue, .vf.has-warning > .vn-issue { top: -30px; left: 8px; }

/* ports */
.port {
  position: absolute; width: 13px; height: 13px; border-radius: 50%; z-index: 6;
  background: var(--bg-3); border: 2px solid var(--text-dim);
}
.port.in { left: calc(50% - 6.5px); top: -7px; cursor: default; }
.port.out { bottom: -7px; left: calc(50% - 6.5px); cursor: crosshair; background: var(--text-dim); }
.port.out:hover { transform: scale(1.35); background: var(--accent-strong); border-color: var(--accent-strong); }
.port.p-yes { left: calc(25% - 6.5px); background: var(--ok); border-color: var(--ok); }
.port.p-no { left: calc(75% - 6.5px); background: var(--error); border-color: var(--error); }
.port-label { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); font-size: 10.5px; font-weight: 600; color: var(--text-dim); pointer-events: none; }
.port.start {
  top: 45px; left: 15px; bottom: auto; width: 16px; height: 16px; font-size: 9px; line-height: 12px; text-align: center;
  color: #fff; background: var(--accent); border-color: var(--accent);
}

/* frames: functions and loops */
.vf { position: absolute; z-index: 1; border-radius: 12px; border: 2px solid var(--line); }
.vf-function { background: color-mix(in srgb, var(--bg-2) 70%, transparent); }
.vf-loop { background: color-mix(in srgb, #e8973a 7%, var(--bg)); border-color: #e8973a; border-style: dashed; z-index: 2; }
.vf.selected { border-color: var(--accent-strong); border-style: solid; }
.vf.has-error { border-color: var(--error); }
.vf.has-warning { border-color: var(--warn); }
.vf-head {
  height: 36px; display: flex; align-items: center; gap: 5px; padding: 0 10px; cursor: move; user-select: none;
  border-bottom: 1px solid var(--line); border-radius: 10px 10px 0 0; font-size: 13px; overflow: hidden; white-space: nowrap;
  background: var(--bg-3);
}
.vf-loop .vf-head { background: color-mix(in srgb, #e8973a 18%, var(--bg-3)); border-bottom-color: #e8973a55; }
.vf-head > * { flex: none; }
.vf-kind { color: var(--text-dim); font-size: 11.5px; margin-right: 2px; }
.vf-loop .vf-kind { color: #e8973a; font-size: 16px; font-weight: bold; }
.vf-function .vf-head input.k-name { font-weight: 600; }
.vf-title { font-weight: 600; }
.vf .port.in, .vf .port.p-out { z-index: 7; }
.vf .port.in { top: -8px; }
.vf .port.p-out { bottom: -8px; }
.vf-resize {
  position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize; z-index: 5;
  background: linear-gradient(135deg, transparent 50%, var(--text-dim) 50%, var(--text-dim) 60%, transparent 60%, transparent 72%, var(--text-dim) 72%, var(--text-dim) 82%, transparent 82%);
  border-radius: 0 0 10px 0; opacity: 0.6;
}

/* canvas toolbar + hint */
.vis-tools {
  position: absolute; right: 10px; top: 10px; z-index: 30; display: flex; align-items: center; gap: 2px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 3px; box-shadow: var(--shadow);
}
.vis-tool { background: none; border: none; border-radius: 5px; padding: 3px 8px; font-size: 13px; color: var(--text); min-width: 28px; }
.vis-tool:hover:not(:disabled) { background: var(--bg-hover); }
.vis-tool.active { background: var(--accent); color: var(--accent-ink); }
.vis-sep { width: 1px; height: 18px; background: var(--line); margin: 0 3px; }
.vis-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 30; pointer-events: none;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text-dim); font-size: 12.5px;
  padding: 6px 12px; border-radius: 8px; max-width: calc(100% - 40px); text-align: center;
}

/* generated code panel */
.vis-code { width: 360px; flex: none; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--bg-2); min-width: 0; }
.vis-code-head { display: flex; align-items: center; justify-content: space-between; padding: 5px 6px 5px 12px; font-size: 12px; color: var(--text-dim); border-bottom: 1px solid var(--line); }
.vis-code-body { flex: 1; overflow: auto; padding: 6px 0; font: 12.5px/1.5 var(--mono); }
.vis-code-line { white-space: pre; padding: 0 12px; }
.vis-code-line[data-id] { cursor: pointer; }
.vis-code-line[data-id]:hover { background: var(--cm-sel); }

@media (max-width: 720px) {
  .vis-palette { width: 130px; }
  .vis-code { position: absolute; right: 0; top: 0; bottom: 0; z-index: 40; width: min(360px, 90vw); }
}

/* board switch */
.board-select {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px;
  color: var(--text); font-size: 13px; max-width: 170px;
}
.board-select.makey { border-color: #e2445c; color: #e2445c; font-weight: 600; }
.vn-port { color: #7a9b2e; font-weight: 600; }

/* native / bytecode selector in the toolbar */
.target-select {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 10px; font-size: 13px; cursor: pointer; color: var(--text);
}
.target-select:hover { background: var(--bg-hover); }
@media (max-width: 700px) { .target-select { max-width: 110px; } }

/* ================= assembler view ================= */
.asm-host { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.asm-bar { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--bg-2); font-size: 13px; }
.asm-bar label { display: flex; gap: 6px; align-items: center; color: var(--text-dim); }
.asm-bar select { background: var(--bg-3); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
.asm-info { color: var(--text-dim); margin-left: auto; }
.asm-body { flex: 1; min-height: 0; display: flex; }
.asm-list { flex: 1 1 58%; min-width: 0; overflow: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; padding: 6px 0 24px; }
.asm-map { flex: 1 1 42%; min-width: 300px; overflow: auto; border-left: 1px solid var(--line); padding: 10px 14px 24px; font-size: 13px; }
.asm-rows > div { white-space: pre; padding: 0 12px; }
.asm-addr { color: var(--text-dim); display: inline-block; width: 4.5ch; margin-right: 1.5ch; }
.asm-bytes { color: var(--text-dim); opacity: 0.75; display: inline-block; width: 15ch; overflow: hidden; vertical-align: bottom; margin-right: 1ch; }
.asm-mn { color: var(--cm-keyword); display: inline-block; min-width: 8ch; margin-right: 1ch; }
.asm-ops { color: var(--text); display: inline-block; min-width: 20ch; }
.asm-dir { color: var(--cm-meta); }
.asm-cmt, .asm-note-i { color: var(--cm-comment); margin-left: 1.5ch; }
.asm-sec { color: var(--cm-meta); font-weight: 600; margin-top: 10px; padding-top: 4px !important; border-top: 1px dashed var(--line); }
.asm-src { color: var(--cm-string); cursor: pointer; background: rgba(127, 127, 127, 0.07); margin-top: 3px; }
.asm-src:hover { background: var(--cm-sel); }
.asm-loc { color: var(--text-dim); display: inline-block; min-width: 12ch; margin-right: 1ch; }
.asm-label { color: var(--cm-def); }
.asm-func { font-weight: 700; color: var(--cm-type); margin-top: 8px; }
.asm-note { margin: 6px 12px 10px; padding: 8px 10px; border-radius: 6px; background: var(--warn-bg); font-family: var(--sans); white-space: normal; }
.asm-card { margin-bottom: 18px; }
.asm-card h3 { font-size: 13.5px; margin: 0 0 4px; }
.asm-sub { margin: 0 0 6px; color: var(--text-dim); font-size: 12.5px; }
.asm-bar-mem { display: flex; height: 38px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin: 6px 0; }
.asm-bar-mem .seg { flex-basis: 0; min-width: 3px; display: flex; flex-direction: column; justify-content: center; padding: 0 4px; overflow: hidden; border-right: 1px solid rgba(0, 0, 0, 0.25); font-size: 11px; line-height: 1.2; color: #fff; }
.asm-bar-mem .seg span, .asm-bar-mem .seg small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asm-bar-mem .seg small { opacity: 0.8; }
.seg-hdr { background: #6b7a86; } .seg-code { background: #00979c; } .seg-data { background: #b5179e; } .seg-rel { background: #8a6d3b; }
.seg-boot { background: #5c6bc0; } .seg-pt { background: #7e57c2; } .seg-part { background: #546e7a; } .seg-app { background: #455a64; }
.seg-prog { background: #e2445c; } .seg-stack { background: #f08c2e; }
.seg-free { background: repeating-linear-gradient(45deg, var(--bg-3), var(--bg-3) 6px, var(--bg-2) 6px, var(--bg-2) 12px); color: var(--text-dim) !important; }
.asm-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.asm-table th { text-align: left; color: var(--text-dim); font-weight: 500; border-bottom: 1px solid var(--line); padding: 3px 6px; }
.asm-table td { padding: 3px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.asm-table td:first-child, .asm-table td:nth-child(2) { font-family: var(--mono); white-space: nowrap; }
.asm-table .dim { color: var(--text-dim); }
.asm-steps { margin: 4px 0 0; padding-left: 20px; font-size: 12.5px; line-height: 1.5; }
.asm-steps li { margin-bottom: 4px; }
@media (max-width: 900px) {
  .asm-body { flex-direction: column; overflow: auto; }
  .asm-list { flex: none; max-height: 60vh; }
  .asm-map { border-left: none; border-top: 1px solid var(--line); min-width: 0; flex: none; }
}
