:root {
  --bg: var(--tg-theme-bg-color, #15171c);
  --bg2: var(--tg-theme-secondary-bg-color, #0e1014);
  --card: var(--tg-theme-section-bg-color, #1d2027);
  --text: var(--tg-theme-text-color, #f2f3f5);
  --hint: var(--tg-theme-hint-color, #8b919c);
  --link: var(--tg-theme-link-color, #ff7a1a);
  --accent: #ff6a00;
  --accent-text: #fff;
  --danger: var(--tg-theme-destructive-text-color, #ff4d4f);
  --ok: #2fbf71;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid transparent;
  border-radius: 10px; padding: 10px 12px; width: 100%; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.hidden { display: none !important; }
.page { padding: 12px 16px calc(96px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; }
h1 { font-size: 24px; margin: 6px 0 2px; letter-spacing: -0.3px; }
h2 { font-size: 17px; margin: 18px 0 8px; }
.sub { color: var(--hint); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.card.tap:active { opacity: .75; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--bg2); color: var(--hint); text-transform: uppercase; letter-spacing: .3px; }
.badge.open { color: var(--accent); }
.badge.planned { color: #4ea4ff; }
.badge.riding { background: var(--ok); color: #fff; }
.btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; padding: 13px 16px;
  border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.secondary { background: var(--card); color: var(--text); }
.btn.ghost { background: transparent; color: var(--link); padding: 8px; }
.btn.small { width: auto; padding: 8px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.tabs { display: flex; background: var(--card); border-radius: 12px; padding: 3px; margin: 12px 0; }
.tabs button { flex: 1; padding: 8px; border-radius: 10px; color: var(--hint); font-weight: 600; }
.tabs button.on { background: var(--accent); color: #fff; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 12px; border-radius: 999px; background: var(--card); font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent); color: #fff; }
.field { margin: 12px 0; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; }
.avatars { display: flex; flex-wrap: wrap; gap: 8px; }
.rider { display: flex; align-items: center; gap: 6px; background: var(--bg2); border-radius: 999px; padding: 4px 10px 4px 4px; font-size: 14px; }
.ava { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  color: #fff; background: #555; object-fit: cover; flex: none; }
.vote-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vote { background: var(--card); border-radius: var(--radius); padding: 12px; text-align: left; border: 2px solid transparent; }
.vote.on { border-color: var(--accent); }
.vote .ico { font-size: 24px; }
.vote .t { font-weight: 600; margin-top: 4px; }
.vote .n { color: var(--hint); font-size: 12px; }
.stops { counter-reset: s; margin: 0; padding: 0; list-style: none; }
.stops li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--bg2); align-items: center; }
.stops li:last-child { border: 0; }
.stops .num { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px;
  font-weight: 700; display: grid; place-items: center; flex: none; }
.stops .num.done { background: var(--ok); }
.stops .num.via { background: var(--hint); }
.map { height: 260px; border-radius: var(--radius); overflow: hidden; background: var(--card); margin: 10px 0; }
.place { display: flex; gap: 12px; align-items: center; }
.place img, .place .noimg { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; background: var(--bg2); }
.place .name { font-weight: 600; }
.empty { text-align: center; color: var(--hint); padding: 40px 10px; }

/* нижний лист */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; background: var(--bg); border-radius: 18px 18px 0 0;
  max-height: 86vh; overflow-y: auto; padding: 8px 16px calc(20px + var(--safe-bottom)); box-shadow: 0 -10px 30px rgba(0,0,0,.3);
  animation: up .2s ease-out; max-width: 640px; margin: 0 auto; }
#sheet .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--hint); opacity: .4; margin: 0 auto 10px; }
#sheet .hero { width: 100%; max-height: 240px; object-fit: cover; border-radius: var(--radius); }
@keyframes up { from { transform: translateY(40px); opacity: 0 } }
#toast { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 16px; right: 16px; z-index: 80; background: #222a;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); color: #fff; padding: 12px 14px; border-radius: 12px;
  font-weight: 600; text-align: center; max-width: 600px; margin: 0 auto; }

/* режим навигации */
.nav { position: fixed; inset: 0; background: var(--bg2); }
.nav #navmap { position: absolute; inset: 0; }
.nav .top { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  left: 10px; right: 10px; display: flex; gap: 8px; z-index: 5; }
.glass { background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.nav .next { flex: 1; padding: 10px 12px; min-width: 0; }
.nav .next .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav .iconbtn { width: 48px; height: 48px; display: grid; place-items: center; font-size: 20px; flex: none; }
.nav .side { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 5; }
.nav .bottom { position: absolute; left: 10px; right: 10px; bottom: calc(12px + var(--safe-bottom)); z-index: 5; display: flex; gap: 8px; align-items: stretch; }
.nav .speed { padding: 8px 14px; text-align: center; min-width: 76px; }
.nav .speed b { font-size: 26px; display: block; line-height: 1; }
.nav .speed span { font-size: 11px; color: var(--hint); }
.nav .alert { position: absolute; top: calc(76px + env(safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)); left: 10px; right: 10px;
  z-index: 6; background: var(--danger); color: #fff; padding: 12px 14px; border-radius: 14px; font-weight: 700; font-size: 17px;
  display: flex; gap: 10px; align-items: center; box-shadow: 0 6px 20px rgba(255,0,0,.3); }
.crosshair { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -44px 0 0 -22px; z-index: 4;
  font-size: 40px; line-height: 44px; text-align: center; pointer-events: none; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }
.signal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* рейтинг и друзья */
.lbrow { gap: 10px; padding: 10px 14px; margin: 6px 0; }
.lbrow .rank { width: 28px; text-align: center; font-size: 16px; flex: none; }
.lbrow.me { box-shadow: 0 0 0 2px var(--accent) inset; }
.tabs button { font-size: 14px; padding: 8px 4px; }
textarea { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid transparent; border-radius: 10px;
  padding: 10px 12px; width: 100%; outline: none; resize: vertical; }
textarea:focus { border-color: var(--accent); }

/* метки на карте (MapLibre) */
.mk { cursor: pointer; user-select: none; }
.mk-stop { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font: 700 13px/28px sans-serif;
  text-align: center; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.mk-stop.done { background: var(--ok); }
.mk-start { background: #111; color: #fff; font: 700 12px/1 sans-serif; padding: 6px 8px; border-radius: 8px; border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.35); position: relative; margin-bottom: 6px; }
.mk-start::after { content: ""; position: absolute; left: 50%; bottom: -8px; margin-left: -6px; border: 6px solid transparent; border-top-color: #111; }
.mk-pin { font-size: 34px; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.mk-me { width: 22px; height: 22px; border-radius: 50%; background: #2f80ff; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(47,128,255,.25); position: relative; }
.mk-me.has-heading i { position: absolute; left: 50%; top: 50%; width: 0; height: 0; margin: -22px 0 0 -7px; border: 7px solid transparent;
  border-bottom: 12px solid #2f80ff; transform-origin: 7px 22px; transform: rotate(var(--hd, 0deg)); }
.mk-rider { display: flex; align-items: center; gap: 4px; }
.mk-rider b { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); flex: none; }
.mk-rider span { background: rgba(0,0,0,.7); color: #fff; font: 600 12px/1 sans-serif; padding: 3px 6px; border-radius: 6px; white-space: nowrap; }
.maplibregl-ctrl-attrib { font-size: 10px; }
