@import url("https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;500;600;700&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:root {
  --teal: #00d4c8;
  --teal-dim: rgba(0, 212, 200, 0.3);
  --teal-glow: rgba(0, 212, 200, 0.5);
  --dark-bg: #1a1a2e;
}

html,
body {
  height: 100%;
  overflow: hidden;
  position: fixed;
  width: 100%;
}

body {
  background: #0a0a12;
  font-family: "Rajdhani", sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ========== SCREEN SYSTEM ========== */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.screen.active {
  display: flex;
}

.screen-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

/* ========== START SCREEN ========== */
#start-screen {
  background: #1a1a2e;
  overflow: hidden;
}

#start-screen .screen-content {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  padding-bottom: max(40px, env(safe-area-inset-bottom, 40px));
}

/* Dark to white gradient overlay */
#start-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.7) 0%,
    rgba(0, 0, 0, 0.3) 40%,
    rgba(255, 255, 255, 0.1) 70%,
    rgba(255, 255, 255, 0.35) 100%
  );
  pointer-events: none;
  z-index: 1;
}

/* Background animation */
#start-screen .screen-bg {
  animation: bgZoomPan 20s ease-in-out infinite alternate;
  transform-origin: center center;
}

@keyframes bgZoomPan {
  0% {
    transform: scale(1.1) translateY(0);
  }
  50% {
    transform: scale(1.15) translateY(-2%);
  }
  100% {
    transform: scale(1.1) translateY(0);
  }
}

/* Logo entrance animation */
.start-logo {
  position: absolute;
  top: 50px;
  right: 20px;
  width: 60px;
  height: auto;
  opacity: 0;
  animation: logoSlideIn 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.3s forwards;
}

@keyframes logoSlideIn {
  0% {
    opacity: 0;
    transform: translateX(50px) scale(0.5);
  }
  100% {
    opacity: 0.9;
    transform: translateX(0) scale(1);
  }
}

/* Title entrance animation - dramatic slam effect */
.start-title {
  margin-top: 25%;
  width: 85%;
  max-width: 350px;
  height: auto;
  opacity: 0;
  animation: titleSlam 1s cubic-bezier(0.16, 1, 0.3, 1) 0.5s forwards;
  filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
}

@keyframes titleSlam {
  0% {
    opacity: 0;
    transform: scale(2.5) translateY(-100px) rotate(-5deg);
    filter: blur(10px) drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
  }
  60% {
    opacity: 1;
    transform: scale(0.95) translateY(10px) rotate(1deg);
    filter: blur(0) drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
  }
  80% {
    transform: scale(1.02) translateY(-5px) rotate(-0.5deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0) rotate(0);
    filter: blur(0) drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
  }
}

/* Play button entrance animation */
.play-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-bottom: 20px;
  opacity: 0;
  animation: playButtonEntrance 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 1.2s
    forwards;
  transition: transform 0.15s ease;
}

@keyframes playButtonEntrance {
  0% {
    opacity: 0;
    transform: translateY(100px) scale(0.5);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.play-button img {
  width: 280px;
  max-width: 80vw;
  height: auto;
  display: block;
  animation: playButtonPulse 2s ease-in-out 2s infinite;
}

#start-screen .play-button img {
  width: 340px;
  max-width: 85vw;
  filter: drop-shadow(0 0 35px rgba(0, 212, 200, 0.5));
}

@keyframes playButtonPulse {
  0%,
  100% {
    transform: scale(1);
    filter: drop-shadow(0 0 20px rgba(0, 212, 200, 0.3));
  }
  50% {
    transform: scale(1.03);
    filter: drop-shadow(0 0 30px rgba(0, 212, 200, 0.6));
  }
}

.play-button:hover img {
  animation: none;
  transform: scale(1.08);
  filter: drop-shadow(0 0 40px rgba(0, 212, 200, 0.8));
}

.play-button:active img {
  transform: scale(0.95);
  filter: brightness(1.3) drop-shadow(0 0 50px rgba(0, 212, 200, 1));
}

/* ========== EXIT ANIMATIONS ========== */
#start-screen.exiting .screen-bg {
  animation: bgZoomOut 0.6s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes bgZoomOut {
  0% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

#start-screen.exiting .start-logo {
  animation: logoExit 0.4s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes logoExit {
  0% {
    opacity: 0.9;
    transform: translateX(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateX(100px) scale(0.3);
  }
}

#start-screen.exiting .start-title {
  animation: titleExit 0.5s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes titleExit {
  0% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  100% {
    opacity: 0;
    transform: scale(3) translateY(-50px);
    filter: blur(20px);
  }
}

#start-screen.exiting .play-button {
  animation: playButtonExit 0.4s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes playButtonExit {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(150px) scale(0.3);
  }
}

/* ========== HOW TO PLAY SCREEN ========== */
#howto-screen {
  background: #1a1a2e;
  overflow: hidden;
}

#howto-screen .screen-bg {
  animation: howtoBgIn 0.8s ease-out forwards;
}

