:root {
  --ui-bg: rgba(10, 12, 16, 0.7);
  --ui-text: #f8fafc;
  --accent: #4f46e5;
  --danger: #ff4444;
  --ok: #33ff66;
  --gold: #fbbf24;
  --cyan: #22d3ee;
}
html, body { margin: 0; height: 100%; overflow: hidden; background: #0f1117; font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji"; color: var(--ui-text); }

/* Ensure images never overflow their containers and scale responsively */
img {
  max-width: 100%;
  height: auto;
}

#hud { position: fixed; inset: 0 auto auto 0; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 10px 12px; z-index: 12; pointer-events: none; }
#lifeBar { position: relative; width: min(280px, 28vw); height: 16px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); border-radius: 999px; overflow: hidden; box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 6px 16px rgba(0,0,0,0.35); }
#lifeFill { position: absolute; inset: 0 auto 0 0; width: 100%; background: linear-gradient(90deg, #22c55e, #16a34a); transition: width 180ms ease; }
#lifeText { font-weight: 700; opacity: 0.9; pointer-events: none; }

#score { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); padding: 8px 14px; background: var(--ui-bg); border: 1px solid rgba(255,255,255,0.1); border-radius: 999px; font-weight: 700; letter-spacing: 0.4px; user-select: none; z-index: 10; backdrop-filter: blur(6px); box-shadow: 0 6px 20px rgba(0,0,0,0.35); }

/* Quiz panel moved top-right to avoid blocking the road - enhanced visibility */
#quiz { position: fixed; top: 16px; right: 16px; padding: 12px 18px; background: rgba(251, 191, 36, 0.25); border: 2px solid rgba(251, 191, 36, 0.6); border-radius: 16px; font-weight: 900; font-size: 18px; letter-spacing: 0.5px; user-select: none; z-index: 11; text-shadow: 0 2px 4px rgba(0,0,0,0.4); display: none; pointer-events: none; box-shadow: 0 8px 32px rgba(251, 191, 36, 0.3); backdrop-filter: blur(8px); }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: radial-gradient(1200px 800px at 50% 50%, rgba(17,19,26,0.86), rgba(12,14,19,0.96)); color: var(--ui-text); text-align: center; padding: 24px; }
.panel { width: min(820px, 92vw); max-height: 90vh; overflow-y: auto; background: rgba(15,17,23,0.7); border: 1px solid rgba(255,255,255,0.08); border-radius: 16px; padding: 24px; box-shadow: 0 25px 80px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05); backdrop-filter: blur(10px); display: flex; flex-direction: column; }

/* Game Logo Styles */
.game-logo {
  width: clamp(200px, 50vw, 400px); /* Responsive width that scales with title */
  height: auto;
  margin: 0 auto 16px auto; /* Center horizontally with bottom margin */
  display: block;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3)); /* Subtle shadow for depth */
  transition: transform 0.3s ease, filter 0.3s ease;
  animation: logoFadeIn 1s ease-out; /* Entrance animation */
}

.game-logo:hover {
  transform: scale(1.02); /* Slight scale on hover */
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.4)) brightness(1.05);
}

/* Logo entrance animation */
@keyframes logoFadeIn {
  0% { 
    opacity: 0; 
    transform: translateY(-20px) scale(0.95); 
  }
  100% { 
    opacity: 1; 
    transform: translateY(0) scale(1); 
  }
}

/* Mobile adjustments for logo */
@media (max-width: 480px) {
  .game-logo {
    width: clamp(150px, 60vw, 250px);
    margin-bottom: 12px;
  }
}

