/* ==========================================================================
   Build a Circuit — UI styles
   Design tokens first; every colour used below comes from them.
   ========================================================================== */

:root {
  --bg: #0d1014;
  --surface-1: #14181e;
  --surface-2: #1a1f27;
  --surface-3: #222833;
  --surface-4: #2b3240;
  --border: #252b35;
  --border-strong: #343c4a;
  --text: #e6e9ef;
  --text-2: #a9b2c0;
  --text-3: #6c7688;
  --accent: #3fb6ff;
  --accent-strong: #1e9cf0;
  --accent-soft: rgba(63, 182, 255, 0.14);
  --accent-contrast: #04121d;
  --success: #3ddc84;
  --success-soft: rgba(61, 220, 132, 0.14);
  --warning: #ffb020;
  --danger: #ff5d5d;
  --danger-soft: rgba(255, 93, 93, 0.14);
  --canvas-bg: #101318;
  --lcd-bg: #0a0d11;
  --lcd-text: #7ee2ff;
  --lcd-amber: #ffc04d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --toolbar-height: 52px;
  --panel-width: 248px;
  --properties-width: 300px;
  --font-ui: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #eef1f5;
  --surface-1: #ffffff;
  --surface-2: #f6f8fa;
  --surface-3: #edf0f4;
  --surface-4: #e2e6ec;
  --border: #e1e5eb;
  --border-strong: #cfd5de;
  --text: #19202b;
  --text-2: #4c5768;
  --text-3: #8791a1;
  --accent: #0a78e6;
  --accent-strong: #0866c7;
  --accent-soft: rgba(10, 120, 230, 0.1);
  --accent-contrast: #ffffff;
  --success: #12a454;
  --success-soft: rgba(18, 164, 84, 0.12);
  --warning: #c77700;
  --danger: #d93636;
  --danger-soft: rgba(217, 54, 54, 0.1);
  --canvas-bg: #fbfcfd;
  --lcd-bg: #12161c;
  --shadow-sm: 0 1px 2px rgba(20, 30, 45, 0.08);
  --shadow-md: 0 6px 18px rgba(20, 30, 45, 0.1);
  --shadow-lg: 0 18px 50px rgba(20, 30, 45, 0.18);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; user-select: text; -webkit-user-select: text; }
[hidden] { display: none !important; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}

/* ========== TOP BAR ========== */
#toolbar {
  height: var(--toolbar-height);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 100;
}

.brand { display: flex; align-items: center; gap: 9px; padding-right: 10px; margin-right: 2px; border-right: 1px solid var(--border); height: 28px; }
.brand-mark { width: 26px; height: 26px; stroke-width: 2.4; }
.brand-mark rect { fill: var(--surface-3); stroke: none; }
.brand-mark path { stroke: var(--accent); }
.brand-name { font-weight: 650; font-size: 14px; letter-spacing: -0.01em; white-space: nowrap; }

.menubar { display: flex; align-items: center; gap: 1px; }

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.toolbar-btn:hover { background: var(--surface-3); color: var(--text); }
.toolbar-btn:active { background: var(--surface-4); }
.toolbar-btn:disabled { opacity: 0.35; cursor: default; background: transparent; }
.toolbar-btn.ghost { border-color: var(--border-strong); color: var(--text); }
.toolbar-btn.icon-only { width: 32px; padding: 0; justify-content: center; }
.toolbar-dropdown.open > .menu-btn { background: var(--surface-3); color: var(--text); }

.btn-group { display: inline-flex; gap: 1px; }

.toolbar-center { flex: 1; display: flex; justify-content: center; min-width: 0; }
#circuit-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  font-weight: 550;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.toolbar-actions { display: flex; align-items: center; gap: 6px; }

/* Theme icon swap */
#tb-theme .icon-moon { display: none; }
[data-theme="light"] #tb-theme .icon-sun { display: none; }
[data-theme="light"] #tb-theme .icon-moon { display: block; }

