function getFormattedDate() {
        const date = new Date();
        const days = ['Min', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'];
        const months = ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agt', 'Sep', 'Okt', 'Nov', 'Des'];

        const dayName = days[date.getDay()];
        const day = date.getDate();
        const month = months[date.getMonth()];
        const year = date.getFullYear();
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');

        return `${dayName}, ${day}-${month}-${year} ${hours}.${minutes}.${seconds}`;
    }

    document.getElementById('currentDate').innerText = getFormattedDate();
 // ==================== SLOT MACHINE SCRIPT ====================
  const symbols = ['🍒', '🍋', '🍊', '🍇', '🥝', '7️⃣', '💎', '🔔', '⭐', '💰'];

  let balance = 500000;
  const betAmount = 10000;

  const reel1 = document.getElementById('reel-1');
  const reel2 = document.getElementById('reel-2');
  const reel3 = document.getElementById('reel-3');
  const spinBtn = document.getElementById('spin-btn');
  const resultDisplay = document.getElementById('result-display');
  const balanceEl = document.getElementById('balance');

  function updateBalance() {
    balanceEl.textContent = 'Rp ' + balance.toLocaleString('id-ID');
  }

  function getRandomSymbol() {
    return symbols[Math.floor(Math.random() * symbols.length)];
  }

  function checkWin(finalSymbols) {
    const [s1, s2, s3] = finalSymbols;
    let message = '';
    let winAmount = 0;

    if (s1 === s2 && s2 === s3) {
      // JACKPOT / BIG WIN
      if (s1 === '7️⃣') {
        message = '🎉 JACKPOT 777! SELAMAT!';
        winAmount = 500000;
      } else {
        message = `🎉 SELAMAT! ${s1} ${s1} ${s1}`;
        winAmount = 150000;
      }
      resultDisplay.classList.add('win');
    } 
    else if (s1 === s2 || s2 === s3 || s1 === s3) {
      message = '👍 Dua Simbol Sama! Lumayan';
      winAmount = 25000;
    } 
    else {
      message = '😢 Coba Lagi... Semangat!';
    }

    if (winAmount > 0) {
      balance += winAmount;
      message += `<br><span style="color:#00ff88">+Rp ${winAmount.toLocaleString('id-ID')}</span>`;
    } else {
      resultDisplay.style.color = '#ff6b6b';
    }

    resultDisplay.innerHTML = message;
    updateBalance();

    // Remove win class after animation
    setTimeout(() => {
      resultDisplay.classList.remove('win');
      resultDisplay.style.color = '';
    }, 1800);
  }

  function spin() {
    if (balance < betAmount) {
      resultDisplay.innerHTML = '❌ Saldo tidak cukup! Isi saldo dulu ya.';
      resultDisplay.style.color = '#ff6b6b';
      return;
    }

    // Deduct bet
    balance -= betAmount;
    updateBalance();

    spinBtn.disabled = true;
    resultDisplay.innerHTML = 'Sedang berputar...';
    resultDisplay.style.color = '#ffd700';

    // Decide final symbols first
    const finalSymbols = [
      getRandomSymbol(),
      getRandomSymbol(),
      getRandomSymbol()
    ];

    const reels = [reel1, reel2, reel3];
    const stopDelays = [1100, 1600, 2100]; // staggered stop

    reels.forEach((reel, index) => {
      reel.classList.add('spinning');

      const interval = setInterval(() => {
        reel.textContent = getRandomSymbol();
      }, 75);

      setTimeout(() => {
        clearInterval(interval);
        reel.classList.remove('spinning');
        reel.textContent = finalSymbols[index];

        // Check win after last reel stops
        if (index === 2) {
          setTimeout(() => {
            checkWin(finalSymbols);
            spinBtn.disabled = false;
          }, 300);
        }
      }, stopDelays[index]);
    });
  }

  // Event Listener
  spinBtn.addEventListener('click', spin);

  // Optional: Press SPACE to spin
  document.addEventListener('keydown', function(e) {
    if (e.key === ' ' && !spinBtn.disabled) {
      e.preventDefault();
      spin();
    }
  });

  // Initialize
  updateBalance();
  console.log('%c[Slot Machine] Mesin slot siap digunakan!', 'color:#ffd700');