:root {
  --bg: #0b1020;
  --bg2: #10182e;
  --card: #151e38;
  --line: #24305a;
  --ink: #eef3ff;
  --muted: #8d9abb;
  --accent: #ff5a1f;
  --accent2: #ffb11f;
  --ice: #5fd4ff;
  --ok: #3ddc84;
  --warn: #ffcc33;
  --bad: #ff4d6d;
  --gold: #ffd34d;
  --silver: #c9d3e6;
  --bronze: #e09a5c;
  --display: "Bebas Neue", Impact, "Arial Narrow", sans-serif;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 60% at 50% -10%, #1b2a5c 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--body);
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
h3 { font: 600 13px/1 var(--body); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
a { color: var(--ice); }
b { font-weight: 800; }

/* ---------- logo ---------- */
.logo { font: 64px/0.9 var(--display); letter-spacing: .02em; transform: skewX(-8deg); }
.logo b { color: var(--accent); font-weight: 400; }
.logo.sm { font-size: 30px; }

/* ---------- screens ---------- */
.screen { min-height: 100%; }
#join { display: flex; flex-direction: column; justify-content: center; padding: calc(24px + var(--safe-top)) 16px 24px; max-width: 460px; margin: 0 auto; }
.brand { text-align: center; margin-bottom: 28px; }
.tag { color: var(--muted); margin: 10px 0 0; font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin: 14px 0; }
.form label { display: block; font-weight: 600; color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.form input {
  display: block; width: 100%; margin-top: 6px; padding: 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--ink);
  font: 600 18px var(--body);
}
.form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn {
  appearance: none; border: 0; border-radius: 14px; padding: 14px 18px; width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #1a0d05;
  font: 800 17px var(--body); cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.big { font-size: 20px; padding: 18px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { width: auto; padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.hint { color: var(--muted); font-size: 14px; margin: 12px 0 0; }
.center { text-align: center; }

/* ---------- app shell ---------- */
#app { display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px; background: rgba(11, 16, 32, .85); backdrop-filter: blur(10px);
}
.top-right { display: flex; gap: 6px; }
.pill { font: 800 12px var(--body); letter-spacing: .06em; padding: 5px 10px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
main { flex: 1; padding: 4px 16px calc(96px + var(--safe-bot)); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center;
  background: rgba(11, 16, 32, .95); border-top: 1px solid var(--line); padding-bottom: var(--safe-bot);
}
.tabs button {
  flex: 1; max-width: 190px; appearance: none; background: none; border: 0; color: var(--muted);
  padding: 10px 0 12px; display: flex; flex-direction: column; align-items: center; gap: 2px; font: 600 12px var(--body); cursor: pointer;
}
.tabs i { font-style: normal; font-size: 22px; filter: grayscale(1); opacity: .6; }
.tabs .on { color: var(--ink); }
.tabs .on i { filter: none; opacity: 1; }

/* ---------- ride tab ---------- */
.banner { background: #2a2350; border: 1px dashed #8a7cff; color: #d9d3ff; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }
.gps { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.dot.mid { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
.dot.bad { background: var(--bad); box-shadow: 0 0 10px var(--bad); }

.go {
  display: grid; place-items: center; width: min(62vw, 240px); aspect-ratio: 1; margin: 18px auto;
  border-radius: 50%; border: 0; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #ff8a4c, var(--accent) 55%, #c63a0a);
  box-shadow: 0 0 0 10px rgba(255, 90, 31, .15), 0 0 0 22px rgba(255, 90, 31, .07), 0 18px 40px rgba(0, 0, 0, .5);
  animation: pulse 2.4s ease-in-out infinite;
}
.go span { font: 96px/1 var(--display); color: #fff; letter-spacing: .04em; transform: skewX(-8deg); text-shadow: 0 4px 0 rgba(0,0,0,.2); }
.go:active { transform: scale(.96); }
@keyframes pulse { 50% { box-shadow: 0 0 0 16px rgba(255, 90, 31, .18), 0 0 0 32px rgba(255, 90, 31, .06), 0 18px 40px rgba(0, 0, 0, .5); } }
@media (prefers-reduced-motion: reduce) { .go { animation: none; } }

.steps { color: var(--muted); font-size: 15px; padding-left: 22px; margin: 8px 0 4px; }
.steps li { margin: 4px 0; }
.steps b { color: var(--ink); }

.statgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--bg2); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font: 34px/1 var(--display); letter-spacing: .02em; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 600; }

/* ---------- board ---------- */
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; margin-top: 12px; }
.seg button { flex: 1; appearance: none; border: 0; background: none; color: var(--muted); padding: 10px; border-radius: 10px; font: 800 14px var(--body); cursor: pointer; }
.seg .on { background: var(--ink); color: var(--bg); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 14px; border-radius: 99px; font: 600 14px var(--body); cursor: pointer; white-space: nowrap;
}
.chips .on { border-color: var(--accent); background: rgba(255, 90, 31, .15); }

.board { list-style: none; padding: 0; margin: 8px 0 0; }
.board li {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin: 8px 0;
}
.board li.me { border-color: var(--ice); box-shadow: inset 0 0 0 1px var(--ice); }
.board .rk { font: 30px/1 var(--display); color: var(--muted); text-align: center; }
.board .rk.r1 { color: var(--gold); } .board .rk.r2 { color: var(--silver); } .board .rk.r3 { color: var(--bronze); }
.board .nm { font-weight: 800; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .sub { color: var(--muted); font-size: 12px; font-weight: 600; }
.board .val { font: 30px/1 var(--display); letter-spacing: .02em; }
.board li.first { background: linear-gradient(135deg, rgba(255, 211, 77, .16), var(--card) 60%); border-color: rgba(255, 211, 77, .5); }
.board .empty { display: block; text-align: center; color: var(--muted); padding: 24px 14px; }

.section { margin-top: 26px; }
.feed, .myruns { list-style: none; padding: 0; margin: 0; }
.feed li, .myruns li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.feed li:last-child, .myruns li:last-child { border-bottom: 0; }
.feed .who { font-weight: 800; }
.feed .when, .myruns .when { color: var(--muted); font-size: 12px; }
.feed .nums, .myruns .nums { text-align: right; font-weight: 600; white-space: nowrap; }
.tag-s { font-size: 11px; font-weight: 800; padding: 2px 6px; border-radius: 6px; background: var(--bg2); color: var(--muted); margin-left: 4px; }
.tag-s.wait { color: var(--warn); } .tag-s.test { color: #b6acff; } .tag-s.bad { color: var(--bad); }
.tips ul { padding-left: 0; list-style: none; margin: 0; }
.tips li { margin: 0 0 10px; font-size: 15px; color: var(--muted); }
.tips li b { color: var(--ink); }

/* ---------- carte ---------- */
.maptools { display: flex; gap: 8px; align-items: stretch; margin-top: 12px; }
.maptools .seg { flex: 1; margin: 0; min-width: 0; }
.maptools .seg button { padding: 8px 6px; font-size: 13px; }
#mapWho {
  flex: none; width: 42%; max-width: 200px; appearance: none; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--ink); font: 600 14px var(--body); padding: 0 12px;
}
.mapwrap {
  position: relative; margin-top: 10px; border-radius: 18px; overflow: hidden; border: 1px solid var(--line);
  height: calc(100dvh - 250px - var(--safe-top) - var(--safe-bot)); min-height: 320px; background: #1a2238;
}
#map { position: absolute; inset: 0; }
.mapmsg {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 500; pointer-events: none;
  background: rgba(11, 16, 32, .85); color: var(--ink); font-weight: 600; font-size: 13px; padding: 6px 12px; border-radius: 99px; white-space: nowrap;
}
.mapmsg:empty { display: none; }
.locbtn {
  position: absolute; left: 10px; bottom: 10px; z-index: 500; width: 46px; height: 46px; border-radius: 50%;
  border: 0; background: #fff; font-size: 22px; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); cursor: pointer;
}
.livebtn {
  position: absolute; left: 10px; top: 10px; z-index: 500; border: 0; border-radius: 99px; padding: 9px 14px;
  background: rgba(11, 16, 32, .9); color: var(--ink); font: 800 13px var(--body); cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35); border: 1px solid var(--line);
}
.livebtn.on { background: var(--ok); color: #05210f; border-color: transparent; }
.mapmsg { top: 56px; }
.livelist { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.livelist .ll-title { font: 600 12px var(--body); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-right: 4px; }
.livelist .ll-empty { color: var(--muted); font-size: 13px; font-weight: 600; }
.livelist button {
  display: inline-flex; align-items: center; gap: 6px; appearance: none; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 99px; padding: 6px 11px; font: 700 13px var(--body);
}
.livelist button i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.livelist small { color: var(--muted); font-weight: 600; }

/* repères des potes sur la carte */
.lm-wrap { background: none; border: 0; }
.lm { position: relative; width: 34px; height: 34px; }
.lm b {
  position: relative; z-index: 1; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--c); color: #0b1020; font: 800 16px var(--body); border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0, 0, 0, .45);
}
.lm.me b { background: #2f8cff; color: #fff; }
.lm span {
  position: absolute; left: 50%; top: 38px; transform: translateX(-50%); white-space: nowrap;
  background: rgba(11, 16, 32, .88); color: #fff; font: 700 12px var(--body); padding: 2px 7px; border-radius: 99px;
}
.lm.fresh::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%; background: var(--c); opacity: .6;
  animation: ping 1.8s ease-out infinite;
}
.lm.me.fresh::before { background: #2f8cff; }
@keyframes ping { from { transform: scale(1); opacity: .6; } to { transform: scale(2.2); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .lm.fresh::before { animation: none; } }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
body.on-map main { padding-bottom: calc(80px + var(--safe-bot)); }
.leaflet-popup-content { font: 14px/1.45 var(--body); }
.leaflet-container a.leaflet-popup-close-button { font-size: 20px; }
.myruns .acts { display: flex; gap: 6px; flex: none; }

/* ---------- riding overlay ---------- */
#riding {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(20px + var(--safe-top)) 16px calc(24px + var(--safe-bot));
  background: radial-gradient(100% 70% at 50% 30%, #2a1408, #000 75%);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.r-gps { display: flex; gap: 8px; align-items: center; color: var(--muted); font-weight: 600; font-size: 14px; }
.r-speed { text-align: center; }
.r-speed span { display: block; font: min(48vw, 260px)/0.85 var(--display); color: #fff; letter-spacing: -.01em; }
.r-speed small { font: 800 16px var(--body); color: var(--accent); letter-spacing: .2em; text-transform: uppercase; }
.r-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; max-width: 440px; }
.r-grid div { background: rgba(255, 255, 255, .06); border-radius: 14px; padding: 12px; text-align: center; }
.r-grid b { display: block; font: 40px/1 var(--display); }
.r-grid span { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.r-hint { color: var(--muted); font-size: 13px; margin: 0; }
.slider {
  position: relative; width: 100%; max-width: 440px; height: 72px; border-radius: 99px;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .15); overflow: hidden;
}
.slider-label { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 800; letter-spacing: .06em; padding-left: 50px; }
.knob {
  position: absolute; top: 4px; left: 4px; width: 64px; height: 62px; border-radius: 99px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #1a0d05; font: 800 26px var(--body);
  touch-action: none; cursor: grab;
}
.knob.back { transition: transform .25s ease; }

/* ---------- summary dialog ---------- */
dialog {
  width: min(92vw, 420px); border: 1px solid var(--line); border-radius: 22px; padding: 20px;
  background: var(--card); color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog .row { display: flex; gap: 10px; margin-top: 16px; }
.sum-title { font: 44px/1 var(--display); margin: 0 0 4px; transform: skewX(-6deg); }
.sum-sub { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.sum-warn { color: var(--warn); font-size: 14px; margin: 12px 0 0; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bot)); transform: translate(-50%, 20px); z-index: 50;
  background: var(--ink); color: var(--bg); font-weight: 800; padding: 12px 16px; border-radius: 14px; max-width: calc(100vw - 32px);
  opacity: 0; pointer-events: none; transition: .25s; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
