/* ============================================================
   Let Occ Flow Lab — interactive.html. The stage follows Tesla's
   occupancy-flow demos (charcoal, height-graded surfaces, moving
   things hued by heading), so the chrome stays neutral: ink, grey,
   hairlines, and one magenta accent for the camera, its ray and
   the weights. Two palettes off html[data-theme].
   ============================================================ */

:root {
  --bg: #2A2B2F;
  --bg-2: #212225;
  --ink: #EEEFF2;
  --ink-2: #A0A2A9;
  --line: rgba(238, 239, 242, 0.14);
  --line-soft: rgba(238, 239, 242, 0.08);
  --chrome: rgba(35, 36, 39, 0.84);
  --raise: rgba(238, 240, 244, 0.05);
  --raise-2: rgba(238, 240, 244, 0.1);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --accent: #E0409A;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --body: "Inter", system-ui, sans-serif;
  --panel: 360px;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #E2E2E6;
  --bg-2: #F6F6F7;
  --ink: #15171B;
  --ink-2: #5F646C;
  --line: rgba(21, 23, 27, 0.13);
  --line-soft: rgba(21, 23, 27, 0.07);
  --chrome: rgba(246, 246, 247, 0.86);
  --raise: rgba(21, 23, 27, 0.04);
  --raise-2: rgba(21, 23, 27, 0.08);
  --shadow: 0 18px 40px rgba(21, 23, 27, 0.12);
  --accent: #CC2F86;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Shell ---------- */
.lab-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel);
  height: 100%;
  height: 100dvh;
}

.stage { position: relative; min-width: 0; }

.viewer-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

.viewer-wrapper canvas { display: block; }

/* While the street is built: the other two labs' overlay, words and type. */
#loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 11px;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.viewer-wrapper.is-loading #loading-overlay { display: flex; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin { to { transform: rotate(1turn); } }

/* The cut back to the loop's start (viewer.js crossLoop). */
.viewer-wrapper > canvas { transition: opacity 180ms ease; }
.viewer-wrapper.is-switching > canvas { opacity: 0; }

/* ---------- Stage head ---------- */
.stage-head {
  position: absolute;
  top: 20px;
  left: 22px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
}

.wordmark {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.wordmark span { font-weight: 500; color: var(--ink-2); }
.wordmark:hover span { color: var(--ink); }

.clock {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chrome);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(14px);
}

.stage-side {
  position: absolute;
  top: 20px;
  right: 22px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: 250px;
  text-align: right;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chrome);
  color: var(--ink-2);
  font-weight: 500;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(14px);
}

.theme-toggle:hover { color: var(--ink); }

.theme-toggle i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, #2A2B2F 50%, #E2E2E6 50%);
}

.stage-facts {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-2);
}

/* ---------- Speed tags ---------- */
.stage-tags {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.tag {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chrome);
  color: var(--ink);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(10px);
  will-change: transform;
}

.tag::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c, var(--accent));
}

.tag[hidden] { display: none; }

/* ---------- Legend (top-left, under the stage head) ---------- */
.legend {
  position: absolute;
  left: 22px;
  top: 64px;
  z-index: 5;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--chrome);
  color: var(--ink-2);
  font-size: 11px;
  backdrop-filter: blur(14px);
}

.legend-occupancy { display: grid; gap: 4px; width: 132px; }
.legend-flow { display: none; gap: 12px; align-items: center; }
html[data-view="flow"] .legend-occupancy { display: none; }
html[data-view="flow"] .legend-flow { display: flex; }

.legend-label { color: var(--ink); font-weight: 500; }

/* render2d.js HEIGHT_STOPS as a gradient, y from −0.4 to 5.2 m (the ends
   label the round metres); change the two together. */
.legend-ramp {
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg, #3C3D3A 0%, #403F3C 10.7%, #3B2F90 21.4%, #5E50C8 39.3%, #8E83DC 64.3%, #C7C1EF 89.3%, #F4F2FC 100%);
}

.legend-ends {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 10px;
}

.legend-flow-words { display: grid; gap: 1px; line-height: 1.35; }
.legend-still { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.legend-still i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: #9D9DA4;
}

#legend-wheel { width: 44px; height: 44px; }



/* ---------- Dock ---------- */
.dock {
  position: absolute;
  left: 50%;
  bottom: 20px;
  z-index: 5;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  max-width: calc(100% - 44px);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--chrome);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dock-group { display: flex; gap: 2px; padding: 0 3px; }
.dock-group + .dock-group { border-left: 1px solid var(--line-soft); }

.dock button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  font-weight: 500;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}

.dock button:hover { color: var(--ink); background: var(--raise); }
.dock button.is-active { color: var(--ink); background: var(--raise-2); }

kbd {
  font-family: var(--body);
  font-size: 10px;
  line-height: 1;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink-2);
}

/* Below this width the dock's key hints no longer fit beside the panel; the
   keys still work. */
