/* Three looks share one set of tokens. Dark is the workbench in the site's navy (repo
   app/globals.css, html[data-theme="dark"]): the board's gold pads, lit LEDs and live wires are the
   brightest things on screen. Gray is neutral, without the blue, its grid drawn as faint white
   lines; it is the default (theme-boot.js). Light is a white desk. The look is chosen in the app
   bar and kept per browser. */
:root {
  color-scheme: dark;
  --bg: #07101b;
  --surface: #0c1726;
  --surface-raised: #13233a;
  --surface-hover: #172a45;
  --surface-muted: #0a1422;
  --canvas: #091320;
  --dot: #1a2a3f;
  --line: #1a2b42;
  --line-strong: #27405f;
  --ink: #e3eefc;
  --muted: #8199b6;
  --faint: #5b7593;
  --accent: #2dd4bf;
  --accent-soft: rgb(45 212 191 / 0.14);
  --run: #16a34a;
  --run-top: #22c55e;
  --danger: #f87171;
  --warn: #fbbf24;
  --console: #050c16;
  --console-ink: #cfe0f3;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --radius: 8px;
  --shadow-pop: 0 1px 0 rgb(255 255 255 / 0.04) inset, 0 10px 28px rgb(0 0 0 / 0.45);

  /* The site's code palette (CodeBlock.tsx), so code looks the same in the chat and here. */
  --code-bg: #0a1a2e;
  --code-text: #dbe8f7;
  --code-muted: #7d9ab5;
  --code-comment: #6f8aa3;
  --code-string: #ffb27a;
  --code-number: #c9a6ff;
  --code-preproc: #ff9ec4;
  --code-keyword: #8ab4f8;
  --code-type: #7fdbe8;
  --code-function: #9fe0a8;
  --code-constant: #ffd479;
  --code-gutter: #4d6886;
  --code-active-line: rgb(127 178 240 / 0.06);
  --code-punct: #9fb6cf;

  --accent-ink: #042a25;
  --appbar-top: #0f1e33;
  --appbar-bottom: #0b1727;
  --logo-bg: linear-gradient(145deg, #134e4a, #0d2f3f);
  --tag-line: rgb(251 191 36 / 0.28);
  --tag-bg: rgb(251 191 36 / 0.1);
  --tag-ink: #fcd34d;
  --ok-ink: #86efac;
  --busy-ink: #99f6e4;
  --error-ink: #fca5a5;
  --danger-line: rgb(248 113 113 / 0.38);
  --danger-bg: rgb(248 113 113 / 0.1);
  --danger-hover: rgb(248 113 113 / 0.18);
  --swatch-ring: rgb(255 255 255 / 0.22);
  --thumb: #f1f7ff;
  --thumb-shadow: rgb(0 0 0 / 0.5);
  --float-bg: rgb(10 20 34 / 0.92);
  --note-line: #23415f;
  --note-bg: rgb(14 32 54 / 0.95);
  --note-ink: #d6e6fa;
  --note-error-line: rgb(248 113 113 / 0.42);
  --note-error-bg: rgb(58 18 22 / 0.95);
  --note-error-ink: #fecaca;
  --note-warn-line: rgb(251 191 36 / 0.38);
  --note-warn-bg: rgb(52 37 8 / 0.95);
  --note-warn-ink: #fde68a;
  --build-error-bg: rgb(58 18 22 / 0.7);
  --build-ok-bg: rgb(14 52 32 / 0.6);

  /* The bench: what the parts and wires sit on. */
  --canvas-vignette: rgb(0 0 0 / 0.5);
  --part-shadow: rgb(0 0 0 / 0.5);
  --part-lift: rgb(0 0 0 / 0.6);
  --wire-casing: rgb(0 0 0 / 0.55);
  --wire-black: #0b0f15;
  --wire-black-rim: #6b7c93;
  --pin-dot-rim: #04101c;
  --flag-ground: #cbd5e1;
  --flag-caption: #94a3b8;

  /* The plotter's series, in a fixed order, checked for colour-blind separation on these surfaces. */
  --plot-1: #3987e5;
  --plot-2: #d95926;
  --plot-3: #199e70;
  --plot-4: #c98500;
  --plot-5: #d55181;
  --plot-6: #008300;
}

/* Neutral gray: the same workbench without the blue cast, like a CAD viewport. */
:root[data-sim-theme="gray"] {
  color-scheme: dark;
  --bg: #1b1c1f;
  --surface: #232428;
  --surface-raised: #2d2e33;
  --surface-hover: #35373c;
  --surface-muted: #1f2023;
  --canvas: #3b3d42;
  --grid-minor: rgb(255 255 255 / 0.045);
  --grid-major: rgb(255 255 255 / 0.09);
  --line: #303236;
  --line-strong: #44464c;
  --ink: #e7e8ea;
  --muted: #a2a5ac;
  --faint: #767980;
  --console: #18191c;
  --console-ink: #d5d7db;
  --shadow-pop: 0 1px 0 rgb(255 255 255 / 0.04) inset, 0 10px 28px rgb(0 0 0 / 0.42);
  --code-bg: #222327;
  --code-text: #dcdee2;
  --code-muted: #8b8f97;
  --code-comment: #80858e;
  --code-gutter: #5e6269;
  --code-active-line: rgb(255 255 255 / 0.04);
  --code-punct: #a9adb5;
  --appbar-top: #27282c;
  --appbar-bottom: #212225;
  --logo-bg: linear-gradient(145deg, #134e4a, #1f2a2b);
  --float-bg: rgb(36 37 41 / 0.94);
  --note-line: #4a4d54;
  --note-bg: rgb(45 46 51 / 0.96);
  --note-ink: #e2e4e8;
  --canvas-vignette: rgb(0 0 0 / 0.26);
  --part-shadow: rgb(0 0 0 / 0.45);
  --part-lift: rgb(0 0 0 / 0.55);
  --wire-casing: rgb(0 0 0 / 0.45);
  --wire-black: #0b0c0e;
  --wire-black-rim: #8b9099;
  --pin-dot-rim: #1b1c1f;
  --flag-ground: #d4d7dc;
  --flag-caption: #a2a5ac;
}

/* Light: a white desk. Colours that were light-on-dark turn into their deeper shades. */
:root[data-sim-theme="light"] {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-raised: #f0f3f7;
  --surface-hover: #e7ecf2;
  --surface-muted: #f5f7fa;
  --canvas: #f6f8fa;
  --dot: #c5ced9;
  --line: #e0e5ec;
  --line-strong: #cad2dc;
  --ink: #0f1a2a;
  --muted: #4b5b70;
  --faint: #8796a8;
  --accent: #0d9488;
  --accent-soft: rgb(13 148 136 / 0.12);
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --warn: #d97706;
  --console: #fafbfc;
  --console-ink: #1f2a37;
  --shadow-pop: 0 1px 2px rgb(15 23 42 / 0.06), 0 8px 24px rgb(15 23 42 / 0.12);
  --code-bg: #ffffff;
  --code-text: #1e293b;
  --code-muted: #64748b;
  --code-comment: #6b7c93;
  --code-string: #c2410c;
  --code-number: #7c3aed;
  --code-preproc: #be185d;
  --code-keyword: #1d4ed8;
  --code-type: #0e7490;
  --code-function: #15803d;
  --code-constant: #a16207;
  --code-gutter: #a3b0c0;
  --code-active-line: rgb(15 23 42 / 0.035);
  --code-punct: #475569;
  --appbar-top: #ffffff;
  --appbar-bottom: #f7f9fb;
  --logo-bg: linear-gradient(145deg, #ccfbf1, #e0f2fe);
  --tag-line: rgb(217 119 6 / 0.3);
  --tag-bg: rgb(251 191 36 / 0.14);
  --tag-ink: #92400e;
  --ok-ink: #15803d;
  --busy-ink: #0f766e;
  --error-ink: #b91c1c;
  --danger-line: rgb(220 38 38 / 0.35);
  --danger-bg: rgb(220 38 38 / 0.07);
  --danger-hover: rgb(220 38 38 / 0.13);
  --swatch-ring: rgb(15 23 42 / 0.18);
  --thumb: #ffffff;
  --thumb-shadow: rgb(15 23 42 / 0.25);
  --float-bg: rgb(255 255 255 / 0.94);
  --note-line: #cfd8e3;
  --note-bg: rgb(255 255 255 / 0.97);
  --note-ink: #1e2b3c;
  --note-error-line: rgb(220 38 38 / 0.35);
  --note-error-bg: rgb(254 242 242 / 0.97);
  --note-error-ink: #991b1b;
  --note-warn-line: rgb(217 119 6 / 0.35);
  --note-warn-bg: rgb(255 251 235 / 0.97);
  --note-warn-ink: #92400e;
  --build-error-bg: #fef2f2;
  --build-ok-bg: #f0fdf4;
  --canvas-vignette: rgb(15 23 42 / 0.05);
  --part-shadow: rgb(15 23 42 / 0.22);
  --part-lift: rgb(15 23 42 / 0.3);
  --wire-casing: rgb(15 23 42 / 0.2);
  --wire-black: #1f2937;
  --wire-black-rim: rgb(15 23 42 / 0.2);
  --pin-dot-rim: #ffffff;
  --flag-ground: #475569;
  --flag-caption: #64748b;
  --plot-1: #2a78d6;
  --plot-2: #eb6834;
  --plot-3: #1baf7a;
  --plot-4: #eda100;
  --plot-5: #e87ba4;
  --plot-6: #008300;
}

::view-transition-old(root),
::view-transition-new(root) { animation-duration: 220ms; }

* { box-sizing: border-box; scrollbar-color: var(--line-strong) transparent; scrollbar-width: thin; }
[hidden] { display: none !important; }

/* The page itself, when the simulator is the whole page. On the site it is a window inside one of
   the site's pages (.sim-host), and the page around it is the site's. */
:root:not(:has(.sim-host)), :root:not(:has(.sim-host)) body { height: 100%; }

:root:not(:has(.sim-host)) body {
  margin: 0;
  background: var(--bg);
}

/* Everything below the page itself is scoped to the simulator, so on the site it leaves the site's
   own widgets alone. :where keeps each rule as weak as it was unscoped. */
:where(.app) {
  /* the site's own font (Heebo, from the site's --font-heebo); Segoe UI when the page runs alone */
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-heebo, "Segoe UI"), "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

:where(.app) :is(h1, h2) { margin: 0; font-weight: 600; }
:where(.app) h1 { font-size: 15px; letter-spacing: 0.1px; }
:where(.app) h2 { font-size: 13px; }

:where(.app) :is(button, select, input) { font: inherit; color: inherit; }
:where(.app) button { cursor: pointer; }
:where(.app) :is(button, select):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

:where(.app) button svg :is(path, rect, circle) { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:where(.app) button svg .solid { fill: currentColor; stroke: none; }

.app {
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr);
  height: 100dvh;
}

/* ---------- top bar ---------- */

.appbar {
  display: flex;
  align-items: center;
  padding-inline: 16px;
  background: linear-gradient(180deg, var(--appbar-top), var(--appbar-bottom));
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* The look: three buttons with a thumb that slides to the chosen one. */
.theme-switch {
  position: relative;
  display: flex;
  flex: none;
  margin-inline-start: auto;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-muted);
}

.theme-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  inset-inline-start: 2px;
  width: 30px;
  border-radius: 7px;
  background: var(--surface-raised);
  box-shadow: inset 0 0 0 1px var(--line-strong), 0 1px 2px rgb(0 0 0 / 0.18);
  transform: translateX(calc(var(--choice, 0) * -30px));
  transition: transform 220ms var(--ease-out);
}

/* Until app.js marks the switch, it already stands on the look theme-boot.js put on the page. */
:root[data-sim-theme="gray"] .theme-switch { --choice: 1; }
:root[data-sim-theme="light"] .theme-switch { --choice: 2; }

.theme-choice {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--faint);
  transition: color 120ms ease;
}

.theme-choice[aria-pressed="true"] { color: var(--accent); }

@media (hover: hover) and (pointer: fine) {
  .theme-choice:hover:not([aria-pressed="true"]) { color: var(--ink); }
}

.logo {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--logo-bg);
  box-shadow: 0 0 0 1px rgb(45 212 191 / 0.28) inset;
  color: var(--accent);
}

