/* lucid lab — shared styles. The homepage's look (public/home/home.css): dark, neon cyan to
   purple, the Lucid wordmark, cards. The chrome (header, footer, keys hint) comes from
   lab/shared/chrome.js; the side panel from lab/shared/shell.js.

   Pages without a lab shell (01–07, 09) keep their own <style> block after this file. The rules
   for their stage, HUD, tools and notes below start with `html body` and name the element ids,
   so they outrank those blocks (an id rule there is 1,0,0; here 1,0,2) without editing the page. */

:root {
  --bg: #07060f;
  --ink: #e8e6f5;
  --text: #e8e6f5;
  --dim: #a7a3c4;
  --cyan: #22e6ff;
  --purple: #b44cff;
  --accent: #22e6ff;
  --line: rgba(140, 120, 255, .22);
  --border: rgba(140, 120, 255, .26);
  --border-strong: rgba(140, 120, 255, .45);
  --panel: #0e0b1f;
  --panel2: #151129;
  --glass: rgba(10, 8, 24, .82);
  --ok: #4fe0a0;
  --warn: #f2c95c;
  --bad: #ff5d7a;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --lab-head-h: 48px;
  --lab-foot-h: 30px;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
html body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 14px/1.5 var(--sans);
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(34, 230, 255, .12), transparent 60%),
    radial-gradient(900px 600px at 90% 10%, rgba(180, 76, 255, .14), transparent 60%),
    var(--bg);
}
a { color: var(--cyan); }
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--cyan); outline-offset: 2px;
}
code, kbd { font-family: var(--mono); }

/* ---- chrome: header ------------------------------------------------------------------ */

