/* basti-tracker — chrome tokens follow the validated dataviz reference palette */

:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;          /* Basti */
  --series-1-dim: rgba(57, 135, 229, 0.10);
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --raa: #ba2c25;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-1-dim: rgba(42, 120, 214, 0.10);
  --good: #006300;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--series-1); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* ---------------------------------------------------------------- header */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1200;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
}
.identity { display: flex; align-items: center; gap: 14px; min-width: 0; }
.plate {
  flex: none; width: 46px; height: 46px; border-radius: 8px;
  background: var(--raa); color: #fff;
  font-family: var(--display); font-weight: 700; font-size: 30px;
  display: grid; place-items: center;
}
/* Without min-width:0 a flex item refuses to shrink below its content, so the
   h1's ellipsis never triggers and the race line wraps out of the box and in
   under the live pill. */
.who { min-width: 0; }
.who h1 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(22px, 3.4vw, 30px); line-height: 1.05;
  text-transform: uppercase; letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.race-line {
  color: var(--ink-3); font-size: 12.5px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.raa-mark { color: var(--raa); font-weight: 700; letter-spacing: 0.06em; }

.live-area { display: flex; align-items: center; gap: 10px; flex: none; }
.live-pill {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; font-size: 12.5px; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--critical); }
.live-pill.ok .live-dot { background: var(--good); animation: pulse 2s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 45%, transparent); }
                   70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.ghost-btn {
  border: 1px solid var(--border); background: none; color: var(--ink-2);
  border-radius: 8px; padding: 6px 11px; font-size: 13px; cursor: pointer;
  font-family: var(--sans);
}
.ghost-btn:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }

/* ---------------------------------------------------------------- layout */
main {
  max-width: 1240px; margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 32px) 40px;
  display: grid; gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  min-width: 0;
}
.card-head { margin-bottom: 8px; }
.card-head h2 {
  font-family: var(--display); font-weight: 600; font-size: 21px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.card-sub { color: var(--ink-3); font-size: 12.5px; }

/* ---------------------------------------------------------------- stat tiles */
.tiles {
  display: grid; gap: 10px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; min-width: 0;
}
.t-label { color: var(--ink-3); font-size: 12px; }
.t-value { font-weight: 600; font-size: clamp(20px, 2.4vw, 27px); line-height: 1.2; margin-top: 2px; }
.t-unit { font-size: 0.55em; font-weight: 500; color: var(--ink-2); }
.t-delta { font-size: 11.5px; color: var(--ink-3); min-height: 1.2em; }
.t-delta.up { color: var(--good); }

/* ---------------------------------------------------------------- map */
.map-card { padding: 0; overflow: hidden; position: relative; }
#map { height: clamp(340px, 52vh, 560px); background: var(--page); }
.leaflet-container { font: inherit; }

.now-card {
  position: absolute; top: 14px; right: 14px; z-index: 1000;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; max-width: min(300px, 70vw);
  font-size: 12.5px; color: var(--ink-2);
}
.nc-place { font-family: var(--display); font-weight: 600; font-size: 19px; color: var(--ink); line-height: 1.2; }
.nc-row strong { color: var(--ink); font-weight: 600; }
.follow-btn {
  position: absolute; bottom: 14px; right: 14px; z-index: 1000;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}
.follow-btn[aria-pressed="true"] { color: var(--series-1); border-color: var(--series-1); }

.basti-marker { position: relative; }
.basti-marker .b-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--series-1); border: 2px solid var(--surface);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}
.basti-marker .b-ring {
  position: absolute; inset: -7px; border-radius: 50%;
  border: 2px solid var(--series-1); opacity: 0;
  animation: ring 2.4s ease-out infinite;
}
@keyframes ring { 0% { transform: scale(0.4); opacity: 0.8; } 80% { transform: scale(1.15); opacity: 0; } 100% { opacity: 0; } }

/* ---------------------------------------------------------------- ribbon + charts */
.ribbon-wrap, .chart { position: relative; }
.ribbon-wrap svg, .chart svg { display: block; width: 100%; height: auto; }
.chart-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.board-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; align-items: start; }

