@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

:root {
  --bg: #0b0d10;
  --fg: #e6edf3;
  --muted: #7d8590;
  --accent: #8bcbff;
  --accent-2: #ffbf69;
  --surface: rgba(15, 19, 24, 0.85);
  --border: rgba(255, 255, 255, 0.1);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
  letter-spacing: 0.5px;
}

#hud {
  position: fixed;
  top: 20px;
  left: 20px;
  right: auto; /* do not stretch across screen */
  width: fit-content; /* contain to content */
  display: grid;
  grid-template-columns: auto auto; /* title + map button */
  align-items: center;
  gap: 32px;
  z-index: 10;
  pointer-events: none;
  padding: 16px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

#hud .title {
  font-size: 26.4px;
  color: var(--accent);
  text-shadow: 0 0 8px rgba(139, 203, 255, 0.3);
  white-space: nowrap;
}

.orange-text {
  color: var(--accent-2);
  text-shadow: 0 0 8px rgba(255, 191, 105, 0.4);
}

#hud .controls {
  display: none; /* hide desktop instructions globally */
}

#game {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

#leaderboard {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 220px;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  z-index: 20;
}

#leaderboard .lb-header { 
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

#leaderboard .lb-title { 
  font-size: 20px;
  color: var(--accent-2);
  margin-bottom: 8px;
  text-shadow: 0 0 8px rgba(255, 191, 105, 0.3);
}

#leaderboard .lb-sub { 
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 8px;
}

#leaderboard .lb-score {
  color: var(--accent);
  font-size: 16px;
}

#leaderboard ol { 
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  max-height: 200px; /* Limit height to show exactly 10 items (12px font + 2px padding + 4px gap = ~18px per item) */
  overflow-y: auto; /* Add scrollbar when needed */
  padding-right: 4px; /* Space for scrollbar */
}

/* Custom scrollbar styling for leaderboard */
#leaderboard ol::-webkit-scrollbar {
  width: 6px;
}

#leaderboard ol::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

#leaderboard ol::-webkit-scrollbar-thumb {
  background: rgba(139, 203, 255, 0.3);
  border-radius: 3px;
}

#leaderboard ol::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 203, 255, 0.5);
}

#leaderboard li { 
  color: var(--fg);
  font-size: 12px;
  padding: 2px 0;
  list-style: none;
  line-height: 1.2;
}

/* Removed .meta styling - using simple text format now */

#win {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.6);
}

.hidden { display: none !important; }
#win.hidden { display: none; }

.win-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 32px 40px;
  border-radius: 12px;
  text-align: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  max-width: 400px;
}

.win-card h1 {
  margin: 0 0 16px 0;
  font-size: 28px;
  color: var(--accent-2);
  text-shadow: 0 0 12px rgba(255, 191, 105, 0.4);
}

.win-card p { 
  color: var(--muted);
  margin: 0;
  font-size: 16px;
  line-height: 1.6;
}

#minimap {
  position: fixed;
  right: 20px;
  bottom: 100px; /* Moved up to avoid mute button (62px height + 20px spacing + 18px margin) */
  width: 200px;
  height: 200px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  padding: 16px 24px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  z-index: 30;
  text-align: center;
  max-width: 80vw;
  animation: toast-in 0.3s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

#countdown {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 40;
  backdrop-filter: blur(8px);
}

.countdown-level {
  font-size: 48px;
  color: var(--text);
  text-align: center;
  opacity: 0.9;
  font-weight: normal;
  margin-bottom: -10px;
}

.countdown-text {
  font-size: 120px;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(139, 203, 255, 0.6);
  animation: countdown-pulse 0.75s ease-in-out;
  text-align: center;
  margin-top: -10px;
}

