<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Live Stream</title>
    <link rel="stylesheet" href="styles.css">
    <script src="script.js"></script>
    <script src="https://resources.blogblog.com/blogblog/data/res/3315978748-indie_compiled.js" async="true"></script> <!-- External script -->
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html, body {
            width: 100%;
            height: 100%;
            overflow: hidden;
            background-color: black;
        }

        .player-container {
            width: 100%;
            height: 100%;
        }

        .player-container iframe {
            width: 100%;
            height: 100%;
            border: none;
        }

        /* Overlay background */
        .overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.7);
            z-index: 999;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        /* Popup container */
        .popup {
            background-color: #1c1c1e;
            border-radius: 10px;
            width: 90%;
            max-width: 400px;
            text-align: center;
            padding: 20px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            color: #ffffff;
        }

        .popup h3 {
            margin: 0 0 10px;
            color: #ffd700; /* Gold color for "Support Us!" */
        }

        .popup p {
            font-size: 14px;
            margin-bottom: 20px;
            color: #d1d1d1;
        }

        .popup button {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            border: none;
            border-radius: 5px;
            margin-bottom: 10px;
            cursor: pointer;
        }

        .popup button.join-now {
            background-color: #007bff;
            color: white;
        }

        .popup button.already-joined {
            background-color: #6c757d;
            color: white;
        }
    </style>
</head>
<body>

    <div class="player-container">
        <iframe 
            id="contentFrame" 
            sandbox="allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation" 
            allow="encrypted-media" 
            allowfullscreen="true" 
            src="http://CrxcShivamlive.pages.dev/Tnt1">
        </iframe>
    </div>

    <div class="overlay" id="popupOverlay" style="display: none;">
        <div class="popup">
            <h3>Support Us!</h3>
            <p>Join our Telegram channel <strong>@CricMantrahd</strong> for more updates.</p>
            <button class="join-now" onclick="joinNow()">Join Now</button>
            <button class="already-joined" onclick="closePopup()">Already Joined</button>
        </div>
    </div>

    <script>
        /**
         * Get the value of a query parameter from the URL.
         * @param {string} param - The name of the query parameter.
         * @returns {string|null} - The value of the query parameter, or null if it doesn't exist.
         */
        function getQueryParam(param) {
            const params = new URLSearchParams(window.location.search);
            return params.get(param);
        }

        /**
         * Decodes the input string using the a ↔ z, b ↔ y, c ↔ x logic.
         * @param {string} encodedStr - The encoded string.
         * @returns {string} - The decoded string.
         */
        function reverseAlphabetMapping(encodedStr) {
            const alphabet = 'abcdefghijklmnopqrstuvwxyz';

const reverseAlphabet = 'zyxwvutsrqponmlkjihgfedcba';
            let decodedStr = '';
            
            for (let char of encodedStr) {
                if (alphabet.includes(char)) {
                    const index = alphabet.indexOf(char);
                    decodedStr += reverseAlphabet[index];
                } else if (alphabet.includes(char.toLowerCase())) {
                    const index = alphabet.indexOf(char.toLowerCase());
                    decodedStr += reverseAlphabet[index].toUpperCase();
                } else {
                    // Non-alphabet characters remain unchanged (like :, /, ., etc.)
                    decodedStr += char;
                }
            }

            return decodedStr;
        }

        /**
         * Sets the source of the iframe using the decoded URL from the "q" parameter.
         */
        function setIframeSource() {
            const encodedUrl = getQueryParam('q'); // Get the value of "q" from the URL
            if (encodedUrl) {
                const decodedUrl = reverseAlphabetMapping(encodedUrl); // Decode the URL
                const iframe = document.getElementById('contentFrame');
                iframe.src = https://${decodedUrl}; // Add "https://" prefix to make it a valid URL
                console.log('Decoded URL:', decodedUrl);
            } else {
                console.error('No "q" parameter found in the URL.');
            }
        }

        // Set the iframe source when the page loads
        window.onload = function() {
            setIframeSource(); // Call iframe setup
            document.getElementById("popupOverlay").style.display = "flex"; // Show the popup
            if (confirm("Join Here To Play Link")) {
                window.location.href = "https://t.me/+kfJZ4exLottkOTY1"; // Telegram link
            }
        };

        // Function to handle the "Join Now" button
        function joinNow() {
            window.location.href = "https://t.me/+kfJZ4exLottkOTY1"; // Telegram link
        }

        // Function to close the popup
        function closePopup() {
            document.getElementById("popupOverlay").style.display = "none";
        }
    </script>

</body>
</html>