:root {
  --game-width: min(800px, 100vw);
  --game-height: min(400px, 50vh);
  --player-size: min(75px, calc(var(--game-width) * 0.09375));
  --platform-height: 20px;
}

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

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #333;
  font-family: Arial, sans-serif;
}

#game-container {
  width: var(--game-width);
  height: var(--game-height);
  position: relative;
  overflow: hidden;
  background: #87ceeb;
  border: 4px solid #4caf50;
  border-radius: 8px;
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

#player {
  width: var(--player-size);
  height: calc(var(--player-size) * 0.666);
  position: absolute;
  top: calc(var(--game-height) - 90px);
  left: 100px;
  transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
  transform-origin: center;
  will-change: transform, top, left;
  display: flex;
  justify-content: center;
  align-items: center;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
}

#player::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  box-sizing: border-box;
}

#player img {
  width: 100%;
  height: 100%;
  transform: scaleX(1) translateZ(0);
  transform-origin: center;
  pointer-events: none;
  position: absolute;
  left: 0;
  top: 0;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  backface-visibility: hidden;
}

#player.jumping {
  animation: jump 1s ease-in-out;
}

.platform {
  position: absolute;
  height: var(--platform-height);
  background: #4caf50;
  border-radius: 4px;
  animation: spawn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center;
  will-change: transform, left;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
}

.platform.breakable {
  background: #ffa500;
  border: 2px solid #ff4500;
  overflow: hidden;
  position: relative;
  will-change: transform, opacity;
}

.platform.breakable::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    #ffa500 33%,
    #ff4500 33%,
    #ff4500 66%,
    #ffa500 66%
  );
  opacity: 0;
}

.platform.decaying {
  animation: shake 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    break 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.platform.decaying::before {
  animation: crack 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.powerup {
  position: absolute;
  width: 30px;
  height: 30px;
  z-index: 5;
  animation: powerup-float 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  will-change: transform, left;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
}

.powerup img {
  width: 100%;
  height: 100%;
}

/* Bomb - Dangerous (Red pulsing warning) */
.powerup[data-type='Bomb'] {
  filter: drop-shadow(0 0 10px rgba(255, 0, 0, 0.8));
  animation: powerup-float 2s cubic-bezier(0.4, 0, 0.6, 1) infinite,
    bomb-danger 1.2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.powerup[data-type='Bomb']::before {
  content: '⚠️';
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  animation: warning-pulse 0.5s ease-in-out infinite;
}

.powerup[data-type='Bomb'] img {
  animation: bomb-shake 0.6s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Wrench - Positive (Green glow) */
.powerup[data-type='Wrench'] {
  filter: drop-shadow(0 0 8px rgba(0, 255, 0, 0.6));
  animation: powerup-float 2s cubic-bezier(0.4, 0, 0.6, 1) infinite,
    positive-glow 2.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Wing Powerup - Positive (Blue/Cyan glow) */
.powerup[data-type='WingPowerup'] {
  filter: drop-shadow(0 0 8px rgba(0, 200, 255, 0.6));
  animation: powerup-float 2s cubic-bezier(0.4, 0, 0.6, 1) infinite,
    positive-glow 2.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

#hud {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
  z-index: 20;
}

.hud-left,
.hud-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-element {
  font-size: 16px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  background: rgba(0, 0, 0, 0.4);
  padding: 5px 12px;
  border-radius: 6px;
  backdrop-filter: blur(5px);
  color: white;
  white-space: nowrap;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: contents;
}

#score-container.hud-element {
  /* Default white color from .hud-element */
}

#high-score.hud-element {
  color: #ffd700;
}

#speed.hud-element {
  color: #00ff00;
}

#double-jumps.hud-element {
  display: none;
  align-items: center;
  gap: 5px;
  min-height: 30px;
}

#double-jumps:not(:empty) {
  display: flex;
}

.wing-indicator {
  width: 20px;
  height: 20px;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.5));
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  will-change: transform;
  backface-visibility: hidden;
}

.wing-indicator:hover {
  transform: scale(1.2) rotate(5deg);
}

#splash-screen,
#game-over {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  text-align: center;
  padding: 20px;
  font-size: clamp(12px, 3vw, 16px);
  z-index: 100;
}

#splash-screen h1 {
  font-size: clamp(24px, 5vw, 36px);
  margin-bottom: 20px;
  width: 100%;
}

