:root {
    /* Surfaces. Vision UI navy, shared with the dashboard and every other
       module via /assets/tokens.css. Never pure black — pure black blooms on
       the Tesla panel in daylight and crushes the numerals. */
    --bg:#030C1D;
    --panel:#060B27;
    --panel-lift:#0A1030;   /* top of the panel gradient, reads as light from above */
    --rule:#4E5E89;   /* structural borders, 3.02:1 on panel */
    --rule-soft:#31406E;   /* decorative hairlines and tape ticks */

    /* Signal. Blue is the resting state; green and red belong to CAST alone.
       That rule is unchanged by the repalette — only the resting colour moved,
       from amber to blue, so the CAST readout is still the one place on the
       instrument where green or red can appear.
       Measured against --panel, not eyeballed:
       lume 7.79  lume-dim 4.94  label 8.58  early 7.25  late 6.36 */
    --lume:#4FA9FF;
    --lume-dim:#6B80B2;
    --label:#A0AEC0;
    --early:#01B574;
    --late:#FF5B5B;

    /* Rhythm. One scale, so spacing decisions stop being ad hoc. */
    --s1: clamp(4px,  0.7vh,  8px);
    --s2: clamp(6px,  1.1vh, 14px);
    --s3: clamp(8px,  1.6vh, 20px);
    --s4: clamp(12px, 2.4vh, 28px);
    --radius: 6px;
  }

  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

  html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--lume);
    font-family: var(--mono);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
  }

  /* The instrument itself is .wrap; body is just the shell grid's host now
     that the shared left nav sits beside it. */
  .wrap {
    height: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: var(--s2);
    gap: var(--s2);
  }

  /* 11px floor, not 9px — this is read at arm's length, not phone range. */
  .lbl {
    font-size: clamp(11px, 1.45vh, 14px);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--label);
    font-weight: 700;
  }

  .num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    line-height: 0.9;
    font-weight: 700;
  }

  /* ---------- status strip ---------- */
  .status {
    display: flex;
    align-items: center;
    gap: clamp(10px, 2vw, 28px);
    padding: 0 var(--s1) var(--s2);
    border-bottom: 1px solid var(--rule-soft);
    flex: 0 0 auto;
  }
  .status .grow { margin-left: auto; }

  .lock {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .dot {
    width: 11px; height: 11px;
    border-radius: 50%;
    background: var(--late);
    box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 22%, transparent);
    color: var(--late);
    transition: background 200ms, color 200ms, box-shadow 200ms;
  }
  .dot[data-lock="good"]   { background: var(--early); color: var(--early); }
  .dot[data-lock="coarse"] { background: var(--lume);  color: var(--lume); }
  .dot[data-lock="none"]   { background: var(--late);  color: var(--late); }

  .status-val {
    font-size: clamp(12px, 1.7vh, 16px);
    color: var(--lume-dim);
    font-variant-numeric: tabular-nums;
  }

  /* back to the dashboard; sized as a touch target, not a text link */
  .nav-btn {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 16px;
    font-weight: 700;
    font-size: clamp(11px, 1.7vh, 15px);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--lume);
    background: linear-gradient(var(--panel-lift), var(--panel));
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    touch-action: manipulation;
    transition: background 120ms, border-color 120ms, color 120ms;
  }
  .nav-btn:active { background: var(--rule-soft); }
  .nav-btn:focus-visible { outline: 2px solid var(--lume); outline-offset: 2px; }

  /* ---------- hero ---------- */
  .hero {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 1fr 1.45fr;
    gap: var(--s3);
    min-height: 0;
  }

  /* Panels read as lit from above: a vertical gradient plus one bright
     hairline along the top edge. Cheaper and crisper in sunlight than a
     drop shadow, which just muddies the edge on a glossy screen. */
  .cell {
    position: relative;
    background: linear-gradient(var(--panel-lift), var(--panel));
    border: 1px solid var(--rule-soft);
    border-radius: var(--radius);
    padding: var(--s3) clamp(12px, 1.8vw, 24px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    min-height: 0;
  }
  .cell::before {
    content: "";
    position: absolute;
    left: var(--radius); right: var(--radius); top: 0;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--rule), transparent);
    pointer-events: none;
  }

  .speed-val {
    font-size: clamp(58px, 15vh, 150px);
    letter-spacing: -0.045em;
  }
  .odo-val {
    font-size: clamp(64px, 17vh, 170px);
    letter-spacing: -0.05em;
  }
  .unit {
    font-size: 0.26em;
    letter-spacing: 0.14em;
    color: var(--lume-dim);
    margin-left: 0.35em;
    font-weight: 700;
  }

  .hero-left  { display: flex; flex-direction: column; gap: var(--s3); min-height: 0; }
  .hero-left .cell { flex: 1 1 0; }

  /* ---------- CAST tape (signature) ---------- */
  .cast {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    justify-content: center;
  }
  .cast-head {
    display: flex;
    align-items: baseline;
    gap: 12px;
  }
  .cast-err {
    font-size: clamp(40px, 10vh, 96px);
    letter-spacing: -0.035em;
    transition: color 200ms;
  }
  .cast-err[data-state="early"] { color: var(--early); }
  .cast-err[data-state="late"]  { color: var(--late); }
  .cast-err[data-state="idle"]  { color: var(--lume-dim); }

  .tape {
    position: relative;
    height: clamp(34px, 6.5vh, 62px);
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid var(--rule-soft);
    overflow: hidden;
  }
  /* Minor ticks every 10%, with the quarter marks carrying more weight so
     the eye can find ±25% without counting. */
  .tape-ticks {
    position: absolute;
    inset: 0;
    background-image:
      repeating-linear-gradient(to right, var(--rule) 0 1px, transparent 1px 25%),
      repeating-linear-gradient(to right, var(--rule-soft) 0 1px, transparent 1px 10%);
  }
  .tape-datum {
    position: absolute;
    left: 50%;
    top: 0; bottom: 0;
    width: 2px;
    margin-left: -1px;
    background: var(--lume);
    box-shadow: 0 0 8px color-mix(in srgb, var(--lume) 45%, transparent);
  }
  .tape-bar {
    position: absolute;
    top: 20%;
    bottom: 20%;
    background: var(--lume-dim);
    border-radius: 2px;
    left: 50%;
    width: 0;
    transition: left 240ms linear, width 240ms linear, background 200ms;
  }
  .tape-bar[data-state="early"] { background: var(--early); }
  .tape-bar[data-state="late"]  { background: var(--late); }

  .cast-sub {
    display: flex;
    gap: clamp(12px, 2.4vw, 32px);
    align-items: baseline;
    min-width: 0;
  }
  /* Each pair stays on one line — a value that wraps away from its unit
     ("−0.16" over "km") is unreadable at a glance, which is the whole job. */
  .cast-sub > div {
    display: flex;
    align-items: baseline;
    gap: 8px;
    white-space: nowrap;
    min-width: 0;
  }
  .cast-sub .v {
    font-size: clamp(15px, 2.6vh, 26px);
    color: var(--lume);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    white-space: nowrap;
  }

  /* ---------- secondary row ---------- */
  .strip {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--s2);
  }
  .strip .cell { padding: var(--s2) clamp(10px, 1.2vw, 18px); }
  .strip .v {
    font-size: clamp(20px, 4vh, 42px);
    letter-spacing: -0.025em;
    margin-top: 0.18em;
  }
  .strip .v .unit { font-size: 0.32em; }

  /* ---------- controls ---------- */
  .controls {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--s2);
  }
  button {
    font-family: inherit;
    font-weight: 700;
    font-size: clamp(11px, 1.7vh, 16px);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--lume);
    background: linear-gradient(var(--panel-lift), var(--panel));
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: var(--s4) 4px;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 120ms, border-color 120ms, color 120ms, transform 120ms;
  }
  button:active { background: var(--rule-soft); transform: translateY(1px); }
  button:focus-visible { outline: 2px solid var(--lume); outline-offset: 2px; }
  button[data-on="true"] {
    color: #14120E;
    background: var(--lume);
    border-color: var(--lume);
  }
  button.warn[data-on="true"] { background: var(--late); border-color: var(--late); color: #fff; }

  .stepper { display: flex; gap: 4px; }
  .stepper button { flex: 1 1 0; padding-left: 0; padding-right: 0; }

  @media (max-width: 760px) {
    .hero { grid-template-columns: 1fr; }
    .strip { grid-template-columns: repeat(3, 1fr); }
    .controls { grid-template-columns: repeat(4, 1fr); }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before { transition: none !important; }
    button:active { transform: none; }
  }
