:root {
  --bg: #f1f5f9; --panel: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #2563eb; --accent-ink: #ffffff; --ok: #15803d; --bad: #b91c1c; --warn: #b45309;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --panel: #111a2e; --ink: #e2e8f0; --muted: #94a3b8; --line: #1f2a44;
    --accent: #3b82f6; --ok: #4ade80; --bad: #f87171; --warn: #fbbf24;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
header { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 700; letter-spacing: .04em; cursor: pointer; }
nav { display: flex; gap: 6px; }
button { font: inherit; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary, button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.small { padding: 1px 8px; font-size: 12px; margin-left: 8px; }
.launcher { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.subtitle { color: var(--muted); font-size: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 16px; min-height: 96px; text-align: left; font-weight: 600; }
.card .icon { font-size: 26px; }
.exp { display: grid; grid-template-columns: 340px 1fr; gap: 12px; padding: 12px; }
.exp aside, .exp main { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.exp h2 { margin: 0 0 4px; font-size: 18px; }
.exp h3 { margin: 14px 0 4px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.param { display: block; margin: 6px 0; }
.param span { display: block; font-size: 13px; }
.param input { width: 100%; }
.controls, .tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.readout { font-variant-numeric: tabular-nums; font-size: 13px; margin-top: 8px; }
pre.readout { white-space: pre-wrap; font-family: inherit; }
.explain { font-size: 13px; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 8px; }
.scene { width: 100%; height: auto; display: block; }
.scene .ground { stroke: var(--muted); stroke-width: 2; }
.scene .ink { stroke: var(--ink); }
.scene .legend { font-size: 16px; }
.graph { margin-top: 10px; }
.graph svg { width: 100%; height: 160px; background: var(--bg); border-radius: 8px; }
.graph .axis { stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.graph-title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.schematic { background: var(--bg); border-radius: 8px; }
.schematic .comp { cursor: pointer; }
.schematic { background: #f8fafc; }
.schematic .selection { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; }
.schematic .pin { fill: #fbbf24; stroke: #78350f; stroke-width: 1.5; }
.schematic .pinlabel { font: 600 10px ui-monospace, Menlo, monospace; fill: #0f172a; pointer-events: none; }
.schematic .pinlabel.board { fill: #0f172a; font-size: 10.5px; }
.schematic .leg { stroke: #9ca3af; stroke-width: 3; }
.schematic .silk { font: 600 9px system-ui, sans-serif; fill: #ecfeff; }
.schematic .logo { font: italic 800 22px system-ui, sans-serif; fill: #ecfeff; }
.schematic .chip { font: 700 10px ui-monospace, monospace; fill: #e5e7eb; }
.schematic .part { font: 600 11px system-ui, sans-serif; fill: #0f172a; }
.schematic .batt { font: 700 11px system-ui, sans-serif; fill: #f8fafc; }
.schematic .lcd { font: 700 13px ui-monospace, Menlo, monospace; fill: #1a2e05; }
.schematic text { pointer-events: none; }
.bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.bottom textarea { width: 100%; height: 230px; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px; resize: vertical; }
.bottom pre { height: 230px; overflow: auto; margin: 0; background: #0b1220; color: #a7f3d0; border-radius: 8px; padding: 8px; font-size: 12px; }
@media (max-width: 900px) {
  .exp { grid-template-columns: 1fr; padding: 8px; }
  .bottom { grid-template-columns: 1fr; }
}
#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 8px 16px; background: #fef3c7; color: #78350f; }
.loading-progress { position: relative; display: block; width: 8rem; height: 8rem; margin: 20vh auto 1rem auto; }
.loading-progress circle { fill: none; stroke: #e0e0e0; stroke-width: 0.6rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child { stroke: #2563eb; stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%; transition: stroke-dasharray 0.05s ease-in-out; }
.loading-progress-text { position: absolute; text-align: center; font-weight: bold; inset: calc(20vh + 3.25rem) 0 auto 0.2rem; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }
/* ---------- workbench ---------- */
.workbench { grid-template-columns: 230px minmax(0, 1fr) 280px; }
.library .toolbar { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 10px; }
.library .toolbar button, .filebtn { padding: 4px 8px; font-size: 12px; }
.filebtn { position: relative; overflow: hidden; display: inline-block; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: var(--panel); }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.cat { margin: 10px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.palette { display: flex; flex-wrap: wrap; gap: 4px; }
.palette button { font-size: 12.5px; padding: 5px 8px; }
.runbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.runbar .hint { font-size: 12px; color: var(--muted); }
.runbar .spacer { flex: 1; }
.canvas-wrap { overflow: auto; max-height: 62vh; border: 1px solid var(--line); border-radius: 8px; outline: none; background: #f8fafc; }
.canvas-wrap:focus { border-color: var(--accent); }
.schematic.editable { max-height: none; user-select: none; display: block; }
.schematic .wirehit { cursor: pointer; }
.schematic .comp { cursor: grab; }
.schematic .pinhit { cursor: crosshair; }
.schematic .pinhit:hover { fill: rgba(249, 115, 22, .25); }
.schematic .pin.hot { fill: #f97316; }
.inspector input[type=number] { width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.howto { padding-left: 18px; }
@media (max-width: 1200px) { .workbench { grid-template-columns: 200px minmax(0, 1fr); } .workbench .inspector { grid-column: 1 / -1; } }
@media (max-width: 900px) { .workbench { grid-template-columns: 1fr; } }
/* Side panels scroll on their own so the bench never jumps away while picking parts. */
.workbench aside { position: sticky; top: 62px; max-height: calc(100vh - 74px); overflow: auto; align-self: start; }
.workbench .canvas-wrap { max-height: calc(100vh - 420px); min-height: 360px; }

.schematic .pin.real { fill: rgba(251, 191, 36, .35); stroke: #f59e0b; stroke-width: 1.2; }
.scene .charge { font: 700 18px system-ui, sans-serif; fill: white; pointer-events: none; }
.param input[type=checkbox] { width: auto; margin: 0 6px 0 0; vertical-align: middle; }

/* AI problem solver */
.solver textarea { width: 100%; box-sizing: border-box; font: inherit; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px; resize: vertical; }
.solver .samples { display: flex; flex-direction: column; gap: 6px; }
.solver .sample { text-align: left; font-size: 12px; color: var(--muted); }
.solver main { display: flex; flex-direction: column; gap: 12px; }
.solver .card-panel { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.solver .badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.solver .steps li { margin: 4px 0; }
.solver .answer { font-weight: 600; color: var(--ok); margin-top: 8px; }
.solver .fault { color: var(--bad); font-weight: 600; }
.solver .check { display: flex; gap: 6px; align-items: center; margin: 8px 0; }
.solver table.verify { border-collapse: collapse; width: 100%; font-size: 13px; }
.solver table.verify th, .solver table.verify td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.solver tr.ok td { color: var(--ok); } .solver tr.bad td { color: var(--bad); }
.solver .wire { stroke: #64748b; stroke-width: 2; }
.solver .settings { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.solver .settings label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.solver .settings input, .solver .settings select { font: inherit; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }

/* Device guide at the bottom of the workbench */
.workbench .devices { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.workbench .devices summary { cursor: pointer; padding: 2px 0; }
.workbench .devices[open] summary { margin-bottom: 8px; }
.workbench .devices .tabs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.workbench .devices .search { font: inherit; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); min-width: 220px; }
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.device { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--bg); }
.device.current { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.device h4 { margin: 2px 0 6px; } .device p { margin: 4px 0; }
.workbench .check { display: flex; gap: 6px; align-items: center; margin: 4px 0; }
.schematic .board-silk { font: 600 6.5px system-ui, sans-serif; fill: #334155; }
.scene .cart-label { font: 700 13px system-ui, sans-serif; fill: #fff; paint-order: stroke; stroke: rgba(0,0,0,.35); stroke-width: 2px; }
.scene .tag { font: 600 13px system-ui, sans-serif; fill: #0f172a; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.scene { border-radius: 10px; }

/* Arduino code editor */
.code-editor { position: relative; border: 1px solid var(--line); border-radius: 8px; background: #0f172a; overflow: visible; }
.code-editor.disabled { opacity: 0.75; }
.ce-toolbar { display: flex; gap: 8px; align-items: center; padding: 4px 6px; background: #111827; border-bottom: 1px solid #1f2937; border-radius: 8px 8px 0 0; }
.ce-toolbar select { font: 12px system-ui, sans-serif; background: #1f2937; color: #e5e7eb; border: 1px solid #334155; border-radius: 6px; padding: 2px 6px; }
.ce-toolbar .muted { color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ce-toolbar select { max-width: 45%; }
.ce-body { display: flex; height: 260px; }
.ce-gutter { width: 42px; overflow: hidden; padding: 8px 4px 8px 0; text-align: right; color: #64748b; background: #0b1220; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; user-select: none; }
.ce-gutter .ce-err { color: #f87171; font-weight: 700; cursor: help; }
.ce-wrap { position: relative; flex: 1; min-width: 0; }
.bottom .code-editor .ce-hl, .bottom .code-editor .ce-input { position: absolute; inset: 0; margin: 0; padding: 8px; border: 0; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre; overflow: auto; tab-size: 2; }
.bottom .code-editor .ce-hl { color: #e2e8f0; background: transparent; height: auto; border-radius: 0; pointer-events: none; overflow: hidden; }
.bottom .code-editor textarea.ce-input { height: auto; width: auto; background: transparent; color: transparent; caret-color: #f8fafc; resize: none; outline: none; border-radius: 0; }
.ce-input::selection { background: rgba(96,165,250,.35); color: transparent; }
.ce-c { color: #64748b; font-style: italic; } .ce-s { color: #a5d6a7; } .ce-p { color: #f472b6; } .ce-n { color: #fbbf24; }
.ce-k { color: #c084fc; } .ce-t { color: #38bdf8; } .ce-f { color: #60a5fa; } .ce-cl { color: #2dd4bf; font-weight: 600; }
.ce-pop { position: absolute; z-index: 20; min-width: 300px; max-width: 460px; max-height: 240px; overflow: auto; background: #1e293b; color: #e2e8f0; border: 1px solid #334155; border-radius: 8px; box-shadow: 0 10px 24px rgba(0,0,0,.35); font: 12px ui-monospace, Menlo, monospace; }
.ce-item { display: flex; gap: 8px; align-items: center; padding: 4px 8px; cursor: pointer; white-space: nowrap; }
.ce-item.on { background: #2563eb; }
.ce-item .ce-sig { color: #94a3b8; overflow: hidden; text-overflow: ellipsis; margin-left: auto; padding-left: 10px; }
.ce-item.on .ce-sig { color: #dbeafe; }
.ce-kind { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; font: 700 10px system-ui; background: #475569; }
.ce-k-Function, .ce-k-Method { background: #2563eb; } .ce-k-Constant { background: #b45309; } .ce-k-Type, .ce-k-Class { background: #0d9488; }
.ce-k-Snippet, .ce-k-Keyword { background: #7c3aed; } .ce-k-Variable { background: #16a34a; } .ce-k-Header { background: #db2777; }
.ce-doc { padding: 6px 8px; border-top: 1px solid #334155; color: #cbd5e1; font: 12px system-ui, sans-serif; white-space: normal; }
.compile-error { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bottom > * { min-width: 0; }

/* AI settings & skills */
.ai-setup aside label, .skill-editor label { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; font-size: 13px; }
.ai-setup input, .ai-setup select, .ai-setup textarea { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.ai-setup textarea { font: 12px/1.45 ui-monospace, Menlo, monospace; resize: vertical; }
.ai-setup .fault { color: var(--bad); font-weight: 600; }
.skills-head { display: flex; justify-content: space-between; align-items: center; }
.skills { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 12px; }
.skills nav { display: flex; flex-direction: column; gap: 6px; }
.skills nav button { text-align: left; display: flex; flex-direction: column; gap: 2px; }
@media (max-width: 900px) { .skills { grid-template-columns: 1fr; } }
.ai-answer { margin-top: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); line-height: 1.5; }
.ai-answer h3, .ai-answer h4, .ai-answer h5 { margin: 10px 0 4px; }
.ai-answer ul { margin: 4px 0; padding-left: 20px; }
.ai-answer code { background: rgba(100,116,139,.18); padding: 0 4px; border-radius: 4px; }
.md-code { background: #0f172a; color: #e2e8f0; padding: 8px 10px; border-radius: 8px; overflow: auto; font: 12px/1.45 ui-monospace, Menlo, monospace; white-space: pre; }
.md-code code { background: none; padding: 0; }
.ai-btn { white-space: nowrap; }
.ai-panel { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.ai-ask { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.ai-ask input { flex: 1; min-width: 120px; font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.device .ai-answer { font-size: 13px; }
