/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --bg2:       #161b22;
  --bg3:       #1c2330;
  --border:    #30363d;
  --border2:   #484f58;
  --copper:    #c87941;
  --copper2:   #e8a060;
  --green:     #3fb950;
  --green-dim: #1a4a22;
  --blue:      #58a6ff;
  --blue-dim:  #1a2d4a;
  --yellow:    #d29922;
  --red:       #f85149;
  --red-dim:   #3d1a1a;
  --purple:    #bc8cff;
  --text:      #e6edf3;
  --text2:     #8b949e;
  --text3:     #484f58;
  --chip-bg:   #1e2a1a;
  --chip-border:#3a5a30;
  --pin-free:  #2d4a35;
  --pin-used:  #7a3a1a;
  --pin-hover: #4a8a50;
  --wire-1:    #c87941;
  --wire-2:    #58a6ff;
  --wire-3:    #3fb950;
  --wire-4:    #bc8cff;
  --wire-5:    #f0883e;
  --font-mono: 'Share Tech Mono', monospace;
  --font-ui:   'Exo 2', sans-serif;
  --font-head: 'Orbitron', sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ───────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 1rem;
  position: relative;
  z-index: 100;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 1.6rem; color: var(--copper); line-height: 1; }
.logo-title {
  font-family: var(--font-head);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--copper2);
}
.logo-sub { font-size: 0.68rem; color: var(--text2); letter-spacing: 0.05em; }
.logo-sep { color: var(--border2); margin: 0 0.4rem; }
.logo-back { font-size: 0.72rem; color: var(--text2); text-decoration: none; letter-spacing: 0.03em; font-family: var(--font-ui); font-weight: 400; }
.logo-back:hover { color: var(--copper2); }

.header-center { display: flex; gap: 0.75rem; }
.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 12px;
  min-width: 80px;
}
.stat-label { font-size: 0.6rem; letter-spacing: 0.1em; color: var(--text2); font-family: var(--font-mono); }
.stat-val { font-family: var(--font-mono); font-size: 0.95rem; color: var(--copper2); }

.header-right { display: flex; gap: 0.6rem; align-items: center; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  transition: border-color 0.15s, color 0.15s;
}
.btn-ghost:hover { border-color: var(--red); color: var(--red); }

.btn-primary {
  background: var(--copper);
  border: none;
  color: #0d1117;
  padding: 7px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--copper2); }
.btn-primary:disabled { background: var(--border2); color: var(--text3); cursor: not-allowed; }

/* ── Component shelf ──────────────────────────────────────────── */
.shelf {
  height: 96px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 6px 1.2rem 6px;
  flex-shrink: 0;
  overflow: hidden;
}
.shelf-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text3);
  letter-spacing: 0.12em;
  margin-bottom: 5px;
}
.shelf-items {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}

.shelf-item {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: grab;
  user-select: none;
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
  min-width: 72px;
}
.shelf-item:hover { border-color: var(--copper); transform: translateY(-2px); }
.shelf-item.disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }
.shelf-item-icon { font-size: 1.4rem; line-height: 1; }
.shelf-item-name { font-size: 0.65rem; color: var(--text2); text-align: center; font-family: var(--font-mono); white-space: nowrap; }
.shelf-item-count {
  position: absolute;
  top: 3px; right: 5px;
  font-size: 0.58rem;
  color: var(--text3);
  font-family: var(--font-mono);
}

/* ── Workspace ────────────────────────────────────────────────── */
.workspace {
  display: flex;
  height: calc(100vh - 56px - 96px - 34px);
  overflow: hidden;
}

/* ── Canvas ───────────────────────────────────────────────────── */
.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: auto;
  background: #484f58;   /* matches --border2 / darker page element gray */
  cursor: default;
}

