/* ========== BASE STYLES ========== */
body {
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-width: 1100px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  white-space: nowrap;
  font-size: 1.2em;
}

.topbar .controls {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#raceTitle {
  font-size: 0.9em;
  color: var(--text-dim);
  white-space: nowrap;
}

.layout {
  display: grid !important;
  grid-template-columns: 280px 1fr 280px !important;
  gap: 12px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.center {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---- race header: two left/right rows ------------------------------------------------
   Was two 3-column grids (`1fr auto 1fr`). On a phone the middle `auto` column squeezed both
   1fr tracks below their content, so the title wrapped mid-phrase and the right-hand prize
   clipped its unit. `min-width: 0` on the flexible track is the part that lets it shrink —
   a 1fr item otherwise refuses to go narrower than its text and pushes the row wider. */
.race-head-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  font-size: 0.85em;
  color: var(--text-dim);
}
.race-head-row + .race-head-row { margin-top: 4px; }
#raceTitle {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.race-count { white-space: nowrap; font-variant-numeric: tabular-nums; }
.race-count b { color: var(--text); font-weight: bold; }
.race-prize {
  font-size: 1.1em;
  color: var(--gold-soft);
  font-weight: bold;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.race-head-row .race-prize:last-child { text-align: right; }
.race-maxsum { font-size: 0.85em; color: var(--text-dim); margin-top: 2px; }
.race-maxsum:empty { display: none; }

.owner-panel {
  padding: 6px 10px;
  background: rgba(255,255,255,0.04);
  border-top: 1px solid rgba(255,255,255,0.1);
}

.owner-label {
  font-size: 12px;
  opacity: 0.6;
  margin-bottom: 4px;
}

#walletSelect {
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 8px;
  background: var(--border);
  color: var(--text);
  border: 2px solid var(--accent);
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  -webkit-appearance: menulist;
  -moz-appearance: menulist;
  appearance: menulist;
}

#walletSelect:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.3);
}

#walletSelect option {
  background: var(--border);
  color: var(--text);
  padding: 8px;
}

.left { background: rgba(255, 0, 0, 0.1); }
.center-col { background: rgba(0, 255, 0, 0.1); }
.right { background: rgba(0, 0, 255, 0.1); }

/* ========== MODAL ========== */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden { display: none; }

.modal-content {
  width: 90%;
  height: 90%;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* The close control gets its own strip above the frame. As an absolutely-positioned button it
   sat on top of whatever the page put in its top-right corner — which is now a Connect. */
.modal-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: none;
  height: 42px;
  padding: 0 8px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
}

.modal-content iframe {
  width: 100%;
  flex: 1;
  min-height: 0;
  height: auto;
  border: none;
}

.modal-content button {
  background: var(--err-fill);
  color: white;
  border: none;
  padding: 7px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

/* ========== PANELS ========== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  transition: 0.2s ease;
}

/* The lift + accent border are the HOVER state. They used to sit on `.panel`
   itself, so every card on every page was permanently "hovered": all of them
   floated 2px above the grid and drew a cyan outline. */
.panel:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.panel h3 {
  margin-top: 0;
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 8px;
}

.highlight {
  border: 1px solid var(--accent);
  flex: none;
  display: flex;
  flex-direction: column;
  margin-top: -12px;
}

/* ========== TRACK & LANES ========== */
.track {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  background: var(--bg-deep);
  position: relative;
  min-height: 50px;
}

#raceTrack {
  position: relative;
  /* Top stop of the track gradient, reused by the START label so it reads as
     part of the track instead of a dark chip floating over it. */
  --track-bg-top: var(--surface);
  background: linear-gradient(to bottom, var(--track-bg-top) 0%, var(--surface) 100%);
  min-width: 760px;  /* 1500m track * 0.5 scale + buffer */
  overflow: hidden;  /* ten lanes: the track never scrolls */
}

#trackGlobal { height: 320px; }
#trackOwner { min-height: 50px; }

.lane {
  height: 36px;
  display: flex;
  align-items: center;
  margin-bottom: 4px;
  padding: 0 10px;
  box-sizing: border-box;
  position: relative; /* establish positioning context for cars in this lane */
}

