/* ─── Reaction Race Game Styles — Professional Polish ─── */

.reaction-race-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1rem;
  background: #0f172a;
  color: #e2e8f0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  position: relative;
  min-height: 500px;
  border-radius: 12px;
}

/* Track area */
.track-area {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.track-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(30, 41, 59, 0.5);
  border-radius: 8px;
  position: relative;
}

.segment-container {
  display: flex;
  gap: 4px;
  flex: 1;
  position: relative;
  padding: 4px 0;
  align-items: center;
}

.avatar-wrapper {
  position: absolute;
  top: 50%;
  transform: translateY(-50%) translateX(-50%);
  left: 0%;
  transition: left 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
}

/* Avatar bounce animation when moving */
.avatar-wrapper.moving .player-avatar {
  animation: avatarBounce 0.5s ease;
}

/* Avatar glow when at finish */
.avatar-wrapper.finished .player-avatar {
  animation: avatarGlow 1.5s ease-in-out infinite;
  box-shadow: 0 0 20px rgba(251, 191, 36, 0.6), 0 0 40px rgba(251, 191, 36, 0.3);
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: white;
  font-size: 14px;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.15);
}

@keyframes avatarBounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.25); }
  50% { transform: scale(0.95); }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes avatarGlow {
  0%, 100% {
    box-shadow: 0 0 16px rgba(251, 191, 36, 0.5), 0 0 32px rgba(251, 191, 36, 0.2);
    border-color: rgba(251, 191, 36, 0.8);
  }
  50% {
    box-shadow: 0 0 24px rgba(251, 191, 36, 0.8), 0 0 48px rgba(251, 191, 36, 0.4);
    border-color: rgba(251, 191, 36, 1);
  }
}

/* Track segments with gradient fill animation */
.track-segment {
  flex: 1;
  height: 24px;
  background: #334155;
  border-radius: 4px;
  transition: background 0.3s, box-shadow 0.3s;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.track-segment.active {
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
  box-shadow: 0 0 12px rgba(14, 165, 233, 0.5), inset 0 0 8px rgba(56, 189, 248, 0.2);
}

/* Shimmer effect on active segments */
.track-segment.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
  animation: segmentShimmer 1.2s ease-in-out infinite;
}

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

/* Streak bonus — golden segments */
.track-segment.streak {
  background: linear-gradient(90deg, #f59e0b, #fbbf24) !important;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.5), inset 0 0 8px rgba(251, 191, 36, 0.2);
}

.track-segment.streak::after {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
}

.finish-flag {
  margin-left: 0.5rem;
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.4));
}

.finished-badge {
  display: none;
  margin-left: 0.5rem;
  color: #10b981;
  font-weight: bold;
  font-size: 12px;
  flex-shrink: 0;
  white-space: nowrap;
  text-shadow: 0 0 8px rgba(16, 185, 129, 0.3);
}

/* Game content layout */
.game-content {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.question-wrapper {
  flex: 1;
  min-width: 0;
}

/* ─── Ranking Sidebar — Gold/Silver/Bronze gradients ─── */
.ranking-list {
  background: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 1rem;
  min-width: 240px;
  max-width: 320px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  flex-shrink: 0;
}

.ranking-title {
  font-weight: bold;
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: #f8fafc;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  padding-bottom: 0.5rem;
}

.ranking-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  font-size: 0.9rem;
  gap: 0.5rem;
  border-radius: 8px;
  transition: background 0.2s, transform 0.2s;
}

.ranking-item:last-child {
  border-bottom: none;
}

.ranking-item:hover {
  background: rgba(255, 255, 255, 0.03);
  transform: translateX(2px);
}

/* Top 3 rankings with gradient backgrounds */
.ranking-item.rank-1st {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.08));
  border: 1px solid rgba(251, 191, 36, 0.3);
  margin-bottom: 0.35rem;
}

.ranking-item.rank-2nd {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.12), rgba(203, 213, 225, 0.06));
  border: 1px solid rgba(148, 163, 184, 0.2);
  margin-bottom: 0.35rem;
}

