/**
 * Muzick's fixed Ethos fingerprint: honey amber accent on the warm-brown
 * neutral ramp. Ethos apps get exactly one accent — no runtime theme
 * picker — so these are applied once at boot, not user-selectable.
 */
const ETHOS_VARS: Record<string, string> = {
  '--ethos-bg0': '#14110D',
  '--ethos-bg1': '#1B1712',
  '--ethos-bg2': '#221D17',
  '--ethos-surface0': '#2C261D',
  '--ethos-surface1': '#372F24',
  '--ethos-surface2': '#423927',
  '--ethos-border': 'rgba(244,234,220,0.09)',
  '--ethos-text': '#F4EEE4',
  '--ethos-secondary': '#B4AA98',
  '--ethos-muted': '#756C5C',
  '--ethos-disabled': '#5a5347',
  '--ethos-accent': '#EDA24E',
  '--ethos-accent-hover': '#E08F32',
  '--ethos-on-accent': '#14110D',
  '--ethos-green': '#22c55e',
  '--ethos-amber': '#eab308',
  '--ethos-red': '#ef4444',
  '--ethos-purple': '#a855f7',
  '--ethos-cyan': '#22d3ee',
  '--ethos-orange': '#f97316',
};

export const STORAGE_KEYS = {
  volume: 'muzick.settings.volume',
} as const;

export function initTheme(): void {
  const root = document.documentElement;
  for (const [key, value] of Object.entries(ETHOS_VARS)) {
    root.style.setProperty(key, value);
  }
}

export function readStoredVolume(fallback: number): number {
  try {
    const stored = localStorage.getItem(STORAGE_KEYS.volume);
    if (stored !== null) {
      const parsed = Number(stored);
      if (Number.isFinite(parsed) && parsed >= 0 && parsed <= 1) return parsed;
    }
  } catch { /* ignore */ }
  return fallback;
}
