/* Siam2dev-IoT — styles */
:root {
  --brand: #e8590c;
  --brand-2: #ff7a2e;
  --top: #16191d;
  --top-2: #23272d;
  --top-text: #e9ecef;
  --bg: #e9ecef;
  --panel: #ffffff;
  --panel-2: #f6f7f8;
  --line: #d9dde1;
  --text: #1f2328;
  --muted: #6b737c;
  --canvas: #eceef0;
  --grid: #c3c8ce;
  --accent: #1f7ae0;
  --ok: #1f9d55;
  --err: #d6336c;
  --warn: #c77700;
  --code-bg: #ffffff;
  --code-text: #24292f;
  --code-gutter: #8c959f;
  --code-cur: rgba(31, 122, 224, .06);
  --sel: rgba(232, 89, 12, .9);
  --code-w: 42vw;
  --con-h: 210px;
  --pal-w: 196px;
  --radius: 8px;
  --font: 'IBM Plex Sans Thai', 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', Consolas, 'Courier New', monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f1114;
  --panel: #181b1f;
  --panel-2: #1f2328;
  --line: #2d3238;
  --text: #e6e8eb;
  --muted: #99a1aa;
  --canvas: #14171a;
  --grid: #2c3137;
  --code-bg: #15181b;
  --code-text: #dfe3e8;
  --code-gutter: #5d6670;
  --code-cur: rgba(255, 255, 255, .04);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg);
  display: flex; flex-direction: column; overflow: hidden;
}
button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: var(--text); }
[hidden] { display: none !important; }
.flex { flex: 1; }
.muted { color: var(--muted); font-size: 12.5px; }
kbd { font-family: var(--mono); font-size: 11px; color: var(--muted); }
code { font-family: var(--mono); font-size: 12.5px; }

/* ---------- top bar ---------- */
.topbar {
  height: 50px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 10px;
  background: var(--top); color: var(--top-text); position: relative; z-index: 30;
  border-bottom: 1px solid #000;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-size: 17px; letter-spacing: .2px; padding-right: 6px; white-space: nowrap; }
.brand b { color: var(--brand-2); font-weight: 600; }
.brand-logo { width: 28px; height: 28px; flex: none; }
.menubar { display: flex; align-items: center; }
.menu { position: relative; }
.menu-btn { background: none; border: 0; padding: 7px 10px; border-radius: 6px; color: var(--top-text); font-size: 13.5px; }
.menu-btn:hover, .menu.open .menu-btn { background: var(--top-2); }
.dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; min-width: 250px; padding: 5px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .22); z-index: 100;
}
.dropdown .mi { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 7px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; position: relative; font-size: 13.5px; }
.dropdown .mi:hover { background: var(--panel-2); }
.dropdown .mi:hover > span:first-child { color: var(--brand); }
.dropdown .sep { height: 1px; background: var(--line); margin: 5px 4px; }
.dropdown .sub { display: none; left: 100%; top: -6px; }
.dropdown .has-sub:hover > .sub { display: block; }
.dropdown .arrow { color: var(--muted); }
.ctx { position: fixed; min-width: 190px; }

