/* LogicLinks Companion
   Warm monochrome UI. The one strong colour, --hi, means "this signal is 1". */

:root {
  --bg: #efede8;
  --panel: #f8f7f4;
  --raised: #ffffff;
  --sunken: #e9e7e1;
  --canvas: #f4f2ee;
  --canvas-dot: #d6d2c8;
  --border: #dedad1;
  --border-strong: #c6c1b5;
  --text: #1f1e1b;
  --text-2: #5a5750;
  --text-3: #8a867c;
  --hover: rgba(31, 30, 27, 0.055);
  --press: rgba(31, 30, 27, 0.1);

  --ink: #1f1e1b;          /* primary buttons, selection */
  --on-ink: #f8f7f4;

  --hi: #e8590c;           /* HIGH / live signal */
  --hi-soft: #fbe3d4;
  --hi-text: #b8440a;
  --lo: #b9b4a8;           /* LOW wire */
  --in: #2d7a4a;           /* input role */
  --in-soft: #dcebdf;
  --out: #1f1e1b;          /* output role */
  --sw: #a87a00;           /* switch channel trace */
  --ok: #2d7a4a;
  --warn: #a66300;
  --warn-soft: #f7ead2;
  --err: #c0362c;
  --err-soft: #f6dcd8;

  --node: #ffffff;
  --node-head: #f3f1ec;
  --node-border: #cfcabe;
  --wire-lo: #c4bfb3;

  --shadow-1: 0 1px 2px rgba(40, 35, 25, 0.06);
  --shadow-2: 0 2px 6px rgba(40, 35, 25, 0.08), 0 12px 32px rgba(40, 35, 25, 0.12);

  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", ui-monospace, Menlo, Consolas, monospace;

  --r-sm: 4px;
  --r: 6px;
  --r-lg: 9px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131211;
    --panel: #1b1a18;
    --raised: #24221f;
    --sunken: #151413;
    --canvas: #171614;
    --canvas-dot: #2c2a26;
    --border: #2c2a26;
    --border-strong: #3d3a35;
    --text: #ebe9e4;
    --text-2: #a7a39a;
    --text-3: #736f67;
    --hover: rgba(235, 233, 228, 0.06);
    --press: rgba(235, 233, 228, 0.11);
    --ink: #ebe9e4;
    --on-ink: #161514;
    --hi: #ff8133;
    --hi-soft: #3a2416;
    --hi-text: #ff9a57;
    --lo: #4a4741;
    --in: #6cc28a;
    --in-soft: #1e2e23;
    --out: #ebe9e4;
    --sw: #e0b23a;
    --ok: #6cc28a;
    --warn: #e0a440;
    --warn-soft: #33281a;
    --err: #ff7a6e;
    --err-soft: #3a1d1a;
    --node: #211f1d;
    --node-head: #282623;
    --node-border: #3d3a35;
    --wire-lo: #45423c;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.35), 0 12px 32px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #131211;
  --panel: #1b1a18;
  --raised: #24221f;
  --sunken: #151413;
  --canvas: #171614;
  --canvas-dot: #2c2a26;
  --border: #2c2a26;
  --border-strong: #3d3a35;
  --text: #ebe9e4;
  --text-2: #a7a39a;
  --text-3: #736f67;
  --hover: rgba(235, 233, 228, 0.06);
  --press: rgba(235, 233, 228, 0.11);
  --ink: #ebe9e4;
  --on-ink: #161514;
  --hi: #ff8133;
  --hi-soft: #3a2416;
  --hi-text: #ff9a57;
  --lo: #4a4741;
  --in: #6cc28a;
  --in-soft: #1e2e23;
  --out: #ebe9e4;
  --sw: #e0b23a;
  --ok: #6cc28a;
  --warn: #e0a440;
  --warn-soft: #33281a;
  --err: #ff7a6e;
  --err-soft: #3a1d1a;
  --node: #211f1d;
  --node-head: #282623;
  --node-border: #3d3a35;
  --wire-lo: #45423c;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.35), 0 12px 32px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }

.hidden { display: none !important; }

.mono { font-family: var(--font-mono); font-size: 0.94em; }
.dim { color: var(--text-3); }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

.ic {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic .fill, svg .fill { fill: currentColor; stroke: none; }
span.ic { display: inline-block; }

kbd {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-3);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Buttons & controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--raised);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
}
.btn:hover:not(:disabled) { background: var(--panel); border-color: var(--text-3); }
.btn:active:not(:disabled) { background: var(--sunken); }
.btn:disabled { opacity: 0.45; box-shadow: none; }

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-ink);
}
.btn-primary:hover:not(:disabled) { background: var(--ink); border-color: var(--ink); opacity: 0.88; }
.btn-primary:active:not(:disabled) { background: var(--ink); opacity: 0.8; }

