<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SATYAM</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
    <style>
        body {
            background-image: url('1.jpg');
            font-family: 'Poppins', sans-serif;
            text-align: center;
            background: linear-gradient(45deg, #2f80ed, #56ccf2);
            color: white;
            padding: 20px;
        }
        h1 {
            color: red;
            font-size: 2.2em;
            font-weight: 600;
        }
        .container {
            padding: 20px;
            background: rgba(0, 0, 0, 0.5);
            border-radius: 10px;
            display: inline-block;
            box-shadow: 0 0 20px black;
        }
        .info {
            color: red;
            font-size: 1.2em;
            margin-bottom: 10px;
            padding: 10px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: 5px;
            box-shadow: 0 0 10px black;
            background: rgba(255, 255, 255, 0.1);
        }
        .inf {
            color: gold;
            font-size: 1.2em;
            margin-bottom: 10px;
            padding: 10px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: 5px;
            box-shadow: 0 0 10px black;
            background: rgba(255, 255, 255, 0.1);
        }
        .history {
            color: yellow;
            max-height: 150px;
            overflow-y: auto;
            background: rgba(255, 255, 255, 0.2);
            padding: 8px;
            border-radius: 4px;
            box-shadow: 0 0 10px black;
        }
        button {
            margin-top: 10px;
            padding: 10px 15px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1em;
            color: white;
            background: rgba(255, 0, 0, 0.7);
            transition: background 0.3s;
        }
        button:hover {
            background: rgba(255, 0, 0, 1);
        }
        #clearHistoryButton {
            background: red;
        }
        #clearHistoryButton:hover {
            background: darkred;
        }
        #telegramButton {
            background: black;
        }
        #telegramButton:hover {
            background: silver;
        }
        .text {
            color: blue;
            background: pink;
            font-size: 1em;
        }
    </style>
</head>
<body>
    <div id="satyam" class="text">WINGO 30SEC</div>
    <h1>MAKE BY :- SATYAM</h1>
    <div class="container">
        <div id="periodNumber" class="info">Period: Loading...</div>
        <div id="result" class="inf">Result: -</div>
        <button id="clearHistoryButton">Clear History</button>
    </div>
    <button id="telegramButton" onclick="openTelegram()">Join us on Telegram</button>
    <h2>History</h2>
    <div id="history" class="history"></div>

    <script>
        let lastPeriod = null;

        function generatePeriodNumber() {
            const now = new Date();
            const hours = now.getHours();
            const minutes = now.getMinutes();
            const seconds = now.getSeconds();

            const totalSeconds = (hours * 3600) + (minutes * 60) + seconds;
            const offset = 19800; // Offset for 5 hours 30 minutes (in seconds)
            const currentDate = now.toISOString().split('T')[0].replace(/-/g, ''); // yyyyMMdd format

            const periodCalculation = 10001 + Math.floor((totalSeconds - offset) / 30);
            const periodNumber = currentDate + "1000" + periodCalculation;

            return { periodNumber, periodCalculation };
        }

        function calculateResult(periodCalculation) {
            let digitSum = Array.from(String(periodCalculation), Number).reduce((sum, num) => sum + num, 0);

            while (digitSum >= 10) {
                digitSum = Array.from(String(digitSum), Number).reduce((sum, num) => sum + num, 0);
            }

            return digitSum <= 4 ? "SMALL" : "BIG";
        }

        function updatePeriod() {
            const { periodNumber, periodCalculation } = generatePeriodNumber();

            // Prevent duplicate updates
            if (periodNumber === lastPeriod) return;

            lastPeriod = periodNumber;
            const result = calculateResult(periodCalculation);
            const currentTime = new Date().toLocaleTimeString();

            // Extract the last three digits
            const lastThreeDigits = periodNumber.slice(-3);

            document.getElementById('periodNumber').innerText = `Period: ${lastThreeDigits}`;
            document.getElementById('result').innerText = `Result: ${result}`;

            const historyEntry = `Period: ${lastThreeDigits}, Result: ${result}`;
            document.getElementById('history').innerHTML += `<div>${historyEntry}</div>`;
        }

        function startAutoUpdate() {
            updatePeriod();
            setInterval(updatePeriod, 1000); // Update every second in the background
        }

        function openTelegram() {
            window.open("https://t.me/devil_air", "_blank"); // Opens Telegram link in a new tab
        }

        document.getElementById('clearHistoryButton').addEventListener('click', function() {
            document.getElementById('history').innerHTML = '';
            document.getElementById('periodNumber').innerText = 'Period: Loading...';
            document.getElementById('result').innerTex
t = 'Result: -';
            lastPeriod = null;
        });

        // Start the automatic period update
        startAutoUpdate();
    </script>
</body>
</html>