/* Balloon Tracker - designed by John Thomas */
:root {
  --bg: #0d1420;
  --panel: #131c2b;
  --panel-2: #1a2537;
  --line: #273449;
  --text: #e7edf6;
  --muted: #8d9bb1;
  --accent: #4cc3ff;
  --accent-ink: #04121c;
  --good: #46d39a;
  --warn: #ffb020;
  --bad: #ff5d73;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  color-scheme: dark;
}
/* the theme follows the device's light or dark setting */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef2f7; --panel: #ffffff; --panel-2: #f3f6fa; --line: #d8e0ea; --text: #142033;
    --muted: #5d6b80; --accent: #0a7bd6; --accent-ink: #ffffff; --shadow: 0 6px 24px rgba(20, 32, 51, .18);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.pad { padding: 12px 14px; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- top bar */
#topbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.logo { width: 26px; height: 26px; color: var(--bad); flex: none; }
.titles { min-width: 0; }
.title { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.subtitle { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock-box { text-align: center; }
.clock { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: .5px; }
.clock-sub { color: var(--muted); font-size: 11px; }
.top-actions { flex: 1; display: flex; justify-content: flex-end; }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.icon { padding: 6px 10px; min-width: 36px; }

/* ---------------------------------------------------------------- sim bar */
#simbar {
  display: flex; align-items: center; gap: 12px; padding: 6px 14px;
  background: var(--panel-2); border-bottom: 1px solid var(--line); z-index: 4;
}
.sim-tag { background: var(--warn); color: #241600; font-weight: 700; font-size: 11px; padding: 3px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .5px; }
.sim-speed { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.sim-speed select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
#sim-slider { flex: 1; min-width: 80px; accent-color: var(--accent); }
.sim-slider-time { font-family: var(--mono); color: var(--muted); min-width: 44px; }

/* ------------------------------------------------------------ main layout */
#main { flex: 1; display: flex; min-height: 0; position: relative; }
#sidebar {
  width: 350px; flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line); z-index: 3; min-height: 0;
}
#mapwrap { flex: 1; position: relative; min-width: 0; }
#cesium { position: absolute; inset: 0; }
.cesium-widget-credits { font-size: 10px !important; opacity: .75; }
.cesium-viewer-bottom { left: 6px !important; bottom: 2px !important; }

.panel-tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: 0; padding: 11px 6px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { display: none; overflow-y: auto; flex: 1; min-height: 0; }
.tab-body.active { display: block; }
.sheet-handle { display: none; }
.section-h { margin: 16px 14px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }

/* --------------------------------------------------------- balloon cards */
.balloon-card {
  display: flex; width: calc(100% - 20px); margin: 8px 10px 0; gap: 10px; align-items: stretch;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; text-align: left;
}
.balloon-card:hover { border-color: var(--muted); }
.balloon-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.bc-swatch { width: 6px; border-radius: 3px; flex: none; }
.swatches { display: flex; flex-direction: column; gap: 3px; width: 6px; }
.swatches i { flex: 1; border-radius: 3px; }
.bc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.bc-top { display: flex; align-items: center; gap: 8px; }
.bc-name { font-weight: 700; font-size: 15px; }
.bc-nick { color: var(--muted); font-size: 12px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 20px; background: var(--line); color: var(--text); margin-left: auto; text-transform: uppercase; letter-spacing: .4px; }
.badge.ascent { background: #1f6f4f; color: #dfffee; }
.badge.descent { background: #8a3a12; color: #fff1e6; }
.badge.landed { background: #2a4d8f; color: #e6efff; }
.badge.probably_landed { background: #4a3f8c; color: #ece8ff; }
.badge.recovered { background: #3d3d3d; color: #ddd; }
.badge.prelaunch { background: #574400; color: #fff4cc; }
.bc-stats { display: grid; grid-template-columns: repeat(3, auto); gap: 2px 12px; font-size: 12px; color: var(--muted); }
.bc-stats b { color: var(--text); font-weight: 600; font-family: var(--mono); }
.bc-stats .bc-plan { grid-column: 1 / -1; }
.bc-sub { font-size: 12px; color: var(--muted); }
.stale { color: var(--warn) !important; }

.vehicle-list { padding: 0 10px 14px; display: grid; gap: 6px; }
.vehicle {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; font-size: 13px;
}
.vehicle .vid { font-family: var(--mono); font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--line); }
.vehicle.recovery .vid { background: #1e5d7a; color: #e4f6ff; }
.vehicle.launch .vid { background: #5b4a1c; color: #fff3d6; }
.vehicle .vage { margin-left: auto; color: var(--muted); font-size: 12px; font-family: var(--mono); }

/* ---------------------------------------------------------------- details */
#details { padding: 10px 12px 18px; }
.d-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.d-head .dot { width: 14px; height: 14px; border-radius: 50%; }
.d-head h2 { margin: 0; font-size: 18px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }
.kv dd .muted { font-family: var(--font); }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; }
.card h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.big { font-size: 20px; font-weight: 700; font-family: var(--mono); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.gm {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--accent-ink);
  background: var(--accent); padding: 6px 10px; border-radius: 8px; font-weight: 600; font-size: 13px;
}
.gm svg { width: 14px; height: 14px; }
/* a car popup's driving-directions button: outlined, so it doesn't look like Open in GPS */
.drive {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--accent);
  border: 1.5px solid var(--accent); padding: 5px 10px; border-radius: 8px; font-weight: 600; font-size: 13px;
}
.drive:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.drive svg { width: 16px; height: 16px; flex: none; }
.popup .assigned { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.linkbtn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; cursor: pointer; color: var(--text); font-size: 13px; }
.src-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.src-table td, .src-table th { padding: 4px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.src-table th { color: var(--muted); font-weight: 600; }
canvas.chart { width: 100%; height: 190px; display: block; }
.events { font-size: 12px; margin: 0; padding-left: 16px; }

/* ----------------------------------------------------------------- layers */
.layer-group { margin-bottom: 14px; }
.layer-group h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.chk { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; }
.chk input { width: 17px; height: 17px; accent-color: var(--accent); }

/* -------------------------------------------------------------- map tools */
#map-tools { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; z-index: 2; }
.tool-group { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; box-shadow: var(--shadow); }
.tool { background: none; border: 0; padding: 7px 11px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; border-right: 1px solid var(--line); }
.tool:last-child { border-right: 0; }
.tool:hover { color: var(--text); }
.tool.active { background: var(--accent); color: var(--accent-ink); }
/* the map menu button and the circling icon are for phones; desktops show the full groups and words */
.map-pick { position: relative; display: flex; }
.map-btn-group, #btn-orbit .ico { display: none; }

.legend {
  position: absolute; left: 10px; bottom: 26px; z-index: 2; background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); max-width: 260px;
}
.legend:empty { display: none; }
.legend:not(.legend-tab) { max-height: calc(100% - 60px); overflow-y: auto; }
.legend .li { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
/* each swatch sits in a 22px slot and is drawn like its mark on the map, in --c */
.legend .slot { flex: 0 0 28px; height: 20px; display: flex; align-items: center; justify-content: center; }
.legend .sw { display: block; flex: none; }
.legend .sw.line { width: 26px; height: 3px; border-radius: 2px; background: var(--c); }
.legend .sw.glow { width: 26px; height: 14px; background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--c) 35%, transparent) 25%, var(--c) 43%, var(--c) 57%, color-mix(in srgb, var(--c) 35%, transparent) 75%, transparent); }
.legend .sw.fill { width: 26px; height: 14px; border-radius: 5px; background: color-mix(in srgb, var(--c) 30%, transparent); }
.legend .sw.area { width: 13px; height: 9px; border-radius: 50%; border: 2px solid var(--c); background: color-mix(in srgb, var(--c) 28%, transparent); outline: 1.2px dashed var(--c); outline-offset: 1.5px; }
.legend .sw.drop { width: 2px; height: 16px; background: repeating-linear-gradient(180deg, color-mix(in srgb, var(--c) 60%, transparent) 0 3px, transparent 3px 5px); }
.legend .sw.hist { width: 20px; height: 2px; background: repeating-linear-gradient(90deg, color-mix(in srgb, var(--c) 70%, transparent) 0 3px, transparent 3px 5px); }
.legend .sw.pts { width: 20px; height: 11px; background: radial-gradient(circle, var(--c) 1.2px, transparent 1.7px) 0 0 / 6px 5.5px; }
.legend .sw.icon { width: 16px; height: 16px; }
.legend .sw.icon.tall { width: auto; height: 20px; }
.legend .sw.icon.trk { width: 13px; height: 13px; margin: 0; }
/* a balloon that has lost contact pulses on the map; its legend icon does too */
@keyframes bt-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .2; } }
.legend .sw.pulse { animation: bt-pulse 1.8s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .legend .sw.pulse { animation: none; opacity: .35; } }
.legend.legend-tab { display: none; }

/* ---------------------------------------------------------------- popup */
.popup {
  position: absolute; z-index: 6; width: 300px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; font-size: 13px;
}
.popup h3 { margin: 0 0 4px; font-size: 15px; padding-right: 26px; }
.popup .close { position: absolute; right: 8px; top: 6px; background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); }
.popup .flags { margin: 6px 0; display: flex; gap: 6px; flex-wrap: wrap; }
.flag { background: #5b1f2a; color: #ffd9df; border-radius: 6px; padding: 2px 6px; font-size: 11px; }
.flag.info { background: #20405a; color: #d6efff; }
.popup .row { margin-top: 8px; }
/* a map marker's card (markers.js) */
.mk-ico { height: 18px; width: auto; vertical-align: -3px; margin-right: 6px; }
.mk-edit { display: flex; gap: 8px; align-items: center; margin: 0 28px 6px 0; }
.mk-edit .mk-ico { margin-right: 0; }
.mk-edit input { flex: 1; min-width: 0; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.mk-edit input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.mk-share { margin-top: 6px; }
.linkbtn.danger { color: var(--bad); border-color: var(--bad); }
.bp-edit { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 2px; }
.bp-edit .linkbtn { padding: 4px 8px; }
.bp-edit input { width: 4.6em; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); font-family: var(--mono); }
.bp-edit input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.bp-unit { color: var(--muted); font-family: var(--font); }
.bp-msg { font-family: var(--font); font-size: 12px; color: var(--muted); margin-top: 2px; }
.bp-msg.bad { color: var(--bad); }
.mk-note { margin: 2px 0 4px; }
.mk-hits { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.mk-hit { text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; cursor: pointer; color: var(--text); font-size: 13px; line-height: 1.35; }
.mk-hit:hover, .mk-hit:focus-visible { border-color: var(--accent); }
.popup .why { margin: 6px 0; }

.toast { position: absolute; left: 50%; transform: translateX(-50%); bottom: 30px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 8px 14px; z-index: 7; box-shadow: var(--shadow); }
/* hover explanations (tips.js): mouse and keyboard only, never on touch screens */
.bt-tip {
  position: fixed; z-index: 30; max-width: 290px; padding: 7px 10px; pointer-events: none;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); font-size: 12.5px; line-height: 1.4; font-weight: 400; text-transform: none; letter-spacing: normal;
}
.bt-tip[hidden] { display: none; }
@media (hover: none) { .bt-tip { display: none !important; } }

/* ---------------------------------------------------------------- modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: min(860px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { overflow-y: auto; padding: 12px 16px 18px; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.info-grid .card { margin: 0; }
.person { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }
.person a { color: var(--accent); text-decoration: none; font-family: var(--mono); white-space: nowrap; }
.pin-row { display: flex; gap: 8px; align-items: center; margin: 8px 0 14px; flex-wrap: wrap; }
.pin-row input { width: 120px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
/* the PIN box: an editable element styled like the text boxes */
.secret-box { width: 140px; min-height: 1.2em; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); white-space: nowrap; overflow: hidden; cursor: text;
  letter-spacing: 2px; outline: none; -webkit-user-select: text; user-select: text; }
.secret-box:focus { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.secret-box:empty::before { content: attr(data-placeholder); color: var(--muted); letter-spacing: 0; }
.zoom-link { color: var(--accent); word-break: break-all; }

/* ------------------------------------------------------------ phones */
@media (max-width: 899px) {
  body { font-size: 15px; }
  #topbar { gap: 10px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); }
  .subtitle, .titles { display: none; }
  .brand { flex: 0 0 auto; }
  .clock-box { flex: 1; text-align: left; }
  .clock { font-size: 18px; }
  .clock-sub { font-size: 10px; }
  #btn-info { padding: 6px 10px; }
  #simbar { gap: 8px; padding: 5px 10px; flex-wrap: wrap; }
  .sim-speed { font-size: 0; gap: 0; }
  .sim-speed select { font-size: 14px; }
  .sim-tag { display: none; }
  #sim-slider { order: 5; flex-basis: 100%; }
  .sim-slider-time { display: none; }

  #main { display: block; }
  #mapwrap { position: absolute; left: 0; right: 0; top: 0; bottom: calc(var(--sheet-h, 190px) - 14px); }
  #sidebar {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: var(--sheet-h, 190px);
    border-right: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .35); transition: height .22s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #sidebar.dragging { transition: none; }
  .sheet-handle { display: flex; justify-content: center; padding: 10px 0 8px; order: -1; cursor: grab; touch-action: none; }
  .panel-tabs { touch-action: none; }
  #sidebar.dragging, #sidebar.dragging * { cursor: grabbing; }
  .tab-body { overscroll-behavior-y: contain; }
  .sheet-handle span { width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
  .tab { padding: 9px 6px; }
  /* one row of small controls along the top, right-aligned, wrapping only if it must */
  #map-tools { top: 8px; right: 8px; left: 8px; gap: 6px; flex-direction: row; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; }
  .tool { padding: 7px 8px; font-size: 12px; }
  .map-btn-group { display: flex; }
  #map-group { display: none; position: absolute; top: calc(100% + 6px); right: 0; flex-direction: column; z-index: 3; }
  #map-group.open { display: flex; }
  #map-group .tool { border-right: 0; border-bottom: 1px solid var(--line); text-align: left; padding: 9px 14px; }
  #map-group .tool:last-child { border-bottom: 0; }
  #btn-exag .lbl, #btn-orbit .lbl { display: none; }
  #btn-orbit .ico { display: inline; }
  .legend { display: none; }
  .legend.legend-tab:not(:empty) { display: block; position: static; background: none; border: 0; box-shadow: none; padding: 0; max-width: none; margin: 0 0 14px; font-size: 13px; }
  .legend-tab h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
  .popup { left: 8px !important; right: 8px; width: auto; top: auto !important; bottom: 22px; max-height: 60%; overflow-y: auto; }
  .balloon-card { padding: 9px 11px; }
  .cesium-viewer-bottom { bottom: 16px !important; }
}

/* status flag beside the clock: shown only when something is wrong */
.status-flag { display: inline-flex; align-items: center; gap: 3px; flex: none; margin-left: 8px;
  background: var(--bad); color: #fff; border: 0; border-radius: 12px; padding: 3px 8px;
  font-weight: 700; font-size: 13px; line-height: 1; cursor: pointer; }
.status-flag[hidden] { display: none; }
.status-flag:hover, .status-flag:focus-visible { filter: brightness(1.1); outline: 2px solid var(--bad); outline-offset: 2px; }
.status-flag .sf-icon { font-size: 14px; }
.problems { margin: 0; padding: 0; list-style: none; }
.problems li { margin: 8px 0; line-height: 1.4; display: flex; gap: 9px; align-items: flex-start; }
/* the mark at the start of a problem: a team's color bar, a tracker's shape, or a neutral "i" */
.problems .pm { flex: none; margin-top: 2px; }
.problems .pm-bar { width: 5px; height: 17px; border-radius: 3px; }
.problems .pm-ico { width: 15px; height: 15px; }
.problems .pm-none { width: 15px; height: 15px; border: 1.5px solid var(--muted); border-radius: 50%; color: var(--muted); font: 700 10px/12px var(--font); text-align: center; box-sizing: border-box; }
/* a tracker's shape beside its name (Trackers table, report popup) */
.trk { width: 13px; height: 13px; margin-right: 5px; vertical-align: -2px; }

/* ------------------------------------------------- after landing (search) */
.legend .sw.faint { opacity: .55; }
.legend .sw.arrow { width: 26px; height: 9px; background: var(--c); clip-path: polygon(0 35%, 70% 35%, 70% 0, 100% 50%, 70% 100%, 70% 65%, 0 65%); }
/* a payload carried off since it landed: the card line, and the Details card */
:root { --moved: #ffb020; }
@media (prefers-color-scheme: light) { :root { --moved: #a35200; } }
.bc-sub.moved { color: var(--moved); font-weight: 600; }
.ground-card .g-moved { color: var(--moved); font-weight: 700; font-size: 15px; margin: 2px 0 6px; }
.ground-card .warn { color: var(--moved); }
.ground-card .g-other { border-left: 3px solid var(--moved); padding: 4px 0 2px 10px; margin: 8px 0; font-size: 13px; }
.ground-card .g-count { font-size: 12px; margin-top: 6px; }