.btn-quiet {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--text-2);
}
.btn-quiet:hover:not(:disabled) { background: var(--hover); border-color: transparent; color: var(--text); }

.btn-danger { color: var(--err); }
.btn-quiet.btn-danger:hover:not(:disabled) { color: var(--err); background: var(--err-soft); }

.btn-sm { height: 26px; padding: 0 8px; font-size: 12.5px; gap: 5px; }
.btn-sm .ic { width: 14px; height: 14px; }

.btn.is-active {
  background: var(--hi-soft);
  border-color: var(--hi);
  color: var(--hi-text);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--text-2);
}
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.icon-btn:active:not(:disabled) { background: var(--press); }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn .ic { width: 15px; height: 15px; }

select, .input {
  height: 26px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--raised);
  padding: 0 6px;
  font-size: 12.5px;
}
select { padding-right: 4px; }
.input { padding: 0 8px; height: 30px; width: 100%; font-size: 13px; }
.input:focus, select:focus { outline: 2px solid var(--ink); outline-offset: -1px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.check input { margin: 0; accent-color: var(--ink); }

.seg {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: 7px;
}
.seg-btn {
  height: 24px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
  font-size: 12.5px;
}
.seg-btn:hover:not(:disabled) { color: var(--text); }
.seg-btn.active {
  background: var(--raised);
  color: var(--text);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--border);
}
.seg-btn:disabled { opacity: 0.4; }
.seg-btn .live-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--text-3);
  vertical-align: 1px;
}
.seg-btn.active .live-dot.on { background: var(--hi); }

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-rows: 44px 1fr 24px;
  height: 100vh;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 8px;
  font-weight: 650;
  font-size: 14px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand-mark { width: 22px; height: 22px; }
.bm-solid { fill: var(--ink); }
.bm-outline { fill: none; stroke: var(--ink); stroke-width: 2.5; }
.bm-dot { fill: var(--hi); }

.menubar { display: flex; gap: 2px; }
.menu { position: relative; }
.menu-trigger {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
}
.menu-trigger:hover, .menu.open .menu-trigger { background: var(--hover); color: var(--text); }

.menu-panel {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  min-width: 250px;
  padding: 5px;
  background: var(--raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.menu.open .menu-panel { display: block; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 30px;
  padding: 0 10px 0 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  color: var(--text);
  cursor: pointer;
}
.menu-item > span:not(.ic) { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-item .ic { color: var(--text-2); }
.menu-item:hover:not(:disabled) { background: var(--hover); }
.menu-item:disabled { color: var(--text-3); cursor: default; }
.menu-item:disabled .ic { opacity: 0.5; }
.menu-item.checked .check::before {
  content: "";
  display: block;
  width: 6px;
  height: 6px;
  margin: 5px;
  border-radius: 50%;
  background: var(--text);
}
.menu-sep { height: 1px; margin: 5px 4px; background: var(--border); }
.menu-label {
  padding: 6px 10px 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
}
.menu-item.port-item { font-family: var(--font-mono); font-size: 12px; }

.titlebar-spacer { flex: 1; }

.device-bar { display: flex; align-items: center; gap: 6px; }

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  max-width: 300px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--raised);
  font-weight: 500;
  font-size: 12.5px;
  white-space: nowrap;
}
.conn-pill > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.conn-pill:hover { border-color: var(--text-3); }
.conn-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--text-3);
}
.conn-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.conn-dot.demo { background: var(--warn); }
.conn-dot.busy { background: var(--text-3); animation: pulse 0.9s ease-in-out infinite alternate; }

@keyframes pulse { from { opacity: 0.3; } to { opacity: 1; } }

.workbench {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 312px;
  min-height: 0;
}

/* ---------- Sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.side-section {
  padding: 12px 12px 14px;
  border-bottom: 1px solid var(--border);
}
.side-section.grow { flex: 1; border-bottom: 0; }

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 26px;
  margin-bottom: 6px;
}
.side-head h2 {
  margin: 0;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
}

.legend { display: flex; gap: 10px; font-size: 11px; color: var(--text-3); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.lg { display: inline-block; width: 8px; height: 8px; border-radius: 2px; }
.lg-in { background: var(--in); }
.lg-out { background: var(--out); }
.lg-hi { background: var(--hi); border-radius: 50%; }

/* Slots */

.slot-list { display: flex; flex-direction: column; gap: 2px; }

