/* global React, INK, CREAM, PULSE, GENS, GradText, CTAButton, Reveal, useReveal, useTyping, Shimmer, SB_EASE,
   MPill, MPillP, MShell, MRail, MHead, MGenerate */
// Create Image feature page — mobile layout (formats follow site-mobile).
const { useState: cmS, useEffect: cmE } = React;
const MCI_PROMPT = 'mirror selfie of me in a white crop top and jean shorts in my bedroom';
const MCI_OUTS = [{ src: 'assets/create/out-mirror.webp' }, { src: 'assets/create/out-garden.webp' }];

// ---------- hero ----------
const MCIHero = () => {
  const [ref, on] = useReveal(0.25);
  const [phase, setPhase] = cmS('idle');
  const [typed, doneTyping] = useTyping(MCI_PROMPT, phase !== 'idle', 28, 400);
  cmE(() => { if (on && phase === 'idle') setPhase('typing'); }, [on]);
  cmE(() => {
    if (phase === 'typing' && doneTyping) { const t = setTimeout(() => setPhase('gen'), 650); return () => clearTimeout(t); }
    if (phase === 'gen') { const t = setTimeout(() => setPhase('done'), 1700); return () => clearTimeout(t); }
    if (phase === 'done') { const t = setTimeout(() => setPhase('typing'), 6000); return () => clearTimeout(t); }
  }, [phase, doneTyping]);
  const ready = phase === 'done';
  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 }}>Create Image</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' }}>
          Type a scene.<br /><GradText>Get the set.</GradText>
        </h1>
      </Reveal>
      <Reveal delay={170}>
        <p style={{ fontSize: 14.5, lineHeight: 1.58, color: 'var(--text-secondary)', margin: '0 0 24px' }}>
          One sentence becomes one to four photos of your Character — 4:5 or 9:16, up to 4K. The first image lands in about twenty seconds.
        </p>
      </Reveal>
      <Reveal delay={250} style={{ marginBottom: 34 }}><CTAButton size="sm">Start generating</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: 13 }}>
          <div style={{ display: 'flex', gap: 5, marginBottom: 11 }}>
            {['Create Image', 'Create Video', 'Live Mode'].map((m, i) =>
              <span key={m} style={{ flex: 1, textAlign: 'center', borderRadius: 9999, padding: '7px 0', fontSize: 9, fontWeight: i === 0 ? 700 : 600, whiteSpace: 'nowrap',
                background: i === 0 ? INK : 'rgb(246,243,242)', color: i === 0 ? '#fff' : 'rgba(28,27,27,0.55)',
                boxShadow: i === 0 ? 'none' : 'inset 0 0 0 1px rgba(28,27,27,0.08)' }}>{m}</span>
            )}
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 9, marginBottom: 11 }}>
            {MCI_OUTS.map((g, i) => {
              // only the first tile plays the generate → reveal animation; the rest
              // are already part of the set and stay in place across the loop
              const anim = i === 0;
              const shown = anim ? ready : true;
              return (
              <div key={i} style={{ position: 'relative', borderRadius: 12, overflow: 'hidden', background: 'rgb(246,243,242)', aspectRatio: '4 / 4.4' }}>
                {anim && !ready && <Shimmer style={{ position: 'absolute', inset: 0 }} />}
                <img loading="lazy" decoding="async" src={g.src} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 18%',
                  opacity: shown ? 1 : 0, filter: shown ? 'none' : 'blur(14px)',
                  transition: anim ? `opacity 0.55s ${SB_EASE}, filter 0.75s ${SB_EASE}` : 'none' }} />
                <span style={{ position: 'absolute', left: 7, bottom: 7, fontSize: 8, fontWeight: 700, color: shown ? '#fff' : 'rgba(28,27,27,0.6)',
                  background: shown ? 'rgba(28,27,27,0.55)' : '#fff', borderRadius: 9999, padding: '3px 7px' }}>{shown ? `${i + 1} / 3` : phase === 'gen' ? 'Generating…' : 'Waiting'}</span>
              </div>
              );
            })}
          </div>
          <div style={{ borderRadius: 14, boxShadow: 'inset 0 0 0 1.5px rgba(129,60,237,0.35)', padding: 9, marginBottom: 9 }}>
            <div style={{ display: 'flex', gap: 8, marginBottom: 9 }}>
              <span style={{ width: 30, height: 30, borderRadius: 8, flexShrink: 0, outline: '1.5px dashed rgba(28,27,27,0.22)', outlineOffset: -1.5, display: 'grid', placeItems: 'center' }}>
                <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="rgba(28,27,27,0.4)" strokeWidth="1.8"><rect x="3" y="5" width="18" height="14" rx="2"/><circle cx="9" cy="10" r="1.6"/><path d="M4 17l5-4 3 2 4-3 4 3"/></svg>
              </span>
              <div style={{ fontSize: 11.5, lineHeight: 1.45, color: typed ? INK : 'rgba(28,27,27,0.42)', minHeight: 30, fontWeight: 500 }}>
                {typed || 'Describe the scene, or drop a reference image…'}
                {phase === 'typing' && <span style={{ display: 'inline-block', width: 2, height: 12, background: 'var(--brand-purple-500)', marginLeft: 2, verticalAlign: 'middle', animation: 'sz-blink 1s step-end infinite' }} />}
              </div>
            </div>
            <div style={{ display: 'flex', gap: 5, flexWrap: 'wrap' }}>
              <span style={{ display: 'inline-flex', alignItems: 'center', gap: 4, borderRadius: 9999, padding: '4px 9px', fontSize: 9, fontWeight: 600, background: 'rgb(246,243,242)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', color: INK }}>
                <span style={{ width: 11, height: 11, borderRadius: '50%', backgroundImage: `url(${GENS[0].src})`, backgroundSize: 'cover', backgroundPosition: 'center 15%' }} />Scarlett
              </span>
              {['1K', '4:5', 'Photo Control'].map(c =>
                <span key={c} style={{ borderRadius: 9999, padding: '4px 9px', fontSize: 9, fontWeight: 600, background: 'rgb(246,243,242)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', color: INK }}>{c}</span>)}
            </div>
          </div>
          <MGenerate count={3} active={doneTyping} />
        </div>
      </Reveal>
    </section>);
};

