@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Metamorphous&family=MedievalSharp&display=swap');
    
body {
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #2c1810 0%, #1a0f0a 50%, #0d0704 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Cinzel', serif;
  color: #fff;
  overflow: hidden;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 80%, rgba(139, 69, 19, 0.3) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(160, 82, 45, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(205, 133, 63, 0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

#gameContainer {
  position: relative;
  background: #0f0f1e;
  border: 3px solid #8B4513;
  border-radius: 10px;
  box-shadow: 0 0 30px rgba(139, 69, 19, 0.5);
}

#mainMenu {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  z-index: 2000;
  border-radius: 0;
  overflow: hidden;
}

#menuBgVideo {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  opacity: 0.8;
}

#menuSidebar {
  position: absolute;
  top: 0;
  right: 0;
  width: 450px;
  height: 100%;
  background: linear-gradient(to left, rgba(13, 7, 4, 0.95), rgba(26, 15, 10, 0.85));
  backdrop-filter: blur(10px);
  border-left: 3px solid #D2691E;
  box-shadow: -5px 0 30px rgba(0, 0, 0, 0.8), inset 10px 0 20px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1;
  padding: 40px;
  box-sizing: border-box;
}

#menuSidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%238B4513' fill-opacity='0.1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
  opacity: 0.5;
}

#mainMenu h1 {
  font-family: 'MedievalSharp', cursive;
  font-size: 2.5em;
  margin: 0 0 10px 0;
  text-shadow: 
    0 0 10px rgba(255, 215, 0, 0.6),
    2px 2px 0 #8B0000,
    4px 4px 0 #000;
  background: linear-gradient(180deg, #FFD700 20%, #FFA500 50%, #B8860B 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titlePulse 4s ease-in-out infinite;
  letter-spacing: 2px;
  text-align: center;
  line-height: 1.1;
  filter: drop-shadow(0 0 5px rgba(255, 215, 0, 0.3));
}

@keyframes titlePulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 5px rgba(255, 215, 0, 0.3)); }
  50% { transform: scale(1.02); filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.6)); }
}

#mainMenu h2 {
  font-family: 'Cinzel', serif;
  font-size: 1.6em;
  color: #E6E6FA;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
  margin: 0 0 40px 0;
  text-align: center;
  font-weight: 600;
  letter-spacing: 4px;
  text-transform: uppercase;
  border-bottom: 2px solid #D2691E;
  padding-bottom: 10px;
  display: inline-block;
}

/* Map Selection */
.map-selection {
  width: 85%;
  margin: 15px 0;
  text-align: center;
}

