/* ========================================
   Math Racing - Colossal Grey Edition
   ======================================== */

:root {
  --system-blue: #0A84FF;
  --system-red: #FF453A;
  --system-orange: #FF9F0A;
  --system-yellow: #FFD60A;
  --system-green: #32D74B;
  --system-teal: #64D2FF;
  
  --bg-color: #334155; /* Slate Grey */
  --card-bg: rgba(51, 65, 85, 0.9);
  --panel-bg: #475569; /* Lighter Grey */
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  
  --radius-xl: 32px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; width: 100%; overflow: hidden;
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* CUSTOM SCROLLBARS FOR A CLEAN LOOK */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

#game-container { position: relative; width: 100vw; height: 100vh; }

.screen {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: none; flex-direction: column; z-index: 10;
  background: var(--bg-color);
}

.screen.active { display: flex; }

/* START SCREEN */
#start-screen {
  background: linear-gradient(rgba(51, 65, 85, 0.4), rgba(30, 41, 59, 0.9)), 
              url('https://images.unsplash.com/photo-1547915771-05a26d2fd537?auto=format&fit=crop&w=1920&q=80');
  background-size: cover; background-position: center;
  /* Fixed: Use flex-start and padding to prevent clipping when content overflows */
  justify-content: flex-start;
  align-items: center;
  overflow-y: auto;
  padding: 80px 20px;
}

.game-title {
  font-size: 100px; font-weight: 900; letter-spacing: -4px;
  background: linear-gradient(#fff, #94a3b8);
  background-clip: text;
  -webkit-background-clip: text; 
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,0.3));
}

.subtitle {
  font-size: 24px; color: var(--system-teal); font-weight: 600;
  margin-bottom: 50px; text-transform: uppercase; letter-spacing: 2px;
}

.start-content {
  text-align: center;
  z-index: 2;
}

/* LEADERBOARD */
.leaderboard-container {
  margin-top: 50px;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  border: 1px solid #475569;
  border-radius: var(--radius-lg);
  padding: 30px;
  width: 700px;
  max-width: 95vw;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.leaderboard-container h2 {
  font-size: 24px;
  color: var(--system-yellow);
  text-align: center;
  margin-bottom: 15px;
}

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

.leaderboard-header {
  display: grid;
  grid-template-columns: 100px 1fr 40px 40px 70px 80px;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 600;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#leaderboard-rows {
  max-height: 250px;
  overflow-y: auto;
  padding-right: 5px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 100px 1fr 40px 40px 70px 80px;
  font-size: 18px;
  color: var(--text-primary);
  align-items: center;
  padding: 5px 0;
}

.leaderboard-row.empty {
  display: block;
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
  padding: 10px 0;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 12px;
  border-radius: 20px;
}


/* BUTTONS */
.btn {
  padding: 18px 40px; border-radius: 40px; border: none; font-weight: 700;
  text-transform: uppercase; cursor: pointer; transition: all 0.3s ease;
}
.btn-primary { background: var(--system-blue); color: white; box-shadow: 0 10px 20px rgba(10, 132, 255, 0.3); }
.btn-primary:hover { transform: translateY(-3px); box-shadow: 0 15px 30px rgba(10, 132, 255, 0.4); }
.btn-secondary { background: rgba(255,255,255,0.1); color: white; backdrop-filter: blur(10px); }

/* SCROLL FIX */
#results-screen {
  overflow-y: auto;
}

/* SETUP SCREEN - APPLE LIKE STYLING */
#setup-screen { 
  background: linear-gradient(180deg, rgba(51, 65, 85, 0.95) 0%, rgba(15, 23, 42, 1) 100%);
  padding: 60px; 
  overflow-y: auto; 
}

.setup-container {
  max-width: 1000px;
  margin: 0 auto;
}

.setup-section { 
  background: rgba(255, 255, 255, 0.03); 
  backdrop-filter: blur(20px);
  padding: 30px; 
  border-radius: var(--radius-xl); 
  margin-bottom: 30px; 
  border: 1px solid rgba(255, 255, 255, 0.05); 
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  transition: transform 0.2s ease;
}

#game-settings-section {
  margin-top: 50px;
}

.setup-section h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #fff;
  letter-spacing: -0.5px;
}

