html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  overflow: hidden;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

#board {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1080px;
  height: 1920px;
  transform: translate(-50%, -50%);
  overflow: visible;
  background: transparent;

  --idle-shake-intensity: 1;
  --idle-pulse-intensity: 1;
  --idle-animation-speed: 1;
  --impact-zoom-scale: 1.35;
  --impact-zoom-duration: 180ms;
  --impact-glow-intensity: 1;
  --impact-glow-duration: 450ms;
  --impact-flash-duration: 100ms;
  --projectile-speed: 420ms;
  --goal-text-duration: 900ms;
  --goal-zoom-scale: 1.2;
  --hit-bounce-duration: 420ms;
}

#bubbleRow {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 14px;
  padding: 28px 20px 20px;
  position: absolute;
  left: 0;
  right: 0;
  top: 135px;
  z-index: 50;
}

.bubble .rank.rank-medal {
  font-size: 36px;
  line-height: 1;
  letter-spacing: 0;
}

.bubble {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(14, 16, 24, 0.72);
  border: 2px solid rgba(120, 200, 255, 0.35);
  box-shadow:
    0 0 16px rgba(80, 180, 255, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  min-width: 160px;
  backdrop-filter: blur(6px);
}

.bubble .rank {
  font-family: ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  font-weight: 800;
  font-size: 32px;
  color: #8be8ff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
}

.bubble-mid img {
  width: 62px;
  height: 62px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.75));
}

.bubble-mid {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.bubble-fallback {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-family: ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.96);
  background: rgba(30, 40, 70, 0.75);
  border: 2px solid rgba(255, 255, 255, 0.22);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
}

.bubble .bubbleScore {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 900;
  font-size: 40px;
  color: #fff;
  letter-spacing: 0.03em;
  text-shadow:
    0 2px 0 #000,
    0 -2px 0 #000,
    2px 0 0 #000,
    -2px 0 0 #000,
    0 0 10px rgba(0, 0, 0, 0.9);
}

#lanes {
  position: absolute;
  left: 0;
  right: 0;
  top: 190px;
  bottom: 50px;
  padding: 0 20px 40px 16px;
}

.lane-row {
  position: absolute;
  left: 16px;
  right: 20px;
  height: 120px;
  display: flex;
  flex-direction: row;
  align-items: center;
  flex: none;
  min-height: 0;
  will-change: transform;
}

#lanes .lane-row:nth-child(1) {
  top: 108px;
}

#lanes .lane-row:nth-child(2) {
  top: 308px;
}

#lanes .lane-row:nth-child(3) {
  top: 508px;
}

#lanes .lane-row:nth-child(4) {
  top: 708px;
}

#lanes .lane-row:nth-child(5) {
  top: 908px;
}

.projectile-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

.lane-aside {
  position: relative;
  z-index: 5;
  width: 168px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 8px 4px 0;
}

.gift-icon-wrap {
  position: relative;
  z-index: 6;
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(12, 14, 22, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.gift-icon-wrap .gift-icon {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}

.gift-icon-fallback {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.92);
  text-align: center;
  line-height: 1.1;
  padding: 4px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

.team-name-label {
  max-width: 180px;
  text-align: center;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
  font-size: 26px;
  line-height: 1.15;
  color: rgba(255, 255, 255, 0.95);
  text-shadow:
    0 2px 0 #000,
    2px 0 0 #000,
    -2px 0 0 #000,
    0 0 10px rgba(0, 0, 0, 0.75);
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(10, 12, 20, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.track {
  position: relative;
  z-index: 3;
  flex: 1;
  height: 120px;
  margin-left: 8px;
  border-radius: 60px;
  background: transparent;
}

.finish-line {
  position: absolute;
  top: 6%;
  bottom: 6%;
  right: 1.2%;
  width: 5px;
  border-radius: 3px;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.88) 0 9px,
    rgba(255, 255, 255, 0.12) 9px 15px
  );
  box-shadow:
    0 0 10px rgba(255, 255, 255, 0.55),
    0 0 26px rgba(100, 200, 255, 0.35);
  opacity: 0.72;
  pointer-events: none;
  z-index: 4;
}

.finish-flag {
  position: absolute;
  right: 0.1%;
  top: 50%;
  transform: translateY(-50%);
  font-size: 34px;
  line-height: 1;
  opacity: 0.78;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.55));
  pointer-events: none;
  z-index: 5;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

.goal-burst {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 35;
  opacity: 0;
}

.goal-burst-text {
  font-family: ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  font-weight: 900;
  font-size: 58px;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.98);
  text-shadow:
    0 0 18px rgba(255, 230, 120, 0.95),
    0 0 36px rgba(255, 140, 60, 0.75),
    0 3px 0 #000,
    0 -3px 0 #000,
    3px 0 0 #000,
    -3px 0 0 #000;
  transform: scale(0.75);
}

.goal-burst--show {
  animation: goalBurstPop var(--goal-text-duration, 900ms) cubic-bezier(0.2, 0.85, 0.35, 1) forwards;
}

.goal-burst--show .goal-burst-text {
  animation: goalTextPulse var(--goal-text-duration, 900ms) ease-out forwards;
}

