:root {
  --bg: #0f1117; --surface: #1a1d27; --surface2: #22263a; --border: #2e3350;
  --accent: #f97316; --gold: #fbbf24; --silver: #94a3b8; --bronze: #cd7f32;
  --text: #e2e8f0; --muted: #8391a7; --road: #3b82f6; --gravel: #a3a3a3; --mtb: #22c55e;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh; padding-bottom: calc(24px + var(--safe-bottom));
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15,17,23,0.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: calc(12px + var(--safe-top)) 16px 12px;
  display: flex; align-items: center; gap: 12px;
}
header .logo { flex-shrink: 0; }
header .titles { flex: 1; min-width: 0; }
header h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header p { color: var(--muted); font-size: 0.78rem; margin-top: 1px; }
.refresh-btn {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 0.82rem; font-weight: 600;
}
.refresh-btn svg { transition: transform 0.3s; }
.refresh-btn.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.section { padding: 16px; }
.section h2 { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 10px; font-weight: 700; }

.week { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.week div { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 8px; text-align: center; }
.week b { display: block; font-size: 1.25rem; }
.week span { font-size: 0.66rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.fitness-note { font-size: 0.74rem; color: var(--muted); margin-top: 8px; line-height: 1.45; }
.fitness-chart { position: relative; height: 170px; margin-top: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.recent { display: flex; flex-direction: column; gap: 8px; }
.recent-item {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; text-decoration: none; color: inherit;
}
.recent-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.recent-main { flex: 1; min-width: 0; }
.recent-title { font-size: 0.88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-sub { font-size: 0.74rem; color: var(--muted); margin-top: 2px; }
.recent-speed { text-align: right; }
.recent-speed b { font-size: 1.05rem; }
.rank-pill { display: inline-block; margin-top: 2px; font-size: 0.68rem; font-weight: 700; padding: 1px 7px; border-radius: 10px; background: var(--surface2); color: var(--muted); }
.rank-pill.pr { background: rgba(251,191,36,0.18); color: var(--gold); }

.stats-banner { padding: 16px; display: flex; flex-direction: column; gap: 14px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: rgba(255,255,255,0.015); }
.map-progress-wrap { position: relative; width: 100%; aspect-ratio: 2 / 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: #0a1e33; }
.map-progress-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0.88; }
.map-progress-wrap svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.map-caption { position: absolute; left: 10px; bottom: 8px; font-size: 0.72rem; color: #fff; background: rgba(0,0,0,0.45); padding: 2px 8px; border-radius: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { padding: 6px 13px; border-radius: 18px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; font-size: 0.82rem; font-weight: 600; white-space: nowrap; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.road.active { background: var(--road); border-color: var(--road); }
.chip.gravel.active { background: #737373; border-color: #737373; }
.chip.mtb.active { background: var(--mtb); border-color: var(--mtb); }
.stats-numbers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.big-stat { text-align: center; }
.big-stat-val { font-size: 1.3rem; font-weight: 800; line-height: 1.1; }
.big-stat-lbl { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 3px; }

.controls { padding: 14px 16px 0; position: sticky; top: calc(58px + var(--safe-top)); z-index: 40; background: var(--bg); padding-bottom: 10px; }
.grid { display: grid; grid-template-columns: 1fr; gap: 16px; padding: 6px 16px 16px; }
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(480px, 1fr)); }
  .stats-banner { flex-direction: row; align-items: center; }
  .map-progress-wrap { width: 340px; flex-shrink: 0; }
  .section, .stats-banner, .controls, .grid { padding-left: 32px; padding-right: 32px; }
}

.route-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.card-header { padding: 14px 16px 12px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-title { font-size: 0.98rem; font-weight: 700; line-height: 1.3; }
.card-meta { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.badges { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.type-badge { padding: 3px 9px; border-radius: 12px; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; white-space: nowrap; }
.type-road { background: rgba(59,130,246,0.18); color: #60a5fa; }
.type-gravel { background: rgba(163,163,163,0.18); color: #d4d4d4; }
.type-mtb { background: rgba(34,197,94,0.18); color: #4ade80; }
.type-mixed { background: rgba(251,191,36,0.18); color: #fbbf24; }
.new-badge { background: rgba(249,115,22,0.18); color: var(--accent); }
.rename-btn { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 3px 8px; font-size: 0.72rem; color: var(--muted); cursor: pointer; }

.card-toggles { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.chip.small { padding: 4px 11px; font-size: 0.74rem; }
.card-stats { padding: 10px 16px; display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--border); background: rgba(255,255,255,0.02); }
.stat { text-align: center; }
.stat-val { font-size: 1rem; font-weight: 700; }
.stat-lbl { font-size: 0.64rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 1px; }

.podium { padding: 12px 16px 10px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; border-bottom: 1px solid var(--border); }
.podium-item { background: var(--surface2); border-radius: 10px; padding: 8px 10px; text-decoration: none; color: inherit; display: block; }
.podium-rank { font-size: 0.8rem; font-weight: 800; }
.rank-1 { color: var(--gold); } .rank-2 { color: var(--silver); } .rank-3 { color: var(--bronze); }
.podium-speed { font-size: 1.1rem; font-weight: 700; }
.podium-time, .podium-date { font-size: 0.68rem; color: var(--muted); }

.map-wrap { height: 180px; width: 100%; background: #1a1d27; }
.map-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--border); background: rgba(255,255,255,0.02); }
.map-location { font-size: 0.72rem; color: var(--muted); }
.view-route-btn { font-size: 0.74rem; font-weight: 600; color: var(--accent); text-decoration: none; white-space: nowrap; }
.chart-wrap { padding: 12px 12px 14px; position: relative; height: 220px; }
.leaflet-tile { filter: brightness(0.85) saturate(0.7); }
.leaflet-control-attribution { display: none; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); transform: translateX(-50%) translateY(150%);
  background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 10px 16px; border-radius: 12px;
  font-size: 0.85rem; z-index: 100; transition: transform 0.25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
