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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Press Start 2P', monospace;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#game-wrapper {
  position: relative;
  width: 320px;
  height: 480px;
  margin: auto;
  top: 50%;
  transform: translateY(-50%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#crt-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.1) 2px,
    rgba(0, 0, 0, 0.1) 4px
  );
  z-index: 10;
}

#mobile-controls.hidden,
.ctrl-btn.hidden,
#btn-retry.hidden {
  display: none !important;
}

#mobile-controls {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

.ctrl-btn {
  position: absolute;
  pointer-events: auto;
  border-radius: 8px;
}

.turbo-btn {
  background: rgba(255, 80, 80, 0.2);
  border: 1px solid rgba(255, 80, 80, 0.35);
}

#btn-left {
  left: 4px;
  bottom: 30px;
  width: 60px;
  height: 60px;
}

#btn-right {
  right: 4px;
  bottom: 30px;
  width: 60px;
  height: 60px;
}

#joystick-container {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  width: 177px;
  height: 64px;
  pointer-events: auto;
  touch-action: none;
  opacity: 0.5;
}

#joystick-rail {
  position: absolute;
  width: 177px;
  height: 61px;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

#joystick-knob {
  position: absolute;
  width: 64px;
  height: 64px;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

#btn-retry {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 110px;
  height: 44px;
  background: rgba(248, 56, 0, 0.3);
  border: 1px solid rgba(248, 56, 0, 0.6);
  color: #FCFCFC;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 1px;
}


/* Responsive scaling */
@media (max-width: 340px) {
  #game-wrapper {
    width: 240px;
    height: 360px;
  }
}

@media (min-width: 341px) and (max-width: 500px) {
  #game-wrapper {
    width: 100vw;
    height: calc(100vw * 1.5);
  }
}

@media (min-width: 501px) and (max-height: 600px) {
  #game-wrapper {
    height: 100vh;
    width: calc(100vh / 1.5);
    top: 0;
    transform: none;
  }
}

@media (min-width: 501px) and (min-height: 601px) {
  #game-wrapper {
    height: min(90vh, 720px);
    width: calc(min(90vh, 720px) / 1.5);
    top: 50%;
    transform: translateY(-50%);
  }
}

/* Landscape warning */
@media (orientation: landscape) and (max-height: 500px) {
  #game-wrapper {
    height: 96vh;
    width: calc(96vh / 1.5);
  }
}