.info-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 40px;
  margin: 0 auto;
  width: 100%;
  max-width: 800px;
}

.controls-section,
.powerups-section {
  flex: 1;
  max-width: 300px;
  margin: 0;
  padding: 15px;
}

.controls-section h2,
.powerups-section h2 {
  font-size: clamp(18px, 4vw, 24px);
  margin-bottom: 15px;
}

.powerup-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 12px 0;
  font-size: clamp(12px, 3vw, 16px);
}

.powerup-item img {
  width: clamp(20px, 5vw, 30px);
  height: clamp(20px, 5vw, 30px);
}

/* Make bomb warning more prominent in splash screen */
.powerup-item:has(img[alt='Bomb']) {
  color: #ff4444;
  font-weight: bold;
  background: rgba(255, 68, 68, 0.1);
  padding: 8px 15px;
  border-radius: 8px;
  border: 2px solid rgba(255, 68, 68, 0.5);
  animation: bomb-warning-flash 1.5s ease-in-out infinite;
}

.powerup-item:has(img[alt='Bomb']) img {
  filter: drop-shadow(0 0 5px rgba(255, 0, 0, 0.8));
}

/* Make positive powerups look good in splash screen */
.powerup-item:has(img[alt='Wrench']) {
  color: #4caf50;
}

.powerup-item:has(img[alt='Wing']) {
  color: #00bcd4;
}

@keyframes bomb-warning-flash {
  0%,
  100% {
    border-color: rgba(255, 68, 68, 0.5);
    background: rgba(255, 68, 68, 0.1);
  }
  50% {
    border-color: rgba(255, 68, 68, 0.9);
    background: rgba(255, 68, 68, 0.2);
  }
}

.start-instruction,
.restart-instruction {
  font-size: clamp(18px, 4vw, 24px);
  margin-top: 20px;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  width: 100%;
  will-change: opacity, transform;
}

#game-over h2 {
  font-size: 48px;
  margin-bottom: 20px;
  color: #ff4444;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.score-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

#final-score,
#final-high-score {
  font-size: 24px;
  padding: 5px 15px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  min-width: 200px;
  text-align: center;
}

#final-high-score {
  color: #ffd700;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

#final-high-score.new-record {
  animation: glow 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite alternate;
  font-weight: bold;
  position: relative;
  will-change: text-shadow;
}

#final-high-score.new-record::before {
  content: '🏆 New Record!';
  position: absolute;
  top: -25px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  color: #ffd700;
  white-space: nowrap;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

@keyframes glow {
  from {
    text-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 15px #e60073, 0 0 20px #e60073,
      0 0 25px #e60073, 0 0 30px #e60073, 0 0 35px #e60073;
  }
  to {
    text-shadow: 0 0 10px #fff, 0 0 20px #ff4da6, 0 0 30px #ff4da6,
      0 0 40px #ff4da6, 0 0 50px #ff4da6, 0 0 60px #ff4da6, 0 0 70px #ff4da6;
  }
}

#mobile-controls {
  position: absolute;
  bottom: 20px;
  width: 100%;
  display: none;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 50;
}

.touch-button {
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  color: white;
  user-select: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform, background;
  backface-visibility: hidden;
}

.touch-button:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.4);
}

@media (max-width: 600px) {
  .info-container {
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }

  .controls-section,
  .powerups-section {
    width: 100%;
    padding: 10px;
  }

  .powerup-item {
    margin: 8px 0;
  }
}

@media (max-width: 768px) {
  #mobile-controls {
    display: flex;
  }
}

@media (max-height: 500px) {
  #splash-screen,
  #game-over {
    padding: 10px;
  }

  #splash-screen h1 {
    margin-bottom: 10px;
  }

  .controls-section,
  .powerups-section {
    margin: 8px 0;
  }

  .powerup-item {
    margin: 4px 0;
  }

  .start-instruction,
  .restart-instruction {
    margin-top: 8px;
  }
}

@keyframes jump {
  0% {
    transform: rotate(0deg) translateZ(0);
  }
  50% {
    transform: rotate(180deg) translateZ(0) scale(1.05);
  }
  100% {
    transform: rotate(360deg) translateZ(0);
  }
}