.slot {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 2px 8px;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
}
.slot:hover { background: var(--hover); }
.slot.selected { background: var(--raised); border-color: var(--border-strong); box-shadow: var(--shadow-1); }
.slot-shape {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r);
  background: var(--sunken);
  color: var(--text-2);
}
.slot-shape .ic { width: 14px; height: 14px; }
.slot.selected .slot-shape { background: var(--ink); color: var(--on-ink); }
.slot.empty .slot-shape { color: var(--text-3); }
.slot-name {
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot.empty .slot-name { color: var(--text-2); font-weight: 450; }
.slot-meta { grid-column: 2 / 4; font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-tags { display: flex; gap: 4px; }

.tag {
  display: inline-flex;
  align-items: center;
  height: 17px;
  padding: 0 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--sunken);
  color: var(--text-2);
  white-space: nowrap;
}
.tag-hw { background: var(--ink); color: var(--on-ink); }
.tag-mod { background: var(--warn-soft); color: var(--warn); }
.tag-in { background: var(--in-soft); color: var(--in); }
.tag-out { background: var(--ink); color: var(--on-ink); }
.tag-hi { background: var(--hi-soft); color: var(--hi-text); }

/* Header grid (mirrors the physical 8x3 header) */

.header-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px;
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.hpin {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 6px 0 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--raised);
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: left;
  min-width: 0;
}
.hpin:hover { border-color: var(--text-3); }
.hpin.unused { background: transparent; border-style: dashed; color: var(--text-3); }
.hpin.selected { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }

.hpin-led {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: transparent;
}
.hpin.input .hpin-led { border-color: var(--in); }
.hpin.output .hpin-led { border-color: var(--out); border-radius: 2px; }
.hpin.hi .hpin-led { background: var(--hi); border-color: var(--hi); }
.hpin.unused .hpin-led { border-style: dotted; }

.hpin-label { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.1; }
.hpin-gp { font-weight: 600; }
.hpin-name {
  font-family: var(--font-ui);
  font-size: 10px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hpin-name:empty { display: none; }


/* Switches */

.sw-block + .sw-block { margin-top: 10px; }
.sw-block-head {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-2);
  margin-bottom: 5px;
}
.sw-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }

.sw {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--raised);
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--text-2);
}
.sw:hover:not(:disabled) { border-color: var(--text-3); }
.sw:disabled { opacity: 0.45; }
.sw-track {
  position: relative;
  width: 24px;
  height: 13px;
  border-radius: 7px;
  background: var(--sunken);
  border: 1px solid var(--border-strong);
  transition: background 0.12s;
}
.sw-track::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform 0.12s, background 0.12s;
}
.sw.hi .sw-track { background: var(--hi); border-color: var(--hi); }
.sw.hi .sw-track::after { transform: translateX(11px); background: #fff; }
.sw.hi { color: var(--text); }

.side-hint { font-size: 11px; color: var(--text-3); }
.sw-name { max-width: 100%; padding: 0 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body p { margin: 0 0 8px; line-height: 1.5; }

.empty-note { font-size: 12px; color: var(--text-3); padding: 2px 2px; }

/* Hierarchy tree */

.tree { font-size: 12.5px; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding-right: 6px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.tree-row:hover { background: var(--hover); }
.tree-row.selected { background: var(--raised); box-shadow: 0 0 0 1px var(--border-strong); }
.tree-twist {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  flex: none;
  border: 0;
  padding: 0;
  background: none;
  color: var(--text-3);
}
.tree-twist .ic { width: 12px; height: 12px; transition: transform 0.1s; }
.tree-row.collapsed .tree-twist .ic { transform: rotate(-90deg); }
.tree-twist.leaf { visibility: hidden; }
.tree-icon { width: 14px; height: 14px; color: var(--text-2); }
.tree-name { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.tree-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-3); }

/* ---------- Center ---------- */

.center {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}

.center-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 8px 0 4px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.center-bar-spacer { flex: 1; }

.tabs { display: flex; align-self: stretch; }
.tab {
  position: relative;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink);
}
.tab-count { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); margin-left: 2px; }

.zoom { display: flex; align-items: center; gap: 1px; }
.zoom-readout {
  min-width: 48px;
  height: 26px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-2);
}
.zoom-readout:hover { background: var(--hover); }

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 12.5px;
  background: var(--warn-soft);
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.notice > .ic { color: var(--warn); }
.notice-text { flex: 1; min-width: 0; }
.notice-text strong { font-weight: 600; }
.notice.info { background: var(--panel); }
.notice.info > .ic { color: var(--text-2); }

.stage { position: relative; flex: 1; min-height: 80px; }

.canvas-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  background-color: var(--canvas);
  background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1.2px);
  background-size: 20px 20px;
}
.canvas-wrap.panning { cursor: grabbing; }

.schematic { display: block; width: 100%; height: 100%; user-select: none; }