/* Grid lines — match darker page grays */
.canvas-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  min-width: 3200px;
  min-height: 2400px;
  background-image:
    linear-gradient(#30363d 1px, transparent 1px),
    linear-gradient(90deg, #30363d 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.7;
  pointer-events: none;
  z-index: 0;
}
.canvas-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  min-width: 3200px;
  min-height: 2400px;
  background-image:
    linear-gradient(#3a4049 1px, transparent 1px),
    linear-gradient(90deg, #3a4049 1px, transparent 1px);
  background-size: 8px 8px;
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}

.wire-layer {
  position: absolute;
  top: 0; left: 0;
  min-width: 3200px;
  min-height: 2400px;
  pointer-events: none;
  z-index: 35;   /* above components (30) so node circles receive clicks */
  overflow: visible;
}

.canvas-grid {
  position: absolute;
  inset: 0;
  z-index: 10;
}

.canvas-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  color: var(--text3);
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.3s;
}
.canvas-hint.hidden { opacity: 0; }
.hint-icon { font-size: 2.5rem; opacity: 0.3; }

/* ── ESP32-S3 chip on canvas ──────────────────────────────────── */
.esp32-chip {
  position: absolute;
  min-width: 120px;
  background: var(--chip-bg);
  border: 2px solid var(--chip-border);
  border-radius: 8px;
  user-select: none;
  z-index: 20;
  box-shadow: 0 0 30px rgba(0,0,0,0.55), 0 8px 32px rgba(0,0,0,0.7);
  cursor: default;   /* chip body: not a move cursor — only drag handle moves it */
}
.chip-top-bar {
  background: var(--chip-border);
  border-radius: 6px 6px 0 0;
  padding: 5px 8px;
  text-align: center;
  cursor: move;       /* drag handle is the top bar only */
}
.chip-drag-handle {
  cursor: move;
}
.chip-name {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--green);
  letter-spacing: 0.12em;
}
.chip-body {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
}
.pin-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pin-col.left { align-items: flex-start; padding-left: 0; margin-left: -14px; }
.pin-col.right { align-items: flex-end; padding-right: 0; margin-right: -14px; }

.chip-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  gap: 4px;
}
.chip-logo {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--green);
  letter-spacing: 0.06em;
  text-align: center;
  line-height: 1.4;
}
.chip-model {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--text3);
  text-align: center;
}
.chip-notch {
  width: 18px; height: 8px;
  background: var(--bg);
  border-radius: 0 0 6px 6px;
  border: 1px solid var(--chip-border);
  border-top: none;
  margin: 0 auto 4px;
}

.pin-item {
  display: flex;
  align-items: center;
  gap: 0;
  height: 18px;
  cursor: pointer;
  position: relative;
}
.pin-col.left .pin-item { flex-direction: row; }
.pin-col.right .pin-item { flex-direction: row-reverse; }

.pin-stub {
  width: 14px; height: 3px;
  background: var(--copper);
  flex-shrink: 0;
  transition: background 0.15s;
}
.pin-item.used .pin-stub { background: var(--copper2); }
.pin-item.power .pin-stub { background: var(--red); }
.pin-item.gnd .pin-stub { background: var(--text3); }

.pin-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--pin-free);
  border: 1.5px solid var(--green-dim);
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  position: relative;
  z-index: 2;
}
.pin-item.used .pin-dot { background: var(--pin-used); border-color: var(--copper); }
.pin-item.power .pin-dot { background: #5a1a1a; border-color: var(--red); }
.pin-item.gnd .pin-dot { background: #1a1a1a; border-color: var(--text3); }
.pin-item:hover .pin-dot { background: var(--pin-hover); border-color: var(--green); transform: scale(1.3); }
.pin-item.drop-target .pin-dot { background: var(--green); border-color: #7fff80; transform: scale(1.5); animation: pulse-pin 0.6s ease infinite; }

@keyframes pulse-pin {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63,185,80,0.4); }
  50% { box-shadow: 0 0 0 5px rgba(63,185,80,0); }
}

.pin-label {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text2);
  padding: 0 3px;
  white-space: nowrap;
  pointer-events: none;
}
.pin-item.used .pin-label { color: var(--copper); }

/* ── Placed components ────────────────────────────────────────── */
.placed-component {
  position: absolute;
  background: var(--bg3);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px 6px;
  cursor: move;
  user-select: none;
  z-index: 30;
  min-width: 110px;
  width: max-content;       /* auto-size to content */
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 18px rgba(0,0,0,0.7);
}
.placed-component:hover { box-shadow: 0 6px 24px rgba(0,0,0,0.8); }
.placed-component.selected {
  box-shadow: 0 0 0 2px rgba(200,121,65,0.4), 0 6px 24px rgba(0,0,0,0.8);
}
.placed-component.unconfigured { border-color: var(--yellow) !important; }
.placed-component.error { border-color: var(--red) !important; }

