<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Sports Guide</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background: #0a0a0a;
            font-family: 'Roboto', Arial, sans-serif;
            overflow: hidden;
        }

        /* Loading Screen */
        #loading {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 9999;
            transition: opacity 0.5s ease;
        }

        #loading.hidden {
            opacity: 0;
            pointer-events: none;
        }

        .spinner {
            width: 50px;
            height: 50px;
            border: 4px solid rgba(255, 255, 255, 0.1);
            border-top-color: #4CAF50;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        .loading-text {
            color: #fff;
            margin-top: 20px;
            font-size: 16px;
            letter-spacing: 1px;
        }

        /* Header */
        #header {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 50px;
            background: linear-gradient(90deg, #1e3c72 0%, #2a5298 100%);
            box-shadow: 0 2px 10px rgba(0,0,0,0.3);
            display: flex;
            align-items: center;
            padding: 0 20px;
            z-index: 100;
        }

        #header h1 {
            color: #fff;
            font-size: 18px;
            font-weight: 500;
            letter-spacing: 0.5px;
        }

        /* Iframe Container */
        #iframe-container {
            position: absolute;
            top: 50px;
            left: 0;
            right: 0;
            bottom: 0;
            background: #000;
        }

        iframe {
            display: block;
            width: 100%;
            height: 100%;
            border: none;
            background: transparent;
        }

        /* Error State */
        #error {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
            color: #fff;
            padding: 30px;
        }

        #error.show {
            display: block;
        }

        .error-icon {
            font-size: 60px;
            margin-bottom: 20px;
        }

        .error-text {
            font-size: 18px;
            margin-bottom: 10px;
        }

        .retry-btn {
            margin-top: 20px;
            padding: 12px 30px;
            background: #4CAF50;
            color: #fff;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .retry-btn:hover {
            background: #45a049;
        }
    </style>
</head>
<body>
    <!-- Loading Screen -->
    <div id="loading">
        <div class="spinner"></div>
        <div class="loading-text">Cargando Sports Guide...</div>
    </div>

    <!-- Header -->
    <div id="header">
        <h1>📺 Sports Guide</h1>
    </div>

    <!-- Iframe Container -->
    <div id="iframe-container">
        <?php
        $url = "https://sport-tv-guide.live/widgetsingle/5ae7b9142f55?list=3&id=1&time_zone=America%2FLima&sport=1&fc=63,102&time12=1&lng=3";
        ?>
        <iframe id="iframe" src="<?=$url?>" allowfullscreen></iframe>
    </div>

    <!-- Error State -->
    <div id="error">
        <div class="error-icon">⚠️</div>
        <div class="error-text">Error al cargar el contenido</div>
        <button class="retry-btn" onclick="retryLoad()">Reintentar</button>
    </div>

    <script>
        const loading = document.getElementById('loading');
        const iframe = document.getElementById('iframe');
        const error = document.getElementById('error');
        
        // Hide loading when iframe loads
        iframe.addEventListener('load', function() {
            setTimeout(() => {
                loading.classList.add('hidden');
            }, 500);
        });

        // Show error if iframe fails to load
        iframe.addEventListener('error', function() {
            loading.classList.add('hidden');
            error.classList.add('show');
        });

        // Retry function
        function retryLoad() {
            error.classList.remove('show');
            loading.classList.remove('hidden');
            iframe.src = iframe.src;
        }

        // Timeout fallback (hide loading after 10 seconds)
        setTimeout(() => {
            if (!loading.classList.contains('hidden')) {
                loading.classList.add('hidden');
            }
        }, 10000);
    </script>
</body>
</html>