.logo svg rect, .logo svg path { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }

.board-name {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.tag {
  padding: 1px 8px;
  border: 1px solid var(--tag-line);
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-ink);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- layout ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7px var(--side-width, 440px);
  min-height: 0;
}

.splitter {
  position: relative;
  cursor: col-resize;
  touch-action: none;
  background: var(--surface);
}

.splitter::after {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 3px;
  width: 2px;
  background: var(--line);
  transform: scaleX(0.5);
  transition: background-color 100ms ease, transform 100ms ease;
}

.splitter:focus-visible { outline: none; }
.splitter:focus-visible::after, .splitter.dragging::after { transform: scaleX(1); background: var(--accent); }

@media (hover: hover) and (pointer: fine) {
  .splitter:hover::after { transform: scaleX(1); background: var(--accent); }
}

/* One column that never grows with its contents: a busy toolbar must not push the code panel. */
.bench {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 48px minmax(0, 1fr) 28px;
  min-width: 0;
  min-height: 0;
}

/* ---------- bench toolbar ---------- */

.bench-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding-inline: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.transport { display: flex; flex: none; align-items: center; gap: 10px; }

.run, .stop {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 15px;
  border-radius: var(--radius);
  font-weight: 600;
  transition: transform 120ms var(--ease-out), filter 120ms ease, background-color 120ms ease;
}

