<!doctype html>
<html lang="id">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title><?php echo $instansi ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="icon" type="image/png" href="https://spinpakarjitu399.fun/uploads/fav_url_1774032019.png?t=1774898741">
    <link rel="stylesheet" href="assets/css/livechat.css">
    
    <style>
/* ===========================
            CSS VARIABLES & RESET
         =========================== */
        :root {
            --primary-gold: #ffd700;
            --secondary-gold: #b8860b;
            --primary-red: #ff0000;
            --dark-red: #8b0000;
            --dark-bg: rgba(0, 0, 0, 0.85);
            --darker-bg: rgba(20, 0, 0, 0.95);
            --glass-effect: rgba(255, 255, 255, 0.1);
            --shadow-glow: 0 0 20px rgba(255, 215, 0, 0.3);
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        /* ===========================
            CONFETTI CANVAS - PALING DEPAN
         =========================== */
        .confetti-canvas {
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
            width: 100vw !important;
            height: 100vh !important;
            pointer-events: none !important;
            z-index: 999999 !important;
        }
        
        /* ===========================
            SWEETALERT STYLING
         =========================== */
        .swal2-container {
            z-index: 999998 !important;
        }
        
        .swal2-popup { 
            background: linear-gradient(135deg, var(--darker-bg), #2a0a0a) !important;
            border: 2px solid var(--primary-gold) !important;
            border-radius: 25px !important;
            box-shadow: 0 0 50px rgba(255, 0, 0, 0.5), inset 0 0 20px rgba(255, 215, 0, 0.2) !important;
            color: #ffffff !important;
            max-width: min(90%, 500px) !important;
            backdrop-filter: blur(10px);
        }
        
        .swal2-title {
            color: var(--primary-gold) !important;
            text-transform: uppercase;
            font-weight: 800;
            text-shadow: 2px 2px 4px #000;
            font-size: clamp(1.2rem, 5vw, 2rem) !important;
            letter-spacing: 2px;
        }
        
        .swal2-html-container { 
            color: #f0f0f0 !important;
            font-size: clamp(0.9rem, 3vw, 1.1rem) !important;
        }
        
        .swal2-confirm {
            background: linear-gradient(135deg, var(--primary-gold), var(--secondary-gold)) !important;
            color: #000 !important;
            font-weight: bold !important;
            padding: 12px 35px !important;
            border-radius: 50px !important;
            font-size: 16px !important;
            transition: transform 0.2s !important;
        }
        
        .swal2-confirm:hover {
            transform: scale(1.05) !important;
        }
        
        /* ===========================
            BODY & MAIN LAYOUT
         =========================== */
        body { 
            background: url('http://spinpakarjitu399.fun/uploads/bg_url_1774108863.jpg') no-repeat center center fixed; 
            background-size: cover; 
            color: white; 
            font-family: 'Poppins', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
            min-height: 100vh; 
            position: relative;
            overflow-x: hidden;
        }
        
        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(135deg, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.4) 100%);
            pointer-events: none;
            z-index: 0;
        }
        
        .main-container { 
            position: relative;
            z-index: 10;
            width: 100%; 
            max-width: 1400px; 
            margin: 0 auto;
            padding: 20px;
        }
        
        .game-wrapper { 
            display: flex; 
            flex-direction: column; 
            align-items: center; 
            justify-content: center; 
            gap: 40px; 
        }
        
        /* ===========================
            TOP LOGO AREA
         =========================== */
        .top-logo-container { 
            width: 100%; 
            text-align: center; 
            margin-bottom: 20px; 
        }
        
        .scroll-wrapper { 
            position: relative; 
            display: inline-block; 
            animation: floatLogo 3s ease-in-out infinite;
        }
        
        @keyframes floatLogo {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }
        
        .scroll-bg { 
            width: 100%; 
            max-width: min(300px, 85vw);
            filter: drop-shadow(0 10px 20px rgba(0,0,0,0.5));
        }
        
        .main-logo { 
            position: absolute; 
            top: 50%; 
            left: 50%; 
            transform: translate(-50%, -50%); 
            max-width: 65%;
            filter: drop-shadow(0 0 20px rgba(255,0,0,0.8)); 
        }
        
        /* ===========================
            WHEEL SECTION - MODERN
         =========================== */
        .wheel-section {
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
        }
        
        .wheel-card {
            background: rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(10px);
            border-radius: 50%;
            padding: 20px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.4), inset 0 1px 1px rgba(255,255,255,0.2);
            border: 1px solid rgba(255,215,0,0.3);
        }
        
        .wheel-box { 
            position: relative; 
            width: 100%; 
            max-width: min(400px, 85vw);
            aspect-ratio: 1;
            display: flex; 
            align-items: center; 
            justify-content: center; 
            z-index: 100;
            animation: floating 4s ease-in-out infinite; 
        }
        
        @keyframes floating {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-8px); }
        }
        
        .wheel-frame { 
            position: absolute; 
            width: 135%; 
            height: 135%; 
            background-repeat: no-repeat; 
            background-position: center; 
            background-size: contain; 
            z-index: 10; 
            pointer-events: none;
            filter: drop-shadow(0 0 15px rgba(255,215,0,0.5));
        }
        
        #canvas { 
            width: 76% !important; 
            height: 76% !important; 
            z-index: 5; 
            border-radius: 50%;
            box-shadow: 0 0 30px rgba(0,0,0,0.5);
            transition: transform 0.3s ease;
        }
        
        /* ===========================
            OVERLAY & SPIN EFFECTS
         =========================== */
        .body-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.8);
            backdrop-filter: blur(5px);
            z-index: 150; /* Di atas segalanya */
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.4s ease;
        }
        
        .body-overlay.active {
            opacity: 1;
            pointer-events: auto;
        }
        
        @keyframes enhancedShake {
            0%, 100% { transform: translate(0, 0) rotate(0); }
            10% { transform: translate(-5px, 4px) rotate(-2deg); }
            20% { transform: translate(5px, -4px) rotate(2deg); }
            30% { transform: translate(-4px, 3px) rotate(-1.5deg); }
            40% { transform: translate(4px, -3px) rotate(1.5deg); }
            50% { transform: translate(-3px, 4px) rotate(-1deg); }
            60% { transform: translate(3px, -4px) rotate(1deg); }
            70% { transform: translate(-4px, 2px) rotate(-1deg); }
            80% { transform: translate(4px, -2px) rotate(1deg); }
            90% { transform: translate(-2px, 1px) rotate(-0.5deg); }
        }
        
        .shake-wheel .wheel-frame,
        .shake-wheel #canvas {
            animation: enhancedShake 0.12s infinite;
        }
        
        .spin-overlay-effect {
            position: absolute;
            inset: 0;
            border-radius: 50%;
            z-index: 15;
            opacity: 0;
            pointer-events: none;
            background: radial-gradient(circle, rgba(255,215,0,0.2) 0%, rgba(255,215,0,0) 70%);
            transition: opacity 0.3s;
        }
        
        .spin-overlay-effect.active {
            opacity: 1;
            animation: spinGlowPulse 1s ease-in-out infinite;
        }
        
        @keyframes spinGlowPulse {
            0%, 100% { 
                box-shadow: 0 0 30px rgba(255,215,0,0.4), inset 0 0 50px rgba(255,215,0,0.2);
            }
            50% { 
                box-shadow: 0 0 70px rgba(255,215,0,0.8), inset 0 0 80px rgba(255,215,0,0.4);
            }
        }
        
        /* SPIN CONFIRM BUTTON */
        .spin-confirm-overlay {
            position: absolute;
            inset: 0;
            z-index: 200; /* Paling atas melebihi backdrop */
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            pointer-events: auto;
            opacity: 0;
            transform: scale(0.9);
            transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
            background: radial-gradient(circle, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 100%);
            border-radius: 50%;
        }
        
        .spin-confirm-overlay:not(.hidden) {
            opacity: 1;
            transform: scale(1);
        }
        
        .spin-confirm-overlay.hidden {
            display: none;
        }
        
        .spin-confirm-box {
            position: relative;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 12px;
            background: linear-gradient(135deg, rgba(0,0,0,0.9), rgba(139,0,0,0.8));
            border-radius: 60px;
            padding: 20px 35px;
            border: 2px solid var(--primary-gold);
            box-shadow: 0 0 40px rgba(255,215,0,0.6);
            backdrop-filter: blur(10px);
            animation: pulseBox 1.5s ease-in-out infinite;
        }
        
        @keyframes pulseBox {
            0%, 100% { transform: scale(1); box-shadow: 0 0 30px rgba(255,215,0,0.4); }
            50% { transform: scale(1.05); box-shadow: 0 0 50px rgba(255,215,0,0.8); }
        }
        
        .spin-confirm-box i {
            font-size: 48px;
            color: var(--primary-gold);
            filter: drop-shadow(0 0 10px rgba(255,215,0,0.8));
            animation: tapHand 1s ease-in-out infinite;
        }
        
        @keyframes tapHand {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-8px); }
        }
        
        .spin-confirm-box div {
            font-size: 20px;
            font-weight: 800;
            color: var(--primary-gold);
            text-transform: uppercase;
            letter-spacing: 2px;
        }
        
        .spin-confirm-box small {
            font-size: 12px;
            color: #ccc;
        }
        
        /* ===========================
            FORM SECTION - MODERN CARD
         =========================== */
        .form-section { 
            width: 100%; 
            max-width: min(450px, 95vw);
            text-align: center; 
        }
        
        .form-card {
            background: rgba(0, 0, 0, 0.7);
            backdrop-filter: blur(15px);
            border-radius: 30px;
            padding: 25px;
            border: 1px solid rgba(255,215,0,0.3);
            box-shadow: 0 15px 35px rgba(0,0,0,0.3);
        }
        
        .header-content-combined { 
            display: flex; 
            align-items: center; 
            justify-content: space-between; 
            gap: 15px; 
            margin-bottom: 20px;
        }
        
        .naga-container { 
            flex: 1; 
            text-align: center; 
            position: relative; 
        }
        
        .naga-img { 
            width: 100%; 
            max-width: clamp(80px, 25vw, 120px);
            animation: goldGlow 2s ease-in-out infinite;
            filter: drop-shadow(0 0 10px rgba(255,215,0,0.5));
        }
        
        @keyframes goldGlow {
            0%, 100% { filter: drop-shadow(0 0 10px rgba(255,215,0,0.5)) brightness(1); }
            50% { filter: drop-shadow(0 0 25px rgba(255,215,0,0.9)) brightness(1.3); }
        }
        
        .cloud-bg { 
            width: 100%; 
            max-width: clamp(140px, 45vw, 200px);
            position: absolute; 
            bottom: -20px; 
            left: 50%;
            transform: translateX(-50%); 
            opacity: 0.5; 
            z-index: 1; 
            animation: cloudFloat 4s ease-in-out infinite;
        }
        
        @keyframes cloudFloat {
            0%, 100% { transform: translateX(-50%) translateY(0); }
            50% { transform: translateX(-50%) translateY(-5px); }
        }
        
        .btn-icon-wrapper { 
            cursor: pointer; 
            text-align: center; 
            transition: transform 0.2s;
        }
        
        .btn-icon-wrapper:hover {
            transform: scale(1.05);
        }
        
        .btn-icon-circle { 
            width: clamp(45px, 12vw, 55px);
            height: clamp(45px, 12vw, 55px);
            background: linear-gradient(135deg, rgba(0,0,0,0.8), rgba(139,0,0,0.6));
            border: 2px solid var(--primary-gold); 
            border-radius: 50%; 
            display: flex; 
            align-items: center; 
            justify-content: center; 
            color: var(--primary-gold); 
            box-shadow: 0 0 15px rgba(255,215,0,0.4); 
            margin: 0 auto 8px; 
            font-size: clamp(18px, 5vw, 22px);
            transition: all 0.3s; 
        }
        
        .btn-icon-circle:hover { 
            transform: scale(1.1);
            box-shadow: 0 0 25px rgba(255,215,0,0.8);
            border-color: #fff;
        }
        
        .btn-icon-wrapper span { 
            font-size: clamp(10px, 2.8vw, 12px);
            font-weight: 700; 
            color: var(--primary-gold); 
            text-shadow: 1px 1px 2px #000; 
        }
        
        .voucher-frame { 
            background: linear-gradient(135deg, rgba(255,215,0,0.1), rgba(139,0,0,0.2));
            border-radius: 25px;
            padding: 30px 20px;
            border: 1px solid rgba(255,215,0,0.3);
            margin-top: 10px;
        }
        
        .input-custom { 
            background: rgba(255,255,255,0.95) !important; 
            border: 2px solid var(--primary-gold) !important; 
            height: clamp(45px, 12vw, 52px);
            font-size: clamp(14px, 4vw, 16px);
            text-align: center; 
            font-weight: 600; 
            color: #000 !important; 
            border-radius: 50px; 
            width: 100%; 
            margin-bottom: 15px;
            transition: all 0.3s;
        }
        
        .input-custom:focus {
            border-color: var(--primary-red) !important;
            box-shadow: 0 0 15px rgba(255,215,0,0.6);
            outline: none;
            transform: scale(1.02);
        }
        
        .input-custom::placeholder {
            color: #666;
            font-weight: 400;
        }
        
        .btn-submit-img { 
            width: 100%; 
            max-width: clamp(140px, 40vw, 170px);
            cursor: pointer; 
            animation: btnPulse 1.5s infinite;
            transition: transform 0.2s;
            filter: drop-shadow(0 5px 10px rgba(0,0,0,0.3));
        }
        
        @keyframes btnPulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.05); filter: drop-shadow(0 5px 15px rgba(255,215,0,0.5)); }
        }
        
        .btn-submit-img:hover {
            transform: scale(1.1);
            animation: none;
        }
        
        /* ===========================
            FOOTER - MODERN
         =========================== */
        .footer-terms { 
            margin-top: 30px; 
            padding: 20px 25px;
            background: rgba(0,0,0,0.7);
            backdrop-filter: blur(10px);
            border-top: 2px solid var(--primary-gold); 
            border-radius: 20px; 
            width: 100%; 
            max-width: min(500px, 95vw);
            transition: all 0.3s;
        }
        
        .footer-terms:hover {
            box-shadow: 0 0 25px rgba(255,215,0,0.2);
        }
        
        .footer-terms ul {
            list-style: none;
            padding-left: 0;
        }
        
        .footer-terms li {
            position: relative;
            padding-left: 20px;
            margin-bottom: 8px;
        }
        
        .footer-terms li::before {
            content: '✨';
            position: absolute;
            left: 0;
            top: 0;
        }
        
        /* ===========================
            WHEEL DECORATIONS
         =========================== */
        .wheel-naga-container {
            position: absolute;
            top: -50px;
            right: -50px;
            width: clamp(100px, 18vw, 180px);
            height: clamp(100px, 18vw, 180px);
            z-index: 90;
            opacity: 0.6;
            display: none;
            pointer-events: none;
        }
        
        .wheel-cloud-bg,
        .wheel-naga-img {
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
            left: 0;
        }
        
        .wheel-cloud-bg {
            animation: wheelCloudFloat 5s ease-in-out infinite;
            opacity: 0.5;
        }
        
        .wheel-naga-img {
            animation: wheelNagaFloat 4s ease-in-out infinite;
            filter: drop-shadow(0 0 15px rgba(255,215,0,0.4));
        }
        
        @keyframes wheelCloudFloat {
            0%, 100% { transform: translate(0, 0) rotate(0); }
            33% { transform: translate(8px, -10px) rotate(3deg); }
            66% { transform: translate(-5px, 6px) rotate(-2deg); }
        }
        
        @keyframes wheelNagaFloat {
            0%, 100% { transform: translate(0, 0) scale(1); }
            50% { transform: translate(0, -12px) scale(1.08); }
        }
        
        /* ===========================
            SNOWFLAKES
         =========================== */
        .snowflake {
            position: fixed;
            top: -10%;
            z-index: 9999;
            user-select: none;
            animation: snowFall 8s linear infinite, snowShake 3s ease-in-out infinite;
        }
        
        @keyframes snowFall { 
            0% { top: -10%; } 
            100% { top: 100%; } 
        }
        
        @keyframes snowShake { 
            0%, 100% { transform: translateX(0); } 
            50% { transform: translateX(80px); } 
        }
        
        .snowflake:nth-of-type(1) { left: 10%; animation-delay: 1s, 1s; }
        .snowflake:nth-of-type(2) { left: 30%; animation-delay: 4s, 2s; }
        .snowflake:nth-of-type(3) { left: 50%; animation-delay: 5s, 3s; }
        .snowflake:nth-of-type(4) { left: 70%; animation-delay: 2.5s, 1s; }
        .snowflake:nth-of-type(5) { left: 83%; animation-delay: 3s, 1.5s; }
        .snowflake:nth-of-type(6) { left: 25%; animation-delay: 2s, 0s; }

        /* ===========================
            RESPONSIVE DESIGN
         =========================== */
        @media (min-width: 768px) {
            .wheel-box { max-width: 450px; }
            .scroll-bg { max-width: 360px; }
            .wheel-naga-container { display: block; }
            .form-card { padding: 35px; }
        }
        
        @media (min-width: 992px) {
            .main-container { padding: 30px; }
            
            .game-wrapper { 
                flex-direction: row; 
                flex-wrap: wrap; 
                justify-content: center; 
                gap: 50px; 
                align-items: flex-start;
            }
            
            .wheel-section { 
                order: 1; 
                flex: 1;
                max-width: 550px;
            }
            
            .form-section { 
                order: 2; 
                flex: 0.8;
                max-width: 450px;
            }
            
            .footer-terms { 
                order: 3; 
                max-width: 100%;
                margin-top: 40px;
            }
            
            .wheel-box { max-width: 500px; }
        }
        
        @media (min-width: 1200px) {
            .game-wrapper { gap: 80px; }
            .wheel-box { max-width: 550px; }
            .form-section { max-width: 480px; }
        }
        
        @media (max-width: 576px) {
            .main-container { padding: 15px; }
            .form-card { padding: 20px; }
            .voucher-frame { padding: 20px 15px; }
            .spin-confirm-box { padding: 15px 25px; }
            .spin-confirm-box i { font-size: 36px; }
            .spin-confirm-box div { font-size: 16px; }
        }
        
        /* Scrollbar Styling */
        ::-webkit-scrollbar {
            width: 8px;
        }
        
        ::-webkit-scrollbar-track {
            background: rgba(0,0,0,0.5);
            border-radius: 10px;
        }
        
        ::-webkit-scrollbar-thumb {
            background: var(--primary-gold);
            border-radius: 10px;
        }
        
        ::-webkit-scrollbar-thumb:hover {
            background: var(--secondary-gold);
        }
    </style>
