.lab { width: min(1500px, 100% - 32px); margin-inline: auto; padding-block: 28px 40px; }
.lab-head { display: flex; justify-content: space-between; align-items: end; gap: 20px; flex-wrap: wrap; margin-bottom: 18px; }
.lab-head h1 { font-size: clamp(1.6rem, 3.4vw, 2.3rem); }
.lab-head .eyebrow { margin-bottom: 6px; }
.lab-tabs { display: inline-flex; border: 2px solid var(--ink); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.lab-tabs button { font: 700 0.98rem var(--display); padding: 10px 18px; border: 0; background: transparent; color: var(--ink); cursor: pointer; }
.lab-tabs button[aria-selected="true"] { background: var(--ink); color: var(--paper); box-shadow: inset 0 -3px 0 var(--yellow); }

.lab-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; background: var(--card); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
.lab-bar button, .lab-palette button, .exports button { font: 500 0.9rem var(--body); padding: 7px 12px; border: 1px solid #8e9ca3; border-radius: var(--radius); background: var(--card); color: var(--ink); cursor: pointer; }
.lab-bar button:hover, .lab-palette button:hover, .exports button:hover { border-color: var(--ink); background: var(--paper); }
.lab-bar select, .lab-bar input { width: auto; padding: 6px 8px; font-size: 0.9rem; }
.lab-bar input[type="number"] { width: 78px; }
.lab-bar label { display: inline-flex; align-items: center; gap: 6px; font: 600 0.78rem var(--body); color: var(--muted); }
.lab-bar .sep { width: 1px; align-self: stretch; background: var(--line); margin-inline: 4px; }

.lab-work { display: grid; grid-template-columns: 196px minmax(0, 1fr) 340px; border: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); background: var(--card); overflow: hidden; }
.lab-palette { display: flex; flex-direction: column; gap: 4px; padding: 10px; border-right: 1px solid var(--line); max-height: 660px; overflow-y: auto; }
.lab-palette button { display: flex; align-items: center; gap: 8px; text-align: left; padding: 3px 8px; font-size: 0.86rem; line-height: 1.2; }
.lab-palette button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.lab-palette svg { width: 46px; height: 25px; flex: none; }
.lab-palette hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

.lab-stage { position: relative; min-width: 0; display: flex; flex-direction: column; }
.lab-stage svg { display: block; width: 100%; height: 600px; touch-action: none; user-select: none; -webkit-user-select: none; }
.lab-stage svg[data-tool="select"] { cursor: grab; }
.lab-stage svg[data-tool="wire"], .lab-stage svg[data-tool="track"], .lab-stage svg[data-tool="place"] { cursor: crosshair; }
.lab-status { margin: 0; padding: 9px 14px; font: 500 0.86rem var(--mono); border-top: 1px solid var(--line); background: var(--paper); min-height: 2.6em; }
.lab-status.ok { color: var(--pin); }
.lab-status.idle { color: var(--muted); }
.lab-status.warn { background: var(--warn); color: #6b4a00; }
.lab-status.err { background: #ffe1dc; color: #9c1708; }

.lab-side { border-left: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 12px; max-height: 660px; overflow-y: auto; }
.lab-side > * { flex: none; }
.lab-side h3 { font-size: 1rem; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.lab-side h3 small { font: 600 0.82rem var(--body); color: var(--muted); }
.lab-props { display: grid; gap: 10px; min-height: 120px; align-content: start; }
.lab-props input, .lab-props select { padding: 7px 10px; font-size: 0.95rem; }
.lab-props input[type="range"] { padding: 0; accent-color: var(--accent); }
.lab-side .check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.lab-side .check input { width: 17px; height: 17px; accent-color: var(--pin); }
.muted { color: var(--muted); font-size: 0.92rem; margin: 0; }
.muted.small { font-size: 0.82rem; }
.readout { margin: 4px 0 0; border: 1px solid var(--line); border-radius: var(--radius); }
.readout div { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border-bottom: 1px solid #e3e9eb; }
.readout div:last-child { border-bottom: 0; }
.readout dt { color: var(--muted); font-size: 0.88rem; }
.readout dd { margin: 0; font: 500 0.92rem var(--mono); font-variant-numeric: tabular-nums; }
#sch-scope { width: 100%; height: auto; border-radius: var(--radius); display: block; }
.lab-side details { font-size: 0.88rem; color: var(--muted); }
.lab-side summary { cursor: pointer; font-weight: 500; color: var(--ink); }
.keys { margin: 8px 0 0; padding-left: 18px; }
kbd { font: 500 0.78rem var(--mono); border: 1px solid #8e9ca3; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--card); color: var(--ink); }

.sch { background: #fbfcfc; color: var(--ink); }
.sch .comp path, .sch .comp circle, .sch .comp rect { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sch .comp .body { fill: #fbfcfc; }
.sch .comp .fill { fill: currentColor; }
.sch .comp .thin { stroke-width: 1.4; }
.sch .comp .glow { stroke: none; filter: blur(5px); }
.sch .comp .hitbox, .lab-palette .hitbox { stroke: none; fill: transparent; }
.sch .comp.on { color: var(--accent-ink); }
.sch .comp.on .hitbox { fill: rgba(255, 91, 31, 0.08); stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 3; }
.sch .comp.ghost { opacity: 0.45; pointer-events: none; }
.sch .wire { stroke: var(--pin); stroke-width: 2.2; stroke-linecap: round; }
.sch .wire.on { stroke: var(--accent); stroke-width: 3.2; }
.sch .hit { stroke: transparent; stroke-width: 14; }
.sch .junction { fill: var(--pin); }
.sch .term { fill: #fbfcfc; stroke: var(--pin); stroke-width: 1.5; pointer-events: none; }
.sch .preview { fill: none; stroke: var(--pin); stroke-width: 2; stroke-dasharray: 6 5; pointer-events: none; }
.sch .cursor-dot { fill: none; stroke: var(--accent); stroke-width: 2; pointer-events: none; }
.sch text { font-family: var(--mono); pointer-events: none; }
.sch .name { font-size: 12px; font-weight: 500; fill: var(--ink); }
.sch .value { fill: var(--muted); font-weight: 400; }
.sch .live { font-size: 11.5px; fill: var(--accent-ink); font-weight: 500; }
.lab-palette .comp path, .lab-palette .comp circle, .lab-palette .comp rect { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.lab-palette .comp .fill { fill: currentColor; }
.lab-palette .comp .glow { display: none; }

.sch .pinlab { font-size: 9px; fill: var(--ink); stroke: none; }
.sch .pinlab.pwr { fill: var(--accent-ink); font-weight: 500; }
.sch .chip-title { font-size: 10.5px; font-weight: 600; fill: var(--ink); letter-spacing: 0.06em; }
.sch .comp .chip-led { stroke: var(--muted); stroke-width: 1; fill: #c9d3d7; }
.sch .comp .chip-led.running { fill: #22c55e; stroke: #15803d; }
.sch .comp .chip-led.error { fill: #ef4444; stroke: #991b1b; }
.lab-code { border: 1px solid var(--line); border-top: 0; background: var(--card); padding: 14px 16px 16px; border-radius: 0 0 var(--radius) var(--radius); }
.lab-code-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.lab-code-head strong { font-family: var(--display); font-size: 1.05rem; }
.lab-code-head .grow { flex: 1; }
.lab-code-head button, .lab-console-head button { font: 500 0.9rem var(--body); padding: 7px 12px; border: 1px solid #8e9ca3; border-radius: var(--radius); background: var(--card); color: var(--ink); cursor: pointer; }
.lab-code-head button:hover, .lab-console-head button:hover { border-color: var(--ink); background: var(--paper); }
.lab-code-head .primary { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 600; }
.lab-code-head .primary:hover { background: var(--accent); border-color: var(--accent); }
.code-state { font: 600 0.78rem var(--body); padding: 3px 8px; border-radius: 999px; background: var(--paper); color: var(--muted); }
.code-state[data-state="running"] { background: #dcfce7; color: #166534; }
.code-state[data-state="error"] { background: #ffe1dc; color: #9c1708; }
.lab-code-body { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 12px; }
#code-src { font: 400 0.9rem/1.55 var(--mono); min-height: 300px; resize: vertical; tab-size: 2; white-space: pre; overflow: auto; background: #fbfcfc; }
.lab-console { display: flex; flex-direction: column; background: var(--ink); border-radius: var(--radius); overflow: hidden; min-height: 300px; }
.lab-console-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 12px; font: 600 0.85rem var(--body); color: #a9c3b6; border-bottom: 1px solid rgba(255, 255, 255, 0.12); }
.lab-console-head button { font-size: 0.78rem; padding: 3px 8px; background: transparent; color: #e6edf0; border-color: rgba(255, 255, 255, 0.3); }
.lab-console-head button:hover { background: rgba(255, 255, 255, 0.12); border-color: #fff; }
#code-out { flex: 1; margin: 0; padding: 10px 12px; color: #e6edf0; font: 400 0.86rem/1.5 var(--mono); overflow: auto; max-height: 360px; white-space: pre-wrap; word-break: break-word; }
.lab-code .muted { margin-top: 10px; }
@media (max-width: 900px) { .lab-code-body { grid-template-columns: 1fr; } }

.pcb { background: #0f1e28; }
.pcb .hit { fill: none; stroke: transparent; }
.pcb .hitbox { fill: transparent; stroke: none; }
.pcb .hitbox.on { stroke: #ffffff; stroke-width: 0.15; stroke-dasharray: 0.6 0.4; fill: rgba(255, 255, 255, 0.06); }
.pcb text { pointer-events: none; }
.layers { display: grid; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0, 0, 0, 0.25); }
.sw.top { background: #e5532d; }
.sw.bottom { background: #3b8eea; }
.sw.silk { background: #f4f6f5; }
.drc { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 0.88rem; }
.drc li { border-left: 4px solid var(--line); background: var(--paper); border-radius: 0 var(--radius) var(--radius) 0; }
.drc li.ok { padding: 8px 10px; border-left-color: var(--pin); color: var(--pin); }
.drc li.error { border-left-color: #d62a17; }
.drc li.warn { border-left-color: #d49b00; }
.drc button { display: block; width: 100%; text-align: left; font: inherit; color: var(--ink); background: none; border: 0; padding: 8px 10px; cursor: pointer; }
.drc button:hover { background: #e2e8ea; }
.exports { display: flex; flex-wrap: wrap; gap: 8px; }
.lab-bar .primary { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 600; }
.lab-bar .primary:hover { background: var(--accent); border-color: var(--accent); }
.exports button:disabled { opacity: 0.45; cursor: default; }
.exports .primary { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 600; }
.exports .primary:hover { background: var(--accent); border-color: var(--accent); }

@media (max-width: 1100px) {
  .lab-work { grid-template-columns: 1fr; }
  .lab-palette { flex-direction: row; overflow-x: auto; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .lab-palette button { flex: none; }
  .lab-palette hr { width: 1px; height: auto; border: 0; border-left: 1px solid var(--line); margin: 0 2px; }
  .lab-stage svg { height: 460px; }
  .lab-side { border-left: 0; border-top: 1px solid var(--line); max-height: none; }
}
