/* IoT Circuit Studio — styles */
:root {
  color-scheme: light;
  --draw-filter: none;
  /* colours that differ in the dark theme (set again in both dark blocks at the end) */
  --btn-primary: var(--primary-2);
  --btn-primary-hover: var(--primary);
  --btn-accent: #0f766e; /* white text: 5.5:1 (the lighter --accent is for fills and borders) */
  --btn-accent-hover: #115e59;
  --accent-text: #0f766e;
  --warn-text: #b45309;
  --primary-text: var(--primary); /* the brand blue used as text: tabs, logo, numbers */
  --sim-tab-fg: #047857;
  --tip-fg: #57534e;
  --k-blue-fg: #1d4ed8;
  --k-black-fg: #111827;
  --k-purple-fg: #6d28d9;
  --ic-fg: #fff; /* the tick / cross inside the coloured check circles */
  --bb-table: #fdfaf3; /* the surface the breadboard and board sit on (Breadboard and Simulate tabs) */
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --surface-4: #e2e8f0;
  --ok-bg: #dcfce7;
  --ok-bg-2: #ecfdf5;
  --ok-bg-3: #f0fdf4;
  --ok-bg-5: #a7f3d0;
  --warn-bg: #fffbeb;
  --warn-bg-2: #fef3c7;
  --warn-bg-3: #fde68a;
  --err-bg: #fef2f2;
  --err-bg-2: #fee2e2;
  --info-bg: #eff6ff;
  --info-bg-2: #dbeafe;
  --info-bg-3: #eef2ff;
  --info-bg-4: #e0e7ff;
  --text-2: #334155;
  --text-3: #475569;
  --muted-2: #94a3b8;
  --ok-fg: #166534;
  --ok-fg-2: #065f46;
  --ok-fg-3: #15803d;
  --warn-fg: #92400e;
  --warn-fg-2: #b45309;
  --warn-fg-3: #78350f;
  --err-fg: #991b1b;
  --err-fg-2: #b91c1c;
  --err-fg-3: #7f1d1d;
  --info-fg: #3730a3;
  --info-fg-2: #1e3a8a;
  --info-fg-3: #1e40af;
  --sky-bg: #f0f9ff;
  --sky-bg-2: #e0f2fe;
  --purple-bg: #ede9fe;
  --teal-bg: #f0fdfa;
  --orange-bg: #ffedd5;
  --cream-bg: #fffdf7;
  --sky-border: #bae6fd;
  --teal-border: #99f6e4;
  --border-strong: #cbd5e1;
  --border-strong-2: #94a3b8;
  --ok-border: #86efac;
  --ok-border-2: #bbf7d0;
  --warn-border-2: #fde68a;
  --err-border: #fecaca;
  --glass-60: rgba(255, 255, 255, 0.6);
  --glass-95: rgba(255, 255, 255, 0.95);
  --glass-90: rgba(255, 255, 255, 0.9);
  --bg: #eef2f7;
  --panel: #ffffff;
  --border: #dbe3ee;
  --text: #0f172a;
  --muted: #5d6c82; /* 4.75:1 on the page background (WCAG AA) */
  --primary: #1e40af;
  --primary-2: #2563eb;
  --accent: #0d9488;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --info: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.06);
  --topbar: 58px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
button { font: inherit; color: inherit; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 14px 0 8px; color: var(--text-2); text-transform: none; }
p { line-height: 1.45; }
kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
}
code { font-family: var(--mono); font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 10px; }
.warn-text { color: var(--warn-text); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: #b8c4d6; }
.btn:focus-visible, .icon-btn:focus-visible, .part-card:focus-visible, .chip:focus-visible, .tabs button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.45);
  outline-offset: 1px;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--btn-primary); border-color: var(--btn-primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--btn-primary-hover); }
