<?php
if (session_status() === PHP_SESSION_NONE) session_start();

$supported_langs = [
    'en' => ['name' => 'English', 'flag' => 'us'],
    'zh' => ['name' => '简体中文', 'flag' => 'cn'],
    'jp' => ['name' => '日本語', 'flag' => 'jp'],
    'kr' => ['name' => '한국어', 'flag' => 'kr'],
    'de' => ['name' => 'Deutsch', 'flag' => 'de'],
    'fr' => ['name' => 'Français', 'flag' => 'fr'],
    'es' => ['name' => 'Español', 'flag' => 'es'],
    'ru' => ['name' => 'Русский', 'flag' => 'ru'],
    'tr' => ['name' => 'Türkçe', 'flag' => 'tr'],
    'vi' => ['name' => 'Tiếng Việt', 'flag' => 'vn']
];

$lang = $_SESSION['lang'] ?? 'en';
if (isset($_GET['lang']) && array_key_exists($_GET['lang'], $supported_langs)) {
    $lang = $_GET['lang'];
    $_SESSION['lang'] = $lang;
}

$translations = [
    'zh' => [
        'home' => '首页', 'market' => '行情', 'second_contract' => '秒合约', 'spot' => '现货交易', 'contract' => '合约交易',
        'mining' => '挖矿', 'swap' => '闪兑', 'personal' => '个人中心', 'login' => '登入', 'register' => '注册',
        'logout' => '退出', 'language' => '语言选择', 'footer_about' => '关于', 'footer_product' => '产品',
        'footer_support' => '支持', 'about_us' => '关于我们', 'news' => '新闻中心', 'terms' => '服务条款',
        'help' => '帮助中心', 'privacy' => '法律与隐私', 'submit_request' => '提交请求', 'api_doc' => '接口文档',
        'fee_structure' => '费率标准', 'app_download' => '应用下载', 'system_status' => '系统状态', 'normal' => '正常',
        'cookie_policy' => '隐私政策', 'platform_advantage' => '为什么选择BYRO', 'partners' => '合作伙伴', 'deposit' => '充值',
        'withdraw' => '提现', 'assets' => '资产', 'enter_verify_code' => '请输入验证码', 'verify_code_error' => '验证码错误或已过期',
        'agree_terms_error' => '请同意服务协议', 'mobile_verify' => '手机验证码', 'email_verify' => '邮箱验证码',
        'login_admin_error' => '管理员请通过后台页面登录', 'fill_full_info' => '请填写完整信息', 'verification_code' => '验证码',
        'agree_tos_privacy' => '我已阅读并同意<a href="/tos.php" target="_blank" class="text-primary text-decoration-none">《服务协议》</a>和<a href="/legal.php" target="_blank" class="text-primary text-decoration-none">《隐私政策》</a>',
        'register_now' => '立即注册', 'resend' => '重新发送', 'send_failed' => '发送失败', 'invalid_email' => '无效的邮箱地址',
        'invalid_mobile' => '无效的手机号码', 'congrats_won' => '恭喜你获利', 'sorry_lost' => '很遗憾亏损', 'trade_won' => '交易获利',
        'trade_lost' => '交易亏损', 'confirm' => '确 认', 'buy' => '买', 'sell' => '卖', 'buy_btn' => '买入', 'sell_btn' => '卖出',
        'confirm_swap' => '确认兑换', 'cancel' => '取消', 'approx' => '约等于', 'select_network' => '选择网络',
        'address_copied' => '地址已复制', 'withdrawal_password_error' => '提现密码错误', 'withdraw_pwd_placeholder' => '请输入提现密码',
        'recharge_amount_label' => '充值金额', 'withdraw_amount_label' => '提现金额', 'i_have_paid' => '我已付款',
        'enter_amount' => '请输入金额', 'crypto_recharge_warning' => '请仅向此地址发送 USDT。发送其他资产可能会导致永久丢失。',
        'recharge_steps' => '充值步骤', 'security_tips' => '安全提示', 'est_receive_fiat' => '预计收到法币',
        'withdraw_steps' => '提现步骤', 'withdraw_password' => '提现密码', 'coin' => '币种', 'address' => '地址',
        'network' => '网络', 'fiat_amount' => '法币金额', 'recharge_amount' => '充值金额', 'withdraw_amount' => '提现金额',
        'withdraw_address' => '提现地址', 'min_withdraw_hint' => '最小提现金额 10 USDT', 'secure' => '安全', 'fast' => '极速',
        'support_247' => '全天候支持', 'market_name' => '行情', 'trading' => '交易', 'status_normal' => '系统状态：正常',
        'copyright' => '© 2023-2024 BYRO. 版权所有。', 'back' => '返回', 'crypto_withdraw' => '加密货币提现',
        'fiat_withdraw' => '法币提现', 'to_receive' => '预计到账', 'confirm_order' => '确认订单', 'select_currency' => '选择币种',
        'fiat_recharge' => '法币充值', 'crypto_recharge' => '加密货币充值', 'est_usdt' => '预计 USDT', 'enter_address' => '请输入地址',
        'enter_password' => '请输入密码', 'request_sent' => '请求已发送，请检查聊天。', 'cs_connect_fail' => '连接失败，请刷新。',
        'copy_success' => '复制成功', 'market_view' => '查看市场', 'prof_terminal' => '专业终端',
        'prof_terminal_desc' => '高性能交易引擎，毫秒级响应。', 'inst_security' => '机构级安全',
        'inst_security_desc' => '多层加密和冷存储方案，确保资产安全。', 'advantage_1_title' => '合规运营',
        'advantage_1_desc' => '全球合规化运营，冷热钱包隔离。', 'advantage_2_title' => '深度流动性',
        'advantage_2_desc' => '毫秒级撮合引擎，流动性充足。', 'advantage_3_title' => '全天候支持',
        'advantage_3_desc' => '多语言客服全天候在线。', 'advantage_4_title' => '多元化产品',
        'advantage_4_desc' => '涵盖现货、合约、秒合约和挖矿。', 'popular_markets' => '热门市场', 'view_more' => '更多',
        'why_choose_us' => '为什么选择我们', 'footer_desc' => 'BYRO是全球领先的数字资产交易平台，为个人和机构提供安全、可靠的交易服务。',
        'hero_title' => '全球领先的数字资产平台', 'hero_subtitle' => '在BYRO开启您的加密货币之旅，安全、稳定、可靠。',
        'get_started' => '立即开启', 'account_exists' => '账号已存在或数据库错误', 'pwd_mismatch' => '两次输入的密码不一致',
        'join_secure' => '加入全球领先的交易平台', 'have_account' => '已有账号？', 'recharge_step1' => '选择您想要充值的币种和网络。',
        'recharge_step2' => '复制充值地址或扫描二维码。', 'recharge_step3' => '完成转账后，等待网络确认。',
        'recharge_step4' => '如有任何问题，请联系在线客服。', 'recharge_tip1' => '请务必核对充值网络，错误的地址将导致资产丢失。',
        'recharge_tip2' => '充值完成后，请妥善保存转账凭证。', 'recharge_tip3' => '请勿向他人透露您的账户私密信息。',
        'recharge_tip4' => '充值由系统自动到账，高峰期可能有延迟。', 'withdraw_step1' => '选择提现币种并输入提现地址。',
        'withdraw_step2' => '输入您想要提现的金额。', 'withdraw_step3' => '确认费用并提交提现申请。',
        'withdraw_step4' => '财务人员将在审核后处理您的请求。', 'withdraw_tip1' => '提现前请确保地址完全正确。',
        'withdraw_tip2' => '错误的提现地址将无法追回资产。', 'withdraw_tip3' => '提现申请一旦提交，无法撤回。',
        'withdraw_tip4' => '如有延误，请联系全天候在线客服。', 'withdraw_fee' => '手续费', 'unit_seconds' => '秒',
        'trading_pair' => '交易对', 'leverage' => '杠杆', 'buy_long' => '买入/做多', 'sell_short' => '卖出/做空',
        'buy_price' => '买入价', 'sell_price' => '卖出价', 'long' => '做多', 'short' => '做空', 'close' => '平仓',
        'settling' => '结算中...', 'amount_limit_error' => '金额超出限制 (%min% - %max%)', 'settlement_price' => '结算价',
        'warning' => '警告', 'high' => '最高', 'low' => '最低', 'chinese' => '简体中文', 'english' => 'English',
        'qr_code' => '二维码', 'bitcoin' => '比特币', 'ethereum' => '以太坊', 'tether' => '泰达币', 'binance_coin' => '币安币',
        'solana' => '索拉纳', 'ripple' => '瑞波币', 'cardano' => '艾达币', 'dogecoin' => '狗狗币', 'polkadot' => '波卡币',
        'polygon' => '马蹄币', 'avalanche' => '雪崩币', 'chainlink' => '链克', 'shiba_inu' => '柴犬币', 'tron' => '波场',
        'bitcoin_cash' => '比特现金', 'litecoin' => '莱特币', 'uniswap' => '独角兽', 'site_title' => '全球领先的数字资产交易平台',
        'unverified' => '未认证', 0 => '审核中', 'verified' => '已认证', 'real_name' => '实名认证', 'credit_score' => '信用分',
        'last_price' => '最新价', 'change_24h' => '24小时涨跌', 'vol_24h' => '24小时成交额', 'welcome_back' => '欢迎回来',
        'forgot_password' => '忘记密码？', 'no_account' => '没有账号？', 'invalid_account_pwd' => '账号或密码错误',
        'account' => '账号 / 邮箱', 'password' => '密码', 'mobile_number' => '手机号码', 'confirm_password' => '确认密码',
        'send_code' => '发送验证码', 'email' => '电子邮箱', 'email_placeholder' => '请输入电子邮箱',
        'registration_verify' => '注册验证', 'mobile_reg' => '手机注册', 'email_reg' => '邮箱注册', 'uploading' => '正在上传...',
        'uid' => '用户ID', 'recharge' => '充值', 'withdrawal' => '提现', 'binary_win' => '秒合约获利', 'binary_loss' => '秒合约亏损',
        'flash_exchange' => '闪兑', 'contract_settle' => '合约结算', 'contract_margin' => '合约保证金',
        'fill_all_fields' => '请填写所有字段', 'kyc_submitted' => '实名认证资料已提交，请等待审核',
        'kyc_pending_desc' => '您的实名认证正在审核中，通常需要 24 小时内完成。', 'full_name' => '全名',
        'enter_full_name' => '请输入全名', 'id_number' => '证件号码', 'enter_id_number' => '请输入证件号码', 'id_front' => '证件正面',
        'id_back' => '证件反面', 'id_handheld' => '手持证件照', 'upload' => '点击上传', 'kyc_steps' => '认证步骤',
        'kyc_step1' => '填写您的真实姓名和身份证号。', 'kyc_step2' => '上传您的身份证正反面照片。',
        'kyc_step3' => '上传您手持身份证的照片，确保面部清晰。', 'submit' => '提交',
        'kyc_instructions' => '请确保上传的照片清晰可见，光线充足，不要遮挡关键信息。认证成功后将无法修改，请务必填写真实信息。',
        'online_support' => '在线客服', 'type_message' => '输入消息...', 'welcome_support' => '欢迎来到支持中心！',
        'mining_desc' => '专业的云挖矿和质押平台。', 'mining_profit' => '挖矿收益', 'mining_return' => '本金退回',
        'mining_invest' => '参加挖矿', 'mining_rebate' => '挖矿返佣', 'spot_buy' => '现货买入', 'spot_sell' => '现货卖出',
        'transfer_in' => '转入', 'transfer_out' => '转出', 'mining_pool' => '矿池', 'day' => '天', 'flexible' => '活期',
        'est_apy' => '预计年化', 'min_deposit' => '起购金额', 'lock_period' => '锁定周期', 'principal_protected' => '本金保障',
        'daily_payouts' => '每日派息', 'why_mining' => '为什么选择挖矿？', 'adv_hardware' => '先进硬件',
        'adv_hardware_desc' => '我们使用最新的矿机。', 'auto_compound' => '自动复利', 'auto_compound_desc' => '每日收益自动再投资。',
        'real_time_monitor' => '实时监控', 'real_time_monitor_desc' => '实时追踪您的算力。', 'calc_profit' => '计算您的收益',
        'calc_desc' => '输入金额估算利润。', 'amount_to_invest' => '投资金额', 'daily_profit' => '每日利润',
        'monthly_profit' => '每月利润', 'try_calc' => '开始计算', 'app_desc' => '移动应用掌控资产。', 'download_on' => '下载于',
        'get_it_on' => '立即获取', 'scan_download' => '扫码下载', 'real_time_alerts' => '实时推送',
        'full_trading_features' => '全功能交易', 'two_fa_security' => '双重验证', 'live_chat_247' => '24/7 客服',
        'our_mission' => '我们的使命', 'mission_content' => '让交易变得触手及安全。', 'global_presence' => '全球布局',
        'presence_content' => '全球多个运营中心。', 'users' => '用户', 'countries' => '国家', 'daily_volume' => '成交额',
        'about_content' => '领先的加密货币平台。', 'news_content' => '获取最新市场资讯。', 'announcement' => '公告',
        'read_more' => '更多', 'newsletter' => '新闻资讯', 'newsletter_desc' => '订阅获取最新洞察。', 'email_address' => '邮箱',
        'join' => '加入', 'popular_topics' => '热门', 'trade_history' => '历史成交', 'effective_date' => '生效日期：2023年1月1日',
        'tos_intro' => '服务条款构成法律协议。', 'tos_1_title' => '1. 接受条款', 'tos_1_content' => '使用表示您同意。',
        'tos_1_extra' => '不同意请停止使用。', 'tos_2_title' => '2. 资格', 'tos_2_content' => '必须年满 18 岁。',
        'tos_3_title' => '3. 安全', 'tos_3_content' => '保护账户凭据。', 'tos_4_title' => '4. 风险', 'tos_4_content' => '交易具有极高风险。',
        'tos_5_title' => '5. 终止', 'tos_5_content' => '保留终止权利。', 'tos_6_title' => '6. 费用', 'tos_6_content' => '同意支付交易费。',
        'tos_7_title' => '7. 合规', 'tos_7_content' => '遵守反洗钱法律。', 'tos_footer' => '有疑问？', 'risk_warning' => '风险披露：',
        'last_updated' => '最后更新：2023年1月1日', 'privacy_intro_alert' => '隐私至关重要。', 'privacy_1_title' => '引言',
        'privacy_1_content' => '保护您的数据。', 'privacy_2_title' => '数据', 'privacy_2_content' => '收集身份和财务。',
        'privacy_data_identity' => '身份：', 'privacy_data_identity_desc' => '姓名、生日。', 'privacy_data_contact' => '联系：',
        'privacy_data_contact_desc' => '邮箱、电话。', 'privacy_data_financial' => '财务：',
        'privacy_data_financial_desc' => '交易记录。', 'privacy_data_tech' => '技术：', 'privacy_data_tech_desc' => '设备信息。',
        'privacy_2_extra_bottom' => '不出售给第三方。', 'privacy_3_title' => '用途', 'privacy_3_content' => '履行法律义务。',
        'privacy_4_title' => '安全性', 'privacy_4_content' => '加密技术保护。', 'privacy_5_title' => '权利',
        'privacy_5_content' => '访问或删除数据。', 'privacy_6_title' => '保留', 'privacy_6_content' => '仅保留必要时间。',
        'privacy_footer' => '修订接受。', 'news_title_1' => '正式上线秒合约', 'news_title_2' => '新增支付方式',
        'news_title_3' => '获得运营牌照', 'news_title_4' => '提升账户安全', 'news_title_5' => '市场研究报告',
        'news_desc_1' => '更快的结算体验。', 'news_desc_2' => '支持全球更多法币。', 'news_desc_3' => '全球合规化进程。',
        'news_desc_4' => '资产安全至上。', 'news_desc_5' => '洞察未来趋势。', 'news_meta' => '2023年12月21日',
        'demo_title' => '高性能交易引擎', 'demo_subtitle' => '顶尖的撮合速度，涵盖现货及秒合约。', 'spot_trading' => '现货交易',
        'futures_trading' => '永续合约', 'binary_trading' => '秒合约交易', 'search' => '搜索', 'time_15m' => '15分',
        'time_1h' => '1时', 'time_1d' => '1日', 'open_orders' => '当前委托', 'no_records_found' => '暂无记录', 'price' => '价格',
        'amount' => '数量', 'quantity' => '数量', 'balance' => '可用余额', 'cycle_settlement' => '周期结算',
        'seconds' => '秒', 'expected_profit' => '预期收益', 'buy_up' => '看涨', 'buy_down' => '看跌', 'profit' => '收益',
        'latency' => '延迟', 'api_connected' => 'API 已连接', 'network_status_normal' => '网络正常',
        'app_experience_now' => '立即体验移动端', 'orders' => '历史订单', 'BTC' => 'BTC', 'ETH' => 'ETH', 'USDT' => 'USDT',
        'trade_spot' => '现货', 'trade_contract' => '永续', 'trade_binary' => '秒合约', 'sec_contract' => '秒合约',
        'time_fs' => '分时', 'time_1m' => '1分', 'time_5m' => '5分', 'time_30m' => '30分', 'time_4h' => '4时', 'time_1w' => '1周',
        'indicators' => '指标', 'chart' => '图表', 'depth' => '深度', 'available_balance' => '可用余额', 'purchase_amount' => '购买金额',
        'executing' => '执行中', 'operation' => '操作', 'failed' => '失败', 'won' => '盈', 'loss' => '亏',
        'limit' => '限价', 'market' => '市价', 'insufficient_balance' => '余额不足', 'unit_seconds' => '秒',
        'settlement_history' => '结算历史', 'total' => '合计', 'support_anywhere' => '随时随地', 'app_mockup_desc' => '全球领先的交易体验',
        'app_store' => 'App Store', 'google_play' => 'Google Play', 'android_apk' => 'Android APK', 'scan_qr_to_download' => '扫描二维码下载',
        'app_guide_step1' => '扫描上方二维码', 'app_guide_step2' => '完成安装与授权', 'app_guide_step3' => '开启您的加密之旅',
        'app_install_auth' => '安装与授权'
    ],
    'en' => [
        'home' => 'Home', 'market' => 'Market', 'second_contract' => 'Binary', 'spot' => 'Spot', 'contract' => 'Contract',
        'mining' => 'Mining', 'swap' => 'Swap', 'personal' => 'Account', 'login' => 'Login', 'register' => 'Register',
        'logout' => 'Logout', 'language' => 'Language', 'footer_about' => 'About', 'footer_product' => 'Products',
        'footer_support' => 'Support', 'about_us' => 'About Us', 'news' => 'News', 'terms' => 'Terms',
        'help' => 'Help Center', 'privacy' => 'Privacy Policy', 'submit_request' => 'Submit', 'api_doc' => 'API',
        'fee_structure' => 'Fees', 'app_download' => 'Download App', 'system_status' => 'Status', 'normal' => 'Normal',
        'cookie_policy' => 'Cookie Policy', 'platform_advantage' => 'Why BYRO', 'partners' => 'Partners', 'deposit' => 'Deposit',
        'withdraw' => 'Withdraw', 'assets' => 'Assets', 'enter_verify_code' => 'Enter code', 'verify_code_error' => 'Invalid or expired',
        'agree_terms_error' => 'Agree to terms', 'mobile_verify' => 'Mobile Verify', 'email_verify' => 'Email Verify',
        'login_admin_error' => 'Admin use backend', 'fill_full_info' => 'Fill information', 'verification_code' => 'Code',
        'agree_tos_privacy' => 'I agree to <a href="/tos.php" target="_blank" class="text-primary text-decoration-none">Terms</a> and <a href="/legal.php" target="_blank" class="text-primary text-decoration-none">Privacy</a>',
        'register_now' => 'Register Now', 'resend' => 'Resend', 'send_failed' => 'Failed', 'invalid_email' => 'Invalid Email',
        'invalid_mobile' => 'Invalid Mobile', 'congrats_won' => 'Congrats, Win', 'sorry_lost' => 'Sorry, Loss', 'trade_won' => 'Profit',
        'trade_lost' => 'Loss', 'confirm' => 'Confirm', 'buy' => 'Buy', 'sell' => 'Sell', 'buy_btn' => 'Buy', 'sell_btn' => 'Sell',
        'confirm_swap' => 'Confirm Swap', 'cancel' => 'Cancel', 'approx' => 'Approx.', 'select_network' => 'Network',
        'address_copied' => 'Copied', 'withdrawal_password_error' => 'Password Error', 'withdraw_pwd_placeholder' => 'Withdrawal Password',
        'recharge_amount_label' => 'Amount', 'withdraw_amount_label' => 'Amount', 'i_have_paid' => 'Paid',
        'enter_amount' => 'Enter Amount', 'crypto_recharge_warning' => 'Only send USDT to this address.',
        'recharge_steps' => 'Steps', 'security_tips' => 'Security', 'est_receive_fiat' => 'Est. Fiat',
        'withdraw_steps' => 'Steps', 'withdraw_password' => 'Password', 'coin' => 'Coin', 'address' => 'Address',
        'network' => 'Network', 'fiat_amount' => 'Fiat', 'recharge_amount' => 'Recharge', 'withdraw_amount' => 'Withdraw',
        'withdraw_address' => 'Address', 'min_withdraw_hint' => 'Min 10 USDT', 'secure' => 'Secure', 'fast' => 'Fast',
        'support_247' => '24/7', 'market_name' => 'Market', 'trading' => 'Trading', 'status_normal' => 'Status: Normal',
        'copyright' => '© 2023-2024 BYRO.', 'back' => 'Back', 'crypto_withdraw' => 'Crypto Withdraw',
        'fiat_withdraw' => 'Fiat Withdraw', 'to_receive' => 'To Receive', 'confirm_order' => 'Confirm', 'select_currency' => 'Select Coin',
        'fiat_recharge' => 'Fiat Recharge', 'crypto_recharge' => 'Crypto Recharge', 'est_usdt' => 'Est. USDT', 'enter_address' => 'Address',
        'enter_password' => 'Password', 'request_sent' => 'Sent, check chat.', 'cs_connect_fail' => 'Fail, refresh.',
        'copy_success' => 'Success', 'market_view' => 'Markets', 'prof_terminal' => 'Terminal',
        'prof_terminal_desc' => 'High performance engine.', 'inst_security' => 'Security',
        'inst_security_desc' => 'Institutional grade security.', 'advantage_1_title' => 'Compliance',
        'advantage_1_desc' => 'Global compliant operations.', 'advantage_2_title' => 'Liquidity',
        'advantage_2_desc' => 'Deep market liquidity.', 'advantage_3_title' => 'Support',
        'advantage_3_desc' => '24/7 online support.', 'advantage_4_title' => 'Products',
        'advantage_4_desc' => 'Diverse products.', 'popular_markets' => 'Hot Markets', 'view_more' => 'More',
        'why_choose_us' => 'Why Us', 'footer_desc' => 'Leading digital asset platform.',
        'hero_title' => 'Global Leading Platform', 'hero_subtitle' => 'Start your crypto journey safely.',
        'get_started' => 'Get Started', 'account_exists' => 'Error', 'pwd_mismatch' => 'Mismatch',
        'join_secure' => 'Join BYRO', 'have_account' => 'Account?', 'recharge_step1' => 'Select coin.',
        'recharge_step2' => 'Copy address.', 'recharge_step3' => 'Wait for network.',
        'recharge_step4' => 'Contact support.', 'recharge_tip1' => 'Check network.',
        'recharge_tip2' => 'Save vouchers.', 'recharge_tip3' => 'Keep private.',
        'recharge_tip4' => 'Peak delay possible.', 'withdraw_step1' => 'Select coin.',
        'withdraw_step2' => 'Enter amount.', 'withdraw_step3' => 'Submit.',
        'withdraw_step4' => 'Processing.', 'withdraw_tip1' => 'Check address.',
        'withdraw_tip2' => 'Non-recoverable.', 'withdraw_tip3' => 'No withdrawal after.',
        'withdraw_tip4' => '24/7 support.', 'withdraw_fee' => 'Fee', 'unit_seconds' => 's',
        'trading_pair' => 'Pair', 'leverage' => 'Leverage', 'buy_long' => 'Buy/Long', 'sell_short' => 'Sell/Short',
        'buy_price' => 'Buy Price', 'sell_price' => 'Sell Price', 'long' => 'Long', 'short' => 'Short', 'close' => 'Close',
        'settling' => 'Settling...', 'amount_limit_error' => 'Limit (%min% - %max%)', 'settlement_price' => 'Price',
        'warning' => 'Warning', 'high' => 'High', 'low' => 'Low', 'chinese' => 'Chinese', 'english' => 'English',
        'qr_code' => 'QR', 'bitcoin' => 'BTC', 'ethereum' => 'ETH', 'tether' => 'USDT', 'binance_coin' => 'BNB',
        'solana' => 'SOL', 'ripple' => 'XRP', 'cardano' => 'ADA', 'dogecoin' => 'DOGE', 'polkadot' => 'DOT',
        'polygon' => 'MATIC', 'avalanche' => 'AVAX', 'chainlink' => 'LINK', 'shiba_inu' => 'SHIB', 'tron' => 'TRX',
        'bitcoin_cash' => 'BCH', 'litecoin' => 'LTC', 'uniswap' => 'UNI', 'site_title' => 'Leading Digital Platform',
        'unverified' => 'Unverified', 0 => 'Pending', 'verified' => 'Verified', 'real_name' => 'KYC', 'credit_score' => 'Credit',
        'last_price' => 'Price', 'change_24h' => '24h Change', 'vol_24h' => '24h Volume', 'welcome_back' => 'Welcome',
        'forgot_password' => 'Forgot?', 'no_account' => 'No account?', 'invalid_account_pwd' => 'Invalid account',
        'account' => 'Account', 'password' => 'Password', 'mobile_number' => 'Mobile', 'confirm_password' => 'Confirm',
        'send_code' => 'Send', 'email' => 'Email', 'email_placeholder' => 'Email', 'registration_verify' => 'Verify',
        'mobile_reg' => 'Mobile', 'email_reg' => 'Email', 'uploading' => 'Uploading...', 'uid' => 'UID',
        'recharge' => 'Recharge', 'withdrawal' => 'Withdrawal', 'binary_win' => 'Profit', 'binary_loss' => 'Loss',
        'flash_exchange' => 'Swap', 'contract_settle' => 'Settle', 'contract_margin' => 'Margin', 'fill_all_fields' => 'Fill all',
        'kyc_submitted' => 'Submitted', 'kyc_pending_desc' => 'Reviewing.', 'full_name' => 'Name', 'enter_full_name' => 'Enter name',
        'id_number' => 'ID', 'enter_id_number' => 'Enter ID', 'id_front' => 'ID Front', 'id_back' => 'ID Back',
        'id_handheld' => 'Handheld', 'upload' => 'Upload', 'kyc_steps' => 'Steps', 'kyc_step1' => 'Info.',
        'kyc_step2' => 'Photos.', 'kyc_step3' => 'Handheld.', 'submit' => 'Submit', 'kyc_instructions' => 'Keep clear.',
        'online_support' => 'Support', 'type_message' => 'Type...', 'welcome_support' => 'Welcome.',
        'mining_desc' => 'Cloud mining.', 'mining_profit' => 'Mining Profit', 'mining_return' => 'Return',
        'mining_invest' => 'Invest', 'mining_rebate' => 'Rebate', 'spot_buy' => 'Spot Buy', 'spot_sell' => 'Spot Sell',
        'transfer_in' => 'In', 'transfer_out' => 'Out', 'mining_pool' => 'Pool', 'day' => 'Day', 'flexible' => 'Flexible',
        'est_apy' => 'APY', 'min_deposit' => 'Min', 'lock_period' => 'Lock', 'principal_protected' => 'Protected',
        'daily_payouts' => 'Daily', 'why_mining' => 'Why Mining?', 'adv_hardware' => 'Hardware',
        'adv_hardware_desc' => 'Latest tech.', 'auto_compound' => 'Auto', 'auto_compound_desc' => 'Reinvest.',
        'real_time_monitor' => 'Monitor', 'real_time_monitor_desc' => 'RT Monitor.', 'calc_profit' => 'Calc',
        'calc_desc' => 'Estimate.', 'amount_to_invest' => 'Investment', 'daily_profit' => 'Daily',
        'monthly_profit' => 'Monthly', 'try_calc' => 'Calc', 'app_desc' => 'Trade mobile.', 'download_on' => 'Download',
        'get_it_on' => 'Get it', 'scan_download' => 'Scan', 'real_time_alerts' => 'Alerts',
        'full_trading_features' => 'Features', 'two_fa_security' => '2FA', 'live_chat_247' => '24/7', 'our_mission' => 'Mission',
        'mission_content' => 'Accessible crypto.', 'global_presence' => 'Presence', 'presence_content' => 'Global centers.',
        'users' => 'Users', 'countries' => 'Countries', 'daily_volume' => 'Volume', 'about_content' => 'Founded 2023.',
        'news_content' => 'Updates.', 'announcement' => 'News', 'read_more' => 'More', 'newsletter' => 'Newsletter',
        'newsletter_desc' => 'Subscribe.', 'email_address' => 'Email', 'join' => 'Join', 'popular_topics' => 'Hot',
        'trade_history' => 'History', 'effective_date' => 'Date: 2023.01.01', 'tos_intro' => 'Terms of Service.',
        'tos_1_title' => '1. Terms', 'tos_1_content' => 'Agreement.', 'tos_1_extra' => 'Stop if disagree.',
        'tos_2_title' => '2. Eligibility', 'tos_2_content' => '18+ years old.', 'tos_3_title' => '3. Security',
        'tos_3_content' => 'Protect credentials.', 'tos_4_title' => '4. Risk', 'tos_4_content' => 'High risk.',
        'tos_5_title' => '5. Termination', 'tos_5_content' => 'Rights.', 'tos_6_title' => '6. Fees', 'tos_6_content' => 'Fees.',
        'tos_7_title' => '7. AML', 'tos_7_content' => 'Compliance.', 'tos_footer' => 'Support?', 'risk_warning' => 'Risk:',
        'last_updated' => 'Updated: 2023.01.01', 'privacy_intro_alert' => 'Privacy.', 'privacy_1_title' => 'Intro',
        'privacy_1_content' => 'Protection.', 'privacy_2_title' => 'Data', 'privacy_2_content' => 'Collection.',
        'privacy_data_identity' => 'ID:', 'privacy_data_identity_desc' => 'Name.', 'privacy_data_contact' => 'Contact:',
        'privacy_data_contact_desc' => 'Email.', 'privacy_data_financial' => 'Finance:', 'privacy_data_financial_desc' => 'Records.',
        'privacy_data_tech' => 'Tech:', 'privacy_data_tech_desc' => 'Device.', 'privacy_2_extra_bottom' => 'No sale.',
        'privacy_3_title' => 'Usage', 'privacy_3_content' => 'Improvement.', 'privacy_4_title' => 'Security',
        'privacy_4_content' => 'Encryption.', 'privacy_5_title' => 'Rights', 'privacy_5_content' => 'Access.',
        'privacy_6_title' => 'Retention', 'privacy_6_content' => 'Retention.', 'privacy_footer' => 'Revised.',
        'news_title_1' => 'Binary Live', 'news_title_2' => 'New Payments', 'news_title_3' => 'License Obtained',
        'news_title_4' => 'Enable 2FA', 'news_title_5' => '2024 Report', 'news_desc_1' => 'Settlement.',
        'news_desc_2' => 'More fiat.', 'news_desc_3' => 'Compliance.', 'news_desc_4' => 'Security.', 'news_desc_5' => 'Trends.',
        'news_meta' => '2023.12.21', 'demo_title' => 'Performance Engine', 'demo_subtitle' => 'Spot & Binary.',
        'spot_trading' => 'Spot Trading', 'futures_trading' => 'Futures', 'binary_trading' => 'Binary Trading',
        'search' => 'Search', 'time_15m' => '15m', 'time_1h' => '1h', 'time_1d' => '1d', 'open_orders' => 'Orders',
        'no_records_found' => 'No records', 'price' => 'Price', 'amount' => 'Amount', 'quantity' => 'Quantity',
        'balance' => 'Balance', 'cycle_settlement' => 'Cycle', 'seconds' => 's', 'expected_profit' => 'Profit',
        'buy_up' => 'Buy Up', 'buy_down' => 'Buy Down', 'profit' => 'Profit', 'latency' => 'Latency',
        'api_connected' => 'API OK', 'network_status_normal' => 'Net OK', 'app_experience_now' => 'Try Mobile',
        'orders' => 'Orders', 'BTC' => 'BTC', 'ETH' => 'ETH', 'USDT' => 'USDT',
        'trade_spot' => 'Spot', 'trade_contract' => 'Futures', 'trade_binary' => 'Binary', 'sec_contract' => 'Binary',
        'time_fs' => 'Time', 'time_1m' => '1m', 'time_5m' => '5m', 'time_30m' => '30m', 'time_4h' => '4h', 'time_1w' => '1w',
        'indicators' => 'Indicators', 'chart' => 'Chart', 'depth' => 'Depth', 'available_balance' => 'Available', 'purchase_amount' => 'Amount',
        'executing' => 'Executing', 'operation' => 'Operation', 'failed' => 'Failed', 'won' => 'Win', 'loss' => 'Loss',
        'limit' => 'Limit', 'market' => 'Market', 'insufficient_balance' => 'Insufficient', 'unit_seconds' => 's',
        'settlement_history' => 'Settlement', 'total' => 'Total', 'support_anywhere' => 'Trade Anywhere', 'app_mockup_desc' => 'Global leading trading experience',
        'app_store' => 'App Store', 'google_play' => 'Google Play', 'android_apk' => 'Android APK', 'scan_qr_to_download' => 'Scan QR to Download',
        'app_guide_step1' => 'Scan the QR above', 'app_guide_step2' => 'Install and authorize', 'app_guide_step3' => 'Start your journey',
        'app_install_auth' => 'Install & Auth'
    ],
];

