:root {
  color-scheme: dark;
  --bg: #090b0f;
  --rail: #10141a;
  --panel: #131821;
  --panel-2: #171d27;
  --line: #273140;
  --line-bright: #3b4a5f;
  --text: #eef4fb;
  --muted: #91a0b2;
  --dim: #5d6b7e;
  --cyan: #5fe7ff;
  --cyan-2: #119fc0;
  --amber: #f2b84b;
  --orange: #ff784f;
  --red: #ff4f61;
  --green: #75e0a7;
  --shadow: rgba(0, 0, 0, 0.42);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at 52% 40%, #111722 0, var(--bg) 56%);
  color: var(--text);
  overflow: hidden;
  height: var(--app-height, 100vh);
}

button,
input {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 190px minmax(700px, 1fr) 320px;
  height: var(--app-height, 100vh);   /* full height — the 52px top appbar was removed */
  min-height: 0;
}

.shell.rail-collapsed {
  grid-template-columns: 0 minmax(720px, 1fr) 320px;
}

.shell.rail-collapsed .mode-rail {
  display: none;
}

/* Guided-tour focus mode: collapse both side columns so a newcomer sees only the scene + the tour
   card, not the full overloaded chrome. Restored on Skip / when the tour ends. (tour.js toggles it.) */
/* Guided-tour focus mode: a clean, full-bleed scene + the tour card, nothing else. Collapse both side
   columns, hide the analysis dock, and strip the appbar's action buttons (so there's no dead menu) —
   only the title stays. The tour drives navigation (Next/Back/Skip); the full lab returns when it ends.
   .workspace is pinned to column 2 so hiding the rail can't reflow the canvas into the 0-width track. */
body.touring .shell {
  grid-template-columns: 0 1fr 0;
}
body.touring .mode-rail,
body.touring .inspector,
body.touring .analysis-dock {
  display: none;
}
body.touring .workspace { grid-column: 2; }
body.touring .topbar { display: none; }   /* scene + tour card only; mode title/icons hidden during the tour */
body.touring .legend { display: none; }    /* the tour cards name each ring in words, so the colour key is redundant */

/* "More" toggle: the sandbox + advanced panels are collapsed by default so the free-explore inspector
   isn't overwhelming; the toggle reveals them on demand. Persisted in localStorage (bhl_adv). */
.adv-toggle {
  width: 100%;
  margin: 4px 0 0;
  padding: 9px 0;
  font: 600 12px Inter, system-ui, sans-serif;
  color: #9fb0c2;
  background: #0e131b;
  border: 1px solid #273140;
  border-radius: 8px;
  cursor: pointer;
}
.adv-toggle:hover { border-color: #5fe7ff; color: #5fe7ff; }
body.adv-collapsed .sandbox-panel,
body.adv-collapsed .status-panel { display: none; }
body.touring .adv-toggle { display: none; }   /* the tour hides the inspector entirely */

/* prominent "what am I seeing?" entry into the field guide (was buried in a tiny rail-footer icon) */
.rail-guide-btn {
  width: 100%;
  margin: 4px 0 2px;
  padding: 8px 0;
  font: 600 11.5px Inter, system-ui, sans-serif;
  color: #05070a;
  background: #5fe7ff;
  border: none;
  border-radius: 7px;
  cursor: pointer;
}
.rail-guide-btn:hover {
  background: #8af0ff;
}

.appbar {
  height: 52px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(3, 5, 8, 0.96);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}

.appbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.appbar-right {
  justify-content: flex-end;
}

.app-title {
  font-size: 25px;
  font-weight: 600;
  letter-spacing: 0;
}

.toolbar-button,
.toolbar-command {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #dce7f2;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
}

.toolbar-button {
  width: 34px;
}

.toolbar-command {
  padding: 0 9px;
  font-size: 12px;
}

.toolbar-button:hover,
.toolbar-command:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

.toolbar-button.active,
.toolbar-command.active {
  color: var(--cyan);
  background: rgba(95, 231, 255, 0.08);
  border-color: rgba(95, 231, 255, 0.24);
}

.toolbar-button svg,
.toolbar-command svg,
.rail-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mode-rail,
.inspector {
  background: linear-gradient(180deg, rgba(19, 24, 33, 0.98), rgba(12, 15, 21, 0.98));
  border-color: var(--line);
  padding: 14px;
}

.mode-rail {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.inspector {
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 14px;
}

.brand-mark {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(95, 231, 255, 0.55);
  border-radius: 50%;
  background:
    radial-gradient(circle, #020305 0 35%, transparent 36%),
    conic-gradient(from 25deg, rgba(255, 120, 79, 0), rgba(255, 120, 79, 0.95), rgba(95, 231, 255, 0.7), rgba(255, 120, 79, 0));
  box-shadow: 0 0 28px rgba(95, 231, 255, 0.25);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 14px;
  line-height: 1.1;
  font-weight: 720;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 13px;
  white-space: nowrap;
}

.brand p,
.eyeline,
.panel p,
dt,
.scale-labels,
.mass-row span {
  color: var(--muted);
}

.brand p {
  margin-top: 4px;
  font-size: 10.5px;
}

.modes {
  display: grid;
  gap: 12px;
}

.mode-button {
  width: 100%;
  min-height: 94px;
  display: grid;
  grid-template-columns: 1fr 32px;
  grid-template-rows: 34px auto auto;
  align-content: center;
  gap: 5px 8px;
  padding: 11px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(23, 29, 39, 0.82), rgba(10, 14, 19, 0.82));
  color: var(--muted);
  text-align: center;
  cursor: pointer;
}

.mode-button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
}

.mode-button.active {
  color: var(--text);
  background: linear-gradient(135deg, rgba(95, 231, 255, 0.16), rgba(242, 184, 75, 0.09));
  border-color: rgba(95, 231, 255, 0.72);
  box-shadow: 0 0 22px rgba(95, 231, 255, 0.08), inset 0 0 0 1px rgba(95, 231, 255, 0.12);
}

.mode-index {
  grid-column: 2;
  grid-row: 1 / span 3;
  width: 32px;
  height: 32px;
  align-self: center;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line-bright);
  font-size: 20px;
  font-weight: 700;
  color: var(--cyan);
}

