/* --- Game page styles with mobile optimizations --- */
body, html {
  font: 16px/1.5 "Arial", sans-serif;
  font-weight: bold;
  margin: 0;
  padding: 0;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000; /* game background */
  color: #111; /* text color */
  
  /* iOS/Mobile optimizations */
  -webkit-touch-callout: none; /* Disable callout on iOS */
  -webkit-user-select: none;   /* Disable text selection */
  user-select: none;           /* Standard property for text selection */
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
  touch-action: manipulation;  /* Disable double-tap zoom */
  overscroll-behavior: none;   /* Prevent bounce scrolling */
}

#game {
  /* Responsive canvas sizing based on screen size */
  width: min(90vw, 70vh * 2/3); /* Width: 90% of viewport width OR 2/3 of 70% viewport height */
  height: min(90vw * 3/2, 70vh); /* Height: 3/2 aspect ratio OR 70% of viewport height */
  image-rendering: auto; /* Allow smooth scaling for non-pixel art graphics */
  display: block; /* Remove inline spacing */
}

/* Responsive sizing for different screen sizes */
@media (max-width: 480px) {
  /* Mobile phones - use most of the screen but be conservative */
  #game {
    width: min(90vw, 400px); /* Cap width to prevent oversizing */
    height: min(90vw * 1.5, 600px); /* Cap height as well */
    max-height: 80vh; /* Reduced from 85vh */
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  /* Tablets - balanced sizing */
  #game {
    width: min(80vw, 60vh * 2/3);
    height: min(80vw * 1.5, 60vh);
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  /* Small laptops/large tablets */
  #game {
    width: min(60vw, 70vh * 2/3);
    height: min(60vw * 1.5, 70vh);
  }
}

@media (min-width: 1025px) {
  /* Desktop - more conservative sizing */
  #game {
    width: min(50vw, 80vh * 2/3);
    height: min(50vw * 1.5, 80vh);
    max-width: 600px; /* Cap maximum size */
    max-height: 900px;
  }
}

#ui { position: absolute; top: 6px; left: 6px; }
canvas { 
  border: 2px solid #333; 
  background: #888; /* Match the middle tone of the canvas metallic gradient */
  /* Canvas optimizations for mobile */
  transform: translateZ(0); /* Hardware acceleration */
  -webkit-transform: translateZ(0);
  will-change: transform;   /* Hint for browser optimization */
}

/* --- Leaderboard page styles --- */
#leaderboard {
  margin: 20px auto;
  /* Responsive width based on screen size */
  width: min(95vw, 800px); /* Use 95% of viewport width up to 800px max */
  max-width: none; /* Remove fixed max-width */
  background-color: #111;  /* dark background */
  border-radius: 12px;
  padding: clamp(16px, 3vw, 24px); /* Responsive padding */
  color: #f0f0f0; /* light text */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  text-align: center;
}

#leaderboard h2 {
  margin-top: 0;
  font-size: clamp(24px, 5vw, 32px); /* Responsive title size */
  color: gold;
  margin-bottom: clamp(12px, 2vw, 20px); /* Responsive spacing */
}

#leaderboard input[type="text"] {
  padding: clamp(6px, 1.5vw, 10px) clamp(8px, 2vw, 12px); /* Responsive padding */
  font-size: clamp(14px, 3vw, 18px); /* Responsive font size */
  border-radius: 6px;
  border: 1px solid #555;
  background-color: #222;
  color: #f0f0f0;
  margin-right: clamp(6px, 1.5vw, 10px); /* Responsive margin */
  width: clamp(200px, 60%, 300px); /* Responsive width with min/max */
  flex: 1; /* Allow input to grow in flex container */
}

#leaderboard button {
  padding: clamp(6px, 1.5vw, 10px) clamp(12px, 3vw, 20px); /* Responsive padding */
  font-size: clamp(14px, 3vw, 18px); /* Responsive font size */
  border-radius: 6px;
  border: none;
  background-color: gold;
  color: #111;
  cursor: pointer;
  font-weight: bold;
  white-space: nowrap; /* Prevent button text wrapping */
}

#leaderboard button:hover {
  background-color: #ffc107;
}

#leaders {
  list-style: none;
  padding: 0;
  margin-top: 20px;
}

#leaders li {
  background-color: #222;
  border: 1px solid #444;
  border-radius: 8px;
  padding: clamp(10px, 2vw, 16px) clamp(12px, 3vw, 20px); /* Responsive padding */
  margin-bottom: clamp(8px, 2vw, 16px); /* Responsive spacing */
  font-size: clamp(14px, 3vw, 18px); /* Responsive font size */
  display: flex;
  align-items: center;
  transition: transform 0.2s, background-color 0.2s;
  gap: clamp(8px, 2vw, 16px); /* Responsive gap between elements */
}

