/* Bench layout: lesson notes on the left like a lab sheet; the board, its tools and the
   instruments (inspector, meter, scope) fill the right. */
:root {
  --bg: #e7ece9; --panel: #f7f9f8; --ink: #16201c; --muted: #56655f; --line: #cdd7d2; --accent: #a95a1c;
  --ok: #2b8549; --warn: #a86d12; --bad: #c0352a;
  --board: #f3f1ea; --board-edge: #d4cfc0; --board-ink: #8d897a; --hole: #474c49; --chan: #e3e0d6;
  --rail-p: #d0453a; --rail-n: #2f5fb3;
  --probe-red: #d9342b; --probe-black: #2a2f2d;
  --scope-bg: #102019; --scope-grid: #24412f; --scope-ink: #9fc3ae; --scope-trace: #ffb23e;
  --code-bg: #eef2f0;
  --display: "Saira Semi Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111715; --panel: #18201d; --ink: #e2eae6; --muted: #93a49d; --line: #2b3732; --accent: #e3904f;
    --ok: #5cc183; --warn: #e2aa4c; --bad: #f0695d;
    --board: #e8e5da; --board-edge: #a9a495; --chan: #d6d2c6;
    --probe-black: #c9d2ce; --code-bg: #121916;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111715; --panel: #18201d; --ink: #e2eae6; --muted: #93a49d; --line: #2b3732; --accent: #e3904f;
  --ok: #5cc183; --warn: #e2aa4c; --bad: #f0695d;
  --board: #e8e5da; --board-edge: #a9a495; --chan: #d6d2c6;
  --probe-black: #c9d2ce; --code-bg: #121916;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15.5px; line-height: 1.5; }
code { font-family: var(--mono); font-size: .9em; }

.app { max-width: 1520px; margin: 0 auto; padding-block: 18px 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; }
.brand { margin-right: auto; }
.eyebrow { font-family: var(--mono); font-size: 11.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); }
h1 { font-family: var(--display); font-weight: 600; font-size: clamp(28px, 3.6vw, 40px); line-height: 1.05; margin: 0; }
.tagline { margin: 6px 0 0; color: var(--muted); font-size: 14.5px; max-width: 60ch; }
.simctl { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

button { font: inherit; font-size: 14px; font-weight: 600; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 12px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; }
button.small { font-size: 13px; padding: 4px 9px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
button:focus-visible, select:focus-visible, input:focus-visible, .tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; border-radius: 0; background: transparent; font-weight: 500; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 16%, var(--panel)); color: var(--accent); font-weight: 600; }
.seg.small button { font-size: 12.5px; padding: 3px 9px; }
.modes button { padding: 8px 16px; }

.layout { display: grid; grid-template-columns: minmax(270px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }

/* lesson sheet */
.lesson { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; display: grid; gap: 10px; min-width: 0; }
@media (min-width: 1101px) { .lesson { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; } }
.lesson-nav { display: grid; gap: 6px; }
.lesson-nav select { width: 100%; }
.lesson-title { font-family: var(--display); font-size: 24px; font-weight: 600; line-height: 1.15; margin: 4px 0 0; text-wrap: balance; }
.lesson-body p { margin: 0 0 10px; }
.lesson h3 { font-family: var(--display); font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 6px 0 0; }
.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tasks li { display: grid; grid-template-columns: 20px 1fr; gap: 10px; align-items: start; font-size: 14.5px; }
.tick { width: 18px; height: 18px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; }
.tasks li.done .tick { background: var(--ok); border-color: var(--ok); }
.tasks li.done .tick::after { content: ""; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }
.tasks li.done > span:last-child { color: var(--muted); }
.tasks li.just .tick { animation: pop .5s ease-out; }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
.why { margin: 0; font-size: 14px; padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--accent) 9%, transparent); }
.lesson-btns { display: flex; justify-content: space-between; gap: 8px; }
.howto { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14.5px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13.5px; }
kbd { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--bg); }

/* toolbar */
.tools { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.tool { display: grid; justify-items: center; gap: 1px; min-width: 64px; padding: 6px 6px 5px; font-size: 11.5px; font-weight: 500; line-height: 1.2; flex: none; }
.tool svg { width: 22px; height: 22px; }
.tool[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, var(--panel)); color: var(--accent); }
.toolopts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); min-height: 30px; margin-top: -4px; }
.swatch { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid var(--line); }
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }

