:root {
  --red: #cc1429; --red-light: #f24d4d; --navy: #0d2454; --navy-light: #294d9e; --gold: #fac233;
  --to-knock: #3b66ed; --talked: #29b86b; --not-home: #fa9924; --muted: #8c94a3;
  --bg: #f2f2f7; --card: #ffffff; --card2: #f7f7fa; --text: #111318; --text2: #6b7280; --line: rgba(0,0,0,.08);
  --glass: rgba(255,255,255,.86); --shadow: 0 6px 24px rgba(0,0,0,.16);
  --red-grad: linear-gradient(135deg, var(--red-light), var(--red));
  --navy-grad: linear-gradient(135deg, var(--navy-light), var(--navy));
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000; --card: #1c1c1e; --card2: #2c2c2e; --text: #f5f5f7; --text2: #a1a1aa; --line: rgba(255,255,255,.1);
    --glass: rgba(28,28,30,.86); --shadow: 0 6px 24px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --bg: #000; --card: #1c1c1e; --card2: #2c2c2e; --text: #f5f5f7; --text2: #a1a1aa; --line: rgba(255,255,255,.1);
  --glass: rgba(28,28,30,.86); --shadow: 0 6px 24px rgba(0,0,0,.5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", system-ui, sans-serif; overscroll-behavior: none; }
body { overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: var(--text); }
h1, h2, h3 { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--text2); }
.small { font-size: 13px; }

.splash { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--navy-grad); color: #fff; font-weight: 800; font-size: 22px; }
.splash img { width: 88px; height: 88px; border-radius: 22px; }

/* ── Welcome ───────────────────────── */
.welcome { position: fixed; inset: 0; overflow-y: auto; background: var(--navy-grad); color: #fff;
  padding: calc(var(--safe-top) + 32px) 16px calc(var(--safe-bottom) + 24px); }
.welcome-inner { max-width: 420px; margin: 0 auto; display: grid; gap: 20px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { width: 60px; height: 60px; border-radius: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.brand h1 { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.brand p { margin: 2px 0 0; opacity: .8; font-size: 14px; }
.panel { background: var(--card); color: var(--text); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card2); border-radius: 12px; padding: 3px; }
.seg button { padding: 9px 4px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--text2); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text2); }
.field input, .field textarea { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); outline: none; }
.field input:focus, .field textarea:focus { border-color: var(--navy-light); }
.code-input { font-size: 28px !important; letter-spacing: 10px; text-align: center; font-weight: 800; }
.err { color: var(--red); font-size: 14px; font-weight: 600; }
.note { font-size: 13px; opacity: .85; text-align: center; line-height: 1.45; }
.note a { color: #fff; }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 15px; border-radius: 999px;
  font-weight: 700; font-size: 17px; background: var(--red-grad); color: #fff; box-shadow: 0 4px 12px rgba(204,20,41,.35); transition: transform .12s; }
.btn:active { transform: scale(.97); }
.btn:disabled { background: rgba(140,148,163,.25); color: var(--text2); box-shadow: none; }
.btn.navy { background: var(--navy-grad); box-shadow: 0 4px 12px rgba(13,36,84,.3); }
.btn.plain { background: var(--card2); color: var(--text); box-shadow: none; }
.btn.danger { background: transparent; color: var(--red); box-shadow: none; border: 1.5px solid var(--red); }
.btn.sm { padding: 10px 14px; font-size: 15px; width: auto; }

/* ── Map screen ────────────────────── */
#map { position: fixed; inset: 0; }
.topbar { position: fixed; left: 10px; right: 10px; top: calc(var(--safe-top) + 10px); display: flex; gap: 8px; align-items: center; z-index: 5; }
.glass { background: var(--glass); backdrop-filter: blur(18px) saturate(1.6); -webkit-backdrop-filter: blur(18px) saturate(1.6);
  border: 1px solid rgba(255,255,255,.18); box-shadow: var(--shadow); }
.wb-button { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: 18px; text-align: left; }
.wb-button .t { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wb-button .s { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wb-button .chev { margin-left: auto; color: var(--text2); flex: none; }
.ring { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; flex: none; position: relative; }
.ring svg { position: absolute; inset: 4px; transform: rotate(-90deg); }
.ring b { font-size: 13px; font-weight: 800; position: relative; }
.icon-btn { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 20px; }
.status-row { position: fixed; top: calc(var(--safe-top) + 72px); left: 10px; right: 10px; z-index: 4; display: grid; gap: 6px; justify-items: start; }
.banner { padding: 8px 12px; border-radius: 14px; font-size: 13px; font-weight: 600; }
.banner.warn { color: #b45309; }
.fabs { position: fixed; right: 12px; bottom: calc(var(--safe-bottom) + 18px); z-index: 4; display: grid; gap: 10px; justify-items: end; transition: bottom .2s; }
.fab { width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; }
.shift-pill { padding: 12px 18px; border-radius: 999px; font-weight: 700; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.shift-pill.on { background: var(--talked); color: #fff; border: 0; }
.shift-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.empty-map { position: fixed; left: 16px; right: 16px; bottom: calc(var(--safe-bottom) + 90px); z-index: 4; padding: 18px; border-radius: 22px; display: grid; gap: 10px; max-width: 460px; margin: 0 auto; }

.card-wrap { position: fixed; left: 10px; right: 10px; bottom: calc(var(--safe-bottom) + 10px); z-index: 6; max-width: 520px; margin: 0 auto; }
.hcard { border-radius: 26px; padding: 16px; display: grid; gap: 12px; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.hhead { display: flex; gap: 12px; align-items: flex-start; }
.hhead .who { flex: 1; min-width: 0; text-align: left; }
.hhead .name { font-size: 20px; font-weight: 800; line-height: 1.2; }
.hhead .addr { font-size: 14px; color: var(--text2); margin-top: 2px; }
.close { width: 30px; height: 30px; border-radius: 50%; background: rgba(140,148,163,.18); color: var(--text2); font-weight: 800; flex: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; gap: 4px; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.actions { display: flex; gap: 10px; align-items: center; }
.actions .btn { flex: 1; white-space: nowrap; font-size: 16px; padding: 14px 10px; min-width: 0; }
.round { width: 46px; height: 46px; border-radius: 50%; background: rgba(140,148,163,.16); display: grid; place-items: center; font-size: 19px; flex: none; }
.lastvisit { font-size: 12px; color: var(--text2); }
.avatars { display: flex; flex: none; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px; border: 2px solid var(--card); }
.avatars .avatar + .avatar { margin-left: -12px; }
.talked-banner { display: flex; gap: 10px; padding: 12px; border-radius: 14px; background: rgba(41,184,107,.12); font-size: 13px; }
.talked-banner b { display: block; font-size: 14px; }

.you-dot { width: 22px; height: 22px; position: relative; }
.you-core { position: absolute; inset: 3px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 1px 6px rgba(0,0,0,.35); }
.you-cone { position: absolute; left: 50%; bottom: 50%; width: 0; height: 0; margin-left: -14px; border-left: 14px solid transparent; border-right: 14px solid transparent;
  border-bottom: 30px solid rgba(26,115,232,.28); transform-origin: 50% 100%; display: none; }
.mate { width: 32px; height: 32px; border-radius: 50%; background: var(--navy-grad); color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center;
  border: 2.5px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.3); transition: transform 3.8s linear; }
.mate.stale { opacity: .5; }
.crosshair { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -100%); z-index: 5; font-size: 40px; pointer-events: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,.4)); }
.fixbar { position: fixed; left: 10px; right: 10px; bottom: calc(var(--safe-bottom) + 10px); z-index: 6; padding: 14px; border-radius: 22px; display: grid; gap: 10px; max-width: 520px; margin: 0 auto; }

/* ── Sheets ────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; top: calc(var(--safe-top) + 12px); z-index: 21; background: var(--bg);
  border-radius: 18px 18px 0 0; display: flex; flex-direction: column; animation: slide .25s cubic-bezier(.2,.8,.2,1); max-width: 640px; margin: 0 auto; }
@keyframes slide { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 16px 10px; }
.sheet-head h2 { font-size: 17px; font-weight: 700; text-align: center; }
.sheet-head .l { justify-self: start; color: var(--navy-light); font-weight: 500; }
.sheet-head .r { justify-self: end; color: var(--navy-light); font-weight: 700; }
@media (prefers-color-scheme: dark) { .sheet-head .l, .sheet-head .r { color: #7ea2ff; } }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 16px 24px; display: grid; gap: 20px; align-content: start; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 16px calc(var(--safe-bottom) + 10px); background: var(--glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); }

.group { background: var(--card); border-radius: 16px; overflow: hidden; }
.group-title { font-size: 13px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .3px; margin: 0 4px -12px; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; }
.row .s { font-size: 13px; color: var(--text2); }
.row.on { background: rgba(41,77,158,.08); }
.bar { height: 6px; border-radius: 3px; background: rgba(140,148,163,.2); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--red), #fa7333); }
.badge { font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: rgba(140,148,163,.18); color: var(--text2); }

.step { display: grid; gap: 12px; }
.step-title { display: flex; gap: 10px; align-items: center; font-size: 19px; font-weight: 800; }
.step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--navy-grad); color: #fff; display: grid; place-items: center; font-size: 14px; flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.answer { padding: 18px 10px; border-radius: 18px; background: var(--card); display: grid; justify-items: center; gap: 8px; font-weight: 700; font-size: 16px;
  border: 2.5px solid transparent; white-space: pre-line; text-align: center; transition: transform .12s; }
.answer:active, .choice:active, .outcome:active { transform: scale(.97); }
.answer .ic { font-size: 30px; }
.outcome { padding: 14px 12px; border-radius: 14px; background: var(--card); display: flex; gap: 10px; align-items: center; font-weight: 600; font-size: 15px; border: 2px solid transparent; text-align: left; }
.choice { min-height: 46px; padding: 6px 4px; border-radius: 12px; font-weight: 600; font-size: 15px; text-align: center; }
.person { background: var(--card); border-radius: 20px; padding: 16px; display: grid; gap: 16px; }
.person-head { display: flex; gap: 10px; align-items: center; }
.q { display: grid; gap: 8px; }
.q > .lbl { font-size: 14px; font-weight: 600; color: var(--text2); }
.flowchips { display: flex; flex-wrap: wrap; gap: 8px; }
.flowchips button { padding: 10px 16px; border-radius: 999px; background: var(--card); font-weight: 600; border: 2px solid transparent; }
.flowchips button.on { background: var(--navy-light); color: #fff; }
.script { background: var(--card); border-radius: 18px; padding: 14px 16px; display: grid; gap: 8px; }
.script .head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.script p { margin: 0; white-space: pre-wrap; font-size: 16px; line-height: 1.5; }
.sign-card { display: flex; gap: 14px; align-items: center; padding: 16px; border-radius: 18px; background: var(--card); border: 2px solid transparent; text-align: left; width: 100%; }
.sign-card.on { border-color: var(--red); background: rgba(204,20,41,.07); }
.sign-card .check { margin-left: auto; font-size: 26px; }
.hint { font-size: 13px; color: var(--text2); display: flex; gap: 6px; }
.flag-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.flag-toggles button { padding: 12px; border-radius: 12px; background: var(--card); font-weight: 600; font-size: 14px; text-align: left; border: 2px solid transparent; }
.flag-toggles button.on { border-color: var(--not-home); background: rgba(250,153,36,.1); }
.flag-toggles button.on.dnk { border-color: var(--red); background: rgba(204,20,41,.08); }
.dnk-warn { background: var(--red); color: #fff; padding: 14px; border-radius: 14px; font-weight: 700; font-size: 15px; }
.voter-line { display: grid; gap: 2px; padding: 12px 16px; }
.voter-line + .voter-line { border-top: 1px solid var(--line); }
.detail-kv { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.notes-list { display: grid; gap: 10px; padding: 14px 16px; }
.notes-list .n { display: grid; gap: 2px; }

#toasts { position: fixed; top: calc(var(--safe-top) + 80px); left: 0; right: 0; z-index: 40; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: var(--shadow); border-radius: 20px;
  padding: 12px 18px; display: flex; gap: 12px; align-items: center; animation: pop .35s cubic-bezier(.2,1.4,.4,1); max-width: calc(100% - 32px); }
.toast .e { font-size: 30px; }
.toast b { display: block; }
@keyframes pop { from { transform: scale(.7) translateY(-10px); opacity: 0; } }

.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: var(--safe-bottom); }

@media (min-width: 900px) {
  .card-wrap { left: 16px; right: auto; width: 420px; margin: 0; }
  .topbar { max-width: 640px; }
}
