:root {
  --bg: #11161c;
  --card: #1a2129;
  --card-2: #222b35;
  --panel: rgba(17, 22, 28, 0.94);
  --line: #2f3a46;
  --text: #eef2f6;
  --muted: #a3afbb;
  --accent: #34d399;
  --ok: #22c55e;
  --warn: #fbbf24;
  --bad: #f87171;
  --help: #dc2626;
  --me: #3b82f6;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Text size (Settings): sizes are in rem, so changing this one value scales the whole app. */
html { font-size: 17px; }
html.text-large { font-size: 20px; }
html.text-xl { font-size: 23px; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  overscroll-behavior: none;
}

/* Header, alerts, screen, tab bar stacked top to bottom; only the screen scrolls. */
body { display: flex; flex-direction: column; }

button { font: inherit; color: inherit; cursor: pointer; }
a { color: #93c5fd; }
h1 { font-size: 1.412rem; margin: 4px 0 12px; }
h2 { font-size: 1.118rem; margin: 0; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.icon-btn svg, .fab svg, .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill, .fab svg .fill { fill: currentColor; }

/* Buttons. `.btn` makes links look like buttons. */
.btn, .wide, .fam-btns button, .sel-btns button, .loc-btns button, .setting-row button, .todo button, .find-btns button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  font-size: 0.941rem; font-weight: 600;
  text-decoration: none;
}
.btn.primary, .composer .primary, .actions .primary { background: var(--accent); border-color: var(--accent); color: #062a1e; }
.wide { display: flex; width: 100%; margin-top: 12px; }
.link { padding: 6px 2px; border: 0; background: none; color: #93c5fd; font-size: 0.941rem; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* Top bar */
.bar {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.059rem; margin-right: auto; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 0.824rem; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill[data-state="ok"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.pill[data-state="warn"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pill[data-state="bad"] { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.07); }

/* Screens */
main { flex: 1; min-height: 0; position: relative; }
.screen { position: absolute; inset: 0; overflow-y: auto; padding: 14px 16px 24px; -webkit-overflow-scrolling: touch; }
.screen > * { max-width: 640px; margin-left: auto; margin-right: auto; }
.screen h2 { margin-top: 26px; margin-bottom: 8px; }

/* Bottom tabs */
.tabbar {
  flex: none;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 4px 4px calc(4px + var(--safe-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.tabbar button {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px;
  border: 0; border-radius: 12px;
  background: none;
  color: var(--muted);
  font-size: 0.765rem; font-weight: 600;
}
.tabbar button[aria-current="page"] { color: var(--text); background: rgba(255, 255, 255, 0.07); }
.badge {
  position: absolute; top: 0; right: calc(50% - 26px);
  min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 11px;
  background: var(--bad); color: #fff;
  font-size: 0.765rem; font-weight: 700; line-height: 22px;
}

/* Cards */
.card, .me-card, .note-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.note-card { margin-bottom: 12px; border-color: color-mix(in srgb, var(--warn) 50%, transparent); color: #fde68a; font-size: 0.941rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h2 { margin: 0; }
#setupList { margin-top: 26px; }

/* My status and the two big buttons */
.me-status { font-size: 1.059rem; font-weight: 600; margin-bottom: 12px; }
.me-status.ok { color: #86efac; }
.me-status.wait { color: var(--warn); }
.me-status.help { color: #fca5a5; }
.big-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 120px;
  border-radius: 18px;
  border: 0;
  font-size: 1.235rem; font-weight: 800;
  color: #fff;
}
.big .ico { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, 0.22); font-size: 1.529rem; line-height: 1; }
.big.ok { background: #15803d; }
.big.help { background: #b91c1c; }
.big:active { transform: scale(0.98); }
.me-where { margin-top: 12px; font-size: 0.882rem; color: var(--muted); }
.me-where.warn { color: var(--warn); }

/* Keep sharing: the toggle card, and the dimmed screen while it's on */
.keep-card { margin-top: 12px; border-color: color-mix(in srgb, var(--me) 50%, transparent); }
.keep-card.on { border-color: var(--accent); }
.keep-toggle { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; cursor: pointer; }
.keep-text { display: flex; flex-direction: column; gap: 2px; }
.keep-text b { font-size: 1.059rem; }
.keep-text small { font-size: 0.824rem; color: var(--muted); }
.keep-card.on .keep-text small { color: #86efac; }
.keep-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch { position: relative; flex: none; width: 60px; height: 34px; border-radius: 17px; background: var(--line); transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.keep-toggle input:checked + .switch { background: var(--accent); }
.keep-toggle input:checked + .switch::after { transform: translateX(26px); }
.keep-toggle input:focus-visible + .switch { outline: 2px solid var(--me); outline-offset: 2px; }
.dim {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 24px;
  background: #000; /* black keeps an OLED screen's power use low */
  color: #4b5563;
  text-align: center;
  cursor: pointer;
  user-select: none; -webkit-user-select: none;
}
.dim-clock { font-size: 3.294rem; font-weight: 300; line-height: 1; margin-bottom: 14px; color: #6b7280; font-variant-numeric: tabular-nums; }
.dim-me { font-size: 1.0rem; font-weight: 600; max-width: 400px; }
.dim-status, .dim-left { font-size: 0.882rem; max-width: 400px; }
.dim-wake { margin-top: 36px; min-height: 64px; padding: 14px 40px; border-radius: 18px; border: 1px solid #374151; background: #111827; color: #9ca3af; font-size: 1.176rem; font-weight: 700; }

/* Setup checklist */
.todo { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.todo li { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; font-size: 0.941rem; }
.todo .tick { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); color: #062a1e; font-weight: 800; font-size: 0.882rem; }
.todo li.done { color: var(--muted); }
.todo li.done .tick { background: var(--accent); border-color: var(--accent); }
.todo button { min-height: 40px; padding: 6px 14px; }

/* Family list */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 26px; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.family, .places { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.family .empty, .places .empty { color: var(--muted); padding: 4px 2px; }
.fam, .place { background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--line); border-radius: 16px; padding: 4px 12px 12px; }
.fam.ok { border-left-color: var(--ok); }
.fam.wait { border-left-color: var(--warn); }
.fam.help { border-left-color: var(--help); background: #3b1111; animation: sos-flash 0.9s ease-in-out infinite alternate; }
.fam-main { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 12px; width: 100%; padding: 8px 0; border: 0; background: none; text-align: left; }
.avatar { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--c); color: #fff; font-size: 1.294rem; font-weight: 800; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); }
.fam-text { display: flex; flex-direction: column; min-width: 0; }
.fam-name { font-size: 1.118rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fam-status { font-weight: 700; color: var(--muted); }
.fam.ok .fam-status { color: #86efac; }
.fam.wait .fam-status { color: var(--warn); }
.fam.help .fam-status { color: #fca5a5; text-transform: uppercase; letter-spacing: 0.5px; }
.fam-where { font-size: 0.824rem; color: var(--muted); }
.fam-bat, .find-bat { font-size: 0.824rem; color: var(--muted); }
.fam-bat.low, .find-bat.low { color: var(--bad); font-weight: 700; }
.find-bat { font-size: 0.941rem; }
.ready-link { display: block; margin: 4px auto 0; }
.ready-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.ready-list li { display: flex; flex-direction: column; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.ready-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.ready-list small.stale { color: var(--warn); font-weight: 700; }
.ready-items { display: flex; flex-wrap: wrap; gap: 6px; }
.ready-items span { padding: 3px 8px; border-radius: 999px; font-size: 0.824rem; font-weight: 600; }
.ready-items .yes { background: color-mix(in srgb, #22c55e 18%, transparent); color: #86efac; }
.ready-items .no { background: color-mix(in srgb, var(--bad) 16%, transparent); color: #fca5a5; }
.fam-allergy { font-size: 0.824rem; font-weight: 700; color: var(--warn); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fam-range { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.fam-dist { font-size: 1.118rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fam-dir { font-size: 0.824rem; color: var(--muted); }
.join-clear { list-style: none; display: flex; justify-content: flex-end; }
.join-clear button, .chat-clear { min-height: 40px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); color: var(--muted); font: inherit; font-size: 0.882rem; font-weight: 600; }
.chat-clear { align-self: flex-end; margin: 8px 12px 0; }
.join-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.join-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 12px 14px; border-radius: 14px; background: var(--card); border: 2px solid var(--warn); }
.join-row.removed { border-color: var(--line); }
.join-row small { display: block; color: var(--muted); font-size: 0.824rem; }
.join-btns { display: flex; gap: 8px; }
.join-btns button { min-height: 44px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card-2); color: inherit; font: inherit; font-weight: 700; }
.join-btns button.primary { background: var(--accent); border-color: var(--accent); color: #04120a; }
.fam-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.fam-btns > * { flex: 1 1 0; min-width: 72px; }
/* Removing someone is rare, so it stays small and quiet next to the big buttons. */
.fam-btns .remove { flex: 0 0 auto; min-width: 0; min-height: 44px; padding: 6px 8px; border: 0; background: none; color: var(--muted); font-size: 0.824rem; text-decoration: underline; text-underline-offset: 3px; }

/* Places on the plan screen */
.place { padding: 12px; border-left-color: var(--c); }
.place.pending { border-style: dashed; }
.place-top { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; }
.place-icon { font-size: 1.529rem; line-height: 1; text-align: center; }
.place-text { display: flex; flex-direction: column; min-width: 0; }
.place-name { font-size: 1.059rem; overflow-wrap: anywhere; }
.place-kind { font-size: 0.824rem; color: var(--muted); }
.place-dist { font-size: 0.882rem; font-weight: 600; text-align: right; color: var(--muted); }
.place-note { margin: 6px 0 0 46px; font-size: 0.882rem; overflow-wrap: anywhere; }
.place .fam-btns { margin-top: 10px; }

/* Plan screen */
.steps { margin: 0; padding-left: 26px; display: flex; flex-direction: column; gap: 8px; }
.steps li::marker { font-weight: 800; color: var(--accent); }
.hint { margin: 0 0 8px; color: var(--muted); font-size: 0.882rem; }
.hint.fine { margin-top: 16px; font-size: 0.824rem; }
.contact-name { font-size: 1.118rem; font-weight: 700; }
.contact-phone { color: var(--muted); margin-bottom: 10px; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; }
.guides { display: flex; flex-direction: column; gap: 8px; }
.guides details { background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.guides summary { padding: 14px 16px; font-weight: 700; cursor: pointer; }
.guides ul { margin: 0; padding: 0 16px 14px 36px; display: flex; flex-direction: column; gap: 6px; }

/* Help alerts and check-in requests (shown above every screen) */
.sos-area { flex: none; display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; padding: 0 12px; }
.sos-area:has(> :not([hidden])) { padding-top: 10px; padding-bottom: 4px; }
.sos-card, .ask-card { padding: 12px 14px; border-radius: 16px; color: #fff; }
.sos-card { background: #7f1d1d; border: 2px solid #ef4444; }
.sos-card:not(.mine) { animation: sos-flash 0.9s ease-in-out infinite alternate; }
.ask-card { background: #3b2f0a; border: 2px solid var(--warn); }
.sos-title, .ask-title { font-size: 1.059rem; font-weight: 800; }
.sos-range { font-size: 1.412rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.sos-sub { font-size: 0.882rem; color: #fecaca; }
.sos-allergy { font-size: 0.941rem; font-weight: 800; color: #fff; }
.sos-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.sos-btns > * {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 0.941rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.sos-btns .primary { background: #fff; border-color: #fff; color: #7f1d1d; font-weight: 800; }
.sos-btns button:disabled { opacity: 0.8; cursor: default; }
.sos-btns .ok-btn { background: #15803d; border-color: #22c55e; font-weight: 800; }
.sos-btns .help-btn { background: #b91c1c; border-color: #ef4444; font-weight: 800; }
.sos-hold {
  position: relative;
  overflow: hidden;
  min-height: 72px;
  padding: 18px;
  border-radius: 16px;
  border: 2px solid #ef4444;
  background: #450a0a;
  font-size: 1.176rem; font-weight: 800;
  touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.sos-hold span:last-child { position: relative; }
.sos-fill { position: absolute; inset: 0; background: #dc2626; transform: scaleX(0); transform-origin: left; }
.sos-hold.holding .sos-fill { transform: scaleX(1); transition: transform 1.5s linear; }
.warn-text { color: var(--warn); }
@keyframes sos-flash { from { border-color: #ef4444; } to { border-color: #fff; } }
@keyframes sos-ring { from { transform: scale(0.6); opacity: 1; } to { transform: scale(1.7); opacity: 0; } }

/* Toast, above the tab bar */
.toast {
  position: fixed;
  bottom: calc(84px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 1100;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 14px;
  background: #0b0f13;
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  font-size: 0.941rem;
}

/* Messages */
.chat-screen { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-screen > * { width: 100%; }
.chat-screen > .chat-clear { width: auto; }
.chat { flex: 1; min-height: 0; overflow: auto; list-style: none; margin: 0 auto; padding: 8px 14px 10px; display: flex; flex-direction: column; }
.chat .empty { color: var(--muted); padding: 10px 2px; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 85%; margin-top: 4px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .from { display: flex; align-items: center; gap: 6px; margin: 10px 4px 2px; font-size: 0.824rem; font-weight: 700; color: var(--muted); }
.msg .from::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.msg.mine .from::before { display: none; }
.bubble { padding: 8px 13px; border-radius: 16px; background: var(--card-2); overflow-wrap: anywhere; }
.msg.mine .bubble { background: color-mix(in srgb, var(--me) 40%, #1a2129); }
.bubble small { display: block; margin-top: 2px; font-size: 0.765rem; color: var(--muted); text-align: right; }
.msg.pending .bubble { outline: 1px dashed var(--muted); opacity: 0.85; }
/* Notices from Jtak ("Sam joined the family"): centered and quiet. */
.msg.sys { align-self: center; align-items: center; max-width: 95%; margin-top: 10px; }
.msg.sys .bubble { background: none; padding: 2px 8px; color: var(--muted); font-size: 0.824rem; text-align: center; }
.msg.sys .bubble small { display: inline; margin-left: 6px; font-size: 0.706rem; }
.quick { flex: none; display: flex; gap: 8px; overflow-x: auto; margin: 0 auto; padding: 10px 14px 2px; border-top: 1px solid var(--line); scrollbar-width: none; }
.quick button { flex: none; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card-2); font-size: 0.882rem; white-space: nowrap; }
.composer { flex: none; display: flex; gap: 8px; margin: 0 auto; padding: 8px 14px 12px; }
.composer input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 1rem; /* 16px or more stops iOS zooming into the field */
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
}
.composer button { padding: 10px 18px; border-radius: 12px; border: 1px solid var(--accent); font-weight: 700; }

/* Map screen */
.map-screen { padding: 0; overflow: hidden; }
.map-screen > * { max-width: none; }
#map { position: absolute; inset: 0; background: #1c232b; }
.fabs { position: absolute; z-index: 1000; right: 12px; bottom: 32px; display: flex; flex-direction: column; gap: 12px; }
.fab {
  display: grid; place-items: center;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.fab[aria-pressed="true"] { color: var(--me); border-color: var(--me); }
.selinfo {
  position: absolute;
  z-index: 1000;
  left: 12px; right: 80px; bottom: 32px;
  max-width: 440px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 6px solid var(--c, var(--accent));
}
.selinfo .who { font-weight: 700; font-size: 1.059rem; }
.selinfo .big { display: block; min-height: 0; font-size: 1.294rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.selinfo .sub { font-size: 0.824rem; color: var(--muted); }
.sel-btns { display: flex; gap: 8px; margin-top: 10px; }
.sel-btns > * { flex: 1; min-height: 40px; padding: 6px 10px; }

/* Map markers */
.me-icon, .tm-icon { background: none; border: 0; }
.me { position: relative; width: 40px; height: 40px; }
.me-dot {
  position: absolute; left: 12px; top: 12px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--me);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}
.me-cone, .tm-arrow { position: absolute; inset: 0; transform: rotate(var(--hdg, 0deg)); }
.me-cone::before {
  content: "";
  position: absolute; left: 50%; top: -6px;
  width: 0; height: 0;
  margin-left: -11px;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 22px solid rgba(59, 130, 246, 0.55);
}
.me[data-hdg="none"] .me-cone, .tm[data-hdg="none"] .tm-arrow { display: none; }
.tm { position: relative; width: 36px; height: 36px; }
.tm-dot {
  position: absolute; left: 8px; top: 8px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4);
}
.tm-arrow::before {
  content: "";
  position: absolute; left: 50%; top: -3px;
  margin-left: -6px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid var(--c);
  filter: drop-shadow(0 0 1px #000);
}
.tm-label {
  position: absolute; left: 32px; top: 6px;
  padding: 1px 7px;
  border-radius: 6px;
  background: rgba(17, 22, 28, 0.88);
  color: #fff;
  font-size: 0.824rem; font-weight: 700;
  white-space: nowrap;
}
.tm-label small { font-weight: 400; color: var(--muted); margin-left: 4px; }
.tm.old .tm-dot { opacity: 0.7; border-style: dashed; }
.tm.selected .tm-dot { box-shadow: 0 0 0 3px var(--c), 0 0 0 5px #fff; }
.tm.sos .tm-dot::after {
  content: "";
  position: absolute; inset: -10px;
  border-radius: 50%;
  border: 3px solid #ef4444;
  animation: sos-ring 1.2s ease-out infinite;
}
.tm.sos .tm-label { background: #b91c1c; color: #fff; }
.wp-icon { background: none; border: 0; }
.wp { position: relative; width: 30px; height: 30px; }
.wp-pin {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 9px;
  background: #fff;
  border: 2px solid var(--c);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  font-size: 0.941rem; line-height: 1;
}
.wp-label {
  position: absolute; left: 34px; top: 5px;
  padding: 1px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: #11161c;
  font-size: 0.824rem; font-weight: 700;
  white-space: nowrap;
}
.wp.selected .wp-pin { box-shadow: 0 0 0 3px var(--c), 0 0 0 5px #fff; }
.wp.pending .wp-pin { border-style: dashed; }
.leaflet-control-layers { background: var(--panel); color: var(--text); border: 1px solid var(--line) !important; }
.leaflet-control-layers-toggle { filter: invert(1); }
.leaflet-container .leaflet-control-attribution { background: rgba(17, 22, 28, 0.75); color: var(--muted); }
.leaflet-container .leaflet-control-attribution a { color: #c7d2dd; }

/* Dialogs */
dialog {
  width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bg);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.65); }
dialog form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
dialog h2 { margin: 0; font-size: 1.235rem; }
dialog small, .opt { color: var(--muted); font-size: 0.824rem; font-weight: 400; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 0.941rem; font-weight: 600; }
dialog label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; }
dialog label.check input { width: 22px; height: 22px; }
dialog input:not([type="checkbox"]):not([type="radio"]), dialog select, dialog textarea {
  font: inherit; font-size: 1rem; font-weight: 400; /* 16px or more stops iOS zooming into the field */
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
}
dialog textarea { resize: vertical; }
dialog input:focus-visible, dialog select:focus-visible, dialog textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--me); outline-offset: 1px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 0.941rem; font-weight: 600; margin-bottom: 8px; }
fieldset.profile { display: flex; flex-direction: column; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
fieldset.profile legend { padding: 0 4px; }
.choice { display: flex; flex-direction: column; gap: 10px; }
.radio-card { position: relative; }
.radio-card input { position: absolute; opacity: 0; }
.radio-card > span { display: flex; flex-direction: column; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); font-weight: 400; }
.radio-card b { font-size: 1rem; }
.radio-card input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--card)); }
.radio-card input:focus-visible + span { outline: 2px solid var(--me); outline-offset: 2px; }
.colors { display: flex; flex-wrap: wrap; gap: 10px; }
.colors label { position: relative; }
.colors input { position: absolute; opacity: 0; }
.colors span { display: block; width: 38px; height: 38px; border-radius: 50%; background: var(--c); border: 3px solid transparent; }
.colors input:checked + span { border-color: #fff; box-shadow: 0 0 0 2px var(--c); }
.colors input:focus-visible + span { outline: 2px solid var(--me); outline-offset: 2px; }
.kinds { display: flex; flex-wrap: wrap; gap: 8px; }
.kinds label { position: relative; flex-direction: row; font-weight: 400; }
.kinds input { position: absolute; opacity: 0; }
.kinds span { display: block; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 0.882rem; }
.kinds input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--card)); }
.kinds input:focus-visible + span { outline: 2px solid var(--me); outline-offset: 1px; }
.loc { display: flex; flex-direction: column; gap: 8px; font-size: 0.941rem; }
#wpLoc { color: var(--muted); font-variant-numeric: tabular-nums; }
.addr { display: flex; flex-direction: column; gap: 6px; }
.addr-row { display: flex; gap: 8px; }
.addr-row input { flex: 1; min-width: 0; }
.addr-row button { flex: none; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.addr-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--card); overflow: hidden; }
.addr-list button { display: block; width: 100%; padding: 10px 12px; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: none; color: inherit; text-align: left; font-size: 0.882rem; line-height: 1.3; }
.addr-list li:first-child button { border-top: 0; }
.addr-list .none { padding: 10px 12px; color: var(--muted); font-size: 0.882rem; }
.addr-off { margin: 0; color: var(--muted); font-size: 0.882rem; }
.jump { position: absolute; z-index: 1000; top: 12px; left: 58px; right: 12px; max-width: 420px; display: flex; flex-direction: column; gap: 6px; }
.jump .addr-row input { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 0.941rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
.jump .addr-row button { background: var(--panel); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
.jump .addr-list { background: var(--panel); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
.loc-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.setting-row small { display: block; }
.setting-row code { display: block; font-size: 0.882rem; color: var(--muted); overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions button { min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.actions .grow { flex: 1; font-size: 1.059rem; }
.actions .danger { margin-right: auto; color: var(--bad); }
.big-link { display: flex; align-items: center; justify-content: center; min-height: 64px; padding: 12px 16px; border-radius: 16px; color: #fff; font-size: 1.059rem; font-weight: 800; text-align: center; text-decoration: none; }
.big-link.ok { background: #15803d; }
.big-link.help { background: #b91c1c; }
#textDlg.help-first #textHelp { order: -1; }
#textDlg.help-first #textTitle, #textDlg.help-first #textBody { order: -2; }

/* Find: one big arrow */
dialog.full { width: min(520px, 100%); height: min(760px, 100%); max-height: 100%; }
.find { height: 100%; align-items: center; text-align: center; }
.find-head { display: flex; align-items: center; justify-content: space-between; width: 100%; text-align: left; }
.find-head h2 { font-size: 1.412rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.find-status { font-size: 1.059rem; font-weight: 700; color: var(--muted); }
.find-status.ok { color: #86efac; }
.find-status.wait { color: var(--warn); }
.find-status.help { color: #fca5a5; }
.compass { position: relative; width: min(56vw, 240px); aspect-ratio: 1; border-radius: 50%; border: 3px solid var(--line); background: radial-gradient(circle, var(--card-2), var(--bg)); flex: none; }
.needle { position: absolute; inset: 10%; transition: transform 0.25s ease-out; }
.needle::before {
  content: "";
  position: absolute; left: 50%; top: 0;
  margin-left: -34px;
  border-left: 34px solid transparent;
  border-right: 34px solid transparent;
  border-bottom: 110px solid var(--accent);
}
.needle::after { content: ""; position: absolute; left: 50%; top: 100px; width: 22px; height: 40%; margin-left: -11px; background: var(--accent); border-radius: 0 0 8px 8px; }
.find-dist { font-size: 2.588rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.find-sub { font-size: 1.059rem; color: var(--muted); }
.find .hint { max-width: 380px; }
.find-allergy { max-width: 420px; padding: 6px 12px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); font-weight: 800; white-space: pre-line; }
.people { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }
.person-head { display: flex; align-items: center; gap: 12px; }
.person-head .avatar { width: 40px; height: 40px; font-size: 1.118rem; flex: none; }
.person-name { font-weight: 700; font-size: 1.059rem; }
.person-phone { color: var(--muted); }
.person .find-about dd a { color: inherit; }
.person .fam-btns { margin-top: 10px; }
.person-empty { color: var(--muted); margin: 8px 0 0; }
.find-about { width: 100%; margin: 0; text-align: left; display: grid; gap: 2px 0; }
.find-about dt { font-size: 0.824rem; color: var(--muted); margin-top: 8px; }
.find-about dd { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.find-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; margin-top: auto; }

@media (prefers-reduced-motion: reduce) {
  .sos-card:not(.mine), .fam.help, .tm.sos .tm-dot::after { animation: none; }
  .needle, .switch, .switch::after { transition: none; }
}

@media (max-width: 380px) {
  .big { min-height: 104px; font-size: 1.118rem; }
  .fam-main { grid-template-columns: 40px 1fr auto; gap: 10px; }
  .avatar { width: 40px; height: 40px; font-size: 1.118rem; }
}

/* Invite: QR code to scan in person, family code in big type */
.qr { width: min(100%, 280px); margin: 0 auto; border-radius: 12px; overflow: hidden; background: #fff; }
.qr svg { display: block; width: 100%; height: auto; }
.code-big { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); text-align: center; }
.code-big code { font-size: 1.5rem; font-weight: 800; letter-spacing: 0.04em; overflow-wrap: anywhere; }

/* The printed plan. Hidden on screen; when printing it is the only thing shown. */
.print-sheet { display: none; }
@media print {
  html, html.text-large, html.text-xl { font-size: 12pt; } /* print at 12pt whatever the screen text size */
  html, body { height: auto; background: #fff !important; color: #000; color-scheme: light; }
  body { display: block; }
  body > :not(.print-sheet), dialog, .toast { display: none !important; }
  .print-sheet { display: block; max-width: none; padding: 0; color: #000; font-family: Georgia, "Times New Roman", serif; line-height: 1.35; }
  .print-sheet h1 { font-size: 20pt; margin: 0 0 2pt; }
  .print-sheet h2 { font-size: 14pt; margin: 14pt 0 4pt; padding-bottom: 2pt; border-bottom: 1.5pt solid #000; break-after: avoid; }
  .print-sheet .printed { margin: 0 0 6pt; font-size: 10pt; color: #333; }
  .print-sheet ol, .print-sheet ul { margin: 0; padding-left: 16pt; }
  .print-sheet li { margin: 0 0 4pt; break-inside: avoid; }
  .print-sheet .pl-coord { font-family: "Courier New", monospace; font-size: 11pt; white-space: nowrap; }
  .print-sheet .pl-note { font-style: italic; }
  .print-sheet .pl-hint { font-size: 10pt; color: #333; margin: 4pt 0 0; }
  .print-sheet .pl-notes { white-space: pre-wrap; overflow-wrap: anywhere; }
  .print-sheet .pl-contact { font-size: 14pt; }
  .print-sheet .pl-people { display: grid; grid-template-columns: 1fr 1fr; gap: 2pt 16pt; list-style: none; padding: 0; }
  .print-sheet .pl-phone { font-family: "Courier New", monospace; }
  .print-sheet .pl-empty { color: #444; font-style: italic; }
  @page { margin: 15mm; }
}
