/* classroomGames/race.css */

.race-game {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  color: #000;
  font-family: "Fredoka", Arial, sans-serif;
}

.race-control-panel {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 210px 180px;
  gap: 12px;
  align-items: center;
  background: #ffe9ff;
  border: 7px solid #000;
  border-radius: 22px;
  padding: 12px 16px;
  box-shadow: 8px 8px 0 rgba(0,0,0,0.22);
}

.race-title-box h2 {
  margin: 0;
  font-size: 30px;
  font-weight: 900;
}

.race-title-box p {
  margin: 4px 0 0;
  font-size: 15px;
  font-weight: 900;
}

.race-leader-box {
  background: #d3ff00;
  border: 5px solid #000;
  border-radius: 16px;
  padding: 8px 12px;
  text-align: center;
  box-shadow: 5px 5px 0 rgba(0,0,0,0.22);
}

.race-leader-box span {
  display: block;
  font-size: 13px;
  font-weight: 900;
}

.race-leader-box strong {
  display: block;
  font-size: 18px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.race-reset-btn {
  width: 100%;
  height: 56px;
  background: #ff9b42;
  font-size: 17px;
  font-weight: 900;
}

.race-name-controls {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 9px;
}

.race-name-btn {
  flex: 0 0 auto;
  min-width: 160px;
  height: 64px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  background: #23d8ff;
  border: 5px solid #000;
  border-radius: 16px;
  padding: 8px 10px;
  box-shadow: 5px 5px 0 rgba(0,0,0,0.25);
  font-family: "Fredoka", Arial, sans-serif;
  font-weight: 900;
}

.race-name-btn strong {
  font-size: 20px;
  line-height: 1;
  overflow-wrap: anywhere;
  text-align: left;
}

.race-name-btn span {
  min-width: 48px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 4px solid #000;
  border-radius: 12px;
  font-size: 16px;
}

.race-name-btn:hover:not(:disabled) {
  background: #d3ff00;
  transform: translateY(-3px) scale(1.02);
}

.race-name-btn.just-moved {
  animation: raceButtonPop 0.35s ease;
}

.race-name-btn.finished {
  background: #fff0a8;
  opacity: 0.85;
}

.race-track-panel {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,0.78), transparent 9%),
    radial-gradient(circle at 83% 22%, rgba(255,255,255,0.72), transparent 10%),
    linear-gradient(180deg, #8ee5ff 0%, #bcf7ff 38%, #9df58f 38%, #70d56f 100%);
  border: 8px solid #000;
  border-radius: 26px;
  box-shadow: inset -7px -7px 0 rgba(0,0,0,0.12);
}

.race-sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.race-cloud {
  position: absolute;
  width: 150px;
  height: 56px;
  background: rgba(255,255,255,0.86);
  border: 5px solid #000;
  border-radius: 999px;
  opacity: 0.55;
  animation: raceCloudMove 16s linear infinite;
}

.race-cloud::before,
.race-cloud::after {
  content: "";
  position: absolute;
  bottom: 8px;
  width: 62px;
  height: 62px;
  background: inherit;
  border: 5px solid #000;
  border-bottom: none;
  border-radius: 50%;
}

.race-cloud::before {
  left: 24px;
}

.race-cloud::after {
  right: 22px;
}

.cloud-one { top: 28px; left: 8%; animation-duration: 18s; }
.cloud-two { top: 86px; left: 42%; animation-duration: 23s; animation-delay: -6s; transform: scale(0.8); }
.cloud-three { top: 40px; left: 72%; animation-duration: 20s; animation-delay: -12s; transform: scale(0.65); }

.race-finish-line {
  position: absolute;
  right: 4.8%;
  top: 7%;
  bottom: 7%;
  width: 78px;
  z-index: 3;
  background:
    linear-gradient(45deg, #000 25%, #fff 25% 50%, #000 50% 75%, #fff 75%) 0 0 / 32px 32px;
  border: 7px solid #000;
  border-radius: 18px;
  box-shadow: 8px 8px 0 rgba(0,0,0,0.25);
}

.race-finish-line span {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
  background: #d3ff00;
  border: 4px solid #000;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 2px;
}

.race-lanes {
  position: absolute;
  inset: 24px 112px 24px 24px;
  display: grid;
  grid-template-rows: repeat(auto-fit, minmax(92px, 1fr));
  gap: 10px;
  z-index: 4;
}

.race-lane {
  min-height: 92px;
  position: relative;
  display: grid;
  grid-template-columns: 145px 1fr 78px;
  gap: 12px;
  align-items: center;
  background: hsla(var(--lane-hue), 85%, 88%, 0.82);
  border: 6px solid #000;
  border-radius: 20px;
  padding: 8px 10px;
  box-shadow: 6px 7px 0 rgba(0,0,0,0.18);
}

.race-lane.finished {
  background: #fff0a8;
  box-shadow:
    0 0 0 5px #d3ff00 inset,
    6px 7px 0 rgba(0,0,0,0.18);
}

.race-lane-name {
  font-size: 22px;
  font-weight: 900;
  overflow-wrap: anywhere;
  line-height: 1;
}

.race-road {
  position: relative;
  height: 78px;
  border: 5px solid #000;
  border-radius: 18px;
  overflow: hidden;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.5) 0 24px, transparent 24px 48px),
    linear-gradient(180deg, #f5f5f5, #cfd8dc);
}

.race-progress-dots {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 5px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
  z-index: 1;
}

.race-progress-dots span {
  height: 9px;
  border: 2px solid #000;
  border-radius: 99px;
  background: #fff;
}

