:root {
  --bg: #0b0d10; --card: #14181d; --card-high: #1b2026; --border: #242b33;
  --lime: #c6f04a; --on-lime: #10140a; --teal: #3ddbb5; --orange: #f5a524; --red: #f0524f;
  --text: #f2f4f5; --muted: #8f99a3;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; -webkit-tap-highlight-color: transparent; }
#map { position: fixed; inset: 0; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; max-width: 100%; color: var(--text); background: var(--card-high); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%; }
label { display: block; color: var(--muted); font-size: 14px; margin: 10px 0 0; }
label input, label select, label textarea { margin-top: 4px; }
input[type=range], input[type=checkbox] { padding: 0; border: 0; background: none; width: 100%; accent-color: var(--lime); }
input[type=checkbox] { width: auto; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }
a { color: var(--teal); }
h1, h2, h3 { margin: 0 0 8px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 22px; padding: 18px; }
.primary { background: var(--lime); color: var(--on-lime); border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 700; }
.primary.small { padding: 7px 12px; }
.ghost { background: transparent; border: 1px solid var(--border); border-radius: 12px; padding: 9px 14px; }
.link { background: none; border: 0; color: var(--teal); padding: 6px; }
.danger { color: var(--red); }
.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; font-size: 14px; }
.round { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--border); background: var(--card); font-size: 22px; display: grid; place-items: center; padding: 0; }
.round.filled { background: var(--lime); color: var(--on-lime); border: 0; }
.pill { background: rgba(20, 24, 29, .92); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: 15px; }
.tabs { display: flex; gap: 4px; background: var(--card-high); border-radius: 12px; padding: 4px; }
.tabs button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 6px; color: var(--muted); font-size: 14px; }
.tabs button.on { background: var(--card); color: var(--text); font-weight: 600; }
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 30; padding: 16px; }
.login-card { width: min(420px, 100%); }
.login-card h1 { color: var(--lime); }
.login-card .tabs { margin: 8px 0 4px; }
.login-card .primary { width: 100%; margin-top: 8px; }
.modal-card { width: min(560px, 100%); max-height: calc(100% - 32px); overflow: auto; position: relative; }
.close { position: absolute; top: 10px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 20px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + var(--safe-bottom)); z-index: 40; background: var(--card-high); border: 1px solid var(--border); border-radius: 14px; padding: 10px 16px; max-width: calc(100% - 32px); }
#attribution { position: fixed; right: 6px; bottom: 2px; z-index: 5; font-size: 11px; color: var(--muted); background: rgba(11, 13, 16, .7); padding: 1px 6px; border-radius: 6px; }
body.driving #attribution { bottom: calc(86px + var(--safe-bottom)); }

