:root {
  /* Wire colors — the active/inactive distinction is the core teaching signal (FR-012, SC-003) */
  --wire-inactive: #64748b; /* slate gray — low/idle */
  --wire-active: #22c55e;   /* bright green — high/energized */
  --wire-preview: #94a3b8;

  /* Logic level fills */
  --level-low: #1e293b;
  --level-high: #22c55e;

  /* Terminal accents by kind */
  --input-accent: #3b82f6;  /* blue */
  --output-accent: #a855f7; /* purple */

  --bg: #0f172a;
  --panel: #1e293b;
  --workspace-bg: #111827;
  --grid: #1f2937;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --danger: #ef4444;
  --bus-accent: #f59e0b; /* amber — a multi-bit bus, distinct from single-bit */
}

/* ---- Thin scrollbars ---------------------------------------------------- */
/* Chrome's default scrollbars are wide; slim them down. Firefox uses
   scrollbar-width/color; Chrome/Safari use the ::-webkit-scrollbar pseudos. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--text-dim) transparent;
}
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

/* ---- Bus (converters, bus ports, bus wires) ---- */
.instance--bus .instance__body {
  stroke: var(--bus-accent);
  stroke-width: 2px;
}
.terminal__port--bus {
  fill: var(--bus-accent);
  stroke: var(--bus-accent);
}
/* Higher specificity (.wire.wire--bus) so a bus wire's thicker amber stroke
   wins over the base `.wire` rule regardless of stylesheet order. */
.wire.wire--bus {
  stroke: var(--bus-accent);
  stroke-width: 6px;
}
/* Bus terminals: amber-accented body, monospace binary readout. Compound
   selectors (.terminal__*.bus__*) keep these winning over the base rules. */
.terminal__body.bus__body {
  fill: #3a2f12;
  stroke: var(--bus-accent);
  stroke-width: 2px;
}
.terminal__label.bus__value {
  fill: var(--bus-accent);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.72rem;
  letter-spacing: 1px;
}
.terminal__label.bus__tag {
  fill: var(--text-dim);
  font-size: 0.68rem;
}
.bus-ctrl__bits {
  display: flex;
  gap: 5px;
  justify-content: center;
  margin-bottom: 6px;
}
.bus-ctrl__bit {
  width: 16px;
  height: 16px;
  accent-color: var(--bus-accent);
  cursor: pointer;
}

/* Transient toast (e.g. a refused bus connection). */
.toast {
  position: absolute;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--danger);
  color: #fff;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  max-width: 80%;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app__header {
  padding: 0.75rem 1.25rem;
  position: relative;
}

.app__header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
}

.app__header p {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 1.25rem;
  background: var(--panel);
  border-top: 1px solid #334155;
  border-bottom: 1px solid #334155;
}

.toolbar button {
  cursor: pointer;
  border: 1px solid #475569;
  background: #334155;
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.toolbar button:hover {
  background: #3f4d63;
}

.toolbar .toolbar__hint {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ---- Workspace / SVG ---- */
.workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--workspace-bg);
}

.workspace svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* let pointer drags pan/move without browser gestures */
  /* Stop the browser's native text-selection / element drag (the translucent
     "ghost image") from hijacking a component drag. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* Zoom / fit controls overlaid on the canvas */
