:root {
  --bg: #0e0f11;
  --surface: #17191c;
  --surface-2: #202328;
  --line: #2c3036;
  --fg: #f1f2f4;
  --muted: #9aa0a8;
  --primary: #ff7a1a;
  --primary-ink: #160b02;
  --ok: #2ecc71;
  --warn: #f5c518;
  --bad: #ff4d5e;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 16px/1.45 "Inter", system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); }
.ok { color: var(--ok); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 8px; }

/* ---------- controls ---------- */
input, select { font: inherit; font-size: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); width: 100%; outline: none; transition: border-color .15s; }
input:focus, select:focus { border-color: var(--primary); }
input[type="range"] { padding: 0; accent-color: var(--primary); border: 0; background: transparent; }
input[type="checkbox"] { width: auto; accent-color: var(--primary); }
button { font: inherit; font-size: 15px; font-weight: 600; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); cursor: pointer; transition: transform .08s, background .15s, border-color .15s; }
button:hover:not(:disabled) { border-color: #3d424a; background: #262a30; }
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.35; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
button.primary:hover:not(:disabled) { background: #ff8c3a; border-color: #ff8c3a; }
button.big { min-height: 58px; font-size: 18px; font-weight: 700; }
button.warn { background: var(--warn); border-color: var(--warn); color: #1a1400; }
button.muted { background: var(--bad); border-color: var(--bad); color: #fff; }
button.round { width: 62px; height: 62px; border-radius: 50%; font-size: 24px; padding: 0; flex: none; }
button.link { background: none; border: 0; color: var(--muted); font-weight: 500; text-decoration: underline; }
button.icon { background: none; border: 0; padding: 6px 8px; color: var(--muted); font-size: 15px; }
button.icon:hover { color: var(--fg); background: var(--surface-2); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > button { flex: 1; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; font-weight: 500; }
label.inline { flex-direction: row; align-items: center; gap: 8px; flex: 1; white-space: nowrap; }
label.inline input, label.inline select { padding: 8px 10px; }

/* ---------- login / home ---------- */
#login, #home { display: grid; place-items: center; padding: 20px 16px; overflow-y: auto; background: radial-gradient(1200px 600px at 20% -10%, #2a1606 0%, transparent 60%), var(--bg); }
.card { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; }
.card.center { text-align: center; margin: auto; padding: 24px 16px; }
#ride > .card.center { position: absolute; inset: 0; justify-content: center; max-width: 440px; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.brand .logo { font-size: 34px; }
.brand h1 { font-size: 28px; font-weight: 800; }
.brand .who { margin-left: auto; color: var(--muted); }
.join input { flex: 1; text-transform: uppercase; letter-spacing: 4px; font-weight: 700; min-height: 58px; min-width: 0; }
.join button { flex: none; }
.sessions { display: flex; flex-direction: column; gap: 8px; }
.session { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 14px 16px; }
.session .muted { font-size: 13px; font-weight: 500; }

/* ---------- toasts & modals ---------- */
#toasts { position: fixed; left: 50%; top: max(14px, env(safe-area-inset-top)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; pointer-events: none; width: min(92vw, 420px); }
.toast { background: #24272c; border: 1px solid var(--line); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; animation: in .2s ease-out; transition: opacity .4s, transform .4s; }
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes in { from { opacity: 0; transform: translateY(-8px); } }
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; z-index: 40; padding: 16px; backdrop-filter: blur(3px); }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; width: min(440px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.modal h3 { color: var(--fg); text-transform: none; letter-spacing: 0; font-size: 19px; margin: 0; }
.modal .code { font-size: 42px; font-weight: 800; letter-spacing: 8px; text-align: center; margin: 4px 0; color: var(--primary); }

/* ---------- planner ---------- */
#plan-map, #map { position: absolute; inset: 0; }
.sheet { position: absolute; z-index: 5; background: var(--surface); display: flex; flex-direction: column; box-shadow: var(--shadow); }
@media (min-width: 900px) {
  .sheet { top: 12px; left: 12px; bottom: 12px; width: 400px; border-radius: 18px; border: 1px solid var(--line); }
  .sheet-handle { display: none !important; }
  .legend { left: 424px !important; }
}
@media (max-width: 899px) {
  .sheet { left: 0; right: 0; bottom: 0; height: 42vh; border-radius: 18px 18px 0 0; border-top: 1px solid var(--line); transition: height .25s ease; padding-bottom: env(safe-area-inset-bottom); }
  .sheet.expanded { height: 82vh; }
  .legend { bottom: calc(42vh + 8px) !important; }
}
.sheet-handle { display: grid; place-items: center; padding: 8px 0 2px; cursor: pointer; }
.sheet-handle span { width: 44px; height: 5px; border-radius: 3px; background: #444a52; }
.tabs { display: flex; gap: 4px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: 0; border-bottom: 3px solid transparent; border-radius: 0; color: var(--muted); padding: 10px 6px 12px; }
.tab.active { color: var(--fg); border-bottom-color: var(--primary); }
.tab:hover:not(.active) { background: none; color: var(--fg); }
.tab-home { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 6px 10px; }
.pane { flex: 1; overflow-y: auto; padding: 12px 14px 18px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.hint { color: var(--muted); font-size: 13.5px; margin: 0; }
.label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.group { display: flex; flex-direction: column; gap: 6px; }
.group.row { flex-direction: row; }
.group.chips { flex-direction: row; flex-wrap: wrap; gap: 6px; }

.searchbox { position: relative; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 6px; list-style: none; background: #1d2024; border: 1px solid var(--line); border-radius: 12px; z-index: 20; box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; }
.suggest li { padding: 10px 12px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.suggest li.active, .suggest li:hover { background: var(--surface-2); }
.suggest .ico { width: 20px; text-align: center; color: var(--primary); }
.picked { font-size: 14px; padding: 2px 4px; }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; color: var(--muted); padding: 9px 6px; border-radius: 9px; font-size: 14px; }
.seg button.active { background: var(--primary); color: var(--primary-ink); }
.seg button:hover:not(.active) { background: #2a2e34; color: var(--fg); }
.chip { flex-direction: row; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; color: var(--fg); font-size: 13.5px; cursor: pointer; user-select: none; }
.chip.locked { color: var(--muted); cursor: default; }

.wp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.wp-item { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-radius: 10px; }
.wp-item:hover { background: var(--surface-2); }
.wp-item.via { padding-left: 16px; }
.wp-item .drag { color: #555b63; cursor: grab; padding: 0 2px; letter-spacing: -2px; user-select: none; touch-action: none; }
.wp-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; font-size: 14.5px; }
.wp-name small { color: var(--muted); font-weight: 500; }
.sortable-ghost { opacity: 0.4; }

.toolbar { display: flex; gap: 6px; }
.tool { flex: 1; font-size: 18px; padding: 8px 0; }

/* waypoint markers on the map and in the list */
.wp { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #111; background: #fff; border: 3px solid var(--primary); box-shadow: 0 2px 8px rgba(0,0,0,.6); cursor: grab; }
.wp-start { background: var(--ok); border-color: #fff; }
.wp-end { background: var(--bad); border-color: #fff; color: #fff; }
.wp-via { width: 16px; height: 16px; border-width: 3px; background: #fff; border-color: #444; }
.wp.small { width: 24px; height: 24px; font-size: 11px; flex: none; cursor: default; box-shadow: none; }
.wp-via.small { width: 14px; height: 14px; margin: 0 5px; }
.wp.ghost { opacity: .8; pointer-events: none; }

.alts { display: flex; gap: 6px; overflow-x: auto; }
.alts:empty { display: none; }
.alt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 120px; padding: 8px 10px; font-size: 13px; font-weight: 500; }
.alt.active { border-color: var(--primary); }
.twist { color: var(--primary); letter-spacing: 1px; font-size: 12px; }

#stats { display: flex; flex-direction: column; gap: 8px; transition: opacity .2s; }
#stats.loading { opacity: .45; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px 8px; text-align: center; }
.kpi .v { font-size: 18px; font-weight: 800; white-space: nowrap; }
.kpi .l { font-size: 11px; color: var(--muted); font-weight: 600; }
.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--surface-2); }
details { background: var(--surface-2); border-radius: 12px; padding: 4px 12px; }
details summary { cursor: pointer; padding: 8px 0; font-weight: 600; font-size: 14px; }
details ul, details ol { margin: 0 0 8px; padding-left: 20px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
details li { cursor: pointer; }
details li:hover { color: var(--primary); }
details li small { color: var(--muted); }
.dubious summary { color: var(--warn); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .primary { grid-column: 1 / -1; min-height: 52px; font-size: 16px; }

.sug-list { display: flex; flex-direction: column; gap: 8px; }
.sug { border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; background: var(--surface-2); }
.sug.active { border-color: var(--c); box-shadow: 0 0 0 1px var(--c); }
.sug-title { font-weight: 700; }
.sug-meta { font-size: 13.5px; color: var(--muted); }
.sug button { align-self: flex-start; padding: 8px 14px; }
button.big.primary#btn-discover { min-height: 52px; }

.lib-list { display: flex; flex-direction: column; gap: 6px; }
.lib-item { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 12px; padding: 10px 8px 10px 14px; }
.lib-main { flex: 1; cursor: pointer; min-width: 0; }
.lib-main b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ctxmenu { position: fixed; z-index: 30; background: #1d2024; border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: flex; flex-direction: column; min-width: 230px; box-shadow: var(--shadow); }
.ctxmenu button { background: none; border: 0; text-align: left; font-weight: 500; padding: 11px 12px; }
.ctxmenu button:hover { background: var(--surface-2); }

.legend { position: absolute; left: 12px; bottom: 30px; z-index: 4; display: flex; align-items: center; gap: 8px; font-size: 11.5px; font-weight: 600; color: #ddd; background: rgba(14, 15, 17, .82); padding: 6px 10px; border-radius: 10px; pointer-events: none; }
.legend-bar { width: 90px; height: 6px; border-radius: 3px; }
.legend-dub::before { content: ""; display: inline-block; width: 16px; height: 4px; margin-right: 5px; vertical-align: middle; background: repeating-linear-gradient(90deg, #ffe14d 0 4px, transparent 4px 8px); }

.maplibregl-ctrl-group { background: var(--surface) !important; border: 1px solid var(--line); }
.maplibregl-ctrl-group button { background: none; border: 0; border-radius: 0; color: var(--fg); padding: 0; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line); }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
.style-btn { font-size: 17px; }
.style-ctrl { position: relative; }
.style-menu { position: absolute; right: calc(100% + 8px); top: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px; display: grid; grid-template-columns: repeat(5, 64px); gap: 6px; box-shadow: var(--shadow); }
.style-menu button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px; font-size: 11.5px; font-weight: 600; background: none; border: 2px solid transparent; border-radius: 10px; color: var(--fg); }
.style-menu button.active { border-color: var(--primary); }
.style-menu .swatch { width: 48px; height: 48px; border-radius: 8px; border: 1px solid #0006; }
.swatch-satellite, .swatch-hybrid { background-image: url("https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/12/1563/2042") !important; background-size: cover; }
.swatch-hybrid { box-shadow: inset 0 0 0 100px #0000, inset 0 -14px 0 -10px #ffd54a; }
@media (max-width: 600px) { .style-menu { grid-template-columns: repeat(3, 64px); } }
.maplibregl-ctrl-scale { background: rgba(14,15,17,.7) !important; color: #ddd !important; border-color: #ddd !important; }

/* ---------- ride ---------- */
.topbar { position: absolute; z-index: 3; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 60px; display: flex; gap: 8px; flex-wrap: wrap; }
.pill { padding: 8px 14px; border-radius: 999px; background: rgba(14,15,17,.85); font-weight: 700; font-size: 14px; border: 1px solid var(--line); }
.pill.ok { background: var(--ok); color: #04210f; border-color: var(--ok); }
.pill.warn { background: var(--warn); color: #1a1400; border-color: var(--warn); }
.pill.bad { background: var(--bad); color: #fff; border-color: var(--bad); }
#people { position: absolute; z-index: 3; top: calc(max(10px, env(safe-area-inset-top)) + 48px); left: 10px; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
#people li { padding: 6px 12px; border-radius: 10px; background: rgba(14,15,17,.85); font-size: 15px; font-weight: 600; border-left: 5px solid #444; transition: border-color .15s; }
#people li.speaking { border-left-color: var(--ok); box-shadow: 0 0 0 1px var(--ok); }
#people li.gone { opacity: .5; }
#btn-audio { position: absolute; z-index: 4; left: 16px; right: 16px; top: 40%; }
.bottombar { position: absolute; z-index: 3; bottom: max(16px, env(safe-area-inset-bottom)); left: 12px; right: 12px; display: flex; gap: 12px; align-items: center; }
.bottombar #btn-mute { flex: 1; min-height: 78px; font-size: 20px; border-radius: 20px; }
.rider { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); border: 3px solid #fff; color: var(--primary-ink); font-weight: 800; display: grid; place-items: center; font-size: 13px; box-shadow: 0 2px 8px #000; transition: opacity .3s; }
.rider.me { background: #3b8cff; color: #fff; }
.rider.stale { opacity: .4; }

/* ---------- planner extras: elevation, POIs, fuel ---------- */
.link.compare { align-self: flex-start; padding: 0; font-size: 13.5px; margin-top: -4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
button.chip { font-weight: 500; }
button.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
label.inline.small { font-size: 13px; }
label.inline.small select { width: auto; }
.elev { background: var(--surface-2); border-radius: 12px; padding: 8px 8px 4px; }
.elev-svg { width: 100%; height: auto; display: block; touch-action: none; cursor: crosshair; }
.elev-svg text { fill: var(--muted); font-size: 9px; font-family: inherit; }
.elev-svg .grid { stroke: #ffffff14; }
.elev-svg .cursor { stroke: #fff; stroke-width: 1; }
.elev-svg .cursor-dot { fill: #fff; }
.elev-svg .hidden { display: none; }
.elev-label { font-size: 11.5px; color: var(--muted); text-align: right; padding: 0 2px; }
.elev-cursor { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 4px solid var(--primary); box-shadow: 0 0 8px #000; pointer-events: none; }
.warn-box { border: 1px solid var(--warn); background: #f5c51814; border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.warn-box b { color: var(--warn); }
.poi-list { display: flex; flex-direction: column; gap: 2px; max-height: 280px; overflow-y: auto; }
.poi { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.poi:hover { background: var(--surface-2); }
.poi-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poi-name small { color: var(--muted); }
.maplibregl-popup-content { background: var(--surface); color: var(--fg); border-radius: 12px; border: 1px solid var(--line); padding: 12px 14px; box-shadow: var(--shadow); }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 0 6px; }
.poi-pop { display: flex; flex-direction: column; gap: 6px; }

/* Group switcher on the home card */
.group-bar { display: flex; gap: 8px; align-items: center; }
.group-bar select { flex: 1; min-width: 0; font-weight: 600; }
.group-key { font: 700 26px/1.2 ui-monospace, Consolas, monospace; letter-spacing: 2px; text-align: center; padding: 12px; border-radius: 12px; background: var(--surface-2, #222); user-select: all; }

/* Ride: quick alerts and push-to-talk */
.alerts { position: absolute; right: 12px; top: 64px; display: flex; flex-direction: column; gap: 6px; z-index: 3; }
.alert-btn { display: flex; align-items: center; gap: 6px; padding: 8px 12px; font-size: 13px; background: rgba(23, 25, 28, 0.92); }
.alert-btn span { font-size: 18px; }
.alert-btn.sos { border-color: var(--bad); color: var(--bad); }
#btn-mode.on { background: var(--primary); color: var(--primary-ink); }
#btn-mute { touch-action: none; user-select: none; }
.alert-pin { font-size: 28px; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)); }

/* Planner: secondary options collapsed by default */
details.options > summary { list-style: none; cursor: pointer; display: flex; flex-direction: column; gap: 2px; padding: 4px 0; }
details.options > summary::-webkit-details-marker { display: none; }
details.options > summary .label::after { content: " ▸"; color: var(--muted); }
details.options[open] > summary .label::after { content: " ▾"; }
details.options > summary .muted { font-size: 12.5px; }
details.options[open] > summary .muted { display: none; }
details.options > .chips, details.options > .row { margin-top: 10px; }

/* Group members list */
.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow: auto; }
.members li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.members .row { gap: 6px; }
.modal h4 { margin: 14px 0 6px; }

.repeat-warn { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(245, 197, 24, 0.12); border: 1px solid rgba(245, 197, 24, 0.35); font-size: 13.5px; }

/* Group chat */
.chat-panel { position: fixed; z-index: 50; right: 16px; bottom: 16px; width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100vh - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; padding: 12px; gap: 8px; }
.chat-head { display: flex; align-items: center; justify-content: space-between; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.bubble { align-self: flex-start; max-width: 85%; background: var(--surface-2); border-radius: 14px; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble b { display: block; color: var(--accent, #ff7a1a); font-size: 13px; }
.bubble.mine { align-self: flex-end; background: #ff7a1a; color: #000; }
.bubble .time { display: block; text-align: right; font-size: 11px; opacity: .6; }
.chat-send { display: flex; gap: 8px; }
.chat-send textarea { flex: 1; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); resize: none; }