/* bench */
.bench { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.board-scroll { overflow-x: auto; }
#board { display: block; width: 100%; min-width: 760px; height: auto; touch-action: pan-x pan-y; user-select: none; -webkit-user-select: none; }
#board.placing { cursor: crosshair; }
#board.erasing .part { cursor: not-allowed; }
.statusline { display: grid; gap: 6px; padding: 8px 4px 0; }
.hint { font-family: var(--mono); font-size: 12.5px; color: var(--muted); min-height: 2.6em; }
.hint b { color: var(--ink); font-weight: 500; }
.alerts { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 99px; }
.chip.warn { background: color-mix(in srgb, var(--warn) 17%, transparent); color: var(--warn); }
.chip.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }

.bb { fill: var(--board); stroke: var(--board-edge); stroke-width: 1.5; }
.chan { fill: var(--chan); }
.rl { stroke-width: 1.5; } .rl.p { stroke: var(--rail-p); } .rl.n { stroke: var(--rail-n); }
.lbl { font-family: var(--mono); font-size: 9px; fill: var(--board-ink); text-anchor: middle; }
.sign { font-family: var(--mono); font-size: 11px; font-weight: 500; text-anchor: middle; }
.sign.p { fill: var(--rail-p); } .sign.n { fill: var(--rail-n); }
.hole { fill: var(--hole); }
.hl { fill: var(--accent); }
.tint { transition: opacity .2s; }

