/* ===== Tokens ===== */
:root {
  --bg: #091210;
  --bg-grad: radial-gradient(130% 80% at 50% -8%, #10211d 0%, #091210 58%);
  --surface: #0f1b19;
  --surface-2: #16241f;
  --surface-3: #1c2e28;
  --line: #203330;
  --line-soft: #1a2a26;
  --fg: #f0f6f4;
  --muted: #88a39c;
  --muted-2: #627b75;
  --accent: #1fd1a6;
  --accent-2: #13b38d;
  --accent-ink: #042a22;
  --amber: #f6b24b;
  --danger: #f06565;
  --online: #3ddc84;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px -12px rgba(0,0,0,0.6);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 66px;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  overscroll-behavior: none; -webkit-font-smoothing: antialiased;
  font-size: 15px; letter-spacing: -0.006em;
}
h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.025em; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
.muted { color: var(--muted); }
.muted.sub { margin: -2px 0 14px; font-size: 13.5px; }
[hidden] { display: none !important; }

/* icon sizing */
svg { display: block; }
.ic { width: 20px; height: 20px; }
.bi svg { width: 17px; height: 17px; }

/* ===== Brand ===== */
.brand { display: flex; align-items: center; gap: 10px; font-size: 21px; font-weight: 800; letter-spacing: -0.03em; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; color: var(--accent-ink);
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 14px -4px rgba(31,209,166,0.6);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-mark.small { width: 28px; height: 28px; border-radius: 9px; }
.brand-mark.small svg { width: 17px; height: 17px; }

/* ===== Join ===== */
.join {
  min-height: 100%; display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 24px) max(18px, var(--safe-left)) calc(var(--safe-bottom) + 24px) max(18px, var(--safe-right));
  background: var(--bg-grad);
}
.join-card {
  width: 100%; max-width: 430px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: 26px; padding: 26px 22px;
  display: flex; flex-direction: column; gap: 15px; box-shadow: var(--shadow-lg);
}
.join-card h1 { font-size: 26px; margin-top: 6px; }
.join-card p.muted { margin: -8px 0 2px; font-size: 14px; }

label { display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: 0.01em; }
input[type=text], input[type=tel], select {
  width: 100%; padding: 14px 15px; font-size: 16px; font-weight: 500;
  color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: var(--muted-2); }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,209,166,0.14); }
.row { display: flex; gap: 12px; }
.row > label { flex: 1; min-width: 0; }

.swatches { display: flex; flex-wrap: wrap; gap: 11px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 2.5px solid transparent; cursor: pointer; padding: 0; transition: transform 0.12s; }
.swatch:active { transform: scale(0.92); }
.swatch.sel { border-color: var(--fg); box-shadow: 0 0 0 3px var(--bg), 0 0 0 4px var(--accent); }

.btn-primary {
  background: linear-gradient(145deg, var(--accent), var(--accent-2)); color: var(--accent-ink);
  border: none; border-radius: var(--radius-sm); padding: 15px; font-size: 16px; font-weight: 800;
  letter-spacing: -0.01em; box-shadow: 0 6px 18px -6px rgba(31,209,166,0.5);
  transition: transform 0.08s, filter 0.15s;
}
.btn-primary:active { transform: translateY(1px); filter: brightness(1.05); }
.btn-ghost { background: transparent; color: var(--danger); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 13px; font-size: 14px; font-weight: 700; }
.btn-small {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 999px; padding: 9px 15px 9px 13px; font-size: 13px; font-weight: 700;
}
.btn-small .bi { display: grid; place-items: center; color: var(--accent); }
.fineprint { font-size: 11.5px; color: var(--muted-2); line-height: 1.55; margin: 2px 0 0; }

/* ===== App layout ===== */
#app { min-height: 100%; display: flex; flex-direction: column; }

