<?php
// Ensure session is started and jump to the root for configuration
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

require_once __DIR__ . '/../config/config.php';
require_once __DIR__ . '/includes/ad-display.php';

$settings_file = __DIR__ . '/../config/site-settings.json';
$site_name = 'tipspac';
if (file_exists($settings_file)) {
    $loaded = json_decode(file_get_contents($settings_file), true);
    if (!empty($loaded['site_name'])) $site_name = $loaded['site_name'];
}

// ==========================================
// DYNAMIC HEADLESS CMS INJECTION
// ==========================================
try {
    $stmt = $pdo->query("SELECT content_key, content_value FROM page_content WHERE page_slug = 'home'");
    $content_matrix = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
} catch (PDOException $e) {
    $content_matrix = [];
}

function get_content($key, $default_text) {
    global $content_matrix;
    return isset($content_matrix[$key]) && trim($content_matrix[$key]) !== '' 
        ? $content_matrix[$key] 
        : $default_text;
}

// Fetch dynamic active subscription plans
try {
    $plan_stmt = $pdo->query("SELECT * FROM subscription_plans WHERE status = 'active' ORDER BY price ASC LIMIT 3");
    $active_plans = $plan_stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $active_plans = [];
}

$is_logged_in = isset($_SESSION['user_id']);
?>

<?php require_once __DIR__ . '/includes/header.php'; ?>

<!-- Neural Background -->
<div class="fixed inset-0 z-0 pointer-events-none opacity-20 bg-cover bg-center bg-no-repeat" style="background-image: url('https://images.unsplash.com/photo-1579952363873-27f3bade9f55?q=80&w=2000&auto=format&fit=crop');"></div>
<div class="fixed inset-0 z-0 bg-gradient-to-t from-[#020617] via-[#020617]/85 to-transparent pointer-events-none"></div>
<canvas id="neuralCanvas" class="fixed inset-0 w-full h-full pointer-events-none z-0 opacity-40"></canvas>

