/* Component appearance. Dynamic quantities arrive as CSS custom properties set by JS (ADR-0004):
   .slider  --value-frac [0,1] handle/fill position;  --host-hi [0,1] top of the allowed region. */

/* ---- connect screen (join a session: room code + your name) ---- */
.connect { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: var(--gap); }
.connect__card {
  width: 100%; max-width: 360px; background: var(--panel); border-radius: var(--radius);
  padding: 28px 24px; display: flex; flex-direction: column; gap: 16px;
}
.connect__title { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: 1px; }
.connect__sub { margin: -6px 0 4px; color: var(--muted); font-size: 15px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 13px; color: var(--muted); letter-spacing: .5px; }
.connect input {
  background: var(--panel-2); border: 1px solid transparent; border-radius: 12px;
  padding: 14px; color: var(--ink); font: inherit; font-size: 17px;
}
.connect__code { text-transform: uppercase; letter-spacing: 3px; font-variant-numeric: tabular-nums; }
.connect input:focus { outline: none; border-color: var(--accent); }
.connect input::placeholder { color: var(--muted); letter-spacing: normal; text-transform: none; }
.connect__error { margin: 0; color: var(--danger); font-size: 14px; }
.connect__go {
  margin-top: 4px; height: 54px; border: none; border-radius: 12px;
  background: var(--accent); color: #04211f; font-size: 18px; font-weight: 800; letter-spacing: 1px;
}
.connect__go:disabled { opacity: .6; }
.connect__go:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---- status bar ---- */
.status {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--panel); border-radius: var(--radius);
  font-size: 15px;
}
.status__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); }
.status[data-connection="connected"] .status__dot { background: var(--ok); }
.status[data-connection="closed"] .status__dot { background: var(--danger); }
.status__text { color: var(--ink); }
.status__lease { margin-left: auto; color: var(--muted); font-size: 13px; }
.status__lease[data-lease="driving"] { color: var(--accent); }

/* ---- machine state display (canvas drawn by state-display.js) ---- */
.state-display {
  background: var(--panel); border-radius: var(--radius);
  display: flex; justify-content: center; padding: 12px;
}
.state-display__canvas { width: 100%; max-width: 320px; height: auto; }

/* ---- "not controlling" veil over the controls (shown when this browser lacks the lease) ---- */
.controls { position: relative; }
.controls__veil {
  position: absolute; inset: 0; z-index: 3;             /* above the sliders regardless of DOM order */
  display: flex; align-items: center; justify-content: center;
  background: rgba(11, 13, 16, .55);                    /* semi-transparent grey over --bg */
  border-radius: var(--radius);
}
.controls__veil-text {
  color: var(--muted); font-size: 14px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase;
  padding: 8px 18px; background: var(--panel-2); border-radius: 999px;
}

/* ---- vertical speed slider ---- */
.slider--vertical { display: flex; flex-direction: column; align-items: center; gap: 12px; height: 100%; }
.slider__track {
  position: relative; width: var(--track-w); flex: 1 1 auto; min-height: 160px;
  background: var(--panel); border-radius: calc(var(--track-w) / 2); overflow: hidden;
}
/* greyed region ABOVE the host limit (undraggable). host-hi is the allowed max fraction. */
.slider__limit {
  position: absolute; left: 0; right: 0; top: 0;
  height: calc((1 - var(--host-hi)) * 100%);
  background: var(--limit);
}
.slider__fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--value-frac) * 100%);
  background: linear-gradient(0deg, var(--accent-dim), var(--accent));
}
.slider__handle {
  position: absolute; left: 50%; bottom: calc(var(--value-frac) * 100%);
  width: var(--handle-d); height: var(--handle-d);
  transform: translate(-50%, 50%);
  background: var(--ink); border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.slider__value { font-variant-numeric: tabular-nums; font-size: 28px; }
.slider__num { font-weight: 700; }
.slider__unit { color: var(--muted); font-size: 18px; margin: 0 2px; }
.slider__label { color: var(--muted); font-size: 14px; letter-spacing: 1px; text-transform: uppercase; }
.slider__handle { touch-action: none; cursor: grab; }
.slider__handle:active { cursor: grabbing; }
.slider__handle:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- range mode: two handles bounding a stroke window; both ends greyed beyond the host window ----
   Consumes --lo-frac/--hi-frac (handle positions) and --host-lo/--host-hi (allowed window). */
.slider--range .slider__limit--top {
  top: 0; height: calc((1 - var(--host-hi)) * 100%);
}
.slider--range .slider__limit--bottom {
  top: auto; bottom: 0; height: calc(var(--host-lo) * 100%);
}
.slider--range .slider__band {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--lo-frac) * 100%);
  height: calc((var(--hi-frac) - var(--lo-frac)) * 100%);
  background: linear-gradient(0deg, var(--accent-dim), var(--accent));
}
.slider--range .slider__handle--lo { bottom: calc(var(--lo-frac) * 100%); }
.slider--range .slider__handle--hi { bottom: calc(var(--hi-frac) * 100%); }

