* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(ellipse 1000px 500px at 70% 0%, #fff3c4 0%, transparent 50%),
    linear-gradient(180deg, #7ec8ff 0%, #b8e4ff 38%, #d9f5c9 70%, #9fd89a 100%);
  color: #2d2148;
  font-family: 'Fredoka', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
  touch-action: none;
}

#ui {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
  z-index: 2;
}

#scoreboard {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#powerups {
  pointer-events: none;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 36px;
  flex: 1;
}
.power-chip {
  background: rgba(255,255,255,0.9);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(40, 30, 80, 0.12);
  animation: chipIn 220ms ease;
}
@keyframes chipIn {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.score-item {
  pointer-events: auto;
  background: rgba(255,255,255,0.84);
  color: #2d2148;
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 8px 24px rgba(40, 30, 80, 0.12);
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.score-item .label {
  opacity: 0.7;
  font-size: 13px;
}
.score-item span:last-child {
  font-weight: 700;
  font-size: 20px;
}

#race-bar-wrap {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 200ms ease;
}
#race-bar-wrap.show { opacity: 1; }
#race-bar {
  position: relative;
  height: 18px;
  border-radius: 999px;
  background: rgba(255,255,255,0.75);
  box-shadow: 0 6px 18px rgba(40, 30, 80, 0.12);
  overflow: hidden;
}
#race-bar .track {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #ff6b9d, #ffd166, #06d6a0, #4cc9f0, #b388ff);
  opacity: 0.22;
}
#race-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.15));
  transition: left 80ms linear;
}
#bird-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 16px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.15));
  transition: left 80ms linear;
}
#treat-marker {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
}
.race-label {
  text-align: center;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #2d2148;
  text-shadow: 0 1px 0 rgba(255,255,255,0.7);
}

#controls { pointer-events: auto; display: flex; gap: 8px; align-items: center; }
#restart, #play, #homeBtn, .home-link {
  cursor: pointer;
  border: none;
  background: linear-gradient(180deg, #ff8fab, #f72585);
  color: white;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  box-shadow: 0 8px 24px rgba(247, 37, 133, 0.28);
}
#restart:hover, #play:hover, #homeBtn:hover, .home-link:hover { filter: brightness(1.05); }
#restart:active, #play:active, #homeBtn:active, .home-link:active { filter: brightness(0.95); }
.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

#toast {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.9);
  font-size: clamp(28px, 6vw, 48px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 4px 0 rgba(45, 33, 72, 0.25), 0 8px 28px rgba(45, 33, 72, 0.35);
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(35, 20, 60, 0.3);
  backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 3;
}
#overlay.show { opacity: 1; pointer-events: auto; }
#overlay .panel {
  background: white;
  color: #2d2148;
  width: min(540px, calc(100vw - 32px));
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(45, 33, 72, 0.3);
}
#overlay h1 {
  margin: 0 0 8px;
  font-size: 30px;
  background: linear-gradient(90deg, #ff6b9d, #ffd166, #06d6a0, #4cc9f0, #b388ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
#overlay p { opacity: 0.85; line-height: 1.45; margin: 0 0 10px; }
#overlay .hint { font-size: 14px; opacity: 0.7; margin-bottom: 16px; }
#overlay .legend {
  display: grid;
  gap: 6px;
  margin: 12px 0 16px;
  font-size: 14px;
}
