:root {
  --bg: #f2f0eb;
  --surface: #fbfaf7;
  --surface-2: #ebe8e1;
  --line: rgba(32, 28, 20, 0.1);
  --line-strong: rgba(32, 28, 20, 0.22);
  --text: #1b1a17;
  --muted: #6b6860;
  --faint: #a19d93;
  --accent: #1b1a17;
  --accent-soft: rgba(27, 26, 23, 0.07);
  --ok: #2f7d4f;
  --warn: #a8690c;
  --bad: #c2412d;
  --ok-soft: rgba(47, 125, 79, 0.1);
  --warn-soft: rgba(168, 105, 12, 0.11);
  --bad-soft: rgba(194, 65, 45, 0.1);
  --radius: 6px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121210;
    --surface: #191917;
    --surface-2: #23221f;
    --line: rgba(255, 250, 240, 0.08);
    --line-strong: rgba(255, 250, 240, 0.18);
    --text: #ecebe5;
    --muted: #96938b;
    --faint: #5f5d57;
    --accent: #ecebe5;
    --accent-soft: rgba(236, 235, 229, 0.09);
    --ok: #5cc28a;
    --warn: #e3a64a;
    --bad: #f07a63;
    --ok-soft: rgba(92, 194, 138, 0.12);
    --warn-soft: rgba(227, 166, 74, 0.13);
    --bad-soft: rgba(240, 122, 99, 0.12);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121210;
  --surface: #191917;
  --surface-2: #23221f;
  --line: rgba(255, 250, 240, 0.08);
  --line-strong: rgba(255, 250, 240, 0.18);
  --text: #ecebe5;
  --muted: #96938b;
  --faint: #5f5d57;
  --accent: #ecebe5;
  --accent-soft: rgba(236, 235, 229, 0.09);
  --ok: #5cc28a;
  --warn: #e3a64a;
  --bad: #f07a63;
  --ok-soft: rgba(92, 194, 138, 0.12);
  --warn-soft: rgba(227, 166, 74, 0.13);
  --bad-soft: rgba(240, 122, 99, 0.12);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
[hidden] { display: none !important; }

/* ---------- top bar */
.bar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: -0.015em; white-space: nowrap; }
.brand svg { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 3; }
.brand svg .fill { fill: var(--accent); stroke: none; }
.grow { flex: 1; }
.conn { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; min-width: 0; }
.conn .dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); transition: background 0.3s; }
.conn[data-state="on"] .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.conn[data-state="demo"] .dot { background: var(--warn); }
.conn[data-state="busy"] .dot { background: var(--warn); }
.meta { color: var(--muted); font: 12px var(--mono); display: flex; gap: 14px; }
.meta b { color: var(--text); font-weight: 500; }

/* ---------- buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font: 500 13px var(--sans);
  padding: 8px 14px;
  border-radius: 5px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.05s;
}
.btn:hover:not(:disabled) { border-color: var(--text); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover:not(:disabled) { opacity: 0.88; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--line-strong); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- landing */
.landing { flex: 1; display: grid; place-items: center; padding: 40px 24px; }
.landing-inner { width: 100%; max-width: 440px; text-align: left; }
.landing h1 { font-size: 30px; font-weight: 600; letter-spacing: -0.03em; margin: 0 0 8px; }
.landing p { color: var(--muted); margin: 0 0 28px; font-size: 15px; }
.landing-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
.landing-actions .btn { padding: 11px 18px; font-size: 14px; }
.landing .fine { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--faint); }

