@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700;900&family=Barlow+Condensed:wght@400;700;900&display=swap');

.page-loader {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg, #0a0a0a);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s;
}
.page-loader.fade-out {
  opacity: 0;
  pointer-events: none;
}
.loader-content {
  text-align: center;
}

:root {
  --red: #e10600;
  --red-dark: #a00400;
  --bg: #0a0a0a;
  --bg2: #111111;
  --bg3: #1a1a1a;
  --bg4: #222222;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --text-muted: #888;
  --accent: #e10600;
  --green: #00d2be;
  --yellow: #ffd700;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
}

/* HEADER */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 60px;
  background: var(--bg2);
  border-bottom: 2px solid var(--red);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 5px;
  color: var(--text);
  user-select: none;
}

.logo-f1 {
  color: var(--red);
  letter-spacing: 2px;
}

nav { display: flex; gap: 0.5rem; }

.nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 1.2rem;
  border-radius: 4px;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn:hover { border-color: var(--red); color: var(--text); }
.nav-btn.active { background: var(--red); border-color: var(--red); color: #fff; }

/* CONTROLS */
.controls-bar {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.2rem 2rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.control-group label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
}

select, input[type="range"] {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.8rem;
  border-radius: 4px;
  font-size: 0.9rem;
  min-width: 160px;
  cursor: pointer;
  transition: border-color 0.2s;
}

select:hover, select:focus { border-color: var(--red); outline: none; }
select:disabled { opacity: 0.4; cursor: not-allowed; }

input[type="range"] {
  padding: 0;
  height: 36px;
  min-width: 120px;
  accent-color: var(--red);
}

input[type="range"]:disabled { opacity: 0.4; }

#btn-load {
  background: var(--red);
  border: none;
  color: #fff;
  padding: 0.5rem 1.8rem;
  border-radius: 4px;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 2px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  align-self: flex-end;
}

#btn-load:hover { background: var(--red-dark); }
#btn-load:active { transform: scale(0.97); }
#btn-load:disabled { opacity: 0.4; cursor: not-allowed; }

/* MAIN */
main { padding: 1.5rem 2rem; }

/* INFO BAR */
.info-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.info-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 1.2rem;
  min-width: 130px;
}

.info-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.info-value {
  display: block;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

/* CHARTS */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.chart-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem;
}

.chart-card.span-2 { grid-column: span 2; }

.standings-row {
  display: flex;
  gap: 1.5rem;
  margin-top: 1.5rem;
}
.standings-half {
  flex: 1;
  min-width: 0;
}
.standings-half table {
  width: 100%;
  font-size: 0.8rem;
}
.standings-half td, .standings-half th {
  padding: 0.35rem 0.5rem;
}
.standings-scroll {
  max-height: 480px;
  overflow-y: auto;
}
.standings-scroll::-webkit-scrollbar { width: 5px; }
.standings-scroll::-webkit-scrollbar-track { background: var(--bg2); }
.standings-scroll::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

.champ-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.champ-toggle-btn {
  padding: 0.3rem 0.8rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.champ-toggle-btn.active {
  background: var(--red);
  color: #fff;
}
.champ-toggle-btn:hover:not(.active) {
  background: rgba(255,255,255,0.05);
}

.champ-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.champ-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid;
  transition: opacity 0.15s;
  user-select: none;
}
.champ-chip.off {
  opacity: 0.25;
}
.champ-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.news-bar {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}
.news-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}
.news-bar-header h3 { margin: 0; }
.news-source {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.news-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.news-item {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  text-decoration: none;
  color: var(--text);
  transition: color 0.15s;
}
.news-item:last-child { border-bottom: none; }
.news-item:hover { color: var(--red); }
.news-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
  margin-top: 5px;
}
.news-title {
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.3;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.chart-header h3 { margin-bottom: 0; }

.chart-toggles {
  display: flex;
  gap: 1rem;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] { display: none; }

.toggle-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  opacity: 0.4;
  transition: opacity 0.2s;
}

.toggle-label:has(input:checked) { color: var(--text); }
.toggle-label:has(input:checked) .toggle-dot { opacity: 1; }

