:root {
  --bg: #0a0a0b;
  --panel: rgba(16, 16, 18, .44);
  --line: rgba(255, 255, 255, .16);
  --text: #e8e8ea;
  --dim: #a0a0a6;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 var(--mono); }
#map { position: fixed; inset: 0; }

/* faint scanline grid over the map, pointer-transparent */
.grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 96px 96px;
  opacity: .12;
  mask-image: radial-gradient(ellipse at center, transparent 40%, #000 100%);
  -webkit-mask-image: radial-gradient(ellipse at center, transparent 40%, #000 100%);
}

/* columns hold the panels; the columns are what is positioned */
.col { position: fixed; z-index: 2; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; scrollbar-width: none;
  max-height: calc(100vh - 32px - 52px); pointer-events: none; }
.col::-webkit-scrollbar { display: none; }
.col > * { pointer-events: auto; }
#hudcols { display: contents; }   /* desktop: the two columns position themselves; phones: see the media query below */
#left { left: 16px; top: max(16px, env(safe-area-inset-top)); width: 244px; }
#right { right: 16px; top: max(16px, env(safe-area-inset-top)); width: 268px; }
.panel {
  position: relative; flex: none;
  padding: 12px 14px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.panel header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.brand { letter-spacing: .18em; font-weight: 600; font-size: 12px; }
.brand b { color: #d71d24; }
.sig { font-size: 10px; letter-spacing: .14em; padding: 2px 6px; border-radius: 3px; border: 1px solid currentColor; }
.sig.ok { color: var(--ok); }
.sig.wait { color: var(--warn); }
.sig.lost { color: var(--bad); animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 0 0 10px; }
.stats div { border-left: 2px solid var(--line); padding-left: 8px; }
.stats dt { color: var(--dim); font-size: 9px; letter-spacing: .14em; }
.stats dd { margin: 0; font-size: 20px; font-variant-numeric: tabular-nums; }

.feed { display: flex; justify-content: space-between; gap: 8px; color: var(--dim); font-size: 11px; margin-bottom: 10px; font-variant-numeric: tabular-nums; }

.toggles { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 8px 0 0; }
.toggles legend { padding: 0; color: var(--dim); font-size: 9px; letter-spacing: .14em; float: left; width: 100%; margin-bottom: 4px; }
.toggles label { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; clear: both; }
.toggles i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 6px var(--c); }
.toggles input { accent-color: #d4d4da; margin-left: auto; }

#credits { position: fixed; z-index: 2; left: 16px; bottom: 8px; color: var(--dim); font-size: 10px; opacity: .7; pointer-events: none; }

/* MapLibre chrome, themed */
.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--line); box-shadow: none !important; }
.maplibregl-ctrl-group button { filter: invert(1) hue-rotate(180deg); }
.maplibregl-ctrl-attrib { background: var(--panel) !important; color: var(--dim) !important; font-family: var(--mono); }
.maplibregl-ctrl-attrib a { color: var(--text) !important; }
.maplibregl-popup-content { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  backdrop-filter: blur(8px); font: 12px/1.45 var(--mono); padding: 10px 12px; box-shadow: 0 4px 24px rgba(0,0,0,.5); }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--line); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--line); }
.maplibregl-popup-close-button { color: var(--text); }
.pop-title { font-weight: 600; letter-spacing: .06em; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.pop-title i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.pop-row { display: flex; justify-content: space-between; gap: 18px; color: var(--dim); }
.pop-row b { color: var(--text); font-weight: 400; font-variant-numeric: tabular-nums; }

@media (max-width: 560px) {
  .panel { width: calc(100vw - 32px); }
  .stats dd { font-size: 16px; }
  .toggles { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
  .toggles legend { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { .sig.lost { animation: none; } }

/* ---- generic panels ---- */
.ph { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: -2px 0 8px; }
.pt { all: unset; cursor: pointer; letter-spacing: .16em; font-size: 10px; color: var(--dim); }
.pt:hover, .pt:focus-visible { color: var(--text); }
.pt::before { content: "▾ "; }
.panel.collapsed .pt::before { content: "▸ "; }
.panel.collapsed .panel-body, .panel.collapsed .panel-note { display: none; }
.panel.collapsed .ph { margin-bottom: -2px; }
.pbadge { font-size: 9px; letter-spacing: .12em; padding: 1px 5px; border-radius: 3px; border: 1px solid currentColor; }
.pbadge.ok { color: var(--ok); } .pbadge.wait { color: var(--warn); }
.pbadge.lost { color: var(--bad); animation: blink 1.2s steps(2) infinite; }
.panel.lost .panel-body { opacity: .45; }
.panel-note { margin-top: 8px; color: var(--bad); font-size: 10px; letter-spacing: .06em; }
.dim { color: var(--dim); }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 0; }
.kv > div { border-left: 2px solid var(--line); padding-left: 8px; min-width: 0; }
.kv .wide { grid-column: 1 / -1; }
.kv dt { color: var(--dim); font-size: 9px; letter-spacing: .14em; }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv dd.gpu { font-size: 10px; white-space: normal; line-height: 1.3; max-height: 2.6em; }

/* ---- mission clock ---- */
.mission { position: fixed; z-index: 3; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: stretch; gap: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.mc-cell { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 6px; align-items: baseline; padding: 6px 14px; border-right: 1px solid var(--line); }
.mc-cell .k { grid-column: 1 / -1; color: var(--dim); font-size: 8px; letter-spacing: .2em; }
.mc-cell .v { font-size: 17px; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.mc-cell .s { color: var(--dim); font-size: 10px; align-self: center; }
.mc-cell.main .v { font-size: 20px; }
.mc-btn { all: unset; cursor: pointer; padding: 0 12px; color: var(--dim); font-size: 10px; letter-spacing: .16em; align-self: stretch; display: flex; align-items: center; }
.mc-btn:hover, .mc-btn:focus-visible { color: var(--text); }
.mc-btn[aria-pressed="true"] { color: var(--warn); }
body.hud-hidden #left, body.hud-hidden #right, body.hud-hidden .banner, body.hud-hidden #credits { display: none; }

/* ---- weather ---- */
.wx-main { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.wx-temp { font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; }
.wx-text { color: var(--dim); }
.wind-arrow { display: inline-block; width: 1em; text-align: center; color: #d4d4da; }

/* ---- sun ---- */
.sun-arc { width: 100%; height: auto; display: block; margin: 0 0 8px; }
.sun-arc .horizon { stroke: var(--line); stroke-width: 1; }
.sun-arc .curve { fill: none; stroke: #f2a33a; stroke-width: 1.4; opacity: .8; }
.sun-arc .sun-dot { fill: #ffd27a; stroke: #070b16; stroke-width: 1.2; filter: drop-shadow(0 0 4px #f2a33a); }

/* ---- SL ---- */
.sl-station + .sl-station { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.sl-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.sl-row { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center; padding: 2px 0; font-size: 12px; }
.sl-row .badge { background: var(--c); color: #fff; text-align: center; border-radius: 3px; font-size: 11px; padding: 0 2px; font-weight: 600; }
.sl-row .dest { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sl-row .when { color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- road traffic ---- */
.tr-head { margin-bottom: 6px; line-height: 1.35; }
.tr-head b { color: #fff; }
.tr-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; padding: 2px 0; font-size: 12px; }
.tr-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 6px var(--c); }
.tr-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-row .dl { color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tr-src { margin-top: 8px; font-size: 9px; letter-spacing: .04em; line-height: 1.35; }
.cam-pop { width: 288px; }
.cam-img { display: block; position: relative; min-height: 120px; margin: 6px 0; background: #050506; border-radius: 4px; overflow: hidden; }
.cam-img img { display: block; width: 100%; height: auto; }
.cam-img img[hidden] { display: none; }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; text-align: center; padding: 8px; }
.cam-msg[hidden] { display: none; }
.cam-desc { margin: 6px 0 2px; font-size: 11px; line-height: 1.35; }
.cam-credit { font-size: 9px; letter-spacing: .04em; }
@media (max-width: 420px) { .cam-pop { width: min(288px, calc(100vw - 72px)); } }

/* ---- places ---- */
.place-actions { display: flex; gap: 6px; margin-bottom: 8px; }
.btn { all: unset; cursor: pointer; flex: 1; text-align: center; font-size: 10px; letter-spacing: .1em; padding: 4px 0; border: 1px solid var(--line); border-radius: 4px; color: var(--text); }
.btn:hover, .btn:focus-visible { border-color: var(--text); background: rgba(255, 255, 255, .10); }
.places { list-style: none; margin: 0; padding: 0; max-height: 232px; overflow-y: auto; scrollbar-width: thin; }
.places button { all: unset; cursor: pointer; display: flex; gap: 8px; width: 100%; padding: 3px 4px; border-radius: 3px; box-sizing: border-box; }
.places button:hover, .places button:focus-visible { background: rgba(255, 255, 255, .12); }
.places button.active { background: rgba(255, 255, 255, .18); color: #fff; }
.places .n { color: var(--dim); font-variant-numeric: tabular-nums; }

/* ---- title card (tour / goto) ---- */
.banner { position: fixed; z-index: 3; left: 50%; bottom: calc(var(--term-h, 60px) + 28px); transform: translate(-50%, 8px); width: min(560px, calc(100vw - 32px));
  padding: 12px 16px; background: var(--panel); border-left: 3px solid #d71d24; border-radius: 4px; opacity: 0; pointer-events: none;
  transition: opacity .5s, transform .5s; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.banner.show { opacity: 1; transform: translate(-50%, 0); }
.banner .bn { display: block; color: var(--dim); font-size: 10px; letter-spacing: .2em; }
.banner .bt { display: block; font-size: 22px; letter-spacing: .04em; margin: 2px 0 4px; }
.banner .bx { display: block; color: var(--text); font-size: 13px; line-height: 1.45; }

/* ---- terminal ---- */
.term { position: fixed; z-index: 4; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(720px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.term:focus-within { border-color: rgba(255, 255, 255, .45); }
.term-out { max-height: 138px; overflow-y: auto; padding: 0 12px; scrollbar-width: thin; }
.term.has-output .term-out { padding: 8px 12px 2px; }
.tl { white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 1.5; }
.tl.pre { white-space: pre; overflow-x: auto; }
.tl.echo { color: var(--dim); } .tl.dim { color: var(--dim); } .tl.err { color: var(--bad); } .tl.ok { color: var(--ok); }
.term-form { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.term .prompt { color: #d71d24; font-weight: 700; }
.term input { all: unset; flex: 1; min-width: 0; font: inherit; color: var(--text); caret-color: #ff6b6b; }
.term input::placeholder { color: var(--dim); }

@media (max-width: 1200px) { .mc-cell.opt { display: none; } .mc-cell .s { display: none; } }
@media (max-width: 900px) { .mission { top: 8px; } }
@media (max-width: 700px) {
  /* one scrolling sheet over the map: vehicles, telemetry, places, then weather, sun and SL */
  #hudcols { display: flex; flex-direction: column; gap: 10px; position: fixed; z-index: 2; left: 8px; right: 8px; top: 64px;
    bottom: calc(var(--term-h, 60px) + 20px); overflow-y: auto; scrollbar-width: none; pointer-events: none; }
  #hudcols > * { pointer-events: auto; }
  #left, #right { position: static; width: auto; max-height: none; overflow: visible; }
  .banner { bottom: calc(var(--term-h, 60px) + 16px); }
}
@media (prefers-reduced-motion: reduce) { .pbadge.lost { animation: none; } .banner { transition: none; } }

@media (max-width: 560px) {
  .mission { max-width: calc(100vw - 16px); }
  .mc-cell { padding: 5px 9px; }
  .mc-cell .v, .mc-cell.main .v { font-size: 15px; letter-spacing: 0; }
  .mc-cell:nth-child(2) { display: none; }          /* UTC: the local time and T+ are what matters on a phone */
  .mc-btn { padding: 0 9px; }
  .term-out { max-height: 96px; }
}

/* The map's zoom / compass buttons sit to the LEFT of the right-hand column, so the column can hug the right edge.
   (column: 16 px margin + 268 px width; the control has its own 10 px margin) */
.maplibregl-ctrl-top-right { right: 286px; }
body.hud-hidden .maplibregl-ctrl-top-right { right: 0; }
@media (max-width: 700px) { .maplibregl-ctrl-top-right { right: 0; } }

/* LIVE is a switch: click to pause every API request */
button.sig { all: unset; box-sizing: border-box; cursor: pointer; font-size: 10px; letter-spacing: .14em; padding: 2px 6px; border-radius: 3px; border: 1px solid currentColor; }
button.sig:hover, button.sig:focus-visible { background: rgba(255, 255, 255, .12); }
.sig.paused, .pbadge.paused { color: var(--dim); }
.sig.paused::before { content: "⏸ "; }

/* ---- traffic panel, camera popup ---- */
.tr-head { margin-bottom: 6px; line-height: 1.35; }
.tr-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 7px; align-items: center; padding: 1px 0; font-size: 12px; }
.tr-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tr-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-row .dl { color: var(--dim); font-variant-numeric: tabular-nums; }
.tr-src { margin-top: 8px; font-size: 10px; line-height: 1.4; }
.cam-pop { width: 288px; max-width: calc(100vw - 80px); }
.cam-img { position: relative; min-height: 130px; background: rgba(0, 0, 0, .35); border-radius: 4px; overflow: hidden; margin: 4px 0 6px; }
.cam-img img { display: block; width: 100%; height: auto; }
.cam-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 8px; font-size: 12px; }
.cam-desc { margin: 4px 0 2px; font-size: 11px; line-height: 1.4; }
.cam-credit { font-size: 10px; }