</head>
<body>

<!-- Snowflakes -->
<div class="snowflakes" aria-hidden="true">
    <div class="snowflake"><img src="https://imgur.com/mN7VrGq.png" height="50" width="50" alt=""></div>
    <div class="snowflake"><img src="https://imgur.com/BvcyUhF.png" height="35" width="25" alt=""></div>
    <div class="snowflake"><img src="https://i.pinimg.com/originals/58/f9/57/58f9571e41f477a6e0b4aa03e0cdec92.gif" height="45" width="45" alt=""></div>
    <div class="snowflake"><img src="https://i.pinimg.com/originals/35/d5/8d/35d58dddf9e9ad33b5de89cde8b2377f.gif" height="45" width="45" alt=""></div>
    <div class="snowflake"><img src="https://i.pinimg.com/originals/1f/d3/ac/1fd3acf4a378b1e2536a4f86fc023b1a.gif" height="50" width="50" alt=""></div>
    <div class="snowflake"><img src="https://i.pinimg.com/originals/ab/ff/54/abff54f67644a641d54ca6fb6cf0ce94.gif" height="50" width="50" alt=""></div>
</div>

<!-- Body Overlay -->
<div class="body-overlay"></div>

<div class="main-container">
    <div class="game-wrapper">
        <!-- Wheel Section -->
        <div class="wheel-section">
            <div class="wheel-naga-container">
                <img src="https://static.vecteezy.com/system/resources/previews/024/679/451/non_2x/dense-cloud-isolated-on-transparent-background-realistic-fog-or-smoke-for-storm-or-sunny-weather-design-cloudy-sky-or-smog-environmental-design-on-a-transparent-background-for-templates-free-png.png" class="wheel-cloud-bg" alt="">
                <img src="https://spinpakarjitu399.fun/uploads/logo_url_1774030766.png" class="wheel-naga-img" alt="">
            </div>

            <div class="wheel-card">
                <div class="wheel-box" id="wheelBox">
                    <div class="spin-overlay-effect" id="spinOverlay"></div>
                    <div class="wheel-frame" style="background-image: url('https://lucky-wheel.88bo.icu/uploads/frame_url_1770752018.png');"></div>
                    <canvas id="canvas" width="500" height="500"></canvas>

                    <div class="spin-confirm-overlay hidden" id="spinConfirm">
                        <div class="spin-confirm-box">
                            <i class="fa-solid fa-hand-pointer"></i>
                            <div>SPIN NOW</div>
                            <small>Tap to start</small>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Form Section -->
        <div class="form-section">
            <div class="form-card">
                <div class="header-content-combined">
                    <div class="btn-icon-wrapper" onclick="showHistory()">
                        <div class="btn-icon-circle"><i class="fa-solid fa-clock-rotate-left"></i></div>
                        <span>RIWAYAT</span>
                    </div>
                    
                    <div class="naga-container">
                        <img src="https://static.vecteezy.com/system/resources/previews/024/679/451/non_2x/dense-cloud-isolated-on-transparent-background-realistic-fog-or-smoke-for-storm-or-sunny-weather-design-cloudy-sky-or-smog-environmental-design-on-a-transparent-background-for-templates-free-png.png" class="cloud-bg" alt="">
                        <img src="https://spinpakarjitu399.fun/uploads/logo_url_1774030766.png" class="naga-img" alt="">
                    </div>
                    
                    <div class="btn-icon-wrapper" onclick="toggleLiveChat()">
                        <div class="btn-icon-circle"><i class="fa-solid fa-comments"></i></div>
                        <span>OBROLAN</span>
                    </div>
                </div>
                
                <h4 style="color:var(--primary-gold); font-size:clamp(16px, 4vw, 20px); font-weight:800; text-transform:uppercase; text-shadow:2px 2px 4px #000; margin-bottom:15px; letter-spacing:1px;">
                    <i class="fa-solid fa-ticket"></i> TUKAR VOUCHER
                </h4>

                <div class="voucher-frame">
                    <input type="text" id="user_name" class="form-control input-custom" placeholder="MASUKKAN USERNAME" autocomplete="off">
                    <input type="text" id="ticket_code" class="form-control input-custom" placeholder="KODE VOUCHER" autocomplete="off">
                    <img src="https://media.tenor.com/Bxmw1okK4L4AAAAj/play-now-games.gif" class="btn-submit-img" onclick="startSpin()" alt="">
                </div>
            </div>
        </div>
