/* global React, INK, CREAM, PULSE, GENS, GradText, CTAButton, Reveal, useReveal, SB_EASE, ED_ACCENTS, EDSplit,
   MShell, MHead, MGenerate */
// Editing Suite feature page — mobile layout (skews alternate right → left → right …).
const { useState: emS, useEffect: emE } = React;

// eyebrows are hero-only on mobile — keep the heading, drop the pill
const MEDBadgeHead = ({ title, sub }) => <MHead title={title} sub={sub} />;
const MEDCard = ({ lean = 'right', children }) => (
  <div style={{ borderRadius: 18, background: '#fff', boxShadow: '0 12px 32px rgba(28,27,27,0.10), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 11, marginTop: 26,
    transform: lean === 'left' ? 'rotate(-1.2deg) perspective(1200px) rotateY(3deg)' : 'rotate(1.2deg) perspective(1200px) rotateY(-3deg)' }}>{children}</div>
);

// hero
const MED_CYCLE = [
  { src: 'assets/edits/base.webp', chip: 'Original' },
  { src: 'assets/edits/expression.webp', chip: 'Expression · laugh' },
  { src: 'assets/edits/object.webp', chip: 'Inpaint · necklace' },
  { src: 'assets/edits/color.webp', chip: 'Recolor · red' }];

const MEDHero = () => {
  const [ref, on] = useReveal(0.25);
  const [step, setStep] = emS(0);
  emE(() => {
    if (!on) return;
    const t = setInterval(() => setStep(s => (s + 1) % MED_CYCLE.length), 2400);
    return () => clearInterval(t);
  }, [on]);
  return (
    <section style={{ background: CREAM, padding: '0 22px 56px' }}>
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '16px 0 30px' }}>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}>
          <img loading="lazy" decoding="async" src="assets/logo-icon.png" alt="" style={{ width: 19, height: 19, objectFit: 'contain' }} />
          <span style={{ fontSize: 16, fontWeight: 800, letterSpacing: '-0.03em', color: INK }}>sozee</span>
        </span>
      </div>
      <div style={{ textAlign: 'center' }}>
        <Reveal>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: 7, marginBottom: 16, borderRadius: 9999, padding: '6px 12px', background: '#fff', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.1)' }}>
            <a href="/" style={{ fontSize: 10.5, fontWeight: 600, color: 'rgba(28,27,27,0.55)' }}>Features</a>
            <span style={{ fontSize: 10, color: 'rgba(28,27,27,0.35)' }}>/</span>
            <span style={{ fontSize: 10.5, fontWeight: 700, color: INK }}>Editing Suite</span>
          </div>
        </Reveal>
        <Reveal delay={90}>
          <h1 style={{ font: '800 44px/1 var(--font-sans)', letterSpacing: '-0.03em', color: INK, margin: '0 0 16px', textWrap: 'balance' }}>
            Edit anything.<br /><GradText>Reshoot nothing.</GradText>
          </h1>
        </Reveal>
        <Reveal delay={170}>
          <p style={{ fontSize: 14.5, lineHeight: 1.58, color: 'var(--text-secondary)', margin: '0 0 24px' }}>
            Make any edit you can imagine in our editing suite — inpaint, expressions, recolor, filters, 4K upscale. One photo, four edits, stacked.
          </p>
        </Reveal>
        <Reveal delay={250} style={{ marginBottom: 34 }}><CTAButton size="sm">Start editing</CTAButton></Reveal>
      </div>
      <Reveal delay={200} y={26}>
        <div ref={ref} style={{ transform: 'rotate(1.2deg) perspective(1200px) rotateY(-3deg)', borderRadius: 20, background: '#fff', boxShadow: '0 20px 44px rgba(28,27,27,0.12), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 12 }}>
          <div style={{ position: 'relative', borderRadius: 13, overflow: 'hidden', height: 300, background: 'rgb(246,243,242)', marginBottom: 10 }}>
            {MED_CYCLE.map((im, i) =>
              <img loading="lazy" decoding="async" key={im.chip} src={im.src} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%',
                opacity: step === i ? 1 : 0, transition: `opacity 0.6s ${SB_EASE}` }} />)}
            <span key={step} style={{ position: 'absolute', left: 8, bottom: 8, fontSize: 8.5, fontWeight: 700, color: '#fff', background: 'rgba(28,27,27,0.55)', borderRadius: 9999, padding: '3px 9px', animation: `sz-status-in 0.4s ${SB_EASE}` }}>{MED_CYCLE[step].chip}</span>
            <span style={{ position: 'absolute', top: 8, right: 8, fontSize: 8, fontWeight: 800, letterSpacing: '0.06em', color: '#fff', background: PULSE, borderRadius: 9999, padding: '3px 9px' }}>4K</span>
          </div>
          <div style={{ display: 'flex', gap: 5, flexWrap: 'wrap' }}>
            {MED_CYCLE.slice(1).map((im, i) =>
              <span key={im.chip} style={{ display: 'inline-flex', alignItems: 'center', gap: 4, borderRadius: 9999, padding: '4px 9px', fontSize: 8.5, fontWeight: 700, transition: `all 0.3s ${SB_EASE}`,
                background: step >= i + 1 ? INK : 'rgb(246,243,242)', color: step >= i + 1 ? '#fff' : 'rgba(28,27,27,0.45)',
                boxShadow: step >= i + 1 ? 'none' : 'inset 0 0 0 1px rgba(28,27,27,0.08)' }}>
                {step >= i + 1 && <svg width="7" height="7" viewBox="0 0 16 16" fill="none"><path d="M3 8.4l3.2 3.2L13.5 4" stroke="#fff" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" /></svg>}
                Edit {i + 1}</span>)}
            <span style={{ marginLeft: 'auto', fontSize: 8.5, fontWeight: 600, color: 'var(--text-tertiary)', alignSelf: 'center' }}>Edits stack</span>
          </div>
        </div>
      </Reveal>
    </section>);
};