.mode-icon {
  grid-column: 1;
  justify-self: center;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(214, 224, 234, 0.58);
  border-radius: 50%;
  color: rgba(214, 224, 234, 0.82);
}

.mode-button.active .mode-icon {
  border-color: rgba(95, 231, 255, 0.86);
  color: var(--cyan);
  box-shadow: 0 0 18px rgba(95, 231, 255, 0.18);
}

.mode-icon svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mode-label {
  display: block;
  font-size: 13px;
  font-weight: 680;
  align-self: end;
}

.mode-detail {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--dim);
}

.lab-link {
  margin-top: 14px;
  padding: 10px 11px;
  display: block;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  text-decoration: none;
}

.lab-link:hover {
  border-color: rgba(95, 231, 255, 0.5);
}

.lab-link-title {
  display: block;
  font-size: 12.5px;
  font-weight: 680;
  color: var(--text);
}

.lab-link-arrow {
  color: var(--dim);
}

.lab-link-sub {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--dim);
}

/* the flagship gets a distinct, fuller cyan card at the top of the rail */
.lab-link.featured {
  margin: 4px 0 14px;
  padding: 12px;
  border-color: rgba(95, 231, 255, 0.45);
  background: rgba(95, 231, 255, 0.07);
}
.lab-link.featured:hover { border-color: var(--cyan); }
.lab-link.featured .lab-link-title { color: #eef4fb; white-space: nowrap; }

/* small section labels in the rail (Scenarios / More) */
.rail-section {
  margin: 16px 2px 2px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

/* labelled action buttons at the bottom of the rail — labels stay visible (mobile has no hover) */
.rail-footer { gap: 8px; }
.rail-action {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #9fb0c2;
  font: 600 10px Inter, system-ui, sans-serif;
  cursor: pointer;
}
.rail-action:hover { border-color: rgba(95, 231, 255, 0.4); color: var(--cyan); }
.rail-action svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.rail-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  justify-content: space-around;
}

.rail-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #c4cfdb;
}

.workspace {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 132px;
  min-width: 0;
  min-height: 0;
  padding: 0;
}

.topbar {
  min-height: 0;
  display: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
}

.eyeline {
  margin-bottom: 5px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.11em;
}