.lab-chrome-head {
  position: sticky; top: 0; z-index: 40;
  height: var(--lab-head-h);
  display: flex; align-items: center; gap: .6rem;
  padding: 0 1rem;
  white-space: nowrap;
  background: rgba(7, 6, 15, .86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.lab-chrome-mark {
  font-weight: 700; letter-spacing: .18em; text-transform: uppercase;
  text-decoration: none; color: var(--ink); text-shadow: 0 0 12px var(--cyan);
}
.lab-chrome-sep { color: var(--border-strong); }
.lab-chrome-crumb { color: var(--dim); text-decoration: none; }
.lab-chrome-crumb:hover { color: var(--cyan); }
.lab-chrome-title { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.lab-chrome-num {
  font: 600 12px var(--mono); color: var(--cyan);
  padding: 1px 8px; border: 1px solid rgba(34, 230, 255, .45); border-radius: 999px;
}
.lab-chrome-name {
  margin: 0; font-size: 15px; font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis;
}
.lab-chrome-nav { margin-left: auto; display: flex; align-items: center; gap: .2rem; }
.lab-chrome-nav a {
  color: var(--dim); text-decoration: none;
  padding: .25rem .6rem; border-radius: 8px; border: 1px solid transparent;
  transition: color .15s, border-color .15s;
}
.lab-chrome-nav a:hover, .lab-chrome-nav a:focus-visible { color: var(--cyan); border-color: var(--line); }
.lab-chrome-nav a[rel] { font-family: var(--mono); font-size: 13px; }

/* ---- chrome: footer ------------------------------------------------------------------ */

.lab-chrome-foot {
  padding: .7rem 1rem; text-align: center;
  color: var(--dim); font-size: 12px;
  border-top: 1px solid var(--line);
}
.lab-chrome-foot a { color: var(--dim); }
.lab-chrome-foot a:hover { color: var(--cyan); }

/* ---- status chips ---------------------------------------------------------------------- */

.lab-chip {
  display: inline-block; font: 11px/1.6 var(--mono);
  padding: 0 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--dim);
}
.lab-chip-webgpu { color: var(--cyan); border-color: rgba(34, 230, 255, .55); background: rgba(34, 230, 255, .07); }
.lab-chip-cpu { color: var(--warn); border-color: rgba(242, 201, 92, .5); background: rgba(242, 201, 92, .06); }
.lab-chip-stub { color: var(--dim); border-style: dashed; }

/* ---- full-screen stage pages (body.lab-full, set by chrome.js) ------------------------- */

body.lab-full { overflow: hidden; }
body.lab-full .lab-chrome-head { position: fixed; left: 0; right: 0; top: 0; }
body.lab-full .lab-chrome-foot,
body.lab-app .lab-chrome-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: var(--lab-foot-h); padding: 0 1rem;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  background: rgba(7, 6, 15, .86);
}
body.lab-full .lab-stage {
  position: fixed !important;
  top: var(--lab-head-h) !important; bottom: var(--lab-foot-h) !important;
  left: 0 !important; right: 0 !important; height: auto !important;
}

html body :is(#sculpt-view, #bricks-view, #meadow-view, #points-view, #flecks-view, #mesh-view, #temporal-view, #bvh-view, #gi-stage) {
  position: fixed; inset: 0; overflow: hidden; background: #000;
}
html body :is(#sculpt-view, #bricks-view, #meadow-view, #points-view, #flecks-view, #mesh-view, #temporal-view, #bvh-view) > canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none;
}

/* HUD: small, unobtrusive, top left. */
html body :is(#sculpt-hud, #bricks-hud, #meadow-hud, #points-hud, #flecks-hud, #mesh-hud, #temporal-hud, #bvh-hud, #gi-hud),
.lab-hud {
  position: absolute; top: 10px; left: 10px; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 2px 12px;
  max-width: min(55%, 44rem);
  padding: 4px 10px;
  font: 12px/1.6 var(--mono); color: var(--dim);
  background: rgba(7, 6, 15, .62);
  border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(4px);
  pointer-events: none;
}
html body :is(#sculpt-hud, #bricks-hud, #meadow-hud, #points-hud, #flecks-hud, #mesh-hud, #temporal-hud, #bvh-hud, #gi-hud) b,
.lab-hud span { color: var(--cyan); font-weight: 600; }
html body #temporal-hud .ok { color: var(--ok); }
html body #temporal-hud .bad { color: var(--bad); }

/* Tools: a floating card, top right. */
html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools, #temporal-legend) {
  position: absolute; top: 10px; right: 10px; left: auto; z-index: 6;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  max-width: min(40rem, 46%);
  padding: 8px 10px;
  font: 13px/1.4 var(--sans); color: var(--text);
  background: var(--glass);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  backdrop-filter: blur(6px);
}
html body #temporal-legend { display: block; color: var(--dim); font-size: 12px; max-width: min(28rem, 40%); }
html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) :is(button, select, input[type="number"]) {
  font: 13px var(--sans); color: var(--text);
  min-height: 30px; padding: 3px 10px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--border); border-radius: 8px;
}
html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) input[type="number"] { width: 5em; padding: 3px 6px; font-family: var(--mono); }
html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) button { cursor: pointer; transition: border-color .15s, color .15s, background .15s; }
html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) button:hover:not(:disabled) { border-color: var(--cyan); color: var(--cyan); }
html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) button[aria-pressed="true"] {
  color: var(--cyan); border-color: var(--cyan); background: rgba(34, 230, 255, .14);
  box-shadow: 0 0 12px rgba(34, 230, 255, .2);
}
html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) button:disabled { opacity: .38; cursor: not-allowed; }
html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) label {
  display: inline-flex; align-items: center; gap: 6px; color: var(--dim);
}
html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) [id$="-value"],
html body :is(#fleck-budget, #report-progress) {
  font: 12px var(--mono); color: var(--cyan); min-width: 3.2em;
}
html body :is(#report-run) {
  color: #07060f; font-weight: 600; border-color: transparent;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
}
html body :is(#report-run):hover:not(:disabled) { color: #07060f; box-shadow: 0 0 16px rgba(34, 230, 255, .35); }
html body #report-actions { display: inline-flex; gap: 8px; align-items: center; }
html body #report-actions a { color: var(--ok); }

/* The old in-page back links: the chrome header has them. */
body.lab-chromed :is(#sculpt-back, #bricks-back, #meadow-back, #points-back, #flecks-back, #mesh-back, #temporal-back, #bvh-back, #gi-back) { display: none; }

/* Notes and errors: a clear panel. JS shows them (display); position is the page's stage. */
html body :is(#sculpt-note, #bricks-note, #meadow-note, #points-note, #flecks-note, #mesh-note, #temporal-note, #bvh-note, #gi-note),
.lab-context-note {
  position: absolute; left: 50%; right: auto; bottom: 16px; z-index: 8;
  transform: translateX(-50%);
  width: min(40rem, calc(100% - 24px));
  padding: 12px 16px 12px 46px;
  font: 13px/1.5 var(--sans); color: var(--text);
  white-space: pre-line;
  background: rgba(38, 10, 30, .94);
  border: 1px solid var(--bad); border-radius: 12px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5), 0 0 24px rgba(255, 93, 122, .18);
}
html body :is(#sculpt-note, #bricks-note, #meadow-note, #points-note, #flecks-note, #mesh-note, #temporal-note, #bvh-note, #gi-note)::before,
.lab-context-note::before {
  content: '!'; position: absolute; left: 14px; top: 12px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--bad); color: #07060f;
  font: 700 13px/20px var(--sans); text-align: center;
}
/* An empty note is never shown, whatever a page's script set on it. */
html body :is(#sculpt-note, #bricks-note, #meadow-note, #points-note, #flecks-note, #mesh-note, #temporal-note, #bvh-note, #gi-note, #bench-note, #compare-note):empty,
.lab-context-note:empty { display: none !important; }
html body #needs-webgpu {
  top: 50%; bottom: auto; transform: translate(-50%, -50%);
  padding: 18px 22px 16px; z-index: 30;
  border-color: rgba(180, 76, 255, .7);
  background: rgba(16, 10, 36, .96);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55), 0 0 32px rgba(180, 76, 255, .25);
}
html body #needs-webgpu::before {
  content: 'WebGPU needed'; position: static; display: block;
  width: auto; height: auto; margin-bottom: 6px; border-radius: 0;
  background: none; color: var(--cyan);
  font: 700 13px/1.4 var(--sans); letter-spacing: .1em; text-transform: uppercase; text-align: left;
}
html body #needs-webgpu p { margin: 0 0 6px; }
html body #needs-webgpu p + p { color: var(--dim); font: 12px var(--mono); }