.canvas-hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 11px;
  color: var(--text-3);
  pointer-events: none;
}

.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  pointer-events: none;
}
.canvas-empty > div { pointer-events: auto; max-width: 380px; padding: 20px; }
.canvas-empty .ce-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 12px;
  border-radius: 10px;
  border: 1px dashed var(--border-strong);
  color: var(--text-3);
}
.canvas-empty .ce-icon .ic { width: 20px; height: 20px; }
.canvas-empty h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.canvas-empty p { margin: 0 0 14px; color: var(--text-2); }
.canvas-empty .ce-actions { display: flex; gap: 8px; justify-content: center; }

/* Schematic nodes (SVG). Colours come from classes so themes apply. */

.n-body { fill: var(--node); stroke: var(--node-border); stroke-width: 1; }
.n-head { fill: var(--node-head); }
.n-rule { stroke: var(--node-border); stroke-width: 1; }
.n-title { fill: var(--text); font: 600 12px var(--font-ui); }
.n-sub { fill: var(--text-3); font: 10.5px var(--font-mono); }
.n-port-label { fill: var(--text-2); font: 11px var(--font-mono); }
.n-formula { fill: var(--text-2); font: 10.5px var(--font-mono); }
.n-kind { fill: var(--text-3); font: 600 9.5px var(--font-ui); letter-spacing: 0.06em; }

.node { cursor: pointer; }
.node.dragging { cursor: grabbing; }
.node:hover > .n-body { stroke: var(--text-3); }
.node.selected > .n-body { stroke: var(--ink); stroke-width: 2; }
.node.dim { opacity: 0.35; }

.node.pin .n-body { fill: var(--node); }
.node.pin.hi .n-body { fill: var(--hi-soft); stroke: var(--hi); }
.node.pin.selected.hi .n-body { stroke: var(--ink); }

.n-gp { fill: var(--text); font: 600 12px var(--font-mono); }
.n-name { fill: var(--text-2); font: 11px var(--font-ui); }

.port { fill: var(--node); stroke: var(--text-3); stroke-width: 1.5; }
.port.hi { fill: var(--hi); stroke: var(--hi); }

.led-box { fill: var(--sunken); stroke: var(--border-strong); stroke-width: 1; }
.led-text { fill: var(--text-2); font: 700 11px var(--font-mono); }
.hi > .led-box, .led.hi .led-box { fill: var(--hi); stroke: var(--hi); }
.hi > .led-text, .led.hi .led-text { fill: #fff; }
.led.toggle { cursor: pointer; }
.led.toggle:hover .led-box { stroke: var(--text); }
.locked .led.toggle { cursor: not-allowed; }

.node.effect .n-head.out-head { fill: var(--node-head); }
.node.effect.hi .n-body { stroke: var(--hi); }
.node.effect.hi.selected .n-body { stroke: var(--ink); }

.n-formula-title { fill: var(--text); font-size: 11px; }

.expand-btn { cursor: pointer; }
.expand-btn rect { fill: var(--raised); stroke: var(--border-strong); stroke-width: 1; }
.expand-btn path { stroke: var(--text-2); stroke-width: 1.6; stroke-linecap: round; fill: none; }
.expand-btn:hover rect { stroke: var(--text); }
.expand-btn:hover path { stroke: var(--text); }

/* An opened nested block: a frame the child circuit is drawn inside */
.node.nested.open > .n-body { fill: color-mix(in srgb, var(--canvas) 70%, var(--node)); stroke-dasharray: 5 4; }
.node.nested.open.selected > .n-body { stroke-dasharray: none; }
.node.open .node > .n-body { fill: var(--node); }

.wire {
  fill: none;
  stroke: var(--wire-lo);
  stroke-width: 1.6;
  transition: stroke 0.12s;
}
.wire.hi { stroke: var(--hi); stroke-width: 2; }
.wire.dim { opacity: 0.18; }
.wire.emph { stroke-width: 2.6; }

.empty-svg-text { fill: var(--text-3); font: 13px var(--font-ui); }

/* Gates table view */

.gates-view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}
.gates-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-2);
}
.gates-scroll { flex: 1; overflow: auto; }

table.grid {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}
table.grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 6px 10px;
  text-align: left;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--panel);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
table.grid td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.grid tr:hover td { background: var(--hover); }
table.grid td.v { text-align: center; width: 1%; }
table.grid th.v { text-align: center; }
table.grid .bit { display: inline-block; min-width: 18px; text-align: center; border-radius: 3px; }
table.grid .bit-1, table.grid .bit.hi { background: var(--hi-soft); color: var(--hi-text); font-weight: 700; }
table.grid .bit-0, table.grid .bit { color: var(--text-3); }
table.grid tr.circuit-break td { border-top: 1px solid var(--border-strong); }
table.grid th.sep, table.grid td.sep { border-left: 1px solid var(--border-strong); }

