<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>magic Eyes - Secure Access</title>
    <style>
        #auth-system {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
            background-size: 400% 400%;
            animation: gradientBG 15s ease infinite;
            z-index: 9999;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        }

        #auth-system * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        .auth-container {
            width: 90%;
            max-width: 380px;
            background: rgba(255, 255, 255, 0.95);
            padding: 2.5rem;
            border-radius: 20px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            backdrop-filter: blur(10px);
            animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
            position: relative;
            overflow: hidden;
        }

        .auth-container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #ff4757, #5352ed, #20bf6b);
            animation: shimmer 2s linear infinite;
        }

        .auth-header {
            text-align: center;
            margin-bottom: 2.5rem;
        }

        .auth-logo-container {
            position: relative;
            height: 80px;
            margin-bottom: 1.5rem;
        }

        .auth-logo {
            font-size: 3.5rem;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            animation: logoFloat 3s ease-in-out infinite;
        }

        .auth-logo-shadow {
            width: 50px;
            height: 10px;
            background: rgba(0, 0, 0, 0.1);
            border-radius: 50%;
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            animation: shadowPulse 3s ease-in-out infinite;
        }

        .auth-title {
            color: #1a1a1a;
            font-size: 1.8rem;
            font-weight: 700;
            margin-bottom: 0.5rem;
            background: linear-gradient(45deg, #1a2a6c, #b21f1f);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .auth-subtitle {
            color: #666;
            font-size: 1rem;
            font-weight: 500;
            opacity: 0.8;
        }

        .auth-form {
            position: relative;
        }

        .input-container {
            position: relative;
            margin-bottom: 1.5rem;
        }

        .auth-input {
            width: 100%;
            padding: 1.2rem;
            border: 2px solid #e0e0e0;
            border-radius: 12px;
            font-size: 1.1rem;
            font-weight: 500;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            background: rgba(255, 255, 255, 0.9);
            letter-spacing: 0.2em;
            text-align: center;
        }

        .auth-input:focus {
            border-color: #1a2a6c;
            outline: none;
            box-shadow: 0 0 0 4px rgba(26, 42, 108, 0.15);
        }

        .auth-input::placeholder {
            color: #999;
            letter-spacing: normal;
        }

        .auth-hint {
            font-size: 0.9rem;
            color: #666;
            margin: 0.5rem 0;
            text-align: center;
            font-weight: 500;
        }

        .auth-error {
            color: #ff4757;
            font-size: 0.9rem;
            margin: 0.5rem 0;
            min-height: 1.2rem;
            text-align: center;
            font-weight: 500;
            transform: translateY(0);
            transition: all 0.3s ease;
        }

        .auth-error.shake {
            animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
        }

        .auth-button {
            width: 100%;
            padding: 1.2rem;
            border: none;
            border-radius: 12px;
            background: linear-gradient(45deg, #1a2a6c, #b21f1f);
            background-size: 200% 200%;
            color: white;
            font-size: 1.1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .auth-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(26, 42, 108, 0.2);
            animation: gradientMove 3s ease infinite;
        }

        .auth-button:active {
            transform: translateY(0);
        }

        .auth-button:disabled {
            opacity: 0.7;
            cursor: not-allowed;
        }

        .loader {
            display: none;
            width: 24px;
            height: 24px;
            border: 3px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            animation: spin 0.8s linear infinite;
        }

        .digit-display {
            display: flex;
            justify-content: center;
            gap: 8px;
            margin-bottom: 1rem;
        }

        .digit {
            width: 14px;
            height: 14px;
            border-radius: 50%;
            background: #e0e0e0;
            transition: all 0.3s ease;
        }

        .digit.filled {
            background: #1a2a6c;
            transform: scale(1.2);
        }

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

        @keyframes slideUp {
            0% {
                opacity: 0;
                transform: translateY(30px);
            }
            100% {
                opacity: 1;
                transform: translateY(0);
            }
        }

        @keyframes logoFloat {
            0%, 100% { transform: translateY(0) translateX(-50%); }
            50% { transform: translateY(-15px) translateX(-50%); }
        }

        @keyframes shadowPulse {
            0%, 100% { transform: translateX(-50%) scale(1); opacity: 0.3; }
            50% { transform: translateX(-50%) scale(0.7); opacity: 0.1; }
        }

        @keyframes shake {
            10%, 90% { transform: translateX(-1px); }
            20%, 80% { transform: translateX(2px); }
            30%, 50%, 70% { transform: translateX(-4px); }
            40%, 60% { transform: translateX(4px); }
        }

        @keyframes shimmer {
            0% { background-position: -200% 0; }
            100% { background-position: 200% 0; }
        }

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

        @media (max-width: 480px) {
            .auth-container {
                padding: 2rem;
                width: 95%;
            }

            .auth-title {
                font-size: 1.5rem;
            }

            .auth-input {
                font-size: 1rem;
                padding: 1rem;
            }
        }
    </style>
</head>
<body>
    <div id="auth-system">
        <div class="auth-container">
            <div class="auth-header">
                <div class="auth-logo-container">
                    <div class="auth-logo">👁️🔐</div>
                    <div class="auth-logo-shadow"></div>
                </div>
                <h1 class="auth-title">Magic Eyes</h1>
                <p class="auth-subtitle">Secure Authentication Required</p>
            </div>
            <form class="auth-form" onsubmit="return authenticateUser(event)">
                <div class="digit-display">
                    <div class="digit"></div>
                    <div class="digit"></div>
                    <div class="digit"></div>
                    <div class="digit"></div>
                    <div class="digit"></div>
                    <div class="digit"></div>
                </div>
                <div class="input-container">
                    <input 
                        type="password" 
                        class="auth-input" 
                        id="authCode"
                        placeholder="Enter Security Code"
                        maxlength="6"
                        pattern="[0-9]*"
                        inputmode="numeric"
                        autocomplete="off"
                        required
                    >
                </div>
                <div class="auth-hint">Please enter your 6-digit security code</div>
                <div class="auth-error" id="authError"></div>
                <button type="submit" class="auth-button" id="authButton">
                    <span class="button-text">Verify Access</span>
                    <span class="loader"></span>
                </button>
            </form>
        </div>
    </div>

    <script>
        function authenticateUser(event) {
            event.preventDefault();
            
            const input = document.getElementById('authCode');
            const error = document.getElementById('authError');
            const button = document.getElementById('authButton');
            const buttonText = button.querySelector('.button-text');
            const loader = button.querySelector('.loader');
            
            // Reset error
            error.textContent = '';
            
            // Validate input
            if (!/^\d{6}$/.test(input.value)) {
                showError('Please enter a valid 6-digit code');
                return false;
            }
            
            // Show loading state
            button.disabled = true;
            buttonText.style.opacity = '0';
            loader.style.display = 'block';
            
            // Authenticate with delay for UX
            setTimeout(() => {
                if (input.value === '590245') {
                    localStorage.setItem('authenticated', 'true');
                    
                    // Success animation
                    document.getElementById('auth-system').style.transition = 'opacity 0.5s ease';
                    document.getElementById('auth-system').style.opacity = '0';
                    
                    setTimeout(() => {
                        document.getElementById('auth-system').style.display = 'none';
                    }, 500);
                } else {
                    showError('Invalid security code');
                    button.disabled = false;
                    buttonText.style.opacity = '1';
                    loader.style.display = 'none';
                    input.value = '';
                    input.focus();
                    updateDigitDisplay('');
                }
            }, 1500);
            
            return false;
        }

        function showError(message) {
            const error = document.getElementById('authError');
            error.textContent = message;
            error.classList.add('shake');
            setTimeout(() => error.classList.remove('shake'), 500);
        }

        function updateDigitDisplay(value) {
            const digits = document.querySelectorAll('.digit');
            digits.forEach((digit, index) => {
                digit.classList.toggle('filled', index < value.length);
            });
        }

        // Input validation and digit display update
        document.getElementById('authCode').addEventListener('input', (e) => {
            const input = e.target;
            const error = document.getElementById('authError');
            
            if (input.value.length > 0 && !/^\d+$/.test(input.value)) {
                error.textContent = 'Numbers only';
                input.value = input.value.replace(/\D/g, '');
            } else {
                error.textContent = '';
            }
            
            updateDigitDisplay(input.value);
        });

        // Check if already authenticated
        if (localStorage.getItem('authenticated') === 'true') {
            document.getElementById('auth-system').style.display = 'none';
        }
    </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Desert Panther AI - Advanced Real-time AI Communication Hub</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        :root {
            --primary-gradient: linear-gradient(135deg, #00c6fb 0%, #005bea 100%);
            --secondary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            --accent-gradient: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
            --dark-bg: #0f172a;
            --light-text: #ffffff;
            --error-color: #ef4444;
            --success-color: #22c55e;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: var(--dark-bg);
            color: var(--light-text);
            min-height: 100vh;
        }

        .loading-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.8);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 1000;
            backdrop-filter: blur(5px);
        }

        .loading-spinner {
            width: 50px;
            height: 50px;
            border: 5px solid #f3f3f3;
            border-top: 5px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 1rem;
        }

        header {
            background: var(--primary-gradient);
            padding: 1rem;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .nav {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo {
            font-size: 1.8rem;
            font-weight: bold;
            background: linear-gradient(to right, #fff, #a5b4fc);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .logo i {
            font-size: 2rem;
            color: #fff;
        }

        .nav-menu {
            display: flex;
            gap: 2rem;
        }

        .nav-item {
            color: white;
            text-decoration: none;
            padding: 0.5rem 1rem;
            border-radius: 0.5rem;
            transition: all 0.3s ease;
        }

        .nav-item:hover {
            background: rgba(255, 255, 255, 0.2);
        }

        .hamburger {
            display: none;
            cursor: pointer;
            background: none;
            border: none;
            color: white;
            font-size: 1.5rem;
        }

        .mobile-menu {
            display: none;
            position: fixed;
            top: 0;
            right: -100%;
            width: 70%;
            height: 100vh;
            background: var(--dark-bg);
            padding: 2rem;
            transition: right 0.3s ease;
            z-index: 1000;
        }

        .mobile-menu.active {
            right: 0;
        }

        .main-content {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 1.5rem;
            margin-top: 2rem;
        }

        .video-container {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 1rem;
            padding: 1.5rem;
            position: relative;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }

        .video-streams {
            display: grid;
            grid-template-columns: 1fr;
            gap: 1.5rem;
        }

        .video-stream {
            width: 100%;
            height: 450px;
            background: #1e293b;
            border-radius: 0.8rem;
            overflow: hidden;
            position: relative;
        }

        .video-overlay {
            position: absolute;
            bottom: 1rem;
            left: 1rem;
            background: rgba(0, 0, 0, 0.7);
            padding: 0.5rem 1rem;
            border-radius: 0.5rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .stream-status {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: var(--success-color);
        }

        .chat-container {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 1rem;
            padding: 1.5rem;
            display: flex;
            flex-direction: column;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }

        .chat-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
        }

        .chat-messages {
            flex-grow: 1;
            overflow-y: auto;
            padding: 1rem;
            height: 500px;
            background: rgba(0, 0, 0, 0.2);
            border-radius: 0.8rem;
            margin-bottom: 1rem;
            scroll-behavior: smooth;
        }

        .message {
            margin-bottom: 1rem;
            padding: 0.8rem 1.2rem;
            border-radius: 0.8rem;
            max-width: 85%;
            animation: messageAppear 0.3s ease;
        }

        @keyframes messageAppear {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .user-message {
            background: var(--primary-gradient);
            margin-left: auto;
        }

        .ai-message {
            background: var(--secondary-gradient);
            margin-right: auto;
        }

        .message-meta {
            font-size: 0.8rem;
            opacity: 0.8;
            margin-top: 0.3rem;
        }

        .input-container {
            display: flex;
            gap: 0.8rem;
            position: relative;
        }

        .input-wrapper {
            flex-grow: 1;
            position: relative;
        }

        input[type="text"] {
            width: 100%;
            padding: 0.8rem 1rem;
            padding-right: 3rem;
            border: none;
            border-radius: 0.8rem;
            background: rgba(255, 255, 255, 0.1);
            color: white;
            font-size: 1rem;
            transition: all 0.3s ease;
        }

        input[type="text"]:focus {
            outline: none;
            background: rgba(255, 255, 255, 0.15);
            box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
        }

        .emoji-picker {
            position: absolute;
            right: 1rem;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            font-size: 1.2rem;
        }

        button {
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 0.8rem;
            background: var(--primary-gradient);
            color: white;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        button:hover {
            opacity: 0.9;
            transform: translateY(-1px);
        }

        button:active {
            transform: translateY(1px);
        }

        .controls {
            display: flex;
            gap: 1rem;
            margin-top: 1.5rem;
            flex-wrap: wrap;
        }

        .control-button {
            padding: 0.8rem 1.5rem;
            border-radius: 0.8rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            min-width: 120px;
            justify-content: center;
        }

        .control-button i {
            font-size: 1.2rem;
        }

        footer {
            margin-top: 3rem;
            padding: 2rem;
            background: var(--primary-gradient);
            text-align: center;
        }

        .developer-info {
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
        }

        .developer-info a {
            color: white;
            text-decoration: none;
            transition: opacity 0.3s ease;
        }

        .developer-info a:hover {
            opacity: 0.8;
        }

        .notification {
            position: fixed;
            top: 2rem;
            right: 2rem;
            padding: 1rem 2rem;
            border-radius: 0.8rem;
            background: var(--success-color);
            color: white;
            animation: slideIn 0.3s ease;
            z-index: 1000;
        }

        @keyframes slideIn {
            from { transform: translateX(100%); opacity: 0; }
            to { transform: translateX(0); opacity: 1; }
        }

        .error {
            background: var(--error-color);
        }

        .settings-panel {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: var(--dark-bg);
            padding: 2rem;
            border-radius: 1rem;
            width: 90%;
            max-width: 500px;
            z-index: 1000;
            display: none;
        }

        .settings-panel.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translate(-50%, -48%); }
            to { opacity: 1; transform: translate(-50%, -50%); }
        }

        @media (max-width: 768px) {
            .main-content {
                grid-template-columns: 1fr;
            }

            .hamburger {
                display: block;
            }

            .nav-menu {
                display: none;
            }

            .video-stream {
                height: 300px;
            }

            .controls {
                justify-content: center;
            }
        }

        .stream-quality {
            position: absolute;
            top: 1rem;
            right: 1rem;
            background: rgba(0, 0, 0, 0.7);
            padding: 0.3rem 0.8rem;
            border-radius: 0.5rem;
            font-size: 0.9rem;
        }

        .ai-thinking {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.5rem 1rem;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 0.5rem;
            margin-bottom: 1rem;
        }

        .typing-indicator {
            display: flex;
            gap: 0.3rem;
        }

        .typing-dot {
            width: 6px;
            height: 6px;
            background: white;
            border-radius: 50%;
            animation: typingAnimation 1.4s infinite;
        }

        .typing-dot:nth-child(2) { animation-delay: 0.2s; }
        .typing-dot:nth-child(3) { animation-delay: 0.4s; }

        @keyframes typingAnimation {
            0%, 60%, 100% { transform: translateY(0); }
            30% { transform: translateY(-4px); }
        }
    </style>
</head>
<body>
    <div class="loading-overlay" id="loadingOverlay">
        <div class="loading-spinner"></div>
    </div>

    <header>
        <nav class="nav container">
            <div class="logo">
                <i class="fas fa-robot"></i>
                Desert Panther AI
            </div>
            <div class="nav-menu">
                <a href="#" class="nav-item">Home</a>
                <a href="#" class="nav-item">Features</a>
                <a href="#" class="nav-item">About</a>
                <a href="#" class="nav-item">Contact</a>
            </div>
            <button class="hamburger" id="menuButton">
                <i class="fas fa-bars"></i>
            </button>
        </nav>
    </header>

    <div class="mobile-menu" id="mobileMenu">
        <div style="text-align: right;">
            <button class="hamburger" id="closeMenu">
                <i class="fas fa-times"></i>
            </button>
        </div>
        <a href="#" class="nav-item">Home</a>
        <a href="#" class="nav-item">Features</a>
        <a href="#" class="nav-item">About</a>
        <a href="#" class="nav-item">Contact</a>
    </div>

    <main class="container">
        <div class="main-content">
            <div class="video-container">
                <div class="video-streams">
                    <video class="video-stream" id="localVideo" autoplay playsinline muted></video>
                    <div class="video-overlay">
                        <div class="stream-status"></div>
                        <span>Live</span>
                    </div>
                    <div class="stream-quality">HD</div>
                    <video class="video-stream" id="remoteVideo" autoplay playsinline></video>
                </div>
                <div class="controls">
                    <button class="control-button" id="startStream">
                        <i class="fas fa-play"></i>
                        Start Stream
                    </button>
                    <button class="control-button" id="toggleAudio">
                        <i class="fas fa-microphone"></i>
                        Toggle Audio
                    </button>
                    <button class="control-button" id="toggleVideo">
                        <i class="fas fa-video"></i>
                        Toggle Video
                    </button>
                    <button class="control-button" id="settings">
                        <i class="fas fa-cog"></i>
                        Settings
                    </button>
                </div>
            </div>

            <div class="chat-container">
                <div class="chat-header">
                    <h2>AI Chat</h2>
                    <button id="clearChat">
                        <i class="fas fa-trash"></i>
                    </button>
                </div>
                <div class="chat-messages" id="chatMessages"></div>
                <div class="input-container">
                    <div class="input-wrapper">
                        <input type="text" id="messageInput" placeholder="Type your message...">
                        <div class="emoji-picker">
                            <i class="far fa-smile"></i>
                        </div>
                    </div>
                    <button id="sendMessage">
                        <i class="fas fa-paper-plane"></i>
                        Send
                    </button>
                </div>
            </div>
        </div>
    </main>

    <div class="settings-panel" id="settingsPanel">
        <h2>Settings</h2>
        <div style="margin-top: 1rem;">
            <h3>Video Quality</h3>
            <select id="videoQuality" style="margin-top: 0.5rem;">
                <option value="720p">HD (720p)</option>
                <option value="1080p">Full HD (1080p)</option>
                <option value="480p">SD (480p)</option>
            </select>
        </div>
        <button style="margin-top: 1rem;" id="closeSettings">Close</button>
    </div>

    <footer>
        <div class="developer-info">
            <p>Developed by Albert</p>
            <p>Contact: <a href="mailto:queenaicpu@gmail.com">queenaicpu@gmail.com</a></p>
            <p>© 2025 Desert Panther AI. All rights reserved.</p>
        </div>
    </footer>

    <script>
        const API_KEY = 'AIzaSyB4zYyXQGT4DHqAdJrjPZoIxys9nn-IGzg';
        const API_ENDPOINT = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent';

        let localStream;
        let peerConnection;
        let isAudioEnabled = true;
        let isVideoEnabled = true;

        // Show loading overlay initially
        const loadingOverlay = document.getElementById('loadingOverlay');
        
        function showLoading() {
            loadingOverlay.style.display = 'flex';
        }

        function hideLoading() {
            loadingOverlay.style.display = 'none';
        }

        function showNotification(message, isError = false) {
            const notification = document.createElement('div');
            notification.className = `notification ${isError ? 'error' : ''}`;
            notification.textContent = message;
            document.body.appendChild(notification);

            setTimeout(() => {
                notification.remove();
            }, 3000);
        }

        async function initWebRTC() {
            try {
                showLoading();
                const constraints = {
                    video: {
                        width: { ideal: 1920 },
                        height: { ideal: 1080 }
                    },
                    audio: true
                };

                localStream = await navigator.mediaDevices.getUserMedia(constraints);
                document.getElementById('localVideo').srcObject = localStream;
                showNotification('Stream started successfully');
            } catch (error) {
                console.error('Error accessing media devices:', error);
                showNotification('Failed to access camera and microphone', true);
            } finally {
                hideLoading();
            }
        }

        async function sendMessageToAI(message) {
            try {
                showAIThinking();
                const response = await fetch(`${API_ENDPOINT}?key=${API_KEY}`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        contents: [{
                            parts: [{
                                text: message
                            }]
                        }]
                    })
                });

                if (!response.ok) {
                    throw new Error('AI response error');
                }

                const data = await response.json();
                hideAIThinking();
                return data.candidates[0].content.parts[0].text;
            } catch (error) {
                console.error('Error communicating with AI:', error);
                hideAIThinking();
                showNotification('Error communicating with AI', true);
                return 'Sorry, I encountered an error processing your message.';
            }
        }

        function showAIThinking() {
            const thinkingIndicator = document.createElement('div');
            thinkingIndicator.className = 'ai-thinking';
            thinkingIndicator.innerHTML = `
                AI is thinking
                <div class="typing-indicator">
                    <div class="typing-dot"></div>
                    <div class="typing-dot"></div>
                    <div class="typing-dot"></div>
                </div>
            `;
            document.getElementById('chatMessages').appendChild(thinkingIndicator);
        }

        function hideAIThinking() {
            const thinkingIndicator = document.querySelector('.ai-thinking');
            if (thinkingIndicator) {
                thinkingIndicator.remove();
            }
        }

        function addMessage(message, isUser = false) {
            const messagesContainer = document.getElementById('chatMessages');
            const messageElement = document.createElement('div');
            messageElement.classList.add('message', isUser ? 'user-message' : 'ai-message');
            messageElement.innerHTML = `
                ${message}
                <div class="message-meta">
                    ${isUser ? 'You' : 'AI'} • ${new Date().toLocaleTimeString()}
                </div>
            `;
            messagesContainer.appendChild(messageElement);
            messagesContainer.scrollTop = messagesContainer.scrollHeight;
        }

        // Event Listeners
        document.getElementById('startStream').addEventListener('click', initWebRTC);

        document.getElementById('toggleAudio').addEventListener('click', () => {
            if (localStream) {
                const audioTrack = localStream.getAudioTracks()[0];
                audioTrack.enabled = !audioTrack.enabled;
                isAudioEnabled = audioTrack.enabled;
                document.querySelector('#toggleAudio i').className = 
                    isAudioEnabled ? 'fas fa-microphone' : 'fas fa-microphone-slash';
                showNotification(`Microphone ${isAudioEnabled ? 'enabled' : 'disabled'}`);
            }
        });

        document.getElementById('toggleVideo').addEventListener('click', () => {
            if (localStream) {
                const videoTrack = localStream.getVideoTracks()[0];
                videoTrack.enabled = !videoTrack.enabled;
                isVideoEnabled = videoTrack.enabled;
                document.querySelector('#toggleVideo i').className = 
                    isVideoEnabled ? 'fas fa-video' : 'fas fa-video-slash';
                showNotification(`Camera ${isVideoEnabled ? 'enabled' : 'disabled'}`);
            }
        });

        document.getElementById('sendMessage').addEventListener('click', async () => {
            const input = document.getElementById('messageInput');
            const message = input.value.trim();
            
            if (message) {
                addMessage(message, true);
                input.value = '';

                const response = await sendMessageToAI(message);
                addMessage(response, false);
            }
        });

        document.getElementById('messageInput').addEventListener('keypress', (e) => {
            if (e.key === 'Enter') {
                document.getElementById('sendMessage').click();
            }
        });

        // Mobile Menu
        document.getElementById('menuButton').addEventListener('click', () => {
            document.getElementById('mobileMenu').classList.add('active');
        });

        document.getElementById('closeMenu').addEventListener('click', () => {
            document.getElementById('mobileMenu').classList.remove('active');
        });

        // Settings Panel
        document.getElementById('settings').addEventListener('click', () => {
            document.getElementById('settingsPanel').classList.add('active');
        });

        document.getElementById('closeSettings').addEventListener('click', () => {
            document.getElementById('settingsPanel').classList.remove('active');
        });

        // Clear Chat
        document.getElementById('clearChat').addEventListener('click', () => {
            document.getElementById('chatMessages').innerHTML = '';
            showNotification('Chat cleared');
        });

        // Initialize
        window.addEventListener('load', () => {
            hideLoading();
        });

        // Handle page visibility change
        document.addEventListener('visibilitychange', () => {
            if (document.hidden) {
                // Page is hidden
                if (localStream) {
                    localStream.getTracks().forEach(track => track.stop());
                }
            } else {
                // Page is visible again
                if (!localStream) {
                    initWebRTC();
                }
            }
        });
    </script>
<head>
    <!-- Prevent page indexing by search engines -->
    <meta name="robots" content="noindex, nofollow">
    <meta name="googlebot" content="noindex, nofollow">
</head>
<body>
    <!-- Your page content goes here -->
</body>
</html>