<!DOCTYPE html>
<html lang="en" class="">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>FLAMES KINGDOM - THE #1 LINK BYPASSER</title>
    <!-- Tailwind CSS via CDN -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- Tailwind configuration: dark mode enabled and custom colors -->
    <script>
      tailwind.config = {
        darkMode: 'class',
        theme: {
          extend: {
            colors: {
              accent: "#8FBC8F", // light green accent
              background: "#000000", // black background for dark mode
            },
            keyframes: {
              fadeIn: {
                '0%': { opacity: '0', transform: 'scale(0.95)' },
                '100%': { opacity: '1', transform: 'scale(1)' },
              },
            },
            animation: {
              fadeIn: "fadeIn 0.5s ease-out forwards",
            },
          },
        },
      };
    </script>
    <!-- QRCode.js Library for generating QR codes -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
    <!-- (Optional) Highlight.js for syntax highlighting if needed -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/atom-one-dark.min.css" />
    <style>
      /* Solid black background */
      body {
        background-color: #000000;
        transition: background-color 0.5s ease, color 0.5s ease;
      }
      /* Fullscreen Canvas for Particle Animation */
      #bgCanvas {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: -1;
      }
      /* Custom Cursor */
      #customCursor {
        position: fixed;
        top: 0;
        left: 0;
        width: 15px;
        height: 15px;
        border-radius: 50%;
        background-color: #8fbc8f;
        pointer-events: none;
        transform: translate(-50%, -50%);
        transition: transform 0.1s ease-out;
        z-index: 1000;
      }
      /* Toast Notification */
      #toast {
        position: fixed;
        top: 20px;
        left: 50%;
        transform: translateX(-50%);
        background: #8fbc8f;
        color: #000;
        padding: 10px 20px;
        border-radius: 5px;
        opacity: 0;
        transition: opacity 0.5s;
        z-index: 50;
      }
      /* Modal Styles with smooth scale transition */
      .modal {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.8);
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 200;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease, transform 0.3s ease;
        transform: scale(0.95);
      }
      .modal.active {
        opacity: 1;
        pointer-events: auto;
        transform: scale(1);
      }
      .modal-content {
        background: #1a1a1a;
        padding: 20px;
        border-radius: 8px;
        width: 90%;
        max-width: 500px;
      }
      /* Back to Top Button */
      #backToTop {
        position: fixed;
        bottom: 30px;
        right: 30px;
        background: #8fbc8f;
        color: #000;
        padding: 10px 15px;
        border-radius: 5px;
        cursor: pointer;
        opacity: 0;
        transition: opacity 0.3s;
        z-index: 100;
      }
      /* Container for QR Code (hidden by default) */
      #qrContainer {
        margin-top: 1rem;
        display: none;
      }
      /* Success Icon Animation */
      .success-icon {
        display: inline-block;
        vertical-align: middle;
        margin-right: 8px;
        animation: fadeIn 0.5s ease-out forwards;
      }
      /* Logging Panel (hidden modal) */
      #logModal .modal-content {
        max-height: 400px;
        overflow-y: auto;
        font-size: 0.875rem;
      }
    </style>
  </head>
  <!-- Start in dark mode by default -->
  <body class="bg-black text-white font-sans antialiased relative overflow-x-hidden">
    <!-- Particle Animation Canvas -->
    <canvas id="bgCanvas"></canvas>
    <!-- Custom Cursor -->
    <div id="customCursor"></div>
    <!-- Toast Notification -->
    <div id="toast">Copied!</div>
    <!-- Back to Top Button -->
    <div id="backToTop">Top</div>

    <!-- Header with Navigation and Language Toggle -->
    <header class="w-full py-4 border-b border-gray-700">
      <div class="container mx-auto flex justify-between items-center px-4">
        <div class="text-2xl font-extrabold tracking-wide">FLAMES KINGDOM</div>
        <nav class="flex items-center space-x-4">
          <a href="https://discord.com" target="_blank" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300">
            Join Discord
          </a>
          <button id="openFavorites" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300">
            Favorites
          </button>
          <button id="openSettings" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300">
            Settings
          </button>
          <button id="openHelp" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300">
            Help
          </button>
          <button id="openAbout" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300">
            About
          </button>
          <button id="openLog" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300">
            Log
          </button>
          <!-- Language toggle button -->
          <button id="langToggle" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300">
            ES
          </button>
          <button id="darkModeToggle" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300">
            Toggle Mode
          </button>
        </nav>
      </div>
    </header>

    <!-- Main Content -->
    <main class="flex flex-col items-center justify-center min-h-screen px-4">
      <div class="bg-gray-900 bg-opacity-90 rounded-lg shadow-2xl p-8 max-w-lg w-full transform transition-all duration-500 hover:scale-105 animate-fadeIn">
        <h1 class="text-3xl md:text-4xl font-extrabold text-center mb-4 bg-gradient-to-r from-accent to-white bg-clip-text text-transparent">
          THE #1 LINK BYPASSER
        </h1>
        <p id="tagline" class="text-center text-gray-300 mb-6">
          Bypass links instantly—skip ads and get direct links without interruption.
        </p>
        <!-- Input Field -->
        <div class="mb-6">
          <input type="text" id="urlInput" placeholder="Paste your link here" class="w-full p-3 rounded border border-gray-700 bg-gray-800 text-white focus:outline-none focus:ring-2 focus:ring-accent transition" />
        </div>
        <!-- Primary Action Buttons -->
        <div class="flex space-x-4 mb-4">
          <button id="bypassButton" class="flex-1 bg-accent text-black font-bold py-3 rounded hover:bg-white hover:text-accent transition duration-300 shadow-lg">
            Bypass Now
          </button>
          <button id="refreshButton" class="flex-1 bg-gray-700 text-white font-bold py-3 rounded hover:bg-gray-600 transition duration-300 shadow-lg">
            Refresh Bypass
          </button>
        </div>
        <!-- Additional Action Buttons -->
        <div class="flex flex-wrap gap-2 mb-4" id="actionButtons">
          <button id="copyButton" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300 hidden">
            Copy Result
          </button>
          <button id="shareButton" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300 hidden">
            Share
          </button>
          <button id="emailButton" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300 hidden">
            Email
          </button>
          <button id="qrButton" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300 hidden">
            QR Code
          </button>
          <button id="saveFavButton" class="px-4 py-2 border border-accent text-accent rounded hover:bg-accent hover:text-black transition duration-300 hidden">
            Save Favorite
          </button>
        </div>
        <!-- Container for QR Code (appears when QR Code is generated) -->
        <div id="qrContainer" class="flex justify-center"></div>
        <!-- Result Display Container -->
        <div id="resultContainer" class="bg-gray-800 p-4 rounded text-sm overflow-x-auto min-h-[100px]">
          <div id="resultMessage" class="text-center"></div>
        </div>
        <!-- History Section with Clear & Export Options -->
        <div id="historyContainer" class="mt-4">
          <div class="flex justify-between items-center mb-2">
            <h2 class="text-lg font-bold">History</h2>
            <div class="flex space-x-2">
              <button id="clearHistory" class="text-sm text-red-500 hover:underline">
                Clear
              </button>
              <button id="exportHistory" class="text-sm text-accent hover:underline">
                Export
              </button>
            </div>
          </div>
          <ul id="historyList" class="space-y-2"></ul>
        </div>
        <!-- Analytics Counter -->
        <div id="analyticsContainer" class="mt-4">
          <p>Total Requests: <span id="analyticsCount"></span></p>
        </div>
      </div>
    </main>

    <!-- Favorites Modal -->
    <div id="favoritesModal" class="modal">
      <div class="modal-content">
        <h2 class="text-xl font-bold mb-4">Favorites</h2>
        <ul id="favoritesList" class="mb-4"></ul>
        <div class="flex justify-end">
          <button id="closeFavorites" class="px-4 py-2 bg-accent text-black rounded">Close</button>
        </div>
      </div>
    </div>

    <!-- Settings Modal -->
    <div id="settingsModal" class="modal">
      <div class="modal-content">
        <h2 class="text-xl font-bold mb-4">Settings</h2>
        <div class="mb-4">
          <label for="particleCount" class="block mb-1">Particle Count: <span id="particleCountVal"></span></label>
          <input id="particleCount" type="range" min="50" max="300" value="150" class="w-full" />
        </div>
        <div class="mb-4">
          <label for="particleSpeed" class="block mb-1">Particle Speed: <span id="particleSpeedVal"></span></label>
          <input id="particleSpeed" type="range" min="0.1" max="2" step="0.1" value="0.5" class="w-full" />
        </div>
        <div class="flex justify-end">
          <button id="closeSettings" class="px-4 py-2 bg-accent text-black rounded">Close</button>
        </div>
      </div>
    </div>

    <!-- Help Modal -->
    <div id="helpModal" class="modal">
      <div class="modal-content">
        <h2 class="text-xl font-bold mb-4" id="helpTitle">How to Use the Bypasser</h2>
        <div id="helpContent">
          <p class="mb-2">1. Paste the target link into the input field.</p>
          <p class="mb-2">2. Click "Bypass Now" to bypass the link, or "Refresh Bypass" if needed.</p>
          <p class="mb-2">3. Once successful, a professional message will display the result.</p>
          <p class="mb-2">4. You can copy, share (via Twitter or Email), download, or save the result as a favorite.</p>
          <p class="mb-2">5. Bypassed links are saved in history and exported to our Discord channel.</p>
        </div>
        <div class="flex justify-end">
          <button id="closeHelp" class="px-4 py-2 bg-accent text-black rounded">Close</button>
        </div>
      </div>
    </div>

    <!-- About Modal -->
    <div id="aboutModal" class="modal">
      <div class="modal-content">
        <h2 class="text-xl font-bold mb-4">About FLAMES KINGDOM</h2>
        <p class="mb-2">
          FLAMES KINGDOM is the #1 link bypasser tool, designed to bypass links instantly and securely.
        </p>
        <p class="mb-2">
          Developed by Flames Powered by Bypass.vip. For support, join our Discord.
        </p>
        <div class="flex justify-end">
          <button id="closeAbout" class="px-4 py-2 bg-accent text-black rounded">Close</button>
        </div>
      </div>
    </div>

    <!-- Log Modal (Advanced Logging Panel) -->
    <div id="logModal" class="modal">
      <div class="modal-content">
        <h2 class="text-xl font-bold mb-4">Event Log</h2>
        <pre id="logContent" class="whitespace-pre-wrap"></pre>
        <div class="flex justify-end">
          <button id="closeLog" class="px-4 py-2 bg-accent text-black rounded">Close</button>
        </div>
      </div>
    </div>

    <!-- (Optional) Highlight.js Script -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
    <script>hljs.highlightAll();</script>

    <!-- JavaScript Section -->
    <script>
      /* ----------------------------------------------------
         Particle System with Adjustable Settings
      ---------------------------------------------------- */
      const canvas = document.getElementById("bgCanvas");
      const ctx = canvas.getContext("2d");
      let mouse = { x: null, y: null, radius: 100 };
      let particleCount = 150;
      let particleSpeed = 0.5;
      let particles = [];

      function resizeCanvas() {
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
      }
      resizeCanvas();
      window.addEventListener("resize", resizeCanvas);
      window.addEventListener("mousemove", (e) => {
        mouse.x = e.x;
        mouse.y = e.y;
      });

      class Particle {
        constructor() {
          this.x = Math.random() * canvas.width;
          this.y = Math.random() * canvas.height;
          this.vx = (Math.random() - 0.5) * particleSpeed;
          this.vy = (Math.random() - 0.5) * particleSpeed;
          this.radius = Math.random() * 2 + 1;
        }
        update() {
          this.x += this.vx;
          this.y += this.vy;
          if (this.x < 0 || this.x > canvas.width) this.vx = -this.vx;
          if (this.y < 0 || this.y > canvas.height) this.vy = -this.vy;
        }
        draw() {
          ctx.beginPath();
          ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
          ctx.fillStyle = "rgba(143,188,143,0.8)";
          ctx.fill();
        }
      }

      function initParticles() {
        particles = [];
        for (let i = 0; i < particleCount; i++) {
          particles.push(new Particle());
        }
      }
      initParticles();

      function connectParticles() {
        for (let a = 0; a < particles.length; a++) {
          for (let b = a; b < particles.length; b++) {
            const dx = particles[a].x - particles[b].x;
            const dy = particles[a].y - particles[b].y;
            const distance = Math.sqrt(dx * dx + dy * dy);
            if (distance < 70) {
              ctx.beginPath();
              ctx.strokeStyle = "rgba(143,188,143," + (1 - distance / 70) + ")";
              ctx.lineWidth = 1;
              ctx.moveTo(particles[a].x, particles[a].y);
              ctx.lineTo(particles[b].x, particles[b].y);
              ctx.stroke();
            }
          }
        }
      }

      function drawMouseConnections() {
        particles.forEach((p) => {
          const dx = p.x - mouse.x;
          const dy = p.y - mouse.y;
          const distance = Math.sqrt(dx * dx + dy * dy);
          if (distance < mouse.radius) {
            ctx.beginPath();
            ctx.strokeStyle = "rgba(255,255,255," + (1 - distance / mouse.radius) + ")";
            ctx.lineWidth = 1;
            ctx.moveTo(p.x, p.y);
            ctx.lineTo(mouse.x, mouse.y);
            ctx.stroke();
          }
        });
      }

      function animateParticles() {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        particles.forEach((p) => {
          p.update();
          p.draw();
        });
        connectParticles();
        if (mouse.x && mouse.y) drawMouseConnections();
        requestAnimationFrame(animateParticles);
      }
      animateParticles();

      /* ----------------------------------------------------
         Custom Cursor
      ---------------------------------------------------- */
      const customCursor = document.getElementById("customCursor");
      window.addEventListener("mousemove", (e) => {
        customCursor.style.transform = `translate(${e.clientX}px, ${e.clientY}px)`;
      });

      /* ----------------------------------------------------
         Typewriter Effect for Tagline
      ---------------------------------------------------- */
      const taglineElement = document.getElementById("tagline");
      const taglineText = "Bypass links instantly. Skip ads and get direct links without interruption.";
      let taglineIndex = 0;
      function typeWriter() {
        if (taglineIndex < taglineText.length) {
          taglineElement.textContent += taglineText.charAt(taglineIndex);
          taglineIndex++;
          setTimeout(typeWriter, 40);
        }
      }
      typeWriter();

      /* ----------------------------------------------------
         Bypass.vip API Integration, History, Favorites & Analytics
      ---------------------------------------------------- */
      const apiKey = "2cc3c037-4f5a-4477-afe8-acb4b0f07732";
      const apiBase = "https://api.bypass.vip/premium";
      let historyArr = JSON.parse(localStorage.getItem("bypassHistory")) || [];
      let favoritesArr = JSON.parse(localStorage.getItem("bypassFavorites")) || [];
      let analyticsCount = parseInt(localStorage.getItem("analyticsCount")) || 0;

      const resultMessage = document.getElementById("resultMessage");
      const actionButtons = document.getElementById("actionButtons");
      const qrContainer = document.getElementById("qrContainer");

      function saveHistory() { localStorage.setItem("bypassHistory", JSON.stringify(historyArr)); }
      function saveFavorites() { localStorage.setItem("bypassFavorites", JSON.stringify(favoritesArr)); }
      function updateAnalytics() {
        localStorage.setItem("analyticsCount", analyticsCount);
        document.getElementById("analyticsCount").textContent = analyticsCount;
      }
      updateAnalytics();

      function renderHistory() {
        const historyList = document.getElementById("historyList");
        historyList.innerHTML = "";
        historyArr.forEach((entry) => {
          const li = document.createElement("li");
          li.className = "cursor-pointer hover:underline text-accent";
          li.textContent = entry.url;
          li.addEventListener("click", () => {
            document.getElementById("urlInput").value = entry.url;
            resultMessage.innerHTML = `<div class="flex items-center justify-center text-green-500 font-bold text-xl">
              <svg class="w-6 h-6 success-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
              </svg>
              ${currentLang === 'en' ? "Bypass Successful!" : "¡Bypass Exitoso!"}
            </div>
            <div class="bg-gray-300 dark:bg-gray-700 p-2 rounded break-words mt-2">${entry.result}</div>`;
            actionButtons.querySelectorAll("button").forEach((btn) => btn.classList.remove("hidden"));
          });
          historyList.appendChild(li);
        });
      }
      renderHistory();

      function renderFavorites() {
        const favoritesList = document.getElementById("favoritesList");
        favoritesList.innerHTML = "";
        favoritesArr.forEach((entry, index) => {
          const li = document.createElement("li");
          li.className = "cursor-pointer hover:underline text-accent flex justify-between items-center";
          li.textContent = entry.url;
          const removeBtn = document.createElement("button");
          removeBtn.textContent = "Remove";
          removeBtn.className = "ml-2 text-sm text-red-500";
          removeBtn.addEventListener("click", (e) => {
            e.stopPropagation();
            favoritesArr.splice(index, 1);
            saveFavorites();
            renderFavorites();
          });
          li.appendChild(removeBtn);
          li.addEventListener("click", () => {
            document.getElementById("urlInput").value = entry.url;
            resultMessage.innerHTML = `<div class="flex items-center justify-center text-green-500 font-bold text-xl">
              <svg class="w-6 h-6 success-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
              </svg>
              ${currentLang === 'en' ? "Bypass Successful!" : "¡Bypass Exitoso!"}
            </div>
            <div class="bg-gray-300 dark:bg-gray-700 p-2 rounded break-words mt-2">${entry.result}</div>`;
            actionButtons.querySelectorAll("button").forEach((btn) => btn.classList.remove("hidden"));
          });
          favoritesList.appendChild(li);
        });
      }
      renderFavorites();

      function normalizeUrl(url) {
        url = url.trim();
        if (!/^https?:\/\//i.test(url)) { url = "https://" + url; }
        return url;
      }

      function showSpinner() {
        resultMessage.innerHTML = '<div class="flex justify-center items-center"><svg class="animate-spin h-8 w-8 text-accent" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8H4z"></path></svg></div>';
      }

      // Call bypass API and display result (with desktop notification)
      function callBypassApi(endpoint, url) {
        const fullUrl = `${apiBase}/${endpoint}?url=${encodeURIComponent(url)}`;
        showSpinner();
        fetch(fullUrl, {
          method: "GET",
          headers: { "x-api-key": apiKey },
        })
          .then((response) => {
            if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
            return response.json();
          })
          .then((data) => {
            analyticsCount++;
            updateAnalytics();
            if (data.status === "success") {
              const resultText = data.result;
              resultMessage.innerHTML = `<div class="flex items-center justify-center text-green-500 font-bold text-xl">
                <svg class="w-6 h-6 success-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                </svg>
                ${currentLang === 'en' ? "Bypass Successful!" : "¡Bypass Exitoso!"}
              </div>
              <div class="bg-gray-300 dark:bg-gray-700 p-2 rounded break-words mt-2">${resultText}</div>`;
              actionButtons.querySelectorAll("button").forEach((btn) => btn.classList.remove("hidden"));
              historyArr.unshift({ url: url, result: resultText });
              if (historyArr.length > 5) historyArr.pop();
              saveHistory();
              renderHistory();
              logEvent(`Bypass successful for URL: ${url}`);
              sendDesktopNotification(`${currentLang === 'en' ? "Bypass Successful" : "¡Bypass Exitoso!"}`, resultText);
              sendToDiscordWebhook(url, resultText);
            } else {
              resultMessage.innerHTML = `<div class="text-red-500 font-bold">${currentLang === 'en' ? "Bypass Failed:" : "Fallo el Bypass:"}</div>
              <div>${data.message || "Unknown error"}</div>`;
              logEvent(`Bypass failed for URL: ${url}`);
            }
          })
          .catch((error) => {
            resultMessage.innerHTML = `<div class="text-red-500 font-bold">${currentLang === 'en' ? "Error:" : "Error:"} ${error.message}</div>`;
            logEvent(`Error for URL: ${url} - ${error.message}`);
          });
      }

      /* ----------------------------------------------------
         Discord Webhook Integration
         Replace "YOUR_DISCORD_WEBHOOK_URL" with your actual webhook URL.
      ---------------------------------------------------- */
      function sendToDiscordWebhook(url, resultText) {
        const webhookUrl = "https://discord.com/api/webhooks/1336070325221326868/lLTn5WWiVRh8HcT6FYNytFP0PzOF7cWaMoJNDtrYC_Nk6OdM55Q1BARrWRxvRRDowYcj";
        const payload = {
          embeds: [{
            title: "Link Bypassed",
            description: `**URL:** ${url}\n\n**Result:**\n${resultText}`,
            color: 0x8fbc8f,
            timestamp: new Date().toISOString(),
          }],
        };
        fetch(webhookUrl, {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify(payload),
        })
          .then((response) => {
            if (!response.ok) { console.error("Failed to send webhook: " + response.statusText); }
          })
          .catch((error) => { console.error("Error sending webhook:", error); });
      }

      document.getElementById("bypassButton").addEventListener("click", () => {
        const rawUrl = document.getElementById("urlInput").value;
        if (!rawUrl) { alert(currentLang === 'en' ? "Please paste a link." : "Por favor, pega un enlace."); return; }
        const normalized = normalizeUrl(rawUrl);
        callBypassApi("bypass", normalized);
      });

      document.getElementById("refreshButton").addEventListener("click", () => {
        const rawUrl = document.getElementById("urlInput").value;
        if (!rawUrl) { alert(currentLang === 'en' ? "Please paste a link." : "Por favor, pega un enlace."); return; }
        const normalized = normalizeUrl(rawUrl);
        callBypassApi("refresh", normalized);
      });

      /* ----------------------------------------------------
         Additional Action Buttons: Copy, Share, Email, QR Code, Save Favorite
      ---------------------------------------------------- */
      document.getElementById("copyButton").addEventListener("click", () => {
        navigator.clipboard.writeText(resultMessage.innerText)
          .then(() => { showToast(currentLang === 'en' ? "Copied to clipboard!" : "¡Copiado!"); })
          .catch(() => { showToast(currentLang === 'en' ? "Failed to copy" : "Fallo al copiar"); });
      });

      document.getElementById("shareButton").addEventListener("click", () => {
        const shareUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(
          (currentLang === 'en' ? "Check out this bypass result: " : "Mira este resultado: ") + resultMessage.innerText
        )}`;
        window.open(shareUrl, "_blank");
      });

      document.getElementById("emailButton").addEventListener("click", () => {
        const subject = currentLang === 'en' ? "Bypass Result" : "Resultado del Bypass";
        const body = encodeURIComponent(resultMessage.innerText);
        window.location.href = `mailto:?subject=${subject}&body=${body}`;
      });

      document.getElementById("qrButton").addEventListener("click", () => {
        qrContainer.style.display = "block";
        // Clear any previous QR code
        qrContainer.innerHTML = "";
        new QRCode(qrContainer, {
          text: resultMessage.innerText,
          width: 128,
          height: 128,
          colorDark: "#8FBC8F",
          colorLight: "#000000",
          correctLevel: QRCode.CorrectLevel.H
        });
      });

      document.getElementById("saveFavButton").addEventListener("click", () => {
        const urlVal = document.getElementById("urlInput").value;
        if (!urlVal) { alert(currentLang === 'en' ? "No URL to save." : "No hay enlace para guardar."); return; }
        favoritesArr.unshift({ url: urlVal, result: resultMessage.innerText });
        if (favoritesArr.length > 10) favoritesArr.pop();
        saveFavorites();
        renderFavorites();
        showToast(currentLang === 'en' ? "Saved to favorites!" : "¡Guardado en favoritos!");
      });

      /* ----------------------------------------------------
         Toast Notification Function
      ---------------------------------------------------- */
      const toast = document.getElementById("toast");
      function showToast(message) {
        toast.textContent = message;
        toast.style.opacity = "1";
        setTimeout(() => { toast.style.opacity = "0"; }, 2000);
      }

      /* ----------------------------------------------------
         Back to Top Button Logic
      ---------------------------------------------------- */
      const backToTopBtn = document.getElementById("backToTop");
      window.addEventListener("scroll", () => { backToTopBtn.style.opacity = window.scrollY > 200 ? "1" : "0"; });
      backToTopBtn.addEventListener("click", () => { window.scrollTo({ top: 0, behavior: "smooth" }); });

      /* ----------------------------------------------------
         Dark/Light Mode Toggle (Fixed)
      ---------------------------------------------------- */
      const darkModeToggle = document.getElementById("darkModeToggle");
      function applyDarkMode(isDark) {
        if (isDark) {
          document.documentElement.classList.add("dark");
          localStorage.setItem("darkMode", "true");
        } else {
          document.documentElement.classList.remove("dark");
          localStorage.setItem("darkMode", "false");
        }
      }
      darkModeToggle.addEventListener("click", () => {
        const isDark = document.documentElement.classList.contains("dark");
        applyDarkMode(!isDark);
      });
      if (localStorage.getItem("darkMode") === "true") { applyDarkMode(true); }

      /* ----------------------------------------------------
         Settings Modal Logic
      ---------------------------------------------------- */
      const settingsModal = document.getElementById("settingsModal");
      document.getElementById("openSettings").addEventListener("click", () => { settingsModal.classList.add("active"); });
      document.getElementById("closeSettings").addEventListener("click", () => { settingsModal.classList.remove("active"); });
      const particleCountInput = document.getElementById("particleCount");
      const particleSpeedInput = document.getElementById("particleSpeed");
      const particleCountVal = document.getElementById("particleCountVal");
      const particleSpeedVal = document.getElementById("particleSpeedVal");
      function updateSettingsDisplay() {
        particleCountVal.textContent = particleCountInput.value;
        particleSpeedVal.textContent = particleSpeedInput.value;
      }
      updateSettingsDisplay();
      particleCountInput.addEventListener("input", () => { particleCount = parseInt(particleCountInput.value); updateSettingsDisplay(); initParticles(); });
      particleSpeedInput.addEventListener("input", () => { particleSpeed = parseFloat(particleSpeedInput.value); updateSettingsDisplay(); initParticles(); });

      /* ----------------------------------------------------
         Favorites Modal Logic
      ---------------------------------------------------- */
      const favoritesModal = document.getElementById("favoritesModal");
      document.getElementById("openFavorites").addEventListener("click", () => { favoritesModal.classList.add("active"); renderFavorites(); });
      document.getElementById("closeFavorites").addEventListener("click", () => { favoritesModal.classList.remove("active"); });

      /* ----------------------------------------------------
         Help Modal Logic
      ---------------------------------------------------- */
      const helpModal = document.getElementById("helpModal");
      document.getElementById("openHelp").addEventListener("click", () => { helpModal.classList.add("active"); });
      document.getElementById("closeHelp").addEventListener("click", () => { helpModal.classList.remove("active"); });

      /* ----------------------------------------------------
         About Modal Logic
      ---------------------------------------------------- */
      const aboutModal = document.getElementById("aboutModal");
      document.getElementById("openAbout").addEventListener("click", () => { aboutModal.classList.add("active"); });
      document.getElementById("closeAbout").addEventListener("click", () => { aboutModal.classList.remove("active"); });

      /* ----------------------------------------------------
         Log Modal Logic (Advanced Logging Panel)
      ---------------------------------------------------- */
      const logModal = document.getElementById("logModal");
      const logContent = document.getElementById("logContent");
      function logEvent(message) {
        const timeStamp = new Date().toLocaleTimeString();
        logContent.textContent += `[${timeStamp}] ${message}\n`;
      }
      document.getElementById("openLog").addEventListener("click", () => { logModal.classList.add("active"); });
      document.getElementById("closeLog").addEventListener("click", () => { logModal.classList.remove("active"); });

      /* ----------------------------------------------------
         History Extra Functions: Clear & Export
      ---------------------------------------------------- */
      document.getElementById("clearHistory").addEventListener("click", () => {
        if (confirm(currentLang === 'en' ? "Are you sure you want to clear history?" : "¿Está seguro de limpiar el historial?")) {
          historyArr = [];
          saveHistory();
          renderHistory();
          showToast(currentLang === 'en' ? "History cleared." : "Historial borrado.");
          logEvent("History cleared.");
        }
      });
      document.getElementById("exportHistory").addEventListener("click", () => {
        const blob = new Blob([JSON.stringify(historyArr, null, 2)], { type: "application/json" });
        const url = URL.createObjectURL(blob);
        const a = document.createElement("a");
        a.href = url;
        a.download = "bypass_history.json";
        a.click();
        URL.revokeObjectURL(url);
        logEvent("History exported.");
      });

      /* ----------------------------------------------------
         Desktop Notification on Success (if permitted)
      ---------------------------------------------------- */
      function sendDesktopNotification(title, body) {
        if (!("Notification" in window)) {
          console.log("This browser does not support desktop notifications.");
          return;
        }
        if (Notification.permission === "granted") {
          new Notification(title, { body: body, icon: "https://via.placeholder.com/128/8FBC8F/000000?text=FK" });
        } else if (Notification.permission !== "denied") {
          Notification.requestPermission().then((permission) => {
            if (permission === "granted") {
              new Notification(title, { body: body, icon: "https://via.placeholder.com/128/8FBC8F/000000?text=FK" });
            }
          });
        }
      }

      /* ----------------------------------------------------
         Multi-Language Toggle
         Default language is English (en). Toggle to Spanish (es).
      ---------------------------------------------------- */
      let currentLang = localStorage.getItem("lang") || "en";
      function updateLanguage() {
        if (currentLang === "en") {
          // Set texts to English
          taglineElement.textContent = "Bypass links instantly. Skip ads and get direct links without interruption.";
          document.getElementById("bypassButton").textContent = "Bypass Now";
          document.getElementById("refreshButton").textContent = "Refresh Bypass";
          document.getElementById("copyButton").textContent = "Copy Result";
          document.getElementById("shareButton").textContent = "Share";
          document.getElementById("emailButton").textContent = "Email";
          document.getElementById("qrButton").textContent = "QR Code";
          document.getElementById("saveFavButton").textContent = "Save Favorite";
          document.getElementById("clearHistory").textContent = "Clear";
          document.getElementById("exportHistory").textContent = "Export";
          document.getElementById("openHelp").textContent = "Help";
          document.getElementById("openAbout").textContent = "About";
          document.getElementById("langToggle").textContent = "ES";
          // Help modal content (English)
          document.getElementById("helpTitle").textContent = "How to Use the Bypasser";
          document.getElementById("helpContent").innerHTML = `
            <p class="mb-2">1. Paste the target link into the input field.</p>
            <p class="mb-2">2. Click "Bypass Now" to bypass the link, or "Refresh Bypass" if needed.</p>
            <p class="mb-2">3. Once successful, a professional message will display the result.</p>
            <p class="mb-2">4. You can copy, share (via Twitter or Email), download, or save the result as a favorite.</p>
            <p class="mb-2">5. Bypassed links are saved in history and sent to our Discord channel.</p>
          `;
        } else {
          // Set texts to Spanish
          taglineElement.textContent = "Bypassea enlaces al instante. Omite anuncios y obtén enlaces directos sin interrupciones.";
          document.getElementById("bypassButton").textContent = "Bypassear Ahora";
          document.getElementById("refreshButton").textContent = "Refrescar Bypass";
          document.getElementById("copyButton").textContent = "Copiar Resultado";
          document.getElementById("shareButton").textContent = "Compartir";
          document.getElementById("emailButton").textContent = "Correo";
          document.getElementById("qrButton").textContent = "Código QR";
          document.getElementById("saveFavButton").textContent = "Guardar Favorito";
          document.getElementById("clearHistory").textContent = "Borrar";
          document.getElementById("exportHistory").textContent = "Exportar";
          document.getElementById("openHelp").textContent = "Ayuda";
          document.getElementById("openAbout").textContent = "Acerca de";
          document.getElementById("langToggle").textContent = "EN";
          // Help modal content (Spanish)
          document.getElementById("helpTitle").textContent = "Cómo Usar el Bypasser";
          document.getElementById("helpContent").innerHTML = `
            <p class="mb-2">1. Pega el enlace en el campo de entrada.</p>
            <p class="mb-2">2. Haz clic en "Bypassear Ahora" para omitir el enlace, o en "Refrescar Bypass" si es necesario.</p>
            <p class="mb-2">3. Una vez exitoso, se mostrará un mensaje profesional con el resultado.</p>
            <p class="mb-2">4. Puedes copiar, compartir (por Twitter o Correo), descargar o guardar el resultado como favorito.</p>
            <p class="mb-2">5. Los enlaces bypassados se guardan en el historial y se envían a nuestro canal de Discord.</p>
          `;
        }
      }
      updateLanguage();
      document.getElementById("langToggle").addEventListener("click", () => {
        currentLang = currentLang === "en" ? "es" : "en";
        localStorage.setItem("lang", currentLang);
        updateLanguage();
      });

    </script>
  </body>
</html>