/* Run / Stop */
.run-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 16px 0 13px;
  margin-left: 4px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 650;
  font-size: 13px;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
}
.run-btn:hover { background: var(--accent-strong); }
.run-btn:active { transform: translateY(1px); }
.run-dot { width: 0; height: 0; border-left: 9px solid currentColor; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.run-btn.on { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); box-shadow: 0 0 0 3px var(--success-soft); }
.run-btn.on:hover { background: var(--surface-4); }
.run-btn.on .run-dot { width: 9px; height: 9px; border: none; border-radius: 2px; background: var(--danger); }

/* Dropdown menus */
.toolbar-dropdown { position: relative; }
.toolbar-dropdown-content {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 232px;
  padding: 5px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: pop 0.12s ease-out;
}
.toolbar-dropdown.open .toolbar-dropdown-content { display: block; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 7px 10px;
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.dropdown-item:hover { background: var(--accent-soft); }
.dropdown-item.disabled { opacity: 0.4; cursor: default; pointer-events: none; }
.dropdown-item .shortcut { color: var(--text-3); font-size: 11.5px; font-family: var(--font-mono); }
.dropdown-item.active, .dropdown-item.view-active { color: var(--accent); }
.dropdown-item.active::after, .dropdown-item.view-active::after { content: '✓'; font-weight: 700; }
.dropdown-separator { height: 1px; background: var(--border); margin: 5px 4px; }
.dropdown-label { padding: 6px 10px 3px; font-size: 10.5px; font-weight: 650; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3); }

/* ========== LAYOUT ========== */
#app { display: flex; height: calc(100vh - var(--toolbar-height)); min-height: 0; }

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 10px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-2);
  flex-shrink: 0;
}
.panel-header-hint { text-transform: none; letter-spacing: 0; font-weight: 450; color: var(--text-3); font-size: 11px; }

/* ========== PARTS LIBRARY ========== */
#component-library {
  width: var(--panel-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.search-wrap { position: relative; margin: 0 12px 8px; }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); pointer-events: none; }
.search-wrap input {
  width: 100%;
  height: 34px;
  padding: 0 10px 0 32px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.search-wrap input::placeholder { color: var(--text-3); }
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

#component-list { flex: 1; overflow-y: auto; padding: 2px 8px 16px; }

.component-category { margin-bottom: 4px; }
.category-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 6px 6px;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  text-align: left;
}
.category-header::before {
  content: '';
  width: 6px; height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
  transition: transform 0.15s;
}
.component-category.collapsed .category-header::before { transform: rotate(-45deg); }
.category-header:hover { color: var(--text-2); }
.category-count { margin-left: auto; font-weight: 550; letter-spacing: 0; background: var(--surface-3); color: var(--text-3); border-radius: 999px; padding: 0 7px; font-size: 10.5px; line-height: 17px; }
.component-category.collapsed .category-items { display: none; }