h2 {
  font-size: clamp(25px, 3vw, 36px);
  line-height: 1.06;
  font-weight: 760;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.icon-button:hover,
.icon-button.active {
  color: var(--cyan);
  border-color: rgba(95, 231, 255, 0.45);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stage {
  position: relative;
  min-height: 0;
  height: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  overflow: hidden;
  background: #05070a;
  box-shadow: none;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.legend {
  position: absolute;
  left: 16px;
  top: 18px;
  bottom: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 32px);
  pointer-events: none;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  border: 0;
  background: transparent;
  color: #d6e0ea;
  font-size: 12px;
  backdrop-filter: blur(12px);
}

.legend-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
}

.panel {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(19, 24, 33, 0.78);
}

.panel h3 {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 740;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mass-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

output {
  font-size: 18px;
  font-weight: 760;
  letter-spacing: 0;
}

.mass-row span {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
}

.scale-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
}

.readouts dl {
  display: grid;
  gap: 5px;
  margin: 0;
}

.readouts div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.readouts div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

dt {
  font-size: 12px;
}

dd {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.panel p {
  font-size: 11.5px;
  line-height: 1.55;
}

.controls {
  display: grid;
  gap: 7px;
}

.controls label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.controls label.disabled {
  opacity: 0.46;
}

.controls label.disabled input {
  cursor: not-allowed;
}

.control-target,
.parameter-hint {
  padding-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.control-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.control-label-row output {
  color: var(--text);
  font-size: 11px;
  font-weight: 650;
}

.sandbox-panel {
  display: grid;
  gap: 8px;
}

.sandbox-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.sandbox-actions {
  padding-top: 2px;
}

.sandbox-demo {
  grid-template-columns: 1fr;
}

.sandbox-demo button {
  border-color: rgba(117, 224, 167, 0.44);
  color: #bff3d6;
}

.sandbox-focus {
  grid-template-columns: 1fr 1fr 1fr;
}

.sandbox-focus button {
  min-height: 27px;
  color: #aab6c5;
}

.launch-presets {
  padding-top: 2px;
}

.launch-presets button {
  border-color: rgba(125, 108, 255, 0.45);
  color: #cdbcff;
}

.launch-presets button:hover {
  border-color: rgba(125, 108, 255, 0.7);
  color: var(--cyan);
  background: rgba(125, 108, 255, 0.12);
}

.velocity-controls {
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.velocity-controls.disabled label {
  opacity: 0.46;
}

.velocity-controls.disabled input {
  cursor: not-allowed;
}

.sandbox-buttons button,
.object-chip {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.035);
  color: #dce7f2;
  font-size: 11px;
  cursor: pointer;
}

.sandbox-buttons button:disabled,
.object-chip:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.sandbox-buttons button:hover,
.object-chip:hover,
.object-chip.active {
  border-color: rgba(95, 231, 255, 0.5);
  color: var(--cyan);
  background: rgba(95, 231, 255, 0.08);
}

.object-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.object-chip {
  padding: 0 8px;
}

#labCanvas {
  cursor: crosshair;
}

.dragging #labCanvas {
  cursor: grabbing;
}

.analysis-dock {
  display: grid;
  grid-template-columns: 1fr 172px;
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid rgba(255,255,255,0.04);
  background: rgba(5, 8, 12, 0.96);
}

.dock-chart {
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
}

.tabs {
  height: 28px;
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}

.tab {
  padding: 0 12px;
  border: 0;
  border-right: 1px solid rgba(255,255,255,0.05);
  background: transparent;
  color: #cdd8e4;
  font-size: 11px;
  cursor: pointer;
}

.tab.active {
  color: var(--cyan);
  box-shadow: inset 0 -2px 0 var(--cyan);
}

#graphCanvas {
  width: 100%;
  height: calc(100% - 28px);
  display: block;
}

.formula-panel {
  display: grid;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0;
  min-height: 0;
  padding: 6px;
}

.formula-panel div {
  display: grid;
  align-content: center;
  gap: 3px;
  min-height: 0;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: rgba(19, 24, 33, 0.62);
}

.formula-panel div:first-child {
  border-radius: 7px 7px 0 0;
}

.formula-panel div:last-child {
  border-bottom: 1px solid var(--line);
  border-radius: 0 0 7px 7px;
}

.formula-panel span {
  color: var(--muted);
  font-size: 9.5px;
}

.formula-panel strong {
  color: #eef4fb;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
  font-weight: 500;
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding: 9px 0 0;
  border-top: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 11.5px;
}

.status-dot {
  width: 9px;
  height: 9px;
  display: inline-block;
  margin-right: 7px;
  border-radius: 50%;
  background: #65d96f;
  box-shadow: 0 0 12px rgba(101,217,111,0.42);
}

.file-input {
  display: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: 360px;
  padding: 10px 12px;
  border: 1px solid rgba(95, 231, 255, 0.28);
  border-radius: 8px;
  background: rgba(8, 11, 16, 0.92);
  color: #eef4fb;
  font-size: 12px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.36);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(0, 0, 0, 0.55);
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  position: relative;
  width: min(520px, 100%);
  max-height: min(680px, calc(var(--app-height, 100vh) - 44px));
  overflow: auto;
  padding: 20px;
  border: 1px solid rgba(95, 231, 255, 0.25);
  border-radius: 8px;
  background: #10161f;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
}

.modal h2 {
  margin: 0 36px 14px 0;
  font-size: 20px;
}

.modal h3 {
  margin: 16px 0 8px;
  color: #eef4fb;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.modal p,
.modal li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.modal ul {
  margin: 0;
  padding-left: 18px;
}

.modal code {
  color: var(--cyan);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: #eef4fb;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .shell {
    grid-template-columns: 228px minmax(420px, 1fr);
    height: auto;
  }

  .inspector {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .appbar {
    grid-template-columns: 1fr auto;
  }

  .appbar-right {
    display: none;
  }
}

@media (max-height: 820px) {
  .workspace {
    grid-template-rows: minmax(0, 1fr) 98px;
  }

  .tabs {
    height: 24px;
  }

  .tab {
    padding: 0 10px;
    font-size: 10px;
  }

  #graphCanvas {
    height: calc(100% - 24px);
  }

  .formula-panel {
    padding: 4px;
  }

  .formula-panel div {
    padding: 3px 6px;
  }

  .formula-panel span {
    display: none;
  }

  .formula-panel strong {
    font-size: 10.5px;
  }
}

@media (max-width: 760px) {
  .shell {
    display: block;
  }

  .mode-rail,
  .workspace,
  .inspector {
    padding: 14px;
  }

  .modes {
    grid-template-columns: 1fr;
  }

  .stage {
    height: 58vh;
  }

  .inspector {
    display: grid;
    grid-template-columns: 1fr;
  }
}
