<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<title>Deposit - CV111</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800;900&display=swap">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
  *{box-sizing:border-box; margin:0; padding:0;}
  :root{
    --bg:#0A0714; --card:#181129; --border:rgba(255,255,255,.07); --border-hi:rgba(155,93,229,.35);
    --gold:#F5C542; --purple:#9B5DE5;
    --grad-main:linear-gradient(135deg,#6C3FC5 0%,#9B5DE5 50%,#B57EF0 100%);
    --grad-gold:linear-gradient(135deg,#F5C542,#E0A926);
    --text:#FFFFFF; --muted:#9691B0; --muted-dim:#5C5870;
    --green:#22D67A; --red:#FF5C7A;
  }
  body{
    min-height:100vh; font-family:'Poppins',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif; color:var(--text);
    background:radial-gradient(circle at 20% 0%, rgba(155,93,229,.12), transparent 45%),
               radial-gradient(circle at 90% 90%, rgba(245,197,66,.06), transparent 40%), var(--bg);
    padding-bottom:40px; -webkit-tap-highlight-color:transparent;
  }
  .top{display:flex;align-items:center;gap:14px;padding:20px 18px 16px;}
  .top a{width:38px;height:38px;border-radius:12px;background:var(--card);border:1px solid var(--border);display:flex;align-items:center;justify-content:center;color:var(--text);text-decoration:none;font-size:16px;}
  .top h1{font-size:19px;font-weight:800;flex:1;text-align:center;padding-right:38px;}
  .wrap{max-width:480px;margin:0 auto;padding:0 18px;}

  .balance-hero{border-radius:24px; padding:26px 22px; margin-bottom:22px; position:relative; overflow:hidden;
    background:linear-gradient(160deg, #1D1533 0%, #120D24 100%); border:1px solid var(--border-hi);
    box-shadow:0 20px 50px -12px rgba(108,63,197,.35), inset 0 1px 0 rgba(255,255,255,.06);}
  .balance-hero::before{content:''; position:absolute; width:180px; height:180px; border-radius:50%;
    background:radial-gradient(circle, rgba(245,197,66,.2), transparent 70%); top:-70px; right:-50px;}
  .balance-hero .lab{font-size:11.5px; color:var(--muted); font-weight:700; letter-spacing:1.5px; text-transform:uppercase; position:relative; z-index:1;}
  .balance-hero .amt{font-size:38px; font-weight:900; margin-top:8px; position:relative; z-index:1; letter-spacing:-.5px;
    background:linear-gradient(135deg,#fff,#F5DFA0); -webkit-background-clip:text; background-clip:text; color:transparent;}
  .balance-hero .amt span{font-size:22px; opacity:.7; margin-right:4px;}

  .section-title{font-size:14px; font-weight:800; margin:0 0 12px; color:#E8E3F8;}

  .methods{display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:20px;}
  .method{position:relative; display:flex; align-items:center; gap:12px; background:var(--card); border:1.5px solid var(--border); border-radius:16px; padding:12px 14px; cursor:pointer; transition:.18s;}
  .method .ic{width:44px; height:44px; border-radius:12px; background:#fff; display:flex; align-items:center; justify-content:center; overflow:hidden; flex-shrink:0; box-shadow:0 4px 12px rgba(0,0,0,.25);}
  .method .ic img{width:100%; height:100%; object-fit:contain; padding:6px;}
  .method .name{font-weight:700; font-size:14px;}
  .method .tag{font-size:10.5px; color:var(--green); font-weight:600; margin-top:2px; display:flex; align-items:center; gap:4px;}
  .method .tag::before{content:''; width:5px; height:5px; border-radius:50%; background:var(--green);}
  .method.active{border-color:var(--purple); background:linear-gradient(135deg, rgba(155,93,229,.15), rgba(155,93,229,.03)); box-shadow:0 8px 24px -8px rgba(155,93,229,.5);}
  .method .check{position:absolute; top:-6px; right:-6px; width:22px; height:22px; border-radius:50%; background:var(--grad-main); color:#fff; display:none; align-items:center; justify-content:center; font-size:11px; font-weight:900; box-shadow:0 2px 8px rgba(155,93,229,.5); border:2px solid var(--bg);}
  .method.active .check{display:flex;}

  .channel-item{background:var(--card); border:1.5px solid var(--border); border-radius:16px; padding:16px; margin-bottom:10px; cursor:pointer; transition:.15s;}
  .channel-item.active{border-color:var(--purple); background:linear-gradient(135deg, rgba(155,93,229,.12), rgba(155,93,229,.02)); box-shadow:0 8px 20px -8px rgba(155,93,229,.4);}
  .channel-item .name{font-weight:700; font-size:14.5px;}
  .channel-item .limit{font-size:11.5px; color:var(--muted); margin-top:4px; font-weight:600;}

  .amounts{display:grid; grid-template-columns:repeat(3,1fr); gap:10px; margin-bottom:22px;}
  .amount-chip{background:var(--card); border:1.5px solid var(--border); border-radius:14px; padding:14px 0; text-align:center; font-weight:800; font-size:15px; cursor:pointer; transition:.15s;}
  .amount-chip.active{border-color:var(--gold); color:var(--gold); background:rgba(245,197,66,.08); box-shadow:0 8px 20px -8px rgba(245,197,66,.35);}

  .btn-submit{width:100%; padding:18px; border-radius:18px; border:none; font-weight:800; font-size:16px; cursor:pointer;
    background:var(--grad-main); color:#fff; box-shadow:0 16px 36px -10px rgba(108,63,197,.6); margin-top:8px; transition:transform .12s;}
  .btn-submit:active{transform:scale(.98);}

  .msg{padding:14px 16px; border-radius:14px; font-size:13px; font-weight:600; margin-bottom:16px; display:flex; align-items:center; gap:10px;}
  .msg-err{background:rgba(255,92,122,.1); border:1px solid rgba(255,92,122,.3); color:var(--red);}
  .center{text-align:center; color:var(--muted); padding:30px 0; font-size:14px;}
</style>
</head>
<body>
<?php $pt = __DIR__ . '/page_transition.php'; if (file_exists($pt)) { include $pt; } ?>
  <div class="top"><a href="/newhome.php">←</a><h1>Deposit</h1></div>
  <div class="wrap">
    <div id="msgBox"></div>

    <div class="balance-hero">
      <div style="display:flex; align-items:flex-start; justify-content:space-between; position:relative; z-index:1;">
        <div>
          <div class="lab">Available Balance</div>
          <div class="amt"><span>৳</span><span id="cashBalance">0</span></div>
        </div>
        <div style="width:48px; height:48px; border-radius:14px; background:linear-gradient(135deg, rgba(245,197,66,.2), rgba(245,197,66,.05)); border:1px solid rgba(245,197,66,.3); display:flex; align-items:center; justify-content:center;">
          <i class="fa-solid fa-wallet" style="color:var(--gold); font-size:19px;"></i>
        </div>
      </div>
      <div style="margin-top:16px; display:inline-flex; align-items:center; gap:6px; background:rgba(34,214,122,.1); border:1px solid rgba(34,214,122,.3); color:var(--green); font-size:11px; font-weight:700; padding:6px 12px; border-radius:20px; position:relative; z-index:1;">
        <i class="fa-solid fa-bolt"></i> Instant Deposit — ১-৫ মিনিটে Balance যোগ হয়
      </div>
    </div>

    <p class="section-title">Payment Method</p>
    <div class="methods">
      <div class="method active" id="dmtd-1" onclick="selectMethod('1')">
        <div class="check">✓</div>
        <div class="ic"><img src="https://cv111.site/pay/images/images.png" alt="bKash"></div>
        <div><div class="name">bKash</div><div class="tag">Instant</div></div>
      </div>
      <div class="method" id="dmtd-2" onclick="selectMethod('2')">
        <div class="check">✓</div>
        <div class="ic"><img src="https://cv111.site/pay/images/unnamed.png" alt="Nagad"></div>
        <div><div class="name">Nagad</div><div class="tag">Instant</div></div>
      </div>
    </div>

    <p class="section-title">Select Channel</p>
    <div id="channelList"><div class="center">লোড হচ্ছে...</div></div>

    <!-- ✅ নতুন যোগ — First-Deposit-Bonus (Optional Toggle) -->
    <div style="background:linear-gradient(135deg, rgba(245,197,66,.12), rgba(245,197,66,.02)); border:1.5px solid rgba(245,197,66,.4); border-radius:14px; padding:14px; margin-bottom:14px;">
        <label style="display:flex; align-items:center; gap:10px; cursor:pointer;">
            <input type="checkbox" id="wantsBonusToggle" style="width:20px; height:20px; accent-color:#F5C542; flex-shrink:0;">
            <div>
                <div style="font-weight:800; font-size:13.5px; color:#fff;">🎁 প্রথম Deposit-এ ১৫০% Bonus নিন!</div>
                <div style="font-size:11px; color:var(--muted); margin-top:3px;">শর্ত: Deposit+Bonus-এর ২০ গুণ Bet না করা পর্যন্ত Withdraw করা যাবে না। নেবে না চাইলে, খালি রাখো — Normal-ভাবে Deposit হবে।</div>
            </div>
        </label>
    </div>

    <p class="section-title">Deposit Amount</p>
    <div class="amount-box" id="customAmountBox" style="background:var(--card); border:1.5px solid var(--border); border-radius:16px; padding:16px; margin-bottom:14px;">
        <div style="font-size:11px; color:var(--muted); font-weight:700; text-transform:uppercase; letter-spacing:.5px; margin-bottom:8px;">নিজে Amount লিখো</div>
        <div style="display:flex; align-items:center; gap:10px;">
            <span style="font-size:22px; font-weight:800; color:var(--gold);">৳</span>
            <input type="number" id="customAmount" placeholder="যেমন: 240" oninput="onCustomAmountInput()" style="flex:1; background:none; border:none; outline:none; color:var(--text); font-size:22px; font-weight:800; font-family:'Poppins';">
        </div>
    </div>
    <div class="amounts" id="amountsList"></div>

    <button class="btn-submit" onclick="proceedDeposit()">Continue করো →</button>
  </div>

<script>
const token = localStorage.getItem('token');
if (!token) window.location.href = '/newlogin.php';

let currentPayId = '2';
let currentChannel = null;
let currentAmount = null;
let allChannels = [];

function md5(str) {
    function rotateLeft(n, s) { return (n << s) | (n >>> (32 - s)); }
    function toHex(n) { let s = '', v; for (let i = 0; i < 4; i++) { v = (n >>> (i * 8)) & 255; s += ('0' + v.toString(16)).slice(-2); } return s; }
    function utf8Encode(str) { return unescape(encodeURIComponent(str)); }
    str = utf8Encode(str);
    const msgLen = str.length;
    const numBlocks = (((msgLen + 8) >>> 6) + 1) * 16;
    const M = new Array(numBlocks).fill(0);
    for (let i = 0; i < msgLen; i++) M[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8);
    M[msgLen >> 2] |= 0x80 << ((msgLen % 4) * 8);
    M[numBlocks - 2] = msgLen * 8;
    let a = 1732584193, b = -271733879, c = -1732584194, d = 271733878;
    const S = [7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21];
    const K = [];
    for (let i = 0; i < 64; i++) K[i] = (Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296)) | 0;
    for (let i = 0; i < numBlocks; i += 16) {
        let A = a, B = b, C = c, D = d;
        for (let j = 0; j < 64; j++) {
            let F, g;
            if (j < 16) { F = (B & C) | (~B & D); g = j; }
            else if (j < 32) { F = (D & B) | (~D & C); g = (5 * j + 1) % 16; }
            else if (j < 48) { F = B ^ C ^ D; g = (3 * j + 5) % 16; }
            else { F = C ^ (B | ~D); g = (7 * j) % 16; }
            F = (F + A + K[j] + (M[i + g] | 0)) | 0;
            A = D; D = C; C = B;
            B = (B + rotateLeft(F, S[j])) | 0;
        }
        a = (a + A) | 0; b = (b + B) | 0; c = (c + C) | 0; d = (d + D) | 0;
    }
    return toHex(a) + toHex(b) + toHex(c) + toHex(d);
}

function showMsg(text, ok){
    document.getElementById('msgBox').innerHTML = `<div class="msg ${ok ? 'msg-ok' : 'msg-err'}"><i class="fa-solid fa-circle-exclamation"></i> ${text}</div>`;
}

async function loadBalance() {
    const random = Math.random().toString(36).substring(2, 15);
    const shonustr = `{"language":1,"random":"${random}"}`;
    const signature = md5(shonustr).toUpperCase();
    try {
        const res = await fetch('/deepanshu/api/webapi/GetBalance.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
            body: JSON.stringify({ language: 1, random, signature, timestamp: Date.now() })
        });
        const data = await res.json();
        if (data.code === 0 && data.data) {
            document.getElementById('cashBalance').textContent = Number(data.data.amount).toLocaleString('en-IN', {maximumFractionDigits: 2});
        }
    } catch (e) {}
}

async function loadChannels(payid) {
    document.getElementById('channelList').innerHTML = '<div class="center">লোড হচ্ছে...</div>';
    const random = Math.random().toString(36).substring(2, 15);
    const shonustr = `{"language":1,"payTypeId":0,"payid":${payid},"random":"${random}"}`;
    const signature = md5(shonustr).toUpperCase();
    try {
        const res = await fetch('/deepanshu/api/webapi/GetRechargeTypes.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
            body: JSON.stringify({ language: 1, payTypeId: 0, payid: Number(payid), random, signature, timestamp: Date.now() })
        });
        const data = await res.json();
        allChannels = (data.data && Object.values(data.data.rechargetypelist || {})) || [];
        renderChannels();
    } catch (e) {
        document.getElementById('channelList').innerHTML = '<div class="center">Load ব্যর্থ হয়েছে।</div>';
    }
}

function renderChannels() {
    const container = document.getElementById('channelList');
    container.innerHTML = '';
    if (allChannels.length === 0) { container.innerHTML = '<div class="center">কোনো Channel নেই।</div>'; return; }
    allChannels.forEach((ch, i) => {
        const div = document.createElement('div');
        div.className = 'channel-item' + (i === 0 ? ' active' : '');
        div.innerHTML = `
            <div style="display:flex; align-items:center; gap:12px;">
                <div style="width:38px; height:38px; border-radius:11px; background:linear-gradient(135deg, rgba(155,93,229,.2), rgba(155,93,229,.05)); display:flex; align-items:center; justify-content:center; flex-shrink:0;">
                    <i class="fa-solid fa-building-columns" style="color:var(--purple); font-size:15px;"></i>
                </div>
                <div>
                    <div class="name">${ch.payName}</div>
                    <div class="limit">Limit: ৳${ch.miniPrice} - ৳${ch.maxPrice}</div>
                </div>
            </div>
        `;
        div.onclick = () => selectChannel(ch, div);
        container.appendChild(div);
    });
    selectChannel(allChannels[0], container.children[0]);
}

function selectChannel(channel, el) {
    document.querySelectorAll('.channel-item').forEach(e => e.classList.remove('active'));
    el.classList.add('active');
    currentChannel = channel;
    renderAmounts(channel);
}

function renderAmounts(channel) {
    const container = document.getElementById('amountsList');
    container.innerHTML = '';
    const list = channel.quickConfigList || [{rechargeAmount: channel.miniPrice}];
    list.forEach((q, i) => {
        const div = document.createElement('div');
        div.className = 'amount-chip' + (i === 0 ? ' active' : '');
        div.textContent = '৳' + q.rechargeAmount;
        div.onclick = () => selectAmount(q.rechargeAmount, div);
        container.appendChild(div);
    });
    if (list[0]) currentAmount = list[0].rechargeAmount;
}

function selectAmount(amount, el) {
    document.querySelectorAll('.amount-chip').forEach(e => e.classList.remove('active'));
    el.classList.add('active');
    currentAmount = amount;
    document.getElementById('customAmount').value = '';
    document.getElementById('customAmountBox').style.borderColor = 'var(--border)';
}

function onCustomAmountInput() {
    const val = parseFloat(document.getElementById('customAmount').value);
    document.querySelectorAll('.amount-chip').forEach(e => e.classList.remove('active'));
    document.getElementById('customAmountBox').style.borderColor = val > 0 ? 'var(--purple)' : 'var(--border)';
    if (val > 0) currentAmount = val;
}

function selectMethod(payid) {
    currentPayId = payid;
    document.getElementById('dmtd-1').classList.toggle('active', payid === '1');
    document.getElementById('dmtd-2').classList.toggle('active', payid === '2');
    loadChannels(payid);
}

function proceedDeposit() {
    if (!currentChannel || !currentAmount) { showMsg('একটা Channel/Amount বেছে নাও।', false); return; }
    if (currentAmount < currentChannel.miniPrice || currentAmount > currentChannel.maxPrice) {
        showMsg(`Amount ৳${currentChannel.miniPrice} থেকে ৳${currentChannel.maxPrice}-এর মধ্যে হতে হবে।`, false);
        return;
    }
    let uid = 0;
    try { uid = JSON.parse(atob(token.split('.')[1])).id || 0; } catch (e) {}
    const wantsBonus = document.getElementById('wantsBonusToggle').checked ? '1' : '0';

    // ✅ Fix — এখন getaway.winbigplay6.site-এর pay/ ফোল্ডারে (key সহ) পাঠাচ্ছে
    const PAYMENT_KEY = 'pk_696bce9caafa58193521115b';
    const targetUrl = currentPayId === '2'
        ? 'https://getaway.winbigplay6.site/pay/nagad.php'
        : 'https://getaway.winbigplay6.site/pay/bkash.php';
    window.location.href = targetUrl + '?key=' + PAYMENT_KEY + '&amount=' + currentAmount + '&uid=' + uid;
}

loadBalance();
loadChannels(currentPayId);
</script>
</body>
</html>
