fix global chat

javascript:(function() {
  // Create and play the initial sound
  const audio = new Audio('https://www.myinstants.com/media/sounds/nouveau-jingle-netflix.mp3');
  audio.play();

  // Password attempt counter
  let passwordAttempts = 0;

  // Create styles for animations and elements
  const style = document.createElement('style');
  style.textContent = `
    @keyframes splashEntrance {
      0% { opacity: 0; transform: scale(0.8) translateY(-100vh); }
      50% { opacity: 1; transform: scale(1.2) translateY(0); }
      70% { transform: scale(1) rotate(360deg); }
      100% { opacity: 0; transform: scale(0.5) translateY(100vh); }
    }
    @keyframes vibrantOutro {
      0% { background-color: #1d1f20; color: #fff; }
      20% { background: linear-gradient(45deg, #ff9a9e 0%, #fad0c4 100%); }
      40% { background: linear-gradient(to bottom, #a18cd1 0%, #fbc2eb 100%); }
      60% { background: linear-gradient(to top, #fad0c4 0%, #ffd1ff 100%); }
      80% { background: #fbc2eb; color: #1d1f20; }
      100% { background: #ffd1ff; }
    }
    @keyframes menuFadeIn {
      0% { opacity: 0; transform: translateY(20px); }
      100% { opacity: 1; transform: translateY(0); }
    }
    @keyframes menuFadeOut {
      0% { opacity: 1; transform: translateY(0); }
      100% { opacity: 0; transform: translateY(20px); }
    }
    #splashScreen, #outroMessage {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 4em;
      font-family: Arial, sans-serif;
      z-index: 10000;
    }
    #splashScreen {
      background-color: #1d1f20;
      color: #00d1b2;
      animation: splashEntrance 5s forwards;
    }
    #passwordContainer {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0,0,0,0.8);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 9999;
      animation: menuFadeIn 3s forwards;
    }
    #passwordEntry {
      background-color: #fff;
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 4px 8px rgba(0,0,0,0.2);
      text-align: center;
    }
    #outroMessage {
      background-color: #ff4444;
      color: #fff;
      opacity: 0;
      animation: vibrantOutro 6s forwards;
    }
    .fade {
      animation: menuFadeIn 3s forwards;
    }
    .fadeOut {
      animation: menuFadeOut 1s forwards;
    }
    .draggable {
      cursor: move;
    }
    #consoleOutput {
      height: 250px;
      overflow-y: auto;
      background-color: #282c34;
      color: #ffffff;
      font-family: monospace;
      padding: 10px;
      border-radius: 4px;
    }
    #consoleInput {
      width: calc(100% - 130px);
      padding: 10px;
      border: 1px solid #ccc;
      border-radius: 4px;
      margin: 5px;
    }
    #consoleContainer {
      transition: width 0.5s ease, height 0.5s ease;
      position: fixed;
      bottom: 10px;
      right: 10px;
      width: 400px;
      height: 400px;
      z-index: 9999;
      background-color: rgba(255, 255, 255, 0.9);
      border: 2px solid #008CBA;
      box-shadow: 0 4px 8px rgba(0,0,0,0.2);
      border-radius: 8px;
    }
    #consoleControlPanel {
      margin: 5px;
      text-align: center;
    }
  `;
  document.head.appendChild(style);

  function createMenuButton(text, color, onClick) {
    const button = document.createElement('button');
    button.textContent = text;
    button.style.width = '100%';
    button.style.padding = '10px';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.backgroundColor = color;
    button.style.color = 'white';
    button.style.fontSize = '1em';
    button.style.cursor = 'pointer';
    button.style.marginBottom = '10px';
    button.onclick = onClick;
    return button;
  }

  // Create the splash screen
  const splashScreen = document.createElement('div');
  splashScreen.id = 'splashScreen';
  splashScreen.textContent = 'BM 4.0 Launcher';
  document.body.appendChild(splashScreen);

  // Password entry container
  const passwordContainer = document.createElement('div');
  passwordContainer.id = 'passwordContainer';
  passwordContainer.style.display = 'none';
  const passwordEntry = document.createElement('div');
  passwordEntry.id = 'passwordEntry';
  passwordEntry.innerHTML = `
    <h2 style="margin-bottom: 10px;">Enter Password</h2>
    <input type="password" id="passwordInput" style="padding: 10px; font-size: 1em;">
    <button id="submitPassword" style="padding: 10px; margin-top: 10px; background-color: #4CAF50; border: none; color: white; border-radius: 5px; cursor: pointer;">Submit</button>
  `;
  passwordContainer.appendChild(passwordEntry);
  document.body.appendChild(passwordContainer);

  // Function to handle password submission
  function handlePasswordSubmit() {
    const passwordInput = document.getElementById('passwordInput').value;
    if (passwordInput === 'dja101') {
      passwordContainer.style.display = 'none';
      initializeMenu();
    } else {
      passwordAttempts++;
      alert('Incorrect password!');
      if (passwordAttempts >= 3) {
        passwordContainer.style.display = 'none';
        showLockoutMessage();
      }
    }
  }

  // Ensure correct event binding
  document.getElementById('submitPassword').onclick = handlePasswordSubmit;

  // Initialize menu after correct password
  function initializeMenu() {
    const menuContainer = document.createElement('div');
    menuContainer.id = 'menuContainer';
    menuContainer.className = 'fade';
    menuContainer.style.position = 'fixed';
    menuContainer.style.top = '10px';
    menuContainer.style.left = '10px';
    menuContainer.style.width = '300px';
    menuContainer.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
    menuContainer.style.borderRadius = '8px';
    menuContainer.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
    menuContainer.style.padding = '10px';
    menuContainer.style.zIndex = '9999';
    document.body.appendChild(menuContainer);

    menuContainer.appendChild(createMenuButton('Games', '#ffc107', () => {
      fadeOut(menuContainer);
      openGamesList();
    }));

    menuContainer.appendChild(createMenuButton('Convert YouTube URL', '#008CBA', () => {
      fadeOut(menuContainer);
      openUnblockWebsiteInterface();
    }));

    menuContainer.appendChild(createMenuButton('Inspect Element', '#FF5733', () => {
      fadeOut(menuContainer);
      openConsoleInterface();
    }));

    menuContainer.appendChild(createMenuButton('Credits', '#6f42c1', () => {
      if (confirm("Are you sure you want to see credits?")) {
        fadeOut(menuContainer);
        openCreditsInterface();
      }
    }));

    menuContainer.appendChild(createMenuButton('Global Chat', '#28a745', () => {
      if (confirm("Are you sure you want to open Global Chat?")) {
        fadeOut(menuContainer);
        openGlobalChat();
      }
    }));

    menuContainer.appendChild(createMenuButton('Close', '#f04e30', () => {
      if (confirm("Are you sure you want to close?")) {
        runOutroSequence();
      }
    }));
  }

  // Function to handle the outro sequence
  function runOutroSequence() {
    const outroMessage = document.createElement('div');
    outroMessage.id = 'outroMessage';
    outroMessage.textContent = 'Thank You!';
    document.body.appendChild(outroMessage);
    setTimeout(() => {
      document.body.innerHTML = ''; // Clear everything after the outro animation
    }, 6000);
  }

  // Function to fade elements out
  function fadeOut(element) {
    element.classList.add('fadeOut');
    setTimeout(() => {
      element.style.display = 'none';
    }, 1000);
  }

  // Show lockout message after 3 incorrect password attempts
  function showLockoutMessage() {
    const outroMessage = document.createElement('div');
    outroMessage.id = 'outroMessage';
    outroMessage.textContent = 'Access Denied!';
    document.body.appendChild(outroMessage);
    setTimeout(() => {
      document.body.innerHTML = '';
    }, 3000);
  }

  // Open games list
  function openGamesList() {
    const gameListContainer = document.createElement('div');
    gameListContainer.id = 'gameListContainer';
    gameListContainer.style.position = 'fixed';
    gameListContainer.style.width = '100%';
    gameListContainer.style.height = '100%';
    gameListContainer.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
    gameListContainer.style.zIndex = '9999';
    gameListContainer.style.display = 'flex';
    gameListContainer.style.alignItems = 'center';
    gameListContainer.style.justifyContent = 'center';
    gameListContainer.style.flexDirection = 'column';
    gameListContainer.classList.add('fade');

    const games = ['Game 1', 'Game 2', 'Game 3', 'Game 4', 'Game 5'];
    const gameList = document.createElement('ul');
    gameList.style.listStyleType = 'none';
    gameList.style.padding = '0';

    games.forEach(game => {
      const gameItem = document.createElement('li');
      gameItem.textContent = game;
      gameItem.style.padding = '10px';
      gameItem.style.cursor = 'pointer';
      gameItem.style.borderBottom = '1px solid #ddd';
      gameItem.onclick = function() {
        openGameEmbed(`https://example.com/${game.toLowerCase().replace(' ', '-')}`);
        fadeOut(gameListContainer);
      };
      gameList.appendChild(gameItem);
    });

    const backButton = document.createElement('button');
    backButton.textContent = 'Back';
    backButton.style.padding = '10px';
    backButton.style.border = 'none';
    backButton.style.borderRadius = '5px';
    backButton.style.backgroundColor = '#dc3545';
    backButton.style.color = 'white';
    backButton.style.cursor = 'pointer';
    backButton.onclick = function() {
      document.body.removeChild(gameListContainer);
      initializeMenu();
    };
    gameListContainer.appendChild(gameList);
    gameListContainer.appendChild(backButton);
    document.body.appendChild(gameListContainer);
  }

  // Open credits interface
  function openCreditsInterface() {
    const creditsContainer = document.createElement('div');
    creditsContainer.id = 'creditsContainer';
    creditsContainer.style.position = 'fixed';
    creditsContainer.style.width = '100%';
    creditsContainer.style.height = '100%';
    creditsContainer.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
    creditsContainer.style.zIndex = '9999';
    creditsContainer.style.display = 'flex';
    creditsContainer.style.alignItems = 'center';
    creditsContainer.style.justifyContent = 'center';
    creditsContainer.style.flexDirection = 'column';
    creditsContainer.classList.add('fade');

    const creditsList = document.createElement('div');
    creditsList.style.padding = '20px';
    creditsList.style.backgroundColor = '#fff';
    creditsList.style.borderRadius = '8px';
    creditsList.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
    creditsList.innerHTML = `
      <h2>Credits</h2>
      <ul style="list-style-type: none; padding: 0;">
        <li>Person A - Developer</li>
        <li>Person B - Designer</li>
        <li>Person C - Tester</li>
      </ul>
    `;

    const backButton = document.createElement('button');
    backButton.textContent = 'Back';
    backButton.style.padding = '10px';
    backButton.style.marginTop = '20px';
    backButton.style.border = 'none';
    backButton.style.borderRadius = '5px';
    backButton.style.backgroundColor = '#6f42c1';
    backButton.style.color = 'white';
    backButton.style.cursor = 'pointer';
    backButton.onclick = function() {
      document.body.removeChild(creditsContainer);
      initializeMenu();
    };
    creditsContainer.appendChild(creditsList);
    creditsContainer.appendChild(backButton);
    document.body.appendChild(creditsContainer);
  }

  // Open game in an embed
  function openGameEmbed(url) {
    const embedContainer = document.createElement('div');
    embedContainer.id = 'embedContainer';
    embedContainer.style.position = 'fixed';
    embedContainer.style.top = '10px';
    embedContainer.style.right = '10px';
    embedContainer.style.width = '600px';
    embedContainer.style.height = '400px';
    embedContainer.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
    embedContainer.style.border = '2px solid #008CBA';
    embedContainer.style.borderRadius = '8px';
    embedContainer.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
    embedContainer.style.zIndex = '9999';
    document.body.appendChild(embedContainer);

    const iframe = document.createElement('iframe');
    iframe.src = url;
    iframe.style.width = '100%';
    iframe.style.height = '100%';
    iframe.style.border = 'none';
    embedContainer.appendChild(iframe);

    const controlPanel = document.createElement('div');
    controlPanel.style.textAlign = 'center';
    controlPanel.style.padding = '10px';
    
    const widthInput = document.createElement('input');
    widthInput.type = 'number';
    widthInput.value = '600';
    widthInput.style.width = '60px';
    controlPanel.appendChild(widthInput);

    const heightInput = document.createElement('input');
    heightInput.type = 'number';
    heightInput.value = '400';
    heightInput.style.width = '60px';
    controlPanel.appendChild(heightInput);

    const resizeButton = document.createElement('button');
    resizeButton.textContent = 'Resize';
    resizeButton.style.padding = '5px 10px';
    resizeButton.style.margin = '5px';
    resizeButton.style.borderRadius = '5px';
    resizeButton.style.border = 'none';
    resizeButton.style.backgroundColor = '#ffc107';
    resizeButton.style.color = 'white';
    resizeButton.style.cursor = 'pointer';
    resizeButton.onclick = function() {
      embedContainer.style.width = `${widthInput.value}px`;
      embedContainer.style.height = `${heightInput.value}px`;
    };
    controlPanel.appendChild(resizeButton);

    const closeEmbedButton = document.createElement('button');
    closeEmbedButton.textContent = 'Close';
    closeEmbedButton.style.padding = '5px 10px';
    closeEmbedButton.style.margin = '5px';
    closeEmbedButton.style.borderRadius = '5px';
    closeEmbedButton.style.border = 'none';
    closeEmbedButton.style.backgroundColor = '#dc3545';
    closeEmbedButton.style.color = 'white';
    closeEmbedButton.style.cursor = 'pointer';
    closeEmbedButton.onclick = function() {
      if (confirm('Are you sure you want to close this game?')) {
        document.body.removeChild(embedContainer);
        openGamesList();
      }
    };
    controlPanel.appendChild(closeEmbedButton);

    const dragButton = document.createElement('button');
    dragButton.textContent = 'Toggle Drag';
    dragButton.style.padding = '5px 10px';
    dragButton.style.margin = '5px';
    dragButton.style.borderRadius = '5px';
    dragButton.style.border = 'none';
    dragButton.style.backgroundColor = '#17a2b8';
    dragButton.style.color = 'white';
    dragButton.style.cursor = 'pointer';
    let isDraggable = false;
    dragButton.onclick = function() {
      if (!isDraggable) {
        makeElementDraggable(embedContainer);
        isDraggable = true;
      } else {
        removeElementDraggable(embedContainer);
        isDraggable = false;
      }
    };
    controlPanel.appendChild(dragButton);

    embedContainer.appendChild(controlPanel);
  }

  // Open website interface
  function openUnblockWebsiteInterface() {
    const frameContainer = document.createElement('div');
    frameContainer.id = 'embedWebsiteContainer';
    frameContainer.style.position = 'absolute';
    frameContainer.style.top = '10px';
    frameContainer.style.right = '10px';
    frameContainer.style.width = '600px';
    frameContainer.style.height = '400px';
    frameContainer.style.zIndex = '9999';
    frameContainer.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
    frameContainer.style.border = '2px solid #008CBA';
    frameContainer.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
    frameContainer.style.borderRadius = '8px';
    document.body.appendChild(frameContainer);

    const iframe = document.createElement('iframe');
    iframe.id = 'embedWebsiteFrame';
    iframe.style.width = '100%';
    iframe.style.height = '100%';
    iframe.style.border = 'none';
    frameContainer.appendChild(iframe);

    const controlPanel = document.createElement('div');
    controlPanel.style.margin = '5px';
    controlPanel.style.textAlign = 'center';
    frameContainer.appendChild(controlPanel);

    // Resize control inputs
    const widthInput = document.createElement('input');
    widthInput.type = 'number';
    widthInput.value = '600';
    widthInput.style.width = '60px';
    widthInput.style.margin = '5px';
    widthInput.title = 'Width';
    controlPanel.appendChild(widthInput);

    const heightInput = document.createElement('input');
    heightInput.type = 'number';
    heightInput.value = '400';
    heightInput.style.width = '60px';
    heightInput.style.margin = '5px';
    heightInput.title = 'Height';
    controlPanel.appendChild(heightInput);

    const resizeButton = document.createElement('button');
    resizeButton.textContent = 'Resize';
    resizeButton.style.padding = '5px 10px';
    resizeButton.style.margin = '5px';
    resizeButton.style.borderRadius = '5px';
    resizeButton.style.border = 'none';
    resizeButton.style.backgroundColor = '#ffa07a';
    resizeButton.style.color = 'white';
    resizeButton.style.cursor = 'pointer';
    resizeButton.onclick = function() {
      const newWidth = widthInput.value + 'px';
      const newHeight = heightInput.value + 'px';
      frameContainer.style.width = newWidth;
      frameContainer.style.height = newHeight;
    };
    controlPanel.appendChild(resizeButton);

    // Toggle draggable state with a button
    const dragButton = document.createElement('button');
    dragButton.textContent = 'Enable Drag';
    dragButton.style.padding = '5px 10px';
    dragButton.style.margin = '5px';
    dragButton.style.borderRadius = '5px';
    dragButton.style.border = 'none';
    dragButton.style.backgroundColor = '#f0ad4e';
    dragButton.style.color = 'white';
    dragButton.style.cursor = 'pointer';
    let isDraggable = false;

    dragButton.onclick = function() {
      if (!isDraggable) {
        makeElementDraggable(frameContainer);
        dragButton.textContent = 'Disable Drag';
        isDraggable = true;
      } else {
        removeElementDraggable(frameContainer);
        dragButton.textContent = 'Enable Drag';
        isDraggable = false;
      }
    };
    controlPanel.appendChild(dragButton);

    const toggleButton = document.createElement('button');
    toggleButton.textContent = 'Close';
    toggleButton.style.padding = '5px 10px';
    toggleButton.style.margin = '5px';
    toggleButton.style.borderRadius = '5px';
    toggleButton.style.border = 'none';
    toggleButton.style.backgroundColor = '#008CBA';
    toggleButton.style.color = 'white';
    toggleButton.style.cursor = 'pointer';
    toggleButton.style.transition = 'background-color 0.3s ease';
    toggleButton.onmouseover = function() {
      toggleButton.style.backgroundColor = '#005f73';
    };
    toggleButton.onmouseout = function() {
      toggleButton.style.backgroundColor = '#008CBA';
    };
    toggleButton.onclick = function() {
      if (confirm('Are you sure you want to close?')) {
        frameContainer.remove();
        initializeMenu(); // Show menu bar again
      }
    };
    controlPanel.appendChild(toggleButton);

    const urlInput = document.createElement('input');
    urlInput.type = 'text';
    urlInput.placeholder = 'Enter YouTube URL';
    urlInput.style.width = '200px';
    urlInput.style.margin = '5px';
    urlInput.style.borderRadius = '5px';
    urlInput.style.border = '1px solid #ccc';
    urlInput.style.padding = '5px';
    controlPanel.appendChild(urlInput);

    const submitButton = document.createElement('button');
    submitButton.textContent = 'Convert';
    submitButton.style.padding = '5px 10px';
    submitButton.style.margin = '5px';
    submitButton.style.borderRadius = '5px';
    submitButton.style.border = 'none';
    submitButton.style.backgroundColor = '#4CAF50';
    submitButton.style.color = 'white';
    submitButton.style.cursor = 'pointer';
    submitButton.style.transition = 'background-color 0.3s ease';
    submitButton.onmouseover = function() {
      submitButton.style.backgroundColor = '#388e3c';
    };
    submitButton.onmouseout = function() {
      submitButton.style.backgroundColor = '#4CAF50';
    };
    submitButton.onclick = function() {
      const url = urlInput.value.trim();
      if (url) {
        const videoId = new URL(url).searchParams.get('v');
        if (videoId) {
          const frame = document.getElementById('embedWebsiteFrame');
          frame.src = `https://www.youtube.com/embed/${videoId}`;
          urlInput.value = '';
          frameContainer.style.display = 'block';
        } else {
          alert('Invalid YouTube URL.');
        }
      }
    };
    controlPanel.appendChild(submitButton);
  }

  // Open console interface (the Inspect Element-like console)
  function openConsoleInterface() {
    const consoleContainer = document.createElement('div');
    consoleContainer.id = 'consoleContainer';
    document.body.appendChild(consoleContainer);

    const consoleControlPanel = document.createElement('div');
    consoleControlPanel.id = 'consoleControlPanel';
    consoleContainer.appendChild(consoleControlPanel);

    // Add console output area
    const consoleOutput = document.createElement('div');
    consoleOutput.id = 'consoleOutput';
    consoleContainer.appendChild(consoleOutput);

    // Add console input and controls
    const consoleInput = document.createElement('input');
    consoleInput.id = 'consoleInput';
    consoleInput.placeholder = 'Enter JavaScript Code';
    consoleControlPanel.appendChild(consoleInput);

    const submitButton = document.createElement('button');
    submitButton.textContent = 'Run';
    submitButton.style.padding = '5px 10px';
    submitButton.style.marginLeft = '5px';
    submitButton.style.borderRadius = '5px';
    submitButton.style.border = 'none';
    submitButton.style.backgroundColor = '#28a745';
    submitButton.style.color = 'white';
    submitButton.style.cursor = 'pointer';
    submitButton.style.transition = 'background-color 0.3s ease';
    submitButton.onclick = function() {
      try {
        const result = eval(consoleInput.value);
        logToConsole(result);
      } catch (error) {
        logToConsole(error, true);
      }
      consoleInput.value = '';
    };
    consoleControlPanel.appendChild(submitButton);

    const clearButton = document.createElement('button');
    clearButton.textContent = 'Clear Console';
    clearButton.style.padding = '5px 10px';
    clearButton.style.marginLeft = '5px';
    clearButton.style.borderRadius = '5px';
    clearButton.style.border = 'none';
    clearButton.style.backgroundColor = '#343a40';
    clearButton.style.color = 'white';
    clearButton.style.cursor = 'pointer';
    clearButton.onclick = function() {
      consoleOutput.innerHTML = '';  // Clear the console's output
    };
    consoleControlPanel.appendChild(clearButton);

    const closeButton = document.createElement('button');
    closeButton.textContent = 'Close';
    closeButton.style.padding = '5px 10px';
    closeButton.style.marginLeft = '5px';
    closeButton.style.borderRadius = '5px';
    closeButton.style.border = 'none';
    closeButton.style.backgroundColor = '#dc3545';
    closeButton.style.color = 'white';
    closeButton.style.cursor = 'pointer';
    closeButton.onclick = function() {
      if (confirm('Are you sure you want to close the console?')) {
        document.body.removeChild(consoleContainer);
        initializeMenu(); // Show menu bar again
      }
    };
    consoleControlPanel.appendChild(closeButton);

    // Resize control inputs for console
    const widthInput = document.createElement('input');
    widthInput.type = 'number';
    widthInput.value = '400';
    widthInput.style.width = '60px';
    widthInput.style.marginLeft = '5px';
    widthInput.title = 'Width';
    consoleControlPanel.appendChild(widthInput);

    const heightInput = document.createElement('input');
    heightInput.value = '400';
    heightInput.type = 'number';
    heightInput.style.width = '60px';
    heightInput.style.marginLeft = '5px';
    heightInput.title = 'Height';
    consoleControlPanel.appendChild(heightInput);

    const resizeButton = document.createElement('button');
    resizeButton.textContent = 'Resize';
    resizeButton.style.padding = '5px 10px';
    resizeButton.style.marginLeft = '5px';
    resizeButton.style.borderRadius = '5px';
    resizeButton.style.border = 'none';
    resizeButton.style.backgroundColor = '#ffc107';
    resizeButton.style.color = 'white';
    resizeButton.style.cursor = 'pointer';
    resizeButton.onclick = function() {
      const newWidth = widthInput.value + 'px';
      const newHeight = heightInput.value + 'px';
      consoleContainer.style.width = newWidth;
      consoleContainer.style.height = newHeight;
    };
    consoleControlPanel.appendChild(resizeButton);

    // Toggle draggable state with a button for console
    const dragButton = document.createElement('button');
    dragButton.textContent = 'Enable Drag';
    dragButton.style.padding = '5px 10px';
    dragButton.style.marginLeft = '5px';
    dragButton.style.borderRadius = '5px';
    dragButton.style.border = 'none';
    dragButton.style.backgroundColor = '#17a2b8';
    dragButton.style.color = 'white';
    dragButton.style.cursor = 'pointer';
    let isDraggable = false;

    dragButton.onclick = function() {
      if (!isDraggable) {
        makeElementDraggable(consoleContainer);
        dragButton.textContent = 'Disable Drag';
        isDraggable = true;
      } else {
        removeElementDraggable(consoleContainer);
        dragButton.textContent = 'Enable Drag';
        isDraggable = false;
      }
    };
    consoleControlPanel.appendChild(dragButton);
  }

  // Open Global Chat (dummy setup; needs a backend)
  function openGlobalChat() {
    const chatContainer = document.createElement('div');
    chatContainer.id = 'chatContainer';
    chatContainer.style.position = 'fixed';
    chatContainer.style.width = '100%';
    chatContainer.style.height = '100%';
    chatContainer.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
    chatContainer.style.zIndex = '9999';
    chatContainer.style.display = 'flex';
    chatContainer.style.alignItems = 'center';
    chatContainer.style.justifyContent = 'center';
    chatContainer.style.flexDirection = 'column';
    chatContainer.classList.add('fade');

    const loadingMessage = document.createElement('div');
    loadingMessage.textContent = 'Connecting to Global Chat...';
    loadingMessage.style.fontSize = '2em';
    chatContainer.appendChild(loadingMessage);

    setTimeout(() => {
      loadingMessage.style.display = 'none';
      const chatBox = document.createElement('div');
      chatBox.style.width = '80%';
      chatBox.style.height = '60%';
      chatBox.style.backgroundColor = '#fff';
      chatBox.style.borderRadius = '8px';
      chatBox.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
      chatBox.style.overflow = 'hidden';
      chatBox.style.display = 'flex';
      chatBox.style.flexDirection = 'column';
      chatBox.style.padding = '10px';
      
      const messages = document.createElement('div');
      messages.style.flexGrow = '1';
      messages.style.overflowY = 'auto';
      messages.style.padding = '5px';
      chatBox.appendChild(messages);
      
      const chatForm = document.createElement('form');
      chatForm.style.display = 'flex';
      chatForm.style.marginTop = '10px';
      
      const nameInput = document.createElement('input');
      nameInput.type = 'text';
      nameInput.placeholder = 'Your Name';
      nameInput.style.flexBasis = '20%';
      nameInput.style.marginRight = '10px';
      nameInput.style.padding = '5px';
      
      const messageInput = document.createElement('input');
      messageInput.type = 'text';
      messageInput.placeholder = 'Enter Message';
      messageInput.style.flexGrow = '1';
      messageInput.style.padding = '5px';
      
      const sendButton = document.createElement('button');
      sendButton.textContent = 'Send';
      sendButton.style.padding = '5px';
      sendButton.style.marginLeft = '10px';
      sendButton.style.border = 'none';
      sendButton.style.borderRadius = '5px';
      sendButton.style.backgroundColor = '#28a745';
      sendButton.style.color = 'white';
      sendButton.style.cursor = 'pointer';
      
      chatForm.onsubmit = function(e) {
        e.preventDefault();
        if (nameInput.value && messageInput.value) {
          const message = document.createElement('div');
          message.style.padding = '5px';
          message.style.borderBottom = '1px solid #ddd';
          message.textContent = `${nameInput.value}: ${messageInput.value}`;
          messages.appendChild(message);
          messageInput.value = '';
          messages.scrollTop = messages.scrollHeight; // scroll to bottom
        }
      };
      
      chatForm.appendChild(nameInput);
      chatForm.appendChild(messageInput);
      chatForm.appendChild(sendButton);
      chatBox.appendChild(chatForm);
      
      const logoutButton = document.createElement('button');
      logoutButton.textContent = 'Log out';
      logoutButton.style.padding = '10px';
      logoutButton.style.marginTop = '20px';
      logoutButton.style.border = 'none';
      logoutButton.style.borderRadius = '5px';
      logoutButton.style.backgroundColor = '#dc3545';
      logoutButton.style.color = 'white';
      logoutButton.style.cursor = 'pointer';
      logoutButton.onclick = function() {
        document.body.removeChild(chatContainer);
        initializeMenu();
      };
      
      chatContainer.appendChild(chatBox);
      chatContainer.appendChild(logoutButton);
    }, 2000); // Simulate loading time
    document.body.appendChild(chatContainer);
  }

  // Function to log output in the console
  function logToConsole(message, isError = false) {
    const consoleOutput = document.getElementById('consoleOutput');
    const messageElement = document.createElement('div');
    messageElement.textContent = message;
    messageElement.style.color = isError ? 'red' : 'white';
    consoleOutput.appendChild(messageElement);
    consoleOutput.scrollTop = consoleOutput.scrollHeight;  // Auto-scroll
  }

  // Function to make an element draggable
  function makeElementDraggable(element) {
    element.classList.add('draggable');
    let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
    element.onmousedown = function(e) {
      e = e || window.event;
      e.preventDefault();
      pos3 = e.clientX;
      pos4 = e.clientY;
      document.onmouseup = closeDragElement;
      document.onmousemove = elementDrag;
    };

    function elementDrag(e) {
      e = e || window.event;
      e.preventDefault();
      pos1 = pos3 - e.clientX;
      pos2 = pos4 - e.clientY;
      pos3 = e.clientX;
      pos4 = e.clientY;
      element.style.top = (element.offsetTop - pos2) + "px";
      element.style.left = (element.offsetLeft - pos1) + "px";
    }

    function closeDragElement() {
      document.onmouseup = null;
      document.onmousemove = null;
    }
  }

  // Function to remove draggable ability from element
  function removeElementDraggable(element) {
    element.classList.remove('draggable');
    element.onmousedown = null;
  }

  setTimeout(() => {
    splashScreen.remove();
    passwordContainer.style.display = 'flex';
  }, 5000);
})();