@keyframes countdown-pulse {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Modal styles */
#modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  max-width: 360px;
  width: 80%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.modal-content {
  padding: 18px;
  text-align: center;
}

.modal h3 {
  margin: 0 0 12px 0;
  color: var(--accent);
  font-size: 1.44em;
  font-family: 'VT323', 'Courier New', monospace;
  text-align: center;
}

.modal p {
  margin: 0 0 18px 0;
  color: var(--text);
  line-height: 1.4;
  font-size: 1.2em;
  font-family: 'VT323', 'Courier New', monospace;
  text-align: center;
}

#input-field {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 17px;
  font-family: 'VT323', 'Courier New', monospace;
  margin-bottom: 12px;
  box-sizing: border-box;
}

#input-field:focus {
  outline: none;
  border-color: var(--accent);
}

.error {
  color: #ff6b6b;
  font-size: 12px;
  font-family: 'VT323', 'Courier New', monospace;
  margin-bottom: 10px;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn {
  padding: 7px 17px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 17px;
  font-family: 'VT323', 'Courier New', monospace;
  transition: background-color 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover {
  background: #6ba9dc;
}

.btn-secondary {
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

/* Mute button */
.mute-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: none;
  border: none;
  cursor: pointer;
  z-index: 15;
  padding: 0;
  user-select: none;
  transition: transform 0.2s ease;
}

.mute-button img {
  width: 62px;
  height: 62px;
  filter: brightness(0.9);
  transition: filter 0.2s ease;
}

.mute-button:hover {
  transform: translateY(-2px);
}

.mute-button:hover img {
  filter: brightness(1.2);
}

.mute-button:active {
  transform: translateY(0);
}



/* Mobile optimizations */
@media (max-width: 768px) {
  /* Mobile specific drawer positioning */
  .mobile-drawer-content {
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-width: none !important;
  }
  /* Welcome screen mobile optimization */
  .welcome-content {
    padding: 20px;
    max-width: 90vw;
  }
  
  .welcome-title {
    font-size: 2.5em;
    margin: 0 0 30px 0;
    line-height: 1.2;
  }
  
  .welcome-leaderboard {
    padding: 15px;
    margin: 20px 0;
  }
  
  .welcome-leaderboard h2 {
    font-size: 1.5em;
    margin: 0 0 12px 0;
  }
  
  #welcome-lb-list {
    font-size: 1em;
    line-height: 1.4;
  }
  
  .start-button {
    padding: 12px 24px;
    font-size: 1.5em;
    margin-top: 20px;
  }
  /* Hide mute button on mobile devices */
  .mute-button {
    display: none;
  }
  /* Ensure map button is visible on mobile */
  .map-button {
    display: inline-flex !important;
  }
  
  /* Optimize HUD for mobile - full width since no leaderboard */
  #hud {
    top: 10px;
    left: 10px;
    right: auto; /* avoid stretching full width */
    width: auto; /* shrink to content */
    max-width: 90vw; /* keep within viewport */
    grid-template-columns: 1fr auto; /* title takes space, map icon minimal */
    grid-template-rows: auto;
    gap: 8px;
    padding: 8px 12px;
    font-size: 14px;
  }
  
  /* Smaller map button on mobile */
  .map-button {
    padding: 4px 6px !important;
    font-size: 14px !important;
  }
  
  .map-icon {
    width: 26px !important; /* 20px * 1.3 = 26px (30% increase from current 20px) */
    height: 26px !important;
  }
  
  #hud .title {
    font-size: 16px;
    text-align: left;
    line-height: 1.2;
  }
  
  /* Hide controls on mobile to save space */
  #hud .controls {
    display: none;
  }
  
  /* Hide desktop leaderboard on mobile - use drawer instead */
  #leaderboard {
    display: none;
  }
  
  /* Minimap mobile adjustments - top right position */
  #minimap {
    top: 60px; /* Below the HUD */
    right: 10px;
    bottom: auto; /* Remove bottom positioning */
    width: 110px;
    height: 110px;
  }
  
  /* Toast mobile adjustments */
  #toast {
    bottom: 160px; /* Above mobile controls */
    max-width: 85vw;
    font-size: 13px;
    padding: 10px 14px;
    line-height: 1.3;
    word-wrap: break-word;
  }
  
  /* Better text scaling for mobile screens */
  body {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  
  /* Ensure minimum touch target sizes */
  button, .btn, .dpad-btn, .action-btn {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Countdown mobile adjustments */
  .countdown-level {
    font-size: 32px;
  }
  
  .countdown-text {
    font-size: 80px;
  }
  
  /* Modal mobile adjustments */
  .modal {
    width: 90%;
    max-width: 320px;
  }
  
  .modal-content {
    padding: 16px;
  }
  
  .modal h3 {
    font-size: 1.3em;
  }
  
  .modal p {
    font-size: 1.1em;
  }
  
  #input-field {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 12px;
  }
  
  .btn {
    padding: 10px 20px;
    font-size: 16px;
  }
}
/* Map button (common) */
.map-button {
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(139, 203, 255, 0.08);
  color: var(--fg);
  font-size: 18px;
  box-shadow: none;
  backdrop-filter: blur(4px);
  pointer-events: auto; /* clickable inside hud */
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-icon {
  width: 22px; /* 16px * 1.4 = 22.4px, rounded to 22px */
  height: 22px;
  filter: brightness(0.9);
  transition: filter 0.2s ease;
}

/* Force minimap visibility when not hidden */
#minimap:not(.hidden) {
  display: block !important;
}

