/* ==========================================================================
   Race Page + Leaderboard Styles
   ========================================================================== */

/* ── Race Layout ─────────────────────────────────────────────────────────── */
.race-page {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-lg);
}

.race-page h1 {
  font-family: var(--font-heading);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-lg);
}

/* ── Step Sections ───────────────────────────────────────────────────────── */
.race-step {
  margin-bottom: var(--space-xl);
}

.race-step h3 {
  font-family: var(--font-heading);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  margin-bottom: var(--space-md);
}

.race-step h3 .step-num {
  display: inline-block;
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  background: var(--primary);
  color: var(--text);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  margin-right: 8px;
}

/* ── Build Selector ──────────────────────────────────────────────────────── */
.build-selector {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.build-selector select {
  flex: 1;
  min-width: 250px;
}

/* ── Car Card ────────────────────────────────────────────────────────────── */
.car-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  display: flex;
  gap: var(--space-md);
  align-items: center;
}

.car-card.car-a { border-left: 4px solid #4A9EFF; }
.car-card.car-b { border-left: 4px solid #FF4A4A; }

.car-card-label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 2px 8px;
  border-radius: 3px;
  margin-bottom: 4px;
}

.car-a .car-card-label {
  background: rgba(74, 158, 255, 0.15);
  color: #4A9EFF;
}

.car-b .car-card-label {
  background: rgba(255, 74, 74, 0.15);
  color: #FF4A4A;
}

.car-card-stats {
  display: flex;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.car-card-stat {
  text-align: center;
}

.car-card-stat .stat-value {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.5rem;
  display: block;
}

.car-card-stat .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.car-card-name {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.1rem;
}

/* ── Opponent Tabs ───────────────────────────────────────────────────────── */
.opponent-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: var(--space-md);
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 3px;
}

.opponent-tab {
  flex: 1;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.opponent-tab.active {
  background: var(--primary);
  color: var(--text);
}

.opponent-tab:hover:not(.active) {
  color: var(--text);
  background: var(--bg-hover);
}

/* ── Stock Car Grid ──────────────────────────────────────────────────────── */
.class-filter-btns {
  display: flex;
  gap: 6px;
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}

.class-filter-btn {
  padding: 4px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.class-filter-btn.active,
.class-filter-btn:hover {
  background: var(--primary-muted);
  border-color: var(--primary);
  color: var(--primary);
}

.stock-car-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-md);
}

.stock-car-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.stock-car-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-glow-red);
}

.stock-car-card.selected {
  border-color: #FF4A4A;
  background: rgba(255, 74, 74, 0.05);
}

.stock-car-card .car-name {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.stock-car-card .car-specs {
  display: flex;
  gap: var(--space-sm);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stock-car-card .car-hp {
  color: var(--primary);
  font-weight: 700;
}

/* ── User Build Search ───────────────────────────────────────────────────── */
.build-search-input {
  display: flex;
  gap: 8px;
  margin-bottom: var(--space-md);
}

.build-search-input input { flex: 1; }

.build-search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.build-search-item {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.build-search-item:hover {
  border-color: var(--primary);
}

.build-search-item.selected {
  border-color: #FF4A4A;
  background: rgba(255, 74, 74, 0.05);
}

/* ── Race Canvas ─────────────────────────────────────────────────────────── */
.race-canvas-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.race-canvas-wrap canvas {
  width: 100%;
  border-radius: var(--radius-md);
  display: block;
}

/* ── Stage Button ────────────────────────────────────────────────────────── */
.stage-btn {
  width: 100%;
  padding: 16px;
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 1.3rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--primary);
  color: var(--text);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.stage-btn:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: var(--shadow-glow-red);
}

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

/* ── Result Modal ────────────────────────────────────────────────────────── */
.race-result {
  text-align: center;
}

.race-result .winner-text {
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 2rem;
  text-transform: uppercase;
  margin-bottom: var(--space-md);
}

.race-result .winner-text.win { color: var(--success); }
.race-result .winner-text.lose { color: var(--error); }

.race-result .margin-text {
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

.result-comparison {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  margin-bottom: var(--space-lg);
}

.result-col {
  padding: var(--space-md);
}

.result-col.car-a-col { text-align: right; }
.result-col.car-b-col { text-align: left; }

.result-col-header {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border);
}

.car-a-col .result-col-header { color: #4A9EFF; }
.car-b-col .result-col-header { color: #FF4A4A; }
.result-col.label-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-sm);
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.result-value {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.25rem;
  margin-bottom: var(--space-md);
}

.result-value.faster { color: var(--success); }

.result-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  flex-wrap: wrap;
}

.btn-facebook {
  background-color: #1877F2;
  color: #fff;
  border: none;
}

.btn-facebook:hover {
  background-color: #166FE5;
  color: #fff;
}

/* ── Leaderboard ─────────────────────────────────────────────────────────── */
.leaderboard-page {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-lg);
}

.leaderboard-page h1 {
  font-family: var(--font-heading);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-lg);
}

