body {
  font-family: "Press Start 2P", cursive;
  background-color: #000;
  color: #fff;
  overflow: hidden;
  /* Prevent zoom on mobile */
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Prevent screen rotation on mobile devices only */
@media (max-width: 768px) {
  body {
    /* Lock orientation to portrait mode */
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);

    /* Prevent orientation changes */
    -webkit-transform-origin: center center;
    -moz-transform-origin: center center;
    -ms-transform-origin: center center;
    -o-transform-origin: center center;
    transform-origin: center center;

    /* Force portrait mode */
    min-height: 100vh;
    min-width: 100vw;
  }
}

/* Show message when device is in landscape mode on mobile - restrict to portrait only */
@media (max-width: 768px) and (orientation: landscape) {
  body::before {
    content: "📱 Please rotate your device to PORTRAIT mode to play! 🔄";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    color: #e9af51;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 1.2rem;
    padding: 2rem;
    z-index: 99999;
    font-family: "Press Start 2P", cursive;
    box-shadow: 0 0 20px rgba(233, 175, 81, 0.3);
  }
}

canvas {
  background-color: #111;
  display: block;
  margin: 0 auto;
  border: 2px solid #ff0000;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Add bottom margin to canvas on mobile screens */
@media (max-width: 768px) {
  canvas {
    margin-bottom: 80px;
  }
}

/* Extra margin for very small screens */
@media (max-width: 480px) {
  canvas {
    margin-bottom: 100px;
  }
}

.ui-panel {
  background-color: #222;
  border: 2px solid #ff0000;
  border-radius: 8px;
  box-shadow: 0 0 10px #ff0000;
  min-width: 0;
  flex: 1;
  margin: 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Mobile Controls Styles - Analog Joystick */
#mobile-controls {
  /* Ensure controller is fully visible with proper margins */
  margin-bottom: 20px;
  margin-left: 10px;
}

/* Hide mobile controls on large screens and web browsers */
@media (min-width: 769px) {
  #mobile-controls {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
  }
}

#joystick-base {
  background: linear-gradient(145deg, #374151, #1f2937);
  border: 3px solid #4b5563;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.1),
    0 8px 16px rgba(0, 0, 0, 0.4);
}

#joystick-area {
  background: linear-gradient(145deg, #4b5563, #374151);
  border: 2px solid #6b7280;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

#joystick-handle {
  background: linear-gradient(145deg, #fbbf24, #f59e0b);
  border: 2px solid #e9af51;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3), 0 0 10px rgba(233, 175, 81, 0.3);
  z-index: 10;
  user-select: none;
  touch-action: none;
  will-change: transform;
  transition: transform 0.05s ease-out;
}

#joystick-handle:active {
  background: linear-gradient(145deg, #e9af51, #d97706);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4), 0 0 15px rgba(233, 175, 81, 0.6);
  transform: scale(0.95);
  transition: transform 0.1s ease-out;
}

/* Joystick movement area indicator */
#joystick-area::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 2px;
  background: rgba(233, 175, 81, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Pulse animation for controller */
@keyframes controllerPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}

#mobile-controls .relative {
  animation: controllerPulse 3s ease-in-out infinite;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.4));
}

/* Responsive adjustments for smaller screens */
@media (max-width: 480px) {
  #mobile-controls {
    bottom: 20px !important;
    left: 20px !important;
  }

  #mobile-controls .w-32 {
    width: 6rem;
    height: 6rem;
  }

  #mobile-controls .w-24 {
    width: 4.5rem;
    height: 4.5rem;
  }

  #mobile-controls .w-12 {
    width: 2.5rem;
    height: 2.5rem;
  }

  /* UI panel adjustments for very small screens */
  .ui-panel {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem !important;
    height: 2.5rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

/* Extra small screens */
@media (max-width: 320px) {
  .ui-panel {
    font-size: 0.65rem;
    padding: 0.2rem 0.3rem !important;
  }
}

/* Mobile popup scrolling improvements */
@media (max-width: 768px) {
  #start-popup {
    padding: 1rem;
  }

  #start-popup > div {
    padding: 1rem;
  }

  /* Ensure content is scrollable on small screens */
  #start-popup,
  #message-box {
    -webkit-overflow-scrolling: touch;
  }

  /* UI panel height consistency for mobile */
  .ui-panel {
    height: 2.8rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

/* Landscape mode adjustments */
@media (orientation: landscape) and (max-height: 500px) {
  #start-popup > div {
    padding: 0.5rem;
  }

  #start-popup h1 {
    font-size: 1.5rem !important;
    margin-bottom: 1rem !important;
  }

  #start-popup .bg-gray-900 {
    margin-bottom: 1rem !important;
  }

  #start-popup .text-xs {
    font-size: 0.6rem;
  }

  /* UI panel height consistency for landscape mode */
  .ui-panel {
    height: 2.2rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.7rem !important;
    padding: 0.2rem 0.4rem !important;
  }

  /* Mobile controls in landscape mode - only when game is running */
  #mobile-controls.game-active {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    bottom: 10px !important;
    left: 10px !important;
    margin-bottom: 0 !important;
    margin-left: 0 !important;
    z-index: 9999 !important;
  }

  #mobile-controls .w-32 {
    width: 5rem !important;
    height: 5rem !important;
  }

  #mobile-controls .w-24 {
    width: 3.5rem !important;
    height: 3.5rem !important;
  }

  #mobile-controls .w-12 {
    width: 2rem !important;
    height: 2rem !important;
  }
}

/* Additional landscape mode detection */
@media (max-height: 500px) {
  #mobile-controls.game-active {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    bottom: 10px !important;
    left: 10px !important;
    margin-bottom: 0 !important;
    margin-left: 0 !important;
    z-index: 9999 !important;
  }
}
