Further enhance and add in some fixes and implement in unused features and refine the code ENTIRELY.

```
<html><head><base href=".">
<title>The HARDCORE PASSWORD 💀 GAME</title>
<meta charset="UTF-8">
<style>
:root {
  --bg-gradient: linear-gradient(135deg, #1a1a1a, #2d2d2d);
  --neon-green: #39ff14;
  --neon-red: #ff1461;
  --neon-blue: #14f0ff;
  --neon-purple: #b537f2;
  --terminal-bg: #000;
  --terminal-color: #39ff14;
  --instructor-bg: rgba(255, 255, 255, 0.1);
  --instructor-color: #ff1461;
  --notification-success: green;
  --notification-error: red;
}

/* Game Menu Screen */
.menu-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, #000, #1a0038);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.game-title {
  font-size: 4em;
  font-family: 'Courier New', monospace;
  color: var(--neon-purple);
  text-shadow: 0 0 10px var(--neon-purple),
               0 0 20px var(--neon-purple),
               0 0 30px var(--neon-purple);
  animation: pulseTitle 2s infinite;
  text-align: center;
  margin-bottom: 40px;
}

.start-button {
  padding: 20px 40px;
  font-size: 24px;
  background: transparent;
  border: 2px solid var(--neon-green);
  color: var(--neon-green);
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: 'Courier New', monospace;
  text-transform: uppercase;
  letter-spacing: 3px;
  position: relative;
  overflow: hidden;
  margin-bottom: 10px;
}

.start-button:hover {
  background: var(--neon-green);
  color: #000;
  transform: scale(1.1);
  box-shadow: 0 0 20px var(--neon-green);
}

.start-button:before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    120deg,
    transparent,
    rgba(57, 255, 20, 0.4),
    transparent
  );
  transition: 0.5s;
}

.start-button:hover:before {
  left: 100%;
}

@keyframes pulseTitle {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

body {
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  font-family: 'Courier New', monospace;
  background: var(--bg-gradient);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Enhanced Game Over Screen */
.game-over {
  color: var(--neon-red);
  font-size: 72px;
  text-align: center;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.95);
  display: none;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 999;
  animation: gameOverPulse 2s infinite;
}

.retry-button {
  margin-top: 30px;
  padding: 15px 30px;
  font-size: 24px;
  background: transparent;
  border: 2px solid var(--neon-red);
  color: var(--neon-red);
  cursor: pointer;
  transition: all 0.3s ease;
}

.retry-button:hover {
  background: var(--neon-red);
  color: #000;
  transform: scale(1.1);
}

@keyframes gameOverPulse {
  0% { text-shadow: 0 0 10px var(--neon-red); }
  50% { text-shadow: 0 0 30px var(--neon-red), 0 0 60px var(--neon-red); }
  100% { text-shadow: 0 0 10px var(--neon-red); }
}

/* Password Input */
.password-input {
  width: 100%;
  padding: 15px;
  background: #333;
  border: 2px solid var(--neon-green);
  color: var(--neon-green);
  font-size: 18px;
  margin-bottom: 20px;
  border-radius: 5px;
}

.password-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Requirements List */
.requirements {
  list-style: none;
  padding: 0;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}

.requirement {
  margin: 15px 0;
  padding: 15px;
  border: 2px solid #444;
  border-radius: 8px;
  background: rgba(0,0,0,0.3);
  font-weight: bold;
  text-shadow: 0 0 5px currentColor;
  transition: all 0.5s ease;
  opacity: 1;
}

.requirement.met {
  border-color: var(--neon-green);
  background: rgba(57, 255, 20, 0.15);
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.3);
}

.requirement.failed {
  border-color: var(--neon-red);
  background: rgba(255, 20, 97, 0.15);
  box-shadow: 0 0 10px rgba(255, 20, 97, 0.3);
}

.requirement.fading {
  opacity: 0;
  transform: translateY(-10px);
}

.requirement.new {
  animation: slideIn 0.5s ease forwards;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Level Display */
.level {
  font-size: 24px;
  color: var(--neon-green);
  margin-bottom: 20px;
  text-align: center;
}

/* Timer */
.timer {
  font-size: 32px;
  color: var(--neon-red);
  margin-bottom: 20px;
  font-family: 'Digital-7', monospace;
}

/* CAPTCHA Container */
.captcha-container {
  background: rgba(255,255,255,0.1);
  padding: 20px;
  border-radius: 10px;
  border: 2px solid var(--neon-blue);
  display: none;
  justify-content: center;
  margin: 20px 0;
}

.crypto-challenge {
  display: none;
}

/* Shake Animation */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-2deg); }
  75% { transform: translateX(5px) rotate(2deg); }
}

.shake {
  animation: shake 0.2s ease-in-out 3;
}

/* Smooth Transition Animations */
.fade-out {
  animation: fadeOut 1s forwards;
}

.fade-in {
  animation: fadeIn 1s forwards;
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Victory Screen */
.victory-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1001;
}

.victory-content {
  text-align: center;
  color: var(--neon-green);
  background: rgba(0, 0, 0, 0.8);
  padding: 40px;
  border-radius: 10px;
  border: 2px solid var(--neon-green);
  box-shadow: 0 0 30px var(--neon-green);
  font-size: 24px;
}

.home-button {
  margin-top: 30px;
  padding: 15px 30px;
  font-size: 24px;
  background: transparent;
  border: 2px solid var(--neon-blue);
  color: var(--neon-blue);
  cursor: pointer;
  transition: transform 0.3s ease;
}

.home-button:hover {
  background: var(--neon-blue);
  color: #fff;
  transform: scale(1.05);
}

/* Penalty Flash Style */
.penalty-flash {
  animation: penaltyFlash 0.5s ease;
}

@keyframes penaltyFlash {
  0% { background: var(--bg-gradient); }
  50% { background: rgba(255, 20, 97, 0.3); }
  100% { background: var(--bg-gradient); }
}

/* Container */
.container {
  opacity: 0;
  transition: opacity 1s ease;
  width: 100%;
  max-width: 600px;
}

.container.fade-in {
  opacity: 1;
}

/* Event Notification Styles */
.event-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 20px;
  border-radius: 10px;
  color: white;
  z-index: 1000;
  animation: slideIn 0.5s ease, fadeOut 0.5s ease 4.5s forwards;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
  background-color: var(--notification-success);
}

.event-notification.success {
  background-color: var(--notification-success);
}

.event-notification.error {
  background-color: var(--notification-error);
}

.event-notification h3 {
  margin: 0 0 10px 0;
  font-size: 1.2em;
}

.event-notification p {
  margin: 0;
  font-size: 0.9em;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

/* How to Play Button */
.how-to-play-button {
  position: fixed;
  top: 20px;
  right: 80px;
  padding: 10px 20px;
  font-size: 16px;
  background: transparent;
  border: 2px solid var(--neon-blue);
  color: var(--neon-blue);
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 1002;
}

.how-to-play-button:hover {
  background: var(--neon-blue);
  color: #000;
  transform: scale(1.05);
}

/* How to Play Window */
.how-to-play-window {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  max-width: 800px;
  max-height: 80vh;
  background: rgba(0, 0, 0, 0.95);
  border: 2px solid var(--neon-purple);
  border-radius: 10px;
  padding: 20px;
  z-index: 1003;
  overflow-y: auto;
  box-shadow: 0 0 30px var(--neon-purple);
  font-family: 'Courier New', monospace;
}

.how-to-play-window h2 {
  color: var(--neon-purple);
  text-align: center;
  margin-bottom: 20px;
}

.how-to-play-window .section {
  margin-bottom: 20px;
  padding: 15px;
  border: 1px solid var(--neon-green);
  border-radius: 5px;
}

.how-to-play-window .section h3 {
  color: var(--neon-green);
  margin-bottom: 10px;
}

.how-to-play-window .section p {
  color: #fff;
  line-height: 1.6;
}

.how-to-play-window .joke {
  font-style: italic;
  color: var(--neon-blue);
  margin: 10px 0;
  padding: 10px;
  background: rgba(20, 240, 255, 0.1);
  border-radius: 5px;
}

.close-how-to-play {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--neon-red);
  font-size: 24px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.close-how-to-play:hover {
  transform: scale(1.2);
}

/* Overlay */
.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1002;
  animation: fadeIn 1s forwards;
}

/* Instructor Styles */
.instructor {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: rgba(0, 0, 0, 0.9) !important;
  color: var(--instructor-color);
  padding: 20px !important;
  border-radius: 8px;
  max-width: 400px !important;
  font-size: 18px !important;
  box-shadow: 0 0 10px var(--instructor-color);
  z-index: 1004;
  text-shadow: 0 0 10px var(--neon-purple);
  display: none;
}

.instructor.visible {
  display: block;
  animation: fadeIn 0.5s forwards;
}

.instructor.hide {
  animation: fadeOut 0.5s forwards;
}

/* Terminal Styles */
.terminal-button {
  position: fixed;
  top: 20px;
  left: 20px;
  padding: 10px 20px;
  font-size: 16px;
  background: transparent;
  border: 2px solid var(--neon-blue);
  color: var(--neon-blue);
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 1002;
  display: none;
}

.terminal-button:hover {
  background: var(--neon-blue);
  color: #fff;
  transform: scale(1.05);
}

.terminal-window {
  position: fixed;
  bottom: 20px;
  left: -500px; /* Move it off-screen */
  width: 400px;
  max-width: 90%;
  background: var(--terminal-bg);
  color: var(--terminal-color);
  border: 2px solid var(--neon-blue);
  border-radius: 8px;
  padding: 10px;
  font-family: 'Courier New', monospace;
  box-shadow: 0 0 20px var(--neon-blue);
  z-index: 1005;
  display: flex;
  flex-direction: column;
  transition: left 0.5s ease;
}

.terminal-window.visible {
  left: 20px;
}

.terminal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  margin-bottom: 10px;
}

.terminal-header button {
  background: transparent;
  border: none;
  color: var(--neon-red);
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.terminal-header button:hover {
  transform: scale(1.2);
}

.terminal-content {
  flex: 1;
  background: #111;
  padding: 10px;
  border-radius: 5px;
  height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.terminal-input {
  width: 100%;
  padding: 8px;
  background: #222;
  border: 1px solid var(--neon-green);
  color: var(--neon-green);
  font-size: 16px;
  border-radius: 4px;

/* Matrix Mode */
.matrix-mode {
  background: #000;
  color: #00ff00;
  text-shadow: 0 0 10px #00ff00;
  font-family: 'Matrix Code NFI', 'Courier New', monospace;
}

/* New styles */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-2deg); }
  75% { transform: translateX(5px) rotate(2deg); }
}

/* Remove budget display styles */
.budget-display {
  display: none;
}

/* Add new styles */
.game-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.9);
  padding: 20px;
  border-radius: 10px;
  display: none;
  z-index: 1000;
}

.notes-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.note {
  width: 60px;
  height: 60px;
  background: var(--neon-purple);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.note:active {
  transform: scale(0.95);
}

.step-indicator {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
}

.step {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
}

.step.active {
  background: var(--neon-green);
}

/* Password History Styles */
.password-history {
  margin: 20px 0;
  padding: 15px;
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--neon-purple);
  border-radius: 8px;
}

.password-history h3 {
  color: var(--neon-purple);
  margin: 0 0 10px 0;
}

.password-history-entry {
  margin: 5px 0;
  padding: 5px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.previous-password {
  color: var(--neon-green);
  font-family: monospace;
  padding: 2px 5px;
  background: rgba(0,0,0,0.2);
  border-radius: 3px;
}
</style>
<script src="https://www.google.com/recaptcha/api.js?onload=onRecaptchaLoad&amp;render=explicit" async="" defer=""></script>
<script>
// Define constants
const PENALTY_TIME = 10; // 10 seconds penalty per failed attempt
const MAX_PENALTIES = 5; // Maximum number of penalties before game over
const TOTAL_SECRETS = 3;

// Declare top-level variables with let
let terminalToggleState = false;
let isTimeFrozen = false;
let activeEvent = null;
let eventTimeout = null;
let currentLevel = 0;
let timeLeft = 600; // 10 minutes
let penalties = 0;
let timerInterval;
let installDate = null;
let achievements = {
  speedrunner: false, // Complete level 1 in under 30 seconds
  hackerman: false,   // Use the terminal 10 times
  secretFinder: false, // Find all hidden secrets
  masochist: false,   // Get penalized 3 times but still complete a level
  terminalGuru: false // Use all terminal commands
};
let terminalUseCount = 0;
let secretsFound = 0;
let captchaRequired = false;
let captchaVerified = false;
let passwordHistory = []; // Add password history tracking

// For DOM element references, let's declare them at the top level
let passwordInput;
let requirementsList;
let levelDisplay;
let timerDisplay;
let gameOverDisplay;
let victoryScreen;
let instructorElement;
let overlay;
let howToPlayWindow;

// Define random events
const RANDOM_EVENTS = {
  timeFreeze: {
    name: 'Time Freeze',
    description: 'Time has frozen for 30 seconds!',
    handler: () => {
      isTimeFrozen = true;
      showInstructorMessage('❄️ Time Freeze activated! You have 30 seconds of frozen time.');
      setTimeout(() => {
        isTimeFrozen = false;
        showInstructorMessage('⏰ Time Freeze deactivated! The clock is ticking again...');
      }, 30000);
    }
  },
  requirementReversal: {
    name: 'Requirement Reversal',
    description: 'Requirements are temporarily reversed!',
    handler: () => {
      const requirements = document.querySelectorAll('.requirement');
      requirements.forEach(req => {
        req.classList.toggle('met');
        req.classList.toggle('failed');
      });
      showInstructorMessage('🔄 Requirements reversed for 10 seconds!');
      setTimeout(() => {
        requirements.forEach(req => {
          req.classList.toggle('met');
          req.classList.toggle('failed');
        });
        showInstructorMessage('Requirements back to normal!');
      }, 10000);
    }
  },
  bonusTime: {
    name: 'Bonus Time',
    description: 'You gained 30 seconds!',
    handler: () => {
      timeLeft += 30;
      updateTimerDisplay();
      showInstructorMessage('⌛ Lucky you! Got 30 seconds bonus time!');
    }
  },
  matrixMode: {
    name: 'Matrix Mode',
    description: 'Enter the Matrix!',
    handler: () => {
      document.body.classList.add('matrix-mode');
      showInstructorMessage('🕶️ Welcome to the Matrix! Everything is code now...');
      setTimeout(() => {
        document.body.classList.remove('matrix-mode');
        showInstructorMessage('Matrix mode deactivated.');
      }, 15000);
    }
  },
  captchaChallenge: {
    name: 'CAPTCHA Challenge',
    description: 'Prove you\'re not a robot!',
    handler: () => {
      captchaRequired = true;
      const captchaContainer = document.getElementById('captchaContainer');
      if (captchaContainer) {
        captchaContainer.style.display = 'flex';
        showInstructorMessage('🤖 CAPTCHA check required! Prove you\'re human.');
      }
    }
  }
};

// Function to trigger random events
function triggerRandomEvent() {
  // Don't trigger events if game is over or victory achieved
  if (timeLeft <= 0 || currentLevel >= levels.length) return;

  const events = Object.values(RANDOM_EVENTS);
  const randomEvent = events[Math.floor(Math.random() * events.length)];

  // Don't stack same event
  if (activeEvent === randomEvent.name) return;

  activeEvent = randomEvent.name;

  // Create and show notification
  const notification = document.createElement('div');
  notification.className = 'event-notification';
  notification.innerHTML = `
    <h3>${randomEvent.name}</h3>
    <p>${randomEvent.description}</p>
  `;
  document.body.appendChild(notification);

  // Remove notification after animation
  setTimeout(() => {
    notification.remove();
  }, 5000);

  // Execute event handler
  randomEvent.handler();

  // Clear active event after delay
  setTimeout(() => {
    activeEvent = null;
  }, 5000);
}

// Define the game levels and their requirements
const levels = [
  {
    level: 1,
    title: "Password 101: The Beginning of Pain",
    requirements: [
      {
        description: "Must contain at least 8 characters but no more than 12",
        test: (password) => password.length >= 8 && password.length <= 12
      },
      {
        description: "Must include a number that when multiplied by 3 equals 21",
        test: (password) => /7/.test(password)
      },
      {
        description: "Must include a happy emoji (😊 😃 😄 😁)",
        test: (password) => /[😊😃😄😁]/.test(password)
      },
      {
        description: "Must start with an uppercase letter that's not A, E, I, O, U",
        test: (password) => /^[BCDFGHJKLMNPQRSTVWXYZ]/.test(password)
      }
    ]
  },
  {
    level: 2,
    title: "The Matrix Reloaded",
    requirements: [
      {
        description: "Must contain binary code that equals 42 when converted to decimal (101010)",
        test: (password) => password.includes('101010')
      },
      {
        description: "Must include a mini ASCII art cat (=^..^=)",
        test: (password) => password.includes('=^..^=')
      },
      {
        description: "Must contain a palindrome at least 3 characters long",
        test: (password) => {
          const matches = password.match(/(.+)/g) || [];
          return matches.some(str => {
            str = str.toLowerCase();
            return str.length >= 3 && str === str.split('').reverse().join('');
          });
        }
      },
      {
        description: "Must include '123' for extra security",
        test: (password) => password.includes('123'),
        isTrap: true
      }
    ]
  },
  {
    level: 3,
    title: "Quantum Cryptography",
    requirements: [
      {
        description: "Must contain the Schrödinger equation (ℏ∂ψ/∂t)",
        test: (password) => password.includes('ℏ∂ψ/∂t')
      },
      {
        description: "Must include π to 3 decimal places",
        test: (password) => password.includes('3.142')
      },
      {
        description: "Must contain at least one character from the Elder Futhark runic alphabet (ᚠᚢᚦᚨᚱᚲ)",
        test: (password) => /[ᚠᚢᚦᚨᚱᚲ]/.test(password)
      },
      {
        description: "Must have 'password' in it (reverse psychology!)",
        test: (password) => password.toLowerCase().includes('password'),
        isTrap: true
      }
    ]
  },
  {
    level: 4,
    title: "The Cosmic Challenge",
    requirements: [
      {
        description: "Must include the chemical formula for caffeine (C₈H₁₀N₄O₂)",
        test: (password) => password.includes('C₈H₁₀N₄O₂')
      },
      {
        description: "Must contain a tiny castle emoji between two guards (👮🏰👮)",
        test: (password) => password.includes('👮🏰👮')
      },
      {
        description: "Must include a Fibonacci sequence of at least 4 numbers",
        test: (password) => /[0-9]+[,\s]+[0-9]+[,\s]+[0-9]+[,\s]+[0-9]+/.test(password) &&
          password.match(/[0-9]+[,\s]+[0-9]+[,\s]+[0-9]+[,\s]+[0-9]+/)[0].split(/[,\s]+/).every((num, i, arr) => {
            if (i < 2) return true;
            return parseInt(num) === parseInt(arr[i-1]) + parseInt(arr[i-2]);
          })
      },
      {
        description: "Must include '!' at the start for emphasis",
        test: (password) => password.startsWith('!'),
        isTrap: true
      }
    ]
  },
  {
    level: 5,
    title: "The Final Ascension",
    isFinalPhase: true,
    requirements: [
      {
        description: "Choose your destiny: Only one password variation is correct!",
        test: (password) => password === generateCorrectFinalPassword()
      }
    ]
  },
  {
    level: 6,
    title: "Snake Password Challenge",
    requirements: [
      {
        description: "Complete Snake Game with score 75+ to enable password input",
        test: (password) => window.snakeGameScore >= 75
      },
      {
        description: "Password must contain your final snake length",
        test: (password) => password.includes(window.snakeLength.toString())
      }
    ],
    specialChallenge: 'snake'
  },
  {
    level: 7, 
    title: "Musical Password",
    requirements: [
      {
        description: "Complete the rhythm sequence correctly",
        test: (password) => window.rhythmComplete
      },
      {
        description: "Password must contain the musical note sequence you played",
        test: (password) => {
          const notes = ['do','re','mi','fa','sol','la','si'];
          return notes.some(note => password.includes(note));
        }
      }
    ],
    specialChallenge: 'rhythm'
  },
  {
    level: 8,
    title: "Palindromic Perfection",
    requirements: [
      {
        description: "Must be a perfect palindrome in both letters and special characters (e.g. @#A1bB1A#@)",
        test: (password) => {
          return password === password.split('').reverse().join('');
        }
      }
    ]
  },
  {
    level: 9,
    title: "Mathematical Mind Games",
    requirements: [
      {
        description: "Must contain a valid mathematical equation (e.g. x^2+3x=0)",
        test: (password) => /[a-z]\^?\d+[\+\-\*\/][a-z\d]+\=\d+/.test(password)
      }
    ]
  },
  {
    level: 10, 
    title: "Emotional Rollercoaster",
    requirements: [
      {
        description: "Must contain opposing emotional words (e.g. happy/sad, love/hate)",
        test: (password) => {
          const emotionalPairs = [
            ['happy', 'sad'],
            ['love', 'hate'],
            ['joy', 'sorrow'],
            ['laugh', 'cry']
          ];
          return emotionalPairs.some(pair => 
            password.toLowerCase().includes(pair[0]) && 
            password.toLowerCase().includes(pair[1])
          );
        }
      }
    ]
  },
  {
    level: 11,
    title: "Shakespeare's Revenge",
    requirements: [
      {
        description: "Must encode a Shakespeare quote (e.g. 'T0b3_Or_N0t_2b3')",
        test: (password) => {
          const shakespeareEncoded = [
            'T0b3_Or_N0t_2b3',
            'R0m30_R0m30',
            'Wh3r3_4rt_Th0u',
            'F00l_M0rt4l'
          ];
          return shakespeareEncoded.some(quote => 
            password.includes(quote)
          );
        }
      }
    ]
  },
  {
    level: 12,
    title: "Temporal Encryption",
    requirements: [
      {
        description: "Must include current timestamp in base-36 (e.g. 2024-11-23_XY:ZZ)",
        test: (password) => {
          const now = new Date();
          const hour = now.getHours().toString(36);
          const minute = now.getMinutes().toString(36);
          const dateStr = `${now.getFullYear()}-${String(now.getMonth()+1).padStart(2,'0')}-${String(now.getDate()).padStart(2,'0')}`;
          const timeStr = `${hour}:${minute}`;
          return password.includes(`${dateStr}_${timeStr}`);
        }
      }
    ]
  },
  {
    level: 13,
    title: "Reverse Keyboard Challenge",
    requirements: [
      {
        description: "Characters must correspond to opposite side of keyboard (q->p, a->;)",
        test: (password) => {
          const keyboardMap = {
            'q':'p', 'w':'o', 'e':'i', 'r':'u', 't':'y',
            'a':';', 's':'l', 'd':'k', 'f':'j', 'g':'h',
            'z':'/', 'x':'.', 'c':',', 'v':'m', 'b':'n'
          };
          return password.split('').every(char => 
            Object.values(keyboardMap).includes(char.toLowerCase())
          );
        }
      }
    ]
  },
  {
    level: 14,
    title: "Prime Position Power",
    requirements: [
      {
        description: "Only use characters from prime-numbered keyboard positions",
        test: (password) => {
          const primePositionChars = '23579cgkquy';
          return password.split('').every(char => 
            primePositionChars.includes(char.toLowerCase())
          );
        }
      }
    ]
  }
];

// Extend the existing levels array with new levels
levels.push(
  {
    level: 8,
    title: "Palindromic Perfection",
    requirements: [
      {
        description: "Must be a perfect palindrome in both letters and special characters (e.g. @#A1bB1A#@)",
        test: (password) => {
          return password === password.split('').reverse().join('');
        }
      }
    ]
  },
  {
    level: 9,
    title: "Mathematical Mind Games",
    requirements: [
      {
        description: "Must contain a valid mathematical equation (e.g. x^2+3x=0)",
        test: (password) => /[a-z]\^?\d+[\+\-\*\/][a-z\d]+\=\d+/.test(password)
      }
    ]
  },
  {
    level: 10, 
    title: "Emotional Rollercoaster",
    requirements: [
      {
        description: "Must contain opposing emotional words (e.g. happy/sad, love/hate)",
        test: (password) => {
          const emotionalPairs = [
            ['happy', 'sad'],
            ['love', 'hate'],
            ['joy', 'sorrow'],
            ['laugh', 'cry']
          ];
          return emotionalPairs.some(pair => 
            password.toLowerCase().includes(pair[0]) && 
            password.toLowerCase().includes(pair[1])
          );
        }
      }
    ]
  },
  {
    level: 11,
    title: "Shakespeare's Revenge",
    requirements: [
      {
        description: "Must encode a Shakespeare quote (e.g. 'T0b3_Or_N0t_2b3')",
        test: (password) => {
          const shakespeareEncoded = [
            'T0b3_Or_N0t_2b3',
            'R0m30_R0m30',
            'Wh3r3_4rt_Th0u',
            'F00l_M0rt4l'
          ];
          return shakespeareEncoded.some(quote => 
            password.includes(quote)
          );
        }
      }
    ]
  },
  {
    level: 12,
    title: "Temporal Encryption",
    requirements: [
      {
        description: "Must include current timestamp in base-36 (e.g. 2024-11-23_XY:ZZ)",
        test: (password) => {
          const now = new Date();
          const hour = now.getHours().toString(36);
          const minute = now.getMinutes().toString(36);
          const dateStr = `${now.getFullYear()}-${String(now.getMonth()+1).padStart(2,'0')}-${String(now.getDate()).padStart(2,'0')}`;
          const timeStr = `${hour}:${minute}`;
          return password.includes(`${dateStr}_${timeStr}`);
        }
      }
    ]
  },
  {
    level: 13,
    title: "Reverse Keyboard Challenge",
    requirements: [
      {
        description: "Characters must correspond to opposite side of keyboard (q->p, a->;)",
        test: (password) => {
          const keyboardMap = {
            'q':'p', 'w':'o', 'e':'i', 'r':'u', 't':'y',
            'a':';', 's':'l', 'd':'k', 'f':'j', 'g':'h',
            'z':'/', 'x':'.', 'c':',', 'v':'m', 'b':'n'
          };
          return password.split('').every(char => 
            Object.values(keyboardMap).includes(char.toLowerCase())
          );
        }
      }
    ]
  },
  {
    level: 14,
    title: "Prime Position Power",
    requirements: [
      {
        description: "Only use characters from prime-numbered keyboard positions",
        test: (password) => {
          const primePositionChars = '23579cgkquy';
          return password.split('').every(char => 
            primePositionChars.includes(char.toLowerCase())
          );
        }
      }
    ]
  }
);

// Function to update level display
function updateLevelDisplay() {
  if (!levelDisplay) return;
  
  // Update level number
  const levelSpan = document.getElementById('level');
  if (levelSpan) {
    levelSpan.textContent = currentLevel + 1;
  }

  // Update level title if it exists
  const levelTitle = document.getElementById('levelTitle');
  if (levelTitle && levels[currentLevel]) {
    levelTitle.textContent = levels[currentLevel].title;
  }
}

// Function to update timer display
function updateTimerDisplay() {
  if (!timerDisplay) return;
  
  const minutes = Math.floor(timeLeft / 60);
  const seconds = timeLeft % 60;
  timerDisplay.textContent = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
  
  // Add visual warning when time is low
  if (timeLeft <= 30) {
    timerDisplay.style.color = 'var(--neon-red)';
    timerDisplay.style.animation = 'pulse 1s infinite';
  } else {
    timerDisplay.style.color = '';
    timerDisplay.style.animation = '';
  }
}

// Function to show penalty
function showPenalty() {
  // Flash the screen red
  document.body.classList.add('penalty-flash');
  setTimeout(() => document.body.classList.remove('penalty-flash'), 500);

  // Play explosion sound if available
  const explosionSound = document.getElementById('explosionSound');
  if (explosionSound) {
    explosionSound.currentTime = 0;
    explosionSound.play().catch(err => console.log('Audio error:', err));
  }

  // Reduce time
  timeLeft = Math.max(0, timeLeft - PENALTY_TIME);
  updateTimerDisplay();

  // Show penalty message
  showInstructorMessage(`⚠️ PENALTY! -${PENALTY_TIME} seconds! You have ${penalties} out of ${MAX_PENALTIES} strikes!`, 3000);
}

// Function to show instructor messages
function showInstructorMessage(message, duration = 5000) {
  if (!instructorElement) return;
  
  // Clear any existing timeout
  if (eventTimeout) {
    clearTimeout(eventTimeout);
  }

  // Show new message
  instructorElement.textContent = message;
  instructorElement.classList.remove('hide');
  instructorElement.classList.add('visible');

  // Set timeout to hide message
  eventTimeout = setTimeout(() => {
    instructorElement.classList.remove('visible');
    instructorElement.classList.add('hide');
  }, duration);
}

// Function to restart game
function restartGame() {
  clearInterval(timerInterval);
  passwordHistory = [];
  currentLevel = 0;
  timeLeft = 600;
  penalties = 0;
  
  // Reset displays
  if (gameOverDisplay) {
    gameOverDisplay.style.display = 'none';
  }
  
  // Reset input
  if (passwordInput) {
    passwordInput.value = '';
    passwordInput.disabled = false;
  }
  
  // Start fresh
  updateLevelDisplay();
  updateRequirements();
  updateTimerDisplay();
  startTimer();
  
  // Show restart message
  showInstructorMessage("Game restarted! Let's try this again... 😈", 3000);
}

// Function to init event system
function initializeEventSystem() {
  // Trigger random events periodically
  setInterval(() => {
    // 10% chance every 30 seconds to trigger an event
    if (Math.random() < 0.1) {
      triggerRandomEvent();
    }
  }, 30000);
}

// Function to reload game
function reloadGame() {
  location.reload();
}

// Start Game Function
function startGame() {
  // Hide menu screen
  const menuScreen = document.getElementById('menuScreen');
  if (menuScreen) {
    menuScreen.style.display = 'none';
  }

  // Show game container  
  const gameContainer = document.getElementById('gameContainer');
  if (gameContainer) {
    gameContainer.style.display = 'flex';
    gameContainer.classList.add('fade-in');
  }

  // Initialize game variables
  currentLevel = 0;
  timeLeft = 600;
  penalties = 0;

  // Get DOM references
  passwordInput = document.getElementById('passwordInput');
  requirementsList = document.getElementById('requirements'); 
  levelDisplay = document.getElementById('levelDisplay');
  timerDisplay = document.getElementById('timer');
  gameOverDisplay = document.getElementById('gameOver');
  victoryScreen = document.getElementById('victoryScreen');
  instructorElement = document.getElementById('instructor');
  overlay = document.getElementById('overlay');
  howToPlayWindow = document.getElementById('howToPlayWindow');

  // Setup password input event listener
  if (passwordInput) {
    passwordInput.addEventListener('input', (e) => {
      updateRequirements(e.target.value); 
    });
  }

  // Initialize displays
  updateLevelDisplay();
  updateRequirements();
  updateTimerDisplay();

  // Start timers and events
  startTimer();
  initializeEventSystem();

  // Show welcome message
  showInstructorMessage("Welcome to The HARDCORE PASSWORD GAME! Let's see if you can handle this... 😈", 5000);
}

// Modify timer function to remove destruction check
function startTimer() {
  timerInterval = setInterval(() => {
    if (isTimeFrozen) return;

    timeLeft--;
    updateTimerDisplay();

    if (timeLeft <= 0) {
      clearInterval(timerInterval);
      gameOver();
    }
  }, 1000);
}
</script>
</head>
<body>
<!-- Menu Screen -->
<div class="menu-screen" id="menuScreen">
  <h1 class="game-title">THE HARDCORE<br>PASSWORD GAME<br>💀</h1>
  <button class="start-button" onclick="startGame()">Start Game</button>
  <button class="how-to-play-button" onclick="showHowToPlay()">How to Play</button>
  <button class="terminal-button" onclick="openTerminal()">Terminal</button>
</div>

<!-- Game Container -->
<div class="container" id="gameContainer" style="display: none; flex-direction: column;">
  <div class="timer" id="timer">10:00</div>
  <div class="level" id="levelDisplay">Level: <span id="level">1</span></div>
  <div class="captcha-container" id="captchaContainer" style="display: none; margin: 20px 0;">
    <div id="recaptchaWidget"></div>
  </div>
  <input type="text" class="password-input" id="passwordInput" placeholder="Enter your password..." autocomplete="off">
  <button class="start-button" style="margin-top: 10px; margin-bottom: 20px;" onclick="submitPassword()">Submit</button>
  <ul class="requirements" id="requirements"></ul>
  <div class="password-history" id="passwordHistory"></div>
</div>

<!-- Enhanced Game Over Screen -->
<div class="game-over" id="gameOver">
  <div>GAME OVER</div>
  <div style="font-size: 24px; margin-top: 20px;">Your journey ends here...</div>
  <button class="retry-button" onclick="restartGame()">Try Again</button>
</div>

<!-- Victory Screen -->
<div class="victory-screen" id="victoryScreen" style="display: none;">
  <div class="victory-content">
    <h1>🏆 Congratulations! 🎉</h1>
    <p>You conquered the HARDCORE PASSWORD GAME!<br> Here's your trophy and a thumbs up! 👍</p>
    <button class="home-button" onclick="reloadGame()">Go Home</button>
    </div>
</div>

<!-- How to Play Window -->
<div class="overlay" id="overlay"></div>
<div class="how-to-play-window" id="howToPlayWindow">
  <button class="close-how-to-play" onclick="hideHowToPlay()">×</button>
  <h2>🎮 HOW TO PLAY THE HARDCORE PASSWORD GAME 💀</h2>
  
  <div class="section">
    <h3>🎯 Objective</h3>
    <p>Create passwords that meet increasingly ridiculous requirements while racing against time. Because apparently, regular passwords weren't annoying enough!</p>
    <div class="joke">Pro tip: If you think this is hard, wait until you try to remember these passwords later! 😅</div>
  </div>
  
  <div class="section">
    <h3>⚔️ Core Mechanics</h3>
    <p>• You have 10 minutes to complete all levels<br>
    • Each level adds new requirements<br>
    • Failed attempts result in time penalties<br>
    • Complete all levels to win (and question your life choices)</p>
    <div class="joke">Remember: The "Forgot Password" button won't save you here! 🤣</div>
  </div>
  
  <div class="section">
    <h3>🌟 Special Features</h3>
    <p>• Random events that either help or mess with you<br>
    • CAPTCHA challenges (because we hate you)<br>
    • Time freezes, requirement reversals, and more!</p>
    <div class="joke">If you see a "Time Freeze" event, thank the password gods. They're usually not this nice! ❄️</div>
  </div>
  
  <div class="section">
    <h3>⚠️ Warnings</h3>
    <p>• Don't rage quit (we're watching)<br>
    • Your keyboard may suffer emotional damage<br>
    • Side effects may include temporary password PTSD</p>
    <div class="joke">If you start dreaming in special characters, that's normal... probably. 🤪</div>
  </div>
  
  <div class="section">
    <h3>🏆 Victory Conditions</h3>
    <p>Complete all levels within the time limit to win and receive your virtual trophy (which is worth absolutely nothing in the real world, but hey, bragging rights!)</p>
    <div class="joke">Achievement Unlocked: "Password Masochist" 🏅</div>
  </div>
</div>

<!-- Instructor -->
<div class="instructor" id="instructor">
  Welcome to the game! Try not to mess this up. 😏
</div>

<!-- Terminal Window -->
<div class="terminal-window" id="terminalWindow">
  <div class="terminal-header">
    <span>Terminal</span>
    <button onclick="closeTerminal()">✖</button>
  </div>
  <div class="terminal-content" id="terminalContent">
    <p>Welcome to the hardcore terminal. Type 'help' to see available commands.</p>
  </div>
  <input type="text" id="terminalInput" class="terminal-input" placeholder="Enter command..." onkeydown="handleTerminalInput(event)">
</div>

<!-- Snake Game Container -->
<div id="snakeGameContainer" class="game-container" style="display: none;">
  <canvas id="snakeCanvas" width="400" height="400"></canvas>
  <div class="score">Score: <span id="snakeScore">0</span></div>
</div>

<!-- Rhythm Game Container -->
<div id="rhythmGameContainer" class="game-container" style="display: none;">
  <div class="notes-container"></div>
  <div class="input-buttons"></div>
</div>

<!-- CAPTCHA Container -->
<div id="advancedCaptcha" class="captcha-container">
  <div class="step-indicator"></div>
  <div class="challenge-content"></div>
  <div class="verification-controls"></div>
</div>

<!-- Audio Elements -->
<audio id="correctSound" src="/answer-correct.mp3"></audio>
<audio id="explosionSound" src="/deltarune-explosion.mp3"></audio>
</body></html>