:root {
  --bg: #f7f9fc;
  --card: #ffffff;
  --text: #121722;
  --muted: #5f6c80;
  --accent: #174b9b;
  --line: #d8e0eb;
  --chip: #f3f6fb;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.hero h1 {
  margin: 0 0 6px 0;
  font-size: 30px;
  letter-spacing: -0.5px;
}

.hero-sub {
  margin: 0 0 10px 0;
  color: var(--muted);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #123f82; text-decoration: none; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin: 16px 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

h2 {
  margin: 0 0 12px 0;
  font-size: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
}

tbody td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
}

tbody tr:last-child td { border-bottom: none; }

.hero {
  margin-bottom: 14px;
}

.hero-top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--line);
  color: var(--muted);
}

.hero-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.hero-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.btn-link {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--chip);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}

#search {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.race-pill {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--chip);
}

.race-pill-title {
  font-weight: 700;
  font-size: 13px;
}

.race-pill-meta {
  font-size: 12px;
  color: var(--muted);
}

.races {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
}

.person-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.person-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.person-name {
  color: #2d6fce;
  font-weight: 700;
  flex: 1 1 auto;
  min-width: 0;
  padding-right: 8px;
}

.person-link {
  color: #2d6fce;
}

.person-link:hover {
  color: #1d56a8;
}

.person-flag {
  color: var(--muted);
  font-size: 13px;
  flex: 0 0 auto;
  white-space: nowrap;
}

.country-flag {
  width: 20px;
  height: 14px;
  display: inline-block;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 2px;
}

.person-scoreline {
  color: var(--muted);
  font-weight: 400;
  font-size: 12.5px;
  line-height: 1.15;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.person-scoreline .score-col {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: center;
  column-gap: 2px;
  text-align: center;
  white-space: nowrap;
}

.person-scoreline .label {
  color: var(--muted);
  display: inline !important;
}

.person-scoreline .num {
  color: #d94b4b;
  display: inline !important;
}

.drivers {
  display: grid;
  gap: 4px;
  margin-top: auto;
}

.driver-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 7px;
  background: #f7f9fd;
  overflow: hidden;
}

.driver-row:hover {
  background: #edf2f9;
}

.driver-name {
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 0;
  min-width: 0;
}

.driver-points {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  font-weight: 700;
  font-size: 11px;
  line-height: 1.05;
  flex: 0 0 auto;
  min-width: 52px;
  margin-left: 2px;
}

.season-totals-table thead th {
  font-size: 15px;
}

.season-totals-card {
  overflow-x: auto;
}

.season-totals-table {
  width: 100%;
}

.season-totals-table thead th,
.season-totals-table tbody td {
  padding-top: 6px;
  padding-bottom: 6px;
}

.season-totals-table tbody td:nth-child(2) a {
  color: #2d6fce;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.05;
}

.season-totals-table tbody td:nth-child(3),
.season-totals-table tbody td:nth-child(4),
.season-totals-table tbody td:nth-child(5),
.season-totals-table tbody td:nth-child(6) {
  font-size: 20px;
  font-weight: 700;
}

.live-cards {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.live-person-card {
  padding-bottom: 12px;
}

.live-scoreline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 4px 0 2px;
  border-top: 1px solid var(--line);
}

.live-score-label {
  color: var(--muted);
  font-size: 13px;
}

.live-score-value {
  color: #d94b4b;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.live-missing-note {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.live-driver-row {
  align-items: flex-start;
}

.live-driver-points {
  min-width: 86px;
  font-size: 11px;
}

.live-hero-meta {
  margin-top: -2px;
}

.live-page-actions {
  display: flex;
  gap: 8px;
}

.live-error-card {
  max-width: 560px;
}

.live-error-text {
  margin: 0;
  color: var(--muted);
}

.live-summary-card {
  max-width: 760px;
}

.live-totals-table {
  width: 100%;
  font-variant-numeric: tabular-nums;
}

.live-totals-table tbody td:nth-child(2) {
  color: #2d6fce;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.05;
}

.live-totals-table tbody td:nth-child(3) {
  color: #d94b4b;
  font-size: 20px;
  font-weight: 700;
}

.pool-box-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.pool-box-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  padding: 8px;
}

.pool-box-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pool-box-list {
  display: grid;
  gap: 4px;
}

.pool-box-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  line-height: 1.15;
}

.pool-box-live-row {
  grid-template-columns: 24px auto 1fr;
}

.pool-box-run {
  color: #d94b4b;
  font-weight: 700;
  text-align: right;
}