#leaders li:hover {
  background-color: #333;
  transform: scale(1.02);
}

#leaders li span {
  font-weight: bold;
  color: #ffd700; /* highlight the score */
}

/* Skin icon styling */
.skin-icon {
  width: clamp(48px, 8vw, 80px) !important; /* Responsive icon size */
  height: clamp(48px, 8vw, 80px) !important;
  margin-right: 0; /* Remove margin since we're using gap in parent */
  border-radius: 6px;
  flex-shrink: 0; /* prevent shrinking */
  background-color: #333; /* fallback if image fails to load */
}

/* --- UNIFIED BUTTON STYLING --- */
/* Base button styles for consistency */
.btn-base {
  font-family: "Arial", sans-serif;
  font-weight: bold;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.btn-base:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

/* Blue theme buttons (score, general actions) */
.btn-blue {
  background: rgba(0, 170, 255, 0.9);
  border-color: #00aaff;
  color: white;
}

.btn-blue:hover {
  background: rgba(0, 170, 255, 1);
  border-color: #0099dd;
}

/* Golden theme buttons (leaderboard, special actions) */
.btn-gold {
  background: rgba(255, 215, 0, 0.9);
  border-color: #ffd700;
  color: #111;
}

.btn-gold:hover {
  background: rgba(255, 215, 0, 1);
  border-color: #ffcc00;
}

/* Specific UI element styles */
#score {
  padding: 8px 12px;
  font-size: 16px;
  border-radius: 8px;
  background: rgba(0, 170, 255, 0.9);
  border: 2px solid #00aaff;
  color: white;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#leaderboard-btn {
  padding: 8px 12px !important;
  font-size: 16px !important;
  border-radius: 8px !important;
  background: rgba(255, 215, 0, 0.9) !important;
  border: 2px solid #ffd700 !important;
  color: #111 !important;
  font-weight: bold !important;
  text-decoration: none !important;
  transition: all 0.2s ease !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
}

#leaderboard-btn:hover {
  background: rgba(255, 215, 0, 1) !important;
  border-color: #ffcc00 !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4) !important;
}

#mute-btn {
  width: 44px !important;
  height: 44px !important;
  font-size: 20px !important;
  border: 2px solid #00aaff !important;
  border-radius: 50% !important;
  background: rgba(0, 170, 255, 0.9) !important;
  color: white !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
  position: fixed !important;
  bottom: 10px !important;
  right: 10px !important;
  z-index: 10001 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

#mute-btn:hover {
  background: rgba(0, 170, 255, 1) !important;
  border-color: #0099dd !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4) !important;
}

/* Skin navigation buttons */
#skin-left, #skin-right {
  width: 40px !important;
  height: 40px !important;
  font-size: 18px !important;
  border: 2px solid #ddd !important;
  border-radius: 8px !important;
  background: rgba(255, 255, 255, 0.95) !important;
  color: #333 !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

#skin-left:hover, #skin-right:hover {
  background: rgba(255, 255, 255, 1) !important;
  border-color: #bbb !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
}

/* Play button in skin menu */
#start {
  font-size: 24px !important;
  padding: 12px 40px !important;
  border: 3px solid #00aaff !important;
  border-radius: 12px !important;
  background: rgba(0, 170, 255, 0.9) !important;
  color: white !important;
  font-weight: bold !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3) !important;
  margin-top: 40px !important;
}

#start:hover {
  background: rgba(0, 170, 255, 1) !important;
  border-color: #0099dd !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4) !important;
}

/* Play button hint text */
#controls-hint {
  font-size: 14px;
  color: #fff;
  opacity: 0.9;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

/* Login overlay buttons */
#login-overlay button {
  padding: 12px 24px !important;
  font-size: 18px !important;
  border: 2px solid #00aaff !important;
  border-radius: 8px !important;
  background: rgba(0, 170, 255, 0.9) !important;
  color: white !important;
  font-weight: bold !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
}

#login-overlay button:hover {
  background: rgba(0, 170, 255, 1) !important;
  border-color: #0099dd !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4) !important;
}

/* Skin name styling */
#skin-name {
  margin-top: 24px !important;
  font-weight: bold !important;
  font-size: 18px !important;
  color: #fff !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7) !important;
  padding: 8px 16px !important;
  background: rgba(0, 0, 0, 0.3) !important;
  border-radius: 8px !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
}

/* Section filter container styling */
#section-filter-container {
  display: flex !important;
  gap: clamp(6px, 1.5vw, 12px) !important;
  margin-bottom: clamp(12px, 2.5vw, 20px) !important;
  align-items: center !important;
  justify-content: center !important;
}

