:root {
  --bg-top: #d6efe8;
  --bg-bottom: #f7fbff;
  --hud-bg: rgba(12, 34, 46, 0.87);
  --hud-text: #f2f8fc;
  --accent: #f9a03f;
  --accent-2: #6ec5a9;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

#game {
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: manipulation;
}

#hud {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(100px, 1fr));
  gap: 8px;
  padding: 10px;
  z-index: 10;
}

.stat {
  background: var(--hud-bg);
  color: var(--hud-text);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.16);
}

.label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.78;
}

#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 18px;
  background: rgba(8, 19, 24, 0.55);
  color: #ffffff;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

#overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

#overlay h1 {
  margin: 0 0 10px 0;
  font-size: clamp(1.8rem, 5vw, 3rem);
}

#overlay p {
  margin: 4px 0;
  max-width: 660px;
}

#startBtn {
  margin-top: 14px;
  padding: 10px 22px;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(120deg, var(--accent), #ffd166);
  color: #1f2930;
}

#testLastClimbBtn,
#retryPlayerDroppedBtn,
#retryFollowerDroppedBtn,
#claimPrizeBtn,
#startSelectedRaceBtn,
#backToRaceSelectionBtn,
.race-card-btn {
  margin-top: 10px;
  padding: 10px 20px;
  border: none;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(120deg, var(--accent-2), #9de8c6);
  color: #123138;
}

.hidden {
  display: none !important;
}

.result-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 18px;
  background: rgba(8, 19, 24, 0.78);
  color: #ffffff;
  z-index: 25;
}

.result-image {
  width: min(88vw, 500px);
  max-height: 40vh;
  object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
  margin-bottom: 14px;
}

.win-image {
  max-height: 44vh;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 26;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 16px;
  top: -20px;
  border-radius: 2px;
  animation: confettiFall var(--fall-duration, 2.8s) linear forwards;
}

@keyframes confettiFall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: translate3d(var(--drift, 40px), 115vh, 0) rotate(640deg);
    opacity: 0;
  }
}

.race-selection {
  justify-content: flex-start;
  padding-top: max(60px, 10vh);
  overflow-y: auto;
}

.race-collage {
  justify-content: flex-start;
  padding-top: max(32px, 6vh);
  overflow-y: auto;
}

.race-collage-shell {
  width: min(1180px, 96vw);
  display: grid;
  grid-template-columns: minmax(250px, 0.95fr) minmax(320px, 1.35fr);
  gap: 18px;
  align-items: stretch;
}

.race-collage-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 22px;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(17, 48, 62, 0.92), rgba(8, 19, 24, 0.88));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.26);
}

.race-collage-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: #9de8c6;
  font-size: 0.78rem;
}

.race-collage-copy h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1.02;
}

.race-collage-copy p {
  margin: 0;
  color: rgba(242, 248, 252, 0.9);
}

.race-collage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.11) !important;
  color: #ffffff !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
}

.race-collage-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.8fr;
  grid-auto-rows: minmax(160px, 1fr);
  gap: 12px;
}

.race-collage-tile {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.2);
  min-height: 160px;
}

.race-collage-tile--large {
  grid-row: span 2;
  min-height: 336px;
}

.race-collage-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(1.05) contrast(1.03);
}

.race-collage-tile span {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(8, 19, 24, 0.72);
  color: #fff;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
}

.race-card-grid {
  margin-top: 16px;
  width: min(1100px, 96vw);
  display: grid;
  grid-template-columns: repeat(3, minmax(210px, 1fr));
  gap: 16px;
}

.race-card {
  background: linear-gradient(165deg, rgba(17, 48, 62, 0.92), rgba(16, 79, 68, 0.86));
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  padding: 16px;
  text-align: left;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
}

.race-card h2 {
  margin: 0 0 10px;
  font-size: 1.25rem;
  color: #ffe9b8;
}

.race-card p {
  margin: 6px 0;
}

.race-card-btn {
  width: 100%;
  margin-top: 14px;
}

@media (max-width: 700px) {
  #hud {
    grid-template-columns: repeat(2, minmax(100px, 1fr));
  }

  .stat {
    padding: 7px 8px;
  }

  .result-image {
    width: min(92vw, 420px);
    max-height: 32vh;
  }

  .race-card-grid {
    grid-template-columns: 1fr;
    width: min(520px, 94vw);
  }

  .race-collage-shell {
    grid-template-columns: 1fr;
  }

  .race-collage-grid {
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: 140px;
  }

  .race-collage-tile--large {
    grid-column: span 2;
    min-height: 220px;
  }
}
