: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.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-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); }
.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; }
.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; }
.src-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
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); }

.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 .li { display: flex; align-items: center; gap: 7px; margin: 2px 0; }
.legend .sw { width: 18px; height: 10px; border-radius: 2px; flex: none; color: var(--muted); }
.legend .sw.dash { background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 9px); height: 3px; }
.legend .sw.area { border: 1.5px solid currentColor; background: var(--line); }
.legend .sw.fill { background: currentColor; opacity: .5; }
.legend .sw.pt { width: 10px; height: 10px; border-radius: 50%; }

/* ---------------------------------------------------------------- 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; }

.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); }

/* ---------------------------------------------------------------- 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); }
.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; }
  #map-tools { top: 8px; right: 8px; gap: 6px; }
  .tool { padding: 8px 9px; font-size: 12px; }
  #view-group, #map-group { flex-direction: column; }
  #view-group .tool, #map-group .tool { border-right: 0; border-bottom: 1px solid var(--line); }
  #view-group .tool:last-child, #map-group .tool:last-child { border-bottom: 0; }
  .legend { display: none; }
  .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; }
}