.map-button:hover {
  background: rgba(139, 203, 255, 0.12);
}

.map-button:hover .map-icon {
  filter: brightness(1.2);
}

.map-button:active {
  transform: translateY(0);
}

/* Welcome Screen */
#welcome-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.welcome-content {
  text-align: center;
  max-width: 600px;
  padding: 40px;
}

.welcome-title {
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 3.5em;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(139, 203, 255, 0.5);
  margin: 0 0 40px 0;
  letter-spacing: 2px;
}

.welcome-leaderboard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin: 30px 0;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.welcome-leaderboard h2 {
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 1.8em;
  color: var(--accent-2);
  margin: 0 0 15px 0;
}

#welcome-lb-list {
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 1.2em;
  color: var(--fg);
  line-height: 1.6;
  max-height: 240px; /* Height for ~10 items (1.2em * 1.6 line-height ≈ 24px per item) */
  overflow-y: auto;
  padding-right: 8px; /* Space for scrollbar */
}

/* Custom scrollbar styling for welcome leaderboard */
#welcome-lb-list::-webkit-scrollbar {
  width: 6px;
}

#welcome-lb-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

#welcome-lb-list::-webkit-scrollbar-thumb {
  background: rgba(139, 203, 255, 0.3);
  border-radius: 3px;
}

#welcome-lb-list::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 203, 255, 0.5);
}

.start-button {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 15px 30px;
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 1.8em;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 30px;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 4px 15px rgba(139, 203, 255, 0.3);
}

.start-button:hover {
  background: #6ba9dc;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 203, 255, 0.4);
}

.start-button:active {
  transform: translateY(0);
}

/* Mobile Touch Controls - Joystick */
.mobile-controls {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 100;
  pointer-events: auto;
}

.mobile-joystick {
  display: flex;
  align-items: center;
  justify-content: center;
}