/* ===== Install banner ===== */
.install-banner {
  display: flex; align-items: center; gap: 12px;
  margin: 12px max(16px, var(--safe-left)) 0 max(16px, var(--safe-right));
  padding: 12px 12px 12px 14px; border-radius: 16px;
  background: linear-gradient(135deg, rgba(31,209,166,0.16), rgba(31,209,166,0.06));
  border: 1px solid rgba(31,209,166,0.35); box-shadow: var(--shadow);
}
.ib-icon { width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0; display: grid; place-items: center; color: var(--accent-ink); background: linear-gradient(145deg, var(--accent), var(--accent-2)); }
.ib-icon svg { width: 22px; height: 22px; }
.ib-text { flex: 1; min-width: 0; }
.ib-title { font-weight: 800; font-size: 14.5px; letter-spacing: -0.01em; }
.ib-sub { font-size: 12px; color: var(--muted); margin-top: 1px; line-height: 1.35; }
.ib-action { flex-shrink: 0; background: linear-gradient(145deg, var(--accent), var(--accent-2)); color: var(--accent-ink); border: none; border-radius: 10px; padding: 9px 15px; font-size: 13px; font-weight: 800; }
.ib-action:active { transform: translateY(1px); }
.ib-close { flex-shrink: 0; width: 30px; height: 30px; border-radius: 9px; border: none; background: transparent; color: var(--muted); display: grid; place-items: center; }
.ib-close svg { width: 16px; height: 16px; }

/* ===== Privacy / location toggle ===== */
.privacy-card {
  display: flex; align-items: center; gap: 13px; margin-bottom: 14px;
  padding: 13px 15px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line-soft); box-shadow: var(--shadow);
}
.pc-ico { width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; display: grid; place-items: center; color: var(--accent); background: rgba(31,209,166,0.12); }
.pc-ico svg { width: 20px; height: 20px; }
.privacy-card.off .pc-ico { color: var(--muted); background: var(--surface-2); }
.pc-main { flex: 1; min-width: 0; }
.pc-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.pc-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.switch {
  flex-shrink: 0; width: 52px; height: 32px; border-radius: 999px; border: none;
  background: var(--surface-3); position: relative; transition: background 0.2s; cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--line);
}
.switch .knob { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.3); transition: transform 0.2s; }
.switch.on { background: linear-gradient(145deg, var(--accent), var(--accent-2)); box-shadow: none; }
.switch.on .knob { transform: translateX(20px); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--safe-top) + 13px) max(16px, var(--safe-right)) 13px max(16px, var(--safe-left));
  background: rgba(9,18,16,0.82); backdrop-filter: blur(16px) saturate(1.3);
  border-bottom: 1px solid var(--line-soft);
}
.trip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.trip-name { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 13px 8px 11px; font-size: 13px; font-weight: 700;
}
.chip .chip-ico { display: grid; place-items: center; color: var(--accent); }
.chip .chip-ico svg { width: 16px; height: 16px; }
.chip.off { color: var(--muted); }
.chip.off .chip-ico { color: var(--muted-2); }
.icon-btn {
  background: var(--surface-3); border: 1px solid var(--line); color: var(--fg);
  border-radius: 11px; width: 40px; height: 40px; display: grid; place-items: center;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.ghost { background: transparent; }

.view { flex: 1; padding: 18px max(16px, var(--safe-right)) calc(var(--tabbar-h) + var(--safe-bottom) + 20px) max(16px, var(--safe-left)); }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.view-head h2 { font-size: 22px; }
.count { color: var(--muted); font-size: 13px; font-weight: 600; }

/* ===== List / cards ===== */
.list { display: flex; flex-direction: column; gap: 11px; }
.card {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 15px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
}
.avatar {
  width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center;
  flex-shrink: 0; font-weight: 800; font-size: 16px; color: #06201b; position: relative;
  letter-spacing: -0.02em;
}
.avatar .dot {
  position: absolute; right: -3px; bottom: -3px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted-2); border: 3px solid var(--surface);
}
.avatar .dot.on { background: var(--online); }
.who { flex: 1; min-width: 0; }
.who .name { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em; }
.who .name .you { font-size: 10px; color: var(--accent-ink); background: var(--accent); padding: 2px 7px; border-radius: 999px; font-weight: 800; letter-spacing: 0.02em; }
.who .meta { color: var(--muted); font-size: 13px; margin-top: 3px; display: flex; gap: 11px; flex-wrap: wrap; align-items: center; }
.who .meta b { color: var(--fg); font-weight: 700; }
.who .meta .mi { display: inline-flex; align-items: center; gap: 4px; }
.who .meta .mi svg { width: 13px; height: 13px; color: var(--muted-2); }
.card-actions { display: flex; gap: 9px; flex-shrink: 0; }
.round {
  width: 42px; height: 42px; border-radius: 13px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--fg); display: grid; place-items: center;
}
.round svg { width: 19px; height: 19px; }
.round.call { color: var(--online); }
.round.talk { color: var(--amber); }
.round.subtle { background: transparent; border-color: var(--line-soft); color: var(--muted); width: 38px; height: 38px; border-radius: 11px; }
.round:active { transform: scale(0.94); }
.dist-pill {
  font-size: 12px; font-weight: 800; color: var(--accent);
  background: rgba(31,209,166,0.12); border-radius: 999px; padding: 4px 10px; white-space: nowrap;
}
.empty { text-align: center; color: var(--muted); padding: 48px 20px; font-size: 14px; line-height: 1.65; }
.empty .ei { display: grid; place-items: center; margin: 0 auto 12px; width: 52px; height: 52px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line-soft); color: var(--muted-2); }
.empty .ei svg { width: 24px; height: 24px; }

