<?php
session_start();

// ======================= اتصال به دیتابیس برای شمارنده کاربران واقعی =======================
$realUserCount = 0;
$extraNumber = 1000;
try {
    $pdo = new PDO("mysql:host=localhost;dbname=planir_focuscloud;charset=utf8mb4", 'planir_focuscloud', 'Mohammad@1381', [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
    ]);
    $stmt = $pdo->query("SELECT COUNT(*) FROM users");
    $realUserCount = (int)$stmt->fetchColumn();
    
    $stmt = $pdo->prepare("SELECT setting_value FROM site_settings WHERE setting_key = 'landing_extra_users'");
    $stmt->execute();
    $extraVal = $stmt->fetchColumn();
    if ($extraVal !== false && is_numeric($extraVal)) {
        $extraNumber = (int)$extraVal;
    }
} catch (Exception $e) {
    $realUserCount = 1250;
}
$totalUsers = $realUserCount + $extraNumber;

$loggedIn = false;
$userName = '';
if (!empty($_SESSION['user_id'])) {
    try {
        $pdo = new PDO("mysql:host=localhost;dbname=planir_focuscloud;charset=utf8mb4", 'planir_focuscloud', 'Mohammad@1381');
        $stmt = $pdo->prepare("SELECT first_name, last_name FROM users WHERE id = ?");
        $stmt->execute([$_SESSION['user_id']]);
        $user = $stmt->fetch();
        if ($user) {
            $loggedIn = true;
            $userName = trim($user['first_name'] . ' ' . $user['last_name']);
        }
    } catch (Exception $e) {}
}
?>
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
    <title>To-Do Cloud | ابر هوشمند مدیریت وظایف</title>
    <meta name="description" content="مدیریت تسک، هدف، پومودورو گروهی و اشتراک‌گذاری ابری — ابزار حرفه‌ای برای تیم‌ها و فریلنسرها">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,300;400;500;600;700;800&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', sans-serif;
            background: #02040c;
            color: #f0f6ff;
            overflow-x: hidden;
            transition: background 1.5s ease;
        }

        body.blackout {
            background: #000000 !important;
        }

        /* ========== پس‌زمینه داینامیک با ذرات و گرادیان متحرک ========== */
        #particle-canvas {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -2;
            background: radial-gradient(ellipse at 40% 50%, #0a1a2f, #010101);
            transition: opacity 1.5s ease;
        }
        body.blackout #particle-canvas {
            opacity: 0;
            pointer-events: none;
        }

        .gradient-aura {
            position: fixed;
            inset: 0;
            z-index: -1;
            background: linear-gradient(125deg, rgba(10,132,255,0.2), rgba(94,92,230,0.2), rgba(255,160,80,0.1));
            background-size: 400% 400%;
            animation: auroraShift 18s ease infinite;
            pointer-events: none;
            transition: opacity 1.5s ease;
        }
        body.blackout .gradient-aura {
            opacity: 0;
        }

        @keyframes auroraShift {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        /* ستاره‌های اولیه (قبل از بلک‌اوت) */
        .stars-container {
            position: fixed;
            inset: 0;
            pointer-events: none;
            z-index: -1;
            overflow: hidden;
        }
        .star {
            position: absolute;
            background: rgba(255, 255, 255, 0.8);
            border-radius: 50%;
            animation: starTwinkle linear infinite;
        }
        @keyframes starTwinkle {
            0% { opacity: 0; transform: scale(0.3) translateY(0); }
            20% { opacity: 1; }
            80% { opacity: 0.6; }
            100% { opacity: 0; transform: scale(1.2) translateY(-100vh); }
        }

        /* ========== محتوای اصلی لندینگ ========== */
        .landing-container {
            position: relative;
            z-index: 10;
            max-width: 1300px;
            margin: 0 auto;
            padding: 1.5rem 2rem 4rem;
            transition: opacity 1s ease;
        }
        body.blackout .landing-container {
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
        }

        /* ========== نوار ناوبری شیشه‌ای ========== */
        .navbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 1.5rem;
            background: rgba(15, 25, 45, 0.6);
            backdrop-filter: blur(20px);
            border-radius: 3rem;
            padding: 0.6rem 2rem;
            border: 1px solid rgba(255, 255, 255, 0.08);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
        }
        .logo {
            display: flex;
            align-items: center;
            gap: 0.8rem;
        }
        .logo-icon {
            width: 46px;
            height: 46px;
            background: linear-gradient(135deg, #0a84ff, #5e5ce6);
            border-radius: 1rem;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
            box-shadow: 0 6px 16px #0a84ff40;
        }
        .logo-text {
            font-size: 1.6rem;
            font-weight: 800;
            background: linear-gradient(125deg, #fff, #9bc0ff);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
        }
        .nav-buttons {
            display: flex;
            gap: 1rem;
        }
        .btn-outline {
            background: transparent;
            border: 1px solid rgba(10,132,255,0.5);
            padding: 0.5rem 1.3rem;
            border-radius: 2.5rem;
            color: #c7e0ff;
            font-weight: 500;
            transition: 0.2s;
            cursor: pointer;
        }
        .btn-outline:hover {
            background: rgba(10,132,255,0.15);
            border-color: #0a84ff;
        }
        .btn-gradient {
            background: linear-gradient(100deg, #0a84ff, #5e5ce6);
            border: none;
            padding: 0.6rem 1.6rem;
            border-radius: 2.5rem;
            color: white;
            font-weight: 700;
            cursor: pointer;
            box-shadow: 0 6px 16px #0a84ff40;
            transition: 0.2s;
        }
        .btn-gradient:hover {
            transform: translateY(-3px);
            filter: brightness(1.05);
        }

        /* ========== Hero Section ========== */
        .hero {
            text-align: center;
            padding: 3rem 0 2rem;
        }
        .hero-badge {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            background: rgba(10,132,255,0.12);
            border-radius: 3rem;
            padding: 0.4rem 1.2rem;
            font-size: 0.85rem;
            margin-bottom: 1.5rem;
            backdrop-filter: blur(8px);
        }
        .hero h1 {
            font-size: 3.8rem;
            font-weight: 800;
            background: linear-gradient(145deg, #ffffff, #7bb3ff, #c084fc);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            line-height: 1.2;
            margin-bottom: 1rem;
        }
        .hero-desc {
            font-size: 1.2rem;
            color: #c5dcff;
            max-width: 650px;
            margin: 0 auto 2rem;
        }

        /* شمارنده کاربران */
        .counter-wrapper {
            display: flex;
            justify-content: center;
            margin: 1rem 0 2rem;
        }
        .counter-card {
            background: rgba(0,0,0,0.5);
            backdrop-filter: blur(16px);
            border-radius: 4rem;
            padding: 0.7rem 2rem;
            display: inline-flex;
            align-items: center;
            gap: 1rem;
            border: 1px solid rgba(255,215,0,0.4);
        }
        .counter-number {
            font-size: 2.8rem;
            font-weight: 800;
            font-family: monospace;
            background: linear-gradient(125deg, #ffd966, #ffb347);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
        }

        /* نقل قول چرخان */
        .quote-box {
            background: linear-gradient(90deg, rgba(10,132,255,0.05), rgba(94,92,230,0.05));
            border-radius: 2rem;
            padding: 2rem;
            text-align: center;
            margin: 2rem 0;
            border-right: 4px solid #ffb347;
        }
        .quote-text {
            font-size: 1.35rem;
            font-style: italic;
            font-weight: 500;
            transition: 0.3s;
        }
        .quote-author {
            margin-top: 0.8rem;
            color: #ffcf7a;
            font-weight: 600;
        }

        /* ========== لیست اول: چگونگی کار (Steps) ========== */
        .section-title {
            text-align: center;
            margin: 4rem 0 2rem;
            font-size: 2rem;
            font-weight: 700;
            position: relative;
        }
        .section-title:after {
            content: '';
            width: 80px;
            height: 4px;
            background: #0a84ff;
            display: block;
            margin: 8px auto 0;
            border-radius: 2px;
        }
        .steps {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 2rem;
            margin-top: 2rem;
        }
        .step-card {
            flex: 1 1 280px;
            background: rgba(15,25,45,0.6);
            backdrop-filter: blur(12px);
            border-radius: 1.5rem;
            padding: 2rem;
            text-align: center;
            border: 1px solid rgba(255,255,255,0.05);
            transition: all 0.3s cubic-bezier(0.2,0.9,0.4,1.2);
        }
        .step-card:hover {
            transform: translateY(-10px);
            background: rgba(35,48,75,0.8);
            border-color: #0a84ff;
            box-shadow: 0 20px 35px -12px #0a84ff;
        }
        .step-card .icon {
            font-size: 2.5rem;
            color: #0a84ff;
            margin-bottom: 1rem;
        }
        .step-card h3 {
            font-size: 1.3rem;
            margin-bottom: 0.8rem;
        }
        .step-card p {
            color: #c5dcff;
        }

        /* ========== لیست دوم: ویژگی‌ها (Features) ========== */
        .features {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
            gap: 2rem;
            margin-top: 2rem;
        }
        .feature-card {
            background: rgba(20,28,48,0.6);
            backdrop-filter: blur(12px);
            border-radius: 2rem;
            padding: 2rem 1.5rem;
            text-align: center;
            transition: 0.3s;
            border: 1px solid rgba(255,255,255,0.05);
            cursor: pointer;
        }
        .feature-card:hover {
            transform: translateY(-12px);
            background: rgba(35,48,75,0.8);
            border-color: #0a84ff;
            box-shadow: 0 20px 35px -12px #0a84ff;
        }
        .feature-card .icon {
            font-size: 2.4rem;
            color: #5e5ce6;
            margin-bottom: 1rem;
        }
        .feature-card h4 {
            font-size: 1.2rem;
            margin-bottom: 0.6rem;
        }
        .feature-card p {
            color: #c5dcff;
        }

        /* ========== ناحیه دمو تعاملی ========== */
        .demo-zone {
            background: rgba(0, 0, 0, 0.45);
            backdrop-filter: blur(12px);
            border-radius: 2rem;
            padding: 2rem;
            margin: 4rem 0;
            border: 1px solid rgba(10,132,255,0.4);
        }
        .demo-tabs {
            display: flex;
            flex-wrap: wrap;
            gap: 0.8rem;
            justify-content: center;
            margin-bottom: 2rem;
        }
        .demo-tab {
            background: rgba(255,255,255,0.05);
            border: none;
            padding: 0.6rem 1.5rem;
            border-radius: 2rem;
            color: #d2e5ff;
            font-weight: 500;
            cursor: pointer;
            transition: 0.2s;
        }
        .demo-tab.active {
            background: #0a84ff;
            color: white;
            box-shadow: 0 0 12px #0a84ff;
        }
        .demo-pane {
            display: none;
            animation: fadeSlide 0.4s;
        }
        .demo-pane.active {
            display: block;
        }
        @keyframes fadeSlide {
            from { opacity: 0; transform: translateY(12px); }
            to { opacity: 1; transform: translateY(0); }
        }

        /* استایل‌های داخلی دموها */
        .task-list {
            max-height: 280px;
            overflow-y: auto;
            margin: 1rem 0;
        }
        .task-row {
            display: flex;
            align-items: center;
            gap: 1rem;
            background: rgba(255,255,255,0.04);
            border-radius: 1rem;
            padding: 0.7rem 1rem;
            margin-bottom: 0.6rem;
        }
        .task-check {
            width: 24px;
            height: 24px;
            border: 2px solid #0a84ff;
            border-radius: 8px;
            cursor: pointer;
        }
        .task-check.completed {
            background: #2ecc71;
            border-color: #2ecc71;
            position: relative;
        }
        .task-check.completed::after {
            content: "✓";
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100%;
            font-size: 13px;
        }
        .goal-progress {
            height: 10px;
            background: #2a334a;
            border-radius: 5px;
            margin: 1rem 0;
        }
        .goal-fill {
            width: 0%;
            height: 100%;
            background: linear-gradient(90deg, #0a84ff, #5e5ce6);
            border-radius: 5px;
            transition: width 0.4s;
        }
        .demo-input {
            background: rgba(255,255,255,0.08);
            border: 1px solid rgba(255,255,255,0.2);
            border-radius: 2rem;
            padding: 0.7rem 1rem;
            color: white;
            flex: 1;
        }

        /* چشم‌انداز و مأموریت */
        .vision-grid {
            display: flex;
            flex-wrap: wrap;
            gap: 2rem;
            margin: 3rem 0;
        }
        .vision-card {
            flex: 1;
            background: rgba(15, 25, 45, 0.5);
            backdrop-filter: blur(12px);
            border-radius: 1.8rem;
            padding: 1.8rem;
        }
        .vision-card p {
            color: #c5dcff;
        }

        /* CTA بزرگ */
        .cta-big {
            background: linear-gradient(125deg, #0a84ff25, #5e5ce625);
            border-radius: 2rem;
            padding: 3rem;
            text-align: center;
            margin: 4rem 0;
        }
        .cta-big h2 {
            margin-bottom: 1rem;
        }

        /* نماد اعتماد و فوتر */
        .enamad {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        footer {
            text-align: center;
            border-top: 1px solid rgba(255,255,255,0.05);
            padding-top: 2rem;
            color: #9ab3d6;
            font-size: 0.8rem;
        }

        /* ========== باکس احراز هویت نهایی (پس از بلک‌اوت) ========== */
        .final-auth-container {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 200;
            opacity: 0;
            visibility: hidden;
            transition: opacity 1s ease, visibility 0.3s;
            backdrop-filter: blur(0px);
        }
        body.blackout .final-auth-container {
            opacity: 1;
            visibility: visible;
        }
        .final-auth-card {
            background: rgba(10, 15, 25, 0.85);
            backdrop-filter: blur(20px);
            border-radius: 56px;
            padding: 48px 40px;
            width: 90%;
            max-width: 480px;
            text-align: center;
            border: 1px solid rgba(10, 132, 255, 0.6);
            box-shadow: 0 0 40px rgba(10, 132, 255, 0.3);
            animation: glowPulse 3s infinite;
            transform: translateY(0);
        }
        @keyframes glowPulse {
            0% { box-shadow: 0 0 20px rgba(10, 132, 255, 0.3); border-color: rgba(10, 132, 255, 0.4); }
            50% { box-shadow: 0 0 50px rgba(10, 132, 255, 0.7); border-color: #0a84ff; }
            100% { box-shadow: 0 0 20px rgba(10, 132, 255, 0.3); border-color: rgba(10, 132, 255, 0.4); }
        }
        .final-logo {
            font-size: 48px;
            font-weight: 800;
            background: linear-gradient(135deg, #fff, #0a84ff);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            margin-bottom: 20px;
        }
        .final-motivation {
            font-size: 18px;
            color: #ffd966;
            margin: 20px 0;
            font-weight: 500;
            min-height: 80px;
            transition: opacity 0.3s;
        }
        .final-user-count {
            font-size: 14px;
            color: rgba(255,255,255,0.7);
            margin-bottom: 30px;
        }
        .final-user-count span {
            font-size: 24px;
            font-weight: 800;
            color: #ffd700;
            font-family: monospace;
        }
        .final-buttons {
            display: flex;
            gap: 20px;
            justify-content: center;
        }
        .final-btn {
            padding: 14px 32px;
            border-radius: 60px;
            font-weight: 700;
            font-size: 16px;
            cursor: pointer;
            transition: 0.3s;
            text-decoration: none;
            display: inline-block;
        }
        .final-btn-login {
            background: transparent;
            border: 1.5px solid #0a84ff;
            color: #0a84ff;
        }
        .final-btn-login:hover {
            background: rgba(10, 132, 255, 0.2);
            transform: translateY(-3px);
        }
        .final-btn-register {
            background: linear-gradient(135deg, #0a84ff, #5e5ce6);
            border: none;
            color: white;
            box-shadow: 0 6px 20px rgba(10, 132, 255, 0.4);
        }
        .final-btn-register:hover {
            transform: translateY(-3px);
            filter: brightness(1.05);
        }

        /* ========== بوم علامت بینهایت ========== */
        #infinityCanvas {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: 50;
            opacity: 0;
            transition: opacity 1.5s ease;
        }
        body.blackout #infinityCanvas {
            opacity: 1;
        }

        /* صفحه Tap to Start */
        #startOverlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.95);
            z-index: 10000;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            backdrop-filter: blur(12px);
            transition: opacity 0.5s;
        }
        .start-content {
            text-align: center;
            color: white;
            animation: fadeInUp 0.8s ease;
        }
        .start-content i {
            font-size: 64px;
            margin-bottom: 20px;
            animation: pulse 1.5s infinite;
        }
        .start-content h2 {
            font-size: 28px;
            margin-bottom: 10px;
        }
        .start-content p {
            font-size: 16px;
            opacity: 0.8;
        }
        @keyframes pulse {
            0% { opacity: 0.6; transform: scale(1);}
            100% { opacity: 1; transform: scale(1.1);}
        }
        @keyframes fadeInUp {
            from { opacity: 0; transform: translateY(30px); }
            to { opacity: 1; transform: translateY(0); }
        }

        /* واکنش‌گرایی */
        @media (max-width: 780px) {
            .landing-container { padding: 1rem; }
            .hero h1 { font-size: 2rem; }
            .counter-number { font-size: 2rem; }
            .final-auth-card { padding: 32px 24px; }
            .final-buttons { flex-direction: column; gap: 12px; }
            .final-btn { width: 100%; text-align: center; }
        }
    </style>
</head>
<body>

<canvas id="particle-canvas"></canvas>
<div class="gradient-aura"></div>
<div class="stars-container" id="starsContainer"></div>

<!-- صفحه Tap to Start -->
<div id="startOverlay">
    <div class="start-content">
        <i class="fas fa-headphones"></i>
        <h2>برای تجربه‌ی کامل، روی صفحه ضربه بزنید</h2>
        <p>🎵 موسیقی پس‌زمینه شروع می‌شود... 🎵</p>
    </div>
</div>

<!-- محتوای اصلی لندینگ -->
<div class="landing-container" id="landingContent">
    <div class="navbar">
        <div class="logo">
            <div class="logo-icon"><i class="fas fa-cloud-upload-alt"></i></div>
            <span class="logo-text">To-Do Cloud</span>
        </div>
        <div class="nav-buttons">
            <?php if ($loggedIn): ?>
                <span style="color:#b8d0ff;">خوش آمدی، <?= htmlspecialchars($userName) ?></span>
                <button class="btn-gradient" onclick="window.location.href='index.html'">داشبورد</button>
            <?php else: ?>
                <button class="btn-outline" onclick="window.location.href='auth.html'">ورود</button>
                <button class="btn-gradient" onclick="window.location.href='auth.html?register=1'">شروع رایگان</button>
            <?php endif; ?>
        </div>
    </div>

    <div class="hero">
        <div class="hero-badge"><i class="fas fa-cloud"></i> ابر هوشمند · بهره‌وری بی‌نهایت <i class="fas fa-star" style="color:#ffd966;"></i></div>
        <h1>تسک‌های خود را<br>به ابر بسپارید</h1>
        <p class="hero-desc">مدیریت حرفه‌ای وظایف، اهداف، پومودورو گروهی و اشتراک‌گذاری امن — یک پلتفرم ابری برای تیم‌ها و فریلنسرهای مدرن.</p>
        <div class="counter-wrapper">
            <div class="counter-card">
                <i class="fas fa-users"></i>
                <span>جامعه کاربران</span>
                <span class="counter-number" id="totalUsersSpan">0</span>
            </div>
        </div>
    </div>

    <div class="quote-box" id="quoteBox">
        <div class="quote-text" id="quoteTxt">«تنها محدودیت تو، ذهنت است.»</div>
        <div class="quote-author" id="quoteAuth">– تونی رابینز</div>
    </div>

    <h2 class="section-title">چگونه کار می‌کند</h2>
    <div class="steps">
        <div class="step-card">
            <div class="icon"><i class="fas fa-user-plus"></i></div>
            <h3>۱. ثبت‌نام و راه‌اندازی</h3>
            <p>با یک کلیک اکانت بسازید، تیم‌تان را دعوت کنید و وارد پنل مدیریت شوید.</p>
        </div>
        <div class="step-card">
            <div class="icon"><i class="fas fa-tasks"></i></div>
            <h3>۲. ایجاد تسک و هدف</h3>
            <p>تسک‌ها را تعریف، اولویت‌بندی و به اهداف هفتگی و ماهانه متصل کنید.</p>
        </div>
        <div class="step-card">
            <div class="icon"><i class="fas fa-users"></i></div>
            <h3>۳. تمرکز و اشتراک‌گذاری</h3>
            <p>در اتاق‌های پومودورو گروهی متمرکز شوید، پروگرس زنده ببینید و با دوستان به اشتراک بگذارید.</p>
        </div>
        <div class="step-card">
            <div class="icon"><i class="fas fa-chart-line"></i></div>
            <h3>۴. تحلیل و بهبود</h3>
            <p>گزارشات لحظه‌ای، نمودار پیشرفت و شاخص‌های کلیدی تیم را زیر نظر داشته باشید.</p>
        </div>
    </div>

    <h2 class="section-title">ویژگی‌های حرفه‌ای</h2>
    <div class="features">
        <div class="feature-card" data-demo="tasks">
            <div class="icon"><i class="fas fa-tasks"></i></div>
            <h4>تسک باکس‌های هوشمند</h4>
            <p>دسته‌بندی، اولویت، زیرتسک و تکرار — قدرتمند و ساده.</p>
        </div>
        <div class="feature-card" data-demo="goals">
            <div class="icon"><i class="fas fa-bullseye"></i></div>
            <h4>اهداف + استریک</h4>
            <p>پیشرفت روزانه، استریک و پاداش کلود — انگیزه‌تان را چند برابر کنید.</p>
        </div>
        <div class="feature-card" data-demo="pomodoro">
            <div class="icon"><i class="fas fa-hourglass-half"></i></div>
            <h4>پومودورو گروهی</h4>
            <p>اتاق‌های تمرکز زنده، چت و تایمر مشترک — بهره‌وری دسته‌جمعی.</p>
        </div>
        <div class="feature-card" data-demo="share">
            <div class="icon"><i class="fas fa-share-alt"></i></div>
            <h4>اشتراک‌گذاری امن</h4>
            <p>با کد ۱۶ رقمی یا مخاطبان، باکس‌ها و اهداف را share کن.</p>
        </div>
        <div class="feature-card">
            <div class="icon"><i class="fas fa-cloud-download-alt"></i></div>
            <h4>همگام‌سازی ابری</h4>
            <p>تمامی تغییرات بدون وقفه و در لحظه روی همه دستگاه‌ها در دسترس است.</p>
        </div>
        <div class="feature-card">
            <div class="icon"><i class="fas fa-shield-alt"></i></div>
            <h4>امنیت لایه‌ای</h4>
            <p>رمزنگاری انتها-به-انتها، بک‌آپ خودکار و تائید دو مرحله‌ای.</p>
        </div>
    </div>

    <div class="demo-zone">
        <div class="demo-tabs" id="demoTabs">
            <button class="demo-tab active" data-pane="tasksDemo">📋 تسک باکس دمو</button>
            <button class="demo-tab" data-pane="goalsDemo">🎯 هدف دمو</button>
            <button class="demo-tab" data-pane="pomodoroDemo">🍅 پومودورو دمو</button>
            <button class="demo-tab" data-pane="shareDemo">🔗 اشتراک دمو</button>
        </div>

        <div id="tasksDemo" class="demo-pane active">
            <h3><i class="fas fa-inbox"></i> تسک‌های جاری (پروژه نمونه)</h3>
            <div class="task-list" id="tasksList"></div>
            <div style="display: flex; gap: 10px; margin-top: 1rem;">
                <input type="text" id="newTaskInput" class="demo-input" placeholder="نام تسک جدید...">
                <button id="addTaskBtn" class="btn-gradient">➕ افزودن</button>
            </div>
            <p class="hero-desc" style="font-size:0.85rem; margin-top:1rem;">✔️ روی دایره کلیک کن تا انجام بدی — تجربه واقعی تسک‌ها.</p>
        </div>

        <div id="goalsDemo" class="demo-pane">
            <h3><i class="fas fa-chart-line"></i> هدف هفته: توسعه فردی</h3>
            <div>پیشرفت: <span id="goalCurrent">0</span> از <span id="goalTarget">20</span> جلسه</div>
            <div class="goal-progress"><div class="goal-fill" id="goalFill"></div></div>
            <div style="display: flex; gap: 1rem; margin-top: 1rem;">
                <button id="incGoalBtn" class="btn-gradient">📈 +۱ پیشرفت</button>
                <button id="resetGoalBtn" class="btn-outline">🔄 ریست</button>
            </div>
        </div>

        <div id="pomodoroDemo" class="demo-pane">
            <h3><i class="fas fa-clock"></i> جلسه فوکوس آزمایشی</h3>
            <div style="text-align:center;">
                <div style="font-size: 3rem; font-family: monospace; letter-spacing: 4px;" id="pomoTimer">25:00</div>
                <div style="display: flex; gap: 1rem; justify-content: center; margin-top: 1rem;">
                    <button id="pomoStart" class="btn-gradient">▶ شروع</button>
                    <button id="pomoPause" class="btn-outline">⏸ توقف</button>
                    <button id="pomoReset" class="btn-outline">🔄 بازنشانی</button>
                </div>
            </div>
        </div>

        <div id="shareDemo" class="demo-pane">
            <h3><i class="fas fa-link"></i> اشتراک‌گذاری دمو</h3>
            <div style="background: rgba(255,255,255,0.05); border-radius: 1rem; padding: 1rem;">
                <p>کد دعوت اختصاصی شما: <strong style="color:#ffd966;">DEMO-XC7F-9H3K</strong></p>
                <button class="btn-outline" onclick="alert('در نسخه اصلی، کد ۱۶ رقمی واقعی دریافت می‌کنید و می‌توانید با دوستان به اشتراک بگذارید.')"><i class="fas fa-copy"></i> کپی کد آزمایشی</button>
            </div>
            <p class="hero-desc" style="font-size:0.9rem;">باکس‌ها، اهداف و نوت‌ها را با کد یا مخاطبان به اشتراک بگذار.</p>
        </div>
    </div>

    <div class="vision-grid">
        <div class="vision-card"><i class="fas fa-eye" style="font-size:2rem; color:#0a84ff;"></i><h3 style="margin:0.7rem 0;">چشم‌انداز</h3><p>تبدیل شدن به جامع‌ترین پلتفرم مدیریت تسک ابری در ایران و منطقه، با تمرکز بر نوآوری و تجربه کاربری فوق‌العاده.</p></div>
        <div class="vision-card"><i class="fas fa-rocket" style="font-size:2rem; color:#0a84ff;"></i><h3 style="margin:0.7rem 0;">ماموریت</h3><p>توانمندسازی افراد و تیم‌ها برای دستیابی به بهره‌وری حداکثری از طریق ابزارهای ساده، هوشمند و اجتماعی.</p></div>
    </div>

    <div class="cta-big">
        <h2 style="font-size:2rem;">به جمع بیش از <span id="ctaCounter">0</span> کاربر بپیوندید</h2>
        <p style="margin:1rem 0;">۲۰۰ کلود هدیه + دعوت از دوستان و پاداش‌های ویژه</p>
        <div style="display: flex; gap: 1rem; justify-content: center;">
            <button class="btn-gradient" onclick="window.location.href='auth.html'">ثبت‌نام رایگان</button>
            <button class="btn-outline" onclick="window.location.href='auth.html'">ورود</button>
        </div>
    </div>

    <div class="enamad">
        <a referrerpolicy='origin' target='_blank' href='https://trustseal.enamad.ir/?id=6248331&Code=apXUkOvbLgX5i8ZnDWYMLeezN9HPU016'>
            <img referrerpolicy='origin' src='https://trustseal.enamad.ir/logo.aspx?id=6248331&Code=apXUkOvbLgX5i8ZnDWYMLeezN9HPU016' alt='' style='cursor:pointer' code='apXUkOvbLgX5i8ZnDWYMLeezN9HPU016'>
        </a>
    </div>

    <footer>
        <p>© 2025 To-Do Cloud · امنیت لایه‌ای · پشتیبانی ۲۴/۷</p>
    </footer>
</div>

<div class="final-auth-container" id="finalAuthContainer">
    <div class="final-auth-card">
        <div class="final-logo">☁️ To-Do Cloud</div>
        <div class="final-motivation" id="finalMotivation">✨ قدرت در دستان توست... ✨</div>
        <div class="final-user-count">به جمع <span id="finalUserCount">0</span> کاربر بپیوندید</div>
        <div class="final-buttons">
            <button class="final-btn final-btn-login" onclick="window.location.href='auth.html'">ورود</button>
            <button class="final-btn final-btn-register" onclick="window.location.href='auth.html?register=1'">ثبت‌نام رایگان</button>
        </div>
    </div>
</div>

<canvas id="infinityCanvas"></canvas>

<script>
    // شمارنده کاربران
    const totalUsers = <?= $totalUsers ?>;
    const counterSpan = document.getElementById('totalUsersSpan');
    const ctaCounterSpan = document.getElementById('ctaCounter');
    const finalCounterSpan = document.getElementById('finalUserCount');
    let current = 0;
    const stepTime = 20;
    const duration = 2000;
    const increment = totalUsers / (duration / stepTime);
    const counterInterval = setInterval(() => {
        current += increment;
        if (current >= totalUsers) {
            counterSpan.innerText = totalUsers.toLocaleString('fa-IR');
            if (ctaCounterSpan) ctaCounterSpan.innerText = totalUsers.toLocaleString('fa-IR');
            if (finalCounterSpan) finalCounterSpan.innerText = totalUsers.toLocaleString('fa-IR');
            clearInterval(counterInterval);
        } else {
            counterSpan.innerText = Math.floor(current).toLocaleString('fa-IR');
            if (ctaCounterSpan) ctaCounterSpan.innerText = Math.floor(current).toLocaleString('fa-IR');
            if (finalCounterSpan) finalCounterSpan.innerText = Math.floor(current).toLocaleString('fa-IR');
        }
    }, stepTime);

    // نقل قول چرخان
    const quotes = [
        { text: "تنها محدودیت تو، ذهنت است.", author: "– تونی رابینز" },
        { text: "موفقیت حاصل تکرار کارهای ساده روزانه است.", author: "– جیم ران" },
        { text: "بزرگترین کشف من این بود که انسان می‌تواند با تغییر نگرشش، زندگی‌اش را تغییر دهد.", author: "– ویلیام جیمز" },
        { text: "راز پیشرفت، شروع کردن است.", author: "– مارک تواین" },
        { text: "اگر می‌توانی رویاهایت را ببینی، می‌توانی به آنها برسی.", author: "– پائولو کوئیلو" },
        { text: "نظم، پل بین اهداف و دستاوردهاست.", author: "– جیم ران" }
    ];
    let idx = 0;
    const quoteText = document.getElementById('quoteTxt');
    const quoteAuthor = document.getElementById('quoteAuth');
    function rotateQuote() {
        const q = quotes[idx % quotes.length];
        quoteText.style.opacity = '0';
        quoteAuthor.style.opacity = '0';
        setTimeout(() => {
            quoteText.innerText = `“${q.text}”`;
            quoteAuthor.innerText = q.author;
            quoteText.style.opacity = '1';
            quoteAuthor.style.opacity = '1';
        }, 300);
        idx++;
    }
    setInterval(rotateQuote, 7000);
    rotateQuote();

    // دمو تسک‌ها
    let tasks = [
        { id: 1, name: "طراحی داشبورد اصلی", completed: false },
        { id: 2, name: "پیاده‌سازی API احراز هویت", completed: true },
        { id: 3, name: "رفع باگ پومودورو", completed: false }
    ];
    function renderTaskList() {
        const container = document.getElementById('tasksList');
        if (!container) return;
        container.innerHTML = '';
        tasks.forEach(t => {
            const row = document.createElement('div');
            row.className = 'task-row';
            row.innerHTML = `
                <div class="task-check ${t.completed ? 'completed' : ''}" data-id="${t.id}"></div>
                <span style="flex:1; ${t.completed ? 'text-decoration:line-through; opacity:0.7;' : ''}">${escapeHtml(t.name)}</span>
                <i class="fas fa-trash-alt" style="color:#ff8a8a; cursor:pointer;" data-id="${t.id}" data-action="delete"></i>
            `;
            container.appendChild(row);
        });
        document.querySelectorAll('.task-check').forEach(el => {
            el.addEventListener('click', (e) => {
                const id = parseInt(el.dataset.id);
                const task = tasks.find(tk => tk.id === id);
                if (task) { task.completed = !task.completed; renderTaskList(); }
                e.stopPropagation();
            });
        });
        document.querySelectorAll('[data-action="delete"]').forEach(icon => {
            icon.addEventListener('click', (e) => {
                const id = parseInt(icon.dataset.id);
                tasks = tasks.filter(t => t.id !== id);
                renderTaskList();
                e.stopPropagation();
            });
        });
    }
    function escapeHtml(str) {
        return str.replace(/[&<>]/g, m => ({ '&':'&amp;', '<':'&lt;', '>':'&gt;' }[m]));
    }
    document.getElementById('addTaskBtn')?.addEventListener('click', () => {
        const inp = document.getElementById('newTaskInput');
        const val = inp.value.trim();
        if (val === '') return;
        tasks.push({ id: Date.now(), name: val, completed: false });
        renderTaskList();
        inp.value = '';
    });
    renderTaskList();

    // دمو هدف
    let goalCurr = 0;
    const goalMax = 20;
    const goalSpan = document.getElementById('goalCurrent');
    const goalFillDiv = document.getElementById('goalFill');
    function updateGoalUI() {
        goalSpan.innerText = goalCurr;
        const percent = (goalCurr / goalMax) * 100;
        goalFillDiv.style.width = percent + '%';
    }
    document.getElementById('incGoalBtn')?.addEventListener('click', () => {
        if (goalCurr < goalMax) {
            goalCurr++;
            updateGoalUI();
            if (goalCurr === goalMax) alert('🎉 هدف دمو کامل شد! در نسخه اصلی پاداش کلود می‌گیرید.');
        }
    });
    document.getElementById('resetGoalBtn')?.addEventListener('click', () => {
        goalCurr = 0;
        updateGoalUI();
    });
    updateGoalUI();

    // دمو پومودورو
    let pomodoroSeconds = 25 * 60;
    let pomoInterval = null;
    let pomoActive = false;
    const pomoDisplay = document.getElementById('pomoTimer');
    function updatePomoDisplay() {
        const mins = Math.floor(pomodoroSeconds / 60);
        const secs = pomodoroSeconds % 60;
        pomoDisplay.innerText = `${mins.toString().padStart(2,'0')}:${secs.toString().padStart(2,'0')}`;
    }
    function startPomo() {
        if (pomoInterval) clearInterval(pomoInterval);
        pomoActive = true;
        pomoInterval = setInterval(() => {
            if (pomodoroSeconds > 0 && pomoActive) {
                pomodoroSeconds--;
                updatePomoDisplay();
                if (pomodoroSeconds === 0) {
                    clearInterval(pomoInterval);
                    alert('✅ جلسه پومودورو دمو تمام شد!');
                    pomoActive = false;
                }
            }
        }, 1000);
    }
    document.getElementById('pomoStart')?.addEventListener('click', () => {
        if (!pomoActive) startPomo();
    });
    document.getElementById('pomoPause')?.addEventListener('click', () => {
        pomoActive = false;
        if (pomoInterval) clearInterval(pomoInterval);
        pomoInterval = null;
    });
    document.getElementById('pomoReset')?.addEventListener('click', () => {
        pomoActive = false;
        if (pomoInterval) clearInterval(pomoInterval);
        pomodoroSeconds = 25 * 60;
        updatePomoDisplay();
    });
    updatePomoDisplay();

    // تغییر تب دمو
    const panes = document.querySelectorAll('.demo-pane');
    const demoTabs = document.querySelectorAll('.demo-tab');
    function switchPane(paneId) {
        panes.forEach(p => p.classList.remove('active'));
        document.getElementById(paneId).classList.add('active');
        demoTabs.forEach(tab => {
            if (tab.dataset.pane === paneId) tab.classList.add('active');
            else tab.classList.remove('active');
        });
    }
    demoTabs.forEach(tab => {
        tab.addEventListener('click', () => switchPane(tab.dataset.pane));
    });
    const featureCards = document.querySelectorAll('.feature-card');
    featureCards.forEach(card => {
        card.addEventListener('click', () => {
            const demo = card.dataset.demo;
            if (demo === 'tasks') switchPane('tasksDemo');
            else if (demo === 'goals') switchPane('goalsDemo');
            else if (demo === 'pomodoro') switchPane('pomodoroDemo');
            else if (demo === 'share') switchPane('shareDemo');
            document.querySelector('.demo-zone').scrollIntoView({ behavior: 'smooth', block: 'start' });
        });
    });

    // موسیقی و بلک‌اوت
    const audio = new Audio('start.mp3');
    audio.loop = false;
    audio.volume = 0.7;
    let musicStarted = false;
    let blackoutTriggered = false;

    const finalMotivations = [
        "✨ امروز روز شروع بزرگیه... ✨",
        "⚡ تو می‌تونی هر کاری رو به سرانجام برسونی! ⚡",
        "💎 هر قدم کوچک، تو را به قلّه نزدیک‌تر می‌کند. 💎",
        "🌟 به جمع برندگان بپیوندید. 🌟",
        "🔥 قدرت در دستان توست. فقط کافیه شروع کنی. 🔥",
        "🎯 اهداف خود را به پرواز درآورید. 🎯"
    ];
    let motivationIndex = 0;
    function rotateMotivation() {
        const el = document.getElementById('finalMotivation');
        if (el) {
            el.style.opacity = '0';
            setTimeout(() => {
                el.innerText = finalMotivations[motivationIndex % finalMotivations.length];
                el.style.opacity = '1';
                motivationIndex++;
            }, 300);
        }
    }
    setInterval(rotateMotivation, 5000);
    rotateMotivation();

    const startOverlay = document.getElementById('startOverlay');
    startOverlay.addEventListener('click', () => {
        if (musicStarted) return;
        audio.play().then(() => {
            musicStarted = true;
            startOverlay.style.display = 'none';
        }).catch(e => { audio.play().catch(()=>{}); });
    });

    audio.addEventListener('ended', () => {
        if (blackoutTriggered) return;
        blackoutTriggered = true;
        document.body.classList.add('blackout');
        initInfinityAnimation();
    });

    // انیمیشن بینهایت
    let infinityCanvas, ctxInf, width, height;
    let infinityParticles = [];
    function initInfinityAnimation() {
        infinityCanvas = document.getElementById('infinityCanvas');
        if (!infinityCanvas) return;
        ctxInf = infinityCanvas.getContext('2d');
        resizeInfinity();
        window.addEventListener('resize', resizeInfinity);
        createInfinityParticles(180);
        animateInfinity();
    }
    function resizeInfinity() {
        width = infinityCanvas.width = window.innerWidth;
        height = infinityCanvas.height = window.innerHeight;
    }
    function createInfinityParticles(count) {
        const a = Math.min(width, height) * 0.22;
        const b = a * 0.5;
        for (let i = 0; i < count; i++) {
            infinityParticles.push({
                t: Math.random() * Math.PI * 2,
                speed: 0.0015 + Math.random() * 0.003,
                size: 2 + Math.random() * 5,
                color: `hsl(${200 + Math.random() * 80}, 100%, 60%)`
            });
        }
    }
    function updateInfinityParticles() {
        const a = Math.min(width, height) * 0.22;
        const b = a * 0.5;
        const cx = width / 2, cy = height / 2;
        for (let p of infinityParticles) {
            p.t += p.speed;
            if (p.t > Math.PI * 2) p.t -= Math.PI * 2;
            let x = a * Math.sin(p.t);
            let y = b * Math.sin(2 * p.t);
            p.x = cx + x;
            p.y = cy + y;
        }
    }
    function drawInfinity() {
        if (!ctxInf) return;
        ctxInf.clearRect(0, 0, width, height);
        const a = Math.min(width, height) * 0.22;
        const b = a * 0.5;
        const cx = width / 2, cy = height / 2;
        ctxInf.beginPath();
        ctxInf.strokeStyle = 'rgba(10, 132, 255, 0.25)';
        ctxInf.lineWidth = 2.5;
        for (let t = 0; t <= Math.PI * 2; t += 0.05) {
            let x = a * Math.sin(t);
            let y = b * Math.sin(2 * t);
            if (t === 0) ctxInf.moveTo(cx + x, cy + y);
            else ctxInf.lineTo(cx + x, cy + y);
        }
        ctxInf.stroke();
        ctxInf.beginPath();
        ctxInf.strokeStyle = 'rgba(94, 92, 230, 0.3)';
        ctxInf.lineWidth = 1.5;
        for (let t = 0; t <= Math.PI * 2; t += 0.05) {
            let x = a * Math.sin(t + 0.2);
            let y = b * Math.sin(2 * t + 0.3);
            if (t === 0) ctxInf.moveTo(cx + x, cy + y);
            else ctxInf.lineTo(cx + x, cy + y);
        }
        ctxInf.stroke();
        for (let p of infinityParticles) {
            ctxInf.beginPath();
            ctxInf.arc(p.x, p.y, p.size, 0, Math.PI * 2);
            ctxInf.fillStyle = p.color;
            ctxInf.shadowBlur = 10;
            ctxInf.shadowColor = '#0a84ff';
            ctxInf.fill();
        }
        ctxInf.shadowBlur = 0;
    }
    function animateInfinity() {
        if (!document.body.classList.contains('blackout')) return;
        updateInfinityParticles();
        drawInfinity();
        requestAnimationFrame(animateInfinity);
    }

    // پس‌زمینه ذرات
    const bgCanvas = document.getElementById('particle-canvas');
    const bgCtx = bgCanvas.getContext('2d');
    let bgW, bgH, bgParticles = [];
    function resizeBg() {
        bgW = bgCanvas.width = window.innerWidth;
        bgH = bgCanvas.height = window.innerHeight;
    }
    window.addEventListener('resize', resizeBg);
    resizeBg();
    class BgParticle {
        constructor() { this.reset(); }
        reset() {
            this.x = Math.random() * bgW;
            this.y = Math.random() * bgH;
            this.vx = (Math.random() - 0.5) * 0.3;
            this.vy = (Math.random() - 0.5) * 0.3;
            this.size = Math.random() * 3 + 1;
            this.alpha = Math.random() * 0.5 + 0.2;
        }
        update() {
            this.x += this.vx;
            this.y += this.vy;
            if (this.x < 0 || this.x > bgW || this.y < 0 || this.y > bgH) this.reset();
        }
        draw() {
            bgCtx.beginPath();
            bgCtx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
            bgCtx.fillStyle = `rgba(10,132,255,${this.alpha})`;
            bgCtx.fill();
        }
    }
    for (let i = 0; i < 150; i++) bgParticles.push(new BgParticle());
    function animateBg() {
        bgCtx.clearRect(0, 0, bgW, bgH);
        bgParticles.forEach(p => { p.update(); p.draw(); });
        requestAnimationFrame(animateBg);
    }
    animateBg();

    // ستاره‌ها
    function generateStars() {
        const container = document.getElementById('starsContainer');
        if (!container) return;
        container.innerHTML = '';
        for (let i = 0; i < 250; i++) {
            const star = document.createElement('div');
            star.classList.add('star');
            const size = Math.random() * 3 + 1;
            star.style.width = size + 'px';
            star.style.height = size + 'px';
            star.style.left = Math.random() * 100 + '%';
            star.style.top = Math.random() * 100 + '%';
            star.style.animationDuration = Math.random() * 12 + 6 + 's';
            star.style.animationDelay = Math.random() * 10 + 's';
            star.style.opacity = Math.random() * 0.8 + 0.2;
            container.appendChild(star);
        }
    }
    generateStars();

    // انیمیشن اسکرول
    const animated = document.querySelectorAll('.step-card, .feature-card, .vision-card, .cta-big');
    const obs = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.style.transition = 'all 0.6s ease-out';
                entry.target.style.opacity = '1';
                entry.target.style.transform = 'translateY(0)';
                obs.unobserve(entry.target);
            }
        });
    }, { threshold: 0.1 });
    animated.forEach(el => {
        el.style.opacity = '0';
        el.style.transform = 'translateY(20px)';
        obs.observe(el);
    });
</script>
</body>
</html>