/* Drive */
#note-card { position: fixed; top: calc(10px + var(--safe-top)); left: 12px; right: 12px; z-index: 10; display: flex; gap: 14px; align-items: center; background: rgba(20, 24, 29, .95); border: 1px solid var(--border); border-radius: 22px; padding: 12px 16px; }
#note-glyph { width: 64px; height: 64px; flex: none; }
#note-text { font-size: 28px; font-weight: 800; }
#note-sub { color: var(--muted); font-size: 16px; }
#status-pill { position: fixed; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 9; }
#note-card:not(.hidden) ~ #status-pill { top: calc(112px + var(--safe-top)); }
.map-buttons { position: fixed; right: 12px; top: 40%; z-index: 10; display: flex; flex-direction: column; gap: 10px; }
#speed-row { position: fixed; left: 12px; right: 12px; bottom: calc(100px + var(--safe-bottom)); z-index: 10; display: flex; align-items: center; gap: 8px; }
#speed-block { background: rgba(20, 24, 29, .95); border: 1px solid var(--border); border-radius: 18px; padding: 6px 14px; text-align: center; min-width: 86px; }
#speed-now { font-size: 34px; font-weight: 800; line-height: 1; }
.unit { color: var(--muted); font-size: 12px; }
.sign { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 20px; background: var(--card); border: 4px solid var(--lime); }
.sign.legal { background: #fff; color: #111; border-color: var(--red); }
#road-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 28px 28px 0 0; padding: 12px 16px calc(14px + var(--safe-bottom)); }
#bottom-bar .titles { flex: 1; text-align: center; min-width: 0; }
#drive-title { color: var(--lime); font-weight: 800; font-size: 20px; }
#drive-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Sheet (navigation, checkpoint creation) */
.sheet { position: fixed; left: 12px; right: 12px; bottom: calc(96px + var(--safe-bottom)); z-index: 20; background: var(--card); border: 1px solid var(--border); border-radius: 22px; padding: 16px; max-height: 60vh; overflow: auto; }
body.home .sheet { left: auto; right: 16px; bottom: 16px; width: 380px; }
.sheet .row { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { border: 1px solid var(--border); background: var(--card-high); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip.on { background: var(--lime); color: var(--on-lime); border-color: var(--lime); font-weight: 600; }

/* Home */
#sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 380px; z-index: 10; background: var(--bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: calc(12px + var(--safe-top)) 14px 14px; gap: 10px; }
#sidebar header { display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 800; font-size: 22px; color: var(--lime); }
.panel { overflow-y: auto; overflow-x: hidden; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.sidebar-toggle { position: fixed; top: calc(12px + var(--safe-top)); left: 12px; z-index: 11; display: none; }
body.home.side-closed #sidebar { display: none; }
body.home .map-buttons { top: auto; bottom: 30px; }
@media (max-width: 760px) {
  #sidebar { width: 100%; top: auto; height: 55%; border-right: 0; border-top: 1px solid var(--border); border-radius: 22px 22px 0 0; }
  .sidebar-toggle { display: grid; }
  body.home .sheet { left: 12px; right: 12px; width: auto; bottom: calc(56% + 8px); }
}
.item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; background: var(--card); border: 1px solid var(--border); }
.item.click { cursor: pointer; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: 13px; }
.live { color: var(--lime); font-size: 13px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: var(--on-lime); background: linear-gradient(135deg, var(--lime), var(--teal)); flex: none; }
.avatar.big { width: 72px; height: 72px; font-size: 26px; }
.section-title { font-weight: 700; margin-top: 6px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.stat { background: var(--card-high); border-radius: 16px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }
table.board { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.board td { padding: 7px 6px; border-bottom: 1px solid var(--border); }
table.board td.num { text-align: right; font-weight: 700; }
table.board tr.me td { color: var(--lime); }

/* Friends' speech bubbles */
/* Sized to its content (name, speed, emoji); the marker already positions it absolutely. */
.bubble { width: max-content; background: rgba(20, 24, 29, .96); border: 1px solid var(--border); border-radius: 12px; padding: 3px 8px; max-width: 170px; box-shadow: 0 4px 16px rgba(0, 0, 0, .45); font-size: 12px; color: var(--muted); cursor: pointer; }
.bubble.open { max-width: 220px; border-radius: 14px; padding: 7px 10px 5px; z-index: 2; }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%); border: 7px solid transparent; border-bottom: 0; border-top-color: rgba(20, 24, 29, .96); }
.bubble-head { display: flex; gap: 6px; align-items: baseline; font-size: 14px; color: var(--text); white-space: nowrap; }
.bubble-head b { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bubble-speed { flex: none; color: var(--lime); font-weight: 700; }
.bubble-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubble-btn { background: none; border: 0; color: var(--lime); font-weight: 600; font-size: 13px; padding: 3px 0 1px; }

/* Map popups */
.maplibregl-popup-content { background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 12px 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .5); }
.maplibregl-popup-tip { border-top-color: var(--card) !important; border-bottom-color: var(--card) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; right: 4px; top: 2px; }
.friend-pop { min-width: 210px; }
.friend-pop .head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.friend-pop .head .avatar { width: 34px; height: 34px; font-size: 13px; }
.friend-pop .primary { margin-top: 8px; width: 100%; }