.lane:last-child {
  margin-bottom: 0;
}

/* My Team uses flex gap, not margin */
#trackOwner .lane {
  margin-bottom: 0;
}

.lane:nth-child(odd) { background: rgba(255, 255, 255, 0.02); }
.lane:nth-child(even) { background: rgba(255, 255, 255, 0.05); }
.owner-lane { background: rgba(0, 200, 255, 0.08); }

/* ========== CARS ========== */
/* ========== TRACK DISTANCE MARKERS ========== */
/* Short 'kilometre-mark' ticks dropping from the top of the track (START,
   500m, 1000m). Height-capped so they never run down toward the panels below.
   Below cars, above lane bg, non-interactive. Positions set in JS. */
#raceTrack .track-line {
  position: absolute;
  top: 0;
  height: 388px;  /* 396px original full track * 0.98 */
  z-index: 1;
  pointer-events: none;
}
#raceTrack .track-line.start {
  width: 10px;
  background: repeating-conic-gradient(var(--text) 0% 25%, var(--bg) 0% 50%);
  background-size: 10px 10px;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.25);
  opacity: 0.92;
}
#raceTrack .track-line.start::after {
  content: 'START';
  position: absolute;
  top: 6px;
  left: calc(100% + 6px);
  font-size: 0.62em;
  letter-spacing: 2px;
  color: var(--text);
  background: var(--track-bg-top);
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
}
#raceTrack .track-line.m500,
#raceTrack .track-line.m1000,
#raceTrack .track-line.m1500 {
  width: 1px;
  border-left: 1px dashed rgba(255, 255, 255, 0.16);
}
#raceTrack .track-line.m500::after {
  content: '500m';
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 0.6em;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.35);
  white-space: nowrap;
}
#raceTrack .track-line.m1000::after {
  content: '1000m';
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 0.6em;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.35);
  white-space: nowrap;
}
/* 1500m is the end of the track (TRACK_LENGTH), so its mark hugs the right edge
   and the label is right-aligned to stay inside the track's overflow:hidden. */
#raceTrack .track-line.m1500::after {
  content: '1500m';
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.6em;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.35);
  white-space: nowrap;
}

/* Race track cars: positioned in lanes */
#raceTrack .car {
  position: absolute;
  top: 50%;
  left: 10px; /* offset by lane's left padding to align with content start */
  margin-top: -5px; /* half height to center vertically */
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 0 !important;
  border-radius: 0 !important;
  z-index: 10;
}

/* Race track car icon (small dot) */
#raceTrack .car-icon {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

#raceTrack .car.driver .car-icon { background: var(--gold-soft); }
#raceTrack .car.crew .car-icon { background: var(--accent); }

/* Highlight current owner's cars during race */
#raceTrack .car.owner {
  outline: 2px solid rgba(0, 200, 255, 0.6);
}

/* Deselected (greyed out) cars on track during race */
#raceTrack .car.deselected .car-icon { background: var(--border-strong); }
#raceTrack .car.deselected .car-label { color: var(--text-muted); }
#raceTrack .car.deselected { opacity: 0.5; }

/* Race track car label */
#raceTrack .car-label {
  color: white;
  white-space: nowrap;
}

/* Mid-race entrant: the backend starts it from 0m, so tag the tick it joined. */
#raceTrack .pit-badge {
  margin-left: 4px;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--surface);
  background: var(--warn);
  flex-shrink: 0;
}

/* My Team panel container */
#trackOwner .track {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px;
  background: var(--bg-deep);
  min-height: 50px;
}

/* My Team panel cars: same layout as race track */
#trackOwner .car {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  left: 0;
  margin: 0;
  padding: 0 !important;
  border-radius: 0 !important;
  /* transform is set inline via JavaScript for movement */
}

#trackOwner .car-icon {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

#trackOwner .car.driver .car-icon { background: var(--gold-soft); }
#trackOwner .car.crew .car-icon { background: var(--accent); }