// ---------- § 01 — Reference to Image ----------
const MCIRef = () => {
  const [ref, on] = useReveal(0.35);
  return (
    <MShell bg="#fff">
      <MHead title={<span>Seen the shot?<br /><GradText>Drop it in.</GradText></span>}
        sub="Drag any photo into the composer — a pose, a framing, a light — and Sozee re-shoots it as your Character. The prompt is optional." />
      <Reveal delay={220} style={{ textAlign: 'center', marginTop: 22 }}><CTAButton size="sm">Join for free</CTAButton></Reveal>
      <Reveal delay={180} y={24}>
        <div ref={ref} style={{ marginTop: 30, transform: 'rotate(-1.2deg) perspective(1200px) rotateY(3deg)', 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: 13 }}>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 30px 1fr', gap: 7, alignItems: 'center', marginBottom: 12 }}>
            <div style={{ position: 'relative', borderRadius: 12, overflow: 'hidden', aspectRatio: '3/3.8' }}>
              <img loading="lazy" decoding="async" src="assets/shots/mirror.webp" alt="Reference" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%',
                filter: 'saturate(0.85)', opacity: on ? 1 : 0, transition: `opacity 0.6s ${SB_EASE}` }} />
              <span style={{ position: 'absolute', left: 7, bottom: 7, fontSize: 7.5, fontWeight: 700, letterSpacing: '0.05em', textTransform: 'uppercase', color: '#fff',
                background: 'rgba(20,16,23,0.6)', borderRadius: 9999, padding: '2px 7px' }}>The reference</span>
            </div>
            <svg width="30" height="16" viewBox="0 0 40 20" style={{ justifySelf: 'center' }}>
              <line x1="2" y1="10" x2="30" y2="10" stroke="#813CED" strokeWidth="2" strokeDasharray="3 6" strokeLinecap="round" style={{ animation: 'sz-dash 1.2s linear infinite' }} />
              <path d="M28 4l8 6-8 6" fill="none" stroke="#813CED" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
            <div style={{ position: 'relative', borderRadius: 12, overflow: 'hidden', aspectRatio: '3/3.8' }}>
              <img loading="lazy" decoding="async" src="assets/create/out-mirror.webp" alt="Your Character" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 16%',
                opacity: on ? 1 : 0, filter: on ? 'none' : 'blur(12px)', transition: `opacity 0.7s ${SB_EASE} 350ms, filter 0.9s ${SB_EASE} 350ms` }} />
              <span style={{ position: 'absolute', left: 7, bottom: 7, fontSize: 7.5, fontWeight: 700, letterSpacing: '0.05em', textTransform: 'uppercase', color: '#fff',
                background: 'rgba(20,16,23,0.6)', borderRadius: 9999, padding: '2px 7px' }}>Your Character</span>
            </div>
          </div>
          <div style={{ display: 'flex', gap: 8, alignItems: 'center', marginBottom: 10 }}>
            <span style={{ position: 'relative', width: 38, height: 38, borderRadius: 10, overflow: 'hidden', flexShrink: 0, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.12)' }}>
              <img loading="lazy" decoding="async" src="assets/shots/mirror.webp" alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%' }} />
            </span>
            <div style={{ flex: 1, minWidth: 0, borderRadius: 11, background: 'rgb(235,231,231)', display: 'flex', alignItems: 'center', padding: '0 11px', height: 38, fontSize: 10.5, fontWeight: 500, color: INK }}>
              keep the pose, framing and light
            </div>
          </div>
          <MGenerate count={1} cost="1" />
        </div>
      </Reveal>
      <Reveal delay={300}>
        <p style={{ marginTop: 18, fontSize: 11, lineHeight: 1.55, color: 'var(--text-tertiary)', textAlign: 'center' }}>
          Works with anything — a saved post, a photo from your camera roll, a past shot you want to run back.
        </p>
      </Reveal>
    </MShell>);
};

