.lab .workspace{min-height:calc(100vh - 80px)}
.lab aside{max-height:calc(100vh - 80px);overflow:auto;position:sticky;top:0}
.lab #search{width:100%;padding:10px;background:#08111e;border:1px solid var(--line);border-radius:8px;color:white;margin-bottom:12px}
.lab #canvas{height:max(590px,72vh)}
.lab .part{width:142px;height:126px;padding-top:6px}
.lab .part:hover{transform:translateY(-4px) scale(1.02);box-shadow:0 14px 28px rgba(0,0,0,.28),0 0 16px rgba(66,217,245,.18)}
.lab .terminal{width:30px;height:30px;top:44px;font-size:10px}
.lab .terminal.extra{top:auto;bottom:-15px}
.lab .terminal.extra:nth-of-type(4){left:18px}
.lab .terminal.extra:nth-of-type(5){right:18px}
.lab .part .symbol{height:26px;width:62px;color:#8fdbff;opacity:.9}
.lab .part strong{max-width:108px;text-align:center;line-height:1.2;font-size:12px}
.part .state{font-size:10px;color:var(--muted);text-align:center;padding:0 8px}
.lab .visual{position:relative;height:44px;width:86px;display:grid;place-items:center;margin-bottom:4px}
.lab .part.powered .state{color:#80f5ae}
.lab .part.blown{border-color:#ff7474;background:#2a1a24}
.lab .part.blown .device{filter:grayscale(.5)}
.lab .part.board{background:#23394b}
.lab .part button{touch-action:none}
.lab .part .toggle{min-height:26px}
.lab .wire-mode{border-color:var(--yellow)}
.lab .status{white-space:pre-line}
.lab .details{grid-template-columns:1fr 1.6fr 1fr}
.control{display:block;margin:8px 0;color:var(--text)}
.control input[type=range]{width:100%}
.control select, .control input, #selection select{background:#142337;color:white;padding:8px;border-radius:8px;border:1px solid var(--line)}
.lab .part.lit{background:color-mix(in srgb,var(--lamp,#eaff63) 25%,#142438);box-shadow:0 0 25px var(--lamp,#eaff63);animation:none}
.lab .part.lit .device.led i,
.lab .part.lit .device.led em,
.lab .part.lit .device.bulb i,
.lab .part.lit .device.bulb em{box-shadow:0 0 14px var(--lamp,#eaff63),0 0 26px var(--lamp,#eaff63)}
.lab .part.lit svg{color:var(--lamp,#eaff63)}
.charge{height:5px;width:75px;background:#263a50;border-radius:4px;overflow:hidden}
.charge i{display:block;height:100%;background:var(--cyan)}

/* Wires */
.wire.active{stroke:#6df7a9;stroke-dasharray:8 9;animation:flow .7s linear infinite}
.wire.active.reverse{animation-direction:reverse}
@keyframes flow{to{stroke-dashoffset:-34}}

/* Hover animation */
.palette-item{transition:transform .2s ease, box-shadow .2s ease, border-color .2s ease}
.palette-item:hover{transform:translateY(-4px) scale(1.02);box-shadow:0 12px 26px rgba(0,0,0,.22),0 0 16px rgba(66,217,245,.14);border-color:var(--cyan)}

/* Generic device visuals */
.device{position:relative;display:block;width:74px;height:34px}
.device i,.device em,.device b{position:absolute;display:block}

.device.battery{width:68px;height:28px;background:#1d3950;border:2px solid #79dfff;border-radius:8px}
.device.battery i{right:-6px;top:8px;width:6px;height:12px;background:#79dfff;border-radius:0 3px 3px 0}
.device.battery b{top:5px;left:12px;font:700 13px/1 Poppins;color:#ffd95e}
.device.battery b.minus{left:auto;right:12px;color:#9be8ff}

.device.led{width:42px;height:34px}
.device.led i{left:9px;top:2px;width:24px;height:18px;background:var(--lamp,#eaff63);border-radius:14px 14px 6px 6px;border:2px solid rgba(255,255,255,.35);opacity:calc(.35 + var(--brightness,.4) * .6)}
.device.led em{left:19px;top:20px;width:2px;height:12px;background:#c4d8ea;box-shadow:8px 0 0 #c4d8ea}
.device.led.rgb i{background:linear-gradient(90deg,#ff6060,#ffea55,#71ff82,#6b8fff,#dd78ff)}

.device.resistor{width:70px;height:22px}
.device.resistor i{left:7px;top:6px;width:56px;height:10px;background:linear-gradient(90deg,#ffe18a,#cf9657,#ffe18a);border-radius:6px;box-shadow:0 0 0 2px #6d4d2f inset}
.device.resistor:before,.device.resistor:after{content:'';position:absolute;top:10px;width:12px;height:2px;background:#b1d8ef}
.device.resistor:before{left:-5px}.device.resistor:after{right:-5px}

.device.switcher{width:66px;height:26px}
.device.switcher i{left:6px;right:6px;top:12px;height:3px;background:#9edfff}
.device.switcher em{left:24px;top:2px;width:3px;height:20px;background:var(--yellow);transform:rotate(-36deg);transform-origin:bottom center;border-radius:2px}
.part.powered .device.switcher em{transform:rotate(0deg)}

.device.buzzer{width:48px;height:32px}
.device.buzzer i{left:6px;top:8px;width:18px;height:16px;background:#20354a;border-radius:6px 0 0 6px;border:2px solid #a6e8ff}
.device.buzzer em{right:4px;top:6px;width:18px;height:18px;border:3px solid transparent;border-right-color:#7fe8ff;border-radius:50%}
.part.powered .device.buzzer em{animation:pulseArc .9s ease-in-out infinite}
@keyframes pulseArc{50%{transform:scale(1.08);opacity:.6}}

.device.motor{width:68px;height:32px}
.device.motor i{left:5px;top:5px;width:38px;height:22px;background:linear-gradient(180deg,#3d7ca0,#23455e);border-radius:9px 12px 12px 9px;border:2px solid #86e6ff}
.device.motor i:after{content:'';position:absolute;right:-8px;top:7px;width:8px;height:8px;background:#d7f4ff;border-radius:50%}
.device.motor .rotor{position:absolute;right:0;top:3px;width:26px;height:26px;border:3px solid var(--cyan);border-radius:50%}
.device.motor .rotor:before,.device.motor .rotor:after{content:'';position:absolute;left:9px;top:2px;width:3px;height:18px;background:var(--cyan);border-radius:3px}
.device.motor .rotor:after{transform:rotate(90deg)}
.part.powered .device.motor .rotor{animation:spin var(--speed,.65s) linear infinite}

.device.fan{width:50px;height:50px}
.device.fan i{left:18px;top:18px;width:14px;height:14px;background:#dff8ff;border:3px solid #59dfff;border-radius:50%;z-index:2}
.device.fan .fan-blade{position:absolute;left:21px;top:4px;width:8px;height:22px;background:linear-gradient(180deg,#82f1ff,#215a74);border-radius:8px 8px 50% 50%;transform-origin:50% 21px}
.device.fan .b1{transform:rotate(0deg)}
.device.fan .b2{transform:rotate(120deg)}
.device.fan .b3{transform:rotate(240deg)}
.part.powered .device.fan{animation:spin var(--speed,.75s) linear infinite}

.device.bulb{width:40px;height:42px}
.device.bulb i{left:8px;top:2px;width:24px;height:24px;background:radial-gradient(circle at 40% 30%,#fffdd5,var(--lamp,#f6eb88) 60%,#d0b83d);border-radius:50%;opacity:calc(.3 + var(--brightness,.4) * .7)}
.device.bulb em{left:14px;top:24px;width:12px;height:12px;background:#7b93a7;border-radius:0 0 6px 6px;box-shadow:0 0 0 2px #4f677c inset}

.device.push{width:54px;height:34px}
.device.push i{left:9px;right:9px;bottom:6px;height:12px;background:#25445d;border-radius:7px;border:2px solid #82dbff}
.device.push em{left:17px;top:2px;width:20px;height:16px;background:var(--yellow);border-radius:8px 8px 5px 5px;transition:transform .12s ease}
.device.push.pressed em{transform:translateY(7px)}

.device.knob{width:44px;height:44px}
.device.knob i{inset:0;border-radius:50%;background:radial-gradient(circle at 35% 35%,#4d6d85,#16283a);border:2px solid #7fe1ff}
.device.knob em{left:50%;top:8px;width:4px;height:16px;background:var(--yellow);border-radius:4px;transform-origin:50% 14px;transition:transform .18s ease}

.device.capacitor{width:60px;height:34px}
.device.capacitor i{top:5px;width:4px;height:22px;background:#a6e3ff}
.device.capacitor i:first-child{left:22px}.device.capacitor i:nth-child(2){left:34px}
.device.capacitor em{left:12px;top:13px;width:12px;height:2px;background:#d7efff;box-shadow:24px 0 0 #d7efff}

.device.diode{width:62px;height:22px}
.device.diode i{left:10px;top:7px;width:26px;height:10px;background:linear-gradient(90deg,#70d7ff,#70d7ff);clip-path:polygon(0 0,100% 50%,0 100%)}
.device.diode em{left:39px;top:5px;width:4px;height:14px;background:var(--yellow)}
.device.diode:before,.device.diode:after{content:'';position:absolute;top:11px;width:10px;height:2px;background:#b5dff2}
.device.diode:before{left:0}.device.diode:after{right:0}

.device.transistor{width:52px;height:38px}
.device.transistor i{left:16px;top:4px;width:20px;height:20px;border-radius:50%;border:2px solid #82dcff}
.device.transistor em,.device.transistor b{background:#b9eaff}
.device.transistor em{left:8px;top:20px;width:2px;height:16px;box-shadow:16px 0 0 #b9eaff,32px 0 0 #b9eaff}
.device.transistor b{left:24px;top:9px;width:14px;height:2px;transform:rotate(-35deg)}

.device.relay{width:66px;height:34px}
.device.relay i{left:6px;top:7px;width:22px;height:20px;border:2px solid #7de0ff;border-radius:6px}
.device.relay em{right:5px;top:14px;width:26px;height:3px;background:#b6edff;transform:rotate(-20deg);transform-origin:left center}
.part.powered .device.relay em{transform:rotate(0deg)}

.device.ldr,.device.pir,.device.ir{width:54px;height:34px}
.device.ldr i,.device.pir i,.device.ir i{left:12px;top:7px;width:30px;height:20px;background:#1d3145;border:2px solid #80deff;border-radius:10px}
.device.ldr em{left:18px;top:11px;width:18px;height:12px;border-radius:8px;background:radial-gradient(circle at 50% 50%,#fcef7d, #593 45%, #0b1320 70%);opacity:.75}
.device.pir em{left:18px;top:9px;width:18px;height:18px;border-radius:50%;background:radial-gradient(circle,#e7f7ff 20%,#7dd9ff 22%,#15293c 62%)}
.device.ir em{left:37px;top:8px;width:12px;height:18px;border-right:3px solid #ff7a7a;border-radius:50%}
.device.ir.active em,.device.pir.active em{animation:pulseArc .8s infinite}
.device.ldr{filter:saturate(1.1);opacity:calc(.7 + (var(--sensor,50%)/100) * .3)}

.device.temp{width:26px;height:44px}
.device.temp i{left:10px;top:2px;width:6px;height:30px;background:#2f4961;border-radius:6px;border:2px solid #86defc}
.device.temp i:after{content:'';position:absolute;left:-6px;bottom:-10px;width:18px;height:18px;background:#1e3347;border:2px solid #86defc;border-radius:50%}
.device.temp em{left:12px;bottom:11px;width:2px;height:12px;background:#ff6e6e;border-radius:2px;box-shadow:0 0 8px rgba(255,110,110,.7)}

.device.touch{width:38px;height:44px}
.device.touch i{left:10px;top:2px;width:18px;height:28px;border-radius:12px 12px 8px 8px;background:linear-gradient(180deg,#c6dff1,#5f7d95);box-shadow:-8px 8px 0 -5px #c6dff1,8px 10px 0 -5px #c6dff1}
.device.touch.active i{box-shadow:-8px 8px 0 -5px #c6dff1,8px 10px 0 -5px #c6dff1,0 0 16px rgba(248,219,84,.7)}

.device.soil{width:44px;height:44px}
.device.soil i{left:10px;bottom:4px;width:4px;height:26px;background:#a7d6ef;box-shadow:12px 0 0 #a7d6ef}
.device.soil em{left:7px;bottom:4px;width:22px;height:12px;background:linear-gradient(180deg,#6a4528,#3a2415);border-radius:10px 10px 2px 2px;opacity:.95}

.device.solar{width:68px;height:40px}
.device.solar i{left:10px;top:10px;width:34px;height:22px;background:linear-gradient(180deg,#2f84ad,#174563);border:2px solid #82e0ff;border-radius:3px;box-shadow:inset 0 0 0 1px rgba(255,255,255,.16)}
.device.solar i:after{content:'';position:absolute;inset:0;background:linear-gradient(90deg,transparent 24%,rgba(255,255,255,.25) 25%,transparent 26%,transparent 49%,rgba(255,255,255,.25) 50%,transparent 51%,transparent 74%,rgba(255,255,255,.25) 75%,transparent 76%),linear-gradient(transparent 48%,rgba(255,255,255,.25) 49%,transparent 50%)}
.device.solar em{right:2px;top:0;width:16px;height:16px;background:radial-gradient(circle,#ffed6f,#f8bd33);border-radius:50%;box-shadow:0 0 calc(4px + var(--sun,80%)/9) rgba(248,219,84,.85)}

.device.fuse{width:58px;height:22px}
.device.fuse i{left:9px;top:5px;width:40px;height:12px;background:rgba(200,245,255,.25);border:2px solid #a9ebff;border-radius:10px}
.device.fuse i:after{content:'';position:absolute;left:10px;top:3px;width:16px;height:2px;background:var(--yellow);transform:rotate(18deg)}
.part.blown .device.fuse i:after{background:#ff6f6f;transform:rotate(0deg) scaleX(.4)}

.device.breadboard{width:74px;height:34px;background:#f5f7fb;border-radius:8px;box-shadow:inset 0 0 0 2px #cbd5e2}
.device.breadboard i{inset:6px;background:radial-gradient(circle,#9ab4c8 1px,transparent 1.5px);background-size:10px 10px}

.device.servo{width:66px;height:40px}
.device.servo i{left:6px;top:10px;width:28px;height:20px;background:linear-gradient(180deg,#2d6e8d,#16364c);border-radius:6px;border:2px solid #82e1ff}
.device.servo .servo-arm{position:absolute;left:31px;top:18px;width:24px;height:4px;background:var(--yellow);border-radius:4px;transform-origin:left center;transition:transform .2s ease}
.part.powered .device.servo .servo-arm{box-shadow:0 0 8px rgba(248,219,84,.55)}

@keyframes spin{to{transform:rotate(360deg)}}

/* General hover for home page cards too */
.cards article{transition:transform .22s ease,box-shadow .22s ease,border-color .22s ease}
.cards article:hover{transform:translateY(-5px);box-shadow:0 14px 28px rgba(0,0,0,.2),0 0 14px rgba(66,217,245,.1);border-color:#3d5e78}

@media(max-width:800px){
  .lab aside{position:static;max-height:240px;overflow:auto}
  .lab #palette{grid-template-columns:repeat(3,minmax(0,1fr))}
  .lab .details{grid-template-columns:1fr}
  .lab #canvas{height:620px}
  .lab .part{width:122px;height:126px}
}
@media(max-width:450px){
  .lab .visual{width:76px}
  .lab .part strong{max-width:98px;font-size:11px}
}

/* Stable animation layer: terminals never move on hover; only artwork lifts. */
.lab .part,.lab .part:hover{transform:none;transition:box-shadow .2s,border-color .2s,background .2s}
.lab .visual{height:58px;display:flex;flex-direction:column;justify-content:center;align-items:center;gap:2px;transition:filter .2s;flex-shrink:0}
.lab .visual .device{flex-shrink:0;zoom:.78}
.lab .visual .symbol{height:18px;flex-shrink:0}
.lab .part:hover .visual{filter:drop-shadow(0 0 5px #42d9f555)}
.lab .part:hover{border-color:#42d9f5}
.wire-base,.wire-flow,.wire-hit{fill:none;stroke-linecap:round;stroke-linejoin:round}
.wire-base{stroke:#42bddd;stroke-width:3;pointer-events:none}
.wire-flow{stroke:#aaffd1;stroke-width:4;stroke-dasharray:2 14;opacity:0;pointer-events:none}
.flowing .wire-base{stroke:#268c74}
.flowing .wire-flow{opacity:1;animation:electron-flow .65s linear infinite}
.flowing.reverse .wire-flow{animation-direction:reverse}
.chosen .wire-base{stroke:#f8db54;stroke-width:5}
@keyframes electron-flow{from{stroke-dashoffset:0}to{stroke-dashoffset:-16}}
.lab .part .device.led i,.lab .part .device.bulb i{opacity:.45;transition:opacity .2s,background .2s,box-shadow .2s}
.lab .part.lit .device.led i,.lab .part.lit .device.bulb i{opacity:calc(.45 + var(--brightness)*.55);background:var(--lamp);box-shadow:0 0 14px var(--lamp)}
.lab .part.lit{box-shadow:0 0 18px color-mix(in srgb,var(--lamp) 60%,transparent)}
.part.closed .device.switcher em{transform:rotate(0deg)}
.device.ldr{opacity:calc(.7 + var(--sensor,.5)*.3)}
.device.solar em{box-shadow:0 0 calc(4px + var(--sun,.8)*12px) #f8db54}
.part.powered .device.fan,.part.powered .device.motor .rotor{animation-timing-function:linear;will-change:transform}

.learning-tools,.assistant-panel{border:1px solid var(--line);border-radius:12px;background:var(--panel);padding:12px;margin-bottom:12px}.learning-tools summary{cursor:pointer;color:var(--cyan);font-weight:700}.tool-grid{display:flex;flex-wrap:wrap;gap:8px;align-items:end;margin-top:12px}.tool-grid label{display:grid;font-size:12px;color:var(--muted);gap:4px}.tool-grid select{background:#142337;color:var(--text);border:1px solid var(--line);padding:10px;border-radius:8px;min-height:44px}.tool-grid .btn{font-size:12px}.learning-tools p,.assistant-panel p{margin:8px 0;font-size:13px}.assistant-panel{margin-top:12px}.assistant-panel h3{color:var(--cyan);margin:0}#guidePanel{border-top:1px solid var(--line);padding-top:10px}.learning-tools button:disabled{opacity:.4;cursor:default}

/* Phone lab: workspace first, palette opens as a touch-friendly bottom sheet. */
.mobile-only{display:none}.canvas-scroll{min-width:0}.drawer-backdrop{display:none}
@media(max-width:800px){
 .lab{font-size:14px}.lab header{position:sticky;top:0;z-index:20;gap:8px;padding:10px 12px;background:#0b1524f5;backdrop-filter:blur(10px)}
 .lab header .brand{font-size:18px}.lab header>strong{font-size:11px;color:var(--muted)}
 .lab header .actions{width:100%;display:grid;grid-template-columns:1.15fr 1fr 1fr;gap:6px}
 .lab header .actions .btn{font-size:12px;padding:8px 4px;min-height:44px;text-align:center}
 .lab .workspace{display:block;min-height:0}.lab .workarea{padding:10px;min-width:0}
 .mobile-only{display:block}.lab .mobile-tools{display:flex;gap:8px;grid-column:1/-1}.mobile-tools .btn{flex:1;font-size:13px}
 .lab .toolbar{display:grid;grid-template-columns:1fr;gap:8px;margin-bottom:10px}
 .lab .toolbar .actions{display:flex;gap:6px}.lab .toolbar .actions .btn{flex:1;min-height:40px;font-size:12px;padding:6px}
 #challenge{font-size:12px;color:var(--muted)}
 .lab aside{display:none;position:fixed;inset:auto 0 0;z-index:42;max-height:80vh;max-height:80dvh;overflow:auto;border:1px solid #3c5873;border-radius:22px 22px 0 0;padding:18px 14px max(18px,env(safe-area-inset-bottom));box-shadow:0 -16px 60px #0009;overscroll-behavior:contain;background:#0e1d2e}
 .lab aside.drawer-open{display:block}.drawer-backdrop:not([hidden]){display:block;position:fixed;inset:0;z-index:41;background:#000a;touch-action:none}
 .drawer-active{overflow:hidden}#closePalette{float:right;min-height:40px;font-size:12px;padding:8px 12px}.lab aside h2{margin-bottom:4px}.lab aside p{margin:8px 0}
 .lab #search{font-size:16px;min-height:46px}.lab #palette{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
 .lab .palette-item{min-height:76px;flex-direction:row;text-align:left;padding:9px;gap:8px;overflow-wrap:anywhere;font-size:12px;touch-action:pan-y}
 .lab .palette-item svg{width:38px;height:30px}.lab .palette-item small{display:none}
 .lab .learning-tools{padding:10px;margin-bottom:8px}.lab .learning-tools summary{min-height:30px;display:list-item;padding:5px 0;font-size:13px}
 .lab .tool-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px}.lab .tool-grid label{grid-column:1/-1;min-width:0}.lab .tool-grid select{width:100%;font-size:16px}.lab .tool-grid .btn{padding:8px 5px;min-height:44px;text-align:center}
 .board-hint{font-size:11px;line-height:1.5;color:var(--muted);padding:6px 2px 9px}
 .canvas-scroll{width:100%;overflow-x:auto;border-radius:12px;overscroll-behavior-x:contain;scroll-margin-top:125px}
 .lab #canvas{width:100%;min-width:320px;height:420px;touch-action:pan-x pan-y;background-size:18px 18px}
 .lab .part{width:106px;height:126px;padding:4px 2px;touch-action:none;box-shadow:0 4px 12px #0004}
 .lab .part strong{max-width:88px;font-size:11px}.lab .part .state{font-size:10px;padding:0 3px}.lab .visual{width:70px;height:52px}
 .lab .terminal{width:38px;height:38px;top:43px;font-size:12px;touch-action:none;z-index:4}.lab .terminal.left{left:-19px}.lab .terminal.right{right:-19px}.lab .terminal.extra{bottom:-19px;top:auto}
 .lab .part .toggle{min-height:32px;min-width:54px;margin-top:2px}.lab .status{font-size:13px;margin-top:8px;padding:12px}
 .lab .details{display:flex;flex-direction:column;gap:8px}.lab #selectionCard{order:-1;scroll-margin-top:125px}.lab .details article{padding:14px}.lab .details p{font-size:13px;line-height:1.55;margin:6px 0}
 .lab .control{margin:12px 0}.lab .control input[type=range]{height:44px;padding:0;touch-action:pan-y;display:block}.lab #selection button,.lab #selection select{min-height:44px;font-size:16px}
 .lab .assistant-panel{margin:10px 0}.lab .assistant-panel p{font-size:13px}
}
@media(hover:none){.lab .part:hover .visual{filter:none}.lab .palette-item:hover{transform:none;box-shadow:none}}