@keyframes spawn {
  0% {
    transform: scaleY(0) translateZ(0);
    opacity: 0;
  }
  60% {
    transform: scaleY(1.05) translateZ(0);
    opacity: 1;
  }
  100% {
    transform: scaleY(1) translateZ(0);
    opacity: 1;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  20% {
    transform: translate3d(-3px, 0, 0) rotate(-1deg);
  }
  40% {
    transform: translate3d(3px, 0, 0) rotate(1deg);
  }
  60% {
    transform: translate3d(-3px, 0, 0) rotate(-1deg);
  }
  80% {
    transform: translate3d(3px, 0, 0) rotate(1deg);
  }
}

@keyframes break {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    filter: brightness(1);
  }
  30% {
    transform: translate3d(0, -2px, 0) rotate(0deg);
    filter: brightness(1.2);
  }
  100% {
    transform: translate3d(0, 100px, 0) rotate(15deg);
    filter: brightness(0.8);
    opacity: 0;
  }
}

@keyframes crack {
  0% {
    opacity: 0;
    transform: scaleX(0.7) scaleY(0) translateZ(0);
  }
  30% {
    opacity: 1;
    transform: scaleX(1) scaleY(1) translateZ(0);
  }
  100% {
    opacity: 1;
    transform: scaleX(1.2) scaleY(1) translateZ(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.02);
  }
}

@keyframes decay {
  to {
    opacity: 0;
  }
}

@keyframes pop-in {
  0% {
    transform: scale(0) rotate(-45deg) translateZ(0);
    opacity: 0;
  }
  60% {
    transform: scale(1.1) rotate(0deg) translateZ(0);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(0deg) translateZ(0);
    opacity: 1;
  }
}

/* Power-up animations */
@keyframes powerup-float {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(0, -10px, 0);
  }
}

@keyframes bomb-danger {
  0%,
  100% {
    filter: drop-shadow(0 0 10px rgba(255, 0, 0, 0.8)) brightness(1);
  }
  50% {
    filter: drop-shadow(0 0 20px rgba(255, 0, 0, 1))
      drop-shadow(0 0 30px rgba(255, 50, 0, 0.8)) brightness(1.1);
  }
}

@keyframes bomb-shake {
  0%,
  100% {
    transform: rotate(0deg) translateZ(0);
  }
  25% {
    transform: rotate(-5deg) translateZ(0);
  }
  50% {
    transform: rotate(0deg) translateZ(0);
  }
  75% {
    transform: rotate(5deg) translateZ(0);
  }
}

@keyframes warning-pulse {
  0%,
  100% {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateZ(0);
  }
  50% {
    opacity: 0.6;
    transform: translateX(-50%) scale(1.3) translateZ(0);
  }
}

@keyframes positive-glow {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(0, -10px, 0) scale(1.08);
  }
}

#game-over {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 1000;
}

#pause-screen {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 1000;
}

#pause-screen h2 {
  font-size: 2em;
  margin-bottom: 20px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.pause-instruction {
  font-size: 1.2em;
  color: #ccc;
}

@keyframes bomb-explosion {
  0% {
    transform: scale(1) rotate(0deg) translateZ(0);
    opacity: 1;
    filter: drop-shadow(0 0 10px rgba(255, 0, 0, 0.8)) brightness(1);
  }
  50% {
    transform: scale(1.5) rotate(180deg) translateZ(0);
    opacity: 0.8;
    filter: drop-shadow(0 0 30px rgba(255, 100, 0, 1))
      drop-shadow(0 0 50px rgba(255, 50, 0, 0.9)) brightness(1.3);
  }
  100% {
    transform: scale(0.2) rotate(360deg) translateZ(0);
    opacity: 0;
    filter: drop-shadow(0 0 0px rgba(255, 0, 0, 0)) brightness(0.5);
  }
}

@keyframes explosion-burst {
  0% {
    width: 0;
    height: 0;
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(255, 100, 0, 0.8);
  }
  50% {
    opacity: 0.6;
  }
  100% {
    width: 200px;
    height: 200px;
    opacity: 0;
    box-shadow: 0 0 60px 60px rgba(255, 50, 0, 0);
  }
}

.bomb-explosion {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 200, 0, 0.8) 0%,
    rgba(255, 100, 0, 0.6) 40%,
    rgba(255, 0, 0, 0.2) 100%
  );
  animation: explosion-burst 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  z-index: 15;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.powerup[data-type='Bomb'].hit-explosion {
  animation: bomb-explosion 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
}
