// app.jsx — root composition + Tweaks
const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "palette": "electric",
  "font": "geist",
  "heroVariant": "split"
}/*EDITMODE-END*/;

/* ──────────────────────────────────────────────────────────
   Paletes — applied as CSS custom properties on <html>
   ────────────────────────────────────────────────────────── */
const PALETTES = {
  electric: {
    label: 'Electric',
    swatch: ['#0B0B0E', '#C8FF00', '#FF5C2E'],
    vars: {
      '--bg':        '#0B0B0E',
      '--bg-2':      '#14141A',
      '--surface':   '#1A1A22',
      '--surface-2': '#22222C',
      '--line':      '#2A2A36',
      '--line-2':    '#3A3A48',
      '--ink':       '#F5F5F2',
      '--ink-2':     '#B8B8B0',
      '--ink-3':     '#7A7A78',
      '--brand':     '#C8FF00',
      '--brand-ink': '#0B0B0E',
      '--accent':    '#FF5C2E',
    },
  },
  warm: {
    label: 'Warm sunrise',
    swatch: ['#FAF7F2', '#1F3A2E', '#B5481C'],
    vars: {
      '--bg':        '#FAF7F2',
      '--bg-2':      '#F2EEE5',
      '--surface':   '#FFFFFF',
      '--surface-2': '#EFEAE0',
      '--line':      '#E0DACD',
      '--line-2':    '#C9C2B2',
      '--ink':       '#1B1F1A',
      '--ink-2':     '#5A5A52',
      '--ink-3':     '#8B8978',
      '--brand':     '#1F3A2E',
      '--brand-ink': '#FAF7F2',
      '--accent':    '#B5481C',
    },
  },
  blueprint: {
    label: 'Blueprint',
    swatch: ['#0B1220', '#5BA3FF', '#FF4D8B'],
    vars: {
      '--bg':        '#0B1220',
      '--bg-2':      '#101A2E',
      '--surface':   '#15233D',
      '--surface-2': '#1B2C4B',
      '--line':      '#243456',
      '--line-2':    '#324868',
      '--ink':       '#F0F5FF',
      '--ink-2':     '#B3C0D9',
      '--ink-3':     '#7385A6',
      '--brand':     '#5BA3FF',
      '--brand-ink': '#0B1220',
      '--accent':    '#FF4D8B',
    },
  },
};

/* ──────────────────────────────────────────────────────────
   Font stacks
   ────────────────────────────────────────────────────────── */
const FONTS = {
  geist: {
    label: 'Geist',
    sample: 'Aa',
    display: "'Geist', ui-sans-serif, system-ui, sans-serif",
    body:    "'Geist', ui-sans-serif, system-ui, sans-serif",
    mono:    "'Geist Mono', ui-monospace, monospace",
  },
  editorial: {
    label: 'Editorial',
    sample: 'Aa',
    display: "'Instrument Serif', 'Times New Roman', serif",
    body:    "'Geist', ui-sans-serif, system-ui, sans-serif",
    mono:    "'Geist Mono', ui-monospace, monospace",
  },
  space: {
    label: 'Space Grotesk',
    sample: 'Aa',
    display: "'Space Grotesk', ui-sans-serif, sans-serif",
    body:    "'Space Grotesk', ui-sans-serif, sans-serif",
    mono:    "'Geist Mono', ui-monospace, monospace",
  },
  bricolage: {
    label: 'Bricolage',
    sample: 'Aa',
    display: "'Bricolage Grotesque', ui-sans-serif, sans-serif",
    body:    "'Bricolage Grotesque', ui-sans-serif, sans-serif",
    mono:    "'Geist Mono', ui-monospace, monospace",
  },
};

function applyTokens(palette, font) {
  const root = document.documentElement.style;
  const p = PALETTES[palette] || PALETTES.electric;
  Object.entries(p.vars).forEach(([k, v]) => root.setProperty(k, v));
  const f = FONTS[font] || FONTS.geist;
  root.setProperty('--font-display', f.display);
  root.setProperty('--font-body', f.body);
  root.setProperty('--font-mono', f.mono);
}

/* ──────────────────────────────────────────────────────────
   App
   ────────────────────────────────────────────────────────── */
function App() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);

  React.useEffect(() => {
    applyTokens(t.palette, t.font);
  }, [t.palette, t.font]);

  return (
    <React.Fragment>
      <Nav />
      <main>
        <Hero variant={t.heroVariant}/>
        <Problem />
        <HowItWorks />
        <Calculator />
        <Features />
        <Results />
        <Pricing />
        <Testimonials />
        <FAQ />
        <About />
        <Contact />
      </main>
      <Footer />

      <TweaksPanel title="Tweaks">
        <TweakSection label="Hero — wariant"/>
        <HeroVariantPicker value={t.heroVariant} onChange={v => setTweak('heroVariant', v)} />

        <TweakSection label="Paleta kolorów"/>
        <PalettePicker value={t.palette} onChange={v => setTweak('palette', v)} />

        <TweakSection label="Krój pisma"/>
        <FontPicker value={t.font} onChange={v => setTweak('font', v)} />
      </TweaksPanel>
    </React.Fragment>
  );
}

