:root {
  --bg: #0b0e13;
  --panel: #131720;
  --panel-2: #171d29;
  --border: #232a36;
  --text: #e8edf4;
  --muted: #8b949e;
  --red: #e10600;
  --red-dim: #e1060033;
  --gold: #f0b429;
  --purple: #c962fd;
  --green: #3fb950;
  --amber: #d29922;
  --blue: #58a6ff;
  --row-alt: #10141c;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}

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

html { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.topnav {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #10141c, var(--bg));
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand:hover { text-decoration: none; }
.brand .stripe {
  width: 10px; height: 20px;
  background: linear-gradient(135deg, var(--red) 0 60%, transparent 60%);
  border-radius: 2px;
  transform: skewX(-20deg);
}
.brand em { color: var(--red); font-style: normal; }

.topnav nav { display: flex; gap: 4px; margin-left: 8px; }
.topnav nav a {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 6px 10px;
  border-radius: 6px;
}
.topnav nav a:hover { color: var(--text); text-decoration: none; background: var(--panel); }
.topnav nav a.active { color: var(--text); background: var(--red-dim); box-shadow: inset 0 0 0 1px #e1060055; }

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

.session-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 14px;
}
.session-banner h1 { font-size: 17px; font-weight: 800; }
.session-banner .circuit { color: var(--muted); font-size: 13px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.live { color: #fff; background: var(--red); border-color: var(--red); }
.badge.live::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: #fff; animation: pulse 1.2s ease-in-out infinite;
}
.badge.finished { color: var(--green); border-color: #3fb95055; }
.badge.upcoming { color: var(--gold); border-color: #f0b42955; }
.badge.sc { color: #111; background: var(--gold); border-color: var(--gold); }

@keyframes pulse { 50% { opacity: 0.25; } }

.countdown { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--gold); }

.grid-live {
  display: grid;
  grid-template-columns: minmax(340px, 5fr) minmax(420px, 7fr);
  gap: 14px;
  align-items: start;
}
.grid-live .col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}
.panel > header .right { display: flex; gap: 8px; align-items: center; }

.map-holder { position: relative; background: radial-gradient(ellipse at 50% 40%, #151b26, var(--panel)); }
.map-holder svg { display: block; width: 100%; height: auto; touch-action: none; cursor: grab; }
.map-holder svg:active { cursor: grabbing; }
.track-outline {
  fill: none;
  stroke: #3a4454;
  stroke-width: 10;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.track-outline-inner { fill: none; stroke: #0b0e13; stroke-width: 4; }
.car-dot { cursor: pointer; stroke: #0b0e13; stroke-width: 2; }
.car-dot.fav { stroke: var(--gold); stroke-width: 3; }
.car-label {
  fill: #fff; font-size: 26px; font-weight: 800; font-family: var(--font);
  paint-order: stroke; stroke: #0b0e13; stroke-width: 5; pointer-events: none;
}
.map-empty { padding: 40px 14px; text-align: center; color: var(--muted); font-size: 13px; }

.timing { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.timing th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}
.timing td { padding: 7px 8px; border-bottom: 1px solid #1a2130; font-size: 13.5px; white-space: nowrap; }
.timing tbody tr { background: var(--panel); }
.timing tbody tr:nth-child(even) { background: var(--row-alt); }
.timing tbody tr.fav { box-shadow: inset 3px 0 0 var(--gold); }
.timing tbody tr.out td { opacity: 0.45; }
.timing tbody tr.pit-row td { background: #1c2333; }
.timing .pos { font-family: var(--mono); font-weight: 700; width: 30px; color: var(--muted); }
.timing .num { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.timing .drv { font-weight: 800; letter-spacing: 0.4px; }
.timing .teambar { width: 4px; padding: 0 !important; }
.timing .gap, .timing .int, .timing .lap { font-family: var(--mono); font-size: 12.5px; }
.timing .lap.fastest { color: var(--purple); font-weight: 700; }
.timing .star { cursor: pointer; color: #3a4454; font-size: 15px; user-select: none; }
.timing .star.on { color: var(--gold); }
.timing .status-pill { font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 999px; }
.status-pill.pit { background: #58a6ff33; color: var(--blue); }
.status-pill.out { background: #f8514933; color: #f85149; }
.status-pill.dsq { background: #f85149; color: #fff; }

.tire {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 10.5px;
  font-weight: 900;
  color: #111;
  border: 2px solid #0006;
}
.tire-age { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-left: 6px; }

.tirewear { display: inline-block; width: 46px; height: 5px; background: #232a36; border-radius: 3px; overflow: hidden; vertical-align: middle; margin-left: 8px; }
.tirewear i { display: block; height: 100%; }

.scenarios { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.scen-row { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.scen-row .tag {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px;
  padding: 2px 8px; border-radius: 999px;
}
.scen-row .tag.clinched { background: #3fb95033; color: var(--green); }
.scen-row .tag.eliminated { background: #f8514933; color: #f85149; }
.scen-row .tag.contention { background: #f0b42922; color: var(--gold); }
.scen-row .pts { margin-left: auto; font-family: var(--mono); color: var(--muted); font-size: 12px; }
.needs { color: var(--text); font-size: 13.5px; padding: 8px 12px; background: var(--panel-2); border-radius: 8px; border-left: 3px solid var(--gold); }
.scen-empty { color: var(--muted); font-size: 13px; padding: 12px 14px; }

.timeline { max-height: 420px; overflow-y: auto; }
.event {
  display: flex; gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid #1a2130;
  font-size: 13px;
  align-items: baseline;
}
.event .t { font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 64px; }
.event .cat { font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); color: var(--muted); flex-shrink: 0; }
.event .cat.flag { color: var(--gold); }
.event .cat.safetycar { color: var(--gold); }
.event .cat.drs { color: var(--green); }
.event .msg { color: var(--text); word-break: break-word; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.filters button {
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
  font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px; cursor: pointer;
}
.filters button.on { color: var(--text); border-color: var(--red); background: var(--red-dim); }

.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.hero {
  background: linear-gradient(135deg, #16121a 0%, var(--panel) 55%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 22px;
  display: flex; flex-direction: column; gap: 12px;
}
.hero h1 { font-size: 26px; font-weight: 900; line-height: 1.15; }
.hero h1 em { color: var(--red); font-style: normal; }
.hero p { color: var(--muted); max-width: 46ch; }
.hero .cta {
  display: inline-block; align-self: flex-start;
  background: var(--red); color: #fff; font-weight: 800;
  padding: 10px 18px; border-radius: 8px; font-size: 14px;
}
.hero .cta:hover { text-decoration: none; filter: brightness(1.1); }

.stand-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stand-table td, .stand-table th { padding: 8px 12px; border-bottom: 1px solid #1a2130; font-size: 14px; text-align: left; }
.stand-table th { font-size: 10px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); }
.stand-table .pts { font-family: var(--mono); text-align: right; font-weight: 700; }
.stand-table tr:first-child td { color: var(--gold); }

.race-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px;
}
.race-card.past { opacity: 0.55; }
.race-card.next { border-color: var(--red); box-shadow: 0 0 0 1px var(--red-dim); }
.race-card h3 { font-size: 15px; }
.race-card .when { color: var(--muted); font-size: 12.5px; }
.race-card .sessions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.race-card .sess {
  font-size: 11px; font-family: var(--mono); color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px;
}
.race-card .sess.race { color: var(--text); border-color: #e1060066; }

.form-strip { display: flex; flex-direction: column; gap: 12px; padding: 12px 14px; }
.form-row { display: flex; align-items: center; gap: 10px; }
.form-row .who { min-width: 52px; font-weight: 800; font-size: 13px; }
.form-bars { display: flex; align-items: flex-end; gap: 4px; flex: 1; height: 34px; }
.form-bar {
  flex: 1; border-radius: 3px 3px 0 0; min-height: 3px; position: relative;
  background: var(--panel-2); border: 1px solid var(--border); border-bottom: none;
}
.form-bar.p1 { background: #f0b42955; border-color: var(--gold); }
.form-bar.p23 { background: #3fb95044; border-color: #3fb95088; }
.form-bar .lbl {
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  font-size: 9.5px; font-family: var(--mono); color: var(--muted);
}
.form-avg { font-family: var(--mono); font-size: 11.5px; color: var(--muted); min-width: 56px; text-align: right; }
.form-races { display: flex; gap: 4px; margin-top: 2px; padding-left: 62px; padding-right: 66px; }
.form-races span {
  flex: 1; text-align: center; font-size: 9px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lastrace-list { display: flex; flex-direction: column; }
.lastrace-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 14px;
  border-bottom: 1px solid #1a2130; font-size: 13.5px;
}
.lastrace-row .pos { font-family: var(--mono); font-weight: 700; color: var(--muted); width: 26px; }
.lastrace-row.p1 .pos { color: var(--gold); }

.footnote { color: var(--muted); font-size: 12px; margin-top: 18px; }
.footnote a { color: var(--muted); text-decoration: underline; }

.updated { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.err { color: var(--amber); font-size: 12px; }

.mobile-tabs { display: none; }

@media (max-width: 960px) {
  .grid-live { grid-template-columns: 1fr; }
  .home-grid { grid-template-columns: 1fr; }
  .topnav { gap: 10px; padding: 10px 14px; flex-wrap: wrap; }
  .wrap { padding: 12px 12px 60px; }
  .mobile-tabs {
    display: flex; gap: 6px; margin-bottom: 12px;
    position: sticky; top: 53px; z-index: 40; background: var(--bg); padding: 6px 0;
  }
  .mobile-tabs button {
    flex: 1; background: var(--panel); color: var(--muted); border: 1px solid var(--border);
    padding: 9px 0; border-radius: 8px; font-weight: 700; font-size: 13px; cursor: pointer;
  }
  .mobile-tabs button.on { color: #fff; background: var(--red); border-color: var(--red); }
  .grid-live .col.hide-mobile { display: none; }
}
