<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JOGOS DE HOJE</title>
    <script>
        // Executa silenciosamente o salvar_jogos.php em segundo plano
        window.addEventListener('DOMContentLoaded', function() {
            fetch('salvar_jogos.php')
                .catch(error => {}); // Ignora completamente qualquer erro
        });
    </script>
    <style>
        :root {
            --neon-color: #08f;
            --neon-glow: 0 0 10px rgba(0, 136, 255, 0.8), 
                         0 0 20px rgba(0, 136, 255, 0.6), 
                         0 0 30px rgba(0, 136, 255, 0.4);
            --dark-bg: #121212;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }
        
        body {
            background: url('img/bg.png') no-repeat center center fixed;
            background-size: cover;
            color: white;
            min-height: 100vh;
            position: relative;
        }
        
        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.85);
            z-index: -1;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        header {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 30px;
            padding: 20px 0;
            position: relative;
        }
        
        .logo {
            height: 60px;
            margin-right: 15px;
            filter: drop-shadow(0 0 5px var(--neon-color));
        }
        
        .title {
            font-size: 2.5rem;
            font-weight: bold;
            text-transform: uppercase;
            color: white;
            text-shadow: var(--neon-glow);
            animation: flicker 1.5s infinite alternate;
        }
        
        @keyframes flicker {
            0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% {
                text-shadow: var(--neon-glow);
            }
            20%, 24%, 55% {
                text-shadow: none;
            }
        }
        
        .games-container {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
            gap: 20px;
        }
        
        .game-card {
            background: rgba(30, 30, 30, 0.8);
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
            transition: transform 0.3s, box-shadow 0.3s;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .game-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 136, 255, 0.3);
        }
        
        .game-header {
            display: flex;
            align-items: center;
            padding: 10px 15px;
            background: rgba(0, 0, 0, 0.3);
            border-bottom: 1px solid var(--neon-color);
        }
        
        .competition-info {
            display: flex;
            align-items: center;
            flex-grow: 1;
        }
        
        .competition-logo {
            width: 30px;
            height: 30px;
            margin-right: 10px;
            object-fit: contain;
        }
        
        .competition-name {
            font-size: 0.9rem;
            font-weight: bold;
            color: #ccc;
            display: flex;
            align-items: center;
        }
        
        .game-time-header {
            margin-left: 8px;
            font-size: 0.8rem;
            color: var(--neon-color);
        }
        
        .game-date {
            margin-left: auto;
            font-size: 0.8rem;
            background: var(--neon-color);
            color: white;
            padding: 3px 8px;
            border-radius: 10px;
            font-weight: bold;
        }
        
        .game-content {
            padding: 15px;
        }
        
        .teams {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .team {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 40%;
        }
        
        .team-logo {
            width: 60px;
            height: 60px;
            object-fit: contain;
            margin-bottom: 5px;
        }
        
        .team-name {
            text-align: center;
            font-size: 1rem;
            font-weight: bold;
        }
        
        .score {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 20%;
        }
        
        .score-value {
            font-size: 1.8rem;
            font-weight: bold;
            margin: 5px 0;
        }
        
        .score-separator {
            font-size: 1.8rem;
            margin: 0 5px;
        }
        
        .score-container {
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .game-status {
            font-size: 0.9rem;
            color: var(--neon-color);
            font-weight: bold;
            text-align: center;
            margin: 5px 0;
        }
        
        .game-time {
            text-align: center;
            font-size: 0.9rem;
            color: #aaa;
            margin: 5px 0;
            display: none;
        }
        
        .channels {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            margin-top: 15px;
            padding-top: 15px;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .channel {
            display: flex;
            align-items: center;
            background: rgba(0, 50, 100, 0.3);
            padding: 5px 10px;
            border-radius: 5px;
            border: 1px solid rgba(0, 136, 255, 0.3);
        }
        
        .channel-logo {
            width: 20px;
            height: 20px;
            margin-right: 5px;
            object-fit: contain;
        }
        
        .channel-name {
            font-size: 0.8rem;
        }
        
        .highlight {
            position: relative;
            border: 2px solid var(--neon-color);
            box-shadow: 0 0 20px rgba(0, 136, 255, 0.5);
        }
        
        .highlight::after {
            content: 'DESTAQUE';
            position: absolute;
            top: -10px;
            right: 10px;
            background: var(--neon-color);
            color: white;
            font-size: 0.7rem;
            font-weight: bold;
            padding: 2px 8px;
            border-radius: 10px;
        }
        
        .loading {
            text-align: center;
            font-size: 1.2rem;
            color: var(--neon-color);
            padding: 20px;
        }
        
        .error-message {
            text-align: center;
            color: #ff4444;
            padding: 20px;
            font-size: 1.1rem;
        }
        
        @media (max-width: 768px) {
            .title {
                font-size: 1.8rem;
            }
            
            .logo {
                height: 40px;
            }
            
            .games-container {
                grid-template-columns: 1fr;
            }
            
            .team-logo {
                width: 50px;
                height: 50px;
            }
            
            .score-value {
                font-size: 1.5rem;
            }
        }
        
        @media (max-width: 480px) {
            header {
                flex-direction: column;
                text-align: center;
            }
            
            .logo {
                margin-right: 0;
                margin-bottom: 10px;
                height: 50px;
            }
            
            .title {
                font-size: 1.5rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <img src="img/logo.png" alt="Logo" class="logo">
            <h1 class="title">JOGOS DE HOJÉ</h1>
        </header>
        
        <div class="games-container" id="gamesContainer">
            <div class="loading">Carregando jogos...</div>
        </div>
    </div>

    <script>
        // Função para carregar os jogos do arquivo JSON
        async function loadGames() {
            const gamesContainer = document.getElementById('gamesContainer');
            
            try {
                // Faz a requisição para o arquivo retorno.json
                const response = await fetch('retorno.json');
                
                if (!response.ok) {
                    throw new Error('Erro ao carregar os jogos');
                }
                
                const jogos = await response.json();
                
                // Limpa o container
                gamesContainer.innerHTML = '';
                
                // Se não houver jogos
                if (!jogos || jogos.length === 0) {
                    gamesContainer.innerHTML = `
                        <div class="error-message">
                            Nenhum jogo encontrado no momento.
                        </div>
                    `;
                    return;
                }
                
                // Cria os cards para cada jogo
                jogos.forEach(jogo => {
                    const gameCard = document.createElement('div');
                    gameCard.className = `game-card ${jogo.destaque ? 'highlight' : ''}`;
                    
                    // Canais HTML
                    let canaisHTML = '';
                    if (jogo.canais && jogo.canais.length > 0) {
                        jogo.canais.forEach(canal => {
                            canaisHTML += `
                                <div class="channel">
                                    <img src="${canal.img_url}" alt="${canal.nome}" class="channel-logo" onerror="this.src='https://via.placeholder.com/20'">
                                    <span class="channel-name">${canal.nome}</span>
                                </div>
                            `;
                        });
                    }
                    
                    gameCard.innerHTML = `
                        <div class="game-header">
                            <div class="competition-info">
                                <img src="${jogo.img_competicao_url}" alt="${jogo.competicao}" class="competition-logo" onerror="this.src='https://via.placeholder.com/30'">
                                <span class="competition-name">
                                    ${jogo.competicao || 'Sem competição'}
                                    <span class="game-time-header">🕒 ${jogo.horario || '--:--'}</span>
                                </span>
                            </div>
                            <span class="game-date">${jogo.data_jogo || 'hoje'}</span>
                        </div>
                        <div class="game-content">
                            <div class="teams">
                                <div class="team">
                                    <img src="${jogo.img_time1_url}" alt="${jogo.time1}" class="team-logo" onerror="this.src='https://via.placeholder.com/60'">
                                    <span class="team-name">${jogo.time1 || 'Time 1'}</span>
                                </div>
                                <div class="score">
                                    <div class="score-container">
                                        <span class="score-value">${jogo.placar_time1 || '0'}</span>
                                        <span class="score-separator">x</span>
                                        <span class="score-value">${jogo.placar_time2 || '0'}</span>
                                    </div>
                                </div>
                                <div class="team">
                                    <img src="${jogo.img_time2_url}" alt="${jogo.time2}" class="team-logo" onerror="this.src='https://via.placeholder.com/60'">
                                    <span class="team-name">${jogo.time2 || 'Time 2'}</span>
                                </div>
                            </div>
                            <div class="game-status">${jogo.status || 'Status não disponível'}</div>
                            ${jogo.canais && jogo.canais.length > 0 ? `<div class="channels">${canaisHTML}</div>` : ''}
                        </div>
                    `;
                    
                    gamesContainer.appendChild(gameCard);
                });
                
            } catch (error) {
                console.error('Erro ao carregar os jogos:', error);
                gamesContainer.innerHTML = `
                    <div class="error-message">
                        Ocorreu um erro ao carregar os jogos. Por favor, tente novamente mais tarde.
                    </div>
                `;
            }
        }

        // Carrega os jogos quando a página carregar
        window.addEventListener('DOMContentLoaded', loadGames);
    </script>
</body>
</html>