<div class="footer-terms">
<h6 style="color:var(--primary-gold); font-size:clamp(13px, 3.5vw, 15px); text-align:center; font-weight:800; margin-bottom:12px;">
<i class="fa-solid fa-circle-info"></i> SYARAT & KETENTUAN EVENT
</h6>
<ul style="color:#ddd; font-size:clamp(11px, 2.8vw, 12px); line-height:1.7; margin:0; padding-left:15px; list-style-type: decimal;">
<li>Setiap Kode Voucher hanya berlaku untuk 1x kesempatan Spin dan akan hangus setelah digunakan.</li>
<li>Peserta wajib memastikan USERNAME yang diinput sudah valid dan sesuai dengan akun yang terdaftar.</li>
<li>Kesalahan penulisan USERNAME atau data diri di luar tanggung jawab penyelenggara dan hadiah dianggap hangus.</li>
<li>Hadiah akan diproses secara otomatis oleh sistem ke dalam akun setelah konfirmasi kemenangan berhasil dilakukan.</li>
<li>Waktu pemrosesan hadiah dapat memakan waktu 1x24 jam jika terjadi kendala teknis atau antrean sistem.</li>
<li>Penyelenggara berhak membatalkan kemenangan jika ditemukan indikasi kecurangan, manipulasi data, atau penggunaan ID ganda.</li>
<li>Promo ini dapat berubah sewaktu-waktu tanpa pemberitahuan terlebih dahulu sesuai dengan kebijakan manajemen.</li>
<li>Segala keputusan panitia/admin bersifat mutlak, final, dan tidak dapat diganggu gugat oleh pihak manapun.</li>
</ul>
</div>
    </div>