/* My Team panel: same critical-HP warning as the race track (blinking red dot, with the
   label held steady red so the car number stays readable). */
#trackOwner .car.low-hp .car-icon {
  animation: lowHpBlink 0.4s infinite;
  background: var(--err-strong) !important;
}
#trackOwner .car.low-hp .car-label { color: var(--err-strong); font-weight: 600; }
#trackOwner .car.wrecked { opacity: 0.35; filter: grayscale(100%); }
#trackOwner .car.wrecked .car-icon { background: var(--text-muted) !important; animation: none; }

#trackOwner .car-label {
  color: white;
  white-space: nowrap;
}

/* Base car styling (fallback) */
.car {
  color: white;
  z-index: 10;
  white-space: nowrap;
}

/* ========== REPLAY CONTROLS ========== */
.replay-controls {
  display: flex;
  gap: 10px;
  padding: 12px 20px;
  background: var(--border);
  border-bottom: 1px solid var(--border-strong);
}

.replay-controls button {
  padding: 8px 16px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  color: var(--bg);
}

.replay-controls button:hover {
  background: var(--accent-strong);
}

#stageDisplay {
  padding: 8px 16px;
  background: var(--bg);
  border-radius: 6px;
  color: var(--accent);
  font-weight: bold;
}

/* ========== RESULTS ========== */
#results {
  margin: 12px 20px;
  padding: 10px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
}

#results h3 {
  margin-top: 0;
  color: var(--accent);
}

#results div {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

/* ========== NFT GARAGE ========== */
#nftList {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 6px;
  min-height: 100px;
  border: 1px solid transparent; /* invisible frame — keeps 1px layout, hides the inner box */
}

#nftList::-webkit-scrollbar {
  width: 6px;
}

#nftList::-webkit-scrollbar-thumb {
  background: #00ffcc;
  border-radius: 4px;
}

.nft-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 6px;
  transition: border-color 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.nft-card:hover {
  border-color: var(--accent);
}

.nft-card > div:first-child {
  font-family: monospace;
  font-size: 13px;
  color: #a5f3fc;
  flex-shrink: 0;
  width: 100%;
  margin-bottom: 4px;
}

/* Role buttons (compact inline) */
.role-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: bold;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  background: var(--border);
  color: var(--text);
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.role-btn:hover {
  border-color: var(--accent);
  background: var(--border-strong);
}

.role-btn.selected {
  color: var(--on-gold);
}

.role-btn.hero-btn.selected {
  background: gold;
  border-color: gold;
}

.role-btn.support-btn.selected {
  background: cyan;
  border-color: cyan;
}

/* Wrecked car button — disabled */
.role-btn.wrecked {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--border-strong) !important;
  border-color: var(--border-strong) !important;
  color: var(--text-muted) !important;
}

.role-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Connect wallet button */
.btn-connect {
  padding: 6px 14px;
  background: var(--btn);
  color: var(--text);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85em;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-connect:hover {
  background: var(--btn);
}
.btn-connect:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Left-panel action buttons — one colour scheme.
   Blue = race actions (registration / treasury / purchase), light purple = info.
   Both classes only carry colour so each button keeps its own inline sizing. */
.btn-blue, .btn-info { color: var(--text); }
.btn-blue { background: var(--btn); border: 1px solid var(--btn); }
.btn-blue:hover { background: var(--btn); border-color: var(--btn); }
.btn-info { background: #a78bfa; border: 1px solid #a78bfa; }
.btn-info:hover { background: #8b5cf6; border-color: #8b5cf6; }

/* Connected address display */
.connected-addr {
  font-family: monospace;
  font-size: 0.75em;
  color: var(--accent);
  word-break: break-all;
}

/* Rarity badge between Driver/Crew buttons */
.rarity-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: bold;
  padding: 3px 8px;
  border: 1px solid;
  border-radius: 10px;
  text-align: center;
  white-space: nowrap;
  line-height: 1.4;
}

/* ========== MATRIX TABLE ========== */
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 4px;
}

.matrix-table th,
.matrix-table td {
  padding: 6px 8px;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--bg);
}

