:root {
  --bg: #090b12;
  --panel: #111521;
  --panel-2: #151b2a;
  --line: #242b3c;
  --muted: #8f98ad;
  --text: #f4f7fb;
  --accent: #00d1b2;
  --accent-2: #19a7ff;
  --danger: #ff5c7a;
  --warn: #ffd166;
  --ok: #42d392;
  --rating-red: #ff5c7a;
  --rating-orange: #ffb45c;
  --rating-green: #42d392;
  --rating-violet: #c084fc;
  --pit: #5cc8ff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(25,167,255,.12), transparent 35rem),
    radial-gradient(circle at top right, rgba(0,209,178,.12), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
.shell { max-width: 1240px; margin: 0 auto; padding: 0 20px; }
.site-main { width: 100%; flex: 1 0 auto; padding-bottom: 28px; }
.footer { flex-shrink: 0; min-height: 28px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: rgba(9,11,18,.88);
  backdrop-filter: blur(12px);
}
.nav { height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; }
.brand-mark { width: 30px; height: 30px; color: var(--accent); }
.nav-links { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nav-links a { color: var(--muted); padding: 8px 10px; border-radius: 9px; font-weight: 650; }
.nav-links a.active, .nav-links a:hover { color: var(--text); background: var(--panel); }

.hero { padding: 28px 0 20px; }
.hero + .driver-session-summary { margin-top: -6px; }
.hero-card {
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(0,209,178,.12), transparent 42%),
    linear-gradient(45deg, rgba(255,255,255,.025) 25%, transparent 25%),
    var(--panel);
  background-size: auto, 18px 18px, auto;
  border-radius: 22px;
  padding: 28px;
}
h1, h2, h3 { margin: 0; letter-spacing: -.03em; }
h1 { font-size: 28px; }
h2 { font-size: 20px; margin: 28px 0 14px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.small { font-size: 12px; }

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  border: 1px solid var(--line);
  background: rgba(17,21,33,.88);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 18px 40px rgba(0,0,0,.18);
}
.error-page .hero-card,
.sync-login .hero-card {
  /*max-width: 720px;*/
}
.sync-login-card {
  max-width: 520px;
}
.stat-value { font-size: 24px; font-weight: 850; color: var(--accent); line-height: 1.1; }
.stat-label { color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .08em; margin-top: 5px; }

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}
.field { display: grid; gap: 6px; min-width: 160px; }
.field label { color: var(--muted); font-size: 12px; font-weight: 700; }
.field-check { min-width: auto; }
.filter-check {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0d111b;
  color: var(--text);
  padding: 8px 12px;
  font-weight: 750;
  white-space: nowrap;
}
.filter-check input { min-height: 0; width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
input, select {
  min-height: 38px;
  border: 1px solid var(--line);
  background: #0d111b;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
}
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 750;
  cursor: pointer;
}
.btn-primary, button[type=submit] { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #00110f; }
.btn-ghost {
  background: rgba(13, 17, 27, .58);
  border-color: rgba(255,255,255,.10);
}
.btn-ghost:hover,
.btn-ghost:focus {
  background: rgba(21, 27, 42, .88);
  border-color: rgba(0, 209, 178, .34);
  color: var(--text);
}

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: rgba(17,21,33,.75); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; background: rgba(255,255,255,.02); }
tr:hover td { background: rgba(255,255,255,.025); }
td.time, th.time { font-variant-numeric: tabular-nums; font-family: "SFMono-Regular", Consolas, monospace; white-space: nowrap; }
.leaderboard-table { min-width: 1120px; }
.leaderboard-table th:nth-child(3),
.leaderboard-table td:nth-child(3),
.leaderboard-table th:nth-child(10),
.leaderboard-table td:nth-child(10),
.leaderboard-table td:nth-child(10) a {
  white-space: nowrap;
}
.leaderboard-table .track-badge,
.leaderboard-table .track-name {
  white-space: nowrap;
}
.table-action { width: 72px; text-align: center; vertical-align: middle; }
.chart-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(0, 209, 178, .35);
  border-radius: 10px;
  background: rgba(0, 209, 178, .08);
  color: var(--accent);
  transition: background .16s ease, border-color .16s ease, transform .16s ease;
}
.chart-link:hover,
.chart-link:focus {
  background: rgba(0, 209, 178, .16);
  border-color: rgba(0, 209, 178, .65);
  transform: translateY(-1px);
}
.chart-link svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); background: #0d111b; color: var(--muted); font-size: 12px; font-weight: 700; }
.badge-ok { color: var(--ok); border-color: rgba(66,211,146,.35); }
.badge-warn { color: var(--warn); border-color: rgba(255,209,102,.35); }
.badge-danger { color: var(--danger); border-color: rgba(255,92,122,.35); }
.badge-score {
  min-width: 50px;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.car-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text);
}
.car-logo {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
  overflow: hidden;
}
.car-logo img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  display: block;
}
.car-logo-fallback {
  color: var(--accent);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .03em;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.car-name {
  min-width: 0;
}
.car-number {
  color: var(--muted);
  white-space: nowrap;
}
.track-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: inherit;
}
.track-flag {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
  font-size: 15px;
  line-height: 1;
}
.track-flag img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  display: block;
}
.track-flag-fallback {
  color: var(--accent);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .03em;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.track-name {
  min-width: 0;
}
h1 .track-badge,
.hero-card .track-badge,
.hero-card .car-badge {
  vertical-align: middle;
}
.score-red { color: var(--rating-red); border-color: rgba(255,92,122,.35); }
.score-orange { color: var(--rating-orange); border-color: rgba(255,180,92,.38); }
.score-green { color: var(--rating-green); border-color: rgba(66,211,146,.35); }
.score-violet { color: var(--rating-violet); border-color: rgba(192,132,252,.42); }
.score-empty { color: var(--muted); border-color: var(--line); }
.stat-value.score-red,
.metric-mini strong.score-red { color: var(--rating-red); }
.stat-value.score-orange,
.metric-mini strong.score-orange { color: var(--rating-orange); }
.stat-value.score-green,
.metric-mini strong.score-green { color: var(--rating-green); }
.stat-value.score-violet,
.metric-mini strong.score-violet { color: var(--rating-violet); }
.stat-value.score-empty,
.metric-mini strong.score-empty { color: var(--muted); }
.delta-time { font-weight: 800; }
.delta-value {
  color: var(--muted);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.delta-violet { color: var(--rating-violet); }
.delta-green { color: var(--rating-green); }
.delta-orange { color: var(--rating-orange); }
.delta-red { color: var(--rating-red); }
.delta-empty { color: var(--muted); }
.best-lap { color: var(--ok); font-weight: 850; }
.best-sector { color: #c084fc; font-weight: 850; }
.badge-pit { color: var(--pit); border-color: rgba(92,200,255,.42); }
.session-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}
.summary-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0d111b;
  padding: 13px 14px;
}
.summary-card span,
.summary-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.summary-card strong {
  display: block;
  margin: 4px 0 3px;
  color: var(--text);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.summary-card small {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.35;
}
.summary-card strong.score-red,
.summary-card b.score-red { color: var(--rating-red); }
.summary-card strong.score-orange,
.summary-card b.score-orange { color: var(--rating-orange); }
.summary-card strong.score-green,
.summary-card b.score-green { color: var(--rating-green); }
.summary-card strong.score-violet,
.summary-card b.score-violet { color: var(--rating-violet); }
.summary-card strong.score-empty,
.summary-card b.score-empty { color: var(--muted); }
.rating-legend {
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(192,132,252,.10), transparent 48%),
    rgba(17,21,33,.82);
  padding: 15px;
  margin: 14px 0;
}
.rating-legend-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.rating-legend-head p { max-width: 620px; margin: 0; }
.rating-legend-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.rating-legend-grid div {
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 12px;
  background: rgba(13,17,27,.72);
  padding: 12px;
}
.rating-legend-grid strong { display: block; margin-bottom: 5px; }
.rating-legend-grid p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.rating-scale {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.rating-scale-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0d111b;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
}
.rating-scale-item i {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}
.rating-scale-item i.score-red { background: var(--rating-red); }
.rating-scale-item i.score-orange { background: var(--rating-orange); }
.rating-scale-item i.score-green { background: var(--rating-green); }
.rating-scale-item i.score-violet { background: var(--rating-violet); }
.metric-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 16px 0; }
.metric-mini { border: 1px solid var(--line); border-radius: 12px; background: #0d111b; padding: 12px; }
.metric-mini strong { display: block; color: var(--text); font-size: 17px; font-variant-numeric: tabular-nums; font-family: "SFMono-Regular", Consolas, monospace; }
.metric-mini span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; margin-top: 4px; }