.toolbar { display: flex; align-items: center; gap: 6px; margin-left: 8px; padding-left: 12px; border-left: 1px solid #333a42; }
.tb {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px;
  border: 0; border-radius: 7px; font-weight: 500; font-size: 13.5px; color: #fff; transition: filter .12s, transform .06s;
}
.tb svg { width: 18px; height: 18px; fill: currentColor; }
.tb:hover:not(:disabled) { filter: brightness(1.12); }
.tb:active:not(:disabled) { transform: translateY(1px); }
.tb:disabled { opacity: .4; cursor: default; }
.tb-compile { background: #2f6fd6; }
.tb-run { background: #1f9d55; }
.tb-run.active { background: #13874a; box-shadow: 0 0 0 2px rgba(46, 204, 113, .35); }
.tb-stop { background: #c92a2a; }
.tb-ghost { background: var(--top-2); }
.tb-share { background: var(--brand); }
.tb-icon { background: var(--top-2); padding: 0 9px; }
.sim-time { font-family: var(--mono); font-size: 13px; color: #9aa4ae; margin-left: 6px; min-width: 84px; }
.sim-running .sim-time { color: #7ee2a8; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.proj-name { background: none; border: 1px dashed transparent; color: #cfd5db; padding: 5px 8px; border-radius: 6px; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-name:hover { border-color: #4a525b; }

/* ---------- layout ---------- */
.layout { flex: 1; min-height: 0; display: flex; }
.palette {
  width: var(--pal-w); flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.no-palette .palette { display: none; }
.pal-head { padding: 10px 10px 8px; border-bottom: 1px solid var(--line); }
.pal-title { font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 7px; display: flex; align-items: center; gap: 6px; }
.badge { background: var(--brand); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; letter-spacing: 0; }
#paletteSearch { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); outline: none; }
#paletteSearch:focus { border-color: var(--brand); }
.pal-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.pal-cat { font-size: 11.5px; font-weight: 600; color: var(--muted); margin: 12px 2px 6px; text-transform: uppercase; letter-spacing: .5px; }
.pal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pal-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 6px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); cursor: grab;
  user-select: none; touch-action: none; transition: border-color .12s, box-shadow .12s, transform .12s;
}
.pal-item:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(232, 89, 12, .15); transform: translateY(-1px); }
.pal-item svg { width: 100%; height: 46px; pointer-events: none; }
.pal-item span { font-size: 11.5px; text-align: center; line-height: 1.25; }
.pal-item[data-type="arduino-uno"], .pal-item[data-type="lcd1602"] { grid-column: span 2; }
.pal-foot { font-size: 11.5px; color: var(--muted); padding: 7px 10px; border-top: 1px solid var(--line); text-align: center; }
.drag-ghost { position: fixed; z-index: 1000; pointer-events: none; transform: translate(-50%, -50%); width: 110px; opacity: .85; filter: drop-shadow(0 6px 12px rgba(0, 0, 0, .25)); }
.drag-ghost svg { width: 100%; height: auto; }
body.dragging, body.dragging * { cursor: grabbing !important; }

/* ---------- stage ---------- */
.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--canvas); }
.stage-bar { height: 40px; flex: none; display: flex; align-items: flex-end; padding: 0 10px; gap: 8px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.stage-bar .tab { padding: 8px 16px; background: var(--canvas); border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; font-weight: 600; font-size: 13px; margin-bottom: -1px; }
.stage-tools { margin-left: auto; align-self: center; display: flex; align-items: center; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
.stage-tools button { width: 28px; height: 26px; border: 0; background: none; border-radius: 5px; font-size: 16px; }
.stage-tools button:hover { background: var(--panel-2); color: var(--brand); }
#zoomLabel { font-family: var(--mono); font-size: 11.5px; min-width: 42px; text-align: center; color: var(--muted); }
.canvas-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.grid-dot { fill: var(--grid); }
.no-grid .grid-bg { display: none; }
#canvas.panning { cursor: grabbing; }
#canvas.wiring { cursor: crosshair; }

/* parts */
.part { cursor: move; }
.part .pl { font: 7px var(--mono); fill: #fff; pointer-events: none; }
.part .tiny, .pal-item .tiny { font: 8px var(--font); }
.part text { pointer-events: none; user-select: none; }
.sel-box { fill: none; stroke: none; pointer-events: none; }
.part.selected .sel-box { stroke: var(--sel); stroke-width: 1.5; stroke-dasharray: 5 4; }
.sim-running .part .hit { cursor: pointer; }

/* pins */
.pin { fill: transparent; stroke: transparent; stroke-width: 1.5; cursor: crosshair; transition: fill .1s; }
.pin:hover, .wiring .pin { fill: rgba(31, 158, 71, .35); stroke: #1e9e47; }
.pin:hover { fill: #2ecc71; r: 5.5; }
.pin.used { fill: rgba(0, 0, 0, .0); }

/* wires */
.wire { cursor: pointer; }
.wire path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.w-hit { stroke: transparent; stroke-width: 12; }
.w-out { stroke: rgba(0, 0, 0, .28); stroke-width: 4.6; }
.w-line { stroke-width: 3; }
.wire:hover .w-out { stroke: rgba(232, 89, 12, .5); stroke-width: 6; }
.wire.selected .w-out { stroke: var(--brand); stroke-width: 6.5; }
#layerTemp { pointer-events: none; }
.w-temp { fill: none; stroke-width: 3; stroke-dasharray: 6 4; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }

.canvas-hint {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); text-align: center; color: var(--muted);
  display: flex; flex-direction: column; gap: 6px; pointer-events: none; background: var(--panel); padding: 22px 30px; border-radius: 12px; border: 1px dashed var(--line);
}
.canvas-hint b { color: var(--text); font-size: 16px; }
.hint-icon { font-size: 26px; color: var(--brand); }
.status-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(22, 25, 29, .9); color: #fff; padding: 7px 14px; border-radius: 20px; font-size: 12.5px; pointer-events: none; white-space: nowrap; }

/* properties panel */
.props {
  position: absolute; top: 12px; right: 12px; width: 250px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12); padding: 10px 12px; font-size: 13px; z-index: 5;
}
.pp-title { font-weight: 600; margin-bottom: 8px; display: flex; flex-direction: column; }
.pp-title small { font-weight: 400; color: var(--muted); font-family: var(--mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.pp-row { display: flex; align-items: center; gap: 8px; margin: 7px 0; flex-wrap: wrap; }
.pp-row label { min-width: 72px; color: var(--muted); font-size: 12.5px; }
.pp-row select, .pp-row input:not([type=range]) { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); }
.pp-row input[type=range] { flex: 1; accent-color: var(--brand); }
.pp-note { font-size: 12px; color: var(--muted); background: var(--panel-2); border-radius: 6px; padding: 6px 8px; margin: 6px 0; }
.pp-actions { display: flex; gap: 6px; margin-top: 10px; }
.pp-actions button { flex: 1; padding: 6px 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); font-size: 12.5px; }
.pp-actions button:hover { border-color: var(--brand); color: var(--brand); }
.pp-actions .danger:hover { border-color: var(--err); color: var(--err); }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; }
.swatches .sw { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); padding: 0; }
.swatches .sw.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--brand); }

/* ---------- splitters ---------- */
.splitter { width: 5px; flex: none; cursor: col-resize; background: var(--line); transition: background .15s; }
.splitter:hover { background: var(--brand); }
.no-code .splitter, .no-code .code { display: none; }

/* ---------- code panel ---------- */
.code { width: var(--code-w); flex: none; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.code-tabs { height: 40px; flex: none; display: flex; align-items: flex-end; gap: 2px; padding: 0 8px; background: var(--panel-2); border-bottom: 1px solid var(--line); overflow-x: auto; }
.code-tab { border: 1px solid transparent; border-bottom: 0; background: none; padding: 8px 14px; border-radius: 8px 8px 0 0; font-size: 13px; color: var(--muted); margin-bottom: -1px; white-space: nowrap; }
.code-tab.on { background: var(--code-bg); border-color: var(--line); color: var(--text); font-weight: 600; }
.code-tab:not(.on):hover { color: var(--text); }
.code-body { flex: 1; min-height: 0; position: relative; }
#editor { position: absolute; inset: 0; }
.pane { position: absolute; inset: 0; display: flex; flex-direction: column; }
.pane-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--line); }
#diagramText { flex: 1; border: 0; resize: none; outline: none; padding: 10px 12px; font: 12.5px/1.5 var(--mono); background: var(--code-bg); color: var(--code-text); }
.libs { padding: 14px 16px; overflow-y: auto; }
.libs h4 { margin: 0 0 10px; }
.lib { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--panel-2); }
.lib b { font-size: 14px; }
.lib .ok { float: right; font-size: 11.5px; color: var(--ok); background: rgba(31, 157, 85, .12); padding: 1px 8px; border-radius: 10px; }
.lib p { margin: 5px 0 0; font-size: 12.5px; color: var(--muted); }

