<script>
function openVideoModal(videoId, sec) {
var modal = document.getElementById('yt-lightbox-modal');
if (!modal) {
modal = document.createElement('div');
modal.id = 'yt-lightbox-modal';
modal.style.cssText = 'position:fixed;top:0;left:0;width:100vw;height:100vh;background:rgba(15,23,42,0.9);z-index:2147483647;display:flex;align-items:center;justify-content:center;opacity:0;transition:opacity 0.3s ease;backdrop-filter:blur(8px);';
modal.addEventListener('click', function(e) { if (e.target === modal) closeVideoModal(); });
var closeBtn = document.createElement('button');
closeBtn.innerHTML = '<i style="font-style:normal;">✕</i> 關閉影片';
closeBtn.style.cssText = 'position:absolute;top:24px;right:24px;background:#ef4444;color:white;border:none;padding:8px 16px;border-radius:99px;font-weight:600;cursor:pointer;z-index:10;box-shadow:0 4px 6px -1px rgba(0,0,0,0.1);';
closeBtn.onclick = closeVideoModal;
var iframeContainer = document.createElement('div');
iframeContainer.id = 'yt-lightbox-container';
iframeContainer.style.cssText = 'width:90%;max-width:1000px;aspect-ratio:16/9;background:#000;border-radius:12px;overflow:hidden;box-shadow:0 25px 50px -12px rgba(0,0,0,0.5);';
modal.appendChild(closeBtn);
modal.appendChild(iframeContainer);
document.body.appendChild(modal);
}
var container = document.getElementById('yt-lightbox-container');
container.innerHTML = '<iframe width="100%" height="100%" src="https://www.youtube.com/embed/' + videoId + '?autoplay=1&start=' + sec + '&rel=0" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
modal.style.display = 'flex';
setTimeout(function() { modal.style.opacity = '1'; }, 10);
}
function closeVideoModal() {
var modal = document.getElementById('yt-lightbox-modal');
if (modal) {
modal.style.opacity = '0';
setTimeout(function() {
modal.style.display = 'none';
document.getElementById('yt-lightbox-container').innerHTML = '';
}, 300);
}
}
</script>