// Map all other languages with basic translations for "global" feel
$lang_bases = [
    'jp' => [
        'home' => 'ホーム', 'market' => 'マーケット', 'trading' => '取引', 'personal' => 'アカウント', 'login' => 'ログイン',
        'register' => '登録', 'assets' => '資産', 'deposit' => '入金', 'withdraw' => '出金', 'support' => 'サポート'
    ],
    'kr' => [
        'home' => '홈', 'market' => '마켓', 'trading' => '거래', 'personal' => '계정', 'login' => '로그인',
        'register' => '회원가입', 'assets' => '자산', 'deposit' => '입금', 'withdraw' => '출금', 'support' => '지원'
    ],
    'de' => [
        'home' => 'Startseite', 'market' => 'Markt', 'trading' => 'Handel', 'personal' => 'Konto', 'login' => 'Anmelden',
        'register' => 'Registrieren', 'assets' => 'Vermögen', 'deposit' => 'Einzahlung', 'withdraw' => 'Auszahlung', 'support' => 'Support'
    ],
    'fr' => [
        'home' => 'Accueil', 'market' => 'Marché', 'trading' => 'Trading', 'personal' => 'Compte', 'login' => 'Connexion',
        'register' => 'S\'inscrire', 'assets' => 'Actifs', 'deposit' => 'Dépôt', 'withdraw' => 'Retrait', 'support' => 'Support'
    ],
    'es' => [
        'home' => 'Inicio', 'market' => 'Mercado', 'trading' => 'Comercio', 'personal' => 'Cuenta', 'login' => 'Acceder',
        'register' => 'Registro', 'assets' => 'Activos', 'deposit' => 'Depósito', 'withdraw' => 'Retirar', 'support' => 'Soporte'
    ],
    'ru' => [
        'home' => 'Главная', 'market' => 'Рынок', 'trading' => 'Торговля', 'personal' => 'Аккаунт', 'login' => 'Вход',
        'register' => 'Регистрация', 'assets' => 'Активы', 'deposit' => 'Депозит', 'withdraw' => 'Вывод', 'support' => 'Поддержка'
    ],
    'tr' => [
        'home' => 'Ana Sayfa', 'market' => 'Piyasa', 'trading' => 'Ticaret', 'personal' => 'Hesap', 'login' => 'Giriş',
        'register' => 'Kayıt Ol', 'assets' => 'Varlıklar', 'deposit' => 'Yatırma', 'withdraw' => 'Çekme', 'support' => 'Destek'
    ],
    'vi' => [
        'home' => 'Trang chủ', 'market' => 'Thị trường', 'trading' => 'Giao dịch', 'personal' => 'Tài khoản', 'login' => 'Đăng nhập',
        'register' => 'Đăng ký', 'assets' => 'Tài sản', 'deposit' => 'Nạp tiền', 'withdraw' => 'Rút tiền', 'support' => 'Hỗ trợ'
    ]
];