.matrix-table th {
  color: var(--accent);
  font-weight: 600;
  background: var(--border);
}

.matrix-table td:first-child {
  color: var(--text-dim);
  text-align: left;
  font-weight: 500;
}

/* ========== RACE MATRIX TABLE ========== */
.race-matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: fixed;
}

.race-matrix-table th,
.race-matrix-table td {
  padding: 8px 4px;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--bg);
}

.race-matrix-table th {
  color: var(--accent);
  font-weight: 600;
  background: var(--border);
  font-size: 12px;
}

.race-matrix-table .row-label {
  text-align: left !important;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface) !important;
  font-size: 12px;
  white-space: nowrap;
  width: 85px;
}

/* ========== RACE MATRIX (7-day) ========== */
#matrix {
  padding: 8px 0;
  overflow-x: auto;
}

#matrix .day {
  flex-shrink: 0;
  width: 100px;
  padding: 10px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
  font-size: 12px;
  color: var(--text);
}

#matrix .day b {
  display: block;
  color: var(--accent);
  margin-bottom: 6px;
  font-size: 12px;
}

/* ========== STANDINGS ========== */
#seasonStandings {
  margin-top: 6px;
  font-size: 12px;
}

.standings-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  color: var(--text);
}

.standings-section {
  margin-bottom: 10px;
}

.standings-section b {
  color: var(--accent);
  font-size: 12px;
}

/* ========== BUTTONS & CONTROLS ========== */
button {
  padding: 10px 18px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
}

button:hover {
  background: var(--accent-strong);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  white-space: nowrap;
  margin-top: 8px;
}

/* ========== RACE PRIZE ========== */
#racePrize {
  font-weight: normal;
  color: var(--text-dim);
}

/* max-trait-label is injected with inline 0.85em by renderer.js; !important wins over inline */
#racePrize .max-trait-label {
  font-size: 0.9em !important;
}

/* ========== UTILITY ========== */
.blink {
  animation: blink 0.5s infinite;
}

@keyframes blink {
  50% { opacity: 0.3; }
}

/* Low HP warning blink */
#raceTrack .car.low-hp .car-icon {
  animation: lowHpBlink 0.4s infinite;
  background: var(--err-strong) !important;
}

@keyframes lowHpBlink {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--err-strong); }
  50% { opacity: 0.3; box-shadow: 0 0 0 transparent; }
}

/* Telemetry and Commentary panels */
#breakdown, #relay {
  font-size: 0.9em;
  line-height: 1.5;
  min-height: 60px;
}
#relay {
  max-height: 400px;
  overflow-y: auto;
}

/* Bitcoin News panel */
#btcNews a:hover { color: var(--accent) !important; }

/* Wrecked car — greyed out but still visible on track */
.nft-card.wrecked {
  opacity: 0.5;
  filter: grayscale(100%);
}

.nft-card.over-limit {
  opacity: 0.4;
  filter: grayscale(100%);
}

#raceTrack .car.wrecked {
  opacity: 0.35;
  filter: grayscale(100%);
}
#raceTrack .car.wrecked .car-icon {
  background: var(--text-muted) !important;
}

/* Placeholder text used when sections have no data */
.placeholder {
  color: var(--text-muted);
  padding: 4px;
}

/* Helper classes for matrix column widths */
.col-width-60 { width: 60px; }
.col-width-70 { width: 70px; }

/* Prize column in driver standings */
.td-prize { color: var(--gold-soft); text-align: right; font-family: monospace; }

/* ========== STANDINGS TABLES (moved from renderer.js) ========== */
.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.standings-table th {
  color: var(--accent);
  padding: 4px;
  font-weight: 600;
}
.standings-table th.th-left { text-align: left; }
.standings-table th.th-center { text-align: center; }
.standings-table th.th-right { text-align: right; }
.standings-table th.th-wide-auto { width: auto; }
.standings-table th.th-narrow { width: 28px; }
.standings-table th.th-pts { width: 36px; }
.standings-table th.th-race { width: 40px; }
.standings-table th.th-hp { width: 40px; }