@keyframes howtoBgIn {
  0% {
    opacity: 0;
    transform: scale(1.1);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Nissan logo in howto */
.howto-logo {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 60px;
  height: auto;
  z-index: 2;
  opacity: 0;
  animation: howtoLogoIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.2s forwards;
}

@keyframes howtoLogoIn {
  0% {
    opacity: 0;
    transform: translateX(30px) scale(0.7);
  }
  100% {
    opacity: 0.9;
    transform: translateX(0) scale(1);
  }
}

.howto-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 450px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px 30px;
  padding-bottom: max(30px, env(safe-area-inset-bottom, 30px));
  gap: 15px;
}

/* Controls image (brake/gas) */
.howto-controls {
  width: 90%;
  max-width: 380px;
  height: auto;
  margin-bottom: 20px;
  opacity: 0;
  animation: howtoControlsIn 0.7s cubic-bezier(0.16, 1, 0.3, 1) 0.3s forwards;
}

@keyframes howtoControlsIn {
  0% {
    opacity: 0;
    transform: translateY(-40px) scale(0.8);
  }
  60% {
    transform: translateY(5px) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Fuel warning text */
.howto-fuel-text {
  width: 85%;
  max-width: 350px;
  height: auto;
  margin-top: 15px;
  opacity: 0;
  animation: howtoFuelTextIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.6s forwards;
}

@keyframes howtoFuelTextIn {
  0% {
    opacity: 0;
    transform: translateX(-30px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Animated Fuel gauge */
.howto-fuel-gauge-wrapper {
  opacity: 0;
  animation: howtoFuelGaugeIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.8s
    forwards;
}

.howto-fuel-gauge-animated {
  position: relative;
  width: 100px;
  height: 100px;
}

.howto-fuel-gauge-animated .fuel-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 10px rgba(0, 212, 200, 0.4));
}

.howto-fuel-fill {
  animation: fuelDepletionDemo 4s ease-in-out infinite;
}

@keyframes fuelDepletionDemo {
  0% {
    stroke-dashoffset: 0;
    stroke: #00d4c8;
  }
  50% {
    stroke-dashoffset: 180;
    stroke: #ff4444;
  }
  100% {
    stroke-dashoffset: 0;
    stroke: #00d4c8;
  }
}

.howto-fuel-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fuelIconPulse 4s ease-in-out infinite;
}

@keyframes fuelIconPulse {
  0%,
  100% {
    color: rgba(255, 255, 255, 0.85);
  }
  50% {
    color: #ff4444;
  }
}

@keyframes howtoFuelGaugeIn {
  0% {
    opacity: 0;
    transform: scale(0.3) rotate(-20deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

/* Fuel gauge label */
.howto-fuel-label {
  width: 140px;
  max-width: 50%;
  height: auto;
  opacity: 0;
  animation: howtoFuelLabelIn 0.4s ease-out 1s forwards;
}

@keyframes howtoFuelLabelIn {
  0% {
    opacity: 0;
    transform: translateY(15px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* How-to play button entrance */
#howto-screen .play-button {
  margin-top: 20px;
  animation: howtoPlayBtnIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 1.2s forwards;
}

#howto-screen .play-button img {
  width: 320px;
  max-width: 85vw;
}

@keyframes howtoPlayBtnIn {
  0% {
    opacity: 0;
    transform: translateY(60px) scale(0.6);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ========== HOW TO PLAY EXIT ANIMATIONS ========== */
#howto-screen.exiting .screen-bg {
  animation: howtoBgOut 0.5s ease-in forwards;
}

@keyframes howtoBgOut {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.2);
    filter: blur(10px);
  }
}

#howto-screen.exiting .howto-logo {
  animation: howtoLogoOut 0.3s ease-in forwards;
}

@keyframes howtoLogoOut {
  0% {
    opacity: 0.9;
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    transform: translateX(50px);
  }
}

#howto-screen.exiting .howto-controls {
  animation: howtoControlsOut 0.4s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes howtoControlsOut {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-60px) scale(1.3);
    filter: blur(5px);
  }
}

#howto-screen.exiting .howto-fuel-text {
  animation: howtoFuelTextOut 0.3s ease-in forwards;
}

@keyframes howtoFuelTextOut {
  0% {
    opacity: 1;
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    transform: translateX(50px);
  }
}

#howto-screen.exiting .howto-fuel-gauge-wrapper {
  animation: howtoFuelGaugeOut 0.35s ease-in 0.05s forwards;
}

@keyframes howtoFuelGaugeOut {
  0% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
  100% {
    opacity: 0;
    transform: scale(0.5) rotate(20deg);
  }
}

#howto-screen.exiting .howto-fuel-label {
  animation: howtoFuelLabelOut 0.25s ease-in forwards;
}