/* ---------------------------------------------------------------- socials */
.social {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px;
  font-size: 13px; margin-bottom: -4px;
}
.social-label { color: var(--ink-3); }
.social a { color: var(--ink-2); text-decoration: none; border-bottom: 1px solid var(--border); }
.social a:hover { color: var(--series-1); border-bottom-color: currentColor; }

/* Inline-Legende in der Kartenunterzeile */
.legend { display: flex; flex-wrap: wrap; gap: 2px 4px; }
.legend .lg:first-child { margin-left: 0; }
.lg { white-space: nowrap; margin-left: 10px; }
.lg-key {
  display: inline-block; width: 13px; height: 0; vertical-align: middle;
  margin-right: 5px; border-top: 2px solid var(--series-1);
}
.lg-key.terrain { height: 8px; border: 0; background: var(--grid); border-radius: 1px; }
.lg-key.raw { border-top-color: color-mix(in srgb, var(--series-1) 55%, transparent); }
.lg-key.avg { border-top-width: 3px; }

.chart-tooltip {
  position: fixed; z-index: 2000; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 7px 10px;
  font-size: 12px; color: var(--ink-2);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  max-width: 240px;
}
.chart-tooltip .tt-value { color: var(--ink); font-weight: 600; font-size: 14px; }
.chart-tooltip .tt-key {
  display: inline-block; width: 12px; height: 0; border-top: 2px solid var(--series-1);
  vertical-align: middle; margin-right: 6px;
}

.table-view { margin-top: 8px; }
.table-view summary { color: var(--ink-3); font-size: 12px; cursor: pointer; }
.tv-scroll { overflow: auto; max-height: 300px; margin-top: 6px; }
.board-scroll { max-height: 480px; }
.splits-scroll { max-height: 480px; }

/* ---------------------------------------------------------------- tables */
table.board { width: 100%; border-collapse: collapse; font-size: 13px; }
.board th {
  text-align: left; color: var(--ink-3); font-weight: 500; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 6px 8px; border-bottom: 1px solid var(--baseline);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.board td {
  padding: 6px 8px; border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap;
}
.board td.name { color: var(--ink); white-space: normal; }
.board tr.me td { background: var(--series-1-dim); color: var(--ink); }
.board tr.me td.name { font-weight: 600; }
.board td.num { text-align: right; }
.board th.num { text-align: right; }
.board tr.upcoming td { color: var(--ink-3); }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; border: 1px solid currentColor;
}
.badge.finished { color: var(--good); }
.badge.dnf, .badge.dsq { color: var(--critical); }
.badge.dns, .badge.otl, .badge.pre { color: var(--ink-3); }

footer { max-width: 1240px; margin: 0 auto; padding: 0 clamp(14px, 3vw, 32px) 28px; }
footer p { color: var(--ink-3); font-size: 12px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 980px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chart-grid, .board-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .now-card { position: static; max-width: none; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; }
  /* Die Karte ist hier gestapelt statt überlagert — der Follow-Button darf
     nicht mehr absolut über der Info-Karte kleben. */
  .follow-btn { position: static; display: block; margin: 0 14px 14px auto; }

  /* Name und Live-Pille passen nebeneinander nicht mehr auf eine Zeile, ohne
     den Namen auf einen Stummel zu kürzen. Also zwei Zeilen — der Kopf bleibt
     dabei trotzdem niedriger als die dreizeilig umbrechende Variante vorher. */
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  .identity { flex: 1 1 100%; gap: 10px; }
  .plate { width: 38px; height: 38px; font-size: 25px; border-radius: 7px; }
  .who h1 { font-size: 19px; }
  .race-line { font-size: 11.5px; }
  .live-area { flex: 1 1 100%; justify-content: space-between; }

  /* Passend zu drawTerrainChart(): die Rohwerte werden hier nicht gezeichnet. */
  .lg-raw { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .basti-marker .b-ring, .live-pill.ok .live-dot { animation: none; }
}