h1 { margin: 0 0 8px; font-size: clamp(24px, 4vw, 40px); letter-spacing: 0.4px; }
p { opacity: 0.9; }
.kbd { display: inline-block; padding: 2px 8px; border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; margin: 0 2px; background: rgba(255,255,255,0.06); font-weight: 600; }
.row { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
.row.button-row { margin-top: auto; padding-top: 16px; flex-shrink: 0; border-top: 1px solid rgba(255,255,255,0.1); }
.btn { appearance: none; border: none; background: linear-gradient(180deg, #6366f1, #4f46e5); color: white; padding: 14px 22px; border-radius: 12px; font-weight: 800; letter-spacing: 0.6px; margin-top: 16px; cursor: pointer; box-shadow: 0 10px 30px rgba(79,70,229,0.45); transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.2s ease; }
.btn:hover { filter: brightness(1.06); box-shadow: 0 16px 40px rgba(79,70,229,0.55); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn[disabled] { cursor: not-allowed; opacity: 0.7; filter: grayscale(0.2) brightness(0.9); box-shadow: none; }
.muted { color: #b3b9c6; font-size: 14px; }
.hidden { display: none; }
canvas { 
  display: block; 
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
}
select.sel { 
  appearance: none; 
  background: linear-gradient(145deg, rgba(255,255,255,0.08), rgba(255,255,255,0.04)); 
  color: #ffffff; 
  border: 1px solid rgba(255,255,255,0.25); 
  padding: 12px 16px; 
  border-radius: 14px; 
  font-weight: 700; 
  font-size: 14px;
  letter-spacing: 0.4px; 
  cursor: pointer; 
  box-shadow: 0 8px 25px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.1); 
  transition: all 0.3s ease; 
  backdrop-filter: blur(8px);
  position: relative;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 16px 16px;
  padding-right: 40px;
}
select.sel:hover { 
  border-color: rgba(79,70,229,0.6); 
  box-shadow: 0 12px 35px rgba(79,70,229,0.25), inset 0 1px 0 rgba(255,255,255,0.15); 
  background: linear-gradient(145deg, rgba(79,70,229,0.1), rgba(79,70,229,0.05));
  transform: translateY(-1px);
}
select.sel:focus { 
  outline: none; 
  border-color: rgba(79,70,229,0.8); 
  box-shadow: 0 0 0 3px rgba(79,70,229,0.25), 0 12px 35px rgba(79,70,229,0.35); 
  background: linear-gradient(145deg, rgba(79,70,229,0.12), rgba(79,70,229,0.06));
}
select.sel option {
  background: #1a1d29;
  color: #ffffff;
  padding: 12px 16px;
  font-weight: 600;
  border: none;
}
.chip { padding: 8px 10px; border-radius: 999px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.18); font-weight: 700; }
.volume-slider { width: 80px; height: 4px; -webkit-appearance: none; background: rgba(255,255,255,0.2); border-radius: 2px; outline: none; }
.volume-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; background: var(--accent); border-radius: 50%; cursor: pointer; }
.volume-slider::-moz-range-thumb { width: 16px; height: 16px; background: var(--accent); border-radius: 50%; cursor: pointer; border: none; }
.circuit-thumb { 
  width: 84px; 
  height: 48px; 
  object-fit: contain; /* Changed from cover to contain for SVGs */
  object-position: center;
  border-radius: 8px; 
  border: 1px solid rgba(255,255,255,0.18); 
  box-shadow: 0 6px 20px rgba(0,0,0,0.25); 
  background: rgba(255,255,255,0.05); /* Light background to help SVG visibility */
  padding: 4px; /* Add padding so SVG doesn't touch edges */
}

/* Loading Progress Bar Styles */
.loading-container {
  margin-top: 24px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.loading-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
  margin-bottom: 8px;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #22d3ee);
  border-radius: 12px;
  width: 0%;
  transition: width 0.3s ease;
  box-shadow: 0 0 12px rgba(79,70,229,0.6);
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.loading-status {
  font-size: 14px;
  color: #b3b9c6;
  font-weight: 600;
  min-height: 20px;
}

/* Game Over Statistics Styles */
.game-stats {
  margin: 20px 0;
  padding: 16px;
  background: rgba(0,0,0,0.3);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  text-align: left;
  flex: 1;
  max-height: 60vh;
  overflow-y: auto;
}

.game-stats h3 {
  margin: 0 0 12px 0;
  text-align: center;
  color: var(--gold);
  font-size: 18px;
}

.game-stats h4 {
  margin: 16px 0 8px 0;
  color: #22d3ee;
  font-size: 14px;
  font-weight: 700;
}

.stats-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
}

.stat-label {
  font-weight: 600;
  color: #b3b9c6;
  font-size: 14px;
}

.stat-value {
  font-weight: 700;
  color: #ffffff;
  font-size: 14px;
}

.operation-breakdown, .level-breakdown {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.operation-item, .level-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.operation-item.addition { border-left-color: #22c55e; }
.operation-item.subtraction { border-left-color: #f59e0b; }
.operation-item.multiplication { border-left-color: #ef4444; }
.operation-item.division { border-left-color: #8b5cf6; }
.operation-item.mixed { border-left-color: var(--cyan); }

.operation-name, .level-name {
  font-weight: 600;
  color: #e2e8f0;
}

.operation-stats, .level-stats {
  font-weight: 500;
  color: #94a3b8;
}

/* Gem Counter Styles */
.gem-counter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  font-size: 12px;
}

.gem-counter-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.gem-shape-name {
  font-weight: 600;
  color: #e2e8f0;
  text-transform: capitalize;
}

.gem-count {
  font-weight: 700;
  color: var(--gold);
  font-size: 13px;
}

/* HUD Gem Counter Styles */
.gem-counter-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  max-width: min(400px, 40vw);
  padding: 8px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.gem-counter-hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.2), rgba(139, 92, 246, 0.2));
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.gem-counter-hud-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transition: left 0.5s ease;
}

.gem-counter-hud-item:hover::before {
  left: 100%;
}

.gem-hud-emoji {
  font-size: 14px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
  animation: gemPulse 2s ease-in-out infinite;
}

.gem-hud-count {
  color: var(--gold);
  font-weight: 800;
  min-width: 16px;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  font-size: 13px;
}

@keyframes gemPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Gem counter title */
.gem-counter-title {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Challenge History Styles */
.challenge-history-list {
  max-height: 200px;
  overflow-y: auto;
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.challenge-item {
  display: grid;
  grid-template-columns: 1fr 60px 60px;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
  border-left: 3px solid;
}

.challenge-item.correct { border-left-color: #22c55e; }
.challenge-item.wrong { border-left-color: #ef4444; }
.challenge-item.avoided { border-left-color: #6b7280; }

.challenge-question {
  font-weight: 600;
  color: #e2e8f0;
  font-family: monospace;
}

.challenge-answer {
  text-align: center;
  font-weight: 500;
  font-family: monospace;
}

.challenge-answer.correct { color: #22c55e; }
.challenge-answer.wrong { color: #ef4444; }
.challenge-answer.avoided { color: #6b7280; }

.challenge-result {
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}

.challenge-result.correct { color: #22c55e; }
.challenge-result.wrong { color: #ef4444; }
.challenge-result.avoided { color: #6b7280; }

/* Start Line Screen Styles */
.start-line-container {
  text-align: center;
  max-width: 600px;
}

.countdown-text {
  font-size: clamp(48px, 8vw, 80px);
  margin: 0 0 24px 0;
  color: var(--gold);
  text-shadow: 0 4px 8px rgba(0,0,0,0.5);
  animation: pulse 2s infinite;
}

.start-instructions {
  margin: 24px 0;
}

.start-instructions p {
  margin: 8px 0;
  font-size: 18px;
}

.countdown-numbers {
  font-size: clamp(120px, 20vw, 200px);
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 8px 16px rgba(0,0,0,0.7);
  animation: countdownPulse 1s ease-in-out;
  margin: 40px 0;
}

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

@keyframes countdownPulse {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.countdown-numbers.go {
  color: var(--ok);
  animation: goAnimation 1s ease-out;
}

@keyframes goAnimation {
  0% { transform: scale(0.5); opacity: 0; color: var(--ok); }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Progress Tracker Styles */
#progressTracker {
  position: fixed;
  top: 80px;
  right: 16px;
  width: 120px;
  background: rgba(15,17,23,0.8);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(8px);
  z-index: 10;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

#progressTitle {
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  color: #f8fafc;
  opacity: 0.9;
}

#levelDisplay {
  background: rgba(0,0,0,0.3);
  padding: 8px;
  border-radius: 4px;
  margin-bottom: 8px;
  border-left: 3px solid #22d3ee;
}

#currentLevelInfo {
  font-size: 12px;
  color: #22d3ee;
  font-weight: bold;
  text-align: center;
}

#progressContainer {
  min-height: 100px;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
}

.progress-indicator {
  width: 100%;
  height: 22px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #e5e7eb; /* default light text */
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  animation: progressPop 0.3s ease-out;
  position: relative;
  overflow: hidden;
}

.progress-indicator.correct {
  background: linear-gradient(135deg, rgba(34,197,94,0.2), rgba(22,163,74,0.2));
  color: #22c55e;
  box-shadow: 0 2px 8px rgba(34,197,94,0.25);
}

.progress-indicator.wrong {
  background: linear-gradient(135deg, rgba(239,68,68,0.2), rgba(220,38,38,0.2));
  color: #ef4444;
  box-shadow: 0 2px 8px rgba(239,68,68,0.25);
}

.progress-indicator.avoided {
  background: linear-gradient(135deg, rgba(249,115,22,0.2), rgba(234,88,12,0.2));
  color: #f59e0b;
  box-shadow: 0 2px 8px rgba(249,115,22,0.25);
}

.progress-indicator::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: progressShine 0.8s ease-out;
}

#progressStats {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}

.progress-stat {
  display: flex;
  align-items: center;
  gap: 2px;
  font-weight: 700;
}

.progress-stat.correct { color: #22c55e; }
.progress-stat.wrong { color: #ef4444; }
.progress-stat.avoided { color: #f97316; }

@keyframes progressPop {
  0% { transform: scale(0.8) translateY(-10px); opacity: 0; }
  50% { transform: scale(1.05) translateY(0); }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes progressShine {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Custom scrollbar for progress container */
#progressContainer::-webkit-scrollbar {
  width: 4px;
}

#progressContainer::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

#progressContainer::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
}

#progressContainer::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.4);
}
