// ✅ Favorites/Recently-Played — শুধু Browser-এর নিজের
// localStorage-এ রাখা হচ্ছে, কোনো Backend/Database
// পরিবর্তন করা হয়নি
function getFavorites() { return JSON.parse(localStorage.getItem('slot_favorites') || '[]'); }
function saveFavorites(list) { localStorage.setItem('slot_favorites', JSON.stringify(list)); }
function getRecent() { return JSON.parse(localStorage.getItem('slot_recent') || '[]'); }
function saveRecent(list) { localStorage.setItem('slot_recent', JSON.stringify(list.slice(0, 30))); }

function toggleFav(gameCode, gameName, gameImg, vendor, el) {
    let favs = getFavorites();
    const idx = favs.findIndex(f => f.code === gameCode);
    if (idx >= 0) { favs.splice(idx, 1); el.classList.remove('active'); }
    else { favs.push({ code: gameCode, name: gameName, img: gameImg, vendor }); el.classList.add('active'); }
    saveFavorites(favs);
}

function addToRecent(gameCode, gameName, gameImg, vendor) {
    let recent = getRecent();
    recent = recent.filter(r => r.code !== gameCode);
    recent.unshift({ code: gameCode, name: gameName, img: gameImg, vendor });
    saveRecent(recent);
}