/* ---- keys hint ------------------------------------------------------------------------- */

.lab-keys {
  position: absolute; left: 10px; bottom: 10px; z-index: 6;
  max-width: calc(100% - 20px);
  font: 12px/1.5 var(--sans); color: var(--dim);
  background: rgba(7, 6, 15, .72);
  border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(4px);
}
.lab-keys summary { cursor: pointer; padding: 3px 10px; list-style: none; user-select: none; }
.lab-keys summary::-webkit-details-marker { display: none; }
.lab-keys summary::after { content: ' ▸'; color: var(--cyan); }
.lab-keys[open] summary::after { content: ' ▾'; }
.lab-keys dl { display: grid; grid-template-columns: auto auto; gap: 3px 10px; margin: 0; padding: 2px 10px 8px; }
.lab-keys dt, .lab-keys dd { margin: 0; }
.lab-keys kbd {
  font-size: 11px; color: var(--ink);
  padding: 0 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
  background: rgba(255, 255, 255, .05);
}
@media (hover: none) { .lab-keys { display: none; } }

/* The canvas shows when it has keyboard focus. */
canvas:focus { outline: none; }
canvas:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; }

/* ---- lab shell pages (00): canvas + side panel (body.lab-app) -------------------------- */

#lab-root { display: flex; flex-direction: column; }
.lab-main { display: flex; min-height: 0; }
body.lab-app .lab-main.lab-stage {
  position: fixed; top: var(--lab-head-h); bottom: var(--lab-foot-h); left: 0; right: 0;
}
.lab-viewport {
  flex: 1; position: relative; min-width: 0; min-height: 280px;
  background: radial-gradient(600px 400px at 50% 40%, rgba(180, 76, 255, .08), transparent 70%), #000;
}
.lab-viewport canvas { display: block; width: 100%; height: 100%; object-fit: contain; touch-action: none; }