.ranking-item.rank-3rd {
  background: linear-gradient(135deg, rgba(180, 83, 9, 0.12), rgba(217, 119, 6, 0.06));
  border: 1px solid rgba(180, 83, 9, 0.2);
  margin-bottom: 0.35rem;
}

.rank-medal {
  width: 24px;
  display: inline-block;
  text-align: center;
  margin-right: 4px;
  font-size: 1rem;
}

.rank-gold {
  color: #fbbf24;
  filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.4));
}

.rank-silver {
  color: #cbd5e1;
  filter: drop-shadow(0 0 4px rgba(203, 213, 225, 0.3));
}

.rank-bronze {
  color: #d97706;
  filter: drop-shadow(0 0 4px rgba(217, 119, 6, 0.3));
}

.rank-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.rank-score {
  font-weight: 700;
  color: #fbbf24;
  font-variant-numeric: tabular-nums;
}

/* ─── Confetti — Multiple shapes, more colors ─── */
.confetti-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}

.confetti {
  position: absolute;
  animation: confettiFall 2.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* Shape: square (default) */
.confetti.square {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

/* Shape: circle */
.confetti.circle {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Shape: star (using clip-path) */
.confetti.star {
  width: 12px;
  height: 12px;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

/* Shape: diamond */
.confetti.diamond {
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  border-radius: 1px;
}

/* Shape: triangle */
.confetti.triangle {
  width: 10px;
  height: 10px;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

/* Confetti colors — vibrant palette */
.confetti.c-red { background: #ef4444; }
.confetti.c-blue { background: #3b82f6; }
.confetti.c-green { background: #22c55e; }
.confetti.c-yellow { background: #facc15; }
.confetti.c-purple { background: #a855f7; }
.confetti.c-pink { background: #ec4899; }
.confetti.c-orange { background: #f97316; }
.confetti.c-cyan { background: #06b6d4; }
.confetti.c-gold { background: #fbbf24; }
.confetti.c-lime { background: #84cc16; }

@keyframes confettiFall {
  0% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }
  50% {
    opacity: 0.9;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) rotate(var(--rot)) scale(0.5);
    opacity: 0;
  }
}

/* ─── End Overlay ─── */
.phase-overlay.ended {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: inherit;
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-content {
  text-align: center;
  padding: 2rem;
  max-width: 520px;
  width: 90%;
}

.overlay-content h1 {
  font-size: 2.25rem;
  margin-bottom: 1.5rem;
  color: #fbbf24;
  text-shadow: 0 2px 12px rgba(251, 191, 36, 0.4);
  animation: trophyBounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}

@keyframes trophyBounce {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* Final rankings with staggered entry */
.final-rankings {
  margin-bottom: 1.5rem;
  background: rgba(30, 41, 59, 0.6);
  border-radius: 12px;
  padding: 1rem;
  text-align: left;
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.final-rank-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  color: #e2e8f0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 8px;
  animation: rankRowSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  transition: background 0.2s;
}

.final-rank-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.final-rank-row:last-child {
  border-bottom: none;
}

/* Staggered entry delays */
.final-rank-row:nth-child(1) { animation-delay: 0.1s; }
.final-rank-row:nth-child(2) { animation-delay: 0.2s; }
.final-rank-row:nth-child(3) { animation-delay: 0.3s; }
.final-rank-row:nth-child(4) { animation-delay: 0.4s; }
.final-rank-row:nth-child(5) { animation-delay: 0.5s; }
.final-rank-row:nth-child(6) { animation-delay: 0.6s; }
.final-rank-row:nth-child(7) { animation-delay: 0.7s; }
.final-rank-row:nth-child(8) { animation-delay: 0.8s; }

@keyframes rankRowSlideIn {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Top 3 final ranking rows */
.final-rank-row.rank-gold-row {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.12), rgba(245, 158, 11, 0.05));
  border: 1px solid rgba(251, 191, 36, 0.25);
}

.final-rank-row.rank-silver-row {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.1), rgba(203, 213, 225, 0.04));
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.final-rank-row.rank-bronze-row {
  background: linear-gradient(135deg, rgba(180, 83, 9, 0.1), rgba(217, 119, 6, 0.04));
  border: 1px solid rgba(180, 83, 9, 0.15);
}

.btn-play-again {
  padding: 0.875rem 2.5rem;
  font-size: 1.05rem;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #38bdf8);
  color: white;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.3);
  position: relative;
  overflow: hidden;
}

.btn-play-again::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transition: left 0.5s ease;
}

.btn-play-again:hover {
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(14, 165, 233, 0.4);
}

.btn-play-again:hover::after {
  left: 100%;
}

.btn-play-again:active {
  transform: scale(0.98);
}

/* ─── Question area ─── */
.question-area {
  background: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(4px);
  border-radius: 12px;
  padding: 1.5rem;
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.question-text {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #f8fafc;
  line-height: 1.4;
}

.timer-display {
  font-size: 0.9rem;
  color: #94a3b8;
  margin-bottom: 0.5rem;
}

.timer-bar-wrap {
  width: 100%;
  height: 6px;
  background: #334155;
  border-radius: 3px;
  margin-bottom: 1.5rem;
  overflow: hidden;
  position: relative;
}

.timer-bar {
  height: 100%;
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
  border-radius: 3px;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px rgba(14, 165, 233, 0.3);
}

.timer-bar.warning {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
}

.timer-bar.danger {
  background: linear-gradient(90deg, #ef4444, #f97316);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.3);
}

.options-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.option-btn {
  padding: 0.875rem 1rem;
  border: 1px solid #334155;
  border-radius: 10px;
  background: #1e293b;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
  text-align: left;
  line-height: 1.3;
  position: relative;
  overflow: hidden;
}

.option-btn:hover:not(:disabled) {
  border-color: #0ea5e9;
  background: #0f172a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.15);
}

.option-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.option-btn.correct {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.2);
  animation: correctPulse 0.5s ease;
}

.option-btn.wrong {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.2);
  animation: wrongShake 0.4s ease;
}

@keyframes correctPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.waiting-text {
  text-align: center;
  color: #94a3b8;
  margin-top: 1rem;
  font-style: italic;
}

/* ─── Speed bonus popup ─── */
.speed-bonus {
  position: absolute;
  font-size: 0.875rem;
  font-weight: 700;
  color: #fbbf24;
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
  pointer-events: none;
  animation: speedBonusFloat 1s ease-out forwards;
  z-index: 10;
}

@keyframes speedBonusFloat {
  0% { opacity: 1; transform: translateY(0) scale(0.8); }
  50% { opacity: 1; transform: translateY(-20px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-40px) scale(0.9); }
}

/* ─── Mobile Responsive ─── */
@media (max-width: 640px) {
  .reaction-race-container {
    padding: 0.75rem;
    gap: 1rem;
  }

  .game-content {
    flex-direction: column;
  }

  .ranking-list {
    min-width: auto;
    width: 100%;
    max-width: none;
    padding: 0.75rem;
  }

  .track-row {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .segment-container {
    min-width: 100%;
    order: 2;
  }

  .track-segment {
    height: 18px;
  }

  .player-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .finish-flag {
    order: 1;
    margin-left: auto;
  }

  .finished-badge {
    order: 3;
    width: 100%;
    text-align: right;
    margin-left: 0;
  }

  .options-wrap {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .option-btn {
    padding: 0.75rem;
    font-size: 0.9rem;
    min-height: 48px;
  }

  .question-text {
    font-size: 1rem;
  }

  .question-area {
    padding: 1rem;
  }

  .overlay-content h1 {
    font-size: 1.75rem;
  }

  .overlay-content {
    padding: 1.5rem 1rem;
  }

  .final-rank-row {
    font-size: 0.9rem;
    padding: 0.5rem;
  }

  .btn-play-again {
    padding: 0.75rem 2rem;
    font-size: 1rem;
  }

  .ranking-item {
    padding: 0.5rem;
    font-size: 0.85rem;
  }
}
