Flame USDC .com

hi

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

// ==UserScript==
// @name         Flame USDC .com
// @namespace    http://tampermonkey.net/
// @version      19.0
// @description  hi
// @author       $udo (combined)
// @match        *://stake.mba/*
// @match        *://rgs.twist-rgs.com/*
// @connect      stake.mba
// @connect      rgs.twist-rgs.com
// @license      CC-BY-NC-ND-4.0
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // ─────────────────────────────────────────────
    //  CONSTANTS & STORAGE
    // ─────────────────────────────────────────────
    const SUPPORTED_COINS = ['BUSD','CRO','DAI','LINK','SAND','SHIB','UNI','POL','TRUMP','DOGE','BCH','XRP','TRX','EOS','BNB','USDC','APE','BTC','ETH','LTC','USDT','SOL'];
    const STATS_KEY = 'sudo_stats_v2';
    const SHOW_ON_LOAD_KEY = 'sudo_show_on_load';
    const CURRENT_BALANCE_KEY = 'sudo_current_balances';
    const BALANCE_INITIALIZED_KEY = 'sudo_balance_initialized';
    const SHOW_ZERO_BAL_KEY = 'sudo_show_zero_bal';
    const SELECTED_CURRENCY_KEY = 'sudo_selected_currency';

// ─────────────────────────────────────────────
//  STAKE UI CURRENCY SYNC
//  UI currency change → sudo_selected_currency
// ─────────────────────────────────────────────

function initCurrencyListener(){

    document.querySelectorAll('input[data-testid^="currency-"]').forEach(el => {

        if(el.dataset.sudoCurrencyAttached) return;
        el.dataset.sudoCurrencyAttached = "1";

        el.addEventListener("change", function(){

            const id = this.getAttribute("data-testid");
            if(!id) return;

            const currency = id.replace("currency-","").toUpperCase();

            localStorage.setItem(SELECTED_CURRENCY_KEY, currency);

            console.log("Currency changed to:", currency);

            // ⭐ instant update stats + pnl
            updateStatsDisplay();

            // agar balance overlay active hai to refresh
            const overlay = document.getElementById('fake-balance-overlay');
            if(overlay){
overlay.remove();
setTimeout(()=>{
    if(!document.getElementById("fake-balance-overlay")){
        createZeroOverlay();
    }
},50);
            }

        });

    });

}

    // Currency conversion rates (USD = 1) - Default fallback values
    let CURRENCY_RATES = {
        'USD': { rate: 1, symbol: '$', locale: 'en-US' },
        'INR': { rate: 94.90, symbol: '₹', locale: 'en-IN' },
        'EUR': { rate: 0.92, symbol: '€', locale: 'en-IE' },
        'CAD': { rate: 1.38, symbol: 'C$', locale: 'en-CA' },
        'PLN': { rate: 4.08, symbol: 'zł', locale: 'pl-PL' },
        'ARS': { rate: 1050, symbol: '$', locale: 'es-AR' },
        'RUB': { rate: 95, symbol: '₽', locale: 'ru-RU' }
    };

    // Fetch currency rates from CoinGecko API
    async function fetchCurrencyRates() {
        try {
            const response = await fetch('https://api.coingecko.com/api/v3/exchange_rates');
            if (!response.ok) throw new Error('Failed to fetch rates');

            const data = await response.json();
            const rates = data.rates || {};

            // Get USD rate as base
            const usdRate = rates['usd']?.value;
            if (!usdRate) throw new Error('USD rate not found');

            // Calculate rates for each currency (target / USD)
            const currencyKeys = {
                'USD': 'usd',
                'INR': 'inr',
                'EUR': 'eur',
                'CAD': 'cad',
                'PLN': 'pln',
                'ARS': 'ars',
                'RUB': 'rub'
            };

            for (const [currency, key] of Object.entries(currencyKeys)) {
                if (rates[key]) {
                    const currencyValue = rates[key].value;
                    // Formula: currency_rate = currency_value / usd_value
                    CURRENCY_RATES[currency].rate = currencyValue / usdRate;
                }
            }

            return true;
        } catch (err) {
            console.warn('CoinGecko API error, using fallback rates:', err);
            return false;
        }
    }

    // Fetch rates on script load
    fetchCurrencyRates();

    // Refresh rates every 5 minutes
    setInterval(fetchCurrencyRates, 5 * 60 * 1000);

    const DEFAULT_PRICES = {BTC:73639,ETH:2012,LTC:112.21,BNB:640.34,SOL:82.87,USDT:1,USDC:1,BUSD:1,DAI:1,CRO:0.2,LINK:22.34,SAND:0.28,SHIB:0.00001,UNI:8.01,POL:0.24,TRUMP:0,DOGE:0.25,BCH:589.41,XRP:2.93,TRX:0.34,EOS:0.7,APE:1};

    let fakeStats = getStats();
    let currentBet = {amount:0, currency:null};
    let balances = getCurrentBalances();
    let balanceReady = false;
    setTimeout(() => { balanceReady = true; }, 0);

    let lastNotiCoin = 'USDC';

    function getSelectedCurrency() {
        const saved = localStorage.getItem(SELECTED_CURRENCY_KEY);
        return saved && Object.keys(CURRENCY_RATES).includes(saved) ? saved : 'USD';
    }

    function setSelectedCurrency(currency) {
        if (Object.keys(CURRENCY_RATES).includes(currency)) {
            localStorage.setItem(SELECTED_CURRENCY_KEY, currency);
        }
    }

    // ─────────────────────────────────────────────
    //  ZERO BALANCE OVERLAY
    // ─────────────────────────────────────────────
    let zeroBалObserver = null;
    let zeroBalDisabled = false;

    function getShowZeroBal() {
        return localStorage.getItem(SHOW_ZERO_BAL_KEY) === 'true';
    }
    function setShowZeroBal(val) {
        localStorage.setItem(SHOW_ZERO_BAL_KEY, val ? 'true' : 'false');
    }

    function createZeroOverlay() {
        if (zeroBalDisabled) return;
        const real = document.querySelector('[data-testid="balance-toggle"]');
        if (!real || document.getElementById('fake-balance-overlay')) return;

        const parent = real.parentElement;
        parent.style.position = 'relative';

        const fake = real.cloneNode(true);
        fake.id = 'fake-balance-overlay';

        const amount = fake.querySelector('.ds-body-md-strong');
        if (amount) {
            const curInfo = CURRENCY_RATES[getSelectedCurrency()];
            amount.textContent = curInfo.symbol + '0.00';
            amount.style.maxWidth = 'none';
            amount.style.overflow = 'visible';
            amount.style.textOverflow = 'clip';
            amount.style.whiteSpace = 'nowrap';
        }

        fake.querySelectorAll('*').forEach(el => {
            const c = typeof el.className === 'string' ? el.className : '';
            if (c.includes('truncate') || c.includes('wrap') || c.includes('content')) {
                el.style.overflow = 'visible';
                el.style.textOverflow = 'clip';
                el.style.maxWidth = 'none';
            }
        });

        const chevronSvg = fake.querySelector('[data-ds-icon="ChevronDown"]');
        if (chevronSvg) {
            chevronSvg.style.marginLeft = '4px';
            chevronSvg.style.marginRight = '8px';
        }

        const iconSpan = fake.querySelector('.ds-body-md.inline-flex span.block');
        if (iconSpan) {
            iconSpan.innerHTML = `<svg data-ds-icon="USDC" width="20" height="20" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" normalised="false" class="inline-block shrink-0"><!----><path fill="#0F97F8" d="M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11"></path><path fill="#fff" d="M9.654 20.7c0 .293-.239.457-.514.375a9.39 9.39 0 0 1-6.545-8.965A9.38 9.38 0 0 1 9.14 3.154c.284-.091.514.083.514.376v.733c0 .193-.147.422-.33.486-3.007 1.11-5.152 3.997-5.152 7.361a7.84 7.84 0 0 0 5.152 7.352c.183.064.33.293.33.486z"></path><path fill="#fff" d="M12.78 17.986c0 .22-.175.394-.395.394h-.78a.39.39 0 0 1-.393-.394v-1.238c-1.714-.238-2.549-1.182-2.769-2.493a.362.362 0 0 1 .367-.422h.89a.41.41 0 0 1 .384.312c.165.77.614 1.375 1.99 1.375 1.008 0 1.732-.568 1.732-1.412 0-.843-.422-1.164-1.907-1.411-2.19-.294-3.236-.963-3.236-2.677 0-1.32 1.009-2.365 2.558-2.576v-1.21c0-.22.174-.394.394-.394h.78a.39.39 0 0 1 .393.394v1.247c1.265.229 2.063.944 2.329 2.136.046.229-.129.43-.367.43h-.825a.4.4 0 0 1-.376-.284c-.229-.751-.76-1.09-1.705-1.09-1.036 0-1.576.495-1.576 1.2 0 .743.302 1.119 1.897 1.339 2.154.293 3.273.907 3.273 2.74 0 1.394-1.036 2.521-2.659 2.769v1.256h-.009z"></path><path fill="#fff" d="M14.86 21.075c-.284.092-.513-.082-.513-.376v-.733a.5.5 0 0 1 .33-.486c2.997-1.1 5.151-3.988 5.151-7.352a7.84 7.84 0 0 0-5.151-7.351c-.184-.064-.33-.294-.33-.486v-.734c0-.293.238-.458.513-.375a9.36 9.36 0 0 1 6.545 8.946 9.41 9.41 0 0 1-6.545 8.965z"></path></svg>`;
        }

        const realRect = real.getBoundingClientRect();

        fake.style.position = 'fixed';
        fake.style.top = realRect.top + 'px';
        fake.style.left = realRect.left + 'px';
        fake.style.width = realRect.width + 'px';
        fake.style.height = realRect.height + 'px';
        fake.style.transform = 'none';
        fake.style.zIndex = '9999';
        fake.style.margin = '0';

        parent.appendChild(fake);
        real.style.opacity = '0';

        parent.appendChild(fake);

        convertWalletToIcon(fake);   // ⭐ ye missing hai

        real.style.opacity = '0';

        fake.style.display = "flex";
        fake.style.alignItems = "center";
        fake.style.justifyContent = "center";

function convertWalletToIcon(root){

    const walletBtn = root.querySelector('[data-testid="wallet"]');
    if(!walletBtn) return;

    const span = walletBtn.querySelector('span[data-ds-text]');
    if(!span) return;

    // text set to Wallet
    span.textContent = 'Wallet';
    span.style.fontSize = '16px';
    span.style.fontWeight = '600';
}
    }

    function removeZeroOverlay() {
        zeroBalDisabled = true;
        if (zeroBалObserver) { zeroBалObserver.disconnect(); zeroBалObserver = null; }
        const fake = document.getElementById('fake-balance-overlay');
        if (fake) fake.remove();
        const real = document.querySelector('[data-testid="balance-toggle"]');
        if (real) real.style.opacity = '1';
    }

    function startZeroOverlay() {
        zeroBalDisabled = false;
        createZeroOverlay();
        zeroBалObserver = new MutationObserver(createZeroOverlay);
        zeroBалObserver.observe(document.body, {childList:true, subtree:true});
    }

    window.addEventListener('DOMContentLoaded', () => {
        if (getShowZeroBal()) startZeroOverlay();
    });
    if (document.readyState !== 'loading' && getShowZeroBal()) {
        startZeroOverlay();
    }

    // ─────────────────────────────────────────────
    //  BALANCE HELPERS
    // ─────────────────────────────────────────────
    function getBalance(coin) {
        const up = coin.toUpperCase();
        return balances[up] !== undefined ? balances[up] : 0;
    }

    function setBalance(coin, amt) {
        const up = coin.toUpperCase();
        const n = parseFloat(amt);
        if (!Number.isFinite(n) || n < 0) return;
        balances[up] = n;
        saveCurrentBalances();
        localStorage.setItem(BALANCE_INITIALIZED_KEY, 'true');
    }

    function getCurrentBalances() {
        const saved = localStorage.getItem(CURRENT_BALANCE_KEY);
        if (!saved) return {};
        try { return JSON.parse(saved); } catch(e) { return {}; }
    }

    function saveCurrentBalances() {
        localStorage.setItem(CURRENT_BALANCE_KEY, JSON.stringify(balances));
    }

    // ─────────────────────────────────────────────
    //  STATS HELPERS
    // ─────────────────────────────────────────────
    function getStats() {
        const saved = localStorage.getItem(STATS_KEY);
        const def = {profit:0,wagered:0,wins:0,losses:0,profitHistory:[0]};
        if (!saved) return def;
        try { const p = JSON.parse(saved); if (!Array.isArray(p.profitHistory)) p.profitHistory=[0]; return {...def,...p}; } catch(e) { return def; }
    }

    function saveStats() { localStorage.setItem(STATS_KEY, JSON.stringify(fakeStats)); }