</div>


<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.6.0/dist/confetti.browser.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
/* GLOBAL DATA - TIDAK DIUBAH */
window.currentChats = [{"u":"admin","m":"Silakan hubungi CS untuk info lebih lanjut","isAdm":1},{"u":"Player8472","m":"Gasskun boskuh","isAdm":0},{"u":"Player8472","m":"Yoii mantap banget","isAdm":0}];
let historyData = [{"u":"akmal123","p":"JACKPOT","n":5000000},{"u":"akmal123234","p":"JACKPOT","n":5000000},{"u":"Akmal123","p":"BONUS","n":2500000}];
const prizes = [{"id":"1","label":"JACKPOT","color":"#ff0000","nominal":"5000000","color_border":"#000000","order":"1"},{"id":"2","label":"BIGWIN","color":"#f5f7fa","nominal":"3000000","color_border":"#000000","order":"2"},{"id":"3","label":"SALDO","color":"#ff0000","nominal":"10000","color_border":"#000000","order":"3"},{"id":"4","label":"X5 WIN","color":"#f5f7fa","nominal":"1500000","color_border":"#000000","order":"4"},{"id":"5","label":"BONUS","color":"#ff0000","nominal":"50000","color_border":"#000000","order":"5"},{"id":"6","label":"FREE SPIN","color":"#f5f7fa","nominal":"20000","color_border":"#000000","order":"6"}];