.run {
  border: 0;
  background: linear-gradient(180deg, var(--run-top), var(--run));
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.22) inset, 0 4px 14px rgb(34 197 94 / 0.25);
  color: #ffffff;
}

.stop {
  border: 1px solid var(--danger-line);
  background: var(--danger-bg);
  color: var(--error-ink);
}

.run:active, .stop:active { transform: scale(0.97); }
.run.busy { filter: saturate(0.55) brightness(0.85); cursor: progress; }

/* The state reads as a status light: grey when idle, green and breathing while running. */
.state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 3px 10px 3px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.state::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
}

.state[data-tone="running"] { color: var(--ok-ink); border-color: rgb(34 197 94 / 0.3); }
.state[data-tone="running"]::before { background: #22c55e; box-shadow: 0 0 0 0 rgb(34 197 94 / 0.6); animation: breathe 1.8s ease-out infinite; }
.state[data-tone="busy"] { color: var(--busy-ink); border-color: rgb(45 212 191 / 0.3); }
.state[data-tone="busy"]::before { background: var(--accent); }
.state[data-tone="error"] { color: var(--error-ink); border-color: rgb(248 113 113 / 0.35); }
.state[data-tone="error"]::before { background: var(--danger); }

@keyframes breathe {
  70% { box-shadow: 0 0 0 6px rgb(34 197 94 / 0); }
  100% { box-shadow: 0 0 0 0 rgb(34 197 94 / 0); }
}

.bench-tools { display: flex; flex: none; align-items: center; gap: 2px; }

.tool {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  transition: background-color 100ms ease, color 100ms ease, transform 100ms var(--ease-out);
}

.tool:active:not(:disabled) { transform: scale(0.94); }
.tool:disabled { opacity: 0.3; cursor: default; }
.tool.danger { color: var(--danger); }
.tool.text {
  width: auto;
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.tool.text[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.tool-divider { width: 1px; height: 18px; margin-inline: 5px; background: var(--line-strong); }

.zoom-level {
  min-width: 46px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

@media (hover: hover) and (pointer: fine) {
  .run:hover { filter: brightness(1.08); }
  .stop:hover { background: var(--danger-hover); }
  .tool:hover:not(:disabled) { background: var(--surface-hover); color: var(--ink); }
  .tool.danger:hover { background: var(--danger-bg); color: var(--error-ink); }
  .tray-item:hover { background: var(--surface-raised); color: var(--ink); }
  .tray-item:hover .tray-art { transform: translateY(-1px) scale(1.05); }
}

/* ---------- docked tools for the selection ---------- */

/* The selection's tools take what room is left; when that is not enough they scroll sideways
   rather than widen the bar. */
.tools {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: safe center;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tools::-webkit-scrollbar { display: none; }
.tools > * { flex: none; }

.tools-label { margin-inline-end: 8px; color: var(--ink); font-size: 13px; font-weight: 600; white-space: nowrap; }

.tools select {
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-raised);
  font-size: 13px;
  font-weight: 600;
  direction: ltr;
}

.swatches { display: flex; align-items: center; gap: 6px; padding-inline: 6px; }

.swatch {
  width: 16px;
  height: 16px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--swatch-ring);
  transition: transform 100ms var(--ease-out);
}

.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--accent); }

@media (hover: hover) and (pointer: fine) {
  .swatch:hover { transform: scale(1.14); }
}

.tool-range {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-inline: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.tool-range output { min-width: 44px; color: var(--ink); font-variant-numeric: tabular-nums; text-align: left; }

.tool-range input {
  --fill: 50%;
  width: clamp(64px, 6.5vw, 96px);
  height: 18px;
  margin: 0;
  background: transparent;
  direction: ltr;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.tool-range input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.tool-range input::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--line-strong) var(--fill));
}

.tool-range input::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-strong); }
.tool-range input::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }

.tool-range input::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--thumb);
  box-shadow: 0 0 0 2px var(--accent), 0 2px 6px var(--thumb-shadow);
  transition: transform 100ms var(--ease-out);
  -webkit-appearance: none;
}

.tool-range input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--thumb);
  box-shadow: 0 0 0 2px var(--accent), 0 2px 6px var(--thumb-shadow);
}

.tool-range input:active::-webkit-slider-thumb { transform: scale(1.15); }

/* ---------- parts tray ---------- */

.bench-body {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  min-height: 0;
}

.tray {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 6px 10px;
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  overflow-y: auto;
}

.tray-group {
  margin: 8px 0 2px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-align: center;
}

.tray-item {
  display: grid;
  justify-items: center;
  gap: 5px;
  width: 100%;
  padding: 8px 2px 7px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: grab;
  touch-action: none;
  transition: background-color 100ms ease, color 100ms ease;
}

.tray-item:active { cursor: grabbing; }

/* A positioned box, so nothing drawn inside a part's art escapes the tray when it scrolls sideways. */
.tray-art {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 38px;
  line-height: 0;
  pointer-events: none;
  transition: transform 140ms var(--ease-out);
}

.tray-art wokwi-led { display: block; transform: translateY(-2px) scale(0.68); }
.tray-art wokwi-resistor { display: block; transform: scale(0.92); }
.tray-art wokwi-pushbutton { display: block; transform: scale(0.62); }
.tray-art wokwi-lcd1602 { display: block; zoom: 0.19; }
.tray-art wokwi-potentiometer { display: block; zoom: 0.48; }
.tray-art wokwi-pir-motion-sensor { display: block; zoom: 0.4; }
.tray-art wokwi-hc-sr04 { display: block; zoom: 0.35; }
.tray-art wokwi-dht22 { display: block; zoom: 0.32; }
.tray-art sim-power-flag { display: block; }
.tray-art sim-oled-ssd1306 { display: block; zoom: 0.36; }
.tray-art wokwi-photoresistor-sensor { display: block; zoom: 0.34; }
.tray-art wokwi-servo { display: block; zoom: 0.31; }
.tray-art wokwi-buzzer { display: block; zoom: 0.44; }
.tray-art wokwi-rgb-led { display: block; zoom: 0.52; }
.tray-art sim-relay-module { display: block; zoom: 0.33; }
.tray-art wokwi-membrane-keypad { display: block; zoom: 0.13; }
.tray-art wokwi-led-ring { display: block; zoom: 0.3; }
.tray-art sim-rc522 { display: block; zoom: 0.17; }
.tray-art sim-dc-motor { display: block; zoom: 0.3; }
.tray-art sim-l298n { display: block; zoom: 0.23; }
.tray-art wokwi-7segment { display: block; zoom: 0.44; }
.tray-art wokwi-slide-switch { display: block; zoom: 0.92; }
.tray-art wokwi-analog-joystick { display: block; zoom: 0.31; }
.tray-art wokwi-ky-040 { display: block; zoom: 0.5; }

/* ---------- the canvas ---------- */