.toggle-dot.drs   { background: linear-gradient(to bottom, rgba(255,255,255,0.85) 50%, rgba(255,255,255,0.15) 50%); }
.toggle-dot.brake { background: linear-gradient(to bottom, rgba(255,255,255,0.15) 50%, rgba(255,255,255,0.85) 50%); }

.chart-card h3 {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 0.8rem;
}

.unit {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0;
}

/* RESULTS TABLE */
#results-table-wrap {
  overflow-x: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.results-table th {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}

.results-table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.results-table tr:hover td { background: var(--bg3); }

.team-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.pos-badge {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-muted);
}

.pos-badge.gold { color: var(--yellow); }
.pos-badge.silver { color: #c0c0c0; }
.pos-badge.bronze { color: #cd7f32; }

/* STATES */
.hidden { display: none !important; }
.view { }

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem;
  color: var(--text-muted);
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  background: #2a0a0a;
  border: 1px solid var(--red);
  color: #ff6b6b;
  border-radius: 6px;
  padding: 1rem 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* ── Compare top layout ── */
.cmp-top-layout {
  display: flex;
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1.5rem;
}

.cmp-drivers-table {
  flex: 1;
  min-width: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.cmp-table { display: flex; flex-direction: column; }

.cmp-row {
  display: grid;
  grid-template-columns: 200px repeat(6, 1fr);
}

.cmp-row + .cmp-row { border-top: 1px solid var(--border); }

.cmp-header .cmp-cell {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.55rem 1rem;
  background: var(--bg3);
}

.cmp-row:not(.cmp-header) .cmp-cell {
  padding: 0.7rem 1rem;
  font-size: 0.88rem;
  color: var(--text);
}

.cmp-name {
  border-left: 4px solid var(--dcolor, var(--border));
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.cmp-fullname {
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0;
}

/* ── Track map ── */
.cmp-track-card {
  width: 100%;
  margin-bottom: 1rem;
}

#cmp-track-map,
#yrs-track-map {
  display: block;
  width: 100%;
  height: 320px;
  cursor: crosshair;
}

#cmp-track-tooltip,
#yrs-track-tooltip,
#chart-cmp-speed-tooltip,
#chart-yrs-speed-tooltip {
  position: fixed;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  font-size: 0.82rem;
  line-height: 1.6;
  pointer-events: none;
  z-index: 300;
  display: none;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* ── Compare pilot panel ── */
.cmp-pilot-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}

#cmp-drivers-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

/* ── Compare driver rows ── */
.cmp-driver-row {
  display: flex;
  gap: 0.8rem;
  align-items: flex-end;
}

.cmp-lap-group input[type="range"] {
  min-width: 120px;
}

/* ── Icon buttons (× e + Piloto) ── */
.btn-icon {
  width: 36px;
  height: 36px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  flex-shrink: 0;
}
.btn-icon:hover { border-color: var(--red); color: var(--text); }

.btn-add-driver {
  background: var(--bg3);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  padding: 0.3rem 0.9rem;
  border-radius: 4px;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-add-driver:hover { border-color: var(--red); color: var(--text); }

.btn-load-inline {
  background: var(--red);
  border: none;
  color: #fff;
  padding: 0.5rem 1.8rem;
  border-radius: 4px;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 2px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  align-self: flex-end;
}
.btn-load-inline:hover { background: var(--red-dark); }
.btn-load-inline:active { transform: scale(0.97); }
.btn-load-inline:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Summary view ── */
.sum-hero {
  display: flex;
  gap: 1.5rem;
  align-items: flex-end;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem 2rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.sum-event { flex: 1; min-width: 200px; }

.sum-round-badge {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--red);
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

.sum-gp-name {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--text);
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}

.sum-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* Podium */
.sum-podium {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.podium-place {
  background: var(--bg3);
  border-radius: 6px 6px 0 0;
  padding: 0.8rem 1rem 0.6rem;
  min-width: 130px;
  text-align: center;
  border-top: 3px solid var(--border);
}

.podium-place.p1 { padding-top: 1.6rem; }
.podium-place.p2 { padding-top: 1rem; }
.podium-place.p3 { padding-top: 0.5rem; }

.podium-pos {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 2rem;
  font-weight: 900;
  color: var(--text-muted);
  line-height: 1;
}
.podium-place.p1 .podium-pos { color: var(--yellow); }
.podium-place.p2 .podium-pos { color: #c0c0c0; }
.podium-place.p3 .podium-pos { color: #cd7f32; }

.podium-driver {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.2rem;
}
.podium-name  { font-size: 0.72rem; color: var(--text-muted); margin: 0.1rem 0; }
.podium-team  { font-size: 0.72rem; font-weight: 600; margin-bottom: 0.3rem; }
.podium-time  { font-size: 0.78rem; color: var(--text-muted); font-family: 'Barlow Condensed', sans-serif; }

/* Timeline */
.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.timeline-item {
  display: grid;
  grid-template-columns: 48px 22px 1fr;
  gap: 0.4rem;
  align-items: center;
  padding: 0.45rem 0.6rem;
  border-left: 3px solid var(--border);
  font-size: 0.8rem;
}

.timeline-item + .timeline-item { border-top: 1px solid rgba(255,255,255,0.03); }

.tl-time  { font-family: 'Barlow Condensed', sans-serif; font-size: 0.78rem; color: var(--text-muted); text-align: right; }
.tl-icon  { text-align: center; font-size: 0.85rem; }
.tl-text  { color: var(--text); line-height: 1.3; }

.tl-sc     { border-left-color: #ff8c00; }
.tl-sc     .tl-text { color: #ff8c00; }
.tl-vsc    { border-left-color: #ffd700; }
.tl-vsc    .tl-text { color: #ffd700; }
.tl-red    { border-left-color: var(--red); background: rgba(225,6,0,0.06); }
.tl-red    .tl-text { color: #ff6b6b; }
.tl-penalty{ border-left-color: #a855f7; }
.tl-penalty .tl-text { color: #c084fc; }
.tl-green  { border-left-color: var(--green); }
.tl-green  .tl-text { color: var(--green); }

/* Grid gain/loss in results */
.gain  { color: var(--green); font-size: 0.78rem; }
.loss  { color: var(--red);   font-size: 0.78rem; }
.same  { color: var(--text-muted); font-size: 0.78rem; }

@media (max-width: 900px) {
  .standings-row {
    flex-direction: column;
    gap: 1rem;
  }
}

@media (max-width: 768px) {
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card.span-2 { grid-column: span 1; }

  header {
    padding: 0.5rem 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  header nav {
    gap: 0.3rem;
    flex-wrap: wrap;
  }
  .nav-btn {
    font-size: 0.65rem;
    padding: 0.3rem 0.6rem;
  }
  .logo { font-size: 1.2rem; }

  .controls-bar {
    padding: 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .control-group select { min-width: 100px; font-size: 0.75rem; }

  main { padding: 0.75rem; }

  .chart-card { padding: 0.8rem; }
  .chart-card h3 { font-size: 0.85rem; }

  /* News bar compact */
  .news-bar { padding: 0.75rem; }
  .news-title { font-size: 0.72rem; }

  /* Championship toggle */
  .champ-toggle-btn { padding: 0.25rem 0.5rem; font-size: 0.65rem; }
  .champ-chip { font-size: 0.6rem; padding: 2px 5px; }

  /* Standings side by side → stacked */
  .standings-row {
    flex-direction: column;
    gap: 1rem;
  }
  .standings-scroll { max-height: none; }

  /* Summary hero */
  .sum-hero { flex-direction: column; gap: 1rem; }
  .sum-podium { justify-content: center; }
  .info-bar { grid-template-columns: repeat(2, 1fr); }

  /* Results table scroll */
  .results-table { font-size: 0.7rem; }
  .results-table th, .results-table td { padding: 0.3rem 0.4rem; }

  /* Compare panel */
  .cmp-pilot-panel { padding: 0.75rem; }
  .cmp-drivers-table { overflow-x: auto; }
}

@media (max-width: 480px) {
  header nav { width: 100%; justify-content: center; }
  .logo { font-size: 1rem; }
  .nav-btn { font-size: 0.6rem; padding: 0.25rem 0.5rem; }

  .info-bar { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .chart-card { padding: 0.6rem; }

  .news-bar-header h3 { font-size: 0.85rem; }
  .news-item { padding: 0.3rem 0; }
  .news-title { font-size: 0.68rem; }

  .champ-chip { font-size: 0.55rem; padding: 2px 4px; }
}
