// 平滑滚动功能
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        
        const targetId = this.getAttribute('href');
        const targetElement = document.querySelector(targetId);
        
        if (targetElement) {
            window.scrollTo({
                top: targetElement.offsetTop - 70,
                behavior: 'smooth'
            });
        }
    });
});

// 中英文切换功能
document.addEventListener('DOMContentLoaded', function() {
    const langToggle = document.getElementById('language-toggle');
    if (langToggle) {
        // 定义中英文内容映射
        const translations = {
            'zh': {
                'members': '团队成员',
                'history': '团队历史',
                'achievements': '团队成就',
                'contact': '联系方式',
                'works': '旗下作品'
            },
            'en': {
                'members': 'Team Members',
                'history': 'Team History',
                'achievements': 'Team Achievements',
                'contact': 'Contact',
                'works': 'Works'
            }
        };
        
        // 当前语言状态
        let currentLang = 'zh';
        
        langToggle.addEventListener('click', function() {
            // 切换语言
            currentLang = currentLang === 'zh' ? 'en' : 'zh';
            
            // 更新按钮文本
            this.textContent = currentLang === 'zh' ? 'EN' : '中文';
            
            // 更新页面内容
            updatePageContent(currentLang, translations);
        });
    }
});

// 更新页面内容函数
function updatePageContent(lang, translations) {
    // 更新导航链接
    const navLinks = document.querySelectorAll('nav a');
    const navKeys = ['members', 'history', 'achievements', 'contact', 'works'];
    
    navLinks.forEach((link, index) => {
        if (navKeys[index]) {
            link.textContent = translations[lang][navKeys[index]];
        }
    });
    
    // 更新区块标题
    const sectionTitles = document.querySelectorAll('section h2');
    const sectionKeys = ['members', 'history', 'achievements', 'contact', 'works'];
    
    sectionTitles.forEach((title, index) => {
        if (sectionKeys[index]) {
            title.textContent = translations[lang][sectionKeys[index]];
        }
    });
    
    // 更新其他固定内容
    const heroSubtitle = document.querySelector('#hero p');
    if (heroSubtitle) {
        heroSubtitle.textContent = lang === 'zh' ? '专业、创新、极致体验' : 'Professional, Innovative, Ultimate Experience';
    }
    
    // 更新页脚
    const footer = document.querySelector('footer p');
    if (footer) {
        footer.textContent = lang === 'zh' ? '© 2023 团队名称. 保留所有权利.' : '© 2023 Team Name. All rights reserved.';
    }
}

// 添加终端效果到英雄区域
document.addEventListener('DOMContentLoaded', function() {
    const hero = document.getElementById('hero');
    
    // 添加加入我们按钮点击事件
    const joinBtn = document.getElementById('join-team-btn');
    if (joinBtn) {
        joinBtn.addEventListener('click', function() {
            window.location.href = 'join-us.html';
        });
    }
    
    // 创建终端光标效果
    const cursor = document.createElement('span');
    cursor.innerHTML = '_';
    cursor.style.animation = 'blink 1s infinite';
    cursor.style.color = 'var(--glow-color)';
    
    // 添加CSS动画
    const style = document.createElement('style');
    style.textContent = `
        @keyframes blink {
            0%, 100% { opacity: 1; }
            50% { opacity: 0; }
        }
    `;
    document.head.appendChild(style);
    
    // 将光标添加到英雄标题后面
    const heroTitle = hero.querySelector('h1');
    if (heroTitle) {
        heroTitle.appendChild(cursor);
    }
    
    // 添加黑客风格的背景动画
    const matrixEffect = document.createElement('div');
    matrixEffect.className = 'matrix-effect';
    matrixEffect.style.cssText = `
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        pointer-events: none;
        z-index: -1;
        opacity: 0.1;
    `;
    
    document.body.appendChild(matrixEffect);
    
    // 创建矩阵雨效果
    createMatrixRain(matrixEffect);
});

// 矩阵雨效果函数
function createMatrixRain(container) {
    const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()_+-=[]{}|;:,.<>?/~`';
    const fontSize = 14;
    const columns = Math.floor(container.offsetWidth / fontSize);
    
    // 创建列数组
    const drops = [];
    for (let i = 0; i < columns; i++) {
        drops[i] = 1;
    }
    
    // 创建画布
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');
    canvas.width = container.offsetWidth;
    canvas.height = container.offsetHeight;
    container.appendChild(canvas);
    
    // 绘制函数
    function draw() {
        // 半透明黑色覆盖层营造拖尾效果
        ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        
        ctx.fillStyle = '#0f0';
        ctx.font = `${fontSize}px monospace`;
        
        // 绘制字符
        for (let i = 0; i < drops.length; i++) {
            const text = chars[Math.floor(Math.random() * chars.length)];
            ctx.fillText(text, i * fontSize, drops[i] * fontSize);
            
            // 重置滴落位置
            if (drops[i] * fontSize > canvas.height && Math.random() > 0.975) {
                drops[i] = 0;
            }
            
            drops[i]++;
        }
    }
    
    // 动画循环
    setInterval(draw, 33);
}