.btn.accent { background: var(--btn-accent); border-color: var(--btn-accent); color: #fff; }
.btn.accent:hover { background: var(--btn-accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--err-bg); border-color: var(--err-border); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(15, 23, 42, 0.06); }
.btn.small { padding: 5px 9px; font-size: 12.5px; }
.icon-btn {
  border: 0;
  background: transparent;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: rgba(15, 23, 42, 0.07); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 16px; color: var(--primary-text); white-space: nowrap; }
.project-name { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 120px; max-width: 420px; }
.project-name input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  background: var(--surface-2);
}
.project-name input:hover { border-color: var(--border); }
.project-name input:focus { outline: none; border-color: var(--primary-2); background: var(--surface); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.save-state { font-size: 11.5px; font-weight: 600; white-space: nowrap; padding: 2px 8px; border-radius: 99px; }
.save-state.ok { color: var(--ok); background: var(--ok-bg); }
.save-state.warn { color: var(--warn-fg); background: var(--warn-bg-2); }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  padding: 6px;
  min-width: 260px;
  z-index: 50;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.menu button:hover { background: var(--surface-3); }
.menu button small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
/* the schematic's right-click menu (js/ui-schmenu.js): a frosted panel that pops out of the corner nearest the click */
.menu.ctx-menu {
  --ctx-hover: color-mix(in srgb, var(--primary-2) 13%, transparent);
  --ctx-danger: #dc2626;
  position: fixed;
  right: auto;
  top: 0;
  min-width: 248px;
  max-width: 320px;
  z-index: 200;
  padding: 5px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--border-strong) 70%, transparent);
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  backdrop-filter: blur(18px) saturate(1.6);
  box-shadow: 0 0 0 0.5px rgba(15, 23, 42, 0.04), 0 2px 6px rgba(15, 23, 42, 0.06), 0 12px 32px -4px rgba(15, 23, 42, 0.18), 0 24px 56px -12px rgba(15, 23, 42, 0.16);
  font-size: 13px;
  transform-origin: var(--ctx-origin, top left);
  animation: ctx-pop 0.14s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes ctx-pop {
  from { opacity: 0; transform: scale(0.94) translateY(-2px); }
}
.ctx-menu button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 30px;
  padding: 5px 8px 5px 9px;
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
  transition: background-color 0.08s ease, color 0.08s ease;
}
.menu.ctx-menu:focus { outline: none; }
.ctx-menu .ctx-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx-menu .ico { width: 16px; height: 16px; color: var(--muted); stroke-width: 1.75; transition: color 0.08s ease; }
.ctx-menu button:hover:not(:disabled), .ctx-menu button:focus:not(:disabled) { background: var(--ctx-hover); outline: none; }
.ctx-menu button:hover:not(:disabled) .ico, .ctx-menu button:focus:not(:disabled) .ico { color: var(--primary-2); }
/* the ring only while the keys are moving the highlight (js/ui-schmenu.js sets .by-keys); the mouse just tints */
.ctx-menu.by-keys button:focus { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--primary-2) 60%, transparent); }
.ctx-menu button:disabled { opacity: 0.4; cursor: default; background: none; }
.ctx-menu button.danger:not(:disabled), .ctx-menu button.danger:not(:disabled) .ico { color: var(--ctx-danger); }
.ctx-menu button.danger:hover:not(:disabled), .ctx-menu button.danger:focus:not(:disabled) { background: color-mix(in srgb, var(--ctx-danger) 12%, transparent); }
.ctx-menu button.danger:hover:not(:disabled) .ico, .ctx-menu button.danger:focus:not(:disabled) .ico { color: var(--ctx-danger); }
.ctx-menu kbd {
  margin-left: 12px;
  padding: 1px 6px;
  border: 0;
  border-radius: 5px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
  box-shadow: none;
  color: var(--muted);
  font-family: var(--font, inherit);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.ctx-menu hr { margin: 4px 8px; border: 0; border-top: 1px solid color-mix(in srgb, var(--border-strong) 60%, transparent); }
.ctx-menu .menu-label {
  padding: 6px 9px 4px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--muted);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .menu.ctx-menu { --ctx-danger: #f87171; background: color-mix(in srgb, var(--surface) 80%, transparent); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 0 0 1px rgba(0, 0, 0, 0.5), 0 16px 40px -6px rgba(0, 0, 0, 0.6); }
}
:root[data-theme="dark"] .menu.ctx-menu { --ctx-danger: #f87171; background: color-mix(in srgb, var(--surface) 80%, transparent); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 0 0 1px rgba(0, 0, 0, 0.5), 0 16px 40px -6px rgba(0, 0, 0, 0.6); }
@media (prefers-reduced-motion: reduce) {
  .menu.ctx-menu { animation: none; }
  .ctx-menu button, .ctx-menu .ico { transition: none; }
}
/* Windows high contrast: solid colours, no glass */
@media (forced-colors: active) {
  .menu.ctx-menu { background: Canvas; backdrop-filter: none; -webkit-backdrop-filter: none; border: 1px solid CanvasText; }
  .ctx-menu button:hover:not(:disabled), .ctx-menu button:focus:not(:disabled) { background: Highlight; color: HighlightText; }
}

/* ---------- Icons (js/icons.js): line drawings in the text colour, in place of emoji ---------- */
.ico { width: 16px; height: 16px; flex: none; display: inline-block; vertical-align: -3px; }
.btn.small .ico { width: 14px; height: 14px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; }
.icon-btn .ico { width: 18px; height: 18px; }
.menu-wrap > .btn .ico:last-child { width: 14px; height: 14px; margin-left: -2px; }
#menu-export button { display: flex; align-items: center; gap: 10px; }
#menu-export button .ico { color: var(--muted); }
.tabs button { display: inline-flex; align-items: center; gap: 6px; }
.mobile-bar { display: none; }

/* ---------- App layout ---------- */
.app {
  --palette-w: 236px;
  --side-w: 350px;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, var(--palette-w)) minmax(0, 1fr) minmax(0, var(--side-w));
  height: calc(100vh - var(--topbar));
  height: calc(100dvh - var(--topbar));
  transition: grid-template-columns 0.18s ease;
}
.palette, .side { background: var(--panel); overflow-y: auto; }
.palette { grid-column: 1; border-right: 1px solid var(--border); padding: 14px; }
.side { grid-column: 3; border-left: 1px solid var(--border); }

/* Collapse tabs: reclaim canvas width on a smaller desktop window without dropping to the mobile drawers. */
.panel-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 6;
  box-shadow: var(--shadow);
  transition: left 0.18s ease, right 0.18s ease, background 0.15s, color 0.15s;
}
.panel-toggle:hover { background: var(--surface-2); color: var(--text); }
#palette-toggle { left: calc(var(--palette-w) - 11px); }
#side-toggle { right: calc(var(--side-w) - 11px); }
html.pnl-palette-collapsed .app { --palette-w: 30px; }
html.pnl-side-collapsed .app { --side-w: 30px; }
@media (min-width: 1101px) {
  html.pnl-palette-collapsed .palette { padding: 0; overflow: hidden; }
  html.pnl-side-collapsed .side { overflow: hidden; }
  html.pnl-palette-collapsed .palette > * { display: none; }
  html.pnl-side-collapsed .side > * { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .app, .panel-toggle { transition: none; }
}
/* The Parts palette and the Properties & circuit check panel only apply to the schematic you're editing, so both
   (and their collapse tabs and mobile drawer buttons) only appear on the Schematic tab — every other tab gets the
   canvas width instead. */
body.hide-palette .palette, body.hide-palette #palette-toggle, body.hide-palette #btn-show-palette { display: none; }
body.hide-side .side, body.hide-side #side-toggle, body.hide-side #btn-show-side { display: none; }
@media (min-width: 1101px) {
  body.hide-palette .app { --palette-w: 0px; }
  body.hide-side .app { --side-w: 0px; }
}
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.close-drawer { display: none; }
.panel-head.mobile-only { display: none; }
#board-select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  margin-bottom: 16px;
  background: var(--surface-2);
}
.part-search {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  margin-bottom: 2px;
}
.part-search:focus { outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.part-card[hidden], .palette-group[hidden] { display: none; }
.palette h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 6px; }
.palette-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.part-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 7px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  cursor: grab;
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.part-card:hover { border-color: var(--primary-2); box-shadow: 0 2px 8px rgba(37, 99, 235, 0.15); }
.part-card:active { transform: scale(0.97); cursor: grabbing; }
.part-icon { display: flex; width: 56px; height: 36px; align-items: center; justify-content: center; }
.part-icon svg { max-width: 100%; max-height: 100%; }
.part-name { font-size: 11.5px; font-weight: 600; text-align: center; line-height: 1.2; }
.howto { margin-top: 18px; padding: 10px 12px; background: var(--sky-bg); border: 1px solid var(--sky-border); border-radius: 10px; font-size: 12.5px; }
.howto h3 { margin: 0 0 6px; color: #075985; text-transform: none; letter-spacing: 0; font-size: 13px; }
.howto ol { margin: 0 0 6px; padding-left: 18px; }
.howto li { margin: 2px 0; }
.howto p { margin: 6px 0 0; }

/* colour keys */
.k { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 99px; margin: 1px 2px; }
.k.blue { background: var(--info-bg-2); color: var(--k-blue-fg); }
.k.red { background: var(--err-bg-2); color: var(--err-fg-2); }
.k.black { background: var(--surface-4); color: var(--k-black-fg); }
.k.purple { background: var(--purple-bg); color: var(--k-purple-fg); }
.k.green { background: var(--ok-bg); color: var(--ok-fg-3); }
.k.amber { background: var(--warn-bg-2); color: var(--warn-fg-2); }

/* ---------- Center ---------- */
.center { grid-column: 2; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 8px 10px 0; background: var(--bg); } /* wraps rather than hiding tabs off-screen */
.tabs button {
  border: 1px solid transparent;
  border-bottom: 0;
  background: transparent;
  padding: 9px 14px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-3);
  white-space: nowrap;
}
.tabs button:hover { background: var(--glass-60); }
.tabs button.active { background: var(--surface); border-color: var(--border); color: var(--primary-text); }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; background: var(--surface); border-top: 1px solid var(--border); margin-top: -1px; }
.view.active { display: flex; }
.banner { padding: 8px 14px; font-size: 13px; background: var(--surface-2); border-bottom: 1px solid var(--border); line-height: 1.45; }
.banner .tag {
  display: inline-block;
  font-weight: 800;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 6px;
  margin-right: 6px;
  background: var(--info-bg-4);
  color: var(--info-fg);
}
.schematic-banner { background: var(--info-bg-3); }
.breadboard-banner { background: var(--warn-bg); }
.breadboard-banner .tag { background: var(--warn-bg-3); color: var(--warn-fg-3); }
.toolbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.zoom { font-size: 12px; font-weight: 600; min-width: 42px; text-align: center; color: var(--muted); }
.wiring-hint { margin-left: auto; font-size: 12.5px; font-weight: 600; color: #0369a1; background: var(--sky-bg-2); padding: 4px 10px; border-radius: 99px; }
.canvas-wrap { flex: 1; position: relative; min-height: 0; }
.schematic { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; background: #fbfdff; display: block; }
.schematic.panning { cursor: grabbing; }
.schematic .comp { cursor: move; }
.schematic .wire, .schematic .wire-label { cursor: pointer; }
.schematic .pin { cursor: crosshair; }
.schematic .pin:hover { fill: rgba(14, 165, 233, 0.3); stroke: #0ea5e9; stroke-width: 1.5; }
.schematic .pin-dot { fill: #fff; stroke: #64748b; stroke-width: 1.2; pointer-events: none; }
.schematic .pin-dot.on { fill: var(--muted); }
.schematic .pin-lead { cursor: pointer; }
.schematic .wire:hover polyline:last-child { stroke-width: 3; }

/* ---------- Breadboard ---------- */
.bb-layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 0; }
.bb-canvas-wrap { position: relative; min-width: 0; min-height: 0; display: flex; }
.bb-canvas { flex: 1; overflow: auto; padding: 12px; background: var(--bb-table); }
.bb-canvas svg { width: 100%; height: auto; display: block; max-width: none; }
.bb-canvas.panning, .bb-canvas.panning * { cursor: grabbing !important; }
.bb-zoom { position: absolute; right: 14px; bottom: 14px; display: flex; align-items: center; gap: 4px; padding: 4px; background: var(--glass-95); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12); }
.bb-canvas .bb-wire, .bb-canvas .bb-part { transition: opacity 0.15s; }
.bb-canvas.focusing .bb-wire:not(.hl), .bb-canvas.focusing .bb-part:not(.hl) { opacity: 0.18; }
.bb-steps { border-left: 1px solid var(--border); overflow-y: auto; padding: 12px 14px; font-size: 13px; }
.bb-steps h3 { margin-top: 0; }
.bb-steps ol { padding-left: 22px; margin: 0; }
.bb-steps li { padding: 6px 6px; border-radius: 6px; line-height: 1.4; cursor: default; }
.bb-steps li[data-jumper], .bb-steps li[data-comp] { cursor: pointer; }
.bb-steps li:hover { background: var(--warn-bg-2); }
.bb-steps li.done { color: var(--muted); text-decoration: line-through; }
.bb-steps li.current { background: var(--info-bg-3); box-shadow: inset 3px 0 0 var(--primary-2); color: var(--text); text-decoration: none; }
.bb-steps-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.bb-steps-head h3 { margin: 0; }
/* Build step by step (js/buildmode.js): the current step, floating over the breadboard */
.bb-canvas-wrap { position: relative; }
.bb-canvas.building.focusing .bb-wire:not(.hl), .bb-canvas.building.focusing .bb-part:not(.hl) { opacity: 0.12; }
.bb-canvas.building .hl { filter: drop-shadow(0 0 4px rgba(37, 99, 235, 0.9)) drop-shadow(0 0 10px rgba(37, 99, 235, 0.55)); }
.build-panel {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 62px;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 14px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22);
  z-index: 8;
}
.build-top { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.build-count { font-weight: 700; color: var(--text); }
.build-top .icon-btn { margin-left: auto; width: 28px; height: 28px; }
.build-bar { height: 5px; margin: 6px 0 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.build-bar span { display: block; height: 100%; border-radius: 99px; background: var(--ok); transition: width 0.25s; }
.build-text { margin: 0 0 10px; font-size: 15px; line-height: 1.45; font-weight: 600; color: var(--text); }
.build-text .ico { width: 17px; height: 17px; margin-right: 6px; vertical-align: -3px; color: var(--ok); }
.build-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.build-actions .btn.primary { min-width: 140px; justify-content: center; }
@media (prefers-reduced-motion: reduce) { .build-bar span { transition: none; } }
.note { margin-top: 12px; font-size: 12px; color: var(--warn-fg-3); background: var(--warn-bg); border: 1px solid var(--warn-border-2); padding: 8px 10px; border-radius: 8px; line-height: 1.45; }

/* Breadboard editing */
.bb-toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--border); background: var(--cream-bg); flex-wrap: wrap; min-height: 42px; font-size: 12.5px; }
.bb-tip { color: var(--tip-fg); flex: 1; }
.bb-sel { font-weight: 700; flex: 1; }
.bb-sel .muted { font-weight: 400; }
.bb-swatches { display: inline-flex; gap: 4px; }
.bb-swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px #94a3b8; cursor: pointer; padding: 0; }
.bb-swatch.on { box-shadow: 0 0 0 2px #0ea5e9; }
.auto-swatch { background: repeating-conic-gradient(#dc2626 0deg 90deg, #2563eb 90deg 180deg, #16a34a 180deg 270deg, #eab308 270deg 360deg); }
.wire-bend { cursor: grab; }
.wire-bend:active { cursor: grabbing; }
.wire-mid { cursor: copy; }
.wire-mid:hover { fill-opacity: 0.9; }
.wire-end { cursor: grab; }
.wire-end:hover { stroke-width: 2.5; }
.wire-end:active { cursor: grabbing; }
svg.bb-editable .bb-part { cursor: grab; }
svg.bb-editable .bb-part.dragging { cursor: grabbing; opacity: 0.85; }
svg.bb-editable .bb-part.sel { filter: drop-shadow(0 0 3px #0ea5e9) drop-shadow(0 0 1px #0ea5e9); }
svg.bb-editable .bb-wire { cursor: pointer; }
svg.bb-editable .bb-wire.sel path:last-of-type { stroke-width: 4; }
svg.bb-editable .bb-wire.sel { filter: drop-shadow(0 0 2px #0ea5e9); }
.bb-handle { fill: transparent; stroke: transparent; cursor: move; }
svg.bb-editable .bb-handle:hover { fill: rgba(14, 165, 233, 0.25); stroke: #0ea5e9; stroke-width: 1.5; }
.bb-ghost { fill: rgba(14, 165, 233, 0.3); stroke: #0ea5e9; stroke-width: 2; pointer-events: none; }
.bb-ghost.bad { fill: rgba(220, 38, 38, 0.25); stroke: #dc2626; }

/* ---------- Tables ---------- */
.doc { padding: 14px 18px; overflow: auto; flex: 1; }
.doc-actions { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; background: var(--surface-3); padding: 8px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); border-bottom: 2px solid var(--border); }
.table td { padding: 8px 10px; border-bottom: 1px solid #edf2f7; vertical-align: top; }
.table tbody tr:hover { background: var(--surface-2); }
#wiring-table tr[data-wire] { cursor: pointer; }
.swatch { display: inline-block; width: 18px; height: 11px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; border: 1px solid rgba(0, 0, 0, 0.2); box-shadow: 0 0 0 1px var(--border-strong); } /* the outline keeps a black wire visible on the dark theme */

/* ---------- Code ---------- */
.code-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.code-libs { font-size: 12.5px; color: var(--text, var(--text)); }
.lib { display: inline-block; background: var(--surface-3); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; margin: 2px; color: var(--text-2); }
/* Editor: a transparent textarea over the highlighted <pre>. Both must share exact metrics. */
.code-editor { flex: 1; display: flex; min-height: 0; background: #0f172a; position: relative; overflow: hidden; }
.code-gutter {
  flex: none;
  width: 46px;
  padding: 14px 0;
  background: #0b1222;
  color: #8494ab; /* the code editor is dark in both themes */
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 20px;
  text-align: right;
  user-select: none;
  will-change: transform;
}
.code-gutter div { padding-right: 10px; }
.code-gutter .err { background: #7f1d1d; color: #fecaca; }
.code-gutter .warn { background: #78350f; color: #fde68a; }
.code-area { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.code,
.code-input {
  margin: 0;
  padding: 14px 18px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 20px;
  tab-size: 2;
  white-space: pre;
  letter-spacing: 0;
  word-spacing: 0;
}
.code { position: absolute; top: 0; left: 0; min-width: 100%; color: #e2e8f0; background: transparent; pointer-events: none; will-change: transform; }
.code code { font-size: inherit; font-family: inherit; }
.code-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  outline: none;
  resize: none;
  overflow: auto;
  background: transparent;
  color: transparent;
  caret-color: #f8fafc;
  -webkit-text-fill-color: transparent;
}
.code-input::selection { background: rgba(96, 165, 250, 0.35); -webkit-text-fill-color: transparent; }
.code-input:focus { box-shadow: inset 0 0 0 2px rgba(56, 189, 248, 0.35); }
.code-state .pill { font-size: 11.5px; }
.code-notice { padding: 8px 14px; background: var(--warn-bg); border-bottom: 1px solid var(--warn-border-2); font-size: 13px; color: var(--warn-fg-3); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.code-notice[hidden] { display: none; }
.code-foot { border-top: 1px solid var(--border); max-height: 45%; overflow-y: auto; padding: 8px 14px; background: var(--surface); }
.code-foot .code-libs { margin-bottom: 6px; }
.code-lint h4 { margin: 4px 0 6px; font-size: 13px; }
.lint { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; padding: 5px 8px; border-radius: 7px; margin-bottom: 4px; background: var(--info-bg); color: var(--info-fg-2); }
.lint.error { background: var(--err-bg); color: var(--err-fg); }
.lint.warning { background: var(--warn-bg); color: var(--warn-fg); }
.lint .sev { font-size: 10.5px; font-weight: 800; text-transform: uppercase; background: none; color: inherit; padding: 0; }
.lint code { background: rgba(0, 0, 0, 0.06); padding: 0 4px; border-radius: 4px; }
.lint-line { border: 0; background: rgba(0, 0, 0, 0.07); border-radius: 5px; padding: 1px 6px; font-size: 11.5px; cursor: pointer; font-family: var(--mono); }
.lint-ok { font-size: 12.5px; color: var(--ok-fg); background: var(--ok-bg-3); padding: 6px 9px; border-radius: 7px; }
.c-com { color: #86efac; }
.c-str { color: #fcd34d; }
.c-pre { color: #f0abfc; }
.c-num { color: #fdba74; }
.c-kw { color: #7dd3fc; font-weight: 600; }

/* ---------- Side panel ---------- */
.panel { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stats div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 8px; text-align: center; }
.stats b { display: block; font-size: 20px; color: var(--primary-text); }
.stats span { font-size: 11.5px; color: var(--muted); }
.empty-cta { background: var(--teal-bg); border: 1px solid var(--teal-border); border-radius: 10px; padding: 10px 12px; }
.empty-cta p { margin: 0 0 8px; }
.insp-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.insp-head h2 { margin: 0; }
.insp-head .part-icon { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 3px; width: 60px; height: 42px; }
.desc { font-size: 13px; color: var(--text-2); margin: 6px 0 10px; }
.field { display: block; margin: 8px 0; }
.field span { display: block; font-size: 12px; font-weight: 600; color: var(--text-3); margin-bottom: 4px; }
.field input, .field select, .pin-select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  background: var(--surface);
}
.field input:focus, .field select:focus, .pin-select:focus { outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.pin-list { list-style: none; margin: 0; padding: 0; }
.pin-list li { padding: 8px 0; border-bottom: 1px dashed var(--border); }
.pin-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.pin-name { font-weight: 600; }
.pin-conn { text-align: right; font-size: 12.5px; color: var(--info-fg-2); font-weight: 600; }
.pin-select { font-size: 12.5px; padding: 5px 7px; }
.chips { margin-top: 5px; font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--ok-border);
  background: var(--ok-bg-3);
  color: var(--ok-fg-3);
  border-radius: 99px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.chip:hover { background: var(--ok-bg); }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.legend { margin: 6px 0; }
.insp-issues { margin-top: 10px; font-size: 12.5px; background: var(--err-bg); color: var(--err-fg); border-radius: 8px; padding: 6px 10px; }

/* Circuit check */
#check-panel h2 { display: flex; align-items: center; gap: 8px; }
.compare-btn { margin-top: 10px; width: 100%; }
.teacher-box { margin-top: 14px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: 10px; background: var(--surface-2); }
.teacher-box h3 { margin: 0 0 6px; font-size: 14px; }
.teacher-box label { display: block; line-height: 1.45; }
.hints-note { font-size: 12.5px; background: var(--info-bg-2); color: var(--info-fg); padding: 8px 10px; border-radius: 8px; margin: 0 0 10px; }
.compare-score { display: flex; align-items: center; gap: 12px; margin: 6px 0 12px; }
.compare-score meter { flex: 1; height: 14px; }
.compare-score b { font-size: 22px; }
.compare-list { padding-left: 18px; }
.compare-list li { margin-bottom: 6px; }
.count { display: inline-flex; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 99px; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 800; }
.count.ok { background: var(--ok-bg); color: var(--ok-fg-3); }
.count.warn { background: var(--warn-bg-2); color: var(--warn-fg-2); }
.count.err { background: var(--err-bg-2); color: var(--err-fg-2); }
.check-summary { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; font-size: 12px; }
.check-summary li { display: flex; align-items: center; gap: 6px; }
.check-summary .ic { display: inline-flex; width: 17px; height: 17px; border-radius: 50%; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; color: var(--ic-fg); flex: none; }
.check-summary .ok .ic { background: var(--ok); }
.check-summary .idle .ic { background: var(--muted); }
.check-summary .idle { color: var(--muted); }
.count.idle { background: var(--surface-2); color: var(--muted); }
.check-summary .warn .ic { background: var(--warn); }
.check-summary .err .ic { background: var(--danger); }
.issue { border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: 9px; padding: 9px 11px; margin-bottom: 8px; cursor: pointer; background: var(--surface); transition: box-shadow 0.15s; }
.issue:hover { box-shadow: var(--shadow); }
.issue.error { border-left-color: var(--danger); }
.issue.warning { border-left-color: var(--warn); }
.issue.focused { box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35); }
.issue-head { display: flex; gap: 8px; align-items: baseline; }
.issue h4 { margin: 0; font-size: 13.5px; line-height: 1.35; }
.sev { flex: none; font-size: 10.5px; font-weight: 800; text-transform: uppercase; padding: 1px 6px; border-radius: 5px; background: var(--info-bg-2); color: #1d4ed8; }
.issue.error .sev { background: var(--err-bg-2); color: var(--err-fg-2); }
.issue.warning .sev { background: var(--warn-bg-2); color: var(--warn-fg-2); }
.issue p { margin: 6px 0 0; font-size: 12.5px; color: var(--text-2); }
.issue .fix { color: var(--text); }
.issue-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.all-good { text-align: center; background: var(--ok-bg-3); border: 1px solid var(--ok-border-2); border-radius: 10px; padding: 16px; font-size: 13px; line-height: 1.5; }
.all-good .big { font-size: 30px; }

/* ---------- Tooltip, toast, modal, tour ---------- */
.tooltip {
  position: fixed;
  z-index: 60;
  max-width: 290px;
  background: #0f172a;
  color: #f1f5f9;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.4;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.tooltip .muted { color: var(--muted-2); }
.tooltip div { margin-top: 3px; }
.tip-hint { color: #7dd3fc; font-size: 11.5px; }
.tip-rate { font-weight: 600; }
.tip-rate.best, .tip-rate.shared { color: #86efac; }
.tip-rate.ok { color: #bef264; }
.tip-rate.avoid { color: #fcd34d; }
.tip-rate.used { color: #fca5a5; }
.tip-rate.bad { color: #cbd5e1; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 20px);
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  max-width: min(560px, calc(100vw - 32px));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 80;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
/* a message sits at the bottom, clear of the toolbar and tabs, and a click on it closes it */
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; cursor: pointer; }
.toast.ok { background: #14532d; }
.toast.warn { background: #7c2d12; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: center; justify-content: center; z-index: 90; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border-radius: 14px; padding: 20px 22px; width: min(720px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3); }
.modal h2 { font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.share-link input { width: 100%; box-sizing: border-box; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: inherit; }
.proj-list { list-style: none; padding: 0; margin: 0; }
.proj-list li { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 9px; margin-bottom: 6px; }
.proj-open { flex: 1; text-align: left; border: 0; background: none; padding: 9px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; border-radius: 9px; }
.proj-open:hover { background: var(--surface-2); }
.proj-open .muted { font-size: 12px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; font-size: 13px; }
.help-grid h3 { margin-top: 10px; }
.help-grid ol { padding-left: 18px; }

.tour {
  position: fixed;
  left: 252px;
  bottom: 18px;
  width: 370px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  padding: 12px 16px 14px;
  z-index: 70;
}
.tour[hidden] { display: none; }
.tour-top { display: flex; justify-content: space-between; align-items: center; }
.tour-count { font-size: 11.5px; font-weight: 700; color: var(--accent-text); text-transform: uppercase; letter-spacing: 0.04em; }
.tour-progress { height: 4px; background: var(--surface-4); border-radius: 4px; margin: 6px 0 10px; overflow: hidden; }
.tour-progress span { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }
.tour h3 { font-size: 16px; margin: 0 0 6px; color: var(--text); }
.tour-body { font-size: 13.5px; line-height: 1.5; }
.tour-status { margin-top: 10px; font-size: 12.5px; font-weight: 600; color: var(--warn-fg); background: var(--warn-bg); padding: 5px 9px; border-radius: 7px; }
.tour-status.ok { color: var(--ok-fg); background: var(--ok-bg); }
.tour-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 12px; }
.tour-hl { outline: 3px solid var(--accent) !important; outline-offset: 2px; animation: pulse 1.4s ease-in-out infinite; border-radius: 8px; }
@keyframes pulse {
  0%, 100% { outline-color: rgba(13, 148, 136, 1); }
  50% { outline-color: rgba(13, 148, 136, 0.3); }
}

/* ---------- Simulation ---------- */
.tabs .sim-tab { color: var(--sim-tab-fg); }
.tabs .sim-tab.active { color: var(--sim-tab-fg); }
body.sim-running .tabs .sim-tab::after { content: ' ●'; color: #16a34a; animation: pulse-dot 1s infinite; }
@keyframes pulse-dot { 50% { opacity: 0.2; } }
.sim-banner { background: var(--ok-bg-2); }
.sim-banner .tag { background: var(--ok-bg-5); color: var(--ok-fg-2); }
.sim-clock { font-family: var(--mono); font-weight: 700; font-size: 13px; color: var(--ok-fg-2); background: var(--ok-bg-2); padding: 3px 9px; border-radius: 6px; }
.sim-live-hint { font-size: 12px; color: var(--muted); margin-left: auto; }
.sim-layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: 0; }
.sim-parts { overflow-y: auto; padding: 12px 16px; background: var(--surface-2); }
.sim-parts h3 { margin: 6px 0 10px; }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 14px; }
.sim-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.sim-card header { display: flex; gap: 8px; align-items: center; }
.sim-card header .part-icon { width: 44px; height: 30px; }
.sim-status { display: flex; flex-wrap: wrap; gap: 4px; }
.pill { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.warn { background: var(--warn-bg-2); color: var(--warn-fg); }
.pill.err { background: var(--err-bg-2); color: var(--err-fg); }
.sim-controls { display: flex; flex-direction: column; gap: 6px; }
.sim-ctl span { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); }
.sim-ctl input[type=range] { width: 100%; accent-color: #059669; }
.sim-hold { justify-content: center; user-select: none; -webkit-user-select: none; touch-action: none; }
.sim-keys { display: grid; gap: 4px; margin-top: 4px; }
.sim-keys .sim-key { justify-content: center; padding: 6px 4px; min-width: 0; font-weight: 600; user-select: none; -webkit-user-select: none; }
.sim-keys.grid .sim-key { font-family: ui-monospace, Menlo, Consolas, monospace; }
.btn.sim-key.down { background: #059669; color: #fff; border-color: #059669; transform: translateY(1px); }
.btn.sim-hold.down, .btn.sim-hold.down:hover { background: #059669; color: #fff; border-color: #059669; transform: translateY(1px); }
.sim-toggle { font-size: 13px; display: flex; gap: 6px; align-items: center; }
.sim-out { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 40px; justify-content: center; }
.sim-reading { font-size: 12.5px; color: var(--text-2); text-align: center; }
.sim-reading.warn { color: var(--warn-fg-2); font-weight: 600; }
.sim-led { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border-strong-2); transition: background 0.08s, box-shadow 0.08s; }
.sim-led.burned { background: #57534e; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; border-color: #292524; }
.sim-buzzer { font-size: 30px; opacity: 0.35; filter: grayscale(1); }
.sim-buzzer.on { opacity: 1; filter: none; animation: shake 0.12s infinite; }
@keyframes shake { 50% { transform: rotate(8deg) scale(1.08); } }
.sim-relay { font-weight: 700; font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--surface-3); color: var(--text-3); border: 2px solid var(--border-strong); }
.sim-relay.on { background: var(--ok-bg); color: var(--ok-fg); border-color: #16a34a; }
.sim-servo { width: 120px; }
.sim-strip { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; background: #0f172a; padding: 6px; border-radius: 6px; }
.sim-px { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.sim-oled { width: 100%; max-width: 256px; border-radius: 4px; border: 3px solid #0f172a; }
.sim-lcd { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; background: #84cc16; color: #1a2e05; padding: 8px 10px; border-radius: 4px; border: 4px solid #1e3a8a; letter-spacing: 1px; line-height: 1.35; }
.sim-lcd.off { background: #3f6212; color: transparent; }
.sim-meter { width: 100%; height: 10px; background: var(--surface-4); border-radius: 99px; overflow: hidden; }
.sim-meter-bar { height: 100%; background: linear-gradient(90deg, #34d399, #059669); }
.sim-side { border-left: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; }
.sim-panel { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.sim-panel h3 { margin: 0 0 8px; }
.sim-panel-head { display: flex; justify-content: space-between; align-items: center; }
.sim-serial { background: #0f172a; color: #a7f3d0; font-family: var(--mono); font-size: 12px; height: 230px; overflow: auto; margin: 0; padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; }
.sim-event { font-size: 12.5px; padding: 6px 9px; border-radius: 7px; margin-bottom: 6px; line-height: 1.4; }
.sim-event.error { background: var(--err-bg); color: var(--err-fg); }
.sim-event.warn { background: var(--warn-bg); color: var(--warn-fg); }
.sim-event.info { background: var(--info-bg); color: var(--info-fg-3); }
.sim-pins td, .sim-pins th { padding: 4px 6px; font-size: 12px; }
.lvl { font-weight: 800; font-size: 11px; padding: 1px 6px; border-radius: 5px; }
.lvl.high { background: var(--orange-bg); color: #c2410c; }
.lvl.low { background: var(--surface-4); color: var(--text-2); }
.lvl.float { background: var(--warn-bg-2); color: var(--warn-fg); }
.lvl.data { background: var(--info-bg-4); color: var(--info-fg); }

/* ---------- Wokwi-style simulator ---------- */
@media (min-width: 1101px) {
  body.sim-wide .app { grid-template-columns: 0 minmax(0, 1fr) 0; }
  body.sim-wide .palette, body.sim-wide .side { visibility: hidden; overflow: hidden; border: 0; padding: 0; }
}
.wk-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.wk-play {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: #16a34a; color: #fff; font-size: 17px; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.45); transition: transform 0.1s, background 0.15s;
}
.wk-play:hover { background: #15803d; transform: scale(1.05); }
.wk-play.running { background: #0f172a; box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35); }
.wk-status { font-size: 13px; font-weight: 600; color: var(--ok-fg-2); }
.wk-status.stale { color: var(--warn-fg-2); }
.wk-status.bad { color: var(--err-fg-2); }
.wk-spacer { flex: 1; }
.wk-mode { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; font-size: 12.5px; }
.wk-mode label { padding: 5px 10px; cursor: pointer; display: flex; gap: 5px; align-items: center; background: var(--surface); }
.wk-mode label:has(input:checked) { background: var(--ok-bg-2); color: var(--ok-fg-2); font-weight: 700; }
.wk-mode label.disabled { opacity: 0.45; cursor: not-allowed; }
.wk-mode label[hidden] { display: none; }
.wk-mode input { accent-color: #059669; margin: 0; }
.wk-beta { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 0 4px; border-radius: 4px; background: var(--info-bg-2); color: var(--info-fg-3); }
.wk-layout { flex: 1; display: grid; grid-template-columns: minmax(300px, 40%) minmax(0, 1fr); min-height: 0; }
.wk-code { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid #1e293b; background: #0f172a; }
.wk-pane-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; background: #1e293b; color: #cbd5e1; font-size: 12.5px; }
.wk-file { font-family: var(--mono); color: #f8fafc; background: #0f172a; padding: 3px 10px; border-radius: 6px 6px 0 0; }
.wk-code .muted { color: var(--muted-2); }
.wk-code-error { padding: 7px 12px; background: #7f1d1d; color: #fee2e2; font-size: 12.5px; line-height: 1.4; }
.wk-code-error[hidden] { display: none; }
.wk-code-error .lint-line { background: rgba(255, 255, 255, 0.18); color: #fff; }
.code-gutter .run { background: #14532d; color: #bbf7d0; }
.wk-right { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.wk-diagram-wrap { flex: 1; position: relative; min-height: 0; background: var(--bb-table); overflow: hidden; }
.wk-diagram { position: absolute; inset: 0; overflow: auto; padding: 10px; }
.wk-diagram svg { width: 100%; height: auto; display: block; min-width: 520px; max-width: none; }
.wk-diagram.panning, .wk-diagram.panning * { cursor: grabbing !important; }
.wk-diagram-wrap .bb-zoom { z-index: 3; }
.wk-hint { position: absolute; left: 10px; bottom: 8px; font-size: 11.5px; color: var(--text-3); background: var(--glass-90); padding: 3px 9px; border-radius: 99px; border: 1px solid var(--border); pointer-events: none; }
.wk-hit { cursor: pointer; }
.wk-hit:hover { stroke: #0ea5e9; stroke-width: 2; stroke-dasharray: 4 3; }
.wk-hit.hold { cursor: grab; }
.wk-hit.hold.down { fill: rgba(34, 197, 94, 0.15); }
.wk-waves.on { animation: wk-pulse 0.25s infinite alternate; }
@keyframes wk-pulse { from { opacity: 0.35; } to { opacity: 1; } }
.wk-popover { position: fixed; width: 240px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 30px rgba(15, 23, 42, 0.22); padding: 10px 12px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.wk-popover[hidden] { display: none; }
/* pointer from the popover to its part (the popover sits above the part, or below when there's no room) */
.wk-popover::after { content: ''; position: absolute; left: var(--arrow-x, 50%); bottom: -7px; width: 12px; height: 12px; margin-left: -6px; background: var(--surface); border: 1px solid var(--border); border-top: 0; border-left: 0; transform: rotate(45deg); }
.wk-popover.below::after { bottom: auto; top: -7px; transform: rotate(225deg); }
.wk-pop-head { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.wk-pop-head .icon-btn { margin-left: auto; width: 26px; height: 26px; font-size: 14px; }
.wk-halt { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 24px)); background: var(--err-bg); border: 1px solid var(--err-border); color: var(--err-fg-3); border-radius: 12px; padding: 10px 14px; font-size: 13px; line-height: 1.45; box-shadow: 0 10px 24px rgba(127, 29, 29, 0.15); z-index: 4; }
.wk-halt[hidden] { display: none; }
.wk-halt-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.wk-bottom { height: 36%; min-height: 170px; display: flex; flex-direction: column; border-top: 1px solid var(--border); background: var(--surface); }
.wk-tabs { display: flex; gap: 2px; padding: 4px 8px 0; background: var(--surface-3); border-bottom: 1px solid var(--border); min-width: 0; }
.wk-tabs button { white-space: nowrap; }
.wk-tabs button { border: 0; background: transparent; padding: 6px 12px; font-size: 12.5px; font-weight: 600; color: var(--text-3); border-radius: 8px 8px 0 0; cursor: pointer; }
.wk-tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 -1px 0 var(--border) inset; }
.wk-panel { display: none; flex: 1; min-height: 0; overflow: auto; padding: 8px 10px; }
.wk-panel.active { display: flex; flex-direction: column; }
.wk-panel .sim-serial { flex: 1; height: auto; min-height: 60px; border-radius: 8px 8px 0 0; }
.wk-panel .sim-parts { padding: 0; background: transparent; overflow: visible; }
.sim-serial .partial { opacity: 0.85; }
.wk-serial-in { display: flex; gap: 6px; padding-top: 6px; }
.wk-serial-in input { flex: 1; border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-family: var(--mono); font-size: 12.5px; }
.wk-serial-in input:focus { outline: none; border-color: #059669; box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15); }

/* ---------- Examples menu: lessons ---------- */
.menu { max-height: min(78vh, 640px); overflow-y: auto; }
.menu-label { padding: 6px 10px 2px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }

/* ---------- Simulate: Dashboard (MQTT) ---------- */
.dash { padding: 10px 12px; }
.dash-empty { max-width: 560px; line-height: 1.5; }
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.dash-status { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.dash-mode { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; font-size: 12.5px; }
.dash-mode label { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; cursor: pointer; }
.dash-mode label + label { border-left: 1px solid var(--border); }
.dash-mode label:has(input:checked) { background: var(--ok-bg-2); color: var(--ok-fg-2); font-weight: 700; }
.dash-btns-right { display: inline-flex; gap: 6px; }
.dash-login { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.dash-login input { margin-left: 6px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.dash-status.ok { color: var(--ok-fg); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.dash-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; min-width: 0; color: var(--primary-2); }
.dash-name { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-val { font-size: 22px; font-weight: 700; color: var(--text); margin: 2px 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.dash-spark { width: 100%; height: 24px; display: block; }
.dash-btns { display: flex; gap: 4px; margin-top: 6px; }
.dash-log { margin-top: 10px; }
.dash-log summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.dash-log pre { font-family: var(--mono); font-size: 12px; max-height: 160px; overflow: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin: 6px 0 0; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 10px 0; }
.iot-fields .row { display: flex; gap: 6px; }
.iot-format { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px 8px; margin: 8px 0; }
.iot-format legend { font-size: 12px; font-weight: 600; color: var(--text-3); padding: 0 4px; }
.iot-format label { display: block; font-size: 13px; margin: 4px 0; line-height: 1.4; }
.iot-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.iot-row .grow { flex: 1; min-width: 180px; }
.iot-row .port { width: 90px; }
.iot-row .port input { width: 100%; }
.iot-row .tls { margin: 0 0 14px; }
.iot-broker .field[hidden] { display: none; }
.iot-fields .row input { flex: 1; min-width: 0; }

/* ---------- Simulate: Serial Plotter ---------- */
.plotter { display: flex; flex-direction: column; height: 100%; min-height: 220px; padding: 8px 12px; gap: 6px; }
.plot-bar { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.plot-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; }
.plot-key { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.plot-key b { font-variant-numeric: tabular-nums; }
.plot-sw { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.plot-btns { display: flex; gap: 6px; }
.plot-canvas { flex: 1; width: 100%; min-height: 170px; border: 1px solid var(--border); border-radius: 8px; }

/* ---------- Simulate: Multimeter ---------- */
.meter { padding: 10px 12px; }
.meter-body { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.meter-face { background: #f5b800; border-radius: 16px; padding: 12px; width: 230px; box-shadow: inset 0 0 0 3px #1f2937; flex: none; }
.meter-lcd { background: #b7c9a8; color: #111827; border-radius: 6px; border: 3px solid #1f2937; height: 64px; display: flex; align-items: baseline; justify-content: flex-end; gap: 6px; padding: 8px 12px; font-family: var(--mono); box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.25); }
.meter-lcd #meter-big { font-size: 34px; font-weight: 700; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.meter-lcd #meter-unit { font-size: 16px; font-weight: 700; }
.meter-modes { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.meter-mode { display: flex; align-items: center; gap: 6px; background: #1f2937; color: #f9fafb; border-radius: 8px; padding: 5px 8px; font-size: 13px; cursor: pointer; }
.meter-mode b { min-width: 26px; color: #fcd34d; }
.meter-mode.on { outline: 2px solid #fff; }
.meter-mode input { accent-color: #f5b800; }
.meter-probes { flex: 1; min-width: 220px; max-width: 460px; }
.meter-probes select { width: 100%; }
.meter-probes .field .probe, .probe { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: -1px; margin: 0 3px 0 0; border: 1px solid var(--border-strong-2); }
.probe.red { background: #dc2626; }
.probe.black { background: #111827; }
.meter-note { min-height: 1.4em; font-weight: 600; color: var(--text-2); }

/* ---------- Simulate: signal generator ---------- */
.siggen { padding: 10px 12px; }
.siggen-body { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.siggen-face { background: #1e3a5f; border-radius: 14px; padding: 12px; width: 236px; box-shadow: inset 0 0 0 3px #0f172a; flex: none; display: flex; flex-direction: column; gap: 10px; }
.siggen-lcd { background: #04121f; color: #67e8f9; border-radius: 6px; border: 2px solid #0f172a; padding: 8px 10px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.siggen-l1 { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; }
.siggen-l1 span { font-size: 18px; font-weight: 700; }
.siggen-l2 { font-size: 11px; opacity: 0.85; min-height: 1.3em; }
.siggen-wave { display: block; width: 100%; height: 56px; margin: 4px 0; }
.siggen-wave path { fill: none; stroke: #67e8f9; stroke-width: 2; vector-effect: non-scaling-stroke; }
.siggen-wave .zero { stroke: rgba(103, 232, 249, 0.25); stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.siggen-out { font: inherit; font-weight: 700; font-size: 13px; letter-spacing: 0.5px; border-radius: 8px; padding: 7px; border: 2px solid #0f172a; background: #334155; color: #e2e8f0; cursor: pointer; }
.siggen-out.on { background: #16a34a; color: #fff; box-shadow: 0 0 10px rgba(74, 222, 128, 0.6); }
.siggen-out:disabled { opacity: 0.55; cursor: not-allowed; }
.siggen-controls { flex: 1; min-width: 220px; max-width: 520px; }
.siggen-controls select { width: 100%; }
.siggen-waves { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 8px; }
.siggen-wave-btn { display: flex; align-items: center; gap: 4px; border: 1px solid var(--border-strong-2); border-radius: 8px; padding: 4px 8px; font-size: 13px; cursor: pointer; }
.siggen-wave-btn input { position: absolute; opacity: 0; pointer-events: none; }
.siggen-wave-btn.on { border-color: var(--accent); outline: 2px solid var(--accent); font-weight: 600; }
.siggen-wave-btn:focus-within { outline: 2px solid var(--accent); }
.siggen-knobs { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px 10px; }
.siggen-knobs input { width: 100%; }
.siggen-presets { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 8px; }

/* ---------- Simulate: fault finding ---------- */
.fault-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 12px; background: var(--warn-bg); border-bottom: 1px solid var(--warn-border-2); color: var(--warn-fg); font-size: 13px; }
.fault-bar[hidden] { display: none; }
.fault-bar.solved { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-fg); }
.fault-bar.gave-up { background: var(--info-bg); border-color: var(--border); color: var(--info-fg); }
.fault-bar .muted { color: inherit; opacity: 0.8; }
.fault-form { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.fault-form select { max-width: 220px; }
.fault-meta { font-variant-numeric: tabular-nums; opacity: 0.85; }
.fault-msg { flex-basis: 100%; font-weight: 600; }
.fault-msg:empty { display: none; }
.fault-actions { display: inline-flex; gap: 6px; }

/* ---------- Send to board (Web Serial) ---------- */
.ws-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.ws-baud { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.ws-out { font-family: var(--mono); font-size: 12.5px; background: #0b1220; color: #d1fae5; border-radius: 8px; padding: 10px; height: 220px; overflow: auto; white-space: pre-wrap; margin: 0 0 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .app { --palette-w: 210px; --side-w: 310px; }
  .tour { left: 226px; }
  .bb-layout { grid-template-columns: minmax(0, 1fr) 270px; }
}
@media (max-width: 1080px) {
  .brand span { display: none; }
  .top-actions .btn { padding: 7px 9px; }
}
/* Tablets (1024 px) and phones: the parts list and the properties panel become drawers, so the canvas gets the width */
@media (max-width: 1100px) {
  :root { --topbar: auto; }
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .project-name { order: 2; flex-basis: 100%; max-width: none; }
  .top-actions { order: 3; flex-basis: 100%; flex-wrap: wrap; margin-left: 0; padding-bottom: 2px; }
  .menu { position: fixed; left: 12px; right: 12px; top: auto; min-width: 0; }
  .mobile-bar { display: flex; gap: 8px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
  .mobile-bar .btn { flex: 1; justify-content: center; }
  .app { display: block; height: auto; }
  .panel-toggle { display: none; }
  .center { height: calc(100dvh - 150px); min-height: 480px; }
  .palette, .side {
    position: fixed;
    top: 0;
    bottom: 0;
    width: min(340px, 88vw);
    z-index: 75;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
    transition: transform 0.25s ease;
  }
  .palette { left: 0; transform: translateX(-105%); }
  .side { right: 0; transform: translateX(105%); }
  body.show-palette .palette, body.show-side .side { transform: none; }
  body.show-palette::after, body.show-side::after { content: ''; position: fixed; inset: 0; z-index: 74; background: rgba(0, 0, 0, 0.35); }
  .close-drawer { display: inline-block; }
  .panel-head.mobile-only { display: flex; padding: 12px 16px 0; }
  .bb-layout { display: block; overflow: auto; }
  .sim-layout { display: block; overflow: auto; }
  /* Simulate: the running circuit first, then the Serial Monitor, then the code — one page that scrolls */
  .wk-layout { display: flex; flex-direction: column; overflow: visible; }
  .wk-right { order: -1; min-height: 0; flex: none; }
  .wk-diagram-wrap { flex: none; height: min(60vh, 520px); min-height: 280px; }
  .wk-bottom { height: auto; min-height: 260px; }
  .wk-code { min-height: 320px; border-right: 0; flex: none; }
  #view-simulate { overflow: auto; }
  .wk-mode { order: 5; }
  .sim-side { border-left: 0; border-top: 1px solid var(--border); }
  .sim-live-hint { display: none; }
  .wk-tabs { flex-wrap: wrap; }
  .wk-tabs button { padding: 6px 9px; }
  .bb-steps { border-left: 0; border-top: 1px solid var(--border); }
  .bb-canvas { overflow-x: auto; }
  .tour { left: 16px; right: 16px; width: auto; bottom: 12px; }
  .help-grid { grid-template-columns: 1fr; }
  .banner { font-size: 12.5px; }
}
@media (max-width: 520px) {
  .tabs button { padding: 8px 10px; font-size: 13px; }
  .toolbar .sep { display: none; }
  .top-actions .sep { display: none; }
  .check-summary { grid-template-columns: 1fr; }
}

/* Parts palette */
.palette-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.part-name { overflow-wrap: anywhere; }
.supply-line { margin: -4px 0 10px; font-size: 12.5px; color: var(--muted); }
.supply-line b { color: var(--text); font-weight: 600; }
details.more { margin: -4px 0 10px; font-size: 13px; }
details.more summary { cursor: pointer; color: var(--primary); }
details.more p { margin: 6px 0 0; line-height: 1.5; }

/* ---------- Code tab: libraries ---------- */
.libs-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.libs-head h4 { margin: 0; }
.libs-head .muted { font-size: 12.5px; line-height: 1.45; }
.libs-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.lib-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.lib-card { border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; background: var(--surface); display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.lib-card.dep { background: var(--surface-2); }
.lib-name { font-size: 13.5px; }
.lib-why { line-height: 1.4; }
.lib-inc code { font-size: 11.5px; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.lib-note { color: var(--warn-fg); background: var(--warn-bg); border-radius: 6px; padding: 3px 7px; }
.lib-actions { display: flex; gap: 6px; margin-top: 2px; }
.lib-actions a.btn { text-decoration: none; }
.lib-core { margin-top: 8px; font-size: 12.5px; color: var(--text-3); }
.lib-core code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.lib-link { color: var(--accent-text); }

/* ---------- Wokwi-style editor tabs + Library Manager ---------- */
.lm-hidden { display: none !important; }
.lm-tabhost { display: flex; align-items: center; background: #1e293b; padding: 0 8px; }
.lm-tabs { display: flex; gap: 2px; }
.lm-tabs button { background: transparent; border: 0; color: var(--muted-2); font: 600 12.5px ui-monospace, Menlo, Consolas, monospace; padding: 8px 12px; border-bottom: 2px solid transparent; cursor: pointer; }
.lm-tabs button:hover { color: #e2e8f0; }
.lm-tabs button.active { color: #fff; border-bottom-color: #22c55e; background: #0f172a; }
.wk-pane-head .lm-tabs button { padding: 6px 10px; }
.lm-panel { flex: 1; min-height: 0; overflow: auto; background: var(--surface); }
.lm-txt { display: flex; flex-direction: column; background: #0f172a; }
.lm-txt[hidden], .lm-manager[hidden] { display: none; }
.lm-textarea { flex: 1; min-height: 200px; width: 100%; border: 0; resize: none; background: #0f172a; color: #e2e8f0; font: 13px/1.6 ui-monospace, Menlo, Consolas, monospace; padding: 12px 14px; outline: none; }
.lm-txt-note { font-size: 12px; padding: 8px 14px; background: #111827; color: var(--muted-2); }
.lm-txt-note code { color: #e2e8f0; }
.lm-manager { padding: 12px 14px; font-size: 13px; }
.lm-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.lm-head b { font-size: 15px; }
.lm-spacer { flex: 1; }
.lm-search { border: 1px solid var(--border); border-radius: 10px; padding: 8px; margin-bottom: 12px; background: var(--surface-2); }
.lm-q { width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 13px; }
.lm-results { max-height: 320px; overflow: auto; margin-top: 6px; }
.lm-row, .lm-res { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--surface-3); }
.lm-res.custom { background: var(--warn-bg); border-radius: 8px; }
.lm-main { flex: 1; min-width: 0; }
.lm-name { font-weight: 700; color: var(--text); text-decoration: none; }
a.lm-name:hover { text-decoration: underline; }
.lm-ver { font: 11.5px ui-monospace, Menlo, monospace; color: var(--muted); margin-left: 4px; }
.lm-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lm-why { color: var(--text-2); }
.lm-tag { font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--surface-3); color: var(--text-3); white-space: nowrap; }
.lm-tag.sim { background: var(--ok-bg); color: var(--ok-fg); }
.lm-tag.warn { background: var(--warn-bg-2); color: var(--warn-fg); }
.lm-tag.ok { background: var(--info-bg-4); color: var(--info-fg); }
.lm-lock { font-size: 14px; opacity: 0.6; }
.lm-installed { color: #16a34a; font-weight: 700; font-size: 12px; white-space: nowrap; }
.lm-empty { padding: 10px 4px; }
.lm-foot { font-size: 11.5px; margin-top: 12px; line-height: 1.6; }
.libs-summary { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.libs-summary .lib { background: var(--info-bg-3); color: var(--info-fg); border-radius: 99px; padding: 1px 8px; font-size: 11.5px; }
.libs-summary .lib.mine { background: var(--ok-bg); color: var(--ok-fg); }
.libs-summary .libs-btns { margin-left: auto; display: inline-flex; gap: 6px; flex-wrap: wrap; }
.libs-how { font-size: 12px; margin: 4px 0 6px; }
.lm-links { font-size: 12px; padding: 8px 14px; background: #111827; color: #cbd5e1; border-top: 1px solid #1e293b; line-height: 1.8; }
.lm-links a { color: #7dd3fc; text-decoration: none; white-space: nowrap; }
.lm-links a:hover { text-decoration: underline; }
.lm-links:empty { display: none; }

/* ---------- parts palette: category dropdowns ---------- */
.pal-tools { display: flex; justify-content: flex-end; margin: 4px 0 2px; }
.palette-group { border: 1px solid var(--border); border-radius: 10px; margin: 6px 0; background: var(--surface); overflow: hidden; }
.palette-group > summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-2); user-select: none; }
.palette-group > summary::-webkit-details-marker { display: none; }
.palette-group > summary::before { content: '▸'; font-size: 11px; color: var(--muted); transition: transform 0.15s; }
.palette-group[open] > summary::before { transform: rotate(90deg); }
.palette-group > summary:hover { background: var(--surface-2); }
.palette-group > summary:focus-visible { outline: 2px solid var(--primary-2); outline-offset: -2px; }
.pal-cat { flex: 1; }
.pal-count { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface-3); border-radius: 99px; padding: 1px 8px; text-transform: none; letter-spacing: 0; }
.palette-group[open] > .palette-grid { padding: 0 8px 8px; }

/* ---------- Oscilloscope (Simulate tab) ---------- */
.scope { display: flex; gap: 10px; flex: 1; min-height: 0; }
.scope-screen { flex: 1 1 60%; min-width: 0; min-height: 170px; border-radius: 8px; border: 6px solid #1f2937; background: #05140d; box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.6); }
.scope-screen canvas { display: block; width: 100%; height: 100%; }
.scope-side { flex: 0 1 330px; min-width: 220px; display: flex; flex-direction: column; gap: 8px; overflow: auto; font-size: 12px; }
.scope-chs { display: flex; flex-direction: column; gap: 4px; }
.scope-ch { display: flex; align-items: center; gap: 6px; }
.scope-ch span { flex: 0 0 38px; font-weight: 700; color: #111; background: var(--ch); border-radius: 4px; text-align: center; padding: 1px 0; font-size: 11px; }
.scope-ch select, .scope-knobs select { flex: 1; min-width: 0; font-size: 12px; padding: 2px 4px; }
.scope-knobs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; align-items: end; }
.scope-knobs label { display: flex; flex-direction: column; gap: 2px; color: var(--muted, var(--muted)); }
.scope-meas table { width: 100%; border-collapse: collapse; font-family: ui-monospace, Menlo, monospace; font-size: 11px; background: #05140d; border-radius: 6px; }
.scope-meas th { color: #86efac; font-weight: 600; text-align: left; padding: 3px 4px; }
.scope-meas td { padding: 2px 4px; white-space: nowrap; }
@media (max-width: 760px) { .scope { flex-direction: column; } .scope-side { flex-basis: auto; } }

/* Raspberry Pi: set-up commands in the Packages tab */
.lm-setup { background: #0f172a; color: #e2e8f0; padding: 8px 10px; border-radius: 8px; font-size: 12px; white-space: pre-wrap; overflow-x: auto; }

/* Code language picker (under the board list) */
.lang-label { margin: 10px 0 4px; font-size: 12px; font-weight: 600; color: var(--text-3); }
.lang-label[hidden] { display: none; }
.lang-pick { display: grid; grid-template-columns: 1fr; margin-bottom: 4px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; font-size: 12.5px; background: var(--surface); }
.lang-pick[hidden] { display: none; }
.lang-pick label { display: flex; gap: 6px; align-items: center; justify-content: flex-start; padding: 5px 10px; cursor: pointer; white-space: nowrap; min-width: 0; }
.lang-pick label + label { border-top: 1px solid var(--border); }
.lang-pick label:has(input:checked) { background: var(--ok-bg-2); color: var(--ok-fg-2); font-weight: 700; }
.lang-pick label.disabled { opacity: 0.45; cursor: not-allowed; }
.lang-pick input { margin: 0; }
.lang-note { margin: 6px 0 0; }

/* Accessibility: a visible keyboard focus ring everywhere, and no motion for people who ask for none */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--primary-2);
  outline-offset: 2px;
}
.code-input:focus-visible, .part-search:focus-visible, .project-name input:focus-visible { outline: none; } /* these draw their own ring */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Keyboard editing of the schematic: the pin picker and its focus ring */
#schematic:focus-visible { outline: 3px solid var(--primary-2); outline-offset: -3px; }
.kb-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 48px));
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 12px 48px rgba(15, 23, 42, 0.35);
}
.kb-dialog[open] { display: flex; flex-direction: column; gap: 8px; }
.kb-dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.kb-dialog h2 { margin: 0; font-size: 16px; }
.kb-dialog p { margin: 0; }
.kb-filter { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: var(--surface); color: var(--text); }
.kb-filter:focus { outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2); }
.kb-list { list-style: none; margin: 0; padding: 0; overflow: auto; min-height: 60px; border: 1px solid var(--border); border-radius: 8px; }
.kb-list li { display: flex; flex-direction: column; gap: 1px; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #eef2f7; }
.kb-list li:last-child { border-bottom: 0; }
.kb-list li.on { background: var(--info-bg-2); }
.kb-list li:hover:not(.on) { background: var(--surface-3); }
.kb-list .kb-h { font-size: 12px; color: var(--muted); }
.kb-list li.kb-remove .kb-l { color: var(--danger); }
.kb-list li.kb-none { cursor: default; color: var(--muted); }
.kb-actions { display: flex; justify-content: flex-end; }

/* the schematic drawing and the palette icons are line art in fixed dark strokes: in the dark theme they are inverted */
#schematic, .part-icon svg { filter: var(--draw-filter); }

/* ---------- Dark theme (VS Code Dark+ colours) ----------
   Chosen from the system setting, or with the sun/moon button (remembered in this browser). Pictures of real parts and
   boards (breadboard, simulator) keep their own colours on a dark mat (see the end of this file); the schematic drawing is inverted. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  color-scheme: dark;
  --draw-filter: invert(0.88) hue-rotate(180deg);
  --bg: #1e1e1e;
  --panel: #252526;
  --border: #3c3c3c;
  --primary: #0e639c;
  --primary-2: #3794ff;
  --accent: #4ec9b0;
  --danger: #f48771;
  --warn: #cca700;
  --ok: #89d185;
  --info: #3794ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
  --surface: #252526;
  --surface-2: #2a2d2e;
  --surface-3: #2d2d30;
  --surface-4: #3c3c3c;
  --ok-bg: #0f2f25;
  --ok-bg-2: #0f2f25;
  --ok-bg-3: #0d2a21;
  --ok-bg-5: #115e3a;
  --warn-bg: #332608;
  --warn-bg-2: #3d2e0a;
  --warn-bg-3: #5b4310;
  --err-bg: #3a1518;
  --err-bg-2: #451a1d;
  --info-bg: #04395e;
  --info-bg-2: #094771;
  --info-bg-3: #062f4a;
  --info-bg-4: #0b4a7a;
  --text-2: #cccccc;
  --text-3: #bbbbbb;
  --muted-2: #a0a0a0;
  --ok-fg: #86efac;
  --ok-fg-2: #6ee7b7;
  --ok-fg-3: #4ade80;
  --warn-fg: #fcd34d;
  --warn-fg-2: #fbbf24;
  --warn-fg-3: #fde68a;
  --err-fg: #fca5a5;
  --err-fg-2: #f87171;
  --err-fg-3: #fecaca;
  --info-fg: #9cdcfe;
  --info-fg-2: #c5cdfb;
  --info-fg-3: #9cdcfe;
  --sky-bg: #0c2a3f;
  --sky-bg-2: #0f3550;
  --purple-bg: #2a1f52;
  --teal-bg: #0b2f2e;
  --orange-bg: #442a10;
  --cream-bg: #2a2d2e;
  --sky-border: #1f5a80;
  --teal-border: #1b6660;
  --border-strong: #454545;
  --border-strong-2: #5a5a5a;
  --ok-border: #1f7a4a;
  --ok-border-2: #1f7a4a;
  --warn-border-2: #8a6a17;
  --err-border: #8b2c33;
  --glass-60: rgba(255, 255, 255, 0.08);
  --glass-95: rgba(37, 37, 38, 0.95);
  --glass-90: rgba(37, 37, 38, 0.9);
  --text: #d4d4d4;
  --muted: #9d9d9d;
  --muted-2: #a0a0a0;
  --btn-primary: #0e639c; /* white text: 6.4:1 */
  --btn-primary-hover: #1177bb;
  --btn-accent: #0f766e; /* white text: 5.5:1 */
  --btn-accent-hover: #115e59;
  --primary-text: #4daafc;
  --sim-tab-fg: #34d399;
  --tip-fg: #bbbbbb;
  --k-blue-fg: #9cdcfe;
  --k-black-fg: #d4d4d4;
  --k-purple-fg: #c586c0;
  --ic-fg: #1e1e1e;
  --bb-table: #2d2d2d; /* a dark work mat: the parts keep their real colours on it */
  --accent-text: #4ec9b0;
  --warn-text: #cca700;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --draw-filter: invert(0.88) hue-rotate(180deg);
  --bg: #1e1e1e;
  --panel: #252526;
  --border: #3c3c3c;
  --primary: #0e639c;
  --primary-2: #3794ff;
  --accent: #4ec9b0;
  --danger: #f48771;
  --warn: #cca700;
  --ok: #89d185;
  --info: #3794ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
  --surface: #252526;
  --surface-2: #2a2d2e;
  --surface-3: #2d2d30;
  --surface-4: #3c3c3c;
  --ok-bg: #0f2f25;
  --ok-bg-2: #0f2f25;
  --ok-bg-3: #0d2a21;
  --ok-bg-5: #115e3a;
  --warn-bg: #332608;
  --warn-bg-2: #3d2e0a;
  --warn-bg-3: #5b4310;
  --err-bg: #3a1518;
  --err-bg-2: #451a1d;
  --info-bg: #04395e;
  --info-bg-2: #094771;
  --info-bg-3: #062f4a;
  --info-bg-4: #0b4a7a;
  --text-2: #cccccc;
  --text-3: #bbbbbb;
  --muted-2: #a0a0a0;
  --ok-fg: #86efac;
  --ok-fg-2: #6ee7b7;
  --ok-fg-3: #4ade80;
  --warn-fg: #fcd34d;
  --warn-fg-2: #fbbf24;
  --warn-fg-3: #fde68a;
  --err-fg: #fca5a5;
  --err-fg-2: #f87171;
  --err-fg-3: #fecaca;
  --info-fg: #9cdcfe;
  --info-fg-2: #c5cdfb;
  --info-fg-3: #9cdcfe;
  --sky-bg: #0c2a3f;
  --sky-bg-2: #0f3550;
  --purple-bg: #2a1f52;
  --teal-bg: #0b2f2e;
  --orange-bg: #442a10;
  --cream-bg: #2a2d2e;
  --sky-border: #1f5a80;
  --teal-border: #1b6660;
  --border-strong: #454545;
  --border-strong-2: #5a5a5a;
  --ok-border: #1f7a4a;
  --ok-border-2: #1f7a4a;
  --warn-border-2: #8a6a17;
  --err-border: #8b2c33;
  --glass-60: rgba(255, 255, 255, 0.08);
  --glass-95: rgba(37, 37, 38, 0.95);
  --glass-90: rgba(37, 37, 38, 0.9);
  --text: #d4d4d4;
  --muted: #9d9d9d;
  --muted-2: #a0a0a0;
  --btn-primary: #0e639c; /* white text: 6.4:1 */
  --btn-primary-hover: #1177bb;
  --btn-accent: #0f766e; /* white text: 5.5:1 */
  --btn-accent-hover: #115e59;
  --primary-text: #4daafc;
  --sim-tab-fg: #34d399;
  --tip-fg: #bbbbbb;
  --k-blue-fg: #9cdcfe;
  --k-black-fg: #d4d4d4;
  --k-purple-fg: #c586c0;
  --ic-fg: #1e1e1e;
  --bb-table: #2d2d2d; /* a dark work mat: the parts keep their real colours on it */
  --accent-text: #4ec9b0;
  --warn-text: #cca700;
}

/* Breadboard and Simulate tabs in the dark theme: a dark mat under the real-coloured parts. Only the page changes —
   exported pictures (PNG, SVG, PDF) are drawn on the light table, for printing. The Simulate tab outlines only the
   board, not the parts: they redraw while the simulation runs, and a filter on them would slow that down. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bb-canvas svg [fill="#fdfaf3"], :root:not([data-theme="light"]) .wk-diagram svg [fill="#fdfaf3"] { fill: var(--bb-table); } /* the table, and holes you see it through */
  :root:not([data-theme="light"]) .bb-canvas svg [stroke="#fdfaf3"], :root:not([data-theme="light"]) .wk-diagram svg [stroke="#fdfaf3"] { stroke: var(--bb-table); } /* the halo around labels */
  :root:not([data-theme="light"]) .bb-canvas .bb-on-table, :root:not([data-theme="light"]) .wk-diagram .bb-on-table { fill: #e2e8f0; }
  :root:not([data-theme="light"]) .bb-canvas .bb-rail-label.plus, :root:not([data-theme="light"]) .wk-diagram .bb-rail-label.plus { fill: #fca5a5; }
  :root:not([data-theme="light"]) .bb-canvas .bb-rail-label.minus, :root:not([data-theme="light"]) .wk-diagram .bb-rail-label.minus { fill: #93c5fd; }
  :root:not([data-theme="light"]) .wk-diagram .bb-warm { fill: #fbbf24; }
  :root:not([data-theme="light"]) .bb-canvas .bb-board, :root:not([data-theme="light"]) .bb-canvas .bb-part:not(.sel), :root:not([data-theme="light"]) .wk-diagram .bb-board { filter: drop-shadow(0 0 1.2px rgba(226, 232, 240, 0.6)); } /* a faint light edge so a black board or part does not melt into the dark mat */
}
:root[data-theme="dark"] .bb-canvas svg [fill="#fdfaf3"], :root[data-theme="dark"] .wk-diagram svg [fill="#fdfaf3"] { fill: var(--bb-table); } /* the table, and holes you see it through */
:root[data-theme="dark"] .bb-canvas svg [stroke="#fdfaf3"], :root[data-theme="dark"] .wk-diagram svg [stroke="#fdfaf3"] { stroke: var(--bb-table); } /* the halo around labels */
:root[data-theme="dark"] .bb-canvas .bb-on-table, :root[data-theme="dark"] .wk-diagram .bb-on-table { fill: #e2e8f0; }
:root[data-theme="dark"] .bb-canvas .bb-rail-label.plus, :root[data-theme="dark"] .wk-diagram .bb-rail-label.plus { fill: #fca5a5; }
:root[data-theme="dark"] .bb-canvas .bb-rail-label.minus, :root[data-theme="dark"] .wk-diagram .bb-rail-label.minus { fill: #93c5fd; }
:root[data-theme="dark"] .wk-diagram .bb-warm { fill: #fbbf24; }
:root[data-theme="dark"] .bb-canvas .bb-board, :root[data-theme="dark"] .bb-canvas .bb-part:not(.sel), :root[data-theme="dark"] .wk-diagram .bb-board { filter: drop-shadow(0 0 1.2px rgba(226, 232, 240, 0.6)); } /* a faint light edge so a black board or part does not melt into the dark mat */

/* ---------- Assignment checklist (js/assignment.js) ---------- */
.assign-panel h2 { display: flex; align-items: center; gap: 8px; }
.assign-panel h2 .ico { width: 18px; height: 18px; color: var(--primary-2); }
.assign-panel h2 .count { margin-left: auto; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); }
.assign-panel h2 .count.all { background: var(--ok-bg); color: var(--ok-fg-2); }
.assign-brief { margin: 4px 0 8px; font-size: 13px; color: var(--text-2); }
.assign-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.assign-list li { display: flex; gap: 8px; align-items: flex-start; }
.assign-list li small { display: block; color: var(--muted); font-size: 12px; }
.assign-list .ic { flex: none; display: inline-flex; width: 18px; height: 18px; border-radius: 50%; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; border: 2px solid var(--border-strong); color: #fff; }
.assign-list li.ok .ic { background: var(--ok); border-color: var(--ok); }
.assign-list.editing li { justify-content: space-between; align-items: center; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; }
.as-add { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.as-add select, .as-add input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; font: inherit; font-size: 13px; background: var(--surface); color: var(--text); }
.as-add input[type="number"] { width: 64px; }
.as-add [hidden] { display: none; }

/* ---------- Power budget (js/power.js, Parts list tab) ---------- */
.power-budget { margin-top: 22px; }
.power-budget h2 { display: flex; align-items: center; gap: 8px; }
.power-budget h2 .ico { width: 18px; height: 18px; color: var(--warn); }
.power-table td:not(:first-child), .power-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; width: 110px; }
.power-table tfoot th { border-top: 2px solid var(--border); }
.power-budget .table th { text-transform: none; letter-spacing: 0; } /* "mA", not "MA" */
.power-warn { padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-fg); font-size: 13px; }
.power-warn .ico { width: 15px; height: 15px; vertical-align: -3px; }
.power-awake input { width: min(360px, 100%); }
.buy { white-space: nowrap; font-size: 12.5px; }
.buy-link { color: var(--accent-text); }

/* ---------- Block coding (js/blocks-editor.js) ---------- */
.code-view-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.code-view-switch .btn { border: 0; border-radius: 0; box-shadow: none; }
.code-view-switch .btn + .btn { border-left: 1px solid var(--border); }
#view-code .code-view-switch .btn[aria-pressed="true"], #view-code .code-view-switch .btn[aria-pressed="true"]:hover { background: var(--btn-primary); color: #fff; }
.blocks-wrap { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 34%); }
.blocks-wrap[hidden] { display: none; }
.blocks-area { position: relative; min-height: 360px; }
.blocks-side { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); background: var(--ed-bg, #0f172a); }
.blocks-side-head { padding: 7px 12px; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.blocks-code { flex: 1; margin: 0; padding: 10px 12px; overflow: auto; font: 12px/1.55 var(--mono); color: var(--ed-fg, #e2e8f0); white-space: pre; }
@media (max-width: 900px) { .blocks-wrap { grid-template-columns: 1fr; grid-template-rows: minmax(360px, 1fr) 220px; } .blocks-side { border-left: 0; border-top: 1px solid var(--border); } }
.code-editor[hidden], .lm-tabhost[hidden] { display: none; }

/* ---------- External power required (js/power.js) ---------- */
.power-status { margin: 10px 0 14px; padding: 10px 12px; border-radius: 10px; font-size: 13px; }
.power-status b { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.power-status b .ico { width: 16px; height: 16px; }
.power-status ul { margin: 6px 0 0; padding-left: 20px; }
.power-status.required { background: var(--warn-bg); color: var(--warn-fg); border: 1px solid var(--warn-border-2); }
.power-status.ok { background: var(--ok-bg); color: var(--ok-fg-2); }
.power-status.ok span { display: block; margin-top: 2px; }
.power-ext { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 8px 0; background: var(--surface); }
.power-ext-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; font-size: 13px; }
.power-ext-head span { color: var(--warn-fg); font-weight: 600; }
.power-ext-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.power-ext-fields .field { margin: 0; }

/* ---------- Simulate → Power supply (js/sim/psupanel.js): a lab bench supply ---------- */
.psu-panel { padding: 10px 12px; display: grid; gap: 12px; }
.psu-empty h3 { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.psu-empty p { font-size: 13px; color: var(--text-2); max-width: 720px; }
.psu-unit { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--surface); }
.psu-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 8px; font-size: 13px; }
.psu-face { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; background: linear-gradient(#374151, #1f2937); box-shadow: inset 0 0 0 2px #9ca3af; }
.psu-lcd { display: inline-flex; align-items: baseline; gap: 4px; min-width: 128px; padding: 6px 10px; border-radius: 6px; background: #0b0b0b; box-shadow: inset 0 0 0 1px #374151; }
.psu-val { font: 700 30px/1 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; color: #ef4444; letter-spacing: 1px; text-shadow: 0 0 8px rgba(239, 68, 68, 0.45); font-variant-numeric: tabular-nums; }
.psu-unit-l { color: #fca5a5; font-size: 14px; }
.psu-face.off .psu-val { color: #7f1d1d; text-shadow: none; }
.psu-face.setting .psu-val { opacity: 0.75; }
.psu-leds { display: grid; gap: 4px; }
.psu-led { font: 700 11px/1 var(--font); color: #6b7280; padding: 3px 7px; border-radius: 4px; background: #111827; }
.psu-led.on { color: #052e16; background: #22c55e; box-shadow: 0 0 8px rgba(34, 197, 94, 0.7); }
.psu-led.cc.on { color: #450a0a; background: #f87171; box-shadow: 0 0 8px rgba(248, 113, 113, 0.7); }
.psu-output { margin-left: auto; padding: 10px 16px; border: 0; border-radius: 8px; font: 700 13px var(--font); letter-spacing: 0.06em; color: #e5e7eb; background: #4b5563; cursor: pointer; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.35); }
.psu-output.on { color: #fff; background: #16a34a; box-shadow: 0 0 10px rgba(22, 163, 74, 0.55), inset 0 -2px 0 rgba(0, 0, 0, 0.25); }
.psu-output:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.psu-ctl { display: grid; gap: 6px; margin: 10px 0 4px; }
.psu-knob { display: grid; grid-template-columns: 110px minmax(120px, 1fr) 80px 16px; align-items: center; gap: 8px; font-size: 13px; }
.psu-knob input[type="number"] { padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: var(--surface); color: var(--text); }
.psu-note { margin: 6px 0; font-size: 12.5px; color: var(--text-2); min-height: 1.4em; }
@media (max-width: 600px) { .psu-knob { grid-template-columns: 1fr 70px 14px; } .psu-knob span { grid-column: 1 / -1; } }
.power-status.over { background: var(--err-bg); color: var(--err-fg); border: 1px solid var(--err-border); }
.psu-warn { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; font-size: 13px; background: var(--warn-bg); color: var(--warn-fg); border: 1px solid var(--warn-border-2); }
.psu-warn[hidden] { display: none; }
.psu-warn b { display: flex; align-items: center; gap: 6px; }
.psu-warn b .ico { width: 15px; height: 15px; }
.psu-warn ul { margin: 4px 0 0; padding-left: 18px; }
.psu-warn.error { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-border); }

/* the student version's tag beside the name (js/edition.js) */
.edition-tag { margin-left: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; letter-spacing: 0.02em; color: var(--accent-text); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.edition-tag[hidden] { display: none; }

/* autocomplete in the code editor (js/editor-assist.js): the editor's own colours, light or dark */
.ac-pop { position: fixed; z-index: 60; min-width: 300px; max-width: min(560px, calc(100vw - 8px)); max-height: 248px; overflow-y: auto; background: var(--ed-bg, #111a2e); border: 1px solid var(--border, #2c3a55); border-radius: 8px; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.22); padding: 4px; font-family: var(--mono); font-size: 12.5px; color: var(--ed-fg, #dbe4f3); }
.ac-pop[hidden] { display: none; }
.ac-item { display: flex; align-items: baseline; gap: 8px; padding: 4px 8px; border-radius: 5px; cursor: pointer; white-space: nowrap; }
.ac-item.on, .ac-item:hover { background: var(--ed-sel, #1e3a6e); }
.ac-kind { flex: none; width: 18px; text-align: center; font-size: 11px; color: var(--ed-kw, #8fb3ff); }
.ac-kind.k-pin { color: var(--ed-com, #6ee7b7); }
.ac-kind.k-class { color: var(--ed-num, #fbbf24); }
.ac-kind.k-snippet { color: var(--ed-pre, #f0abfc); }
.ac-label { flex: none; }
.ac-detail { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--ed-gutter-fg, #8494ab); font-family: var(--font, inherit); font-size: 11.5px; }

/* coaching in the code check (student version, js/coach.js) */
.coach { margin: 6px 0 2px 22px; padding: 0; display: grid; gap: 6px; font-size: 12.5px; line-height: 1.5; }
.coach[hidden] { display: none; }
.coach li { padding: 6px 10px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 8%, transparent); border-left: 3px solid var(--accent); }
.coach code { font-size: 11.5px; }
.coach-why { display: block; margin-top: 3px; color: var(--text-2); }
.coach-btn svg { width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px; }

/* the Code tab: the code check on the left of the editor */
.code-body { flex: 1; min-height: 0; display: flex; }
.code-body > .code-editor { flex: 1; min-width: 0; }
.code-body > :not(.code-side):not(.code-editor) { flex: 1; min-width: 0; }
.code-side { flex: none; width: 340px; max-width: 40%; overflow-y: auto; scroll-padding-top: 36px; padding: 10px 12px; border-right: 1px solid var(--border); background: var(--surface); }
.code-side[hidden], .code-side.lm-hidden { display: none; }
.code-side .code-lint h4 { margin-top: 0; position: sticky; top: -10px; padding: 4px 0; background: var(--surface); z-index: 1; }
.code-side .lint { flex-wrap: wrap; }
.code-side .lint .btn { margin-top: 4px; }
.code-side .coach { margin-left: 18px; width: 100%; }
.code-foot:not(:has(.code-libs:not(:empty))) { display: none; }
@media (max-width: 900px) {
  /* a phone: the code, then its check under it; the Code tab scrolls so neither is squeezed away */
  #view-code { overflow-y: auto; }
  .code-body { flex: none; flex-direction: column; }
  .code-body > .code-editor { flex: none; height: 62vh; min-height: 300px; }
  .code-side { order: 2; width: auto; max-width: none; max-height: 50vh; border-right: 0; border-top: 1px solid var(--border); }
  #view-code .code-foot { max-height: none; }
}
.coach-fns { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 2px; color: var(--text-2); }
.coach .coach-fns li { background: none; border: 0; padding: 0; border-radius: 0; list-style: disc; }
.code-view-switch[hidden] { display: none; }

/* the student version: each part's steps in the code check (js/coach.js progress) */
.progress-box { margin-bottom: 12px; }
.progress-box h4 { display: flex; justify-content: space-between; align-items: baseline; }
.pg-row { padding: 6px 8px; border-radius: 7px; background: var(--surface-2); margin-bottom: 4px; font-size: 12.5px; }
.pg-row.all { background: var(--ok-bg-3); }
.pg-steps { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; }
.pg-step { color: var(--text-2); white-space: nowrap; }
.pg-step.done { color: var(--ok-fg); font-weight: 600; }

/* hover tip in the code editor: what a name is (js/editor-assist.js) */
.ac-tip { position: fixed; z-index: 61; max-width: min(420px, calc(100vw - 16px)); padding: 6px 10px; border-radius: 7px; background: var(--ed-bg, #111a2e); color: var(--ed-fg, #dbe4f3); border: 1px solid var(--border, #2c3a55); box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2); font-size: 12.5px; line-height: 1.45; pointer-events: none; }
.ac-tip[hidden] { display: none; }