/* === LEADERBOARD RESPONSIVE DESIGN === */

/* Mobile phones - optimize for smaller screens */
@media (max-width: 480px) {
  /* Adjust body layout for leaderboard page on mobile */
  body {
    align-items: flex-start !important; /* Align to top instead of center */
    /* Minimal padding to prevent horizontal scrolling */
    padding-top: max(15px, env(safe-area-inset-top, 15px)) !important;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px)) !important;
    padding-left: max(8px, env(safe-area-inset-left, 8px)) !important;
    padding-right: max(8px, env(safe-area-inset-right, 8px)) !important;
    min-height: 100vh;
    min-height: 100dvh; /* Use dynamic viewport height if supported */
    box-sizing: border-box;
    overflow-x: hidden; /* Prevent any horizontal scrolling */
  }
  
  #leaderboard {
    /* Ensure no horizontal scrolling on mobile */
    margin: 0 auto;
    width: 85vw; /* Conservative width to prevent horizontal scrolling */
    max-width: calc(100vw - 50px); /* Generous margins to ensure fit */
    padding: 12px; /* Keep internal padding the same */
    border-radius: 8px;
    /* Prevent content from being cut off */
    max-height: calc(100vh - 40px); /* Reduced margins for more space */
    max-height: calc(100dvh - 40px); /* Dynamic viewport height if supported */
    overflow-y: auto;
    /* Ensure scrollable content is visible */
    scrollbar-width: thin;
  }
  
  #leaderboard h2 {
    font-size: 20px; /* Reduced from 24px */
    margin-bottom: 8px; /* Reduced from 12px */
  }
  
  #section-filter-container {
    flex-direction: column !important;
    gap: 6px !important; /* Reduced from 8px */
    margin-bottom: 10px !important; /* Reduced spacing */
  }
  
  #leaderboard input[type="text"] {
    width: 100% !important;
    margin-right: 0 !important;
    font-size: 14px; /* Reduced from 16px */
    padding: 8px 10px; /* Reduced padding */
  }
  
  #leaderboard button {
    width: 100%;
    font-size: 14px; /* Reduced from 16px */
    padding: 8px 12px; /* Reduced padding */
  }
  
  #leaders li {
    padding: 8px; /* Reduced from 12px */
    margin-bottom: 6px; /* Reduced spacing between items */
    font-size: 13px; /* Slightly smaller text */
    flex-direction: column;
    text-align: center;
    gap: 6px; /* Reduced internal gap */
  }
  
  .skin-icon {
    width: 50px !important; /* Reduced from 60px */
    height: 50px !important;
  }
}

/* Mobile portrait orientation - no horizontal scrolling */
@media (max-width: 480px) and (orientation: portrait) {
  #leaderboard {
    width: 88vw; /* Conservative width to prevent scrolling jiggle */
    max-width: calc(100vw - 45px); /* Safe margins for all devices */
    padding: 10px 18px; /* Slightly reduced horizontal padding */
  }
  
  #leaders li {
    padding: 8px 16px; /* Compact but still readable */
    margin-bottom: 4px; /* Tighter spacing */
  }
}

/* Extra small mobile screens and landscape mobile */
@media (max-width: 480px) and (max-height: 600px) {
  body {
    padding-top: 10px !important; /* Further reduced */
    padding-bottom: 10px !important;
  }
  
  #leaderboard {
    padding: 8px; /* Very compact padding */
    max-height: calc(100vh - 25px); /* More aggressive space usage */
    max-height: calc(100dvh - 25px);
  }
  
  #leaderboard h2 {
    font-size: 18px; /* Even smaller title */
    margin-bottom: 6px; /* Minimal spacing */
  }
  
  #leaders li {
    padding: 6px 10px; /* Very compact list items */
    margin-bottom: 3px; /* Minimal spacing between items */
    font-size: 12px; /* Smaller text */
  }
  
  .skin-icon {
    width: 40px !important; /* Even smaller icons */
    height: 40px !important;
  }
}

/* Tablets - balanced layout */
@media (min-width: 481px) and (max-width: 768px) {
  #leaderboard {
    width: 90vw;
    max-width: 600px;
    padding: 20px;
  }
  
  #leaders li {
    font-size: 16px;
  }
  
  .skin-icon {
    width: 64px !important;
    height: 64px !important;
  }
}

/* Large screens - wider layout */
@media (min-width: 1200px) {
  #leaderboard {
    max-width: 900px;
    padding: 32px;
  }
  
  #leaderboard h2 {
    font-size: 36px;
    margin-bottom: 24px;
  }
  
  #leaders li {
    font-size: 18px;
    padding: 16px 24px;
  }
  
  .skin-icon {
    width: 80px !important;
    height: 80px !important;
  }
}