// § 01 Inpaint
const MEDInpaint = () => {
  const [ref, on] = useReveal(0.35);
  const [done, setDone] = emS(false);
  emE(() => {
    if (!on) return;
    const t = setInterval(() => setDone(d => !d), 3200);
    return () => clearInterval(t);
  }, [on]);
  return (
    <MShell bg="#fff">
      <MEDBadgeHead label="Editing Suite · Inpaint" ac={ED_ACCENTS.Inpaint} title={<span>Brush the spot.<br /><GradText>Say the word.</GradText></span>}
        sub="Paint where the edit goes and type what changes — the edit lands only where you painted." />
      <MEDCard lean="left">
        <div ref={ref} style={{ position: 'relative', borderRadius: 12, overflow: 'hidden', height: 300, background: 'rgb(246,243,242)', marginBottom: 9 }}>
          <img loading="lazy" decoding="async" src="assets/edits/base.webp" alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%' }} />
          <img loading="lazy" decoding="async" src="assets/edits/object.webp" alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%',
            opacity: done ? 1 : 0, transition: `opacity 0.7s ${SB_EASE}` }} />
          {!done && <span style={{ position: 'absolute', left: '44%', top: '24%', width: 62, height: 38, borderRadius: '50%',
            background: 'rgba(129,60,237,0.28)', boxShadow: '0 0 0 2px rgba(129,60,237,0.55)', animation: 'sz-pulse-dot 1.6s ease-in-out infinite' }} />}
          <span style={{ position: 'absolute', left: 8, bottom: 8, fontSize: 8.5, fontWeight: 700, color: '#fff', background: 'rgba(28,27,27,0.55)', borderRadius: 9999, padding: '3px 9px' }}>
            {done ? 'Applied — only where painted' : 'Brush where it goes'}</span>
        </div>
        <div style={{ display: 'flex', gap: 7, alignItems: 'center' }}>
          <span style={{ width: 36, height: 36, borderRadius: 9, overflow: 'hidden', flexShrink: 0, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.12)', background: '#fff' }}>
            <img loading="lazy" decoding="async" src="assets/edits/necklace.png" alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} /></span>
          <div style={{ flex: 1, minWidth: 0, borderRadius: 10, background: 'rgb(235,231,231)', display: 'flex', alignItems: 'center', padding: '0 11px', height: 36, fontSize: 10.5, fontWeight: 500, color: INK }}>
            add this necklace
          </div>
          <span style={{ display: 'inline-flex', alignItems: 'center', borderRadius: 10, height: 36, padding: '0 12px', background: PULSE, color: '#fff', fontSize: 8.5, fontWeight: 800, letterSpacing: '0.05em' }}>APPLY ✦</span>
        </div>
      </MEDCard>
    </MShell>);
};

