<script>
const btn = document.getElementById("themeToggle");
// Load saved theme OR system preference
const saved = localStorage.getItem("theme");
if (saved === "dark" || (!saved && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.body.classList.add("dark");
btn.textContent = "☀️";
}
btn.onclick = () => {
document.body.classList.toggle("dark");
const isDark = document.body.classList.contains("dark");
btn.textContent = isDark ? "☀️" : "🌙";
localStorage.setItem("theme", isDark ? "dark" : "light");
};
</script>