.joystick-base {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  /* Make joystick more subtle/less apparent */
  background: rgba(15, 19, 24, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: none;
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.joystick-thumb {
  position: absolute;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  /* Softer thumb visuals */
  background: rgba(139, 203, 255, 0.12);
  border: 1px solid rgba(139, 203, 255, 0.35);
  cursor: pointer;
  user-select: none;
  touch-action: none;
  transition: all 0.1s ease;
  backdrop-filter: blur(3px);
}

.joystick-thumb:active {
  background: rgba(139, 203, 255, 0.2);
  border-color: rgba(139, 203, 255, 0.7);
}

/* Show mobile controls on mobile devices */
@media (max-width: 768px) {
  .mobile-controls {
    display: flex !important;
  }
}

/* Also show mobile controls based on touch capability */
@media (pointer: coarse) {
  .mobile-controls {
    display: flex !important;
  }
}

/* Hide mobile controls on desktop */
@media (min-width: 769px) {
  .mobile-controls {
    display: none !important;
  }
}

/* Landscape orientation - smaller joystick for landscape */
@media (max-width: 768px) and (orientation: landscape) {
  /* Keep portrait layout for consistency */
  #hud .title {
    font-size: 14px;
  }
  
  #leaderboard {
    width: 180px;
    max-height: 30vh;
  }
  
  #minimap {
    width: 100px;
    height: 100px;
  }
  
  /* Smaller joystick for landscape */
  .joystick-base {
    width: 100px;
    height: 100px;
  }
  
  .joystick-thumb {
    width: 40px;
    height: 40px;
  }
  
  .mobile-controls {
    bottom: 20px;
    right: 20px;
  }
}

/* Mobile Drawer (use on all devices) */
.mobile-drawer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  display: block;
}

.mobile-drawer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.mobile-drawer-content {
  position: absolute;
  top: 0;
  left: 20px; /* Align with HUD position */
  right: auto;
  width: 400px;
  max-width: calc(100vw - 40px);
  max-height: 70vh;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  transform: translateY(-100%);
  transition: transform 0.3s ease-out;
}

.mobile-drawer.open .mobile-drawer-content {
  transform: translateY(0);
}

.mobile-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.mobile-drawer-header h2 {
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 20px;
  margin: 0;
  color: var(--accent);
  text-shadow: 0 0 8px rgba(139, 203, 255, 0.3);
}

.mobile-drawer-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s ease;
}

.mobile-drawer-close:hover {
  color: var(--fg);
}

.mobile-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.mobile-drawer-leaderboard {
  width: 100%;
}

.mobile-lb-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.mobile-lb-title {
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 20px;
  color: var(--accent-2);
  margin-bottom: 8px;
  text-shadow: 0 0 8px rgba(255, 191, 105, 0.3);
}

.mobile-lb-sub {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 8px;
}

.mobile-lb-score {
  color: var(--accent);
  font-size: 16px;
}

#mobile-lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 200px; /* Limit height to show ~10 items with scrollbar for rest */
  overflow-y: auto;
  padding-right: 4px; /* Space for scrollbar */
}

/* Custom scrollbar styling for mobile leaderboard */
#mobile-lb-list::-webkit-scrollbar {
  width: 6px;
}

#mobile-lb-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

#mobile-lb-list::-webkit-scrollbar-thumb {
  background: rgba(139, 203, 255, 0.3);
  border-radius: 3px;
}

#mobile-lb-list::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 203, 255, 0.5);
}

#mobile-lb-list li {
  color: var(--fg);
  font-size: 12px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  line-height: 1.2;
}

.mobile-drawer-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
}

.mobile-drawer-btn {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
}

.mobile-drawer-btn.restart-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
}

.mobile-drawer-btn.restart-btn:hover {
  background: rgba(139, 203, 255, 0.1);
  transform: translateY(-1px);
}

.mobile-drawer-btn.new-game-btn {
  background: var(--accent-2);
  color: var(--bg);
  border: 1px solid var(--accent-2);
}

.mobile-drawer-btn.new-game-btn:hover {
  background: #e6a85c;
  transform: translateY(-1px);
}

.mobile-drawer-btn:active {
  transform: translateY(0);
}

/* Make title clickable with arrow on all devices */
#mobile-drawer-trigger {
  cursor: pointer;
  user-select: none;
  position: relative;
  pointer-events: auto;
}

#mobile-drawer-trigger:hover {
  color: var(--accent-2);
}

#mobile-drawer-trigger::after {
  content: " ▼";
  font-size: 12px;
  opacity: 0.7;
  margin-left: 8px;
}

/* Portrait orientation optimized - no warning needed */