.standings-table tr {
  border-bottom: 1px solid var(--border);
}
.standings-table tr:last-child { border-bottom: none; }
.standings-table tr.row-leader { background: rgba(255, 215, 0, 0.08); }

.standings-table td {
  padding: 4px;
}
.standings-table td.td-rank { color: var(--text-dim); text-align: center; }
.standings-table td.td-car { color: var(--text); font-weight: 500; }
/* Team car count after the owner address — same size as the address, greyed so the address stays
   the label and "(3 cars)" reads as an aside. */
.standings-table td.td-car .team-cars { color: var(--text-dim); font-weight: 400; }
/* Team column in the race standings — the owner address of the car. Car is pinned narrow and
   Team is the flexible one, so the spare table width lands to the RIGHT of the team address
   (before P) instead of opening a gap between the car label and the team that owns it. */
.standings-table th.th-car { width: 64px; }
.standings-table th.th-team { width: auto; }
/* Team reads as the car's owner, so it carries the Car cell's type and colour exactly
   (var(--text) / weight 500 — same values as td-car above). */
.standings-table td.td-team { color: var(--text); font-weight: 500; }
.standings-table td.td-stat { color: var(--text); text-align: right; font-family: monospace; }
.standings-table td.td-sum { color: var(--gold-soft); text-align: right; font-family: monospace; font-weight: 600; }
.standings-table td.td-distance { color: var(--accent); text-align: right; font-family: monospace; font-weight: 600; }
.standings-table td.td-hp { text-align: right; font-weight: 600; }

/* Sub-blocks inside a standings panel: car table + team table, split by a blank line.
   Fixed layout + one flexible name column keeps the Points/Prize columns of every
   standings table on the same x, so the numbers line up down the panel. */
.standings-sep { height: 14px; }
.standings-table.cols-fixed { table-layout: fixed; }
.standings-table th.th-num { width: 68px; }
/* Car table carrying the Race 1..N strip: pin the Car column so the reclaimed width goes
   to the race columns instead of stretching the (short) car label, which had no width and
   swallowed every spare pixel. Race cells share whatever is left. */
.standings-table.cols-fixed.has-race-cols th:nth-child(2),
.standings-table.cols-fixed.has-race-cols td:nth-child(2) { width: 120px; }
.standings-table th.th-race-pts,
.standings-table td.td-race-pts {
  /* Centred, not right-aligned: the race columns absorb the table's spare width, so
     a right-aligned value sat flush against the right edge of a very wide cell (172px
     of dead space to its left on a 1920px window) and the R strip read as pushed right.
     Centred keeps each value under its own Rn header at any table width. */
  text-align: center;
  font-family: monospace;
  color: var(--text-dim);
  padding: 4px 3px;
}

/* HP color helpers used in race standings */
.hp-normal { color: var(--text); }
.hp-warning { color: var(--gold-soft); }
.hp-danger { color: var(--err-strong); }

/* The race standings carry the P/T/S/C/Sum columns TWICE — traits first, then the
   distance components the car has banked. One rule splits the groups so the pair of
   identical header labels cannot be read as one run of ten columns. */
.standings-table th.th-group,
.standings-table td.td-group { border-left: 1px solid var(--border-strong); padding-left: 7px; }

/* ...and the second set makes 15 columns. Below the desktop grid's 1344px the panel
   already scrolls horizontally, so pin a floor instead of crushing them into the
   one-set table's 520px (numbers legible, rule detail off-screen). */
@media (max-width: 1399px) {
  #raceStandings table.standings-table.has-dist { min-width: 760px; }
  /* `td.td-team { word-break: break-all }` (phone block) collapses this auto-width
     column once ten numeric columns are pinned, splitting one abbreviated address over
     three lines. A floor keeps each row one line tall. */
  #raceStandings table.standings-table.has-dist th.th-team,
  #raceStandings table.standings-table.has-dist td.td-team { min-width: 84px; }
}

