:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --text: #15181e;
  --muted: #5c6370;
  --primary: #2b5bb8;
  --primary-text: #ffffff;
  --border: #d5d9e2;
  --good: #2e7d32;
  --warn: #b26a00;
  --warn-bg: #f9a825;
  --bad: #c62828;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --surface: #1a1e26;
    --surface-2: #232833;
    --text: #e8eaf0;
    --muted: #9aa2b1;
    --primary: #8ab4ff;
    --primary-text: #0b1530;
    --border: #2e3442;
    --good: #66bb6a;
    --warn: #ffb74d;
    --bad: #ef5350;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1218;
  --surface: #1a1e26;
  --surface-2: #232833;
  --text: #e8eaf0;
  --muted: #9aa2b1;
  --primary: #8ab4ff;
  --primary-text: #0b1530;
  --border: #2e3442;
  --good: #66bb6a;
  --warn: #ffb74d;
  --bad: #ef5350;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

button, .button {
  font: inherit;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  background: none;
  color: var(--primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--primary); color: var(--primary-text); font-weight: 600; }
button.icon { font-size: 22px; padding: 4px 10px; color: var(--text); }
.button.outline { border: 1px solid var(--border); }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.title { flex: 1; min-width: 0; }
.title h1 { margin: 0; font-size: 20px; }
.title p { margin: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; align-items: center; gap: 2px; }

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  color: #fff;
  font-weight: 700;
}
.banner.warn { background: var(--warn-bg); color: #1b1300; }
.banner.bad { background: var(--bad); color: #fff; }
.banner span { flex: 1; }
.banner button { background: rgba(0, 0, 0, 0.25); color: inherit; }

.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.map-col { display: flex; flex-direction: column; }
#map { height: 45dvh; min-height: 240px; background: var(--surface-2); }

.position {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--surface-2);
}
.position > div { flex: 1; min-width: 0; }
.position[hidden] { display: none; }
.pos-label { font-size: 12px; font-weight: 600; color: var(--primary); }
.pos-coords { font-weight: 600; font-variant-numeric: tabular-nums; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
  padding: 8px 16px max(16px, env(safe-area-inset-bottom));
  align-content: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}
.card.stale > * { opacity: 0.45; }
.card.wide { grid-column: 1 / -1; }
.card h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary);
}
.card .headline {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}
.field .label { color: var(--muted); }
.field .value { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card-link { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.card-link a { color: var(--primary); }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

/* Map markers */
.marker-quad svg { display: block; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5)); }
.marker-home {
  width: 24px; height: 24px; border-radius: 50%;
  background: #2e7d32; color: #fff; border: 2px solid #fff;
  font: 700 13px/20px system-ui, sans-serif; text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.follow-btn {
  background: var(--surface); color: var(--primary); border: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); font-weight: 600;
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  max-width: min(440px, calc(100vw - 32px));
  padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { margin-top: 0; font-size: 20px; }
dialog label { display: block; font-size: 13px; color: var(--muted); }
dialog input {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Side by side on wide screens */
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  .layout { flex-direction: row; }
  .map-col { flex: 1; }
  #map { flex: 1; height: auto; }
  .cards { flex: 1; overflow-y: auto; }
}