.pool-box-car {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.pool-box-name {
  color: var(--text);
  min-width: 0;
}

.metric {
  white-space: nowrap;
}

.car-no {
  font-weight: 700;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #eef3fb;
  color: var(--text);
  flex: 0 0 auto;
}

.grid-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

.all-races-grid {
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}

.all-races-grid .sticky-col {
  position: -webkit-sticky;
  position: sticky;
  left: 0;
  z-index: 3;
  background: #ffffff;
  box-shadow: 1px 0 0 var(--line);
  transform: translateZ(0);
}

.all-races-grid .driver-col {
  width: 220px;
  min-width: 220px;
  max-width: 220px;
}

.all-races-grid .driver-cell {
  width: 220px;
  min-width: 220px;
  max-width: 220px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.all-races-grid .race-col {
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  vertical-align: bottom;
  height: 120px;
  padding: 0;
  overflow: visible;
}

.all-races-grid .race-head {
  display: block;
  height: 120px;
  width: 44px;
  position: relative;
  overflow: visible;
  border: none;
}

.all-races-grid .race-label {
  display: block;
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%) rotate(-56deg);
  transform-origin: center bottom;
  white-space: nowrap;
  width: max-content;
  font-size: 10px;
  line-height: 1;
  color: var(--muted);
  text-align: center;
}

.all-races-grid .pos-cell {
  text-align: center;
  font-weight: 700;
  font-size: 11px;
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  padding: 5px 2px;
}

.all-races-grid th,
.all-races-grid td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.all-races-grid thead th {
  border-top: 1px solid var(--line);
  overflow: visible;
  vertical-align: bottom;
}

.all-races-grid tr > *:first-child {
  border-left: 1px solid var(--line);
}

.all-races-grid thead .sticky-col {
  z-index: 5;
}

.all-races-grid thead th.race-col {
  border-top: none;
}

@media (max-width: 700px) {
  .all-races-grid .driver-col,
  .all-races-grid .driver-cell {
    width: 184px;
    min-width: 184px;
    max-width: 184px;
  }

  .all-races-grid .race-col,
  .all-races-grid .pos-cell {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
  }

  .all-races-grid .race-col,
  .all-races-grid .race-head {
    height: 90px;
  }

  .all-races-grid .race-label {
    font-size: 8px;
  }
}

.driver-text {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.15;
}

.selected {
  display: grid;
  gap: 6px;
}

.race-links {
  margin-top: 4px;
}

.race {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #ffffff;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.race:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.06);
}

.race-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.race-meta {
  color: var(--muted);
  font-size: 13px;
}

.missing {
  color: #b00020;
  font-size: 13px;
}

.total-row td {
  border-top: 1px solid var(--line);
  font-weight: 700;
}

.total-row .total-label {
  text-align: right;
  color: var(--muted);
}

.total-row .total-value {
  text-align: right;
}

.person-race-table {
  font-variant-numeric: tabular-nums;
  width: fit-content;
  min-width: 760px;
  max-width: 100%;
}

.person-race-card {
  display: inline-block;
  width: auto;
  max-width: 100%;
}

.person-race-table th:nth-child(5),
.person-race-table td:nth-child(5) {
  text-align: right;
  padding-right: 10px;
  white-space: nowrap;
  width: 92px;
}

.person-race-table th:nth-child(4),
.person-race-table td:nth-child(4) {
  width: 92px;
}

.person-race-table .total-row .total-value {
  padding-right: 10px;
  text-align: right;
}

@media (max-width: 900px) {
  .person-race-table {
    width: 100%;
    min-width: 0;
  }
}

/* All-races page (CSS grid version for better Safari/iPhone behavior) */
.ar-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  background: #ffffff;
  --ar-scroll-x: 0px;
}

.ar-grid {
  display: grid;
  width: max-content;
  min-width: 100%;
}

.ar-top-left,
.ar-head-cell,
.ar-driver-cell,
.ar-cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.ar-top-left {
  height: 118px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 20px;
  font-weight: 700;
  color: var(--muted);
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
}

.ar-head-cell {
  height: 118px;
  position: relative;
  border-top: none;
  border-right: none;
  border-bottom: 1px solid var(--line);
  display: block;
  overflow: visible;
  padding-top: 0;
  z-index: 2;
}

.ar-race-label {
  position: absolute;
  top: auto;
  bottom: 8px;
  left: 6px;
  transform: rotate(-55deg);
  transform-origin: left bottom;
  white-space: nowrap;
  font-size: 10px;
  line-height: 1;
  color: var(--muted);
  text-align: left;
}

/* Keep first angled label clear of the Driver divider */
.ar-grid > .ar-head-cell:first-of-type .ar-race-label {
  left: 10px;
}

.ar-driver-cell {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-left: 1px solid var(--line);
  background: #ffffff;
  font-size: 16px;
  font-weight: 600;
}

.ar-cell {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}

.ar-sticky {
  position: -webkit-sticky;
  position: sticky;
  left: 0;
  z-index: 4;
  background: #ffffff;
  box-shadow: 1px 0 0 var(--line);
}

.ar-top-left.ar-sticky {
  z-index: 6;
}

.ios-fix .ar-sticky {
  position: relative;
  left: auto;
  transform: translateX(var(--ar-scroll-x));
}

@media (max-width: 700px) {
  .ar-grid {
    grid-template-columns: 180px repeat(36, 40px) !important;
  }

  .ar-top-left,
  .ar-head-cell {
    height: 108px;
  }

  .ar-race-label {
    font-size: 9px;
    bottom: 8px;
    left: 5px;
  }

  .ar-driver-cell,
  .ar-cell {
    height: 50px;
    font-size: 13px;
  }

  .season-totals-table thead th {
    font-size: 12px;
  }

  .season-totals-table thead th,
  .season-totals-table tbody td {
    padding: 5px 4px;
  }

  .season-totals-table tbody td:nth-child(2) a {
    font-size: 20px;
  }

  .season-totals-table tbody td:nth-child(3),
  .season-totals-table tbody td:nth-child(4),
  .season-totals-table tbody td:nth-child(5),
  .season-totals-table tbody td:nth-child(6) {
    font-size: 16px;
  }
}

@media (max-width: 1200px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .races { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .races { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-cards { grid-template-columns: 1fr; }
  .pool-box-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .hero-controls { grid-template-columns: 1fr; }
  .hero h1 { font-size: 24px; }
  table { font-size: 13px; }
  .cards { grid-template-columns: 1fr; }
  .races { grid-template-columns: 1fr; }
  .pool-box-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}


.pool-box-total-row {
  grid-template-columns: auto 1fr auto;
  gap: 6px;
}

.pool-box-points {
  color: #d94b4b;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}
