:root {
  --bg: #0f1419;
  --panel: #1a1f26;
  --border: #2a313b;
  --text: #d8dde4;
  --muted: #7e8896;
  --accent: #4aa3ff;
  --total: #f5d442;
  --error: #ff6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.selector label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: var(--muted);
}

.selector label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text);
}

.selector select,
.selector button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.9rem;
}

.selector button {
  cursor: pointer;
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0e13;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  align-self: flex-end;
}

.disclaimer {
  margin: 0;
  padding: 0.75rem 1.5rem;
  background: #2a1f0f;
  border-bottom: 1px solid #5a3f1a;
  border-left: 4px solid #f5d442;
  color: #e8dec3;
  font-size: 0.85rem;
  line-height: 1.5;
}

.disclaimer strong {
  color: var(--total);
}

.disclaimer p {
  margin: 0;
}

.disclaimer p + p {
  margin-top: 0.5rem;
}

.disclaimer .sources a,
.disclaimer .contact a {
  color: var(--accent);
  text-decoration: none;
  margin: 0 0.15rem;
}

.disclaimer .sources a:hover,
.disclaimer .contact a:hover {
  text-decoration: underline;
}

section {
  padding: 1rem 1.5rem;
}

section h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin: -0.25rem 0 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend .item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.legend .swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.legend .swatch.s-gold   { background: rgba(255, 215, 0, 0.55);  box-shadow: 0 0 0 1px rgba(255, 215, 0, 0.35) inset; }
.legend .swatch.s-silver { background: rgba(203, 213, 225, 0.55); box-shadow: 0 0 0 1px rgba(203, 213, 225, 0.35) inset; }
.legend .swatch.s-bronze { background: rgba(205, 127, 50, 0.55);  box-shadow: 0 0 0 1px rgba(205, 127, 50, 0.35) inset; }
.legend .swatch.s-purple { background: rgba(168, 85, 247, 0.65);  box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.45) inset; }

/* Collapsible race section ------------------------------------------------ */
details.race {
  margin: 0.75rem 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

details.race > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.6rem 0.9rem;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  user-select: none;
  background: #1f262f;
  border-bottom: 1px solid transparent;
  transition: background 0.12s ease;
}

details.race > summary::-webkit-details-marker { display: none; }
details.race > summary::marker { content: ""; }

details.race > summary::before {
  content: "▸";
  display: inline-block;
  width: 0.9rem;
  color: var(--accent);
  transition: transform 0.15s ease;
}

details.race[open] > summary::before { content: "▾"; }
details.race[open] > summary { border-bottom-color: var(--border); }

details.race > summary:hover { background: #242c36; }

details.race .race-title { flex: 1; }

details.race .race-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 3px;
}

details.race .race-link:hover {
  background: rgba(74, 163, 255, 0.1);
  text-decoration: none;
}

details.race > .group,
details.race > .error,
details.race > p {
  padding: 0 0.9rem;
}

details.race > .group:first-of-type { padding-top: 0.4rem; }
details.race > .group:last-of-type  { padding-bottom: 0.6rem; }