.comp-header {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 5px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.comp-icon  { font-size: 0.8rem; }
.comp-title {
  font-family: var(--font-head);
  font-size: 0.52rem;
  letter-spacing: 0.05em;
  color: var(--text);
  flex: 1;
}
.comp-id { font-size: 0.5rem; color: var(--text3); font-family: var(--font-mono); }
.comp-color-swatch {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.12s;
}
.comp-color-swatch:hover { transform: scale(1.3); }

/* Pin rows — one per pin group */
.comp-pins { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.comp-pin-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 16px;
}
.comp-pin-label {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  transition: color 0.2s;
  white-space: nowrap;
}
.comp-pin-assigned {
  font-family: var(--font-mono);
  font-size: 0.52rem;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
}
.comp-pin-assigned.ok {
  color: var(--text2);
  background: var(--border);
}
.comp-pin-assigned.ok:hover { background: var(--border2); color: var(--text); }
.comp-pin-assigned.miss {
  color: var(--red);
  background: var(--red-dim);
}
.comp-status {
  font-size: 0.55rem;
  margin-top: 3px;
  font-family: var(--font-mono);
  border-top: 1px solid var(--border);
  padding-top: 3px;
}
.comp-status.ok { color: var(--green); }
.comp-status.warn { color: var(--yellow); }
.comp-status.err { color: var(--red); }
.placed-component.unconfigured { border-color: var(--yellow); }
.placed-component.error { border-color: var(--red); }


/* Component color swatch in card header */
.comp-color-swatch {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.12s;
}
.comp-color-swatch:hover { transform: scale(1.3); }

/* Color picker in panel */
.form-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.5rem;
}
.form-color-row label { font-size: 0.72rem; color: var(--text2); flex: 1; font-family: var(--font-mono); }
.form-color-input {
  width: 32px; height: 24px;
  border: 1px solid var(--border2);
  border-radius: 3px;
  padding: 1px;
  background: var(--bg3);
  cursor: pointer;
}
.color-reset-btn {
  font-size: 0.62rem;
  color: var(--text3);
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 6px;
  cursor: pointer;
  font-family: var(--font-mono);
}
.color-reset-btn:hover { color: var(--copper); border-color: var(--copper); }

/* USB port text label on chips */
.chip-usb-label {
  font-family: var(--font-head);
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  padding: 3px 5px;
  border-radius: 3px;
  border: 1.5px solid currentColor;
  opacity: 0.85;
  line-height: 1;
}
.chip-usb-label-top {
  margin: 2px auto 4px;
}
.chip-usb-labels-bottom {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 2px;
  padding-bottom: 3px;
}

/* ── Wires ────────────────────────────────────────────────────── */
.wire {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
/* Outline underlay */
.wire-outline {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
  pointer-events: none;
}
/* Draggable wire-end node circles */
.wire-node {
  cursor: grab;
  transition: r 0.1s;
}
.wire-node:hover { r: 11; }
/* Wire drag preview */
.wire-drag-preview {
  fill: none;
  stroke: rgba(255,255,255,0.85);
  stroke-width: 2;
  stroke-dasharray: 8 5;
  stroke-linecap: round;
  pointer-events: none;
}

/* ── Right panel ──────────────────────────────────────────────── */
.panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ptab {
  flex: 1;
  padding: 10px 8px;
  background: transparent;
  border: none;
  color: var(--text2);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  letter-spacing: 0.04em;
}
.ptab:hover { color: var(--text); }
.ptab.active { color: var(--copper2); border-bottom-color: var(--copper); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.panel-body.hidden { display: none; }

.panel-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 0.8rem;
  color: var(--text3);
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.6;
}
.empty-icon { font-size: 2rem; opacity: 0.4; }

/* Config form */
.form-section { margin-bottom: 1.2rem; }
.form-section-title {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text3);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.5rem;
}
.form-label {
  font-size: 0.75rem;
  color: var(--text2);
  min-width: 80px;
  flex-shrink: 0;
}
.form-input, .form-select {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus { border-color: var(--copper); }
.form-select option { background: var(--bg3); }

.form-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.4rem;
}
.form-check-row input[type=checkbox] { accent-color: var(--copper); width: 14px; height: 14px; cursor: pointer; }
.form-check-row label { font-size: 0.75rem; color: var(--text2); cursor: pointer; }

.pin-assign-table { width: 100%; border-collapse: collapse; }
.pin-assign-table td { padding: 3px 4px; font-size: 0.72rem; font-family: var(--font-mono); }
.pin-assign-table td:first-child { color: var(--text2); }
.pin-assign-table select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  width: 100%;
  outline: none;
}
.pin-assign-table select:focus { border-color: var(--copper); }

.btn-form {
  width: 100%;
  padding: 7px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  margin-top: 0.4rem;
  transition: background 0.15s, border-color 0.15s;
}
.btn-form:hover { background: var(--bg); border-color: var(--copper); }
.btn-form.danger { border-color: var(--red); color: var(--red); }
.btn-form.danger:hover { background: var(--red-dim); }

