/* --- Google Font Import --- */
@import url('https://fonts.googleapis.com/css2?family=Creepster&family=Cinzel:wght@400;700&family=Roboto+Mono&display=swap');

/* --- CSS Variables for Theme Management (Ice/Frost Theme) --- */
:root {
  --bg-dark: #081118; /* Deep dark blue-black for ice theme */
  --bg-gradient: linear-gradient(135deg, #081118, #112233, #1a2d44); /* Ice-inspired dark gradient */
  
  --primary-accent: #88DDFF; /* Bright ice blue primary */
  --secondary-accent: #FFAA44; /* Warm orange for contrast against ice */
  --ice-blue: #4488FF; /* Bright ice blue */
  --frost-cyan: #88CCFF; /* Pale ice cyan */
  --success-warm: #FFAA00; /* Bright warm orange for success (warm contrast) */
  
  --text-light: #E4F4FF; /* Cool off-white with slight blue tint */
  --text-muted: #99CCDD; /* Cool blue-gray for muted text */
  --text-primary: #CCE4FF; /* Cool light blue for primary text */
  
  --font-display: 'Creepster', cursive; /* Spooky font for titles */
  --font-body: 'Cinzel', serif; /* Elegant, slightly gothic font for body */
  --font-monospace: 'Roboto Mono', monospace; /* For keys/code */
}

/* --- Base & Body Styles --- */
html, body { 
  margin: 0; 
  height: 100%; 
  overflow: hidden; 
  background: var(--bg-dark); 
  font-family: var(--font-body);
  color: var(--text-light);
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="%23E0E0E0"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>') 12 12, auto; /* Subtle custom cursor */
}

/* --- Main Menu Styles --- */
#mainMenu {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-gradient);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

#mainMenu.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-20px); /* Add a slight slide-up effect */
}

.menu-title {
  font-family: var(--font-display);
  font-size: 7rem; /* Slightly larger */
  letter-spacing: 8px; /* More dramatic spacing */
  color: #fff;
  text-shadow: 0 0 15px var(--primary-accent), 0 0 30px var(--frost-cyan), 0 0 60px var(--ice-blue); /* Ice blue and cyan glow */
  margin-bottom: 1.5rem;
  text-align: center;
  animation: ice-shimmer 4s ease-in-out infinite alternate;
}

@keyframes ice-shimmer {
  0%, 19%, 23%, 26%, 54%, 58%, 100% {
    text-shadow:
      0 0 15px var(--primary-accent),
      0 0 30px var(--frost-cyan),
      0 0 60px var(--ice-blue),
      0 0 120px var(--ice-blue),
      0 0 150px var(--frost-cyan);
    opacity: 1;
  }
  20%, 24%, 55% {
    text-shadow: 
      0 0 5px var(--primary-accent),
      0 0 10px var(--frost-cyan);
    opacity: 0.9;
  }
  90% {
    opacity: 1;
    text-shadow:
      0 0 20px var(--primary-accent),
      0 0 40px var(--frost-cyan);
  }
}

.menu-subtitle {
  font-family: var(--font-body);
  font-size: 1.3rem;
  color: var(--text-muted);
  margin-bottom: 4rem;
  text-align: center;
  max-width: 500px;
  line-height: 1.6;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 1.5rem; /* More space between buttons */
  align-items: center;
}

.menu-button {
  padding: 18px 45px; /* Larger buttons */
  font-family: var(--font-body);
  font-weight: 700; /* Bolder text */
  font-size: 1.1rem;
  letter-spacing: 2px;
  color: #fff;
  background: var(--primary-accent);
  border: 2px solid var(--primary-accent); /* Solid border for primary */
  border-radius: 5px; /* Sharper corners */
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 0 20px rgba(136, 221, 255, 0.4); /* Ice blue glow */
  text-transform: uppercase;
}

.menu-button:hover {
  transform: translateY(-8px) scale(1.05); /* More pronounced hover */
  box-shadow: 0 0 30px rgba(136, 221, 255, 0.8), 0 0 5px var(--text-light);
  background: linear-gradient(45deg, var(--primary-accent), var(--frost-cyan)); /* Ice gradient change */
}

.menu-button:active {
  transform: translateY(-3px) scale(0.98);
  box-shadow: 0 0 10px rgba(136, 221, 255, 0.6);
}

.menu-button.secondary {
  background: transparent;
  border: 2px solid var(--secondary-accent); /* Warm orange border */
  color: var(--secondary-accent);
  box-shadow: 0 0 15px rgba(255, 170, 68, 0.3);
}