.lab-side {
  width: 340px; flex-shrink: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
  background: rgba(10, 8, 24, .9);
  border-left: 1px solid var(--line);
}
.lab-card {
  padding: 12px 14px;
  background: linear-gradient(160deg, rgba(34, 230, 255, .045), rgba(180, 76, 255, .07));
  border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color .2s, box-shadow .2s;
}
.lab-card h2 {
  margin: 0 0 10px;
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--cyan);
}

.lab-controls { display: flex; flex-direction: column; gap: 8px; }
.lab-control {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px;
  font-size: 13px; color: var(--dim);
}
.lab-control input[type="number"], .lab-control select {
  width: 8rem; min-height: 30px;
  padding: 3px 8px;
  font: 12px var(--mono); color: var(--text);
  background: rgba(0, 0, 0, .35);
  border: 1px solid var(--border); border-radius: 8px;
}
.lab-control input[type="number"]:hover, .lab-control select:hover { border-color: var(--border-strong); }
.lab-control-check { display: flex; justify-content: flex-start; gap: 8px; cursor: pointer; }
input[type="checkbox"], input[type="range"] { accent-color: var(--cyan); }
input[type="range"] { cursor: pointer; }
.lab-control-btn { margin-top: 2px; align-self: flex-start; }
.lab-caption { color: var(--dim); font-size: 12px; padding: 4px 0 0; border-top: 1px dashed var(--line); }

table.lab-caps { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
table.lab-caps td, table.lab-caps th { padding: 4px 4px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
table.lab-caps td:first-child { width: 46%; color: var(--dim); font: 11px var(--mono); }
table.lab-caps td.cap-value { text-align: right; font-family: var(--mono); color: var(--text); }
table.lab-caps.lab-caps-collapsed tr.lab-cap-more { display: none; }
.lab-linkbtn {
  margin-top: 8px; padding: 2px 0;
  font: 12px var(--sans); color: var(--cyan);
  background: none; border: 0; cursor: pointer;
}
.lab-linkbtn:hover { text-decoration: underline; }
.lab-linkbtn[hidden] { display: none; }

.lab-metrics { display: flex; flex-direction: column; gap: 6px; }
.lab-metric {
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  padding: 5px 8px; font-size: 13px; color: var(--dim);
  background: rgba(0, 0, 0, .3); border-radius: 8px;
}
.metric-value { font-family: var(--mono); font-size: 12px; color: var(--cyan); text-align: right; overflow-wrap: anywhere; }
.metric-value:empty::after { content: '—'; }

/* Buttons: secondary by default; primary / danger by role. */
.lab-btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.lab-btnrow + .lab-btnrow, .bench-status + .lab-btnrow { margin-top: 8px; }
.lab-btn {
  min-height: 32px; padding: 5px 12px;
  font: 13px var(--sans); color: var(--text);
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--border); border-radius: 9px;
  cursor: pointer;
  transition: border-color .15s, color .15s, box-shadow .15s, opacity .15s;
}
.lab-btn:hover:not(:disabled) { border-color: var(--cyan); color: var(--cyan); }
.lab-btn-primary, #btn-start, #btn-matrix, #wg-run {
  color: #07060f; font-weight: 600; border-color: transparent;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
}
.lab-btn-primary:hover:not(:disabled), #btn-start:hover:not(:disabled), #btn-matrix:hover:not(:disabled), #wg-run:hover:not(:disabled) {
  color: #07060f; box-shadow: 0 0 16px rgba(34, 230, 255, .35), 0 0 26px rgba(180, 76, 255, .2);
}
.lab-btn-danger, #btn-stop { color: var(--bad); border-color: rgba(255, 93, 122, .55); }
.lab-btn-danger:hover:not(:disabled), #btn-stop:hover:not(:disabled) { color: #fff; border-color: var(--bad); background: rgba(255, 93, 122, .18); }
.lab-btn:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }
.lab-btn[aria-busy="true"] { opacity: .75; position: relative; padding-left: 26px; }
.lab-btn[aria-busy="true"]::before {
  content: ''; position: absolute; left: 10px; top: 50%; width: 8px; height: 8px; margin-top: -4px;
  border-radius: 50%; background: currentColor; animation: lab-pulse 1s ease-in-out infinite;
}