let currentRotation = 0;
let isSpinning = false;
let pendingSpinData = null;
let confettiInterval = null;

/* AUDIO */
const audioBG = new Audio("/assets/sound/music.mp4");
audioBG.volume = 0.3;
audioBG.loop = true;

const audioSpin = new Audio("/assets/sound/wheel.mp3");
audioSpin.volume = 0.5;

const audioWin = new Audio("/assets/sound/winning.mp3");
const audioZonk = new Audio("");

/* DOM */
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const wheelBox = document.getElementById("wheelBox");
const spinConfirm = document.getElementById("spinConfirm");
const bodyOverlay = document.querySelector(".body-overlay");
const spinOverlay = document.getElementById("spinOverlay");

/* HELPERS */
function darkenColor(hex, percent) {
    hex = hex.replace("#", "");
    if (hex.length === 3) hex = hex.split("").map(h => h + h).join("");
    const num = parseInt(hex, 16);
    const r = Math.floor((num >> 16) * (1 - percent / 100));
    const g = Math.floor(((num >> 8) & 0xff) * (1 - percent / 100));
    const b = Math.floor((num & 0xff) * (1 - percent / 100));
    return `rgb(${r},${g},${b})`;
}

function playBGM() {
    if (audioBG.paused) audioBG.play().catch(() => {});
}