@keyframes howtoFuelLabelOut {
  0% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(30px);
  }
}

#howto-screen.exiting .play-button {
  animation: howtoPlayBtnOut 0.3s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes howtoPlayBtnOut {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(80px) scale(0.5);
  }
}

/* ========== GAME SCREEN ========== */
#game-screen {
  z-index: 500;
  transition: opacity 0.4s ease-out;
}

/* Flash effect when game starts */
#game-screen::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: white;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
}

#game-screen.flash-in::before {
  animation: gameStartFlash 0.6s ease-out forwards;
}

@keyframes gameStartFlash {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* Game screen fade out to end screen */
#game-screen.exiting {
  animation: gameScreenFadeOut 0.4s ease-in forwards;
}

@keyframes gameScreenFadeOut {
  0% {
    opacity: 1;
    filter: blur(0);
  }
  100% {
    opacity: 0;
    filter: blur(8px);
  }
}

/* Vignette effect on game screen */
#game-screen::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 50%,
    rgba(0, 0, 0, 0.3) 100%
  );
  pointer-events: none;
  z-index: 10;
  opacity: 0;
}

#game-screen.active::after {
  animation: vignetteIn 1s ease-out 0.5s forwards;
}

@keyframes vignetteIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

#game-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 500px;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
}

#game-container {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Landing impact shake effect */
#game-container.landing-shake {
  animation: landingShake 0.25s ease-out;
}

@keyframes landingShake {
  0% {
    transform: translateY(0);
  }
  20% {
    transform: translateY(6px);
  }
  40% {
    transform: translateY(-4px);
  }
  60% {
    transform: translateY(3px);
  }
  80% {
    transform: translateY(-1px);
  }
  100% {
    transform: translateY(0);
  }
}

#canvas-holder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#canvas-holder canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}

/* Progress Bar */
#progress-bar {
  position: absolute;
  top: 25px;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  z-index: 100;
  pointer-events: none;
}

#progress-line {
  position: relative;
  height: 2px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 1px;
}

#progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 30%;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 1px;
  transition: width 0.3s ease;
}

#progress-marker {
  position: absolute;
  top: 50%;
  left: 30%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 14px;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  transition: left 0.3s ease;
}

/* Logo */
#logo {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 100;
  pointer-events: none;
  opacity: 0.7;
}