/* ===== Place cards ===== */
.place-card { align-items: stretch; }
.place-main { flex: 1; min-width: 0; }
.place-top { display: flex; align-items: center; gap: 10px; }
.place-ico { width: 34px; height: 34px; border-radius: 11px; flex-shrink: 0; display: grid; place-items: center; background: rgba(246,178,75,0.14); color: var(--amber); }
.place-ico svg { width: 18px; height: 18px; }
.place-name { font-weight: 800; font-size: 16px; flex: 1; min-width: 0; letter-spacing: -0.01em; }
.place-when { display: inline-flex; align-items: center; gap: 6px; color: var(--amber); font-size: 13px; font-weight: 700; margin-top: 9px; }
.place-when svg { width: 14px; height: 14px; }
.place-note { color: var(--muted); font-size: 13px; margin-top: 7px; line-height: 1.5; }
.place-rows { margin-top: 13px; display: flex; flex-direction: column; gap: 9px; }
.prow { display: flex; align-items: center; gap: 10px; }
.pdot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.pname { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdist { font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.place-foot { display: flex; gap: 9px; margin-top: 13px; }
.place-foot .btn-row { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; background: var(--surface-2); color: var(--fg); border: 1px solid var(--line); border-radius: 11px; padding: 10px; font-size: 13px; font-weight: 700; }
.place-foot .btn-row svg { width: 16px; height: 16px; color: var(--accent); }
.place-foot .btn-row:active { transform: scale(0.98); }

/* ===== Map ===== */
#view-map { padding: 0; position: relative; }
#map { position: absolute; inset: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom)); }
.leaflet-container { background: #e9efed; font-family: inherit; }
.leaflet-control-zoom a { border-radius: 10px !important; color: #0e201d !important; }
.fab {
  position: absolute; right: calc(16px + var(--safe-right));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  width: 52px; height: 52px; border-radius: 16px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2)); color: var(--accent-ink);
  border: none; z-index: 500; display: grid; place-items: center; box-shadow: var(--shadow-lg);
}
.fab svg { width: 22px; height: 22px; }
.map-hint {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--safe-top) + 74px); z-index: 500;
  background: var(--amber); color: #3a2400; font-weight: 700; font-size: 13px;
  padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow-lg);
}
.map-pin-marker { filter: drop-shadow(0 3px 4px rgba(0,0,0,0.4)); }

