@font-face {
  font-family: 'RubikOne';
  src: url('./RubikOne-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

/* ✅ FIXED: Better viewport handling for iOS */
html,
body {
  height: 100%;
  min-height: 100vh;
  min-height: -webkit-fill-available; /* iOS Safari fix */
  margin: 0;
  padding: 0;
  width: 100%;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
  position: fixed; /* Prevent iOS address bar resize issues */
}

/* ✅ FIXED: Better background handling */
body {
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  background-attachment: fixed; /* Important for iOS */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.game-container {
  position: relative;
  user-select: none;
  width: 100%;
  height: 100%;
}

.countdown-overlay {
  position: fixed; /* Changed from absolute */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  font-family: 'RubikOne';
  font-size: 5rem;
  z-index: 1000;
}

#cloud {
  position: absolute;
  top: 40px;
  margin-top: 60px;
  left: 60%;
  transform: translateX(10%);
  z-index: 15;
}

#bacteria_cloud {
  position: relative;
  top: 145px;
  left: 70px;
  z-index: 15;
}

#game_canvas {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-image: url('../assets/sprites/purifier.png');
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  width: 280px;
  height: 500px;
  max-width: 280px;
  max-height: 500px;
  object-fit: contain;
}

#verticalGuideLine {
  position: absolute;
  right: 5px;
  width: 2px;
  background-color: white;
  display: none;
  z-index: -1;
}

#warningLine {
  position: absolute;
  width: 100%;
  height: 3px;
  border-top: 3px dashed red;
  opacity: 0.5;
  display: none;
  z-index: -1;
  transform: translateY(0);
}

.blinking {
  animation: blink 0.6s step-start infinite;
}

@keyframes blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.conversion-message {
  font-size: 9px;
  color: red;
  text-align: center;
  margin-top: 0px;
  font-family: 'RubikOne';
  background-color: rgba(255, 255, 255, 0.8);
  padding: 0px;
  border-radius: 0px;
}

.info_panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px 0;
  margin-top: 20px;
  margin-left: 25px;
  border-radius: 15px;
  background: white;
}

.bubble_container {
  position: relative;
  background-image: url('../assets/sprites/bubble.png');
  background-size: contain;
  background-repeat: no-repeat;
  width: 60px;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 1;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

.powerup_bubble {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
  animation: float 2s infinite ease-in-out;
}

.powerupoverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(192, 192, 192, 0.7);
  display: none;
  z-index: 1000;
}

#powerup_lightning,
#powerup_rocket {
  width: 50px;
  height: 50px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  border: none;
  outline: none;
  background-color: transparent;
}

#powerup_lightning {
  width: 40px;
  height: 40px;
  background-image: url(../assets/sprites/powerups/lightning.png);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  border: none;
  outline: none;
  background-color: transparent;
  border-radius: 50%;
  position: relative;
}

#powerup_lightning.flicker-effect:not(:disabled) {
  animation: lightningFlicker 0.6s infinite alternate, float 2s infinite ease-in-out;
  box-shadow: 0 0 20px 10px rgba(255, 255, 0, 0.8);
}

@keyframes lightningFlicker {
  0% {
    opacity: 1;
    box-shadow: 0 0 20px 10px rgba(255, 255, 0, 1);
  }
  100% {
    opacity: 0.8;
    box-shadow: 0 0 15px 5px rgba(255, 255, 0, 0.5);
  }
}

@keyframes float {
  0% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
  100% {
    transform: translateY(0);
  }
}

#powerup_rocket {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  transition: all 0.3s ease;
  background-image: url(../assets/sprites/powerups/rocket.png);
  width: 50px;
}

#powerup_rocket.flicker-effect:not(:disabled) {
  animation: rocketFlicker 0.6s infinite alternate, float 2s infinite ease-in-out;
  box-shadow: 0 0 15px 5px rgba(255, 0, 0, 0.8);
}

@keyframes rocketFlicker {
  0% {
    opacity: 1;
    box-shadow: 0 0 15px 5px rgba(255, 0, 0, 1);
  }
  100% {
    opacity: 0.8;
    box-shadow: 0 0 15px 5px rgba(255, 0, 0, 0.5);
  }
}

#powerup_rocket.enabled {
  background-color: transparent;
  box-shadow: 0 0 15px 5px rgba(255, 0, 0, 0.7);
}

.rocket-effect {
  position: absolute;
  background-image: url('../assets/sprites/powerups/rocket.png');
  background-size: contain;
  background-repeat: no-repeat;
  top: 36%;
  left: 25%;
  width: 200px;
  height: 200px;
  z-index: 10000;
  animation: rocket-fly 2s forwards;
}

