/* ========== BASE STYLES ========== */
body {
  font-family: Arial, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  margin: 0;
  min-width: 1100px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #020617;
  border-bottom: 1px solid #1e293b;
  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: #94a3b8;
  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;
}

.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: 11px;
  opacity: 0.6;
  margin-bottom: 4px;
}

#walletSelect {
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 8px;
  background: #1e293b;
  color: #e2e8f0;
  border: 2px solid #38bdf8;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  -webkit-appearance: menulist;
  -moz-appearance: menulist;
  appearance: menulist;
}

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

#walletSelect option {
  background: #1e293b;
  color: #e2e8f0;
  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: #0b0e14;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.modal-content iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.modal-content button {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #ff4444;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}

/* ========== PANELS ========== */
.panel {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 10px;
  transition: 0.2s ease;
  transform: translateY(-2px);
  border-color: #38bdf8;
}

.panel h3 {
  margin-top: 0;
  font-size: 14px;
  color: #38bdf8;
  margin-bottom: 8px;
}

.highlight {
  border: 1px solid #38bdf8;
  flex: none;
  display: flex;
  flex-direction: column;
  margin-top: -12px;
}

/* ========== TRACK & LANES ========== */
.track {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  background: #020617;
  position: relative;
  min-height: 50px;
}

#raceTrack {
  position: relative;
  background: linear-gradient(to bottom, #0b1a2a 0%, #0a1624 100%);
  min-width: 760px;  /* 1500m track * 0.5 scale + buffer */
  overflow-x: auto;
}

#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 ========== */
/* 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: #ffd700; }
#raceTrack .car.crew .car-icon { background: #00c2ff; }

/* 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: #555; }
#raceTrack .car.deselected .car-label { color: #666; }
#raceTrack .car.deselected { opacity: 0.5; }

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

/* My Team panel container */
#trackOwner .track {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px;
  background: #020617;
  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: #ffd700; }
#trackOwner .car.crew .car-icon { background: #00c2ff; }

#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: #1e293b;
  border-bottom: 1px solid #334155;
}

.replay-controls button {
  padding: 8px 16px;
  background: #38bdf8;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  color: #0f172a;
}

.replay-controls button:hover {
  background: #0ea5e9;
}

#stageDisplay {
  padding: 8px 16px;
  background: #0f172a;
  border-radius: 6px;
  color: #38bdf8;
  font-weight: bold;
}

/* ========== RESULTS ========== */
#results {
  margin: 12px 20px;
  padding: 10px;
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 10px;
}

#results h3 {
  margin-top: 0;
  color: #38bdf8;
}

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

/* ========== NFT GARAGE ========== */
#nftList {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 6px;
  min-height: 100px;
  border: 1px solid #333;
}

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

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

.nft-card {
  background: #0f172a;
  border: 1px solid #1e293b;
  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: #38bdf8;
}

.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: 11px;
  font-weight: bold;
  border: 1px solid #334155;
  border-radius: 4px;
  cursor: pointer;
  background: #1e293b;
  color: #e2e8f0;
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.role-btn:hover {
  border-color: #38bdf8;
  background: #1e3a5f;
}

.role-btn.selected {
  color: #000;
}

.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: #333 !important;
  border-color: #555 !important;
  color: #888 !important;
}

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

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

/* Connected address display */
.connected-addr {
  font-family: monospace;
  font-size: 0.75em;
  color: #38bdf8;
  word-break: break-all;
}

/* Rarity badge between Driver/Crew buttons */
.rarity-badge {
  display: inline-block;
  font-size: 10px;
  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 #1e293b;
  background: #0f172a;
}

.matrix-table th {
  color: #38bdf8;
  font-weight: 600;
  background: #1e293b;
}

.matrix-table td:first-child {
  color: #94a3b8;
  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 #1e293b;
  background: #0f172a;
}

.race-matrix-table th {
  color: #38bdf8;
  font-weight: 600;
  background: #1e293b;
  font-size: 12px;
}

.race-matrix-table .row-label {
  text-align: left !important;
  font-weight: 500;
  color: #94a3b8;
  background: #0a1624 !important;
  font-size: 11px;
  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: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  text-align: center;
  font-size: 11px;
  color: #e2e8f0;
}

#matrix .day b {
  display: block;
  color: #38bdf8;
  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: #e2e8f0;
}

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

.standings-section b {
  color: #38bdf8;
  font-size: 12px;
}

/* ========== BUTTONS & CONTROLS ========== */
button {
  padding: 10px 18px;
  background: #38bdf8;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
}

button:hover {
  background: #0ea5e9;
}

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

/* ========== RACE PRIZE ========== */
#racePrize {
  font-size: 1.2em;
  font-weight: bold;
  color: #ffd700;
  padding: 10px;
  text-align: center;
  background: rgba(255, 215, 0, 0.1);
  border-radius: 8px;
}

/* ========== 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: #ef4444 !important;
}

@keyframes lowHpBlink {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px #ef4444; }
  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;
}

/* 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: #666 !important;
}

/* Placeholder text used when sections have no data */
.placeholder {
  color: #888;
  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: #ffd700; 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: #38bdf8;
  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 #1e293b;
}
.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: #94a3b8; text-align: center; }
.standings-table td.td-car { color: #e2e8f0; font-weight: 500; }
.standings-table td.td-stat { color: #e2e8f0; text-align: right; font-family: monospace; }
.standings-table td.td-sum { color: #fbbf24; text-align: right; font-family: monospace; font-weight: 600; }
.standings-table td.td-distance { color: #38bdf8; text-align: right; font-family: monospace; font-weight: 600; }
.standings-table td.td-hp { text-align: right; font-weight: 600; }

/* HP color helpers used in race standings */
.hp-normal { color: #e2e8f0; }
.hp-warning { color: #fbbf24; }
.hp-danger { color: #ef4444; }
