:root {
  --bg: #15151e;
  --bg-card: #1f1f2b;
  --bg-row: #262636;
  --fg: #ececf1;
  --fg-dim: #9a9aa8;
  --accent: #e10600;
  --accent-fg: #fff;
  --line: #33334a;
  --ok: #34c98e;
  --soft: #ff2d2d;
  --medium: #ffd12e;
  --hard: #d8d8e0;
  --intermediate: #43b02a;
  --wet: #0067ad;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; }

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.5rem;
  padding: 0.9rem 1.2rem;
  border-bottom: 2px solid var(--accent);
}

.site-header h1 { margin: 0; font-size: 1.25rem; letter-spacing: 0.02em; }
.accent { color: var(--accent); }

.home-link {
  flex-basis: 100%;
  font-size: 0.78rem;
  color: var(--fg-dim);
  text-decoration: none;
}
.home-link:hover { color: var(--fg); text-decoration: underline; }
@media (min-width: 640px) {
  .home-link { flex-basis: auto; margin-right: 0.5rem; }
  .site-header h1 { margin-right: auto; }
}

.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.tabs a {
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--fg-dim);
}
.tabs a.active { background: var(--accent); color: var(--accent-fg); }
.tabs a:hover:not(.active) { background: var(--bg-card); color: var(--fg); }

