import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { RouterProvider } from '@tanstack/react-router';
import { router } from './router';
import { useUiStore, applyTheme } from './stores/uiStore';
// "The Living Codex" type system (self-hosted, offline-safe): Spectral (editorial
// serif headings), Hanken Grotesk (UI), Spline Sans Mono (stats/dice).
import '@fontsource/spectral/400.css';
import '@fontsource/spectral/500.css';
import '@fontsource/spectral/600.css';
import '@fontsource/spectral/700.css';
import '@fontsource/spectral/400-italic.css';
import '@fontsource-variable/hanken-grotesk/index.css';
import '@fontsource-variable/spline-sans-mono/index.css';
import './styles/globals.css';

// Apply persisted theme before first paint.
applyTheme(useUiStore.getState().theme);

const rootEl = document.getElementById('root');
if (!rootEl) throw new Error('Root element #root not found');

createRoot(rootEl).render(
  <StrictMode>
    <RouterProvider router={router} />
  </StrictMode>,
);