.group h4 {
  margin: 0.75rem 0 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lauf h5 {
  margin: 0.5rem 0 0.3rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.lauf h5 .meta {
  font-weight: normal;
  color: var(--muted);
  margin-left: 0.5rem;
  font-size: 0.75rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

thead th {
  background: #232a33;
  position: sticky;
  top: 0;
  text-align: left;
  padding: 0.4rem 0.6rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th.num { text-align: right; }
thead th.race-col { text-align: center; border-left: 1px solid var(--border); }
thead th.lap { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

tbody td {
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid #232a33;
  white-space: nowrap;
}

tbody tr:nth-child(odd) td { background: rgba(255, 255, 255, 0.02); }
tbody tr:hover td { background: rgba(74, 163, 255, 0.08); }

td.num, td.lap {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.lap { color: var(--muted); }

/* Optional per-lap detail columns (diff to leader + position). Rendered in a
 * dimmer hue so the eye still locks onto the lap time first. A left-border
 * on the diff cell separates one lap-triplet from the next. */
th.lap-diff, td.lap-diff {
  border-left: 1px solid #232a33;
  font-size: 0.78rem;
  color: #8a93a0;
}
th.lap-pos, td.lap-pos {
  font-size: 0.78rem;
  color: #8a93a0;
  padding-right: 0.5rem;
}

td.total { font-weight: 700; color: var(--total); }

/* Podium points highlights in the championship table (1st/2nd/3rd per Lauf).
 * Classic medal colors: gold / silver / bronze. */
td.pts-1, td.pts-2, td.pts-3 { font-weight: 700; }
td.pts-1 { background: rgba(255, 215, 0,  0.22); color: #ffd34d; }
td.pts-2 { background: rgba(203, 213, 225, 0.22); color: #e2e8f0; }
td.pts-3 { background: rgba(205, 127, 50, 0.22); color: #e89c5a; }
tbody tr:nth-child(odd) td.pts-1 { background: rgba(255, 215, 0,  0.26); }
tbody tr:nth-child(odd) td.pts-2 { background: rgba(203, 213, 225, 0.26); }
tbody tr:nth-child(odd) td.pts-3 { background: rgba(205, 127, 50, 0.26); }

/* Lap-matrix highlights:
 *   .lap-purple — session-overall fastest lap (unique)
 *   .lap-gold   — fastest in this lap column
 *   .lap-silver — 2nd-fastest in this lap column
 *   .lap-bronze — 3rd-fastest in this lap column
 * Precedence (purple > gold > silver > bronze) is resolved server-side, so a
 * cell never carries more than one of these classes. */
td.lap.lap-purple,
td.lap.lap-gold,
td.lap.lap-silver,
td.lap.lap-bronze { font-weight: 700; }

td.lap.lap-purple {
  background: rgba(168, 85, 247, 0.32);
  color: #d8b4fe;
  box-shadow: inset 0 0 0 1px rgba(192, 132, 252, 0.55);
}
td.lap.lap-gold   { background: rgba(255, 215, 0,  0.22); color: #ffd34d; }
td.lap.lap-silver { background: rgba(203, 213, 225, 0.22); color: #e2e8f0; }
td.lap.lap-bronze { background: rgba(205, 127, 50, 0.22); color: #e89c5a; }

tbody tr:nth-child(odd) td.lap.lap-purple { background: rgba(168, 85, 247, 0.38); }
tbody tr:nth-child(odd) td.lap.lap-gold   { background: rgba(255, 215, 0,  0.26); }
tbody tr:nth-child(odd) td.lap.lap-silver { background: rgba(203, 213, 225, 0.26); }
tbody tr:nth-child(odd) td.lap.lap-bronze { background: rgba(205, 127, 50, 0.26); }

/* Keep the highlight readable even on DNF/greyed-out rows. */
tbody tr.dnf td.lap.lap-purple,
tbody tr.dnf td.lap.lap-gold,
tbody tr.dnf td.lap.lap-silver,
tbody tr.dnf td.lap.lap-bronze { font-style: normal; }

tbody tr.dnf td {
  color: var(--muted);
  font-style: italic;
}

/* Guest finishers — appear in the table for context but score no points. */
tbody tr.guest td {
  color: #b9c1cc;
  background: rgba(120, 130, 150, 0.06);
}
tbody tr:nth-child(odd).guest td { background: rgba(120, 130, 150, 0.10); }

.guest-tag {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(120, 130, 150, 0.18);
  color: #b9c1cc;
  border-radius: 3px;
}

tbody tr.dnf .status {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: rgba(255, 107, 107, 0.15);
  color: var(--error);
  border-radius: 2px;
  font-style: normal;
}

.empty { color: var(--muted); font-style: italic; padding: 0.4rem 0; margin: 0; }
.error { color: var(--error); padding: 0.4rem 0; margin: 0; }

footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
}

footer p {
  margin: 0.2rem 0;
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}
