/* Head to Head — two drivers, one shared track per metric. */

.h2h-controls {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-7);
}

.h2h-pick {
  background: var(--panel);
  color: var(--ink-0);
  border: var(--border) solid var(--surface-3);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  min-width: 16rem;
  cursor: pointer;
}

.h2h-vs {
  font-family: var(--font-display);
  font-stretch: var(--stretch-display);
  color: var(--ink-2);
  font-size: var(--text-sm);
}

.h2h-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2.2fr) minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}

.h2h-middle {
  display: grid;
  gap: var(--space-5);
  min-width: 0;
}

/* --- Nameplates ---------------------------------------------------------- */

.h2h-plate {
  border-top: var(--space-1) solid var(--c);
  padding-top: var(--space-4);
}

.h2h-plate[data-side="b"] { text-align: right; }

.h2h-photo {
  width: 100%;
  max-width: 14rem;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: top center;
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: var(--space-3);
}

.h2h-plate[data-side="b"] .h2h-photo { margin-inline-start: auto; }

.h2h-plate-name {
  font-family: var(--font-display);
  font-stretch: var(--stretch-display);
  font-weight: 700;
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
}

.h2h-plate-team {
  font-size: var(--text-sm);
  color: var(--ink-2);
  margin-top: var(--space-1);
}

.h2h-plate-best {
  font-size: var(--text-xs);
  color: var(--ink-2);
  margin-top: var(--space-2);
  font-variant-numeric: tabular-nums;
}

/* --- Scoreline ------------------------------------------------------------
   The headline number: shared grands prix each driver finished ahead in. */

.h2h-score {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  justify-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-5);
  border-bottom: var(--hairline) solid var(--surface-2);
}

.h2h-score-val {
  font-family: var(--font-mono);
  font-size: var(--text-display);
  font-weight: 700;
  line-height: var(--leading-tight);
  font-variant-numeric: tabular-nums;
}

.h2h-score-dash {
  color: var(--ink-2);
  font-size: var(--text-xl);
}

.h2h-score-cap {
  grid-column: 1 / -1;
  color: var(--ink-2);
  font-size: var(--text-xs);
  text-align: center;
  text-wrap: balance;
}

/* --- Bars ---------------------------------------------------------------- */

.h2h-bars { margin: 0; }

.h2h-metric {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--ink-2);
  margin-top: var(--space-5);
}

.h2h-row {
  display: grid;
  grid-template-columns: 5rem 1fr 5rem;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-2) 0 0;
}

.h2h-val { font-size: var(--text-base); color: var(--ink-2); }
.h2h-row .h2h-val:first-child { text-align: right; }
.h2h-row .h2h-val:last-child { text-align: left; }

/* The leader is marked by weight and lightness, never by a semantic hue. */
.h2h-val[data-lead="true"] { color: var(--ink-0); font-weight: 700; }

.h2h-track {
  position: relative;
  height: var(--space-3);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}

.h2h-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  /* Animates on every redraw, because the change IS the information. */
  transition: transform var(--dur-base) var(--ease-out-expo);
}

.h2h-fill[data-side="a"] {
  left: 0;
  transform-origin: left;
}

.h2h-fill[data-side="b"] {
  right: 0;
  transform-origin: right;
}

/* --- Round-by-round ledger ------------------------------------------------
   One cell per shared grand prix. The livery says which team, the initials say
   which driver — the meaning survives with colour removed. */

.h2h-ledger-box { margin-top: var(--space-7); }

.h2h-ledger-cap {
  font-size: var(--text-xs);
  color: var(--ink-2);
  margin-bottom: var(--space-3);
}

.h2h-ledger {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(3.5rem, 1fr));
  gap: var(--space-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.h2h-round {
  --c: var(--surface-3);
  display: grid;
  gap: var(--space-1);
  justify-items: center;
  padding: var(--space-3) var(--space-2);
  background: var(--panel);
  border-block-end: var(--space-1) solid var(--c);
  border-radius: var(--radius-sm);
  cursor: default;
}

.h2h-round-no {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-2);
}

.h2h-round-who {
  font-family: var(--font-display);
  font-stretch: var(--stretch-display);
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--ink-0);
}

/* No winner: a dead heat, or a round one of them never started. Reads as
   absence rather than as a third team. */
.h2h-round[data-ahead="tie"] .h2h-round-who,
.h2h-round[data-ahead="none"] .h2h-round-who { color: var(--ink-2); }

@media (max-width: 60rem) {
  .h2h-stage { grid-template-columns: 1fr; }
  .h2h-plate[data-side="b"] { text-align: left; }
  .h2h-plate[data-side="b"] .h2h-photo { margin-inline-start: 0; }
  .h2h-photo { max-width: 10rem; }
  .h2h-row { grid-template-columns: 4rem 1fr 4rem; }
  .h2h-pick { min-width: 0; flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .h2h-fill { transition: none; }
}
