:root {
  color-scheme: dark;
  --sky: #060a14;
  --sky-glow: #0d1630;
  --panel: #0e1528;
  --panel-2: #131c34;
  --line: #233054;
  --line-strong: #34436f;
  --text: #e9edf8;
  --text-2: #a3aeca;
  --text-3: #7480a0;
  --plate-platform: #0f1a33;
  --plate-native: #141633;
  --plate-edge: #26345c;
  --wall-l: #1c2643;
  --wall-r: #141c34;
  --roof: #27324f;
  --edge: #3a4876;
  --win-off: #0a0f1e;
  --st-waiting: #ff8a3d;
  --st-unsaved: #ff4d5e;
  --st-nopr: #b18cff;
  --st-pr: #ffc845;
  --st-done: #4cd38a;
  --st-idle: #6fa8ff;
  --focus: #8fb4ff;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--sky);
  color: var(--text);
  font: 14px/1.5 var(--font);
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
}
button:hover { border-color: var(--line-strong); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: var(--focus); }
svg.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { display: flex; flex-direction: column; height: 100%; }

.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: baseline; gap: 10px; margin-right: auto; }
.brand h1 { font-size: 18px; font-weight: 600; margin: 0; letter-spacing: 0.02em; }
.brand span { color: var(--text-3); font-size: 13px; }
.fresh { font-size: 13px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.fresh::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--st-done); }
.fresh.warn { color: var(--st-pr); }
.fresh.warn::before { background: var(--st-pr); }
.fresh.bad { color: var(--st-unsaved); }
.fresh.bad::before { background: var(--st-unsaved); }

.bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; font-size: 13px; padding: 4px 10px; min-height: 30px; }
.chip .dot { width: 10px; height: 10px; border-radius: 3px; }
.chip b { font-weight: 600; }
.chip[aria-pressed="false"] { color: var(--text-3); border-style: dashed; background: transparent; }
.chip[aria-pressed="false"] .dot { opacity: 0.35; }
.search { width: 240px; max-width: 40vw; background: var(--sky); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; min-height: 34px; }

