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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Arial Black', 'Helvetica Neue', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  position: relative;
  width: min(100vw, 430px);
  height: min(100vh, calc(min(100vw, 430px) * 19.5 / 9));
  overflow: hidden;
  background: #0a3669;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}

#scene {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ----- Distance Meter (top right) ----- */
#meter {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: clamp(150px, 38vw, 240px);
  aspect-ratio: 336 / 214;
  background: url('score_meter.webp') center/contain no-repeat;
  pointer-events: none;
  z-index: 4;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.4));
}

/* Overlay the live distance number on the central numeric area of the meter image */
#distance {
  position: absolute;
  top: 33%;
  left: 20%;
  right: 22%;
  height: 30%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-family: 'Impact', 'Arial Black', sans-serif;
  font-size: clamp(20px, 6vw, 36px);
  font-weight: 900;
  color: #0a3669;
  letter-spacing: 1px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  background: linear-gradient(180deg, #e6f1f8 0%, #c8dded 100%);
  border-radius: 4px;
  padding: 0 6px;
}

/* Overlay the best distance on the bottom strip of the meter image */
#best {
  position: absolute;
  top: 72%;
  left: 25%;
  right: 8%;
  height: 20%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Impact', 'Arial Black', sans-serif;
  font-size: clamp(10px, 2.6vw, 16px);
  font-weight: 900;
  color: #0a3669;
  letter-spacing: 1px;
  background: linear-gradient(180deg, #b8d4e8 0%, #9fc3dc 100%);
  border-radius: 3px;
  padding: 0 4px;
  white-space: nowrap;
}

/* ----- Tap Button (bottom right) ----- */
#tapBtn {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: max(16px, env(safe-area-inset-right));
  width: clamp(120px, 30vw, 180px);
  height: clamp(120px, 30vw, 180px);
  background: url('tap_button.webp') center/contain no-repeat;
  border: none;
  outline: none;
  cursor: pointer;
  filter:
    drop-shadow(0 0 6px rgba(255, 220, 80, 0.95))
    drop-shadow(0 0 16px rgba(255, 160, 30, 0.85))
    drop-shadow(0 0 28px rgba(255, 120, 0, 0.6))
    drop-shadow(0 8px 18px rgba(0, 0, 0, 0.5));
  transition: transform 70ms ease-out, filter 120ms;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
  animation: btnGlow 1.6s ease-in-out infinite alternate;
}
#tapBtn:active {
  transform: scale(0.88);
  filter:
    drop-shadow(0 0 10px rgba(255, 240, 120, 1))
    drop-shadow(0 0 22px rgba(255, 180, 40, 0.95))
    drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5))
    brightness(1.1);
}
#tapBtn.pulse {
  animation: btnPulse 0.7s ease-in-out infinite, btnGlow 1.6s ease-in-out infinite alternate;
}
@keyframes btnPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes btnGlow {
  from {
    filter:
      drop-shadow(0 0 4px rgba(255, 220, 80, 0.7))
      drop-shadow(0 0 12px rgba(255, 160, 30, 0.65))
      drop-shadow(0 0 22px rgba(255, 120, 0, 0.45))
      drop-shadow(0 8px 18px rgba(0, 0, 0, 0.5));
  }
  to {
    filter:
      drop-shadow(0 0 8px rgba(255, 240, 120, 1))
      drop-shadow(0 0 20px rgba(255, 180, 40, 0.95))
      drop-shadow(0 0 34px rgba(255, 130, 0, 0.75))
      drop-shadow(0 8px 18px rgba(0, 0, 0, 0.5));
  }
}

/* ----- Power HUD (during runup) ----- */
#powerHud {
  position: absolute;
  bottom: clamp(170px, 28vh, 260px);
  left: 50%;
  transform: translateX(-50%);
  width: 78%;
  max-width: 420px;
  z-index: 6;
  text-align: center;
  pointer-events: none;
}

#powerHint {
  font-size: clamp(20px, 4.5vw, 28px);
  font-weight: 900;
  color: #fff;
  letter-spacing: 4px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6), 0 0 14px rgba(255, 100, 0, 0.85);
  margin-bottom: 12px;
  animation: hintPulse 0.32s ease-in-out infinite alternate;
}

#powerBarTrack {
  width: 100%;
  height: 22px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

#powerFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffeb3b 0%, #ff9800 50%, #d32f2f 100%);
  transition: width 60ms linear;
}

@keyframes hintPulse {
  from { transform: scale(1); opacity: 0.9; }
  to { transform: scale(1.08); opacity: 1; }
}

/* ----- Overlays ----- */
.overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(8, 22, 50, 0.78) 0%, rgba(8, 22, 50, 0.85) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  color: #fff;
  text-align: center;
  padding: 24px;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.overlayInner {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.overlay h1 {
  font-size: clamp(40px, 11vw, 72px);
  letter-spacing: 6px;
  color: #ffd400;
  -webkit-text-stroke: 2px #c1272d;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.4), 0 14px 30px rgba(255, 80, 0, 0.55);
  margin-bottom: 4px;
  line-height: 1;
}

.overlay h2 {
  font-size: clamp(18px, 4.5vw, 30px);
  letter-spacing: 4px;
  margin-bottom: 24px;
  color: #fff;
}

.overlay p {
  font-size: clamp(14px, 3.6vw, 18px);
  margin: 6px 0;
  max-width: 480px;
  color: #e6f3ff;
  line-height: 1.4;
}

.overlay button {
  margin-top: 28px;
  padding: 16px 44px;
  font-size: clamp(18px, 4vw, 24px);
  font-weight: 900;
  letter-spacing: 3px;
  background: #d32f2f;
  color: #fff;
  border: none;
  border-radius: 60px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 6px 0 #7f1212, 0 12px 26px rgba(0, 0, 0, 0.5);
  transition: transform 80ms, box-shadow 80ms;
  -webkit-tap-highlight-color: transparent;
}

.overlay button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #7f1212, 0 6px 14px rgba(0, 0, 0, 0.45);
}

.hidden { display: none !important; }

/* ----- End screen ----- */
.dist-label {
  margin-top: 8px;
  font-size: clamp(14px, 3.4vw, 20px);
  color: #cfe6ff;
  letter-spacing: 3px;
}

.dist {
  font-size: clamp(44px, 12vw, 80px);
  font-weight: 900;
  color: #ffd400;
  letter-spacing: 2px;
  text-shadow: 0 4px 0 #c1272d, 0 8px 22px rgba(0, 0, 0, 0.55);
  margin: 4px 0 14px 0;
  line-height: 1;
}

.coupon {
  margin-top: 12px;
  padding: 22px 28px 26px;
  background: #0a1428;
  border: 3px dashed #ffd400;
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  width: 100%;
  max-width: 360px;
}

.coupon-label {
  color: #cfe6ff;
  font-size: clamp(12px, 2.8vw, 14px);
  letter-spacing: 2px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.code {
  font-size: clamp(26px, 7vw, 42px);
  font-weight: 900;
  letter-spacing: 6px;
  color: #ffd400;
  font-family: 'Courier New', monospace;
  background: #000;
  padding: 14px 18px;
  border-radius: 8px;
  border: 2px solid #ffd400;
  text-shadow: 0 0 14px rgba(255, 212, 0, 0.65);
}