/* Fuel Gauge */
#fuel-gauge {
  position: absolute;
  left: 20px;
  bottom: 100px;
  width: 70px;
  height: 70px;
  z-index: 150;
  pointer-events: none;
}

#fuel-gauge .fuel-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 8px rgba(0, 212, 200, 0.3));
}

#fuel-fill {
  transition: stroke-dashoffset 0.3s ease, stroke 0.3s ease;
}

#fuel-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Fuel gauge states */
#fuel-gauge.low .fuel-ring {
  filter: drop-shadow(0 0 10px rgba(255, 170, 0, 0.5));
}

#fuel-gauge.low #fuel-icon {
  color: #ffaa00;
}

#fuel-gauge.critical {
  animation: fuelCriticalPulse 0.5s ease-in-out infinite;
}

#fuel-gauge.critical .fuel-ring {
  filter: drop-shadow(0 0 12px rgba(255, 68, 68, 0.6));
}

#fuel-gauge.critical #fuel-icon {
  color: #ff4444;
}

@keyframes fuelCriticalPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

/* Fuel collection flash */
#fuel-gauge.collecting {
  animation: fuelCollectFlash 0.4s ease-out;
}

#fuel-gauge.collecting .fuel-ring {
  filter: drop-shadow(0 0 20px rgba(0, 255, 240, 0.8));
}

#fuel-gauge.collecting #fuel-icon {
  color: #00fff0;
}

@keyframes fuelCollectFlash {
  0% {
    transform: scale(1.2);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

/* Stats Overlay */
#stats-overlay {
  position: absolute;
  top: 50px;
  left: 15px;
  z-index: 100;
  pointer-events: none;
  color: white;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* Landing pulse effect on UI */
#stats-overlay.landing-pulse {
  animation: landingPulse 0.35s ease-out;
}

@keyframes landingPulse {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  30% {
    transform: scale(1.15);
    filter: brightness(1.5);
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.8),
      0 2px 10px rgba(0, 0, 0, 0.5);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  }
}

/* Flying/Airborne UI effects */
#stats-overlay.flying {
  animation: flyingPulse 0.8s ease-in-out infinite;
}

@keyframes flyingPulse {
  0%,
  100% {
    transform: scale(1) translateY(0);
    filter: brightness(1);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  }
  50% {
    transform: scale(1.05) translateY(-3px);
    filter: brightness(1.2);
    text-shadow: 0 0 15px rgba(0, 212, 200, 0.6), 0 2px 10px rgba(0, 0, 0, 0.5);
  }
}

/* Flying indicator glow on speed */
#stats-overlay.flying #speed {
  color: var(--teal);
  text-shadow: 0 0 10px var(--teal-glow);
  transition: color 0.3s ease, text-shadow 0.3s ease;
}

/* Touch controls glow when flying */
#touch-controls.flying .control-btn {
  filter: drop-shadow(0 0 15px var(--teal-glow));
}

#touch-controls.flying .gas-btn {
  animation: flyingButtonPulse 1s ease-in-out infinite;
}

@keyframes flyingButtonPulse {
  0%,
  100% {
    filter: drop-shadow(0 0 10px var(--teal-dim));
  }
  50% {
    filter: drop-shadow(0 0 20px var(--teal-glow));
  }
}

#distance {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 1px;
}

#distance .unit {
  font-size: 16px;
  font-weight: 400;
  opacity: 0.7;
  margin-left: 2px;
}

#speed {
  font-size: 18px;
  font-weight: 500;
  opacity: 0.8;
  margin-top: 2px;
}

#speed .unit {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.7;
  margin-left: 2px;
}

/* Timer Display */
#timer-display {
  position: absolute;
  top: 50px;
  right: 15px;
  z-index: 100;
  pointer-events: none;
  color: white;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 1px;
}

#timer-display .unit {
  font-size: 14px;
  font-weight: 400;
  opacity: 0.7;
  margin-left: 2px;
}

#timer-display.warning {
  color: #ff6b6b;
  animation: timerWarning 0.5s ease-in-out infinite;
}