/* ============================ owner console ============================ */
.card { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; }
.card__title {
  margin: 0 0 12px; font-size: 13px; font-weight: 600;
  letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted);
}

/* ---- roster: the signature — who's on the machine, who holds the lease ----
   Bounded + scrollable so a big room never pushes the controls off-screen; the active driver is
   rendered first and sticks to the top of the scroll area, so who's driving is always in view. */
.roster__list {
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px;
  max-height: 264px; overflow-y: auto;
}
.roster__row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--panel-2); border-radius: 12px;
  border-left: 3px solid transparent;
}
.roster__row[data-active="true"] {
  border-left-color: var(--accent);
  position: sticky; top: 0; z-index: 1;                 /* pin the driver above the scrolling others */
}
.roster__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.roster__row[data-active="true"] .roster__dot { background: var(--ok); }
.roster__pid { font-weight: 600; font-variant-numeric: tabular-nums; margin-right: auto; }
.roster__chip {
  font-size: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--accent);
}
.roster__btn {
  border: 1px solid var(--panel); border-radius: 10px; padding: 8px 14px;
  font-size: 14px; font-weight: 600; color: var(--ink); background: var(--panel);
}
.roster__btn[data-action="grant"] { background: var(--accent-dim); border-color: var(--accent-dim); }
.roster__btn[data-action="revoke"] { background: transparent; border-color: var(--muted); color: var(--muted); }
.roster__btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.roster__empty { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
@container (min-width: 720px) { .roster__list { max-height: min(60vh, 520px); } }

/* ---- invite card: the room code + copy the guest link ---- */
.invite { text-align: center; }
.invite__code {
  font-size: 34px; font-weight: 800; letter-spacing: 6px; font-variant-numeric: tabular-nums;
  color: var(--accent); margin: 2px 0 6px;
}
.invite__hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.invite__copy {
  width: 100%; height: 48px; border: 1px solid var(--accent-dim); border-radius: 12px;
  background: var(--accent-dim); color: var(--ink); font-size: 16px; font-weight: 700; letter-spacing: .5px;
}
.invite__copy:active { filter: brightness(.9); }
.invite__copy[data-copied="true"] { background: var(--ok); border-color: var(--ok); color: #04210f; }
.invite__copy:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- limits card: cap + stroke-window sliders, then the switches ---- */
.envelope__sliders {
  display: flex; justify-content: center; gap: calc(var(--gap) * 1.5);
  height: 220px; margin-bottom: 18px;
}
.switches { display: flex; flex-direction: column; gap: 4px; }
.switch {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; padding: 10px 4px; color: var(--ink);
  font-size: 15px; text-align: left; width: 100%;
}
.switch__label { flex: 1 1 auto; }
.switch__track {
  flex: 0 0 auto; position: relative; width: 46px; height: 28px;
  border-radius: 14px; background: var(--panel-2); transition: background .15s;
}
.switch__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s;
}
.switch[aria-checked="true"] .switch__track { background: var(--accent-dim); }
.switch[aria-checked="true"] .switch__track::after { transform: translateX(18px); background: var(--accent); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ---- owner e-stop bar (estop + re-arm side by side) ----
   Sticky to the bottom of the viewport: when the console is tall enough to scroll, STOP floats at the
   bottom (always visible, thumb-reachable) and fades the scrolling content into it; when everything
   fits it just rests in flow. Owns the bottom safe-area (the console padding hands it off). */
.ownerbar {
  display: flex; gap: 12px;
  position: sticky; bottom: 0; z-index: 4;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  box-shadow: 0 -18px 20px -6px var(--bg);
}
.ownerbar .estop { flex: 1 1 auto; }
.rearm {
  flex: 0 0 auto; padding: 0 22px; border-radius: var(--radius);
  border: 2px solid var(--accent); background: transparent; color: var(--accent);
  font-size: 18px; font-weight: 700;
}
.rearm:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .switch__track, .switch__track::after { transition: none; }
}

/* ---- e-stop: always present, unmissable, large touch target ---- */
.estop {
  height: var(--estop-h); border: none; border-radius: var(--radius);
  background: var(--danger); color: var(--danger-ink);
  font-size: 26px; font-weight: 800; letter-spacing: 2px;
}
.estop:active { filter: brightness(.9); }
.estop[data-latched="true"] { background: var(--panel-2); color: var(--danger); outline: 2px solid var(--danger); }
