/* Attack of The Kruptins - Styles */

html, body { 
  margin: 0; 
  height: 100%; 
  background: #000; 
  color: #fff; 
  font-family: system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif; 
}

#canvas { 
  display: block; 
  margin: 0 auto; 
  image-rendering: pixelated; 
}

#hud { 
  position: fixed; 
  left: 12px; 
  top: 10px; 
  font-size: 14px; 
  opacity: 0.9; 
  user-select: none; 
}

#help { 
  position: fixed; 
  left: 12px; 
  top: 30px; 
  font-size: 12px; 
  color: #bfbfbf; 
  opacity: 0.9; 
  user-select: none; 
}

/* Credits counter (top-right) */
#credits {
  position: fixed; 
  right: 12px; 
  top: 10px;
  background: rgba(60,60,60,0.85);
  color: #63a3ff; 
  font-weight: 700; 
  font-size: 14px;
  padding: 4px 8px; 
  border-radius: 6px; 
  user-select: none;
}

/* Kill counter (top-right, below credits) */
#kills {
  position: fixed; 
  right: 12px; 
  top: 40px;
  background: rgba(60,60,60,0.85);
  color: #00ff63; 
  font-weight: 700; 
  font-size: 14px;
  padding: 4px 8px; 
  border-radius: 6px; 
  user-select: none;
}

/* Rooms cleared counter (top-right, below kills) */
#rooms {
  position: fixed; 
  right: 12px; 
  top: 70px;
  background: rgba(60,60,60,0.85);
  color: #ff6363; 
  font-weight: 700; 
  font-size: 14px;
  padding: 4px 8px; 
  border-radius: 6px; 
  user-select: none;
}

/* Lives counter (top-right, below rooms) */
#lives {
  position: fixed; 
  right: 12px; 
  top: 100px;
  background: rgba(60,60,60,0.85);
  color: #ffaa00; 
  font-weight: 700; 
  font-size: 14px;
  padding: 4px 8px; 
  border-radius: 6px; 
  user-select: none;
}

/* Lives display (top-right, below rooms) */
#lives-display {
  position: fixed; 
  right: 12px; 
  top: 100px;
  background: rgba(60,60,60,0.85);
  color: #ffaa63; 
  font-weight: 700; 
  font-size: 14px;
  padding: 4px 8px; 
  border-radius: 6px; 
  user-select: none;
  display: none; /* Hidden by default, shown when > 1 life */
}

/* Debug god mode indicator */
#debug {
  position: fixed; 
  left: 50%; 
  top: 10px;
  transform: translateX(-50%);
  background: rgba(0, 100, 0, 0.85);
  color: #00ff00; 
  font-weight: 700; 
  font-size: 16px;
  padding: 6px 12px; 
  border-radius: 6px; 
  user-select: none;
  display: none;
}

/* --- Mobile touch UI --- */
#touch-ui { 
  position: fixed; 
  inset: 0; 
  pointer-events: none;
  display: none; /* Hide by default */
}

/* Only show touch UI on mobile devices */
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
  #touch-ui {
    display: block;
  }
}

/* Force show touch UI if JavaScript detects mobile */
#touch-ui.force-mobile {
  display: block !important;
}

#dpad { 
  position: fixed; 
  left: 3vw; 
  bottom: 4vh; 
  width: 28vw; 
  height: 28vw; 
  max-width: 220px; 
  max-height: 220px; 
  pointer-events: auto; 
}

.dpad-btn { 
  position: absolute; 
  width: 34%; 
  height: 34%; 
  background: rgba(128,128,128,0.2); 
  border: 2px solid rgba(200,200,200,0.4); 
  border-radius: 14px; 
  color: #fff; 
  font-size: clamp(16px, 6vw, 26px); 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  user-select: none; 
  -webkit-user-select: none; 
  touch-action: none; 
}

.dpad-btn:active { 
  background: rgba(160,160,160,0.28); 
}

#btn-up    { left: 33%; top: 3%; }
#btn-down  { left: 33%; bottom: 3%; }
#btn-left  { top: 33%; left: 3%; }
#btn-right { top: 33%; right: 3%; }

/* --- Digital Joystick --- */
#joystick {
  position: fixed;
  left: 3vw;
  bottom: 4vh;
  width: 28vw;
  height: 28vw;
  max-width: 220px;
  max-height: 220px;
  touch-action: none;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

#joystick .outer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(128,128,128,0.20);
  border-radius: 50%;
  pointer-events: none;
}

#joystick .inner {
  position: absolute;
  width: 38%;
  height: 38%;
  left: 31%;
  top: 31%;
  background: rgba(128,128,128,0.50);
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  transition: left 0.08s, top 0.08s;
}

/* --- Control selection screen --- */
#control-selection {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: #fff;
  font-family: system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

#control-selection h1 {
  font-size: 36px;
  margin-bottom: 40px;
  color: #ff6363;
}

#control-selection .control-option {
  background: rgba(60,60,60,0.85);
  border: 2px solid rgba(200,200,200,0.4);
  border-radius: 12px;
  padding: 20px 40px;
  margin: 15px;
  font-size: 20px;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 300px;
  text-align: center;
}

