// aerOS Guest v2 — fresh/bold theme system. buildTheme(t) -> palette C driven by tweaks.
(function () {
  // Accent presets (curated). Each: base + a darker shade for gradients.
  const ACCENTS = {
    '#E0742F': '#B85718', // Ember (default)
    '#C99A3E': '#9C7320', // Gold
    '#9E2B36': '#741B24', // Wine
    '#2F7D6B': '#1C5849', // Jade
    '#6C5CE0': '#4B3CC0', // Iris
    '#D14D7A': '#A8325B', // Rose
  };

  function mix(a, pct, b) { return `color-mix(in oklab, ${a} ${pct}%, ${b})`; }

  function buildTheme(t) {
    const accent = t.accent || '#E0742F';
    const accentDark = ACCENTS[accent] || mix(accent, 70, '#000');
    const dark = t.theme !== 'light';

    const base = dark ? {
      bg: '#14110D', bg2: '#1E1A14', bg3: '#262019', bgGlass: 'rgba(30,26,20,0.72)',
      ink: '#F5EFE4', ink2: '#C7BCA8', muted: '#8C8273',
      line: 'rgba(245,239,228,0.10)', line2: 'rgba(245,239,228,0.16)',
      shadow: '0 18px 40px -12px rgba(0,0,0,0.6)', cardShadow: '0 2px 14px rgba(0,0,0,0.35)',
    } : {
      bg: '#F6F1E8', bg2: '#FFFFFF', bg3: '#FFFFFF', bgGlass: 'rgba(255,253,249,0.78)',
      ink: '#1C1712', ink2: '#5C5346', muted: '#988C79',
      line: 'rgba(28,23,18,0.09)', line2: 'rgba(28,23,18,0.14)',
      shadow: '0 18px 40px -14px rgba(40,30,15,0.30)', cardShadow: '0 2px 14px rgba(40,30,15,0.07)',
    };

    return {
      dark, accent, accentDark,
      accentSoft: dark ? mix(accent, 18, '#14110D') : mix(accent, 12, '#fff'),
      accentInk: '#fff',
      onAccentSoft: dark ? mix(accent, 78, '#fff') : accentDark,
      // diet colors
      veg: '#5FAE5F', vegan: '#3E9D6B', spicy: '#E0492F', gf: '#C99A3E', star: '#E0A82E',
      ...base,
    };
  }

  // Font stacks. headingFont tweak picks the display face.
  const HEAD_FONTS = {
    bodoni: '"Bodoni Moda", "Times New Roman", serif',
    cormorant: '"Cormorant Garamond", Georgia, serif',
    space: '"Space Grotesk", system-ui, sans-serif',
    archivo: '"Archivo", system-ui, sans-serif',
  };
  function headFont(t) { return HEAD_FONTS[t.headingFont] || HEAD_FONTS.bodoni; }
  const BODY_FONT = '"Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif';

  const CUR = { '₺': { sym: '₺', loc: 'tr-TR', rate: 1 }, '$': { sym: '$', loc: 'en-US', rate: 0.031 }, '€': { sym: '€', loc: 'de-DE', rate: 0.029 } };
  function money(n, cur = '₺') {
    const c = CUR[cur] || CUR['₺'];
    const v = Math.round(n * c.rate);
    return c.sym === '$' || c.sym === '€' ? c.sym + v.toLocaleString(c.loc) : c.sym + v.toLocaleString('tr-TR');
  }

  // global style: fonts + keyframes + scrollbar reset
  const st = document.createElement('style');
  st.textContent = `
    @keyframes g2pop{from{opacity:0;transform:scale(.94)}to{opacity:1;transform:scale(1)}}
    @keyframes g2up{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
    @keyframes g2rise{from{transform:translateY(14px)}to{transform:translateY(0)}}
    @keyframes g2sheet{from{transform:translateY(100%)}to{transform:translateY(0)}}
    @keyframes g2fade{from{opacity:0}to{opacity:1}}
    @keyframes g2pulse{0%{box-shadow:0 0 0 0 var(--g2acc,rgba(224,116,47,.5))}70%{box-shadow:0 0 0 12px rgba(0,0,0,0)}100%{box-shadow:0 0 0 0 rgba(0,0,0,0)}}
    @keyframes g2shimmer{0%{background-position:-200% 0}100%{background-position:200% 0}}
    @keyframes g2spin{to{transform:rotate(360deg)}}
    .g2-noscroll::-webkit-scrollbar{width:0;height:0}
    .g2-noscroll{scrollbar-width:none}
    /* Entrance: transform-only (NO opacity) so a frozen/hidden-tab frame keeps the
       element visible (opacity defaults to 1) — never stuck invisible. */
    .g2-stagger>*{animation:g2rise .5s cubic-bezier(.22,1,.36,1)}
  `;
  document.head.appendChild(st);

  window.G2THEME = { buildTheme, headFont, BODY_FONT, money, ACCENTS, HEAD_FONTS };
})();
