// Theme system for the church web app.
// Each theme is a full role-mapped palette. Default = Warm Stone (matches the reference screenshots).
// Light themes get dark text on light surfaces; dark themes get light text on dark surfaces.

const CHURCH_THEMES = [
  {
    id: 'warm-stone', name: 'Warm Stone', mode: 'light',
    page: '#EFEADF', bar: '#D9D6CD', barText: '#2E2B26',
    surface: '#FBF9F3', surfaceText: '#2E2B26',
    ink: '#332F29', body: '#3A372F', muted: '#7A756B',
    accent: '#6E6A62', accentText: '#FFFFFF',
    pill: '#6E6A62', pillText: '#FFFFFF',
    border: '#C9C4B8', field: '#FFFFFF', fieldText: '#2E2B26',
    swatches: ['#EFEADF', '#6E6A62', '#BE8450', '#332F29']
  },
  {
    id: 'black-gold', name: 'Black & Gold', mode: 'dark',
    page: '#14213D', bar: '#0B1228', barText: '#FCA311',
    surface: '#000000', surfaceText: '#FFFFFF',
    ink: '#FCA311', body: '#E5E5E5', muted: '#9AA1AE',
    accent: '#FCA311', accentText: '#000000',
    pill: '#FCA311', pillText: '#000000',
    border: '#2A3556', field: '#0B1228', fieldText: '#FFFFFF',
    swatches: ['#14213D', '#FCA311', '#000000', '#E5E5E5']
  },
  {
    id: 'emerald-jungle', name: 'Emerald Jungle', mode: 'dark',
    page: '#0A120F', bar: '#12271C', barText: '#9DB089',
    surface: '#253E2D', surfaceText: '#EAEFE4',
    ink: '#9DB089', body: '#D5DECB', muted: '#6C7D5E',
    accent: '#6C7D5E', accentText: '#0A120F',
    pill: '#425940', pillText: '#EAEFE4',
    border: '#36513B', field: '#12271C', fieldText: '#EAEFE4',
    swatches: ['#0A120F', '#425940', '#6C7D5E', '#9DB089']
  },
  {
    id: 'midnight-brass', name: 'Midnight & Brass', mode: 'dark',
    page: '#172531', bar: '#0E1820', barText: '#F3D068',
    surface: '#2C4657', surfaceText: '#F4F7FA',
    ink: '#F3D068', body: '#DCE6EC', muted: '#8FA3B0',
    accent: '#C7A43B', accentText: '#0E1820',
    pill: '#C7A43B', pillText: '#0E1820',
    border: '#3C5A6E', field: '#0E1820', fieldText: '#F4F7FA',
    swatches: ['#172531', '#C7A43B', '#4D6473', '#F3D068']
  },
  {
    id: 'charcoal-peach', name: 'Charcoal & Peach', mode: 'dark',
    page: '#111822', bar: '#0A0F16', barText: '#F3B899',
    surface: '#333740', surfaceText: '#F4F1EE',
    ink: '#F3B899', body: '#DDD8D3', muted: '#9A9794',
    accent: '#F3B899', accentText: '#1A1F27',
    pill: '#745850', pillText: '#F8EDE6',
    border: '#454953', field: '#0A0F16', fieldText: '#F4F1EE',
    swatches: ['#111822', '#745850', '#F3B899', '#6C6A6A']
  },
  {
    id: 'aristocratic-blue', name: 'Aristocratic Blue', mode: 'dark',
    page: '#212223', bar: '#16171A', barText: '#E0ECF1',
    surface: '#354B56', surfaceText: '#EAF2F6',
    ink: '#9BBECF', body: '#D6E3EB', muted: '#7E97A6',
    accent: '#6290A8', accentText: '#0E1418',
    pill: '#43607A', pillText: '#EAF2F6',
    border: '#46606D', field: '#16171A', fieldText: '#EAF2F6',
    swatches: ['#212223', '#43607A', '#6290A8', '#9BBECF']
  },
  {
    id: 'rust-petrol', name: 'Rust & Petrol', mode: 'dark',
    page: '#0E1618', bar: '#081012', barText: '#C98A66',
    surface: '#0D3644', surfaceText: '#EAF0F2',
    ink: '#C98A66', body: '#CBD3D5', muted: '#8C8987',
    accent: '#7C4B2F', accentText: '#F6ECE4',
    pill: '#7C4B2F', pillText: '#F6ECE4',
    border: '#1C4754', field: '#081012', fieldText: '#EAF0F2',
    swatches: ['#0E1618', '#0D3644', '#7C4B2F', '#A1714F']
  },
  {
    id: 'cold-pagoda', name: 'Cold Pagoda Blue', mode: 'dark',
    page: '#0F181C', bar: '#081013', barText: '#A9EDF3',
    surface: '#15424D', surfaceText: '#E6FAFC',
    ink: '#A9EDF3', body: '#CDE9ED', muted: '#5FB4C2',
    accent: '#0F8498', accentText: '#04181C',
    pill: '#0F8498', pillText: '#E6FAFC',
    border: '#1E5260', field: '#081013', fieldText: '#E6FAFC',
    swatches: ['#0F181C', '#0F8498', '#38C3D7', '#A9EDF3']
  },
  {
    id: 'jungle-copper', name: 'Jungle Teal & Copper', mode: 'dark',
    page: '#051822', bar: '#020E14', barText: '#D7A878',
    surface: '#1B6F5E', surfaceText: '#EAF6F2',
    ink: '#D7A878', body: '#CFE3DC', muted: '#7FA89D',
    accent: '#2F9D8F', accentText: '#04201C',
    pill: '#A5623B', pillText: '#F6ECE4',
    border: '#27806C', field: '#020E14', fieldText: '#EAF6F2',
    swatches: ['#051822', '#1B6F5E', '#A5623B', '#C48E5C']
  },
  {
    id: 'storm-green', name: 'Storm Green & Pastel', mode: 'dark',
    page: '#103433', bar: '#0A2423', barText: '#E6E2E6',
    surface: '#2F524F', surfaceText: '#EDF2F1',
    ink: '#CFE0DD', body: '#DCE6E4', muted: '#9FB1AF',
    accent: '#5D7874', accentText: '#0A2423',
    pill: '#5D7874', pillText: '#EDF2F1',
    border: '#3E605C', field: '#0A2423', fieldText: '#EDF2F1',
    swatches: ['#103433', '#2F524F', '#5D7874', '#BEC5C5']
  }
];

function applyTheme(t) {
  const r = document.documentElement;
  const map = {
    page: t.page, bar: t.bar, 'bar-text': t.barText,
    surface: t.surface, 'surface-text': t.surfaceText,
    ink: t.ink, body: t.body, muted: t.muted,
    accent: t.accent, 'accent-text': t.accentText,
    pill: t.pill, 'pill-text': t.pillText,
    border: t.border, field: t.field, 'field-text': t.fieldText
  };
  Object.keys(map).forEach(k => r.style.setProperty('--' + k, map[k]));
  r.style.setProperty('--shadow', t.mode === 'dark' ? '0 8px 30px rgba(0,0,0,.45)' : '0 8px 30px rgba(60,52,38,.16)');
  r.style.setProperty('--scrim', t.mode === 'dark' ? 'rgba(0,0,0,.6)' : 'rgba(40,36,28,.45)');
}

window.CHURCH_THEMES = CHURCH_THEMES;
window.applyTheme = applyTheme;