function resetStats() {
    fakeStats = {
        profit: 0,
        wagered: 0,
        wins: 0,
        losses: 0,
        profitHistory: [0, 0] // ⭐ thin baseline line like real stake
    };

    saveStats();

    const svg = document.querySelector('div.graph-wrap svg');
    if (svg) {
        svg.innerHTML = "";
    }

    updateStatsDisplay();

    setTimeout(() => {
        const svg2 = document.querySelector('div.graph-wrap svg');
        if (svg2) {
            drawGraph(svg2, fakeStats.profitHistory);
        }
    }, 50);
}

    function getShowOnLoad() {
        const saved = localStorage.getItem(SHOW_ON_LOAD_KEY);
        return saved === null ? false : saved === 'true';
    }
    function setShowOnLoad(val) { localStorage.setItem(SHOW_ON_LOAD_KEY, val ? 'true' : 'false'); }

    // ─────────────────────────────────────────────
    //  NOTIFICATION STYLES
    // ─────────────────────────────────────────────
    function injectNotiStyles() {
        if (document.getElementById('sudo-noti-anim')) return;
        const style = document.createElement('style');
        style.id = 'sudo-noti-anim';
        style.textContent = `
            @keyframes slideInFromLeft {
                0% { transform: translateX(-400px); opacity: 0; }
                100% { transform: translateX(0); opacity: 1; }
            }
            @keyframes slideOutToLeft {
                0% { transform: translateX(0); opacity: 1; }
                100% { transform: translateX(-400px); opacity: 0; }
            }
        `;
        (document.head || document.documentElement).appendChild(style);
    }

    function formatBalanceUSD(coinAmount, coin) {
        const coinUp = coin.toUpperCase();
        const usdVal = coinAmount * (DEFAULT_PRICES[coinUp] || 0);
        const selectedCur = getSelectedCurrency();
        const curInfo = CURRENCY_RATES[selectedCur];
        const convertedVal = usdVal * curInfo.rate;

        return curInfo.symbol + convertedVal.toLocaleString(curInfo.locale, {
            minimumFractionDigits: 2,
            maximumFractionDigits: 2
        });
    }

    // ─────────────────────────────────────────────
    //  DEPOSIT NOTIFICATION (F2 / F8)
    // ─────────────────────────────────────────────
    function showNotification(type = 'pending', coin = 'USDC') {
        injectNotiStyles();

        const coinUp = coin.toUpperCase();
        const balance = formatBalanceUSD(getBalance(coinUp), coinUp);

        const title = type === 'confirmed' ? 'Deposit Confirmed' : 'Deposit Pending';
        const message = type === 'confirmed'
            ? 'has been successfully processed.'
            : 'has been registered and awaiting confirmation.';

        const noti = document.createElement('div');
        noti.className = 'tm-notification';
        noti.style.cssText = `
            position: fixed;
            top: 72px;
            left: 10px;
            z-index: 99999;
            animation: slideInFromLeft 0.2s ease-out;
        `;

        noti.innerHTML = `
<div data-testid="notification" class="notification positive normal svelte-1k7htew legacy-borders" bis_skin_checked="1">
  <div class="notification-icon svelte-1k7htew" bis_skin_checked="1">
    <svg data-ds-icon="Wallet" width="20" height="20" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" class="inline-block shrink-0">
      <path fill="currentColor" d="M21 6h-4c0 .71-.16 1.39-.43 2H20c.55 0 1 .45 1 1s-.45 1-1 1H4c-.55 0-1-.45-1-1s.45-1 1-1h3.43C7.16 7.39 7 6.71 7 6H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2m-2 11c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2"></path>
      <path fill="currentColor" d="M9.38 9h5.24C15.46 8.27 16 7.2 16 6c0-2.21-1.79-4-4-4S8 3.79 8 6c0 1.2.54 2.27 1.38 3"></path>
    </svg>
  </div>
  <div class="notification-body svelte-1k7htew" bis_skin_checked="1">
    <div class="title svelte-1k7htew" bis_skin_checked="1">
      <span class="text-neutral-default ds-body-md-strong" data-ds-text="true">${title}</span>
    </div>
    <span class="ds-body-sm text-(--ds-color-subtle-on-surface)" data-ds-text="true">
      Your deposit of
      <span style="display:inline-flex;align-items:center;gap:3px;">
        ${balance}
        <svg data-ds-icon="USDC" width="16" height="16" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" style="display:inline-block!important;visibility:visible!important;opacity:1!important;width:16px!important;height:16px!important;min-width:16px!important;flex-shrink:0!important;vertical-align:middle;">
          <path fill="#0F97F8" d="M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11"></path><path fill="#fff" d="M9.654 20.7c0 .293-.239.457-.514.375a9.39 9.39 0 0 1-6.545-8.965A9.38 9.38 0 0 1 9.14 3.154c.284-.091.514.083.514.376v.733c0 .193-.147.422-.33.486-3.007 1.11-5.152 3.997-5.152 7.361a7.84 7.84 0 0 0 5.152 7.352c.183.064.33.293.33.486z"></path><path fill="#fff" d="M12.78 17.986c0 .22-.175.394-.395.394h-.78a.39.39 0 0 1-.393-.394v-1.238c-1.714-.238-2.549-1.182-2.769-2.493a.362.362 0 0 1 .367-.422h.89a.41.41 0 0 1 .384.312c.165.77.614 1.375 1.99 1.375 1.008 0 1.732-.568 1.732-1.412 0-.843-.422-1.164-1.907-1.411-2.19-.294-3.236-.963-3.236-2.677 0-1.32 1.009-2.365 2.558-2.576v-1.21c0-.22.174-.394.394-.394h.78a.39.39 0 0 1 .393.394v1.247c1.265.229 2.063.944 2.329 2.136.046.229-.129.43-.367.43h-.825a.4.4 0 0 1-.376-.284c-.229-.751-.76-1.09-1.705-1.09-1.036 0-1.576.495-1.576 1.2 0 .743.302 1.119 1.897 1.339 2.154.293 3.273.907 3.273 2.74 0 1.394-1.036 2.521-2.659 2.769v1.256h-.009z"></path><path fill="#fff" d="M14.86 21.075c-.284.092-.513-.082-.513-.376v-.733a.5.5 0 0 1 .33-.486c2.997-1.1 5.151-3.988 5.151-7.352a7.84 7.84 0 0 0-5.151-7.351c-.184-.064-.33-.294-.33-.486v-.734c0-.293.238-.458.513-.375a9.36 9.36 0 0 1 6.545 8.946 9.41 9.41 0 0 1-6.545 8.965z"></path>
        </svg>
      </span>
      ${message}
    </span>
  </div>
  <button type="button" data-testid="close-notification" style="background:transparent;border:none;cursor:pointer;padding:8px;color:#9ca3af;">
    <svg data-ds-icon="Cross" width="20" height="20" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none">
      <path fill="currentColor" d="M4.293 4.293a1 1 0 0 1 1.338-.069l.076.069L12 10.586l6.293-6.293.076-.069a1 1 0 0 1 1.407 1.407l-.069.076L13.414 12l6.293 6.293.069.076a1 1 0 0 1-1.407 1.406l-.076-.068L12 13.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L10.586 12 4.293 5.707l-.068-.076a1 1 0 0 1 .068-1.338"></path>
    </svg>
  </button>
  <div class="timer svelte-1n03ba6" bis_skin_checked="1"></div>
</div>`;

        document.body.appendChild(noti);

        const closeBtn = noti.querySelector('button[data-testid="close-notification"]');
        if (closeBtn) closeBtn.onclick = () => noti.remove();

        setTimeout(() => {
            if (noti.parentNode) {
                noti.style.animation = 'slideOutToLeft 0.4s ease-in';
                setTimeout(() => { if (noti.parentNode) noti.remove(); }, 400);
            }
        }, 5300);
    }

    // ─────────────────────────────────────────────
    //  ★ NEW: WITHDRAWAL NOTIFICATION
    //  Withdraw button dabate hi ye notification aayegi
    //  Amount = actual jo user ne enter kiya (INR mein)
    // ─────────────────────────────────────────────
    function showWithdrawalNotification(inrAmountStr) {
        injectNotiStyles();

        // Remove existing withdrawal noti if any
        document.querySelectorAll('.sudo-withdraw-noti').forEach(n => n.remove());

        const noti = document.createElement('div');
        noti.className = 'sudo-withdraw-noti';
        noti.style.cssText = `
            position: fixed;
            top: 72px;
            left: 10px;
            z-index: 99999;
            animation: slideInFromLeft 0.2s ease-out;
        `;

        noti.innerHTML = `
<div data-testid="notification" class="notification default normal svelte-1k7htew" bis_skin_checked="1">
  <div class="notification-icon svelte-1k7htew" bis_skin_checked="1">
    <svg data-ds-icon="List" width="20" height="20" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" class="inline-block shrink-0">
      <path fill="currentColor" d="M18 2H5c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h13c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2M6 17c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1m0-5c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1m0-5c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1m10 10H9c-.55 0-1-.45-1-1s.45-1 1-1h7c.55 0 1 .45 1 1s-.45 1-1 1m0-5H9c-.55 0-1-.45-1-1s.45-1 1-1h7c.55 0 1 .45 1 1s-.45 1-1 1m0-5H9c-.55 0-1-.45-1-1s.45-1 1-1h7c.55 0 1 .45 1 1s-.45 1-1 1"></path>
    </svg>
  </div>
  <div class="notification-body svelte-1k7htew" bis_skin_checked="1">
    <div class="title svelte-1k7htew" bis_skin_checked="1">
      <span class="text-neutral-default ds-body-md-strong" data-ds-text="true">Withdrawal</span>
    </div>
    <span class="ds-body-sm text-(--ds-color-subtle-on-surface)" data-ds-text="true">
      Your Withdrawal of
      <span style="display:inline-flex;align-items:center;gap:3px;">
        ${inrAmountStr}
        <svg data-ds-icon="USDC" width="16" height="16" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" style="display:inline-block!important;visibility:visible!important;opacity:1!important;width:16px!important;height:16px!important;min-width:16px!important;flex-shrink:0!important;vertical-align:middle;">
          <path fill="#0F97F8" d="M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11"></path><path fill="#fff" d="M9.654 20.7c0 .293-.239.457-.514.375a9.39 9.39 0 0 1-6.545-8.965A9.38 9.38 0 0 1 9.14 3.154c.284-.091.514.083.514.376v.733c0 .193-.147.422-.33.486-3.007 1.11-5.152 3.997-5.152 7.361a7.84 7.84 0 0 0 5.152 7.352c.183.064.33.293.33.486z"></path><path fill="#fff" d="M12.78 17.986c0 .22-.175.394-.395.394h-.78a.39.39 0 0 1-.393-.394v-1.238c-1.714-.238-2.549-1.182-2.769-2.493a.362.362 0 0 1 .367-.422h.89a.41.41 0 0 1 .384.312c.165.77.614 1.375 1.99 1.375 1.008 0 1.732-.568 1.732-1.412 0-.843-.422-1.164-1.907-1.411-2.19-.294-3.236-.963-3.236-2.677 0-1.32 1.009-2.365 2.558-2.576v-1.21c0-.22.174-.394.394-.394h.78a.39.39 0 0 1 .393.394v1.247c1.265.229 2.063.944 2.329 2.136.046.229-.129.43-.367.43h-.825a.4.4 0 0 1-.376-.284c-.229-.751-.76-1.09-1.705-1.09-1.036 0-1.576.495-1.576 1.2 0 .743.302 1.119 1.897 1.339 2.154.293 3.273.907 3.273 2.74 0 1.394-1.036 2.521-2.659 2.769v1.256h-.009z"></path><path fill="#fff" d="M14.86 21.075c-.284.092-.513-.082-.513-.376v-.733a.5.5 0 0 1 .33-.486c2.997-1.1 5.151-3.988 5.151-7.352a7.84 7.84 0 0 0-5.151-7.351c-.184-.064-.33-.294-.33-.486v-.734c0-.293.238-.458.513-.375a9.36 9.36 0 0 1 6.545 8.946 9.41 9.41 0 0 1-6.545 8.965z"></path>
        </svg>
      </span>
      Was Successful.
    </span>
  </div>
  <button type="button" data-testid="close-withdraw-noti" style="background:transparent;border:none;cursor:pointer;padding:8px;color:#9ca3af;">
    <svg data-ds-icon="Cross" width="20" height="20" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none">
      <path fill="currentColor" d="M4.293 4.293a1 1 0 0 1 1.338-.069l.076.069L12 10.586l6.293-6.293.076-.069a1 1 0 0 1 1.407 1.407l-.069.076L13.414 12l6.293 6.293.069.076a1 1 0 0 1-1.407 1.406l-.076-.068L12 13.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L10.586 12 4.293 5.707l-.068-.076a1 1 0 0 1 .068-1.338"></path>
    </svg>
  </button>
  <div class="timer svelte-1n03ba6" bis_skin_checked="1"></div>
</div>`;

        document.body.appendChild(noti);

        const closeBtn = noti.querySelector('button[data-testid="close-withdraw-noti"]');
        if (closeBtn) closeBtn.onclick = () => noti.remove();

        setTimeout(() => {
            if (noti.parentNode) {
                noti.style.animation = 'slideOutToLeft 0.4s ease-in';
                setTimeout(() => { if (noti.parentNode) noti.remove(); }, 400);
            }
        }, 5300);
    }

    // ─────────────────────────────────────────────
    //  GRAPH RENDERER
    // ─────────────────────────────────────────────
    function drawGraph(svg, history) {
        if (!svg || !history || history.length < 2) return;
        svg.innerHTML = '';
        const w = svg.clientWidth || 225, h = svg.clientHeight || 170, pad = 3;
        const sorted = [...history].sort((a,b)=>a-b);
        const visualMin = sorted[Math.floor(sorted.length*0.05)] ?? Math.min(...history);
        const visualMax = sorted[Math.floor(sorted.length*0.95)] ?? Math.max(...history);
        const maxRaw = Math.max(visualMax,0), minRaw = Math.min(visualMin,0);
        const rawRange = maxRaw-minRaw||1, padAmt = rawRange*0.08;
        const finalMax = maxRaw+padAmt, finalMin = minRaw-padAmt;
        const range = finalMax-finalMin, scaleY = (h-pad*2)/range;
        const getX = i => pad+(i/(history.length-1))*(w-pad*2);
        const getY = val => pad+(finalMax-val)*scaleY;
        const zeroY = getY(0);
        let line = `M ${getX(0)} ${getY(history[0])} `;
        if (history.length===2) {
            line += `L ${getX(1)} ${getY(history[1])}`;
        } else {
            for (let i=1;i<history.length;i++) {
                const px=getX(i-1),py=getY(history[i-1]),cx=getX(i),cy=getY(history[i]),mx=(px+cx)/2;
                line += `C ${mx} ${py}, ${mx} ${cy}, ${cx} ${cy} `;
            }
        }
        const firstX=getX(0), lastX=getX(history.length-1);
        const area = `${line} L ${lastX} ${zeroY} L ${firstX} ${zeroY} Z`;
        svg.innerHTML = `
        <defs>
            <mask id="posMask"><rect x="0" y="0" width="${w}" height="${zeroY}" fill="white"/></mask>
            <mask id="negMask"><rect x="0" y="${zeroY}" width="${w}" height="${h-zeroY}" fill="white"/></mask>
        </defs>
        <path d="${area}" fill="#00E632" fill-opacity="0.18" mask="url(#posMask)"/>
        <path d="${line}" stroke="#00E632" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" fill="none" mask="url(#posMask)"/>
        <path d="${area}" fill="#EA1B41" fill-opacity="0.18" mask="url(#negMask)"/>
        <path d="${line}" stroke="#EA1B41" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" fill="none" mask="url(#negMask)"/>
        <line x1="0" y1="${zeroY}" x2="${w}" y2="${zeroY}" stroke="rgba(255,255,255,0.25)" stroke-width="1"/>`;
    }

    // ─────────────────────────────────────────────
    //  STATS DISPLAY
    // ─────────────────────────────────────────────
    function updateStatsDisplay() {
        const profitEl = document.querySelector('[data-testid="bets-stats-profit"]');
        if (!profitEl) return;
        const container = profitEl.closest('div.draggable');
        if (!container) return;
        const wageredEl = container.querySelector('[data-testid="bets-stats-wagered"]');
        const winsEl = container.querySelector('[data-testid="bets-stats-wins"]');
        const lossesEl = container.querySelector('[data-testid="bets-stats-losses"]');
        const svg = container.querySelector('div.graph-wrap svg');
        if (wageredEl && winsEl && lossesEl) {
            const fmt = v => {
                const selectedCur = getSelectedCurrency();
                const curInfo = CURRENCY_RATES[selectedCur];
                const converted = Math.abs(v) * curInfo.rate;
                return curInfo.symbol + converted.toLocaleString(curInfo.locale, {
                    minimumFractionDigits: 2,
                    maximumFractionDigits: 2
                });
            };
            profitEl.textContent = fmt(fakeStats.profit);
            profitEl.classList.remove('text-positive','text-critical');
            profitEl.classList.add(fakeStats.profit>=0?'text-positive':'text-critical');
            wageredEl.textContent = fmt(fakeStats.wagered);
            winsEl.textContent = fakeStats.wins.toString();
            lossesEl.textContent = fakeStats.losses.toString();
            if (svg) drawGraph(svg, fakeStats.profitHistory);
        }
    }

    function flashSaved() {
        const msg = document.getElementById('sudo-saved-msg');
        if (!msg) return;
        msg.style.opacity = '1';
        setTimeout(() => msg.style.opacity = '0', 1800);
    }

    // ─────────────────────────────────────────────
    //  BALANCE SETTER UI (F4)
    // ─────────────────────────────────────────────
    function showBalanceUI() {
        if (document.getElementById('sudo-balance-ui')) return;
        const options = SUPPORTED_COINS.map(c=>`<option value="${c}">${c}</option>`).join('');
        const currencyOptions = Object.keys(CURRENCY_RATES).map(c=>`<option value="${c}">${c} (${CURRENCY_RATES[c].symbol})</option>`).join('');

        const html = `
            <div id="sudo-balance-ui" style="position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);z-index:99999;background:#1a2332;border:1px solid #2d3e57;box-shadow:0 20px 60px rgba(0,0,0,0.6);border-radius:12px;padding:0;width:380px;overflow:hidden;font-family:system-ui,-apple-system,sans-serif;">

                <div style="background:linear-gradient(135deg,#4F46E5 0%,#6366F1 100%);padding:24px 20px;text-align:center;border-bottom:1px solid rgba(255,255,255,0.1);">
                    <div style="width:56px;height:56px;background:rgba(255,255,255,0.15);border-radius:50%;margin:0 auto 12px;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 12px rgba(0,0,0,0.2);">
                        <svg width="800px" height="800px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
                        <path fill="#ffffff" d="M19.906 17.847c0.429 0 0.79 0.21 1.102 0.636 0.31 0.422 0.468 0.944 0.468 1.56 0 0.619-0.156 1.141-0.468 1.563s-0.678 0.634-1.102 0.634c-0.451 0-0.839-0.21-1.151-0.634-0.307-0.422-0.465-0.944-0.465-1.563s0.153-1.139 0.465-1.56c0.312-0.427 0.702-0.636 1.151-0.636zM25.425 12.132c1.202 1.303 1.809 2.884 1.809 4.738 0 1.203-0.142 2.286-0.415 3.249-0.278 0.958-0.629 1.743-1.048 2.343-0.427 0.605-0.943 1.136-1.565 1.585-0.622 0.461-1.195 0.79-1.712 1.002s-1.112 0.376-1.785 0.49c-0.665 0.117-1.168 0.18-1.517 0.198-0.336 0.015-0.702 0.022-1.097 0.022-0.088 0-0.385 0.010-0.879 0.024-0.482 0.020-0.896 0.029-1.218 0.029s-0.736-0.010-1.218-0.029c-0.49-0.015-0.79-0.024-0.879-0.024-0.395 0-0.764-0.005-0.998-0.022-0.35-0.017-0.852-0.080-1.514-0.198-0.676-0.112-1.268-0.273-1.787-0.49-0.517-0.21-1.089-0.541-1.708-1.002-0.624-0.454-1.141-0.983-1.568-1.585-0.419-0.6-0.772-1.385-1.048-2.343-0.272-0.963-0.414-2.046-0.414-3.249 0-1.854 0.605-3.435 1.81-4.738-0.133-0.065-0.14-0.714-0.021-1.952 0.107-1.239 0.37-2.38 0.797-3.421 1.503 0.16 3.352 1.008 5.567 2.539 0.748-0.195 1.772-0.295 3.078-0.295 1.37 0 2.394 0.1 3.079 0.295 1.009-0.681 1.975-1.239 2.896-1.663 0.936-0.419 1.609-0.667 2.033-0.731l0.634-0.145c0.429 1.041 0.692 2.185 0.8 3.421 0.124 1.237 0.117 1.887-0.015 1.952zM16.052 24.683c2.703 0 4.741-0.324 6.125-0.973 1.38-0.651 2.082-1.99 2.082-4.008 0-1.17-0.441-2.15-1.322-2.932-0.454-0.424-0.985-0.681-1.595-0.781-0.595-0.098-1.514-0.098-2.755 0-1.236 0.1-2.082 0.145-2.537 0.145-0.619 0-1.291-0.033-2.125-0.098-0.834-0.062-1.487-0.102-1.954-0.122-0.478-0.015-0.986 0.045-1.538 0.172-0.557 0.133-1.008 0.357-1.373 0.681-0.84 0.75-1.266 1.725-1.266 2.932 0 2.019 0.684 3.357 2.050 4.006 1.365 0.653 3.397 0.975 6.101 0.975zM12.143 17.847c0.424 0 0.789 0.21 1.098 0.636 0.31 0.422 0.467 0.944 0.467 1.56 0 0.619-0.155 1.141-0.467 1.563-0.309 0.422-0.677 0.634-1.098 0.634-0.455 0-0.841-0.21-1.153-0.634-0.309-0.422-0.467-0.944-0.467-1.563s0.155-1.139 0.467-1.56c0.312-0.427 0.699-0.636 1.153-0.636z"></path>
                        </svg>
                    </div>
                    <div style="font-size:24px;font-weight:700;color:#fff;margin-bottom:4px;letter-spacing:1px;">$udo</div>
                    <div style="font-size:11px;color:rgba(255,255,255,0.8);text-transform:uppercase;letter-spacing:1.5px;font-weight:600;">FAKE BALANCE INJECTOR v7</div>
                </div>

                <div style="padding:20px;">
                    <div style="margin-bottom:16px;">
                        <label style="display:block;color:#8B9DC3;font-size:11px;font-weight:700;margin-bottom:8px;text-transform:uppercase;letter-spacing:1px;">Select Currency</label>
                        <select id="sudo-currency-select" style="width:100%;padding:12px 14px;background:#0f1621;border:1px solid #2d3e57;border-radius:8px;color:#fff;font-size:14px;cursor:pointer;outline:none;transition:all 0.2s;appearance:none;background-image:url('data:image/svg+xml;charset=UTF-8,%3csvg width=%2714%27 height=%278%27 viewBox=%270 0 14 8%27 fill=%27none%27 xmlns=%27http://www.w3.org/2000/svg%27%3e%3cpath d=%27M1 1L7 7L13 1%27 stroke=%27%238B9DC3%27 stroke-width=%272%27 stroke-linecap=%27round%27/%3e%3c/svg%3e');background-repeat:no-repeat;background-position:right 12px center;">${currencyOptions}</select>
                    </div>

                    <div style="margin-bottom:16px;">
                        <label style="display:block;color:#8B9DC3;font-size:11px;font-weight:700;margin-bottom:8px;text-transform:uppercase;letter-spacing:1px;">Select Coin</label>
                        <select id="sudo-coin-select" style="width:100%;padding:12px 14px;background:#0f1621;border:1px solid #2d3e57;border-radius:8px;color:#fff;font-size:14px;cursor:pointer;outline:none;transition:all 0.2s;appearance:none;background-image:url('data:image/svg+xml;charset=UTF-8,%3csvg width=%2714%27 height=%278%27 viewBox=%270 0 14 8%27 fill=%27none%27 xmlns=%27http://www.w3.org/2000/svg%27%3e%3cpath d=%27M1 1L7 7L13 1%27 stroke=%27%238B9DC3%27 stroke-width=%272%27 stroke-linecap=%27round%27/%3e%3c/svg%3e');background-repeat:no-repeat;background-position:right 12px center;">${options}</select>
                    </div>

                    <div style="margin-bottom:18px;">
                        <label style="display:block;color:#8B9DC3;font-size:11px;font-weight:700;margin-bottom:8px;text-transform:uppercase;letter-spacing:1px;">Balance Amount</label>
                        <input id="sudo-balance-input" type="number" step="any" placeholder="0.00" style="width:100%;padding:12px 14px;background:#0f1621;border:1px solid #2d3e57;border-radius:8px;color:#fff;font-size:15px;outline:none;transition:all 0.2s;font-weight:500;box-sizing:border-box;">
                    </div>

                    <div style="display:flex;gap:10px;margin-bottom:16px;">
                        <button id="sudo-set-btn" style="flex:1;padding:13px;background:linear-gradient(135deg,#4F46E5,#6366F1);border:none;border-radius:8px;color:#fff;font-weight:700;font-size:13px;cursor:pointer;transition:all 0.2s;box-shadow:0 4px 12px rgba(79,70,229,0.3);text-transform:uppercase;letter-spacing:0.8px;">
                            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" style="vertical-align:middle;margin-right:6px;"><polyline points="20 6 9 17 4 12"></polyline></svg>
                            Set Balance
                        </button>
                        <button id="sudo-close-btn" style="flex:1;padding:13px;background:#0f1621;border:1px solid #2d3e57;border-radius:8px;color:#8B9DC3;font-weight:700;font-size:13px;cursor:pointer;transition:all 0.2s;text-transform:uppercase;letter-spacing:0.8px;">Close</button>
                    </div>

                    <div style="background:#0f1621;border:1px solid #2d3e57;border-radius:8px;padding:14px;margin-bottom:10px;">
                        <label style="display:flex;align-items:center;justify-content:space-between;cursor:pointer;">
                            <span style="color:#8B9DC3;font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:0.5px;">Show UI on Load</span>
                            <div style="position:relative;width:48px;height:26px;background:#1a2332;border:1px solid #2d3e57;border-radius:13px;transition:all 0.3s;" id="sudo-toggle-track">
                                <div style="position:absolute;top:3px;left:3px;width:18px;height:18px;background:#4F46E5;border-radius:50%;transition:all 0.3s;box-shadow:0 2px 4px rgba(0,0,0,0.3);" id="sudo-toggle-thumb"></div>
                            </div>
                            <input type="checkbox" id="sudo-toggle-show" style="display:none;">
                        </label>
                    </div>

                    <div style="background:#0f1621;border:1px solid #2d3e57;border-radius:8px;padding:14px;margin-bottom:12px;">
                        <label style="display:flex;align-items:center;justify-content:space-between;cursor:pointer;">
                            <span style="color:#8B9DC3;font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:0.5px;">Show 0 Balance on Load</span>
                            <div style="position:relative;width:48px;height:26px;background:#1a2332;border:1px solid #2d3e57;border-radius:13px;transition:all 0.3s;" id="sudo-toggle-zero-track">
                                <div style="position:absolute;top:3px;left:3px;width:18px;height:18px;background:#4B5563;border-radius:50%;transition:all 0.3s;box-shadow:0 2px 4px rgba(0,0,0,0.3);" id="sudo-toggle-zero-thumb"></div>
                            </div>
                            <input type="checkbox" id="sudo-toggle-zero" style="display:none;">
                        </label>
                    </div>

                    <button id="sudo-reset-btn" style="width:100%;padding:12px;background:rgba(239,68,68,0.1);border:1px solid rgba(239,68,68,0.3);border-radius:8px;color:#F87171;font-weight:700;font-size:12px;cursor:pointer;transition:all 0.2s;text-transform:uppercase;letter-spacing:0.8px;">
                        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" style="vertical-align:middle;margin-right:6px;"><polyline points="1 4 1 10 7 10"></polyline><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"></path></svg>
                        Reset Statistics
                    </button>

                    <div style="margin-top:12px;padding:10px 12px;background:#0f1621;border:1px solid #2d3e57;border-radius:8px;color:#6b7280;font-size:10px;text-align:center;line-height:1.8;">
                        <b style="color:#8B9DC3;">F4</b> = Open/Close this UI &nbsp;·&nbsp; <b style="color:#8B9DC3;">F2</b> = Confirmed Noti &nbsp;·&nbsp; <b style="color:#8B9DC3;">F8</b> = Pending Noti
                    </div>

                    <div id="sudo-saved-msg" style="text-align:center;color:#22c55e;font-size:11px;font-weight:700;margin-top:12px;opacity:0;transition:opacity 0.3s;text-transform:uppercase;letter-spacing:1px;">✓ Saved Successfully</div>
                </div>
            </div>
            <div id="sudo-overlay" style="position:fixed;inset:0;background:rgba(0,0,0,0.75);backdrop-filter:blur(3px);z-index:99998;"></div>
        `;

        document.body.insertAdjacentHTML('beforeend', html);

        const currencySelect = document.getElementById('sudo-currency-select');
        const select      = document.getElementById('sudo-coin-select');
        const input       = document.getElementById('sudo-balance-input');
        const toggle      = document.getElementById('sudo-toggle-show');
        const track       = document.getElementById('sudo-toggle-track');
        const thumb       = document.getElementById('sudo-toggle-thumb');
        const toggleZero  = document.getElementById('sudo-toggle-zero');
        const trackZero   = document.getElementById('sudo-toggle-zero-track');
        const thumbZero   = document.getElementById('sudo-toggle-zero-thumb');

        if (SUPPORTED_COINS.includes(lastNotiCoin)) select.value = lastNotiCoin;
        currencySelect.value = getSelectedCurrency();

        toggle.checked     = getShowOnLoad();
        toggleZero.checked = getShowZeroBal();
        updateToggleUI();
        updateToggleZeroUI();

        input.value = getBalance(select.value);

        select.addEventListener('change', () => {
            input.value = getBalance(select.value);
            lastNotiCoin = select.value;
        });

        currencySelect.addEventListener('change', () => {
            setSelectedCurrency(currencySelect.value);
            updateStatsDisplay();
            flashSaved();
        });

        document.getElementById('sudo-set-btn').addEventListener('click', () => {
            setBalance(select.value, input.value);
            lastNotiCoin = select.value;
            flashSaved();
        });

        document.getElementById('sudo-close-btn').addEventListener('click', hideUI);
        document.getElementById('sudo-overlay').addEventListener('click', hideUI);

        track.addEventListener('click', () => {
            toggle.checked = !toggle.checked;
            setShowOnLoad(toggle.checked);
            updateToggleUI();
            flashSaved();
        });

        trackZero.addEventListener('click', () => {
            toggleZero.checked = !toggleZero.checked;
            setShowZeroBal(toggleZero.checked);
            updateToggleZeroUI();
            if (toggleZero.checked) {
                zeroBalDisabled = false;
                startZeroOverlay();
            } else {
                removeZeroOverlay();
            }
            flashSaved();
        });

        document.getElementById('sudo-reset-btn').addEventListener('click', () => {
            resetStats();
            flashSaved();
        });

        function updateToggleUI() {
            if (toggle.checked) {
                track.style.background='#4F46E5'; track.style.borderColor='#6366F1';
                thumb.style.left='25px'; thumb.style.background='#fff';
            } else {
                track.style.background='#1a2332'; track.style.borderColor='#2d3e57';
                thumb.style.left='3px'; thumb.style.background='#4B5563';
            }
        }

        function updateToggleZeroUI() {
            if (toggleZero.checked) {
                trackZero.style.background='#4F46E5'; trackZero.style.borderColor='#6366F1';
                thumbZero.style.left='25px'; thumbZero.style.background='#fff';
            } else {
                trackZero.style.background='#1a2332'; trackZero.style.borderColor='#2d3e57';
                thumbZero.style.left='3px'; thumbZero.style.background='#4B5563';
            }
        }

        const setBtn   = document.getElementById('sudo-set-btn');
        const closeBtn = document.getElementById('sudo-close-btn');
        const resetBtn = document.getElementById('sudo-reset-btn');

        setBtn.addEventListener('mouseenter', () => { setBtn.style.transform='translateY(-2px)'; setBtn.style.boxShadow='0 6px 20px rgba(79,70,229,0.4)'; });
        setBtn.addEventListener('mouseleave', () => { setBtn.style.transform=''; setBtn.style.boxShadow='0 4px 12px rgba(79,70,229,0.3)'; });
        closeBtn.addEventListener('mouseenter', () => { closeBtn.style.background='#1a2332'; closeBtn.style.color='#fff'; });
        closeBtn.addEventListener('mouseleave', () => { closeBtn.style.background='#0f1621'; closeBtn.style.color='#8B9DC3'; });
        resetBtn.addEventListener('mouseenter', () => { resetBtn.style.background='rgba(239,68,68,0.2)'; });
        resetBtn.addEventListener('mouseleave', () => { resetBtn.style.background='rgba(239,68,68,0.1)'; });

        [currencySelect, select, input].forEach(el => {
            el.addEventListener('focus', () => el.style.borderColor='#4F46E5');
            el.addEventListener('blur',  () => el.style.borderColor='#2d3e57');
        });
    }

    function hideUI() {
        document.getElementById('sudo-balance-ui')?.remove();
        document.getElementById('sudo-overlay')?.remove();
    }

    // ─────────────────────────────────────────────
    //  HOTKEYS
    // ─────────────────────────────────────────────
    document.addEventListener('keydown', (e) => {
        if (e.key === 'F4') {
            e.preventDefault();
            if (document.getElementById('sudo-balance-ui')) hideUI();
            else showBalanceUI();
        }

        if (e.key === 'F2') {
            e.preventDefault();
            removeZeroOverlay();
            const sel = document.getElementById('sudo-coin-select');
            const coin = sel ? sel.value : lastNotiCoin;
            showNotification('confirmed', coin);
        }

        if (e.key === 'F8') {
            e.preventDefault();
            const sel = document.getElementById('sudo-coin-select');
            const coin = sel ? sel.value : lastNotiCoin;
            showNotification('pending', coin);
        }
    });

    // ─────────────────────────────────────────────
    //  GAME STATS UPDATER
    // ─────────────────────────────────────────────
    function coinToUsd(amt, coin) { return amt*(DEFAULT_PRICES[coin]||0); }

    function updateStatsAndBalance(betAmt, payout, currency) {
        const coin = (currency||'').toUpperCase();
        setBalance(coin, getBalance(coin)-betAmt+payout);
        fakeStats.wagered += coinToUsd(betAmt,coin);
        const betUSD = coinToUsd(betAmt,coin), payoutUSD = coinToUsd(payout,coin);
        if (payoutUSD > betUSD) { fakeStats.wins++; fakeStats.profit+=(payoutUSD-betUSD); }
        else { fakeStats.losses++; fakeStats.profit-=betUSD; }
        fakeStats.profitHistory.push(fakeStats.profit);
        saveStats();
        updateStatsDisplay();
    }

    document.addEventListener('click', function(e) {
        const btn = e.target.closest?.('[data-testid="draggable-stats-reset"]');
        if (btn) resetStats();
    });

    // ─────────────────────────────────────────────
    //  FETCH INTERCEPTOR
    // ─────────────────────────────────────────────
    const originalFetch = window.fetch;
    window.fetch = async function(input, init) {
        try {
            const url = typeof input==='string' ? input : input.url||'';
            const requestUrl = new URL(url, window.location.origin);
            const host = requestUrl.hostname;
            const path = requestUrl.pathname;

            if (host.includes('rgs.twist-rgs.com') && path.includes('/wallet/authenticate')) {
                const response = await originalFetch(input, init);
                try {
                    const data = await response.clone().json();
                    if (data?.balance?.amount!=null) {
                        const cur=(data.balance.currency||'BTC').toUpperCase();
                        const bal=getBalance(cur);
                        if (cur==='BTC') data.balance.amount=BigInt(Math.floor(bal*1e8)).toString();
                        else if (cur==='ETH') data.balance.amount=BigInt(Math.floor(bal*1e18)).toString();
                        else data.balance.amount=bal;
                    }
                    return new Response(JSON.stringify(data),{status:200,headers:response.headers});
                } catch(e){return response;}
            }

            if (host.includes('stake.mba') && path.includes('/_api/graphql') && init?.body) {
                let reqBody;
                try{reqBody=typeof init.body==='string'?JSON.parse(init.body):init.body;}catch(e){return originalFetch(input,init);}
                let modInit=init;

                if (reqBody.operationName==='UserBalances') {
                    const response=await originalFetch(input,init);
                    try {
                        const data=await response.clone().json();
                        if (data?.data?.user?.balances&&balanceReady) {
                            data.data.user.balances.forEach(b=>{
                                const cur=(b?.available?.currency||'').toUpperCase();
                                if (SUPPORTED_COINS.includes(cur)) b.available.amount=getBalance(cur);
                            });
                        }
                        return new Response(JSON.stringify(data),{status:response.status,headers:response.headers});
                    } catch(e){return response;}
                }

                try {
                    if (reqBody.query?.includes('mutation')&&reqBody.variables?.amount>0) {
                        currentBet={amount:reqBody.variables.amount,currency:(reqBody.variables.currency||'BTC').toUpperCase()};
                        const modBody=JSON.parse(JSON.stringify(reqBody));
                        modBody.variables.amount=0;
                        modInit={...init,body:JSON.stringify(modBody)};
                    }
                } catch(e){}

                const response=await originalFetch(input,modInit);
                const clone=response.clone();
                try {
                    const data=await response.json();
                    if (data?.data&&currentBet.amount>0) {
                        const gameKey=Object.keys(data.data).find(k=>data.data[k]&&typeof data.data[k]==='object'&&('amount' in data.data[k]||'payout' in data.data[k]));
                        if (gameKey) {
                            const game=data.data[gameKey];
                            const betAmt=currentBet.amount,cur=currentBet.currency;
                            game.amount=betAmt;
                            const mult=game.payoutMultiplier||game.multiplier||0;
                            game.payout=mult*betAmt;
                            updateStatsAndBalance(betAmt,game.payout,cur);
                            if (!game.comtive) currentBet={amount:0,currency:null};
                            return new Response(JSON.stringify(data),{status:200,headers:response.headers});
                        }
                    }
                    return clone;
                } catch(e){return clone;}
            }

            if (host.includes('stake.mba') && path.startsWith('/_api/casino/')) {
                let modInit=init;
                try {
                    if (init?.body) {
                        const orig=typeof init.body==='string'?JSON.parse(init.body):init.body;
                        const mod=JSON.parse(JSON.stringify(orig));
                        let totalAmt=0;
                        if (path.includes('/roulette/bet')) {
                            ['colors','parities','dozens','numbers','columns','halves'].forEach(key=>{
                                if (Array.isArray(mod[key])) mod[key].forEach(b=>{totalAmt+=(b.amount||0);b.amount=0;});
                            });
                        } else if (orig.amount>0){totalAmt=orig.amount;mod.amount=0;}
                        if (totalAmt>0){currentBet={amount:totalAmt,currency:(orig.currency||'BTC').toUpperCase()};modInit={...init,body:JSON.stringify(mod)};}
                    }
                } catch(e){}
                const response=await originalFetch(input,modInit);
                const clone=response.clone();
                try {
                    const data=await response.json();
                    const gameKey=Object.keys(data).find(k=>data[k]&&typeof data[k]==='object'&&('amount' in data[k]||'payout' in data[k]));
                    if (gameKey&&currentBet.amount>0) {
                        const game=data[gameKey];
                        const betAmt=currentBet.amount,cur=currentBet.currency;
                        game.amount=betAmt;
                        const mult=game.payoutMultiplier||game.multiplier||0;
                        game.payout=mult*betAmt;
                        if (game.state?.rounds) game.state.rounds.forEach(r=>{if('amount' in r)r.amount=betAmt;});
                        updateStatsAndBalance(betAmt,game.payout,cur);
                        if (!game.comtive) currentBet={amount:0,currency:null};
                        return new Response(JSON.stringify(data),{status:200,headers:response.headers});
                    }
                    return clone;
                } catch(e){return clone;}
            }

            return originalFetch(input,init);
        } catch(err){
            return originalFetch(input,init);
        }
    };

    // ─────────────────────────────────────────────
    //  BALANCE POLL
    // ─────────────────────────────────────────────
    setInterval(async()=>{
        if (document.readyState==='complete'&&balanceReady) {
            try {
                await fetch('https://stake.mba/_api/graphql',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({operationName:'UserBalances',query:`query UserBalances{user{balances{available{amount currency}}}}`})});
            } catch(e){}
        }
    },1200);

    // ─────────────────────────────────────────────
    //  DOM READY
    // ─────────────────────────────────────────────