@keyframes goalBurstPop {
  0% {
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  72% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes goalTextPulse {
  0% {
    transform: scale(0.55) rotate(-2deg);
    filter: blur(1px);
  }
  22% {
    transform: scale(var(--goal-zoom-scale, 1.2)) rotate(0deg);
    filter: blur(0);
  }
  55% {
    transform: scale(1) rotate(0deg);
  }
  100% {
    transform: scale(1.08) rotate(1deg);
    filter: blur(0);
  }
}

.projectile-slot {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 90px;
  height: 90px;
  left: calc(14% + 72% * 0);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
}

.projectile-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
}

.projectile-fly {
  position: absolute;
  left: 0;
  top: 0;
  width: 90px;
  height: 90px;
  margin: 0;
  pointer-events: none;
  z-index: 1;
  will-change: transform;
}

.projectile-fly img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
}

.projectile-slot.fly-active {
  transition: left var(--projectile-speed, 420ms) cubic-bezier(0.25, 0.9, 0.36, 1);
}

.avatar-slot {
  position: absolute;
  top: 50%;
  margin-top: -60px;
  width: 120px;
  height: 120px;
  left: calc(12% + 74% * 0);
  z-index: 8;
  transition: left 0.42s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.avatar-slot.avatar-snap {
  transition: none !important;
}

.avatar-slot .inner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 24%;
  overflow: visible;
}

.avatar-slot img.logo {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.55));
  animation-name: idlePulse;
  animation-duration: calc(1.8s / var(--idle-animation-speed, 1));
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}

.avatar-slot.idle-shake img.logo {
  animation-name: idlePulse, idleShake;
  animation-duration:
    calc(1.8s / var(--idle-animation-speed, 1)),
    calc(2.8s / var(--idle-animation-speed, 1));
  animation-timing-function: ease-in-out, ease-in-out;
  animation-iteration-count: infinite, infinite;
  animation-direction: alternate, normal;
}

.avatar-slot.hit-zoom img.logo {
  animation: hitZoom var(--impact-zoom-duration, 180ms) cubic-bezier(0.2, 0.9, 0.39, 1.4) forwards;
}

.avatar-slot.bounce-impact img.logo {
  animation: hitBounce var(--hit-bounce-duration, 420ms) cubic-bezier(0.3, 1.4, 0.54, 1) forwards;
}

.avatar-slot.impact-glow .inner {
  filter:
    drop-shadow(
      0 0 calc(18px * var(--impact-glow-intensity, 1)) rgba(255, 235, 140, 0.95)
    )
    drop-shadow(
      0 0 calc(36px * var(--impact-glow-intensity, 1)) rgba(90, 200, 255, 0.75)
    )
    drop-shadow(0 4px 10px rgba(0, 0, 0, 0.55));
}

.avatar-slot.impact-flash .inner {
  animation: impactFlash var(--impact-flash-duration, 100ms) ease-out;
}

.avatar-slot.advance img.logo {
  animation-name: idlePulse;
  animation-duration: calc(1.8s / var(--idle-animation-speed, 1));
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}

.fallback-avatar {
  width: 100%;
  height: 100%;
  border-radius: 24%;
  display: grid;
  place-items: center;
  font-family: ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  font-weight: 900;
  font-size: 54px;
  color: rgba(255, 255, 255, 0.95);
  background: radial-gradient(circle at 35% 30%, rgba(120, 200, 255, 0.35), rgba(30, 40, 80, 0.85));
  border: 2px solid rgba(255, 255, 255, 0.2);
  animation-name: idlePulse;
  animation-duration: calc(1.8s / var(--idle-animation-speed, 1));
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}

.avatar-slot.idle-shake .fallback-avatar {
  animation-name: idlePulse, idleShake;
  animation-duration:
    calc(1.8s / var(--idle-animation-speed, 1)),
    calc(2.8s / var(--idle-animation-speed, 1));
  animation-timing-function: ease-in-out, ease-in-out;
  animation-iteration-count: infinite, infinite;
  animation-direction: alternate, normal;
}

@keyframes impactFlash {
  0% {
    filter: brightness(1.55) contrast(1.05);
  }
  100% {
    filter: brightness(1) contrast(1);
  }
}

@keyframes idlePulse {
  from {
    transform: scale(calc(1 - 0.015 * var(--idle-pulse-intensity, 1)));
    filter: brightness(calc(1 + 0.02 * var(--idle-pulse-intensity, 1)));
  }
  to {
    transform: scale(calc(1 + 0.04 * var(--idle-pulse-intensity, 1)));
    filter: brightness(calc(1 + 0.06 * var(--idle-pulse-intensity, 1)));
  }
}

@keyframes idleShake {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(calc(-1deg * var(--idle-shake-intensity, 1)));
  }
  75% {
    transform: rotate(calc(1.2deg * var(--idle-shake-intensity, 1)));
  }
}

@keyframes hitZoom {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(var(--impact-zoom-scale, 1.35));
  }
  100% {
    transform: scale(1.05);
  }
}

@keyframes hitBounce {
  0% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-18px) scale(1.08);
  }
  65% {
    transform: translateY(4px) scale(1);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

.race-audio-unlock {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 9999;
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

.race-audio-unlock:hover {
  background: rgba(20, 20, 20, 0.88);
}

.race-audio-unlock:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.race-audio-unlock.is-hidden {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  .projectile-slot.fly-active,
  .projectile-fly {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  .goal-burst--show,
  .goal-burst--show .goal-burst-text {
    animation-duration: 420ms !important;
  }

  .lane-row {
    transition-duration: 0.12s !important;
  }
}