.canvas { position: relative; min-width: 0; min-height: 0; overflow: hidden; }

/* The inset shadow darkens the edges under the parts, so the middle of the bench reads as lit. */
.frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-color: var(--canvas);
  background-image: radial-gradient(var(--dot) 1.1px, transparent 1.1px);
  background-size: var(--cell, 32px) var(--cell, 32px);
  background-position: var(--pan-x, 0) var(--pan-y, 0);
  box-shadow: inset 0 0 140px var(--canvas-vignette);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}

/* The neutral look draws the grid as faint white lines, a little stronger every fifth one. */
:root[data-sim-theme="gray"] .frame {
  background-image:
    linear-gradient(to right, var(--grid-major) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-major) 1px, transparent 1px),
    linear-gradient(to right, var(--grid-minor) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-minor) 1px, transparent 1px);
  background-size:
    calc(var(--cell, 32px) * 5) calc(var(--cell, 32px) * 5),
    calc(var(--cell, 32px) * 5) calc(var(--cell, 32px) * 5),
    var(--cell, 32px) var(--cell, 32px),
    var(--cell, 32px) var(--cell, 32px);
}

.frame:focus { outline: none; }
.frame.panning { cursor: grabbing; }
.frame.over-pin { cursor: crosshair; }
.part.turning { cursor: grabbing; }

.stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}

.stage-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}

/* line-height 0: the part drawings are inline SVGs, and a drawing shorter than a text line
   would otherwise sit lower than its pin coordinates. */
.part {
  position: absolute;
  top: 0;
  left: 0;
  line-height: 0;
  cursor: grab;
  filter: drop-shadow(0 2px 2.5px var(--part-shadow));
  transition: filter 120ms ease-out;
}

.part > * { display: block; pointer-events: none; }
.part.lifted { cursor: grabbing; filter: drop-shadow(0 9px 12px var(--part-lift)); }
.selection-frame { fill: none; stroke: var(--accent); pointer-events: none; }
.part.ghost { opacity: 0.9; pointer-events: none; }
.part.burnt > * { filter: grayscale(1) brightness(0.5); }

.wire-hit { fill: none; stroke: transparent; stroke-width: calc(14px * var(--zoom-inverse, 0.5)); pointer-events: stroke; cursor: pointer; }
.frame.over-run-y .wire-hit, .frame.sliding-y, .frame.sliding-y .wire-hit { cursor: ns-resize; }
.frame.over-run-x .wire-hit, .frame.sliding-x, .frame.sliding-x .wire-hit { cursor: ew-resize; }
.wire-casing { fill: none; stroke: var(--wire-casing); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.wire-base { fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* A black wire on a dark bench: the core stays black and the casing becomes its light rim. */
.wire[data-color="#1f2937"] .wire-base { stroke: var(--wire-black); }
.wire[data-color="#1f2937"] .wire-casing { stroke: var(--wire-black-rim); stroke-width: 3; }

.wire-live {
  fill: none;
  stroke: #fbbf24;
  stroke-width: 3.6;
  stroke-linecap: butt;
  stroke-linejoin: round;
  opacity: 0;
  transition: opacity 90ms linear;
}

.wire.live .wire-live { opacity: 0.3; }
.wire.selected .wire-base { stroke-width: 2.3; }
.wire.selected .wire-casing { stroke-width: 4; }

@media (hover: hover) and (pointer: fine) {
  .wire:hover .wire-base { stroke-width: 2.1; }
  .wire:hover .wire-casing { stroke-width: 3.6; }
}

.wire-draft { fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.pin-dot { fill: var(--accent); stroke: var(--pin-dot-rim); stroke-width: 0.6; }
.pin-ring { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1; }
.pin-pulse { fill: none; stroke: var(--accent); stroke-width: 1; transform-box: fill-box; transform-origin: center; }

/* A sensor answering the firmware: a ranger's ping, a DHT reading. Drawn on the part, so it turns
   with it. */
.sensor-pulse { position: absolute; border-radius: 50%; pointer-events: none; }
.sensor-pulse.sonar { border: 2px solid var(--accent); }
.sensor-pulse.dht { background: radial-gradient(rgb(45 212 191 / 0.5), rgb(45 212 191 / 0) 70%); }

/* A PIR that sees motion keeps rippling until its hold time runs out. */
.part.sensing::before,
.part.sensing::after {
  content: "";
  position: absolute;
  left: calc(var(--sense-x) - var(--sense-size) / 2);
  top: calc(var(--sense-y) - var(--sense-size) / 2);
  width: var(--sense-size);
  height: var(--sense-size);
  border: 2px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  animation: sensing 1.4s var(--ease-out) infinite;
}

.part.sensing::after { animation-delay: 0.7s; }

@keyframes sensing {
  from { transform: scale(0.9); opacity: 1; }
  to { transform: scale(1.6); opacity: 0; }
}

.smoke {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #8b95a5;
  pointer-events: none;
}

/* ---------- floating labels on the canvas ---------- */

.readout {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  gap: 8px;
  padding: 4px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--float-bg);
  box-shadow: var(--shadow-pop);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 90ms ease-out;
}

.readout.open { opacity: 1; }
.readout span:last-child { color: var(--accent); font-variant-numeric: tabular-nums; }
.readout span:last-child:empty { display: none; }

.hint {
  position: absolute;
  top: 14px;
  left: 50%;
  margin: 0;
  padding: 6px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--float-bg);
  box-shadow: var(--shadow-pop);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity 180ms ease-out;
}

.hint.gone { opacity: 0; }

/* Zoom sits in a corner of the canvas, like a map's, leaving the top bar to the selected part. */
.zoom-dock {
  position: absolute;
  bottom: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--float-bg);
  box-shadow: var(--shadow-pop);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.zoom-dock .tool { width: 30px; height: 30px; }
.zoom-dock .tool-divider { height: 16px; margin-inline: 3px; }

.draw-hint {
  position: absolute;
  bottom: 58px;
  left: 50%;
  margin: 0;
  padding: 5px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--float-bg);
  color: var(--ink);
  font-size: 12.5px;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 110ms ease-out;
}

.draw-hint.open { opacity: 1; }

.notes {
  position: absolute;
  bottom: 58px;
  left: 50%;
  display: grid;
  gap: 6px;
  width: min(540px, calc(100% - 32px));
  margin: 0;
  padding: 0;
  list-style: none;
  transform: translateX(-50%);
  pointer-events: none;
}

.note {
  padding: 8px 13px;
  border: 1px solid var(--note-line);
  border-radius: var(--radius);
  background: var(--note-bg);
  box-shadow: var(--shadow-pop);
  color: var(--note-ink);
  font-size: 13px;
  transition: opacity 140ms ease-out, transform 140ms var(--ease-out);
}

@starting-style {
  .note { opacity: 0; transform: translateY(4px); }
}

