:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #111827;
  --muted: #5b6474;
  --line: #e3e7ee;
  --chip: #eef1f6;
  --accent: #0b6bff;
  --accent-text: #ffffff;
  --live: #12b76a;
  --warn: #f5a623;
  --bad: #e5484d;
  --shadow: 0 -6px 30px rgba(15, 23, 42, 0.14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --card: #161b22;
    --text: #e6edf3;
    --muted: #9aa4b2;
    --line: #2a313c;
    --chip: #222a35;
    --accent: #3d8bff;
    --shadow: 0 -6px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --card: #161b22; --text: #e6edf3; --muted: #9aa4b2; --line: #2a313c;
  --chip: #222a35; --accent: #3d8bff; --shadow: 0 -6px 30px rgba(0, 0, 0, 0.5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
[hidden] { display: none !important; }
h1 { font-size: 1.35rem; margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.fine { font-size: 0.8rem; margin: 12px 0 0; }

.map { position: fixed; inset: 0; z-index: 0; background: var(--bg); }

/* Bottom sheet over the map */
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 480px);
  max-height: 78vh;
  overflow-y: auto;
  z-index: 500;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 720px) {
  .sheet { left: 24px; top: 24px; bottom: auto; transform: none; border-radius: 20px; max-height: calc(100vh - 48px); }
}

.brand { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.brand p { margin: 4px 0 0; font-size: 0.92rem; }

.notice {
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0 0 14px;
  font-size: 0.92rem;
}

.field { display: block; border: 0; padding: 0; margin: 0 0 14px; }
.field > span, .field > legend { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; padding: 0; }
input[type="text"] {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
}
input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  font: inherit;
  font-size: 0.9rem;
  color: inherit;
  background: var(--chip);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
}
.chips button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--chip);
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.btn.big { width: 100%; padding: 14px; font-size: 1.05rem; margin-top: 4px; }

.status-row { display: flex; align-items: center; gap: 8px; }
.status-row .spacer { flex: 1; }
#status-sub { margin: 4px 0 12px; min-height: 1.2em; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--live); animation: pulse 1.6s infinite; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 60%, transparent); }
  100% { box-shadow: 0 0 0 9px transparent; }
}
.pill { background: var(--chip); border-radius: 999px; padding: 3px 10px; font-size: 0.85rem; font-weight: 600; }

.link-box { display: flex; gap: 8px; margin-bottom: 14px; }
.link-box input { flex: 1; min-width: 0; font-size: 0.9rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}
.stats > div { background: var(--bg); border-radius: 12px; padding: 8px 10px; }
.stats .label { display: block; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stats .value { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }

.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }

.person { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.who { min-width: 0; }
.who h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 1.2rem;
}
#ended h1 { margin-bottom: 6px; }
#ended .actions { margin-top: 14px; }

/* Map marker */
.person-marker { position: relative; }
.pm-dot {
  position: absolute; inset: 6px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #0b6bff; color: #fff;
  font: 700 15px/1 system-ui, sans-serif;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.pm-pulse {
  position: absolute; inset: 0; border-radius: 50%;
  background: rgba(11, 107, 255, 0.35);
  animation: ring 2s ease-out infinite;
}
.person-marker.stale .pm-dot { background: #8a94a6; }
.person-marker.stale .pm-pulse { display: none; }
@keyframes ring { 0% { transform: scale(0.6); opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }
.acc-circle { fill: #0b6bff; fill-opacity: 0.12; stroke: #0b6bff; stroke-opacity: 0.35; stroke-width: 1; }
.trail { stroke: #0b6bff; stroke-opacity: 0.55; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; fill: none; }

.fab {
  position: fixed; right: 12px; z-index: 600;
  bottom: calc(min(78vh, 330px) + 12px);
  width: 46px; height: 46px; border-radius: 50%;
  border: 0; background: var(--card); color: var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  display: grid; place-items: center; cursor: pointer;
}
@media (min-width: 720px) { .fab { bottom: 24px; right: 24px; } }

.leaflet-control-attribution { font-size: 10px; }
@media (max-width: 719px) {
  .leaflet-top.leaflet-right { top: env(safe-area-inset-top); }
}
@media (prefers-reduced-motion: reduce) {
  .pm-pulse, .dot.live { animation: none; }
}

/* Pocket mode */
.pocket-btn { margin: 0 0 8px; background: #000; color: #fff; }
.pocket {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #000;
  color: #6b6b6b;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
.pocket-info { display: flex; align-items: center; justify-content: center; gap: 10px; max-width: calc(100vw - 80px); font-size: 0.95rem; transition: transform 2s ease; }
.pocket .dot { width: 8px; height: 8px; animation: none; }
.pocket .dot.live { background: #0d6b40; }
.pocket .dot.warn { background: #8a5d12; }
.pocket .dot.bad { background: #8c2a2d; }
.pocket-tip { max-width: 320px; font-size: 0.8rem; color: #555; margin-top: 18px; }
.slider {
  position: absolute;
  left: 50%;
  bottom: calc(48px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(80vw, 300px);
  height: 56px;
  border-radius: 28px;
  background: #0d0d0d;
  border: 1px solid #222;
}
.slider-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  color: #4a4a4a;
  pointer-events: none;
}
.slider-knob {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #262626;
  color: #8a8a8a;
  display: grid;
  place-items: center;
  font-size: 26px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
}
.slider-knob:focus-visible { outline: 2px solid #555; outline-offset: 2px; }