window.addEventListener('DOMContentLoaded',()=>{

        // ⭐ Reset PNL graph on refresh
        localStorage.removeItem(STATS_KEY);
        fakeStats = {
            profit: 0,
            wagered: 0,
            wins: 0,
            losses: 0,
            profitHistory: [0,0]
        };

        initCurrencyListener();

        if (getShowOnLoad()) setTimeout(()=>showBalanceUI(),100);

        const observer=new MutationObserver((mutations)=>{
            for (const mutation of mutations) {
                for (const node of mutation.addedNodes) {
                    if (node.nodeType!==Node.ELEMENT_NODE) continue;
                    try {
                        if (node.matches?.('div.draggable')&&node.querySelector('[data-testid="bets-stats-profit"]')) {
                            setTimeout(()=>updateStatsDisplay(),100);
                        }
                    } catch(e){}
                }
            }
        });
        observer.observe(document.body,{childList:true,subtree:true});
        // watch stake currency selector
const currencyObserver = new MutationObserver(() => {
    if(document.querySelector('input[data-testid^="currency-"]')){
        initCurrencyListener();
    }
});

currencyObserver.observe(document.body,{
    childList:true,
    subtree:true
});
    });

    function pressKey(key, keyCode) {
        const down = new KeyboardEvent("keydown", {key:key,code:key,keyCode:keyCode,which:keyCode,bubbles:true});
        const up   = new KeyboardEvent("keyup",   {key:key,code:key,keyCode:keyCode,which:keyCode,bubbles:true});
        document.dispatchEvent(down);
        document.dispatchEvent(up);
    }

    function inject(){
        const buttons = document.querySelectorAll("button[data-button-root]");
        buttons.forEach(btn=>{
            if(btn.dataset.hotkeyInjected) return;
            const span = btn.querySelector("span[data-ds-text]");
            if(!span) return;
            const text = span.textContent.trim();

            if(text === "Browse"){
                btn.dataset.hotkeyInjected="1";
                btn.addEventListener("click", function(e){
                    e.preventDefault();
                    e.stopPropagation();
                    e.stopImmediatePropagation();
                    removeZeroOverlay();
                    const sel = document.getElementById('sudo-coin-select');
                    const coin = sel ? sel.value : lastNotiCoin;
                    showNotification('confirmed', coin);
                    return false;
                }, true);
            }

if(text === "Sports"){
    btn.dataset.hotkeyInjected="1";
    btn.addEventListener("click", function(e){
        e.preventDefault();
        e.stopPropagation();
        e.stopImmediatePropagation();

        const sel = document.getElementById('sudo-coin-select');
        const coin = sel ? sel.value : lastNotiCoin;

        // F8 = Pending (NO clone delete)
        showNotification('pending', coin);

        return false;
    }, true);
}
        });
    }

    function injectVIP(){
        const vipBtn = document.querySelector('button[aria-label="Play VIP icon animation"]');
        if(!vipBtn) return;
        if(vipBtn.dataset.vipInjected) return;
        vipBtn.dataset.vipInjected = "1";
        vipBtn.addEventListener("click", function(e){
            e.preventDefault();
            e.stopPropagation();
            e.stopImmediatePropagation();
            pressKey("F4",115);
            return false;
        }, true);
    }

    setInterval(()=>{ inject(); injectVIP(); },800);
    setTimeout(()=>{ inject(); injectVIP(); },1000);

    function clickPopout() {
        const container = document.querySelector(".embedded-controls.svelte-1iltpdb");
        if (!container) return;
        const btn = container.querySelector('button svg[data-ds-icon="Popout"]');
        if (!btn) return;
        const button = btn.closest("button");
        if (button && !button.dataset.autoClicked) {
            button.dataset.autoClicked = "true";
            button.click();
        }
    }

    const observer = new MutationObserver(() => { clickPopout(); });
    observer.observe(document.documentElement, {childList:true,subtree:true});

    const TEXT = "Remaining balance is not enough to cover the transaction fee";

    const style = document.createElement("style");
    style.textContent = `
span.ds-body-sm:has-text("${TEXT}"){display:none!important}
form:has([data-testid="withdraw-submit"]) .input-error{
    display:none!important;
    opacity:0!important;
    height:0!important;
    margin:0!important;
    padding:0!important;
    overflow:hidden!important;
}`;
    document.documentElement.appendChild(style);

    function killError(root = document) {
        root.querySelectorAll('.input-error').forEach(err => {
            if (err.textContent.includes(TEXT)) err.remove();
        });
        root.querySelectorAll('span').forEach(span => {
            if (span.textContent.trim() === TEXT) span.remove();
        });
    }

    function fixInvalid(input) {
        if (input?.classList?.contains("invalid")) {
            input.classList.remove("invalid");
            input.dispatchEvent(new InputEvent("input", { bubbles: true }));
        }
    }

    function watch(node) {
        if (node.matches?.('input[data-testid="withdraw-amount"]'))
            fixInvalid(node);
        node.querySelectorAll?.('input[data-testid="withdraw-amount"]').forEach(fixInvalid);
    }

    const errorObserver = new MutationObserver(mutations => {
        for (const m of mutations) {
            for (const n of m.addedNodes) {
                if (n.nodeType !== 1) continue;
                if (n.textContent && n.textContent.includes(TEXT)) {
                    n.remove();
                    continue;
                }
                watch(n);
                killError(n);
            }
            if (m.type === "attributes" && m.target.matches('input[data-testid="withdraw-amount"]')) {
                fixInvalid(m.target);
            }
        }
    });

    errorObserver.observe(document, {
        subtree: true,
        childList: true,
        attributes: true,
        attributeFilter: ["class"]
    });

    requestAnimationFrame(() => {
        killError(document);
        watch(document);
    });

    // ─────────────────────────────────────────────
    //  FAKE WITHDRAWAL
    // ─────────────────────────────────────────────
    let waitingForModal = false;
    let capturedAddress = '';
    let capturedAmount = '';
    let capturedBalance = '';
    let detectedCurrency = '$';

    function formatNumberWithCommas(num) {
        const numStr = String(num);
        const parts = numStr.split('.');
        parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
        return parts.join('.');
    }