/* ========== MID-RANGE LAPTOPS ========== */
/* The desktop grid's real minimum is 1344px: 280px sidebar + the track's own 760px + 280px, plus
   gaps. `body { min-width: 1100px }` understated it, so a 1280px laptop (a very common width) got a
   horizontal scrollbar on the whole page. Between 821 and 1399 the sidebars give back a little room
   and the centre column scrolls on its own; the track keeps its geometry either way. Above 1400
   nothing changes. */
@media (max-width: 1399px) and (min-width: 821px) {
  body { min-width: 0; }
  .layout { grid-template-columns: 240px minmax(0, 1fr) 240px !important; }
  .center { overflow-x: auto; }
  #raceStandings, #seasonStandings, #matrix { overflow-x: auto; }
}

/* ========== PHONE / NARROW SCREENS ========== */
/* The layout above is desktop-first (280px | centre | 280px with a 1100px floor), which on a phone
   meant the whole thing was scaled down to fit — 16px text arriving at roughly 5px, with buttons
   too small to hit. Below 820px it collapses to a single column and each block keeps its OWN
   geometry rather than being squeezed:

   - #raceTrack stays 760px wide and scrolls. It is NOT resized: TRACK_LENGTH * TRACK_SCALE and the
     distance markers are pixel maths inside it, so a narrower track puts the markers somewhere the
     simulation does not agree with.
   - the standings matrices keep readable columns and scroll horizontally instead of wrapping every
     cell into a two-line mess.
   - touch targets get a real minimum height; nothing becomes a 12px tap.
   Pinch-zoom stays enabled (no user-scalable=no). */