.menu-button.secondary:hover {
  background: var(--secondary-accent);
  color: var(--bg-dark); /* Dark text on hover */
  box-shadow: 0 0 25px rgba(255, 170, 68, 0.6);
  transform: translateY(-8px) scale(1.05);
}

/* --- Styles for All Overlay Screens (Modals, Game Over, Win) --- */
#instructionsModal, #gameOverScreen, #winScreen, #storyScreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none; 
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1001;
  background: rgba(0, 0, 0, 0.7); /* Darker, more opaque background */
  backdrop-filter: blur(10px); /* More blur */
  -webkit-backdrop-filter: blur(10px); 
  padding: 1.5rem;
  box-sizing: border-box;
}

/* --- Story Screen Styles --- */
.story-content {
  background: rgba(8, 17, 24, 0.98); /* Ice theme dark background */
  border: 2px solid var(--primary-accent); /* Ice blue border */
  border-radius: 8px; /* Sharper corners */
  padding: 3rem;
  max-width: 650px;
  box-shadow: 0 0 40px rgba(136, 221, 255, 0.4), inset 0 0 15px rgba(136, 221, 255, 0.2); /* Ice blue shadows */
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: ice-pulse 4s infinite ease-in-out;
}

@keyframes ice-pulse {
  0%, 100% { border-color: var(--primary-accent); box-shadow: 0 0 40px rgba(136, 221, 255, 0.4), inset 0 0 15px rgba(136, 221, 255, 0.2); }
  50% { border-color: var(--frost-cyan); box-shadow: 0 0 50px rgba(136, 204, 255, 0.6), inset 0 0 20px rgba(136, 204, 255, 0.3); }
}

.story-title {
  font-family: var(--font-display);
  font-size: 2.8rem;
  color: var(--primary-accent);
  margin-bottom: 2rem;
  text-shadow: 0 0 10px rgba(136, 221, 255, 0.6);
  letter-spacing: 2px;
}

.story-text {
  font-family: var(--font-body);
  font-size: 1.15rem;
  line-height: 2; /* More generous line height */
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.story-highlight {
  font-family: var(--font-display); /* Use display font for emphasis */
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin: 2.5rem 0 2rem 0;
  color: var(--ice-blue); /* Ice blue for warning */
  text-shadow: 0 0 10px var(--ice-blue);
  letter-spacing: 1px;
}

/* --- Transition Overlay --- */
#transitionOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 999;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.8); /* Darker transition */
}

.transition-text {
  font-family: var(--font-display);
  font-size: 3rem; /* Larger transition text */
  color: var(--secondary-accent);
  text-align: center;
  text-shadow: 0 0 25px rgba(255, 170, 68, 0.8), 0 0 10px rgba(255, 170, 68, 0.6);
  animation: fadeInOut 4s ease-in-out; /* Longer fade */
  max-width: 90%;
}

@keyframes fadeInOut {
  0%, 100% { opacity: 0; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.05); } /* Slight bounce */
}

.instructions-intro {
  font-style: italic;
  color: var(--secondary-accent);
  margin-bottom: 1.2rem;
  font-weight: 700;
  text-shadow: 0 0 5px rgba(255, 170, 68, 0.3);
}

/* --- Mobile Controls (Slightly re-themed) --- */
#mobileControls {
  display: none; 
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 100;
}

.joystick-container {
  position: absolute;
  pointer-events: all;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#movementJoystick {
  bottom: 50px; /* Slightly higher */
  left: 50px;
}

#touchLookArea {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: all;
  z-index: -1;
}

.joystick-base {
  width: 130px; /* Larger base */
  height: 130px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4); /* Darker background */
  border: 3px solid rgba(136, 221, 255, 0.5); /* Ice blue border */
  position: relative;
  backdrop-filter: blur(8px); /* More blur */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.joystick-stick {
  width: 60px; /* Larger stick */
  height: 60px;
  border-radius: 50%;
  background: rgba(136, 221, 255, 0.7); /* Ice blue stick */
  border: 2px solid var(--primary-accent);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: background 0.1s, box-shadow 0.1s;
  box-shadow: 0 2px 12px rgba(136, 221, 255, 0.6);
}

.joystick-stick.active {
  background: rgba(136, 221, 255, 1);
  box-shadow: 0 2px 20px rgba(136, 221, 255, 0.9);
}

.joystick-label {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-body);
  font-size: 1rem; /* Slightly larger label */
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
}