// § 02 Expression
const MEDExpression = () => {
  const [sel, setSel] = emS(1);
  return (
    <MShell>
      <MEDBadgeHead label="Editing Suite · Expression" ac={ED_ACCENTS.Expression} title={<span>New mood.<br /><GradText>One click.</GradText></span>}
        sub="Ten expressions applied without touching a prompt. Her face, still her." />
      <MEDCard lean="right">
        <div style={{ position: 'relative', borderRadius: 12, overflow: 'hidden', height: 300, background: 'rgb(246,243,242)', marginBottom: 9 }}>
          <img loading="lazy" decoding="async" src="assets/edits/base.webp" alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%' }} />
          <img loading="lazy" decoding="async" src="assets/edits/expression.webp" alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%',
            opacity: sel === 1 ? 1 : 0, transition: `opacity 0.55s ${SB_EASE}` }} />
        </div>
        <div className="m-nosb" style={{ display: 'flex', gap: 5, overflowX: 'auto' }}>
          {['Original', 'Playful laugh', 'Soft smile', 'Wink', 'Seductive'].map((n, i) =>
            <span key={n} onClick={() => setSel(i > 1 ? 1 : i)} style={{ borderRadius: 9999, padding: '6px 11px', fontSize: 9.5, fontWeight: sel === i ? 700 : 600, cursor: 'pointer', whiteSpace: 'nowrap', flexShrink: 0,
              background: sel === i ? INK : 'rgb(246,243,242)', color: sel === i ? '#fff' : 'rgba(28,27,27,0.6)',
              boxShadow: sel === i ? 'none' : 'inset 0 0 0 1px rgba(28,27,27,0.08)' }}>{n}</span>)}
        </div>
      </MEDCard>
    </MShell>);
};

// § 03 Recolor
const MEDRecolor = () => (
  <MShell bg="#fff">
    <MEDBadgeHead label="Editing Suite · Recolor" ac={ED_ACCENTS.Recolor} title={<span>Type the edit.<br /><GradText>Watch it happen.</GradText></span>}
      sub="Fabric, light and shadow follow the change — nothing else moves. Drag the handle." />
    <MEDCard lean="left">
      <EDSplit before="assets/edits/object.webp" after="assets/edits/color.webp" labelB="Before" labelA="Recolored" h={300} />
      <div style={{ display: 'flex', gap: 7, alignItems: 'center', marginTop: 9 }}>
        <div style={{ flex: 1, minWidth: 0, borderRadius: 10, background: 'rgb(235,231,231)', display: 'flex', alignItems: 'center', padding: '0 11px', height: 36, fontSize: 10.5, fontWeight: 500, color: INK }}>
          make the top red
        </div>
        <span style={{ display: 'inline-flex', alignItems: 'center', borderRadius: 10, height: 36, padding: '0 12px', background: PULSE, color: '#fff', fontSize: 8.5, fontWeight: 800, letterSpacing: '0.05em' }}>APPLY ✦</span>
      </div>
    </MEDCard>
  </MShell>
);

// § 04 Filters
const MED_SLIDERS = [['Contrast', 62], ['Exposure', 48], ['Sharpness', 70], ['Grain', 22]];
const MEDFilters = () => (
  <MShell>
    <MEDBadgeHead label="Editing Suite · Filters" ac={ED_ACCENTS.Filters} title={<span>Grade it<br /><GradText>like film.</GradText></span>}
      sub="Contrast, exposure, sharpness, grain — dialed on sliders with a live before/after split." />
    <MEDCard lean="right">
      <EDSplit before="assets/edits/color.webp" after="assets/edits/color.webp" beforeFilter="saturate(0.68) contrast(0.92) brightness(1.06)" labelB="Original" labelA="Graded" h={240} />
      <div style={{ display: 'flex', flexDirection: 'column', gap: 11, marginTop: 12, padding: '0 2px 4px' }}>
        {MED_SLIDERS.map(([n, v]) =>
          <div key={n}>
            <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 5 }}>
              <span style={{ fontSize: 9.5, fontWeight: 700, color: INK }}>{n}</span>
              <span style={{ fontSize: 9, fontWeight: 600, color: 'var(--text-tertiary)' }}>{v}</span>
            </div>
            <div style={{ position: 'relative', height: 3.5, borderRadius: 9999, background: 'rgb(235,231,231)' }}>
              <span style={{ position: 'absolute', left: 0, top: 0, bottom: 0, width: `${v}%`, borderRadius: 9999, background: PULSE }} />
              <span style={{ position: 'absolute', left: `${v}%`, top: '50%', transform: 'translate(-50%,-50%)', width: 12, height: 12, borderRadius: '50%', background: '#fff', boxShadow: '0 2px 8px rgba(28,27,27,0.3), 0 0 0 1px rgba(28,27,27,0.08)' }} />
            </div>
          </div>
        )}
      </div>
    </MEDCard>
  </MShell>
);

