:root {
  --bg: #eef0ee;
  --sheet: #ffffff;
  --text: #16181b;
  --muted: #5c6168;
  --line: #e2e4e1;
  --chip: #f2f3f1;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --go: #15803d;
  --go-soft: #dcfce7;
  --warn: #9a3412;
  --warn-soft: #ffedd5;
  --theirs: #f97316;
  --shadow: 0 -8px 30px rgba(0, 0, 0, 0.16);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101113;
    --sheet: #1a1b1e;
    --text: #ececea;
    --muted: #a1a5ab;
    --line: #2d2f34;
    --chip: #24262a;
    --accent: #4c8dff;
    --go: #4ade80;
    --go-soft: #133d24;
    --warn: #fdba74;
    --warn-soft: #432414;
    --shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }

#map { position: fixed; inset: 0; }

/* Top bar */
#topbar {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 5;
}
.brand, #status {
  pointer-events: auto;
  background: var(--sheet);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  font-weight: 700;
}
.brand { letter-spacing: -0.01em; }
#status { font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
#status.offline { color: var(--warn); }
#status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--go); }
#status.offline::before { background: var(--warn); }

#locate {
  position: fixed;
  right: 12px;
  top: calc(58px + env(safe-area-inset-top));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--sheet);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  font-size: 22px;
  cursor: pointer;
  z-index: 5;
}

#hint {
  position: fixed;
  top: calc(58px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--sheet);
  border-radius: 999px;
  padding: 8px 8px 8px 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 6;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
#hint button { background: var(--sheet); color: var(--text); border: 0; border-radius: 999px; padding: 4px 12px; cursor: pointer; }

#toast {
  position: fixed;
  top: calc(58px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--text);
  color: var(--sheet);
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* Bottom sheet; a side panel on wide screens */
#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: 560px;
  max-height: 62dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--sheet);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  z-index: 10;
}
#sheet.tucked { display: none; }

@media (min-width: 900px) {
  #sheet {
    top: 16px;
    left: 16px;
    bottom: 16px;
    right: auto;
    width: 400px;
    max-height: none;
    border-radius: 20px;
    margin: 0;
    padding-bottom: 16px;
  }
  #topbar { left: 432px; }
}

h1, h2 { margin: 0 0 6px; letter-spacing: -0.02em; line-height: 1.15; }
h1 { font-size: 26px; }
h2 { font-size: 21px; }
p { margin: 0 0 12px; }
.lede { color: var(--muted); }
.fine { color: var(--muted); font-size: 13px; margin-top: 12px; }
.sub { color: var(--muted); font-size: 14px; margin: 0; }
.muted { color: var(--muted); }
strong { font-weight: 650; }

.how { margin: 4px 0 16px; padding: 0; list-style: none; display: grid; gap: 8px; }
.how li { display: grid; grid-template-columns: 28px 1fr; gap: 8px; color: var(--muted); }

/* Buttons */
button { cursor: pointer; }
.big {
  min-height: 54px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--chip);
  font-size: 17px;
  font-weight: 650;
  padding: 10px 16px;
}
.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.wide { width: 100%; }
.ghost {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 12px;
  padding: 0 12px;
  white-space: nowrap;
}
.link { border: 0; background: none; color: var(--accent); padding: 4px 0; font-weight: 600; }
.choices { display: grid; gap: 10px; margin: 8px 0; }
.choices.two { grid-template-columns: 1fr 1fr; }
.actions {
  position: sticky;
  bottom: calc(-16px - env(safe-area-inset-bottom));
  margin: 14px -16px calc(-16px - env(safe-area-inset-bottom));
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--sheet);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}
.actions.single { grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .actions { bottom: -16px; margin-bottom: -16px; padding-bottom: 16px; }
}

/* Setup form */
.sheet-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.field-label { display: block; font-weight: 650; margin: 16px 0 6px; }
input[type="search"], input[type="text"] {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  background: var(--chip);
  font-size: 16px;
}
.search { display: flex; gap: 8px; }
.results { list-style: none; margin: 6px 0 0; padding: 0; }
.results button {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  padding: 10px 4px;
}
.chosen {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--go-soft);
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--chip);
  font-size: 14px;
}
.status.bad { background: var(--warn-soft); color: var(--warn); }

/* Live */
.live-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.pulse { width: 14px; height: 14px; margin-top: 7px; border-radius: 50%; background: var(--go); flex: none; animation: pulse 1.8s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(21, 128, 61, 0.5); }
  100% { box-shadow: 0 0 0 14px rgba(21, 128, 61, 0); }
}
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
.count { font-weight: 650; margin: 4px 0 8px; }
.empty { color: var(--muted); padding: 14px; border: 1px dashed var(--line); border-radius: 12px; }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 8px 12px; font-size: 14px; margin-bottom: 12px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 0 6px; }

.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.person {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: start;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: none;
  padding: 12px;
}
.person.selected { border-color: var(--theirs); box-shadow: inset 0 0 0 1px var(--theirs); }
.person .icon { font-size: 24px; line-height: 1.2; }
.person .who { display: grid; gap: 2px; min-width: 0; }
.person .who span { font-size: 14px; color: var(--muted); }
.person .who strong { overflow-wrap: anywhere; }
.person .when { font-weight: 700; white-space: nowrap; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 6px; padding: 1px 6px; background: var(--go-soft); color: var(--go); }
.passenger { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; }
.passenger .buttons { display: flex; gap: 6px; }
.passenger button { border-radius: 10px; border: 1px solid var(--line); background: var(--chip); padding: 8px 10px; font-weight: 600; }

/* Modal */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
}
#modal[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 80dvh;
  overflow-y: auto;
  background: var(--sheet);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 900px) {
  #modal { align-items: center; }
  .modal-card { border-radius: 20px; }
}

/* Map markers. MapLibre positions the outer element with a transform, so styles go on the inner one. */
.marker { cursor: pointer; }
.pin {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: #fff;
  border: 3px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s;
}
.pin.match { border-color: #16a34a; }
.pin.dim { opacity: 0.5; filter: grayscale(0.7); }
.pin.selected { border-color: var(--theirs); transform: scale(1.25); }
.flag { font-size: 30px; line-height: 1; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4)); }
.me-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #1f6feb;
  border: 3px solid #fff;
  box-shadow: 0 0 0 7px rgba(31, 111, 235, 0.22), 0 1px 4px rgba(0, 0, 0, 0.3);
}
.me-dot.manual { background: #7c3aed; box-shadow: 0 0 0 7px rgba(124, 58, 237, 0.22), 0 1px 4px rgba(0, 0, 0, 0.3); }

.noscript { position: fixed; inset: auto 16px 16px; background: var(--sheet); padding: 16px; border-radius: 12px; }