/* code editor */
.ce { display: flex; background: var(--code-bg); font: 13.5px/20px var(--mono); color: var(--code-text); overflow: hidden; }
.ce-gutter { width: 46px; flex: none; overflow: hidden; color: var(--code-gutter); text-align: right; padding: 8px 10px 0 0; user-select: none; border-right: 1px solid var(--line); background: var(--code-bg); }
.ce-lines div { height: 20px; }
.ce-lines div.err { color: #fff; background: var(--err); border-radius: 3px; }
.ce-body { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.ce-layer { position: absolute; top: 0; left: 0; min-width: 100%; pointer-events: none; }
.ce-pre, .ce-ta { margin: 0; padding: 8px 14px 60px; font: inherit; white-space: pre; tab-size: 2; letter-spacing: 0; }
.ce-pre { color: var(--code-text); }
.ce-ta {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; outline: none; resize: none; overflow: auto;
  background: transparent; color: transparent; caret-color: var(--brand); -webkit-text-fill-color: transparent;
}
.ce-ta::selection { background: rgba(31, 122, 224, .25); -webkit-text-fill-color: transparent; }
.ce-curline { position: absolute; left: 0; right: -4000px; height: 20px; background: var(--code-cur); }
.ce-errline { position: absolute; left: 0; right: -4000px; height: 20px; background: rgba(214, 51, 108, .14); border-left: 3px solid var(--err); }
.c-com { color: #8b949e; font-style: italic; }
.c-str { color: #0a7d3e; }
.c-num { color: #b35900; }
.c-pre { color: #8250df; }
.c-type { color: #0550ae; font-weight: 600; }
.c-kw { color: #a626a4; }
.c-fn { color: #d4580a; }
.c-const { color: #0b7c8c; font-weight: 600; }
[data-theme="dark"] .c-str { color: #7ee2a8; }
[data-theme="dark"] .c-num { color: #ffb86b; }
[data-theme="dark"] .c-pre { color: #c39cff; }
[data-theme="dark"] .c-type { color: #79b8ff; }
[data-theme="dark"] .c-kw { color: #f28fe0; }
[data-theme="dark"] .c-fn { color: #ff9a57; }
[data-theme="dark"] .c-const { color: #56d4e4; }

/* ---------- console ---------- */
.con-splitter { height: 5px; flex: none; cursor: row-resize; background: var(--line); }
.con-splitter:hover { background: var(--brand); }
.console { height: var(--con-h); flex: none; display: flex; flex-direction: column; background: var(--panel); min-height: 0; }
.console.collapsed { height: 38px; }
.console.collapsed .con-pane { display: none; }
.con-bar { display: flex; align-items: center; gap: 2px; padding: 4px 8px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.con-tab { border: 0; background: none; padding: 5px 11px; border-radius: 6px; font-size: 12.5px; color: var(--muted); }
.con-tab.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }
.con-btn { border: 0; background: none; color: var(--muted); padding: 2px 8px; }
.con-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.log { flex: 1; overflow-y: auto; padding: 6px 10px; font: 12.5px/1.6 var(--mono); }
.log > div { white-space: pre-wrap; word-break: break-word; }
.log-time { color: var(--muted); margin-right: 8px; font-size: 11px; }
.log-ok { color: var(--ok); }
.log-err { color: var(--err); }
.log-warn { color: var(--warn); }
.log a { color: var(--accent); }
.con-clear { position: absolute; right: 10px; top: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; font-size: 11.5px; padding: 2px 9px; color: var(--muted); }
.serial-out { flex: 1; margin: 0; overflow: auto; padding: 8px 12px; font: 13px/1.5 var(--mono); background: #0e1114; color: #d7f5df; white-space: pre-wrap; word-break: break-all; }
.serial-in { display: flex; gap: 6px; padding: 6px 8px; border-top: 1px solid var(--line); align-items: center; }
.serial-in input { flex: 1; min-width: 60px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); outline: none; font-family: var(--mono); font-size: 12.5px; }
.serial-in input:focus { border-color: var(--brand); }
.serial-in select { padding: 5px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); font-size: 12px; }
.chk { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 3px; white-space: nowrap; }

.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 7px; padding: 7px 14px; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 5px 11px; font-size: 12.5px; }

/* ---------- status bar ---------- */
.statusbar { height: 26px; flex: none; display: flex; align-items: center; gap: 18px; padding: 0 12px; font-size: 12px; background: var(--top); color: #aeb6be; }
.statusbar a { color: var(--brand-2); text-decoration: none; }
.st-state::before { content: '●'; margin-right: 6px; color: #6c757d; }
.st-state.ok::before { color: #2ecc71; }
.st-state.err::before { color: #ff6b8b; }
.st-state.run::before { color: #2ecc71; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- modal & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(10, 12, 15, .5); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px; }
.modal-card { width: 460px; max-width: 100%; max-height: 86vh; display: flex; flex-direction: column; background: var(--panel); border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }
.modal-card.wide { width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { border: 0; background: none; font-size: 16px; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.inp { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); }
.share-box { width: 100%; height: 90px; font: 12px var(--mono); padding: 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); resize: none; }
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.ex-card { text-align: left; display: flex; flex-direction: column; gap: 4px; border: 1px solid var(--line); background: var(--panel-2); border-radius: 9px; padding: 12px; }
.ex-card:hover { border-color: var(--brand); box-shadow: 0 4px 14px rgba(232, 89, 12, .15); }
.ex-card span { font-size: 12.5px; color: var(--muted); }
.kb { border-collapse: collapse; width: 100%; }
.kb td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.kb kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 2px 6px; color: var(--text); }
.ref { border-collapse: collapse; width: 100%; font-size: 13px; }
.ref th { text-align: left; white-space: nowrap; padding: 7px 10px 7px 0; vertical-align: top; color: var(--brand); }
.ref td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.help li { margin-bottom: 6px; }
.about { text-align: center; }
.about-logo svg { width: 56px; height: 56px; }
.about h3 { margin: 8px 0; }
.about a { color: var(--brand); }
#toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1f2328; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 300; transition: opacity .2s, transform .2s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--err); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .tb span { display: none; }
  .tb { padding: 0 10px; }
  .proj-name { max-width: 120px; }
  .brand span { display: none; }
}
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .palette { width: auto; height: 118px; border-right: 0; border-bottom: 1px solid var(--line); }
  .pal-head, .pal-foot, .pal-cat { display: none; }
  .pal-list { display: flex; overflow-x: auto; overflow-y: hidden; gap: 6px; padding: 8px; }
  .pal-grid { display: contents; }
  .pal-item { width: 96px; flex: none; }
  .stage { flex: 1 1 50%; min-height: 240px; }
  .splitter { display: none; }
  .code { width: auto; flex: 1 1 50%; min-height: 0; }
  .menu-btn { padding: 6px 6px; font-size: 12.5px; }
  .sim-time, #btnExamples, .proj-name { display: none; }
  .statusbar { display: none; }
}

/* dark-mode wire contrast & mobile menu */
[data-theme="dark"] .w-out { stroke: rgba(255, 255, 255, .28); }
[data-theme="dark"] .wire:hover .w-out { stroke: rgba(255, 122, 46, .6); }
.menu-btn { white-space: nowrap; }
@media (max-width: 820px) { .menubar { overflow-x: auto; flex-shrink: 1; min-width: 0; } .toolbar { padding-left: 6px; margin-left: 2px; } }

/* ---------- lessons ---------- */
.tab-lessons { color: var(--brand) !important; }
.tab-lessons.on { color: var(--brand) !important; }
.tb-lessons { background: #2f6fd6; }
.lessons { position: absolute; inset: 0; overflow-y: auto; padding: 16px 18px 40px; background: var(--code-bg); line-height: 1.65; }
.ls-hero { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; padding: 16px 18px; border-radius: 12px; background: linear-gradient(135deg, #fff1e8, #eef3ff); border: 1px solid var(--line); margin-bottom: 14px; }
[data-theme="dark"] .ls-hero { background: linear-gradient(135deg, #2a1d14, #172033); }
.ls-hero h3 { margin: 0 0 4px; font-size: 18px; }
.ls-hero p { margin: 0; color: var(--muted); font-size: 13px; max-width: 420px; }
.ls-progress { min-width: 170px; }
.ls-bar { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; }
.ls-bar span { display: block; height: 100%; background: var(--ok); border-radius: 8px; transition: width .3s; }
.ls-progress small { color: var(--muted); font-size: 12px; }
.ls-list { display: flex; flex-direction: column; gap: 8px; }
.ls-item { display: flex; gap: 12px; align-items: flex-start; text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); transition: border-color .12s, box-shadow .12s, transform .12s; }
.ls-item:hover { border-color: var(--brand); box-shadow: 0 4px 14px rgba(232, 89, 12, .12); transform: translateY(-1px); }
.ls-no { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--panel-2); border: 2px solid var(--line); color: var(--brand); }
.ls-item.done .ls-no { background: var(--ok); border-color: var(--ok); color: #fff; }
.ls-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ls-meta b { font-size: 14px; }
.ls-meta small { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.ls-tags { display: flex; gap: 6px; margin-top: 4px; }
.lv { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; font-weight: 600; white-space: nowrap; }
.lv-easy { background: rgba(31, 157, 85, .13); color: var(--ok); }
.lv-mid { background: rgba(232, 140, 26, .15); color: #c46a00; }
.lv-hard { background: rgba(214, 51, 108, .13); color: var(--err); }
.lv-time { background: var(--panel-2); color: var(--muted); font-weight: 500; }
.ls-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; position: sticky; top: -16px; background: var(--code-bg); padding: 6px 0; z-index: 2; }
.ls-back { border: 0; background: none; color: var(--brand); font-weight: 600; padding: 4px 0; }
.ls-article h2 { margin: 6px 0 4px; font-size: 20px; line-height: 1.35; }
.ls-article h4 { margin: 18px 0 6px; font-size: 15px; }
.ls-article p, .ls-article li { font-size: 13.5px; }
.ls-article ul, .ls-article ol { padding-left: 20px; margin: 4px 0; }
.ls-article code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 12px; }
.ls-head { display: flex; gap: 6px; align-items: center; }
.ls-chip { background: var(--brand); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 9px; border-radius: 10px; }
.ls-sum { color: var(--muted); margin: 0 0 10px; }
.ls-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 4px; }
.btn.run { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.ls-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px 14px 10px; margin-top: 12px; }
.ls-box h4 { margin-top: 10px; }
.ls-parts li::marker { content: '▸ '; color: var(--brand); }
.ls-mini { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font: 12.5px/1.55 var(--mono); overflow-x: auto; margin: 6px 0; }
.ls-note { background: rgba(31, 122, 224, .08); border-left: 3px solid var(--accent); padding: 6px 10px; border-radius: 0 6px 6px 0; }
.ls-wire { width: 100%; border-collapse: collapse; font-size: 13px; }
.ls-wire th { text-align: left; background: var(--panel-2); padding: 6px 8px; font-weight: 600; border-bottom: 1px solid var(--line); }
.ls-wire td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.ls-codehead { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; }
.ls-codehead h4 { margin: 0; }
.ls-code { margin: 8px 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); font: 12.5px/1.55 var(--mono); overflow-x: auto; max-height: 460px; }
.ls-challenge { background: rgba(232, 89, 12, .07); border: 1px dashed rgba(232, 89, 12, .45); border-radius: 10px; padding: 2px 14px 10px; margin-top: 16px; }
.ls-done { display: flex; align-items: center; gap: 8px; margin: 16px 0 8px; font-weight: 600; cursor: pointer; }
.ls-done input { width: 18px; height: 18px; accent-color: var(--ok); }
.ls-nav { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.tb, .tb span { white-space: nowrap; }
@media (max-width: 1500px) { #btnExamples span, #btnShare span { display: none; } #btnExamples, #btnShare { padding: 0 9px; } .proj-name { max-width: 170px; } }

/* ---------- breadboard pins ---------- */
.pin.bb { r: 3.2; }
.pin.snap { fill: rgba(46, 204, 113, .55); stroke: #1e9e47; }
.pal-item[data-type="breadboard"] { grid-column: span 2; }

/* ---------- IoT dashboard ---------- */
.iot-status { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; padding: 6px 10px; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.iot-status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #9aa1a9; }
.iot-status .dot.on { background: #2ecc71; } .iot-status .dot.wait { background: #f0a020; animation: pulse 1s infinite; }
.iot-body { flex: 1; min-height: 0; display: flex; gap: 8px; padding: 8px; }
.iot-grid { flex: 1.4; min-width: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; align-content: start; }
.iot-empty { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; padding: 12px; border: 1px dashed var(--line); border-radius: 8px; line-height: 1.6; }
.iot-card { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--panel-2); display: flex; flex-direction: column; gap: 3px; }
.ic-head { display: flex; justify-content: space-between; gap: 6px; align-items: flex-start; font-size: 12px; }
.ic-head b { font-family: var(--mono); word-break: break-all; }
.ic-badges { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
.ic-val { font-size: 22px; font-weight: 600; font-family: var(--mono); color: var(--brand); word-break: break-all; line-height: 1.2; }
.ic-spark { position: relative; height: 34px; }
.ic-spark svg { width: 100%; height: 34px; display: block; }
.ic-range { position: absolute; right: 0; top: -2px; font-size: 10px; color: var(--muted); }
.ic-time { font-size: 11px; }
.ic-ctrl { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.ic-ctrl input { flex: 1; min-width: 60px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); font-size: 12px; }
.ic-ctrl .btn.on { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.iot-side { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 6px; }
.iot-log { flex: 1; min-height: 0; overflow-y: auto; background: #0e1114; color: #cfe8d6; border-radius: 8px; padding: 6px 8px; font: 11.5px/1.5 var(--mono); }
.iot-log .il-pub { color: #7ee2a8; } .iot-log .il-send { color: #8cc4ff; } .iot-log .il-sub { color: #ffd479; } .iot-log .il-warn { color: #ffb86b; } .iot-log .il-err { color: #ff7b9c; } .iot-log .il-ok { color: #9ff0c0; }
.iot-pub { display: flex; gap: 4px; }
.iot-pub input { flex: 1; min-width: 50px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); font-size: 12px; font-family: var(--mono); }

/* ---------- lessons part 2, quiz, account ---------- */
.ls-part { margin: 14px 2px 2px; font-weight: 700; font-size: 13.5px; color: var(--brand); }
.ls-part small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.lv-esp { background: rgba(31, 122, 224, .13); color: var(--accent); }
.lv-quiz { background: rgba(142, 68, 173, .12); color: #8e44ad; }
.ls-quiz { border: 1px solid var(--line); border-radius: 10px; padding: 4px 14px 12px; margin-top: 16px; background: var(--panel); }
.qz { margin: 10px 0; }
.qz p { margin: 0 0 4px; }
.qz-opt { display: flex; gap: 8px; align-items: flex-start; padding: 5px 8px; border-radius: 7px; cursor: pointer; font-size: 13.5px; border: 1px solid transparent; }
.qz-opt:hover { background: var(--panel-2); }
.qz-opt input { margin-top: 4px; accent-color: var(--brand); }
.qz-opt.ok { background: rgba(31, 157, 85, .12); border-color: rgba(31, 157, 85, .5); }
.qz-opt.bad { background: rgba(214, 51, 108, .1); border-color: rgba(214, 51, 108, .45); }
.qz-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.qz-result { font-size: 13px; color: var(--muted); }
.ok-txt { color: var(--ok); }
.acct { font-size: 12.5px; white-space: nowrap; }
.acct a { color: #ffb38a; text-decoration: none; padding: 5px 9px; border: 1px solid #3a4048; border-radius: 6px; }
.acct a:hover { border-color: var(--brand); }
.acct-name { color: #d9dee3; padding: 5px 8px; border-radius: 6px; background: var(--top-2); }
.acct-name small { color: #9aa4ae; margin-left: 4px; }
.cloud-list { display: flex; flex-direction: column; gap: 8px; }
.cloud-item { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.cloud-item > div { flex: 1; display: flex; flex-direction: column; }
.dropdown .sub { max-height: 70vh; overflow-y: auto; }