/* DRAW WHEEL */
function draw() {
    const arc = (Math.PI * 2) / prizes.length;
    ctx.clearRect(0, 0, 500, 500);

    prizes.forEach((p, i) => {
        const start = i * arc;
        const end = start + arc;

        const grad = ctx.createRadialGradient(250,250,50,250,250,250);
        grad.addColorStop(0, p.color);
        grad.addColorStop(1, darkenColor(p.color, 40));

        ctx.fillStyle = grad;
        ctx.beginPath();
        ctx.arc(250, 250, 245, start, end);
        ctx.lineTo(250, 250);
        ctx.fill();

        ctx.save();
        ctx.strokeStyle = p.color_border || "#ffd700";
        ctx.lineWidth = 5;
        ctx.stroke();
        ctx.restore();

        ctx.save();
        ctx.translate(250, 250);
        ctx.rotate(start + arc / 2);
        ctx.textAlign = "right";
        ctx.fillStyle = "#fff";

        if (p.nominal > 0) {
            ctx.font = "bold 30px Arial";
            ctx.fillText(new Intl.NumberFormat("id-ID").format(p.nominal), 210, 0);
            ctx.font = "bold 13px Arial";
            ctx.fillText(p.label.toUpperCase(), 210, 22);
        } else {
            ctx.font = "bold 22px Arial";
            ctx.fillText(p.label, 210, 8);
        }
        ctx.restore();
    });

    const grad = ctx.createLinearGradient(225,225,275,275);
    grad.addColorStop(0,"#ffd700");
    grad.addColorStop(1,"#b8860b");
    ctx.beginPath();
    ctx.arc(250,250,25,0,Math.PI*2);
    ctx.fillStyle="#111";
    ctx.fill();
    ctx.strokeStyle=grad;
    ctx.lineWidth=5;
    ctx.stroke();
}