.bench-status {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px; padding: 5px 8px;
  font: 12px var(--mono); color: var(--dim);
  background: rgba(0, 0, 0, .3); border-radius: 8px;
}
.bench-status::before {
  content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong);
}
.lab-card.is-running { border-color: rgba(34, 230, 255, .6); box-shadow: 0 0 22px rgba(34, 230, 255, .14); }
.lab-card.is-running .bench-status { color: var(--text); }
.lab-card.is-running .bench-status::before { background: var(--cyan); animation: lab-pulse 1s ease-in-out infinite; }
.lab-matrix { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.lab-matrix table.lab-caps { display: block; overflow-x: auto; table-layout: auto; white-space: nowrap; margin-top: 8px; }
.lab-matrix table.lab-caps th { font: 11px var(--mono); color: var(--dim); text-align: left; }
.lab-matrix table.lab-caps td:first-child { width: auto; }

.lab-help { font-size: 12px; color: var(--dim); margin: 0; }

@keyframes lab-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---- documents: the lab index, stubs, P10 ---------------------------------------------- */

.lab-wrap { width: 100%; max-width: 62rem; margin: 0 auto; padding: 0 1.25rem; }
.lab-doc-main { min-height: calc(100vh - var(--lab-head-h) - 44px); padding-bottom: 2rem; }
.lab-hero { padding: 2.4rem 0 .6rem; text-align: center; }
.lab-hero h1 {
  margin: 0; font-size: 2rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink);
  text-shadow: 0 0 18px rgba(34, 230, 255, .55), 0 0 36px rgba(180, 76, 255, .35);
}
.lab-hero p { margin: .6rem auto 0; max-width: 40rem; color: var(--dim); }
.lab-legend { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin: 1rem 0 0; font-size: 12px; color: var(--dim); }
.lab-group-title {
  margin: 2.2rem 0 1rem;
  font-size: 1rem; letter-spacing: .1em; text-transform: uppercase; color: var(--purple);
}
.lab-cards { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.lab-card-link {
  display: flex; flex-direction: column; gap: .35rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius); text-decoration: none; color: var(--ink);
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(34, 230, 255, .07), rgba(180, 76, 255, .09));
  transition: border-color .18s, box-shadow .18s, transform .18s;
}
.lab-card-link:hover, .lab-card-link:focus-visible {
  border-color: var(--cyan); outline: none; transform: translateY(-2px);
  box-shadow: 0 0 0 1px var(--cyan), 0 0 26px rgba(34, 230, 255, .28), 0 0 40px rgba(180, 76, 255, .2);
}
.lab-card-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.lab-card-num { font: 600 12px var(--mono); color: var(--purple); }
.lab-card-link b { color: var(--cyan); font-size: 1.05rem; }
.lab-card-link span.lab-card-line { color: var(--dim); font-size: .92rem; }
.lab-card-link.is-stub { border-style: dashed; background: rgba(20, 16, 40, .4); }
.lab-proto-note { margin-top: 2rem; padding-top: 1rem; font-size: 12px; color: var(--dim); border-top: 1px solid var(--line); }
.rm-heading { margin: 2.2rem 0 .6rem; font-size: 1rem; letter-spacing: .1em; text-transform: uppercase; color: var(--purple); }
.rm-totals { margin: 0 0 6px; font: 13px var(--mono); color: var(--dim); }

