<?php
require_once __DIR__ . '/../db/config.php';
session_start();

$user = null;
if (isset($_SESSION['user_id'])) {
    $stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
    $stmt->execute([$_SESSION['user_id']]);
    $user = $stmt->fetch();
}

$lang = $_GET['lang'] ?? $_SESSION['lang'] ?? 'en';
if (!in_array($lang, ['en', 'zh'])) {
    $lang = 'en';
}
$_SESSION['lang'] = $lang;

function mt($key) {
    global $lang;
    $translations = [
        'en' => [
            'Home' => 'Home', 'Spot' => 'Spot', 'Perpetual' => 'Perpetual', 'Markets' => 'Markets', 'Exchange' => 'Exchange',
            'Login' => 'Login', 'Register' => 'Register', 'Profile' => 'Profile', 'Logout' => 'Logout',
            'Deposit' => 'Deposit', 'Withdraw' => 'Withdraw', 'Assets' => 'Assets', 'Security' => 'Security',
            'Buy' => 'Buy', 'Sell' => 'Sell', 'Limit' => 'Limit', 'Market' => 'Market', 'Price' => 'Price',
            'Amount' => 'Amount', 'Total' => 'Total', 'Available' => 'Available', 'Trade' => 'Trade',
            'Market Trends' => 'Market Trends', 'Real-time Prices' => 'Real-time Prices', 'High' => 'High', 'Low' => 'Low',
            'Download App' => 'Download App', 'Customer Service' => 'Customer Service',
            'Identity Verification' => 'Identity Verification', 'Trading Password' => 'Trading Password',
            'Success' => 'Success', 'Error' => 'Error', 'Matching Account' => 'Matching Account',
            'Establishing secure connection with liquidity provider...' => 'Establishing secure connection with liquidity provider...',
            'Awaiting merchant confirmation...' => 'Awaiting merchant confirmation...',
            'Matching in progress' => 'Matching in progress',
            'The specialized account for this transaction will be provided by our agent shortly.' => 'The specialized account for this transaction will be provided by our agent shortly.',
            'Transfer the exact amount. Upload proof below.' => 'Transfer the exact amount. Upload proof below.',
            'Bank Name' => 'Bank Name', 'Account Number' => 'Account Number', 'Beneficiary' => 'Beneficiary', 'Reference' => 'Reference',
            'Copy' => 'Copy', 'Upload Proof' => 'Upload Proof', 'Selected' => 'Selected', 'Transfer Completed' => 'Transfer Completed',
            'Your transfer is being reviewed. ETA: 10-20 mins.' => 'Your transfer is being reviewed. ETA: 10-20 mins.',
            'Back to Wallet' => 'Back to Wallet', 'Matched & Active' => 'Matched & Active',
            'Services' => 'Services', 'Spot Trading' => 'Spot Trading', 'Futures Trading' => 'Futures Trading',
            'Support' => 'Support', 'Help Center' => 'Help Center', 'About Us' => 'About Us', 'Privacy Policy' => 'Privacy Policy', 'Terms of Service' => 'Terms of Service',
            'System Status' => 'System Status', 'Normal' => 'Normal', 'Overview' => 'Overview', 'Full Name' => 'Full Name', 'ID Number' => 'ID Number', 'Submit' => 'Submit', 'Next-Gen Trading Engine' => 'Next-Gen Trading Engine',
            'Experience ultra-low latency and institutional-grade liquidity on our professional K-line trading platform.' => 'Experience ultra-low latency and institutional-grade liquidity on our professional K-line trading platform.',
            'Register Now' => 'Register Now', 'Start Trading' => 'Start Trading', 'Go to Futures' => 'Go to Futures', 'Global Crypto Hub' => 'Global Crypto Hub',
            'Access real-time global market data and execute trades across multiple asset classes with one unified account.' => 'Access real-time global market data and execute trades across multiple asset classes with one unified account.',
            'Secure Asset Custody' => 'Secure Asset Custody', 'Your funds are safe with our institutional-grade security, multi-sig cold storage, and comprehensive insurance fund.' => 'Your funds are safe with our institutional-grade security, multi-sig cold storage, and comprehensive insurance fund.',
            'Security Center' => 'Security Center', '24/7 Global Support' => '24/7 Global Support', 'Our dedicated professional support team is available around the clock to assist you in multiple languages.' => 'Our dedicated professional support team is available around the clock to assist you in multiple languages.',
            'Contact Support' => 'Contact Support', 'Asset' => 'Asset', '24h Change' => '24h Change', '24h High' => '24h High', 'Action' => 'Action', 'All Markets' => 'All Markets',
            'Real-time updates from global exchanges' => 'Real-time updates from global exchanges', 'Safe & Secure' => 'Safe & Secure', 'Industry-leading encryption and multi-signature cold storage for your digital assets.' => 'Industry-leading encryption and multi-signature cold storage for your digital assets.',
            'Instant Execution' => 'Instant Execution', 'Advanced matching engine processing over 100,000 transactions per second.' => 'Advanced matching engine processing over 100,000 transactions per second.',
            'Get help whenever you need it with our around-the-clock professional customer service.' => 'Get help whenever you need it with our around-the-clock professional customer service.',
            'Trade Anywhere, Anytime' => 'Trade Anywhere, Anytime', 'Experience the full power of our exchange on your mobile device. Trade spot and futures with ease.' => 'Experience the full power of our exchange on your mobile device. Trade spot and futures with ease.',
            'Scan to download' => 'Scan to download', 'Compatible with iOS and Android devices.' => 'Compatible with iOS and Android devices.',
            'Account Overview' => 'Account Overview', 'Total Balance' => 'Total Balance', 'Security Settings' => 'Security Settings', 'Login Password' => 'Login Password',
            'Change' => 'Change', 'Verified' => 'Verified', 'Reviewing...' => 'Reviewing...', 'none' => 'Unverified', 'pending' => 'Pending', 'approved' => 'Verified',
            'Trade with up to 100x leverage on BTC, ETH, and other major crypto pairs with professional risk management tools.' => 'Trade with up to 100x leverage on BTC, ETH, and other major crypto pairs with professional risk management tools.',
            'Perpetual Contracts' => 'Perpetual Contracts', 'Identity verification submitted and is under review.' => 'Identity verification submitted and is under review.',
            'New passwords do not match.' => 'New passwords do not match.', 'Password must be at least 6 characters.' => 'Password must be at least 6 characters.', 'Password updated successfully.' => 'Password updated successfully.', 'Current password incorrect.' => 'Current password incorrect.',
            'Hello! Welcome to BITCrypto. How can we help you today?' => 'Hello! Welcome to BITCrypto. How can we help you today?',
            'Type a message...' => 'Type a message...', 'Thank you for your message. An agent will be with you shortly.' => 'Thank you for your message. An agent will be with you shortly.',
            'For security reasons, never share your login or trading passwords with anyone, including our support agents.' => 'For security reasons, never share your login or trading passwords with anyone, including our support agents.',
            'Why Choose BITCrypto?' => 'Why Choose BITCrypto?', 'Global Liquidity' => 'Global Liquidity', 'Deep order books and high liquidity across all trading pairs for minimal slippage.' => 'Deep order books and high liquidity across all trading pairs for minimal slippage.',
            'Advanced Trading' => 'Advanced Trading', 'Professional charting tools, multi-order types, and real-time execution.' => 'Professional charting tools, multi-order types, and real-time execution.',
            'Trusted by Millions' => 'Trusted by Millions', 'Join a global community of traders and investors on one of the most secure platforms.' => 'Join a global community of traders and investors on one of the most secure platforms.',
            'Our Partners' => 'Our Partners', 'Global Trust' => 'Global Trust', 'Assets Overview' => 'Assets Overview', 'BITCrypto provides a comprehensive ecosystem for crypto enthusiasts, from beginners to professional institutional traders.' => 'BITCrypto provides a comprehensive ecosystem for crypto enthusiasts, from beginners to professional institutional traders.',
            'Our Global Partners' => 'Our Global Partners', 'Primary Network' => 'Primary Network', 'Smart Contracts' => 'Smart Contracts', 'Security Audit' => 'Security Audit', 'Financial Partner' => 'Financial Partner', 'Strategic Advisor' => 'Strategic Advisor',
            'Unverified' => 'Unverified', 'Verification' => 'Verification', 'digits' => 'digits', 'Search Pairs' => 'Search Pairs', 'No open orders' => 'No open orders', 'Time' => 'Time', 'Pair' => 'Pair', 'Type' => 'Type', 'Side' => 'Side', 'Filled' => 'Filled', 'Open Orders' => 'Open Orders', 'Order History' => 'Order History', 'Positions' => 'Positions',
            'Total Net Value' => 'Total Net Value', 'Yesterday Profit/Loss' => 'Yesterday Profit/Loss', 'Link' => 'Link', 'Recent Activities' => 'Recent Activities', 'Account Login' => 'Account Login', 'Update failed' => 'Update failed', 'Confirm New Trading Password' => 'Confirm New Trading Password', 'New Trading Password' => 'New Trading Password',
            'The World\'s Leading' => 'The World\'s Leading', 'Crypto Exchange' => 'Crypto Exchange', 'Trade Bitcoin, Ethereum, and hundreds of other cryptocurrencies with the lowest fees in the industry.' => 'Trade Bitcoin, Ethereum, and hundreds of other cryptocurrencies with the lowest fees in the industry.',
            'Get Started' => 'Get Started', 'View Markets' => 'View Markets', 'Users' => 'Users', '24h Volume' => '24h Volume', 'Countries' => 'Countries',
            'Stay updated with real-time price changes' => 'Stay updated with real-time price changes', 'View All' => 'View All', 'Name' => 'Name',
            'Experience the most professional trading environment' => 'Experience the most professional trading environment',
            'Multi-sig Cold Storage' => 'Multi-sig Cold Storage', 'DDoS Protection' => 'DDoS Protection', '2FA Security' => '2FA Security',
            'Ultra-low Latency' => 'Ultra-low Latency', 'High Liquidity' => 'High Liquidity', 'Zero Slippage' => 'Zero Slippage',
            'Multi-language Support' => 'Multi-language Support', 'Live Chat' => 'Live Chat', 'Fast Response' => 'Fast Response',
            'Trusted by industry leaders worldwide' => 'Trusted by industry leaders worldwide', 'Payment Partner' => 'Payment Partner', 'Infrastructure' => 'Infrastructure',
            'Download on the' => 'Download on the', 'Get it on' => 'Get it on', 'Compatible with iOS and Android devices.' => 'Compatible with iOS and Android devices.',
            'Trade Anywhere' => 'Trade Anywhere', 'Download BITCrypto mobile app for iOS and Android' => 'Download BITCrypto mobile app for iOS and Android',
            'Secure & Trusted' => 'Secure & Trusted', 'Your assets are protected by industry-leading security' => 'Your assets are protected by industry-leading security',
            'Crypto Deposit' => 'Crypto Deposit', 'Fiat Deposit' => 'Fiat Deposit', 'Select Currency' => 'Select Currency', 'Deposit Amount' => 'Deposit Amount', 'Submit Deposit' => 'Submit Deposit',
            'Select Fiat Currency' => 'Select Fiat Currency', 'Confirm Deposit' => 'Confirm Deposit',
            'Order ID' => 'Order ID',
            'A local merchant has been found. Matching account details...' => 'A local merchant has been found. Matching account details...', 
            'Welcome! I am your dedicated matching assistant. I am currently verifying the liquidity provider for your deposit.' => 'Welcome! I am your dedicated matching assistant. I am currently verifying the liquidity provider for your deposit.',
            'Matching successful. I have secured a high-priority account for your transaction. Please find the details on the right.' => 'Matching successful. I have secured a high-priority account for your transaction. Please find the details on the right.',
            'Please upload your payment receipt/screenshot first.' => 'Please upload your payment receipt/screenshot first.',
            'Thank you for the update. We have received your payment proof and are now verifying the transaction on the blockchain. Your balance will be updated shortly.' => 'Thank you for the update. We have received your payment proof and are now verifying the transaction on the blockchain. Your balance will be updated shortly.',
            'Receipt uploaded successfully. Waiting for admin approval.' => 'Receipt uploaded successfully. Waiting for admin approval.',
            'Network' => 'Network', 'Scan QR code to deposit' => 'Scan QR code to deposit', 'Upload screenshot of your transaction' => 'Upload screenshot of your transaction', 'Instant' => 'Instant', 'Regional Support' => 'Regional Support',
            'We will match you with a local merchant to facilitate your deposit in your local currency.' => 'We will match you with a local merchant to facilitate your deposit in your local currency.',
            'Processing Time: 10-30 mins' => 'Processing Time: 10-30 mins', 'Exchange Rate' => 'Exchange Rate', 'Service Fee' => 'Service Fee', 'Free' => 'Free',
            'Secure Payment' => 'Secure Payment', 'All transactions are encrypted' => 'All transactions are encrypted', 'Fast Arrival' => 'Fast Arrival', 'Most deposits arrive in mins' => 'Most deposits arrive in mins', 'Live help for your deposit' => 'Live help for your deposit',
            'Address copied to clipboard' => 'Address copied to clipboard'
        ],
        'zh' => [
            'Home' => '首页', 'Spot' => '现货', 'Perpetual' => '永续合约', 'Markets' => '市场行情', 'Exchange' => '快捷换币',
            'Login' => '登录', 'Register' => '注册', 'Profile' => '个人中心', 'Logout' => '退出登录',
            'Deposit' => '充值', 'Withdraw' => '提现', 'Assets' => '资产总览', 'Security' => '安全设置',
            'Buy' => '买入', 'Sell' => '卖出', 'Limit' => '限价', 'Market' => '市价', 'Price' => '价格',
            'Amount' => '数量', 'Total' => '成交额', 'Available' => '可用余额', 'Trade' => '交易',
            'Market Trends' => '市场趋势', 'Real-time Prices' => '实时行情', 'High' => '最高', 'Low' => '最低',
            'Download App' => '下载APP', 'Customer Service' => '在线客服',
            'Identity Verification' => '实名认证', 'Trading Password' => '资金密码',
            'Success' => '操作成功', 'Error' => '操作失败', 'Matching Account' => '匹配账户',
            'Establishing secure connection with liquidity provider...' => '正在与流动性提供商建立安全连接...',
            'Awaiting merchant confirmation...' => '等待商家确认...',
            'Matching in progress' => '正在匹配中',
            'The specialized account for this transaction will be provided by our agent shortly.' => '该交易的专用账户将由我们的代理稍后提供。',
            'Transfer the exact amount. Upload proof below.' => '请转账准确金额。在下方上传凭证。',
            'Bank Name' => '银行名称', 'Account Number' => '账号', 'Beneficiary' => '收款人', 'Reference' => '备注/附言',
            'Copy' => '复制', 'Upload Proof' => '上传凭证', 'Selected' => '已选择', 'Transfer Completed' => '我已完成转账',
            'Your transfer is being reviewed. ETA: 10-20 mins.' => '您的转账正在审核中。预计时间：10-20分钟。',
            'Back to Wallet' => '返回钱包', 'Matched & Active' => '已匹配并激活',
            'Services' => '服务', 'Spot Trading' => '现货交易', 'Futures Trading' => '期货交易',
            'Support' => '支持', 'Help Center' => '帮助中心', 'About Us' => '关于我们', 'Privacy Policy' => '隐私政策', 'Terms of Service' => '服务条款',
            'System Status' => '系统状态', 'Normal' => '正常', 'Overview' => '概览', 'Full Name' => '真实姓名', 'ID Number' => '证件号码', 'Submit' => '提交', 'Next-Gen Trading Engine' => '下一代交易引擎',
            'Experience ultra-low latency and institutional-grade liquidity on our professional K-line trading platform.' => '在我们的专业K线交易平台上体验超低延迟和机构级流动性。',
            'Register Now' => '立即注册', 'Start Trading' => '开始交易', 'Go to Futures' => '前往合约', 'Global Crypto Hub' => '全球加密枢纽',
            'Access real-time global market data and execute trades across multiple asset classes with one unified account.' => '通过一个统一的账户访问实时全球市场数据并跨多个资产类别执行交易。',
            'Secure Asset Custody' => '安全的资产托管', 'Your funds are safe with our institutional-grade security, multi-sig cold storage, and comprehensive insurance fund.' => '您的资金在我们机构级的安全性、多重签名冷存储和全面的保险基金保护下非常安全。',
            'Security Center' => '安全中心', '24/7 Global Support' => '24/7 全球支持', 'Our dedicated professional support team is available around the clock to assist you in multiple languages.' => '我们专业的支持团队全天候为您提供多种语言的帮助。',
            'Contact Support' => '联系支持', 'Asset' => '资产', '24h Change' => '24h 涨跌', '24h High' => '24h 最高', 'Action' => '操作', 'All Markets' => '全部市场',
            'Real-time updates from global exchanges' => '来自全球交易所的实时更新', 'Safe & Secure' => '安全可靠', 'Industry-leading encryption and multi-signature cold storage for your digital assets.' => '为您的数字资产提供行业领先的加密和多重签名冷存储。',
            'Instant Execution' => '即时执行', 'Advanced matching engine processing over 100,000 transactions per second.' => '每秒处理超过 100,000 笔交易的先进撮合引擎。',
            'Get help whenever you need it with our around-the-clock professional customer service.' => '通过我们全天候的专业客户服务，随时获得您需要的帮助。',
            'Trade Anywhere, Anytime' => '随时随地进行交易', 'Experience the full power of our exchange on your mobile device. Trade spot and futures with ease.' => '在您的移动设备上体验我们交易所的全部功能。轻松交易现货和期货。',
            'Scan to download' => '扫码下载', 'Compatible with iOS and Android devices.' => '兼容 iOS 和 Android 设备。',
            'Account Overview' => '账户概览', 'Total Balance' => '总资产', 'Security Settings' => '安全设置', 'Login Password' => '登录密码',
            'Change' => '修改', 'Verified' => '已认证', 'Reviewing...' => '审核中...', 'none' => '未认证', 'pending' => '审核中', 'approved' => '已认证',
            'Trade with up to 100x leverage on BTC, ETH, and other major crypto pairs with professional risk management tools.' => '在 BTC、ETH 和其他主要加密货币对上使用高达 100 倍的杠杆进行交易，并配备专业的风险管理工具。',
            'Perpetual Contracts' => '永续合约', 'Identity verification submitted and is under review.' => '身份认证已提交，正在审核中。',
            'New passwords do not match.' => '新密码不匹配。', 'Password must be at least 6 characters.' => '密码长度必须至少为6位。', 'Password updated successfully.' => '密码更新成功。', 'Current password incorrect.' => '当前密码不正确。',
            'Hello! Welcome to BITCrypto. How can we help you today?' => '您好！欢迎来到 BITCrypto。今天有什么可以帮您的？',
            'Type a message...' => '输入消息...', 'Thank you for your message. An agent will be with you shortly.' => '感谢您的消息，客服人员稍后将为您提供服务。',
            'For security reasons, never share your login or trading passwords with anyone, including our support agents.' => '出于安全考虑，请勿向任何人（包括我们的客服人员）透露您的登录密码或交易密码。',
            'Why Choose BITCrypto?' => '为什么选择 BITCrypto？', 'Global Liquidity' => '全球流动性', 'Deep order books and high liquidity across all trading pairs for minimal slippage.' => '所有交易对均拥有深度订单簿和高流动性，确保最小滑点。',
            'Advanced Trading' => '高级交易', 'Professional charting tools, multi-order types, and real-time execution.' => '专业的图表工具、多种订单类型和实时执行。',
            'Trusted by Millions' => '数百万用户的信赖', 'Join a global community of traders and investors on one of the most secure platforms.' => '加入全球交易者和投资者的社区，在最安全的平台之一上进行交易。',
            'Our Partners' => '合作伙伴', 'Global Trust' => '全球信任', 'Assets Overview' => '资产总览', 'BITCrypto provides a comprehensive ecosystem for crypto enthusiasts, from beginners to professional institutional traders.' => 'BITCrypto 为加密爱好者提供了一个全面的生态系统，从初学者到专业的机构交易者都能在这里找到适合自己的工具。',
            'Our Global Partners' => '我们的全球合作伙伴', 'Primary Network' => '主要网络', 'Smart Contracts' => '智能合约', 'Security Audit' => '安全审计', 'Financial Partner' => '金融伙伴', 'Strategic Advisor' => '战略顾问',
            'Unverified' => '未认证', 'Verification' => '实名认证', 'digits' => '位数字', 'Search Pairs' => '搜索币种', 'No open orders' => '无挂单', 'Time' => '时间', 'Pair' => '币种', 'Type' => '类型', 'Side' => '方向', 'Filled' => '已成交', 'Open Orders' => '当前挂单', 'Order History' => '历史订单', 'Positions' => '当前仓位',
            'Total Net Value' => '总资产折算', 'Yesterday Profit/Loss' => '昨日盈亏', 'Link' => '去绑定', 'Recent Activities' => '最近动态', 'Account Login' => '账号登录', 'Update failed' => '更新失败', 'Confirm New Trading Password' => '确认新资金密码', 'New Trading Password' => '新资金密码',
            'The World\'s Leading' => '全球领先的', 'Crypto Exchange' => '数字资产交易所', 'Trade Bitcoin, Ethereum, and hundreds of other cryptocurrencies with the lowest fees in the industry.' => '在行业最低费率的交易所交易比特币、以太坊和数百种其他加密货币。',
            'Get Started' => '立即开始', 'View Markets' => '查看行情', 'Users' => '用户', '24h Volume' => '24h 成交额', 'Countries' => '覆盖国家',
            'Stay updated with real-time price changes' => '实时掌握价格波动', 'View All' => '查看全部', 'Name' => '币种名称',
            'Experience the most professional trading environment' => '体验最专业的交易环境',
            'Multi-sig Cold Storage' => '多重签名冷存储', 'DDoS Protection' => 'DDoS 防护', '2FA Security' => '双重身份验证',
            'Ultra-low Latency' => '极低延迟', 'High Liquidity' => '高流动性', 'Zero Slippage' => '零滑点',
            'Multi-language Support' => '多语言支持', 'Live Chat' => '实时聊天', 'Fast Response' => '极速响应',
            'Trusted by industry leaders worldwide' => '全球行业领导者的信赖', 'Payment Partner' => '支付合作伙伴', 'Infrastructure' => '基础设施',
            'Download on the' => '在 App Store 下载', 'Get it on' => '在 Google Play 下载', 'Compatible with iOS and Android devices.' => '兼容 iOS 和 Android 设备。',
            'Trade Anywhere' => '随时随地交易', 'Download BITCrypto mobile app for iOS and Android' => '下载 BITCrypto 移动端 App，支持 iOS 和 Android',
            'Secure & Trusted' => '安全可靠', 'Your assets are protected by industry-leading security' => '您的资产受到行业领先的安全保护',
            'Crypto Deposit' => '数字货币充值', 'Fiat Deposit' => '法币充值', 'Select Currency' => '选择币种', 'Deposit Amount' => '充值金额', 'Submit Deposit' => '提交充值',
            'Select Fiat Currency' => '选择法币', 'Confirm Deposit' => '确认充值',
            'Order ID' => '订单编号',
            'A local merchant has been found. Matching account details...' => '已找到本地商家。正在匹配账户详情...', 
            'Welcome! I am your dedicated matching assistant. I am currently verifying the liquidity provider for your deposit.' => '欢迎！我是您的专属匹配助手。我目前正在为您验证流动性提供商。',
            'Matching successful. I have secured a high-priority account for your transaction. Please find the details on the right.' => '匹配成功。我已为您的交易锁定了一个高优先级账户。请查看右侧的详细信息。',
            'Please upload your payment receipt/screenshot first.' => '请先上传您的付款收据/截图。',
            'Thank you for the update. We have received your payment proof and are now verifying the transaction on the blockchain. Your balance will be updated shortly.' => '感谢您的反馈。我们已收到您的付款凭证，目前正在区块链上验证该交易。您的余额稍后将更新。',
            'Receipt uploaded successfully. Waiting for admin approval.' => '凭证上传成功。等待管理员审核。',
            'Network' => '网络', 'Scan QR code to deposit' => '扫码充值', 'Upload screenshot of your transaction' => '上传交易截图', 'Instant' => '秒到账', 'Regional Support' => '区域支持',
            'We will match you with a local merchant to facilitate your deposit in your local currency.' => '我们将为您匹配本地商家，方便您以本地货币进行充值。',
            'Processing Time: 10-30 mins' => '处理时间：10-30 分钟', 'Exchange Rate' => '汇率', 'Service Fee' => '手续费', 'Free' => '免费',
            'Secure Payment' => '安全支付', 'All transactions are encrypted' => '所有交易均已加密', 'Fast Arrival' => '极速到账', 'Most deposits arrive in mins' => '大多数充值在几分钟内到账', 'Live help for your deposit' => '充值实时帮助',
            'Address copied to clipboard' => '地址已复制到剪贴板'
        ]
    ];

    return $translations[$lang][$key] ?? $translations['en'][$key] ?? $key;
}

