:root {
  --bg: #0d1114;
  --surface: #161c21;
  --surface-2: #1f272e;
  --line: #2b353d;
  --text: #edf1f3;
  --muted: #95a1ab;
  --accent: #ffb020;
  --accent-ink: #1c1300;
  --go: #3ddc84;
  --stop: #ff5a5c;
  /* Saira and Barlow have no Cyrillic: Fira fills in for local (Macedonian) names. */
  --display: 'Saira Condensed', 'Fira Sans Extra Condensed', 'Arial Narrow', sans-serif;
  --body: 'Barlow', 'Fira Sans', system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
  --edge: 12px;
  --dock-h: 68px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 16px/1.45 var(--body); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input {
  font: inherit; color: var(--text); width: 100%; margin-top: 6px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 13px 14px; outline: none;
}
input:focus { border-color: var(--accent); }
h1, h2, h3 { margin: 0; font-family: var(--display); font-weight: 800; letter-spacing: 0.01em; line-height: 1.05; }
h1 { font-size: 40px; text-transform: uppercase; }
h2 { font-size: 26px; text-transform: uppercase; }
h3 { font-size: 15px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
dl, dd { margin: 0; }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; font-weight: 700; }
.num small, dd small { font-family: var(--body); font-size: 0.5em; font-weight: 600; color: var(--muted); margin-left: 3px; }
.muted { color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); font-size: 14px; margin: 18px 0 0; }
.error { color: var(--stop); font-size: 14px; margin: 0; }
.error:empty { display: none; }
.warn { color: var(--accent); margin: 0 0 12px; }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.btn {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 50px; padding: 0 16px;
  border-radius: 12px; background: var(--surface-2); font-weight: 700; font-size: 16px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger, .link.danger { color: var(--stop); }
.btn:disabled { opacity: 0.5; }
.link { color: var(--muted); font-weight: 600; font-size: 15px; padding: 10px 0; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.actions + .link { display: block; margin: 6px auto 0; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface); border-radius: 12px; padding: 4px; }
.seg button { padding: 10px 0; border-radius: 9px; font-weight: 700; font-size: 15px; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--text); }
.seg.small button { padding: 7px 0; font-size: 14px; }
.sq { display: inline-block; width: 11px; height: 11px; border-radius: 2px; flex: none; }

/* ---------- the map is the app ---------- */
#map { position: fixed; inset: 0; background: #232a30; }

.player { width: 34px; height: 34px; }
.player svg { width: 100%; height: 100%; fill: #fff; stroke: var(--bg); stroke-width: 2.5; }
.player circle { display: none; fill: #4da3ff; stroke: #fff; stroke-width: 3; }
.player.still path { display: none; }
.player.still circle { display: block; }

.odo-popup .maplibregl-popup-content {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; font: 15px/1.35 var(--body); display: grid;
}
.odo-popup .maplibregl-popup-content span { color: var(--muted); font-size: 13px; }
.odo-popup .maplibregl-popup-tip { display: none; }

/* ---------- HUD on top of the map ---------- */
#hud {
  position: fixed; z-index: 20; top: calc(var(--safe-t) + var(--edge)); left: var(--edge); right: var(--edge);
  display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;
}
#hud > * > * { pointer-events: auto; }
.hud-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: 15px;
}
.hud-chip .num { font-size: 22px; }
.hud-chip:empty { display: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.go { background: var(--go); }
.dot.wait { background: var(--accent); }
.map-btns { display: flex; flex-direction: column; gap: 8px; }
.map-btns button {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
}
.map-btns button.on { color: var(--accent); border-color: var(--accent); }
.map-btns svg { width: 22px; height: 22px; }

/* ---------- dock: ranks | start | profile ---------- */
#dock {
  position: fixed; z-index: 40; left: var(--edge); right: var(--edge); bottom: var(--edge);
  max-width: 520px; margin: 0 auto; height: var(--dock-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
}
#dock[hidden] { display: none; }
#dock > a, .to-map {
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 6px 0;
}
#dock > a.on { color: var(--accent); }
#dock svg { width: 24px; height: 24px; }
.dock-mid { display: grid; place-items: center; min-width: 132px; }
.to-map { color: var(--text); padding: 6px 28px; }
.start {
  height: 52px; padding: 0 34px; border-radius: 13px; background: var(--accent); color: var(--accent-ink);
  font: 800 26px/1 var(--display); text-transform: uppercase; letter-spacing: 0.08em;
  transition: transform 0.12s ease-out;
}
.start:active { transform: scale(0.96); }