@media (max-width: 1400px) {
  .dock kbd { display: none; }
}

/* One loop of the street, as a fill under the dock. */
.phase-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: var(--line-soft);
}

.phase-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  transform-origin: left;
  transform: scaleX(var(--u, 0));
  background: var(--accent);
}

/* ---------- Panel ---------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 20px 20px;
  border-left: 1px solid var(--line);
  background: var(--bg-2);
  overflow-y: auto;
}

.kicker {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.panel-head h1 {
  margin: 0 0 6px;
  font-weight: 700;
  font-size: 21px;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.panel-head p:last-child,
.panel-hint {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-2);
}

.panel-hint { font-size: 11.5px; margin-top: 8px; }

.pane { margin: 0; }

#pane-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 160 / 90;
  border-radius: 6px;
  background: #000;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.chip {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--raise);
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.3;
  cursor: pointer;
}

.chip:hover { color: var(--ink); background: var(--raise-2); }
.chip.is-active { color: var(--ink); border-color: var(--accent); }

.pane figcaption {
  min-height: 3.1em;
  margin-top: 8px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-2);
}

.panel-section h2 {
  margin: 0 0 6px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.ray-hit {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}

#ray-plot {
  display: block;
  width: 100%;
  height: 112px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--bg);
}

.plot-key {
  display: flex;
  gap: 14px;
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--ink-2);
}

.plot-key span { display: inline-flex; align-items: center; gap: 6px; }
.plot-key span::before { content: ""; width: 12px; }
.key-sdf::before { height: 0; border-top: 1.5px solid var(--ink); }
.key-weight::before { height: 8px; background: var(--accent); }
.key-depth::before { height: 0; border-top: 1.5px dashed var(--accent); }

.readout {
  display: grid;
  gap: 3px;
  margin: 10px 0 0;
  font-size: 12px;
}

.readout div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  border-bottom: 1px solid var(--line-soft);
}

.readout dt { color: var(--ink-2); }

.readout dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.readout dd.is-moving { color: var(--accent); }

.slider {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--ink-2);
}

.slider > span { display: flex; justify-content: space-between; }
.slider output { margin-left: auto; margin-right: 3px; font-family: var(--mono); color: var(--ink); }
.slider input { width: 100%; accent-color: var(--accent); }

.results {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.results caption {
  margin-bottom: 4px;
  text-align: left;
  font-size: 11.5px;
  color: var(--ink-2);
}

.results th {
  padding: 4px 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--line);
  font-weight: 500;
  text-align: right;
  color: var(--ink-2);
}

.results td {
  padding: 3px 0;
  text-align: right;
  font-family: var(--mono);
  font-size: 11.5px;
}

.results th:first-child,
.results td:first-child {
  text-align: left;
  font-family: var(--body);
  font-size: 12px;
}

.results tbody tr:last-child td { border-bottom: 1px solid var(--ink); }
.results tr.group td { border-top: 1px solid var(--line-soft); }
.results small { color: var(--ink-2); font-size: 10.5px; }
.results tr.is-ours td { color: var(--ink); font-weight: 600; }
.results tr.is-ours td:first-child { box-shadow: inset 2px 0 0 var(--accent); padding-left: 7px; }

.panel-foot {
  margin: auto 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-2);
}

.panel-foot a { color: var(--ink); }
.panel-foot strong { color: var(--ink); font-weight: 600; }

/* ---------- Embedded (interactive.html?embed) ---------- */
/* Framed as a thumbnail (~255px wide; retained, the homepage row shows a
   video): the stage alone, in the other two thumbnails' palette (viewer.js
   THEMES when embedded). */
html.is-embed .stage-head,
html.is-embed .stage-side,
html.is-embed .stage-tags,
html.is-embed .legend,
html.is-embed .dock,
html.is-embed .panel {
  display: none;
}

html.is-embed .lab-shell {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

html.is-embed { --bg: #F0EEE6; }
html.is-embed[data-theme="dark"] { --bg: #1c1c1a; }

html.is-embed #loading-overlay { color: #171916; background: #F0EEE6; }
html.is-embed .spinner { border-color: rgba(23, 25, 22, 0.18); border-top-color: #ee5b38; }
html.is-embed[data-theme="dark"] #loading-overlay { color: #f2eee8; background: #1c1c1a; }
html.is-embed[data-theme="dark"] .spinner { border-color: rgba(242, 238, 232, 0.16); border-top-color: #e9873f; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  :root { --panel: 320px; }
  .stage-facts { display: none; }
  .legend { display: none; }
}

@media (max-width: 720px) {
  .lab-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .panel {
    max-height: 48dvh;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 16px 16px 18px;
    gap: 14px;
  }

  .stage-head { top: 14px; left: 14px; gap: 10px; }
  .stage-side { top: 14px; right: 14px; }
  .dock { bottom: 12px; max-width: calc(100% - 24px); overflow-x: auto; }
  kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .viewer-wrapper > canvas { transition: none; }
}