.component-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 8px 3px 4px;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text);
  transition: background 0.1s, border-color 0.1s;
}
.component-item:hover { background: var(--surface-3); }
.component-item.active { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.component-item[draggable="true"]:active { cursor: grabbing; }
.component-icon { width: 44px; height: 30px; flex-shrink: 0; border-radius: 5px; background: var(--surface-2); }
.component-label { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ========== CANVAS ========== */
#canvas-container { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--canvas-bg); }
#canvas-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
#circuit-canvas { flex: 1; display: block; min-width: 0; min-height: 0; cursor: default; }

.canvas-hud {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}
.hud-btn {
  min-width: 30px;
  height: 28px;
  padding: 0 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.hud-btn:hover { background: var(--surface-3); color: var(--text); }
.hud-btn svg { width: 16px; height: 16px; }
.hud-zoom { font-family: var(--font-mono); font-size: 11.5px; min-width: 50px; }
.hud-sep { width: 1px; height: 18px; background: var(--border); margin: 0 2px; }

.empty-state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; padding: 24px; }
.empty-card {
  pointer-events: auto;
  max-width: 420px;
  text-align: center;
  padding: 28px 30px 24px;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(6px);
}
.empty-icon { width: 92px; height: 58px; color: var(--accent); stroke-width: 2.2; margin-bottom: 6px; }
.empty-card h2 { font-size: 18px; font-weight: 650; letter-spacing: -0.01em; margin-bottom: 8px; }
.empty-card p { color: var(--text-2); font-size: 13px; line-height: 1.55; margin-bottom: 18px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; }

/* ========== BENCH SUPPLY BAR ========== */
#power-supply-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 48px;
  padding: 8px 14px;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
}
.bench-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bench-group.is-empty { opacity: 0.45; }
.bench-spacer { flex: 1; }
.bench-label { font-size: 11px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); white-space: nowrap; }
.bench-number { width: 58px; height: 26px; padding: 0 6px; background: var(--lcd-bg); color: var(--lcd-text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: 12.5px; text-align: right; }
.bench-number:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.bench-unit { height: 26px; min-width: 34px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 650; cursor: pointer; }
.bench-unit:hover { background: var(--surface-3); color: var(--text); }
#supply-target { color: var(--accent); letter-spacing: 0; text-transform: none; margin-left: 2px; }
#voltage-slider { width: 180px; accent-color: var(--accent); cursor: pointer; }
#voltage-slider:disabled { cursor: default; }
.lcd {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--lcd-text);
  background: var(--lcd-bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 3px 9px;
  min-width: 78px;
  text-align: right;
  text-shadow: 0 0 8px color-mix(in srgb, var(--lcd-text) 45%, transparent);
  white-space: nowrap;
}
.lcd-amber { color: var(--lcd-amber); text-shadow: 0 0 8px color-mix(in srgb, var(--lcd-amber) 45%, transparent); }
.bench-status { color: var(--text-2); font-family: var(--font-mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }

.sim-running-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 11.5px;
  font-weight: 650;
}
.sim-running-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

#status-bar {
  height: 26px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  font-size: 11.5px;
  color: var(--text-3);
  background: var(--surface-1);
  border-top: 1px solid var(--border);
}
.status-item { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.status-item span { color: var(--text-2); }
.status-spacer { flex: 1; }
.status-hints { overflow: hidden; text-overflow: ellipsis; }

/* ========== RIGHT COLUMN ========== */
#right-column {
  width: var(--properties-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  min-height: 0;
}
#properties-panel { flex: 1 1 55%; min-height: 0; display: flex; flex-direction: column; }
#about-circuit-panel { flex: 1 1 45%; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--border); }
#prop-content, #about-circuit-content { flex: 1; overflow-y: auto; padding: 0 14px 16px; }

.prop-hint, .about-hint { color: var(--text-3); font-size: 12.5px; text-align: center; padding: 28px 18px; line-height: 1.55; }

.prop-header { padding: 2px 0 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.prop-title-row { display: flex; align-items: baseline; gap: 8px; }
.prop-ref { font-size: 17px; font-weight: 700; font-family: var(--font-mono); color: var(--accent); }
.prop-type-label { color: var(--text-2); font-size: 12.5px; font-weight: 550; }
.prop-description { color: var(--text-3); font-size: 12px; margin-top: 4px; line-height: 1.45; }

.prop-controls { display: flex; flex-direction: column; gap: 10px; padding: 10px; margin-bottom: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.control-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.control-state { font-weight: 600; }
.prop-help { color: var(--text-3); font-size: 11.5px; line-height: 1.45; }
.press-btn.pressed { transform: translateY(1px); filter: brightness(0.85); }

.prop-slider-row { display: flex; flex-direction: column; gap: 6px; }
.slider-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-2); }
.slider-value { font-family: var(--font-mono); color: var(--text); }
.prop-slider { width: 100%; accent-color: var(--accent); cursor: pointer; }
.pot-readout { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }

.prop-live { margin-bottom: 10px; padding: 10px; border-radius: var(--radius); background: var(--lcd-bg); border: 1px solid var(--border-strong); }
.live-rate { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 8px; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: #6e7a8d; }
.live-rate-select { height: 22px; padding: 0 4px; background: transparent; color: #a9b2c0; border: 1px solid #2c3442; border-radius: var(--radius-sm); font-size: 11px; text-transform: none; letter-spacing: 0; }
.burn-panel { margin-bottom: 12px; padding: 12px; border-radius: var(--radius); background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); }
.burn-title { font-size: 12px; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--danger); }
.burn-why { margin: 6px 0 10px; font-size: 12.5px; line-height: 1.5; color: var(--text); }
.burn-fixes-title { font-size: 11.5px; font-weight: 650; color: var(--text-2); margin-bottom: 4px; }
.burn-fixes { margin: 0 0 10px; padding-left: 18px; font-size: 12.5px; line-height: 1.5; color: var(--text); }
.burn-fixes li { margin-bottom: 4px; }
.burn-reset { width: 100%; }
.fault-panel { background: color-mix(in srgb, var(--warning) 12%, transparent); border-color: color-mix(in srgb, var(--warning) 50%, transparent); }
.fault-panel .burn-title { color: var(--warning); }
.fault-maker { margin-top: 12px; padding: 8px 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.fault-maker summary { cursor: pointer; font-size: 12px; font-weight: 650; color: var(--text-2); }
.fault-row { display: flex; gap: 8px; margin-top: 8px; }
.fault-row .prop-select { flex: 1; min-width: 0; }
.burn-order { margin: 0 0 10px; padding-left: 18px; font-size: 12px; line-height: 1.5; color: var(--text-2); }
.burn-order .burn-current { color: var(--text); font-weight: 650; }
.burn-note { margin-top: 6px; font-size: 11px; color: var(--text-3); }
.prop-temp { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; padding: 7px 10px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.prop-temp-value { font-family: var(--font-mono); font-size: 13px; font-weight: 650; color: var(--text); }
.prop-temp-note { font-size: 11.5px; color: var(--text-3); }
.prop-live.warn { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.live-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.live-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.live-label { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: #6e7a8d; }
.live-value { font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--lcd-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-extra { margin-top: 8px; font-size: 11.5px; color: #c7d0dc; }

.prop-fields { display: flex; flex-direction: column; gap: 2px; }
.prop-row { display: grid; grid-template-columns: 112px 1fr; align-items: center; gap: 8px; padding: 3px 0; }
.prop-row label { font-size: 12px; color: var(--text-2); line-height: 1.25; }
.prop-control { display: flex; align-items: center; gap: 6px; min-width: 0; }
.prop-input, .prop-select {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.prop-select { font-family: var(--font-ui); cursor: pointer; }
.prop-input:focus, .prop-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.prop-input.invalid { border-color: var(--danger); background: var(--danger-soft); }
.prop-unit { color: var(--text-3); font-size: 12px; min-width: 18px; }
.prop-actions { margin-top: 12px; display: flex; gap: 8px; }
.prop-actions .btn { flex: 1; }

.resistor-color-bands { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.bands-label { font-size: 12px; color: var(--text-2); }
.color-band-display { display: flex; gap: 5px; padding: 4px 10px; background: #d8c39a; border-radius: 10px; }
.color-band { width: 7px; height: 26px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
.tolerance-band { margin-left: 8px; }

/* About this circuit */
.about-circuit-title { font-size: 15px; font-weight: 650; margin: 6px 0 8px; letter-spacing: -0.005em; }
.about-circuit-text { color: var(--text-2); font-size: 12.8px; line-height: 1.6; user-select: text; -webkit-user-select: text; }
.about-lookfor { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.about-lookfor-title { font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.about-lookfor p { font-size: 12.8px; line-height: 1.55; color: var(--text); user-select: text; -webkit-user-select: text; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn:disabled, .auth-link:disabled { opacity: 0.55; cursor: default; pointer-events: none; }

/* ========== MODALS ========== */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(5, 8, 12, 0.55);
  backdrop-filter: blur(3px);
  z-index: 500;
  animation: fade 0.15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  max-height: 100%;
  padding: 20px 22px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: rise 0.18s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.modal-header h3 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.modal-subtitle { color: var(--text-3); font-size: 12.5px; margin-top: 3px; }
.modal-close {
  width: 32px; height: 32px;
  flex-shrink: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-3);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-3); color: var(--text); }

/* Examples gallery */
.examples-dialog { width: min(1040px, 100%); height: min(760px, 100%); }
.examples-toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.examples-toolbar .search-wrap { margin: 0; max-width: 360px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
}
.chip:hover { background: var(--surface-3); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
#examples-list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 10px;
  align-content: start;
  padding: 2px 4px 4px 2px;
}
.example-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-height: 118px;
  padding: 13px 14px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.12s, box-shadow 0.12s;
}
.example-card:hover { border-color: var(--accent); background: var(--surface-3); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.example-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 999px;
}
.example-title { font-size: 13.5px; font-weight: 650; color: var(--text); line-height: 1.3; }
.example-description {
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Saved modules */
.modules-dialog { width: min(560px, 100%); max-height: min(620px, 100%); }
.modules-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 0; }
.module-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.module-info { flex: 1; min-width: 0; }
.module-name { font-size: 13.5px; font-weight: 650; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.module-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.module-row .btn { height: 28px; padding: 0 12px; }
.modules-empty { padding: 28px 12px; text-align: center; color: var(--text-2); font-size: 13px; line-height: 1.55; }

/* Shortcuts */
.shortcuts-dialog { width: min(760px, 100%); }
.shortcuts-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.shortcut-section h4 { font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3); margin-bottom: 8px; }
.shortcut-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px dashed var(--border); font-size: 12.5px; color: var(--text-2); }
.shortcut-row:last-child { border-bottom: 0; }

/* Code editor */
#code-editor-modal .modal-content { width: min(920px, 100%); height: min(640px, 100%); }
#code-editor-container { flex: 1; display: flex; gap: 12px; min-height: 0; }
#code-textarea {
  flex: 1;
  resize: none;
  padding: 14px;
  background: var(--lcd-bg);
  color: #dfe6f1;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  tab-size: 4;
  outline: none;
}
#code-textarea:focus { border-color: var(--accent); }
#pin-reference { width: 210px; overflow-y: auto; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); font-size: 11.5px; }
#pin-reference h4 { font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3); margin-bottom: 8px; }
.pin-ref-item { display: flex; justify-content: space-between; padding: 2px 0; color: var(--text-2); font-family: var(--font-mono); }
.code-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; }

/* ========== INSTRUMENT PANELS ========== */
#instrument-container { position: fixed; inset: 0; pointer-events: none; z-index: 300; }
#instrument-container > * { pointer-events: auto; }
.instrument-panel {
  position: absolute;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  color: var(--text);
  user-select: none;
}
.instrument-titlebar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  cursor: move;
}
.instrument-title { font-size: 12.5px; font-weight: 650; color: var(--text); }
.inst-dots { display: flex; gap: 6px; }
.inst-dot { width: 14px; height: 14px; border-radius: 50%; cursor: pointer; }
.inst-dot-min { background: #e8a317; }
.inst-dot-close { background: #e84040; }
.inst-dot:hover { filter: brightness(1.15); }
.instrument-content { padding: 8px; flex: 1; overflow: auto; }
.instrument-panel select, .instrument-panel input[type="text"], .instrument-panel input[type="number"] {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text);
  padding: 3px 6px;
}
.instrument-panel button { cursor: pointer; }
/* Plot screens stay dark in both themes, like a real instrument */
.instrument-canvas { display: block; width: 100%; background: #0a0a0a; border: 1px solid #333; border-radius: 4px; }
/* Parameter Sweep */
.sweep-form { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; margin-bottom: 10px; }
.sweep-form label { font-size: 11px; color: var(--text-2); text-align: right; }
.sweep-form select, .sweep-form input { font-size: 12px; }
.sweep-form input { font-family: var(--font-mono); }
.instrument-panel .sweep-run { width: 100%; margin-bottom: 8px; }
.sweep-status { font-size: 11px; color: var(--text-3); margin-top: 4px; text-align: center; }

/* ========== CONTEXT MENU / TOOLTIPS / TOASTS ========== */
.context-menu {
  position: fixed;
  min-width: 190px;
  padding: 5px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  animation: pop 0.1s ease-out;
}
.context-menu-item { padding: 7px 10px; border-radius: 5px; font-size: 13px; cursor: pointer; }
.context-menu-item:hover { background: var(--accent-soft); }
.context-menu-separator { height: 1px; background: var(--border); margin: 5px 4px; }

.circuit-tooltip {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-width: 260px;
  padding: 7px 10px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 12px;
  pointer-events: none;
  z-index: 600;
}
.tooltip-ref { font-family: var(--font-mono); font-weight: 700; color: var(--accent); }
.tooltip-type { color: var(--text-2); font-size: 11.5px; }
.tooltip-value { font-family: var(--font-mono); color: var(--text); }
.tooltip-hint { margin-top: 3px; font-size: 11px; color: var(--success); font-weight: 600; }

#toast-container { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 900; pointer-events: none; }
.toast {
  max-width: 520px;
  padding: 9px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  font-weight: 550;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: none; }
.toast-warn { border-color: var(--warning); color: var(--warning); }

/* Instrument probe cursor: the needle tip (bottom left) is the hot spot */
#circuit-canvas.probe-cursor { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M2 30 11 21' stroke='%23111' stroke-width='3.4' stroke-linecap='round'/%3E%3Cpath d='M2.6 29.4 11 21' stroke='%23e6e6e6' stroke-width='1.6' stroke-linecap='round'/%3E%3Cpath d='M11.5 20.5 23.5 8.5' stroke='%23111' stroke-width='8.4' stroke-linecap='round'/%3E%3Cpath d='M11.5 20.5 23.5 8.5' stroke='%23e53935' stroke-width='5.6' stroke-linecap='round'/%3E%3Cpath d='M24 8c2-3 4-5 7-6' stroke='%23111' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") 2 30, crosshair; }

/* ========== ACCOUNTS (hosted site only: html[data-cloud], set by js/boot.js) ========== */
html:not([data-cloud]) .cloud-only { display: none !important; }
html[data-cloud] .local-only { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Sign-in screen: covers the app until a verified account is signed in */
.auth-gate { display: none; }
html[data-cloud] .auth-gate:not(.hidden) {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: max(24px, 8vh) 16px 24px;
  background: var(--bg);
}
.auth-card {
  width: min(400px, 100%);
  padding: 28px 26px 18px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
.auth-brand .brand-mark { width: 34px; height: 34px; }
.auth-brand .brand-name { display: inline; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.auth-tagline { margin: 8px 0 22px; text-align: center; color: var(--text-3); font-size: 12.5px; line-height: 1.5; }
.auth-step { display: flex; flex-direction: column; gap: 12px; }
.auth-step form { display: flex; flex-direction: column; gap: 12px; }
.auth-title { font-size: 17px; font-weight: 650; text-align: center; }
.auth-note { color: var(--text-2); font-size: 13px; line-height: 1.55; text-align: center; overflow-wrap: anywhere; }
.auth-field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.auth-field input {
  height: 40px;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
}
.auth-field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-keep { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 12.5px; cursor: pointer; }
.auth-keep input { width: 15px; height: 15px; accent-color: var(--accent); }
.code-input { text-align: center; font-family: var(--font-mono); font-size: 20px !important; letter-spacing: 6px; }
.auth-submit { width: 100%; height: 40px; font-size: 13.5px; }
.auth-link {
  align-self: center;
  min-height: 32px;
  padding: 4px 8px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.auth-link:hover { text-decoration: underline; }
.auth-toggle { text-align: center; color: var(--text-3); font-size: 12.5px; }
.auth-error, .auth-success { padding: 9px 12px; border-radius: var(--radius); font-size: 12.5px; line-height: 1.45; overflow-wrap: anywhere; }
.auth-error { background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.auth-success { background: var(--success-soft); border: 1px solid color-mix(in srgb, var(--success) 35%, transparent); color: var(--success); }
.auth-check { width: 48px; height: 48px; margin: 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--success-soft); color: var(--success); font-size: 26px; }
.auth-spinner { width: 30px; height: 30px; margin: 10px auto 0; border: 3px solid var(--surface-4); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-footer { display: flex; justify-content: center; gap: 8px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 12px; }
.auth-footer a, .account-footer a { color: var(--text-3); text-decoration: none; }
.auth-footer a:hover, .account-footer a:hover { color: var(--accent); text-decoration: underline; }

/* My circuits */
.circuits-footer { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.circuits-count { flex: 1; color: var(--text-3); font-size: 12px; }

/* Account dialog */
.account-dialog { width: min(520px, 100%); max-height: min(720px, 100%); overflow-y: auto; }
.account-sections { display: flex; flex-direction: column; gap: 12px; }
.account-section { padding: 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.account-row > .btn { flex-shrink: 0; white-space: nowrap; }
.account-row h4 { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 650; }
.account-hint { margin-top: 3px; color: var(--text-3); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.account-lead { color: var(--text-2); font-size: 13px; line-height: 1.5; }
.account-step { color: var(--text-2); font-size: 12.5px; line-height: 1.5; }
.account-form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
#acct-reauth { margin-top: 0; }
.account-actions { display: flex; justify-content: flex-end; gap: 8px; }
.account-footer { display: flex; align-items: center; gap: 14px; padding-top: 4px; font-size: 12.5px; }
.badge { padding: 1px 7px; border-radius: 999px; background: var(--surface-4); color: var(--text-3); font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.badge.badge-on { background: var(--success-soft); color: var(--success); }
.qr-canvas { align-self: center; width: 200px; height: 200px; border-radius: var(--radius-sm); image-rendering: pixelated; }
.secret-key { font-family: var(--font-mono); font-size: 12px; color: var(--text); word-break: break-all; user-select: all; -webkit-user-select: all; }
@media (max-width: 480px) {
  .account-row { flex-direction: column; align-items: stretch; }
  .auth-card { padding: 22px 18px 14px; }
}

/* ========== SCROLLBARS ========== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 10px; border: 3px solid var(--surface-1); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ========== RESPONSIVE ========== */
@media (max-width: 1280px) {
  :root { --panel-width: 220px; --properties-width: 272px; }
  .status-hints { display: none; }
}
@media (max-width: 1100px) {
  .brand-name, #btn-examples span { display: none; }
  .toolbar-center { display: none; }
  .toolbar-actions { margin-left: auto; }
}
@media (max-width: 900px) {
  #right-column { display: none; }
  .shortcuts-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  #component-library { display: none; }
  .menubar .toolbar-dropdown:nth-child(n+5) { display: none; }
  #voltage-slider { width: 110px; }
  .shortcuts-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ========== PRINT ========== */
@media print {
  #toolbar, #component-library, #right-column, #power-supply-bar, #status-bar, .canvas-hud { display: none; }
  #canvas-container { width: 100%; height: 100%; }
  body { background: white; }
}
