<?php
/**
 * Plugin Name: InterFutbol Layout - Safety Net
 * Description: Registers [interfutbol_layout] shortcode. Must-use plugin - always loaded, cannot be deactivated.
 * Version: 1.0
 */
if (!defined("ABSPATH")) exit;


if (!function_exists('get_champions_league_scores')) {
function get_champions_league_scores() {
    $cache_key = 'cl_scores_cache';
    if (isset($_GET['clear_cache'])) delete_transient($cache_key);
    $cached = get_transient($cache_key);
    if ($cached !== false) return $cached;
    $matches = array();
    $url = 'https://www.thesportsdb.com/api/v1/json/3/eventsnextleague.php?id=492';
    $r = wp_remote_get($url, array('timeout' => 3));
    if (!is_wp_error($r)) {
        $d = json_decode(wp_remote_retrieve_body($r), true);
        if (!empty($d['events'])) $matches = array_slice($d['events'], 0, 8);
    }
    if (empty($matches)) {
        $url = 'https://www.thesportsdb.com/api/v1/json/3/eventspastleague.php?id=492';
        $r = wp_remote_get($url, array('timeout' => 3));
        if (!is_wp_error($r)) {
            $d = json_decode(wp_remote_retrieve_body($r), true);
            if (!empty($d['events'])) $matches = array_slice(array_reverse($d['events']), 0, 8);
        }
    }
    if (empty($matches) && function_exists('iff_season_fallback_events')) {
        $matches = iff_season_fallback_events(492, ['2025-2026', '2026-2027', '2025'], 'cl_scores_fallback');
    }
    set_transient($cache_key, $matches, 1500);
    return $matches;
}
}

    if (!function_exists('interfutbol_dynamic_layout')) {
    function interfutbol_dynamic_layout() {
        // Pagination support
        $paged = max(1, get_query_var('paged', 1));
        if ($paged == 1) {
            $paged = max(1, get_query_var('page', 1));
        }
        $per_page = 15;

        // Get posts for main content with pagination
        $args = array(
            'posts_per_page' => $per_page,
            'paged' => $paged,
            'post_status' => 'publish',
            'orderby' => 'date',
            'order' => 'DESC',
            'cache_results' => false,
            'update_post_meta_cache' => false,
            'update_post_term_cache' => false
        );

        $query = new WP_Query($args);
        $posts = $query->posts;
        $total_pages = $query->max_num_pages;

        // Fetch videos early so they can be injected inline between posts
        $videos = function_exists('get_latest_youtube_videos') ? get_latest_youtube_videos() : [];

        $posts_html = '';
        $post_count = 0;
        $inline_video_idx = 0;

        foreach ($posts as $post) {
            setup_postdata($post);
            $post_count++;

            $title     = get_the_title($post->ID);
            $excerpt   = wp_trim_words(get_the_excerpt($post->ID), 30) . '...';
            $date      = get_the_date('Y-m-d', $post->ID);
            $link      = get_permalink($post->ID);
            $thumbnail = get_the_post_thumbnail_url($post->ID, 'thumbnail');

            $image_cell = '';
            $views = (int) get_post_meta($post->ID, '_iff_views', true);
            if ($thumbnail) {
                $image_cell = '
                    <td width="150" valign="top" style="padding-right: 10px;">
                        <div style="width: 150px; height: 150px; overflow: hidden; position: relative; background: #f0f0f0;">
                            <img src="' . esc_url($thumbnail) . '" loading="lazy" style="width: 100%; height: 100%; object-fit: cover; object-position: center center; display: block;" alt="' . esc_attr($title) . '">
                        </div>
                    </td>';
            }

            $posts_html .= '
            <table width="100%" border="1" bordercolor="#ccc" cellpadding="6" cellspacing="0" style="margin-bottom: 15px; background: #fff;">
                <tr>
                    ' . $image_cell . '
                    <td valign="top">
                        <h3 style="margin: 0; font-size: 15px;"><a href="' . esc_url($link) . '" style="color: #c00; text-decoration: none;">' . esc_html($title) . '</a></h3>
                        <p style="font-size: 13px; color: #666; margin: 3px 0 8px 0;">' . esc_html($date) . ' &nbsp;<span style="color:#bbb;">|</span>&nbsp; <span style="color:#aaa;">' . number_format($views) . ' кўришлар</span></p>
                        <p style="line-height: 1.2; margin: 0; font-size: 15px;">' . esc_html($excerpt) . '</p>
                    </td>
                </tr>
            </table>';

            // ── Inject video card after every 4th post (ESPN style) ──
            if ($post_count % 4 === 0 && !empty($videos) && $inline_video_idx < count($videos)) {
                $v        = $videos[$inline_video_idx];
                $vid      = esc_attr($v['id']);
                $vtitle   = esc_html($v['title']);
                $vchannel = esc_html($v['channel']);
                $thumb    = 'https://img.youtube.com/vi/' . $vid . '/mqdefault.jpg';

                $posts_html .= '
            <div style="border:1px solid #ddd;margin-bottom:15px;background:#fff;">
                <div style="position:relative;padding-bottom:56.25%;height:0;overflow:hidden;background:#000;cursor:pointer;" onclick="iffPlayVideo(this,\'' . $vid . '\')">
                    <img class="yt-thumb" src="' . $thumb . '" loading="lazy" style="position:absolute;top:0;left:0;width:100%;height:100%;object-fit:cover;">
                    <div class="yt-play-btn" style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:60px;height:60px;background:rgba(0,0,0,0.65);border-radius:50%;display:flex;align-items:center;justify-content:center;pointer-events:none;">
                        <svg viewBox="0 0 24 24" style="width:30px;height:30px;fill:#fff;margin-left:5px;"><path d="M8 5v14l11-7z"/></svg>
                    </div>
                    <div class="yt-iframe-wrap" style="display:none;position:absolute;top:0;left:0;width:100%;height:100%;">
                        <iframe width="100%" height="100%" src="" frameborder="0" allow="accelerometer;autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture" allowfullscreen style="position:absolute;top:0;left:0;width:100%;height:100%;"></iframe>
                    </div>
                </div>
                <div style="padding:10px 12px 12px 12px;">
                    <div style="font-size:15px;font-weight:bold;color:#111;line-height:1.4;">' . $vtitle . '</div>
                    <div style="font-size:12px;color:#888;margin-top:4px;">' . $vchannel . '</div>
                </div>
            </div>';

                $inline_video_idx++;
            }
        }

        wp_reset_postdata();

        // Pagination links
        $pagination_html = '';
        if ($total_pages > 1) {
            $pagination_html .= '<div style="text-align: center; padding: 15px 0; font-size: 13px;">';
            if ($paged > 1) {
                $prev_url = get_pagenum_link($paged - 1);
                $pagination_html .= '<a href="' . esc_url($prev_url) . '" style="margin: 0 5px; padding: 5px 12px; background: #2c3e50; color: #fff; text-decoration: none;">&laquo; Олдинги</a>';
            }
            for ($i = 1; $i <= $total_pages; $i++) {
                $page_url = get_pagenum_link($i);
                if ($i == $paged) {
                    $pagination_html .= '<span style="margin: 0 3px; padding: 5px 10px; background: #c00; color: #fff; font-weight: bold;">' . $i . '</span>';
                } else {
                    $pagination_html .= '<a href="' . esc_url($page_url) . '" style="margin: 0 3px; padding: 5px 10px; background: #eee; color: #333; text-decoration: none;">' . $i . '</a>';
                }
            }
            if ($paged < $total_pages) {
                $next_url = get_pagenum_link($paged + 1);
                $pagination_html .= '<a href="' . esc_url($next_url) . '" style="margin: 0 5px; padding: 5px 12px; background: #2c3e50; color: #fff; text-decoration: none;">Кейинги &raquo;</a>';
            }
            $pagination_html .= '</div>';
        }

        // Get recent posts for sidebar
        $sidebar_args = array(
            'posts_per_page' => 20,
            'post_status' => 'publish',
            'orderby' => 'date',
            'order' => 'DESC',
            'cache_results' => false,
            'no_found_rows' => true
        );

        $sidebar_posts = get_posts($sidebar_args);
        $sidebar_html = '';

        foreach ($sidebar_posts as $post) {
            $title = get_the_title($post->ID);
            $date = get_the_date('Y-m-d', $post->ID);
            $link = get_permalink($post->ID);

            $sidebar_html .= '
                        <a href="' . esc_url($link) . '" style="font-size: 15px; line-height: 1.3; text-decoration: none; color: #333 !important;">' . esc_html($title) . '</a><br>
                        <span style="color: #999; font-size: 13px;">' . esc_html($date) . '</span><br>
                        <div style="border-top: 1px solid #ddd; margin: 5px 0;"></div>';
        }

        // If no posts, show placeholder
        if (empty($posts_html)) {
            $posts_html = '
            <table width="100%" border="1" bordercolor="#ccc" cellpadding="10" cellspacing="0" style="margin-bottom: 15px; background: #fff;">
                <tr>
                    <td>
                        <h3 style="margin: 0; font-size: 14px;"><a href="#" style="color: #c00; text-decoration: none;">ИнтерФутболга хуш келибсиз</a></h3>
                        <p style="font-size: 11px; color: #666; margin: 3px 0 8px 0;">01.01.2026</p>
                        <p style="line-height: 1.4; margin: 0;">Биринчи постингизни яратинг!</p>
                    </td>
                </tr>
            </table>';
        }

        if (empty($sidebar_html)) {
            $sidebar_html = '
                        <a href="#" style="font-size: 17px; line-height: 1.3; text-decoration: none;">Хуш келибсиз</a><br>
                        <span style="color: #999; font-size: 15px;">01.01.2026</span>';
        }

        // Get scores for all leagues
        $pl_matches   = get_league_scores('PL',  'pl_scores_cache');
        $bl_matches   = get_league_scores('BL1', 'bl_scores_cache');
        $pd_matches   = get_league_scores('PD',  'pd_scores_cache');
        $sa_matches   = get_league_scores('SA',  'sa_scores_cache');
        $fl1_matches  = get_league_scores('FL1', 'fl1_scores_cache');
        $cl_matches   = get_champions_league_scores();
        $uzsl_matches = get_uzbek_league_scores();
        $tsl_matches  = get_turkish_league_scores();

        // Build scoreboards
        // build_league_scoreboard() is provided by a WPCode snippet, not this file — guard against
        // it being unavailable (e.g. WPCode pausing a snippet after an unrelated error) so a missing
        // snippet degrades to an empty card instead of taking the whole homepage down.
        $iff_no_matches_html = '<div style="padding:10px;color:#666;font-size:12px;text-align:center">Ўйинлар йўқ</div>';
        $pl_scoreboard   = function_exists('build_league_scoreboard') ? build_league_scoreboard($pl_matches)  : $iff_no_matches_html;
        $bl_scoreboard   = function_exists('build_league_scoreboard') ? build_league_scoreboard($bl_matches)  : $iff_no_matches_html;
        $pd_scoreboard   = function_exists('build_league_scoreboard') ? build_league_scoreboard($pd_matches)  : $iff_no_matches_html;
        $sa_scoreboard   = function_exists('build_league_scoreboard') ? build_league_scoreboard($sa_matches)  : $iff_no_matches_html;
        $fl1_scoreboard  = function_exists('build_league_scoreboard') ? build_league_scoreboard($fl1_matches) : $iff_no_matches_html;
        $cl_scoreboard   = build_uzbek_scoreboard($cl_matches);
        $uzsl_scoreboard = build_uzbek_scoreboard($uzsl_matches);
        $tsl_scoreboard  = build_uzbek_scoreboard($tsl_matches);
        $wc_matches     = get_world_cup_scores();
        $wc_scoreboard  = build_wc_scoreboard($wc_matches);
        $wc_card_html = '<a href="https://iff.uz/jch-2026/" class="scoreboard-link" target="_blank" rel="noopener" style="text-decoration:none;display:block;">'
            . '<div class="scoreboard-card" style="background:#fff;border-radius:12px;padding:15px;box-shadow:0 2px 8px rgba(0,0,0,0.1);margin-bottom:15px;transition:transform 0.2s,box-shadow 0.2s;cursor:pointer;">'
            . '<div style="display:flex;align-items:center;margin-bottom:15px;padding-bottom:10px;border-bottom:1px solid #eee;">'
            . '<span style="font-size:20px;margin-right:8px;">&#127942;</span>'
            . '<span style="font-size:14px;font-weight:bold;color:#024075;">ЖЧ 2026</span>'
            . '<span style="margin-left:auto;font-size:10px;color:#999;">→</span>'
            . '</div>'
            . $wc_scoreboard
            . '</div></a>';

        // ── WEEKLY POLL (AI-generated, auto-refreshed every Monday) ─
        $poll_config   = get_option('iff_poll_config', array(
            'key'      => 'iff_poll_' . date('Y_W'),
            'question' => 'Ўзбекистон U-20 терма жамоаси Жаҳон чемпионатига чиқадими?',
            'options'  => array('Ҳа, чиқади', 'Йўқ, қийин', 'Ҳали эрта айтиш')
        ));
        $poll_key      = $poll_config['key'];
        $poll_question = $poll_config['question'];
        $poll_options  = $poll_config['options'];

        $votes       = get_option($poll_key, array());
        $total_votes = array_sum($votes);

        // Build YouTube-style option pills (pre-vote)
        $options_html = '';
        foreach ($poll_options as $idx => $opt) {
            $options_html .= '<div class="iff-poll-option" data-idx="' . $idx . '" onclick="iffSelectOption(this,\'' . esc_js($poll_key) . '\')">
                <div class="iff-poll-radio"></div>
                <span>' . esc_html($opt) . '</span>
            </div>';
        }

        // Build YouTube-style result bars (post-vote)
        $results_html = '';
        foreach ($poll_options as $idx => $opt) {
            $v   = isset($votes[$idx]) ? (int)$votes[$idx] : 0;
            $pct = $total_votes > 0 ? round(($v / $total_votes) * 100) : 0;
            $results_html .= '<div class="iff-poll-bar" data-idx="' . $idx . '">
                <div class="iff-bar-fill" style="width:' . $pct . '%"></div>
                <div class="iff-bar-inner">
                    <span class="iff-voted-check">✓</span>
                    <span class="iff-bar-label">' . esc_html($opt) . '</span>
                    <span class="iff-bar-pct" data-label="' . $idx . '">' . $pct . '%</span>
                </div>
            </div>';
        }

        // Poll comments (stored in WP options, latest 8 shown)
        $comments_key     = 'iff_poll_comments_' . $poll_key;
        $poll_comments    = get_option($comments_key, array());
        $recent_comments  = array_slice($poll_comments, -8);
        $comments_display = '';
        foreach (array_reverse($recent_comments) as $c) {
            $comments_display .= '<div style="border-top:1px solid #f0f0f0;padding:7px 0;">
                <div style="display:flex;justify-content:space-between;margin-bottom:2px;">
                    <span style="font-size:12px;font-weight:bold;color:#333;">' . esc_html($c['name']) . '</span>
                    <span style="font-size:10px;color:#aaa;">' . esc_html($c['time']) . '</span>
                </div>
                <div style="font-size:12px;color:#555;line-height:1.4;">' . esc_html($c['text']) . '</div>
            </div>';
        }
        $comment_count = count($poll_comments);

        $poll_html = '
        <div class="iff-poll-wrap" style="border:1px solid #e0e0e0;border-radius:4px;overflow:hidden;">
            <div class="iff-poll-header">
                <svg viewBox="0 0 24 24" style="width:14px;height:14px;fill:#2c3e50;flex-shrink:0;"><path d="M9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4zm2.5 2.1H4.5V5h15v14.1zm0-16.1H4.5C3.4 3 3 3.4 3 4.5v15c0 1.1.4 1.5 1.5 1.5h15c1.1 0 1.5-.4 1.5-1.5v-15C21 3.4 20.6 3 19.5 3z"/></svg>
                Ҳафтанинг савол
            </div>
            <div class="iff-poll-body">
                <p class="iff-poll-question">' . esc_html($poll_question) . '</p>
                <div id="iff-poll-form-' . esc_attr($poll_key) . '">
                    ' . $options_html . '
                    <button class="iff-vote-btn" onclick="iffSubmitPoll(\'' . esc_js($poll_key) . '\')">Овоз бериш</button>
                </div>
                <div id="iff-poll-results-' . esc_attr($poll_key) . '" style="display:none;">
                    ' . $results_html . '
                    <div class="iff-poll-total" data-total>' . number_format($total_votes) . ' та овоз</div>
                </div>
            </div>
            <div style="border-top:1px solid #eee;">
                <button onclick="iffToggleComments(\'' . esc_js($poll_key) . '\')"
                    style="width:100%;background:none;border:none;padding:10px 12px;text-align:left;cursor:pointer;display:flex;align-items:center;justify-content:space-between;font-size:12px;color:#555;">
                    <span>Фикрлар <span style="color:#999;">(' . $comment_count . ')</span></span>
                    <svg id="iff-comment-arrow-' . esc_attr($poll_key) . '" viewBox="0 0 24 24" style="width:16px;height:16px;fill:#999;transition:transform 0.2s;"><path d="M7 10l5 5 5-5z"/></svg>
                </button>
                <div id="iff-comment-panel-' . esc_attr($poll_key) . '" style="display:none;">
                    <div id="iff-poll-comments-' . esc_attr($poll_key) . '" style="height:200px;overflow-y:scroll;padding:0 12px;border-top:1px solid #f0f0f0;border-bottom:1px solid #f0f0f0;background:#fafafa;">
                        ' . ($comments_display ?: '<div style="font-size:12px;color:#aaa;padding:10px 0;">Биринчи фикрни қолдиринг!</div>') . '
                    </div>
                    <div style="padding:8px 12px 12px 12px;">
                    <input type="text" id="iff-comment-name-' . esc_attr($poll_key) . '" placeholder="Исмингиз (ихтиёрий)" maxlength="60"
                        style="width:100%;box-sizing:border-box;border:1px solid #ddd;padding:6px 8px;font-size:12px;margin-bottom:5px;">
                    <textarea id="iff-comment-text-' . esc_attr($poll_key) . '" placeholder="Фикрингиз..." maxlength="500" rows="2"
                        style="width:100%;box-sizing:border-box;border:1px solid #ddd;padding:6px 8px;font-size:12px;resize:vertical;"></textarea>
                    <button onclick="iffSubmitComment(\'' . esc_js($poll_key) . '\')"
                        style="background:#2c3e50;color:#fff;border:none;padding:6px 14px;font-size:12px;cursor:pointer;width:100%;margin-top:5px;">
                        Фикр қолдириш
                    </button>
                    </div>
                </div>
            </div>
        </div>';

        // ── SCORES STRIP (ESPN-style) ───────────────────────────────
        $scores_strip_html = '';
        $strip_league_data = array(
            array('matches' => $uzsl_matches,  'label' => 'UZB'),
            array('matches' => $tsl_matches,   'label' => 'TUR'),
            array('matches' => $pl_matches,    'label' => 'EPL'),
            array('matches' => $bl_matches,    'label' => 'BUN'),
            array('matches' => $pd_matches,    'label' => 'ESP'),
            array('matches' => $sa_matches,    'label' => 'ITA'),
            array('matches' => $fl1_matches,   'label' => 'FRA'),
            array('matches' => $cl_matches,    'label' => 'UCL'),
        );
        foreach ($strip_league_data as $lg) {
            $league_matches = $lg['matches'];
            $league_label   = $lg['label'];
            if (empty($league_matches) || !is_array($league_matches)) continue;
            $chips = '';
            $count = 0;
            foreach ($league_matches as $m) {
                if ($count >= 5) break;
                if (isset($m['strHomeTeam'])) {
                    // TheSportsDB format
                    $home       = $m['strHomeTeam'] ?? '';
                    $away       = $m['strAwayTeam'] ?? '';
                    $status_raw = $m['strStatus'] ?? '';
                    $is_live    = stripos($status_raw, 'progress') !== false || stripos($status_raw, 'live') !== false || stripos($status_raw, 'half') !== false;
                    $finished   = $status_raw === 'Match Finished';
                    if ($finished || ($m['intHomeScore'] !== null && $m['intHomeScore'] !== '')) {
                        $home_score = $m['intHomeScore'] ?? '-';
                        $away_score = $m['intAwayScore'] ?? '-';
                        $status_lbl = $finished ? 'Якун' : $status_raw;
                    } elseif ($is_live) {
                        $home_score = $m['intHomeScore'] ?? '0';
                        $away_score = $m['intAwayScore'] ?? '0';
                        $status_lbl = 'ЖОНЛИ';
                    } else {
                        $home_score = '';
                        $away_score = '';
                        $time_val   = isset($m['strTimeLocal']) ? substr($m['strTimeLocal'], 0, 5) : (isset($m['strTime']) ? substr($m['strTime'], 0, 5) : '--:--');
                        $status_lbl = $time_val;
                    }
                } else {
                    // Football-data.org format
                    $home       = isset($m['homeTeam']['shortName']) ? $m['homeTeam']['shortName'] : ($m['homeTeam']['name'] ?? '');
                    $away       = isset($m['awayTeam']['shortName']) ? $m['awayTeam']['shortName'] : ($m['awayTeam']['name'] ?? '');
                    $status_raw = $m['status'] ?? '';
                    $is_live    = in_array($status_raw, array('IN_PLAY','PAUSED','1H','HT','2H','ET','P'));
                    $finished   = $status_raw === 'FINISHED';
                    $fth = $m['score']['fullTime']['home'] ?? ($m['score']['fullTime']['homeTeam'] ?? null);
                    $fta = $m['score']['fullTime']['away'] ?? ($m['score']['fullTime']['awayTeam'] ?? null);
                    if ($fth !== null && $fth !== '') {
                        $home_score = $fth;
                        $away_score = $fta;
                        $status_lbl = $finished ? 'Final' : $status_raw;
                    } elseif ($is_live) {
                        $home_score = $m['score']['halfTime']['home'] ?? 0;
                        $away_score = $m['score']['halfTime']['away'] ?? 0;
                        $minute     = $m['minute'] ?? '';
                        $status_lbl = $minute ? $minute . "'" : 'LIVE';
                    } else {
                        $home_score = '';
                        $away_score = '';
                        $status_lbl = isset($m['utcDate']) ? date('H:i', strtotime($m['utcDate']) + 18000) : '--:--';
                    }
                }
                if (empty($home) && empty($away)) { $count++; continue; }
                $status_class = $is_live ? ' iff-chip-live' : ($finished ? ' iff-chip-final' : '');
                $chips .= '<div class="iff-score-chip">'
                    . '<div class="iff-chip-status' . $status_class . '">' . esc_html($status_lbl) . '</div>'
                    . '<div class="iff-chip-row"><span class="iff-chip-name">' . esc_html($home) . '</span><span class="iff-chip-num">' . esc_html((string)$home_score) . '</span></div>'
                    . '<div class="iff-chip-row"><span class="iff-chip-name">' . esc_html($away) . '</span><span class="iff-chip-num">' . esc_html((string)$away_score) . '</span></div>'
                    . '</div>';
                $count++;
            }
            if ($chips) {
                $scores_strip_html .= '<div class="iff-league-grp">'
                    . '<div class="iff-league-lbl">' . esc_html($league_label) . '</div>'
                    . $chips
                    . '</div>';
            }
        }
        if (!$scores_strip_html) {
            $scores_strip_html = '<span style="color:#888;font-size:11px;padding:0 20px;">Натижалар кутилмоқда</span>';
        }

        // Get home URL for menu
        $home_url = home_url('/');

        // Get visitor stats
        $visitor_stats = function_exists('iff_get_visitor_stats_html') ? iff_get_visitor_stats_html() : '';

        // 3-column layout with INTERACTIVE MENU
        $output = <<<HTML
    <style>
    /* Hide WordPress theme elements completely */
    .site-header, header.site-header, #masthead, .site-branding, .site-title, .site-description { display: none !important; }
    #site-navigation, .main-navigation, .primary-menu, .navbar, header nav, .site-header nav { display: none !important; }
    .entry-header .entry-title, article .entry-title, .page-header .page-title, h1.entry-title { display: none !important; }
    .site-footer, footer.site-footer, #colophon, .site-info { display: none !important; }

    html { height: 100%; margin: 0; padding: 0; }
    html, body { margin: 0 !important; padding: 0 !important; font-family: Arial, sans-serif; font-size: 10px; background: #ededed; }
    body { padding-top: 76px !important; margin: 0 !important; min-height: 100vh !important; }
    body.admin-bar { padding-top: 108px !important; }
    #page, .site, .site-content, .entry-content, main, article { min-height: calc(100vh - 76px) !important; display: flex !important; flex-direction: column !important; }
    .entry-content > .main-wrapper { flex: 1; display: flex; flex-direction: column; }
    body::before { content: ""; position: fixed; top: 0; left: 0; right: 0; height: 76px; background: #024075; z-index: 997; }
    body.admin-bar::before { top: 32px; }
    body.admin-bar .social-bar { top: 32px !important; }
    body.admin-bar .iff-scores-bar { top: 68px !important; }
    body > *, body > * > *, #page, #content, .site, .site-content, .entry-content, article, main, .page, .post {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
    /* Force social bar to absolute top */
    body > :first-child { margin-top: 0 !important; padding-top: 0 !important; }
    * { margin-top: 0 !important; }
    a { color: #0000EE; text-decoration: underline; }
    a:visited { color: #551A8B; }
    a:hover { color: #FF0000; }
    .sidebar-news a, .sidebar-news a:hover, .sidebar-news a:visited { color: #333 !important; }
    .scoreboard-link:hover .scoreboard-card { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
    .scoreboard-link, .scoreboard-link:visited, .scoreboard-link:hover { color: inherit !important; text-decoration: none !important; }
    .scoreboard-card { overflow: hidden; }
    .scoreboard-card span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .menu-bar { background: #032d52; width: 70%; margin: 0 auto; display: flex; align-items: center; position: relative; height: 50px; box-sizing: border-box; padding: 0 4px 0 0; }
    .menu-bar-logo { width: auto; height: 34px; display: block; padding: 0 8px 0 0; flex-shrink: 0; }
    .menu-bar-links { flex: 1; text-align: center; padding: 0 4px; display: flex; align-items: center; justify-content: center; overflow: hidden; flex-wrap: nowrap; }
    .menu-bar a { color: #fff; text-decoration: none; padding: 0 6px; font-size: 11px; white-space: nowrap; }
    .menu-bar a:hover { color: #3498db; text-decoration: underline; }
    .menu-item { position: relative; display: inline-block; padding: 5px 0; }
    .dropdown {
        display: none;
        position: absolute;
        background: #34495e;
        min-width: auto;
        white-space: nowrap;
        z-index: 1000;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        margin-top: 5px;
        padding-top: 5px;
        box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    }
    .dropdown::before {
        content: "";
        position: absolute;
        top: -5px;
        left: 0;
        right: 0;
        height: 5px;
        background: transparent;
    }
    .dropdown a {
        display: block;
        padding: 10px 15px;
        font-size: 12px;
        border-bottom: 1px solid #2c3e50;
        transition: background 0.2s;
    }
    .dropdown a:last-child { border-bottom: none; }
    .dropdown a:hover { background: #2c3e50; }
    .menu-item:hover .dropdown { display: block; }
    .nav-icons { margin-left: auto; display: flex; gap: 5px; align-items: center; flex-shrink: 0; }
    .nav-icon { width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; background: transparent; border: 1px solid rgba(255,255,255,0.3); border-radius: 50%; cursor: pointer; transition: all 0.2s; color: #fff; text-decoration: none; }
    .nav-icon:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.6); transform: scale(1.1); }
    .nav-icon svg { width: 15px; height: 15px; fill: currentColor; }
    .search-container, .contact-container { position: relative; }
    .nav-dropdown { display: none; position: absolute; top: 100%; right: 0; margin-top: 10px; background: #fff; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.3); padding: 15px; z-index: 1001; min-width: 300px; }
    .nav-dropdown.active { display: block; }
    .nav-dropdown input, .nav-dropdown textarea { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 5px; font-size: 14px; outline: none; box-sizing: border-box; margin-bottom: 10px; font-family: inherit; }
    .nav-dropdown input:focus, .nav-dropdown textarea:focus { border-color: #3498db; }
    .nav-dropdown textarea { min-height: 100px; resize: vertical; }
    .nav-dropdown button { width: 100%; padding: 12px; background: #c00; color: #fff; border: none; border-radius: 5px; font-size: 14px; cursor: pointer; font-weight: bold; }
    .nav-dropdown button:hover { background: #a00; }
    .nav-dropdown label { display: block; font-size: 12px; color: #666; margin-bottom: 4px; font-weight: bold; }
    .nav-dropdown h4 { margin: 0 0 12px 0; color: #333; font-size: 16px; border-bottom: 1px solid #eee; padding-bottom: 8px; }
    .contact-success { color: #28a745; text-align: center; padding: 20px; font-weight: bold; }
    .lang-switcher { display: flex; gap: 2px; align-items: center; padding-right: 4px; margin-left: 4px; flex-shrink: 0; }
    .lang-switcher button { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.4); color: #fff; padding: 3px 7px; font-size: 10px; cursor: pointer; border-radius: 3px; transition: all 0.2s; font-weight: 600; letter-spacing: 0.3px; }
    .lang-switcher button:hover { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.7); }
    .lang-switcher button.active { background: #e8a000; border-color: #e8a000; color: #fff; font-weight: 700; }
    .content-wrapper { width: 70%; margin: 0 auto; }
    .main-wrapper { min-height: calc(100vh - 40px); }
    .page-content { }
    .content-table { display: flex; align-items: flex-start; }
    .content-table .left-sidebar { width: 25%; padding: 8px; background: #ededed; box-sizing: border-box; }
    .content-table .main-content { width: 50%; padding: 0 15px 10px 15px; background: #fff; box-sizing: border-box; }
    .content-table .right-sidebar { width: 25%; padding: 0 10px 10px 10px; background: #f5f5f5; display: flex; flex-direction: column; box-sizing: border-box; }
    .content-table .right-sidebar .news-table { flex: 1; display: flex; flex-direction: column; }
    .content-table .right-sidebar .news-table .news-content { flex: 1; }
    .social-bar { background: #024075 !important; padding: 0; width: 100vw !important; max-width: 100vw !important; box-sizing: border-box; margin: 0 !important; display: block; }
    .social-bar-inner { width: 100% !important; max-width: none !important; margin: 0 !important; display: flex; justify-content: center; align-items: center; gap: 10px; padding: 8px 0; box-sizing: border-box; background: #024075 !important; position: relative; }
    .social-bar a { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: transparent; border: 1px solid rgba(255,255,255,0.3); transition: all 0.3s; }
    .social-bar a img { width: 100%; height: 100%; border-radius: 50%; }
    .social-bar a:hover { transform: translateY(-3px); border-color: rgba(255,255,255,0.6); }
    .footer-privacy { background: #1a1a1a; color: #999; padding: 8px 20px; font-size: 11px; line-height: 1.4; width: 100%; box-sizing: border-box; position: fixed; bottom: 0; left: 0; right: 0; z-index: 9999; display: none; }
    .footer-privacy-inner { width: 100%; margin: 0; text-align: justify; padding: 0; display: block; }
    .footer-privacy p { margin: 3px 0; font-size: 11px; }
    .footer-privacy strong { font-weight: bold; color: #fff; font-size: 11px; }
    .footer-privacy a { color: #4a9eff; text-decoration: none; font-size: 11px; }
    .footer-privacy a:hover { text-decoration: underline; }

    /* ── YouTube-style Poll ── */
    .iff-poll-wrap { background:#fff; font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif; }
    .iff-poll-header { background:#e0e0e0; padding:8px 12px; font-weight:700; font-size:13px; display:flex; align-items:center; gap:6px; color:#222; }
    .iff-poll-body { padding:12px; }
    .iff-poll-question { font-size:14px; font-weight:600; color:#0f0f0f; margin:0 0 14px 0; line-height:1.5; }
    .iff-poll-option {
        display:flex; align-items:center; gap:10px;
        padding:10px 14px; border:1.5px solid #d3d3d3; border-radius:20px;
        cursor:pointer; margin-bottom:8px; font-size:13px; color:#0f0f0f;
        transition:background 0.15s,border-color 0.15s; user-select:none;
    }
    .iff-poll-option:hover { background:#fafafa; border-color:#aaa; }
    .iff-poll-option.yt-selected { background:#fff0f0; border-color:#c00; }
    .iff-poll-radio {
        width:16px; height:16px; border:2px solid #909090; border-radius:50%;
        flex-shrink:0; transition:border-color 0.15s; position:relative;
    }
    .iff-poll-option.yt-selected .iff-poll-radio { border-color:#c00; }
    .iff-poll-option.yt-selected .iff-poll-radio::after {
        content:''; position:absolute; top:50%; left:50%;
        transform:translate(-50%,-50%);
        width:8px; height:8px; border-radius:50%; background:#c00;
    }
    .iff-vote-btn {
        width:100%; margin-top:4px; background:#c00; color:#fff;
        border:none; border-radius:20px; padding:9px 18px;
        font-size:13px; font-weight:600; cursor:pointer; transition:background 0.15s;
    }
    .iff-vote-btn:hover { background:#a00; }
    .iff-vote-btn:disabled { background:#bbb; cursor:default; }
    .iff-poll-bar {
        position:relative; border-radius:20px; overflow:hidden;
        margin-bottom:8px; border:1.5px solid #e5e5e5; min-height:40px;
    }
    .iff-poll-bar.yt-voted { border-color:#c00; }
    .iff-bar-fill {
        position:absolute; left:0; top:0; bottom:0; width:0%;
        background:rgba(204,0,0,0.10); border-radius:20px;
        transition:width 0.65s cubic-bezier(.4,0,.2,1);
    }
    .iff-poll-bar.yt-voted .iff-bar-fill { background:rgba(204,0,0,0.18); }
    .iff-bar-inner { position:relative; display:flex; align-items:center; padding:10px 14px; gap:8px; }
    .iff-voted-check { color:#c00; font-size:13px; font-weight:700; width:14px; flex-shrink:0; opacity:0; }
    .iff-poll-bar.yt-voted .iff-voted-check { opacity:1; }
    .iff-bar-label { flex:1; font-size:13px; color:#0f0f0f; }
    .iff-bar-pct { font-size:13px; font-weight:700; color:#0f0f0f; min-width:32px; text-align:right; }
    .iff-poll-total { font-size:11px; color:#606060; margin-top:10px; text-align:right; }

    /* ── Scores Bar ── */
    .iff-scores-bar { background:#024075; position:fixed; top:36px; left:0; right:0; width:100vw !important; overflow-x:auto; white-space:nowrap; scrollbar-width:none; -ms-overflow-style:none; border-bottom:1px solid #2a2a2a; cursor:grab; box-sizing:border-box; z-index:999; }
    .iff-scores-bar::-webkit-scrollbar { display:none; }
    .iff-scores-inner { display:inline-flex; align-items:stretch; min-height:40px; }
    .iff-league-grp { display:inline-flex; align-items:stretch; border-right:1px solid #333; }
    .iff-league-lbl { display:inline-flex; align-items:center; justify-content:center; padding:0 8px; font-size:9px; font-weight:700; color:#777; text-transform:uppercase; letter-spacing:0.5px; border-right:1px solid #2a2a2a; min-width:28px; writing-mode:vertical-rl; text-orientation:mixed; transform:rotate(180deg); }
    .iff-score-chip { display:inline-flex; flex-direction:column; justify-content:center; padding:3px 12px; border-right:1px solid #222; flex-shrink:0; min-width:110px; }
    .iff-score-chip:last-child { border-right:none; }
    .iff-chip-status { font-size:9px; color:#777; margin-bottom:2px; white-space:nowrap; }
    .iff-chip-status.iff-chip-live { color:#c00; font-weight:700; }
    .iff-chip-status.iff-chip-final { color:#888; }
    .iff-chip-row { display:flex; align-items:center; justify-content:space-between; gap:6px; }
    .iff-chip-name { font-size:11px; color:#ccc; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:75px; }
    .iff-chip-num { font-size:11px; font-weight:700; color:#fff; min-width:14px; text-align:right; }
    @keyframes iff-blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

    /* ── Card Grid ── */
    .iff-card-grid { display:grid; grid-template-columns:1fr 1fr; gap:10px; padding:10px; }
    .iff-card { background:#fff; border-radius:5px; overflow:hidden; box-shadow:0 1px 3px rgba(0,0,0,0.1); transition:transform 0.15s,box-shadow 0.15s; display:flex; flex-direction:column; }
    .iff-card:hover { transform:translateY(-2px); box-shadow:0 4px 12px rgba(0,0,0,0.15); }
    .iff-card-img-wrap { display:block; overflow:hidden; }
    .iff-card-img { width:100%; height:130px; object-fit:cover; display:block; transition:transform 0.2s; }
    .iff-card:hover .iff-card-img { transform:scale(1.03); }
    .iff-card-noimg { background:#e8e8e8; height:130px; }
    .iff-card-body { padding:8px 10px 10px; flex:1; display:flex; flex-direction:column; }
    .iff-card-cat { display:inline-block; background:#c00; color:#fff; font-size:9px; font-weight:700; padding:2px 6px; text-transform:uppercase; letter-spacing:0.4px; margin-bottom:5px; border-radius:2px; }
    .iff-card-title { margin:0 0 5px 0; font-size:12px; font-weight:700; line-height:1.35; flex:1; }
    .iff-card-title a { color:#111; text-decoration:none; }
    .iff-card-title a:hover { color:#c00; }
    .iff-card-title a:visited { color:#333; }
    .iff-card-date { font-size:10px; color:#999; }
    .iff-card-video { grid-column:1 / -1; }

    /* ── Section separator ── */
    .iff-section-sep { width:70%; margin:8px auto 0; border:none; border-top:3px solid #024075; }

    /* ── Dark Mode ── */
    body.iff-dark,
    html body.iff-dark,
    body.iff-dark #page,
    body.iff-dark .site,
    body.iff-dark #content,
    body.iff-dark #primary,
    body.iff-dark .site-content,
    body.iff-dark .entry-content,
    body.iff-dark main,
    body.iff-dark article { background:#121212 !important; color:#ddd !important; }
    body.iff-dark .content-table .main-content { background:#1e1e1e !important; }
    body.iff-dark .content-table .right-sidebar { background:#181818 !important; }
    body.iff-dark .content-table .left-sidebar { background:#121212 !important; }
    body.iff-dark .scoreboard-card { background:#1e1e1e !important; box-shadow:0 2px 8px rgba(0,0,0,0.4) !important; }
    body.iff-dark .scoreboard-card span { color:#ccc !important; }
    body.iff-dark table { background:#1e1e1e !important; border-color:#333 !important; }
    body.iff-dark table td, body.iff-dark table th { border-color:#333 !important; color:#ccc !important; }
    body.iff-dark a { color:#7ab3f0 !important; }
    body.iff-dark a:visited { color:#a78bda !important; }
    body.iff-dark a:hover { color:#ff6b6b !important; }
    body.iff-dark .sidebar-news a, body.iff-dark .sidebar-news a:visited, body.iff-dark .sidebar-news a:hover { color:#ccc !important; }
    body.iff-dark .iff-poll-wrap { background:#1e1e1e !important; border-color:#333 !important; }
    body.iff-dark .iff-poll-header { background:#2a2a2a !important; color:#ddd !important; }
    body.iff-dark .iff-poll-question { color:#eee !important; }
    body.iff-dark .iff-poll-option { border-color:#444 !important; color:#ddd !important; }
    body.iff-dark .iff-poll-option:hover { background:#2a2a2a !important; }
    body.iff-dark .nav-dropdown { background:#1e1e1e !important; }
    body.iff-dark .nav-dropdown input, body.iff-dark .nav-dropdown textarea { background:#2a2a2a !important; border-color:#444 !important; color:#ddd !important; }
    body.iff-dark .nav-dropdown h4 { color:#ddd !important; border-color:#333 !important; }
    body.iff-dark .main-content table,
    body.iff-dark .main-content table td,
    body.iff-dark .main-content table tr { background:#1e1e1e !important; border-color:#333 !important; color:#ccc !important; }
    body.iff-dark .main-content { background:#1e1e1e !important; }
    body.iff-dark .news-table { background:#1e1e1e !important; border-color:#333 !important; }
    body.iff-dark .news-table div { background:#1e1e1e !important; border-color:#333 !important; color:#ccc !important; }
    body.iff-dark .news-table > div:first-child { background:#2a2a2a !important; color:#eee !important; }
    body.iff-dark .sidebar-news { background:#1e1e1e !important; color:#ccc !important; }
    body.iff-dark .sidebar-news * { color:#ccc !important; background:transparent !important; border-color:#333 !important; }
    body.iff-dark .sidebar-news a, body.iff-dark .sidebar-news a:visited, body.iff-dark .sidebar-news a:hover { color:#ddd !important; }
    body.iff-dark #btnDark { background:rgba(255,255,255,0.15) !important; }

    .iff-scroll-btn { position:absolute; top:0; bottom:0; width:28px; background:linear-gradient(to right, transparent, rgba(0,0,0,0.7)); border:none; color:#aaa; font-size:20px; cursor:pointer; padding:0; line-height:1; transition:opacity 0.2s, color 0.2s; z-index:10; }
    .iff-scroll-btn:hover { color:#fff; }
    .iff-scroll-left { left:0; background:linear-gradient(to left, transparent, rgba(0,0,0,0.7)); opacity:0; }
    .iff-scroll-right { right:0; }

    /* ── Mobile layout ── */
    @media (max-width: 900px) {
        .content-wrapper, .menu-bar { width: 96%; }
        .content-table { flex-wrap: wrap; }
        .content-table .left-sidebar,
        .content-table .main-content,
        .content-table .right-sidebar { width: 100%; }
        .content-table .left-sidebar  { order: 2; }
        .content-table .main-content  { order: 1; }
        .content-table .right-sidebar { order: 3; }
    }
    @media (max-width: 480px) {
        .iff-team-name { font-size: 12px !important; }
        .iff-card-grid { grid-template-columns: 1fr; }
    }

    </style>

    <div class="main-wrapper">
    <div class="page-content">
    <!-- SOCIAL MEDIA BAR -->
    <div class="social-bar" style="position:fixed;top:0;left:0;right:0;z-index:1000;padding-bottom:0;">
        <div class="social-bar-inner" style="margin: 0; padding-bottom: 0;">
            <a href="https://t.me/interfutboluz1" target="_blank" title="Telegram"><img src="https://iff.uz/wp-content/uploads/2026/01/telegram.png" alt="Telegram"></a>
            <a href="https://facebook.com/interfutbolofficial" target="_blank" title="Facebook"><img src="https://iff.uz/wp-content/uploads/2026/01/facebook.png" alt="Facebook"></a>
            <a href="https://twitter.com/InterFUTBOLuz" target="_blank" title="Twitter"><img src="https://iff.uz/wp-content/uploads/2026/01/x.png" alt="Twitter"></a>
            <a href="https://instagram.com/interfutbol.uz/" target="_blank" title="Instagram"><img src="https://iff.uz/wp-content/uploads/2026/01/instagram.png" alt="Instagram"></a>
            <a href="https://ok.ru/interfutbolinfo" target="_blank" title="Odnoklassniki"><img src="https://iff.uz/wp-content/uploads/2026/01/ok.png" alt="OK"></a>
            {$visitor_stats}
        </div>
    </div>

    <!-- SCORES BAR -->
    <div class="iff-scores-bar" id="iffScoresBar">
        <div class="iff-scores-inner">{$scores_strip_html}</div>
        <button class="iff-scroll-btn iff-scroll-left" id="iffScrollLeft" onclick="iffScroll(-1)" title="&#8592;">&#8249;</button>
        <button class="iff-scroll-btn iff-scroll-right" id="iffScrollRight" onclick="iffScroll(1)" title="&#8594;">&#8250;</button>
    </div>
    <script>
    (function(){
        var el = document.getElementById('iffScoresBar');
        var btnL = document.getElementById('iffScrollLeft');
        var btnR = document.getElementById('iffScrollRight');
        if (!el) return;
        // Drag to scroll
        var isDown = false, startX, scrollLeft;
        el.addEventListener('mousedown', function(e){ if(e.target.classList.contains('iff-scroll-btn')) return; isDown=true; el.style.cursor='grabbing'; startX=e.pageX-el.offsetLeft; scrollLeft=el.scrollLeft; });
        el.addEventListener('mouseleave', function(){ isDown=false; el.style.cursor='grab'; });
        el.addEventListener('mouseup', function(){ isDown=false; el.style.cursor='grab'; });
        el.addEventListener('mousemove', function(e){ if(!isDown) return; e.preventDefault(); var x=e.pageX-el.offsetLeft; el.scrollLeft=scrollLeft-(x-startX); });
        // Update button visibility
        function updateBtns() {
            if (!btnL || !btnR) return;
            btnL.style.opacity = el.scrollLeft > 10 ? '1' : '0';
            btnR.style.opacity = el.scrollLeft < el.scrollWidth - el.clientWidth - 10 ? '1' : '0';
        }
        el.addEventListener('scroll', updateBtns);
        updateBtns();
        window.iffScroll = function(dir) {
            el.scrollBy({ left: dir * 300, behavior: 'smooth' });
        };
    })();
    </script>

    <!-- VIDEO BANNER -->
    <div style="width: 70%; margin: 0 auto; background: #2c3e50; position: relative; padding: 0; margin-top: 0;">
        <div style="width: 100%; display: flex; justify-content: center; align-items: center; background: #ededed;">
            <video autoplay loop muted playsinline style="width: 100%; height: auto; display: block;">
                <source src="https://iff.uz/wp-content/uploads/2026/04/Untitled-1-1.mp4" type="video/mp4">
            </video>
        </div>
    </div>

    <!-- MENU BAR WITH LOGO AND CATEGORIES -->
    <div class="menu-bar">
        <img src="https://iff.uz/wp-content/uploads/2026/01/InterFutbol-1.png" alt="InterFutbol" class="menu-bar-logo">
        <div class="menu-bar-links">
            <span class="menu-item">
                <a href="https://iff.uz/category/turnirlar/">Турнирлар</a>
                <div class="dropdown">
                    <a href="https://iff.uz/category/turnirlar/jch/">ЖЧ</a>
                    <a href="https://iff.uz/category/turnirlar/evro/">Евро</a>
                    <a href="https://iff.uz/category/turnirlar/ok/">ОК</a>
                    <a href="https://iff.uz/category/turnirlar/echl/">ЕЧЛ</a>
                    <a href="https://iff.uz/category/turnirlar/ochl/">ОЧЛ</a>
                </div>
            </span> |
            <span class="menu-item">
                <a href="https://iff.uz/category/bugunning-gapi/">Бугуннинг гапи</a>
                <div class="dropdown">
                    <a href="https://iff.uz/category/bugunning-gapi/jahon-futboli/">Жаҳон футболи</a>
                    <a href="https://iff.uz/category/bugunning-gapi/osiyo-futboli/">Осиё футболи</a>
                    <a href="https://iff.uz/category/bugunning-gapi/ozbekiston/">Ўзбекистон</a>
                </div>
            </span> |
            <span class="menu-item">
                <a href="https://iff.uz/category/maqolalar/">Мақолалар</a>
                <div class="dropdown">
                    <a href="https://iff.uz/category/maqolalar/mulohoza/">Мулоҳаза</a>
                    <a href="https://iff.uz/category/maqolalar/suhbat/">Суҳбат</a>
                    <a href="https://iff.uz/category/maqolalar/tahlil/">Таҳлил</a>
                    <a href="https://iff.uz/category/maqolalar/munosabat/">Муносабат</a>
                    <a href="https://iff.uz/category/maqolalar/aks-sado/">Акс-садо</a>
                </div>
            </span> |
            <span class="menu-item">
                <a href="https://iff.uz/category/galereya/">Галарея</a>
                <div class="dropdown">
                    <a href="https://iff.uz/category/galereya/foto/">Фото</a>
                    <a href="https://iff.uz/category/galereya/video/">Видео</a>
                    <a href="https://iff.uz/category/galereya/karikatura/">Карикатура</a>
                    <a href="https://iff.uz/category/galereya/mem/">Мем</a>
                </div>
            </span> |
            <a href="https://iff.uz/category/maktubingizni-oldik/">Мактубингизни олдик</a> |
            <span class="menu-item">
                <a href="https://iff.uz/category/chempionatlar/">Чемпионатлар</a>
                <div class="dropdown">
                    <a href="https://iff.uz/category/chempionatlar/ozbekiston-chempionat/">Ўзбекистон</a>
                    <a href="https://iff.uz/category/chempionatlar/apl/">АПЛ</a>
                    <a href="https://iff.uz/category/chempionatlar/la-liga/">Ла лига</a>
                    <a href="https://iff.uz/category/chempionatlar/a-seriya/">А-серия</a>
                    <a href="https://iff.uz/category/chempionatlar/bundesliga/">Бундеслига</a>
                    <a href="https://iff.uz/category/chempionatlar/oliy-divizion/">Олий дивизион</a>
                </div>
            </span> |
            <span class="menu-item">
                <a href="https://iff.uz/category/biz-haqimizda/">Биз ҳақимизда</a>
                <div class="dropdown">
                    <a href="https://iff.uz/category/biz-haqimizda/gazeta/">Газета</a>
                    <a href="https://iff.uz/category/biz-haqimizda/maxsus-son/">Махсус сон</a>
                    <a href="https://iff.uz/category/biz-haqimizda/jurnal/">Журнал</a>
                </div>
            </span>
            <div class="nav-icons">
                <!-- Search Icon -->
                <div class="search-container">
                    <a href="#" class="nav-icon" onclick="toggleSearch(event)" title="Қидириш">
                        <svg viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>
                    </a>
                    <div class="nav-dropdown" id="searchDropdown">
                        <form action="{$home_url}" method="get">
                            <input type="text" name="s" placeholder="Қидириш..." autocomplete="off">
                            <button type="submit">Қидириш</button>
                        </form>
                    </div>
                </div>
                <div class="lang-switcher">
                    <button onclick="toggleScript()" id="btnScript" title="Ёзув тизимини алмаштириш">Лотин</button>
                    <button onclick="iffToggleDark()" id="btnDark" title="Кун/тун режими" style="padding:4px 8px;line-height:1;display:flex;align-items:center;justify-content:center;">
                        <svg id="btnDarkIcon" viewBox="0 0 24 24" style="width:14px;height:14px;fill:#fff;"><path d="M12 3a9 9 0 1 0 9 9c0-.46-.04-.92-.1-1.36a5.389 5.389 0 0 1-4.4 2.26 5.403 5.403 0 0 1-3.14-9.8c-.44-.06-.9-.1-1.36-.1z"/></svg>
                    </button>
                </div>
            </div>
        </div>
    </div>


    <!-- Yandex.RTB global init (once per page) -->
    <script>window.yaContextCb=window.yaContextCb||[]</script>
    <script src="https://yandex.ru/ads/system/context.js" async></script>


    <hr class="iff-section-sep">
    <div class="content-wrapper">
    <div class="content-table">
        <!-- LEFT SIDEBAR - Scoreboards -->
        <div class="left-sidebar">
            {$wc_card_html}

            <!-- Ўзбек Суперлигаси -->
            <a href="https://pfl.uz/en" class="scoreboard-link" target="_blank" rel="noopener" style="text-decoration:none;display:block;">
                <div class="scoreboard-card" style="background:#fff;border-radius:12px;padding:15px;box-shadow:0 2px 8px rgba(0,0,0,0.1);margin-bottom:15px;transition:transform 0.2s,box-shadow 0.2s;cursor:pointer;">
                    <div style="display:flex;align-items:center;margin-bottom:15px;padding-bottom:10px;border-bottom:1px solid #eee;">
                        <img src="https://r2.thesportsdb.com/images/media/league/badge/ttbcir1643757051.png" alt="Ўзбек Суперлигаси" style="width:24px;height:24px;margin-right:8px;">
                        <span style="font-size:14px;font-weight:bold;color:#1a5276;">Ўзбек Суперлигаси</span>
                        <span style="margin-left:auto;font-size:10px;color:#999;">→</span>
                    </div>
                    {$uzsl_scoreboard}
                </div>
            </a>

            <!-- Süper Lig -->
            <a href="https://www.tff.org/default.aspx?pageID=198" class="scoreboard-link" target="_blank" rel="noopener" style="text-decoration:none;display:block;">
                <div class="scoreboard-card" style="background:#fff;border-radius:12px;padding:15px;box-shadow:0 2px 8px rgba(0,0,0,0.1);margin-bottom:15px;transition:transform 0.2s,box-shadow 0.2s;cursor:pointer;">
                    <div style="display:flex;align-items:center;margin-bottom:15px;padding-bottom:10px;border-bottom:1px solid #eee;">
                        <img src="https://r2.thesportsdb.com/images/media/league/badge/h7xx231601671132.png" alt="Süper Lig" style="width:24px;height:24px;margin-right:8px;">
                        <span style="font-size:14px;font-weight:bold;color:#e30a17;">Süper Lig</span>
                        <span style="margin-left:auto;font-size:10px;color:#999;">→</span>
                    </div>
                    {$tsl_scoreboard}
                </div>
            </a>

            <!-- Yandex Ad Block R-A-18747543-1 -->
            <div style="margin-bottom:15px;text-align:center;">
                <div id="yandex_rtb_R-A-18747543-1"></div>
                <script>
                window.yaContextCb.push(() => {
                    Ya.Context.AdvManager.render({
                        "blockId": "R-A-18747543-1",
                        "renderTo": "yandex_rtb_R-A-18747543-1"
                    })
                })
                </script>
            </div>

            <!-- Premier League -->
            <a href="{$home_url}premier-league/" class="scoreboard-link" target="_blank" rel="noopener" style="text-decoration: none; display: block;">
                <div class="scoreboard-card" style="background: #fff; border-radius: 12px; padding: 15px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin-bottom: 15px; transition: transform 0.2s, box-shadow 0.2s; cursor: pointer;">
                    <div style="display: flex; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #eee;">
                        <img src="https://crests.football-data.org/PL.png" alt="Premier League" style="width: 24px; height: 24px; margin-right: 8px;">
                        <span style="font-size: 14px; font-weight: bold; color: #37003c;">Premier League</span>
                        <span style="margin-left: auto; font-size: 10px; color: #999;">→</span>
                    </div>
                    {$pl_scoreboard}
                </div>
            </a>

            <!-- Bundesliga -->
            <a href="{$home_url}bundesliga/" class="scoreboard-link" target="_blank" rel="noopener" style="text-decoration: none; display: block;">
                <div class="scoreboard-card" style="background: #fff; border-radius: 12px; padding: 15px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin-bottom: 15px; transition: transform 0.2s, box-shadow 0.2s; cursor: pointer;">
                    <div style="display: flex; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #eee;">
                        <img src="https://crests.football-data.org/BL1.png" alt="Bundesliga" style="width: 24px; height: 24px; margin-right: 8px;">
                        <span style="font-size: 14px; font-weight: bold; color: #d20515;">Bundesliga</span>
                        <span style="margin-left: auto; font-size: 10px; color: #999;">→</span>
                    </div>
                    {$bl_scoreboard}
                </div>
            </a>

            <!-- La Liga -->
            <a href="{$home_url}la-liga/" class="scoreboard-link" target="_blank" rel="noopener" style="text-decoration: none; display: block;">
                <div class="scoreboard-card" style="background: #fff; border-radius: 12px; padding: 15px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); transition: transform 0.2s, box-shadow 0.2s; cursor: pointer;">
                    <div style="display: flex; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #eee;">
                        <img src="https://crests.football-data.org/PD.png" alt="La Liga" style="width: 24px; height: 24px; margin-right: 8px;">
                        <span style="font-size: 14px; font-weight: bold; color: #ee8707;">La Liga</span>
                        <span style="margin-left: auto; font-size: 10px; color: #999;">→</span>
                    </div>
                    {$pd_scoreboard}
                </div>
            </a>

            <!-- Serie A -->
            <a href="{$home_url}serie-a/" class="scoreboard-link" target="_blank" rel="noopener" style="text-decoration: none; display: block;">
                <div class="scoreboard-card" style="background: #fff; border-radius: 12px; padding: 15px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin-top: 15px; transition: transform 0.2s, box-shadow 0.2s; cursor: pointer;">
                    <div style="display: flex; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #eee;">
                        <img src="https://crests.football-data.org/SA.png" alt="Serie A" loading="lazy" style="width: 24px; height: 24px; margin-right: 8px;">
                        <span style="font-size: 14px; font-weight: bold; color: #024494;">Serie A</span>
                        <span style="margin-left: auto; font-size: 10px; color: #999;">→</span>
                    </div>
                    {$sa_scoreboard}
                </div>
            </a>

            <!-- Ligue 1 -->
            <a href="https://www.ligue1.com/" class="scoreboard-link" target="_blank" rel="noopener" style="text-decoration: none; display: block;">
                <div class="scoreboard-card" style="background: #fff; border-radius: 12px; padding: 15px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin-top: 15px; transition: transform 0.2s, box-shadow 0.2s; cursor: pointer;">
                    <div style="display: flex; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #eee;">
                        <img src="https://crests.football-data.org/FL1.png" alt="Ligue 1" loading="lazy" style="width: 24px; height: 24px; margin-right: 8px;">
                        <span style="font-size: 14px; font-weight: bold; color: #003f8a;">Ligue 1</span>
                        <span style="margin-left: auto; font-size: 10px; color: #999;">→</span>
                    </div>
                    {$fl1_scoreboard}
                </div>
            </a>

            <!-- Champions League -->
            <a href="https://www.uefa.com/uefachampionsleague/" class="scoreboard-link" target="_blank" rel="noopener" style="text-decoration: none; display: block;">
                <div class="scoreboard-card" style="background: #fff; border-radius: 12px; padding: 15px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin-top: 15px; transition: transform 0.2s, box-shadow 0.2s; cursor: pointer;">
                    <div style="display: flex; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #eee;">
                        <img src="https://crests.football-data.org/CL.png" alt="Champions League" loading="lazy" style="width: 24px; height: 24px; margin-right: 8px;">
                        <span style="font-size: 14px; font-weight: bold; color: #00337f;">Чемпионлар лигаси</span>
                        <span style="margin-left: auto; font-size: 10px; color: #999;">→</span>
                    </div>
                    {$cl_scoreboard}
                </div>
            </a>

        </div>

        <!-- MAIN CONTENT CENTER -->
        <div class="main-content">
            {$posts_html}
            {$pagination_html}
        </div>

        <!-- RIGHT SIDEBAR - Poll + News Feed -->
        <div class="right-sidebar">
            <!-- Yandex.RTB R-A-19041845-1 -->
            <div id="yandex_rtb_R-A-19041845-1" style="margin-bottom:12px;"></div>
            <script>
            window.yaContextCb.push(() => {
                Ya.Context.AdvManager.render({
                    "blockId": "R-A-19041845-1",
                    "renderTo": "yandex_rtb_R-A-19041845-1"
                })
            })
            </script>
            {$poll_html}
            <div class="news-table" style="border: 1px solid #ccc; background: #fff; margin-top: 12px;">
                <div style="background: #e0e0e0; font-weight: bold; font-size: 14px; padding: 6px;">Сўнгги янгиликлар</div>
                <div class="sidebar-news news-content" style="font-size: 15px; line-height: 1.5; padding: 6px;">
                    {$sidebar_html}
                </div>
            </div>
        </div>
    </div>
    </div>
    </div><!-- end page-content -->

    <!-- FOOTER - PRIVACY POLICY -->
    <div class="footer-privacy">
        <div class="footer-privacy-inner">
            <strong>"InterFUTBOL" gazetasi / internet-nashrining</strong> (O'zbekiston matbuot va axborot agentligi (O'zMAA, O'zbekiston Respublikasi Prezidenti Administratsiyasi huzuridagi Axborot va ommaviy kommunikatsiyalar agentligi) tomonidan 25.06.2008 yil sanasida 0149-sonli guvohnoma bilan ommaviy axborot vositasi sifatida qayta ro'yxatga olingan. Matnli materiallarni to'liq ko'chirish yoki qisman iqtibos keltirishga, shuningdek, fotografik, grafik, audio va/yoki videomateriallaridan foydalanishga <a href="https://iff.uz">"InterFUTBOL.uz"</a> saytiga giperhavola mavjud bo'lgan va/yoki "Interfutbol.uz" internet-nashrining muallifligini ko'rsatuvchi yozuv ilova qilingan taqdirda yo'l qo'yiladi. <strong>Nashr ko'rsatkichi: 629</strong> | <strong>Tahririyat manzili:</strong> 160300, Kosonsoy shaxri, Chorbog' ko'chasi, 17-uy. <strong>E-mail:</strong> zakovat@gmail.com, info@zakovat.uz
        </div>
    </div>
    </div><!-- end main-wrapper -->

    <script>
    var iffContactAjax = {
        ajaxurl: '<?php echo admin_url("admin-ajax.php"); ?>',
        nonce: '<?php echo wp_create_nonce("iff_contact_nonce"); ?>'
    };
    </script>

    <script>
    function toggleSearch(event) {
        event.preventDefault();
        document.getElementById('contactDropdown').classList.remove('active');
        var dropdown = document.getElementById('searchDropdown');
        dropdown.classList.toggle('active');
        if (dropdown.classList.contains('active')) {
            dropdown.querySelector('input').focus();
        }
    }

    function toggleContact(event) {
        event.preventDefault();
        document.getElementById('searchDropdown').classList.remove('active');
        var dropdown = document.getElementById('contactDropdown');
        dropdown.classList.toggle('active');
        if (dropdown.classList.contains('active')) {
            document.getElementById('contactEmail').focus();
        }
    }

    function sendContact() {
        var email = document.getElementById('contactEmail').value;
        var subject = document.getElementById('contactSubject').value || 'Mavzu yoq';
        var message = document.getElementById('contactMessage').value;
        var submitBtn = document.querySelector('#contactForm button');

        if (!email || !message) {
            alert('Iltimos, email va xabarni toldiring!');
            return;
        }

        // Disable button and show loading
        submitBtn.disabled = true;
        submitBtn.textContent = 'Yuborilmoqda...';

        // Send via WordPress REST API
        var xhr = new XMLHttpRequest();
        xhr.open('POST', '/wp-json/iff/v1/contact', true);
        xhr.setRequestHeader('Content-Type', 'application/json');

        xhr.onload = function() {
            try {
                var response = JSON.parse(xhr.responseText);
                if (response.success) {
                    // Show success
                    document.getElementById('contactForm').style.display = 'none';
                    document.getElementById('contactSuccess').style.display = 'block';

                    setTimeout(function() {
                        document.getElementById('contactForm').style.display = 'block';
                        document.getElementById('contactSuccess').style.display = 'none';
                        document.getElementById('contactEmail').value = '';
                        document.getElementById('contactSubject').value = '';
                        document.getElementById('contactMessage').value = '';
                        document.getElementById('contactDropdown').classList.remove('active');
                        submitBtn.disabled = false;
                        submitBtn.textContent = 'Yuborish';
                    }, 2500);
                } else {
                    alert('Xatolik: ' + (response.message || 'Xabar yuborilmadi'));
                    submitBtn.disabled = false;
                    submitBtn.textContent = 'Yuborish';
                }
            } catch(e) {
                alert('Server xatoligi');
                submitBtn.disabled = false;
                submitBtn.textContent = 'Yuborish';
            }
        };

        xhr.onerror = function() {
            alert('Tarmoq xatoligi');
            submitBtn.disabled = false;
            submitBtn.textContent = 'Yuborish';
        };

        xhr.send(JSON.stringify({
            email: email,
            subject: subject,
            message: message
        }));
    }

    // Close dropdowns when clicking outside
    document.addEventListener('click', function(e) {
        var searchContainer = document.querySelector('.search-container');
        var contactContainer = document.querySelector('.contact-container');
        var searchDropdown = document.getElementById('searchDropdown');
        var contactDropdown = document.getElementById('contactDropdown');

        if (searchContainer && searchDropdown && !searchContainer.contains(e.target)) {
            searchDropdown.classList.remove('active');
        }
        if (contactContainer && contactDropdown && !contactContainer.contains(e.target)) {
            contactDropdown.classList.remove('active');
        }
    });

    // Dark mode
    var moonPath = 'M12 3a9 9 0 1 0 9 9c0-.46-.04-.92-.1-1.36a5.389 5.389 0 0 1-4.4 2.26 5.403 5.403 0 0 1-3.14-9.8c-.44-.06-.9-.1-1.36-.1z';
    var sunPath  = 'M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zM2 13h2c.55 0 1-.45 1-1s-.45-1-1-1H2c-.55 0-1 .45-1 1s.45 1 1 1zm18 0h2c.55 0 1-.45 1-1s-.45-1-1-1h-2c-.55 0-1 .45-1 1s.45 1 1 1zM11 2v2c0 .55.45 1 1 1s1-.45 1-1V2c0-.55-.45-1-1-1s-1 .45-1 1zm0 18v2c0 .55.45 1 1 1s1-.45 1-1v-2c0-.55-.45-1-1-1s-1 .45-1 1zM5.99 4.58a.996.996 0 0 0-1.41 0 .996.996 0 0 0 0 1.41l1.06 1.06c.39.39 1.03.39 1.41 0s.39-1.03 0-1.41L5.99 4.58zm12.37 12.37a.996.996 0 0 0-1.41 0 .996.996 0 0 0 0 1.41l1.06 1.06c.39.39 1.03.39 1.41 0a.996.996 0 0 0 0-1.41l-1.06-1.06zm1.06-12.37l-1.06 1.06a.996.996 0 0 0 0 1.41c.39.39 1.03.39 1.41 0l1.06-1.06a.996.996 0 0 0 0-1.41.996.996 0 0 0-1.41 0zM7.05 18.36l-1.06 1.06a.996.996 0 0 0 0 1.41c.39.39 1.03.39 1.41 0l1.06-1.06a.996.996 0 0 0 0-1.41.996.996 0 0 0-1.41 0z';
    function iffSetDarkIcon(isDark) {
        var icon = document.getElementById('btnDarkIcon');
        if (icon) icon.querySelector('path').setAttribute('d', isDark ? sunPath : moonPath);
    }
    function iffToggleDark() {
        var isDark = document.body.classList.toggle('iff-dark');
        iffSetDarkIcon(isDark);
        localStorage.setItem('iff_dark', isDark ? '1' : '0');
    }
    (function() {
        if (localStorage.getItem('iff_dark') === '1') {
            document.body.classList.add('iff-dark');
            iffSetDarkIcon(true);
        }
    })();

    function switchToLatin() {
        var elements = document.querySelectorAll('body *');
        elements.forEach(function(el) {
            if (el.tagName !== 'SCRIPT' && el.tagName !== 'STYLE') {
                for (var i = 0; i < el.childNodes.length; i++) {
                    var node = el.childNodes[i];
                    if (node.nodeType === 3) {
                        node.textContent = convertToLatin(node.textContent);
                    }
                }
            }
        });
        window._iffScript = 'latin';
        ['btnScript','btnScriptInner'].forEach(function(id){var b=document.getElementById(id);if(b){b.textContent='Кир';b.classList.add('active');}});
    }

    function switchToCyrillic() {
        var elements = document.querySelectorAll('body *');
        elements.forEach(function(el) {
            if (el.tagName !== 'SCRIPT' && el.tagName !== 'STYLE') {
                for (var i = 0; i < el.childNodes.length; i++) {
                    var node = el.childNodes[i];
                    if (node.nodeType === 3) {
                        node.textContent = convertToCyrillic(node.textContent);
                    }
                }
            }
        });
        window._iffScript = 'cyrillic';
        ['btnScript','btnScriptInner'].forEach(function(id){var b=document.getElementById(id);if(b){b.textContent='Лотин';b.classList.remove('active');}});
    }

    function toggleScript() {
        if (window._iffScript === 'latin') { switchToCyrillic(); } else { switchToLatin(); }
    }

    function convertToLatin(text) {
        var map = {'А':'A','а':'a','Б':'B','б':'b','В':'V','в':'v','Г':'G','г':'g','Д':'D','д':'d','Е':'E','е':'e','Ё':'Yo','ё':'yo','Ж':'J','ж':'j','З':'Z','з':'z','И':'I','и':'i','Й':'Y','й':'y','К':'K','к':'k','Л':'L','л':'l','М':'M','м':'m','Н':'N','н':'n','О':'O','о':'o','П':'P','п':'p','Р':'R','р':'r','С':'S','с':'s','Т':'T','т':'t','У':'U','у':'u','Ф':'F','ф':'f','Х':'X','х':'x','Ц':'Ts','ц':'ts','Ч':'Ch','ч':'ch','Ш':'Sh','ш':'sh','Щ':'Shch','щ':'shch','Ъ':'','ъ':'','Ы':'I','ы':'i','Ь':'','ь':'','Э':'E','э':'e','Ю':'Yu','ю':'yu','Я':'Ya','я':'ya','Ў':'Oʻ','ў':'oʻ','Қ':'Q','қ':'q','Ғ':'Gʻ','ғ':'gʻ','Ҳ':'H','ҳ':'h'};
        return text.split('').map(function(char) { return map[char] || char; }).join('');
    }

    function convertToCyrillic(text) {
        var map = {'A':'А','a':'а','B':'Б','b':'б','V':'В','v':'в','G':'Г','g':'г','D':'Д','d':'д','E':'Е','e':'е','Yo':'Ё','yo':'ё','J':'Ж','j':'ж','Z':'З','z':'з','I':'И','i':'и','Y':'Й','y':'й','K':'К','k':'к','L':'Л','l':'л','M':'М','m':'м','N':'Н','n':'н','O':'О','o':'о','P':'П','p':'п','R':'Р','r':'р','S':'С','s':'с','T':'Т','t':'т','U':'У','u':'у','F':'Ф','f':'ф','X':'Х','x':'х','Ch':'Ч','ch':'ч','Sh':'Ш','sh':'ш','Oʻ':'Ў','oʻ':'ў','Q':'Қ','q':'қ','Gʻ':'Ғ','gʻ':'ғ','H':'Ҳ','h':'ҳ'};
        var result = text;
        Object.keys(map).sort(function(a,b){return b.length-a.length;}).forEach(function(key) {
            result = result.split(key).join(map[key]);
        });
        return result;
    }

    // ── YouTube video player ──────────────────────────────────────
    function iffPlayVideo(el, videoId) {
        var wrap = el.querySelector('.yt-iframe-wrap');
        var img  = el.querySelector('.yt-thumb');
        var btn  = el.querySelector('.yt-play-btn');
        if (!wrap) return;
        wrap.style.display = 'block';
        if (img)  img.style.display = 'none';
        if (btn)  btn.style.display = 'none';
        var iframe = wrap.querySelector('iframe');
        if (iframe && !iframe.src) {
            iframe.src = 'https://www.youtube.com/embed/' + videoId + '?autoplay=1&rel=0';
        }
    }

    // Switch to a different video in the ESPN-style player
    function iffSwitchVideo(idx) {
        var items  = document.querySelectorAll('.iff-video-item');
        var thumbs = document.querySelectorAll('.iff-thumb-item');

        items.forEach(function(item, i) {
            // Stop any playing iframe
            var iframe = item.querySelector('iframe');
            if (iframe) iframe.src = '';
            var wrap = item.querySelector('.yt-iframe-wrap');
            if (wrap) wrap.style.display = 'none';
            var img = item.querySelector('.yt-thumb');
            if (img) img.style.display = 'block';
            var btn = item.querySelector('.yt-play-btn');
            if (btn) btn.style.display = 'flex';
            item.style.display = (i === idx) ? 'block' : 'none';
        });

        thumbs.forEach(function(t, i) {
            t.style.outline = (i === idx) ? '2px solid #c00' : 'none';
        });
    }

    // ── Toggle comment panel (YouTube-style dropdown) ─────────────
    function iffToggleComments(pollKey) {
        var panel = document.getElementById('iff-comment-panel-' + pollKey);
        var arrow = document.getElementById('iff-comment-arrow-' + pollKey);
        if (!panel) return;
        var open = panel.style.display === 'block';
        panel.style.display = open ? 'none' : 'block';
        if (arrow) arrow.style.transform = open ? '' : 'rotate(180deg)';
    }

    // ── Poll comment submission ───────────────────────────────────
    function iffSubmitComment(pollKey) {
        var nameEl = document.getElementById('iff-comment-name-' + pollKey);
        var textEl = document.getElementById('iff-comment-text-' + pollKey);
        var container = document.getElementById('iff-poll-comments-' + pollKey);
        if (!nameEl || !textEl || !container) return;

        var name = nameEl.value.trim();
        var text = textEl.value.trim();
        if (!text) { textEl.focus(); return; }
        // Auto-generate name if blank
        if (!name) { name = 'Меҳмон' + Math.floor(1000 + Math.random() * 9000); }

        var btn = textEl.parentNode.querySelector('button');
        if (btn) { btn.disabled = true; btn.textContent = '...'; }

        var xhr = new XMLHttpRequest();
        xhr.open('POST', '/wp-json/iff/v1/poll-comment', true);
        xhr.setRequestHeader('Content-Type', 'application/json');
        xhr.onload = function() {
            if (xhr.status === 200) {
                var data = JSON.parse(xhr.responseText);
                var c = data.comment;
                var div = document.createElement('div');
                div.style.cssText = 'border-top:1px solid #f0f0f0;padding:7px 0;';
                div.innerHTML = '<div style="display:flex;justify-content:space-between;margin-bottom:2px;">'
                    + '<span style="font-size:12px;font-weight:bold;color:#333;">' + c.name + '</span>'
                    + '<span style="font-size:10px;color:#aaa;">' + c.time + '</span></div>'
                    + '<div style="font-size:12px;color:#555;line-height:1.4;">' + c.text + '</div>';
                container.insertBefore(div, container.firstChild);
                nameEl.value = '';
                textEl.value = '';
                // Update comment count label
                var countEl = container.parentNode.previousSibling;
                if (countEl) {
                    var spans = container.parentNode.parentNode.querySelectorAll('span[style*="color:#999"]');
                    spans.forEach(function(s) { if (s.textContent.indexOf('(') > -1) { /* update */ } });
                }
            }
            if (btn) { btn.disabled = false; btn.textContent = 'Фикр қолдириш'; }
        };
        xhr.onerror = function() {
            if (btn) { btn.disabled = false; btn.textContent = 'Фикр қолдириш'; }
        };
        xhr.send(JSON.stringify({ poll_key: pollKey, name: name, text: text }));
    }

    // ── YouTube-style poll: select option ────────────────────────
    function iffSelectOption(el, pollKey) {
        var form = document.getElementById('iff-poll-form-' + pollKey);
        if (!form) return;
        form.querySelectorAll('.iff-poll-option').forEach(function(o) { o.classList.remove('yt-selected'); });
        el.classList.add('yt-selected');
    }

    // ── YouTube-style poll: submit vote ──────────────────────────
    function iffSubmitPoll(pollKey) {
        var form    = document.getElementById('iff-poll-form-' + pollKey);
        var results = document.getElementById('iff-poll-results-' + pollKey);
        if (!form) return;

        var selected = form.querySelector('.iff-poll-option.yt-selected');
        if (!selected) {
            // Briefly shake unselected options to hint user
            form.querySelectorAll('.iff-poll-option').forEach(function(o) {
                o.style.transition = 'border-color 0.1s';
                o.style.borderColor = '#c00';
                setTimeout(function() { o.style.borderColor = ''; }, 600);
            });
            return;
        }
        var optionIndex = selected.getAttribute('data-idx');

        var btn = form.querySelector('.iff-vote-btn');
        if (btn) { btn.disabled = true; btn.textContent = '...'; }

        var xhr = new XMLHttpRequest();
        xhr.open('POST', '/wp-json/iff/v1/poll-vote', true);
        xhr.setRequestHeader('Content-Type', 'application/json');
        xhr.onload = function() {
            if (xhr.status === 200) {
                var data = JSON.parse(xhr.responseText);
                // Mark voted bar + animate fills
                results.querySelectorAll('.iff-poll-bar').forEach(function(bar) {
                    var idx = bar.getAttribute('data-idx');
                    var pct = data.percentages[idx] || 0;
                    if (idx === optionIndex) bar.classList.add('yt-voted');
                    var fill  = bar.querySelector('.iff-bar-fill');
                    var label = bar.querySelector('[data-label]');
                    if (label) label.textContent = pct + '%';
                    // Delay width so CSS transition plays after display:block
                    if (fill) setTimeout(function() { fill.style.width = pct + '%'; }, 60);
                });
                var totalEl = results.querySelector('[data-total]');
                if (totalEl) totalEl.textContent = data.total.toLocaleString() + ' та овоз';
                form.style.display = 'none';
                results.style.display = 'block';
                try { localStorage.setItem('iff_voted_' + pollKey, optionIndex); } catch(e) {}
            } else {
                if (btn) { btn.disabled = false; btn.textContent = 'Овоз бериш'; }
            }
        };
        xhr.onerror = function() {
            if (btn) { btn.disabled = false; btn.textContent = 'Овоз бериш'; }
        };
        xhr.send(JSON.stringify({ poll_key: pollKey, option: optionIndex }));
    }

    // On page load: restore voted state from localStorage
    (function() {
        var forms = document.querySelectorAll('[id^="iff-poll-form-"]');
        forms.forEach(function(form) {
            var key = form.id.replace('iff-poll-form-', '');
            try {
                var votedIdx = localStorage.getItem('iff_voted_' + key);
                if (votedIdx !== null) {
                    form.style.display = 'none';
                    var results = document.getElementById('iff-poll-results-' + key);
                    if (results) {
                        results.style.display = 'block';
                        var votedBar = results.querySelector('.iff-poll-bar[data-idx="' + votedIdx + '"]');
                        if (votedBar) votedBar.classList.add('yt-voted');
                    }
                }
            } catch(e) {}
        });
    })();

    // Footer: show only when scrolled to bottom
    (function() {
        var footer = document.querySelector('.footer-privacy');
        if (!footer) return;

        // Move footer to body
        document.body.appendChild(footer);

        function checkScroll() {
            var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
            var windowHeight = window.innerHeight;
            var docHeight = document.documentElement.scrollHeight;

            // Show footer when near bottom (within 100px)
            if (scrollTop + windowHeight >= docHeight - 100) {
                footer.style.display = 'block';
            } else {
                footer.style.display = 'none';
            }
        }

        window.addEventListener('scroll', checkScroll);
        window.addEventListener('resize', checkScroll);

        // Initial check
        setTimeout(checkScroll, 100);
    })();
    </script>
    HTML;

        return $output;
    }
    } // end function_exists interfutbol_dynamic_layout

    
// Track post views on single post pages
add_action('wp_head', function() {
    if (is_single()) {
        $id    = get_the_ID();
        $count = (int) get_post_meta($id, '_iff_views', true);
        update_post_meta($id, '_iff_views', $count + 1);
    }
});

add_shortcode('interfutbol_layout', 'interfutbol_dynamic_layout');

add_filter('should_load_remote_block_patterns', '__return_false');