.lab-panel {
  margin: 1.2rem 0; padding: 1.1rem 1.3rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: rgba(20, 16, 40, .6);
}
.lab-panel h2 { margin: 0 0 .6rem; font-size: 1rem; letter-spacing: .06em; text-transform: uppercase; color: var(--cyan); }
.lab-panel p { margin: 0 0 .7rem; max-width: 52rem; }
.lab-panel p:last-child { margin-bottom: 0; }
.lab-panel-stub { border-style: dashed; text-align: center; }
.lab-table-wrap { overflow-x: auto; max-width: 100%; margin: .6rem 0; }
.lab-table { border-collapse: collapse; font: 12px var(--mono); }
.lab-table th, .lab-table td { padding: 4px 8px; border: 1px solid var(--line); text-align: right; white-space: nowrap; }
.lab-table th { color: var(--dim); background: rgba(0, 0, 0, .25); font-weight: 600; }
.lab-table th:first-child, .lab-table td:first-child { text-align: left; }
.lab-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: .8rem 0; }
.lab-actions label { display: inline-flex; gap: 6px; align-items: center; color: var(--dim); }
.lab-actions select {
  min-height: 32px; padding: 3px 8px; font: 13px var(--sans); color: var(--text);
  background: rgba(0, 0, 0, .35); border: 1px solid var(--border); border-radius: 8px;
}
.lab-status { font: 12px var(--mono); color: var(--dim); }

/* ---- the bench pages (styled by id; their markup is the bench builder's) --------------- */