.leaderboard-filter {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  align-items: center;
}

.leaderboard-filter select {
  min-width: 250px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th {
  font-family: var(--font-heading);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 12px 16px;
  text-align: left;
  border-bottom: 2px solid var(--border);
}

.leaderboard-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.leaderboard-table tr:hover td {
  background: var(--bg-hover);
}

.leaderboard-table tr.current-user td {
  background: var(--primary-muted);
}

.leaderboard-table .rank-cell {
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 1.2rem;
  width: 50px;
}

.leaderboard-table .rank-cell.top-3 { color: var(--warning); }

.leaderboard-table .et-cell {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
}

.leaderboard-pagination {
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .race-page, .leaderboard-page {
    padding: var(--space-md);
  }

  .stock-car-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-sm);
  }

  .car-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .car-card-stats {
    gap: var(--space-md);
  }

  .result-comparison {
    font-size: 0.85rem;
  }

  .result-value {
    font-size: 1rem;
  }

  .stage-btn {
    font-size: 1.1rem;
    padding: 14px;
  }

  .leaderboard-table {
    font-size: 0.85rem;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 8px 10px;
  }
}

@media (max-width: 480px) {
  .stock-car-grid {
    grid-template-columns: 1fr 1fr;
  }

  .opponent-tabs {
    flex-direction: column;
  }

  .class-filter-btns {
    gap: 4px;
  }
}

/* ── Staging Overlay ────────────────────────────────────────────────────── */
.staging-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: radial-gradient(ellipse at center, #1a1a1a 0%, #000 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.staging-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.staging-logo {
  width: 225px;
  max-width: 70vw;
  height: auto;
  filter: drop-shadow(0 0 30px rgba(230, 57, 70, 0.3));
  margin-bottom: 32px;
}

.staging-text {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: #888;
  margin-bottom: 28px;
  animation: stageTextPulse 1.2s ease-in-out infinite;
}

.staging-lights {
  display: flex;
  align-items: center;
  gap: 16px;
}

.tree-light {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #1a1a1a;
  border: 2px solid #333;
  transition: background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.tree-light.lit {
  background: #D4A800;
  border-color: #D4A800;
  box-shadow: 0 0 12px 4px rgba(212, 168, 0, 0.5), 0 0 40px 8px rgba(212, 168, 0, 0.15);
}

.tree-light.green.lit {
  background: #00CC44;
  border-color: #00CC44;
  box-shadow: 0 0 12px 4px rgba(0, 204, 68, 0.5), 0 0 40px 8px rgba(0, 204, 68, 0.15);
}

@keyframes stageTextPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ── Red Light Foul ─────────────────────────────────────────────────────── */
.tree-light.red-lit {
  background: #FF2222;
  border-color: #FF2222;
  box-shadow: 0 0 12px 4px rgba(255, 34, 34, 0.5), 0 0 40px 8px rgba(255, 34, 34, 0.15);
}

/* ── Launch Button ──────────────────────────────────────────────────────── */
.launch-btn {
  margin-top: 28px;
  padding: 16px 64px;
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 1.5rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  background: #333;
  color: #666;
  border: 2px solid #444;
  border-radius: var(--radius-md);
  cursor: not-allowed;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
  box-shadow: none;
  opacity: 0.6;
}

.launch-btn.ready {
  background: #00CC44;
  color: #000;
  border-color: #00CC44;
  cursor: pointer;
  opacity: 1;
  box-shadow: 0 0 20px rgba(0, 204, 68, 0.3);
  animation: launchPulse 0.8s ease-in-out infinite;
}

.launch-btn.ready:active {
  transform: scale(0.96);
}

@keyframes launchPulse {
  0%, 100% { box-shadow: 0 0 20px rgba(0, 204, 68, 0.3); }
  50% { box-shadow: 0 0 40px rgba(0, 204, 68, 0.6); }
}

/* ── Reaction Time Display ──────────────────────────────────────────────── */
.staging-rt {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 2rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 16px;
  min-height: 2.5rem;
}

.staging-rt.foul {
  color: #FF2222;
}

.staging-rt.good {
  color: #00CC44;
}

/* ── Mod Impact Table ───────────────────────────────────────────────────── */
.mod-impact {
  margin-top: var(--space-lg);
  text-align: left;
}

.mod-impact-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border);
}

.mod-impact table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.mod-impact th {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.mod-impact th:last-child,
.mod-impact td:last-child {
  text-align: right;
}

.mod-impact td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.mod-impact .et-saved {
  color: var(--success);
  font-family: var(--font-heading);
  font-weight: 700;
}

.mod-impact tfoot td {
  font-weight: 700;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.mod-impact .stock-baseline {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: var(--space-sm);
}
