<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<title>Wallet - 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; --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%), var(--bg); padding-bottom:40px;}
  .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:28px 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);}
  .balance-hero::before{content:''; position:absolute; width:200px; height:200px; border-radius:50%;
    background:radial-gradient(circle, rgba(155,93,229,.25), transparent 70%); top:-80px; 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:40px; font-weight:900; margin-top:8px; position:relative; z-index:1;
    background:linear-gradient(135deg,#fff,#D8CCFA); -webkit-background-clip:text; background-clip:text; color:transparent;}
  .balance-hero .amt span{font-size:22px; opacity:.7; margin-right:4px;}
  .refresh-btn{position:absolute; top:24px; right:24px; width:38px; height:38px; border-radius:12px; background:rgba(255,255,255,.08);
    border:1px solid var(--border); color:var(--gold); display:flex; align-items:center; justify-content:center; z-index:2; cursor:pointer;}
  .refresh-btn.spin i{animation:spin .6s linear;}
  @keyframes spin{to{transform:rotate(360deg);}}

  .actions-row{display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:24px;}
  .action-card{background:var(--card); border:1.5px solid var(--border); border-radius:18px; padding:20px 14px; text-align:center; text-decoration:none; color:var(--text); transition:.15s;}
  .action-card:active{transform:scale(.96);}
  .action-icon{width:50px; height:50px; border-radius:16px; margin:0 auto 10px; display:flex; align-items:center; justify-content:center; font-size:20px;}
  .action-card span{font-weight:700; font-size:13.5px;}

  .section-title{font-size:14px; font-weight:800; margin:0 0 14px;}
  .quick-links{display:flex; flex-direction:column; gap:10px;}
  .quick-link{display:flex; align-items:center; gap:14px; background:var(--card); border:1.5px solid var(--border); border-radius:16px; padding:16px; text-decoration:none; color:var(--text);}
  .quick-link .ic{width:42px; height:42px; border-radius:12px; display:flex; align-items:center; justify-content:center; font-size:17px; flex-shrink:0;}
  .quick-link .info{flex:1;}
  .quick-link .name{font-weight:700; font-size:14px;}
  .quick-link .desc{font-size:11.5px; color:var(--muted); margin-top:2px;}
</style>
</head>
<body>
  <div class="top"><a href="/newhome.php">←</a><h1>Wallet</h1></div>
  <div class="wrap">

    <div class="balance-hero">
      <button class="refresh-btn" id="refreshBtn" onclick="refreshBalance()"><i class="fa-solid fa-rotate"></i></button>
      <div class="lab">Total Balance</div>
      <div class="amt"><span>৳</span><span id="cashBalance">0</span></div>
    </div>

    <div class="actions-row">
      <a href="/newdeposit_panel.php" class="action-card">
        <div class="action-icon" style="background:linear-gradient(135deg, rgba(34,214,122,.2), rgba(34,214,122,.05));">
          <i class="fa-solid fa-arrow-down" style="color:#22D67A;"></i>
        </div>
        <span>Deposit</span>
      </a>
      <a href="/newwithdraw_premium.php" class="action-card">
        <div class="action-icon" style="background:linear-gradient(135deg, rgba(155,93,229,.2), rgba(155,93,229,.05));">
          <i class="fa-solid fa-arrow-up" style="color:var(--purple);"></i>
        </div>
        <span>Withdraw</span>
      </a>
    </div>

    <div class="section-title">দ্রুত যাও</div>
    <div class="quick-links">
      <a href="/newhistory.php" class="quick-link">
        <div class="ic" style="background:rgba(245,197,66,.15); color:var(--gold);"><i class="fa-solid fa-clock-rotate-left"></i></div>
        <div class="info"><div class="name">Transaction History</div><div class="desc">আগের সব Deposit/Withdraw দেখো</div></div>
        <i class="fa-solid fa-chevron-right" style="color:var(--muted);"></i>
      </a>
      <a href="/newsafe.php" class="quick-link">
        <div class="ic" style="background:rgba(34,214,122,.15); color:var(--green);"><i class="fa-solid fa-vault"></i></div>
        <div class="info"><div class="name">Safe / Vault</div><div class="desc">Balance আলাদা করে রাখো</div></div>
        <i class="fa-solid fa-chevron-right" style="color:var(--muted);"></i>
      </a>
      <a href="/newbonusterms.php" class="quick-link">
        <div class="ic" style="background:rgba(255,92,122,.15); color:var(--red);"><i class="fa-solid fa-gift"></i></div>
        <div class="info"><div class="name">Deposit Bonus</div><div class="desc">Bonus-এর নিয়ম দেখো</div></div>
        <i class="fa-solid fa-chevron-right" style="color:var(--muted);"></i>
      </a>
    </div>

  </div>

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

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);
}

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', {minimumFractionDigits: 2});
        }
    } catch (e) {
        document.getElementById('cashBalance').textContent = '--';
    }
}

function refreshBalance() {
    const btn = document.getElementById('refreshBtn');
    btn.classList.add('spin');
    loadBalance().finally(() => setTimeout(() => btn.classList.remove('spin'), 600));
}

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