/* Show mobile controls on touch devices or small screens */
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
  #mobileControls.enabled {
    display: block;
  }
}

/* --- Instructions Modal Content --- */
.instructions-content {
  background: rgba(8, 17, 24, 0.95); /* Ice theme dark background */
  border: 1px solid var(--primary-accent); /* Ice blue border */
  border-radius: 10px;
  padding: 2.5rem;
  width: 100%;
  max-width: 700px; /* Wider modal */
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 0 30px rgba(136, 221, 255, 0.3);
  color: var(--text-light);
}

.instructions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  border-bottom: 1px dashed rgba(255, 170, 68, 0.3); /* Dashed separator */
  padding-bottom: 1rem;
}

.instructions-title {
  font-family: var(--font-display);
  font-size: 3rem;
  letter-spacing: 3px;
  color: var(--primary-accent);
  margin: 0;
  text-shadow: 0 0 10px rgba(136, 221, 255, 0.5);
}

.close-button {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 3rem; /* Larger close button */
  line-height: 1;
  cursor: pointer;
  transition: all 0.3s ease;
}

.close-button:hover {
  color: var(--ice-blue); /* Ice blue on hover */
  transform: rotate(90deg) scale(1.1);
}

.instructions-section {
  margin-bottom: 2rem;
}

.instructions-section h3 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  letter-spacing: 1.5px;
  color: var(--secondary-accent); /* Warm orange for section titles */
  margin-bottom: 0.8rem;
  border-bottom: 1px solid rgba(255, 170, 68, 0.4);
  padding-bottom: 0.5rem;
  text-shadow: 0 0 8px rgba(255, 170, 68, 0.3);
}

.instructions-section ul {
  line-height: 2;
  padding-left: 1.5rem;
  margin: 0;
  list-style-type: '❄️ '; /* Ice/snowflake list markers */
  color: var(--text-light);
}

.instructions-section li {
  margin-bottom: 0.7rem;
}

.instructions-section p {
  color: var(--text-muted);
  line-height: 1.8;
}

.key {
  background: rgba(0, 0, 0, 0.5);
  color: var(--secondary-accent);
  padding: 5px 12px;
  border-radius: 3px;
  font-family: var(--font-monospace); /* Monospace for keys */
  font-size: 0.95rem;
  font-weight: bold;
  border: 1px solid rgba(136, 221, 255, 0.5);
  margin: 0 3px;
  box-shadow: inset 0 0 5px rgba(136, 221, 255, 0.2);
}

/* --- Game UI (HUD) Styles --- */
#gameUI {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
  font-family: var(--font-monospace); /* Monospace for HUD */
}

#info { 
  position: absolute; 
  bottom: 15px; 
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.4); 
  font-family: var(--font-monospace); 
  font-size: 13px;
}

#gameStats {
  position: absolute;
  top: 25px;
  right: 25px;
  font-family: var(--font-monospace);
  font-size: 1.3rem; /* Larger stats */
  font-weight: 600;
  background: rgba(8, 17, 24, 0.8); /* Ice theme dark background */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 12px 25px;
  border-radius: 10px;
  border: 1px solid rgba(255, 170, 68, 0.4); /* Warm orange border */
  display: flex;
  gap: 25px;
  box-shadow: 0 0 15px rgba(255, 170, 68, 0.2);
}
#collectibleStat, #timeStat {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--secondary-accent);
}
#collectibleStat::before { content: '❄️'; /* Ice crystal icon */ margin-right: 5px; }
#timeStat::before { content: '⏰'; /* Clock icon */ margin-right: 5px; }


/* --- Distance Meter --- */
#distanceMeter {
  position: absolute;
  top: 100px;
  right: 25px;
  font-family: var(--font-monospace);
  font-size: 1.1rem;
  font-weight: 700;
  background: rgba(8, 17, 24, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 12px 20px;
  border-radius: 10px;
  border: 1px solid var(--ice-blue); /* Ice blue border for danger */
  min-width: 140px;
  text-align: center;
  box-shadow: 0 0 20px rgba(68, 136, 255, 0.3);
}

.distance-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.distance-value {
  font-size: 1.8rem; /* Larger value */
  color: var(--ice-blue);
  text-shadow: 0 0 15px rgba(68, 136, 255, 0.8);
  animation: ice-danger 1.5s infinite ease-in-out alternate;
}

@keyframes ice-danger {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.08); text-shadow: 0 0 20px rgba(68, 136, 255, 1); }
}