/* Notes panel */
.notes-header {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text3);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
}
.notes-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.notes-list li {
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 4px;
  border-left: 3px solid;
  background: var(--bg3);
  line-height: 1.4;
}
.note-ok    { border-color: var(--green);  color: var(--text2); }
.note-warn  { border-color: var(--yellow); color: var(--text); }
.note-error { border-color: var(--red);    color: var(--red); }
.note-info  { border-color: var(--blue);   color: var(--text2); }

/* Libraries panel */
.lib-note { font-size: 0.75rem; color: var(--text2); margin-bottom: 0.8rem; line-height: 1.5; }
.lib-note a { color: var(--copper); }
.lib-note code { background: var(--bg3); padding: 1px 5px; border-radius: 3px; font-family: var(--font-mono); font-size: 0.7rem; }
.lib-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.lib-list li {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text);
  background: var(--bg3);
  padding: 5px 10px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.lib-tag {
  font-size: 0.58rem;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text3);
  letter-spacing: 0.06em;
}
.lib-always .lib-tag { border-color: var(--green-dim); color: var(--green); }

/* ── Context menu ─────────────────────────────────────────────── */
.ctx-menu {
  position: fixed;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 4px;
  z-index: 1000;
  min-width: 130px;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.ctx-menu.visible { display: block; }
.ctx-item {
  padding: 7px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: 4px;
  color: var(--text);
  transition: background 0.1s;
}
.ctx-item:hover { background: var(--bg3); }
.ctx-item.ctx-danger { color: var(--red); }
.ctx-item.ctx-danger:hover { background: var(--red-dim); }
.ctx-sep { height: 1px; background: var(--border); margin: 3px 4px; }

/* ── Tooltip ──────────────────────────────────────────────────── */
.tooltip {
  position: fixed;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 0.72rem;
  color: var(--text);
  max-width: 220px;
  line-height: 1.5;
  pointer-events: none;
  z-index: 2000;
  display: none;
  font-family: var(--font-ui);
}
.tooltip.visible { display: block; }
.tooltip-title { font-weight: 600; color: var(--copper2); margin-bottom: 2px; }
.tooltip-body { color: var(--text2); }

/* ── Drag ghost ───────────────────────────────────────────────── */
.drag-ghost {
  position: fixed;
  background: var(--bg3);
  border: 1.5px solid var(--copper);
  border-radius: 6px;
  padding: 6px 10px;
  pointer-events: none;
  z-index: 9999;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--copper2);
  box-shadow: 0 4px 20px rgba(200,121,65,0.3);
  opacity: 0.9;
  transform: rotate(2deg);
  display: none;
}

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Resistor / cap symbols on wires ─────────────────────────── */
.wire-annotation {
  font-family: var(--font-mono);
  font-size: 9px;
  fill: var(--yellow);
  pointer-events: none;
}

