:root {
  --bg: #10151b;
  --panel: #171e26;
  --panel-2: #1e2733;
  --line: #2b3644;
  --ink: #e6edf3;
  --muted: #93a4b3;
  --accent: #ffb224;
  --accent-dim: #8a6415;
  --ok: #40c47c;
  --warn: #e5a83b;
  --bad: #ef6a6a;
  --info: #6cb2e6;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

button {
  font: inherit;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: linear-gradient(180deg, #1b232d, #141b23);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1100;
}

.wordmark {
  font-family: "Avenir Next Condensed", "Futura", "Arial Narrow", var(--sans);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}

.wordmark-sub {
  color: var(--accent);
  margin-left: 6px;
}

.ident {
  display: flex;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.chip {
  font-family: var(--mono);
  font-size: 12px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-dim {
  color: var(--muted);
}

.chip:empty {
  display: none;
}

.mission-control {
  display: flex;
  align-items: center;
}

.btn-mission {
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}

.btn-mission.start {
  border-color: var(--ok);
  color: var(--ok);
  background: rgba(64, 196, 124, 0.08);
}

.btn-mission.stop {
  border-color: var(--bad);
  color: var(--bad);
  background: rgba(239, 106, 106, 0.08);
}

.leds {
  display: flex;
  gap: 14px;
}

.led {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.led i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #3a4654;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.6);
  transition: background 0.3s, box-shadow 0.3s;
}

.led.on i {
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
}

.led.bad i {
  background: var(--bad);
  box-shadow: 0 0 6px var(--bad);
}

/* Real time switch */

.rt-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.rt-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.rt-toggle input {
  position: absolute;
  opacity: 0;
}

.switch {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  position: relative;
  transition: background 0.2s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s, background 0.2s;
}

.rt-toggle input:checked + .switch {
  background: var(--accent-dim);
}

.rt-toggle input:checked + .switch::after {
  transform: translateX(18px);
  background: var(--accent);
}

.rt-toggle input:focus-visible + .switch {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

/* ---------- Notices ---------- */

/* Slim overlay strip pinned to the top of the video stage. */
.boot-notice {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(13, 17, 22, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #e8ce96;
  font-size: 12.5px;
  letter-spacing: 0.01em;
}

.boot-notice::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 6px rgba(229, 168, 59, 0.7);
}

.boot-notice.error {
  color: #f1b3b3;
}

.boot-notice.error::before {
  background: var(--bad);
  box-shadow: 0 0 6px rgba(239, 106, 106, 0.7);
}

.hidden {
  display: none !important;
}

/* ---------- Grid ---------- */

.grid {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  grid-template-areas:
    "video map"
    "compass telemetry"
    "control control"
    "checkpoints checkpoints";
  gap: 14px;
  padding: 14px 18px;
  max-width: 1600px;
  margin: 0 auto;
}

.video-panel {
  grid-area: video;
}

.map-panel {
  grid-area: map;
}


.compass-panel {
  grid-area: compass;
}

.telemetry-panel {
  grid-area: telemetry;
}

.control-panel {
  grid-area: control;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px 14px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- Video ---------- */

.video-stage {
  position: relative;
}

.player {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.player > div {
  width: 100%;
  height: 100%;
}

/* Overlay, not a flex sibling — the video always gets the full panel. */
.placeholder {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #000;
  text-align: center;
  padding: 0 24px;
}

.ph-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #cbd6df;
}

.ph-title.warn {
  color: var(--warn);
}

.ph-title.error {
  color: var(--bad);
}

.ph-sub {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted);
  max-width: 480px;
}

.ph-start {
  margin-top: 14px;
  font-size: 14px;
  padding: 10px 26px;
}

.pip {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 28%;
  aspect-ratio: 3 / 2;
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  z-index: 800;
}

/* ---------- Map ---------- */

#map {
  height: 420px;
  border-radius: 8px;
  background: var(--panel-2);
}

.map-panel .leaflet-container {
  font-family: var(--sans);
}

.mini-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.rover-icon {
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6));
}

.rover-icon svg {
  transition: transform 0.2s ease-out;
}

/* Checkpoint markers: segmented pill, one segment per coinciding checkpoint,
   each colored by its own state. */
.cp-marker {
  display: flex;
  height: 24px;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 11px;
  width: max-content;
}

.cp-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 25px;
  padding: 0 5px;
  background: #46535f;
  color: #dbe4ec;
}

.cp-seg + .cp-seg {
  border-left: 1px solid rgba(0, 0, 0, 0.35);
}

.cp-seg.done {
  background: #2e7d4f;
  color: #fff;
}

.cp-seg.next {
  background: var(--accent);
  color: #10151b;
}

.cp-marker.has-next {
  animation: cp-pulse 2s ease-out infinite;
}

@keyframes cp-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 178, 36, 0.55);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(255, 178, 36, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 178, 36, 0);
  }
}