.race-progress-dots span.filled {
  background: #d3ff00;
}

.race-racer {
  position: absolute;
  left: calc(var(--race-x) * 1%);
  top: 50%;
  transform: translate(-2px, -50%);
  z-index: 2;
  display: grid;
  justify-items: center;
  transition: left 0.38s cubic-bezier(.2, 1.4, .33, 1), transform 0.25s ease;
}

.race-racer-body {
  position: relative;
  animation: raceWaddle 0.55s ease-in-out infinite;
  transform-origin: 50% 90%;
}

.race-racer.finished .race-racer-body {
  animation: raceWinnerBounce 0.72s ease-in-out infinite;
}

.race-racer.hop .race-racer-body {
  animation: raceHop 0.38s ease;
}

.race-student-photo {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #fff;
  border: 5px solid #000;
  border-radius: 50%;
  box-shadow: 5px 5px 0 rgba(0,0,0,0.25);
}

.race-student-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.race-student-photo span {
  font-size: 38px;
}

.race-feet {
  position: absolute;
  left: 50%;
  bottom: -10px;
  width: 58px;
  height: 18px;
  transform: translateX(-50%);
}

.race-feet span {
  position: absolute;
  bottom: 0;
  width: 24px;
  height: 12px;
  background: #ff7fcb;
  border: 4px solid #000;
  border-radius: 999px;
}

.race-feet span:first-child {
  left: 2px;
  animation: raceFootLeft 0.55s ease-in-out infinite;
}

.race-feet span:last-child {
  right: 2px;
  animation: raceFootRight 0.55s ease-in-out infinite;
}

.race-racer-name {
  margin-top: 7px;
  background: #fff;
  border: 3px solid #000;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.18);
}

.race-score-badge {
  width: 68px;
  height: 54px;
  display: grid;
  place-items: center;
  background: #d3ff00;
  border: 5px solid #000;
  border-radius: 14px;
  font-size: 20px;
  font-weight: 900;
}

.race-celebration-overlay {
  position: fixed;
  inset: 0;
  z-index: 12000;
  pointer-events: none;
  overflow: hidden;
  background: rgba(255,255,255,0.1);
}

.race-celebration-card {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  min-width: min(520px, 82vw);
  background: #fff0a8;
  border: 8px solid #000;
  border-radius: 30px;
  padding: 28px;
  text-align: center;
  box-shadow: 14px 14px 0 rgba(0,0,0,0.32);
  animation: raceCelebratePop 0.45s ease;
}

.race-celebration-place {
  width: 90px;
  height: 90px;
  display: grid;
  place-items: center;
  margin: 0 auto 10px;
  background: #d3ff00;
  border: 7px solid #000;
  border-radius: 50%;
  font-size: 34px;
  font-weight: 900;
}

.race-celebration-card h2 {
  margin: 0;
  font-size: 44px;
  font-weight: 900;
}

.race-celebration-card p {
  margin: 10px 0 0;
  font-size: 22px;
  font-weight: 900;
}

.race-celebration-piece {
  position: absolute;
  left: var(--left);
  top: -60px;
  font-size: calc(28px * var(--scale));
  animation: raceConfettiFall var(--duration) ease-in var(--delay) forwards;
  transform: rotate(var(--rotate));
  text-shadow: 3px 3px 0 #000;
}

.race-celebration-overlay.fade-out {
  animation: raceOverlayFade 0.55s ease forwards;
}

@keyframes raceWaddle {
  0%, 100% { transform: rotate(-5deg) translateY(0); }
  50% { transform: rotate(5deg) translateY(-4px); }
}

@keyframes raceWinnerBounce {
  0%, 100% { transform: translateY(0) rotate(-3deg) scale(1); }
  50% { transform: translateY(-7px) rotate(3deg) scale(1.08); }
}

@keyframes raceHop {
  0% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-18px) scale(1.08); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes raceFootLeft {
  0%, 100% { transform: translateX(-5px) rotate(-8deg); }
  50% { transform: translateX(6px) rotate(8deg); }
}

@keyframes raceFootRight {
  0%, 100% { transform: translateX(6px) rotate(8deg); }
  50% { transform: translateX(-5px) rotate(-8deg); }
}

@keyframes raceButtonPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08) rotate(-1deg); }
  100% { transform: scale(1); }
}

@keyframes raceCloudMove {
  0% { margin-left: -18%; }
  100% { margin-left: 38%; }
}

@keyframes raceCelebratePop {
  0% { transform: translate(-50%, -50%) scale(0.65) rotate(-4deg); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
}

@keyframes raceConfettiFall {
  0% { transform: translateY(0) rotate(0deg) scale(var(--scale)); opacity: 1; }
  100% { transform: translateY(110vh) rotate(var(--rotate)) scale(var(--scale)); opacity: 0.85; }
}

@keyframes raceOverlayFade {
  to { opacity: 0; }
}

@media (max-width: 950px) {
  .race-control-panel {
    grid-template-columns: 1fr;
  }

  .race-lanes {
    inset-right: 95px;
  }

  .race-lane {
    grid-template-columns: 110px 1fr 62px;
  }

  .race-lane-name {
    font-size: 16px;
  }
}

@media (max-width: 650px) {
  .race-name-btn {
    min-width: 130px;
  }

  .race-lanes {
    inset: 18px 88px 18px 16px;
  }

  .race-lane {
    grid-template-columns: 1fr;
    min-height: 128px;
  }

  .race-lane-name,
  .race-score-badge {
    display: none;
  }
}