<main class="relative z-10 flex-1 w-full flex flex-col items-center pt-2 pb-10">

    <!-- ========== HERO SECTION ========== -->
    <section class="w-full max-w-5xl mx-auto px-4 flex flex-col items-center text-center space-y-5 mt-2 md:mt-8">
        <!-- Status Badge -->
        <div class="relative group cursor-pointer">
            <div class="absolute -inset-1 bg-gradient-to-r from-emerald-500 to-cyan-500 rounded-full blur opacity-25 group-hover:opacity-75 transition duration-500"></div>
            <div class="relative flex items-center space-x-2 bg-slate-900/80 backdrop-blur-md border border-slate-700/50 px-4 py-1.5 rounded-full text-[9px] md:text-xs font-bold tracking-widest uppercase text-emerald-400">
                <span class="relative flex h-2 w-2">
                    <span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75"></span>
                    <span class="relative inline-flex rounded-full h-2 w-2 bg-emerald-500"></span>
                </span>
                <span>Neural Engine v2.0 Online</span>
            </div>
        </div>

        <!-- Headline -->
        <h1 class="text-4xl sm:text-5xl md:text-7xl font-extrabold tracking-tight text-white max-w-4xl leading-tight drop-shadow-2xl">
            <?php echo htmlspecialchars(get_content('home_hero_title', 'Smarter Predictions')); ?><br/>
            <span class="text-transparent bg-clip-text bg-gradient-to-r from-emerald-400 via-cyan-400 to-blue-500">
                Driven by <span id="typing-text" class="border-r-4 border-emerald-400 pr-1"></span>
            </span>
        </h1>

        <!-- Description -->
        <p class="text-[11px] sm:text-sm md:text-lg text-slate-300 max-w-2xl leading-relaxed font-medium drop-shadow-md px-2">
            <?php echo nl2br(htmlspecialchars(get_content('home_hero_subtitle', 'Stop guessing. Our exclusive machine-learning algorithms process millions of historical data points and tactical conditions to yield highly calculated match outcomes.'))); ?>
        </p>

        <!-- CTA -->
        <div class="flex items-center justify-center pt-3 w-full max-w-[250px] sm:max-w-sm px-2">
            <a href="login-register.php" class="relative group w-full block">
                <div class="absolute -inset-1 bg-gradient-to-r from-emerald-500 via-cyan-500 to-blue-500 rounded-2xl sm:rounded-3xl blur opacity-70 group-hover:opacity-100 transition duration-500 group-hover:duration-200 animate-pulse"></div>
                <div class="relative w-full flex items-center justify-center px-6 py-3.5 sm:px-8 sm:py-4 bg-[#020617] rounded-2xl sm:rounded-3xl text-white font-black tracking-widest text-[10px] sm:text-sm uppercase hover:bg-transparent transition-colors duration-300 shadow-[0_0_20px_rgba(56,189,248,0.3)]">
                    <span><?php echo htmlspecialchars(get_content('home_cta_button', 'Get Started Now')); ?></span>
                    <svg class="w-4 h-4 ml-2 group-hover:translate-x-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7l5 5m0 0l-5 5m5-5H6"></path></svg>
                </div>
            </a>
        </div>
    </section>

    <!-- ========== STATS CAROUSEL ========== -->
    <style>
        .hide-scrollbar::-webkit-scrollbar { display: none; }
        .hide-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
        .drag-slider { cursor: grab; }
        .drag-slider:active { cursor: grabbing; }
        .stat-card {
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        }
        .stat-card:hover {
            transform: translateY(-4px) scale(1.02);
            border-color: rgba(16, 185, 129, 0.5);
        }
    </style>

    <div class="w-full max-w-5xl mx-auto pt-10 md:pt-16 overflow-hidden">
        <div id="statsCarousel" class="drag-slider flex overflow-x-auto snap-x snap-mandatory gap-4 md:grid md:grid-cols-4 md:gap-6 hide-scrollbar pb-6 px-4 w-full scroll-smooth" style="-webkit-overflow-scrolling: touch;">
            <div class="shrink-0 w-[70%] sm:w-[45%] md:w-auto snap-center stat-card relative bg-slate-900/60 backdrop-blur-xl border border-slate-700/50 p-5 md:p-6 rounded-2xl md:rounded-3xl hover:border-emerald-500/50 transition-all duration-500 text-center select-none">
                <span class="block text-2xl md:text-3xl mb-1 md:mb-2 pointer-events-none">🧠</span>
                <span class="text-[9px] md:text-[10px] text-slate-400 uppercase tracking-widest font-bold pointer-events-none">Algorithms Active</span>
                <span class="block text-2xl md:text-3xl font-black text-white mt-1 tracking-tight counter pointer-events-none" data-target="162">0</span>
            </div>
            <div class="shrink-0 w-[70%] sm:w-[45%] md:w-auto snap-center stat-card relative bg-slate-900/60 backdrop-blur-xl border border-slate-700/50 p-5 md:p-6 rounded-2xl md:rounded-3xl hover:border-emerald-500/50 transition-all duration-500 text-center select-none">
                <span class="block text-2xl md:text-3xl mb-1 md:mb-2 pointer-events-none">🎯</span>
                <span class="text-[9px] md:text-[10px] text-slate-400 uppercase tracking-widest font-bold pointer-events-none">Win-Rate Accuracy</span>
                <span class="block text-2xl md:text-3xl font-black text-emerald-400 mt-1 tracking-tight pointer-events-none"><span class="counter" data-target="84">0</span>%</span>
            </div>
            <div class="shrink-0 w-[70%] sm:w-[45%] md:w-auto snap-center stat-card relative bg-slate-900/60 backdrop-blur-xl border border-slate-700/50 p-5 md:p-6 rounded-2xl md:rounded-3xl hover:border-emerald-500/50 transition-all duration-500 text-center select-none">
                <span class="block text-2xl md:text-3xl mb-1 md:mb-2 pointer-events-none">⚡</span>
                <span class="text-[9px] md:text-[10px] text-slate-400 uppercase tracking-widest font-bold pointer-events-none">Computed Matches</span>
                <span class="block text-2xl md:text-3xl font-black text-white mt-1 tracking-tight pointer-events-none"><span class="counter" data-target="256">0</span>k+</span>
            </div>
            <div class="shrink-0 w-[70%] sm:w-[45%] md:w-auto snap-center stat-card relative bg-slate-900/60 backdrop-blur-xl border border-slate-700/50 p-5 md:p-6 rounded-2xl md:rounded-3xl hover:border-emerald-500/50 transition-all duration-500 text-center select-none">
                <span class="block text-2xl md:text-3xl mb-1 md:mb-2 pointer-events-none">⏱️</span>
                <span class="text-[9px] md:text-[10px] text-slate-400 uppercase tracking-widest font-bold pointer-events-none">Uptime Compute</span>
                <span class="block text-2xl md:text-3xl font-black text-amber-400 mt-1 tracking-tight pointer-events-none"><span class="counter" data-target="99">0</span>.9%</span>
            </div>
        </div>
    </div>

    <!-- ========== DATA SOURCES ========== -->
    <div class="w-full border-y border-slate-800/60 bg-slate-950/40 backdrop-blur mt-4 mb-10 py-6">
        <div class="max-w-5xl mx-auto px-4 flex flex-col items-center">
            <span class="text-[10px] uppercase tracking-widest font-bold text-slate-500 mb-4">Integrated Data Sources & Coverage</span>
            <div class="flex flex-wrap justify-center items-center gap-6 md:gap-12 opacity-60 grayscale hover:grayscale-0 transition-all duration-500">
                <span class="text-sm md:text-lg font-black tracking-tighter text-white">OneFootball</span>
                <span class="text-sm md:text-lg font-black tracking-tighter text-white">FlashScore</span>
                <span class="text-sm md:text-lg font-black tracking-tighter text-white">BeSoccer</span>
                <span class="text-sm md:text-lg font-black tracking-tighter text-white">SofaScore</span>
                <span class="text-sm md:text-lg font-black tracking-tighter text-white">OptaData</span>
            </div>
        </div>
    </div>

    <!-- ========== STORY SECTION ========== -->
    <section class="w-full max-w-5xl mx-auto px-4 py-10 md:py-16">
        <div class="grid grid-cols-1 md:grid-cols-2 gap-10 items-center">
            <div>
                <span class="text-emerald-400 font-bold tracking-widest text-[10px] uppercase mb-2 block">
                    <?php echo htmlspecialchars(get_content('home_story_pretitle', 'Our Story')); ?>
                </span>
                <h2 class="text-3xl md:text-4xl font-black text-white tracking-tight mb-4">
                    <?php echo htmlspecialchars(get_content('home_story_title', 'Engineered to')); ?> <span class="text-transparent bg-clip-text bg-gradient-to-r from-emerald-400 to-cyan-400">Win.</span>
                </h2>
                <div class="space-y-4 text-sm text-slate-400 leading-relaxed">
                    <p><?php echo nl2br(htmlspecialchars(get_content('home_story_p1', 'We developed a proprietary AI football prediction engine that uses deep machine learning to generate accurate, emotionless, data-driven tips.'))); ?></p>
                    <p><strong class="text-white">Constantly Evolving:</strong> <?php echo nl2br(htmlspecialchars(get_content('home_story_p2', 'Our algorithm undergoes daily learning processes to enhance the accuracy of its AI-powered networks after every single match.'))); ?></p>
                    <p><strong class="text-white">Proven Results:</strong> <?php echo nl2br(htmlspecialchars(get_content('home_story_p3', 'Since deployment, our core engine has analyzed over 256,185 matches across the globe with unmatched consistency.'))); ?></p>
                </div>
            </div>
            <div class="relative bg-slate-900/60 backdrop-blur border border-slate-800 rounded-3xl p-6 overflow-hidden">
                <div class="absolute -top-10 -right-10 w-40 h-40 bg-emerald-500/20 rounded-full blur-3xl"></div>
                <pre class="text-[10px] md:text-xs text-emerald-400 font-mono overflow-x-hidden opacity-80 select-none">