.note.error { border-color: var(--note-error-line); background: var(--note-error-bg); color: var(--note-error-ink); }
.note.warn { border-color: var(--note-warn-line); background: var(--note-warn-bg); color: var(--note-warn-ink); }

/* ---------- status bar ---------- */

.statusbar {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 0;
  padding-inline: 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.statusbar div { display: flex; gap: 6px; }
.statusbar dt { color: var(--faint); white-space: nowrap; }
.statusbar dd { margin: 0; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- code and output ---------- */

.side {
  display: grid;
  grid-template-rows: minmax(0, 1.4fr) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: var(--code-bg);
}

.panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.panel + .panel { border-top: 1px solid var(--line); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 40px;
  flex: none;
  padding-inline: 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.hint-text { color: var(--faint); font-size: 12px; }

.mono {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 10px 14px;
  overflow: auto;
  text-align: left;
  font-family: Consolas, "Cascadia Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.55;
}

.editor { flex: 1; min-height: 0; overflow: hidden; }
.editor .cm-editor { height: 100%; }

.file-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.file-icon path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.dirty, .mode-tag {
  padding: 1px 8px;
  border: 1px solid var(--tag-line);
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-ink);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

/* On the site the simulator fills the page below the site's top strip (.sim-host). Below 900px it
   stacks and takes its own height, as it does here. */
.sim-host { height: 100%; }
.sim-host > .app { height: 100%; }
@media (max-width: 900px) {
  .sim-host, .sim-host > .app { height: auto; }
}

.mode-tag { border-color: var(--line-strong); background: transparent; color: var(--muted); }


.examples {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-raised);
  font-size: 12.5px;
}

.tabs { justify-content: flex-start; gap: 2px; padding-inline: 8px; }
.tabs .hint-text { margin-inline-start: auto; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition: background-color 100ms ease, color 100ms ease;
}

.tab[aria-selected="true"] { background: var(--surface-raised); color: var(--ink); }

@media (hover: hover) and (pointer: fine) {
  .tab:hover { color: var(--ink); }
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #dc2626;
  color: #ffffff;
  font-size: 11px;
}

.build { flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; background: var(--console); }
.build-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }

.build-item {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: start;
}

button.build-item { cursor: pointer; }
.build-item.error { border-color: var(--note-error-line); background: var(--build-error-bg); }
.build-item.ok { border-color: rgb(34 197 94 / 0.35); background: var(--build-ok-bg); }
.build-where { color: var(--error-ink); font-size: 12px; font-weight: 700; }
.build-what { font-size: 13.5px; }
.build-original { color: var(--muted); font-family: Consolas, "Cascadia Mono", Menlo, monospace; font-size: 12px; text-align: left; }
.build-output { margin-top: 8px; padding: 8px 10px; background: var(--surface); border-radius: 7px; white-space: pre-wrap; }

.serial {
  background: var(--console);
  color: var(--console-ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.serial-send {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  padding: 7px 8px 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--console);
}

.serial-prompt { color: var(--accent); font-family: Consolas, "Cascadia Mono", Menlo, monospace; font-size: 16px; line-height: 1; }

.serial-text {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-muted);
  color: var(--console-ink);
  font-family: Consolas, "Cascadia Mono", Menlo, monospace;
  font-size: 13px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.serial-text::placeholder { color: var(--faint); font-family: var(--font-heebo, "Segoe UI"), "Segoe UI", system-ui, -apple-system, Arial, sans-serif; font-size: 12.5px; }
.serial-text:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.serial-text:disabled { border-color: var(--line); background: transparent; cursor: not-allowed; }

.serial-ending {
  height: 30px;
  padding: 0 4px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 12px;
}

.serial-submit {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  transition: background-color 120ms ease, color 120ms ease, transform 100ms var(--ease-out);
}

.serial-submit svg path { stroke-width: 2.2; }
.serial-submit:active:not(:disabled) { transform: scale(0.94); }
.serial-submit:disabled { background: var(--surface-raised); color: var(--faint); cursor: default; }

/* ---------- Serial Plotter ---------- */

.plot { display: flex; flex: 1; flex-direction: column; min-height: 0; background: var(--console); }

.plot-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 4px 8px 4px 12px;
  border-bottom: 1px solid var(--line);
}

.plot-legend { display: flex; flex: 1; flex-wrap: wrap; gap: 4px 14px; min-width: 0; }
.plot-key { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.plot-key i, .plot-tip-row i { display: inline-block; width: 14px; height: 2px; border-radius: 1px; background: var(--key); }
.plot-key b { color: var(--ink); font-family: Consolas, "Cascadia Mono", Menlo, monospace; font-weight: 600; font-variant-numeric: tabular-nums; }
.plot-clear { flex: none; }

.plot-area { position: relative; flex: 1; min-height: 0; }
.plot-canvas { display: block; width: 100%; height: 100%; }
.plot-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.plot-tip {
  position: absolute;
  display: grid;
  gap: 3px;
  min-width: 120px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--float-bg);
  box-shadow: var(--shadow-pop);
  font-size: 12px;
  pointer-events: none;
}

.plot-tip-head { color: var(--faint); font-size: 11px; }
.plot-tip-row { display: grid; grid-template-columns: 14px auto 1fr; align-items: center; gap: 7px; }
.plot-tip-row b { color: var(--ink); font-family: Consolas, "Cascadia Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
.plot-tip-row span { color: var(--muted); }

.plot-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  margin: 0;
  padding: 24px;
  color: var(--faint);
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
  pointer-events: none;
}

.plot-empty code { padding: 1px 5px; border-radius: 4px; background: var(--surface-raised); color: var(--muted); font-size: 12px; }

/* ---------- phone ---------- */

@media (max-width: 900px) {
  .app { height: auto; min-height: 100dvh; }
  /* The examples menu is as wide as its longest name; here it leaves room for the file's tags. */
  .examples { max-width: 40vw; }
  .mode-tag { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .board-name { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .splitter { display: none; }
  .bench { grid-template-rows: auto 70dvh 28px; }
  .bench-bar { flex-wrap: wrap; padding-block: 7px; }
  .tools { order: 3; flex-basis: 100%; min-height: 30px; justify-content: flex-start; }
  .tools:empty { display: none; }
  .bench-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .tray { flex-direction: row; padding: 4px 6px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .tray-group { display: none; }
  .tray-item { gap: 6px; padding: 4px 2px; white-space: nowrap; }
  .tray-art { height: 28px; }
  .tray-art wokwi-led { transform: scale(0.5); }
  .tray-art wokwi-resistor { transform: scale(0.76); }
  .tray-art wokwi-pushbutton { transform: scale(0.46); }
  .tray-art wokwi-potentiometer { zoom: 0.36; }
  .tray-art wokwi-pir-motion-sensor { zoom: 0.3; }
  .tray-art wokwi-hc-sr04 { zoom: 0.28; }
  .tray-art wokwi-dht22 { zoom: 0.24; }
  .tray-art sim-power-flag { zoom: 0.8; }
  .tray-art sim-oled-ssd1306 { zoom: 0.26; }
  .tray-art wokwi-photoresistor-sensor { zoom: 0.26; }
  .tray-art wokwi-servo { zoom: 0.23; }
  .tray-art wokwi-buzzer { zoom: 0.32; }
  .tray-art wokwi-rgb-led { zoom: 0.38; }
  .tray-art sim-relay-module { zoom: 0.25; }
  .tray-art wokwi-membrane-keypad { zoom: 0.095; }
  .tray-art wokwi-led-ring { zoom: 0.22; }
  .tray-art sim-rc522 { zoom: 0.12; }
  .tray-art sim-dc-motor { zoom: 0.22; }
  .tray-art wokwi-7segment { zoom: 0.32; }
  .tray-art wokwi-slide-switch { zoom: 0.7; }
  .tray-art wokwi-analog-joystick { zoom: 0.23; }
  .tray-art wokwi-ky-040 { zoom: 0.37; }
  .tray-art sim-l298n { zoom: 0.17; }
  .side { grid-template-rows: auto auto; border-inline-end: 0; border-top: 1px solid var(--line); }
  .mono { max-height: 300px; }
  .serial { min-height: 180px; }
  .statusbar { gap: 12px; }
  .hint { width: min(84%, 300px); white-space: normal; text-align: center; border-radius: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .theme-switch::before { transition: none; }
  .note, .hint, .run, .stop, .tool, .swatch, .part, .tray-art { transition: none; }
  .state[data-tone="running"]::before { animation: none; }
  .part.sensing::before { animation: none; opacity: 0.9; }
  .part.sensing::after { display: none; }
}

/* ---------- saved circuits ---------- */

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.project { display: flex; align-items: center; gap: 6px; min-width: 0; margin-inline-start: 22px; }
.project[hidden] { display: none; }

.project-name {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 260px;
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  transition: background-color 100ms ease;
}

.project-name svg { flex: none; color: var(--accent); }
.project-name > span:not(.project-unsaved) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-name.untitled { color: var(--muted); font-weight: 500; }
.project-name.shared { cursor: default; }
.project-name.shared:disabled { opacity: 1; }
.project-name.untitled svg { color: var(--faint); }

/* Unsaved changes: a small dot after the name, as editors mark a changed file. */
.project-unsaved { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.project-unsaved[hidden] { display: none; }

.project .tool.text { display: inline-flex; gap: 6px; }
.project .tool.text svg { flex: none; }
.project-save.pending { border-color: var(--accent); color: var(--accent); }
.tool.text:disabled { opacity: 0.45; cursor: default; }

.tool.text.primary { border-color: var(--accent); background: var(--accent); color: var(--bg); }
.tool.text.primary.danger { border-color: var(--danger); background: var(--danger); color: var(--bg); }

@media (hover: hover) and (pointer: fine) {
  .project-name:hover:not(:disabled) { background: var(--surface-hover); }
  .tool.text:hover:not(:disabled) { border-color: var(--accent); }
  .tool.text.primary:hover:not(:disabled) { background: var(--accent); color: var(--bg); filter: brightness(1.08); }
  .tool.text.primary.danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.08); }
}

/* Panels over the simulator: My circuits, the name of a circuit, a yes/no question. */
.sheet {
  /* Centred on the screen; the site's CSS reset zeroes every margin, so it is set here again. */
  margin: auto;
  width: min(520px, calc(100vw - 32px));
  max-height: min(620px, calc(100dvh - 64px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
  font-family: var(--font-heebo, "Segoe UI"), "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  direction: rtl;
}

.sheet.small { width: min(400px, calc(100vw - 32px)); }
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet[open] { display: flex; flex-direction: column; animation: sheet-in 180ms var(--ease-out); }
.sheet[open]::backdrop { animation: sheet-fade 180ms ease; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes sheet-fade { from { opacity: 0; } }

.sheet form, .sheet-body { display: flex; flex-direction: column; gap: 14px; padding: 18px 18px 16px; }
.sheet h2 { margin: 0; font-size: 15px; font-weight: 700; }
.sheet-text { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; }

.sheet-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 8px; padding-inline-start: 18px; border-bottom: 1px solid var(--line); }
.sheet-count { color: var(--faint); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sheet-close { margin-inline-start: auto; }

.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; }
.projects .sheet-foot { padding: 12px 18px; border-top: 1px solid var(--line); justify-content: flex-start; }

.sheet-error { margin: 0; padding: 8px 10px; border-radius: 7px; background: var(--danger-bg); color: var(--error-ink); font-size: 13px; }
.projects .sheet-error { margin: 12px 18px 0; }
.sheet-error[hidden] { display: none; }

.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.field input {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
}
.field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.projects-list { flex: 1; min-height: 0; margin: 0; padding: 6px; overflow-y: auto; list-style: none; }
.projects-list[aria-busy="true"]:empty { min-height: 120px; }

.projects-row { display: flex; align-items: center; gap: 2px; padding-inline-end: 4px; border-radius: 8px; }
.projects-row.current { background: var(--accent-soft); }

.projects-open {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: start;
}

.projects-open svg { grid-row: span 2; color: var(--faint); }
.projects-row.current .projects-open svg { color: var(--accent); }
.projects-name { overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.projects-when { color: var(--faint); font-size: 12px; }
.projects-row.current .projects-when { color: var(--accent); font-weight: 600; }

.projects-row .tool { flex: none; opacity: 0.75; }
.projects-row:focus-within .tool { opacity: 1; }

.projects-empty { margin: 0; padding: 36px 28px; color: var(--muted); font-size: 13.5px; line-height: 1.6; text-align: center; }
.projects-empty[hidden] { display: none; }

@media (hover: hover) and (pointer: fine) {
  .projects-row:hover .tool { opacity: 1; }
  .projects-open:hover { background: var(--surface-hover); }
  .projects-row.current .projects-open:hover { background: transparent; }
}

/* Sharing: the link with its copy button, and how the viewers' version is coming along. */
.share-link { display: flex; gap: 8px; }
.share-link[hidden] { display: none; }
.share-link input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--ink);
  font: 13px Consolas, "Cascadia Mono", Menlo, monospace;
}
.share-link input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.share-link .tool.text { height: 34px; }

.share-status { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.share-status[hidden] { display: none; }
.share-status::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.share-status[data-tone="ok"]::before { background: var(--run-top); }
.share-status[data-tone="bad"] { color: var(--error-ink); }
.share-status[data-tone="bad"] { align-items: flex-start; }
.share-status[data-tone="bad"]::before { margin-top: 6px; }
.share-detail { display: block; margin-top: 4px; font-family: Consolas, "Cascadia Mono", Menlo, monospace; font-size: 12px; }
.share-status[data-tone="bad"]::before { background: var(--danger); }
.share-status[data-tone="busy"]::before { background: var(--warn); animation: share-pulse 1s ease-in-out infinite alternate; }
@keyframes share-pulse { from { opacity: 0.35; } }

.sheet-spacer { flex: 1; }
.tool.text.quiet-danger { border-color: transparent; background: transparent; color: var(--error-ink); }
.projects-row .tool.on { color: var(--accent); opacity: 1; }
.projects-shared {
  margin-inline-start: 8px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  .tool.text.quiet-danger:hover:not(:disabled) { border-color: transparent; background: var(--danger-bg); }
}

@media (max-width: 900px) {
  .project { margin-inline-start: 10px; }
  .project-name { max-width: 150px; padding: 0 6px; }
  .project .tool.text { width: 32px; padding: 0; justify-content: center; }
  .project .tool.text .label { display: none; }
}

/* A phone: the saved circuit gets its own row under the title, so the bar never runs wider than
   the screen. */
@media (max-width: 560px) {
  .app { grid-template-rows: auto minmax(0, 1fr); }
  .appbar { flex-wrap: wrap; row-gap: 6px; padding-block: 8px; }
  .brand { flex: 1; }
  .appbar h1 { white-space: nowrap; }
  .project { order: 3; flex-basis: 100%; margin-inline-start: 0; }
  .project-name { flex: 1; max-width: none; padding-inline-start: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet[open], .sheet[open]::backdrop, .share-status::before { animation: none; }
}

/* ---------- a guest's invitation to write code (on the site, data-sim-signin) ---------- */

.invite {
  --violet: #a78bfa;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0 12px 12px;
  padding: 20px 20px 18px;
  border: 1.5px solid transparent;
  border-radius: 18px;
  background:
    radial-gradient(90% 120% at 100% 0%, color-mix(in srgb, var(--accent) 24%, transparent), transparent 60%) padding-box,
    radial-gradient(70% 110% at 0% 100%, color-mix(in srgb, var(--violet) 20%, transparent), transparent 60%) padding-box,
    linear-gradient(var(--surface-raised), var(--surface-raised)) padding-box,
    linear-gradient(130deg, var(--accent), var(--violet) 55%, var(--accent)) border-box;
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--accent) 10%, transparent),
    0 18px 40px -18px color-mix(in srgb, var(--accent) 55%, transparent),
    var(--shadow-pop);
  animation: invite-in 600ms var(--ease-out) both, invite-breathe 4.5s ease-in-out 900ms infinite;
}

/* a big faint code mark in the corner */
.invite-glyph {
  position: absolute;
  inset-inline-start: -6px;
  bottom: -26px;
  z-index: -1;
  color: color-mix(in srgb, var(--accent) 13%, transparent);
  font: 900 92px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: -6px;
  pointer-events: none;
  direction: ltr;
}

.invite-head { display: flex; align-items: center; gap: 14px; }

.invite-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(140deg, var(--accent), var(--violet));
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--accent) 80%, transparent), 0 1px 0 rgb(255 255 255 / 0.3) inset;
}

.invite-icon path { fill: none; stroke: #ffffff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.invite-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.invite-eyebrow {
  align-self: flex-start;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.invite-text strong { color: var(--ink); font-size: 19px; font-weight: 900; line-height: 1.25; }

.invite-perks { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }

.invite-perks li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 700;
}

.invite-perks svg { width: 15px; height: 15px; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.invite-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }

.invite-join {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 22px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--violet)));
  box-shadow: 0 10px 24px -10px color-mix(in srgb, var(--accent) 90%, transparent), 0 1px 0 rgb(255 255 255 / 0.35) inset;
  color: #ffffff;
  font-size: 15px;
  font-weight: 900;
  text-decoration: none;
  text-shadow: 0 1px 1px rgb(0 0 0 / 0.18);
  transition: transform 180ms var(--ease-out), box-shadow 180ms var(--ease-out), filter 180ms var(--ease-out);
}

