// Theme initialization script to prevent flash
(function() {
  const getThemeFromCookie = () => {
    const matches = document.cookie.match(/theme=([^;]+)/);
    return matches ? matches[1] : null;
  };
  const theme = getThemeFromCookie() || 'dark';
  const html = document.documentElement;
  if (theme === 'dark' || (theme === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
    html.classList.add('dark');
    html.classList.remove('light');
  } else {
    html.classList.add('light');
    html.classList.remove('dark');
  }
})();