.driver-laps { margin-top: 14px; }
.driver-laps table { min-width: 980px; }
.lap-chart-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0d111b;
  padding: 14px;
  margin: 14px 0 0;
}
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.chart-head p { margin: 4px 0 0; }
.lap-chart-wrap { position: relative; width: 100%; height: 320px; max-height: 320px; }
.lap-chart { display: block; width: 100% !important; height: 100% !important; max-height: 320px; }
@media (max-width: 800px) {
  .lap-chart-wrap { height: 260px; max-height: 260px; }
}
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.rank-list { display: grid; gap: 10px; }
.rank-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 72px;
  border: 1px solid var(--line);
  background: rgba(17,21,33,.82);
  border-radius: 13px;
  padding: 11px;
}
.rank-number { color: var(--muted); font-weight: 850; font-variant-numeric: tabular-nums; }
.rank-title { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.rank-value { text-align: right; font-variant-numeric: tabular-nums; font-family: "SFMono-Regular", Consolas, monospace; color: var(--accent); font-weight: 850; }
.rank-title .car-badge,
.rank-title .track-badge {
  max-width: 100%;
  vertical-align: middle;
}
.rank-title .car-name,
.rank-title .track-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pagination { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 18px 0 4px; }
.page-link, .page-status {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: rgba(17,21,33,.78);
  color: var(--text);
  font-weight: 750;
}
.page-status { color: var(--muted); }

@media (max-width: 800px) {
  .nav { height: auto; padding: 12px 0; align-items: flex-start; flex-direction: column; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .session-summary { grid-template-columns: 1fr 1fr; }
  .metric-strip { grid-template-columns: 1fr 1fr; }
  .rating-legend-head { flex-direction: column; gap: 8px; }
  .rating-legend-grid { grid-template-columns: 1fr; }
  .hero-card { padding: 20px; }
  h1 { font-size: 23px; }
  .toolbar { align-items: stretch; }
  .field, .toolbar .btn, .toolbar button { width: 100%; }
  .hero-card p .btn { margin-top: 6px; }
  .chart-head { align-items: flex-start; flex-direction: column; }
  .rank-item { grid-template-columns: 28px minmax(0, 1fr); }
  .rank-value { grid-column: 2; text-align: left; }
}
