:root {
  --ink: #172033;
  --muted: #5c6573;
  --paper: #f3ecdf;
  --card: #fffdf8;
  --line: #e3d7c4;
  --green: #0f6e56;
  --green-deep: #0b5342;
  --danger: #9f2d2d;
  --gold: #a16207;
  --shadow: 0 14px 36px rgba(23, 32, 51, 0.12);
  --sheet: 46dvh;
  color-scheme: light;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
}

body[data-role="user"] { background: #fff; }

#setup[hidden], #user[hidden], #host[hidden] { display: none !important; }

#user {
  min-height: 100%;
  display: grid;
  place-items: center;
  background: #fff;
}

#share-location {
  width: min(240px, 70vw);
  height: min(240px, 70vw);
  border: 0;
  border-radius: 50%;
  background: #111;
  color: #fff;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

#share-location:disabled { opacity: 1; cursor: wait; }

#host {
  position: fixed;
  inset: 0;
  background: #e8eef2;
}

#host #map {
  position: absolute;
  inset: 0;
  height: auto;
}

#host #map iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.user-link {
  position: absolute;
  z-index: 2;
  left: 12px;
  right: 12px;
  top: calc(12px + env(safe-area-inset-top));
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: #1a73e8;
  font-size: 14px;
  font-weight: 650;
  text-decoration: underline;
  word-break: break-all;
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.16);
}

button, input { font: inherit; color: inherit; }

button {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 12px 14px;
  cursor: pointer;
}

button:focus-visible, input:focus-visible {
  outline: 3px solid #0f6e56;
  outline-offset: 2px;
}

button.primary, #start-form button[type="submit"] {
  background: var(--green);
  color: #f4fffb;
  border-color: var(--green-deep);
  font-weight: 700;
}

button.danger {
  background: #fff5f5;
  color: var(--danger);
  border-color: #f0c9c9;
  font-weight: 700;
}

button:disabled { opacity: 0.65; cursor: wait; }

.screen { min-height: 100%; }

#setup { overflow: auto; }

.setup-inner {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
}

.brand h1, .card h2, .topbar h1 { margin: 0; }

.eyebrow {
  margin: 12px 0 4px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
}

.brand h1 { font-size: 34px; line-height: 1.05; letter-spacing: -0.03em; }

.lede, .fine, .card li, #status-line, .code-hint, .code-label, .urls {
  color: var(--muted);
}

.lede { font-size: 17px; line-height: 1.45; }

.mark {
  display: block;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 50% 42%, transparent 0 5px, #e2b340 6px 14px, transparent 15px),
    linear-gradient(#e2b340, #e2b340) 50% 78% / 4px 16px no-repeat,
    #172033;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 14px;
}

.card h2 { font-size: 18px; }

.card ol { margin: 8px 0 0; padding-left: 18px; }
.card li { margin: 6px 0; line-height: 1.4; }

label { display: block; font-weight: 650; margin: 12px 0; }

input {
  display: block;
  width: 100%;
  margin-top: 6px;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid #d5cbb8;
  background: #fff;
  padding: 10px 12px;
  font-size: 16px;
}

#code { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 750; }

.fine { font-size: 14px; line-height: 1.4; margin: 8px 0; }

.urls {
  margin: 12px 0 0;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-all;
  white-space: pre-line;
}

.error { min-height: 1.2em; color: var(--danger); font-weight: 650; }

#install { width: 100%; margin-top: 12px; background: var(--ink); color: white; border-color: var(--ink); font-weight: 700; }

#track { position: fixed; inset: 0; }

#map { position: absolute; inset: 0; background: #d9d3c7; }

.topbar {
  position: absolute;
  z-index: 500;
  top: calc(10px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.topbar h1 {
  font-size: 16px;
  max-width: 70vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#status-line { margin: 2px 0 0; font-size: 13px; }

#sheet {
  position: absolute;
  z-index: 600;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--sheet);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--card);
  box-shadow: 0 -10px 30px rgba(23, 32, 51, 0.16);
}

.sheet-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }

.regular-link, .share-link {
  color: var(--green-deep);
  font-weight: 750;
  word-break: break-all;
}

.regular-link { display: block; margin-top: 12px; }

.share-link {
  display: block;
  text-align: left;
  text-decoration: none;
  background: #f7f1e6;
  border: 1px solid #eadfcd;
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 0;
}

#share-url {
  display: block;
  margin-top: 4px;
  color: var(--green-deep);
  font-size: 14px;
  font-weight: 750;
  text-decoration: underline;
  word-break: break-all;
}

.code-label, .code-hint { display: block; font-size: 11px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; }

.code {
  display: block;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 30px;
  letter-spacing: 0.16em;
  font-weight: 800;
  color: var(--ink);
}

.sheet-stats { text-align: right; }
.sheet-stats p { margin: 0; }
#people-count { font-weight: 750; }
#duration { color: var(--muted); font-variant-numeric: tabular-nums; }

#track-note { margin: 0; }

#people {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  min-height: 0;
  flex: 1;
}

.person {
  width: 100%;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  margin-bottom: 8px;
  background: #fff;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.person strong { display: block; }
.person small { color: var(--muted); }
.person em { font-style: normal; font-size: 13px; font-weight: 750; }
.person em.live { color: var(--green); }
.person em.stale, .person em.waiting { color: var(--gold); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .danger { grid-column: 1 / -1; }

.toast {
  position: fixed;
  z-index: 800;
  left: 50%;
  bottom: calc(var(--sheet) + 12px);
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: white;
  padding: 10px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.person-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  color: white;
  font: 800 12px/1 "Segoe UI", system-ui, sans-serif;
  position: relative;
}

.person-dot.me { box-shadow: 0 0 0 3px #172033, 0 2px 8px rgba(0, 0, 0, 0.35); }
.person-dot.stale { filter: grayscale(0.85); opacity: 0.8; }

.nose {
  position: absolute;
  width: 0;
  height: 0;
  top: -8px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 8px solid currentColor;
  transform-origin: 50% 22px;
}

.leaflet-div-icon { background: transparent; border: none; }
.leaflet-bottom.leaflet-left { bottom: calc(var(--sheet) + 8px); }
.leaflet-top { top: 74px; }

.empty {
  color: var(--muted);
  padding: 8px 2px;
}