@keyframes timerWarning {
  0%,
  100% {
    transform: scale(1);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  }
  50% {
    transform: scale(1.1);
    text-shadow: 0 0 20px rgba(255, 107, 107, 0.8);
  }
}

/* ========== END SCREEN ========== */
#end-screen {
  background: #2d2a3d;
  overflow: hidden;
  justify-content: center;
  align-items: center;
  z-index: 1100;
}

#end-screen .screen-bg {
  animation: endBgIn 0.5s ease-out forwards;
}

@keyframes endBgIn {
  0% {
    opacity: 0.5;
    transform: scale(1.02);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Logo in end screen */
.end-logo {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 60px;
  height: auto;
  z-index: 2;
  opacity: 0;
  animation: endLogoIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.3s forwards;
}

@keyframes endLogoIn {
  0% {
    opacity: 0;
    transform: translateX(30px) scale(0.7);
  }
  100% {
    opacity: 0.9;
    transform: translateX(0) scale(1);
  }
}

.end-content {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  max-width: 450px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
}

/* Win/Lose Title */
.end-title {
  font-size: 52px;
  font-weight: 700;
  color: white;
  margin-bottom: 10px;
  letter-spacing: 3px;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  opacity: 0;
  animation: endTitleIn 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.3s forwards;
}

.end-title.win {
  color: #4ade80;
  text-shadow: 0 0 30px rgba(74, 222, 128, 0.5);
}

.end-title.lose {
  color: #a94747;
  text-shadow: 0 0 30px rgba(248, 113, 113, 0.5);
}

@keyframes endTitleIn {
  0% {
    opacity: 0;
    transform: scale(2) translateY(-30px);
    filter: blur(10px);
  }
  60% {
    transform: scale(0.95) translateY(5px);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Subtitle */
.end-subtitle {
  font-size: 18px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 40px;
  letter-spacing: 2px;
  opacity: 0;
  animation: endSubtitleIn 0.6s ease-out 0.6s forwards;
}

@keyframes endSubtitleIn {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* End Screen Buttons */
.end-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
  max-width: 350px;
  align-items: center;
}

.end-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  transition: transform 0.2s ease;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

.end-button:first-child {
  animation: endButtonIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.8s forwards;
}

.end-button:last-child {
  animation: endButtonIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.95s forwards;
}

@keyframes endButtonIn {
  0% {
    opacity: 0;
    transform: translateY(40px) scale(0.8);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.end-button img {
  width: 100%;
  max-width: 320px;
  height: auto;
  display: block;
}

.end-button:hover img {
  transform: scale(1.03);
  filter: brightness(1.1);
}

.end-button:active img {
  transform: scale(0.97);
  filter: brightness(1.2);
}

/* End screen exit animations */
#end-screen.exiting .screen-bg {
  animation: endBgOut 0.5s ease-in forwards;
}

@keyframes endBgOut {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.3);
    filter: blur(10px);
  }
}

#end-screen.exiting .end-logo,
#end-screen.exiting .end-title,
#end-screen.exiting .end-subtitle,
#end-screen.exiting .end-button {
  animation: endElementsOut 0.4s ease-in forwards;
}

@keyframes endElementsOut {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-30px) scale(0.9);
  }
}

/* Touch Controls */
#touch-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  padding: 20px 20px;
  padding-bottom: max(30px, env(safe-area-inset-bottom, 30px));
  z-index: 150;
  pointer-events: none;
}

#touch-controls > * {
  pointer-events: auto;
}

#right-controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
}

.pedal-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Tilt buttons */
.tilt-btn {
  width: 56px;
  height: 56px;
}

.tilt-btn .pedal-icon {
  width: 24px;
  height: 24px;
}

.tilt-btn:active,
.tilt-btn.active {
  transform: scale(0.92);
  background: rgba(0, 212, 200, 0.2);
  box-shadow: 0 0 25px var(--teal-glow), inset 0 0 20px rgba(0, 212, 200, 0.15);
}

