/* ─────────────────────────────────────────────────────────────
   TinkerBench — ATL virtual tinkering lab
   Palette is taken from the lab itself: an ESD bench mat,
   solder-mask green, header-pin gold, tool-handle orange,
   and the resistor colour code for categories.
   ───────────────────────────────────────────────────────────── */

:root {
  /* the mat (canvas) */
  --mat: #cfd9d3;
  --mat-dot: #a7b7ae;
  --mat-dot-big: #93a59b;

  /* chrome */
  --chrome: #f1f0ec;
  --chrome-2: #e6e4dd;
  --card: #fbfaf7;
  --ink: #141a18;
  --ink-2: #3d4744;
  --ink-3: #5a6460;        /* secondary text: 4.8:1 or better on chrome, chrome-2 and card */
  --line: #c9cbc3;
  --line-2: #aeb2a9;

  /* meaning colours */
  --run: #ff6a13;          /* tool-handle orange, only for Run */
  --run-ink: #141a18;      /* the label on it: white on this orange is under 3:1 */
  --live: #1c7c54;         /* solder-mask green, the bench is live */
  --on-live: #fff;         /* text and ticks drawn on a green fill */
  --gold: #d9a21b;         /* header-pin gold, selection */
  --gold-deep: #a97a0c;
  --gold-ink: #7a5a05;     /* gold as text on paper */
  --danger: #c8322b;
  --danger-ink: #c8322b;   /* danger as text */
  --warn: #c98c00;
  --warn-ink: #8a5a00;     /* warn as text: the bright amber is under 3:1 on paper */
  --focus: #a97a0c;
  --copper: #b87333;
  --shadow-ink: #141a18;   /* the hard shadows: ink on paper, near black under dark bench lighting */

  /* categories = resistor colour code */
  --cat-boards: #6f3fd4;     /* violet */
  --cat-power: #c8322b;      /* red */
  --cat-passive: #8b5a2b;    /* brown */
  --cat-logic: #2f6fed;      /* blue */
  --cat-input: #6b7280;      /* grey */
  --cat-light: #d99a00;      /* yellow */
  --cat-motion: #e46b1a;     /* orange */
  --cat-sensor: #1c8a4f;     /* green */
  --cat-display: #157a86;    /* teal */
  --cat-comms: #cf3f8c;      /* magenta */
  --cat-measure: #2f4858;    /* slate */

  --shadow-hard: 3px 3px 0 var(--shadow-ink);
  --shadow-soft: 0 6px 18px rgba(20, 26, 24, .16);
  color-scheme: light;

  --font-display: 'Bricolage Grotesque', 'Segoe UI Variable Display', 'Segoe UI', system-ui, sans-serif;
  --font-ui: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, 'Cascadia Mono', 'Courier New', monospace;

  --rail-h: 56px;
  --shelf-w: 296px;
  --clip-w: 372px;
  --radius: 10px;
}

[data-theme="dark"] {
  --mat: #22302b;
  --mat-dot: #34473f;
  --mat-dot-big: #3f544b;
  --chrome: #1a1f1d;
  --chrome-2: #232927;
  --card: #262d2a;
  --ink: #edf0ec;
  --ink-2: #c3cac5;
  --ink-3: #8b958f;
  --line: #3a423e;
  --line-2: #4c5652;
  --gold: #e6b53a;
  --gold-ink: #e6b53a;
  --live: #3fbf86;
  --on-live: #0f1a14;
  --danger-ink: #ff7a70;
  --warn-ink: #dda21f;
  --focus: #e6b53a;
  --shadow-ink: #0c0f0e;
  --shadow-soft: 0 6px 18px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--chrome);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; line-height: 1.15; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; }
code { font-family: var(--font-mono); font-size: .92em; background: var(--chrome-2); padding: 0 .3em; border-radius: 4px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
* { scrollbar-color: var(--line-2) transparent; }
::selection { background: var(--gold); color: var(--ink); }
[hidden] { display: none !important; }

/* ───────────── Top rail ───────────── */
.rail {
  height: var(--rail-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 0 14px 0 12px;
  background: var(--chrome);
  border-bottom: 2px solid var(--ink);
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 36px; height: 36px; }
.mark-bg { fill: var(--live); }
.mark-trace { stroke: var(--gold); }
.mark-pad { fill: var(--gold); }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brand-sub { font-size: 12px; color: var(--ink-3); }

.rail-center { display: flex; justify-content: center; min-width: 0; }
.mission-chip {
  display: inline-flex; align-items: center; gap: 9px;
  max-width: 100%;
  padding: 6px 14px 6px 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow-hard);
  font-weight: 700;
  transition: transform .08s ease, box-shadow .08s ease;
}
.mission-chip:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow-ink); }
.mission-chip-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ink-3); flex: none; }
.mission-chip.has-mission .mission-chip-dot { background: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 35%, transparent); }
.mission-chip-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.rail-actions { display: flex; align-items: center; gap: 10px; grid-column: 3; justify-self: end; }
.rail-group { display: flex; gap: 4px; padding-left: 10px; border-left: 1px solid var(--line-2); }

.sim-state { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-3); margin-right: 4px; }
.sim-lamp { width: 10px; height: 10px; border-radius: 50%; background: var(--line-2); transition: background .2s; }
.sim-state.is-live .sim-lamp { background: var(--live); box-shadow: 0 0 10px var(--live); animation: lamp 1.4s ease-in-out infinite; }
.sim-state.is-live .sim-label { color: var(--live); font-weight: 700; }
@keyframes lamp { 50% { box-shadow: 0 0 3px var(--live); } }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  font-weight: 700;
  box-shadow: var(--shadow-hard);
  transition: transform .08s ease, box-shadow .08s ease, background .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--chrome-2); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow-ink); }