.invite-join svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform 180ms var(--ease-out); }

@media (hover: hover) {
  .invite-join:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
    box-shadow: 0 14px 30px -10px var(--accent), 0 1px 0 rgb(255 255 255 / 0.35) inset;
  }
  .invite-join:hover svg { transform: translateX(-3px); }
}

.invite-join:active { transform: scale(0.97); }

.invite-signin { color: var(--ink); font-size: 13px; font-weight: 700; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 4px; }
.invite-signin:hover { text-decoration-color: var(--accent); }

.invite-join:focus-visible, .invite-signin:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

@keyframes invite-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
}

@keyframes invite-breathe {
  50% {
    box-shadow:
      0 0 0 6px color-mix(in srgb, var(--accent) 16%, transparent),
      0 22px 48px -18px color-mix(in srgb, var(--accent) 70%, transparent),
      var(--shadow-pop);
  }
}

/* typing into the locked code points here */
.invite.nudge { animation: invite-nudge 560ms var(--ease-out); }

@keyframes invite-nudge {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .invite, .invite.nudge { animation: none; }
  .invite.nudge { outline: 2px solid var(--accent); outline-offset: 2px; }
  .invite-join, .invite-join svg { transition: none; }
}

/* ---------- the examples gallery (lib/gallery.js) ---------- */

