/* =========================================================
   КОНСТРУКТОР ЕЛЕКТРИЧНОГО КОЛА
   Власні токени: SVG деталей написаний під них.
   Панель деталей ліворуч вузька — поле є героєм сторінки.
   ========================================================= */
#circuit{
  --panel:var(--card); --wire:#3f444d; --accent:var(--primary); --gold:#f6a609; --cb-cell:#e3ebfb;
  max-width:1240px; margin:0 auto; user-select:none; -webkit-user-select:none;
}
#circuit button{
  font:inherit;font-weight:600;cursor:pointer;border:2px solid transparent;border-radius:11px;
  padding:9px 15px;background:var(--accent);color:#fff;min-height:42px;
}
#circuit button.sec{background:var(--panel);color:var(--ink);border-color:var(--line)}
#circuit button.warn{background:var(--gold);color:#3d2a00}
#circuit button:disabled{opacity:.45;cursor:default}
#circuit button:active{transform:translateY(1px)}
#circuit button.rb{background:var(--panel);color:var(--ink);border-color:var(--line)}
#circuit button.rb.on{background:var(--accent);color:#fff;border-color:var(--accent)}

/* ---- верхня смуга: підказка, швидкість, очистити ---- */
.cb-bar{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin:0 0 10px}
.cb-hint{flex:1;min-width:260px;color:var(--muted);font-size:15px;line-height:1.4}
.cb-hint b{color:var(--ink)}
.cb-bar .speed{display:flex;align-items:center;gap:8px;color:var(--muted);font-size:15px}
.cb-bar input[type=range]{width:120px;padding:0;border:none}
.cb-hist{display:flex;gap:4px}
#circuit button.icon{padding:6px 10px;display:grid;place-items:center}
#circuit button.icon svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round}

/* ---- панель деталей + поле ---- */
.cb-main{display:grid;grid-template-columns:128px 1fr;gap:10px;align-items:start}
.cb-pal{
  background:var(--panel);border:1px solid var(--line);border-radius:16px;padding:8px;box-shadow:var(--shadow);
  display:flex;flex-direction:column;gap:6px;
}
.cb-pal-t{font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:.5px;color:var(--muted);text-align:center}
#circuit button.cb-item{
  background:var(--panel);color:var(--ink);border:1.5px solid var(--line);padding:4px;min-height:0;
  display:flex;flex-direction:column;align-items:center;gap:0;cursor:grab;touch-action:none;
}
#circuit button.cb-item:hover:not(:disabled){border-color:var(--accent);background:var(--primary-l)}
.cb-item svg{width:100%;height:58px;display:block;pointer-events:none}
.cb-item span{font-size:13px;pointer-events:none}
@media(max-width:760px){
  .cb-main{grid-template-columns:1fr}
  .cb-pal{flex-direction:row;flex-wrap:wrap}
  #circuit button.cb-item{width:92px}
  .cb-pal-t{width:100%}
}

