<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TANMAY Prediction with AutoPeriod</title>
    <style>
        body {
            margin: 0;
            font-family: 'Arial', sans-serif;
            background-color: #1e1e2d;
            color: white;
            display: flex;
            flex-direction: column;
            height: 100vh;
        }

        /* Prediction Bar Container */
        .prediction-container {
            background-color: #292a3d;
            width: 100%;
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            box-sizing: border-box;
            border-radius: 15px; /* Curved edges for prediction bar */
        }

        /* Header Section */
        .header {
            text-align: center;
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 10px;
        }

        /* Prediction Bar */
        .prediction-bar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 90%;
        }

        /* Sliders */
        .sliders {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .slider-label {
            display: flex;
            align-items: center;
            font-size: 12px;
            gap: 5px;
        }

        .slider-label input {
            width: 30px;
            height: 15px;
            -webkit-appearance: none;
            appearance: none;
            background-color: #444;
            border-radius: 15px;
            position: relative;
            cursor: pointer;
            outline: none;
        }

        .slider-label input:checked {
            background-color: #007bff;
        }

        .slider-label input::before {
            content: '';
            position: absolute;
            width: 12px;
            height: 12px;
            background-color: white;
            border-radius: 50%;
            top: 1px;
            left: 2px;
            transition: all 0.3s ease;
        }

        .slider-label input:checked::before {
            left: 16px;
        }

        /* Prediction Section */
        .prediction-box {
            background-color: #33334c;
            padding: 5px 10px;
            border-radius: 15px;
            font-size: 12px;
            font-weight: bold;
            text-align: center;
            color: #ffeb3b;
            flex: 1;
            margin: 0 10px;
        }

        /* Timer Box */
        .timer-box {
            background-color: #444;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 14px;
            font-weight: bold;
            color: white;
        }

        /* Period Box */
        .period-box {
            margin-top: 5px;
            font-size: 12px;
            font-weight: bold;
            text-align: center;
            color: #f2f2f2;
        }

        /* WebView */
        .webview-container {
            flex: 3;
            width: 100%;
            background-color: #fff;
            overflow: hidden;
        }

        .webview {
            width: 100%;
            height: 100%;
            border: none;
        }

        /* Wait Message */
        .wait-message {
            font-size: 14px;
            font-weight: bold;
            color: #ff5733;
            margin-top: 10px;
            display: none; /* Hidden by default */
        }
    </style>
</head>
<body>
    <!-- Prediction Bar Container -->
    <div class="prediction-container">
        <!-- Header Section -->
        <div class="header">ALL GAME Prediction</div>

        <!-- Period Box -->
        <div class="period-box" id="period1m">Period: -</div>

        <!-- Prediction Bar -->
        <div class="prediction-bar">
            <!-- Sliders -->
            <div class="sliders">
                <label class="slider-label">
                    Big/Small
                    <input type="radio" name="prediction" id="bigSmall" onclick="setPredictionType('BIG/SMALL')">
                </label>
                <label class="slider-label">
                    Red/Green
                    <input type="radio" name="prediction" id="redGreen" onclick="setPredictionType('RED/GREEN')">
                </label>
                <label class="slider-label">
                    Number
                    <input type="radio" name="prediction" id="number" onclick="setPredictionType('NUMBER')">
                </label>
            </div>

            <!-- Prediction Result -->
            <div class="prediction-box" id="predictionBox">
                Next result is: -
            </div>

            <!-- Timer -->
            <div class="timer-box" id="timerBox">60</div>
        </div>

        <!-- Wait for New Period Message -->
        <div class="wait-message" id="waitMessage">Wait for the New Period...</div>
    </div>

    <!-- WebView Container -->
    <div class="webview-container">
        <iframe class="webview" id="webview" src="https://91123.in"></iframe>
    </div>

    <script>
        let predictionType = null; // Stores the current prediction type
        let periodEnded = true; // Flag to check if the period has ended
        let waitingForNewPeriod = false; // Flag to show wait message
        const predictionBox = document.getElementById('predictionBox');
        const timerBox = document.getElementById('timerBox');
        const periodBox = document.getElementById('period1m'); // Period Box Element
        const waitMessage = document.getElementById('waitMessage'); // Wait message element

        // Set Prediction Type
        function setPredictionType(type) {
            predictionType = type; // Set the prediction type based on the selected slider
            generateResult();
        }

        // Generate Prediction Result
        function generateResult() {
            if (periodEnded) {
                let result = '';
                if (predictionType === 'BIG/SMALL') {
                    result = Math.random() < 0.5 ? 'BIG' : 'SMALL';
                } else if (predictionType === 'RED/GREEN') {
                    result = Math.random() < 0.5 ? 'RED' : 'GREEN';
                } else if (predictionType === 'NUMBER') {
                    result = Math.floor(Math.random() * 10); // Random number between 0-9
                } else {
                    result = 'Select Prediction Type';
                }
                predictionBox.textContent = `Next result is: ${result}`;
                periodEnded = false; // Mark the period as ended after showing the result
                waitMessage.style.display = 'none'; // Hide wait message after generating result
            }
        }

        // Timer and AutoPeriod Functionality
        function startAutoPeriod() {
            setInterval(() => {
                // Get Current Time
                const calendar = new Date();
                const seconds = calendar.getUTCSeconds();
                const remainingSeconds = 60 - seconds;
                const minutes = calendar.getUTCMinutes();
                const hours = calendar.getUTCHours();

                // Calculate Total Minutes since Midnight UTC
                const totalMinutes = hours * 60 + minutes;

                // Update Period Number (formatted as yyyyMMdd1000XXXXX)
                const periodNumber = `${calendar.getUTCFullYear()}${(calendar.getUTCMonth() + 1).toString().padStart(2, '0')}${calendar.getUTCDate().toString().padStart(2, '0')}1000${(10001 + totalMinutes)}`;
                periodBox.textContent = `Period: ${periodNumber}`;

                // Update Timer Display
                timerBox.textContent = remainingSeconds.toString().padStart(2, '0');

                // Automatically Generate New Result at the Start of Each Period
                if (remainingSeconds === 60 && predictionType) {
                    periodEnded = true; // Reset flag to allow new result
                    waitMessage.style.display = 'block'; // Show "Wait for New Period" message
                    generateResult(); // Generate result for the new period
                }
            }, 1000); // Update every second
        }

        // Initialize AutoPeriod
        window.onload = startAutoPeriod;
    </script>
</body>
</html>