/* ---------- layout */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
  padding: 20px 24px 24px;
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
}
.live { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; align-content: start; min-width: 0; }
.live .duo { grid-column: 1 / -1; }
.duo { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
/* Show only the cards for what the robot is getting. */
.live[data-focus="distance"] .colour-card,
.live[data-focus="colour"] .hero,
.live[data-focus="colour"] .zones-card { display: none; }
.live[data-focus="colour"] .colour-card { order: -1; }
.live[data-focus="colour"] .swatch { width: 96px; height: 96px; }
.zones-card { display: flex; flex-direction: column; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.card-head, .hero-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.sub { color: var(--muted); font-size: 12.5px; min-height: 18px; }
/* Professional mode shows data lines (raw, signal, status), which read best in the instrument face. */
body[data-view="pro"] .sub { font: 11.5px/1.6 var(--mono); }

.pill {
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 8px 3px 7px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.pill[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); }
.pill[data-tone="warn"] { background: var(--warn-soft); color: var(--warn); }
.pill[data-tone="bad"] { background: var(--bad-soft); color: var(--bad); }
.pill[data-tone="accent"] { background: var(--accent-soft); color: var(--accent); }

.readout { display: flex; align-items: baseline; gap: 8px; margin: 14px 0 2px; }
.readout .num { font: 400 72px/1 var(--mono); letter-spacing: -0.06em; transition: color 0.2s; }
.readout.small .num { font-size: 38px; letter-spacing: -0.05em; }
.readout .unit { color: var(--muted); font: 14px var(--mono); }
.hero[data-dim="1"] .readout .num { color: var(--faint); }
.hero[data-dim="1"] .readout .unit { visibility: hidden; }
#spark { width: 100%; height: 120px; display: block; margin-top: 14px; }

/* ---------- output meter */
.meter { position: relative; height: 34px; margin: 16px 0 6px; }
.meter > div { position: absolute; top: 0; bottom: 0; }
.meter-track { left: 0; right: 0; top: 14px !important; bottom: 14px !important; background: var(--surface-2); border-radius: 3px; }
.meter-fault {
  left: 0; width: calc(100% * 0.1 / 3.3); top: 14px !important; bottom: 14px !important;
  background: repeating-linear-gradient(-45deg, var(--bad-soft) 0 3px, transparent 3px 6px);
  border-radius: 3px 0 0 3px;
}
.meter-span { top: 14px !important; bottom: 14px !important; background: var(--accent-soft); border-radius: 3px; transition: left 0.3s, width 0.3s; }
.meter-mark { width: 2px; background: var(--line-strong); top: 9px !important; bottom: 9px !important; transform: translateX(-1px); border-radius: 1px; transition: left 0.3s; }
.meter-mark::after {
  content: attr(data-label);
  position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
  font-size: 10px; color: var(--muted); white-space: nowrap;
}
.meter-needle {
  width: 12px; height: 12px; top: 11px !important; bottom: auto !important;
  border-radius: 50%; background: var(--text); box-shadow: 0 0 0 3px var(--surface);
  transform: translateX(-6px); transition: left 0.12s linear, background 0.2s;
}
.meter[data-fault="1"] .meter-needle { background: var(--bad); }
.meter-scale { display: flex; justify-content: space-between; color: var(--faint); font: 10.5px var(--mono); margin-bottom: 8px; }

/* ---------- colour */
.colour { display: flex; align-items: center; gap: 20px; margin: 16px 0 10px; }
.swatch {
  width: 64px; height: 64px; border-radius: 50%; flex: none;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background 0.4s;
}
.ratios { flex: 1; display: grid; gap: 8px; }
.ratio { display: grid; grid-template-columns: 12px 1fr 38px; align-items: center; gap: 10px; font-size: 11.5px; color: var(--muted); }
.ratio i { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.ratio b { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--muted); transition: width 0.3s; }
.ratio em { font: 11.5px var(--mono); text-align: right; color: var(--text); }
#barR { background: #e5484d; } #barG { background: #30a46c; } #barB { background: #3e63dd; }

/* ---------- zones */
.zones { display: grid; gap: 5px; margin: 16px auto 0; width: 100%; max-width: 340px; }
.zone {
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 3px;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.15;
  background: var(--surface-2);
  color: var(--muted);
  transition: background 0.25s, color 0.25s;
}
.zone { font-family: var(--mono); }
.zone small { display: block; font-size: 10px; font-weight: 400; opacity: 0.7; text-align: center; }
.hint { color: var(--muted); font-size: 13px; margin: auto 0; padding: 18px 0; max-width: 260px; display: grid; gap: 12px; justify-items: start; }
.zones[data-grid="4"] .zone { font-size: 11px; }
.zones[data-grid="4"] .zone small { display: none; }

/* ---------- settings panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: sticky;
  top: 77px;
  max-height: calc(100vh - 97px);
}
.panel-scroll { overflow-y: auto; padding: 6px 0; flex: 1; }
.section { padding: 16px 22px 10px; }
.section + .section { border-top: 1px solid var(--line); }
.section h2 { margin: 0 0 12px; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.row { display: grid; grid-template-columns: 112px 1fr; align-items: center; gap: 12px; min-height: 38px; }
.row > label { color: var(--muted); font-size: 13px; }
.row .note { grid-column: 2; color: var(--faint); font-size: 11.5px; margin: -4px 0 6px; }
.ctl { display: flex; gap: 6px; align-items: center; min-width: 0; }
.ctl .dash { color: var(--faint); }
.field { position: relative; flex: 1; min-width: 0; }
.field input, .field select {
  width: 100%;
  appearance: none;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text);
  font: 13px var(--sans);
  font-variant-numeric: tabular-nums;
  padding: 7px 10px;
  transition: border-color 0.15s, background 0.15s;
}
.field input { padding-right: 36px; }
.field select { padding-right: 26px; cursor: pointer; }
.field.select::after {
  content: ""; position: absolute; right: 11px; top: 50%; width: 6px; height: 6px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
.field input:hover, .field select:hover { border-color: var(--line-strong); }
.field .u { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); font-size: 11.5px; pointer-events: none; }
.field input::-webkit-inner-spin-button { display: none; }
.field input[type=number] { -moz-appearance: textfield; }

.seg { display: flex; background: var(--surface-2); border-radius: 6px; padding: 2px; width: 100%; }
.seg button {
  flex: 1; appearance: none; border: 0; background: transparent; color: var(--muted);
  font: 500 12.5px var(--sans); padding: 5px 8px; border-radius: 4px; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line-strong); }

.switch { appearance: none; width: 34px; height: 20px; border-radius: 99px; background: var(--line-strong); position: relative; cursor: pointer; transition: background 0.2s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,0.2); transition: transform 0.2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(14px); }

.changed .field input, .changed .field select, .changed .seg { box-shadow: inset 2px 0 0 var(--accent); }
.invalid .field input, .invalid .field select, .invalid .seg { border-color: var(--bad) !important; background: var(--bad-soft); }

details.section > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary h2 { margin: 0; }
details.section > summary::after { content: "+"; color: var(--muted); font-size: 15px; line-height: 1; }
details.section[open] > summary::after { content: "–"; }
details.section[open] > summary { margin-bottom: 12px; }
.adv .row { grid-template-columns: 1fr 132px; }
.adv .row > label { font: 12px var(--mono); }

.actions { border-top: 1px solid var(--line); padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.status { font-size: 12.5px; color: var(--muted); min-height: 18px; }
.status[data-tone="bad"] { color: var(--bad); }
.status[data-tone="ok"] { color: var(--ok); }
.buttons { display: flex; gap: 8px; justify-content: flex-end; }
.buttons .btn { flex: none; }
.buttons .btn.ghost { margin-right: auto; }

/* ---------- toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 5px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens */
@media (max-width: 1180px) {
  .live { grid-template-columns: 1fr; }
}
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; padding: 16px; }
  .panel { position: static; max-height: none; }
  .panel-scroll { flex: none; overflow: visible; }
  .actions { position: sticky; bottom: 0; background: var(--surface); border-radius: 0 0 var(--radius) var(--radius); }
  .meta { display: none; }
}
@media (max-width: 560px) {
  .duo { grid-template-columns: 1fr; }
  .bar { padding: 12px 16px; gap: 12px; }
  .readout .num { font-size: 60px; }
  .row { grid-template-columns: 96px 1fr; }
  #btnDisconnect { padding: 6px 8px; }
}
@media (max-width: 900px) {
  /* Row 1: brand, status (truncates) and Disconnect. Row 2: view and theme switches. */
  .bar .grow { display: none; }
  .conn { flex: 1 1 0; }
  #connText { overflow: hidden; text-overflow: ellipsis; }
  .bar { flex-wrap: wrap; row-gap: 0; }
  .bar::after { content: ""; order: 9; flex-basis: 100%; height: 0; } /* forces the line break */
  #viewSwitch { order: 10; margin-top: 10px; }
  #themeSwitch { order: 11; margin-top: 10px; margin-left: auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- header switches */
.seg.mini { width: auto; padding: 2px; border-radius: 6px; }
.seg.mini button { padding: 4px 10px; font-size: 12px; border-radius: 4px; flex: none; }
.seg.icons button { padding: 4px 7px; display: grid; place-items: center; }
.ico { display: inline-grid; width: 16px; height: 16px; }
.ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
body[data-view="simple"] .pro-only { display: none !important; }

/* ---------- landing steps */
.landing .lede { margin-bottom: 24px; }
.steps { list-style: none; padding: 0; margin: 0 0 28px; display: grid; gap: 10px; counter-reset: none; }
/* The number sits in the left gutter, so the step text flows as one block of
   inline content (bold words and all) instead of being split into grid cells. */
.steps li { position: relative; padding-left: 30px; min-height: 22px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.steps li > span {
  position: absolute; left: 0; top: 0;
  font: 12px/22.4px var(--mono); color: var(--faint);
}
.steps b { color: var(--text); font-weight: 600; }

/* ---------- simple panel */
.intro { color: var(--muted); font-size: 13px; margin: -4px 0 12px; }
.item { padding: 6px 0 12px; display: grid; gap: 8px; }
.item-l { font-size: 13px; font-weight: 500; }
.help { margin: -2px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.sentence {
  margin: 4px 0 10px; padding: 10px 12px; border-radius: 4px; background: var(--surface-2); border-left: 2px solid var(--line-strong);
  color: var(--text); font-size: 12.5px; line-height: 1.5;
}
.item .seg button { white-space: normal; line-height: 1.25; padding: 7px 8px; }
.item .seg button:disabled { opacity: 0.35; cursor: not-allowed; }

.cards { display: grid; gap: 8px; }
.opt {
  appearance: none; text-align: left; cursor: pointer; font: inherit; color: var(--text);
  display: grid; grid-template-columns: 36px 1fr; grid-template-rows: auto auto; column-gap: 12px; row-gap: 1px; align-items: center;
  padding: 12px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.opt:hover { border-color: var(--line-strong); }
.opt .ico {
  grid-row: 1 / 3; width: 36px; height: 36px; padding: 8px; border-radius: 4px;
  background: var(--surface-2); color: var(--muted); transition: background 0.15s, color 0.15s;
}
.opt-t { font-weight: 600; font-size: 13.5px; }
.opt-d { color: var(--muted); font-size: 12px; }
.opt[aria-checked="true"] { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.opt[aria-checked="true"] .ico { background: var(--text); color: var(--bg); }
.opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* sliders */
.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
.range-val { font-size: 13px; font-weight: 500; min-width: 72px; text-align: right; }
.range { appearance: none; -webkit-appearance: none; width: 100%; height: 22px; background: transparent; margin: 0; cursor: pointer; }
.range::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--fill, 0%), var(--surface-2) var(--fill, 0%));
}
.range::-moz-range-track { height: 4px; border-radius: 2px; background: var(--surface-2); }
.range::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}
.range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line-strong); box-shadow: 0 1px 3px rgba(0,0,0,0.18); }
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent); }

.dual-wrap { position: relative; height: 22px; }
.dual-track { position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 2px; background: var(--surface-2); }
.dual-fill { position: absolute; top: 9px; height: 4px; border-radius: 2px; background: var(--accent); }
.range.dual { position: absolute; inset: 0; pointer-events: none; }
.range.dual::-webkit-slider-runnable-track { background: transparent; }
.range.dual::-moz-range-track { background: transparent; }
.range.dual::-moz-range-progress { background: transparent; }
.range.dual::-webkit-slider-thumb { pointer-events: auto; position: relative; z-index: 2; }
.range.dual::-moz-range-thumb { pointer-events: auto; }
