:root {
  color-scheme: dark;
  --bg: #090b10;
  --panel: #111625;
  --panel-border: #1e2740;
  --text: #f4f7ff;
  --muted: #a9b5d4;
  --live: #4fd188;
  --warn: #ffb84d;
  --off: #ff7f7f;
  --driver-number-slot-size: 1.75rem;
  --driver-number-image-max-height: 20px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  border-bottom: 1px solid var(--panel-border);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 0.8rem;
  gap: 0.75rem;
}

h1,
h2,
p,
ol {
  margin: 0;
}

h1 {
  font-size: 1rem;
  letter-spacing: 0.03em;
}

h2 {
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status {
  display: inline-flex;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
}

.header-right {
  text-align: right;
}

.header-meta-row {
  margin-top: 0.12rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.status-detail {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.03em;
}

.status-detail-flag-yellow,
.status-detail-neutralised {
  color: var(--warn);
}

.status-detail-flag-red {
  color: var(--off);
}

.status-detail-live {
  color: var(--live);
}

.countdown {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.5rem;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(30, 39, 64, 0.45);
  font-size: 0.72rem;
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status-live {
  color: var(--live);
}

.status-reconnecting {
  color: var(--warn);
}

.status-neutralised,
.status-flag-yellow {
  color: #101010;
  background: var(--warn);
  border-radius: 999px;
  padding: 0.18rem 0.5rem;
}

.status-flag-red {
  color: #ffffff;
  background: #cf3f3f;
  border-radius: 999px;
  padding: 0.18rem 0.5rem;
}

.status-offline {
  color: var(--off);
}

.status-waiting {
  color: var(--muted);
}

.view-root {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.latest-section {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-bottom: 1px solid var(--panel-border);
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.8rem;
}

.latest-laps-list,
.leaderboard-list {
  list-style: none;
  padding: 0 0.5rem 0.5rem;
  margin: 0;
  overflow: auto;
  min-height: 0;
  flex: 1 1 auto;
}

.lap-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: start;
  border-top: 1px solid var(--panel-border);
  padding: 0.55rem 0.35rem;
  font-size: 0.85rem;
}

@keyframes lapRowPulse {
  0% {
    background-color: transparent;
  }

  35% {
    background-color: rgba(255, 255, 255, 0.08);
  }

  100% {
    background-color: transparent;
  }
}

.lap-row-pulse-latest,
.lap-row-pulse-leaderboard {
  animation: lapRowPulse 0.5s ease-out 1;
}

.lap-row:first-child {
  border-top: 0;
}

.driver-stack {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.driver-meta {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.driver-team-dot {
  width: 0.55rem;
  height: 0.55rem;
  flex: 0 0 0.55rem;
  border-radius: 999px;
  background: var(--muted);
}

.driver-indicators {
  display: inline-flex;
  align-items: center;
  gap: 0.18rem;
  flex: 0 0 auto;
}

.driver-number {
  color: var(--muted);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.driver-number-slot {
  width: var(--driver-number-slot-size);
  height: var(--driver-number-slot-size);
  flex: 0 0 var(--driver-number-slot-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  overflow: hidden;
}

.driver-number-image {
  max-height: var(--driver-number-image-max-height);
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.driver-number-slot-fallback .driver-number-fallback {
  display: inline-block;
  text-align: center;
  line-height: 1;
  font-size: 0.72rem;
}

.tyre-badge {
  width: 0.825rem;
  height: 0.825rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1.5px solid currentColor;
  font-size: 7px;
  font-weight: bold;
  line-height: 1;
  text-transform: uppercase;
  background: transparent;
  top: -3px;
  position: relative;
}

.tyre-badge-soft {
  color: #ff5f5f;
}

.tyre-badge-medium {
  color: #ffd84d;
}

.tyre-badge-hard {
  color: #ffffff;
}

.tyre-badge-unknown {
  color: var(--muted);
}

.pit-stop-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.16rem;
  margin-left: 0.05rem;
}

.pit-stop-dot {
  width: 0.28rem;
  height: 0.28rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
}

.driver-name {
  font-weight: 700;
}

.driver-name-elimination-risk {
  color: var(--off);
}

.driver-name-short {
  display: none;
  letter-spacing: 0.04em;
}

.driver-team {
  color: var(--muted);
  font-size: 0.76rem;
}

.sector-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: flex-end;
}

.sector-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.08rem 0.3rem;
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--panel-border);
}

.sector-pill-pending {
  color: var(--muted);
}

.sector-pill-slower {
  color: #1b1b1b;
  background: var(--warn);
  border-color: var(--warn);
}

.sector-pill-personal {
  color: #07170d;
  background: var(--live);
  border-color: var(--live);
}

.sector-pill-overall {
  color: #f4ecff;
  background: #9d67ff;
  border-color: #9d67ff;
}

.lap-time {
  font-variant-numeric: tabular-nums;
}

.lap-time-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  min-width: 0;
}

.lap-time {
  font-weight: 700;
  white-space: nowrap;
}

.lap-gap {
  color: var(--muted);
  font-size: 0.74rem;
  white-space: nowrap;
}

.empty-message {
  color: var(--muted);
  padding: 0.6rem 0.8rem 0.8rem;
  font-size: 0.82rem;
}

.leaderboard-section {
  flex: 0 0 35vh;
  min-height: 35vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: flex-basis 180ms ease;
  border-bottom: 1px solid var(--panel-border);
}

.leaderboard-section.is-expanded {
  flex-basis: 80vh;
}

.leaderboard-toggle {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: transparent;
  border-radius: 999px;
  width: 1.9rem;
  height: 1.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  position: relative;
}

.leaderboard-toggle:hover {
  border-color: #2c3960;
}

.leaderboard-toggle::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid #ffffff;
  border-bottom: 2px solid #ffffff;
  transform: translateY(-1px) rotate(-135deg);
  transform-origin: center;
  transition: transform 180ms ease;
  margin-top: 5px;
}

.is-expanded .leaderboard-toggle::before {
  margin-top: -2px;
}

.leaderboard-toggle[aria-expanded="true"]::before {
  transform: translateY(-1px) rotate(45deg);
}

.leaderboard-toggle:focus-visible {
  outline: 2px solid #2f6cff;
  outline-offset: 1px;
}

.idle-view {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.race-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.race-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
  padding: 0.75rem 0.8rem;
  border-bottom: 1px solid var(--panel-border);
}

.race-summary-item {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.race-summary-label {
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.race-summary-value {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.race-board {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.race-board-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(5.5rem, auto) minmax(5.5rem, auto);
  gap: 0.75rem;
  padding: 0.15rem 0.85rem 0.4rem;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.race-board-column-gap {
  text-align: right;
}

.race-list {
  list-style: none;
  padding: 0 0.5rem 0.5rem;
  margin: 0;
  overflow: auto;
  min-height: 0;
  flex: 1 1 auto;
}

.race-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(5.5rem, auto) minmax(5.5rem, auto);
  gap: 0.75rem;
  align-items: center;
  border-top: 1px solid var(--panel-border);
  padding: 0.6rem 0.35rem;
}

.race-row:first-child {
  border-top: 0;
}

.race-row-battle {
  background: rgba(255, 184, 77, 0.08);
  box-shadow: inset 3px 0 0 var(--warn);
  animation: raceBattlePulse 1s ease-in-out infinite alternate;
}

@keyframes raceBattlePulse {
  0% {
    background-color: rgba(255, 184, 77, 0.05);
  }

  100% {
    background-color: rgba(255, 184, 77, 0.12);
  }
}

.race-row-position-change {
  animation: racePositionChangeFade 3s ease-out 1;
}

.race-row-position-change .race-driver-names,
.race-row-position-change .race-gap {
  font-weight: 700;
}

@keyframes racePositionChangeFade {
  0% {
    background-color: rgba(79, 209, 136, 0.16);
  }

  100% {
    background-color: transparent;
  }
}

.race-row-position-change-down {
  animation-name: racePositionChangeFadeDown;
}

@keyframes racePositionChangeFadeDown {
  0% {
    background-color: rgba(255, 127, 127, 0.14);
  }

  100% {
    background-color: transparent;
  }
}

.race-driver-cell {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.16rem;
}

.race-driver-identity {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.race-position {
  width: 1.4rem;
  color: var(--muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex: 0 0 1.4rem;
}

.race-driver-names {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.race-position-change {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1rem;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
}

.race-position-change-up {
  color: var(--live);
}

.race-position-change-down {
  color: var(--off);
}

.race-lap-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0.08rem 0.32rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.race-lap-badge-overall {
  color: #f4ecff;
  background: #9d67ff;
}

.race-gap-cell {
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  text-align: right;
}

.race-gap {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.race-gap-cell-leader .race-gap {
  font-weight: 700;
}

.race-gap-cell-ahead .race-gap {
  color: var(--muted);
  font-size: 0.75rem;
}

@media (max-width: 720px) {
  :root {
    --driver-number-slot-size: 1.55rem;
  }

  .driver-name-full,
  .driver-team {
    display: none;
  }

  .driver-name-short {
    display: inline;
  }

  .lap-row {
    grid-template-columns: 1fr auto;
    gap: 0.4rem;
    font-size: 0.8rem;
  }

  .sector-pill {
    padding: 0.06rem 0.3rem;
    font-size: 0.64rem;
  }

  .lap-time-wrap {
    gap: 0.25rem;
  }

  .race-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .race-board-columns {
    grid-template-columns: minmax(0, 1fr) minmax(4.6rem, auto) minmax(4.6rem, auto);
    gap: 0.5rem;
    padding: 0.1rem 0.8rem 0.3rem;
    font-size: 0.62rem;
  }

  .race-row {
    grid-template-columns: minmax(0, 1fr) minmax(4.6rem, auto) minmax(4.6rem, auto);
    gap: 0.5rem;
    padding: 0.55rem 0.3rem;
  }

  .race-position {
    width: 1.2rem;
    flex-basis: 1.2rem;
  }

  .pit-stop-dots {
    gap: 0.14rem;
  }

  .pit-stop-dot {
    width: 0.24rem;
    height: 0.24rem;
  }

  .race-position-change {
    min-width: 0.9rem;
    font-size: 0.72rem;
  }

  .race-lap-badge {
    padding: 0.06rem 0.28rem;
    font-size: 0.58rem;
  }

  .race-gap-cell-leader .race-gap {
    font-size: 0.82rem;
  }

  .race-gap-cell-ahead .race-gap {
    font-size: 0.68rem;
  }
}