/* ---------- Analyzer dock ---------- */

.dock-resizer {
  height: 5px;
  margin-top: -3px;
  position: relative;
  z-index: 5;
  cursor: ns-resize;
}
.dock-resizer:hover, .dock-resizer.dragging { background: var(--border-strong); }

.dock {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  height: 260px;
  min-height: 36px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.dock.collapsed { height: 37px !important; }
.dock.collapsed .dock-body { display: none; }
.dock.collapsed .dock-title .chev { transform: rotate(-90deg); }

.dock-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 8px 0 4px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  flex: none;
}
.dock-bar { scrollbar-width: thin; }
.dock-bar::-webkit-scrollbar { height: 4px; }
.dock-title {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 8px 0 4px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  font-weight: 600;
}
.dock-title:hover { background: var(--hover); }
.dock-title .chev { width: 14px; height: 14px; color: var(--text-3); transition: transform 0.1s; }
.dock-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; flex: none; }
.dock-spacer { flex: 1; }
.dock-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--sunken);
  color: var(--text-2);
}
.status-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}
.status-chip.running { background: var(--hi-soft); color: var(--hi-text); }
.status-chip.running::before { opacity: 1; animation: pulse 0.8s ease-in-out infinite alternate; }
.status-chip.armed { background: var(--warn-soft); color: var(--warn); }

.seg-sm { padding: 1px; border-radius: 6px; flex: none; }
.seg-sm .seg-btn { height: 22px; padding: 0 9px; font-size: 12px; border-radius: 5px; }
.az-fields { display: inline-flex; align-items: center; gap: 6px; }

.field { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); }

.dock-body { position: relative; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }

.wave { display: grid; grid-template-columns: 184px 1fr; min-height: 100%; }
.wave-gutter {
  position: sticky;
  left: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  z-index: 1;
}
.wave-plot { position: relative; min-width: 0; background: var(--raised); cursor: crosshair; }
.wave-plot.panning { cursor: grabbing; }
.wave-plot canvas { display: block; }

.wave-ruler-pad { height: 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 4px; }
.gutter-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 18px;
  padding: 0 5px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font-size: 11px;
  color: var(--text-2);
}
.gutter-btn:hover { background: var(--hover); color: var(--text); }
.gutter-btn .ic { width: 12px; height: 12px; }
.wave-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 8px 0 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  white-space: nowrap;
}
.wave-row { position: relative; cursor: grab; user-select: none; }
.wave-row:hover { background: var(--hover); }
.wave-row.dragging { opacity: 0.45; }
.wave-grip { display: grid; place-items: center; width: 10px; margin: 0 -4px 0 -6px; color: var(--text-3); opacity: 0; flex: none; }
.wave-grip .ic { width: 14px; height: 14px; }
.wave-row:hover .wave-grip { opacity: 1; }
.wave-x {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-right: -4px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  opacity: 0;
  flex: none;
}
.wave-x .ic { width: 12px; height: 12px; }
.wave-row:hover .wave-x { opacity: 1; }
.wave-x:hover { background: var(--press); color: var(--text); }
.wave-drop { position: absolute; left: 4px; right: 4px; height: 2px; border-radius: 1px; background: var(--ink); pointer-events: none; }
.wave-swatch { width: 3px; height: 14px; border-radius: 2px; flex: none; }
.wave-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.wave-name .mono { font-weight: 600; }
.wave-name .alias { color: var(--text-3); margin-left: 4px; }
.wave-val {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  min-width: 16px;
  text-align: center;
  border-radius: 3px;
  color: var(--text-3);
}
.wave-val.hi { color: var(--hi-text); background: var(--hi-soft); }

.wave-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-3);
  font-size: 12.5px;
}

.popover {
  position: fixed;
  z-index: 60;
  width: 240px;
  max-height: 340px;
  overflow-y: auto;
  padding: 6px;
  background: var(--raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.pop-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px 6px; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.pop-head .links { display: flex; gap: 2px; }
.pop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 26px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 12.5px;
  cursor: pointer;
}
.pop-item:hover { background: var(--hover); }
.pop-item input { margin: 0; accent-color: var(--ink); }
.pop-group { padding: 6px 6px 2px; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); }

@container (max-width: 1180px) {
  .dock-bar .field > span:first-child { display: none; }
  .dock-bar .btn-quiet > span { display: none; }
  .dock-meta { display: none; }
}
@container (max-width: 1120px) {
  .dock-title span { display: none; }
}
@container (max-width: 900px) {
  .dock-bar .btn-sm > span { display: none; }
  .dock-title span { display: none; }
}