.btn-sm { padding: 5px 11px; font-size: 13px; box-shadow: 2px 2px 0 var(--shadow-ink); }
.btn-sm:active { box-shadow: 0 0 0 var(--shadow-ink); }
.btn-ghost { background: transparent; box-shadow: none; border-color: var(--line-2); font-weight: 400; }
.btn-ghost:hover { border-color: var(--ink-3); }
.btn-ghost:active { transform: none; }
.btn-run { background: var(--run); color: var(--run-ink); border-color: var(--ink); padding-left: 12px; }
.btn-run:hover { background: color-mix(in srgb, var(--run) 86%, #fff); }
.btn-run.is-running { background: var(--ink); color: var(--chrome); }
[data-theme="dark"] .btn-run.is-running { background: var(--chrome); color: var(--ink); }
.btn-run-icon { width: 0; height: 0; border-left: 9px solid currentColor; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.btn-run.is-running .btn-run-icon { width: 11px; height: 11px; border: 0; background: currentColor; border-radius: 2px; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
}
.icon-btn:hover { background: var(--chrome-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:disabled { opacity: .35; cursor: default; }
/* the panel buttons: on a desktop a window icon whose band fills while that panel is out; on a phone the drawer icons */
.panel-toggle .ico-drawer { display: none; }
.panel-toggle[aria-expanded="true"] .ico-band { fill: currentColor; }
.rail-more { display: contents; }
.rail-more-toggle { display: none; }
.drawer-scrim, .drawer-close { display: none; }
.tab-short { display: none; }
.only-touch { display: none; }
@media (pointer: coarse) { .only-touch { display: inline; } .only-mouse { display: none; } }
/* the page itself never zooms or pulls-to-refresh: the bench handles its own pinch, the drawers only scroll */
html, body { overscroll-behavior: none; }
body { touch-action: pan-x pan-y; }
.icon-btn.is-active { background: var(--ink); color: var(--chrome); }

/* ───────────── Workshop layout ───────────── */
.workshop {
  /* the page may be zoomed for a big screen (js/display.js): a viewport height is zoomed with it, so divide it back */
  height: calc(100vh / var(--zf, 1) - var(--rail-h));
  height: calc(100dvh / var(--zf, 1) - var(--rail-h));
  display: grid;
  grid-template-columns: var(--shelf-w) 1fr var(--clip-w);
  position: relative;
  overflow: hidden;          /* the slide-in drawers must not widen the page on phones */
}

/* ───────────── Shelf (left) ───────────── */
.shelf {
  display: flex; flex-direction: column;
  background: var(--chrome);
  border-right: 2px solid var(--ink);
  min-height: 0;
  z-index: 5;
}
.shelf-controls { display: contents; }
.shelf-tabs, .clip-tabs { display: flex; border-bottom: 2px solid var(--ink); background: var(--chrome-2); }
.shelf-tab, .clip-tab {
  flex: 1;
  padding: 10px 6px 9px;
  border: 0; background: transparent;
  font-family: var(--font-display); font-weight: 700; font-size: 14px;
  color: var(--ink-3);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.shelf-tab:hover, .clip-tab:hover { color: var(--ink); }
.shelf-tab.is-active, .clip-tab.is-active { color: var(--ink); background: var(--chrome); border-bottom-color: var(--gold); }
.shelf-pane, .clip-pane { display: none; flex: 1; min-height: 0; overflow: auto; }
.shelf-pane.is-active, .clip-pane.is-active { display: flex; flex-direction: column; }

.shelf-search { padding: 12px 12px 6px; }
.shelf-search input, .shelf-filter select, .serial-in input, .prop-text {
  width: 100%;
  padding: 8px 11px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--card);
}
.shelf-search input::placeholder { color: var(--ink-3); }
.shelf-filter { padding: 0 12px 8px; }
.select-wrap { position: relative; display: block; }
.select-wrap select { appearance: none; padding-right: 32px; cursor: pointer; }
.select-caret { position: absolute; right: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); pointer-events: none; fill: none; stroke: var(--ink); stroke-width: 2; }
.select-sm select { padding: 5px 30px 5px 9px; font-size: 13px; border: 2px solid var(--ink); border-radius: 7px; background: var(--card); color: var(--ink); }
.select-sm select:disabled { opacity: .55; cursor: default; }

.cat-strip { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 12px 10px; }
.cat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 6px;
  border: 1.5px solid var(--line-2);
  border-radius: 999px;
  background: var(--card);
  font-size: 12px; color: var(--ink-2);
}
.cat-chip .band { width: 9px; height: 13px; border-radius: 2px; background: var(--c); }
.cat-chip.is-active { border-color: var(--ink); background: var(--c); color: #fff; font-weight: 700; }
.cat-chip.is-active .band { background: #fff; }
.cat-chip[data-cat="light"].is-active, .cat-chip[data-cat="motion"].is-active { color: #141a18; }
.cat-chip[data-cat="all"].is-active { color: var(--chrome); }
.cat-chip[data-cat="all"].is-active .band { background: var(--chrome); }
.cat-chip[data-cat="light"].is-active .band, .cat-chip[data-cat="motion"].is-active .band { background: #141a18; }

.part-list { flex: 1; overflow: auto; padding: 0 8px 8px; }
.part-group { margin-top: 4px; }
.part-group-title {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 6px 5px;
  font-family: var(--font-display); font-weight: 700; font-size: 12.5px;
  color: var(--ink-2);
}
.part-group-title .band { width: 6px; height: 16px; border-radius: 2px; background: var(--c); }
.part-item {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center; gap: 10px;
  padding: 6px 8px 6px 6px;
  border-radius: 9px;
  cursor: grab;
  border: 1.5px solid transparent;
  user-select: none;
}
@media (hover: hover) { .part-item:hover { background: var(--card); border-color: var(--line-2); } }
.part-item:active { cursor: grabbing; }
.part-item.is-dragging { opacity: .5; }
.part-thumb { width: 46px; height: 36px; display: grid; place-items: center; overflow: hidden; }
.part-thumb svg { max-width: 46px; max-height: 36px; }
.part-name { font-weight: 700; font-size: 13px; line-height: 1.2; }
.part-desc { font-size: 12px; color: var(--ink-3); line-height: 1.25; margin-top: 1px; }
.part-empty { padding: 30px 14px; color: var(--ink-3); text-align: center; }
.part-empty .link-btn { margin-top: 10px; font-weight: 700; color: var(--ink); }
.shelf-hint { padding: 8px 14px 12px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line); }

/* missions pane */
.mission-list { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.mission-card {
  padding: 10px 10px 10px 8px;
  border: 2px solid var(--line-2); border-radius: var(--radius);
  background: var(--card);
}
.mission-main { display: grid; grid-template-columns: 34px 1fr; gap: 10px; width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.mission-card:hover { border-color: var(--ink); }
/* the active card offers its worked answer (js/solutions.js) */
.mission-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0 44px; }
.mission-card.is-active { border-color: var(--ink); box-shadow: var(--shadow-hard); }
.mission-card.is-done { opacity: .78; }
.mission-num {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800;
  border: 2px solid var(--ink);
  background: var(--chrome-2);
}
.mission-card.is-done .mission-num { background: var(--live); color: var(--on-live); }
.mission-card.is-active .mission-num { background: var(--gold); }
.mission-title { font-weight: 700; font-size: 13.5px; }
.mission-goal { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.mission-level { font-size: 12px; color: var(--ink-3); margin-top: 4px; }


/* ───────────── Bench ───────────── */
.bench-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--mat); }
/* zoomed back to plain screen pixels, so the pointer maths in bench.js holds on any screen; the parts grow through the view zoom instead */
.bench { zoom: calc(1 / var(--zf, 1)); width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; user-select: none; -webkit-user-select: none; }
.bench text { pointer-events: none; }
.bench.is-panning { cursor: grabbing; }
.bench.is-wiring { cursor: crosshair; }
.mat { fill: var(--mat); }
.mat-dot { fill: var(--mat-dot); }
.mat-dot-big { fill: var(--mat-dot-big); }

.part { cursor: move; }
.part .art { will-change: transform; }
.part.is-selected .part-outline { stroke: var(--gold); stroke-width: 2.5; stroke-dasharray: 6 4; }
.part-outline { fill: none; stroke: none; pointer-events: none; }
.pin { fill: #d9a21b; stroke: #6b4b04; stroke-width: 1; cursor: crosshair; transition: r .1s; }
@media (hover: hover) { .pin:hover { fill: #fff; stroke: var(--gold-deep); stroke-width: 2; } }
.pin.is-hot { fill: #fff; stroke: var(--gold-deep); stroke-width: 2; }
.pin.is-strip { fill: #ffd54a; stroke: #6b4b04; }
.pin-hole { fill: transparent; stroke: none; }
@media (hover: hover) { .pin-hole:hover { fill: #fff; stroke: var(--gold-deep); stroke-width: 1.5; } }
.pin-hole.is-hot { fill: #fff; stroke: var(--gold-deep); stroke-width: 1.5; }
.pin-hole.is-strip { fill: #ffd54a; stroke: #6b4b04; stroke-width: 1; }
.pin-hit { fill: transparent; cursor: crosshair; }
.pin-label { font-family: var(--font-mono); font-size: 7px; font-weight: 750; fill: var(--ink); stroke: var(--mat); stroke-width: 2.2px; stroke-linejoin: round; paint-order: stroke fill; pointer-events: none; opacity: 0; }
/* knobs, dials, trim screws and the joystick's stick: turn them on the bench */
.knob-hit { fill: transparent; stroke: transparent; stroke-width: 2; cursor: grab; }
@media (hover: hover) { .knob-hit:hover { stroke: var(--gold); } }
.bench.is-knob, .bench.is-knob .knob-hit { cursor: grabbing; }
.bench.show-labels .pin-label { opacity: 1; }
/* parts that explain themselves (js/partinfo.js): the selected part and the one under the pointer
   always show their pin names; every part carries its name on the mat */
.part.is-selected .pin-label, .part.is-hover .pin-label, .pin-names.is-focus .pin-label { opacity: 1; }
.part-tag { pointer-events: none; }
.part-tag text { font-family: var(--font-ui); font-size: 8.5px; font-weight: 700; text-anchor: middle; fill: var(--ink-2); stroke: var(--mat); stroke-width: 3px; stroke-linejoin: round; paint-order: stroke fill; }
.part-tag.is-focus text { fill: var(--ink); }

.wire { fill: none; stroke-linecap: round; stroke-width: 3.2; pointer-events: none; }
.wire-hit { fill: none; stroke: transparent; stroke-width: 12; cursor: pointer; stroke-linecap: round; }
.wire-hit:hover + .wire { stroke-width: 4.2; }
.wire-selected { stroke: var(--gold); stroke-width: 7; opacity: .6; fill: none; stroke-linecap: round; pointer-events: none; }
.wire-flow { fill: none; stroke: #fff; stroke-width: 1.6; stroke-dasharray: 3 9; stroke-linecap: round; opacity: .9; pointer-events: none; }
.wire-rubber { fill: none; stroke: var(--gold); stroke-width: 3; stroke-dasharray: 6 5; pointer-events: none; }
.wire-alligator { stroke-width: 4.5; }

.strip-glow { fill: var(--gold); opacity: .28; pointer-events: none; rx: 4; }

/* live readouts: a sticker under each part and a voltage tag on every wired pin, only while running */
#layerReadouts { pointer-events: none; }
.readout rect { fill: var(--card); stroke: var(--ink); stroke-width: 1; opacity: .96; }
.readout text { font-family: var(--font-mono); font-size: 8px; font-weight: 600; fill: var(--ink); text-anchor: middle; dominant-baseline: middle; }
.readout.is-ok text { fill: var(--live); }
.readout.is-warn text { fill: var(--warn-ink); }
.readout.is-warn rect { stroke: var(--warn); }
.readout.is-danger text { fill: var(--danger-ink); }
.readout.is-danger rect { stroke: var(--danger); stroke-width: 1.5; }
.pin-volt rect { fill: var(--card); stroke: var(--ink-3); stroke-width: .6; opacity: .92; }
.pin-volt text { font-family: var(--font-mono); font-size: 5.5px; fill: var(--ink-2); text-anchor: middle; dominant-baseline: middle; }
.pin-volt.is-hi text { fill: var(--live); font-weight: 700; }
.pin-volt.is-float text { fill: var(--warn-ink); font-weight: 700; }
.pin-volt.is-float rect { stroke: var(--warn); }

.svg-text { font-family: var(--font-mono); }
.silk { font-family: var(--font-mono); fill: #fff; font-size: 6.5px; pointer-events: none; }

.bench-tools {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  width: max-content; max-width: calc(100% - 24px);
  z-index: 3;
}
.tool-cluster {
  display: flex; gap: 2px; padding: 3px;
  background: var(--card);
  border: 2px solid var(--ink); border-radius: 10px;
  box-shadow: var(--shadow-hard);
}
.tool-btn {
  width: 30px; height: 28px;
  display: grid; place-items: center;
  border: 0; border-radius: 6px; background: transparent; color: var(--ink-2);
}
.tool-btn:hover { background: var(--chrome-2); color: var(--ink); }
.tool-btn.is-on { background: var(--ink); color: var(--chrome); }
.tool-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool-zoom { width: auto; padding: 0 8px; font-family: var(--font-mono); font-size: 11.5px; }
.wire-colors { gap: 3px; padding: 4px 5px; }
.wire-swatch { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; background: var(--c); padding: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
[data-theme="dark"] .wire-swatch { box-shadow: inset 0 0 0 1px rgba(255,255,255,.35); }   /* the black wire stays visible under dark bench lighting */
.wire-swatch.is-active { border-color: var(--ink); transform: scale(1.15); }

/* ── the 3D axis control ──
   The bench camera on three axes in the usual CAD colours: X red, Y green, Z blue. The triad shows the
   bench's own axes as the camera sees them; the rows step each axis 15°; the chips jump to set views.
   The same markup sits on the bench (.axis-control) and in Inspect (.axis-panel). */
.axis-control, .axis-panel, .bench-menu { --ax-x: #d43a35; --ax-y: #1b8a4c; --ax-z: #2c68d8; }
[data-theme="dark"] .axis-control, [data-theme="dark"] .axis-panel, [data-theme="dark"] .bench-menu { --ax-x: #ff6f66; --ax-y: #4cc985; --ax-z: #77a3ff; }
.axis-control {
  position: absolute; right: 12px; bottom: 62px; z-index: 3; width: 200px;
  padding: 8px; color: var(--ink);
  border: 2px solid var(--ink); border-radius: 12px; background: var(--card);
  box-shadow: var(--shadow-hard);
}
.axis-head { display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.axis-gizmo { width: 58px; height: 58px; overflow: visible; }
.gizmo-plane { fill: color-mix(in srgb, var(--ink) 6%, transparent); stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 2.5 2; }
.gizmo-origin { fill: var(--ink); }
.gizmo-axis { cursor: pointer; }
.gizmo-axis line { stroke-width: 2.6; stroke-linecap: round; }
.gizmo-axis circle { stroke: var(--card); stroke-width: 1.4; }
.gizmo-axis text { font: 800 8px/1 var(--font-mono); fill: var(--card); text-anchor: middle; pointer-events: none; }
.gizmo-x line { stroke: var(--ax-x); } .gizmo-x circle { fill: var(--ax-x); }
.gizmo-y line { stroke: var(--ax-y); } .gizmo-y circle { fill: var(--ax-y); }
.gizmo-z line { stroke: var(--ax-z); } .gizmo-z circle { fill: var(--ax-z); }
.gizmo-axis.is-back { opacity: .42; }
.gizmo-axis.is-active circle { stroke: var(--ink); stroke-width: 2; }
.gizmo-axis:hover circle { stroke: var(--gold); stroke-width: 2.2; }
.axis-title { display: grid; gap: 4px; min-width: 0; }
.axis-title strong { font: 800 14px/1 var(--font-display); }
.axis-title span { font: 600 10.5px/1.25 var(--font-mono); color: var(--ink-3); }
.axis-fold { width: 26px; height: 26px; padding: 0; align-self: start; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: var(--ink-2); }
.axis-fold:hover { background: var(--chrome-2); color: var(--ink); }
.axis-fold svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s ease; }
.axis-control.is-collapsed .axis-fold svg { transform: rotate(180deg); }
.axis-control.is-collapsed .axis-body { display: none; }
.axis-body { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.axis-rows { display: grid; gap: 3px; }
.axis-row { --axc: var(--ax-x); display: grid; grid-template-columns: 28px 28px minmax(0, 1fr) 28px; align-items: center; gap: 4px; padding: 2px; border-radius: 8px; }
.axis-row.axis-y { --axc: var(--ax-y); } .axis-row.axis-z { --axc: var(--ax-z); }
.axis-row.is-active { background: var(--chrome-2); box-shadow: inset 0 0 0 1.5px var(--axc); }
.axis-key { height: 26px; padding: 0; border: 1.5px solid var(--axc); border-radius: 6px; background: transparent; color: var(--axc); font: 800 12px/1 var(--font-mono); }
.axis-key:hover, .axis-row.is-active .axis-key { background: var(--axc); color: var(--card); }
.axis-step { height: 26px; padding: 0; border: 1.5px solid var(--line-2); border-radius: 6px; background: var(--card); color: var(--ink); font: 700 15px/1 var(--font-ui); }
.axis-step:hover { background: var(--gold); border-color: var(--ink); color: #141a18; }
.axis-angle { text-align: center; font: 700 12px/1 var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ink); }
.axis-presets { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; margin-top: 7px; }
.axis-presets button { height: 25px; min-width: 0; padding: 0 1px; border: 1.5px solid var(--line-2); border-radius: 6px; background: var(--card); color: var(--ink-2); font: 700 10.5px/1 var(--font-ui); }
.axis-presets button:hover { border-color: var(--ink); color: var(--ink); }
.axis-presets button.is-active { border-color: var(--ink); background: var(--ink); color: var(--chrome); }
.axis-panel .axis-row { grid-template-columns: 34px 34px minmax(0, 1fr) 34px; gap: 5px; }
.axis-panel .axis-key, .axis-panel .axis-step, .axis-panel .axis-presets button { height: 30px; }
.axis-panel .axis-presets { gap: 5px; margin-top: 8px; }
.axis-panel .axis-presets button { font-size: 11.5px; }
/* Phones and small tablets: the same control as a pill in the bench corner, above "What's happening?". It starts
   folded (its triad still shows which way the bench faces) and a tap anywhere on the pill opens it upwards. Every
   button is at least 40 px for a finger. */
@media (max-width: 980px) {
  .axis-control { right: 8px; bottom: calc(var(--status-bottom, 10px) + 50px); width: min(236px, calc(100% - 16px)); padding: 4px 4px 6px 6px; }
  /* never up over the toolbar, whatever is open below it: a short screen scrolls the buttons instead */
  .axis-control:not(.is-collapsed) { max-height: calc(100% - var(--tools-bottom, 50px) - var(--status-bottom, 10px) - 58px); overflow: hidden auto; overscroll-behavior: contain; }
  .axis-control.is-collapsed { width: auto; max-width: calc(100% - 16px); padding: 3px 3px 3px 5px; border-radius: 26px; }
  .axis-head { position: relative; grid-template-columns: 38px minmax(0, 1fr) 40px; gap: 6px; }
  .axis-gizmo { width: 38px; height: 38px; }
  .axis-title strong { font-size: 13.5px; }
  .axis-title span { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .axis-control.is-collapsed .axis-title span { max-width: 96px; }
  .axis-fold { width: 40px; height: 40px; align-self: center; border-radius: 50%; }
  .axis-fold svg { width: 14px; height: 14px; }
  .axis-fold::before { content: ''; position: absolute; inset: 0; }   /* the whole head is the button */
  .axis-body { margin: 6px 2px 0 0; padding-top: 6px; }
  .axis-row { grid-template-columns: 40px 44px minmax(0, 1fr) 44px; }
  .axis-key, .axis-step, .axis-presets button { height: 40px; }
  .axis-key { font-size: 14px; } .axis-step { font-size: 19px; } .axis-angle { font-size: 13px; }
  .axis-presets { gap: 4px; margin-top: 6px; }
  .axis-presets button { font-size: 12px; }
  .axis-panel .axis-row { grid-template-columns: 44px 48px minmax(0, 1fr) 48px; }
  .axis-panel .axis-key, .axis-panel .axis-step, .axis-panel .axis-presets button { height: 40px; }
  body.tut-active .axis-control { display: none; }   /* the tour's sheet has the bottom of the screen */
}
/* a phone on its side has more width than height: the set views stand beside the axis rows */
@media (max-width: 980px) and (max-height: 520px) {
  .axis-control { bottom: calc(var(--status-bottom, 10px) + 46px); }
  .axis-control:not(.is-collapsed) { width: auto; padding-bottom: 4px; max-height: calc(100% - var(--tools-bottom, 50px) - var(--status-bottom, 10px) - 54px); }
  .axis-body { display: grid; grid-template-columns: 196px 92px; gap: 8px; align-items: start; margin-top: 4px; padding-top: 4px; }
  .axis-row { padding: 0; }
  .axis-presets { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 0; gap: 3px; }
}
/* a finger leaves :hover on the last button it tapped, so touch screens light a button only while it is pressed */
@media (hover: none) {
  .axis-step:hover { background: var(--card); border-color: var(--line-2); color: var(--ink); }
  .axis-step:active { background: var(--gold); border-color: var(--ink); color: #141a18; }
  .axis-key:hover { background: transparent; color: var(--axc); }
  .axis-key:active, .axis-row.is-active .axis-key { background: var(--axc); color: var(--card); }
  .axis-presets button:hover { border-color: var(--line-2); color: var(--ink-2); }
  .axis-presets button:active { border-color: var(--ink); color: var(--ink); }
  .axis-presets button.is-active { border-color: var(--ink); background: var(--ink); color: var(--chrome); }
  .axis-fold:hover { background: transparent; color: var(--ink-2); }
  .gizmo-axis:hover circle { stroke: var(--card); stroke-width: 1.4; }
  .gizmo-axis.is-active:hover circle { stroke: var(--ink); stroke-width: 2; }
}

.bench-status {
  position: absolute; left: 12px; right: 12px; bottom: var(--status-bottom, 12px);
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  pointer-events: none;
}
.status-msgs { display: flex; flex-direction: column; gap: 6px; max-width: 70%; }
.status-msg {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 9px;
  border: 2px solid var(--ink); border-radius: 8px;
  background: var(--card);
  box-shadow: var(--shadow-hard);
  font-size: 13px;
  pointer-events: auto;
  animation: pop-in .18s ease;
}
.status-msg.is-danger { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--card)); }
.status-msg.is-warn { background: color-mix(in srgb, var(--warn) 16%, var(--card)); }
.status-msg.is-ok { background: color-mix(in srgb, var(--live) 14%, var(--card)); }
.status-msg-ico { width: 18px; height: 18px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 12px; color: #fff; background: var(--ink-3); }
.status-msg.is-danger .status-msg-ico { background: var(--danger); }
.status-msg.is-warn .status-msg-ico { background: var(--warn); color: #141a18; }
.status-msg.is-ok .status-msg-ico { background: var(--live); color: var(--on-live); }
.status-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: auto; }
.why-btn { background: var(--card); }
.why-btn:hover { background: var(--gold); }
.status-meta:empty { display: none; }
.status-meta { font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); background: color-mix(in srgb, var(--card) 80%, transparent); padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
@keyframes pop-in { from { transform: translateY(6px); opacity: 0; } }

.pin-tip {
  position: absolute; z-index: 4; pointer-events: none;
  padding: 4px 8px;
  background: var(--ink); color: var(--chrome);
  border-radius: 6px;
  font-size: 12px; font-family: var(--font-mono);
  white-space: nowrap;
  transform: translate(-50%, -130%);
}
.pin-tip b { color: var(--gold); }

/* rest the mouse on a part: what it is, what it does, how to wire it */
.part-card {
  position: absolute; z-index: 4; width: 264px; pointer-events: none;
  padding: 10px 12px 9px; color: var(--ink);
  background: var(--card); border: 2px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow-hard);
  font: 400 12.5px/1.45 var(--font-ui);
  animation: part-card-in .14s cubic-bezier(.2, .8, .2, 1);
}
@keyframes part-card-in { from { opacity: 0; transform: translateY(4px); } }
.part-card-head { display: flex; gap: 9px; align-items: stretch; margin-bottom: 6px; }
.part-card-band { flex: none; width: 5px; border-radius: 3px; background: var(--c); }
.part-card-head div { display: grid; gap: 2px; }
.part-card-head b { font: 750 14px/1.2 var(--font-display); }
.part-card-head span { font-size: 11.5px; color: var(--ink-3); }
.part-card p { margin: 0; }
.part-card-what { margin-bottom: 6px !important; }
.part-card-wire { padding: 6px 8px; border-radius: 6px; background: var(--chrome-2); color: var(--ink-2); font-size: 12px; }
.part-card-wire span { font-weight: 700; color: var(--ink); margin-right: 5px; }
.part-card-wire span::after { content: ':'; }
.part-card-foot { margin-top: 7px !important; font-size: 11px; color: var(--ink-3); }

/* right-click a part, a wire or the mat (js/benchmenu.js): each action with its key beside it */
.bench-menu {
  position: absolute; z-index: 8; width: 244px; max-height: calc(100% - 16px); overflow: auto; overscroll-behavior: contain;
  padding: 5px; color: var(--ink); background: var(--card); border: 2px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow-hard);
  font: 400 13px/1.3 var(--font-ui); animation: part-card-in .12s cubic-bezier(.2, .8, .2, 1);
}
.bench-menu:focus { outline: none; }
.bm-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 4px 8px 6px; }
.bm-head b { font: 750 14px/1.2 var(--font-display); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-head span { flex: none; font: 600 11.5px/1 var(--font-mono); color: var(--ink-3); }
.bm-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); text-align: left; }
.bm-item:hover, .bm-item:focus-visible { background: var(--chrome-2); }
.bm-item:focus-visible, .bm-chip:focus-visible, .bench-menu .wire-swatch:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--focus); }
.bm-item:disabled { opacity: .4; cursor: default; background: transparent; }
.bm-item.is-danger { color: var(--danger-ink); }
.bm-key { flex: none; font: 600 11px/1 var(--font-mono); color: var(--ink-3); white-space: nowrap; }
.bm-sep { height: 1px; margin: 4px 6px; background: var(--line); }
.bm-label { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 4px 8px 3px; font-size: 11.5px; font-weight: 700; color: var(--ink-2); }
.bm-row { display: flex; align-items: center; gap: 3px; padding: 3px 6px; }
.bm-gap { flex: 0 0 5px; }
.bm-chip { flex: 1 1 0; min-width: 0; height: 27px; padding: 0 2px; border: 1.5px solid var(--line-2); border-radius: 6px; background: var(--card); color: var(--ink-2); font: 700 11px/1 var(--font-ui); white-space: nowrap; }
.bm-chip:hover { border-color: var(--ink); color: var(--ink); }
.bm-chip[aria-checked="true"] { border-color: var(--ink); background: var(--ink); color: var(--chrome); }
.bm-axis { --axc: var(--ax-x); flex: 0 0 27px; border-color: var(--axc); color: var(--axc); font: 800 12px/1 var(--font-mono); }
.bm-axis-y { --axc: var(--ax-y); } .bm-axis-z { --axc: var(--ax-z); }
.bm-axis:hover, .bm-axis[aria-checked="true"] { border-color: var(--axc); background: var(--axc); color: var(--card); }
.bm-swatches { flex-wrap: wrap; gap: 6px; padding: 4px 8px 6px; }
.bench-menu .bm-swatches .wire-swatch { display: block; cursor: pointer; }   /* all ten, also where the phone toolbar shows six */
@media (pointer: coarse) { .bm-key { display: none; } }   /* keys mean nothing where there is no keyboard */
@media (any-pointer: coarse) {
  .bench-menu { width: 260px; }
  .bm-item { padding: 10px; }
  .bm-chip { height: 36px; }
  .bm-axis { flex-basis: 36px; }
  .bench-menu .wire-swatch { width: 28px; height: 28px; }
}

.mission-banner {
  position: absolute; top: calc(var(--tools-bottom, 50px) + 8px); left: 12px; right: 12px;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  background: var(--card);
  border: 2px solid var(--ink); border-radius: 10px;
  box-shadow: var(--shadow-hard);
  z-index: 3;
}
.mission-banner-title { font-family: var(--font-display); font-weight: 800; font-size: 14px; white-space: nowrap; border: 0; background: none; padding: 0; color: inherit; text-align: left; cursor: pointer; }
.mission-count { font-family: var(--font-mono); font-weight: 600; font-size: 12px; color: var(--ink-3); margin-left: 4px; }
.mission-banner.is-collapsed .mission-checks { display: none; }
.mission-checks { display: flex; flex-wrap: wrap; gap: 6px 14px; flex: 1; }
.mission-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.mission-check .tick { flex: none; width: 15px; height: 15px; border: 2px solid var(--ink-3); border-radius: 4px; display: grid; place-items: center; }
.mission-check.is-done { color: var(--ink); }
.mission-check.is-done .tick { background: var(--live); border-color: var(--live); }
.mission-check.is-done .tick::after { content: ''; width: 5px; height: 8px; border: solid var(--on-live); border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.mission-banner .btn-ghost { padding: 4px 11px; font-size: 12.5px; }
.mission-banner .btn-ghost svg, .drawer-close svg, .modal-close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.mission-banner #missionQuit { padding: 4px 7px; min-width: 30px; justify-content: center; }
/* a worked answer is on the bench, not the student's own: dashed gold edge and a tag */
.mission-banner.is-solution { border-style: dashed; border-color: var(--gold-deep); }
.mission-tag { display: inline-block; margin-right: 8px; padding: 1px 7px; border-radius: 5px; background: var(--gold); color: #141a18; font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; vertical-align: 1px; }

/* ───────────── Clipboard (right) ───────────── */
.clipboard {
  display: flex; flex-direction: column;
  background: var(--chrome);
  border-left: 2px solid var(--ink);
  min-height: 0; position: relative;
  z-index: 5;
}
.clip-clip {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  width: 64px; height: 14px;
  border: 2px solid var(--ink); border-radius: 6px;
  background: var(--gold);
  z-index: 6;
}
.clip-tabs { padding-top: 6px; }
.clip-tab { font-size: 13px; }

.clip-pane { padding: 0; }
.clip-section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.clip-section h3 { font-size: 15px; margin-bottom: 8px; }
.clip-section h4 { font-size: 13px; color: var(--ink-2); margin: 10px 0 5px; }
.clip-section p { color: var(--ink-2); font-size: 13px; margin-bottom: 6px; }
.clip-section ul { margin: 4px 0 6px 18px; padding: 0; color: var(--ink-2); font-size: 13px; }
.clip-section li { margin-bottom: 3px; }
.clip-empty { padding: 40px 22px; text-align: center; color: var(--ink-3); }
.clip-empty h3 { color: var(--ink-2); margin-bottom: 6px; }

.inspect-head { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; }
.inspect-thumb { width: 64px; height: 52px; display: grid; place-items: center; background: var(--card); border: 1.5px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.inspect-thumb svg { max-width: 60px; max-height: 48px; }
.inspect-title { font-size: 17px; }
.inspect-cat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); margin-top: 3px; }
.inspect-cat .band { width: 7px; height: 12px; border-radius: 2px; background: var(--c); }

.cad-view-section h3 { display: flex; align-items: center; gap: 7px; }
.cad-view-section h3::after { content: 'CAD'; padding: 2px 5px; border-radius: 4px; background: var(--ink); color: var(--chrome); font: 700 9px/1 var(--font-mono); letter-spacing: .08em; }
.clip-section .cad-view-hint { margin: 8px 0 0; font-size: 11.5px; }

.prop { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.prop:last-child { border-bottom: 0; }
.prop-label { font-size: 13px; }
.prop-hint { grid-column: 1 / -1; font-size: 12px; color: var(--ink-3); margin-top: -4px; }
.prop-value { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); min-width: 54px; text-align: right; }
.prop-range { grid-column: 1 / -1; width: 100%; accent-color: var(--gold); margin: 0; }
.size-ctl { display: inline-flex; align-items: center; gap: 4px; }
.size-ctl .size-val { font-family: var(--font-mono); font-size: 13px; min-width: 42px; text-align: center; }
.size-btn { width: 28px; height: 26px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 7px; background: var(--card); font-weight: 700; font-size: 15px; line-height: 1; padding: 0; box-shadow: 2px 2px 0 var(--shadow-ink); }
.size-btn:active { transform: translate(2px, 2px); box-shadow: none; }
.size-btn:disabled { opacity: .35; box-shadow: none; }
.prop-size .prop-hint { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.prop-select { padding: 4px 26px 4px 8px; border: 2px solid var(--ink); border-radius: 7px; background: var(--card); font-size: 13px; }
.prop-text { padding: 5px 9px; font-size: 13px; border-radius: 7px; }
.prop-number { width: 90px; padding: 4px 8px; border: 2px solid var(--ink); border-radius: 7px; background: var(--card); font-family: var(--font-mono); font-size: 12.5px; }
.toggle { position: relative; width: 44px; height: 24px; border: 2px solid var(--ink); border-radius: 999px; background: var(--chrome-2); padding: 0; }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); transition: transform .15s; }
.toggle.is-on { background: var(--live); }
.toggle.is-on::after { transform: translateX(20px); background: #fff; }
.press-btn { touch-action: none; user-select: none; -webkit-user-select: none; padding: 6px 12px; border: 2px solid var(--ink); border-radius: 8px; background: var(--card); font-weight: 700; box-shadow: 2px 2px 0 var(--shadow-ink); user-select: none; }
.press-btn:active, .press-btn.is-down { transform: translate(2px, 2px); box-shadow: none; background: var(--gold); }
.prop-full { grid-column: 1 / -1; }

.keypad-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.keypad-grid .press-btn { padding: 7px 0; text-align: center; font-family: var(--font-mono); }
.remote-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.remote-grid .press-btn { padding: 7px 0; text-align: center; font-size: 12px; }
.joy-pad { position: relative; width: 120px; height: 120px; margin: 4px auto; border: 2px solid var(--ink); border-radius: 50%; background: var(--card); touch-action: none; cursor: crosshair; }
.joy-pad::before, .joy-pad::after { content: ''; position: absolute; background: var(--line); }
.joy-pad::before { left: 50%; top: 4px; bottom: 4px; width: 1px; }
.joy-pad::after { top: 50%; left: 4px; right: 4px; height: 1px; }
.joy-knob { position: absolute; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); border: 3px solid var(--gold); transform: translate(-50%, -50%); pointer-events: none; }
.line-track { position: relative; height: 34px; border: 2px solid var(--ink); border-radius: 6px; background: #f2efe6; overflow: hidden; }
.line-track .line { position: absolute; top: 0; bottom: 0; width: 12%; background: #141a18; }
.line-track .sensors { position: absolute; left: 4%; right: 4%; top: 50%; display: flex; justify-content: space-between; transform: translateY(-50%); }
.line-track .sensors i { width: 8px; height: 8px; border-radius: 50%; background: #c8322b; border: 1px solid #fff; }
.line-track .sensors i.on { background: #3fbf86; }

.pin-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.pin-table td { padding: 3px 4px; border-bottom: 1px solid var(--line); }
.pin-table td:first-child { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; }
.pin-table td:last-child { font-family: var(--font-mono); text-align: right; color: var(--ink-2); }
.pin-table .v-hi { color: var(--live); font-weight: 600; }
.pin-table .v-float { color: var(--warn-ink); }
.truth-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; font-family: var(--font-mono); text-align: center; }
.truth-table th { font-family: var(--font-display); font-size: 12px; color: var(--ink-3); padding: 3px 6px; border-bottom: 2px solid var(--ink); }
.truth-table td { padding: 3px 6px; border-bottom: 1px solid var(--line); }
.truth-table td.tt-out { font-weight: 700; border-left: 2px solid var(--ink); }
.truth-table td.tt-out.is-hi { color: var(--live); }
.live-line b { font-family: var(--font-mono); }
.live-line.is-ok b { color: var(--live); }
.live-line.is-warn b { color: var(--warn-ink); }
.live-line.is-danger b { color: var(--danger-ink); }

.chat { display: flex; flex-direction: column; gap: 5px; max-height: 180px; overflow: auto; padding: 8px; background: var(--card); border: 2px solid var(--ink); border-radius: 10px; }
.chat-msg { max-width: 85%; padding: 5px 10px; border-radius: 12px; font-size: 12.5px; font-family: var(--font-mono); }
.chat-msg.from-phone { align-self: flex-end; background: var(--live); color: var(--on-live); }
.chat-msg.from-board { align-self: flex-start; background: var(--chrome-2); }
.chat-form { display: flex; gap: 6px; margin-top: 6px; }
.chat-form input { flex: 1; padding: 5px 9px; border: 2px solid var(--ink); border-radius: 7px; background: var(--card); font-size: 13px; }

.scope { width: 100%; height: 120px; background: #10231d; border: 2px solid var(--ink); border-radius: 8px; display: block; }
.meter-read { font-family: var(--font-mono); font-size: 28px; font-weight: 600; padding: 8px 12px; background: #d6e8c4; color: #1e2a1a; border: 2px solid var(--ink); border-radius: 8px; text-align: right; letter-spacing: .02em; }
.meter-read small { font-size: 13px; color: #4c5a45; }
.lcd-preview { font-family: var(--font-mono); background: #2f6f3a; color: #d8f3c8; padding: 6px 8px; border-radius: 6px; letter-spacing: .12em; white-space: pre; font-size: 13px; }

/* explain tab */
.ex-source { padding: 8px 10px; margin-bottom: 8px; background: var(--card); border: 1.5px solid var(--line-2); border-radius: 9px; }
.ex-source-head { font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.ex-source-head b { color: var(--ink); }
.ex-path { margin: 4px 0 8px 18px; padding: 0; font-size: 13px; color: var(--ink-2); }
.ex-path li { margin-bottom: 3px; }
.ex-path li::marker { color: var(--gold-ink); font-family: var(--font-mono); }
.ex-path .ex-back { color: var(--live); font-weight: 700; list-style: none; margin-left: -18px; }
.ex-path .ex-open { color: var(--danger-ink); font-weight: 700; list-style: none; margin-left: -18px; }
.ex-problems, .ex-parts { margin: 0; padding: 0 0 0 18px; font-size: 13px; color: var(--ink-2); }
.ex-problems li, .ex-parts li { margin-bottom: 6px; }
.ex-problems li.is-bad { color: var(--danger-ink); font-weight: 700; }
.ex-problems li.is-bad .link-btn, .ex-parts .link-btn { font-weight: 400; margin-left: 2px; padding: 2px 3px; }
.ex-problems li.is-idle { color: var(--ink-3); }
.ex-ok { color: var(--live); font-weight: 700; }
.ex-hint { font-size: 12.5px; color: var(--ink-2); padding: 7px 10px; background: color-mix(in srgb, var(--gold) 12%, var(--card)); border: 1.5px solid color-mix(in srgb, var(--gold) 45%, var(--line-2)); border-radius: 8px; }
.part.is-path .part-outline { stroke: var(--live); stroke-width: 3; stroke-dasharray: none; animation: pathpulse 1s ease-in-out infinite; }
.wire-g.is-path .wire { stroke-width: 6; filter: url(#softglow); animation: pathpulse 1s ease-in-out infinite; }
@keyframes pathpulse { 50% { opacity: .55; } }

/* learn tab */
.learn-why { padding: 8px 11px; background: color-mix(in srgb, var(--gold) 14%, var(--card)); border: 1.5px solid color-mix(in srgb, var(--gold) 55%, var(--line-2)); border-radius: 8px; font-size: 13px; color: var(--ink-2); }
.learn-mistake { padding: 8px 11px; background: color-mix(in srgb, var(--danger) 8%, var(--card)); border: 1.5px solid color-mix(in srgb, var(--danger) 55%, var(--line-2)); border-radius: 8px; font-size: 13px; margin-top: 8px; color: var(--ink-2); }
.learn-mistake b { color: var(--danger-ink); }
.learn-wiring { font-size: 13px; }
.learn-wiring li { margin-bottom: 4px; }
.learn-code { position: relative; }
.learn-code pre { font-family: var(--font-mono); font-size: 11.5px; line-height: 1.45; background: var(--card); border: 1.5px solid var(--line-2); border-radius: 8px; padding: 10px 12px; overflow: auto; margin: 0; max-height: 220px; }
.learn-code .btn { margin-top: 8px; }

/* code tab */
.clip-pane-code { display: none; }
.clip-pane-code.is-active { display: flex; }
.code-head, .serial-head { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); align-items: center; }
.code-head .select-wrap { flex: 1 1 150px; min-width: 0; }
.select-wrap select { width: 100%; max-width: 100%; }
.code-editor { min-height: 140px; }
.code-editor { flex: 1; min-height: 0; display: grid; grid-template-columns: 38px 1fr; background: var(--card); }
.code-gutter { font-family: var(--font-mono); font-size: 12px; line-height: 1.5; color: var(--ink-3); padding: 10px 0; text-align: right; background: var(--chrome-2); overflow: hidden; user-select: none; }
.code-gutter div { padding-right: 8px; height: 18px; }
.code-scroll { position: relative; overflow: hidden; }
.code-highlight, #codeText {
  position: absolute; inset: 0;
  margin: 0; padding: 10px 12px;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.5;
  white-space: pre; overflow: auto;
  tab-size: 2;
}
.code-highlight { pointer-events: none; color: var(--ink); }
#codeText { background: transparent; color: transparent; caret-color: var(--ink); border: 0; resize: none; outline: none; }
#codeText::placeholder { color: var(--ink-3); }
#codeText::selection { background: color-mix(in srgb, var(--gold) 40%, transparent); }
.tk-kw { color: #a03a9a; font-weight: 600; }
.tk-fn { color: #0f6f8a; }
.tk-num { color: #b5521a; }
.tk-str { color: #1c7c54; }
.tk-cm { color: var(--ink-3); font-style: italic; }
.tk-pp { color: #8b5a2b; }
[data-theme="dark"] .tk-kw { color: #e08de0; }
[data-theme="dark"] .tk-fn { color: #6fd0ea; }
[data-theme="dark"] .tk-num { color: #f0a070; }
[data-theme="dark"] .tk-str { color: #7fdcb0; }
.code-foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-3); }
.code-foot .is-error { color: var(--danger-ink); font-weight: 700; }

/* serial tab */
.clip-pane-serial { display: none; }
.clip-pane-serial.is-active { display: flex; }
.serial-head .select-wrap { flex: 1; }
.serial-out { flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; font-family: var(--font-mono); font-size: 12px; line-height: 1.5; background: var(--card); white-space: pre-wrap; word-break: break-word; }
.serial-out .ln-err { color: var(--danger-ink); font-weight: 600; }
.serial-out .ln-sys { color: var(--ink-3); font-style: italic; }
.serial-out .ln-in { color: var(--live); }
.serial-in { display: flex; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); }

/* ───────────── Toasts & modals ───────────── */
.toast-stack { position: fixed; bottom: 96px; right: calc(var(--clip-w) + 16px); width: min(440px, calc(100vw / var(--zf, 1) - 32px)); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; z-index: 50; pointer-events: none; }
@media (max-width: 980px) { .toast-stack { bottom: auto; top: calc(var(--rail-h) + 66px); right: 8px; width: min(440px, calc(100vw - 16px)); } }
@media (max-width: 560px) { .toast-stack { top: calc(var(--rail-h) + 112px); } }
.toast { max-width: 100%; padding: 8px 14px; background: var(--ink); color: var(--chrome); border-radius: 8px; font-size: 13px; box-shadow: var(--shadow-soft); animation: pop-in .18s ease; }
.toast.is-ok { background: var(--live); color: var(--on-live); }
.toast.is-danger { background: var(--danger); color: #fff; }

.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(20, 26, 24, .45); z-index: 60; padding: 20px; }
.modal-card { position: relative; width: min(560px, 100%); max-height: calc(90vh / var(--zf, 1)); overflow: auto; overscroll-behavior: contain; padding: 26px 28px; background: var(--chrome); border: 2px solid var(--ink); border-radius: 16px; box-shadow: 6px 6px 0 var(--shadow-ink); }
.modal-card h2 { font-size: 24px; margin-bottom: 12px; }
.modal-close { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); }
.modal-close:hover, .drawer-close:hover { background: var(--chrome-2); color: var(--ink); }
.modal-close svg { width: 20px; height: 20px; }
.help-steps { margin: 0; padding-left: 20px; }
.help-steps li { margin-bottom: 10px; color: var(--ink-2); }
.help-steps b { color: var(--ink); }
.help-check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.help-check input { margin-top: 3px; accent-color: var(--gold); flex: none; }
.help-reset { margin-top: 14px; font-size: 12.5px; color: var(--ink-3); }
.link-btn { border: 0; background: none; padding: 0; color: var(--ink-2); text-decoration: underline; font-size: inherit; cursor: pointer; }
.link-btn:hover { color: var(--danger-ink); }
.help-net { margin-top: 14px; padding: 8px 12px; background: var(--card); border: 2px dashed var(--line-2); border-radius: 8px; font-size: 13px; color: var(--ink-2); }
.help-net b { font-family: var(--font-mono); color: var(--ink); }
.help-stable { margin-top: 8px; border-style: solid; }
.help-qr { display: block; width: 132px; height: 132px; margin-top: 8px; border: 2px solid var(--ink); border-radius: 6px; background: #fff; image-rendering: pixelated; }
.help-keys { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 16px; font-size: 12.5px; color: var(--ink-2); }
.kbd { display: inline-block; padding: 0 6px; border: 1.5px solid var(--ink); border-bottom-width: 3px; border-radius: 5px; background: var(--card); font-family: var(--font-mono); font-size: 11.5px; }
.done-card { text-align: center; }
.stamp {
  display: inline-block; margin-bottom: 14px;
  padding: 6px 18px;
  font-family: var(--font-display); font-weight: 800; font-size: 30px; letter-spacing: .01em;
  color: var(--live); border: 4px solid var(--live); border-radius: 8px;
  transform: rotate(-6deg);
  animation: stamp .4s cubic-bezier(.16, 1, .3, 1);   /* lands firmly, no bounce */
}
@keyframes stamp { from { transform: rotate(-6deg) scale(2.2); opacity: 0; } }
.done-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
/* admin only (js/share.js): a browser that opened /gh/ */
body:not(.is-admin) .admin-only { display: none !important; }
.share-lede { color: var(--ink-2); margin-bottom: 12px; }
.share-check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 10px; }
.share-row { display: flex; gap: 8px; align-items: center; }
.share-url { flex: 1; min-width: 0; padding: 8px 10px; border: 2px solid var(--line-2); border-radius: 8px; background: var(--card); color: var(--ink); font: 12.5px var(--font-mono); }
.share-url:focus { border-color: var(--ink); outline: none; }
.share-status { margin-top: 12px; font-size: 13px; color: var(--ink-3); display: flex; gap: 8px; align-items: baseline; }
.share-status::before { content: ''; flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); }
.share-status.is-up::before { background: var(--live); }
.share-status.is-down::before { background: var(--gold); }
.share-status:empty { display: none; }

/* ───────────── Guided tours ───────────── */
.tut-overlay { position: fixed; inset: 0; z-index: 70; pointer-events: none; }
.tut-spot { position: fixed; border: 3px solid var(--gold); border-radius: 10px; box-shadow: 0 0 0 300vmax rgba(20, 26, 24, .5), 0 0 0 6px color-mix(in srgb, var(--gold) 35%, transparent); transition: left .18s ease, top .18s ease, width .18s ease, height .18s ease; pointer-events: none; }
.tut-card { position: fixed; width: min(360px, calc(100vw / var(--zf, 1) - 32px)); padding: 14px 16px 12px; background: var(--chrome); color: var(--ink); border: 2px solid var(--ink); border-radius: 12px; box-shadow: 5px 5px 0 var(--shadow-ink); pointer-events: auto; z-index: 71; }
.tut-card.is-sheet { left: auto !important; right: 12px; bottom: 12px; top: auto !important; width: min(420px, calc(100vw - 24px)); }
.tut-progress { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.tut-card h3 { font-size: 17px; margin-bottom: 4px; }
.tut-card p { font-size: 13.5px; color: var(--ink-2); margin: 0 0 10px; }
.tut-card p b { color: var(--ink); }
.tut-card p code { font-size: .9em; }
.tut-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tut-spacer { flex: 1; }
.tut-card.is-waiting .tut-progress::after { content: '  · waiting for you'; color: var(--gold-ink); }
.tut-card.is-done { border-color: var(--live); box-shadow: 5px 5px 0 var(--live); }
.tut-card.is-done .tut-progress::after { content: '  · done'; color: var(--live); }
body.tut-active .toast-stack { display: none; }
.help-first { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 14px; border: 2px solid var(--ink); border-radius: 10px; background: color-mix(in srgb, var(--gold) 18%, var(--card)); }
.help-first > div { flex: 1; font-size: 13.5px; color: var(--ink-2); }
.help-first b { color: var(--ink); }
.help-h3 { font-size: 15px; margin: 14px 0 8px; }
.tour-list { display: flex; flex-direction: column; gap: 6px; }
.tour-card { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px; padding: 8px 10px; border: 1.5px solid var(--line-2); border-radius: 9px; background: var(--card); text-align: left; cursor: pointer; }
.tour-card:hover { border-color: var(--ink); }
.tour-check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-2); display: grid; place-items: center; font-size: 12px; font-weight: 800; color: var(--on-live); }
.tour-card.is-done .tour-check { background: var(--live); border-color: var(--live); }
.tour-title { display: block; font-weight: 700; font-size: 13.5px; }
.tour-blurb { display: block; font-size: 12px; color: var(--ink-3); }
.tour-min { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.mission-tours-head { padding: 12px 12px 4px; }
.mission-tours-head h3 { font-size: 14px; }
.mission-tours-head p { font-size: 12px; color: var(--ink-3); }
.mission-tours { padding: 4px 10px 6px; display: flex; flex-direction: column; gap: 6px; }
.howto-search { width: 100%; padding: 7px 11px; border: 2px solid var(--ink); border-radius: 8px; background: var(--card); margin-bottom: 8px; }
.howto-list { max-height: 260px; overflow: auto; border: 1.5px solid var(--line-2); border-radius: 9px; background: var(--card); }
.howto { border-bottom: 1px solid var(--line); }
.howto:last-child { border-bottom: 0; }
.howto summary { padding: 8px 12px; font-weight: 700; font-size: 13px; cursor: pointer; list-style: none; display: flex; gap: 8px; }
.howto summary::before { content: '›'; color: var(--ink-3); transition: transform .12s; }
.howto[open] summary::before { transform: rotate(90deg); }
.howto p { padding: 0 12px 10px 28px; font-size: 13px; color: var(--ink-2); }
.howto-none { padding: 12px; font-size: 13px; color: var(--ink-3); }

/* ───────────── Responsive ───────────── */
/* On a desktop the component library is a horizontal workbench drawer. The right
   clipboard keeps its full height; phones retain the familiar left slide-in drawer. */
@media (min-width: 981px) {
  .workshop {
    grid-template-columns: minmax(0, 1fr) var(--clip-w);
    grid-template-rows: minmax(0, 1fr) clamp(206px, 24vh, 236px);
  }
  .bench-wrap { grid-column: 1; grid-row: 1; }
  .clipboard { grid-column: 2; grid-row: 1 / span 2; }
  .shelf {
    grid-column: 1; grid-row: 2;
    border-right: 0; border-top: 2px solid var(--ink);
  }
  .shelf-controls {
    display: grid;
    grid-template-columns: minmax(190px, 240px) minmax(150px, 190px) minmax(0, 1fr);
    align-items: center;
    min-height: 50px;
    border-bottom: 1px solid var(--line);
  }
  .shelf-search { padding: 7px 8px 7px 10px; }
  .shelf-search input { padding-top: 7px; padding-bottom: 7px; }
  .shelf-filter { padding: 7px 8px 7px 0; }
  .shelf-filter select { padding-top: 7px; padding-bottom: 7px; }
  .cat-strip {
    min-width: 0; flex-wrap: nowrap; overflow-x: auto;
    padding: 7px 10px 7px 2px; scrollbar-width: thin;
  }
  .cat-chip { flex: none; }
  .part-list {
    display: flex; align-items: stretch;
    overflow-x: auto; overflow-y: hidden;
    padding: 4px 8px 8px;
    scroll-snap-type: x proximity;
  }
  .part-group {
    position: relative; display: flex; flex: none; align-items: stretch; gap: 6px;
    margin: 0 8px 0 0; padding: 27px 8px 0 0;
    border-right: 1px solid var(--line);
  }
  .part-group:last-child { border-right: 0; }
  .part-group-title {
    position: absolute; inset: 0 auto auto 2px;
    height: 27px; padding: 5px 5px 4px;
  }
  .part-group-title .band { height: 13px; }
  .part-item {
    flex: 0 0 176px; width: 176px; min-height: 76px;
    padding: 7px 8px;
    background: var(--card); border-color: var(--line);
    box-shadow: 0 2px 5px color-mix(in srgb, var(--shadow-ink) 13%, transparent);
    scroll-snap-align: start;
  }
  @media (hover: hover) {
    .part-item:hover { border-color: var(--ink-3); transform: translateY(-1px); box-shadow: 0 4px 9px color-mix(in srgb, var(--shadow-ink) 18%, transparent); }
  }
  .part-thumb { width: 52px; height: 48px; overflow: visible; }
  .part-thumb svg { max-width: 52px; max-height: 48px; filter: drop-shadow(1px 2px 1px rgba(0, 0, 0, .22)); }
  .part-name { font-size: 13px; }
  .part-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .shelf-hint { display: none; }

  .shelf-pane[data-pane="missions"].is-active {
    flex-direction: row; align-items: stretch; overflow-x: auto; overflow-y: hidden;
  }
  .shelf-pane[data-pane="missions"] .mission-tours-head {
    flex: 0 0 152px; display: flex; flex-direction: column; justify-content: center;
    padding: 12px; border-right: 1px solid var(--line);
  }
  .shelf-pane[data-pane="missions"] .mission-tours,
  .shelf-pane[data-pane="missions"] .mission-list {
    flex: none; flex-direction: row; align-items: stretch; gap: 8px; padding: 10px;
  }
  .shelf-pane[data-pane="missions"] .tour-card { flex: 0 0 270px; width: 270px; }
  .shelf-pane[data-pane="missions"] .mission-card { flex: 0 0 284px; width: 284px; }
  .shelf-pane[data-pane="missions"] .mission-actions { margin: 8px 0 0; flex-wrap: nowrap; }
  .shelf-pane[data-pane="missions"] .mission-actions .btn-sm { padding: 4px 9px; font-size: 12.5px; white-space: nowrap; }

  /* either panel can be put away for a bigger bench: the rail buttons or the ✕ in its tabs (js/ui.js showPanel) */
  .workshop.shelf-off { grid-template-rows: minmax(0, 1fr) 0; }
  .workshop.clip-off { grid-template-columns: minmax(0, 1fr) 0; }
  .workshop.shelf-off .shelf, .workshop.clip-off .clipboard { display: none; }
  .workshop.shelf-off .bench-empty-shelf { display: inline-flex; }
  .workshop.clip-off ~ .toast-stack { right: 16px; }
  .drawer-close { display: grid; place-items: center; flex: none; width: 36px; border: 0; background: transparent; color: var(--ink-3); margin-bottom: -2px; }
}

@media (max-width: 1180px) {
  :root { --clip-w: 330px; --shelf-w: 270px; }
  .tab-long { display: none; } .tab-short { display: inline; }
}
@media (max-width: 980px) {
  .workshop { grid-template-columns: 1fr; }
  .rail { gap: 8px; }
  .rail-actions { gap: 6px; }
  .mission-banner { top: auto; bottom: 52px; flex-wrap: wrap; }
  .bench-status { bottom: var(--status-bottom, 10px); }
  .shelf, .clipboard { position: absolute; top: 0; bottom: 0; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-soft); }
  .clipboard { right: 0; transform: translateX(105%); }
  .shelf.is-open, .clipboard.is-open { transform: none; }
  .panel-toggle .ico-drawer { display: block; }
  .panel-toggle .ico-dock { display: none; }
  .rail-panels { border-left: 0; padding-left: 0; gap: 6px; }
  .rail-center { display: none; }
  .brand-sub { display: none; }
  .sim-state .sim-label { display: none; }
}
@media (max-width: 560px) {
  .rail { gap: 6px; padding: 0 8px; }
  .btn-run { padding: 6px 10px; }
}


/* ───────────── Phones and small tablets: touch-first overrides ───────────── */
@media (max-width: 980px) {
  body.tut-active .shelf, body.tut-active .clipboard { bottom: var(--tut-sheet, 0px); }
  body.tut-active .mission-banner { bottom: calc(52px + var(--tut-sheet, 0px)); }
  body.tut-on-bench .bench-tools { opacity: .3; pointer-events: none; }
  .drawer-scrim { display: block; position: absolute; inset: 0; z-index: 4; background: rgba(20, 26, 24, .35); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .workshop.has-drawer .drawer-scrim { opacity: 1; pointer-events: auto; }
  .shelf, .clipboard { width: min(86vw, 380px); }
  .shelf { padding-left: env(safe-area-inset-left); }
  .clipboard { padding-right: env(safe-area-inset-right); }
  .drawer-close { display: grid; place-items: center; flex: none; width: 44px; border: 0; background: transparent; color: var(--ink-2); margin-bottom: -2px; }
  .drawer-close svg { width: 20px; height: 20px; }
  .clip-clip { display: none; }
  .clip-tabs { padding-top: 0; }
  .shelf-tab, .clip-tab { font-size: 13px; padding: 12px 4px 10px; white-space: nowrap; }
  .tab-long { display: none; } .tab-short { display: inline; }
  .panel-toggle, .icon-btn { width: 40px; height: 40px; }
  .btn-run { min-height: 40px; }
  .cat-strip { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
  .cat-strip::-webkit-scrollbar { display: none; }
  .cat-chip { flex: none; padding: 6px 11px 6px 8px; font-size: 13px; }
  .part-item { padding: 9px 8px; }
  .pin-label { font-size: 8.5px; stroke-width: 2.8px; }
  /* Dense 0.1-inch headers cannot hold horizontal multi-character names on a
     phone. Angled callouts keep each pin visually separate without hiding any. */
  .pin-label[data-dir="up"], .pin-label[data-dir="down"] { transform-box: fill-box; transform-origin: center; transform: rotate(-58deg); }
  .pin-label[data-dir="up"][data-lane="1"] { transform: translateY(-5px) rotate(-58deg); }
  .pin-label[data-dir="down"][data-lane="1"] { transform: translateY(5px) rotate(-58deg); }
  .mission-card, .tour-card { padding: 12px 10px; }
  /* inputs at 16px so iOS does not zoom the page when they get focus */
  .shelf-search input, .shelf-filter select, .prop-select, .prop-text, .prop-number, .select-sm select, #codeText, .code-highlight, #serialInput, .chat-form input, .howto-search { font-size: 16px; }
  .code-gutter { font-size: 16px; line-height: 1.5; }
  .code-gutter div { height: 24px; }
  .prop { padding: 10px 0; }
  .prop-range { height: 32px; }
  .toggle { width: 52px; height: 30px; }
  .toggle::after { width: 22px; height: 22px; }
  .toggle.is-on::after { transform: translateX(22px); }
  .press-btn { padding: 10px 16px; }
  .size-btn { width: 36px; height: 32px; }
  .btn-sm { padding: 8px 14px; }
  .bench-tools { top: 8px; gap: 6px; }
  .tool-btn { width: 40px; height: 38px; }
  .tool-btn svg { width: 20px; height: 20px; }
  .wire-swatch { width: 26px; height: 26px; }
  .wire-swatch:nth-child(n+7) { display: none; }
  .mission-banner { padding: 6px 10px; gap: 8px; }
  .mission-banner .btn-ghost { min-height: 36px; padding: 4px 12px; }
  .mission-banner #missionQuit { min-width: 36px; }
  .mission-check { font-size: 12.5px; }
  .status-msg { font-size: 12.5px; }
  .status-msgs { max-width: calc(100% - 12px); }
  .status-meta { display: none; }
  .why-btn { padding: 8px 12px; }
  .modal { padding: 10px; align-items: flex-end; }
  .modal-card { max-height: 92dvh; padding: 18px 16px; border-radius: 14px; }
  .modal-close { position: sticky; top: 0; float: right; margin: -6px -6px 0 0; width: 40px; height: 40px; font-size: 28px; background: var(--chrome); border-radius: 50%; }
  .help-first { flex-direction: column; align-items: stretch; }
  .howto-list { max-height: none; }
  .tut-card.is-sheet { padding: 12px 14px 10px; }
  .tut-card.is-sheet h3 { font-size: 16px; }
  .tut-card.is-sheet p { font-size: 13px; }
}
@media (max-width: 760px) {
  .rail-more { display: none; position: absolute; top: calc(var(--rail-h) + 4px); right: 8px; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100vw - 16px); gap: 6px; padding: 6px; background: var(--card); border: 2px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow-hard); z-index: 25; }
  .rail-more.is-open { display: flex; }
  .rail-more .rail-group { border-left: 0; padding-left: 0; }
  .rail-more-toggle { display: grid; }
  .rail-actions .rail-group { display: flex; }
}
@media (max-width: 560px) {
  .brand-text { display: none; }
  .brand { gap: 0; }
  .bench-tools { width: calc(100% - 16px); }
  /* two tidy rows: edit + fit on the first, wire colours + view toggles on the second (redo lives in the ⋯ menu) */
  #toolFlow, #toolZoomIn, #toolZoomOut, #toolRedo { display: none; }   /* pinch to zoom; keep Fit and labels */
  .tool-zoom { min-width: 52px; }
  .tools-zoom { order: 2; } .wire-colors { order: 3; } .tools-view { order: 4; }
  .tut-card.is-sheet { left: 12px !important; right: 12px; width: auto; }
}
@media (max-width: 980px) and (max-height: 520px) {
  /* landscape phones: let the whole shelf pane scroll and keep the tour card out of the way */
  .shelf-pane.is-active { overflow-y: auto; display: block; }
  .shelf-search, .shelf-filter, .cat-strip { flex: none; }
  .part-list { flex: none; overflow: visible; }
  .shelf-hint { display: none; }
  .tut-card.is-sheet { left: auto !important; right: 12px; width: min(320px, 46vw); bottom: 8px; }
  .bench-tools { top: 6px; gap: 6px; max-width: calc(100% - 16px); flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; padding: 0 4px 4px 0; }
  .bench-tools::-webkit-scrollbar { display: none; }
  .tool-cluster { flex: none; }
  .tool-btn { width: 36px; height: 34px; }
  #toolFlow, #toolZoomIn, #toolZoomOut { display: none; }
  .mission-banner { bottom: 8px; }
  .modal-card { max-height: 96dvh; }
}

/* ───────── Big touch panels and touch laptops at desktop width ─────────
   A 30 to 40 inch panel at 1080p runs the desktop layout at 1x, where 28 px tool buttons and 18 px swatches
   are too small for a finger. Any touch input grows the controls to phone sizes; the layout stays as it is. */
@media (min-width: 981px) and (any-pointer: coarse) {
  .icon-btn { width: 40px; height: 40px; }
  .btn-run { min-height: 40px; }
  .mission-chip { min-height: 40px; }
  .tool-btn { width: 40px; height: 38px; }
  .tool-btn svg { width: 20px; height: 20px; }
  .tool-zoom { width: auto; min-width: 56px; }
  .wire-swatch { width: 26px; height: 26px; }
  .wire-colors { gap: 5px; padding: 5px 7px; }
  .shelf-tab, .clip-tab { padding: 13px 6px 12px; }
  .drawer-close { width: 44px; }
  .cat-chip { padding: 7px 12px 7px 9px; font-size: 13px; }
  .part-item { padding: 9px 8px; }
  .mission-card, .tour-card { padding: 12px 10px; }
  .howto summary { padding: 12px 12px; }
  .btn-sm { padding: 8px 14px; }
  .why-btn { padding: 9px 14px; }
  .size-btn { width: 40px; height: 36px; }
  .prop { padding: 10px 0; }
  .prop-select, .prop-number, .prop-text, .select-sm select { min-height: 40px; }
  .prop-range { height: 32px; }
  .toggle { width: 52px; height: 30px; }
  .toggle::after { width: 22px; height: 22px; }
  .toggle.is-on::after { transform: translateX(22px); }
  .press-btn { padding: 10px 16px; }
  .keypad-grid .press-btn, .remote-grid .press-btn { padding: 11px 0; }
  .mission-banner .btn-ghost { min-height: 40px; padding: 6px 14px; }
  .mission-banner #missionQuit { min-width: 40px; }
  .mission-banner-title { min-height: 40px; }
  .modal-close { width: 44px; height: 44px; }
  .link-btn { padding: 4px 2px; }
  .help-check input { width: 22px; height: 22px; margin-top: 0; }
  .axis-control { width: 236px; }
  .axis-row { grid-template-columns: 40px 44px minmax(0, 1fr) 44px; }
  .axis-key, .axis-step, .axis-presets button, .axis-panel .axis-key, .axis-panel .axis-step, .axis-panel .axis-presets button { height: 40px; }
  .axis-fold { width: 40px; height: 40px; }
}

/* ───────── The empty bench ───────── */
.bench-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 96px 24px 72px; pointer-events: none; z-index: 2; }
.bench-empty-card { width: min(400px, 100%); padding: 16px 18px 14px; background: var(--card); border: 2px solid var(--ink); border-radius: 12px; box-shadow: var(--shadow-hard); text-align: left; }
.bench-empty-card h2 { font-size: 19px; margin-bottom: 6px; }
.bench-empty-card p { font-size: 13.5px; color: var(--ink-2); }
.bench-empty-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.bench-empty-actions .btn { pointer-events: auto; }
.bench-empty-shelf { display: none; }
body.tut-active .bench-empty { display: none; }
@media (max-width: 980px) {
  .bench-empty { padding: 140px 16px 96px; }
  .bench-empty-shelf { display: inline-flex; }
  .bench-empty-actions #emptyTour { background: transparent; box-shadow: none; border-color: var(--line-2); font-weight: 400; }   /* the shelf comes first on a phone */
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0s !important; transition-duration: 0s !important; }
}

/* Help: screen size */
.help-size { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.help-size select { font: inherit; padding: 4px 8px; border: 2px solid var(--ink); border-radius: 7px; background: var(--card); color: var(--ink); }
.help-size label { color: var(--ink-2); font-weight: 700; }
.help-size-note { color: var(--ink-3); }
