<?php
session_start();
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

if (!isset($_SESSION['streak'])) {
    $_SESSION['streak'] = 0;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chirivia - Save the Planet, Save Your Chircuit</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-green: #2E8B57;
            --secondary-blue: #4682B4;
            --accent-color: #5F9EA0;
            --background-light: #F0F8FF;
            --surface-white: #FFFFFF;
            --text-dark: #2F4F4F;
            --font-headings: 'Inter', sans-serif;
            --font-body: 'Inter', sans-serif;
            --spacing-base: 8px;
            --border-radius: 0.5rem; /* 8px */
        }

        body {
            font-family: var(--font-body);
            background-color: var(--background-light);
            color: var(--text-dark);
            margin: 0;
            line-height: 1.6;
        }

        .container {
            max-width: 960px;
            margin: 0 auto;
            padding: calc(var(--spacing-base) * 2);
        }

        h1, h2, h3 {
            font-family: var(--font-headings);
            color: var(--primary-green);
        }

        .header {
            background: var(--surface-white);
            padding: calc(var(--spacing-base) * 2) 0;
            border-bottom: 1px solid #eee;
            text-align: center;
        }

        .header .logo {
            font-family: var(--font-headings);
            font-size: 2rem;
            color: var(--primary-green);
            text-decoration: none;
            font-weight: bold;
        }

        .hero {
            background: linear-gradient(135deg, var(--primary-green), var(--secondary-blue));
            color: var(--surface-white);
            padding: calc(var(--spacing-base) * 8) calc(var(--spacing-base) * 2);
            text-align: center;
            background-image: url('assets/pasted-20251004-214642-63e1d23c.webp');
            background-size: 100% auto;
            background-repeat: no-repeat;
            background-position: center 25%;
            position: relative;
        }
        
        .hero::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.5);
        }

        .hero-content {
            position: relative;
            z-index: 1;
        }

        .hero h1 {
            font-size: 4rem;
            margin-bottom: var(--spacing-base);
            color: var(--surface-white);
        }

        .hero p {
            font-size: 1.25rem;
            margin-bottom: calc(var(--spacing-base) * 3);
        }

        .cta-button {
            background-color: var(--accent-color);
            color: var(--surface-white);
            padding: calc(var(--spacing-base) * 1.5) calc(var(--spacing-base) * 3);
            border: none;
            border-radius: var(--border-radius);
            font-size: 1.1rem;
            font-weight: bold;
            text-decoration: none;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .cta-button:hover {
            background-color: #53868B;
        }

        .section {
            padding: calc(var(--spacing-base) * 6) 0;
            border-bottom: 1px solid #eee;
        }
        
        .section:last-child {
            border-bottom: none;
        }

        .pet-section {
            display: flex;
            align-items: center;
            gap: calc(var(--spacing-base) * 4);
        }

        .pet-section .pet-image-frame {
            width: 300px;
            height: 300px;
            border-radius: 50%;
            overflow: hidden;
            border: 5px solid var(--surface-white);
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
        }

        .pet-section img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transform: scale(1.2);
        }
        
        .pet-status h2 {
            margin-top: 0;
            font-size: 2.5rem;
            margin-bottom: 0;
        }

        .streak-counter {
            font-size: 1.5rem;
            font-weight: bold;
            color: var(--secondary-blue);
        }

        .about-section h2 {
            font-size: 2.5rem;
        }

        .about-section {
            display: flex;
            align-items: center;
            gap: calc(var(--spacing-base) * 4);
        }
        
        .about-section img {
            max-width: 400px;
            border-radius: var(--border-radius);
        }

        .footer {
            background-color: var(--surface-white);
            text-align: center;
            padding: calc(var(--spacing-base) * 3) 0;
            margin-top: calc(var(--spacing-base) * 4);
            font-size: 0.9rem;
        }
        
        .footer a {
            color: var(--primary-green);
            text-decoration: none;
        }

        @keyframes float {
            0% {
                transform: translateY(0px);
            }
            50% {
                transform: translateY(-20px);
            }
            100% {
                transform: translateY(0px);
            }
        }

        .animated-pet {
            animation: float 3s ease-in-out infinite;
        }

        .pet-image-frame img {
            position: absolute;
            top: 0;
            left: 0;
            opacity: 0;
            transition: opacity 1s ease-in-out;
        }

        .pet-image-frame img.active {
            opacity: 1;
        }

        /* Chat Widget */
        .chat-widget-container {
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 1000;
        }
        .chat-bubble {
            width: 60px;
            height: 60px;
            background-color: var(--secondary-blue);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
            transition: transform 0.2s;
        }
        .chat-bubble:hover {
            transform: scale(1.1);
        }
        .chat-window {
            display: none;
            position: absolute;
            bottom: 80px;
            right: 0;
            width: 350px;
            max-width: 90vw;
            background: #fff;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.3);
            flex-direction: column;
        }
        .chat-header {
            background: var(--secondary-blue);
            color: white;
            padding: 15px;
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .chat-header p {
            margin: 0;
            font-weight: bold;
        }
        .close-chat {
            cursor: pointer;
            font-size: 24px;
        }
        .chat-body {
            padding: 15px;
            height: 300px;
            overflow-y: auto;
            background: #f9f9f9;
        }
        .message {
            margin-bottom: 15px;
        }
        .message p {
            background: #e9e9eb;
            padding: 10px 15px;
            border-radius: 15px;
            display: inline-block;
            max-width: 80%;
            margin: 0;
        }
        .chat-footer {
            padding: 15px;
            display: flex;
            border-top: 1px solid #ddd;
        }
        .chat-footer input {
            flex: 1;
            border: 1px solid #ddd;
            border-radius: 20px;
            padding: 10px;
            margin-right: 10px;
        }
        .chat-footer button {
            background: var(--secondary-blue);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 20px;
            cursor: pointer;
        }
        
        .cta-button img {
        }

    </style>
</head>
<body>


    

    <main>
        <section class="hero">
            <div class="hero-content">
                <h1>Chirivia</h1>
                <p>Save the Planet, Save Your Chircuit.</p>
            </div>
        </section>

        <div style="text-align: center; padding: 24px 0; background-color: var(--background-light); border-bottom: 1px solid #eee;">
            <a href="quiz.php?v=<?php echo time(); ?>" class="cta-button" style="margin-right: 16px;">Play Trivia</a>
            <a href="actions.php?v=<?php echo time(); ?>" class="cta-button" style="margin-right: 16px;">Log an Action</a>
            <a href="streaks.php?v=<?php echo time(); ?>" class="cta-button" style="margin-right: 16px;">Streaks</a>
            <a href="chatbot.php?v=<?php echo time(); ?>" class="cta-button">Chatbot</a>
        </div>

        <div class="container">
            <section class="section pet-section">
                <div class="pet-image-frame animated-pet" style="position: relative;">
                    <img src="assets/pasted-20251004-192255-8c7c39e6.webp" alt="A cute, healthy pet chircuit." class="active">
                    <img src="assets/pasted-20251004-222033-3b718197.webp" alt="A happy, playful pet chircuit.">
                </div>
                <div class="pet-status">
                    <h2>Your Pet Chircuit</h2>
                    <p>Keep me alive by learning about our planet!</p>
                    <div class="streak-counter">
                        🔥 Streak: <?php echo $_SESSION['streak']; ?> <?php echo ($_SESSION['streak'] == 1) ? 'day' : 'days'; ?> 🔥
                    </div>
                </div>
            </section>

            <section class="section about-section">
                <div>
                    <h2>About Chirivia</h2>
                    <p>Chirivia makes learning about environmental issues fun and engaging. Every correct answer helps you maintain your streak and contributes to a (virtual) healthier planet, keeping your pet happy and healthy.</p>
                    <p>You can also log real-world actions to get extra points!</p>
                </div>
                <img src="https://picsum.photos/seed/about/800/600" alt="A person planting a small tree, symbolizing environmental action.">
            </section>
        </div>
    </main>

    <footer class="footer">
        <div class="container">
            <p>&copy; 2025 Chirivia. All Rights Reserved. | <a href="privacy.php">Privacy Policy</a></p>
        </div>
    </footer>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const petImageFrame = document.querySelector('.pet-image-frame');
            const images = petImageFrame.querySelectorAll('img');
            let currentIndex = 0;

            setInterval(() => {
                images[currentIndex].classList.remove('active');
                currentIndex = (currentIndex + 1) % images.length;
                images[currentIndex].classList.add('active');
            }, 3000); // Change image every 3 seconds
        });
    </script>

    <!-- Chat Widget -->
    <div class="chat-widget-container">
        <div id="chat-bubble" class="chat-bubble">
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="white"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z"/></svg>
        </div>
        <div id="chat-window" class="chat-window">
            <div class="chat-header">
                <p>Chat with us!</p>
                <span id="close-chat" class="close-chat">&times;</span>
            </div>
            <div class="chat-body">
                <div class="message received">
                    <p>Hi there! How can I help you today?</p>
                </div>
            </div>
            <div class="chat-footer">
                <input type="text" placeholder="Type a message...">
                <button>Send</button>
            </div>
        </div>
    </div>

    <script>
        const chatBubble = document.getElementById('chat-bubble');
        const chatWindow = document.getElementById('chat-window');
        const closeChat = document.getElementById('close-chat');

        chatBubble.addEventListener('click', () => {
            chatWindow.style.display = 'flex';
            chatBubble.style.display = 'none';
        });

        closeChat.addEventListener('click', () => {
            chatWindow.style.display = 'none';
            chatBubble.style.display = 'flex';
        });
    </script>

</body>
</html>