/* ---------- Inspector ---------- */

.inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--border);
}

.insp-head { padding: 14px 14px 12px; border-bottom: 1px solid var(--border); }
.insp-kind {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}
.insp-kind .ic { width: 13px; height: 13px; }
.insp-kind .spacer { flex: 1; }
.insp-title-row { display: flex; align-items: center; gap: 8px; }

.title-edit {
  flex: 1;
  min-width: 0;
  height: 30px;
  margin-left: -7px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.title-edit:hover { border-color: var(--border); }
.title-edit:focus { border-color: var(--ink); background: var(--raised); outline: none; }
.title-edit::placeholder { color: var(--text); opacity: 1; }
.title-edit:focus::placeholder { color: var(--text-3); }

.insp-sub { margin-top: 2px; font-size: 12px; color: var(--text-2); }

.insp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.insp-section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.insp-section:last-child { border-bottom: 0; }
.insp-section h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
}
.insp-section h3 .count { font-family: var(--font-mono); font-weight: 500; color: var(--text-3); letter-spacing: 0; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; font-size: 12.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.formula {
  padding: 8px 10px;
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  max-height: 160px;
  overflow-y: auto;
}

.plist { display: flex; flex-direction: column; gap: 1px; }
.prow {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 0 4px 0 6px;
  border-radius: 5px;
}
.prow:hover { background: var(--hover); }
.prow.clickable { cursor: pointer; }
.val {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 18px;
  border-radius: 3px;
  background: var(--sunken);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
}
.val.hi { background: var(--hi); color: #fff; }
.prow .gp { flex: none; width: 40px; font-family: var(--font-mono); font-size: 12px; font-weight: 600; }
.prow .desc { flex: 1; min-width: 0; font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .desc.mono { font-family: var(--font-mono); font-size: 11.5px; }
.prow .reorder { display: flex; opacity: 0; }
.prow:hover .reorder, .prow:focus-within .reorder { opacity: 1; }
.prow .reorder .icon-btn { width: 20px; height: 22px; }
.prow .reorder .ic { width: 13px; height: 13px; }

.name-edit {
  flex: 1;
  min-width: 0;
  height: 24px;
  padding: 0 5px;
  margin-left: -5px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 12.5px;
}
.name-edit:hover { border-color: var(--border); }
.name-edit:focus { border-color: var(--ink); background: var(--raised); outline: none; }
.name-edit::placeholder { color: var(--text); opacity: 1; }
.name-edit:focus::placeholder { color: var(--text-3); }

.big-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--raised);
  text-align: left;
}
.big-toggle:hover:not(:disabled) { border-color: var(--text-3); }
.big-toggle:disabled { opacity: 0.55; }
.big-toggle .bt-label { font-weight: 600; }
.big-toggle .bt-sub { font-size: 11.5px; color: var(--text-3); }
.big-toggle .bt-val {
  display: grid;
  place-items: center;
  width: 38px;
  height: 30px;
  border-radius: var(--r);
  background: var(--sunken);
  font: 700 16px var(--font-mono);
  color: var(--text-3);
}
.big-toggle.hi .bt-val { background: var(--hi); color: #fff; }

.insp-note { font-size: 12px; color: var(--text-3); line-height: 1.5; }
.insp-note + .insp-note { margin-top: 6px; }

/* ---------- Status bar ---------- */

.statusbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
}
.sb-item { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; height: 22px; }
.sb-item + .sb-item:not(.sb-btn)::before { content: ""; }
.sb-item .ic { width: 13px; height: 13px; }
.sb-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.sb-item .dot.ok { background: var(--ok); }
.sb-item .dot.hi { background: var(--hi); }
.sb-item .dot.demo { background: var(--warn); }
.sb-spacer { flex: 1; }
.sb-btn { border: 0; background: transparent; border-radius: 4px; color: var(--text-2); font-size: 11.5px; }
.sb-btn:hover { background: var(--hover); color: var(--text); }
.xp-bar { width: 60px; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.xp-bar > i { display: block; height: 100%; background: var(--ink); }

/* ---------- Modal ---------- */

.modal-root { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 18, 15, 0.38); }
.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 440px;
  max-width: 100%;
  max-height: calc(100vh - 48px);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  animation: modal-in 0.14s ease-out;
}
.modal.wide { width: 720px; }
.modal.xwide { width: 880px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(0.99); } }

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px 12px;
}
.modal-title { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.modal-sub { margin-top: 3px; font-size: 12.5px; color: var(--text-2); }
.modal-head .icon-btn { margin: -3px -6px 0 auto; }
.modal-body { padding: 4px 18px 16px; overflow-y: auto; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
.modal-foot .foot-note { margin-right: auto; font-size: 12px; color: var(--text-3); }

.form-label { display: block; margin-bottom: 6px; font-size: 12.5px; font-weight: 550; color: var(--text-2); }

.spinner {
  width: 22px;
  height: 22px;
  margin: 28px auto;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  margin-bottom: 12px;
  border-radius: var(--r);
  background: var(--warn-soft);
  font-size: 12.5px;
}
.banner .ic { color: var(--warn); margin-top: 1px; }
.banner.error { background: var(--err-soft); }
.banner.error .ic { color: var(--err); }

.tt-wrap {
  max-height: 52vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--raised);
}
.tt-wrap table.grid td { text-align: center; padding: 3px 10px; }
.tt-wrap table.grid th { text-align: center; background: var(--raised); }
.tt-wrap tr.current td { background: var(--hi-soft) !important; }
.tt-wrap tr.clickable { cursor: pointer; }
.tt-pager { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.tt-pager .pages { display: flex; gap: 4px; }

/* Pin mapping */

.map-mode { display: flex; gap: 8px; margin-bottom: 14px; }
.map-mode .opt {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--raised);
  text-align: left;
}
.map-mode .opt:disabled { opacity: 0.45; }
.map-mode .opt.active { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.map-mode .opt b { display: block; font-weight: 600; margin-bottom: 2px; }
.map-mode .opt span { font-size: 12px; color: var(--text-2); }

.map-group-head { display: flex; justify-content: space-between; align-items: center; margin: 12px 0 6px; font-size: 11.5px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); }
.map-row {
  display: grid;
  grid-template-columns: 44px 1fr 16px 210px;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid var(--border);
}
.map-row .gp { font-family: var(--font-mono); font-weight: 600; }
.map-row .desc { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); }
.map-row .arrow { color: var(--text-3); }
.map-row select { width: 100%; }
.map-row select.conflict { border-color: var(--err); }