.canvas-controls {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.canvas-controls button {
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  border: 1px solid #475569;
  background: #1e293b;
  color: var(--text);
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-controls button:hover {
  background: #334155;
}

/* ---- Wires ---- */
.wire {
  fill: none;
  stroke: var(--wire-inactive);
  stroke-width: 3;
  stroke-linecap: round;
  pointer-events: none; /* all interaction is handled by the fat .wire-hit band */
  transition: stroke 80ms linear, stroke-width 80ms linear;
}

.wire--active {
  stroke: var(--wire-active);
}

/* Hovering anywhere in the clickable band highlights the visible wire, so the
   highlighted area and the removable area always match. */
.wire-group:hover .wire {
  stroke-width: 6;
}

.wire-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 16; /* fat invisible hit target so wires are easy to click */
  stroke-linecap: round;
  pointer-events: stroke;
  cursor: pointer;
}

.wire-preview {
  fill: none;
  stroke: var(--wire-preview);
  stroke-width: 2.5;
  stroke-dasharray: 6 5;
  pointer-events: none;
}

/* ---- Terminals ---- */
.terminal {
  cursor: default;
}

.terminal__body {
  stroke-width: 2.5;
  fill: var(--level-low);
  transition: fill 80ms linear;
}

.terminal--input .terminal__body {
  stroke: var(--input-accent);
  cursor: pointer; /* inputs are clickable to toggle */
}

.terminal--output .terminal__body {
  stroke: var(--output-accent);
}

.terminal--high .terminal__body {
  fill: var(--level-high);
}

.terminal__label {
  fill: var(--text);
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

/* Connection port nubs */
.terminal__port {
  fill: #0f172a;
  stroke: #94a3b8;
  stroke-width: 2;
  cursor: crosshair;
}

.terminal__port:hover {
  stroke: #e2e8f0;
}

/* Invisible, larger click target around a port nub (easy to hit; wins over an
   overlapping wire band at a connected port). */
.port-hit {
  fill: transparent;
  stroke: none;
  cursor: crosshair;
}

.terminal__port--pending {
  fill: #fde047;
  stroke: #fde047;
}

.terminal__port--high {
  fill: var(--wire-active);
  stroke: var(--wire-active);
}

/* NAND block in the playground */
.gate-block__body {
  fill: #1e293b;
  stroke: #a855f7;
  stroke-width: 2.5;
}

.gate-block__label {
  fill: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

/* ===== Step 4: components, toolbox, selection ===== */

/* Generic component instance block */
.instance__body {
  fill: #1e293b;
  stroke: #a855f7;
  stroke-width: 2.5;
}

.instance__label {
  fill: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

/* Per-placement label (step 25): amber, prominent, with the type name beneath. */
.instance__label--named {
  fill: #f0d9a0;
}

.instance__sublabel {
  fill: var(--text-dim);
  font-size: 9px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

/* Surfaced seven-segment digits drawn on a composite body (step 25) reuse the
   .seg / .seg--on / .seg--off styling of a full display, but at a much smaller
   size — so the segment stroke must scale down too, or thick strokes merge into a
   solid blob. */
.instance__surfaced-digit {
  pointer-events: none;
}

.instance__surfaced-digit .seg {
  stroke-width: 3;
}

.instance__port-label {
  fill: var(--text-dim);
  font-size: 10px;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

/* RAM: the memory colour code is blue — a deeper blue body with a bright blue
   outline, plus a monospace binary readout of the value currently being read. */
.instance--ram .instance__body {
  fill: #15294a;
  stroke: #4d8bff;
}

.ram__tag {
  fill: #9cc2ff;
  font-size: 11px;
  letter-spacing: 1px;
}

.ram__value {
  fill: #dbe9ff;
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  font-size: 13px;
  letter-spacing: 1px;
}

/* Selection highlight */
.selected .terminal__body,
.selected .instance__body {
  stroke: #fde047;
  stroke-width: 3.5;
}

/* Marquee selection rectangle */
.marquee {
  fill: rgba(253, 224, 71, 0.08);
  stroke: #fde047;
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  pointer-events: none;
}

/* Toolbox palette overlay */
.toolbox {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  z-index: 5;
  width: 180px; /* initial; overridden by the inline style and the resize handle */
  max-height: calc(100% - 1.2rem);
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 0.5rem;
}

/* Scrolls independently so the resize handle (a non-scrolling sibling) stays put. */
.toolbox__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* Right-edge drag handle to resize the toolbox width. */
.toolbox__resize {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  border-radius: 0 8px 8px 0;
  touch-action: none;
}
.toolbox__resize:hover {
  background: rgba(148, 163, 184, 0.25);
}

.toolbox__title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}

.toolbox__hint {
  font-size: 0.68rem;
  color: var(--text-dim);
  opacity: 0.8;
  margin-bottom: 0.5rem;
}

.modal__section {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  margin: 0.5rem 0 0.2rem;
}

.toolbox__create {
  width: 100%;
  cursor: pointer;
  border: 1px solid #475569;
  background: #334155;
  color: var(--text);
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

.toolbox__create:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.toolbox__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.toolbox__entry {
  display: flex;
  gap: 0.3rem;
}

.toolbox__chip {
  flex: 1;
  cursor: grab;
  text-align: left;
  border: 1px solid #475569;
  background: #1e293b;
  color: var(--text);
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  font-size: 0.82rem;
}

.toolbox__chip:hover {
  background: #334155;
}

.toolbox__chip.armed {
  border-color: var(--wire-active);
  box-shadow: 0 0 0 1px var(--wire-active) inset;
}

.toolbox__edit {
  cursor: pointer;
  border: 1px solid #475569;
  background: #1e293b;
  color: var(--text-dim);
  border-radius: 6px;
  font-size: 0.8rem;
  padding: 0 0.4rem;
}

.toolbox__edit:hover {
  color: var(--text);
}

/* Reorder controls (step 30): ▲▼ to move a component within its section. */
.toolbox__reorder {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}
.toolbox__move {
  cursor: pointer;
  border: 1px solid #475569;
  background: #1e293b;
  color: var(--text-dim);
  border-radius: 4px;
  font-size: 0.5rem;
  line-height: 1;
  padding: 1px 0.3rem;
}
.toolbox__move:hover:not(:disabled) {
  color: var(--text);
  border-color: #64748b;
}
.toolbox__move:disabled {
  opacity: 0.35;
  cursor: default;
}

.rename {
  margin: 0.3rem 0 0.1rem;
  padding: 0.3rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.rename__row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.rename__tag {
  width: 26px;
  font-size: 0.68rem;
  color: var(--text-dim);
}

.rename__input,
.modal__input {
  flex: 1;
  width: 100%;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 4px;
  color: var(--text);
  font-size: 0.8rem;
  padding: 0.2rem 0.35rem;
}

/* A non-editable row value (e.g. a surfaced display's slot in the create popup). */
.rename__readonly {
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  background: transparent;
  border-color: transparent;
}

/* Create-component popup (opens at the click position) */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(2, 6, 23, 0.45);
}

.modal__box {
  position: absolute;
  /* --mx/--my are the click position (set inline); clamp within the viewport */
  left: min(var(--mx, 50%), calc(100vw - 372px));
  top: min(var(--my, 20%), calc(100vh - 252px));
  background: var(--panel);
  border: 1px solid #475569;
  border-radius: 10px;
  padding: 1.1rem 1.2rem;
  width: 360px;
  max-width: calc(100vw - 1.5rem);
  min-height: 240px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.modal__title {
  font-size: 0.9rem;
  font-weight: 650;
  margin-bottom: 0.6rem;
}

.modal__actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.7rem;
}

.modal__actions button {
  cursor: pointer;
  border: 1px solid #475569;
  background: #334155;
  color: var(--text);
  padding: 0.35rem 0.8rem;
  border-radius: 6px;
  font-size: 0.82rem;
}

/* Right-click context menu */
.ctx-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
}

.ctx-menu {
  position: absolute;
  left: min(var(--mx, 50%), calc(100vw - 240px));
  top: min(var(--my, 20%), calc(100vh - 110px));
  min-width: 200px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 0.3rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.ctx-heading {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  padding: 0.3rem 0.6rem 0.1rem;
}

.ctx-sep {
  height: 1px;
  background: #334155;
  margin: 0.25rem 0.3rem;
}

.ctx-item {
  cursor: pointer;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.ctx-item:hover {
  background: #334155;
}

.ctx-item--danger {
  color: #fca5a5;
}

.ctx-item--danger:hover {
  background: #7f1d1d;
  color: #fff;
}

/* Toolbox delete-component affordance */
.rename__delete {
  margin-top: 0.35rem;
  cursor: pointer;
  border: 1px solid #7f1d1d;
  background: #3f1d1d;
  color: #fca5a5;
  border-radius: 6px;
  font-size: 0.78rem;
  padding: 0.3rem 0.5rem;
}

.rename__delete:hover {
  background: #7f1d1d;
  color: #fff;
}

.rename__msg {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  color: #fca5a5;
}

/* Delete affordance */
.terminal__delete {
  fill: var(--danger);
  cursor: pointer;
  opacity: 0.85;
}

.terminal__delete:hover {
  opacity: 1;
}

.terminal__delete-x {
  fill: #fff;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}

.workspace__empty {
  fill: var(--text-dim);
  font-size: 14px;
  text-anchor: middle;
}

/* ===== Step 2: NAND gate view ===== */

/* Scene selector (segmented control in the header) */
.scenes {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.scenes button {
  cursor: pointer;
  border: 1px solid #475569;
  background: #1e293b;
  color: var(--text-dim);
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  font-size: 0.82rem;
}

.scenes button:hover {
  background: #334155;
  color: var(--text);
}

.scenes button.scenes__active {
  background: var(--input-accent);
  border-color: var(--input-accent);
  color: #fff;
}

/* Power rails */
.rail {
  stroke-width: 5;
  stroke-linecap: round;
}

.rail--vdd {
  stroke: var(--wire-active); /* VDD is the high rail */
}

.rail--gnd {
  stroke: var(--wire-inactive); /* GND is the low rail */
}

.rail-label {
  font-size: 13px;
  font-weight: 700;
  fill: var(--text-dim);
  dominant-baseline: middle;
  user-select: none;
}

/* Conductors inside the gate (transistor leads + buses) carry a logic level */
.conductor {
  fill: none;
  stroke: var(--wire-inactive);
  stroke-width: 3.5;
  stroke-linecap: round;
  transition: stroke 80ms linear;
}

.conductor--high {
  stroke: var(--wire-active);
}

/* The live conducting path from the driving rail to the output */
.conductor--path {
  stroke-width: 5.5;
}

.node-dot {
  fill: var(--text);
}

/* Control (gate) lines from inputs to transistor gates */
.ctrl-line {
  fill: none;
  stroke: var(--wire-inactive);
  stroke-width: 2.5;
  stroke-dasharray: 5 4;
  transition: stroke 80ms linear;
}

.ctrl-line--high {
  stroke: var(--wire-active);
}

/* Transistor symbols */
.transistor__body {
  stroke-width: 2.5;
  rx: 6;
  fill: #0f172a;
  transition: fill 80ms linear, stroke 80ms linear;
}

.transistor--nmos .transistor__body {
  stroke: #38bdf8;
}

.transistor--pmos .transistor__body {
  stroke: #f472b6;
}

/* Conducting (closed) transistor: filled/energized; open: dim */
.transistor--on .transistor__body {
  fill: #14532d;
  stroke: var(--wire-active);
}

.transistor--off .transistor__body {
  opacity: 0.55;
}

.transistor__label {
  font-size: 12px;
  font-weight: 700;
  fill: var(--text);
  text-anchor: middle;
  dominant-baseline: central;
  user-select: none;
}

.transistor__state {
  font-size: 10px;
  fill: var(--text-dim);
  text-anchor: middle;
  user-select: none;
}

.gate-caption {
  fill: var(--text-dim);
  font-size: 12px;
  text-anchor: middle;
}

.gate-caption--strong {
  fill: var(--text);
  font-size: 14px;
  font-weight: 650;
}

/* Edit-schematic action in the toolbox rename panel */
.rename__edit-schematic {
    margin-top: 10px;
    width: 100%;
    padding: 6px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
}

.rename__edit-schematic:hover {
    background: var(--hover);
}

/* "Editing a component schematic" banner (shown during an edit session) */
.edit-banner {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 14px;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.edit-banner__label {
    font-size: 14px;
}

.edit-banner__actions {
    display: flex;
    gap: 8px;
}

.edit-banner__save,
.edit-banner__cancel {
    padding: 5px 14px;
    border-radius: 6px;
    border: 1px solid var(--line);
    cursor: pointer;
    font-size: 13px;
}

.edit-banner__save {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
}

.edit-banner__cancel {
    background: transparent;
    color: var(--ink);
}

.edit-banner__save:hover,
.edit-banner__cancel:hover {
    filter: brightness(1.1);
}

/* ===== Step 20: read-only inspect (drill-into) banner + breadcrumb ===== */
.inspect-banner {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: 80%;
    padding: 8px 14px;
    /* Amber/dashed — visually distinct from the accent-bordered edit banner. */
    border: 1px dashed #c9a23a;
    border-radius: 10px;
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.inspect-banner__tag {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #d7b24a;
    white-space: nowrap;
}

.inspect-banner__path {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    flex-wrap: nowrap;
}

.inspect-banner__sep {
    opacity: 0.5;
}

.inspect-banner__crumb {
    background: transparent;
    border: none;
    color: var(--ink);
    cursor: pointer;
    font-size: 13px;
    padding: 2px 4px;
    border-radius: 4px;
    white-space: nowrap;
    max-width: 14ch;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inspect-banner__crumb:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.08);
}

.inspect-banner__crumb--current {
    font-weight: 700;
    cursor: default;
}

.inspect-banner__actions {
    display: flex;
    gap: 8px;
}

.inspect-banner__back,
.inspect-banner__close {
    padding: 5px 12px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.inspect-banner__back:hover,
.inspect-banner__close:hover {
    filter: brightness(1.1);
}

/* "Edit component" — jumps from read-only inspection into an edit tab (step 24).
   Accented (amber, like an edit tab) so it stands out from the neutral Back/Close. */
.inspect-banner__edit {
    padding: 5px 12px;
    border-radius: 6px;
    border: 1px solid #b07a1e;
    background: #2a2418;
    color: #f0d9a0;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.inspect-banner__edit:hover {
    filter: brightness(1.15);
}

/* ===== Step 11: clock signal ===== */
.terminal--clock .clock__body {
    stroke: #f59e0b; /* amber — distinct from input(blue)/output(purple) */
}

.terminal--clock.terminal--high .clock__body {
    fill: var(--level-high);
}

.clock__tag {
    fill: #f59e0b;
    font-weight: 700;
}

/* Per-clock controls (run/pause, step, pace) rendered in a foreignObject */
.clock-ctrl {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    color: var(--text);
}

.clock-ctrl__row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.clock-ctrl__btn {
    padding: 1px 6px;
    border: 1px solid var(--line, #475569);
    border-radius: 4px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    line-height: 1.2;
}

.clock-ctrl__btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.clock-ctrl__hz {
    margin-left: auto;
    color: var(--text-dim);
}

.clock-ctrl__slider {
    width: 100%;
}

/* Clock name field (in the per-clock controls panel) */
.clock-ctrl__name {
    width: 100%;
    padding: 2px 5px;
    border: 1px solid var(--line, #475569);
    border-radius: 4px;
    background: var(--bg, #0f172a);
    color: var(--text);
    font-size: 11px;
}

/* ===== Step 12: seven-segment display ===== */
.instance--display .instance__body {
    fill: #1a1f2e;
    stroke: #f43f5e; /* rose — distinct device accent */
    stroke-width: 2.5;
}

/* Each segment is a thick rounded line; off = dim, on = bright red glow */
.seg {
    stroke-width: 8;
    stroke-linecap: round;
    pointer-events: none;
}

.seg--off {
    stroke: #2a2f3e; /* barely-there, like an unlit LED segment */
}

.seg--on {
    stroke: #ff3b3b; /* lit red LED */
}

/* ===== Step 16: workspace tabs ===== */
.ws-tabs {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 0.4rem 1.25rem 0;
  background: var(--panel);
  border-bottom: 1px solid #334155;
  /* Scroll horizontally if there are many tabs, but never vertically: with
     overflow-x set, overflow-y would otherwise compute to `auto` and the tabs'
     1px overhang (top: 1px + borders) would trigger a stray vertical scrollbar. */
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 2.1rem;
}

/* A tab: rounded top, sits on the bottom border; the active one "connects" to
   the canvas by matching its background and dropping the bottom edge. */
.ws-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.4rem 0.35rem 0.7rem;
  background: #172033;
  border: 1px solid #334155;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  color: var(--text-dim);
  font-size: 0.82rem;
  white-space: nowrap;
  position: relative;
  top: 1px;
}

.ws-tab--active {
  background: var(--workspace-bg);
  color: var(--text);
  border-top: 2px solid var(--input-accent);
  padding-top: calc(0.3rem - 1px);
}

/* An ephemeral edit tab (step 24): visually transient — dashed amber border and a
   tinted background so it's clearly not a saved workspace. */
.ws-tab--edit {
  background: #2a2418;
  border-color: #b07a1e;
  border-style: dashed;
  font-style: italic;
}

.ws-tab--edit.ws-tab--active {
  background: #3a3016;
  border-top: 2px solid #e0a72e;
  color: #f0d9a0;
}

.ws-tab__name {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-tab__rename {
  background: #0f172a;
  border: 1px solid var(--input-accent);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  width: 9rem;
  padding: 0.05rem 0.3rem;
}

.ws-tab__close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 0.2rem;
  border-radius: 4px;
}

.ws-tab__close:hover {
  background: var(--danger);
  color: #fff;
}

/* "New workspace" affordances, styled as quiet pills at the end of the row. */
.ws-tab__new {
  align-self: center;
  margin-left: 0.3rem;
  background: none;
  border: 1px solid #334155;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.82rem;
  line-height: 1.2;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
}

.ws-tab__new:hover {
  background: #334155;
  color: var(--text);
}

/* Per-tab export action, matching the close button's quiet styling. */
.ws-tab__export {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0 0.2rem;
  border-radius: 4px;
}
.ws-tab__export:hover {
  background: var(--input-accent);
  color: #fff;
}

/* ===== Step 17: toolbox sections ===== */
.toolbox__sections {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.toolbox__section {
  border: 1px solid #334155;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.4);
}
.toolbox__section.drag-over {
  border-color: var(--input-accent);
  background: rgba(59, 130, 246, 0.12);
}
.toolbox__section-header {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.3rem;
}
.toolbox__section-fold {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
}
.toolbox__section-rename,
.toolbox__section-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0 0.25rem;
  border-radius: 4px;
}
.toolbox__section-delete:hover {
  background: var(--danger);
  color: #fff;
}
.toolbox__section-rename:hover {
  color: var(--text);
}
.toolbox__new-section {
  margin-top: 0.45rem;
  width: 100%;
  background: none;
  border: 1px dashed #475569;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.3rem;
  border-radius: 6px;
}
.toolbox__new-section:hover {
  background: #334155;
  color: var(--text);
}

/* Context-menu submenu for a user section: an inline label that expands its
   panel on hover (kept inline rather than a floating flyout so the menu's own
   overflow-y scroll never clips it). */
.ctx-submenu__label {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  cursor: default;
}
.ctx-submenu__panel {
  display: none;
  padding-left: 0.5rem;
  border-left: 2px solid #334155;
  margin-left: 0.4rem;
  flex-direction: column;
  gap: 0.15rem;
}
.ctx-submenu:hover .ctx-submenu__panel {
  display: flex;
}
.ctx-submenu:hover .ctx-submenu__label {
  background: #334155;
  color: var(--text);
  border-radius: 6px;
}

/* Builtins-section terminal pseudo-items (Input/Output/Clock/Bus in/out). */
.toolbox__chip--terminal {
  font-style: italic;
  opacity: 0.95;
}

/* Copyable build stamp, pinned bottom-right — reveals a stale cached asset. */
.build-badge {
  position: fixed;
  right: 8px;
  bottom: 6px;
  z-index: 1000;
  padding: 2px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.4;
  color: #9aa4b2;
  background: rgba(20, 24, 31, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  cursor: pointer;
  user-select: all;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.build-badge:hover {
  opacity: 1;
}

/* ===== Step 21: import-components dialog ===== */
.import-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.import-dialog {
  width: min(560px, 92vw);
  max-height: 80vh;
  overflow: auto;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.import-dialog__title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}

.import-dialog__row {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
}

.import-dialog__cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.import-dialog__pane-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.7;
  margin-bottom: 6px;
}

.import-dialog__list {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  min-height: 120px;
  max-height: 320px;
  overflow: auto;
}

.import-dialog__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  font-size: 13px;
  cursor: pointer;
}

.import-dialog__item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.import-dialog__none,
.import-dialog__empty {
  opacity: 0.6;
  font-size: 13px;
  padding: 4px;
}

.import-dialog__resolved {
  font-size: 13px;
  padding: 3px 4px;
}

.import-dialog__resolved--dep {
  opacity: 0.65;
  font-style: italic;
}

.import-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.import-dialog__cancel,
.import-dialog__confirm {
  padding: 6px 16px;
  border-radius: 6px;
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 13px;
}

.import-dialog__confirm {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.import-dialog__confirm:disabled {
  opacity: 0.5;
  cursor: default;
}

.import-dialog__cancel {
  background: transparent;
  color: var(--ink);
}

/* ===== Step 31: versioned bundle import preview ===== */
.bundle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px;
  font-size: 13px;
}

.bundle-row__name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bundle-row__badge {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bundle-row__badge--new {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.bundle-row__badge--ver {
  color: #c89b3c;
  border-color: #c89b3c;
}

.bundle-row__badge--have {
  opacity: 0.6;
}

.bundle-row__fp {
  flex: 0 0 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  opacity: 0.7;
}

/* ===== Step 22: bus value hover tooltip ===== */
.bus-tooltip {
  position: absolute;
  z-index: 20;
  /* Sit just above-right of the pointer, and never eat the hover/click. */
  transform: translate(12px, -28px);
  pointer-events: none;
  padding: 2px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: nowrap;
  color: var(--ink);
  background: rgba(20, 24, 31, 0.92);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}


/* ===== Step 26: interactions help popup ===== */
.help-button {
  position: absolute;
  top: 0.75rem;
  right: 1.25rem;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid #475569;
  background: #172033;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

.help-button:hover {
  filter: brightness(1.15);
  border-color: var(--input-accent, #38bdf8);
}

/* The help popup reuses .modal (backdrop) + .modal__box, but is centered and
   wider than the click-positioned dialogs. */
.help-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
}

.help-box {
  position: relative;
  left: auto;
  top: auto;
  width: 620px;
  max-width: calc(100vw - 1.5rem);
  max-height: min(82vh, 720px);
  min-height: 0;
  padding: 1rem 1.2rem 1.2rem;
}

.help-box__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.help-box__head .modal__title {
  margin-bottom: 0;
  font-size: 1rem;
}

.help-box__close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
}

.help-box__close:hover {
  color: var(--text);
}

.help-box__intro {
  margin: 0.4rem 0 0.8rem;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.help-box__body {
  columns: 2;
  column-gap: 1.6rem;
}

.help-cat {
  break-inside: avoid;
  margin-bottom: 0.9rem;
}

.help-cat__title {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--input-accent, #38bdf8);
  border-bottom: 1px solid #334155;
  padding-bottom: 0.15rem;
}

.help-entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.18rem 0;
}

.help-entry__text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.help-entry__gesture {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
}

.help-entry__effect {
  font-size: 0.74rem;
  color: var(--text-dim);
}

.help-entry__fig {
  flex: 0 0 auto;
}

/* Inline-SVG gesture illustrations. */
.help-fig {
  width: 52px;
  height: 26px;
  display: block;
}

.help-fig__wire,
.help-fig__arrow {
  stroke: #94a3b8;
  stroke-width: 2;
}

.help-fig__arrowhead {
  fill: #94a3b8;
}

.help-fig__port {
  fill: #1e293b;
  stroke: #94a3b8;
  stroke-width: 1.5;
}

.help-fig__port--lit {
  fill: var(--level-high, #22c55e);
  stroke: var(--level-high, #22c55e);
}

.help-fig__chip {
  fill: #2a3550;
  stroke: #475569;
}

.help-fig__body,
.help-fig__inside {
  fill: #172033;
  stroke: #475569;
}

.help-fig__marquee {
  fill: rgba(56, 189, 248, 0.12);
  stroke: var(--input-accent, #38bdf8);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

/* Single column on narrow windows so nothing is clipped. */
@media (max-width: 560px) {
  .help-box__body {
    columns: 1;
  }
}

/* ===== Step 28: annotation areas ===== */
/* Each area's <g> carries a colour class setting `--area-col`; children read it. */
.area--slate {
  --area-col: #94a3b8;
}
.area--blue {
  --area-col: #3b82f6;
}
.area--teal {
  --area-col: #14b8a6;
}
.area--green {
  --area-col: #22c55e;
}
.area--amber {
  --area-col: #f59e0b;
}
.area--orange {
  --area-col: #f97316;
}
.area--rose {
  --area-col: #f43f5e;
}
.area--violet {
  --area-col: #8b5cf6;
}

/* The backdrop rectangle: dashed border + translucent fill, NON-interactive so
   components/wires/empty-canvas gestures on top are never blocked. */
.area__rect {
  fill: color-mix(in srgb, var(--area-col) 10%, transparent);
  stroke: var(--area-col);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

/* The label "tab" — the area's only interactive body affordance (move / rename /
   menu). */
.area__tab {
  cursor: move;
}
.area__tab-bg {
  fill: color-mix(in srgb, var(--area-col) 32%, transparent);
  stroke: var(--area-col);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: auto;
}
.area__label {
  fill: var(--area-col);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  user-select: none;
}

/* Active-area outline + corner resize handles. */
.area__outline {
  fill: none;
  stroke: var(--area-col);
  stroke-width: 1.5;
  stroke-dasharray: 2 2;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  opacity: 0.9;
}
.area__handle {
  fill: var(--area-col);
  stroke: #0b1020;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: auto;
  cursor: nwse-resize;
}

/* The per-area colour/delete menu (reuses .ctx-menu chrome). */
.area-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px;
  max-width: 168px;
}
.area-swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 5px;
  border: 2px solid #1f2937;
  background: var(--area-col);
  cursor: pointer;
}
.area-swatch:hover {
  border-color: #e5e7eb;
}

/* ===== Step 27: logical probes + chronogram ===== */
/* A ring around a probed port. */
.probe-marker {
  fill: none;
  stroke: #38bdf8;
  stroke-width: 2;
  stroke-dasharray: 3 2;
  pointer-events: none;
}

/* Bottom chronogram dock: a flex child after the workspace, fixed-ish height. */
.chronogram {
  flex: 0 0 auto;
  height: min(38vh, 260px);
  display: flex;
  flex-direction: column;
  background: #0d1426;
  border-top: 1px solid #334155;
  overflow: hidden;
}

/* Collapsed: shrink to just the header bar; hide the traces + axis. */
.chronogram--collapsed {
  height: auto;
}
.chronogram--collapsed .chronogram__rows,
.chronogram--collapsed .chronogram__axis {
  display: none;
}

.chronogram__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.6rem;
  border-bottom: 1px solid #1f2937;
}

.chronogram__fold {
  flex: 0 0 auto;
  margin-right: 0.45rem;
  width: 1.25rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 0.7rem;
  line-height: 1;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid #334155;
  border-radius: 4px;
  cursor: pointer;
}
.chronogram__fold:hover {
  color: var(--text);
  border-color: #475569;
}

.chronogram__title {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--text-dim);
}

.chronogram__axis {
  display: flex;
  justify-content: space-between;
  flex: 1;
  margin-left: 1rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.68rem;
  color: var(--text-dim);
}

.chronogram__rows {
  flex: 1;
  overflow-y: auto;
}

.chrono__row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid #161f33;
}

.chrono__label {
  flex: 0 0 9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
  padding: 0 0.5rem;
  border-right: 1px solid #1f2937;
  overflow: hidden;
}

.chrono__name {
  font-size: 0.76rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chrono__ctrls {
  display: inline-flex;
  gap: 1px;
  flex: 0 0 auto;
}

.chrono__btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.1rem 0.15rem;
}

.chrono__btn:hover {
  color: var(--text);
}

.chrono__plot {
  flex: 1;
  height: 34px;
  display: block;
  background:
    linear-gradient(90deg, #131c2e 1px, transparent 1px) repeat-x;
  background-size: 50px 100%;
}

/* The bit waveform — constant stroke width despite horizontal stretch. */
.chrono__bit {
  fill: none;
  stroke: var(--wire-active);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chrono__bus {
  fill: rgba(245, 158, 11, 0.18);
  stroke: var(--bus-accent);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chrono__bus-val {
  fill: var(--bus-accent);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 9px;
  text-anchor: middle;
  dominant-baseline: middle;
}