.cb-stage{position:relative;background:#fff;border:1px solid var(--line);border-radius:16px;padding:6px;box-shadow:var(--shadow);min-width:0}
.cb-stage svg{display:block;width:100%;height:auto;touch-action:none}

/* ---- деталі, дроти, контакти ---- */
.cb-wire polyline{fill:none;stroke-linecap:round;stroke-linejoin:round}
.cb-wire .core{stroke:var(--wire);stroke-width:12}
.cb-wire .halo{stroke:transparent;stroke-width:22}
.cb-wire .hitw{stroke:transparent;stroke-width:28;cursor:pointer}
.cb-wire:hover .halo{stroke:rgba(116,192,252,.35)}
.cb-wire.sel .halo{stroke:#74c0fc}
.cb-wire.drop .halo{stroke:#8ce99a}
.cb-wire.drop .core{stroke:#2f9e44}
.cb-wend{fill:#4dabf7;stroke:#fff;stroke-width:3;pointer-events:none}
.cb-marq[hidden]{display:none}
.cb-marq{fill:rgba(77,171,247,.08);stroke:#4dabf7;stroke-width:2;stroke-dasharray:8 6;pointer-events:none}
.cb-part{cursor:move}
.cb-part.press{cursor:pointer}
.cb-part.press:hover .hit{fill:rgba(77,171,247,.12)}
/* світіння, дим, хвилі, зарядне — лише картинка: невидимі, вони не мають перехоплювати клацання */
.cb-part :is(.glow,.glowOut,.smoke,.waves,.blocked,.crack,.bat-heat,.bat-leak,.charger){pointer-events:none}
.cb-part .selbox{pointer-events:none;fill:rgba(77,171,247,.08);stroke:#4dabf7;stroke-width:3;stroke-dasharray:8 6}

.cb-term{fill:#fff;stroke:var(--accent);stroke-width:3;cursor:crosshair;transition:r .12s}
.cb-term:hover,.cb-term.hot{r:13px;fill:var(--accent)}

.el{fill:#4dabf7;stroke:#1864ab;stroke-width:2;pointer-events:none}
.elm{fill:#0b3d66;pointer-events:none}
#cbDots,#cbLabels,#cbRubber{pointer-events:none}

.cb-lab{font-size:17px;fill:var(--muted)}
.cb-lab.strong{font-weight:700;font-size:18px}
.cb-lab.word{font-weight:700;fill:#e03131}
.cb-lab.pol{font-weight:700;font-size:20px}
.cb-lab.pol.plus{fill:#ff8787}
.cb-lab.pol.minus{fill:#74c0fc}

/* ---- контекстне вікно властивостей (подвійний клік) ---- */
.cb-pop{
  position:absolute;z-index:5;width:max-content;max-width:min(360px,calc(100% - 12px));
  background:var(--card);border:1px solid var(--line);border-radius:14px;padding:10px 12px 12px;
  box-shadow:0 12px 36px rgba(30,30,80,.22);
}
.cb-pop[hidden]{display:none}
.cb-pop-h{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:6px;font-size:17px}
#circuit .cb-pop button.x{background:none;color:var(--muted);min-height:0;padding:2px 8px;font-size:16px}
.cb-pop-row{margin:8px 0}
.cb-pop-row>span{display:block;font-size:13px;font-weight:700;color:var(--muted);margin-bottom:4px}
.cb-seg{display:flex;flex-wrap:wrap;gap:5px}
#circuit .cb-pop button{min-height:36px;padding:6px 11px;font-size:14px}
.cb-pop-acts{display:flex;flex-wrap:wrap;gap:6px;margin-top:10px;padding-top:10px;border-top:1px solid var(--line)}

/* ---- вигляд «Макетка» ---- */
.cb-view{flex-wrap:nowrap}
#cbHover{pointer-events:none}
.bb-ring{fill:none;stroke-width:2.5;pointer-events:none}
.bb-ring.hover{stroke:#4dabf7}
.bb-ring.ok{stroke:#2f9e44}
.bb-ring.bad{stroke:#e03131}
.cb-part.bad{opacity:.5}
/* модуль живлення MB102 і кабель від павербанка */
.bb-cable{stroke:#868e96;stroke-width:16;stroke-linecap:round;fill:none}
.bb-plug{fill:#ced4da;stroke:#868e96;stroke-width:1.5}
.bb-pcb{fill:#1f2327;stroke:#0b0d0f;stroke-width:2}
.bb-usb{fill:#dee2e6;stroke:#868e96;stroke-width:2}
.bb-usb-in{fill:#495057}
.bb-dc{fill:#101214;stroke:#343a40;stroke-width:2}
.bb-dc-in{fill:#343a40;stroke:#868e96;stroke-width:2}
.bb-btn{cursor:pointer}
.bb-btn-base{fill:#343a40;stroke:#0b0d0f;stroke-width:1.5}
.bb-btn-cap{fill:#f1f3f5;stroke:#adb5bd;stroke-width:1.5}
.bb-btn:hover .bb-btn-cap{fill:#fff;stroke:#4dabf7}
.bb-led{fill:#1e4d2b;stroke:#0b2e13;stroke-width:1.5}
.bb-led.on{fill:#8ce99a;stroke:#2f9e44}
.bb-glow{fill:#69db7c;opacity:.45;pointer-events:none}
.bb-mtext{fill:#adb5bd;font-size:12px;font-weight:700;letter-spacing:1px;text-anchor:middle}
.bb-jmp{fill:#fcc419;stroke:#b08900;stroke-width:1.5}
.bb-mv{fill:#fcc419;font-size:10px;font-weight:700;text-anchor:middle}
.bb-pin{fill:#e9c46a;stroke:#9c7a1c;stroke-width:1}
.bb-trace{fill:none;stroke:#c08a4a;stroke-width:2.5;stroke-linejoin:round;pointer-events:none}
.bb-body{fill:#f4f4f1;stroke:#d6d8dc;stroke-width:2}
.bb-groove{fill:#e4e6e9}
.bb-seam{stroke:#e2e4e8;stroke-width:1.5}
.bb-line{stroke-width:2}
.bb-line.plus{stroke:#f06595}
.bb-line.minus{stroke:#4dabf7}
.bb-sign{font-size:16px;font-weight:700;text-anchor:middle}
.bb-sign.plus{fill:#f06595}
.bb-sign.minus{fill:#4dabf7}
.bb-holes rect{fill:#5c636d}
.bb-num{font-size:9px;fill:#9aa1ab;text-anchor:middle}
.bb-strip{fill:rgba(250,176,5,.2);stroke:rgba(230,150,0,.55);stroke-width:1.2}
.bb-jump polyline{fill:none;stroke-linecap:round;stroke-linejoin:round}
.bb-jump{cursor:grab}
.bb-jump .hit{stroke:transparent;stroke-width:14}
.bb-jump .halo{stroke:transparent;stroke-width:11}
.bb-jump.sel .halo{stroke:#74c0fc}
.bb-jump .edge{stroke:rgba(0,0,0,.25);stroke-width:6.5}
.bb-jump .core{stroke-width:4.5}
.bb-jump .plug{fill:#adb5bd;stroke:#495057;stroke-width:1}

/* ---- повідомлення ---- */
#circuit .msg{
  margin:8px 0 0;padding:12px 14px;border-radius:12px;background:var(--panel);border:1px solid var(--line);
  font-size:16px;min-height:56px;display:flex;align-items:center;
}

.cb-teacher{margin-top:14px;background:var(--card);border:1px solid var(--line);border-radius:12px;padding:10px 14px}
.cb-teacher summary{cursor:pointer;font-weight:700}
.cb-teacher p{color:var(--muted);line-height:1.5}

@media (prefers-reduced-motion: reduce){ .cb-term{transition:none} }
