export function formatSvelteTheme(design) {
  const { colors, typography, spacing, borders } = design;
  const lines = [];

  lines.push('/* Svelte theme — generated by designlang */');
  lines.push('/* Import in +layout.svelte or app.css */');
  lines.push('');
  lines.push(':root {');
  lines.push('  /* Colors */');
  if (colors.primary) lines.push(`  --color-primary: ${colors.primary.hex};`);
  if (colors.secondary) lines.push(`  --color-secondary: ${colors.secondary.hex};`);
  if (colors.accent) lines.push(`  --color-accent: ${colors.accent.hex};`);
  for (const [i, n] of colors.neutrals.slice(0, 10).entries()) {
    lines.push(`  --color-neutral-${(i + 1) * 100}: ${n.hex};`);
  }
  if (colors.backgrounds.length > 0) lines.push(`  --color-background: ${colors.backgrounds[0]};`);
  if (colors.text.length > 0) lines.push(`  --color-text: ${colors.text[0]};`);
  lines.push('');
  lines.push('  /* Typography */');
  if (typography.families.length > 0) lines.push(`  --font-primary: '${typography.families[0].name}', sans-serif;`);
  if (typography.families.length > 1) lines.push(`  --font-secondary: '${typography.families[1].name}', sans-serif;`);
  if (typography.body) lines.push(`  --font-size-base: ${typography.body.size}px;`);
  for (const s of typography.scale.slice(0, 8)) {
    lines.push(`  --font-size-${s.size}: ${s.size}px;`);
  }
  lines.push('');
  lines.push('  /* Spacing */');
  if (spacing.base) lines.push(`  --spacing-base: ${spacing.base}px;`);
  for (const [i, val] of spacing.scale.slice(0, 12).entries()) {
    lines.push(`  --spacing-${i + 1}: ${val}px;`);
  }
  lines.push('');
  lines.push('  /* Border Radii */');
  for (const r of borders.radii) {
    lines.push(`  --radius-${r.label}: ${r.value}px;`);
  }
  lines.push('}');

  return lines.join('\n');
}
