:root {
  --bg: #0b0f14;
  --panel: #111821;
  --panel-2: #18212c;
  --line: #263241;
  --text: #d7e0ea;
  --muted: #8a99aa;
  --accent: #f2b134;
  --live: #57d38c;
  --hostile: #ff5a5a;
  --friend: #59c6ff;
  --bar-h: 44px;
  --tl-h: 52px;
  --panel-w: 320px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
a { color: var(--friend); }
small { color: var(--muted); font-weight: normal; }
button { font: inherit; color: inherit; }

/* ── top bar ─────────────────────────────────────────── */
#bar {
  position: fixed; inset: 0 0 auto 0; height: var(--bar-h); z-index: 1000;
  display: flex; align-items: center; gap: 14px; padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand b { letter-spacing: .18em; font-size: 16px; color: var(--accent); }
.brand span { color: var(--muted); font-size: 12px; }
#alerts {
  flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: 13px;
}
#alerts .a { cursor: pointer; }
#alerts .a + .a::before { content: " · "; color: var(--muted); }
#alerts .l3 { color: var(--hostile); font-weight: 600; }
#alerts .l2 { color: var(--accent); }
#alerts .l1 { color: var(--text); }
#alerts .quiet, #alerts .sep { color: var(--muted); }
#dtg { font: 600 13px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .05em; white-space: nowrap; }
#dtg.replay { color: var(--accent); }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.on { border-color: var(--accent); color: var(--accent); }
.btn.ghost { background: transparent; }
.btn:focus-visible, .seg button:focus-visible, #tl:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── map ─────────────────────────────────────────────── */
#map {
  position: fixed; top: var(--bar-h); bottom: var(--tl-h); left: 0; right: var(--panel-w);
  background: #0e1319;
}
.leaflet-container { font: inherit; background: #0e1319; }
.leaflet-control-attribution { background: rgba(11,15,20,.7) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--panel-2); color: var(--text); }
.ms { pointer-events: auto; }
.ms img { display: block; }
.grid-label { color: rgba(242,177,52,.75); font: 600 11px ui-monospace, monospace; text-shadow: 0 0 3px #000; white-space: nowrap; }
.ring-label { color: rgba(215,224,234,.6); font: 11px ui-monospace, monospace; text-shadow: 0 0 3px #000; white-space: nowrap; }
.wx-label { color: rgba(170,190,255,.75); font: 10px ui-monospace, monospace; text-shadow: 0 0 3px #000; }
.wx-centre { font: 700 16px system-ui; text-shadow: 0 0 4px #000; text-align: center; line-height: 1; }
.wx-centre small { display: block; font: 10px ui-monospace, monospace; color: inherit; }
.ev-mark { width: 14px; height: 14px; transform: rotate(45deg); border: 2px solid #000; }
.ev-mark.recent { box-shadow: 0 0 0 4px rgba(242,177,52,.35); }
.measure-label { background: rgba(11,15,20,.85); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; font: 12px ui-monospace, monospace; white-space: nowrap; }
.map-picking { cursor: crosshair !important; }

#readout {
  position: fixed; left: 8px; bottom: calc(var(--tl-h) + 8px); z-index: 900;
  background: rgba(11,15,20,.85); border: 1px solid var(--line); border-radius: 4px;
  padding: 3px 8px; font: 12px ui-monospace, monospace; pointer-events: none;
}
#readout:empty { display: none; }

/* ── side panel ──────────────────────────────────────── */
#panel {
  position: fixed; top: var(--bar-h); bottom: var(--tl-h); right: 0; width: var(--panel-w); z-index: 950;
  background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 4px 12px 16px;
}
#panel details { border-bottom: 1px solid var(--line); padding: 8px 0; }
#panel summary { cursor: pointer; font-weight: 600; padding: 2px 0; list-style-position: inside; }
.layers { display: grid; gap: 4px; margin: 8px 0; }
.layers label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin: 8px 0; }
.seg button { flex: 1; background: transparent; border: 0; padding: 5px 4px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--panel-2); color: var(--accent); }
.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 8px 0; }
.palette button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
  padding: 4px 2px; display: grid; justify-items: center; gap: 2px; font-size: 10px; color: var(--muted);
}
.palette button img { height: 30px; }
.palette button.on { border-color: var(--accent); color: var(--accent); }
.field { display: grid; gap: 3px; font-size: 12px; color: var(--muted); margin: 6px 0; }
.field input, .field textarea, dialog input {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font: inherit; width: 100%;
}
.row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.file input { display: none; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }
.list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 2px; }
.list li { display: flex; gap: 8px; align-items: flex-start; padding: 5px 4px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.list li:hover { background: var(--panel-2); }
.list li time { color: var(--muted); font: 11px ui-monospace, monospace; white-space: nowrap; padding-top: 2px; }
.list li .dot { flex: none; width: 8px; height: 8px; margin-top: 5px; transform: rotate(45deg); }
.list li img { height: 18px; flex: none; }
.los-opts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.sources { color: var(--muted); font-size: 11px; margin-top: 12px; }
.sources a { color: var(--muted); }

body:not(.unlocked) .unlocked-only { display: none; }
body.unlocked .locked-only { display: none; }

#sel { border-bottom: 1px solid var(--line); padding: 10px 0; }
#sel h3 { margin: 0 0 4px; font-size: 15px; display: flex; gap: 8px; align-items: center; }
#sel h3 img { height: 26px; }
#sel dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; font-size: 13px; }
#sel dt { color: var(--muted); }
#sel dd { margin: 0; font-family: ui-monospace, monospace; font-size: 12px; }
#sel .row { margin-top: 8px; }
#sel .x { float: right; }
.x { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; line-height: 1; }

/* ── line of sight card ──────────────────────────────── */
#los {
  position: fixed; left: 12px; right: calc(var(--panel-w) + 12px); bottom: calc(var(--tl-h) + 40px);
  z-index: 960; max-width: 720px; margin: 0 auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.los-head { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.los-head span { flex: 1; }
#losCanvas { width: 100%; height: 160px; display: block; margin-top: 6px; }

/* ── timeline ────────────────────────────────────────── */
#timeline {
  position: fixed; inset: auto 0 0 0; height: var(--tl-h); z-index: 1000;
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--panel); border-top: 1px solid var(--line);
}
.live { font-weight: 700; letter-spacing: .08em; }
.live.on { color: var(--live); border-color: var(--live); }
#tl { position: relative; flex: 1; height: 36px; cursor: ew-resize; touch-action: none; }
#tlCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#tlCursor { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); right: 0; pointer-events: none; }
#tlCursor.live { background: var(--live); }
#tlTime { font: 12px ui-monospace, monospace; color: var(--muted); min-width: 92px; text-align: right; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  max-width: 340px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 6px; font-size: 16px; }
dialog p { color: var(--muted); font-size: 13px; }
.err { color: var(--hostile) !important; min-height: 1em; }