/* ────────── Custom Tweaks controls ────────── */

function HeroVariantPicker({ value, onChange }) {
  const opts = [
    { id: 'split',      label: 'Split + dashboard', desc: 'Headline + mock panelu' },
    { id: 'stat',       label: '20–30%', desc: 'Wielka liczba sterująca' },
    { id: 'storefront', label: 'Storefront', desc: 'Editorial · Pon–Sob → 24/7' },
  ];
  return (
    <div className="tw-variants">
      {opts.map(o => (
        <button key={o.id} className={`tw-var ${value===o.id?'is-on':''}`} onClick={()=>onChange(o.id)}>
          <div className="tw-var-label">{o.label}</div>
          <div className="tw-var-desc">{o.desc}</div>
        </button>
      ))}
      <style>{`
        .tw-variants{ display:flex; flex-direction:column; gap:6px; padding: 0 8px 6px; }
        .tw-var{
          text-align:left; background: rgba(0,0,0,.04);
          border:1px solid rgba(0,0,0,.08);
          border-radius: 8px; padding: 8px 10px;
          font: inherit; color: inherit;
          transition: border-color .15s, background .15s;
        }
        .tw-var.is-on{
          border-color: #0B0B0E;
          background: rgba(0,0,0,.06);
        }
        .tw-var-label{ font-size: 12px; font-weight: 600; }
        .tw-var-desc{ font-size: 10.5px; opacity: 0.7; margin-top: 1px; }
      `}</style>
    </div>
  );
}

function PalettePicker({ value, onChange }) {
  return (
    <div className="tw-pal">
      {Object.entries(PALETTES).map(([id, p]) => (
        <button key={id} className={`tw-pal-card ${value===id?'is-on':''}`} onClick={()=>onChange(id)}>
          <div className="tw-pal-sw">
            {p.swatch.map((c,i) => <span key={i} style={{ background: c }}/>)}
          </div>
          <span className="tw-pal-label">{p.label}</span>
        </button>
      ))}
      <style>{`
        .tw-pal{ display:flex; flex-direction:column; gap:6px; padding: 0 8px 6px; }
        .tw-pal-card{
          display:flex; align-items:center; gap: 10px;
          padding: 6px 8px; background: rgba(0,0,0,.04);
          border: 1px solid rgba(0,0,0,.08);
          border-radius: 8px;
          font: inherit; color: inherit;
        }
        .tw-pal-card.is-on{ border-color: #0B0B0E; background: rgba(0,0,0,.07); }
        .tw-pal-sw{ display:flex; gap: 0; border-radius: 6px; overflow:hidden; border: 1px solid rgba(0,0,0,.12); }
        .tw-pal-sw span{ display:block; width: 16px; height: 22px; }
        .tw-pal-label{ font-size: 12px; font-weight: 500; }
      `}</style>
    </div>
  );
}

function FontPicker({ value, onChange }) {
  return (
    <div className="tw-fnt">
      {Object.entries(FONTS).map(([id, f]) => (
        <button key={id} className={`tw-fnt-card ${value===id?'is-on':''}`} onClick={()=>onChange(id)}
          style={{ fontFamily: f.display }}>
          <span className="tw-fnt-sample">{f.sample}</span>
          <span className="tw-fnt-label">{f.label}</span>
        </button>
      ))}
      <style>{`
        .tw-fnt{
          display:grid; grid-template-columns: 1fr 1fr;
          gap: 6px; padding: 0 8px 6px;
        }
        .tw-fnt-card{
          display:flex; align-items:center; gap: 8px;
          padding: 8px 10px;
          background: rgba(0,0,0,.04);
          border: 1px solid rgba(0,0,0,.08);
          border-radius: 8px;
          color: inherit;
        }
        .tw-fnt-card.is-on{ border-color: #0B0B0E; background: rgba(0,0,0,.07); }
        .tw-fnt-sample{
          font-size: 22px; font-weight: 600;
          letter-spacing: -0.02em;
          line-height: 1;
        }
        .tw-fnt-label{ font-size: 11px; opacity: 0.7; font-family: ui-sans-serif, sans-serif; }
      `}</style>
    </div>
  );
}

/* ────────── Mount ────────── */
ReactDOM.createRoot(document.getElementById('root')).render(<App/>);