function t($key) { return mt($key); }

// Determine if we need a back button (not on index.php)
$current_page = basename($_SERVER['PHP_SELF']);
$is_home = ($current_page == 'index.php');
?>
<!DOCTYPE html>
<html lang="<?php echo $lang; ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BITCrypto - Global Leading Crypto Exchange</title>
    <link rel="icon" type="image/png" href="favicon.png">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
    <style>
        :root {
            --primary-bg: #0b0e11;
            --secondary-bg: #181a20;
            --accent-color: #f0b90b;
            --text-main: #eaecef;
            --text-muted: #848e9c;
            --success: #0ecb81;
            --danger: #f6465d;
            --okx-blue: #0046ff;
            --bit-gradient: linear-gradient(45deg, #0046ff, #00ff96);
        }
        body { background: var(--primary-bg); color: var(--text-main); font-family: 'Inter', sans-serif; overflow-x: hidden; padding-bottom: 70px; }
        @media (min-width: 992px) { body { padding-bottom: 0; } }

        .navbar { background: var(--secondary-bg); border-bottom: 1px solid #2b2f36; padding: 0.8rem 0; }
        .logo-text {
            font-size: 1.5rem;
            font-weight: 800;
            background: var(--bit-gradient);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            letter-spacing: -0.5px;
        }
        .logo-img {
            height: 40px;
            margin-right: 12px;
            background: transparent;
            border: none;
            display: block;
        }

        .back-button {
            display: <?php echo $is_home ? 'none' : 'flex'; ?>;
            align-items: center;
            gap: 8px;
            color: var(--text-muted);
            text-decoration: none;
            font-weight: 600;
            padding: 8px 16px;
            border-radius: 20px;
            background: rgba(255,255,255,0.05);
            transition: all 0.3s;
            margin-right: 15px;
        }
        .back-button:hover { background: rgba(255,255,255,0.1); color: white; }

        /* Bottom Nav for Mobile */
        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: 70px;
            background: #181a20;
            border-top: 1px solid #2b2f36;
            display: flex;
            justify-content: space-around;
            align-items: center;
            z-index: 2001;
            padding-bottom: env(safe-area-inset-bottom);
        }
        .nav-item-mobile {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: #848e9c;
            text-decoration: none;
            font-size: 0.65rem;
            transition: all 0.2s;
        }
        .nav-item-mobile i { font-size: 1.3rem; margin-bottom: 4px; }
        .nav-item-mobile.active { color: var(--okx-blue); }

        .floating-chat {
            position: fixed;
            bottom: 90px;
            right: 20px;
            z-index: 2000;
            width: 55px;
            height: 55px;
            background: var(--bit-gradient);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
            box-shadow: 0 10px 25px rgba(0, 70, 255, 0.4);
            cursor: pointer;
            text-decoration: none;
        }

        @media (min-width: 992px) {
            .bottom-nav { display: none; }
            .floating-chat { bottom: 30px; right: 30px; width: 65px; height: 65px; font-size: 1.8rem; }
        }
    </style>
</head>
<body>

<nav class="navbar navbar-expand-lg navbar-dark sticky-top">
    <div class="container">
        <div class="d-flex align-items-center">
            <a href="javascript:history.back()" class="back-button d-lg-none">
                <i class="fas fa-chevron-left"></i>
            </a>
            <a class="navbar-brand d-flex align-items-center" href="index.php">
                <img src="assets/images/logo.png" alt="Logo" class="logo-img">
                <span class="logo-text">BITCrypto</span>
            </a>
        </div>
        
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto ms-lg-4">
                <li class="nav-item"><a class="nav-link px-3" href="index.php"><?php echo mt('Home'); ?></a></li>
                <li class="nav-item"><a class="nav-link px-3" href="trade.php?type=spot"><?php echo mt('Spot'); ?></a></li>
                <li class="nav-item"><a class="nav-link px-3" href="trade.php?type=contract"><?php echo mt('Perpetual'); ?></a></li>
                <li class="nav-item"><a class="nav-link px-3" href="market.php"><?php echo mt('Markets'); ?></a></li>
                <li class="nav-item"><a class="nav-link px-3" href="exchange.php"><?php echo mt('Exchange'); ?></a></li>
            </ul>
            <ul class="navbar-nav ms-auto align-items-center">
                <li class="nav-item dropdown me-3">
                    <a class="nav-link dropdown-toggle" href="#" id="langDropdown" role="button" data-bs-toggle="dropdown">
                        <i class="fas fa-globe me-1"></i> <?php 
                            $langs = ['en' => 'English', 'zh' => '简体中文'];
                            echo $langs[$lang] ?? 'English';
                        ?>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-end shadow-lg">
                        <li><a class="dropdown-item" href="?lang=en">English</a></li>
                        <li><a class="dropdown-item" href="?lang=zh">简体中文</a></li>
                    </ul>
                </li>
                <?php if ($user): ?>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                            <div class="bg-secondary rounded-circle d-flex align-items-center justify-content-center me-2" style="width: 32px; height: 32px;">
                                <i class="fas fa-user small"></i>
                            </div>
                            <?php echo htmlspecialchars($user['username']); ?>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end shadow-lg">
                            <li class="px-3 py-2 small text-muted border-bottom border-secondary mb-1">UID: <?php echo str_pad($user['uid'] ?? 0, 6, '0', STR_PAD_LEFT); ?></li>
                            <li><a class="dropdown-item" href="profile.php"><i class="fas fa-wallet me-2"></i> <?php echo mt('Assets'); ?></a></li>
                            <li><a class="dropdown-item" href="profile.php?tab=security"><i class="fas fa-user-shield me-2"></i> <?php echo mt('Security'); ?></a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item text-danger" href="logout.php"><i class="fas fa-sign-out-alt me-2"></i> <?php echo mt('Logout'); ?></a></li>
                        </ul>
                    </li>
                <?php else: ?>
                    <li class="nav-item"><a class="nav-link px-3" href="login.php"><?php echo mt('Login'); ?></a></li>
                    <li class="nav-item"><a class="btn btn-primary px-4 ms-2 border-0" style="background: var(--okx-blue);" href="register.php"><?php echo mt('Register'); ?></a></li>
                <?php endif; ?>
            </ul>
        </div>
    </div>
</nav>

<!-- Bottom Nav for Mobile -->
<div class="bottom-nav">
    <a href="index.php" class="nav-item-mobile <?php echo $current_page == 'index.php' ? 'active' : ''; ?>">
        <i class="fas fa-house"></i>
        <span><?php echo mt('Home'); ?></span>
    </a>
    <a href="market.php" class="nav-item-mobile <?php echo $current_page == 'market.php' ? 'active' : ''; ?>">
        <i class="fas fa-chart-simple"></i>
        <span><?php echo mt('Markets'); ?></span>
    </a>
    <a href="trade.php" class="nav-item-mobile <?php echo ($current_page == 'trade.php' && ($_GET['type'] ?? 'spot') == 'spot') ? 'active' : ''; ?>">
        <i class="fas fa-repeat"></i>
        <span><?php echo mt('Spot'); ?></span>
    </a>
    <a href="trade.php?type=contract" class="nav-item-mobile <?php echo ($current_page == 'trade.php' && ($_GET['type'] ?? '') == 'contract') ? 'active' : ''; ?>">
        <i class="fas fa-bolt"></i>
        <span><?php echo mt('Perpetual'); ?></span>
    </a>
    <a href="profile.php" class="nav-item-mobile <?php echo $current_page == 'profile.php' ? 'active' : ''; ?>">
        <i class="fas fa-wallet"></i>
        <span><?php echo mt('Assets'); ?></span>
    </a>
</div>

<!-- Global Floating Chat -->
<a href="chat.php" class="floating-chat shadow-lg">
    <i class="fas fa-headset"></i>
</a>