/* Library */

.lib-tabs { display: flex; gap: 2px; padding: 0 18px; border-bottom: 1px solid var(--border); }
.lib-tabs .tab { height: 34px; }
.lib-list { display: flex; flex-direction: column; }
.lib-item {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 2px 10px;
  padding: 10px 8px;
  border-radius: var(--r);
  cursor: pointer;
}
.lib-item + .lib-item { border-top: 1px solid var(--border); }
.lib-item:hover { background: var(--hover); }
.lib-item .li-icon { grid-row: span 2; display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--r); background: var(--sunken); color: var(--text-2); }
.lib-item .li-title { font-weight: 600; }
.lib-item .li-desc { grid-column: 2 / 4; font-size: 12px; color: var(--text-2); }
.lib-item .li-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }
.lib-save { display: flex; gap: 8px; margin-bottom: 12px; }
.lib-save .input { flex: 1; }

.milestone { display: grid; grid-template-columns: 22px 1fr auto; gap: 2px 10px; padding: 10px 2px; align-items: center; }
.milestone + .milestone { border-top: 1px solid var(--border); }
.milestone .ms-check { grid-row: span 2; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border-strong); color: transparent; }
.milestone.done .ms-check { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.milestone .ms-check .ic { width: 12px; height: 12px; stroke-width: 2.2; }
.milestone .ms-title { font-weight: 600; }
.milestone .ms-pts { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-3); }
.milestone .ms-desc { grid-column: 2 / 4; font-size: 12px; color: var(--text-2); }
.progress-head { display: flex; align-items: baseline; gap: 10px; margin: 4px 0 6px; }
.progress-head .lvl { font-size: 15px; font-weight: 650; }
.progress-head .pts { font-family: var(--font-mono); font-size: 12px; color: var(--text-3); }
.progress-bar { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; margin-bottom: 8px; }
.progress-bar > i { display: block; height: 100%; background: var(--ink); }