.part { cursor: pointer; }
#board.placing .part, #board.placing .fixed { pointer-events: none; }
.w { fill: none; stroke-width: 4.6; stroke-linecap: round; }
.hitw { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; }
.pin, .leg { fill: #a9b1ad; }
.lead { stroke: #9aa4a0; stroke-width: 2; fill: none; stroke-linecap: round; }
.res { fill: #d8c08e; stroke: #b39a68; }
.ledbody { stroke: rgba(0,0,0,.3); stroke-width: 1; }
.swbody { fill: #2b2f2e; }
.swcap { fill: #c43a2e; } .swcap.down { fill: #7f241c; }
.slide { fill: #2b2f2e; } .knob { fill: #d9dcda; }
.pad { fill: #c8873a; stroke: #8f5d25; }
.arm { stroke: #c7ccd0; stroke-width: 3.2; stroke-linecap: round; }
.spark { fill: #ffe27a; }
.capbody { fill: #24427a; stroke: #14264a; } .capband { fill: #d8dde6; }
.diodebody { fill: #1d1d1d; } .diodeband { fill: #c9c9c9; }
.potbody { fill: #2c4f8f; stroke: #1b335f; } .potknob { fill: #e3e5e4; stroke: #9aa2a0; } .potmark { stroke: #2b2f2e; stroke-width: 2; stroke-linecap: round; }
.ldrbody { fill: #c98a3c; stroke: #8b5a22; } .ldrtrack { fill: none; stroke: #f3e6c8; stroke-width: 1.4; }
.npnbody { fill: #232726; } .npntext { font-family: var(--mono); font-size: 7px; fill: #e6e6e6; text-anchor: middle; }
.hitbox { fill: transparent; }
.flow { fill: none; stroke: #ffa516; stroke-width: 3.3; stroke-linecap: round; stroke-dasharray: .1 14; pointer-events: none; }
#gOver { pointer-events: none; }
.ring { fill: none; stroke-width: 2.2; }
.ring.ok { stroke: var(--ok); } .ring.bad { stroke: var(--bad); }
.ring.probe-r { stroke: var(--probe-red); } .ring.probe-b { stroke: var(--probe-black); }
.ghostline { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 5 4; opacity: .8; }
.ghostline.bad { stroke: var(--bad); }
.selbox { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 4 3; }
.probe circle { stroke: #fff; stroke-width: 1.2; }
.probe line { stroke-width: 1.6; }
.probe.red circle { fill: var(--probe-red); } .probe.red line { stroke: var(--probe-red); }
.probe.black circle { fill: #2a2f2d; } .probe.black line { stroke: #2a2f2d; }
.probe text { font-family: var(--mono); font-size: 9px; font-weight: 500; fill: #fff; text-anchor: middle; }
.smoke circle { fill: #8c8c8c; opacity: 0; transform-box: fill-box; transform-origin: center; animation: smoke 1.6s ease-out forwards; }
.smoke circle:nth-child(2) { animation-delay: .2s; } .smoke circle:nth-child(3) { animation-delay: .4s; }
@keyframes smoke { 0% { opacity: .75; transform: translate(0, 0) scale(.6); } 100% { opacity: 0; transform: translate(6px, -40px) scale(2.2); } }

.bat-body { fill: #2b2f2e; } .bat-cap { fill: #c9a227; }
.bat-txt { font-family: var(--display); font-size: 16px; font-weight: 600; fill: #f1efe7; text-anchor: middle; }
.bat-sub { font-family: var(--mono); font-size: 8px; fill: #b9bdb9; text-anchor: middle; }
.term { fill: #b9c0bd; stroke: #6f7673; }
.fixed { cursor: pointer; }
.mcu-pcb { fill: #1f5a4a; stroke: #143d32; stroke-width: 1.5; }
.mcu-title { font-family: var(--mono); font-size: 8.5px; letter-spacing: .08em; fill: #cfe8de; }
.mcu-pin { font-family: var(--mono); font-size: 10px; font-weight: 500; fill: #f0f6f3; }
.mcu-sub { font-family: var(--mono); font-size: 8px; fill: #9cc4b5; }
.mcu-val { font-family: var(--mono); font-size: 10.5px; font-weight: 500; fill: #ffffff; text-anchor: end; }
.mcu-val.HIGH { fill: #ffb86b; } .mcu-val.LOW { fill: #9ad1ff; } .mcu-val.FLOAT, .mcu-val.UNDEF { fill: #ff8a80; }
.hdr { fill: #1a1a1a; } .hdr-hole { fill: #c9a227; }
.chip-ic { fill: #151a19; } .chip-pin { fill: #b6bcba; }

/* panels */
.panels { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 12px; align-items: start; }
@media (max-width: 780px) { .panels { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; display: grid; gap: 12px; }
.panel h2 { font-family: var(--display); font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.insp-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.insp-head h2 { color: var(--ink); font-size: 18px; letter-spacing: .02em; text-transform: none; display: flex; gap: 8px; align-items: baseline; }
.insp-head h2 span { font-family: var(--body); font-size: 14px; font-weight: 500; color: var(--muted); }
.insp-actions { display: flex; gap: 6px; }
.muted { color: var(--muted); margin: 0; font-size: 14.5px; }
.legs { font-size: 13.5px; color: var(--muted); margin: 0; }
.legs b { color: var(--ink); font-weight: 500; font-family: var(--mono); font-size: 12.5px; }
.note { margin: 0; font-size: 13.5px; padding: 8px 10px; border-radius: 7px; }
.note.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.field { display: grid; gap: 5px; }
.field label { font-size: 14px; font-weight: 500; }
.field .row { display: flex; align-items: center; gap: 10px; }
.field output { font-family: var(--mono); font-size: 13.5px; min-width: 6ch; text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
select { font: inherit; font-size: 14.5px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); max-width: 100%; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; font-weight: 500; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
dl.reads { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; font-size: 14px; }
dl.reads dt { color: var(--muted); }
dl.reads dd { margin: 0; font-family: var(--mono); font-size: 13.5px; text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-family: var(--body); font-size: 12.5px; font-weight: 600; }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 17%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.pill.off { background: color-mix(in srgb, var(--muted) 14%, transparent); color: var(--muted); }
pre.code { margin: 0; font-family: var(--mono); font-size: 12px; line-height: 1.5; background: var(--code-bg); border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; overflow-x: auto; }
details summary { cursor: pointer; font-size: 14px; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }
.hold { touch-action: none; }

.probe-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.big { font-family: var(--mono); font-size: 34px; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; }
.probe-legend { font-size: 13.5px; color: var(--muted); display: grid; gap: 3px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.dot.red { background: var(--probe-red); } .dot.black { background: var(--probe-black); }
.probe-ctl { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13.5px; color: var(--muted); }
#scope { display: block; width: 100%; height: 180px; border-radius: 8px; }
.scope-meta { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-family: var(--mono); font-size: 12px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .smoke circle, .tasks li.just .tick { animation: none; } }
