<?php
// ================= MODE DEVELOPER =================
$DEV_MODE = false; // ⚠️ ubah ke false di production


session_start();
require_once __DIR__ . '/../../../../function/connect.php';

$id_user = $_SESSION['extplayer'];
$today   = date('Y-m-d');

// CEK LOGIN
if (!isset($_SESSION['extplayer']) || empty($_SESSION['extplayer'])) {
    header("Location: index.php?pesan=23"); // arahkan ke home
    exit;
}

$rewardsArr = [
    1000,
    1000,
    1000,
    5000,
    5000,
    10000,
    10000,
    20000,
    20000,
    25000,
    25000,
    50000,
    50000,
    100000,
    277000,
    900000
];

$rewardsJson = json_encode($rewardsArr);
// ================= AMBIL HADIAH DARI USER =================
$qUser = mysqli_query($koneksi, "
    SELECT roda_hadiah
    FROM tb_user
    WHERE extplayer = '$id_user'
    LIMIT 1
");

$user = mysqli_fetch_assoc($qUser);
$winConfig = (int)($user['roda_hadiah'] ?? 0);

// ================= VALIDASI =================
$winIndex = array_search($winConfig, $rewardsArr, true);

// fallback aman
if ($winIndex === false) {
    $winIndex = 0;
    $winConfig = $rewardsArr[0];
}

if ($DEV_MODE) {
    $spin = 9999; // unlimited demo spin
}

// HITUNG DEPOSIT HARI INI (top up sukses)
$q = mysqli_query($koneksi, "
    SELECT COUNT(*) AS total
    FROM tb_transaksi
    WHERE id_user = '$id_user'
    AND transaksi = 'Top Up'
    AND status = 'Sukses'
    AND DATE(tanggal) = '$today'
");
$data = mysqli_fetch_assoc($q);
$depositCount = (int)$data['total'];

// HITUNG BONUS SPIN YANG SUDAH DITERIMA HARI INI (misal id_bonus=7 untuk spin)
$q2 = mysqli_query($koneksi, "
    SELECT COUNT(*) AS used_spin
    FROM tb_bonus
    WHERE id_user = '$id_user'
    AND id_bonus = '7'
    AND DATE(tanggal) = '$today'
");
$data2 = mysqli_fetch_assoc($q2);
$usedSpin = (int)$data2['used_spin'];

// Total spin = depositCount (max 2) - usedSpin
$maxSpinPerDay = 2;
$spin = max(0, min($depositCount, $maxSpinPerDay) - $usedSpin);

// ================= RIWAYAT BONUS / TURNOVER =================
$qTurnover = mysqli_query($koneksi, "
    SELECT nominal, tanggal, status
    FROM tb_bonus
    WHERE id_user = '$id_user'
    ORDER BY tanggal DESC
    LIMIT 20
");
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css?v=2.6.0.0">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Roda Hadiah - koiwin</title>
</head>
<body>

<div class="none-header">
    <div class="left" onclick="window.location.href='?page=home'">
        <i class="fas fa-chevron-left"></i> Back
    </div>
    <div class="right">
        <a id="openRiwayat" class="icon-btn-none">
            <i class="fa-solid fa-list"></i> Riwayat Bonus
        </a>
        <a id="openLeaderboard" class="icon-btn-none">
            <i class="fa-solid fa-trophy"></i> Leaderboard
        </a>
        <a href="javascript:void(0)" onclick="openLiveChat()" class="button-nav">
            <i class="fas fa-headset m-auto"></i>
        </a>
    </div>
</div>

<div class="title"><span>Roda</span> Hadiah</div>
<div class="wheel-wrap">
    <div class="pointer"></div>
    <div class="outer">
        <div class="wheel-lights"></div>
        <div class="wheel" id="wheel">
            <?php
            $totalSlices = count($rewardsArr);
            $degPerSlice = 360 / $totalSlices;

            // buat dividers & slices
            for ($i = 0; $i < $totalSlices; $i++):
                $deg = $i * $degPerSlice;
                $nominal = $rewardsArr[$i];
                // pilih ikon sesuai nominal (contoh)
                if ($nominal <= 1000) $icon = 'fa-coins';
                elseif ($nominal < 100000) $icon = 'fa-gem';
                else $icon = 'fa-diamond'; // atau ikon lain
            ?>
                <!-- Divider -->
                <div class="divider" style="transform:rotate(<?= $deg ?>deg)"></div>
                
                <!-- Slice -->
                <div class="slice" style="transform:rotate(<?= $deg ?>deg)">
                    <span><i class="fa-solid <?= $icon ?>"></i>Rp <?= number_format($nominal, 0, ',', '.') ?></span>
                </div>
            <?php endfor; ?>
        </div>

        <!-- TOMBOL SPIN (TIDAK IKUT MUTER) -->
        <div class="center">
            <div class="spin-btn" onclick="spin()">SPIN</div>
        </div>
        <?php if ($DEV_MODE): ?>
        <div class="center">
            <div class="spin-btn" onclick="spinDemo()">DEMO</div>
        </div>
        <?php endif; ?>
    </div>
</div>
<div class="info">
    Anda memiliki <b id="spinCount"><?= $spin ?></b> Spin
</div>
<div class="deposit">
    <div>
        Setiap deposit x1 Spin<br>
        <small>Deposit hari ini: <?= $spin ?>/∞</small>
    </div>
    <button>Deposit</button>
</div>
<div class="popup" id="popup">
    <div class="popup-box">
        <h2 id="resultText"></h2>
<button onclick="document.getElementById('popup').style.display='none'">OK</button>
    </div>
</div>

<!-- MODAL -->
<div id="riwayatModal" class="modal">
    <div class="modal-content">
        <div class="modal-header">
            <span class="modal-title"><i class="fa-solid fa-list"></i> Riwayat Bonus</span>
            <span class="modal-close">&times;</span>
        </div>
        <div class="modal-body">
            <div class="turnover-table">
                <table>
                    <thead>
                        <tr>
                            <th>Nominal</th>
                            <th>Tanggal</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody id="historyBody">
                        <tr>
                            <td colspan="3" class="empty">Memuat data...</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div> <!-- Tutup modal-content riwayatModal -->
</div> <!-- Tutup riwayatModal -->

<!-- MODAL LEADERBOARD -->
<div id="leaderboardModal" class="modal">
    <div class="modal-content leaderboard leaderboard-modern">

        <div class="modal-header">
            <span class="modal-title"><i class="fa-solid fa-trophy"></i> Leaderboard</span>
            <span class="modal-close" id="closeLeaderboard">&times;</span>
        </div>

        <div class="lb-user-card">
            <div class="lb-user-left">
                <img id="lbAvatar" class="lb-avatar" alt="Avatar">
                <div>
                    <div class="lb-username" id="lbUsername">-</div>
                    <div class="lb-badge">User</div>
                </div>
            </div>

            <div class="lb-user-stats">
                <div>
                    <small>Posisi Saya</small>
                    <b class="green" id="lbRank">-</b>
                </div>
                <div>
                    <small>Total Win</small>
                    <b class="green" id="lbTotalWin">Rp 0</b>
                </div>
                <div>
                    <small>Bonus</small>
                    <b class="green" id="lbBonus">Rp 0</b>
                </div>
            </div>

            <button class="lb-play-btn">🏆 Main untuk Hadiah Lebih Besar!</button>
        </div>

        <!-- LIST -->
        <div class="leaderboard-list" id="leaderboardBody">
            <div class="loading">Memuat leaderboard...</div>
        </div>

    </div>
</div>


<link
    rel="stylesheet"
    id="templateStyle"
    type="text/css"
    href="luxury-them/custom/css/style.css?v=2.6.0.0"
>

<script>
const DEV_MODE = <?= $DEV_MODE ? 'true' : 'false' ?>;

function spinDemo(forceIndex = null) {
    if (spinning) return;
    spinning = true;

    const index = Math.floor(Math.random() * rewards.length);

    const sliceDeg = 360 / rewards.length;
    const sliceCenter = index * sliceDeg + sliceDeg / 2;
    const pointerDeg = 270;
    const fullSpin = 360 * 4;

    const finalDeg = fullSpin + (pointerDeg - sliceCenter);

    wheel.style.transition = 'none';
    wheel.style.transform = 'rotate(0deg)';
    wheel.offsetHeight;

    wheel.style.transition = 'transform 1s cubic-bezier(.17,.67,.17,1)';
    wheel.style.transform = `rotate(${finalDeg}deg)`;

    setTimeout(() => {
        const realIndex = (index + 1) % rewards.length;
        const reward = rewards[realIndex];
        resultText.innerText = '[DEMO] ' + reward;
        popup.style.display = 'flex';

        console.log('🎯 DEMO RESULT:', reward);
        spinning = false;
    }, 1000);
}
</script>
<script>
const leaderboardModal = document.getElementById("leaderboardModal");
const openLeaderboard  = document.getElementById("openLeaderboard");
const leaderboardBody  = document.getElementById("leaderboardBody");
const closeLeaderboard = leaderboardModal.querySelector(".modal-close");

openLeaderboard.onclick = () => {
    leaderboardModal.style.display = "flex";
    loadLeaderboardHeader(); // ⬅️ ini
    loadLeaderboard();
};

closeLeaderboard.onclick = () => {
    leaderboardModal.style.display = "none";
};

window.onclick = e => {
    if (e.target === leaderboardModal) {
        leaderboardModal.style.display = "none";
    }
};

function loadLeaderboard() {
    leaderboardBody.innerHTML = `<div class="loading">Memuat leaderboard...</div>`;
    
    fetch('template/page/hadiah/load_leaderboard.php')
        .then(res => res.json())
        .then(data => {
            
            if (!data || data.length === 0) {
                leaderboardBody.innerHTML = `<div class="empty">Belum ada data</div>`;
                return;
            }
            
            let html = '';
            
            data.forEach(user => {
                html += `
                <div class="lb-row">
                    <div class="lb-rank ${user.rank <= 3 ? 'top'+user.rank : ''}">
                        ${user.rank}
                    </div>

                    <img src="/../../../../uploads/avatar/${user.avatar}" class="lb-avatar-sm">

                    <div class="lb-info">
                        <div class="lb-name">${user.username}</div>
                        <div class="lb-turnover">Rp ${Number(user.total_win).toLocaleString()}</div>
                    </div>

                    <div class="lbBonus">
                        Rp ${Number(user.bonus).toLocaleString()}
                    </div>
                </div>
                `;
            });
            
            leaderboardBody.innerHTML = html;
        });
}
</script>
<script>

function loadLeaderboardHeader() {
    
    // Tutup modal leaderboard saat tombol close di klik
document.getElementById('closeLeaderboard').addEventListener('click', function() {
    document.getElementById('leaderboardModal').style.display = 'none';
});

    fetch('template/page/hadiah/load_leaderboard_header.php')
        .then(res => res.json())
        .then(data => {
            if (!data.username) return;

            document.getElementById('lbUsername').innerText = data.username;
            document.getElementById('lbAvatar').src =
                '/../../../../uploads/avatar/' + data.avatar;

            document.getElementById('lbRank').innerText = data.posisi;
            document.getElementById('lbTotalWin').innerText =
                'Rp ' + Number(data.total_win).toLocaleString();

            document.getElementById('lbBonus').innerText =
                'Rp ' + Number(data.bonus).toLocaleString();
        });
}
</script>
<script>

const rewards = <?= $rewardsJson ?>; // dari PHP
const winIndex = <?= $winIndex ?>;

let spinning = false;
let spinLeft = <?= $spin ?>;

function spin() {
    if (spinning || spinLeft <= 0) return;
    spinning = true;
    
    fetch('template/page/hadiah/spin_process.php', {
            method: 'POST'
        })
        .then(res => res.json())
        .then(res => {
            if (res.status !== 'success') {
                alert(res.message);
                spinning = false;
                return;
            }
            
            const reward = res.nominal;
            const winIndex = rewards.indexOf(reward);
            
            if (winIndex === -1) {
                alert('Config hadiah tidak valid');
                spinning = false;
                return;
            }
            
            spinLeft--;
            document.getElementById('spinCount').innerText = spinLeft;
            
            const sliceDeg = 360 / rewards.length;
            const baseOffset = sliceDeg / -5;
            const jitter = sliceDeg * 0.08;
            const randomShift = (Math.random() * jitter * -1) - jitter;
            
            const sliceCenter = (winIndex * sliceDeg) + baseOffset + randomShift;
            const pointerDeg = 270;
            const finalDeg = (360 * 6) + (pointerDeg - sliceCenter);
            
            const wheel = document.getElementById('wheel');
            const popup = document.getElementById('popup');
            const resultText = document.getElementById('resultText');
            
            wheel.style.transition = 'none';
            wheel.style.transform = 'rotate(0deg)';
            wheel.offsetHeight;
            
            wheel.style.transition = 'transform 1s cubic-bezier(.17,.67,.17,1)';
            wheel.style.transform = `rotate(${finalDeg}deg)`;
            
            setTimeout(() => {
                resultText.innerText = 'Anda mendapatkan Rp ' + reward.toLocaleString();
                popup.style.display = 'flex';
                spinning = false;
            }, 1000);
        });
}
</script>
<script>
const modal = document.getElementById("riwayatModal");
const openBtn = document.getElementById("openRiwayat");
const closeBtn = modal.querySelector(".modal-close");
const historyBody = document.getElementById("historyBody");

openBtn.onclick = () => {
    modal.style.display = "flex";
    loadHistory();
};

closeBtn.onclick = () => modal.style.display = "none";

window.onclick = e => {
    if (e.target === modal) modal.style.display = "none";
};

function loadHistory() {
    historyBody.innerHTML = `
        <tr>
            <td colspan="3" class="empty">Memuat data...</td>
        </tr>
    `;

    fetch('template/page/hadiah/load_history.php')
        .then(res => res.json())
        .then(data => {
            if (data.length === 0) {
                historyBody.innerHTML = `
                    <tr>
                        <td colspan="3" class="empty">Belum ada riwayat</td>
                    </tr>
                `;
                return;
            }

            let html = '';
            data.forEach(row => {
                html += `
                    <tr>
                        <td class="gold">Rp ${Number(row.nominal).toLocaleString()}</td>
                        <td>${formatDate(row.tanggal)}</td>
                        <td>
                            <span class="status ${row.status.toLowerCase()}">
                                ${row.status}
                            </span>
                        </td>
                    </tr>
                `;
            });

            historyBody.innerHTML = html;
        });
}

function formatDate(dateStr) {
    const d = new Date(dateStr);
    return d.toLocaleDateString('id-ID', {
        day: '2-digit',
        month: '2-digit',
        year: 'numeric',
        hour: '2-digit',
        minute: '2-digit'
    });
}
</script>

</body>
</html>

<style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: Arial, Helvetica, sans-serif;
        }

        body {
            min-height: 100vh;
            background: #121212; /* Warna hitam gelap tema utama */
            
        }


        .title {
            text-align: center;
            font-size: 34px;
            font-weight: 900;
            margin: 8px 0 18px;
            color: #d4af37;
        }

        .title span {
            color: #ffaa00; /* Warna emas lebih cerah */
        }

        .wheel-wrap {
            width: 95vw;
            max-width: 380px;
            aspect-ratio: 1/1;
            margin: 0 auto;
            position: relative;
        }

        .wheel-lights {
            position: absolute;
            inset: 6px;
            border-radius: 50%;
            pointer-events: none;
            background:
                radial-gradient(circle at 50% 0%, #d4af37 6px, transparent 7px),
                radial-gradient(circle at 85% 15%, #d4af37 6px, transparent 7px),
                radial-gradient(circle at 100% 50%, #d4af37 6px, transparent 7px),
                radial-gradient(circle at 85% 85%, #d4af37 6px, transparent 7px),
                radial-gradient(circle at 50% 100%, #d4af37 6px, transparent 7px),
                radial-gradient(circle at 15% 85%, #d4af37 6px, transparent 7px),
                radial-gradient(circle at 0% 50%, #d4af37 6px, transparent 7px),
                radial-gradient(circle at 15% 15%, #d4af37 6px, transparent 7px);
            animation: spinLights 50s linear infinite, blink 2s ease-in-out infinite alternate;
            filter: drop-shadow(0 0 6px rgba(212, 175, 55, 0.8));
            z-index: 4;
        }

        @keyframes spinLights {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        @keyframes blink {
            from { opacity: 0.5; }
            to { opacity: 1; }
        }

        .pointer {
            position: absolute;
            top: -2px;
            left: 50%;
            transform: translateX(-50%);
            width: 0;
            height: 0;
            border-left: 14px solid transparent;
            border-right: 14px solid transparent;
            border-top: 26px solid #bfa20a; /* Warna emas keemasan */
            z-index: 20;
        }

        .outer {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            padding: 16px;
            border: 7px solid #b68d00; /* Warna emas */
            box-shadow: 0 0 20px rgba(182, 141, 0, 0.9);
        }

        .wheel {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            position: relative;
            transition: transform 8s ease-out;
            overflow: hidden;
            background: conic-gradient(
                #d4af37 0deg 22.5deg,   /* slice 1 */
                #926f00 22.5deg 45deg,  /* slice 2 */
                #4a3c00 45deg 67.5deg,  /* slice 3 */
                #b68600 67.5deg 90deg,  /* slice 4 */
                #554b00 90deg 112.5deg, /* slice 5 */
                #000000 112.5deg 135deg, /* slice 6 */
                #a38600 135deg 157.5deg, /* slice 7 */
                #664c00 157.5deg 180deg, /* slice 8 */
                #d4af37 180deg 202.5deg, /* slice 9 */
                #926f00 202.5deg 225deg, /* slice 10 */
                #4a3c00 225deg 247.5deg, /* slice 11 */
                #b68600 247.5deg 270deg, /* slice 12 */
                #554b00 270deg 292.5deg, /* slice 13 */
                #000000 292.5deg 315deg, /* slice 14 */
                #a38600 315deg 337.5deg, /* slice 15 */
                #664c00 337.5deg 360deg  /* slice 16 */
            );
        }

        /* ===== PEMBATAS IRISAN ===== */
        .divider {
            position: absolute;
            width: 50%;
            height: 3px;
            top: 50%;
            left: 50%;
            transform-origin: 0% 50%;
            background: linear-gradient(90deg, #d4af37, #fff0a1, #d4af37);
            z-index: 3;
            box-shadow: 0 0 8px rgba(212, 175, 55, 0.8);
        }

        /* ===== LABEL ===== */
        .slice {
            position: absolute;
            width: 50%;
            height: 50%;
            top: 50%;
            left: 50%;
            transform-origin: 0% 0%;
            z-index: 3;
        }

        .slice span {
            position: absolute;
            left: 50%;
            top:-22%;
            
            font-weight: 200;
            font-size: 12px; /* Font diperkecil untuk kenyamanan */
            color: #ffda6a;
            text-shadow: 0 0 3px rgba(0,0,0,0.6);
            white-space: nowrap;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 1px;
            line-height: 1.2;
            width: 100px;
            max-width: 80px; /* optional untuk teks panjang */
            text-align: center;
        }

        .slice span i {
            font-size: 16px; /* Ikon diperkecil */
            color: #f4a300;
            margin-bottom:2px;
        }

        .center {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 5;
        }

        .spin-btn {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            background: linear-gradient(180deg, #b68d00, #b38600);
            box-shadow: 0 8px 18px rgba(182, 141, 0, 0.7);
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 900;
            font-size: 17px;
            color: #121212;
            cursor: pointer;
            transition: transform 0.2s;
        }

        .spin-btn:hover {
            transform: scale(1.05);
        }

        .info {
            text-align: center;
            margin: 14px 0;
            font-size: 18px;
            font-weight: 600;
            color: #d4af37;
        }

        .deposit {
            margin: 18px 16px;
            background: linear-gradient(180deg, #4a3c00, #b68d00); /* gold dark */
            border-radius: 16px;
            padding: 16px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: #ffda6a; /* teks emas cerah */
        }

        .deposit button {
            padding: 10px 18px;
            border-radius: 10px;
            background: linear-gradient(180deg, #b68d00, #f4a300); /* emas cerah */
            border: none;
            font-weight: 800;
            color: #121212; /* teks gelap supaya kontras */
            cursor: pointer;
            transition: transform 0.2s;
        }

        .deposit button:hover {
            transform: scale(1.05);
        }

        .popup {
            position: fixed;
            inset: 0;
            background: rgba(30, 0, 60, 0.25);
            backdrop-filter: blur(2px);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: 99;
        }

        .popup-box {
            background: linear-gradient(180deg, #4a3c00, #b68d00);
            padding: 16px 24px; /* Padding diperkecil */
            border-radius: 12px; /* Border-radius diperkecil */
            text-align: center;
            box-shadow: 0 0 20px rgba(182, 141, 0, 0.9);
            color: #121212;
            font-weight: 700;
            font-size: 14px; /* Font size diperkecil */
            max-width: 280px; /* Lebar maksimal diperkecil */
            width: 90%;
        }

        .popup-box button {
            margin-top: 10px;
            padding: 6px 14px; /* Padding diperkecil */
            border: none;
            border-radius: 6px; /* Border-radius diperkecil */
            background: #d4af37;
            font-weight: 800;
            cursor: pointer;
            color: #121212;
            font-size: 14px; /* Font size diperkecil */
            transition: background 0.2s;
        }

        .popup-box button:hover {
            background: #bfa20a;
        }

        /* ================= TURNOVER TABLE ================= */
        .turnover-wrap {
            margin: 2px 16px 40px;
            background: linear-gradient(180deg, #1e1e1e, #161616);
            border-radius: 16px;
            padding: 14px;
            box-shadow: 0 0 18px rgba(212, 175, 55, 0.25);
        }

        .turnover-title {
            font-size: 16px;
            font-weight: 800;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 8px;
            color: #d4af37;
        }

        .turnover-table {
            overflow-x: auto;
        }

        .turnover-table table {
            width: 100%;
            border-collapse: collapse;
            font-size: 13px;
            min-width: 300px;
        }

        .turnover-table th {
            background: #141414;
            color: #ffda6a;
            padding: 10px;
            text-align: left;
            font-weight: 700;
            white-space: nowrap;
        }

        .turnover-table td {
            padding: 10px;
            border-bottom: 1px solid rgba(212, 175, 55, 0.15);
            color: #e6c97a;
            white-space: nowrap;
        }

        .turnover-table tr:last-child td {
            border-bottom: none;
        }

        .turnover-table .gold {
            color: #ffda6a;
            font-weight: 700;
        }

        /* STATUS BADGE */
        .status {
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 11px;
            font-weight: 800;
            display: inline-block;
        }

        .status.sukses {
            background: rgba(0, 200, 120, 0.15);
            color: #3dffb2;
        }

        .status.pending {
            background: rgba(255, 200, 0, 0.15);
            color: #ffd966;
        }

        .status.gagal {
            background: rgba(255, 80, 80, 0.15);
            color: #ff8a8a;
        }

        .empty {
            text-align: center;
            padding: 18px;
            color: #888;
            font-style: italic;
        }

        .modal {
            display: none;
            position: fixed;
            z-index: 999;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow-y: auto;
            background: rgba(0,0,0,0.65);
            backdrop-filter: blur(2px);
        }

        .modal-content {
            background: linear-gradient(180deg,#1e1e1e,#161616);
            margin: 60px auto;
            border-radius: 16px;
            padding: 16px;
            width: 90%;
            max-width: 400px;
            box-shadow: 0 0 25px rgba(212,175,55,0.5);
            animation: slideDown 0.3s ease-out;
        }

        @keyframes slideDown {
            from { transform: translateY(-50px); opacity:0; }
            to { transform: translateY(0); opacity:1; }
        }

        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-weight: 700;
            color: #d4af37;
            margin-bottom: 12px;
        }

        .modal-close {
            cursor: pointer;
            font-size: 20px;
            color: #ffda6a;
        }

        .modal-body {
            max-height: 300px;
            overflow-y: auto;
        }
        
        
        .leaderboard {
            max-width: 420px;
        }
        
        .leaderboard-list {
            max-height: 70vh;
            overflow-y: auto;
        }
        
        .leaderboard-item {
            display: flex;
            align-items: center;
            padding: 10px;
            border-bottom: 1px solid rgba(255,255,255,.08);
        }
        
        .leaderboard-item .rank {
            width: 40px;
            font-weight: bold;
            color: gold;
        }
        
        .leaderboard-item .avatar {
            width: 42px;
            height: 42px;
            border-radius: 50%;
            margin-right: 10px;
            object-fit: cover;
        }
        
        .leaderboard-item .info {
            flex: 1;
        }
        
        .leaderboard-item .username {
            font-weight: 600;
        }
        
        .leaderboard-item .total {
            font-size: 13px;
            color: #f4d03f;
        }
        
        /* TOP 3 SPECIAL */
        .leaderboard-item.top1 { background: linear-gradient(90deg,#ffd70022,#0000); }
        .leaderboard-item.top2 { background: linear-gradient(90deg,#c0c0c022,#0000); }
        .leaderboard-item.top3 { background: linear-gradient(90deg,#cd7f3222,#0000); }
        
        /* ===== LEADERBOARD MODERN ===== */
.leaderboard-modern {
    padding: 0;
}

.lb-user-card {
    background: #1c1c1c;
    padding: 14px;
    border-radius: 16px;
    margin-bottom: 14px;
}

.lb-user-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.lb-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
}

.lb-username {
    font-weight: 700;
}

.lb-badge {
    font-size: 12px;
    color: #888;
}

.lb-user-stats {
    display: flex;
    justify-content: space-between;
    margin: 12px 0;
    text-align: center;
}

.lb-user-stats small {
    font-size: 11px;
    color: #888;
}

.lb-user-stats b {
    display: block;
    font-size: 14px;
}

.green {
    color: #4cff9a;
}

.lb-play-btn {
    width: 100%;
    border: none;
    padding: 10px;
    border-radius: 12px;
    font-weight: 800;
    background: linear-gradient(180deg,#f7d774,#cfa92b);
    cursor: pointer;
}

/* ===== LIST ===== */
.lb-row {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.lb-rank {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #2a2a2a;
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
}

.lb-rank.top1 { background: #ffd700; color:#000 }
.lb-rank.top2 { background: #c0c0c0; color:#000 }
.lb-rank.top3 { background: #cd7f32; color:#000 }

.lb-avatar-sm {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 10px;
}

.lb-info {
    flex: 1;
}

.lb-name {
    font-weight: 600;
}

.lb-turnover {
    font-size: 12px;
    color: #aaa;
}

.lb-bonus {
    font-weight: 700;
    color: #4cff9a;
}

</style>   