// nyashelf-tokens.jsx
// Color palettes + theme helper. Resolves to CSS variables consumed across components.

const NYA_PALETTES = {
  night: {
    label: 'Ночь',
    bg0: '#2a1a4a', bg1: '#1a1438', bg2: '#3d2a5c',
    accentA: '#f5a3c7', accentB: '#c89bf0',
    glow:    '#ff9ecd',
    moon:    '#f5e6a8',
    text:    '#ece8ff', textDim: '#9a8fc4',
    cardBg:  'rgba(60,40,90,0.28)',
    cardBorder: 'rgba(200,155,240,0.18)',
  },
  twilight: {
    label: 'Сумерки',
    bg0: '#1f2a5c', bg1: '#0f1638', bg2: '#2a1f5c',
    accentA: '#a5c3f5', accentB: '#c89bf0',
    glow:    '#9ecdff',
    moon:    '#e8d4ff',
    text:    '#e8ecff', textDim: '#8a96c4',
    cardBg:  'rgba(40,55,100,0.30)',
    cardBorder: 'rgba(165,195,245,0.18)',
  },
  sakura: {
    label: 'Сакура',
    bg0: '#3d1a3a', bg1: '#2a0e30', bg2: '#5c2a4a',
    accentA: '#ffb3d9', accentB: '#e8a3f0',
    glow:    '#ff9ecd',
    moon:    '#ffd9b3',
    text:    '#ffe8f4', textDim: '#c49ab8',
    cardBg:  'rgba(90,40,75,0.30)',
    cardBorder: 'rgba(255,179,217,0.18)',
  },
  moonlit: {
    label: 'Лунный',
    bg0: '#1a2440', bg1: '#0e1428', bg2: '#2a3454',
    accentA: '#c4e4ff', accentB: '#b3c8ff',
    glow:    '#a8d8ff',
    moon:    '#f5e6a8',
    text:    '#e8f0ff', textDim: '#8a9ac4',
    cardBg:  'rgba(40,55,90,0.32)',
    cardBorder: 'rgba(196,228,255,0.18)',
  },
};

function buildThemeStyle(t) {
  const p = NYA_PALETTES[t.palette] || NYA_PALETTES.night;
  const glow = t.glow / 100;
  return {
    '--bg-0': p.bg0,
    '--bg-1': p.bg1,
    '--bg-2': p.bg2,
    '--accent-a': p.accentA,
    '--accent-b': p.accentB,
    '--glow': p.glow,
    '--glow-soft': `${p.glow}${Math.round(glow * 0.55 * 255).toString(16).padStart(2, '0')}`,
    '--glow-strong': `${p.glow}${Math.round(glow * 255).toString(16).padStart(2, '0')}`,
    '--glow-amount': glow,
    '--moon': p.moon,
    '--text': p.text,
    '--text-dim': p.textDim,
    '--card-bg': p.cardBg,
    '--card-border': p.cardBorder,
    '--radius': `${t.radius}px`,
    '--radius-sm': `${Math.max(8, t.radius * 0.55)}px`,
    '--radius-lg': `${t.radius * 1.4}px`,
    '--anim-speed': t.animations ? '1' : '0',
    color: p.text,
  };
}

Object.assign(window, { NYA_PALETTES, buildThemeStyle });