/* ---------- Toasts & tooltip ---------- */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 36px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 420px;
  padding: 9px 12px;
  border-radius: var(--r-lg);
  background: var(--ink);
  color: var(--on-ink);
  font-size: 12.5px;
  box-shadow: var(--shadow-2);
  animation: toast-in 0.16s ease-out;
  pointer-events: auto;
}
.toast.error { background: var(--err); color: #fff; }
.toast .ic { width: 14px; height: 14px; }
.toast.leaving { opacity: 0; transform: translateY(4px); transition: opacity 0.2s, transform 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

.tip {
  position: fixed;
  z-index: 300;
  max-width: 280px;
  padding: 7px 9px;
  border-radius: var(--r);
  background: var(--ink);
  color: var(--on-ink);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: var(--shadow-2);
}
.tip b { display: block; margin-bottom: 2px; font-weight: 600; }

/* ---------- Narrow windows ---------- */

@media (max-width: 1280px) {
  .workbench { grid-template-columns: 248px minmax(0, 1fr) 280px; }
  .canvas-hint { display: none; }
}
@media (max-width: 1060px) {
  .workbench { grid-template-columns: 236px minmax(0, 1fr); }
  .inspector {
    position: fixed;
    right: 8px;
    top: 52px;
    bottom: 32px;
    width: 300px;
    z-index: 40;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-2);
  }
  .inspector.no-selection { display: none; }
  .brand-name { display: none; }
}

/* ---------- Developer: firmware tool (dev-tools builds only) ---------- */

.dev-badge {
  height: 18px;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--warn-soft);
  color: var(--warn);
  font: 600 10.5px/18px var(--font-mono);
  letter-spacing: 0.04em;
}
.sb-fw .dot { animation: pulse 0.8s ease-in-out infinite alternate; }

.modal.fw-modal { width: 1080px; height: calc(100vh - 48px); }
.fw-modal .modal-body { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; gap: 10px; padding-top: 6px; }

.fw-top { display: grid; grid-template-columns: 210px 1fr; gap: 14px; flex: none; }
.fw-cmds { display: flex; flex-direction: column; gap: 1px; max-height: 300px; overflow-y: auto; }
.fw-group { padding: 8px 8px 3px; font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.fw-group:first-child { padding-top: 0; }
.fw-cmd {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 27px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  text-align: left;
  font-size: 12.5px;
}
.fw-cmd:hover { background: var(--hover); }
.fw-cmd.active { background: var(--ink); color: var(--on-ink); }
.fw-cmd .fw-loop { margin-left: auto; font-size: 11px; opacity: 0.6; }

.fw-opts { align-self: start; min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--raised); }
.fw-opts h3 { margin: 0 0 3px; font-size: 13.5px; font-weight: 650; }
.fw-desc { margin: 0 0 10px; font-size: 12.5px; color: var(--text-2); line-height: 1.5; }
.fw-desc code, .fw-meta code { font-family: var(--font-mono); font-size: 0.92em; }
.fw-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.fw-row > .fw-label { width: 92px; flex: none; font-size: 12px; font-weight: 550; color: var(--text-2); }
.fw-row .input { height: 28px; flex: 1; min-width: 180px; width: auto; font-family: var(--font-mono); font-size: 12px; }
.fw-row select { height: 28px; }
.fw-files { flex: 1; min-width: 180px; max-height: 110px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-sm); padding: 4px 6px; background: var(--panel); }
.fw-files .check { display: flex; padding: 2px 0; font-family: var(--font-mono); font-size: 11.5px; }
.fw-files .empty-note { padding: 4px 0; }
.fw-warn { display: flex; gap: 6px; align-items: flex-start; margin-top: 10px; font-size: 12px; color: var(--warn); line-height: 1.45; }
.fw-warn .ic { flex: none; width: 14px; height: 14px; margin-top: 1px; }

.fw-console-head { display: flex; align-items: center; gap: 8px; flex: none; min-width: 0; }
.fw-console-head .fw-title { font: 600 12px var(--font-mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fw-console-head .status-chip.ok { background: var(--in-soft); color: var(--ok); }
.fw-console-head .status-chip.err { background: var(--err-soft); color: var(--err); }
.fw-console-head .fw-spacer { flex: 1; }
.fw-console {
  flex: 1;
  min-height: 140px;
  margin: 0;
  padding: 8px 10px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--sunken);
  font: 11.5px/1.5 var(--font-mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
}
.fw-console .fw-l { min-height: 1.5em; }
.fw-console .sys { color: var(--text-3); }
.fw-console .in { color: var(--in); font-weight: 600; }
.fw-console .warn { color: var(--warn); }
.fw-console .err { color: var(--err); }
.fw-console .pending { color: var(--text); }
.fw-console .pending::after { content: "▍"; color: var(--text-3); animation: pulse 0.8s ease-in-out infinite alternate; }
.fw-console-empty { color: var(--text-3); }

.fw-reply { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: none; padding: 8px 10px; border-radius: var(--r); background: var(--warn-soft); }
.fw-reply .fw-reply-q { margin-right: 4px; font-size: 12.5px; font-weight: 550; color: var(--text); }
.fw-input { display: flex; gap: 8px; flex: none; }
.fw-input .input { flex: 1; font-family: var(--font-mono); font-size: 12px; }

.fw-modal .modal-foot .check { margin-right: 4px; white-space: nowrap; }
.fw-meta { margin-right: auto; font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 760px) {
  .fw-top { grid-template-columns: 1fr; }
  .fw-cmds { max-height: 140px; }
}