// § 05 Upscale
const MEDUpscale = () => {
  const [res, setRes] = emS(2);
  return (
    <MShell bg="#fff">
      <MEDBadgeHead label="Editing Suite · Upscale" ac={ED_ACCENTS.Upscale} title={<span>Finish it<br /><GradText>in 4K.</GradText></span>}
        sub="One click takes the final edit to 4096px — crisp enough for print, heavy enough for any crop." />
      <MEDCard lean="left">
        <div style={{ position: 'relative', borderRadius: 12, overflow: 'hidden', height: 300, background: 'rgb(246,243,242)', marginBottom: 9 }}>
          <img loading="lazy" decoding="async" src="assets/edits/color.webp" alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 10%',
            transform: 'scale(1.15)', filter: res === 0 ? 'blur(1.6px)' : res === 1 ? 'blur(0.6px)' : 'none', transition: `filter 0.5s ${SB_EASE}` }} />
          <span style={{ position: 'absolute', top: 8, right: 8, fontSize: 8.5, fontWeight: 800, letterSpacing: '0.06em', color: '#fff', background: PULSE, borderRadius: 9999, padding: '3px 9px' }}>{['1K', '2K', '4K'][res]}</span>
          <span style={{ position: 'absolute', left: 8, bottom: 8, fontSize: 8.5, fontWeight: 700, color: '#fff', background: 'rgba(28,27,27,0.55)', borderRadius: 9999, padding: '3px 9px' }}>Detail crop · {['1024px', '2048px', '4096px'][res]}</span>
        </div>
        <div style={{ display: 'flex', gap: 5, alignItems: 'center' }}>
          {['1K', '2K', '4K'].map((n, i) =>
            <span key={n} onClick={() => setRes(i)} style={{ borderRadius: 9999, padding: '6px 13px', fontSize: 9.5, fontWeight: res === i ? 700 : 600, cursor: 'pointer',
              background: res === i ? INK : 'rgb(246,243,242)', color: res === i ? '#fff' : 'rgba(28,27,27,0.6)',
              boxShadow: res === i ? 'none' : 'inset 0 0 0 1px rgba(28,27,27,0.08)' }}>{n}</span>)}
          <span style={{ marginLeft: 'auto', fontSize: 8.5, color: 'var(--text-tertiary)' }}>Print-ready</span>
        </div>
      </MEDCard>
    </MShell>);
};

// § 06 pipeline
const MED_NEXT = [
  { t: 'The Scheduler', d: 'Queue the fixed photo to six platforms.', kind: 'sched', href: '/#11 Scheduler' },
  { t: 'Create Video', d: 'Make the finished photo move.', kind: 'video', href: '/create-video' },
  { t: 'Photo Shoot', d: 'Shoot a locked set of ten around it.', kind: 'shoot', href: '/#05 Photo Shoot' }];