/* the button that opens it, in the code panel's head */
.gal-open {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px 0 8px;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 50%, #a78bfa));
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--accent) 80%, transparent), 0 1px 0 rgb(255 255 255 / 0.3) inset;
  color: #ffffff;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 160ms var(--ease-out), filter 160ms var(--ease-out);
}

.gal-open svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linejoin: round; }

.gal-open-count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.25);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* a soft ring that keeps calling until the gallery has been opened once */
.gal-open::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: gal-call 2.4s var(--ease-out) 1.2s infinite;
  pointer-events: none;
}

@keyframes gal-call {
  0% { opacity: 0.7; transform: scale(1); }
  70%, 100% { opacity: 0; transform: scale(1.18, 1.45); }
}

@media (hover: hover) {
  .gal-open:hover { transform: translateY(-1px); filter: brightness(1.07); }
}
.gal-open:active { transform: scale(0.97); }
.gal-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.gal-open[hidden] { display: none; }

/* the sheet */
.gallery {
  --gal-light: #fbbf24;
  --gal-sense: #38bdf8;
  --gal-screen: #84cc16;
  --gal-move: #fb923c;
  --gal-input: #e879f9;
  margin: auto;
  width: min(1100px, calc(100vw - 28px));
  max-height: min(860px, calc(100dvh - 40px));
  padding: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line-strong));
  border-radius: 22px;
  background:
    radial-gradient(60% 40% at 85% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%),
    radial-gradient(50% 35% at 10% 0%, color-mix(in srgb, #a78bfa 16%, transparent), transparent 70%),
    var(--surface);
  color: var(--ink);
  box-shadow: 0 40px 100px -30px rgb(0 0 0 / 0.7), 0 0 0 6px color-mix(in srgb, var(--accent) 8%, transparent);
  font-family: var(--font-heebo, "Segoe UI"), "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  direction: rtl;
}

.gallery[open] { display: flex; flex-direction: column; animation: gal-in 380ms var(--ease-out); }
.gallery::backdrop { background: rgb(4 10 20 / 0.62); backdrop-filter: blur(5px); }
.gallery[open]::backdrop { animation: sheet-fade 260ms ease; }

@keyframes gal-in { from { opacity: 0; transform: translateY(16px) scale(0.97); } }

.gal-head { display: flex; flex: none; align-items: flex-start; gap: 16px; padding: 26px 28px 8px; }
.gal-titles { display: flex; flex: 1; flex-direction: column; gap: 6px; min-width: 0; }

.gal-eyebrow {
  align-self: flex-start;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.gal-titles h2:focus { outline: none; }
.gal-titles h2 { margin: 0; font-size: clamp(22px, 2.4vw, 30px); font-weight: 900; line-height: 1.15; letter-spacing: -0.01em; }
.gal-titles p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }

.gal-close {
  display: grid;
  flex: none;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface-raised);
  color: var(--muted);
  cursor: pointer;
}
.gal-close svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.gal-close:hover { color: var(--ink); }
.gal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.gal-filters { display: flex; flex: none; flex-wrap: wrap; gap: 8px; padding: 12px 28px 16px; }

