:root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --grid: #e8e7e2;
  --track: #c9c8c2;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --series-1: #2a78d6; /* velocidad */
  --series-throttle: #1baf7a; /* slot 3 */
  --series-brake: #eb6834; /* slot 2 */
  --accent: #2a78d6;
  --best: #7b3fc4;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --grid: #2a2a27;
    --track: #4a4a45;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --series-1: #3987e5;
    --series-throttle: #199e70;
    --series-brake: #d95926;
    --accent: #3987e5;
    --best: #b18cf0;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-0: #111110;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #2f2f2c;
  --grid: #2a2a27;
  --track: #4a4a45;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --series-1: #3987e5;
  --series-throttle: #199e70;
  --series-brake: #d95926;
  --accent: #3987e5;
  --best: #b18cf0;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
}
h1 {
  font-size: 18px;
}
h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
h3 {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 14px 0 6px;
}
.muted {
  color: var(--text-muted);
}
.num,
.board td,
.tile__value,
.kv strong {
  font-variant-numeric: tabular-nums;
}

/* ---------- Barra superior ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.session {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
  min-width: 0;
}
.status-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.kv {
  font-size: 13px;
}
.badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.badge--live {
  background: var(--critical);
  color: #fff;
}
.flag {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 13px;
}
.flag--good .flag__icon {
  color: var(--good);
}
.flag--warning .flag__icon {
  color: var(--warning);
}
.flag--critical .flag__icon {
  color: var(--critical);
}
.flag--neutral .flag__icon {
  color: var(--text-muted);
}

/* ---------- Layout ---------- */
.grid {
  display: grid;
  gap: 12px;
  padding: 12px 16px 24px;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  grid-template-areas:
    'board map'
    'board tele'
    'rc weather';
}
.panel--board {
  grid-area: board;
}
.panel--map {
  grid-area: map;
}
.panel--tele {
  grid-area: tele;
  position: relative;
}
.panel--rc {
  grid-area: rc;
}
.panel--weather {
  grid-area: weather;
}
@media (max-width: 980px) {
  .grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'board' 'map' 'tele' 'rc' 'weather';
  }
}
.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  min-width: 0;
}
.panel__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
select {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font: inherit;
}
.hint {
  font-size: 12px;
  margin: 8px 0 0;
}

/* ---------- Tabla de posiciones ---------- */
.table-wrap {
  overflow-x: auto;
}
.board {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.board th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.board td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
.board tbody tr {
  cursor: pointer;
}
.board tbody tr:hover {
  background: var(--surface-2);
}
.board tbody tr.is-selected {
  background: var(--surface-2);
  box-shadow: inset 3px 0 0 var(--accent);
}
.board tr.is-out td {
  color: var(--text-muted);
}
.driver {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.driver__bar {
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: var(--text-muted);
}
.driver__team {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}
.best {
  color: var(--best);
  font-weight: 700;
}
.delta-up {
  color: var(--good);
}
.delta-down {
  color: var(--critical);
}
.tyre {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tyre__dot {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  font-size: 10px;
  font-weight: 800;
}
.tyre--SOFT .tyre__dot {
  border-color: #e34948;
}
.tyre--MEDIUM .tyre__dot {
  border-color: #eda100;
}
.tyre--HARD .tyre__dot {
  border-color: #c3c2b7;
}
.tyre--INTERMEDIATE .tyre__dot {
  border-color: #0ca30c;
}
.tyre--WET .tyre__dot {
  border-color: #2a78d6;
}

/* ---------- Mapa ---------- */
.map {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  border-radius: 8px;
  background: var(--surface-1);
}

/* ---------- Telemetría ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0 12px;
}
.tiles--compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 560px) {
  .tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.tile {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.tile__label {
  font-size: 11px;
  color: var(--text-muted);
}
.tile__value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}
.tile__unit {
  font-size: 11px;
  color: var(--text-muted);
}
.chart {
  margin-top: 8px;
}
.chart__title {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.chart__canvas {
  width: 100%;
  height: 130px;
  display: block;
  touch-action: none;
}
.legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}
.legend__key {
  width: 14px;
  height: 2px;
  border-radius: 1px;
}
.legend__key--throttle {
  background: var(--series-throttle);
}
.legend__key--brake {
  background: var(--series-brake);
}
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.2);
  min-width: 150px;
  z-index: 3;
}
.tooltip__row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.tooltip__row strong {
  font-variant-numeric: tabular-nums;
}
.tooltip__key {
  width: 12px;
  height: 2px;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}

/* ---------- Race control / radio ---------- */
.rc-list,
.radio-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 340px;
  overflow-y: auto;
}
.rc-list li {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 4px 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--grid);
  font-size: 13px;
}
.rc-time,
.rc-lap {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.rc-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-secondary);
  margin-right: 6px;
}
.radio-list {
  max-height: 200px;
}
.radio-list li {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  font-size: 12px;
}
.radio-list audio {
  height: 28px;
  max-width: 220px;
}