const MEDPipeMedia = ({ kind }) => (
  <div style={{ width: 96, borderRadius: 11, overflow: 'hidden', flexShrink: 0, aspectRatio: '4/4.4', background: '#fff', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 5, boxSizing: 'border-box', display: 'flex', flexDirection: 'column', gap: 4 }}>
    {kind === 'sched' &&
      <div style={{ display: 'flex', flexDirection: 'column', gap: 4, flex: 1, minHeight: 0 }}>
        {[['assets/edits/color.webp', 'IG · 9:00'], ['assets/shoot/set-2.webp', 'TT · 12:30'], ['assets/create/out-garden.webp', 'OF · 6:00']].map(([src, l]) =>
          <span key={l} style={{ display: 'flex', alignItems: 'center', gap: 5, borderRadius: 6, background: 'rgb(250,247,247)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.07)', padding: '0 5px', flex: 1, minHeight: 0 }}>
            <span style={{ width: 14, height: 14, borderRadius: 4, overflow: 'hidden', flexShrink: 0 }}>
              <img loading="lazy" decoding="async" src={src} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 20%' }} /></span>
            <span style={{ fontSize: 7, fontWeight: 700, color: INK, whiteSpace: 'nowrap' }}>{l}</span>
          </span>)}
      </div>}
    {kind === 'video' &&
      <span style={{ position: 'relative', flex: 1, minHeight: 0, borderRadius: 6, overflow: 'hidden', background: 'rgb(246,243,242)', display: 'block' }}>
        <video src="assets/video/explore-1.mp4" autoPlay muted loop playsInline preload="metadata" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%' }} />
      </span>}
    {kind === 'shoot' &&
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 4, flex: 1, minHeight: 0 }}>
        {[1, 2, 3, 4].map((n, i) =>
          <span key={n} style={{ position: 'relative', borderRadius: 5, overflow: 'hidden', boxShadow: i === 0 ? '0 0 0 1.5px var(--brand-purple-500)' : 'inset 0 0 0 1px rgba(28,27,27,0.08)' }}>
            <img loading="lazy" decoding="async" src={`assets/shoot/set-${n}.webp`} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 20%' }} /></span>)}
      </div>}
  </div>
);

const MEDPipeline = () => (
  <MShell>
    <MHead title={<span>Fixed.<br /><GradText>Now ship it.</GradText></span>}
      sub="The finished photo is already on a board wired into the rest of the studio." />
    <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginTop: 28 }}>
      {MED_NEXT.map((c, i) =>
        <Reveal key={c.t} delay={i * 90} y={20}>
          <a href={c.href} style={{ display: 'flex', gap: 12, borderRadius: 16, overflow: 'hidden', background: '#fff', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', color: 'inherit', padding: 10, transform: `rotate(${i % 2 ? 0.9 : -0.9}deg)` }}>
          <MEDPipeMedia kind={c.kind} />
            <div style={{ minWidth: 0, alignSelf: 'center' }}>
              <div style={{ fontSize: 14.5, fontWeight: 700, letterSpacing: '-0.01em', color: INK, marginBottom: 4 }}>{c.t}</div>
              <div style={{ fontSize: 11.5, lineHeight: 1.5, color: 'var(--text-secondary)' }}>{c.d}</div>
            </div>
          </a>
        </Reveal>
      )}
    </div>
    <Reveal delay={280} style={{ textAlign: 'center', marginTop: 20 }}>
      <a href="/" style={{ fontSize: 12.5, fontWeight: 600, color: 'var(--brand-purple-700)' }}>See the full tour →</a>
    </Reveal>
  </MShell>
);

const MEDPage = () => (
  <React.Fragment>
    <div style={{ fontFamily: 'var(--font-sans)', maxWidth: 430, margin: '0 auto', boxShadow: '0 0 0 1px rgba(28,27,27,0.06), 0 0 60px rgba(28,27,27,0.08)', overflow: 'clip' }}>
      <div data-screen-label="Hero — Editing Suite"><MEDHero /></div>
      <div data-screen-label="01 Inpaint"><MEDInpaint /></div>
      <div data-screen-label="02 Expression"><MEDExpression /></div>
      <div data-screen-label="03 Recolor"><MEDRecolor /></div>
      <div data-screen-label="04 Filters"><MEDFilters /></div>
      <div data-screen-label="05 Upscale"><MEDUpscale /></div>
      <div data-screen-label="06 Ship it"><MEDPipeline /></div>
      <div data-screen-label="07 Pricing"><window.MPricingSection /></div>
      <div data-screen-label="08 FAQ"><window.MFAQSection /></div>
      <div data-screen-label="CTA + Footer"><window.MFinalSection /></div>
    </div>
    <window.MCISticky />
    <window.SozeeNavMobile siteHref="/" localLabels={{ '/editing-suite': 'Hero — Editing Suite', '06 Edit Image': 'Hero — Editing Suite', '15 Pricing': '07 Pricing', '16 FAQ': '08 FAQ' }} />
  </React.Fragment>
);

Object.assign(window, { MEDPage });