/* INTRO */
function showWelcomePopup() {
    Swal.fire({
        title: "🎰 SELAMAT DATANG",
        text: "Klik OK untuk memulai permainan!",
        confirmButtonText: "OK, SPIN!",
        confirmButtonColor: "#ffd700",
        allowOutsideClick: false,
        background: "linear-gradient(135deg, #1a0a0a, #2a0a0a)"
    }).then((r) => {
        if (r.isConfirmed) startIntro();
    });
}

function startIntro() {
    if (isSpinning) return;
    isSpinning = true;
    
    audioSpin.currentTime = 0;
    audioSpin.play().catch(() => {});
    
    canvas.style.transition = "transform 3s cubic-bezier(0.1, 0, 0.2, 1)";
    currentRotation = 1080;
    canvas.style.transform = `rotate(${currentRotation}deg)`;
    
    setTimeout(() => {
        audioSpin.pause();
        audioSpin.currentTime = 0;
        isSpinning = false;
        playBGM();
    }, 3000);
}

/* MAIN SPIN */
function startSpin() {
    if (isSpinning) return;
    
    const user = document.getElementById("user_name").value.trim();
    const code = document.getElementById("ticket_code").value.trim();
    
    if (!user || !code) {
        return Swal.fire({
            icon: "warning",
            title: "⚠️ DATA KOSONG",
            text: "Isi Username & Voucher terlebih dahulu!",
            confirmButtonColor: "#ffd700"
        });
    }
    
    wheelBox.classList.add("shake-wheel");
    bodyOverlay.classList.add("active");
    spinOverlay.classList.add("active");
    
    wheelBox.scrollIntoView({ behavior: "smooth", block: "center" });
    
    $.post("ajax/check-ticket.php", {
        username: user,
        ticket_code: code
    }, function (data) {
        if (data.status !== "valid") {
            resetUX();
            return Swal.fire({
                icon: "error",
                title: "❌ GAGAL",
                text: data.message || "Voucher tidak valid atau sudah digunakan!",
                confirmButtonColor: "#dc3545"
            });
        }
        
        pendingSpinData = data;
        
        setTimeout(() => {
            spinConfirm.classList.remove("hidden");
            spinConfirm.classList.add("active");
            spinConfirm.onclick = confirmStartSpin;
        }, 700);
    }, "json");
}

/* CONFIRM SPIN */
function confirmStartSpin() {
    if (!pendingSpinData || isSpinning) return;
    isSpinning = true;
    
    const data = pendingSpinData;
    pendingSpinData = null;
    
    resetUX();
    spinConfirm.classList.remove("active");
    setTimeout(() => spinConfirm.classList.add("hidden"), 300);
    
    audioBG.pause();
    audioSpin.currentTime = 0;
    audioSpin.play().catch(() => {});
    
    const sector = 360 / prizes.length;
    const targetAngle = (data.target * sector) + (sector / 2);
    const POINTER_ANGLE = 270;
    
    currentRotation = currentRotation - (currentRotation % 360) + (360 * 10) + (POINTER_ANGLE - targetAngle);
    
    canvas.style.transition = "transform 7s cubic-bezier(0.15,0,0.15,1)";
    setTimeout(() => canvas.style.transform = `rotate(${currentRotation}deg)`, 50);
    
    setTimeout(() => {
        audioSpin.pause();
        (data.prize.nominal > 0 ? audioWin : audioZonk).play().catch(() => {});
        
        if (data.prize.nominal > 0) {
            startWinConfetti();
            setTimeout(() => showWinModal(data), 800);
        } else {
            setTimeout(() => showLoseModal(data), 500);
        }
    }, 7000);
}

/* CONFETTI */
function startWinConfetti() {
    stopWinConfetti();
    let power = 50;
    
    confettiInterval = setInterval(() => {
        confetti({
            particleCount: power,
            spread: 120,
            startVelocity: 50,
            gravity: 0.9,
            origin: { x: Math.random(), y: Math.random() * 0.4 },
            zIndex: 999999
        });
        
        if (power < 400) power += 20;
    }, 300);
}

function stopWinConfetti() {
    if (confettiInterval) {
        clearInterval(confettiInterval);
        confettiInterval = null;
    }
}

