:root {
  --bg: #fbf6ee;
  --surface: #fffdf9;
  --text: #2a1f1a;
  --muted: #6e5f55;
  --border: #eadfce;
  --accent: #c41e3a;
  --accent-text: #ffffff;
  --gold: #d4a017;
  --header-bg: #0f4d2c;
  --header-text: #fff8ec;
  --header-muted: #cfe3d3;
  --track: #efe5d6;
  --error-bg: #fdecec;
  --error-text: #8a1c1c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1a13;
    --surface: #13241a;
    --text: #f3ece0;
    --muted: #a9b9ad;
    --border: #24402f;
    --accent: #e8475f;
    --accent-text: #ffffff;
    --gold: #e8bd45;
    --header-bg: #0a2e1b;
    --header-text: #fff8ec;
    --header-muted: #a9c9b2;
    --track: #20382a;
    --error-bg: #3a1d20;
    --error-text: #ffb3b3;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
.muted { color: var(--muted); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--header-text);
  /* gentle snowfall over pine green, with a gold ribbon underneath */
  background:
    radial-gradient(circle at 12% 30%, rgba(255, 255, 255, 0.35) 0 1.5px, transparent 2px),
    radial-gradient(circle at 38% 75%, rgba(255, 255, 255, 0.25) 0 1px, transparent 1.5px),
    radial-gradient(circle at 63% 20%, rgba(255, 255, 255, 0.3) 0 1.5px, transparent 2px),
    radial-gradient(circle at 86% 60%, rgba(255, 255, 255, 0.25) 0 1px, transparent 1.5px),
    var(--header-bg);
  background-size: 90px 60px, 70px 50px, 110px 70px, 60px 40px, auto;
  border-bottom: 4px solid var(--gold);
}
.topbar .muted { color: var(--header-muted); }
.topbar h1 { letter-spacing: 0.01em; }
.topbar h1::after { content: " 🎄"; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo { height: 44px; width: auto; max-width: 40vw; object-fit: contain; display: block; background: #fff; border-radius: 8px; padding: 4px 8px; }
.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar p { margin: 2px 0 0; font-size: 0.85rem; }
.status { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; text-align: right; }
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
}
button:hover { border-color: var(--accent); }
#refresh-btn { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
#refresh-btn:hover { filter: brightness(1.1); }
#refresh-btn:disabled { opacity: 0.6; cursor: wait; }

.layout { flex: 1; display: flex; min-height: 0; }
.map-wrap { flex: 1; min-width: 0; }
#map { height: 100%; width: 100%; }

.panel {
  width: 400px;
  max-width: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--bg); }
.tabs button {
  flex: 1;
  border: 0;
  border-radius: 0;
  border-bottom: 3px solid transparent;
  padding: 10px 4px;
  font-size: 0.85rem;
}
.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; background: var(--surface); }
.tab-body { padding: 12px 16px; overflow-y: auto; flex: 1; }

.error {
  margin: 12px 16px 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 0.85rem;
}

.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li {
  display: grid;
  grid-template-columns: 28px 30px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.leaderboard li:hover { background: var(--bg); }
.rank { font-weight: 700; color: var(--muted); text-align: center; }
.team-name { font-weight: 600; overflow-wrap: anywhere; }
.team-sub { font-size: 0.78rem; color: var(--muted); }
.km { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.bar { height: 6px; background: var(--track); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 3px; }

.select-row { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
select {
  font: inherit;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.detail-head { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; }
.detail-head h2 { margin: 0; font-size: 1.15rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.stat { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.stat .label { font-size: 0.75rem; color: var(--muted); }
.stat .value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
h3 { font-size: 0.95rem; margin: 16px 0 6px; color: var(--header-bg); }
@media (prefers-color-scheme: dark) { h3 { color: var(--gold); } }

.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 6px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }

.dbar-row { margin-bottom: 8px; }
.dbar-label { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 2px; gap: 8px; }
.dbar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; background: var(--track); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.8rem; margin-bottom: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.xmas-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border-radius: 50%;
  background: #fff;
  border-style: solid;
  line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
.team-icon .xmas-badge { box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45); }
.leaflet-tooltip.team-label { font-weight: 600; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .map-wrap { flex: none; height: 50vh; }
  .panel { width: 100%; border-left: 0; border-top: 1px solid var(--border); flex: 1; }
  .status span { display: none; }
  .logo { height: 30px; }
  .topbar h1 { font-size: 1.05rem; }
}