.theme-reset {
  font: inherit;
  font-size: 0.75rem;
  color: var(--fg-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  cursor: pointer;
}
.theme-reset:hover { color: var(--fg); border-color: var(--accent); }

.live-dot {
  display: inline-block;
  width: 0.55em; height: 0.55em;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 1.2s infinite;
  vertical-align: middle;
}
@keyframes pulse { 50% { opacity: 0.25; } }
.live-dot[hidden] { display: none; }

.mock-banner {
  background: #4a3b00;
  color: #ffe08a;
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
}

main { max-width: 980px; margin: 0 auto; padding: 1.2rem; }

.view h2 { margin: 0.2rem 0 1rem; font-size: 1.15rem; }
.muted { color: var(--fg-dim); }
.small { font-size: 0.82rem; }
.error-box {
  background: #3a1114; border: 1px solid #7a2229;
  padding: 0.8rem 1rem; border-radius: 8px;
}

table { width: 100%; border-collapse: collapse; margin-bottom: 1.5rem; }
th, td { text-align: left; padding: 0.45rem 0.6rem; }
thead th {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fg-dim); border-bottom: 1px solid var(--line);
}
tbody tr:nth-child(odd) { background: var(--bg-row); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.gp-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.gp-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.gp-card.past { opacity: 0.5; }
.gp-card.next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.gp-card-flag {
  width: 100%;
  height: 64px;
  object-fit: cover;
  object-position: center;
  display: block;
  background: var(--bg-row);
}
.gp-card-body { padding: 0.8rem 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.gp-card-top { display: flex; align-items: center; gap: 0.7rem; }
.gp-card-date {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--bg-row);
  line-height: 1.1;
  flex-shrink: 0;
}
.gp-card-date .month { font-size: 0.62rem; letter-spacing: 0.04em; color: var(--accent); font-weight: 700; }
.gp-card-date .day { font-size: 1.15rem; font-weight: 800; }
.gp-card-round { color: var(--fg-dim); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }
.gp-card-name { font-weight: 700; font-size: 1rem; line-height: 1.25; }
.gp-card-circuit { color: var(--fg-dim); font-size: 0.8rem; }

a.session-row {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
a.session-row:hover {
  background: var(--bg-row);
  border-color: var(--accent);
}

.back-link {
  display: inline-block;
  color: var(--fg-dim);
  text-decoration: none;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}
.back-link:hover { color: var(--fg); text-decoration: underline; }

.circuit-card-head { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.5rem; }
.circuit-flag { width: 40px; height: 27px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.circuit-name { font-weight: 700; }
.circuit-card p { margin: 0.3rem 0; }
.circuit-card a { color: var(--accent); }

.session-list { display: flex; flex-direction: column; gap: 0.5rem; }
.session-row {
  display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap;
}
.session-row .session-name { font-weight: 600; min-width: 10rem; }
.session-row.status-ao_vivo { border-color: var(--accent); }

.badge.status-ao_vivo { background: var(--accent); color: var(--accent-fg); animation: pulse 1.4s infinite; }
.badge.status-concluida { background: var(--line); color: var(--fg-dim); }
.badge.status-agendada { background: transparent; border: 1px solid var(--line); color: var(--fg-dim); }
.badge {
  display: inline-block;
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.1rem 0.45rem; border-radius: 4px;
  background: var(--line); color: var(--fg);
  vertical-align: middle;
}
.badge.sprint { background: #6b3fa0; }
.badge.est { background: #4a3b00; color: #ffe08a; }
.badge.new { background: #103a2a; color: var(--ok); }
.badge.current { background: var(--accent); color: var(--accent-fg); }
.badge.consolidated { background: #103a2a; color: var(--ok); }

.team-bar {
  display: inline-block; width: 4px; height: 1em;
  border-radius: 2px; margin-right: 0.5em; vertical-align: -0.12em;
  background: var(--fg-dim);
}

/* ── equipes e pilotos ── */
.teams-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.team-card {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  padding: 0;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.team-card:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--fg-dim); }
.team-card:disabled { cursor: default; opacity: 0.75; }
.team-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
  background: var(--line);
}
.team-card-title { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.team-card-name {
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.team-card-points { font-size: 0.78rem; opacity: 0.85; white-space: nowrap; flex-shrink: 0; }
.team-logo-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 6px;
  padding: 2px 6px;
  flex-shrink: 0;
  line-height: 0;
}
.team-logo { height: 20px; width: auto; max-width: 56px; object-fit: contain; display: block; }
.team-card-drivers { display: flex; gap: 0.7rem; padding: 0.9rem; }
.driver-chip { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; flex: 1; min-width: 0; }
.driver-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
  background: var(--bg-row);
}
.driver-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.8rem;
  background: var(--bg-row);
  color: var(--fg);
}
.driver-chip .driver-name {
  font-size: 0.72rem;
  text-align: center;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* ── pneus (resumo por padrão; detalhe por sessão ao clicar no piloto) ── */
.tyres-compact { display: flex; flex-direction: column; gap: 0.1rem; margin-top: 0.5rem; }
.tyres-item:nth-child(odd) .tyres-row { background: var(--bg-row); }
.tyres-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  width: 100%;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.tyres-row:hover { background: var(--line); }
.tyres-toggle { width: 0.8rem; flex-shrink: 0; color: var(--fg-dim); font-size: 0.65rem; }
.tyres-row .driver-label {
  font-weight: 700;
  font-size: 0.78rem;
  min-width: 3rem;
  flex-shrink: 0;
}
.tyres-counts { margin-left: auto; flex-shrink: 0; }
.tyres-detail {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.4rem 0.5rem 0.7rem 2.3rem;
}
.tyres-detail[hidden] { display: none; }
.tyres-session { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.tyres-session-name { font-size: 0.72rem; color: var(--fg-dim); min-width: 9rem; flex-shrink: 0; }
.tyres-stint { display: inline-flex; flex-direction: column; align-items: center; gap: 0.05rem; }
.tyres-stint-pace { font-size: 0.62rem; white-space: nowrap; }

/* resumo compacto na página do round */
.tyres-summary-card { display: flex; flex-direction: column; gap: 0.3rem; }
.tyres-summary-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.tyres-summary-toggle {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  padding: 0;
  cursor: pointer;
}
.tyres-summary-toggle:hover { text-decoration: underline; }

/* lista de uma sessão específica (página da sessão) */
.tyres-session-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  flex-wrap: wrap;
}
.tyres-compact > .tyres-session-row:nth-child(odd) { background: var(--bg-row); }
.tyres-chips-inline { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tyre-chip {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 0.08rem 0.4rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--fg-dim);
  cursor: default;
}
.tyre-chip.current { border-color: var(--accent); color: var(--fg); box-shadow: 0 0 0 1px var(--accent); }
.tyre-chip sup { margin-left: 0.1rem; color: var(--medium); }
.tyre-chip.SOFT { border-color: color-mix(in srgb, var(--soft) 50%, var(--line)); }
.tyre-chip.MEDIUM { border-color: color-mix(in srgb, var(--medium) 50%, var(--line)); }
.tyre-chip.HARD { border-color: color-mix(in srgb, var(--hard) 50%, var(--line)); }
.tyre-chip.INTERMEDIATE { border-color: color-mix(in srgb, var(--intermediate) 50%, var(--line)); }
.tyre-chip.WET { border-color: color-mix(in srgb, var(--wet) 50%, var(--line)); }
.tyre-chip.current.SOFT { border-color: var(--soft); }
.tyre-chip.current.MEDIUM { border-color: var(--medium); }
.tyre-chip.current.HARD { border-color: var(--hard); }
.tyre-chip.current.INTERMEDIATE { border-color: var(--intermediate); }
.tyre-chip.current.WET { border-color: var(--wet); }
.tyres-row .tyre-chip { font-size: 0.85rem; padding: 0.15rem 0.6rem; }

.compound {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6em; height: 1.6em; border-radius: 50%;
  font-size: 0.72rem; font-weight: 800; color: #111;
  border: 2px solid currentColor;
}
.compound.SOFT { background: var(--soft); color: #fff; border-color: var(--soft); }
.compound.MEDIUM { background: var(--medium); border-color: var(--medium); }
.compound.HARD { background: var(--hard); border-color: var(--hard); }
.compound.INTERMEDIATE { background: var(--intermediate); color: #fff; border-color: var(--intermediate); }
.compound.WET { background: var(--wet); color: #fff; border-color: var(--wet); }
.compound.UNKNOWN { background: var(--line); color: var(--fg); border-color: var(--line); }

/* ── comparativo de ritmo (Fase 4) ── */
.pace-controls { display: flex; align-items: center; gap: 0.5rem; margin: 0.5rem 0; }
.pace-driver-select {
  background: var(--bg-card); color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 0.3rem 0.5rem; font: inherit;
}
.pace-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.4rem; font-size: 0.8rem; }
.pace-legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.pace-legend-swatch {
  display: inline-block; width: 1.4rem; height: 3px; border-radius: 2px;
  background: var(--pace-swatch-color, var(--accent));
}
.pace-legend-swatch.dashed {
  background: repeating-linear-gradient(
    to right, var(--pace-swatch-color, var(--accent)) 0 4px, transparent 4px 7px);
}
.pace-chart-host { width: 100%; overflow-x: auto; }
.pace-chart { width: 100%; height: auto; min-width: 480px; }
.pace-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.pace-axis-label { font-size: 8px; fill: var(--fg-dim); }
.pace-line { opacity: 0.95; }
.pace-excluded-dot { fill: var(--fg-dim); opacity: 0.6; }

/* ── live ── */
.live-status { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; }
.rc-feed { list-style: none; padding: 0; margin: 0; }
.rc-feed li { padding: 0.3rem 0; border-bottom: 1px solid var(--line); font-size: 0.85rem; }
.rc-feed time { color: var(--fg-dim); margin-right: 0.6em; font-variant-numeric: tabular-nums; }
.stale-banner { color: var(--medium); }

/* ── home ── */
.home-countdown-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-top: 0.4rem;
}
@media (min-width: 640px) {
  .home-countdown-value { font-size: 2rem; }
}

.impact-summary {
  border-left: 3px solid var(--accent);
}
.impact-summary p { margin: 0.3rem 0; }
.impact-summary p:first-child { margin-top: 0; }
.impact-summary p:last-child { margin-bottom: 0; }

.delta-up { color: var(--ok); font-variant-numeric: tabular-nums; }
.delta-down { color: var(--soft); font-variant-numeric: tabular-nums; }

.battles-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.7rem;
  margin-top: 1rem;
  margin-bottom: 1.5rem;
}
@media (min-width: 640px) {
  .battles-list { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}
.battle-card { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0; }
.battle-title { font-weight: 700; }

/* ── piloto favorito (Fase 3) ── */
.favorite-section { margin-bottom: 1.2rem; }
.favorite-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.favorite-chip {
  font: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--fg-dim);
  cursor: pointer;
}
.favorite-chip:hover { border-color: var(--accent); color: var(--fg); }
.favorite-chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.favorite-edit-toggle {
  font: inherit;
  font-size: 0.78rem;
  background: none;
  border: none;
  color: var(--fg-dim);
  cursor: pointer;
  padding: 0.2rem 0;
  margin-top: 0.4rem;
}
.favorite-edit-toggle:hover { color: var(--fg); text-decoration: underline; }
.favorite-edit-picker { margin-top: 0.4rem; }

.favorite-hero-list { display: grid; grid-template-columns: 1fr; gap: 0.7rem; margin-bottom: 0.5rem; }
@media (min-width: 640px) {
  .favorite-hero-list { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}
.favorite-hero { border-left: 3px solid var(--accent); display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0; }
.favorite-hero-head { display: flex; align-items: center; gap: 0.5rem; font-size: 1rem; }

/* ── live: timeline narrada + destaque de favorito (Fase 3) ── */
.live-hero { margin-bottom: 1rem; }
.live-timeline {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 1.2rem;
  max-height: 14rem;
  overflow-y: auto;
}
.timeline-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  font-size: 0.85rem;
}
.timeline-row:nth-child(odd) { background: var(--bg-row); }
.timeline-row.favorite-event { border-left: 3px solid var(--accent); }
.timeline-icon { flex-shrink: 0; }
.timeline-time { font-variant-numeric: tabular-nums; flex-shrink: 0; }
tr.favorite-row { box-shadow: inset 3px 0 0 var(--accent); }
tr.favorite-row td:first-child { font-weight: 800; }

.debug-download-btn {
  font: inherit;
  font-size: 0.78rem;
  margin-top: 0.8rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px dashed var(--line);
  color: var(--fg-dim);
  cursor: pointer;
}
.debug-download-btn:hover { border-color: var(--accent); color: var(--fg); }

.site-footer {
  max-width: 980px; margin: 2rem auto 0; padding: 1rem 1.2rem 2rem;
  color: var(--fg-dim); font-size: 0.78rem;
  border-top: 1px solid var(--line);
}

@media (max-width: 600px) {
  main { padding: 0.8rem; }
  th, td { padding: 0.35rem 0.4rem; }
}