/* MODALS */
function showWinModal(data) {
    Swal.fire({
        title: "🎉 SELAMAT! 🎉",
        html: `
            <div style="text-align:center">
                <h1 style="color:#ffd700; font-size:clamp(2rem,8vw,3rem); margin:20px 0; font-weight:800;">
                    Rp ${new Intl.NumberFormat("id-ID").format(data.prize.nominal)}
                </h1>
                <p style="font-size:clamp(1rem,4vw,1.2rem); margin:0;">${data.prize.label}</p>
                <p style="font-size:0.9rem; margin-top:10px;">✨ Hadiah akan diproses otomatis ✨</p>
            </div>
        `,
        confirmButtonText: "AMBIL HADIAH",
        confirmButtonColor: "#ffd700",
        allowOutsideClick: false
    }).then(() => {
        stopWinConfetti();
        isSpinning = false;
        playBGM();
        document.getElementById("ticket_code").value = "";
        loadRecentHistories();
    });
}

function showLoseModal(data) {
    Swal.fire({
        title: "😢 SAYANG SEKALI",
        html: `
            <div style="text-align:center">
                <h1 style="color:#ffd700; font-size:clamp(2rem,8vw,2.5rem); margin:20px 0;">
                    ${data.prize.label}
                </h1>
                <p>Semoga beruntung lain kali!</p>
                <p>🎯 Terus coba dan raih jackpot 🎯</p>
            </div>
        `,
        confirmButtonText: "Coba Lagi",
        confirmButtonColor: "#ffd700",
        allowOutsideClick: false
    }).then(() => {
        isSpinning = false;
        playBGM();
        document.getElementById("ticket_code").value = "";
        loadRecentHistories();
    });
}

/* RESET UX */
function resetUX() {
    wheelBox.classList.remove("shake-wheel");
    bodyOverlay.classList.remove("active");
    spinOverlay.classList.remove("active");
}

/* HISTORY */
function showHistory() {
    let html = '<div style="max-height:400px;overflow-y:auto;">';
    
    if (historyData.length === 0) {
        html += '<p class="text-center" style="padding:20px;">Belum ada riwayat spin</p>';
    } else {
        historyData.forEach((h, i) => {
            const user = h.u.substring(0, 2) + '***';
            html += `
                <div style="display:flex;justify-content:space-between;align-items:center;padding:12px 10px;border-bottom:1px solid rgba(255,215,0,0.2);">
                    <span style="font-weight:600;">👤 ${user}</span> 
                    <span style="color:#ffd700;font-weight:700;">${h.p}</span> 
                    <span style="color:#ffd700;">Rp ${new Intl.NumberFormat('id-ID').format(h.n || 0)}</span>
                </div>
            `;
        });
    }
    html += '</div>';
    
    Swal.fire({
        title: '📜 RIWAYAT SPIN',
        html: html,
        showCloseButton: true,
        showConfirmButton: false,
        background: "linear-gradient(135deg, #1a0a0a, #2a0a0a)",
        width: window.innerWidth < 576 ? '90%' : '500px'
    });
}

/* Live Chat Toggle */
function toggleLiveChat() {
    const liveChatBtn = document.querySelector('[onclick="toggleLiveChat()"]');
    if (typeof window.toggleChat === 'function') {
        window.toggleChat();
    } else if (window.livechat && window.livechat.toggle) {
        window.livechat.toggle();
    }
}

/* POLLING */
function loadRecentChats() {
    $.getJSON('ajax/get-chats.php', d => { if (d.chats) window.currentChats = d.chats; });
}

function loadRecentHistories() {
    $.getJSON('ajax/get-histories.php', d => { if (d.histories) historyData = d.histories; });
}

setInterval(loadRecentChats, 5000);
setInterval(loadRecentHistories, 5000);

/* INIT */
draw();
window.onload = showWelcomePopup;

/* Snowflakes animation timing */
document.querySelectorAll('.snowflake').forEach((flake, index) => {
    const duration = Math.random() * 8 + 6;
    const drift = Math.random() * 100 + 50;
    flake.style.animation = `snowFall ${duration}s linear infinite, snowDrift ${drift}s ease-in-out infinite`;
    flake.style.animationDelay = `${Math.random() * 5}s, ${Math.random() * 3}s`;
});
</script>

<script src="assets/js/livechat.js"></script>
<script defer src="https://static.cloudflareinsights.com/beacon.min.js/v8c78df7c7c0f484497ecbca7046644da1771523124516" integrity="sha512-8DS7rgIrAmghBFwoOTujcf6D9rXvH8xm8JQ1Ja01h9QX8EzXldiszufYa4IFfKdLUKTTrnSFXLDkUEOTrZQ8Qg==" data-cf-beacon='{"version":"2024.11.0","token":"44f3edb68b154eceb49c8fc26ba2712e","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}' crossorigin="anonymous"></script>
</body>
</html>