function evaluateMatch(home, away) {
  let xG_Home = NeuralNet.calcXG(home.form);
  let xG_Away = NeuralNet.calcXG(away.form);
  let poisson = Distribution.analyze(xG_Home, xG_Away);
  
  if (poisson.prob > 0.84) {
      return { 
         pick: "OVER 2.5", 
         confidence: "89%", 
         status: "VERIFIED" 
      };
  }
}
// AI Engine Processing... 14,203 metrics parsed.
                </pre>
            </div>
        </div>
    </section>

    <!-- ========== PREMIUM SLIPS ========== -->
    <?php
    try {
        $slip_query = "SELECT match_time, team_a, team_b, game_option, access_tier FROM admin_manual_tips WHERE tip_type = 'SLIP' AND match_date = CURDATE() ORDER BY match_time ASC LIMIT 5";
        $homepage_slips = $pdo->query($slip_query)->fetchAll(PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
        $homepage_slips = []; 
    }
    $is_vip = isset($_SESSION['user_tier']) && $_SESSION['user_tier'] === 'VIP';
    ?>

    <section class="w-full max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-16 relative z-10">
        <div class="flex flex-col md:flex-row md:items-end justify-between mb-8">
            <div>
                <div class="inline-flex items-center space-x-2 bg-amber-500/10 border border-amber-500/20 px-3 py-1 rounded-full text-[9px] font-bold tracking-widest uppercase text-amber-500 mb-3">
                    <span class="w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse"></span>
                    <span>VIP Accumulators</span>
                </div>
                <h2 class="text-3xl md:text-4xl font-black text-white tracking-tight">
                    <?php echo htmlspecialchars(get_content('home_slips_title', 'Collection')); ?> <span class="text-transparent bg-clip-text bg-gradient-to-r from-amber-400 to-orange-400">Premium Slips</span>
                </h2>
                <p class="text-sm text-slate-400 mt-2">
                    <?php echo htmlspecialchars(get_content('home_slips_subtitle', 'Highly curated accumulator selections managed by our core administration team.')); ?>
                </p>
            </div>
            <a href="bet-of-the-day.php" class="mt-4 md:mt-0 text-xs font-bold text-amber-500 hover:text-amber-400 uppercase tracking-widest flex items-center transition">
                Open Main Terminal 
                <svg class="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path></svg>
            </a>
        </div>

        <div class="bg-slate-900/60 backdrop-blur-xl border border-slate-800 rounded-3xl overflow-hidden shadow-2xl">
            <div class="hidden md:grid grid-cols-12 gap-4 p-5 border-b border-slate-800 bg-slate-950/40 text-[10px] font-black tracking-widest uppercase text-slate-500">
                <div class="col-span-6 pl-2">Match Fixture</div>
                <div class="col-span-2 text-center">Tier</div>
                <div class="col-span-2 text-center">Accumulator Pick</div>
                <div class="col-span-2 text-right pr-2">Action</div>
            </div>

            <div class="divide-y divide-slate-800/60">
                <?php if (empty($homepage_slips)): ?>
                    <div class="p-10 text-center text-xs text-slate-500 font-bold uppercase tracking-widest">
                        Today's combo slips are currently being finalized. Check back shortly.
                    </div>
                <?php else: ?>
                    <?php foreach ($homepage_slips as $slip): 
                        $is_premium = ($slip['access_tier'] === 'VIP');
                        $is_unlocked = !$is_premium || $is_vip; 
                    ?>
                        <div class="flex flex-col md:grid md:grid-cols-12 gap-4 p-5 hover:bg-slate-800/30 transition items-center">
                            
                            <div class="col-span-6 flex items-center space-x-4 w-full">
                                <span class="text-[10px] font-mono font-bold text-slate-500"><?php echo htmlspecialchars($slip['match_time']); ?></span>
                                <div class="font-bold text-sm text-white truncate">
                                    <?php echo htmlspecialchars($slip['team_a']); ?> 
                                    <span class="text-slate-600 font-normal mx-1">vs</span> 
                                    <?php echo htmlspecialchars($slip['team_b']); ?>
                                </div>
                            </div>

                            <div class="col-span-2 text-center w-full mt-3 md:mt-0 flex justify-between md:justify-center items-center">
                                <span class="md:hidden text-[9px] font-bold text-slate-500 uppercase tracking-widest">Access Tier:</span>
                                <?php if ($is_premium): ?>
                                    <span class="text-[9px] font-black tracking-widest text-amber-500 uppercase">👑 VIP</span>
                                <?php else: ?>
                                    <span class="text-[9px] font-black tracking-widest text-emerald-400 uppercase">👤 FREE</span>
                                <?php endif; ?>
                            </div>

                            <div class="col-span-2 text-center w-full mt-2 md:mt-0 flex justify-between md:justify-center items-center">
                                <span class="md:hidden text-[9px] font-bold text-slate-500 uppercase tracking-widest">Prediction:</span>
                                <?php if ($is_unlocked): ?>
                                    <span class="font-extrabold text-amber-400 text-sm md:text-base tracking-wider">
                                        <?php echo htmlspecialchars($slip['game_option']); ?>
                                    </span>
                                <?php else: ?>
                                    <span class="bg-slate-800 text-transparent font-black px-3 py-1 rounded-lg text-xs tracking-wider blur-[5px] select-none">
                                        LOCKED
                                    </span>
                                <?php endif; ?>
                            </div>

                            <div class="col-span-2 text-right w-full mt-4 md:mt-0 flex justify-end">
                                <?php if ($is_unlocked): ?>
                                    <a href="bet-of-the-day.php" class="bg-slate-800 hover:bg-slate-700 border border-slate-600 text-white font-bold px-4 py-2 rounded-xl text-[10px] tracking-widest uppercase transition">
                                        View Slip
                                    </a>
                                <?php else: ?>
                                    <a href="login-register.php" class="bg-gradient-to-r from-amber-500 to-orange-500 text-slate-950 font-black px-4 py-2 rounded-xl text-[10px] tracking-widest uppercase transition shadow-lg shadow-amber-900/30 hover:opacity-90">
                                        Unlock VIP
                                    </a>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endforeach; ?>
                <?php endif; ?>
            </div>
        </div>
    </section>

    <!-- ========== LEAGUE COVERAGE ========== -->
    <section class="w-full max-w-5xl mx-auto px-4 py-12 text-center">
        <h2 class="text-xl md:text-2xl font-black text-white tracking-tight mb-2">
            <?php echo htmlspecialchars(get_content('home_leagues_title', 'Analyzing 160+ Leagues Worldwide')); ?>
        </h2>
        <p class="text-[10px] md:text-xs text-slate-400 mb-8 max-w-md mx-auto">
            <?php echo htmlspecialchars(get_content('home_leagues_subtitle', 'From the Premier League down to local second-divisions, our AI misses nothing.')); ?>
        </p>
        
        <div class="flex flex-wrap justify-center gap-3">
            <span class="bg-slate-900/50 border border-slate-700/50 text-slate-300 text-xs px-4 py-2 rounded-lg font-bold hover:border-emerald-500/50 hover:bg-slate-800/50 transition-all">Premier League</span>
            <span class="bg-slate-900/50 border border-slate-700/50 text-slate-300 text-xs px-4 py-2 rounded-lg font-bold hover:border-emerald-500/50 hover:bg-slate-800/50 transition-all">La Liga</span>
            <span class="bg-slate-900/50 border border-slate-700/50 text-slate-300 text-xs px-4 py-2 rounded-lg font-bold hover:border-emerald-500/50 hover:bg-slate-800/50 transition-all">Bundesliga</span>
            <span class="bg-slate-900/50 border border-slate-700/50 text-slate-300 text-xs px-4 py-2 rounded-lg font-bold hover:border-emerald-500/50 hover:bg-slate-800/50 transition-all">Serie A</span>
            <span class="bg-slate-900/50 border border-slate-700/50 text-slate-300 text-xs px-4 py-2 rounded-lg font-bold hover:border-emerald-500/50 hover:bg-slate-800/50 transition-all">Ligue 1</span>
            <span class="bg-slate-900/50 border border-slate-700/50 text-slate-300 text-xs px-4 py-2 rounded-lg font-bold hover:border-emerald-500/50 hover:bg-slate-800/50 transition-all">Champions League</span>
            <span class="bg-slate-900/50 border border-slate-700/50 text-slate-300 text-xs px-4 py-2 rounded-lg font-bold hover:border-emerald-500/50 hover:bg-slate-800/50 transition-all">+ 154 More</span>
        </div>
    </section>

    <!-- ========== HOW IT WORKS ========== -->
    <section class="w-full max-w-5xl mx-auto px-4 py-10">
        <div class="text-center mb-10">
            <h2 class="text-2xl md:text-3xl font-black text-white tracking-tight">
                <?php echo htmlspecialchars(get_content('home_how_title', 'How Our Engine Works')); ?>
            </h2>
            <p class="text-[10px] md:text-xs text-slate-400 mt-2 max-w-xl mx-auto">
                <?php echo nl2br(htmlspecialchars(get_content('home_how_subtitle', 'Transparency is our priority. Here is how we turn raw data into profitable betting intelligence.'))); ?>
            </p>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
            <div class="bg-slate-900/50 backdrop-blur border border-slate-800 p-6 rounded-2xl text-center md:text-left hover:border-emerald-500/30 transition-all duration-300 group">
                <div class="w-10 h-10 bg-blue-500/10 rounded-lg flex items-center justify-center mb-4 mx-auto md:mx-0 group-hover:scale-110 transition-transform">
                    <svg class="w-5 h-5 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"></path></svg>
                </div>
                <h3 class="text-sm font-bold text-white mb-2 uppercase tracking-wider">1. Data Integration</h3>
                <p class="text-[11px] text-slate-400 leading-relaxed">We extract verified stats, xG data, and tactical injury news from official licensed providers in real-time.</p>
            </div>
            
            <div class="bg-slate-900/50 backdrop-blur border border-slate-800 p-6 rounded-2xl text-center md:text-left hover:border-emerald-500/30 transition-all duration-300 group">
                <div class="w-10 h-10 bg-amber-500/10 rounded-lg flex items-center justify-center mb-4 mx-auto md:mx-0 group-hover:scale-110 transition-transform">
                    <svg class="w-5 h-5 text-amber-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"></path></svg>
                </div>
                <h3 class="text-sm font-bold text-white mb-2 uppercase tracking-wider">2. Validation</h3>
                <p class="text-[11px] text-slate-400 leading-relaxed">Every dataset is cleaned. We remove statistical noise to ensure the engine only processes pure, factual logic.</p>
            </div>

            <div class="bg-slate-900/50 backdrop-blur border border-slate-800 p-6 rounded-2xl text-center md:text-left hover:border-emerald-500/30 transition-all duration-300 group">
                <div class="w-10 h-10 bg-emerald-500/10 rounded-lg flex items-center justify-center mb-4 mx-auto md:mx-0 group-hover:scale-110 transition-transform">
                    <svg class="w-5 h-5 text-emerald-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>
                </div>
                <h3 class="text-sm font-bold text-white mb-2 uppercase tracking-wider">3. Neural Processing</h3>
                <p class="text-[11px] text-slate-400 leading-relaxed">The AI combines neural networks with pattern recognition to output probabilities that consistently outperform human intuition.</p>
            </div>
        </div>
    </section>

    <!-- ========== TESTIMONIALS ========== -->
    <section class="w-full max-w-5xl mx-auto px-4 pt-8 pb-12">
        <div class="flex flex-col items-center justify-center mb-8">
            <h2 class="text-lg md:text-xl font-bold text-white uppercase tracking-widest text-center mb-2">Trusted by Bettors Worldwide</h2>
            <div class="flex items-center space-x-1">
                <span class="text-emerald-500 font-black text-lg">★</span>
                <span class="text-emerald-500 font-black text-lg">★</span>
                <span class="text-emerald-500 font-black text-lg">★</span>
                <span class="text-emerald-500 font-black text-lg">★</span>
                <span class="text-emerald-500 font-black text-lg">★</span>
                <span class="text-[10px] text-slate-400 font-bold ml-2">Excellent 4.9/5</span>
            </div>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
            <div class="bg-slate-900/40 backdrop-blur border border-slate-800 p-5 rounded-xl hover:border-emerald-500/30 transition-all">
                <p class="text-xs text-slate-300 italic mb-3">"The accuracy on the Over 2.5 goals market is insane. Way better than standard tipping sites because it strips out the emotion. Highly recommend."</p>
                <div class="flex items-center space-x-2">
                    <div class="w-6 h-6 bg-blue-600 rounded-full flex items-center justify-center text-[10px] font-bold text-white">JD</div>
                    <span class="text-[10px] font-bold text-slate-400">John D. <span class="text-emerald-400 ml-1">✓ Verified</span></span>
                </div>
            </div>
            <div class="bg-slate-900/40 backdrop-blur border border-slate-800 p-5 rounded-xl hidden md:block hover:border-emerald-500/30 transition-all">
                <p class="text-xs text-slate-300 italic mb-3">"I was skeptical at first, but the consistency of the AI Engine is undeniable. My ROI has steadily climbed since I switched to the Pro plan."</p>
                <div class="flex items-center space-x-2">
                    <div class="w-6 h-6 bg-amber-600 rounded-full flex items-center justify-center text-[10px] font-bold text-white">MK</div>
                    <span class="text-[10px] font-bold text-slate-400">Marcus K. <span class="text-emerald-400 ml-1">✓ Verified</span></span>
                </div>
            </div>
        </div>
    </section>

    <!-- ========== AD SLOT ========== -->
    <div class="w-full max-w-4xl mx-auto px-4 pt-2 pb-6">
        <?php display_ad_slot($pdo, 'in_content'); ?>
    </div>

    <!-- ========== PRICING MATRIX ========== -->
    <section id="pricing-matrix" class="w-full max-w-6xl mx-auto px-4 pt-8 pb-16">
        <div class="text-center mb-12">
            <h2 class="text-3xl md:text-5xl font-black text-white tracking-tight mb-4">
                <?php echo htmlspecialchars(get_content('home_pricing_title', 'Unlock the Neural Network')); ?>
            </h2>
            <p class="text-sm md:text-base text-slate-400 max-w-2xl mx-auto">
                <?php echo htmlspecialchars(get_content('home_pricing_subtitle', 'All plans include complete platform data access. Cancel effortlessly anytime.')); ?>
            </p>
        </div>

        <?php if (empty($active_plans)): ?>
            <div class="bg-slate-900/60 border border-slate-800 rounded-3xl p-10 text-center max-w-2xl mx-auto">
                <span class="text-slate-500 text-xs font-bold uppercase tracking-widest block mb-2">No Content Configured</span>
                <p class="text-slate-400 text-sm">Add dynamic subscription plans in the admin terminal.</p>
            </div>
        <?php else: ?>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8 md:gap-6 lg:gap-8 items-stretch">
                <?php foreach ($active_plans as $plan): 
                    $is_popular = $plan['is_popular'];
                    $card_bg = $is_popular 
                        ? 'bg-slate-900/90 backdrop-blur-2xl border-2 border-emerald-500/60 rounded-[2rem] p-8 text-center shadow-[0_0_50px_-12px_rgba(16,185,129,0.2)] md:scale-105 z-10 transition-all duration-300 hover:-translate-y-2 relative flex flex-col justify-between' 
                        : 'bg-slate-900/60 backdrop-blur-xl border border-slate-700/80 hover:border-slate-600 rounded-[2rem] p-8 text-center transition-all duration-300 hover:-translate-y-2 relative flex flex-col justify-between shadow-[0_0_50px_-16px_rgba(0,0,0,0.5)]';
                ?>
                    <div class="<?php echo $card_bg; ?>">
                        
                        <?php if ($is_popular): ?>
                            <div class="absolute -top-4 left-1/2 transform -translate-x-1/2 bg-gradient-to-r from-emerald-400 to-cyan-500 text-slate-950 font-black text-[10px] tracking-widest uppercase px-4 py-1.5 rounded-full shadow-lg whitespace-nowrap border border-cyan-200/50">
                                Most Popular 🔥
                            </div>
                        <?php endif; ?>
                        
                        <div>
                            <span class="text-xs font-black tracking-widest uppercase text-slate-400 mb-2 block mt-2">
                                <?php echo htmlspecialchars($plan['plan_name']); ?>
                            </span>
                            
                            <div class="flex items-center justify-center space-x-1 mb-6">
                                <span class="text-4xl font-black text-white tracking-tight">$<?php echo number_format($plan['price'], 2); ?></span>
                                <span class="text-xs text-slate-500 font-bold mt-2 tracking-wider">/ <?php echo intval($plan['duration_days']); ?>d</span>
                            </div>
                            
                            <ul class="text-left space-y-4 mb-8 flex flex-col justify-start">
                                <?php 
                                $features = explode("\n", $plan['features']);
                                foreach (array_filter(array_map('trim', $features)) as $feature):
                                ?>
                                    <li class="flex items-center text-sm text-slate-300 font-medium leading-tight">
                                        <svg class="w-5 h-5 text-emerald-400 mr-3 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
                                        <span><?php echo htmlspecialchars($feature); ?></span>
                                    </li>
                                <?php endforeach; ?>
                            </ul>
                        </div>
                        
                        <div class="mt-auto pt-2 w-full">
                            <?php if ($is_logged_in): ?>
                                <a href="checkout.php?plan=<?php echo $plan['id']; ?>" class="block w-full <?php echo $is_popular ? 'bg-gradient-to-r from-emerald-500 to-cyan-500 hover:from-emerald-400 hover:to-cyan-400 text-slate-950 shadow-lg shadow-cyan-500/25 border border-cyan-400/30' : 'bg-slate-800 hover:bg-slate-700 border border-slate-600 text-white'; ?> font-black py-4 rounded-xl text-xs uppercase tracking-widest transition">Subscribe Now</a>
                            <?php else: ?>
                                <a href="login-register.php" class="block w-full bg-slate-800 hover:bg-slate-700 border border-slate-600 text-white font-black py-4 rounded-xl text-xs uppercase tracking-widest transition">Subscribe Now</a>
                            <?php endif; ?>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </section>

    <!-- ========== FAQ SECTION ========== -->
    <section class="w-full max-w-3xl mx-auto px-4 pt-4 pb-16">
        <div class="text-center mb-8">
            <h2 class="text-2xl md:text-3xl font-black text-white tracking-tight">
                <?php echo htmlspecialchars(get_content('home_faq_title', 'Got Any Questions?')); ?>
            </h2>
            <p class="text-[10px] md:text-xs text-slate-400 mt-2">
                <?php echo htmlspecialchars(get_content('home_faq_subtitle', "We've got answers.")); ?>
            </p>
        </div>

        <div class="space-y-4">
            <div class="bg-slate-900/60 border border-slate-800 rounded-xl overflow-hidden hover:border-emerald-500/30 transition-all">
                <button class="faq-btn w-full text-left px-6 py-4 flex justify-between items-center focus:outline-none hover:bg-slate-800/30 transition">
                    <span class="font-bold text-sm text-slate-200">How does the algorithm work?</span>
                    <svg class="w-5 h-5 text-emerald-400 transform transition-transform duration-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
                </button>
                <div class="faq-content hidden px-6 pb-4 text-xs text-slate-400 leading-relaxed">
                    Our platform utilizes deep machine learning to analyze historical football data, player statistics, and mathematical models (like Poisson distribution) to forecast match outcomes with high accuracy.
                </div>
            </div>
            <div class="bg-slate-900/60 border border-slate-800 rounded-xl overflow-hidden hover:border-emerald-500/30 transition-all">
                <button class="faq-btn w-full text-left px-6 py-4 flex justify-between items-center focus:outline-none hover:bg-slate-800/30 transition">
                    <span class="font-bold text-sm text-slate-200">What are the main advantages of this platform?</span>
                    <svg class="w-5 h-5 text-emerald-400 transform transition-transform duration-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
                </button>
                <div class="faq-content hidden px-6 pb-4 text-xs text-slate-400 leading-relaxed">
                    We remove human bias and emotion from betting. You save hours of research time while relying on a system that processes far more data variables than a human ever could.
                </div>
            </div>
            <div class="bg-slate-900/60 border border-slate-800 rounded-xl overflow-hidden hover:border-emerald-500/30 transition-all">
                <button class="faq-btn w-full text-left px-6 py-4 flex justify-between items-center focus:outline-none hover:bg-slate-800/30 transition">
                    <span class="font-bold text-sm text-slate-200">Can I place bets directly here?</span>
                    <svg class="w-5 h-5 text-emerald-400 transform transition-transform duration-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
                </button>
                <div class="faq-content hidden px-6 pb-4 text-xs text-slate-400 leading-relaxed">
                    No. We are strictly a predictive analytics and data provider. We do not accept bets or function as a bookmaker.
                </div>
            </div>
        </div>
    </section>

</main>

<?php require_once __DIR__ . '/includes/footer.php'; ?>

<script>
    // ==========================================
    // FAQ ACCORDION
    // ==========================================
    const faqBtns = document.querySelectorAll('.faq-btn');
    faqBtns.forEach(btn => {
        btn.addEventListener('click', () => {
            const content = btn.nextElementSibling;
            const icon = btn.querySelector('svg');
            
            document.querySelectorAll('.faq-content').forEach(c => {
                if (c !== content) c.classList.add('hidden');
            });
            document.querySelectorAll('.faq-btn svg').forEach(i => {
                if (i !== icon) i.style.transform = 'rotate(0deg)';
            });

            content.classList.toggle('hidden');
            icon.style.transform = content.classList.contains('hidden') ? 'rotate(0deg)' : 'rotate(180deg)';
        });
    });

    // ==========================================
    // STATS CAROUSEL – AUTO-PLAY & DRAG
    // ==========================================
    const slider = document.getElementById('statsCarousel');
    let isDown = false;
    let startX;
    let scrollLeft;
    let autoPlayTimer;

    function startAutoPlay() {
        autoPlayTimer = setInterval(() => {
            if (slider && slider.scrollWidth > slider.clientWidth) {
                const maxScrollLeft = slider.scrollWidth - slider.clientWidth;
                if (slider.scrollLeft >= maxScrollLeft - 10) {
                    slider.scrollTo({ left: 0, behavior: 'smooth' });
                } else {
                    const card = slider.querySelector('.stat-card');
                    if (card) {
                        const cardWidth = card.offsetWidth + 16; 
                        slider.scrollBy({ left: cardWidth, behavior: 'smooth' });
                    }
                }
            }
        }, 3500); 
    }

    function stopAutoPlay() { clearInterval(autoPlayTimer); }

    if (slider) {
        startAutoPlay();
        slider.addEventListener('mouseenter', stopAutoPlay);
        slider.addEventListener('mouseleave', startAutoPlay);
        slider.addEventListener('touchstart', stopAutoPlay, {passive: true});
        slider.addEventListener('touchend', startAutoPlay);

        slider.addEventListener('mousedown', (e) => {
            isDown = true;
            startX = e.pageX - slider.offsetLeft;
            scrollLeft = slider.scrollLeft;
            slider.style.scrollSnapType = 'none'; 
            stopAutoPlay();
        });
        slider.addEventListener('mouseleave', () => {
            isDown = false;
            slider.style.scrollSnapType = 'x mandatory';
        });
        slider.addEventListener('mouseup', () => {
            isDown = false;
            slider.style.scrollSnapType = 'x mandatory';
            setTimeout(startAutoPlay, 500);
        });
        slider.addEventListener('mousemove', (e) => {
            if (!isDown) return;
            e.preventDefault();
            const x = e.pageX - slider.offsetLeft;
            const walk = (x - startX) * 2;
            slider.scrollLeft = scrollLeft - walk;
        });
    }

    // ==========================================
    // TYPING EFFECT
    // ==========================================
    const words = ["Precision AI.", "Deep Learning.", "Live Data.", "Neural Networks."];
    let i = 0;
    let timer;
    const typingSpan = document.getElementById('typing-text');

    function typingEffect() {
        if(!typingSpan) return;
        let word = words[i].split("");
        var loopTyping = function() {
            if (word.length > 0) {
                typingSpan.innerHTML += word.shift();
            } else {
                setTimeout(deletingEffect, 2000);
                return false;
            }
            timer = setTimeout(loopTyping, 100);
        };
        loopTyping();
    }

    function deletingEffect() {
        if(!typingSpan) return;
        let word = words[i].split("");
        var loopDeleting = function() {
            if (word.length > 0) {
                word.pop();
                typingSpan.innerHTML = word.join("");
            } else {
                if (words.length > (i + 1)) { i++; } else { i = 0; }
                setTimeout(typingEffect, 500);
                return false;
            }
            timer = setTimeout(loopDeleting, 50);
        };
        loopDeleting();
    }
    typingEffect();

    // ==========================================
    // NUMBER COUNTER ANIMATION
    // ==========================================
    const counters = document.querySelectorAll('.counter');
    counters.forEach(counter => {
        const target = +counter.getAttribute('data-target');
        const duration = 1500;
        const startTime = performance.now();

        function updateCounter(currentTime) {
            const elapsed = currentTime - startTime;
            const progress = Math.min(elapsed / duration, 1);
            const eased = 1 - Math.pow(1 - progress, 3);
            const current = Math.ceil(eased * target);
            counter.innerText = current;

            if (progress < 1) {
                requestAnimationFrame(updateCounter);
            } else {
                counter.innerText = target;
            }
        }
        requestAnimationFrame(updateCounter);
    });

    // ==========================================
    // NEURAL CANVAS BACKGROUND
    // ==========================================
    const canvas = document.getElementById("neuralCanvas");
    if(canvas) {
        const ctx = canvas.getContext("2d");
        let width, height;
        let particles = [];
        let mouse = { x: null, y: null, radius: 150 };
        
        window.addEventListener('mousemove', function(e) {
            mouse.x = e.x;
            mouse.y = e.y;
        });

        function initCanvas() {
            width = canvas.width = window.innerWidth;
            height = canvas.height = window.innerHeight;
            particles = [];
            let particleCount = (width * height) / 12000;
            
            for (let i = 0; i < particleCount; i++) {
                particles.push({
                    x: Math.random() * width,
                    y: Math.random() * height,
                    vx: (Math.random() - 0.5) * 1.5,
                    vy: (Math.random() - 0.5) * 1.5,
                    radius: Math.random() * 1.5 + 0.5
                });
            }
        }

        function animateCanvas() {
            ctx.clearRect(0, 0, width, height);
            
            for (let i = 0; i < particles.length; i++) {
                let p = particles[i];
                p.x += p.vx;
                p.y += p.vy;
                
                if (p.x < 0 || p.x > width) p.vx *= -1;
                if (p.y < 0 || p.y > height) p.vy *= -1;
                
                ctx.beginPath();
                ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2);
                ctx.fillStyle = "rgba(16, 185, 129, 0.35)";
                ctx.fill();
                
                for (let j = i + 1; j < particles.length; j++) {
                    let p2 = particles[j];
                    let dist = Math.sqrt(Math.pow(p.x - p2.x, 2) + Math.pow(p.y - p2.y, 2));
                    
                    if (dist < 100) {
                        ctx.beginPath();
                        ctx.moveTo(p.x, p.y);
                        ctx.lineTo(p2.x, p2.y);
                        ctx.strokeStyle = `rgba(16, 185, 129, ${1 - dist/100})`;
                        ctx.lineWidth = 0.5;
                        ctx.stroke();
                    }
                }
                
                if (mouse.x && mouse.y) {
                    let mouseDist = Math.sqrt(Math.pow(p.x - mouse.x, 2) + Math.pow(p.y - mouse.y, 2));
                    if (mouseDist < mouse.radius) {
                        ctx.beginPath();
                        ctx.moveTo(p.x, p.y);
                        ctx.lineTo(mouse.x, mouse.y);
                        ctx.strokeStyle = `rgba(16, 185, 129, ${0.8 - mouseDist/mouse.radius})`;
                        ctx.lineWidth = 1;
                        ctx.stroke();
                    }
                }
            }
            requestAnimationFrame(animateCanvas);
        }

        window.addEventListener("resize", initCanvas);
        initCanvas();
        animateCanvas();
    }
</script>