.fab { display: none; }

/* ── phones ──────────────────────────────────────────── */
@media (max-width: 760px) {
  :root { --panel-w: 0px; --tl-h: 48px; --bar-h: 72px; }
  .brand span { display: none; }
  #bar { gap: 6px 10px; padding: 6px 10px; flex-wrap: wrap; align-content: center; }
  #dtg { margin-left: auto; }
  #alerts { order: 10; flex-basis: 100%; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 12px; line-height: 1.3; }
  #dtg { font-size: 11px; }
  #map { right: 0; }
  #panel {
    top: auto; left: 0; right: 0; width: auto; max-height: 58vh; bottom: var(--tl-h);
    border-left: 0; border-top: 1px solid var(--line); border-radius: 12px 12px 0 0;
    transform: translateY(110%); transition: transform .2s ease;
    padding: 4px 16px 16px;
  }
  body.sheet #panel { transform: none; }
  .fab {
    display: block; position: fixed; right: 12px; bottom: calc(var(--tl-h) + 12px); z-index: 940;
    background: var(--panel); box-shadow: 0 2px 8px rgba(0,0,0,.5);
  }
  body.sheet .fab { display: none; }
  #readout { bottom: calc(var(--tl-h) + 56px); }
  #los { right: 12px; }
  #tlTime { min-width: 0; font-size: 11px; }
}