/* ---------- Compass ---------- */

.compass {
  display: flex;
  align-items: center;
  gap: 18px;
}

#compass-svg {
  width: 168px;
  height: 168px;
  flex: none;
}

.compass-readout {
  display: flex;
  flex-direction: column;
}

.compass-degrees {
  font-family: var(--mono);
  font-size: 34px;
  font-weight: 600;
  color: var(--accent);
}

.compass-cardinal {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Telemetry tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.tile {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tile-wide {
  grid-column: span 3;
}

.tile-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.tile-value {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.tile-value b {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
}

.tile-value em {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
}

.tile-mono {
  font-family: var(--mono);
  font-size: 13px;
}

.meter {
  height: 5px;
  border-radius: 3px;
  background: #0c1116;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--ok);
  transition: width 0.4s, background 0.4s;
}

.sig-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 16px;
}

.sig-bars i {
  width: 5px;
  border-radius: 2px 2px 0 0;
  background: #313d4b;
}

.sig-bars i:nth-child(1) { height: 20%; }
.sig-bars i:nth-child(2) { height: 40%; }
.sig-bars i:nth-child(3) { height: 60%; }
.sig-bars i:nth-child(4) { height: 80%; }
.sig-bars i:nth-child(5) { height: 100%; }

.sig-bars i.on {
  background: var(--info);
}

.freshness {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.telemetry-panel.stale .tile-value b,
.telemetry-panel.stale .compass-degrees {
  color: var(--muted);
}

.telemetry-panel.stale .freshness {
  color: var(--warn);
}

/* ---------- Controls ---------- */

.drive {
  display: flex;
  gap: 18px;
  align-items: flex-start;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 6px;
  grid-template-areas:
    ". up ."
    "left stop right"
    ". down .";
}

.pad {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.1s, border-color 0.1s;
}

.pad[data-dir="forward"] { grid-area: up; }
.pad[data-dir="left"] { grid-area: left; }
.pad[data-dir="right"] { grid-area: right; }
.pad[data-dir="back"] { grid-area: down; }
.pad-stop { grid-area: stop; }

.pad:hover {
  border-color: var(--muted);
}

.pad.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.pad-stop {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--bad);
  border-color: rgba(239, 106, 106, 0.5);
}

.pad-stop:hover,
.pad-stop:active {
  background: rgba(239, 106, 106, 0.15);
  border-color: var(--bad);
}

.pad:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

.drive-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-width: 0;
  max-width: 420px;
}

.slider-label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.slider-label b {
  font-family: var(--mono);
  color: var(--ink);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.on {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255, 178, 36, 0.08);
}

.btn-ghost {
  background: transparent;
  font-size: 12px;
  padding: 4px 10px;
}

.kbd-hint {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.control-feedback {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  min-height: 15px;
}

.control-feedback.err {
  color: var(--bad);
}

.speak {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  max-width: 640px;
}

.speak input {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 7px 12px;
  font: inherit;
}

.speak input:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 1px;
}

/* ---------- Missions panel ---------- */

.missions-panel {
  grid-area: checkpoints;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 12px 8px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--ink);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

.tab-pane {
  min-height: 48px;
}

.active-mission-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.mission-meta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.empty {
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
}

.mission-list {
  display: flex;
  flex-direction: column;
}

.mission-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
}

.mission-row:last-child {
  border-bottom: none;
}

.mission-slug {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  min-width: 180px;
}

.mission-detail {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.mission-row .spacer {
  flex: 1;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge-ok {
  border-color: var(--ok);
  color: var(--ok);
}

.badge-bad {
  border-color: var(--bad);
  color: var(--bad);
}

.badge-live {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Checkpoints ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.chips li {
  font-family: var(--mono);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
}

.chips li.done {
  border-color: var(--ok);
  color: var(--ok);
}

.chips li.next {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Footer ---------- */

.footer {
  display: flex;
  gap: 18px;
  padding: 10px 18px 24px;
  max-width: 1600px;
  margin: 0 auto;
}

.footer a {
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
  font-family: var(--mono);
}

.footer a:hover {
  color: var(--info);
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "video"
      "map"
      "compass"
      "telemetry"
      "control"
      "checkpoints";
  }

  .ident {
    display: none;
  }
}

@media (max-width: 560px) {
  .leds .led {
    font-size: 0;
    gap: 0;
  }

  .drive {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
