<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Data Life Eyes Pro - 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">Data Life Eyes Pro</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 Video Chat</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', system-ui, sans-serif;
        }

        :root {
            --primary-gradient: linear-gradient(135deg, #00c6ff, #0072ff);
            --secondary-gradient: linear-gradient(135deg, #f6d365, #fda085);
            --danger-gradient: linear-gradient(135deg, #ff416c, #ff4b2b);
            --success-gradient: linear-gradient(135deg, #00b09b, #96c93d);
            --dark-bg: #0a0a0a;
            --card-bg: rgba(255,255,255,0.05);
        }

        body {
            background: var(--dark-bg);
            color: #fff;
            min-height: 100vh;
            overflow-x: hidden;
        }

        .loading-screen {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: var(--dark-bg);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 9999;
            transition: opacity 0.5s;
        }

        .loader {
            width: 50px;
            height: 50px;
            border: 5px solid #fff;
            border-top: 5px solid transparent;
            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 Styles */
        header {
            background: var(--primary-gradient);
            padding: 1rem;
            box-shadow: 0 2px 15px rgba(0,0,0,0.4);
            position: relative;
            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, #e0e0e0);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .logo i {
            background: white;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        /* Sidebar Menu */
        .sidebar {
            position: fixed;
            top: 0;
            right: -300px;
            width: 300px;
            height: 100vh;
            background: rgba(0,0,0,0.95);
            transition: 0.3s ease;
            z-index: 1000;
            padding: 2rem;
            backdrop-filter: blur(10px);
        }

        .sidebar.active {
            right: 0;
        }

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

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

        .menu-items {
            list-style: none;
        }

        .menu-items li {
            margin: 1rem 0;
        }

        .menu-items a {
            color: white;
            text-decoration: none;
            font-size: 1.1rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            transition: 0.3s;
        }

        .menu-items a:hover {
            color: #00c6ff;
            transform: translateX(10px);
        }

        /* Main Content */
        .video-grid {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 1.5rem;
            margin: 2rem 0;
        }

        .video-container {
            background: var(--card-bg);
            border-radius: 15px;
            overflow: hidden;
            position: relative;
        }

        .main-video {
            width: 100%;
            aspect-ratio: 16/9;
            background: var(--card-bg);
            border-radius: 15px;
            overflow: hidden;
            position: relative;
        }

        .pip-video {
            position: absolute;
            width: 200px;
            height: 150px;
            bottom: 20px;
            right: 20px;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 4px 15px rgba(0,0,0,0.3);
            border: 2px solid rgba(255,255,255,0.1);
        }

        #localVideo, #remoteVideo {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        /* Chat Section */
        .chat-section {
            background: var(--card-bg);
            border-radius: 15px;
            display: flex;
            flex-direction: column;
            height: 100%;
        }

        .chat-header {
            padding: 1rem;
            border-bottom: 1px solid rgba(255,255,255,0.1);
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .chat-messages {
            flex: 1;
            overflow-y: auto;
            padding: 1rem;
        }

        .message {
            margin: 0.5rem 0;
            padding: 0.8rem;
            border-radius: 10px;
            max-width: 80%;
        }

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

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

        .chat-input {
            padding: 1rem;
            border-top: 1px solid rgba(255,255,255,0.1);
            display: flex;
            gap: 0.5rem;
        }

        .chat-input input {
            flex: 1;
            padding: 0.8rem;
            border-radius: 25px;
            border: none;
            background: rgba(255,255,255,0.1);
            color: white;
            outline: none;
        }

        .send-btn {
            background: var(--primary-gradient);
            border: none;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            color: white;
            cursor: pointer;
            transition: 0.3s;
        }

        .send-btn:hover {
            transform: scale(1.1);
        }

        /* Controls */
        .controls {
            display: flex;
            justify-content: center;
            gap: 1rem;
            padding: 1.5rem;
            background: rgba(255,255,255,0.05);
            border-radius: 50px;
            margin: 1rem auto;
            max-width: 500px;
            backdrop-filter: blur(10px);
        }

        .control-btn {
            background: var(--secondary-gradient);
            border: none;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.2rem;
        }

        .control-btn:hover {
            transform: scale(1.1);
            box-shadow: 0 0 15px rgba(0,198,255,0.5);
        }

        .control-btn.active {
            background: var(--danger-gradient);
        }

        /* Status Indicators */
        .status-indicators {
            display: flex;
            gap: 1rem;
            margin: 1rem 0;
            padding: 0.5rem;
            background: rgba(255,255,255,0.05);
            border-radius: 25px;
            justify-content: center;
        }

        .indicator {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-size: 0.9rem;
        }

        .indicator-dot {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: #666;
        }

        .indicator-dot.active {
            background: #00ff00;
            box-shadow: 0 0 10px rgba(0,255,0,0.5);
        }

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

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

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

        .developer-info a:hover {
            text-shadow: 0 0 10px rgba(255,255,255,0.5);
        }

        /* Animations */
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

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

        .fade-in {
            animation: fadeIn 0.5s ease forwards;
        }

        .slide-in {
            animation: slideIn 0.5s ease forwards;
        }

        /* Notifications */
        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 1rem;
            border-radius: 10px;
            background: var(--success-gradient);
            color: white;
            z-index: 1000;
            animation: slideIn 0.5s ease forwards;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
        }

        /* Responsive Design */
        @media (max-width: 1024px) {
            .video-grid {
                grid-template-columns: 1fr;
            }
            
            .pip-video {
                width: 150px;
                height: 100px;
            }
        }

        @media (max-width: 768px) {
            .controls {
                flex-wrap: wrap;
                gap: 0.5rem;
            }

            .control-btn {
                width: 45px;
                height: 45px;
                font-size: 1rem;
            }

            .status-indicators {
                flex-direction: column;
                align-items: center;
            }
        }
    </style>
</head>
<body>
    <div class="loading-screen">
        <div class="loader"></div>
    </div>

    <header>
        <nav class="nav container">
            <div class="logo">
                <i class="fas fa-paw"></i>
                Desert Panther AI
            </div>
            <button id="menuBtn" class="control-btn">
                <i class="fas fa-bars"></i>
            </button>
        </nav>
    </header>

    <div class="sidebar">
        <div class="sidebar-header">
            <h2>Menu</h2>
            <button class="close-btn">×</button>
        </div>
        <ul class="menu-items">
            <li><a href="#"><i class="fas fa-home"></i> Home</a></li>
            <li><a href="#"><i class="fas fa-cog"></i> Settings</a></li>
            <li><a href="#"><i class="fas fa-user"></i> Profile</a></li>
            <li><a href="#"><i class="fas fa-info-circle"></i> About</a></li>
            <li><a href="#"><i class="fas fa-question-circle"></i> Help</a></li>
        </ul>
    </div>

    <main class="container">
        <div class="status-indicators">
            <div class="indicator">
                <div class="indicator-dot" id="connectionStatus"></div>
                <span>Connection</span>
            </div>
            <div class="indicator">
                <div class="indicator-dot" id="audioStatus"></div>
                <span>Audio</span>
            </div>
            <div class="indicator">
                <div class="indicator-dot" id="videoStatus"></div>
                <span>Video</span>
            </div>
        </div>

        <div class="video-grid">
            <div class="video-container">
                <div class="main-video">
                    <video id="remoteVideo" autoplay playsinline></video>
                </div>
                <div class="pip-video">
                    <video id="localVideo" autoplay playsinline muted></video>
                </div>
            </div>

            <div class="chat-section">
                <div class="chat-header">
                    <i class="fas fa-robot"></i>
                    <span>AI Assistant</span>
                </div>
                <div class="chat-messages" id="chatMessages">
                    <!-- Messages will be added here dynamically -->
                </div>
                <div class="chat-input">
                    <input type="text" id="messageInput" placeholder="Type your message...">
                    <button class="send-btn">
                        <i class="fas fa-paper-plane"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="controls">
            <button class="control-btn" id="muteBtn" title="Mute/Unmute">
                <i class="fas fa-microphone"></i>
            </button>
            <button class="control-btn" id="videoBtn" title="Video On/Off">
                <i class="fas fa-video"></i>
            </button>
            <button class="control-btn" id="screenShareBtn" title="Share Screen">
                <i class="fas fa-desktop"></i>
            </button>
            <button class="control-btn" id="recordBtn" title="Record">
                <i class="fas fa-record-vinyl"></i>
            </button>
            <button class="control-btn" id="callBtn" title="Start/End Call">
                <i class="fas fa-phone"></i>
            </button>
        </div>
    </main>

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

    <script>
        // Configuration
        const configuration = {
            iceServers: [
                { urls: 'stun:stun.l.google.com:19302' },
                { urls: 'stun:stun1.l.google.com:19302' },
                { urls: 'stun:stun2.l.google.com:19302' },
                { urls: 'stun:stun3.l.google.com:19302' },
                { urls: 'stun:stun4.l.google.com:19302' }
            ]
        };

        // Global variables
        let peerConnection;
        let localStream;
        let remoteStream;
        let isCallStarted = false;
        let screenStream;
        let mediaRecorder;
        let recordedChunks = [];

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

        // DOM Elements
        const localVideo = document.getElementById('localVideo');
        const remoteVideo = document.getElementById('remoteVideo');
        const muteBtn = document.getElementById('muteBtn');
        const videoBtn = document.getElementById('videoBtn');
        const screenShareBtn = document.getElementById('screenShareBtn');
        const recordBtn = document.getElementById('recordBtn');
        const callBtn = document.getElementById('callBtn');
        const menuBtn = document.getElementById('menuBtn');
        const sidebar = document.querySelector('.sidebar');
        const closeBtn = document.querySelector('.close-btn');
        const messageInput = document.getElementById('messageInput');
        const chatMessages = document.getElementById('chatMessages');
        const loadingScreen = document.querySelector('.loading-screen');

        // Status indicators
        const connectionStatus = document.getElementById('connectionStatus');
        const audioStatus = document.getElementById('audioStatus');
        const videoStatus = document.getElementById('videoStatus');

        // Initialize
        async function initialize() {
            try {
                await initStream();
                setupEventListeners();
                setupChat();
                hideLoadingScreen();
            } catch (error) {
                showNotification('Error initializing application', 'error');
                console.error('Initialization error:', error);
            }
        }

        // Initialize media stream
        async function initStream() {
            try {
                localStream = await navigator.mediaDevices.getUserMedia({
                    video: true,
                    audio: true
                });
                localVideo.srcObject = localStream;
                updateStatusIndicators();
            } catch (err) {
                showNotification('Error accessing media devices', 'error');
                console.error('Media device error:', err);
            }
        }

        // WebRTC functions
        async function startCall() {
            if (isCallStarted) return;
            
            try {
                peerConnection = new RTCPeerConnection(configuration);
                
                // Add local stream tracks
                localStream.getTracks().forEach(track => {
                    peerConnection.addTrack(track, localStream);
                });

                // Handle incoming stream
                peerConnection.ontrack = event => {
                    remoteVideo.srcObject = event.streams[0];
                    remoteStream = event.streams[0];
                };

                // ICE candidate handling
                peerConnection.onicecandidate = event => {
                    if (event.candidate) {
                        // Send candidate to signaling server
                        console.log('New ICE candidate:', event.candidate);
                    }
                };

                // Connection state changes
                peerConnection.onconnectionstatechange = () => {
                    updateConnectionStatus(peerConnection.connectionState);
                };

                isCallStarted = true;
                updateUI();
                
                // Connect to AI service
                await connectToAI();
                
            } catch (error) {
                showNotification('Error starting call', 'error');
                console.error('Call error:', error);
            }
        }

        // AI Connection
        async function connectToAI() {
            try {
                const response = await fetch(API_ENDPOINT, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': `Bearer ${API_KEY}`
                    },
                    body: JSON.stringify({
                        contents: [{
                            parts: [{
                                text: "Initialize video chat session"
                            }]
                        }]
                    })
                });

                if (!response.ok) throw new Error('AI connection failed');
                
                showNotification('Connected to AI service', 'success');
            } catch (error) {
                showNotification('Error connecting to AI service', 'error');
                console.error('AI connection error:', error);
            }
        }

        // UI Updates
        function updateUI() {
            callBtn.classList.toggle('active', isCallStarted);
            callBtn.innerHTML = isCallStarted ? 
                '<i class="fas fa-phone-slash"></i>' : 
                '<i class="fas fa-phone"></i>';
        }

        function updateStatusIndicators() {
            audioStatus.classList.toggle('active', 
                localStream.getAudioTracks()[0].enabled);
            videoStatus.classList.toggle('active', 
                localStream.getVideoTracks()[0].enabled);
        }

        function updateConnectionStatus(state) {
            connectionStatus.classList.toggle('active', 
                state === 'connected' || state === 'completed');
        }

        // Screen Sharing
        async function toggleScreenShare() {
            try {
                if (!screenStream) {
                    screenStream = await navigator.mediaDevices.getDisplayMedia({
                        video: true
                    });
                    const videoTrack = screenStream.getVideoTracks()[0];
                    const sender = peerConnection.getSenders().find(s => 
                        s.track.kind === 'video');
                    await sender.replaceTrack(videoTrack);
                    screenShareBtn.classList.add('active');
                    
                    videoTrack.onended = () => {
                        stopScreenShare();
                    };
                } else {
                    stopScreenShare();
                }
            } catch (error) {
                showNotification('Error sharing screen', 'error');
                console.error('Screen share error:', error);
            }
        }

        function stopScreenShare() {
            if (screenStream) {
                screenStream.getTracks().forEach(track => track.stop());
                const videoTrack = localStream.getVideoTracks()[0];
                const sender = peerConnection.getSenders().find(s => 
                    s.track.kind === 'video');
                sender.replaceTrack(videoTrack);
                screenStream = null;
                screenShareBtn.classList.remove('active');
            }
        }

        // Recording
        function toggleRecording() {
            if (!mediaRecorder || mediaRecorder.state === 'inactive') {
                startRecording();
            } else {
                stopRecording();
            }
        }

        function startRecording() {
            recordedChunks = [];
            const stream = new MediaStream([
                ...localStream.getTracks(),
                ...remoteStream.getTracks()
            ]);
            
            mediaRecorder = new MediaRecorder(stream);
            
            mediaRecorder.ondataavailable = event => {
                if (event.data.size > 0) {
                    recordedChunks.push(event.data);
                }
            };

            mediaRecorder.onstop = () => {
                const blob = new Blob(recordedChunks, {
                    type: 'video/webm'
                });
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = 'recording.webm';
                a.click();
            };

            mediaRecorder.start();
            recordBtn.classList.add('active');
        }

        function stopRecording() {
            mediaRecorder.stop();
            recordBtn.classList.remove('active');
        }

        // Chat Functions
        function setupChat() {
            const sendBtn = document.querySelector('.send-btn');
            
            messageInput.addEventListener('keypress', e => {
                if (e.key === 'Enter') sendMessage();
            });
            
            sendBtn.addEventListener('click', sendMessage);
        }

        async function sendMessage() {
            const message = messageInput.value.trim();
            if (!message) return;

            addMessageToChat(message, 'user');
            messageInput.value = '';

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

                const data = await response.json();
                addMessageToChat(data.response, 'ai');
            } catch (error) {
                showNotification('Error sending message', 'error');
                console.error('Chat error:', error);
            }
        }

        function addMessageToChat(message, type) {
            const messageElement = document.createElement('div');
            messageElement.classList.add('message', `${type}-message`);
            messageElement.textContent = message;
            chatMessages.appendChild(messageElement);
            chatMessages.scrollTop = chatMessages.scrollHeight;
        }

        // Utility Functions
        function showNotification(message, type = 'success') {
            const notification = document.createElement('div');
            notification.className = `notification ${type}`;
            notification.textContent = message;
            document.body.appendChild(notification);
            
            setTimeout(() => {
                notification.remove();
            }, 3000);
        }

        function hideLoadingScreen() {
            loadingScreen.style.opacity = '0';
            setTimeout(() => {
                loadingScreen.style.display = 'none';
            }, 500);
        }

        // Event Listeners
        function setupEventListeners() {
            muteBtn.addEventListener('click', () => {
                const audioTrack = localStream.getAudioTracks()[0];
                audioTrack.enabled = !audioTrack.enabled;
                muteBtn.innerHTML = audioTrack.enabled ? 
                    '<i class="fas fa-microphone"></i>' : 
                    '<i class="fas fa-microphone-slash"></i>';
                muteBtn.classList.toggle('active');
                updateStatusIndicators();
            });

            videoBtn.addEventListener('click', () => {
                const videoTrack = localStream.getVideoTracks()[0];
                videoTrack.enabled = !videoTrack.enabled;
                videoBtn.innerHTML = videoTrack.enabled ? 
                    '<i class="fas fa-video"></i>' : 
                    '<i class="fas fa-video-slash"></i>';
                videoBtn.classList.toggle('active');
                updateStatusIndicators();
            });

            screenShareBtn.addEventListener('click', toggleScreenShare);
            recordBtn.addEventListener('click', toggleRecording);
            callBtn.addEventListener('click', startCall);

            menuBtn.addEventListener('click', () => {
                sidebar.classList.add('active');
            });

            closeBtn.addEventListener('click', () => {
                sidebar.classList.remove('active');
            });

            // Close sidebar when clicking outside
            document.addEventListener('click', e => {
                if (!sidebar.contains(e.target) && 
                    !menuBtn.contains(e.target)) {
                    sidebar.classList.remove('active');
                }
            });
        }

        // Error Handling
        window.onerror = function(msg, url, lineNo, columnNo, error) {
            showNotification(`Error: ${msg}`, 'error');
            console.error('Global error:', {msg, url, lineNo, columnNo, error});
            return false;
        };

        // Initialize on page load
        window.addEventListener('load', initialize);
    </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>