/* ============================================================
   WORKBENCH (breadboard) — PCB aesthetic with IC chips
   ============================================================
   Layers (bottom → top):
   1. .bb-viewport       — PCB surface + pan/zoom canvas
   2. .bb-chain-v2       — one chain, absolute in canvas space
   3.   .bb-chain-strip  — slim metric header above chain
   4.   .bb-zones-layer  — voltage-zone tinted bands
   5.   svg.bb-traces    — copper trace SVG overlay
   6.   .bb-battery      — source brick with terminals
   7.   .bb-chip         — IC-style slot cards with pin legs
   ============================================================ */

#railsContainer.is-breadboard {
  padding: 0;
  background: transparent;
  border: none;
}

/* ------------------------------------------------------------
   PCB VIEWPORT
   ------------------------------------------------------------ */
.bb-viewport {
  position: relative;
  width: 100%;
  height: 560px;
  overflow: hidden;
  border-radius: 4px;
  background:
    /* silkscreen cross-hatch */
    repeating-linear-gradient(45deg,
      transparent 0 6px,
      rgba(255, 255, 255, 0.015) 6px 7px),
    /* perforated via dots */
    radial-gradient(circle at 16px 16px,
      rgba(10, 6, 2, 0.35) 1px, transparent 1.4px),
    /* PCB green fiberglass */
    linear-gradient(180deg, #1f4430 0%, #17342a 100%);
  background-size: 100% 100%, 32px 32px, 100% 100%;
  border: 3px solid #5a3e22;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.08),
    inset 0 -3px 8px rgba(0, 0, 0, 0.4),
    0 4px 12px rgba(0, 0, 0, 0.35);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.bb-viewport.is-panning { cursor: grabbing; }

.bb-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
}

/* ------------------------------------------------------------
   CHAIN (v2) — container for all layers of one chain
   ------------------------------------------------------------ */
.bb-chain-v2 {
  position: absolute;
  overflow: visible;
}

/* Header strip — slim metric bar above the chain */
.bb-chain-strip {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, #2b4238 0%, #1a2b23 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(199, 122, 58, 0.35);   /* copper underline */
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 1.2px;
  color: rgba(253, 240, 213, 0.85);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  z-index: 4;
  border-radius: 3px 3px 0 0;
}
.bb-strip-label { font-weight: bold; letter-spacing: 2.5px; color: var(--gold); }
.bb-strip-v {
  background: rgba(10, 6, 2, 0.5);
  padding: 1px 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  color: #ffd97d;
  font-weight: bold;
}
.bb-strip-meter {
  margin-left: auto;
  background: rgba(10, 6, 2, 0.5);
  padding: 1px 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  color: #98e8b0;
}
.bb-strip-meter.warn { color: #ffd47a; border-color: rgba(255, 212, 122, 0.4); }
.bb-strip-meter.over { color: #ff9090; border-color: rgba(255, 144, 144, 0.5); animation: stripOverPulse 1s infinite; }
@keyframes stripOverPulse { 50% { background: rgba(166, 48, 48, 0.4); } }
.bb-strip-base {
  background: rgba(10, 6, 2, 0.3);
  padding: 1px 6px;
  border: 1px dashed rgba(253, 240, 213, 0.25);
  border-radius: 2px;
  color: rgba(253, 240, 213, 0.65);
  font-size: 9px;
}

/* ------------------------------------------------------------
   ZONE BANDS
   ------------------------------------------------------------
   One per contiguous run of same-zone slots. Tinted subtly so
   the band reads as a region without drowning chips.
   ------------------------------------------------------------ */
.bb-zones-layer {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 1;
}
.bb-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px dashed rgba(255, 255, 255, 0.15);
  border-right: 1px dashed rgba(255, 255, 255, 0.15);
  box-sizing: border-box;
}
.bb-zone:first-child  { border-left: none; }
.bb-zone:last-child   { border-right: none; }

.bb-zone.zone-9v  { background: linear-gradient(180deg, rgba(199, 122, 58, 0.22), rgba(199, 122, 58, 0.08)); }
.bb-zone.zone-5v  { background: linear-gradient(180deg, rgba(90, 160, 196, 0.22), rgba(90, 160, 196, 0.08)); }
.bb-zone.zone-3v  { background: linear-gradient(180deg, rgba(104, 196, 126, 0.22), rgba(104, 196, 126, 0.08)); }
.bb-zone.zone-1_5v { background: linear-gradient(180deg, rgba(170, 170, 170, 0.20), rgba(170, 170, 170, 0.06)); }
.bb-zone.zone-dead { background: linear-gradient(180deg, rgba(60, 30, 20, 0.25), rgba(30, 15, 10, 0.1)); }

.bb-zone-label {
  position: absolute;
  top: 6px;
  left: 10px;
  font-family: 'Courier New', monospace;
  font-size: 9px;
  letter-spacing: 2.5px;
  font-weight: bold;
  color: rgba(253, 240, 213, 0.6);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.bb-zone.zone-9v  .bb-zone-label { color: #ffbd85; }
.bb-zone.zone-5v  .bb-zone-label { color: #a8d8f0; }
.bb-zone.zone-3v  .bb-zone-label { color: #a8e8c0; }
.bb-zone.zone-dead .bb-zone-label { color: rgba(255, 100, 80, 0.7); }

/* ------------------------------------------------------------
   COPPER TRACES
   ------------------------------------------------------------ */
svg.bb-traces {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 2;
}
.bb-trace {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 3px rgba(199, 122, 58, 0.35));
}
/* Base trace colors per zone */
.bb-trace.trace-zone-9v  { stroke: #d78a4a; }
.bb-trace.trace-zone-5v  { stroke: #6cb8d8; }
.bb-trace.trace-zone-3v  { stroke: #7dd89a; }
.bb-trace.trace-zone-dead { stroke: #6a3a2a; stroke-dasharray: 4 3; }

/* Live = vivid, muted = darker, dead = dashed */
.bb-trace.trace-live  { opacity: 1; }
.bb-trace.trace-muted { opacity: 0.35; }
.bb-trace.trace-dead  { opacity: 0.55; stroke-dasharray: 4 3; }

/* ------------------------------------------------------------
   BATTERY BRICK
   ------------------------------------------------------------ */
.bb-battery {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #2b1810 0%, #1a0e08 100%);
  border: 2px solid #6a4020;
  border-radius: 4px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.05),
    0 4px 8px rgba(0, 0, 0, 0.5),
    0 0 0 1px var(--gold);
  color: var(--gold);
  overflow: hidden;
}

.bb-battery-terminals {
  position: absolute;
  top: -8px;
  left: 6px;
  right: 6px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.bb-term {
  background: linear-gradient(180deg, #f4d976 0%, var(--brass-dark) 100%);
  color: var(--ink);
  width: 14px;
  height: 14px;
  border-radius: 2px;
  text-align: center;
  font-size: 11px;
  font-weight: bold;
  line-height: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 2px rgba(0,0,0,0.5);
  font-family: Arial, sans-serif;
}

.bb-battery-body {
  flex: 1;
  padding: 14px 6px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.bb-battery-voltage {
  font-family: 'Didot', Georgia, serif;
  font-size: 22px;
  font-weight: bold;
  color: var(--gold);
  text-shadow: 0 0 6px rgba(255, 217, 125, 0.35);
  line-height: 1;
}
.bb-battery-cap {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  color: rgba(253, 240, 213, 0.7);
  letter-spacing: 1px;
}

.bb-battery-pills {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  margin-top: 4px;
}
.bb-bat-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  background: rgba(10, 6, 2, 0.6);
  border: 1px solid rgba(201, 169, 97, 0.35);
  border-radius: 2px;
  padding: 1px 4px;
  font-family: 'Courier New', monospace;
  font-size: 8px;
  color: rgba(253, 240, 213, 0.7);
}
.bb-bat-pill.locked { border-color: rgba(201, 169, 97, 0.7); }
.bb-bat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bb-bat-remove {
  background: transparent;
  border: none;
  color: rgba(255, 144, 144, 0.75);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.bb-bat-remove:hover { color: #ff6060; }
.bb-bat-lock { font-size: 8px; opacity: 0.6; }

.bb-battery-add {
  margin-top: auto;
  background: transparent;
  color: rgba(253, 240, 213, 0.7);
  border: 1px dashed rgba(253, 240, 213, 0.4);
  border-radius: 2px;
  padding: 2px 6px;
  font-family: 'Courier New', monospace;
  font-size: 9px;
  letter-spacing: 1px;
  cursor: pointer;
  width: 100%;
}
.bb-battery-add:hover {
  color: var(--gold);
  border-color: var(--gold);
}

/* Battery "lead wire" — the short copper stub poking out the right edge.
   Picks up visually where the first trace begins. */
.bb-battery-lead {
  position: absolute;
  top: 50%;
  right: -6px;
  width: 10px;
  height: 5px;
  background: linear-gradient(90deg, #9a6030, #c77a3a);
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 4px rgba(199, 122, 58, 0.5);
  transform: translateY(-50%);
}

/* ------------------------------------------------------------
   CHIPS
   ------------------------------------------------------------ */
.bb-chip {
  position: absolute;
  z-index: 3;
  box-sizing: border-box;
}

/* Pin legs (SVG) — sits behind chip body so legs tuck under edges */
.bb-chip-pins {
  position: absolute;
  top: 0;
  left: -10px;   /* matches LEG_L in JS */
  pointer-events: none;
  z-index: 1;
}
.bb-pin {
  fill: #b8b8b8;
  stroke: #606060;
  stroke-width: 0.5;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}

/* Empty chip — dashed outline inviting placement */
.bb-chip-empty {
  background: transparent;
  cursor: pointer;
  z-index: 3;
}
.bb-chip-empty-inner {
  position: absolute;
  inset: 0;
  border: 2px dashed rgba(253, 240, 213, 0.4);
  border-radius: 6px;
  background: rgba(10, 6, 2, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: rgba(253, 240, 213, 0.55);
  font-family: Georgia, serif;
  transition: all 0.15s;
}
.bb-chip-empty:hover .bb-chip-empty-inner {
  border-color: var(--gold);
  background: rgba(201, 169, 97, 0.15);
  color: var(--gold);
}
.bb-chip-plus {
  font-size: 32px;
  font-weight: normal;
  line-height: 1;
}
.bb-chip-empty-hint {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  letter-spacing: 1.5px;
  text-align: center;
  line-height: 1.3;
}

/* Filled chip — IC body */
.bb-chip-filled .bb-chip-body {
  position: absolute;
  inset: 0;
  background:
    /* tiny silkscreen speckle */
    radial-gradient(circle at 10% 20%, rgba(255, 255, 255, 0.03) 0.5px, transparent 1px),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.03) 0.5px, transparent 1px),
    linear-gradient(180deg, #2a2422 0%, #181412 100%);
  border: 1px solid #0a0a0a;
  border-radius: 4px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.06),
    inset 0 -3px 6px rgba(0, 0, 0, 0.6),
    0 4px 8px rgba(0, 0, 0, 0.55);
  color: rgba(253, 240, 213, 0.85);
  font-family: Georgia, serif;
  padding: 8px 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  z-index: 2;
}

/* Chip orientation notch (top-left dot like real ICs) */
.bb-chip-notch {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(253, 240, 213, 0.25);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.5);
}

/* Status LED — top right */
.bb-chip-led {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.bb-chip-led.led-ok {
  background: #5ed688;
  box-shadow: 0 0 5px rgba(94, 214, 136, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.bb-chip-led.led-bad {
  background: #e65050;
  box-shadow: 0 0 5px rgba(230, 80, 80, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  animation: ledBlink 1.2s infinite;
}
@keyframes ledBlink { 50% { opacity: 0.35; } }

/* Silkscreen part name (stencil-y white on dark chip) */
.bb-chip-silkscreen {
  margin-top: 8px;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 1.5px;
  font-weight: bold;
  color: rgba(253, 240, 213, 0.95);
  text-align: center;
  text-transform: uppercase;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bb-chip-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
}
.bb-chip-icon svg { max-width: 100%; max-height: 100%; }

.bb-chip-sub {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  color: rgba(253, 240, 213, 0.6);
  letter-spacing: 0.5px;
}

.bb-chip-tuning {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  color: var(--gold);
  background: rgba(201, 169, 97, 0.15);
  border: 1px dashed rgba(201, 169, 97, 0.5);
  padding: 1px 5px;
  border-radius: 2px;
  cursor: help;
}

.bb-chip-fault {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bad);
  color: #fff;
  font-family: 'Courier New', monospace;
  font-size: 8px;
  letter-spacing: 1.2px;
  padding: 1px 6px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.5);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}

/* Remove × (floats in top-right corner, revealed on hover) */
.bb-chip-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--ink);
  color: #fff;
  border: 1px solid var(--bad);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, transform 0.1s;
  z-index: 5;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
.bb-chip:hover .bb-chip-remove { opacity: 1; }
.bb-chip-remove:hover { background: var(--bad); transform: scale(1.1); }

.bb-chip-lock {
  position: absolute;
  top: 4px;
  right: 18px;
  font-size: 10px;
  opacity: 0.7;
  z-index: 5;
}

/* Converter chips get a subtle copper-tinged border to visually signal
   "this chip changes voltage." */
.bb-chip.bb-chip-converter .bb-chip-body {
  border-color: #8a5a2a;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.06),
    inset 0 -3px 6px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(199, 122, 58, 0.5),
    0 4px 8px rgba(0, 0, 0, 0.55);
}

/* Broken chip: red tint overlay */
.bb-chip.state-voltage_mismatch .bb-chip-body,
.bb-chip.state-no_power         .bb-chip-body,
.bb-chip.state-invalid_part     .bb-chip-body {
  background:
    linear-gradient(180deg, #3a1818 0%, #251010 100%);
  border-color: rgba(166, 48, 48, 0.7);
}

/* ------------------------------------------------------------
   CONTROLS OVERLAY (zoom, reset, add chain) — unchanged structure
   ------------------------------------------------------------ */
.bb-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
  align-items: center;
  background: linear-gradient(180deg, var(--brass) 0%, var(--brass-dark) 100%);
  border: 1px solid var(--brass-dark);
  border-radius: 3px;
  padding: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 3px 6px rgba(0, 0, 0, 0.3);
  z-index: 10;
}
.bb-ctrl-btn {
  background: rgba(28, 20, 12, 0.6);
  color: #fdf0d5;
  border: 1px solid var(--brass-dark);
  padding: 4px 10px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  font-weight: bold;
  border-radius: 2px;
  cursor: pointer;
  min-width: 26px;
  letter-spacing: 1px;
}
.bb-ctrl-btn:hover { background: rgba(28, 20, 12, 0.85); color: var(--gold); }
.bb-ctrl-btn:active { transform: translateY(1px); }
.bb-zoom-readout {
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  color: #fdf0d5;
  padding: 0 6px;
  min-width: 44px;
  text-align: center;
}
.bb-ctrl-btn.bb-reset {
  margin-left: 4px;
  border-left: 1px solid rgba(253, 240, 213, 0.3);
  padding-left: 8px;
}
.bb-ctrl-btn.bb-add-chain {
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  border-color: var(--green-dark);
  padding: 4px 8px;
  font-size: 10px;
}
.bb-ctrl-btn.bb-add-chain:hover {
  background: linear-gradient(180deg, #4e7a5a 0%, var(--green) 100%);
  color: #fff;
}

/* ------------------------------------------------------------
   HINT WATERMARK
   ------------------------------------------------------------ */
.bb-hint {
  position: absolute;
  bottom: 10px;
  left: 14px;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 1.2px;
  color: rgba(253, 240, 213, 0.35);
  pointer-events: none;
  z-index: 5;
  text-transform: uppercase;
}
.bb-hint span { color: rgba(253, 240, 213, 0.6); font-weight: bold; }

/* ------------------------------------------------------------
   EMPTY WORKSPACE
   ------------------------------------------------------------ */
.bb-canvas-empty {
  position: absolute;
  top: 100px;
  left: 100px;
  background: rgba(253, 240, 213, 0.92);
  border: 2px dashed var(--brass);
  border-radius: 6px;
  padding: 30px 40px;
  text-align: center;
  color: var(--ink);
  min-width: 340px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.bb-canvas-empty .bb-empty-title {
  font-family: Georgia, serif;
  font-size: 14px;
  letter-spacing: 4px;
  color: var(--brass-dark);
  margin-bottom: 10px;
}
.bb-canvas-empty .bb-empty-hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-light);
  margin-bottom: 14px;
}
.bb-first-chain-btn {
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  color: #fdf0d5;
  border: 1px solid var(--green-dark);
  padding: 8px 18px;
  font-family: Georgia, serif;
  font-size: 11px;
  letter-spacing: 2px;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.bb-first-chain-btn:hover { transform: translateY(-1px); }

/* ------------------------------------------------------------
   RESPONSIVE
   ------------------------------------------------------------ */
@media (max-width: 700px) {
  .bb-viewport { height: 440px; }
  .bb-controls { flex-wrap: wrap; max-width: 180px; }
}

/* Tuneable chip: hover state signals it's interactive */
.bb-chip.bb-chip-tuneable { cursor: pointer; }
.bb-chip.bb-chip-tuneable:hover .bb-chip-body {
  border-color: var(--gold);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.08),
    inset 0 -3px 6px rgba(0, 0, 0, 0.6),
    0 0 0 1px var(--gold),
    0 4px 12px rgba(255, 217, 125, 0.25);
}
.bb-chip-tuning.tuneable {
  cursor: pointer;
}
.bb-chip.bb-chip-tuneable:hover .bb-chip-tuning.tuneable {
  background: rgba(201, 169, 97, 0.35);
  color: #ffd97d;
}

/* ============================================================
   DAMPENED TUNING BADGE (breadboard chip)
   ============================================================ */
.bb-chip-tuning.dampened {
  background: linear-gradient(180deg, #e8dcf5 0%, #c8b8dc 100%);
  border-color: #4a3a6a;
  color: #4a3a6a;
  font-weight: bold;
}
.bb-tune-arrow {
  margin: 0 2px;
  color: var(--brass-dark);
  font-weight: normal;
  opacity: 0.8;
}

/* Damper category visual accent on chips (purple-ish) */
.bb-chip-filled[class*="zone-5v"] .bb-chip-silkscreen {
  /* default styling unchanged */
}