@media (max-width: 820px) {
  body { min-width: 0; }

  .layout { grid-template-columns: 1fr !important; }

  .topbar {
    flex-wrap: wrap;
    padding: 10px 12px;
  }
  .topbar h1 { font-size: 1.05em; white-space: normal; }
  .topbar .controls { flex-wrap: wrap; width: 100%; }
  /* ---- the race header on a phone -----------------------------------------------------
     Two rows of left/right is already the phone shape, so what is left is to stop the WORDS
     competing with the NUMBERS: "SEASON PRIZE:" and "RACE PRIZE:" are what pushed the right-hand
     block past the panel edge (the screenshot read `1,128.24 US`), and the trophy/bag icons
     already say which number is which. The countdown keeps only its clock. */
  .prize-lbl, .phone-hide { display: none; }
  /* A trait-sum RULE, not race state: it only earns its space when there is room for it. */
  #racePrize .max-trait-label { display: none; }
  .race-head-row { font-size: 13px; column-gap: 8px; }
  #raceTitle { font-size: 12px; letter-spacing: -0.1px; }
  .race-count { font-size: 12px; }
  .race-prize { font-size: 12.5px !important; letter-spacing: -0.2px; }
  #driverStatusRow { font-size: 12px !important; margin-top: 3px !important; }

  /* Buttons must be tappable. A thumb needs ~40px. */
  button, .btn, a.btn, select, input[type="submit"] {
    min-height: 40px;
    font-size: 14px;
  }

  /* The 760px track scrolls inside the phone's width, keeping its own geometry.
     Safari needs -webkit-overflow-scrolling for momentum. */
  .center { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Standings and the race matrix scroll rather than crush their columns. */
  #raceStandings, #seasonStandings, #matrix {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #raceStandings table, #seasonStandings table { min-width: 520px; }

  /* Sidebars stack (they are grid rows now) and keep a sane gap. */
  .sidebar, .center { gap: 10px; }

  /* Long wallet addresses must wrap instead of forcing the page wider. */
  .addr, .mono, td.td-team { word-break: break-all; }
}

/* ========== RACE STATUS CHIPS + TOPBAR CTA + LINE-UP GRID ==========
   Phase B. The status strip used to stack five lines of mixed alignment, two of them gold,
   so nothing read as the headline. One fact per chip, equal weight, tabular numerals. */
.race-chips {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.chip-k {
  font-size: 12px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.chip-v {
  font-size: 18px;
  font-weight: 700;
  color: var(--gold-soft);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}

.chip-u {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-left: 4px;
}

.chip-money { border-color: var(--gold-tint); }

.race-min {
  color: var(--text-muted);
  font-weight: 400;
}

/* The one primary action: gold = money, always visible, never behind a wallet. */
.btn-buy {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 9px 18px;
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: var(--on-gold);
  cursor: pointer;
  white-space: nowrap;
}
.btn-buy:hover { background: var(--gold-soft); border-color: var(--gold-soft); }

.btn-gold {
  background: var(--gold) !important;
  border-color: var(--gold) !important;
  color: var(--on-gold) !important;
  font-weight: 700;
}
.btn-gold:hover { background: var(--gold-soft) !important; }

/* Trust row — one thin strip under the topbar. Small on purpose: it is reassurance, not
   navigation, and it must not compete with the race header or the gold CTA. */
.trust-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
  padding: 8px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.trust-row[hidden] { display: none; }
.trust-item { display: flex; align-items: center; gap: 6px; min-width: 0; }
.trust-k { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--text-faint); }
.trust-row a { color: var(--text-dim); text-decoration: none; font-family: var(--font-mono); }
.trust-row a:hover { color: var(--accent); }
.trust-note { margin-left: auto; color: var(--text-faint); }
.trust-dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.trust-dot.live { background: var(--ok-strong); }
.trust-dot.test { background: var(--warn); }
/* On a phone the strip is reassurance, not content: drop the sentence and tighten what is
   left, so it costs one line instead of two above the fold. */
@media (max-width: 560px) {
  /* Seven 70px stage columns forced the race matrix to 623px inside a 368px panel, so a phone
     showed four stages and a scrollbar. Share the width instead: the columns are icon-or-two-
     digit cells, they do not need 70px. */
  .race-matrix-table th,
  .race-matrix-table td { padding: 5px 1px; font-size: 11px; }
  .race-matrix-table th { font-size: 9px; }
  .race-matrix-table .row-label { width: 60px; font-size: 10px; }
  .race-matrix-table .col-width-70,
  .race-matrix-table .col-width-60 { width: auto; }
  .trust-row { padding: 6px 14px; gap: 4px 12px; font-size: 11px; }
  .trust-note { display: none; }
  .trust-k { font-size: 9px; }
  /* The strip sits between the two top CTAs on a phone (the wallet panel is ordered first),
     so anything that wraps it to a second line splits them. Chain + collection is the one
     fact a buyer checks; the treasury address is on the pool page. */
  .trust-treasury { display: none; }
}

/* Inline icon set (#i-* symbols in index.html). Stroke follows the label's colour, so one
   rule works on a gold button, a blue one and a ghost. Sized to the 14px UI type beside it. */
.ico {
  width: 14px;
  height: 14px;
  margin-right: 6px;
  vertical-align: -2px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* Line-up grid: the entered field parked on the start line (see renderer.js). */
.grid-car {
  position: absolute;
  left: 14px;          /* clear of the chequered start strip, which is 10px at x=10 */
  top: 50%;
  z-index: 2;          /* above the start line (z-index 1) */
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 186px;    /* art + id left, trait sum right — a starting grid, not a scatter of labels */
  padding: 2px 9px;    /* 30px art + 2px border + 4px padding = the lane's 36px, no overflow */
  border-radius: 4px 12px 12px 4px;   /* nose to the right: a car on the grid, not a label */
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.gdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.gdot.driver { background: var(--gold-soft); }
.gdot.crew   { background: var(--accent); }

.gcar-id { font-variant-numeric: tabular-nums; }
.gsum {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.grid-more {
  position: absolute;
  right: 8px;
  bottom: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
}

@media (max-width: 820px) {
  .btn-buy { width: 100%; margin-top: 8px; }
  .race-chips { flex-direction: column; }
  /* The vote card is the least urgent panel on the page and it owned the whole first screen
     on a phone. `display: contents` lifts the left rail's children into the one-column grid so
     they can be ordered around the race column — ordering *inside* the rail could never move
     the vote below the track. */
  .sidebar.left { display: contents; }
  #walletPanel  { order: 1; }
  .center       { order: 2; }
  #garagePanel  { order: 3; }
  #paymentsPanel{ order: 3; }
  .sidebar.right{ order: 4; }
  #votePanel    { order: 5; }
  .sidebar.left > .panel:last-child { order: 6; }
  /* "How it works" closes the right rail on desktop, where the rail is in the first
     screen. On a phone the whole rail sits below the race, so lift the card to the top
     of it — it is the only panel that explains the product to a stranger. */
  .sidebar.right > .panel:last-child { order: -1; }
}

/* ========== BRAND LOCKUP ==========
   The h1 was one inline run: a 19px logo, then "SANRAT Grand Prix" at one weight, with a
   green text-shadow over all of it. Split into mark / wordmark / tracked subtitle, and the
   glow moved to the wordmark alone at a size that suits a 27px face instead of a 14px one. */
@keyframes brandGlow {
  0%, 100% { text-shadow: 0 0 4px rgba(74, 222, 128, .10); }
  50%      { text-shadow: 0 0 9px rgba(74, 222, 128, .20); }
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  white-space: nowrap;
}

.brand-mark {
  height: 64px;          /* was 1.2em ≈ 19px — the mark read as a bullet, not a logo.
                            64, not 52: the A2 art carries circuit traces and whiskers that need
                            the room, and at 52 they collapse into a gold smear on a 1x screen. */
  width: 64px;
  object-fit: contain;
  animation: breathe 5s ease-in-out infinite;
  filter: drop-shadow(0 0 7px rgba(74, 222, 128, .20));
}

.brand-text { display: flex; flex-direction: column; line-height: 1; }

.brand-name {
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: .16em;
  color: var(--text);
  animation: brandGlow 4.5s ease-in-out infinite;
}

.brand-sub {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  /* Not gold: on this system gold means money, and the CTA is the only gold on the
     screen. A muted subtitle reads flatter and more premium than a third yellow. */
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 5px;
}

@media (max-width: 820px) {
  .topbar .brand { gap: 9px; }
  .brand-mark { height: 46px; width: 46px; }
  .brand-name { font-size: 21px; letter-spacing: .12em; }
  .brand-sub  { font-size: 12px; letter-spacing: .26em; margin-top: 4px; }
}

/* ========== HOW IT WORKS ==========
   Three steps, one loop. The numbered pips are counters, not links — nothing here is
   interactive except the "read the rules" link at the bottom. */
.howto {
  counter-reset: how;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.howto li {
  counter-increment: how;
  position: relative;
  padding-left: 26px;
}

.howto li::before {
  content: counter(how);
  position: absolute;
  left: 0;
  top: 1px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.howto b {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.howto span {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.howto-more {
  display: inline-block;
  margin-top: 11px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.howto-more:hover { color: var(--accent-strong); text-decoration: underline; }

/* The wallet connect is a door, not the goal. It was a full-width saturated fill sitting
   directly under the gold CTA — two primaries on one screen. Outline now; the fill returns
   on hover so it still reads as pressable. */
#connectBtn {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-strong);
}
#connectBtn:hover {
  background: rgba(56, 189, 248, .10);
  border-color: var(--accent);
}

/* Wallet button states.
   These used to be inline `style.background` writes in the connect handler: the signed-in
   state painted a solid green slab and left the label in its default cyan, which is cyan on
   green — about 1.6:1, unreadable. State lives in data-state now, and every state keeps the
   outline construction, so the gold CTA stays the only filled button on the page. */
#connectBtn[data-state="signed"] {
  background: rgba(74, 222, 128, .10);
  border-color: var(--ok);
  color: var(--ok);
}

#connectBtn[data-state="signing"],
#connectBtn[data-state="connecting"],
#connectBtn[data-state="retry"] {
  background: rgba(245, 158, 11, .12);
  border-color: var(--warn);
  color: var(--warn);
}

/* The address line under the button is information, not a control: cyan means
   "clickable" everywhere else on this page, and at 0.75em it fell under the type floor. */
.connected-addr {
  font-size: 12px;
  color: var(--text-dim);
}
