//===============================================================
// IntersectionObserver 動画制御
//===============================================================
(function(){
	var video = document.querySelector(".bgVideo");
	if(!video) return;

	// prefers-reduced-motion / saveData 対応
	var prefersReduced = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
	var saveData = navigator.connection && navigator.connection.saveData;
	if(prefersReduced || saveData){
		video.pause();
		video.removeAttribute("autoplay");
		return;
	}

	var observer = new IntersectionObserver(function(entries){
		entries.forEach(function(entry){
			if(entry.isIntersecting){
				video.play().catch(function(){});
			} else {
				video.pause();
			}
		});
	}, {threshold: 0.25});

	observer.observe(video);
})();
