<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Puzzle Nature - Where Stories Bloom</title>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
        <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
        <link rel="stylesheet" href="/static/css/style.css">
    </head>
<body class="homepage-body">
    <!-- Modern Navigation -->
    <nav class="navbar navbar-expand-lg navbar-light modern-nav">
        <div class="container">
            <a class="navbar-brand modern-brand" href="/">
                <i class="fas fa-leaf me-2"></i>Puzzle Nature
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <div class="navbar-nav ms-auto">
                    <a class="nav-link active" href="/home"><i class="fas fa-home me-1"></i>Home</a>
                    <a class="nav-link nature-nav" href="#" onclick="showSection('about')"><i class="fas fa-leaf me-1"></i>About</a>
                    <a class="nav-link nature-nav" href="#" onclick="showSection('topics')"><i class="fas fa-seedling me-1"></i>Topics</a>
                    <a class="nav-link nature-nav" href="#" onclick="showSection('explore')"><i class="fas fa-mountain me-1"></i>Explore</a>
                    <a class="nav-link" href="/publish"><i class="fas fa-pen me-1"></i>Publish</a>
                    <a class="nav-link" href="/collaborations"><i class="fas fa-users me-1"></i>Collaborations</a>
                    <a class="nav-link" href="/profile"><i class="fas fa-user me-1"></i>Profile</a>
                    <a class="nav-link logout-btn" href="/logout"><i class="fas fa-sign-out-alt me-1"></i>Logout</a>
                </div>
            </div>
        </div>
    </nav>

    <!-- Hero Section -->
    <div class="hero-section">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-lg-8">
                    <h1 class="hero-title">🌿 Welcome back, Nature Writer!</h1>
                    <p class="hero-subtitle">Continue documenting the wonders of our natural world. Share your connection with nature through powerful storytelling.</p>
                </div>
                <div class="col-lg-4 text-end">
                    <div class="hero-stats">
                        <div class="stat-item">
                            <h3 class="stat-number">{{ article_count }}</h3>
                            <p class="stat-label">Articles Written</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container main-content">
        {% if first_login_password %}
        <div class="modern-alert password-alert">
            <div class="alert-content">
                <div class="alert-icon">
                    <i class="fas fa-key"></i>
                </div>
                <div class="alert-text">
                    <h5>Welcome! Your Account Password</h5>
                    <p>Your account has been created successfully. Here is your generated password:</p>
                    <div class="password-display">
                        <code class="text-black">{{ first_login_password }}</code>
                        <button class="copy-btn" onclick="copyPassword('{{ first_login_password }}')">
                            <i class="fas fa-copy"></i>
                        </button>
                    </div>
                    <small><i class="fas fa-exclamation-triangle"></i> Please save this password immediately. It will not be shown again.</small>
                </div>
                <button type="button" class="modern-close" onclick="this.parentElement.parentElement.style.display='none'">
                    <i class="fas fa-times"></i>
                </button>
            </div>
        </div>
        {% endif %}

        <!-- Quick Actions Bar -->
        <div class="quick-actions-bar">
            <div class="actions-left">
                <h2 class="section-title">
                    <i class="fas fa-tree me-2"></i>Your Nature Stories
                </h2>
                <div class="article-progress">
                    <span class="progress-text">{{ article_count }} of 20 nature stories shared</span>
                    <div class="progress-bar-container">
                        <div class="progress-bar" style="width: {{ (article_count / 20 * 100) }}%"></div>
                    </div>
                </div>
            </div>
            <div class="actions-right">
                <a href="/publish" class="btn btn-primary modern-btn">
                    <i class="fas fa-seedling me-2"></i>Share Nature Story
                </a>
            </div>
        </div>

        <!-- Main Content Sections -->
        <div class="content-sections">
            <!-- Articles Section (Default) -->
            <div id="articles-section" class="content-section active">
                {% if articles %}
                    <div class="articles-grid">
                        {% for article in articles %}
                            <div class="article-card">
                                <div class="card-header">
                                    <div class="article-meta">
                                        <span class="article-date">
                                            <i class="fas fa-calendar-alt me-1"></i>{{ article.created_at }}
                                        </span>
                                        <div class="article-authors">
                                            <span class="author-info">
                                                <i class="fas fa-user me-1"></i>{{ article.author_name }}
                                                {% if article.collaborator_name %}
                                                <span class="collaborator">& {{ article.collaborator_name }}</span>
                                                {% endif %}
                                            </span>
                                        </div>
                                    </div>
                                </div>
                                <div class="card-content">
                                    <h3 class="article-title">{{ article.title }}</h3>
                                    <p class="article-excerpt">{{ article.content[:200] }}{% if article.content|length > 200 %}...{% endif %}</p>
                                </div>
                                <div class="card-footer">
                                    <a href="/article/{{ article.uuid }}" class="read-more-btn">
                                        <span>Read Article</span>
                                        <i class="fas fa-arrow-right ms-2"></i>
                                    </a>
                                    <div class="article-actions">
                                        <button class="action-btn" title="Share">
                                            <i class="fas fa-share-alt"></i>
                                        </button>
                                        <button class="action-btn" title="Bookmark">
                                            <i class="fas fa-bookmark"></i>
                                        </button>
                                    </div>
                                </div>
                                <!-- Hidden UUIDs for functionality -->
                                <span class="d-none author-uuid">{{ article.author_uuid }}</span>
                                {% if article.collaborator_uuid %}
                                <span class="d-none collaborator-uuid">{{ article.collaborator_uuid }}</span>
                                {% endif %}
                            </div>
                        {% endfor %}
                    </div>
                {% else %}
                    <div class="empty-state">
                        <div class="empty-icon">
                            <i class="fas fa-seedling"></i>
                        </div>
                        <h3>No Articles Yet</h3>
                        <p>Your nature writing journey begins here. Start sharing your connection with the natural world!</p>
                        <a href="/publish" class="btn btn-primary modern-btn">
                            <i class="fas fa-plus me-2"></i>Write Your First Nature Story
                        </a>
                    </div>
                {% endif %}
            </div>

            <!-- About Section -->
            <div id="about-section" class="content-section">
                <div class="nature-about">
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="about-content">
                                <h2 class="nature-title">
                                    <i class="fas fa-leaf me-2"></i>About Puzzle Nature
                                </h2>
                                <p class="lead">Connect with nature through the power of words. Puzzle Nature is a platform dedicated to environmental storytelling, wildlife conservation narratives, and the profound relationship between humanity and the natural world.</p>
                                
                                <div class="nature-stats">
                                    <div class="stat-card">
                                        <i class="fas fa-tree"></i>
                                        <h4>1,247</h4>
                                        <span>Nature Stories</span>
                                    </div>
                                    <div class="stat-card">
                                        <i class="fas fa-users"></i>
                                        <h4>892</h4>
                                        <span>Eco Writers</span>
                                    </div>
                                    <div class="stat-card">
                                        <i class="fas fa-globe"></i>
                                        <h4>45</h4>
                                        <span>Countries</span>
                                    </div>
                                </div>

                                <div class="mission-statement">
                                    <h4><i class="fas fa-compass me-2"></i>Our Mission</h4>
                                    <p>To inspire environmental consciousness through authentic storytelling, fostering a deeper connection between readers and the natural world while promoting conservation through the power of narrative.</p>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="nature-features">
                                <div class="feature-item">
                                    <div class="feature-icon">
                                        <i class="fas fa-mountain"></i>
                                    </div>
                                    <div class="feature-text">
                                        <h5>Wilderness Chronicles</h5>
                                        <p>Share your adventures and observations from the wild places of our world.</p>
                                    </div>
                                </div>
                                <div class="feature-item">
                                    <div class="feature-icon">
                                        <i class="fas fa-dove"></i>
                                    </div>
                                    <div class="feature-text">
                                        <h5>Wildlife Stories</h5>
                                        <p>Document encounters with wildlife and contribute to conservation awareness.</p>
                                    </div>
                                </div>
                                <div class="feature-item">
                                    <div class="feature-icon">
                                        <i class="fas fa-seedling"></i>
                                    </div>
                                    <div class="feature-text">
                                        <h5>Sustainable Living</h5>
                                        <p>Share insights on eco-friendly practices and sustainable lifestyle choices.</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Topics Section -->
            <div id="topics-section" class="content-section">
                <div class="nature-topics">
                    <h2 class="nature-title text-center mb-5">
                        <i class="fas fa-seedling me-2"></i>Nature Writing Topics
                    </h2>
                    <div class="topics-grid">
                        <div class="topic-card" onclick="filterByTopic('wildlife')">
                            <div class="topic-icon">
                                <i class="fas fa-paw"></i>
                            </div>
                            <h4>Wildlife & Animals</h4>
                            <p>Stories about animal behavior, conservation, and wildlife encounters.</p>
                            <span class="topic-count">23 articles</span>
                        </div>
                        <div class="topic-card" onclick="filterByTopic('conservation')">
                            <div class="topic-icon">
                                <i class="fas fa-shield-alt"></i>
                            </div>
                            <h4>Conservation</h4>
                            <p>Environmental protection, sustainability, and conservation efforts.</p>
                            <span class="topic-count">18 articles</span>
                        </div>
                        <div class="topic-card" onclick="filterByTopic('adventure')">
                            <div class="topic-icon">
                                <i class="fas fa-hiking"></i>
                            </div>
                            <h4>Outdoor Adventures</h4>
                            <p>Hiking, camping, and wilderness exploration experiences.</p>
                            <span class="topic-count">31 articles</span>
                        </div>
                        <div class="topic-card" onclick="filterByTopic('climate')">
                            <div class="topic-icon">
                                <i class="fas fa-thermometer-half"></i>
                            </div>
                            <h4>Climate & Weather</h4>
                            <p>Climate change, weather patterns, and environmental science.</p>
                            <span class="topic-count">15 articles</span>
                        </div>
                        <div class="topic-card" onclick="filterByTopic('botanical')">
                            <div class="topic-icon">
                                <i class="fas fa-leaf"></i>
                            </div>
                            <h4>Plants & Botany</h4>
                            <p>Flora, gardening, forest ecology, and plant conservation.</p>
                            <span class="topic-count">27 articles</span>
                        </div>
                        <div class="topic-card" onclick="filterByTopic('photography')">
                            <div class="topic-icon">
                                <i class="fas fa-camera"></i>
                            </div>
                            <h4>Nature Photography</h4>
                            <p>Visual storytelling through nature and landscape photography.</p>
                            <span class="topic-count">19 articles</span>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Explore Section -->
            <div id="explore-section" class="content-section">
                <div class="nature-explore">
                    <h2 class="nature-title text-center mb-5">
                        <i class="fas fa-mountain me-2"></i>Explore Nature's Stories
                    </h2>
                    
                    <div class="explore-featured">
                        <h3><i class="fas fa-star me-2"></i>Featured This Week</h3>
                        <div class="featured-grid">
                            <div class="featured-card">
                                <div class="featured-image">
                                    <i class="fas fa-forest"></i>
                                </div>
                                <div class="featured-content">
                                    <h5>The Silent Forest</h5>
                                    <p>A journey through the ancient redwood groves of California...</p>
                                    <div class="featured-meta">
                                        <span><i class="fas fa-user"></i> Sarah Wilson</span>
                                        <span><i class="fas fa-eye"></i> 1.2k views</span>
                                    </div>
                                </div>
                            </div>
                            <div class="featured-card">
                                <div class="featured-image">
                                    <i class="fas fa-water"></i>
                                </div>
                                <div class="featured-content">
                                    <h5>Ocean's Voice</h5>
                                    <p>Marine conservation through the eyes of a marine biologist...</p>
                                    <div class="featured-meta">
                                        <span><i class="fas fa-user"></i> Dr. Michael Chen</span>
                                        <span><i class="fas fa-eye"></i> 890 views</span>
                                    </div>
                                </div>
                            </div>
                            <div class="featured-card">
                                <div class="featured-image">
                                    <i class="fas fa-mountain"></i>
                                </div>
                                <div class="featured-content">
                                    <h5>Peak Reflections</h5>
                                    <p>Life lessons learned at 14,000 feet above sea level...</p>
                                    <div class="featured-meta">
                                        <span><i class="fas fa-user"></i> Alex Rodriguez</span>
                                        <span><i class="fas fa-eye"></i> 1.5k views</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="explore-categories">
                        <h3><i class="fas fa-compass me-2"></i>Discover by Region</h3>
                        <div class="region-cards">
                            <div class="region-card" onclick="exploreRegion('forests')">
                                <i class="fas fa-tree"></i>
                                <h5>Forest Stories</h5>
                                <span>42 articles</span>
                            </div>
                            <div class="region-card" onclick="exploreRegion('oceans')">
                                <i class="fas fa-wave"></i>
                                <h5>Ocean Tales</h5>
                                <span>28 articles</span>
                            </div>
                            <div class="region-card" onclick="exploreRegion('mountains')">
                                <i class="fas fa-mountain"></i>
                                <h5>Mountain Chronicles</h5>
                                <span>35 articles</span>
                            </div>
                            <div class="region-card" onclick="exploreRegion('deserts')">
                                <i class="fas fa-sun"></i>
                                <h5>Desert Narratives</h5>
                                <span>16 articles</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Footer -->
    <footer class="modern-footer">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <p class="footer-text">&copy; 2025 Puzzle. Empowering writers worldwide.</p>
                </div>
                <div class="col-md-6 text-end">
                    <div class="social-links">
                        <a href="#" title="Twitter"><i class="fab fa-twitter"></i></a>
                        <a href="#" title="Facebook"><i class="fab fa-facebook"></i></a>
                        <a href="#" title="Instagram"><i class="fab fa-instagram"></i></a>
                    </div>
                </div>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        function copyPassword(password) {
            navigator.clipboard.writeText(password).then(() => {
                const btn = event.target.closest('.copy-btn');
                const originalIcon = btn.innerHTML;
                btn.innerHTML = '<i class="fas fa-check"></i>';
                setTimeout(() => {
                    btn.innerHTML = originalIcon;
                }, 2000);
            });
        }

        function showSection(sectionName) {
            // Hide all sections
            document.querySelectorAll('.content-section').forEach(section => {
                section.classList.remove('active');
            });
            
            // Remove active class from all nav links
            document.querySelectorAll('.nav-link').forEach(link => {
                link.classList.remove('active');
            });
            
            // Show selected section
            const targetSection = document.getElementById(sectionName + '-section');
            if (targetSection) {
                targetSection.classList.add('active');
            }
            
            // Add active class to clicked nav link
            event.target.classList.add('active');
            
            // Update section title
            const sectionTitles = {
                'about': 'About Puzzle Nature',
                'topics': 'Nature Writing Topics',
                'explore': 'Explore Nature Stories',
                'articles': 'Your Nature Stories'
            };
            
            const titleElement = document.querySelector('.section-title');
            if (titleElement && sectionTitles[sectionName]) {
                titleElement.innerHTML = `<i class="fas fa-${getIconForSection(sectionName)} me-2"></i>${sectionTitles[sectionName]}`;
            }
        }
        
        function getIconForSection(section) {
            const icons = {
                'about': 'leaf',
                'topics': 'seedling',
                'explore': 'mountain',
                'articles': 'tree'
            };
            return icons[section] || 'tree';
        }

        function filterByTopic(topic) {
            // This would filter articles by topic in a real implementation
            console.log('Filtering by topic:', topic);
            
            // Show notification
            const notification = document.createElement('div');
            notification.className = 'topic-notification';
            notification.innerHTML = `<i class="fas fa-filter"></i> Filtering articles by ${topic}...`;
            document.body.appendChild(notification);
            
            setTimeout(() => {
                notification.remove();
                showSection('articles');
            }, 2000);
        }

        function exploreRegion(region) {
            // This would show articles from a specific region in a real implementation
            console.log('Exploring region:', region);
            
            // Show notification
            const notification = document.createElement('div');
            notification.className = 'region-notification';
            notification.innerHTML = `<i class="fas fa-compass"></i> Exploring ${region} stories...`;
            document.body.appendChild(notification);
            
            setTimeout(() => {
                notification.remove();
                showSection('articles');
            }, 2000);
        }

        // Initialize default section
        document.addEventListener('DOMContentLoaded', function() {
            // Set articles as default active section
            document.getElementById('articles-section').classList.add('active');
            
            // Set default section title
            const titleElement = document.querySelector('.section-title');
            if (titleElement) {
                titleElement.innerHTML = '<i class="fas fa-tree me-2"></i>Your Nature Stories';
            }
        });
    </script>
</body>
</html>