:root, :root[data-theme="dark"] {
  --lab-primary: #075f73;
  --lab-on-primary: #fff;
  --lab-secondary: #c5e7f1;
  --lab-on-secondary: #18252f;
  --lab-accent: #f5bd52;
  --lab-on-accent: #18252f;
  --lab-background: #f3f7f8;
  --lab-canvas-ink: #18252f;
  --lab-paper: #fff;
  --lab-ink: #18252f;
  --lab-muted: #4c5d6c;
  --lab-border: #7c8b99;
  --lab-soft: #eff3f6;
  --lab-radius: 18px;
  --lab-primary-text: #075f73;
  --green: var(--lab-primary);
  --green-dark: var(--lab-primary);
  --green-light: var(--lab-secondary);
  --line: var(--lab-border);
}
:root[data-theme="dark"] {
  --lab-background: #151e29;
  --lab-canvas-ink: #f8fafc;
  --lab-paper: #202d3c;
  --lab-ink: #f8fafc;
  --lab-muted: #bac9d8;
  --lab-border: #94a8bc;
  --lab-soft: #29394b;
  --lab-primary-text: #f8fafc;
}
:root[data-theme] {
  --color-paper: var(--lab-background);
  --color-paper-raised: var(--lab-paper);
  --color-paper-soft: var(--lab-soft);
  --color-paper-muted: var(--lab-soft);
  --color-ink: var(--lab-ink);
  --color-ink-muted: var(--lab-muted);
  --color-rule: var(--lab-border);
  --color-rule-strong: var(--lab-border);
  --color-accent: var(--lab-primary-text);
  --color-accent-hover: var(--lab-primary-text);
  --color-accent-soft: var(--lab-secondary);
  --color-accent-ink: var(--lab-primary-text);
  --color-focus: var(--lab-canvas-ink);
  --color-warning-paper: var(--lab-soft);
  --color-warning-ink: var(--lab-ink);
  --radius-control: 8px;
  --radius-panel: var(--lab-radius);
}
html { color-scheme: light; scroll-padding-bottom: 100px; }
html[data-theme="dark"] { color-scheme: dark; }
html[data-theme] body { background: var(--lab-background); color: var(--lab-canvas-ink); font-family: "Segoe UI", Arial, sans-serif; font-size: 15px; line-height: 1.5; }
html[data-theme] :focus-visible { outline: 3px solid var(--lab-canvas-ink); outline-offset: 4px; }
html[data-theme] button, html[data-theme] select, html[data-theme] input, html[data-theme] summary { font: inherit; }
html[data-theme] button, html[data-theme] summary, html[data-theme] a { -webkit-tap-highlight-color: transparent; }
html[data-theme] button { cursor: pointer; }
html[data-theme] button:disabled { cursor: not-allowed; opacity: .62; }
html[data-theme] button:active:not(:disabled) { transform: translateY(1px); }
html[data-theme] .sidebar { width: 230px; padding: 28px 18px 18px; background: var(--lab-paper); color: var(--lab-ink); border-right: 1px solid var(--lab-border); }
html[data-theme] .brand { padding-inline: 0; max-width: 100%; }
html[data-theme] .brand-logo { display: block; width: 194px; max-width: 100%; height: auto; flex: 0 1 auto; }
html[data-theme] body.sidebar-collapsed .sidebar .brand-logo { width: 46px; height: 46px; object-fit: cover; object-position: left center; flex-basis: 46px; }
html[data-theme] .brand-name { color: var(--lab-ink); font-weight: 800; }
html[data-theme] .brand-name > span { color: var(--lab-muted); letter-spacing: 2px; }
html[data-theme] .sidebar-label { color: var(--lab-muted); font-size: 11px; letter-spacing: .08em; padding-top: 38px; }
html[data-theme] .nav-item { font-size: 14px; min-height: 48px; color: var(--lab-muted); border-radius: 10px; font-weight: 600; }
html[data-theme] .sidebar .nav-item.active { background: var(--lab-secondary); color: var(--lab-on-secondary); box-shadow: none; }
html[data-theme] .nav-item:hover:not(.active) { background: var(--lab-soft); color: var(--lab-ink); }
html[data-theme] .nav-count { color: inherit; font-size: 11px; }
html[data-theme] .workspace { margin-left: 230px; }
html[data-theme] .topbar { background: var(--lab-paper); color: var(--lab-ink); border-bottom: 1px solid var(--lab-border); height: auto; min-height: 78px; padding: 14px 32px; gap: 16px; }
html[data-theme] .topbar-right { gap: 12px; }
html[data-theme] #page-label { font-size: 14px; color: var(--lab-muted); }
html[data-theme] main { max-width: 1500px; padding: 26px 32px 0; }
html[data-theme] h1 { font-family: Bahnschrift, "Arial Narrow", "Segoe UI", sans-serif; font-size: clamp(2rem, 3.2vw, 3.3rem); line-height: 1.08; letter-spacing: -.04em; font-weight: 800; color: inherit; margin: 0 0 12px; }
html[data-theme] h2, html[data-theme] h3, html[data-theme] h4 { color: var(--lab-ink); }
html[data-theme] .page-intro { gap: 24px; padding: 10px 0 28px; align-items: center; }
html[data-theme] .page-intro p { color: inherit; font-size: 15px; max-width: 48ch; }
html[data-theme] .playground-intro { padding: 0 0 22px; background: transparent; color: var(--lab-canvas-ink); border-radius: 0; margin: 0; }
html[data-theme] .intro-actions { padding-top: 0; flex-wrap: wrap; flex-shrink: 1; justify-content: end; }
html[data-theme] .button { min-height: 44px; font-size: 13px; font-weight: 650; padding: 11px 16px; border-radius: 9px; gap: 8px; white-space: normal; }
html[data-theme] .button.primary { color: var(--lab-on-primary); background: var(--lab-primary); border: 1px solid var(--lab-primary); box-shadow: none; }
html[data-theme] .button.primary:hover { filter: brightness(.94); }
html[data-theme] .button.secondary { color: var(--lab-ink); background: var(--lab-paper); border: 1px solid var(--lab-border); box-shadow: none; }
html[data-theme] .button.secondary:hover { background: var(--lab-soft); }
html[data-theme] .icon-button { width: 44px; height: 44px; flex-shrink: 0; color: var(--lab-ink); background: var(--lab-paper); border-radius: 9px; }
html[data-theme] .icon-button:hover { background: var(--lab-soft); }
html[data-theme] .mode-control { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 4px; border-radius: 999px; }
html[data-theme] .mode-control::before { box-sizing: border-box; }
html[data-theme] .mode-control::before, html[data-theme] .mode-control::after { display: block; }
html[data-theme] .mode-control button { position: relative; min-height: 40px; min-width: 82px; color: var(--lab-muted); font-size: 13px; padding: 8px 12px; border-radius: 999px; z-index: auto; }
html[data-theme] .mode-control button.active { background: transparent; color: var(--lab-ink); font-weight: 750; box-shadow: none; }
html[data-theme] .device-toolbar { background: var(--lab-paper); color: var(--lab-ink); border: 1px solid var(--lab-border); border-radius: 12px; padding: 12px 16px; margin: 0 0 28px; flex-wrap: wrap; gap: 12px; }
html[data-theme] .device-toolbar label { font-size: 12px; color: var(--lab-muted); display: flex; flex-direction: row; align-items: center; gap: 12px; }
html[data-theme] select, html[data-theme] dialog input:not([type="range"]), html[data-theme] #login-password { min-height: 44px; max-width: 100%; border: 1px solid var(--lab-border); border-radius: 7px; color: var(--lab-ink); background: var(--lab-paper); padding: 8px; font-size: 16px; }
html[data-theme] .device-presence { color: var(--lab-ink); font-size: 12px; background: var(--lab-soft); border-radius: 6px; padding: 9px; }
html[data-theme] .device-summary { background: var(--lab-soft); border: 1px solid var(--lab-border); padding: 14px; border-radius: 12px; }
html[data-theme] .device-summary p, html[data-theme] .connection-label, html[data-theme] .device-heading > span, html[data-theme] .device-heading .icon { color: var(--lab-ink); font-size: 12px; }
html[data-theme] .status-dot { background: var(--lab-primary-text); box-shadow: none; animation: none; }
html[data-theme] .status-dot.neutral { background: var(--lab-muted); }
html[data-theme] .sidebar-account, html[data-theme] .sidebar-account summary, html[data-theme] .account-menu-items { background: var(--lab-paper); color: var(--lab-ink); border-color: var(--lab-border); }
html[data-theme] .account-caption { color: var(--lab-muted); font-size: 11px; }
html[data-theme] .account-avatar { color: var(--lab-on-secondary); background: var(--lab-secondary); }
html[data-theme] .account-menu-items button { color: var(--lab-ink); min-height: 44px; font-size: 14px; }
html[data-theme] .account-menu-items button:hover { background: var(--lab-soft); }
.source-heading { display: none !important; }
html[data-theme] .data-source-label { background: var(--lab-soft); color: var(--lab-ink); border: 1px solid var(--lab-border); font-size: 11px; padding: 3px 7px; }
.workspace-heading { display: flex; justify-content: space-between; gap: 18px; align-items: start; margin: 0 0 18px; }
.workspace-heading h2 { font-size: 23px; letter-spacing: -.035em; line-height: 1.2; margin: 0 0 8px; }
html[data-theme] .workspace-heading h2, html[data-theme] #inventory-count, html[data-theme] .large-count { color: var(--lab-canvas-ink); }
.workspace-heading p { font-size: 13px; line-height: 1.6; color: inherit; margin: 0; }
.layout-state { display: inline-block; font-size: 12px; line-height: 1.5; font-weight: 650; text-align: right; max-width: 23ch; color: var(--lab-canvas-ink); }
.layout-state[data-editing="true"] { background: var(--lab-accent); color: var(--lab-on-accent); padding: 8px 12px; border-radius: 7px; }
.builder-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-bottom: 22px; align-items: start; }
.builder-toolbar > div { display: flex; flex-wrap: wrap; gap: 8px; }
.workspace-templates { max-width: 100%; position: relative; }
.workspace-templates > summary { padding: 11px 14px; border: 1px solid var(--lab-border); border-radius: 8px; background: var(--lab-paper); color: var(--lab-ink); cursor: pointer; min-height: 44px; font-size: 13px; }
.workspace-templates > div { display: flex; flex-direction: column; position: absolute; top: 100%; right: 0; min-width: 230px; z-index: 15; background: var(--lab-paper); color: var(--lab-ink); border: 1px solid var(--lab-border); padding: 8px; border-radius: 8px; box-shadow: 0 8px 20px #0002; }
.workspace-templates button { background: transparent; color: inherit; min-height: 44px; padding: 10px; text-align: left; }
.workspace-templates button:hover { background: var(--lab-soft); }
.builder-catalog { background: var(--lab-paper); color: var(--lab-ink); border: 1px solid var(--lab-border); padding: 20px; border-radius: 12px; margin-bottom: 24px; }
.catalog-heading { display: flex; justify-content: space-between; align-items: start; gap: 20px; flex-wrap: wrap; }
.catalog-heading h3 { margin: 0 0 6px; font-size: 18px; }
.catalog-heading p { max-width: 60ch; margin: 0 0 18px; font-size: 13px; color: var(--lab-muted); }
#widget-catalog { display: flex; flex-wrap: wrap; gap: 8px; }
.catalog-item { display: flex; flex-direction: column; gap: 3px; text-align: left; min-height: 58px; border: 1px solid var(--lab-border); padding: 10px 14px; border-radius: 8px; background: var(--lab-paper); color: var(--lab-ink); }
.catalog-item span { font-size: 13px; font-weight: 650; }
.catalog-item small { font-size: 11px; }
.catalog-item[aria-pressed="true"] { background: var(--lab-secondary); color: var(--lab-on-secondary); }
.tips-option { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 13px; }
.tips-option input { width: 20px; height: 20px; accent-color: var(--lab-primary); }
.widget-board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; align-items: stretch; }
.lab-widget { grid-column: span var(--widget-width, 1); display: flex; flex-direction: column; min-width: 0; background: var(--lab-paper); color: var(--lab-ink); border: 1px solid var(--lab-border); border-radius: var(--lab-radius); }
html[data-lab-style="outlined"] .lab-widget { border-width: 2px; }
html[data-lab-style="playful"] .lab-widget-sensor .sensor-heading .icon { color: var(--lab-on-secondary); background: var(--lab-secondary); padding: 7px; width: 36px; height: 36px; border-radius: 9px; }
html[data-lab-style="flat"] .lab-widget { border: 1px solid var(--lab-border); border-radius: 8px; box-shadow: none; }
.lab-widget[data-height="tall"] > .widget-content { min-height: 390px; }
.widget-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
html[data-theme] .lab-widget .panel, html[data-theme] .lab-widget .sensor-card { background: transparent; border: 0; border-radius: 0; padding: 22px; box-shadow: none; color: var(--lab-ink); margin: 0; flex: 1; }
html[data-theme] .lab-widget .sensor-card { overflow: visible; --chart: var(--lab-primary-text); display: flex; flex-direction: column; }
html[data-theme] .sensor-name { font-size: 14px; color: var(--lab-ink); font-weight: 650; white-space: normal; gap: 8px; }
html[data-theme] .sensor-source { color: var(--lab-muted); font-size: 10px; letter-spacing: 0; text-align: right; white-space: normal; font-family: inherit; }
html[data-theme] .sensor-reading { font-family: Bahnschrift, "Segoe UI", sans-serif; font-size: clamp(2.3rem, 3.5vw, 3.4rem); font-weight: 600; letter-spacing: -.04em; margin: 20px 0 14px; }
html[data-theme] .sensor-unit { color: var(--lab-muted); font-size: 18px; }
html[data-theme] .sensor-footer > span { font-size: 12px; color: var(--lab-muted); white-space: normal; }
html[data-theme] .sparkline { width: 90px; max-width: 100%; height: 38px; }
html[data-theme] .sparkline polyline { stroke: var(--lab-primary-text); stroke-width: 2; }
.sensor-data-status { font-size: 11px; line-height: 1.6; margin: 14px 0 0; color: var(--lab-muted); }
.sensor-visual { display: none; }
.widget-tip { border-top: 1px solid var(--lab-border); font-size: 12px; line-height: 1.7; margin: 0; padding: 12px 20px; color: var(--lab-muted); }
.lab-widget[data-view="chart"] .sparkline { width: 100%; height: 75px; }
.lab-widget[data-view="chart"] .sensor-footer { flex-direction: column; align-items: start; gap: 12px; }
.lab-widget:not([data-view="chart"]) .sparkline { display: none; }
.lab-widget[data-view="gauge"] .sensor-visual, .lab-widget[data-view="thermometer"] .sensor-visual, .lab-widget[data-view="progress"] .sensor-visual, .lab-widget[data-view="indicator"] .sensor-visual { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.sensor-scale { font-size: 11px; color: var(--lab-muted); }
.sensor-meter { height: 14px; border: 1px solid var(--lab-border); background: var(--lab-soft); border-radius: 4px; overflow: hidden; }
.sensor-meter > span { display: block; height: 100%; width: var(--sensor-percent); background: var(--lab-primary-text); }
.lab-widget[data-view="gauge"] .sensor-meter { width: 146px; height: 74px; max-width: 100%; margin: 0 auto; background: var(--lab-soft); border-radius: 80px 80px 0 0; position: relative; overflow: hidden; }
.lab-widget[data-view="gauge"] .sensor-meter > span { position: absolute; left: calc(50% - 2px); bottom: 0; height: 60px; width: 4px; transform: rotate(var(--sensor-angle)); transform-origin: 50% 100%; background: var(--lab-primary-text); }
.lab-widget[data-view="thermometer"] .sensor-meter { height: 95px; width: 24px; border-radius: 12px; position: relative; }
.lab-widget[data-view="thermometer"] .sensor-meter > span { position: absolute; bottom: 0; width: 100%; height: var(--sensor-percent); }
.lab-widget[data-view="indicator"] .sensor-meter { height: 85px; width: 100%; position: relative; }
.lab-widget[data-view="indicator"] .sensor-meter > span { position: absolute; bottom: 0; width: 100%; height: var(--sensor-percent); }
.no-data .sensor-meter > span { visibility: hidden; }
html[data-theme] .water-track { display: none; }
html[data-theme] .lab-widget h3 { font-size: 17px; font-weight: 700; letter-spacing: -.025em; }
html[data-theme] .panel-heading p, html[data-theme] .compact-label p, html[data-theme] .panel-footnote { color: var(--lab-muted); font-size: 12px; line-height: 1.7; }
html[data-theme] .panel-heading p { margin-top: 6px; }
html[data-theme] .panel-footnote { margin-top: 16px; }
html[data-theme] .text-button { color: var(--lab-primary-text); font-size: 12px; min-height: 44px; font-weight: 650; }
html[data-theme] .component-tag { color: var(--lab-muted); background: var(--lab-soft); border: 1px solid var(--lab-border); font-size: 11px; }
html[data-theme] .led-summary { color: var(--lab-muted); font-size: 12px; margin-top: 18px; }
html[data-theme] .led-summary strong { color: var(--lab-ink); }
html[data-theme] .led-row { border-color: var(--lab-border); gap: 10px; }
html[data-theme] .led-row-copy strong { color: var(--lab-ink); font-size: 14px; }
html[data-theme] .led-row-copy > span { color: var(--lab-muted); font-size: 12px; }
html[data-theme] .led-row-actions button { color: var(--lab-primary-text); background: transparent; font-size: 12px; min-height: 44px; }
html[data-theme] .led-visual { background: var(--lab-soft); }
html[data-theme] .relay-channel { border-color: var(--lab-border); background: var(--lab-paper); padding: 13px; border-radius: 10px; }
html[data-theme] .relay-name h4 { color: var(--lab-ink); font-size: 14px; }
html[data-theme] .relay-name > span, html[data-theme] .relay-code { color: var(--lab-muted); font-size: 12px; }
html[data-theme] .relay-number { color: var(--lab-on-secondary); background: var(--lab-secondary); font-size: 12px; }
html[data-theme] .relay-circuit { color: var(--lab-muted); }
html[data-theme] .relay-circuit.connected { color: var(--lab-primary-text); }
html[data-theme] .switch { width: 48px; min-width: 48px; height: 28px; border: 1px solid var(--lab-border); background: var(--lab-muted); padding: 3px; }
html[data-theme] .switch > span { width: 20px; height: 20px; background: #fff; }
html[data-theme] .switch[aria-checked="true"] { background: var(--lab-primary); border-color: var(--lab-primary); }
html[data-theme] .switch[aria-checked="true"] > span { transform: translateX(19px); background: var(--lab-on-primary); }
html[data-theme] .switch::after { inset: -9px -1px; }
html[data-theme] .servo-readout, html[data-theme] .servo-readout > span, html[data-theme] #servo-value { color: var(--lab-ink); }
html[data-theme] .servo-readout small { color: var(--lab-muted); }
html[data-theme] .servo-presets { gap: 8px; }
html[data-theme] .servo-presets button { min-height: 48px; color: var(--lab-ink); background: var(--lab-paper); border: 1px solid var(--lab-border); font-size: 12px; }
html[data-theme] .servo-presets button span { color: inherit; font-size: 12px; }
html[data-theme] .servo-presets button.selected { color: var(--lab-on-secondary); background: var(--lab-secondary); border-color: var(--lab-border); }
html[data-theme] .range { accent-color: var(--lab-primary); min-height: 44px; }
html[data-theme] .compact-label h3 { color: var(--lab-ink); }
html[data-theme] .mini-icon { background: var(--lab-secondary); color: var(--lab-on-secondary); }
html[data-theme] .control-status, html[data-theme] .control-lock-note { color: var(--lab-muted); font-size: 12px; line-height: 1.7; }
html[data-theme] .controls-locked { opacity: 1; }
.command-feedback { margin: 16px 0 0; padding: 10px; color: var(--lab-ink); background: var(--lab-soft); border-radius: 7px; font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.command-feedback[data-state="error"] { border: 1px solid var(--lab-border); }
.widget-tools { padding: 12px; border-bottom: 1px solid var(--lab-border); background: var(--lab-soft); border-radius: var(--lab-radius) var(--lab-radius) 0 0; }
.widget-tool-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: end; justify-content: start; }
.widget-tool-row + .widget-tool-row { margin-top: 8px; }
.widget-tool-row button { min-height: 44px; background: var(--lab-paper); color: var(--lab-ink); border: 1px solid var(--lab-border); padding: 7px 10px; border-radius: 6px; font-size: 12px; }
.widget-tool-row .drag-handle { background: transparent; border-color: transparent; display: flex; align-items: center; gap: 8px; cursor: grab; font-size: 19px; font-weight: 700; }
.drag-handle span { font-size: 12px; }
.widget-tool-row label { font-size: 11px; display: flex; flex-direction: column; color: var(--lab-muted); }
html[data-theme] .widget-tool-row select { font-size: 12px; min-height: 44px; padding: 7px; }
.widget-dragging { border-style: dashed; }
.widget-board[data-editing="true"] .widget-content { opacity: .68; user-select: none; pointer-events: none; }
.widget-board[data-editing="true"] .lab-widget { outline: 1px dashed var(--lab-border); outline-offset: 3px; }
.workspace-empty { padding: 32px; border: 1px dashed var(--lab-border); font-size: 15px; line-height: 1.8; }
html[data-theme] .simulation-note { color: var(--lab-canvas-ink); background: transparent; border-top: 1px solid var(--lab-border); padding: 22px 0; margin-top: 28px; font-size: 12px; line-height: 1.7; }
html[data-theme] .simulation-note a { color: inherit; text-decoration: underline; text-underline-offset: 3px; min-height: 44px; display: inline-flex; align-items: center; }
html[data-theme] .page-footer { color: var(--lab-canvas-ink); border-color: var(--lab-border); padding-bottom: 25px; font-size: 12px; }
html[data-theme] .inventory-row, html[data-theme] .activity-panel, html[data-theme] .guide-main, html[data-theme] .guide-aside { background: var(--lab-paper); color: var(--lab-ink); border-color: var(--lab-border); border-radius: 12px; }
html[data-theme] .inventory-description h2 { font-size: 17px; }
html[data-theme] .inventory-description p, html[data-theme] .guide-main p, html[data-theme] .guide-aside p, html[data-theme] .guide-aside dd { color: var(--lab-muted); font-size: 14px; }
html[data-theme] .inventory-icon, html[data-theme] .guide-step > span { background: var(--lab-secondary); color: var(--lab-on-secondary); }
html[data-theme] .category-tag, html[data-theme] .section-note, html[data-theme] .inventory-number { color: var(--lab-muted); font-size: 12px; }
html[data-theme] .filter-button { min-height: 44px; padding: 10px 14px; color: var(--lab-ink); border: 1px solid var(--lab-border); background: var(--lab-paper); font-size: 13px; }
html[data-theme] .filter-button.selected { color: var(--lab-on-primary); background: var(--lab-primary); }
html[data-theme] .eyebrow { color: inherit; letter-spacing: .03em; font-size: 11px; margin-bottom: 10px; }
html[data-theme] .eyebrow > span { display: none; }
html[data-theme] .activity-info { color: var(--lab-canvas-ink); font-size: 14px; }
html[data-theme] .activity-row { border-color: var(--lab-border); padding: 15px; }
html[data-theme] .activity-row p { color: var(--lab-ink); font-size: 14px; }
html[data-theme] .activity-row time, html[data-theme] .activity-row .log-type { color: var(--lab-muted); font-size: 12px; }
html[data-theme] .activity-table-heading { background: var(--lab-soft); color: var(--lab-ink); font-size: 12px; }
.activity-empty { padding: 24px; font-size: 15px; line-height: 1.8; color: var(--lab-ink); }
.status-page { padding: 28px; background: var(--lab-paper); color: var(--lab-ink); border: 1px solid var(--lab-border); border-radius: var(--lab-radius); }
.status-page h2 { font-size: 24px; margin-top: 0; }
.status-page dl { display: grid; grid-template-columns: minmax(100px, 1fr) 3fr; gap: 0; }
.status-page dt, .status-page dd { border-top: 1px solid var(--lab-border); margin: 0; padding: 14px 0; font-size: 14px; }
.status-page dd { padding-left: 12px; overflow-wrap: anywhere; }
.status-page p { font-size: 14px; line-height: 1.8; }
html[data-theme] .guide-step h3, html[data-theme] .guide-aside dt { color: var(--lab-ink); font-size: 16px; }
html[data-theme] .guide-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: stretch; }
html[data-theme] .guide-main, html[data-theme] .guide-aside { min-width: 0; padding: 28px; border: 1px solid var(--lab-border); }
html[data-theme] .guide-grid h2 { margin: 0 0 20px; line-height: 1.4; }
html[data-theme] .guide-step { gap: 16px; border-color: var(--lab-border); }
html[data-theme] .guide-step > span { display: grid; place-items: center; flex: 0 0 32px; height: 32px; padding: 0; border-radius: 6px; }
html[data-theme] .guide-step > div { min-width: 0; }
html[data-theme] .guide-main > .button { margin-left: 48px; }
@media (max-width: 1100px) {
  html[data-theme] .guide-grid { grid-template-columns: minmax(0, 1fr); }
}
html[data-theme] dialog { background: var(--lab-paper); color: var(--lab-ink); border: 1px solid var(--lab-border); border-radius: 18px; max-width: calc(100vw - 28px); max-height: calc(100dvh - 36px); overflow-y: auto; box-shadow: 0 16px 60px #0003; padding: 24px; }
dialog::backdrop { background: #101e2e66; backdrop-filter: none; }
html[data-theme] dialog p, html[data-theme] dialog label { color: var(--lab-muted); font-size: 14px; }
html[data-theme] dialog h2 { font-size: 24px; letter-spacing: -.03em; }
html[data-theme] .toast { background: var(--lab-primary); color: var(--lab-on-primary); border: 1px solid var(--lab-on-primary); font-size: 14px; max-width: calc(100vw - 32px); line-height: 1.6; }
#studio-dialog { width: min(620px, calc(100vw - 28px)); margin: auto 20px auto auto; padding: 24px; }
.studio-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.studio-heading h2 { margin: 0 0 8px; }
.studio-heading p { margin: 0; line-height: 1.7; }
.studio-presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 24px 0; }
.studio-presets button { min-height: 66px; display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px; background: var(--lab-paper); color: var(--lab-ink); border: 1px solid var(--lab-border); border-radius: 9px; font-size: 13px; }
.studio-presets button[aria-pressed="true"] { outline: 2px solid var(--lab-ink); outline-offset: 2px; }
.preset-swatch { height: 30px; width: 30px; flex: 0 0 30px; border: 7px solid var(--swatch-soft); background: var(--swatch); border-radius: 9px; }
.studio-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
html[data-theme] .color-field { display: grid; grid-template-columns: 1fr 44px; align-items: center; font-size: 13px; }
.color-field span { grid-column: 1 / -1; font-size: 11px; font-family: Consolas, monospace; }
html[data-theme] .color-field input[type="color"] { height: 44px; min-height: 44px; width: 44px; padding: 3px; background: var(--lab-paper); cursor: pointer; }
.studio-options { display: flex; flex-wrap: wrap; gap: 14px; margin: 24px 0 10px; }
.studio-options label { display: flex; flex: 1 1 130px; flex-direction: column; gap: 6px; min-width: 0; }
.studio-options input[type="range"] { accent-color: var(--lab-primary); min-height: 44px; width: 100%; }
.studio-options output { font-size: 12px; }
.studio-note { font-size: 12px; line-height: 1.7; }
.studio-preview { display: flex; flex-direction: column; gap: 10px; padding: 22px; margin: 22px 0; border-radius: var(--lab-radius); border: 1px solid var(--lab-border); background: var(--lab-secondary); color: var(--lab-on-secondary); }
.studio-preview > span:first-child { font-size: 12px; }
.studio-preview strong { font-family: Bahnschrift, "Segoe UI", sans-serif; font-size: 27px; line-height: 1.2; letter-spacing: -.03em; }
.preview-color { color: var(--lab-on-accent); background: var(--lab-accent); padding: 8px 12px; border-radius: 6px; width: fit-content; font-size: 12px; }
html[data-theme] .studio-storage { font-size: 12px; line-height: 1.7; }
.studio-footer { display: flex; flex-wrap: wrap; justify-content: end; gap: 8px; border-top: 1px solid var(--lab-border); padding-top: 18px; }
html[data-theme] .login-page { background: var(--lab-background); color: var(--lab-canvas-ink); }
html[data-theme] .login-layout { max-width: 1040px; gap: 48px; }
html[data-theme] .login-brand { color: inherit; }
html[data-theme] .login-brand p { font-size: 22px; font-weight: 700; color: inherit; }
html[data-theme] .login-brand p span { color: inherit; font-size: 14px; }
html[data-theme] .login-card { border: 1px solid var(--lab-border); border-radius: var(--lab-radius); padding: 32px; background: var(--lab-paper); color: var(--lab-ink); box-shadow: none; }
html[data-theme] .login-card h1 { font-size: 32px; color: var(--lab-ink); }
html[data-theme] .login-card p, html[data-theme] .login-card label { font-size: 14px; line-height: 1.7; color: var(--lab-muted); }
html[data-theme] .login-card input { min-height: 48px; font-size: 16px; }
html[data-theme] #login-error { color: var(--lab-ink); font-weight: 600; }
html[data-theme] .mobile-connection-details { color: var(--lab-ink); background: var(--lab-soft); }
html[data-theme] .mobile-connection-details summary { min-height: 44px; padding: 10px; }
html[data-theme] .mobile-bottom-nav { color: var(--lab-ink); width: calc(100% - 48px); max-width: 360px; left: 0; right: 0; border-radius: 999px; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; }
html[data-theme] .mobile-bottom-nav::before, html[data-theme] .mobile-bottom-nav::after { display: block; }
html[data-theme] .mobile-bottom-nav::before { width: calc((100% - 12px) / 5); }
html[data-theme] .mobile-bottom-nav .nav-item { background: transparent; color: var(--lab-muted); font-size: 10px; min-height: 52px; padding: 5px 3px; border-radius: 999px; min-width: 0; }
html[data-theme] .mobile-bottom-nav .nav-item.active { color: var(--lab-ink); background: transparent; font-weight: 750; }
html[data-theme] body.sidebar-collapsed .workspace { margin-left: 82px; }
html[data-theme] body.sidebar-collapsed .sidebar { width: 82px; }
@media (max-width: 1180px) {
  .widget-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lab-widget { grid-column: span min(2, var(--widget-width)); }
  html[data-theme] .playground-intro { flex-wrap: wrap; }
  html[data-theme] .intro-actions { justify-content: start; }
  html[data-theme] .led-row { flex-wrap: wrap; }
  html[data-theme] .led-row-actions { order: 4; width: 100%; }
}
@media (max-width: 760px) {
  html[data-theme] .workspace, html[data-theme] body.sidebar-collapsed .workspace { margin-left: 0; }
  html[data-theme] .sidebar, html[data-theme] body.sidebar-collapsed .sidebar { width: min(340px, calc(100vw - 32px)); }
  html[data-theme] main { padding: 22px 18px 0; padding-bottom: calc(94px + env(safe-area-inset-bottom)); }
  html[data-theme] .topbar { min-height: 72px; padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); gap: 8px; flex-wrap: wrap; }
  html[data-theme] .topbar-right { gap: 6px; margin-left: auto; }
  html[data-theme] .mobile-header-brand { display: flex; }
  html[data-theme] .sidebar > .brand { display: none; }
  html[data-theme] .topbar .brand-logo { width: 144px; height: auto; flex-basis: auto; }
  html[data-theme] .topbar .brand-name { font-size: 15px; }
  html[data-theme] .topbar .brand-name > span { margin-top: 4px; font-size: 8px; }
  html[data-theme] .mode-control button { min-width: 63px; min-height: 44px; padding: 8px; font-size: 12px; }
  html[data-theme] .topbar .theme-toggle { width: 44px; }
  html[data-theme] .playground-intro { padding: 0 0 20px; margin: 0; }
  html[data-theme] h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); }
  html[data-theme] .page-intro p { font-size: 14px; }
  html[data-theme] .intro-actions { gap: 8px; }
  html[data-theme] .button { font-size: 12px; padding: 10px 12px; }
  html[data-theme] .device-toolbar { margin-bottom: 26px; padding: 12px; }
  .workspace-heading { flex-direction: column; gap: 10px; }
  .layout-state { max-width: none; text-align: left; }
  .workspace-heading h2 { font-size: 23px; }
  .widget-board { gap: 14px; }
  html[data-theme] .lab-widget .panel, html[data-theme] .lab-widget .sensor-card { padding: 18px; }
  .widget-tip { padding: 10px 18px; }
  html[data-theme] .sensor-heading { flex-wrap: wrap; }
  html[data-theme] .sensor-source { text-align: left; }
  html[data-theme] .sensor-reading { font-size: 2.5rem; }
  .builder-toolbar { margin-bottom: 18px; }
  .workspace-templates { width: 100%; }
  .workspace-templates > div { position: static; width: 100%; min-width: 0; margin-top: 6px; box-shadow: none; }
  .builder-catalog { padding: 16px; }
  .builder-toolbar > div { width: 100%; }
  .widget-tool-row { gap: 8px; }
  html[data-theme] .inventory-row { padding: 16px 12px; }
  html[data-theme] .inventory-toolbar { align-items: start; flex-direction: column; gap: 14px; }
  html[data-theme] .filter-group { gap: 6px; flex-wrap: wrap; }
  html[data-theme] .large-count { font-size: 35px; }
  html[data-theme] .guide-main, html[data-theme] .guide-aside { padding: 22px; }
  html[data-theme] .activity-row { grid-template-columns: 60px 8px 1fr; gap: 8px; }
  html[data-theme] .activity-row .log-type { grid-column: 3; }
  html[data-theme] .simulation-note { flex-wrap: wrap; }
  #studio-dialog { margin: auto; padding: 18px; }
  .studio-footer { justify-content: start; }
  html[data-theme] .login-layout { gap: 20px; }
  html[data-theme] .login-card { padding: 24px; }
  html[data-theme] .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
}
@media (max-width: 540px) {
  .widget-board { grid-template-columns: minmax(0, 1fr); }
  .lab-widget { grid-column: 1 / -1; }
  .studio-fields { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .studio-heading > div { min-width: 0; }
  .studio-presets button { padding: 10px 8px; gap: 8px; font-size: 12px; }
  .preset-swatch { width: 22px; height: 22px; flex-basis: 22px; border-width: 5px; }
  html[data-theme] .widget-tool-row select, html[data-theme] .studio-options select { font-size: 16px; max-width: 100%; }
  .dialog-actions { flex-wrap: wrap; }
  html[data-theme] .device-toolbar label { width: 100%; min-width: 0; }
  html[data-theme] .device-toolbar select { flex: 1; min-width: 0; max-width: 100%; font-size: 16px; }
  .lab-widget-sensor .sensor-heading { flex-wrap: nowrap; }
  html[data-theme] .topbar .brand-name { display: block; font-size: 13px; }
  html[data-theme] .sensor-reading { font-size: 3rem; }
  html[data-theme] .sensor-footer { justify-content: start; }
  html[data-theme] .page-intro:not(.playground-intro) { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .lab-widget, .button, .widget-tools, .mode-control { border: 1px solid ButtonText !important; }
}

body:has(dialog[open]) { overflow: hidden; }

@media (max-width: 360px) {
  html[data-theme] .topbar { padding-inline: 12px; gap: 6px; }
  html[data-theme] .topbar .brand-name { font-size: 12px; }
  html[data-theme] .mode-control button { min-width: 0; padding-inline: 4px; font-size: 11px; }
}

html[data-theme] .mode-control, html[data-theme] .mobile-bottom-nav {
  background: var(--lab-paper);
  background: color-mix(in srgb, var(--lab-paper) 82%, transparent);
  border: 1px solid color-mix(in srgb, var(--lab-border) 55%, var(--lab-paper));
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 5px 18px #00000012, inset 0 1px 1px #ffffff70;
}
html[data-theme] .mode-control::before, html[data-theme] .mobile-bottom-nav::before {
  border-radius: 999px;
  background: var(--lab-secondary);
  background: color-mix(in srgb, var(--lab-secondary) 84%, var(--lab-paper));
  border: 1px solid color-mix(in srgb, var(--lab-border) 45%, var(--lab-paper));
  box-shadow: inset 0 1px 2px #ffffffa0, 0 2px 5px #00000012;
}
@media (prefers-reduced-transparency: reduce) {
  html[data-theme] .mode-control, html[data-theme] .mobile-bottom-nav { background: var(--lab-paper); backdrop-filter: none; -webkit-backdrop-filter: none; }
}

html[data-lab-style="playful"] .lab-widget,
html[data-lab-style="playful"] .inventory-row,
html[data-lab-style="playful"] .activity-panel,
html[data-lab-style="playful"] .guide-main,
html[data-lab-style="playful"] .guide-aside,
html[data-lab-style="playful"] .status-page,
html[data-lab-style="playful"] .studio-preview {
  border: 2px solid var(--lab-ink);
  border-radius: min(var(--lab-radius), 6px);
  box-shadow: 4px 4px 0 var(--lab-ink);
}
html[data-lab-style="playful"] .button {
  border: 2px solid var(--lab-ink);
  border-radius: 3px;
  box-shadow: 3px 3px 0 var(--lab-ink);
  font-weight: 750;
}
html[data-lab-style="playful"] .button:active { box-shadow: 1px 1px 0 var(--lab-ink); transform: translate(2px, 2px); }
html[data-lab-style="playful"] .workspace-heading h2,
html[data-lab-style="playful"] .page-intro h1 { font-weight: 850; letter-spacing: -.04em; }
html[data-lab-style="flat"] .workspace { font-family: "Segoe UI", Arial, sans-serif; }
html[data-lab-style="flat"] .button { border-radius: 6px; box-shadow: none; font-weight: 600; }
html[data-lab-style="flat"] .inventory-row,
html[data-lab-style="flat"] .activity-panel,
html[data-lab-style="flat"] .guide-main,
html[data-lab-style="flat"] .guide-aside,
html[data-lab-style="flat"] .studio-preview { border-radius: 8px; box-shadow: none; }

html[data-lab-style="playful"] #studio-dialog {
  border: 2px solid var(--lab-ink);
  border-radius: 4px;
  box-shadow: 6px 6px 0 var(--lab-ink);
}
html[data-lab-style="playful"] .studio-presets button,
html[data-lab-style="playful"] .studio-heading .icon-button {
  border: 2px solid var(--lab-ink);
  border-radius: 3px;
}
html[data-lab-style="playful"] .studio-heading h2 { font-weight: 850; letter-spacing: -.04em; }
html[data-lab-style="flat"] #studio-dialog { border-radius: 8px; box-shadow: 0 8px 24px #0002; }

html[data-theme="dark"] .brand-logo, html[data-theme="dark"] .login-logo-card img {
  filter: invert(1) hue-rotate(180deg);
  mix-blend-mode: screen;
}