/* ── Animations ───────────────────────────────────────────────── */
@keyframes drop-in {
  from { opacity: 0; transform: scale(0.85) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.placed-component { animation: drop-in 0.18s ease; }

@keyframes wire-draw {
  from { stroke-dashoffset: 1000; }
  to   { stroke-dashoffset: 0; }
}
.wire-new {
  stroke-dasharray: 1000;
  animation: wire-draw 0.35s ease forwards;
}

/* -- OS toggle buttons -------------------------------------------- */
.os-btn-group { display: flex; gap: 4px; }
.os-btn {
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--text2);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.os-btn:hover { border-color: var(--copper); color: var(--copper); }
.os-btn-active { border-color: var(--copper); color: var(--copper2); background: var(--bg2); }

/* -- Launch hint text --------------------------------------------- */
.launch-hint {
  font-size: 0.68rem;
  color: var(--text2);
  line-height: 1.5;
  padding: 5px 8px;
  background: var(--bg3);
  border-left: 2px solid var(--border2);
  border-radius: 0 4px 4px 0;
  margin-bottom: 0.5rem;
}
.launch-hint code {
  background: var(--bg2);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  color: var(--copper2);
}

/* -- Config 2 section --------------------------------------------- */
.config2-section {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 1rem;
  background: var(--bg3);
}
.config2-title {
  color: var(--blue) !important;
  border-bottom-color: var(--blue-dim) !important;
  margin-bottom: 0.6rem;
}

/* -- Instructions button ------------------------------------------ */
.btn-instructions {
  background: var(--text2);
  border: 1px solid var(--text2);
  color: var(--bg2);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  transition: background 0.15s, border-color 0.15s;
}
.btn-instructions:hover { background: var(--text); border-color: var(--text); color: var(--bg); }

/* -- Instructions modal ------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.modal-overlay.visible { display: flex; }

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  max-width: 680px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title {
  font-family: var(--font-head);
  font-size: 0.9rem;
  color: var(--copper2);
  letter-spacing: 0.06em;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text2);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--red); background: var(--red-dim); }

.modal-body {
  overflow-y: auto;
  padding: 1.4rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.modal-intro {
  font-size: 0.82rem;
  color: var(--text2);
  line-height: 1.65;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.modal-step {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.modal-step-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--copper);
  color: #0d1117;
  font-family: var(--font-head);
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}
.modal-step-body { flex: 1; }
.modal-step-title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.84rem;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.modal-step-body p {
  font-size: 0.78rem;
  color: var(--text2);
  line-height: 1.65;
  margin-bottom: 0.4rem;
}
.modal-step-body a { color: var(--copper2); }
.modal-step-body a:hover { color: var(--copper); }
.modal-step-body code {
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--green);
}
.modal-step-body strong { color: var(--text); }
.modal-note {
  background: var(--bg3);
  border-left: 3px solid var(--blue);
  padding: 6px 10px;
  border-radius: 0 4px 4px 0;
  font-size: 0.75rem !important;
  color: var(--text2) !important;
}

/* -- Stat chip tooltips ------------------------------------------- */
.stat-chip { cursor: default; }

/* -- Chip visual elements ----------------------------------------- */
/* Minimal: just text labels. No fake module boxes or decorative elements. */
.chip-logo-text {
  font-family: var(--font-head);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  line-height: 1.3;
  margin: 6px 4px 2px;
}
.chip-model-text {
  font-family: var(--font-mono);
  font-size: 0.44rem;
  color: var(--text3);
  text-align: center;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}
.chip-notch {
  width: 18px; height: 8px;
  background: var(--bg);
  border-radius: 0 0 6px 6px;
  border: 1px solid var(--chip-border);
  border-top: none;
  margin: 0 auto 4px;
}
/* Legacy classes kept as no-ops so old HTML refs don't error */
.chip-module-s3, .chip-module-c3, .chip-module-text, .chip-module-model,
.chip-mcu-bare, .chip-mcu-text, .chip-center-mid, .chip-rgb-dot,
.chip-usb-row { display: none; }

/* -- Bottom pins (XIAO VIN/GND) ----------------------------------- */
.chip-bottom-pins {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 2px 0;
}
.pin-item-bottom {
  flex-direction: column;
  align-items: center;
  height: auto;
  gap: 0;
}
.pin-stub-bottom {
  width: 3px;
  height: 8px;
  background: var(--copper);
}

/* -- Device selector ---------------------------------------------- */
.device-selector-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 1.2rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.device-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text3);
  letter-spacing: 0.12em;
  flex-shrink: 0;
  margin-right: 4px;
}
.device-btn {
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  white-space: nowrap;
}
.device-btn:hover { border-color: var(--copper); color: var(--copper); }
.device-btn.active { border-color: var(--copper); color: var(--copper2); background: var(--bg2); font-weight: 700; }


/* -- Chip visual elements ----------------------------------------- */
.chip-shield {
  width: 70%;
  padding-bottom: 55%;
  background: linear-gradient(145deg, #2a2a2a 0%, #1a1a1a 60%, #111 100%);
  border: 1.5px solid #444;
  border-radius: 4px;
  margin: 4px auto 6px;
  position: relative;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.8), 0 2px 4px rgba(0,0,0,0.5);
}
.chip-shield::after {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 3px;
}

.chip-usb-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.chip-usb {
  width: 28px;
  height: 14px;
  background: linear-gradient(180deg, #5a4a3a 0%, #3a2a1a 100%);
  border: 1.5px solid #6a5a4a;
  border-radius: 3px 3px 5px 5px;
  position: relative;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.6);
}
.chip-usb::before {
  content: '';
  position: absolute;
  top: 2px; left: 3px; right: 3px; bottom: 3px;
  background: #2a1a0a;
  border-radius: 1px 1px 3px 3px;
}
.chip-usb-top {
  border-radius: 5px 5px 3px 3px;
  margin: 0 auto 4px;
}

/* -- Bottom pins (XIAO VIN/GND) ----------------------------------- */
.chip-bottom-pins {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 4px 0 2px;
}
.pin-item-bottom {
  flex-direction: column;
  align-items: center;
  height: auto;
}
.pin-stub-bottom {
  width: 3px;
  height: 10px;
  background: var(--copper);
  flex-shrink: 0;
}
