/* lab.css — the StarLab lab as an app (the web edition program, 2026-10-19): the world fills the frame, a dock holds the
   tools. Portrait first: on a phone the world takes the screen above the dock, the materials scroll in one row under the
   controls, and everything else waits in the "more" sheet. Holding on the world uses the tool; nothing on the stage is
   selectable (a long press on iOS selected the canvas as text). One file for the dev page and the site's /lab/, staged
   beside lab.js.

   ★ THE CATALOG'S LOOK (Track D's round 12, 2026-10-20): the lab is a context of the house catalog (.lab-app.ui-ctx,
   data-tier="phone": the 44 px floor at every width; the accent StarLab's) and its controls are the catalog's,
   love-shared/web/catalog.css, linked before this sheet as house/catalog.css with the house tokens scoped to the lab
   (house/tokens.css; both copies kept by the monorepo's scripts/design-tokens-sync.py and staged with the engine). A
   button is .ui-btn, the play its primary (filled at rest, hollow while the world runs), a tool a .ui-chip, the size a
   .ui-slider, the sheet's inputs .ui-field, the witness a .ui-badge. This sheet keeps the LAYOUT and the lab's own
   marks: the world, the brush ring, a tool's swatch, the size dot and the slider in the tool's colour. */

.lab-app {
  /* the house tokens (house/tokens.css, scoped to [data-lab-app]: the same values on the dev page, inside the
     platform's /lab/ and in the bench's D5), under the lab's own names for the stage; the fallbacks are for a page that
     links this sheet alone. The world is dark whatever the page is. */
  --lab-bg: var(--ink, #090c13);
  --lab-panel: var(--panel, #111726);
  --lab-raise: var(--panel2, #19212f);
  --lab-line: var(--line, #232c40);
  --lab-text: var(--text, #dce3ee);
  --lab-dim: var(--faint, #7e8b9f);
  --lab-bad: var(--danger, #e06550);
  --c: #1a528c; /* the tool's colour, set by lab.js */
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: var(--lab-h, min(100svh, 860px));
  background: var(--lab-bg);
  color: var(--lab-text);
  border-radius: var(--lab-radius, 14px);
  overflow: hidden;
  font: 13px/1.35 var(--mono, ui-monospace, Menlo, monospace);   /* the house's face, as its LÖVE twin draws */
  -webkit-text-size-adjust: 100%;
}
.lab-app.ui-ctx { --accent: var(--accent-starlab, #4de6ff); }
.lab-app * { box-sizing: border-box; }

/* ── the stage: the world, its title line, the hint, the brush ring, the loading overlay ── */
.lab-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/* absolutely placed: with a definite height the canvas's own aspect ratio became a minimum width, which widened the
   grid past a phone's screen */
.lab-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  touch-action: none;
  cursor: crosshair;
  outline: none;
}
.lab-top {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 18px;
  background: linear-gradient(color-mix(in srgb, var(--lab-bg) 62%, transparent), transparent);
  pointer-events: none;
}
.lab-world {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-weight: 650;
  font-size: 16px;
  letter-spacing: 0.01em;
  pointer-events: auto;
}
.lab-world #name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lab-world.many::after { content: "▾"; color: var(--lab-dim); font-size: 12px; }
.lab-world select {
  position: absolute;
  inset: -6px;
  opacity: 0;
  font-size: 16px; /* iOS zooms into a select under 16 px */
}
.lab-world:not(.many) select { display: none; }
.lab-meta { display: flex; align-items: center; gap: 8px; color: var(--lab-dim); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* the witness: the catalog's badge (data-tone ok or danger, lab.js); the size of the meta line around it */
.lab-meta .lab-badge { font-size: 11px; font-weight: 600; }
.lab-badge:empty { display: none; }

.lab-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  padding: var(--space-3, 6px) var(--space-5, 12px);
  border: 1px solid var(--lab-line);
  border-radius: var(--radius-card, 6px);
  background: color-mix(in srgb, var(--lab-panel) 88%, transparent);
  color: var(--lab-text);
  font-size: 12px;
  text-align: center;
  text-wrap: balance;   /* the house face is wider than the system's: a long line takes two, never an ellipsis */
  pointer-events: none;
  transition: opacity 0.6s;
}
.lab-hint.gone { opacity: 0; }

/* the brush: a ring at the finger; it fills while a hold arms, then pulses in the tool's colour while it sprays */
.lab-brush {
  --d: 44px;
  position: absolute;
  left: 0;
  top: 0;
  width: var(--d);
  height: var(--d);
  margin: calc(var(--d) / -2) 0 0 calc(var(--d) / -2);
  border-radius: 50%;
  border: 2px solid var(--c);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45), inset 0 0 14px var(--c);
  opacity: 0;
  transform: scale(0.4);
  pointer-events: none;
}
.lab-brush.arming { opacity: 0.7; transform: scale(1); transition: transform var(--hold, 260ms) ease-out, opacity var(--hold, 260ms); }
.lab-brush.on { opacity: 0.95; transform: scale(1); animation: lab-pulse 0.55s ease-in-out infinite alternate; }
@keyframes lab-pulse { from { transform: scale(0.9); } to { transform: scale(1.08); } }

/* the loading overlay: its bar animates a transform (the compositor runs it while the engine's compile blocks the page) */
.lab-stage .boot {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--lab-bg) 82%, transparent) center / cover no-repeat;
  transition: opacity 0.4s, background-color 0.4s;
}
.lab-stage .boot.warm { background-color: color-mix(in srgb, var(--lab-bg) 35%, transparent); }
.lab-stage .boot.done { opacity: 0; pointer-events: none; }
.lab-stage .boot.idle .boot-bar { display: none; }
.lab-stage .boot-card {
  width: min(420px, 84%);
  padding: var(--space-6, 16px);
  border: 1px solid var(--lab-line);
  border-radius: var(--radius-card, 6px);
  background: color-mix(in srgb, var(--lab-panel) 92%, transparent);
  font-size: 13px;
}
.lab-stage .boot-title { font-weight: 650; margin-bottom: var(--space-2, 4px); }
.lab-stage .boot-stage { color: var(--lab-text); margin-bottom: var(--space-5, 12px); overflow-wrap: anywhere; }
.lab-stage .boot-stage.bad { color: var(--lab-bad); }
.lab-stage .boot-bar { height: 4px; border-radius: var(--radius-1, 2px); background: var(--lab-raise); overflow: hidden; }
.lab-stage .boot-bar i { display: block; width: 32%; height: 100%; border-radius: var(--radius-1, 2px); background: var(--accent); animation: lab-boot-slide 1.2s ease-in-out infinite; will-change: transform; }
@keyframes lab-boot-slide { from { transform: translateX(-110%); } to { transform: translateX(320%); } }
.lab-stage .boot-note { margin-top: 10px; color: var(--lab-dim); font-size: 12px; }
/* the stop: the overlay comes back with what happened and a restart (lab.js `stopped`) */
.lab-stage .boot.stopped { background-color: color-mix(in srgb, var(--lab-bg) 86%, transparent); }
.lab-stage .boot.stopped .boot-bar { display: none; }
.lab-stage .boot.stopped .boot-note { overflow-wrap: anywhere; }
/* the restart: the catalog's primary button (lab.js) */
.lab-stage .boot-restart { margin-top: var(--space-5, 12px); padding: 0 var(--space-6, 16px); font-weight: 650; }

/* ── the dock: its layout (the catalog draws the controls) ── */
.lab-dock {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4, 8px);
  padding: var(--space-5, 12px) var(--space-5, 12px) calc(var(--space-5, 12px) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--lab-line);
  background: var(--lab-panel);
}
.lab-bar { display: flex; align-items: center; gap: var(--space-4, 8px); }
.lab-bar .lab-btn, .lab-more .lab-btn { display: inline-grid; place-items: center; -webkit-tap-highlight-color: transparent; }
.lab-btn svg { width: 18px; height: 18px; fill: currentColor; }
/* the play: the screen's one main action, a step larger than the floor */
.lab-bar .lab-play { min-width: var(--size-row-h-lg, 56px); min-height: var(--size-row-h-lg, 56px); padding: 0; }
.lab-play svg { width: 22px; height: 22px; }
.lab-size { flex: 1; display: flex; align-items: center; gap: var(--space-4, 8px); min-width: 0; padding: 0 var(--space-2, 4px); }
/* a zero base width: the range input's own 129 px otherwise counted toward the row's minimum on a phone; the slider
   fills in the tool's colour (the lab's mark, over the catalog's accent) */
.lab-size input { flex: 1; width: 0; min-width: 0; accent-color: var(--c); }
.lab-size .dot {
  flex: 0 0 auto;
  width: calc(8px + var(--s, 3) * 3px);
  height: calc(8px + var(--s, 3) * 3px);
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 2px var(--lab-line);
}
.lab-mats {
  display: flex;
  gap: var(--space-3, 6px);
  margin: 0 calc(-1 * var(--space-5, 12px));
  padding: var(--space-1, 2px) var(--space-5, 12px);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-padding-inline: var(--space-5, 12px);   /* the snap keeps the row's inset (it scrolled the first tool flush) */
  scrollbar-width: none;
}
.lab-mats::-webkit-scrollbar { display: none; }
/* a tool: the catalog's chip (aria-checked the chosen one), laid out as a column, its swatch above its name */
.lab-mats > .lab-mat {
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: var(--space-2, 4px);
  width: 60px;
  padding: var(--space-3, 6px) var(--space-1, 2px) var(--space-2, 4px);
  font-size: 11.5px;
  scroll-snap-align: start;
  -webkit-tap-highlight-color: transparent;
}
.lab-mat i {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 55%), var(--m);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--lab-line);
}
.lab-mat.erase i { background: repeating-linear-gradient(45deg, var(--line-strong, #62708a) 0 4px, var(--lab-raise) 4px 8px); }
/* on the accent fill the swatch keeps a dark rim, so a pale material still reads as a mark */
.lab-mat[aria-checked="true"] i { box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.35), 0 0 0 2px var(--lab-bg); }

/* the more sheet: the world list, a folder, the pace, the render scale, the fingerprint, save, the numbers */
.lab-more {
  position: absolute;
  left: var(--space-4, 8px);
  right: var(--space-4, 8px);
  bottom: calc(100% + var(--space-4, 8px));
  max-height: min(62vh, 520px);
  overflow: auto;
  padding: var(--space-5, 12px);
  border: 1px solid var(--lab-line);
  border-radius: var(--radius-card, 6px);
  background: var(--lab-panel);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  font-size: 12px;
}
.lab-more[hidden] { display: none; }
.lab-more-row { display: flex; flex-wrap: wrap; gap: var(--space-4, 8px) var(--space-5, 12px); align-items: center; margin-bottom: var(--space-5, 12px); }
.lab-more label { display: inline-flex; align-items: center; gap: var(--space-3, 6px); color: var(--lab-dim); }
.lab-more .ui-field { font-size: 16px; } /* iOS zooms into a field under 16 px */
.lab-more input[type="number"] { width: 4.6em; }
.lab-more input[type="file"] { max-width: 210px; color: var(--lab-dim); font-size: 12px; }
.lab-hud { display: grid; grid-template-columns: max-content 1fr; gap: 3px var(--space-5, 12px); margin: 0 0 var(--space-4, 8px); }
.lab-hud dt { color: var(--lab-dim); }
.lab-hud dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.lab-log { margin: 0; max-height: 9em; overflow: auto; color: var(--lab-dim); font: 11px/1.4 var(--mono, ui-monospace, Menlo, monospace); white-space: pre-wrap; }
.lab-err { margin: 0; padding: 0 var(--space-5, 12px); color: var(--lab-bad); font: 12px/1.4 var(--mono, ui-monospace, Menlo, monospace); white-space: pre-wrap; }
.lab-err:empty { display: none; }

/* a phone on its side: the dock becomes a column at the right */
@media (orientation: landscape) and (max-height: 560px) {
  .lab-app { grid-template-rows: none; grid-template-columns: minmax(0, 1fr) min(260px, 38vw); }
  .lab-dock { align-content: start; border-top: 0; border-left: 1px solid var(--lab-line); overflow-y: auto; padding-bottom: 10px; }
  .lab-mats { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
  .lab-more { left: auto; right: calc(100% + 8px); bottom: 8px; width: min(420px, 60vw); }
}

@media (prefers-reduced-motion: reduce) {
  .lab-brush.on { animation: none; }
  .lab-stage .boot-bar i { animation-duration: 3s; }
}

/* ★ THE BACKDROP (2026-11-03): ?backdrop=1, the lab behind another page (the s2ar.dev home frames it): the world is the
   whole frame; the dock, the title line, the hint, the brush ring and the loading card go (the page above keeps its own
   picture until the engine says ready) */
html.lab-backdrop, html.lab-backdrop body { height: 100%; margin: 0; overflow: hidden; background: #000; }
.lab-backdrop .lab-app { height: 100vh; height: 100svh; grid-template-rows: minmax(0, 1fr); border-radius: 0; }
/* ★ (2026-11-03, the home on the engine) the app over the whole window on its own ground: the site's /lab/ page holds
   its header, its title and its words above the app, which a backdrop frame must not show (the dev page has none) */
.lab-backdrop .lab-app { position: fixed; inset: 0; z-index: 2147483647; background: #000; }
.lab-backdrop .lab-dock, .lab-backdrop .lab-top, .lab-backdrop .lab-hint, .lab-backdrop .lab-brush,
.lab-backdrop .lab-stage .boot { display: none; }