.gal-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), border-color 160ms var(--ease-out), color 160ms var(--ease-out);
}
.gal-chip span { color: var(--faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.gal-chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.gal-chip[aria-pressed="true"] span { color: inherit; opacity: 0.75; }
.gal-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.gal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(205px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 4px 28px 28px;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
}
.gal-grid li { animation: gal-card-in 420ms var(--ease-out) both; animation-delay: calc(var(--i) * 22ms + 120ms); }
.gal-grid li[hidden] { display: none; }

@keyframes gal-card-in { from { opacity: 0; transform: translateY(12px); } }

.gal-card {
  --c: var(--accent);
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--surface-raised);
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
  transition: transform 200ms var(--ease-out), border-color 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}
.gal-card[data-cat="light"] { --c: var(--gal-light); }
.gal-card[data-cat="sense"] { --c: var(--gal-sense); }
.gal-card[data-cat="screen"] { --c: var(--gal-screen); }
.gal-card[data-cat="move"] { --c: var(--gal-move); }
.gal-card[data-cat="input"] { --c: var(--gal-input); }

.gal-art {
  position: relative;
  display: grid;
  place-items: center;
  height: 128px;
  overflow: hidden;
  line-height: 0;
  background:
    radial-gradient(60% 75% at 50% 55%, color-mix(in srgb, var(--c) 30%, transparent), transparent 72%),
    radial-gradient(color-mix(in srgb, var(--ink) 9%, transparent) 1px, transparent 1px) 0 0 / 12px 12px,
    var(--canvas);
  border-bottom: 1px solid var(--line);
  pointer-events: none;
}
.gal-art > * { transition: transform 260ms var(--ease-out); }

.gal-text { display: flex; flex-direction: column; gap: 5px; padding: 12px 14px 44px; }
.gal-text strong { font-size: 15px; font-weight: 800; line-height: 1.3; }
.gal-blurb { color: var(--muted); font-size: 12.5px; line-height: 1.5; }

.gal-go {
  position: absolute;
  inset-inline-start: 14px;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 16%, transparent);
  color: var(--c);
  font-size: 12px;
  font-weight: 800;
  transition: background-color 200ms var(--ease-out), color 200ms var(--ease-out);
}
.gal-go svg { fill: currentColor; }

@media (hover: hover) {
  .gal-card:hover {
    transform: translateY(-4px);
    border-color: var(--c);
    box-shadow: 0 18px 34px -18px color-mix(in srgb, var(--c) 75%, transparent);
  }
  .gal-card:hover .gal-art > * { transform: scale(1.08); }
  .gal-card:hover .gal-go { background: var(--c); color: #0b1220; }
}
.gal-card:active { transform: scale(0.98); }
.gal-card:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; }

/* each part at a size that fills the card's picture */
.gal-art wokwi-led { display: block; zoom: 1.45; }
.gal-art wokwi-pushbutton { display: block; zoom: 1.35; }
.gal-art wokwi-lcd1602 { display: block; zoom: 0.48; }
.gal-art wokwi-potentiometer { display: block; zoom: 1.2; }
.gal-art wokwi-pir-motion-sensor { display: block; zoom: 0.95; }
.gal-art wokwi-hc-sr04 { display: block; zoom: 0.85; }
.gal-art wokwi-dht22 { display: block; zoom: 0.78; }
.gal-art wokwi-photoresistor-sensor { display: block; zoom: 0.8; }
.gal-art sim-oled-ssd1306 { display: block; zoom: 0.85; }
.gal-art wokwi-servo { display: block; zoom: 0.72; }
.gal-art wokwi-buzzer { display: block; zoom: 1.05; }
.gal-art wokwi-rgb-led { display: block; zoom: 1.25; }
.gal-art sim-relay-module { display: block; zoom: 0.8; }
.gal-art wokwi-membrane-keypad { display: block; zoom: 0.3; }
.gal-art wokwi-led-ring { display: block; zoom: 0.72; }
.gal-art sim-rc522 { display: block; zoom: 0.42; }
.gal-art sim-dc-motor { display: block; zoom: 0.7; }
.gal-art wokwi-7segment { display: block; zoom: 1.05; }
.gal-art wokwi-slide-switch { display: block; zoom: 2; }
.gal-art wokwi-analog-joystick { display: block; zoom: 0.75; }
.gal-art wokwi-ky-040 { display: block; zoom: 1.15; }

.gal-wave { width: 130px; height: 66px; }
.gal-wave path { fill: none; stroke: var(--gal-screen); stroke-width: 3; stroke-linecap: round; }
.gal-wave path.alt { stroke: var(--accent); opacity: 0.85; }
.gal-term { width: 120px; height: 70px; }
.gal-term rect { fill: var(--console); stroke: var(--line-strong); stroke-width: 2; }
.gal-term path { fill: none; stroke: var(--gal-input); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

@media (max-width: 640px) {
  .gal-head { padding: 18px 16px 4px; }
  .gal-filters { padding: 10px 16px 12px; flex-wrap: nowrap; overflow-x: auto; }
  .gal-chip { flex: none; }
  .gal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 4px 16px 20px; }
  .gal-art { height: 96px; }
  .gal-art > * { transform: scale(0.75); }
  .gal-text { padding: 10px 11px 40px; }
  .gal-text strong { font-size: 13.5px; }
  .gal-blurb { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .gal-open::after { animation: none; display: none; }
  .gallery[open], .gal-grid li { animation: none; }
  .gal-card, .gal-art > *, .gal-open, .gal-chip { transition: none; }
}