foreach(['jp', 'kr', 'de', 'fr', 'es', 'ru', 'tr', 'vi'] as $l) {
    if (!isset($translations[$l])) {
        // Clone English but override with basic translations if available
        $translations[$l] = $translations['en'];
        if (isset($lang_bases[$l])) {
            foreach($lang_bases[$l] as $k => $v) {
                $translations[$l][$k] = $v;
            }
        }
    }
}

function __($key) {
    global $translations, $lang;
    $fallback = 'en';
    return $translations[$lang][$key] ?? ($translations[$fallback][$key] ?? $key);
}

function getCoinIcon($symbol) {
    $symbol = strtoupper($symbol);
    $icon_ids = [
        'BTC' => '1/small/bitcoin.png', 'ETH' => '279/small/ethereum.png', 'USDT' => '325/small/tether.png',
        'BNB' => '825/small/binance-coin-logo.png', 'SOL' => '4128/small/solana.png', 'XRP' => '44/small/xrp-symbol-white-128.png',
        'ADA' => '975/small/cardano.png', 'DOGE' => '5/small/dogecoin.png', 'DOT' => '12171/small/polkadot.png',
        'MATIC' => '4713/small/matic-network.png', 'AVAX' => '12559/small/avalanche.png', 'LINK' => '877/small/chainlink.png',
        'SHIB' => '11939/small/shiba-inu.png', 'TRX' => '1094/small/tron.png', 'BCH' => '153/small/bitcoin-cash.png',
        'LTC' => '2/small/litecoin.png', 'UNI' => '12504/small/uniswap.png', 'ARB' => '29359/small/arbitrum.png',
        'OP' => '25244/small/optimism.png', 'APT' => '27355/small/aptos.png', 'USDC' => '6319/small/usdc.png',
        'PEPE' => '31386/small/pepe.png', 'FIL' => '12817/small/filecoin.png', 'NEAR' => '10365/small/near.png',
        'ATOM' => '1481/small/cosmos.png', 'IMX' => '17233/small/immutable-x.png', 'KAS' => '26851/small/kaspa.png',
        'DAI' => '992/small/dai.png', 'STX' => '2069/small/stacks.png', 'RNDR' => '11634/small/render-token.png',
        'INJ' => '12882/small/injective_protocol.png', 'TIA' => '31967/small/tia.png', 'SUI' => '26375/small/sui-ocean-64.png',
        'SEI' => '31322/small/sei.png',
    ];
    if (isset($icon_ids[$symbol])) {
        return "https://coin-images.coingecko.com/coins/images/" . $icon_ids[$symbol];
    }
    return "https://bin.bnbstatic.com/static/images/home/market/coin-icon/" . $symbol . ".png";
}
