// ─────────────────────────────────────────────────────────────
// Øneiro — theme system
// 3 directions × light/dark; exposed via window.OneiroTheme
// ─────────────────────────────────────────────────────────────

const THEMES = {
  // Deep night — black/indigo, soft glows, starfield, liminal
  night: {
    dark: {
      bg:       '#05060e',
      bgEnd:    '#0b0a1f',
      ink:      '#e8e7ff',
      inkSoft:  'rgba(232,231,255,0.62)',
      inkFaint: 'rgba(232,231,255,0.30)',
      line:     'rgba(160,160,255,0.14)',
      panel:    'rgba(20,18,46,0.55)',
      accent:   '#8a7bff',     // periwinkle
      accent2:  '#c8b4ff',
      glow:     '#7c6cff',
      rem:      '#ff8fb7',     // soft rose for REM moments
      surface:  'rgba(255,255,255,0.04)',
      grid:     'rgba(150,150,220,0.07)',
      starA:    '#fff',
      starB:    '#a99dff',
      serif:    '"Cormorant Garamond", "Garamond", serif',
      sans:     '"Inter Tight", "Inter", system-ui, sans-serif',
      mono:     '"JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace',
      label:    'v0.1 · phase sync',  // status label
    },
    light: {
      bg:       '#f1eeff',
      bgEnd:    '#e2def7',
      ink:      '#0a0a23',
      inkSoft:  'rgba(10,10,35,0.66)',
      inkFaint: 'rgba(10,10,35,0.32)',
      line:     'rgba(40,30,120,0.14)',
      panel:    'rgba(255,255,255,0.55)',
      accent:   '#5a4cd1',
      accent2:  '#7a6cf0',
      glow:     '#8a7bff',
      rem:      '#d44b8b',
      surface:  'rgba(40,30,120,0.04)',
      grid:     'rgba(40,30,120,0.06)',
      starA:    '#0a0a23',
      starB:    '#5a4cd1',
      serif:    '"Cormorant Garamond", "Garamond", serif',
      sans:     '"Inter Tight", "Inter", system-ui, sans-serif',
      mono:     '"JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace',
      label:    'v0.1 · phase sync',
    }
  },
  // Soft & dreamlike — washed pastels, blur, gradient fog, ambient
  dreamlike: {
    dark: {
      bg:       '#1a1530',
      bgEnd:    '#3a2444',
      ink:      '#fdf3ec',
      inkSoft:  'rgba(253,243,236,0.66)',
      inkFaint: 'rgba(253,243,236,0.30)',
      line:     'rgba(255,200,210,0.14)',
      panel:    'rgba(255,180,200,0.06)',
      accent:   '#ffb1d0',     // dusty pink
      accent2:  '#9eb8ff',     // soft periwinkle
      glow:     '#ffb1d0',
      rem:      '#ffc88a',     // peach
      surface:  'rgba(255,255,255,0.05)',
      grid:     'rgba(255,200,210,0.07)',
      starA:    '#fff',
      starB:    '#ffb1d0',
      serif:    '"Cormorant Garamond", "Garamond", serif',
      sans:     '"Inter Tight", "Inter", system-ui, sans-serif',
      mono:     '"JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace',
      label:    'v0.1 · phase sync',
    },
    light: {
      bg:       '#fbe9e0',
      bgEnd:    '#f3d7e8',
      ink:      '#3a1f3b',
      inkSoft:  'rgba(58,31,59,0.66)',
      inkFaint: 'rgba(58,31,59,0.30)',
      line:     'rgba(58,31,59,0.14)',
      panel:    'rgba(255,255,255,0.55)',
      accent:   '#c25a8e',
      accent2:  '#7a8cd6',
      glow:     '#c25a8e',
      rem:      '#d9744c',
      surface:  'rgba(58,31,59,0.04)',
      grid:     'rgba(58,31,59,0.06)',
      starA:    '#3a1f3b',
      starB:    '#c25a8e',
      serif:    '"Cormorant Garamond", "Garamond", serif',
      sans:     '"Inter Tight", "Inter", system-ui, sans-serif',
      mono:     '"JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace',
      label:    'v0.1 · phase sync',
    }
  },
  // Esoteric / occult — Greek as ritual object, sigils, astrology
  esoteric: {
    dark: {
      bg:       '#0a0805',
      bgEnd:    '#1a0f06',
      ink:      '#e8d8b4',           // aged parchment
      inkSoft:  'rgba(232,216,180,0.66)',
      inkFaint: 'rgba(232,216,180,0.30)',
      line:     'rgba(212,175,55,0.20)',
      panel:    'rgba(40,28,12,0.55)',
      accent:   '#d4af37',           // antique gold
      accent2:  '#b08d3a',
      glow:     '#d4af37',
      rem:      '#c9533d',           // rust
      surface:  'rgba(212,175,55,0.04)',
      grid:     'rgba(212,175,55,0.07)',
      starA:    '#e8d8b4',
      starB:    '#d4af37',
      serif:    '"Cormorant Garamond", "Garamond", serif',
      sans:     '"Cormorant Garamond", "Garamond", serif', // serifs everywhere
      mono:     '"JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace',
      label:    'v0.1 · phase sync',  // greek label
    },
    light: {
      bg:       '#f5ecd6',
      bgEnd:    '#e9d9b3',
      ink:      '#2a1a08',
      inkSoft:  'rgba(42,26,8,0.66)',
      inkFaint: 'rgba(42,26,8,0.30)',
      line:     'rgba(120,80,30,0.20)',
      panel:    'rgba(255,250,235,0.55)',
      accent:   '#8a6320',
      accent2:  '#a0762a',
      glow:     '#8a6320',
      rem:      '#a8412b',
      surface:  'rgba(120,80,30,0.04)',
      grid:     'rgba(120,80,30,0.07)',
      starA:    '#2a1a08',
      starB:    '#8a6320',
      serif:    '"Cormorant Garamond", "Garamond", serif',
      sans:     '"Cormorant Garamond", "Garamond", serif',
      mono:     '"JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace',
      label:    'v0.1 · phase sync',
    }
  }
};

function useTheme(variant, mode) {
  const t = THEMES[variant]?.[mode] || THEMES.night.dark;
  // expose CSS vars so non-react CSS can pick up colors
  React.useEffect(() => {
    const r = document.documentElement;
    Object.entries(t).forEach(([k, v]) => r.style.setProperty(`--t-${k}`, v));
    r.style.setProperty('color-scheme', mode);
  }, [t, mode]);
  return t;
}

window.THEMES = THEMES;
window.useOneiroTheme = useTheme;
