/* === Candy Land Theme === */
@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&display=swap');

:root {
  --pink: #ff6eb4;
  --purple: #c77dff;
  --yellow: #ffe066;
  --teal: #00e5cc;
  --red: #ff4d6d;
  --white: #fff9fc;
  --lane-bg: rgba(255,255,255,0.18);
  --lane-border: rgba(255,255,255,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Fredoka One', cursive, sans-serif;
  background: linear-gradient(135deg, #ff9de2 0%, #a78bfa 40%, #67e8f9 100%);
  min-height: 100vh;
  overflow-x: hidden; /* allow vertical scroll on mobile */
  user-select: none;
}

/* === Candy background dots === */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.25) 2px, transparent 2px),
    radial-gradient(circle, rgba(255,230,102,0.3) 3px, transparent 3px);
  background-size: 60px 60px, 90px 90px;
  background-position: 0 0, 30px 30px;
  pointer-events: none;
  animation: bgDrift 8s linear infinite;
}

@keyframes bgDrift {
  from { background-position: 0 0, 30px 30px; }
  to   { background-position: 60px 60px, 90px 90px; }
}

/* === Buttons === */
.btn {
  display: inline-block;
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  padding: 0.6em 1.4em;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 6px 0 rgba(0,0,0,0.2), 0 0 20px rgba(255,255,255,0.4);
  transition: transform 0.1s, box-shadow 0.1s;
  letter-spacing: 1px;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.2); }
.btn-play  { background: var(--yellow); color: #7c3aed; }
.btn-again { background: var(--teal);   color: #164e63; }
.btn-home  { background: var(--pink);   color: #831843; }

/* === Floating candy decorations === */
.candies {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.candy {
  position: absolute;
  font-size: 2.5rem;
  animation: floatCandy linear infinite;
  opacity: 0.7;
}
@keyframes floatCandy {
  0%   { transform: translateY(110vh) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.7; }
  90%  { opacity: 0.7; }
  100% { transform: translateY(-10vh) rotate(360deg); opacity: 0; }
}

/* === START SCREEN === */
#start-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 2rem;
  position: relative;
  z-index: 10;
}

.game-title {
  font-size: clamp(3rem, 10vw, 6rem);
  color: white;
  text-shadow: 0 4px 0 var(--purple), 0 8px 20px rgba(0,0,0,0.2);
  line-height: 1.1;
  margin-bottom: 0.4em;
}

.game-subtitle {
  font-size: clamp(1.2rem, 4vw, 2rem);
  color: var(--yellow);
  text-shadow: 0 2px 0 rgba(0,0,0,0.2);
  margin-bottom: 2rem;
}

/* === RACE SCREEN === */
#race-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 10;
}

#progress-bar-container {
  background: rgba(0,0,0,0.25);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#progress-bar-container .pb-label {
  color: white;
  font-size: 1rem;
  white-space: nowrap;
}

#progress-track {
  flex: 1;
  height: 28px;
  background: rgba(255,255,255,0.2);
  border-radius: 999px;
  position: relative;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.4);
}

.pb-runner {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  transition: left 0.1s linear;
  filter: drop-shadow(0 0 4px white);
}

.pb-finish {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
}

#lanes-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.lane {
  flex: 1;
  position: relative;
  border-bottom: 3px dashed rgba(255,255,255,0.3);
  overflow: hidden;
  display: flex;
  align-items: center;
}
.lane:last-child { border-bottom: none; }

/* scrolling candy bg per lane */
.lane-bg {
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(90deg,
      transparent 0px, transparent 120px,
      rgba(255,255,255,0.06) 120px, rgba(255,255,255,0.06) 122px
    );
  animation: laneBgScroll 3s linear infinite;
}

@keyframes laneBgScroll {
  from { background-position: 0 0; }
  to   { background-position: -240px 0; }
}

.lane-label {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255,255,255,0.6);
  font-size: 0.9rem;
  pointer-events: none;
  z-index: 2;
}

.finish-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  background: repeating-linear-gradient(
    180deg,
    #000 0px, #000 14px,
    #fff 14px, #fff 28px
  );
  z-index: 5;
  box-shadow: 0 0 20px rgba(255,255,255,0.8);
  /* left set by JS */
}

.finish-flag {
  position: absolute;
  top: 6px;
  font-size: 2.4rem;
  pointer-events: none;
  z-index: 5;
  /* left set by JS */
}

/* === Runner === */
.runner {
  position: absolute;
  left: 4%;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 4;
  transition: left 0.08s linear;
}

.runner-name {
  font-size: 0.75rem;
  color: white;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
  margin-bottom: 2px;
  white-space: nowrap;
}

.runner-body {
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1;
  animation: runBounce 0.35s ease-in-out infinite alternate;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,0.2));
}

.runner.slowed .runner-body {
  animation: wobble 0.2s ease-in-out infinite alternate;
  filter: drop-shadow(0 4px 4px rgba(255,0,0,0.3));
}

.runner.is-hawa .runner-body {
  filter: drop-shadow(0 0 8px var(--yellow)) drop-shadow(0 4px 4px rgba(0,0,0,0.2));
}

@keyframes runBounce {
  from { transform: translateY(0) scaleX(1);   }
  to   { transform: translateY(-6px) scaleX(0.95); }
}
@keyframes wobble {
  from { transform: translateY(0) rotate(-8deg); }
  to   { transform: translateY(-4px) rotate(8deg); }
}

/* === Obstacles === */
.obstacle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  z-index: 3;
  animation: obstacleWiggle 0.6s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes obstacleWiggle {
  from { transform: translateY(-50%) scale(1);    }
  to   { transform: translateY(-60%) scale(1.05); }
}

/* tap flash */
#tap-flash {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.15);
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  border-radius: 50%;
  transition: opacity 0.15s;
}
#tap-flash.active { opacity: 1; }

/* === WIN/LOSE SCREEN === */
#end-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 2rem;
  position: relative;
  z-index: 10;
}

.end-title {
  font-size: clamp(2.5rem, 10vw, 5rem);
  color: white;
  text-shadow: 0 4px 0 var(--purple), 0 8px 20px rgba(0,0,0,0.2);
  margin-bottom: 0.3em;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
.end-subtitle {
  font-size: clamp(1.2rem, 4vw, 2rem);
  color: var(--yellow);
  margin-bottom: 1.5em;
  animation: popIn 0.5s 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.trophy-podium {
  font-size: clamp(4rem, 12vw, 7rem);
  margin-bottom: 1rem;
  animation: trophyBounce 0.7s 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
@keyframes trophyBounce {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}

.end-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 1rem;
  animation: popIn 0.5s 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

/* === Confetti === */
.confetti-piece {
  position: fixed;
  top: -20px;
  width: 12px;
  height: 14px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
  pointer-events: none;
  z-index: 100;
}
@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* candy rain on win */
.candy-rain {
  position: fixed;
  top: -30px;
  font-size: 1.8rem;
  animation: candyRainFall linear forwards;
  pointer-events: none;
  z-index: 99;
}
@keyframes candyRainFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(360deg); opacity: 0.5; }
}