#control-selection .control-option:hover {
  background: rgba(80,80,80,0.9);
  border-color: rgba(255,255,255,0.6);
  transform: translateY(-2px);
}

#control-selection .control-option:active {
  transform: translateY(0);
}

#control-selection.hidden {
  display: none;
}

/* Boot sequence: hide options, center and grow title */
#control-selection.booting .control-option {
  display: none !important;
}

#control-selection.booting h1 {
  margin: 0;
  animation: boot-zoom 1.6s ease-out forwards;
}

/* During boot, hide everything except title */
#control-selection.booting > *:not(h1) {
  display: none !important;
}

@keyframes boot-zoom {
  0% { transform: scale(1); opacity: 1; letter-spacing: 0px; }
  60% { transform: scale(1.8); opacity: 1; letter-spacing: 1px; }
  100% { transform: scale(2.2); opacity: 1; letter-spacing: 2px; }
}

/* --- Upgrade Menu --- */
.upgrade-menu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20, 20, 20, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  padding: 25px;
  min-width: 400px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 2000; /* Higher z-index to ensure it's above mobile controls */
  color: #fff;
  font-family: system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

/* Mobile-friendly upgrade menu */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  .upgrade-menu {
    top: 15px;
    left: 40px;
    right: 40px;
    bottom: 15px;
    transform: none;
    min-width: unset;
    max-width: unset;
    max-height: unset;
    height: auto;
    width: calc(100vw - 80px);
    padding: 12px;
    border-radius: 12px;
    z-index: 2000; /* Ensure it's above mobile controls */
    overflow-y: auto;
    overflow-x: hidden;
    position: fixed;
  }
}

/* Landscape mobile - need more aggressive margins */
@media (max-height: 600px) and (orientation: landscape), 
       (max-width: 926px) and (orientation: landscape) {
  .upgrade-menu {
    left: 60px !important;
    right: 60px !important;
    width: calc(100vw - 120px) !important;
    top: 10px !important;
    bottom: 10px !important;
    padding: 10px !important;
  }
}

/* Disable touch controls when upgrade menu is open */
.upgrade-menu:not(.hidden) ~ #touch-ui {
  pointer-events: none !important;
}

/* Disable all touch interactions on the game canvas when upgrade menu is open */
.upgrade-menu:not(.hidden) ~ * canvas {
  pointer-events: none !important;
}

/* Disable document-level touch events when upgrade menu is open */
body:has(.upgrade-menu:not(.hidden)) {
  touch-action: none;
}

.upgrade-menu h2 {
  margin: 0 0 20px 0;
  text-align: center;
  color: #63a3ff;
  font-size: 24px;
  font-weight: 700;
}

.menu-credits {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: #63a3ff;
  margin-bottom: 20px;
  padding: 8px 12px;
  background: rgba(60, 60, 60, 0.4);
  border-radius: 6px;
}

.upgrade-item {
  margin-bottom: 15px;
  padding: 15px;
  background: rgba(60, 60, 60, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

.upgrade-item:hover {
  background: rgba(80, 80, 80, 0.4);
}

.upgrade-name {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 6px;
}

.upgrade-desc {
  font-size: 14px;
  color: #bfbfbf;
  margin-bottom: 10px;
  line-height: 1.3;
}

.upgrade-button {
  width: 100%;
  padding: 10px;
  background: rgba(99, 163, 255, 0.8);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

/* Mobile-friendly upgrade buttons */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  .upgrade-button {
    padding: 15px;
    font-size: 16px;
    min-height: 50px;
    touch-action: manipulation;
  }
  
  .upgrade-item {
    margin-bottom: 20px;
    padding: 20px;
  }
  
  .upgrade-name {
    font-size: 18px;
  }
  
  .upgrade-desc {
    font-size: 16px;
  }
  
  .close-button {
    padding: 18px;
    font-size: 18px;
    min-height: 55px;
  }
}

.upgrade-button:hover:not(:disabled) {
  background: rgba(99, 163, 255, 1.0);
  transform: translateY(-1px);
}

.upgrade-button:disabled {
  background: rgba(60, 60, 60, 0.5);
  color: rgba(255, 255, 255, 0.5);
  cursor: not-allowed;
  transform: none;
}

.close-button {
  width: 100%;
  margin-top: 20px;
  padding: 12px;
  background: rgba(255, 99, 99, 0.8);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.close-button:hover {
  background: rgba(255, 99, 99, 1.0);
  transform: translateY(-1px);
}

/* Mobile upgrade button */
#mobile-upgrade-btn {
  position: fixed;
  right: 12px;
  top: 130px; /* Below lives counter */
  width: 50px;
  height: 50px;
  background: rgba(255, 215, 0, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  color: #000;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  pointer-events: auto;
  z-index: 1000;
  transition: all 0.2s ease;
}

#mobile-upgrade-btn:hover {
  background: rgba(255, 215, 0, 1.0);
  transform: scale(1.1);
}

#mobile-upgrade-btn:active {
  transform: scale(0.95);
}

/* Only show for mobile control scheme users (not based on screen size) */
#mobile-upgrade-btn {
  display: none;
}

/* Show when mobile controls are active */
body.mobile-controls #mobile-upgrade-btn {
  display: flex;
}
