:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa2b1;
  --accent: #fc4c02;      /* Strava orange */
  --accent-2: #3b82f6;
  --good: #22c55e;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
button { font: inherit; cursor: pointer; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 16px 64px; }

header.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: rgba(15,17,21,.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.topbar .brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.topbar .spacer { flex: 1; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }

.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font-weight: 600; transition: .15s;
}
.btn:hover { border-color: #3a4150; background: #262b35; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: .85rem; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 820px) { .grid.cols-4 { grid-template-columns: repeat(2,1fr); } .grid.cols-2 { grid-template-columns: 1fr; } }

.stat { text-align: left; }
.stat .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 1.7rem; font-weight: 700; margin-top: 2px; }
.stat .v small { font-size: .9rem; color: var(--muted); font-weight: 500; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 8px 0 18px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { background: var(--surface); border: 0; color: var(--muted); padding: 7px 12px; }
.seg button.active { background: var(--accent); color: #fff; }
select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font: inherit;
}
.muted { color: var(--muted); }
.section-title { display: flex; align-items: center; gap: 10px; margin: 30px 0 12px; }
.section-title h2 { margin: 0; }

canvas { max-width: 100%; }
.chart-box { position: relative; height: 280px; }
@media (max-width: 820px) { .chart-box { height: 240px; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: .92rem; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: rgba(255,255,255,.02); }
td.thumbcell { width: 96px; padding-right: 2px; }
.thumb {
  display: block; width: 88px; height: 60px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.thumb.none { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; }
@media (max-width: 640px) { td.thumbcell { width: 64px; } .thumb { width: 58px; height: 42px; } }

.bigmap { height: 500px; position: relative; z-index: 0; }
@media (max-width: 640px) { .bigmap { height: 340px; } }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.map-pop { font: inherit; }
.map-pop .muted { color: var(--muted); font-size: .82rem; margin: 2px 0 8px; }
.map-pop .row { display: flex; gap: 6px; flex-wrap: wrap; }
tr.flash td { background: rgba(252,76,2,.14); transition: background 1.2s; }
#runsBody tr { cursor: pointer; }
#runsBody tr.is-away td:first-child { box-shadow: inset 3px 0 0 var(--accent-2); }
.tag.away { color: var(--accent-2); border-color: rgba(59,130,246,.45); background: rgba(59,130,246,.12); }
.tag.race { color: var(--accent); border-color: rgba(252,76,2,.5); background: rgba(252,76,2,.12); }

.modal.lg { width: 860px; max-height: 92vh; overflow-y: auto; }
.detmap { height: 380px; margin-top: 14px; border-radius: 10px; position: relative; z-index: 0; }
.modal.lg .stat { padding: 12px; }
@media (max-width: 640px) { .detmap { height: 260px; } }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: .75rem; color: var(--muted); }
.pill-live { color: var(--good); }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

/* Map */
#map, .mini-map { border-radius: 12px; }
#map { height: 380px; }
.leaflet-container { background: #0b0d10; }

/* Weather */
.wx-now { display: flex; align-items: center; gap: 16px; }
.wx-now .emoji { font-size: 3rem; line-height: 1; }
.wx-now .temp { font-size: 2.2rem; font-weight: 700; }
.wx-days { display: grid; grid-template-columns: repeat(5,1fr); gap: 8px; margin-top: 14px; }
.wx-day { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px; text-align: center; font-size: .8rem; }
.wx-day .e { font-size: 1.4rem; }
@media (max-width: 640px){ .wx-days { grid-template-columns: repeat(3,1fr);} }

/* Toast */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: .25s; z-index: 100; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none;
  align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; width: 460px; max-width: 100%; box-shadow: var(--shadow); }
.modal label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
.modal input, .modal textarea, .modal select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 9px 11px; font: inherit;
}
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.hero { text-align: center; padding: 56px 16px; }
.hero .big { font-size: 2.1rem; }
.hero p { color: var(--muted); max-width: 520px; margin: 8px auto 24px; }
.hidden { display: none !important; }
.copyrow { display: flex; gap: 8px; align-items: center; }
.copyrow input { flex: 1; }