/* --- Minimap --- */
#minimapContainer {
  position: absolute;
  bottom: 25px;
  right: 25px;
  background: rgba(8, 17, 24, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 170, 68, 0.4);
  box-shadow: 0 0 15px rgba(255, 170, 68, 0.2);
}

.minimap-label {
  font-family: var(--font-monospace);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 8px;
  text-align: center;
}

#minimap {
  display: block;
  border-radius: 6px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 1px solid rgba(255, 170, 68, 0.6);
}


/* --- Game Over & Win Screen Content Styles --- */
.game-over-title, .win-title {
  font-family: var(--font-display);
  font-size: 6rem; /* Larger */
  letter-spacing: 4px;
  margin-bottom: 1.5rem;
  text-align: center;
}

.game-over-title {
  color: var(--ice-blue);
  text-shadow: 0 0 30px var(--ice-blue), 0 0 10px rgba(68, 136, 255, 0.5);
  animation: ice-shake 0.8s ease-in-out infinite alternate;
}

@keyframes ice-shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-5px) translateY(-2px); }
  50% { transform: translateX(5px) translateY(2px); }
  75% { transform: translateX(-3px) translateY(1px); }
  100% { transform: translateX(0); }
}

.win-title {
  color: var(--success-warm); /* Bright success orange */
  text-shadow: 0 0 30px var(--success-warm), 0 0 10px rgba(255, 170, 0, 0.5);
  animation: win-glow 2s ease-in-out infinite alternate;
}

@keyframes win-glow {
  0%, 100% { text-shadow: 0 0 30px var(--success-warm); }
  50% { text-shadow: 0 0 45px var(--success-warm), 0 0 15px rgba(255, 170, 0, 0.8); }
}

.final-stats {
  font-size: 1.3rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.5);
  padding: 2rem 3rem;
  border-radius: 10px;
  margin-bottom: 3rem;
  border: 1px solid var(--primary-accent);
  box-shadow: 0 0 25px rgba(136, 221, 255, 0.3);
}
.final-stats p {
  margin-top: 0;
  color: var(--text-muted);
  line-height: 1.8;
}
.stat-item {
  margin-top: 1rem;
  color: var(--secondary-accent);
  font-weight: 700;
}
.stat-item span {
    color: var(--text-light);
    font-family: var(--font-monospace);
    letter-spacing: 1px;
}


/* --- Responsive Design --- */
@media (max-width: 768px) {
  .menu-title {
    font-size: 3.5rem;
    letter-spacing: 4px;
  }
  .menu-subtitle {
    font-size: 1rem;
    margin-bottom: 2rem;
  }
  .menu-button {
    padding: 12px 30px;
    font-size: 0.9rem;
  }
  .game-over-title, .win-title {
    font-size: 3rem;
  }
  .instructions-content {
    padding: 1.5rem;
    max-width: 95%;
  }
  .instructions-title {
    font-size: 2rem;
  }
  .instructions-section h3 {
    font-size: 1.3rem;
  }
  .close-button {
    font-size: 2rem;
  }
  #gameStats {
    top: 15px;
    right: 15px;
    font-size: 1rem;
    padding: 10px 15px;
    gap: 15px;
  }
  #distanceMeter {
    top: 80px;
    right: 15px;
    font-size: 0.9rem;
    padding: 8px 12px;
    min-width: 100px;
  }
  .distance-value {
    font-size: 1.2rem;
  }
  #minimapContainer {
    bottom: 15px;
    right: 15px;
    padding: 8px;
  }
  #minimap {
    width: 120px;
    height: 120px;
  }
  .final-stats {
    font-size: 1rem;
    padding: 1.5rem 1.5rem;
  }
  #movementJoystick {
    bottom: 20px;
    left: 20px;
  }
  .joystick-base {
    width: 100px;
    height: 100px;
  }
  .joystick-stick {
    width: 40px;
    height: 40px;
  }
  .joystick-label {
    font-size: 0.8rem;
    bottom: -20px;
  }
}

/* Scrollbar styling for instructions modal */
.instructions-content::-webkit-scrollbar {
  width: 8px;
}

.instructions-content::-webkit-scrollbar-track {
  background: var(--bg-dark);
  border-radius: 10px;
}

.instructions-content::-webkit-scrollbar-thumb {
  background: var(--primary-accent);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2);
}

.instructions-content::-webkit-scrollbar-thumb:hover {
  background: darken(var(--primary-accent), 10%);
}