.player-config { 
  background: rgba(255, 255, 255, 0.02); 
  border: 1px solid rgba(255, 255, 255, 0.08); 
  padding: 25px; 
  border-radius: var(--radius-xl); 
  margin-bottom: 0px; 
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.setting-row:last-child {
  border-bottom: none;
}
.setting-row label {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
}

select {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 10px;
  padding: 10px 15px;
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  appearance: none;
  text-align: right;
  min-width: 150px;
}
select option {
  background: #1e293b;
  color: white;
}

/* GAME SCREEN */
.game-header {
  height: 80px; background: rgba(30, 41, 59, 0.85); backdrop-filter: blur(30px);
  border-bottom: 1px solid #475569; display: flex; align-items: center; justify-content: space-between; padding: 0 40px; z-index: 100;
}

.game-main { flex: 1; display: flex; flex-direction: row; overflow: hidden; background: #0f172a; }
.track-container { flex: 1; position: relative; background: #0f172a; }

.quiz-panel {
  width: 450px; min-width: 450px; background: #1e293b;
  border-left: 1px solid #475569; display: flex; flex-direction: column; padding: 40px; justify-content: center;
}

.players-stats-bar {
  height: 120px; background: #1e293b; border-top: 1px solid #475569;
  display: flex; align-items: center; padding: 0 30px; gap: 20px; overflow-x: auto;
}

.player-stat { min-width: 240px; background: #334155; padding: 15px; border-radius: var(--radius-lg); border: 2px solid #475569; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); position: relative; }
.player-stat.active { background: #51617a; border-width: 5px !important; z-index: 5; }
.player-stat-bar { height: 10px; background: #1e293b; border-radius: 5px; margin: 10px 0; overflow: hidden; }
.player-stat-progress { height: 100%; transition: width 0.3s ease; }

/* QUIZ */
.math-question { font-size: 60px; font-weight: 900; color: #fff; margin-bottom: 40px; text-align: center; }
.answer-buttons { display: flex; flex-direction: column; gap: 15px; width: 100%; }
.btn-answer { background: #475569; color: #fff; font-size: 36px; font-weight: 800; padding: 25px; border-radius: var(--radius-lg); border: none; cursor: pointer; transition: all 0.2s ease; }
.btn-answer:hover { background: var(--system-blue); transform: scale(1.02); }
.btn-answer.correct { background: var(--system-green) !important; }
.btn-answer.wrong { background: var(--system-red) !important; }

@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
  100% { transform: scale(1); opacity: 1; }
}

/* SETUP COMPONENTS */
.player-count-buttons { 
  display: flex; 
  background: rgba(0, 0, 0, 0.2); 
  border-radius: 12px; 
  padding: 4px; 
  width: fit-content;
}

.btn-player-count { 
  width: 60px; 
  height: 40px; 
  border-radius: 8px; 
  border: none; 
  background: transparent; 
  color: var(--text-secondary); 
  font-size: 16px; 
  font-weight: 600; 
  cursor: pointer; 
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-player-count.active { 
  background: rgba(255, 255, 255, 0.2); 
  color: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2); 
}

.vehicle-option {
  padding: 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.vehicle-option:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.vehicle-option.selected {
  background: var(--system-blue-light);
  border-color: var(--system-blue);
  box-shadow: 0 0 15px rgba(0, 122, 255, 0.4);
}

.vehicle-thumb {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: contain;
  border-radius: 8px;
  background: #1a1a1a;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.vehicle-label {
  font-size: 10px;
  font-weight: 600;
  color: #94a3b8;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.vehicle-option.selected .vehicle-label {
  color: white;
}

#player-configs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 25px;
  align-items: start;
}

.overlay { background: rgba(15, 23, 42, 0.9); }
.countdown-number { font-size: 200px; color: var(--system-teal); text-shadow: 0 0 50px rgba(100, 210, 255, 0.5); }

/* RESULTS AND PODIUM */
.results-content {
  width: 100%; max-width: 800px; margin: 0 auto; padding: 40px;
  display: flex; flex-direction: column; align-items: center; gap: 30px;
  z-index: 2;
  overflow-y: auto;
}

.results-title {
  font-size: 48px; font-weight: 900; color: var(--system-yellow);
  text-shadow: 0 4px 10px rgba(0,0,0,0.5); text-align: center;
}

.podium-container {
  display: flex; align-items: flex-end; justify-content: center; gap: 15px;
  height: 250px; margin: 20px 0 40px;
}

.podium-step {
  display: flex; flex-direction: column; align-items: center;
  width: 140px; position: relative;
}

.podium-player-name {
  font-size: 18px; font-weight: 800; margin-bottom: 10px; text-align: center;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%;
}

.podium-stats {
  font-size: 12px; font-weight: 600; background: rgba(0,0,0,0.5);
  padding: 4px 8px; border-radius: 12px; margin-bottom: 10px;
  display: flex; gap: 8px;
}
.stat-correct { color: var(--system-green); }
.stat-wrong { color: var(--system-red); }

.podium-block {
  width: 100%; border-radius: 12px 12px 0 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: 15px; box-shadow: 0 -10px 20px rgba(0,0,0,0.2) inset;
  position: relative; overflow: hidden;
}

.podium-block::after {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 30%;
  background: linear-gradient(180deg, rgba(255,255,255,0.2) 0%, transparent 100%);
}

.podium-rank {
  font-size: 48px; font-weight: 900; color: rgba(255,255,255,0.9);
  text-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.podium-step.rank-1 .podium-block { height: 160px; background: linear-gradient(135deg, #FFD700, #B8860B); }
.podium-step.rank-2 .podium-block { height: 120px; background: linear-gradient(135deg, #E0E0E0, #9E9E9E); }
.podium-step.rank-3 .podium-block { height: 90px; background: linear-gradient(135deg, #CD7F32, #8B4513); }

.results-table {
  width: 100%; background: var(--card-bg); border-radius: var(--radius-lg);
  border: 1px solid #475569; overflow: hidden; margin-bottom: 20px;
}

.results-header {
  display: grid; grid-template-columns: 60px 2fr 1fr 1fr 1fr;
  padding: 15px 20px; background: rgba(255, 255, 255, 0.05); font-weight: 700; color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1); text-transform: uppercase; font-size: 12px;
  letter-spacing: 0.5px;
}

#results-rows {
  max-height: 250px;
  overflow-y: auto;
}

.results-row {
  display: grid; grid-template-columns: 60px 2fr 1fr 1fr 1fr;
  padding: 15px 20px; border-bottom: 1px solid #475569; align-items: center;
  font-weight: 600;
}
.results-row:last-child { border-bottom: none; }

.results-buttons {
  display: flex; gap: 20px; justify-content: center; flex-wrap: wrap;
}

.player-config h3 {
  font-size: 22px;
  margin-bottom: 5px;
  color: var(--system-teal);
}

.diff-select-inline {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  min-width: 180px;
  text-align: left;
}