/* Gas button */
.gas-btn {
  width: 90px;
  height: 90px;
}

.gas-btn:active,
.gas-btn.active {
  transform: scale(0.92);
  filter: brightness(1.2);
}

/* Brake button */
.brake-btn {
  width: 80px;
  height: 80px;
}

.brake-btn:active,
.brake-btn.active {
  transform: scale(0.92);
  filter: brightness(1.2);
}

/* Boost button */
.boost-btn {
  width: 60px;
  height: 60px;
}

.boost-btn:active,
.boost-btn.active {
  transform: scale(0.92);
  background: rgba(0, 212, 200, 0.2);
  box-shadow: 0 0 25px var(--teal-glow), inset 0 0 20px rgba(0, 212, 200, 0.15);
}

/* Landscape warning */
@media screen and (orientation: landscape) and (max-height: 500px) {
  body::before {
    content: "📱 Please rotate to portrait mode";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #0a0a12;
    color: var(--teal);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    font-size: 20px;
    text-align: center;
    padding: 20px;
    font-weight: 600;
    letter-spacing: 1px;
  }
}

/* Small screen adjustments */
@media screen and (max-width: 380px) {
  .tilt-btn {
    width: 48px;
    height: 48px;
  }

  .gas-btn {
    width: 70px;
    height: 70px;
  }

  .brake-btn {
    width: 65px;
    height: 65px;
  }

  .boost-btn {
    width: 52px;
    height: 52px;
  }

  #distance {
    font-size: 26px;
  }

  #boost-indicator {
    width: 50px;
    height: 50px;
    bottom: 160px;
  }
}

/* Larger screen adjustments */
@media screen and (min-width: 500px) {
  #touch-controls {
    padding: 25px 20px;
  }

  .tilt-btn {
    width: 64px;
    height: 64px;
  }

  .gas-btn {
    width: 100px;
    height: 100px;
  }

  .brake-btn {
    width: 90px;
    height: 90px;
  }
}

/* ========== TUTORIAL OVERLAY ========== */
#tutorial-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 200;
  display: none;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}

#tutorial-overlay.active {
  display: flex;
  animation: tutorialFadeIn 0.3s ease-out;
}

@keyframes tutorialFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.tutorial-text {
  color: white;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 3px;
  text-align: center;
  text-shadow: 0 0 30px rgba(0, 212, 200, 1), 0 0 60px rgba(0, 212, 200, 0.5),
    0 4px 15px rgba(0, 0, 0, 0.8);
  padding: 25px 50px;
  background: rgba(0, 20, 25, 0.5);
  border: 2px solid rgba(0, 212, 200, 0.4);
  border-radius: 12px;
  animation: tutorialPulse 1.5s ease-in-out infinite;
  margin-bottom: 100px;
}

@keyframes tutorialPulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 20px rgba(0, 212, 200, 0.3);
  }
  50% {
    transform: scale(1.02);
    box-shadow: 0 0 40px rgba(0, 212, 200, 0.5);
  }
}

/* Highlight gas button during tutorial step 1 */
#game-screen.tutorial-gas #gas-btn {
  z-index: 250;
  position: relative;
  filter: drop-shadow(0 0 25px rgba(0, 212, 200, 1))
    drop-shadow(0 0 40px rgba(0, 212, 200, 0.7));
  animation: highlightPulse 1s ease-in-out infinite;
}

/* Dim brake button during gas tutorial */
#game-screen.tutorial-gas #brake-btn {
  opacity: 0.3;
}

/* Highlight brake button during tutorial step 2 */
#game-screen.tutorial-brake #brake-btn {
  z-index: 250;
  position: relative;
  filter: drop-shadow(0 0 25px rgba(0, 212, 200, 1))
    drop-shadow(0 0 40px rgba(0, 212, 200, 0.7));
  animation: highlightPulse 1s ease-in-out infinite;
}

/* Dim gas button during brake tutorial */
#game-screen.tutorial-brake #gas-btn {
  opacity: 0.3;
}

@keyframes highlightPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}