.explosion-effect {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10000;
  display: none;
}

.explosion-effect img {
  width: 800px;
  height: auto;
  animation: explosionGlowAnim 3s infinite;
}

@keyframes explosionGlowAnim {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
  100% {
    opacity: 0;
    transform: scale(0.8);
  }
}

@keyframes rocket-explosion-glow {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

.multiplier {
  font-size: 48px;
  color: yellow;
  animation: multiplierAnim 2s forwards;
  margin-top: 10px;
  z-index: 10000;
}

#rocketMultiplier {
  display: block;
  font-size: 48px;
  color: yellow;
  position: absolute;
  top: 60%;
  left: 53%;
  transform: translate(-50%, -50%);
  z-index: 1000;
}

@keyframes multiplierAnim {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  50% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-20px);
  }
}

.lightning-effect {
  position: absolute;
  top: 50%;
  left: 60%;
  transform: translate(-50%, -50%);
  background-image: url('../assets/sprites/powerups/lightning.png');
  background-size: contain;
  background-repeat: no-repeat;
  width: 250px;
  height: 150px;
  animation: lightning-strike 3s forwards;
  z-index: 1000;
}

@keyframes lightning-strike {
  0% {
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.point_bubble {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.timer_bubble,
.next_bubble {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.point_display {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgb(17, 48, 134);
  font-size: 10px;
}

.point_display img {
  width: 20px;
  height: auto;
}

#timer {
  font-size: 25px;
  color: #dc9f13;
  text-align: center;
  margin: 5px 0px;
}

.next_display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 70%;
}

.next_display img {
  max-width: 100%;
  max-height: 80%;
  height: auto;
  object-fit: contain;
}

#next_text {
  font-size: 10px;
  color: #dc9f13;
  text-align: center;
  margin-bottom: -3px;
}

.controls {
  position: fixed;
  left: -2%;
  display: flex;
  background: none;
  pointer-events: auto;
}

.control-button {
  border: none;
  cursor: pointer;
  background: none;
  transition: transform 0.2s;
  pointer-events: auto;
}

@keyframes redGlow {
  0% {
    box-shadow: 0 0 10px red;
  }
  50% {
    box-shadow: 0 0 20px red;
  }
  100% {
    box-shadow: 0 0 10px red;
  }
}

.control-button img {
  width: 60px;
  height: auto;
  background: none;
}

.control-button:hover {
  background-color: none;
}

#homeButton {
  margin-right: -20px;
}

#gameOverOverlay {
  font-family: 'Arial', sans-serif;
}

.modal {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.7);
}

.modal-content {
  background-color: #fefefe;
  margin: 46% auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
  text-align: center;
}

#closeModalButton {
  padding: 10px 20px;
  margin: 10px;
  border: none;
  border-radius: 5px;
  background-color: #4caf50;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s;
}

#closeModalButton:hover {
  background-color: #45a049;
}

#score_text {
  font-size: 10px;
  color: #dc9f13;
  text-align: center;
  margin-bottom: -3px;
}

#best_text {
  font-size: 10px;
  color: #dc9f13;
  text-align: center;
  margin-bottom: -3px;
}

.bubble_container:hover .tooltip {
  visibility: visible;
}

.powerup_timer {
  font-size: 13px;
  margin-top: -10px;
  color: #ff0000;
  display: none;
}

@keyframes warning-flash {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.warning-flicker {
  animation: warning-flash 0.5s ease-in-out infinite;
}

/* ✅ MOBILE MEDIA QUERIES */
@media only screen and (max-width: 768px) {
  html, body {
    min-height: -webkit-fill-available; /* Critical for iOS */
  }
  
  #game_canvas {
    width: 100%;
    height: 70vh;
    bottom: 0;
    max-width: 100vw;
  }

  .ui-element {
    position: absolute;
    z-index: 10;
  }

  .info_panel {
    margin-left: 0;
    padding: 5px 0;
  }
  
  .bubble_container {
    width: 60px;
    height: 60px;
  }
  
  #timer,
  #points,
  #highest,
  #next_text {
    font-size: 14px;
  }
  
  #next_bacteria {
    max-width: 40px;
  }
}

@media (max-width: 480px) {
  .bubble_container {
    width: 50px;
    height: 50px;
  }
  
  #timer,
  #points,
  #highest,
  #next_text {
    font-size: 12px;
  }
  
  #next_bacteria {
    max-width: 30px;
  }
}