html body :is(#bench-controls, #compare-controls) {
  gap: 10px 14px; padding: 10px 12px; margin-bottom: 10px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 12px;
  font: 13px var(--sans);
}
html body :is(#bench-controls, #compare-controls) select {
  min-height: 30px; padding: 3px 8px; color: var(--text);
  background: rgba(0, 0, 0, .35); border: 1px solid var(--border); border-radius: 8px;
}
html body :is(#bench-run, #compare-run) {
  min-height: 32px; padding: 4px 18px; cursor: pointer;
  font: 600 13px var(--sans); color: #07060f;
  border: 0; border-radius: 9px;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
}
html body :is(#bench-run, #compare-run):disabled { opacity: .45; cursor: progress; }
html body :is(#bench-progress, #compare-progress, #bench-gpu, #compare-gpu, #compare-set) { font: 12px var(--mono); }
html body :is(#bench-canvas, #compare-canvas) { border: 1px solid var(--line); border-radius: 10px; }
html body :is(#bench-table, #compare-table) { display: block; max-width: 100%; overflow-x: auto; font: 12px var(--mono); }
html body :is(#bench-table, #compare-table) :is(th, td) { border-color: var(--line); padding: 3px 8px; white-space: nowrap; }
html body :is(#bench-note, #compare-note) {
  padding: 10px 14px; color: var(--text); font: 13px var(--sans);
  background: rgba(38, 10, 30, .94); border: 1px solid var(--bad); border-radius: 10px;
}
html body :is(#bench-legend, #compare-legend) { font: 12px/1.6 var(--sans); }
body.lab-chromed :is(#bench-controls, #compare-controls) > a[href="../"] { display: none; }

/* ---- narrow screens: the panel stacks under the canvas -------------------------------- */

@media (max-width: 760px) {
  .lab-chrome-head { gap: .45rem; padding: 0 .7rem; }
  .lab-chrome-chip, .lab-chrome-roadmap, .lab-chrome-crumb, .lab-chrome-crumb + .lab-chrome-sep { display: none; }
  .lab-chrome-nav a { padding: .25rem .4rem; }
  .lab-chrome-foot { font-size: 11px; }

  body.lab-app { overflow: auto; }
  body.lab-app .lab-chrome-foot { position: static; height: auto; padding: .6rem 1rem; white-space: normal; }
  body.lab-app .lab-main.lab-stage { position: static; flex-direction: column; }
  .lab-main { flex-direction: column; }
  .lab-viewport { flex: none; height: 62vh; }
  .lab-side { width: auto; max-height: none; overflow: visible; border-left: 0; border-top: 1px solid var(--line); }

  html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools, #temporal-legend) {
    top: auto; left: 0; right: 0; bottom: 0; max-width: none; max-height: 45%;
    overflow-y: auto; border-radius: 12px 12px 0 0;
  }
  html body :is(#sculpt-hud, #bricks-hud, #meadow-hud, #points-hud, #flecks-hud, #mesh-hud, #temporal-hud, #bvh-hud, #gi-hud), .lab-hud {
    max-width: calc(100% - 20px);
  }
  html body :is(#sculpt-note, #bricks-note, #meadow-note, #points-note, #flecks-note, #mesh-note, #temporal-note, #bvh-note, #gi-note) { bottom: auto; top: 50%; transform: translate(-50%, -50%); }
  .lab-hero h1 { font-size: 1.5rem; }
}

/* ---- on-screen camera pad (M1.13; M1.16: the shared .m-pad of shared/mobile.css) --------- */

body.lab-pad-force .m-pad { display: block; }
body.lab-pad-off .m-pad { display: none; }

/* ---- phone panels (M1.14, chrome.js): a bar of toggles, the tools sheet, closable notes -- */

.lab-phonebar {
  display: none; position: absolute; z-index: 9;
  top: 8px; right: calc(8px + var(--safe-right, 0px));
  gap: 6px;
}
@media (max-width: 700px), (pointer: coarse) { .lab-phonebar { display: flex; } }
body.lab-pad-force .lab-phonebar { display: flex; }
/* Wider touch screens keep the tools card top right: the bar (Pad only) sits bottom centre. */
@media (min-width: 701px) {
  .lab-phonebar { top: auto; right: auto; left: 50%; bottom: calc(10px + var(--safe-bottom, 0px)); transform: translateX(-50%); }
  .lab-pb-tools, .lab-pb-stats { display: none; }
}
.lab-pb-btn {
  min-width: 44px; min-height: 44px; padding: 0 12px;
  font: 600 13px var(--sans); color: var(--text);
  background: var(--glass);
  border: 1px solid var(--border); border-radius: 10px;
  backdrop-filter: blur(6px);
  cursor: pointer;
}
.lab-pb-btn[aria-expanded="true"], .lab-pb-btn[aria-pressed="true"] { color: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 12px rgba(34, 230, 255, .2); }
.lab-pb-pad { display: none; }
@media (pointer: coarse) { .lab-pb-pad { display: inline-block; } }
body.lab-pad-force .lab-pb-pad { display: inline-block; }
.lab-sheet-close { display: none; }

/* Notes and errors close on a tap (chrome.js); the × says so. They come back with new text. */
html body :is(#sculpt-note, #bricks-note, #meadow-note, #points-note, #flecks-note, #mesh-note, #temporal-note, #bvh-note, #gi-note, #bench-note, #compare-note),
.lab-context-note { cursor: pointer; padding-right: 44px; }
html body :is(#sculpt-note, #bricks-note, #meadow-note, #points-note, #flecks-note, #mesh-note, #temporal-note, #bvh-note, #gi-note, #bench-note, #compare-note)::after,
.lab-context-note::after {
  content: '×'; position: absolute; top: 4px; right: 6px;
  width: 36px; height: 36px; font: 400 24px/36px var(--sans); text-align: center; color: var(--dim);
}
html body :is(#sculpt-note, #bricks-note, #meadow-note, #points-note, #flecks-note, #mesh-note, #temporal-note, #bvh-note, #gi-note, #bench-note, #compare-note, #needs-webgpu).lab-dismissed,
.lab-context-note.lab-dismissed { display: none !important; }

@media (max-width: 700px) {
  /* Tools: hidden until the Tools button opens them as a bottom sheet with a close strip. */
  html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools, #temporal-legend) {
    display: none; z-index: 10;
    top: auto; left: 0; right: 0; bottom: 0; max-width: none; max-height: 60%;
    overflow-y: auto; overscroll-behavior: contain;
    padding: 0 12px calc(12px + var(--safe-bottom, 0px));
    border-radius: 14px 14px 0 0;
  }
  html body.lab-tools-open :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) { display: flex; }
  html body.lab-tools-open #temporal-legend { display: block; }
  html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools, #temporal-legend) > .lab-sheet-close {
    display: block; position: sticky; top: 0; z-index: 1; order: -1;
    flex: 0 0 100%; width: 100%; min-height: 44px; margin: 0 0 4px; padding: 0 6px;
    font: 400 26px/44px var(--sans); text-align: right; color: var(--dim);
    background: var(--glass); border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
  }
  /* HUD: hidden until Stats; tap it to hide it again. */
  html body :is(#sculpt-hud, #bricks-hud, #meadow-hud, #points-hud, #flecks-hud, #mesh-hud, #temporal-hud, #bvh-hud, #gi-hud) { display: none; }
  html body.lab-hud-open :is(#sculpt-hud, #bricks-hud, #meadow-hud, #points-hud, #flecks-hud, #mesh-hud, #temporal-hud, #bvh-hud, #gi-hud) {
    display: flex; top: 60px; max-height: 45%; overflow-y: auto; pointer-events: auto; cursor: pointer;
  }
}

/* ---- touch-sized controls, nothing wider than the screen (M1.15) ----------------------- */

body.lab-embedded :is(.m-pad, .lab-phonebar) { display: none !important; }

@media (pointer: coarse) {
  .lab-chrome-mark, .lab-chrome-crumb, .lab-chrome-nav a { min-height: 44px; display: inline-flex; align-items: center; }
  .lab-btn, .lab-linkbtn, .lab-keys summary, .lab-control select, .lab-control input[type="number"], .lab-actions select { min-height: 44px; }
  .lab-control-check { min-height: 44px; align-items: center; }
  html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) :is(button, select, input[type="number"]) { min-height: 44px; }
  html body :is(#sculpt-tools, #bricks-tools, #points-tools, #flecks-tools, #mesh-tools, #bvh-tools, #gi-tools) label { min-height: 44px; }
  html body :is(#bench-controls, #compare-controls) :is(button, select) {
    min-height: 44px; padding: 6px 16px; touch-action: manipulation; cursor: pointer;
  }
  html body :is(#bench-run, #compare-run, #report-run, #btn-start, #btn-matrix, #wg-run) { min-height: 44px; }
  html body :is(#bench-controls, #compare-controls) :is(a, label) { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; padding: 0 4px; }
  .lab-card-link { min-height: 44px; }
}

@media (max-width: 700px) {
  /* The crumb comes back as the way to the index; "All prototypes" is the longest label. */
  .lab-chrome-crumb, .lab-chrome-crumb + .lab-chrome-sep { display: inline-flex; }
  .lab-chrome-index { display: none; }
  .lab-chrome-head { padding: 0 calc(.6rem + var(--safe-right, 0px)) 0 calc(.6rem + var(--safe-left, 0px)); }
  .lab-wrap { padding: 0 .8rem; }
  .lab-cards { grid-template-columns: 1fr; }
  .lab-side { padding-bottom: calc(14px + var(--safe-bottom, 0px)); }
  html body :is(#bench-controls, #compare-controls) { gap: 8px; max-width: 100%; }
  html body :is(#bench-controls, #compare-controls) :is(button, select) { flex: 1 1 auto; }
  html body :is(#bench-frame, #bench-canvas, #compare-canvas) { width: 100%; max-width: 100%; }
  html body :is(#bench-legend, #compare-legend) { max-width: 100%; overflow-wrap: anywhere; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .lab-card-link:hover, .lab-card-link:focus-visible { transform: none; }
}