// ---------- § 04 — Formats & quality ----------
const MCI_FMT = [
  { src: GENS[1].src, ar: '4 / 5', chip: '4:5 · Feed' },
  { src: GENS[3].src, ar: '9 / 16', chip: '9:16 · Stories & Reels' },
  { src: GENS[0].src, ar: '4 / 5', chip: '1K · 2K · 4K', badge: '4K' }];

const MCIFormats = () => (
  <MShell>
    <MHead title={<span>Every format<br /><GradText>the feed asks for.</GradText></span>}
      sub="Portrait for the feed, tall for Stories — one to four photos per run, rendered up to 4K. Pick the shape before you generate." />
    <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'flex-start', marginTop: 34, padding: '0 2px' }}>
      {[{ ...MCI_FMT[0], w: 158, r: '-3.5deg', mt: 14, z: 1 },
        { ...MCI_FMT[1], w: 122, r: '2.5deg', mt: 0, ml: -26, z: 3 },
        { ...MCI_FMT[2], w: 152, r: '-1.5deg', mt: 30, ml: -24, z: 2 }].map((f, i) =>
        <Reveal key={i} delay={140 + i * 110} y={22} style={{ zIndex: f.z, position: 'relative' }}>
          <div style={{ width: f.w, marginTop: f.mt, marginLeft: f.ml || 0, transform: `rotate(${f.r})` }}>
            <div style={{ position: 'relative', borderRadius: 14, overflow: 'hidden', aspectRatio: f.ar, boxShadow: '0 16px 34px rgba(28,27,27,0.18), 0 0 0 4px #fff' }}>
              <img loading="lazy" decoding="async" src={f.src} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 14%' }} />
              {f.badge && <span style={{ position: 'absolute', top: 8, right: 8, fontSize: 9, fontWeight: 800, letterSpacing: '0.06em', color: '#fff',
                background: PULSE, borderRadius: 9999, padding: '3px 9px', boxShadow: '0 6px 16px -2px rgba(104,19,212,0.5)' }}>{f.badge}</span>}
            </div>
            <div style={{ marginTop: 10, fontSize: 9.5, fontWeight: 700, color: 'rgba(28,27,27,0.6)', letterSpacing: '0.04em', textAlign: 'center', whiteSpace: 'nowrap' }}>{f.chip}</div>
          </div>
        </Reveal>
      )}
    </div>
  </MShell>
);

// ---------- § 06 — Where the image goes next ----------
const MCI_NEXT = [
  { t: 'Photo Shoot', d: 'Pick the best photo — Sozee shoots a locked set of ten around it.', kind: 'shoot', tag: 'Turn 1 into 10', href: '/#05 Photo Shoot' },
  { t: 'Create Video', d: 'Make it move — same scene, with her voice on the track.', kind: 'video', tag: 'Direct the take', href: '/create-video' },
  { t: 'The Scheduler', d: 'Queue it to six platforms straight from the board.', kind: 'sched', tag: 'Queued · IG · 9:00', href: '/#11 Scheduler' }];