.banner { padding: 8px 16px; font-size: 13px; background: #2a1d0b; color: #ffd68a; border-bottom: 1px solid #4b3410; }
.banner[hidden] { display: none; }

.main { position: relative; flex: 1; min-height: 0; display: flex; }
.stage {
  position: relative; flex: 1; min-width: 0; overflow: hidden; touch-action: none; cursor: grab;
  background: radial-gradient(ellipse at 50% 35%, var(--sky-glow), var(--sky) 70%);
}
.stage.dragging { cursor: grabbing; }
/* Child selector on purpose: a plain ".stage svg" also stretched the button
   icons inside .controls over the whole stage and swallowed their clicks. */
.stage > svg#city { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.star { fill: #c9d6ff; }

.plate { stroke: var(--plate-edge); stroke-width: 1; stroke-dasharray: 5 5; }
.plate-platform { fill: var(--plate-platform); }
.plate-native { fill: var(--plate-native); }
.bld { cursor: move; }
.wall-l { fill: var(--wall-l); stroke: var(--edge); stroke-width: 0.6; }
.wall-r { fill: var(--wall-r); stroke: var(--edge); stroke-width: 0.6; }
.roof { fill: var(--roof); stroke: var(--edge); stroke-width: 0.6; }
.bld.sel .wall-l, .bld.sel .wall-r, .bld.sel .roof { stroke: var(--focus); stroke-width: 1.4; }
.antenna { stroke: var(--edge); stroke-width: 1.2; }
.win.off { fill: var(--win-off); }
.win { cursor: pointer; }
.st-waiting { fill: var(--st-waiting); }
.st-unsaved { fill: var(--st-unsaved); }
.st-nopr { fill: var(--st-nopr); }
.st-pr { fill: var(--st-pr); }
.st-done { fill: var(--st-done); }
.st-idle { fill: var(--st-idle); }
.win.draft { fill-opacity: 0.5; }
.win.stale { fill-opacity: 0.55; }
.win.fail { stroke: var(--st-unsaved); stroke-width: 1.2; }
.win.sel { stroke: #ffffff; stroke-width: 2; }
.beacon { fill: var(--st-waiting); }
.blink { animation: blink 1.2s steps(2, start) infinite; }
@keyframes blink { to { opacity: 0.2; } }
@media (prefers-reduced-motion: reduce) { .blink { animation: none; } }

.labels { position: absolute; inset: 0; pointer-events: none; }
.label {
  position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer;
  background: rgba(10, 15, 30, 0.88); border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 3px 8px; text-align: center; white-space: nowrap; font-size: 12px; line-height: 1.35;
  transform-origin: 50% 100%;
}
.label b { display: block; font-weight: 600; color: var(--text); }
.label span { color: var(--text-2); font-size: 11px; }
.label .w { color: var(--st-waiting); }
.label.sel { border-color: var(--focus); }
/* Hidden because it would overlap a more important label (see placeLabels). */
.label.off, .district.off { visibility: hidden; pointer-events: none; }
.district { position: absolute; left: 0; top: 0; font-size: 13px; color: var(--text-3); letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; pointer-events: none; }

.controls { position: absolute; right: 16px; bottom: 16px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.controls button { background: rgba(14, 21, 40, 0.92); }
.legend { position: absolute; left: 16px; bottom: 16px; font-size: 12px; color: var(--text-3); background: rgba(14, 21, 40, 0.8); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; max-width: 46%; }

.tip {
  position: absolute; pointer-events: none; z-index: 5; max-width: 320px;
  background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 6px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.tip[hidden] { display: none; }
.tip small { display: block; color: var(--text-2); font-size: 12px; }

.drawer {
  width: 400px; max-width: 100%; border-left: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 15px; font-weight: 600; margin: 0; flex: 1; min-width: 0; }
.drawer-body { overflow-y: auto; padding: 14px 16px 24px; flex: 1; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.title { font-size: 16px; font-weight: 600; margin: 10px 0 6px; overflow-wrap: anywhere; }
.need { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 12px 0; color: var(--text); overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px 10px; font-size: 13px; margin: 12px 0; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts code { background: var(--sky); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--text-3); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions a { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--line-strong); color: var(--text); min-height: 34px; }
.actions a.primary { background: #1d3a7a; border-color: #2f56a8; }
.group { margin: 16px 0 6px; font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; display: flex; justify-content: space-between; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { width: 100%; justify-content: flex-start; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 8px 2px; gap: 10px; }
.row:hover { background: var(--panel-2); }
.row .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.row .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row small { color: var(--text-3); white-space: nowrap; }
.dot.st-waiting { background: var(--st-waiting); }
.dot.st-unsaved { background: var(--st-unsaved); }
.dot.st-nopr { background: var(--st-nopr); }
.dot.st-pr { background: var(--st-pr); }
.dot.st-done { background: var(--st-done); }
.dot.st-idle { background: var(--st-idle); }

.state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; }
.state[hidden] { display: none; }
.state .card { max-width: 480px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; }
.state h2 { margin: 0 0 8px; font-size: 17px; }
.state p { color: var(--text-2); margin: 0 0 12px; }
.state code { background: var(--sky); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
button[aria-busy="true"] { opacity: 0.8; cursor: progress; }

.toast {
  position: absolute; left: 50%; bottom: 72px; transform: translateX(-50%); z-index: 10;
  background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 8px 14px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.toast[hidden] { display: none; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line-strong); border-radius: 12px; padding: 20px 22px; max-width: 420px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(3, 6, 14, 0.7); }
dialog h2 { margin: 0 0 8px; font-size: 16px; }
dialog p { margin: 0 0 16px; color: var(--text-2); }
dialog .actions { justify-content: flex-end; }
dialog .warn { background: #5a3a0c; border-color: #8a5a14; }

@media (max-width: 720px) {
  .top { padding: 8px 16px; }
  .brand span { display: none; }
  /* Icon-only on phones so the header stays on one line; the buttons keep
     their names through aria-label. */
  .top button span { display: none; }
  .bar { flex-wrap: wrap; }
  .search { width: 100%; max-width: none; order: 2; }
  .chips { order: 1; flex-basis: 100%; }
  .legend { display: none; }
  .main { flex-direction: column; }
  .drawer { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; max-height: 62%; border-left: 0; border-top: 1px solid var(--line-strong); border-radius: 12px 12px 0 0; z-index: 8; }
  .controls { bottom: 12px; right: 12px; }
}