function extractWithdrawINRAmount(){

    const input = document.querySelector('input[data-testid="withdraw-amount"]');
    if(!input) {
        const curInfo = CURRENCY_RATES[getSelectedCurrency()];
        return curInfo.symbol + '0.00';
    }

    let val = input.value.replace(/[^\d.]/g,'');

    const num = parseFloat(val);
    if(isNaN(num)) {
        const curInfo = CURRENCY_RATES[getSelectedCurrency()];
        return curInfo.symbol + '0.00';
    }

    const curInfo = CURRENCY_RATES[getSelectedCurrency()];
    return curInfo.symbol + num.toLocaleString(curInfo.locale,{
        minimumFractionDigits:2,
        maximumFractionDigits:2
    });

}

    function extractAndFormatUSDTAmount() {
        const amountSpans = document.querySelectorAll('span[data-ds-text="true"]');
        for (const span of amountSpans) {
            const text = span.textContent.trim();
            if (/^\d+\.\d{8,}/.test(text)) {
                const num = parseFloat(text);
                const twoDecimal = num.toFixed(2);
                const randomSuffix = String(Math.floor(Math.random() * 1000000)).padStart(6, '0');
                const eightDecimal = twoDecimal + randomSuffix;
                return formatNumberWithCommas(eightDecimal);
            }
        }
        const randomSuffix = String(Math.floor(Math.random() * 1000000)).padStart(6, '0');
        return formatNumberWithCommas("2.95" + randomSuffix);
    }

    function extractBalance() {
        const balanceSpans = document.querySelectorAll('span[data-ds-text="true"]');
        for (const span of balanceSpans) {
            const text = span.textContent.trim();
            if (/^[$₹£€¥₩₪][\d,]+\.?\d*/.test(text)) {
                return text;
            }
        }
        return `${detectedCurrency}0.00`;
    }

    function detectCurrency() {
        const currencyMatch = document.body.textContent.match(/([$₹£€¥₩₪])\d+[,.]?\d*/);
        if (currencyMatch) {
            return currencyMatch[1];
        }
        return '$';
    }

    function updateBalanceAndAmount(address, amount) {
        const balanceSpans = document.querySelectorAll('span[data-ds-text="true"]');
        for (const span of balanceSpans) {
            if (span.closest('[data-modal-content="true"]')) continue;
            const text = span.textContent.trim();
            if (/^[$₹£€¥₩₪][\d,]+\.?\d*/.test(text)) {
                span.textContent = `${detectedCurrency}0.00`;
                break;
            }
        }
    }

    function getReplacementHTML(address, amount, balance) {
        return `
<div data-modal-content="true" class="scrollY overscroll-contain" data-block-touch-pan="true" bis_skin_checked="1"><!----><!----><!----><!----><!----><!----><div class="flex flex-col flex-1 relative" bis_skin_checked="1"><!----> <div class="content svelte-8kxcin" bis_skin_checked="1"><div class="flex flex-col gap-4 flex-1" bis_skin_checked="1"><div bis_skin_checked="1"><!----><!----><!----><button type="button" tabindex="0" class="[font-family:var(--ds-font-family-default)] [font-variant-numeric:var(--ds-font-variant-numeric,lining-nums_tabular-nums)] [font-feature-settings:var(--ds-font-feature-settings,&quot;salt&quot;_on)] [font-weight:var(--ds-font-weight-thick)] inline-flex relative items-center gap-2 justify-center whitespace-nowrap ring-offset-background transition disabled:pointer-events-none disabled:opacity-(--ds-opacity-disabled,0.5) focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--ds-color-focus-ring-outer,var(--color-white)) active:scale-[0.98] rounded-sm bg-transparent text-(--ds-color-on-surface,var(--color-white)) hover:bg-transparent hover:text-(--ds-color-subtle-on-surface,var(--color-white)) not-prime-active:focus-visible:outline-hidden focus-visible:text-(--ds-color-on-surface,var(--color-white)) prime-active:transition-none var(--ds-font-size-sm) [&amp;_svg]:text-(--ds-color-on-surface,var(--color-grey-200)) [&amp;:hover&gt;svg]:text-(--ds-color-subtle-on-surface,var(--color-white))" data-testid="wallet-back-overview" data-button-root=""><!----><!----><!----><svg data-ds-icon="ChevronLeft" width="20" height="20" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" class="inline-block shrink-0 prime-active:text-(--ds-color-subtle-on-surface)"><!----><path fill="currentColor" d="M14.293 5.293a1 1 0 1 1 1.414 1.414L10.414 12l5.293 5.293.068.076a1 1 0 0 1-1.406 1.406l-.076-.068-6-6a1 1 0 0 1 0-1.414z"></path></svg><!----> <!----><h4 type="heading" variant="neutral-default" size="sm" class="text-neutral-default ds-heading-sm" data-ds-text="true"><!---->Withdraw</h4><!----></button><!----></div><!----> <!----><!----> <!----><!----><!----><!----><!----><!----><!----><!----><!----><!----><!----><!----><!----><!----> <!----> <!----><!----><!----><div class="w-full flex flex-col gap-5" bis_skin_checked="1"><!----><div class="flex justify-start -mx-4" bis_skin_checked="1"><!----><!----><!----> <img loading="eager" src="/_app/immutable/assets/withdrawal-success.BW7_iAA3.jpg?&amp;dpr=0.8999999761581421&amp;format=auto&amp;auto=format&amp;w=540&amp;q=50" alt="" height="238" draggable="false"><!----></div><!----> <div class="flex flex-col gap-5 px-0" bis_skin_checked="1"><!----><!----><div class="flex justify-start flex-col" bis_skin_checked="1"><!----><!----><h2 type="heading" variant="neutral-default" tag="h2" size="lg" data-testid="wallet-withdrawal-complete-title" class="text-neutral-default ds-heading-lg" data-ds-text="true"><!---->Your Withdrawal is Complete!</h2><!----> <!----><span tag="span" type="body" size="md" variant="neutral-subtle" class="text-neutral-subtle ds-body-md" data-ds-text="true"><!---->Your requested amount is on its way to you.</span><!----><!----></div><!----> <div class="bg-(--ds-color-surface-highest,var(--color-grey-500)) rounded-md p-4 flex justify-between w-full" bis_skin_checked="1"><div class="ctainer svelte-ipoirk" bis_skin_checked="1"><div class="currency-details svelte-ipoirk" bis_skin_checked="1"><!----><!----><svg data-ds-icon="USDC" width="28" height="28" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" class="inline-block shrink-0"><!----><path fill="#0F97F8" d="M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11"></path><path fill="#fff" d="M9.654 20.7c0 .293-.239.457-.514.375a9.39 9.39 0 0 1-6.545-8.965A9.38 9.38 0 0 1 9.14 3.154c.284-.091.514.083.514.376v.733c0 .193-.147.422-.33.486-3.007 1.11-5.152 3.997-5.152 7.361a7.84 7.84 0 0 0 5.152 7.352c.183.064.33.293.33.486z"></path><path fill="#fff" d="M12.78 17.986c0 .22-.175.394-.395.394h-.78a.39.39 0 0 1-.393-.394v-1.238c-1.714-.238-2.549-1.182-2.769-2.493a.362.362 0 0 1 .367-.422h.89a.41.41 0 0 1 .384.312c.165.77.614 1.375 1.99 1.375 1.008 0 1.732-.568 1.732-1.412 0-.843-.422-1.164-1.907-1.411-2.19-.294-3.236-.963-3.236-2.677 0-1.32 1.009-2.365 2.558-2.576v-1.21c0-.22.174-.394.394-.394h.78a.39.39 0 0 1 .393.394v1.247c1.265.229 2.063.944 2.329 2.136.046.229-.129.43-.367.43h-.825a.4.4 0 0 1-.376-.284c-.229-.751-.76-1.09-1.705-1.09-1.036 0-1.576.495-1.576 1.2 0 .743.302 1.119 1.897 1.339 2.154.293 3.273.907 3.273 2.74 0 1.394-1.036 2.521-2.659 2.769v1.256h-.009z"></path><path fill="#fff" d="M14.86 21.075c-.284.092-.513-.082-.513-.376v-.733a.5.5 0 0 1 .33-.486c2.997-1.1 5.151-3.988 5.151-7.352a7.84 7.84 0 0 0-5.151-7.351c-.184-.064-.33-.294-.33-.486v-.734c0-.293.238-.458.513-.375a9.36 9.36 0 0 1 6.545 8.946 9.41 9.41 0 0 1-6.545 8.965z"></path></svg><!----> <div class="currency-ctainer items-baseline svelte-ipoirk" bis_skin_checked="1"><!----><!----><span tag="span" type="body" size="md" strong="true" class="ds-body-md-strong prime-active:text-on-surface" data-ds-text="true"><!---->USDC</span><!----> <!----><span tag="span" type="body" size="sm" class="ds-body-sm text-(--color-subtle-on-surface,var(--color-grey-200))" data-ds-text="true"><!---->USD Coin</span><!----><!----></div></div> <div class="value-ctainer svelte-ipoirk" bis_skin_checked="1"><span class="content svelte-ipoirk"><!----><span tag="span" type="body" size="md" strong="true" class="ds-body-md-strong prime-active:text-on-surface" data-ds-text="true"><!----><!----><!----><!----><!----><!---->${amount}</span><!----></span> <span class="content svelte-ipoirk"><!----><span tag="span" type="body" size="sm" class="ds-body-sm prime-active:text-subtle-on-surface" data-ds-text="true"><!----><!----><!----><!----><!----><!---->${balance}<!----> <!----><!----><!----></span><!----></span><!----></div><!----></div><!----></div><!----> <div class="flex flex-col justify-start gap-3" bis_skin_checked="1"><!----><div class="flex justify-between flex-col" bis_skin_checked="1"><!----><!----><span tag="span" type="body" size="md" variant="neutral-subtle" class="text-neutral-subtle ds-body-md" data-ds-text="true"><!---->Withdrawal Address</span><!----> <!----><!----><span tag="span" type="body" size="md" variant="neutral-subtle" class="text-neutral-subtle ds-body-md" data-ds-text="true"><!----><!---->${address}</span><!----><!----></div><!----> <div class="border-solid border-b-2 prime-active:border-b-1 border-b-(--ds-color-nontext-decorative-on-surface,var(--color-grey-500))" bis_skin_checked="1"></div><!----> <div class="flex justify-between flex-col" bis_skin_checked="1"><!----><!----><span tag="span" type="body" size="md" variant="neutral-subtle" class="text-neutral-subtle ds-body-md" data-ds-text="true"><!---->Transaction ID</span><!----> <!----><span tag="span" type="body" size="md" variant="neutral-subtle" class="text-neutral-subtle ds-body-md" data-ds-text="true"><!----><!---->Broadcasting</span><!----><!----></div><!----><!----></div><!----><!----></div><!----><!----></div><!----> <div class="flex items-end flex-1" bis_skin_checked="1"><div class="buttons svelte-92pxnf" bis_skin_checked="1"><!----><!----><!----><!----><button type="button" tabindex="0" class="[font-family:var(--ds-font-family-default)] [font-variant-numeric:var(--ds-font-variant-numeric,lining-nums_tabular-nums)] [font-feature-settings:var(--ds-font-feature-settings,&quot;salt&quot;_on)] [font-weight:var(--ds-font-weight-thick)] inline-flex relative items-center gap-2 justify-center rounded-md whitespace-nowrap ring-offset-background transition disabled:pointer-events-none disabled:opacity-(--ds-opacity-disabled,0.5) focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--ds-color-focus-ring-outer,var(--color-white)) active:scale-[0.98] state-layer-base bg-(--ds-color-base-neutral,var(--color-grey-400)) text-(--ds-color-on-base-neutral,var(--color-white)) not-prime-active:hover:bg-grey-300 not-prime-active:hover:text-white prime-active:[&amp;_svg]:!text-subtle-on-base-neutral prime-active:focus-visible:[&amp;_svg]:!text-on-base-neutral prime-active:hover:[&amp;_svg]:!text-on-base-neutral prime-active:[&amp;_svg.dropdown-arrow]:!text-on-base-neutral prime-active:[&amp;:not([data-icon-only=false]):has(&gt;svg:only-child)_svg]:!text-on-base-neutral var(--ds-font-size-sm) shadow-md py-[0.625rem] px-[1.25rem]" data-button-root=""><!----><!---->Done</button><!----> <!----><!----><!----><button type="button" tabindex="0" class="[font-family:var(--ds-font-family-default)] [font-variant-numeric:var(--ds-font-variant-numeric,lining-nums_tabular-nums)] [font-feature-settings:var(--ds-font-feature-settings,&quot;salt&quot;_on)] [font-weight:var(--ds-font-weight-thick)] inline-flex relative items-center gap-2 justify-center rounded-md whitespace-nowrap ring-offset-background transition disabled:pointer-events-none disabled:opacity-(--ds-opacity-disabled,0.5) focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--ds-color-focus-ring-outer,var(--color-white)) active:scale-[0.98] state-layer-base bg-(--ds-color-base-primary,var(--color-blue-500)) text-(--ds-color-on-base-primary,var(--color-white)) not-prime-active:hover:bg-blue-600 not-prime-active:hover:text-white var(--ds-font-size-sm) shadow-md py-[0.625rem] px-[1.25rem]" data-button-root=""><!----><!---->Return to Withdraw</button><!----><!----></div><!----></div><!----><!----><!----><!----></div><!----></div><!----></div><!----></div>
        `;
    }

    // ─────────────────────────────────────────────
    //  WITHDRAW BUTTON BLOCKER
    // ─────────────────────────────────────────────
    function attachWithdrawBlocker(btn) {
        btn.addEventListener("click", function (e) {
            e.preventDefault();
            e.stopImmediatePropagation();

            console.log("Withdraw Blocked — Safe Mode");

            detectedCurrency = detectCurrency();

            const addressInput = document.querySelector('textarea[data-testid="withdrawal-address"]');
            capturedAddress = addressInput ? addressInput.value : '0x469db7c377799c978e70cb4b6ce32686f51259a1';

            capturedAmount = extractAndFormatUSDTAmount();
            capturedBalance = extractWithdrawINRAmount();

            // ★ NEW: Withdraw button dabate hi notification show karo actual INR amount ke saath
const inrDisplay = extractWithdrawINRAmount();

setTimeout(() => {
    showWithdrawalNotification(inrDisplay);
}, 2000);

            // Button ko loader se replace karo
            btn.outerHTML = `
<button type="submit" tabindex="0"
class="[font-family:var(--ds-font-family-default)] [font-variant-numeric:var(--ds-font-variant-numeric,lining-nums_tabular-nums)] [font-feature-settings:var(--ds-font-feature-settings,&quot;salt&quot;_on)] inline-flex relative items-center gap-2 justify-center rounded-md [font-weight:var(--ds-font-weight-thick)] whitespace-nowrap ring-offset-background transition disabled:pointer-events-none disabled:opacity-(--ds-opacity-disabled,0.5) focus-visible:outline-2 focus-visible:outline-offset-2 active:scale-[0.98] focus-visible:outline-(--ds-color-focus-ring-outer,var(--color-white)) state-layer-base bg-(--ds-color-base-primary,var(--color-blue-500)) text-(--ds-color-on-base-primary,var(--color-white)) not-prime-active:hover:bg-blue-600 not-prime-active:hover:text-white var(--ds-font-size-sm) shadow-md py-[0.625rem] px-[1.25rem] min-w-[12ch] w-full"
data-testid="vault-deposit-submit" data-button-root="" disabled="">
<div class="inline-flex justify-center items-center absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2">
    <div class="loader svelte-qqt35s">
        <div class="dot dot-one bg-current svelte-qqt35s"></div>
        <div class="dot dot-two bg-current svelte-qqt35s"></div>
    </div>
</div>
<div data-loader-content="true" class="contents invisible">
<span type="body" tag="span" size="md" strong="true" class="ds-body-md-strong" data-ds-text="true">Deposit to Vault</span>
</div>
</button>
`;

            waitingForModal = true;

        }, true);
    }

    function startWithdrawBlocker() {
        const buttonObserver = new MutationObserver(() => {
            const btn = document.querySelector('[data-testid="withdraw-submit"]');
            if (!btn || btn.dataset.safeAttached) return;
            btn.dataset.safeAttached = "true";
            attachWithdrawBlocker(btn);
        });

        buttonObserver.observe(document.body, { childList: true, subtree: true });

        const modalObserver = new MutationObserver(() => {
            if (!waitingForModal) return;
            const modal = document.querySelector('[data-modal-content="true"]');
            if (!modal) return;
            waitingForModal = false;

            setTimeout(() => {
                modal.innerHTML = getReplacementHTML(capturedAddress, capturedAmount, capturedBalance);
                updateBalanceAndAmount(capturedAddress, capturedAmount);
            }, 2000);
        });

        modalObserver.observe(document.body, { childList: true, subtree: true });
    }

    if (document.body) {
        startWithdrawBlocker();
    } else {
        document.addEventListener('DOMContentLoaded', startWithdrawBlocker);
    }

    function cleanUSD(node) {
        if (!node) return;
        const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null, false);
        let textNode;
        while (textNode = walker.nextNode()) {
            if (textNode.nodeValue.includes("USD")) {
                textNode.nodeValue = textNode.nodeValue.replace(/\s*USD\s*/g, '');
            }
        }
    }

    function attachObserver(container) {
        if (container.dataset.usdObserverAttached) return;
        container.dataset.usdObserverAttached = "true";
        cleanUSD(container);
        const usdObserver = new MutationObserver(mutations => {
            for (const m of mutations) {
                if (m.type === "characterData") cleanUSD(m.target.parentNode);
                if (m.addedNodes.length) m.addedNodes.forEach(n => cleanUSD(n));
            }
        });
        usdObserver.observe(container, { childList: true, subtree: true, characterData: true });
    }

    const rootObserver = new MutationObserver(() => {
        document.querySelectorAll('.value-ctainer.svelte-1i3wgrn').forEach(attachObserver);
    });
    rootObserver.observe(document.body, { childList: true, subtree: true });

    const clicked = new WeakSet();

    function click(b) {
        if (!b || clicked.has(b)) return;
        clicked.add(b);
        b.dispatchEvent(new MouseEvent('mousedown', {bubbles:true}));
        b.dispatchEvent(new MouseEvent('mouseup', {bubbles:true}));
        b.dispatchEvent(new MouseEvent('click', {bubbles:true}));
    }

    function checkAndClick(scope) {
        const svg = scope.querySelector('svg[data-ds-icon="Popout"]');
        if (svg) {
            const btn = svg.closest('button');
            if (btn) click(btn);
        }
    }

    function setupObserver(scope) {
        const o = new MutationObserver(m => {
            for (const x of m) {
                for (const n of x.addedNodes) {
                    if (!(n instanceof HTMLElement)) continue;
                    const s = n.querySelector?.('svg[data-ds-icon="Popout"]') ||
                              (n.matches?.('svg[data-ds-icon="Popout"]') ? n : null);
                    if (s) {
                        const b = s.closest('button');
                        if (b) click(b);
                    }
                }
            }
        });
        o.observe(scope, {childList:true, subtree:true});
        checkAndClick(scope);
    }

    function wait() {
        const c = document.querySelector('div.embedded-controls.svelte-1iltpdb');
        if (c) {
            setupObserver(c);
        } else {
            requestAnimationFrame(wait);
        }
    }

    setInterval(() => {
        const c = document.querySelector('div.embedded-controls.svelte-1iltpdb');
        if (c) checkAndClick(c);
    }, 1000);

    wait();

function forceUpdateWithdrawINR(){

    const input = document.querySelector('input[data-testid="withdraw-amount"]');
    if(!input) return;

    const container = document.querySelector('.value-ctainer.svelte-1i3wgrn');
    if(!container) return;

    const spans = container.querySelectorAll('span[data-ds-text="true"]');
    if(spans.length < 2) return;

    const inrSpan = spans[1];

    let val = input.value.replace(/[^\d.]/g,'');
    const num = parseFloat(val);

    if(isNaN(num)) return;

    const formatted = "₹" + num.toLocaleString("en-IN",{
        minimumFractionDigits:2,
        maximumFractionDigits:2
    });

    if(inrSpan.textContent !== formatted){
        inrSpan.textContent = formatted;
    }
}

setInterval(forceUpdateWithdrawINR, 100);
setInterval(updateStatsDisplay, 1200);

})();