<?php
// Ensure this path jumps up from public/ to the root for config
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'];
}
?>

<?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-1508098682722-e99c43a406b2?q=80&w=2000&auto=format&fit=crop');"></div>
<div class="fixed inset-0 z-0 bg-gradient-to-t from-[#020617] via-[#020617]/90 to-[#020617]/80 pointer-events-none"></div>
<canvas id="neuralCanvas" class="fixed inset-0 w-full h-full pointer-events-none z-0 opacity-35"></canvas>

<main class="relative z-10 flex-1 w-full max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 pt-8 pb-20 space-y-12">

    <!-- Hero Section -->
    <div class="text-center space-y-4">
        <div class="inline-flex items-center space-x-2 bg-emerald-500/10 border border-emerald-500/20 px-3 py-1 rounded-full text-[9px] font-bold tracking-widest uppercase text-emerald-400">
            <span class="w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse"></span>
            <span>Platform Academy & Educational Guides</span>
        </div>
        <h1 class="text-4xl md:text-6xl font-black text-white tracking-tight">AI Platform <span class="text-transparent bg-clip-text bg-gradient-to-r from-emerald-400 to-cyan-400">Tutorials</span></h1>
        <p class="text-xs md:text-sm text-slate-400 max-w-xl mx-auto">Master the machine learning neural engine, decode prediction metrics, live feeds, and advanced risk management.</p>
    </div>

    <!-- Ad Slot (optional) -->
    <div class="w-full flex justify-center">
        <?php display_ad_slot($pdo, 'header'); ?>
    </div>

    <!-- Video Section -->
    <div class="bg-slate-900/60 backdrop-blur-xl border border-slate-800 rounded-[2rem] p-6 md:p-8 space-y-6 max-w-4xl mx-auto shadow-2xl">
        <div class="flex items-center space-x-3 border-b border-slate-800 pb-3">
            <span class="w-2 h-2 rounded-full bg-emerald-400 animate-pulse"></span>
            <h3 class="text-xs font-black text-white uppercase tracking-widest">System Master Walkthrough</h3>
        </div>
        
        <div class="aspect-video bg-slate-950 border border-slate-800 rounded-2xl overflow-hidden shadow-inner relative group">
            <video class="w-full h-full object-cover" controls poster="https://images.unsplash.com/photo-1508098682722-e99c43a406b2?q=80&w=1200&auto=format&fit=crop">
                <source src="../assets/video/tutorial.mp4" type="video/mp4">
                Your browser does not support the video tag.
            </video>
            <!-- Optional play overlay -->
            <div class="absolute inset-0 flex items-center justify-center pointer-events-none group-hover:opacity-0 transition-opacity duration-300">
                <div class="w-16 h-16 rounded-full bg-emerald-500/20 backdrop-blur flex items-center justify-center border border-emerald-500/30">
                    <svg class="w-8 h-8 text-emerald-400" fill="currentColor" viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>
                </div>
            </div>
        </div>
    </div>

    <!-- Prediction Outputs & Risk Management -->
    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
        <!-- Prediction Outputs -->
        <div class="bg-slate-900/40 backdrop-blur border border-slate-800/60 rounded-[2rem] p-6 md:p-8 space-y-6">
            <h2 class="text-base font-black text-white tracking-tight uppercase border-b border-slate-800/60 pb-3">Decoding Prediction Outputs</h2>
            <div class="grid grid-cols-2 gap-3 text-[10px] text-slate-300 font-medium">
                <div class="bg-slate-950/80 border border-slate-800 p-4 rounded-xl text-center hover:border-emerald-500/30 transition-all">
                    <span class="block font-black text-emerald-400 text-xs mb-1">1X2</span>
                    Standard Match outcome probability matrix.
                </div>
                <div class="bg-slate-950/80 border border-slate-800 p-4 rounded-xl text-center hover:border-emerald-500/30 transition-all">
                    <span class="block font-black text-emerald-400 text-xs mb-1">GG/BTTS</span>
                    Both teams will score analytics check.
                </div>
                <div class="bg-slate-950/80 border border-slate-800 p-4 rounded-xl text-center hover:border-emerald-500/30 transition-all">
                    <span class="block font-black text-emerald-400 text-xs mb-1">O2.5</span>
                    Over 2.5 match goals threshold margin.
                </div>
                <div class="bg-slate-950/80 border border-slate-800 p-4 rounded-xl text-center hover:border-emerald-500/30 transition-all">
                    <span class="block font-black text-emerald-400 text-xs mb-1">Banker</span>
                    Highest confidence 84%+ automated picks.
                </div>
            </div>
        </div>

        <!-- Risk Management -->
        <div class="bg-slate-900/40 backdrop-blur border border-slate-800/60 rounded-[2rem] p-6 md:p-8 space-y-4">
            <h2 class="text-base font-black text-white tracking-tight uppercase border-b border-slate-800/60 pb-3">Bankroll & Risk Management</h2>
            <p class="text-xs text-slate-400 leading-relaxed">
                Never risk more than <span class="text-emerald-400 font-bold">1-2%</span> of your total assigned capital on a single computed prediction. Even with elite-level algorithmic accuracy, market variance exists. Stake size should scale strictly according to the neural precision meters displayed on your dashboard.
            </p>
            <div class="flex items-center gap-3 bg-slate-950/60 border border-slate-800 rounded-xl p-3">
                <span class="text-2xl">📊</span>
                <span class="text-[10px] text-slate-400">Use the <span class="text-white font-bold">AI Bet Builder</span> to simulate different stake levels and see projected ROI.</span>
            </div>
        </div>
    </div>

    <!-- Step-by-Step Guide (New) -->
    <div class="bg-slate-900/40 backdrop-blur border border-slate-800/60 rounded-[2rem] p-6 md:p-8 space-y-6">
        <h2 class="text-base font-black text-white tracking-tight uppercase border-b border-slate-800/60 pb-3 flex items-center gap-2">
            <span class="text-emerald-400">📘</span> How to Use the Platform
        </h2>
        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div class="bg-slate-950/60 border border-slate-800 rounded-xl p-4 text-center hover:border-emerald-500/30 transition-all">
                <div class="text-3xl mb-2">1️⃣</div>
                <h4 class="text-sm font-bold text-white">Explore Predictions</h4>
                <p class="text-[10px] text-slate-400 mt-1">Browse daily bankers, AI picks, and VIP slips on the Odds Database.</p>
            </div>
            <div class="bg-slate-950/60 border border-slate-800 rounded-xl p-4 text-center hover:border-emerald-500/30 transition-all">
                <div class="text-3xl mb-2">2️⃣</div>
                <h4 class="text-sm font-bold text-white">Use AI Bet Builder</h4>
                <p class="text-[10px] text-slate-400 mt-1">Generate custom accumulators using neural network parameters.</p>
            </div>
            <div class="bg-slate-950/60 border border-slate-800 rounded-xl p-4 text-center hover:border-emerald-500/30 transition-all">
                <div class="text-3xl mb-2">3️⃣</div>
                <h4 class="text-sm font-bold text-white">Track Performance</h4>
                <p class="text-[10px] text-slate-400 mt-1">Monitor your betting history and ROI in the Performance Ledger.</p>
            </div>
        </div>
    </div>

    <!-- FAQ Section -->
    <div class="w-full max-w-3xl mx-auto px-4 pt-4 border-t border-slate-800/60 mt-6">
        <div class="text-center mb-8">
            <h2 class="text-2xl md:text-3xl font-black text-white tracking-tight">Got Any Questions?</h2>
            <p class="text-[10px] md:text-xs text-slate-400 mt-2">Platform Academy Knowledge Base.</p>
        </div>

        <div class="space-y-3">
            <div class="bg-slate-900/60 border border-slate-800 rounded-xl overflow-hidden 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 prediction 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 autonomous deep learning and neural networks to parse millions of historical statistics, real-time tactical conditions, and Poisson distributions to calculate highly probable match results.
                </div>
            </div>
            <div class="bg-slate-900/60 border border-slate-800 rounded-xl overflow-hidden 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 eliminate emotional bias from sporting predictions. Our terminal saves hours of manual analysis time, tracking lines covering 160+ leagues globally with computer-grade precision.
                </div>
            </div>
            <div class="bg-slate-900/60 border border-slate-800 rounded-xl overflow-hidden 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 upgrade to VIP at any time?</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">
                    Yes! You can upgrade to VIP directly from the <a href="billing.php" class="text-emerald-400 hover:underline">Billing</a> page. Enjoy exclusive tips, advanced analytics, and priority support.
                </div>
            </div>
        </div>
    </div>

    <!-- Ad Slot (optional) -->
    <div class="w-full flex justify-center py-4">
        <?php display_ad_slot($pdo, 'in_content'); ?>
    </div>

</main>

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

<script>
    // FAQ Accordion with smooth toggle
    const faqBtns = document.querySelectorAll('.faq-btn');
    faqBtns.forEach(btn => {
        btn.addEventListener('click', () => {
            const content = btn.nextElementSibling;
            const icon = btn.querySelector('svg');
            
            // Close other open FAQs
            document.querySelectorAll('.faq-content').forEach(c => {
                if (c !== content && !c.classList.contains('hidden')) {
                    c.classList.add('hidden');
                    c.previousElementSibling.querySelector('svg').style.transform = 'rotate(0deg)';
                }
            });

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

    // Neural Background
    const canvas = document.getElementById("neuralCanvas");
    if(canvas) {
        const ctx = canvas.getContext("2d");
        let width, height;
        let particles = [];
        let mouse = { x: null, y: null };
        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) / 15000;
            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.3)";
                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();
                    }
                }
            }
            requestAnimationFrame(animateCanvas);
        }
        window.addEventListener("resize", initCanvas);
        initCanvas();
        animateCanvas();
    }
</script>