/* ---------- side panels ---------- */
.panel {
  position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
  padding: calc(var(--safe-t) + 22px) 0 calc(var(--safe-b) + var(--dock-h) + 40px);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0.28s;
  visibility: hidden;
}
.panel.left { transform: translateX(-100%); }
.panel.right { transform: translateX(100%); }
.panel.open { transform: none; visibility: visible; }
.panel-inner { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.panel h1 { margin-bottom: 18px; }
.panel h2 { margin: 34px 0 12px; display: flex; align-items: baseline; justify-content: space-between; }
.panel h2 .muted { font: 600 15px var(--body); text-transform: none; }
.panel h3 { margin: 22px 0 4px; }
.panel .seg + .seg { margin-top: 10px; }

.board { list-style: none; margin: 16px 0 0; padding: 0; }
.board li { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line); }
.board li.muted { display: block; text-align: center; padding: 40px 0; border: 0; }
.board .r { font-size: 22px; color: var(--muted); text-align: center; }
.board .p1 .r { color: #ffcf4d; } .board .p2 .r { color: #c9d1db; } .board .p3 .r { color: #d9965b; }
.board .me { background: var(--surface); border-radius: 10px; border-bottom-color: transparent; }
.board .who { display: grid; min-width: 0; }
.board .n { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.board .who .muted { font-size: 14px; }
.board .score { font-size: 24px; text-align: right; }

.profile-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.profile-head h1 { margin: 0 0 2px; }
.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border-radius: 14px; overflow: hidden; }
.totals > div { background: var(--surface); padding: 12px 10px; }
.totals dt, .stats dt, .strip dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.totals dd { font-size: 24px; }

.acts { list-style: none; margin: 0; padding: 0; }
.acts > li { border-bottom: 1px solid var(--line); }
.acts > li.muted { border: 0; padding: 24px 0; text-align: center; }
.acts .row { display: grid; grid-template-columns: 58px 1fr auto; gap: 12px; align-items: center; padding: 12px 2px; }
.acts .t { display: grid; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.acts .t .muted { font-size: 14px; }
.acts .score { font-size: 22px; text-align: right; }
.acts .pending { opacity: 0.7; }
.gain { color: var(--accent); }
.kind { font: 700 13px/1 var(--display); text-transform: uppercase; letter-spacing: 0.08em; }
.kind.walk { color: var(--go); } .kind.run { color: #ff7aa2; } .kind.drive { color: var(--accent); }

.achievements { list-style: none; margin: 0; padding: 0; }
.achievements li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.achievements li:not(.got) .ach-name { color: var(--muted); }
.ach-top, .ach-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.ach-name { font: 700 19px var(--display); text-transform: uppercase; letter-spacing: 0.03em; }
.ach-foot { font-size: 14px; margin-top: 6px; }
.ach-foot .num { flex: none; }
.bar { height: 5px; border-radius: 3px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }
.pips { display: flex; gap: 5px; }
.pips i { width: 9px; height: 9px; transform: rotate(45deg); background: var(--surface-2); border: 1px solid var(--line); }
.pips i.on { background: var(--accent); border-color: var(--accent); }

/* ---------- bottom sheet: live HUD, finish, review ---------- */
#sheet {
  position: fixed; z-index: 25; left: var(--edge); right: var(--edge); bottom: var(--edge);
  max-width: 560px; margin: 0 auto; max-height: 64dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px;
}
#sheet[hidden] { display: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { font-size: 30px; }
.icon-btn { width: 44px; height: 44px; margin: -6px -6px 0 0; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 10px; }
.stats dd { font-size: 26px; }
.field { display: block; margin-top: 16px; font-size: 14px; font-weight: 600; }
.place-img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; background: var(--surface-2); margin-bottom: 12px; }
.place-text { margin: 0 0 12px; max-width: 65ch; }
.facts { display: grid; gap: 8px; margin: 0 0 12px; }
.facts dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.facts dd { overflow-wrap: anywhere; }
.links { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 4px; }
.links a { color: var(--accent); font-weight: 600; padding: 8px 0; }
.setting { display: flex; align-items: center; gap: 16px; margin-top: 28px; padding: 14px; background: var(--surface); border-radius: 14px; }
.setting > div { display: grid; gap: 2px; flex: 1; }
.setting .muted { font-size: 14px; }
.setting .btn { width: auto; flex: none; min-height: 44px; }
.sub-h { margin: 16px 0 0; display: flex; justify-content: space-between; }
.sub-h .muted { text-transform: none; letter-spacing: 0; font: 500 14px var(--body); }
.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.hud-left .num { font-size: 20px; }
#challenges { gap: 6px; }
#challenges .muted + .num { margin-right: 6px; }
.season { margin: 14px 0 0; }
.crown { color: #ffcf4d; }
.podium { list-style: none; padding: 0; margin: 8px 0 0; }
.podium li { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; padding: 8px 4px; }
.podium .r { text-align: center; color: var(--muted); }
.credit { color: var(--muted); font-size: 13px; margin: 40px 0 0; }
.credit a { text-decoration: underline; }
.places-line { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; font-size: 14px; }
.tag { background: var(--surface-2); border-radius: 8px; padding: 5px 9px; font-weight: 600; }

.live-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.speed { display: flex; align-items: baseline; gap: 6px; }
.speed .num { font-size: 84px; font-weight: 800; line-height: 0.8; }
.speed .unit { font: 700 16px var(--display); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.trip { text-align: right; }
.trip .big { font-size: 36px; line-height: 1; }
.trip .muted { font-size: 14px; }
.strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.strip dd { font-size: 21px; }
#gpserr { margin-top: 10px; }
.hold {
  position: relative; overflow: hidden; width: 100%; height: 54px; margin-top: 14px; border-radius: 12px;
  background: var(--surface-2); color: var(--stop); font: 800 21px var(--display); text-transform: uppercase; letter-spacing: 0.08em;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.hold .fill { position: absolute; inset: 0; background: rgba(255, 90, 92, 0.24); transform-origin: left; transform: scaleX(0); }
.hold.holding .fill { transform: scaleX(1); transition: transform 1s linear; }
.hold .txt { position: relative; }

/* ---------- auth ---------- */
#auth { position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow-y: auto; }
#auth[hidden] { display: none; }
.auth { max-width: 400px; margin: 0 auto; min-height: 100%; padding: calc(var(--safe-t) + 48px) 20px 40px; display: flex; flex-direction: column; justify-content: center; }
.brand { font-size: 76px; color: var(--accent); letter-spacing: 0.02em; }
.lede { font-size: 18px; margin: 8px 0 28px; color: var(--muted); max-width: 30ch; }
.form { display: grid; gap: 14px; margin-top: 18px; }
.form label { font-size: 14px; font-weight: 600; }
.form label[hidden] { display: none; }

#toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 70px); z-index: 60; transform: translate(-50%, -20px); opacity: 0;
  background: var(--surface-2); border: 1px solid var(--line); padding: 11px 16px; border-radius: 12px;
  font-weight: 600; font-size: 15px; transition: transform 0.22s ease-out, opacity 0.22s; pointer-events: none;
  max-width: calc(100% - 32px); width: max-content;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* Phone sideways in a dash mount: the sheet becomes a right-hand column. */
@media (orientation: landscape) and (max-height: 560px) {
  #sheet { left: auto; top: calc(var(--safe-t) + var(--edge)); right: max(var(--edge), env(safe-area-inset-right)); width: 340px; max-height: none; }
  #hud.live, #hud.finish, #hud.review { right: calc(340px + 2 * var(--edge)); }
  .speed .num { font-size: 72px; }
  #sheet.sheet-live { display: flex; flex-direction: column; justify-content: space-between; }
  #sheet.sheet-live .hold { margin-top: auto; }
  #sheet.sheet-live .strip { grid-template-columns: repeat(2, 1fr); row-gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .panel, #toast, .start { transition: none; }
}