/* ===== Talk ===== */
#view-talk { display: flex; flex-direction: column; }
.channel-row { display: flex; align-items: center; gap: 11px; margin-bottom: 16px; }
.channel-row > .muted { font-size: 13px; font-weight: 600; }
.channel-row select { flex: 1; }
.talk-status { text-align: center; color: var(--muted); font-size: 14px; font-weight: 600; min-height: 22px; margin-bottom: 8px; }
.talk-status.live { color: var(--amber); }
.ptt-wrap { display: grid; place-items: center; padding: 20px 0 28px; }
.ptt {
  position: relative; width: 196px; height: 196px; border-radius: 50%; border: none;
  background: radial-gradient(circle at 50% 36%, #1d3a34, #0e1f1b);
  color: #eaf3f1; box-shadow: inset 0 0 0 1.5px var(--line), inset 0 2px 20px rgba(0,0,0,0.4), 0 16px 40px -14px rgba(0,0,0,0.6);
  touch-action: none; user-select: none; -webkit-user-select: none; transition: transform 0.08s ease;
}
.ptt-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.ptt-ico { display: grid; place-items: center; }
.ptt-ico svg { width: 44px; height: 44px; color: var(--accent); }
.ptt-label { font-weight: 800; font-size: 13px; letter-spacing: 0.14em; }
.ptt .ptt-ring { position: absolute; inset: -7px; border-radius: 50%; border: 2.5px solid var(--accent); opacity: 0.35; }
.ptt.active { background: radial-gradient(circle at 50% 36%, #2b7363, #16453b); transform: scale(0.97); }
.ptt.active .ptt-ring { animation: pulse 1.15s ease-out infinite; border-color: var(--amber); opacity: 1; }
.ptt.active .ptt-ico svg { color: #fff; }
.ptt.receiving { background: radial-gradient(circle at 50% 36%, #51401a, #2c210b); }
.ptt.receiving .ptt-ring { border-color: var(--amber); animation: pulse 1.15s ease-out infinite; }
.ptt.receiving .ptt-ico svg { color: var(--amber); }
@keyframes pulse { 0% { transform: scale(1); opacity: 0.85; } 100% { transform: scale(1.2); opacity: 0; } }

.talk-log-head { font-size: 12px; color: var(--muted-2); font-weight: 700; margin: 4px 0 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.talk-log { display: flex; flex-direction: column; gap: 9px; }
.tl-item { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line-soft); border-radius: 14px; padding: 11px 13px; box-shadow: var(--shadow); }
.tl-item .who-s { flex: 1; min-width: 0; }
.tl-item .who-s .n { font-weight: 700; font-size: 14px; }
.tl-item .who-s .t { font-size: 12px; color: var(--muted); }
.tl-play { border: none; background: linear-gradient(145deg, var(--accent), var(--accent-2)); color: var(--accent-ink); width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; }
.tl-play svg { width: 16px; height: 16px; fill: currentColor; stroke: none; margin-left: 1px; }

/* ===== Sheets ===== */
.sheet { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,0.55); backdrop-filter: blur(3px); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel {
  width: 100%; max-width: 520px; background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: 26px 26px 0 0;
  padding: 20px max(18px, var(--safe-right)) calc(24px + var(--safe-bottom)) max(18px, var(--safe-left));
  display: flex; flex-direction: column; gap: 14px; max-height: 88vh; overflow-y: auto;
  animation: slideup 0.24s cubic-bezier(0.2,0.8,0.2,1); box-shadow: var(--shadow-lg);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h3 { font-size: 20px; }
.sheet hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.place-loc { display: flex; flex-direction: column; gap: 9px; }
.radio { flex-direction: row; align-items: center; gap: 10px; color: var(--fg); font-weight: 600; font-size: 14px; }
.radio input { width: auto; accent-color: var(--accent); }

/* ===== Tabbar ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  padding: 9px max(8px, var(--safe-right)) calc(8px + var(--safe-bottom)) max(8px, var(--safe-left));
  background: rgba(11,21,19,0.9); backdrop-filter: blur(18px) saturate(1.3); border-top: 1px solid var(--line-soft);
}
.tab { flex: 1; background: none; border: none; color: var(--muted-2); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0; }
.tab-ico { display: grid; place-items: center; width: 44px; height: 30px; border-radius: 11px; transition: background 0.18s, color 0.18s; }
.tab-ico svg { width: 23px; height: 23px; }
.tab-label { font-size: 11px; font-weight: 700; letter-spacing: 0.01em; }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { background: rgba(31,209,166,0.14); }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 20px); z-index: 200;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--fg); color: var(--bg); font-weight: 700; font-size: 13.5px;
  padding: 12px 18px; border-radius: 999px; box-shadow: var(--shadow-lg); max-width: 86%;
}

/* ===== Light theme ===== */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f6f5; --bg-grad: radial-gradient(130% 80% at 50% -8%, #e4efeb 0%, #f3f6f5 60%);
    --surface: #ffffff; --surface-2: #f7faf9; --surface-3: #eef3f1;
    --line: #dde6e3; --line-soft: #e7eeec; --fg: #0d1f1b; --muted: #5a7470; --muted-2: #8aa29c;
    --accent: #0fab8c; --accent-2: #0b9579; --accent-ink: #ffffff; --online: #16a85c;
    --shadow: 0 1px 2px rgba(16,40,34,0.06), 0 8px 24px -14px rgba(16,40,34,0.18);
    --shadow-lg: 0 16px 44px -16px rgba(16,40,34,0.28);
    color-scheme: light;
  }
  :root:not([data-theme="dark"]) .topbar { background: rgba(243,246,245,0.82); }
  :root:not([data-theme="dark"]) .tabbar { background: rgba(255,255,255,0.9); }
  :root:not([data-theme="dark"]) .avatar { color: #ffffff; }
  :root:not([data-theme="dark"]) .ptt { color: #eafaf6; }
  :root:not([data-theme="dark"]) .leaflet-container { background: #e9efed; }
}