.map-selection h3 {
  font-family: 'MedievalSharp', cursive;
  color: #D4AF37;
  font-size: 1.1em;
  margin-bottom: 10px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

.map-options {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.map-option {
  background: linear-gradient(to bottom, #3E2723, #1B0F0E);
  border: 2px solid #5D4037;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
}

.map-option:hover {
  border-color: #D4AF37;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.map-option.selected {
  border-color: #FFD700;
  background: linear-gradient(to bottom, #5D4037, #2E1B18);
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.4), inset 0 0 10px rgba(255, 215, 0, 0.1);
}

.map-icon {
  font-size: 1.8em;
  margin-bottom: 4px;
}

.map-name {
  font-family: 'Cinzel', serif;
  font-size: 0.75em;
  color: #BCAAA4;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.map-option.selected .map-name {
  color: #FFD700;
}

.menu-button {
  background: linear-gradient(to bottom, #5D4037, #3E2723);
  border: 2px solid #8D6E63;
  border-top-color: #A1887F;
  border-bottom-color: #281815;
  color: #FFECB3;
  padding: 18px 23px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
  font-size: 1.3em;
  font-family: 'Cinzel', serif;
  margin: 12px 0;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 2px;
  box-shadow: 
    0 4px 6px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.1);
  position: relative;
  overflow: hidden;
  width: 80%;
  max-width: 350px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-button::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity 0.2s;
}

.menu-button:hover {
  background: linear-gradient(to bottom, #6D4C41, #4E342E);
  border-color: #FFD700;
  color: #FFF;
  transform: translateY(-2px);
  box-shadow: 
    0 0 15px rgba(255, 215, 0, 0.3),
    0 6px 10px rgba(0,0,0,0.6);
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

.menu-button:hover::after {
  opacity: 1;
}

.menu-button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.ornament {
  color: #D2691E;
  font-size: 24px;
  margin: 15px 0;
  text-align: center;
  font-family: 'MedievalSharp', cursive;
  opacity: 0.8;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

canvas {
  display: block;
}

/* Game HUD Styles */
#gameHUD {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 15px;
  box-sizing: border-box;
  z-index: 100;
  pointer-events: none; /* Allow clicks to pass through */
  font-family: 'Cinzel', serif;
}

.hud-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  max-width: 1200px;
  margin: 0 auto;
}

/* Stats (Left) */
.hud-stats-container {
  display: flex;
  gap: 15px;
}

.hud-stat {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #8B4513;
  border-radius: 6px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.hud-icon {
  font-size: 1.2em;
  color: #FFD700;
  text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
}

.hud-value {
  color: #fff;
  font-weight: bold;
  font-size: 1.1em;
  text-shadow: 1px 1px 2px #000;
}

/* Bars (Center) */
.hud-bars-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  margin-top: 5px;
}

.hud-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-bar-icon {
  font-size: 1.2em;
  width: 24px;
  text-align: center;
  text-shadow: 0 0 5px rgba(0,0,0,0.8);
}

.heart-icon { color: #DC143C; }
.star-icon { color: #FFD700; }

.hud-bar {
  width: 300px;
  height: 20px;
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid #5D4037;
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.8);
}

.hud-bar-fill {
  height: 100%;
  border-radius: 8px;
  transition: width 0.3s ease;
  position: relative;
}

.hud-bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.3), transparent);
  border-radius: 8px 8px 0 0;
}

.hp-fill {
  background: linear-gradient(90deg, #8B0000, #DC143C);
  box-shadow: 0 0 10px rgba(220, 20, 60, 0.5);
}

.xp-fill {
  background: linear-gradient(90deg, #B8860B, #FFD700);
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.hud-bar-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000, 0 0 4px #000;
  white-space: nowrap;
  z-index: 2;
}

/* Level (Right) */
.hud-level-container {
  display: flex;
  align-items: flex-start;
}

.level-badge {
  background: linear-gradient(135deg, #2c1810, #0d0704);
  border: 2px solid #FFD700;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
  position: relative;
}

.level-badge::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 1px solid rgba(255, 215, 0, 0.3);
  border-radius: 50%;
}

.level-label {
  font-size: 0.7em;
  color: #D2691E;
  margin-bottom: 2px;
}

.level-value {
  font-size: 1.8em;
  font-weight: bold;
  color: #FFD700;
  line-height: 1;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

/* Mobile Responsive HUD */
@media (max-width: 768px) {
  .hud-top-bar {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    grid-template-areas: 
      "level bars"
      "kills bars";
    gap: 8px;
    padding: 10px;
    padding-top: 0px; /* Space for timer */
    width: 100%;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
    position: relative;
  }
  
  /* Break the stats container to position children independently */
  .hud-stats-container {
    display: contents;
  }
  
  /* Kills Stat - Positioned under Level */
  .hud-stats-container .hud-stat:first-child {
    grid-area: kills;
    justify-self: center;
    width: auto;
    padding: 4px 8px;
    font-size: 0.9em;
    position: relative;
    top: 5px;
    right: -268px;
    /* margin-top: -5px; */
  }
  
  /* Timer Stat - Positioned Absolute Top Center */
  .hud-stats-container .hud-stat:last-child {
    position: absolute;
    top: 5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid #FFD700;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
  }
  
  .hud-level-container {
    grid-area: level;
    position: static;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .hud-bars-container {
    grid-area: bars;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding-left: 5px;
  }
  
  .hud-bar {
    width: 100%;
    max-width: 100%;
  }
  
  .level-badge {
    width: 50px;
    height: 50px;
    margin: 0;
  }
  
  .level-label {
    font-size: 0.6em;
    display: block;
  }
  
  .level-value {
    font-size: 1.4em;
  }
}

/* Level Up Menu Styles */
#levelUpMenu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, #1a0f0a 0%, #0d0704 100%);
  border: 2px solid #8B4513;
  border-radius: 12px;
  padding: 30px;
  display: none;
  z-index: 2000;
  text-align: center;
  width: 90%;
  max-width: 500px;
  box-shadow: 
    0 0 50px rgba(0, 0, 0, 0.9),
    inset 0 0 20px rgba(139, 69, 19, 0.2);
  font-family: 'Cinzel', serif;
}

#levelUpMenu::before {
  content: '';
  position: absolute;
  top: -5px;
  left: -5px;
  right: -5px;
  bottom: -5px;
  border: 1px solid #D2691E;
  border-radius: 16px;
  pointer-events: none;
  opacity: 0.5;
}

.levelup-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 25px;
}

.levelup-header h3 {
  font-family: 'MedievalSharp', cursive;
  font-size: 2em;
  margin: 0;
  background: linear-gradient(to bottom, #FFD700, #FFA500);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  letter-spacing: 1px;
}

.ornament-small {
  color: #D2691E;
  font-size: 1.2em;
}

.upgrade-grid {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.upgrade-option {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid #5D4037;
  border-radius: 8px;
  padding: 15px 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 20px;
  position: relative;
  overflow: hidden;
}

.upgrade-option:hover {
  background: linear-gradient(90deg, rgba(139, 69, 19, 0.2), rgba(210, 105, 30, 0.1));
  border-color: #FFD700;
  transform: translateX(5px);
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.upgrade-icon {
  font-size: 2em;
  min-width: 50px;
  height: 50px;
  background: rgba(0,0,0,0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #8B4513;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.upgrade-info {
  text-align: left;
  flex-grow: 1;
}

.upgrade-name {
  color: #FFD700;
  font-weight: bold;
  font-size: 1.1em;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.upgrade-desc {
  color: #ccc;
  font-size: 0.9em;
  line-height: 1.3;
}

.upgrade-select-hint {
  color: #D2691E;
  font-size: 0.8em;
  font-weight: bold;
  opacity: 0;
  transform: translateX(-10px);
  transition: all 0.3s ease;
}

.upgrade-option:hover .upgrade-select-hint {
  opacity: 1;
  transform: translateX(0);
}

/* Star Level Indicators */
.upgrade-stars {
  display: flex;
  gap: 3px;
  margin-top: 6px;
}

.upgrade-stars .star {
  font-size: 1em;
  transition: all 0.2s ease;
}

.upgrade-stars .star.filled {
  color: #FFD700;
  text-shadow: 0 0 5px rgba(255, 215, 0, 0.6);
}

.upgrade-stars .star.empty {
  color: #888888;
  text-shadow: none;
}

/* Ensure text visibility on hover for type-passive (blue background) */
.type-passive.upgrade-option:hover .upgrade-desc,
.type-passive.upgrade-option:hover .upgrade-name {
  color: #fff;
}

.type-weapon.upgrade-option:hover .upgrade-desc {
  color: #fff;
}

.type-upgrade.upgrade-option:hover .upgrade-desc {
  color: #fff;
}

/* Maxed out upgrade styling */
.upgrade-option.upgrade-maxed {
  opacity: 0.6;
  cursor: not-allowed;
  border-color: #4a4a4a;
}

.upgrade-option.upgrade-maxed:hover {
  transform: none;
  box-shadow: none;
  border-color: #4a4a4a;
}

.upgrade-option.upgrade-maxed .upgrade-select-hint {
  color: #888;
  opacity: 1;
  transform: translateX(0);
}

/* Type-specific styling */
.type-weapon .upgrade-name { color: #FF4500; }
.type-passive .upgrade-name { color: #4169E1; }
.type-upgrade .upgrade-name { color: #FFD700; }

/* Mobile Responsive Level Up */
@media (max-width: 480px) {
  #levelUpMenu {
    width: 95%;
    padding: 20px;
  }
  
  .levelup-header h3 {
    font-size: 1.5em;
  }
  
  .upgrade-option {
    padding: 12px;
    gap: 12px;
  }
  
  .upgrade-icon {
    font-size: 1.5em;
    min-width: 40px;
    height: 40px;
  }
  
  .upgrade-name {
    font-size: 1em;
  }
  
  .upgrade-desc {
    font-size: 0.85em;
  }
}
#pauseMenu {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, rgba(42, 24, 16, 0.95) 0%, rgba(26, 15, 10, 0.98) 50%, rgba(13, 7, 4, 0.99) 100%);
  border: 4px solid #8B4513;
  border-radius: 15px;
  padding: 30px;
  display: none;
  z-index: 250;
  text-align: center;
  min-width: 300px;
  box-shadow: 
    0 0 50px rgba(139, 69, 19, 0.8),
    inset 0 0 30px rgba(255, 215, 0, 0.1);
  color: #fff;
  font-family: 'Cinzel', serif;
}

#pauseMenu::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 80%, rgba(139, 69, 19, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(160, 82, 45, 0.15) 0%, transparent 50%);
  border-radius: 11px;
  pointer-events: none;
}

.pause-title {
  font-family: 'MedievalSharp', cursive;
  font-size: 2.2em;
  margin: 0 0 20px 0;
  background: linear-gradient(45deg, #FFD700, #FFA500, #FFD700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 3px 3px 0px #8B4513;
  letter-spacing: 2px;
  position: relative;
  z-index: 1;
}

/* Pause Menu Powerups Display */
.pause-powerups {
  width: 100%;
  margin-bottom: 15px;
}

.pause-powerups h4 {
  font-family: 'MedievalSharp', cursive;
  color: #D4AF37;
  font-size: 1em;
  margin: 0 0 10px 0;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

.powerup-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-height: 120px;
  overflow-y: auto;
}

.powerup-item {
  background: linear-gradient(to bottom, rgba(93, 64, 55, 0.8), rgba(62, 39, 35, 0.9));
  border: 1px solid #8D6E63;
  border-radius: 6px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85em;
}

.powerup-icon {
  font-size: 1.1em;
}

.powerup-name {
  color: #FFECB3;
  font-family: 'Cinzel', serif;
  font-size: 0.8em;
}

.powerup-level {
  color: #FFD700;
  font-weight: bold;
  font-size: 0.85em;
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 4px;
}

.no-powerups {
  color: #888;
  font-style: italic;
  font-size: 0.9em;
  padding: 10px;
}

.pause-button {
  background: linear-gradient(145deg, #8B4513, #A0522D);
  border: 3px solid #D2691E;
  color: #FFD700;
  padding: 15px 25px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1.1em;
  font-family: 'Cinzel', serif;
  margin: 8px;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.4);
  position: relative;
  overflow: hidden;
  min-width: 180px;
  z-index: 1;
}

.pause-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.2), transparent);
  transition: left 0.5s;
}

.pause-button:hover {
  background: linear-gradient(145deg, #A0522D, #CD853F);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.5);
  border-color: #FFD700;
}

.pause-button:hover::before {
  left: 100%;
}

.pause-button:active {
  transform: translateY(0px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.pause-info {
  margin: 15px 0;
  color: #D2691E;
  font-size: 0.9em;
  position: relative;
  z-index: 1;
}

.pause-ornament {
  color: #8B4513;
  font-size: 16px;
  margin: 10px 0;
  position: relative;
  z-index: 1;
}

.upgrade-option {
  background: #2c2c54;
  border: 2px solid #d4af37;
  color: #fff;
  padding: 15px;
  margin: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}

.upgrade-option:hover {
  background: #c49a1361;
  color: #000;
}

#gameOver {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.95);
  border: 3px solid #dc143c;
  border-radius: 15px;
  padding: 30px;
  display: none;
  z-index: 300;
  text-align: center;
}

button {
  background: #d4af37;
  border: none;
  color: #000;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: bold;
  margin: 5px;
}

button:hover {
  background: #ffd700;
}

/* Instructions Modal Styles */
#instructionsModal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  z-index: 3000; /* Higher than everything else */
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(8px);
}

.modal-content {
  background: linear-gradient(135deg, #1a0f0a 0%, #0d0704 100%);
  border: 2px solid #8B4513;
  border-radius: 12px;
  padding: 40px;
  width: 90%;
  max-width: 900px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.9);
  position: relative;
  color: #e0e0e0;
  font-family: 'Cinzel', serif;
}

.modal-content::-webkit-scrollbar {
  width: 8px;
}

.modal-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
}

.modal-content::-webkit-scrollbar-thumb {
  background: #8B4513;
  border-radius: 4px;
}

.modal-header {
  text-align: center;
  margin-bottom: 30px;
  padding-right: 30px; /* Make space for close button */
}

.modal-title {
  font-family: 'MedievalSharp', cursive;
  font-size: 2.8em;
  margin: 0;
  background: linear-gradient(to bottom, #FFD700, #B8860B);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 2px 10px rgba(255, 215, 0, 0.2);
  letter-spacing: 1px;
}

.modal-divider {
  height: 2px;
  background: linear-gradient(90deg, transparent, #8B4513, transparent);
  margin-top: 15px;
  width: 60%;
  margin-left: auto;
  margin-right: auto;
}

.modal-body-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  margin-bottom: 30px;
}

.modal-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.instruction-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(139, 69, 19, 0.3);
  border-radius: 6px;
  padding: 25px;
  box-sizing: border-box;
  /* Removed height: 100% to prevent overflow issues */
}

.card-title {
  color: #D2691E;
  font-size: 1.4em;
  margin-top: 0;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(210, 105, 30, 0.3);
  padding-bottom: 10px;
  font-weight: 600;
}

.instruction-text {
  line-height: 1.6;
  color: #ccc;
  font-size: 1.1em;
}

/* Controls Styling */
.control-grid {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.key-group {
  display: flex;
  gap: 5px;
}

.key {
  background: linear-gradient(to bottom, #4a4a4a, #2a2a2a);
  border: 1px solid #666;
  border-bottom: 3px solid #1a1a1a;
  border-radius: 4px;
  color: #fff;
  font-family: sans-serif;
  font-weight: bold;
  font-size: 0.9em;
  min-width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.control-label {
  color: #aaa;
  font-size: 1.1em;
}

.mobile-hint {
  margin-top: 20px;
  font-size: 0.9em;
  color: #888;
  font-style: italic;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 10px;
}

/* Lists */
.feature-list, .upgrade-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.feature-list li, .upgrade-list li {
  margin-bottom: 12px;
  padding-left: 20px;
  position: relative;
  line-height: 1.5;
  color: #ccc;
}

.feature-list li::before {
  content: '◆';
  color: #D2691E;
  position: absolute;
  left: 0;
  font-size: 0.8em;
  top: 4px;
}

.upgrade-list li::before {
  content: '⚔';
  color: #FFD700;
  position: absolute;
  left: 0;
  font-size: 0.9em;
  top: 2px;
}

.upgrade-name {
  color: #FFD700;
  font-weight: bold;
}

.close-button {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid #8B4513;
  border-radius: 50%;
  color: #D2691E;
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 10;
}

.close-button:hover {
  color: #FFD700;
  background: rgba(139, 69, 19, 0.3);
  border-color: #FFD700;
  transform: scale(1.1);
}

.modal-footer {
  text-align: center;
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.modal-close-btn-large {
  background: linear-gradient(to bottom, #5D4037, #3E2723);
  border: 1px solid #8B4513;
  color: #FFD700;
  padding: 10px 30px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Cinzel', serif;
  font-weight: bold;
  font-size: 1em;
  transition: all 0.2s;
}

.modal-close-btn-large:hover {
  background: linear-gradient(to bottom, #6D4C41, #4E342E);
  border-color: #FFD700;
  transform: translateY(-2px);
}

.footer-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, #333, transparent);
  width: 100%;
  margin-bottom: 10px;
}

.footer-blessing {
  color: #888;
  font-style: italic;
  font-size: 1em;
  margin: 0;
}

/* Responsive */
@media (max-width: 768px) {
  .modal-body-grid {
    grid-template-columns: 1fr;
  }
  
  .modal-content {
    padding: 20px;
    width: 95%;
    max-height: 90vh;
  }
  
  .modal-title {
    font-size: 2em;
  }
  
  .instruction-card {
    padding: 15px;
  }
  
  .close-button {
    top: 10px;
    right: 10px;
  }
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
  #menuSidebar {
    width: 100%;
    background: rgba(13, 7, 4, 0.75);
    border-left: none;
    padding: 10px;
  }

  body {
    padding: 10px;
    box-sizing: border-box;
  }
  
  #gameContainer {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }
  
  #gameCanvas {
    width: 100% !important;
    height: 300px !important;
    position: relative;
    top: 5rem;
  }
  
  #mainMenu h1 {
    font-size: 2.2em;
    margin: 0.1em 0;
  }
  
  #mainMenu h2 {
    font-size: 1.1em;
  }
  
  .menu-button {
    padding: 15px 20px;
    font-size: 1em;
    min-width: 250px;
    margin: 6px;
  }
  
  .modal-content {
    max-width: 95vw;
    max-height: 90vh;
    padding: 20px;
    margin: 10px;
  }
  
  .modal-title {
    font-size: 2em;
  }
  
  #ui {
    font-size: 12px;
  }
  
  #xpBar, #hpBar {
    width: 250px;
  }
}

@media (max-width: 480px) {
  #mainMenu h1 {
    font-size: 1.8em;
  }
  
  .menu-button {
    padding: 12px 16px;
    font-size: 0.9em;
    min-width: 200px;
  }
  
  /* Adjust bars for very small screens if needed, but let grid handle layout */
  .hud-bar {
    height: 16px;
  }
  
  .hud-bar-text {
    font-size: 10px;
  }
}

/* Mobile Virtual Controls */
#mobileControls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 200px;
  pointer-events: none;
  z-index: 150;
  display: none;
}

.mobile-joystick {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, rgba(139, 69, 19, 0.6) 0%, rgba(139, 69, 19, 0.3) 70%, transparent 100%);
  border: 3px solid rgba(210, 105, 30, 0.8);
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  background: linear-gradient(145deg, #D2691E, #8B4513);
  border: 2px solid #FFD700;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 
    0 4px 8px rgba(0, 0, 0, 0.4),
    inset 0 2px 4px rgba(255, 215, 0, 0.3);
  transition: all 0.1s ease;
}

.mobile-actions {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  pointer-events: auto;
}

.mobile-button {
  width: 60px;
  height: 60px;
  background: linear-gradient(145deg, #8B4513, #A0522D);
  border: 3px solid #D2691E;
  border-radius: 50%;
  color: #FFD700;
  font-size: 16px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
  transition: all 0.1s ease;
}

.mobile-button:active {
  transform: scale(0.95);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Show mobile controls only on touch devices */
@media (hover: none) and (pointer: coarse) {
  #mobileControls {
    display: block !important;
  }
}

/* Prevent text selection on touch devices */
@media (hover: none) and (pointer: coarse) {
  * {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
}

/* Fullscreen button and fullscreen canvas behavior */
.fullscreen-btn {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 1500;
  background: rgba(0,0,0,0.5);
  color: #FFD700;
  border: 2px solid rgba(212,105,30,0.9);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.6);
  pointer-events: auto; /* allow clicks */
}
.fullscreen-btn:hover {
  background: rgba(0,0,0,0.7);
  color: #FFFFFF;
}

/* Ensure container/canvas fill the screen in fullscreen mode */
#gameContainer:-webkit-full-screen,
#gameContainer:fullscreen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}

#gameContainer:-webkit-full-screen canvas,
#gameContainer:fullscreen canvas {
  width: 100vw !important;
  height: 100vh !important;
  display: block;
}

/* When in fullscreen remove body overflow to avoid scrollbars */
:-webkit-full-screen-ancestor, :fullscreen-ancestor {
  overflow: hidden;
}