const MPipeMedia = ({ 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 === '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>}
    {kind === 'video' && <React.Fragment>
      <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>
      <span style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 3, borderRadius: 6, padding: '4px 0', background: PULSE, color: '#fff', fontSize: 6.5, fontWeight: 800, letterSpacing: '0.05em' }}>GENERATE ✦</span>
    </React.Fragment>}
    {kind === 'sched' &&
      <div style={{ display: 'flex', flexDirection: 'column', gap: 4, flex: 1, minHeight: 0 }}>
        {[['assets/gen/beach-pool.png', '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>}
  </div>
);

const MCIPipeline = () => (
  <MShell bg="#fff">
    <MHead title={<span>One image is<br /><GradText>just the start.</GradText></span>}
      sub="Every photo lands on a board wired into the rest of the studio." />
    <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginTop: 28 }}>
      {MCI_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: CREAM, 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)` }}>
            <MPipeMedia kind={c.kind} />
            <div style={{ minWidth: 0, alignSelf: 'center' }}>
              <span style={{ display: 'inline-block', fontSize: 8, fontWeight: 700, color: 'var(--brand-purple-700)', background: 'var(--brand-purple-50)', border: '1px solid var(--brand-purple-200)', borderRadius: 9999, padding: '2px 7px', marginBottom: 6 }}>{c.tag}</span>
              <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>
);

// sticky bottom CTA for the mobile layout
const MCISticky = () => {
  const [on, setOn] = cmS(false);
  cmE(() => {
    const check = () => {
      // hide again once the closing CTA + footer comes into view — the bar never overlaps it
      const foot = document.querySelector('[data-screen-label="CTA + Footer"]');
      const atFooter = foot ? foot.getBoundingClientRect().top < window.innerHeight - 40 : false;
      setOn(window.scrollY > window.innerHeight * 0.9 && !atFooter);
    };
    window.addEventListener('scroll', check, { passive: true });
    check();
    return () => window.removeEventListener('scroll', check);
  }, []);
  return (
    <div style={{ position: 'fixed', bottom: 0, left: '50%', width: 'min(430px, 100vw)', boxSizing: 'border-box', zIndex: 55,
      padding: '18px 16px 12px', pointerEvents: on ? 'auto' : 'none',
      background: 'linear-gradient(to top, rgba(252,248,248,0.96) 55%, rgba(252,248,248,0))',
      transform: `translate(-50%, ${on ? '0%' : '120%'})`, transition: 'transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1)' }}>
      {/* szCTA, not szGo: on the Brands pages this must open the waitlist form */}
      <button onClick={() => window.szCTA && window.szCTA('Start for free', 'sticky-mobile')}
        style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 9, width: '100%', height: 50, border: 0, cursor: 'pointer',
        borderRadius: 9999, background: PULSE, color: '#fff', fontFamily: 'inherit', fontSize: 13.5, fontWeight: 700, letterSpacing: '0.06em', textTransform: 'uppercase',
        boxShadow: '0 10px 26px -6px rgba(104,19,212,0.55)' }}>
        Start for free
        <svg width="15" height="15" viewBox="0 0 16 16" fill="none"><path d="M3 8h9M8.5 4l4 4-4 4" stroke="#fff" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round"/></svg>
      </button>
    </div>
  );
};

const MCIPage = () => (
  <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 — Create Image"><MCIHero /></div>
      <div data-screen-label="01 Reference to Image"><MCIRef /></div>
      <div data-screen-label="02 Photo Control"><window.MPhotoControlSection /></div>
      <div data-screen-label="03 Explore prompts"><window.MExploreSection /></div>
      <div data-screen-label="04 Formats and Quality"><MCIFormats /></div>
      <div data-screen-label="05 What comes next"><MCIPipeline /></div>
      <div data-screen-label="06 Pricing"><window.MPricingSection /></div>
      <div data-screen-label="07 FAQ"><window.MFAQSection /></div>
      <div data-screen-label="CTA + Footer"><window.MFinalSection /></div>
    </div>
    <MCISticky />
    <window.SozeeNavMobile siteHref="/" localLabels={{ '/create-image': 'Hero — Create Image', '04 Photo Control': '02 Photo Control', '14 Explore': '03 Explore prompts', '15 Pricing': '06 Pricing', '16 FAQ': '07 FAQ' }} />
  </React.Fragment>
);

Object.assign(window, { MCIPage, MCISticky });
