/* ============================================
   RACE TAB - Chao Garden Racing Minigame
   ============================================ */

/* --- Opponent Picker --- */

.race-subtitle {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 1rem;
}

.race-opponents-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.race-opponent-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 20px;
  transition: all 0.2s ease;
}

.race-opponent-card:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: translateY(-2px);
}

.race-opponent-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.race-opponent-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.race-opponent-info {
  flex: 1;
  min-width: 0;
}

.race-opponent-name {
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.race-opponent-level {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 600;
}

.race-opponent-stats {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.2rem;
}

.race-stat {
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
}

.race-btn {
  flex-shrink: 0;
  padding: 0.5rem 1rem !important;
  font-size: 0.9rem !important;
  border-radius: 14px !important;
}

/* --- Countdown --- */

.race-countdown-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 350px;
  gap: 2rem;
}

.race-matchup {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.race-matchup-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.race-matchup-vs {
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: white;
  text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.3);
}

.race-matchup-name {
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.race-countdown-number {
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 6rem;
  font-weight: 700;
  color: white;
  text-shadow: 4px 4px 0px rgba(0, 0, 0, 0.3);
  line-height: 1;
}

.race-countdown-number--pop {
  animation: countdown-pop 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.race-countdown-number--go {
  color: #FFD700;
  font-size: 8rem;
  animation: countdown-go 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes countdown-pop {
  0% { transform: scale(2); opacity: 0; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes countdown-go {
  0% { transform: scale(3); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Race HUD --- */

.race-hud {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 16px;
  margin-bottom: 0.5rem;
}

.race-timer {
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  min-width: 60px;
  text-align: center;
}

.race-position-bar {
  flex: 1;
  position: relative;
}

.race-position-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  position: relative;
  overflow: visible;
}

.race-position-marker {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  transition: left 0.1s linear;
}

.race-position-marker--player {
  background: #fbbf24;
  border: 2px solid white;
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.6);
}

.race-position-marker--ghost {
  background: #a78bfa;
  border: 2px solid rgba(255, 255, 255, 0.6);
  opacity: 0.7;
}

.race-position-segments {
  display: flex;
  margin-top: 3px;
  height: 3px;
  border-radius: 2px;
  overflow: hidden;
}

.race-position-seg { height: 100%; }
.race-position-seg--sprint { background: #4ade80; }
.race-position-seg--climb { background: #a78bfa; }
.race-position-seg--swim { background: #60a5fa; }

/* --- Race Viewport --- */

.race-viewport {
  width: 100%;
  height: 220px;
  overflow: hidden;
  position: relative;
  border-radius: 20px;
  border: 3px solid rgba(255, 255, 255, 0.5);
  background: linear-gradient(180deg, #87CEEB 0%, #B8E6FF 60%, #7CB342 60%, #558B2F 100%);
}

.race-viewport--boosting::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0px,
    transparent 40px,
    rgba(255, 255, 255, 0.06) 40px,
    rgba(255, 255, 255, 0.06) 42px
  );
  animation: speed-bg 0.15s linear infinite;
  pointer-events: none;
  z-index: 5;
}

@keyframes speed-bg {
  0% { transform: translateX(0); }
  100% { transform: translateX(-42px); }
}

.race-track {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  will-change: transform;
}

/* --- Terrain Segments --- */

.race-segment {
  position: absolute;
  top: 0;
  height: 100%;
}

.race-segment--sprint {
  background: linear-gradient(180deg,
    #87CEEB 0%, #B8E6FF 55%,
    #7CB342 55%, #558B2F 75%,
    #5D4037 75%, #3E2723 100%
  );
}

.race-segment--climb {
  background: linear-gradient(180deg,
    #9575CD 0%, #7E57C2 25%,
    #8D6E63 25%, #6D4C41 60%,
    #5D4037 60%, #4E342E 100%
  );
}

.race-segment--swim {
  background: linear-gradient(180deg,
    #87CEEB 0%, #64B5F6 30%,
    #42A5F5 30%, #1E88E5 70%,
    #1565C0 70%, #0D47A1 100%
  );
}

.race-segment--swim::before {
  content: '';
  position: absolute;
  top: 28%;
  left: 0;
  right: 0;
  height: 8px;
  background: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.3) 0px,
    rgba(255, 255, 255, 0) 20px,
    rgba(255, 255, 255, 0.3) 40px
  );
  animation: waves 2s linear infinite;
  z-index: 1;
}

@keyframes waves {
  0% { background-position-x: 0; }
  100% { background-position-x: 40px; }
}

.race-segment-label {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  z-index: 1;
}

.race-finish-line {
  position: absolute;
  top: 0;
  height: 100%;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: repeating-linear-gradient(
    0deg,
    white 0px, white 10px,
    #333 10px, #333 20px
  );
  opacity: 0.7;
  z-index: 2;
}

/* --- Characters --- */

.race-character {
  position: absolute;
  z-index: 10;
  will-change: transform;
  transition: bottom 0.3s ease;
}

.race-blob {
  position: relative;
  width: 44px;
  height: 40px;
}

.race-blob--small {
  width: 24px;
  height: 22px;
}

.race-blob--small .race-blob-body {
  width: 24px;
  height: 22px;
}

.race-blob-body {
  width: 40px;
  height: 36px;
  border-radius: 50% 50% 45% 45%;
  position: absolute;
  top: 0;
  left: 2px;
  border: 2.5px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.race-blob--player .race-blob-body {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

.race-blob--ghost .race-blob-body {
  background: linear-gradient(135deg, #a78bfa, #8b5cf6);
  opacity: 0.65;
}

/* Eyes */
.race-blob-eye {
  width: 7px;
  height: 8px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 10px;
  z-index: 1;
}

.race-blob-eye--left { left: 11px; }
.race-blob-eye--right { left: 24px; }

.race-blob-pupil {
  width: 3.5px;
  height: 3.5px;
  background: #333;
  border-radius: 50%;
  position: absolute;
  top: 2.5px;
  left: 2px;
}

/* Feet */
.race-blob-foot {
  width: 10px;
  height: 6px;
  border-radius: 0 0 5px 5px;
  position: absolute;
  bottom: -4px;
  background: inherit;
}

.race-blob--player .race-blob-foot { background: #f59e0b; }
.race-blob--ghost .race-blob-foot { background: #8b5cf6; opacity: 0.65; }

.race-blob-foot--left { left: 8px; }
.race-blob-foot--right { right: 8px; }

/* Character label */
.race-char-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

/* --- Character Animation States --- */

/* Running */
.race-char--running .race-blob {
  animation: char-bounce 0.35s ease-in-out infinite;
}

.race-char--running .race-blob-foot--left {
  animation: char-run-foot 0.35s ease-in-out infinite;
}

.race-char--running .race-blob-foot--right {
  animation: char-run-foot 0.35s ease-in-out infinite 0.175s;
}

@keyframes char-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes char-run-foot {
  0%, 100% { transform: translateX(0) translateY(0); }
  50% { transform: translateX(4px) translateY(-3px); }
}

/* Climbing */
.race-char--climbing .race-blob {
  animation: char-climb 0.6s ease-in-out infinite;
}

@keyframes char-climb {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* Swimming */
.race-char--swimming .race-blob {
  animation: char-swim 0.8s ease-in-out infinite;
}

@keyframes char-swim {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-4px) rotate(3deg); }
  75% { transform: translateY(4px) rotate(-3deg); }
}

/* Boosting */
.race-char--boosting .race-blob-body {
  box-shadow: 0 0 20px rgba(255, 165, 0, 0.8), 0 0 40px rgba(255, 100, 0, 0.3);
  filter: brightness(1.3);
}

.race-boost-trail {
  display: none;
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 16px;
}

.race-char--boosting .race-boost-trail {
  display: block;
}

.race-boost-trail::before,
.race-boost-trail::after {
  content: '';
  position: absolute;
  height: 2px;
  background: linear-gradient(to left, rgba(255, 200, 0, 0.9), transparent);
  animation: speed-line 0.3s linear infinite;
}

.race-boost-trail::before {
  top: 3px;
  width: 35px;
  right: 0;
}

.race-boost-trail::after {
  bottom: 3px;
  width: 25px;
  right: 5px;
  animation-delay: 0.15s;
}

@keyframes speed-line {
  0% { opacity: 1; transform: scaleX(1); }
  100% { opacity: 0; transform: scaleX(0.3); }
}

/* Exhausted */
.race-char--exhausted .race-blob-body {
  filter: saturate(0.4) brightness(0.7);
}

.race-char--exhausted .race-blob {
  animation: char-wobble 0.8s ease-in-out infinite;
}

@keyframes char-wobble {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-2px) rotate(-4deg); }
  75% { transform: translateY(-1px) rotate(4deg); }
}

/* --- Controls: Stamina + Boost --- */

.race-controls {
  margin-top: 0.75rem;
}

.race-stamina-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.race-stamina-label {
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-weight: 700;
  font-size: 0.8rem;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  text-transform: uppercase;
  letter-spacing: 1px;
  min-width: 65px;
}

.race-stamina-bar {
  flex: 1;
  height: 22px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 11px;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  overflow: hidden;
}

.race-stamina-fill {
  height: 100%;
  background: linear-gradient(90deg, #00FF88, #00CC66);
  border-radius: 9px;
  transition: width 0.1s linear;
}

.race-stamina-fill--low {
  background: linear-gradient(90deg, #FF8C00, #FF6B00);
  animation: stamina-pulse 0.5s ease-in-out infinite;
}

.race-stamina-fill--empty {
  background: linear-gradient(90deg, #FF4444, #CC0000);
  animation: stamina-pulse 0.3s ease-in-out infinite;
}

@keyframes stamina-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.race-boost-btn {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  padding: 0.9rem 2rem;
  background: linear-gradient(135deg, #FF6B00, #FF8C00);
  border: 4px solid rgba(255, 255, 255, 0.6);
  border-radius: 22px;
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: white;
  text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 107, 0, 0.4);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
  transition: all 0.1s ease;
}

.race-boost-btn:active,
.race-boost-btn--active {
  background: linear-gradient(135deg, #FF8C00, #FFB347);
  transform: scale(0.96);
  box-shadow: 0 2px 8px rgba(255, 107, 0, 0.6);
}

.race-boost-btn--disabled,
.race-boost-btn:disabled {
  background: linear-gradient(135deg, #888, #666);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: none;
  cursor: default;
}

/* --- Results --- */

.race-results-card {
  text-align: center;
}

.race-results-title {
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 2.5rem;
  font-weight: 700;
  color: white;
  text-shadow: 3px 3px 0px rgba(0, 0, 0, 0.3);
  margin-bottom: 1.5rem;
}

.race-results-title--win {
  color: #FFD700;
  animation: win-glow 1.5s ease-in-out infinite;
}

.race-results-title--lose {
  color: #FF6B6B;
}

@keyframes win-glow {
  0%, 100% { text-shadow: 3px 3px 0px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 215, 0, 0.3); }
  50% { text-shadow: 3px 3px 0px rgba(0, 0, 0, 0.3), 0 0 40px rgba(255, 215, 0, 0.6); }
}

.race-result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  margin-bottom: 0.5rem;
}

.race-result-player {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-weight: 600;
  color: white;
}

.race-result-time {
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.race-result-diff {
  font-family: 'Fredoka', 'Comic Neue', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 0.75rem;
}

.race-results-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* --- Responsive --- */

@media (max-width: 768px) {
  .race-viewport {
    height: 200px;
    border-radius: 16px;
  }

  .race-countdown-number {
    font-size: 5rem;
  }

  .race-countdown-number--go {
    font-size: 6rem;
  }

  .race-boost-btn {
    max-width: none;
    padding: 0.8rem 1.5rem;
    font-size: 1.2rem;
  }

  .race-results-title {
    font-size: 2rem;
  }

  .race-controls {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
