// Posiro MVP — mobile-first single-page. Goal: capture email.
// Three hero copy variants for A/B testing via Tweaks.

// Real ChatGPT-generated samples; same person across all 12 scenes.
const INPUT_IMGS = ['img/input-1.png','img/input-2.png','img/input-3.png'];
const OUTPUT_IMGS = [
  { src:'img/out-beach.png',     label:'Beach'    },
  { src:'img/out-evening.png',   label:'Evening'  },
  { src:'img/out-gym.png',       label:'Gym'      },
  { src:'img/out-fashion.png',   label:'Fashion'  },
  { src:'img/out-studio.png',    label:'Studio'   },
  { src:'img/out-sunset.png',    label:'Sunset'   },
  { src:'img/out-travel.png',    label:'Travel'   },
  { src:'img/out-editorial.png', label:'Editorial'},
  { src:'img/out-casual.png',    label:'Casual'   },
];
const VIDEO_IMGS = [
  { src:'img/video-tokyo.png',    label:'Tokyo',  duration:'0:18' },
  { src:'img/video-flowers.png',  label:'Sunset', duration:'0:14' },
  { src:'img/video-elevator.png', label:'Mirror', duration:'0:09' },
  { src:'img/video-beach.png',    label:'Beach',  duration:'0:22' },
];

function Img({ src, label, ratio='3/4', sample=false, style }) {
  return (
    <div style={{
      position:'relative', width:'100%', aspectRatio:ratio,
      borderRadius:14, overflow:'hidden',
      background:'#F3F4F6',
      boxShadow:'0 1px 2px rgba(10,14,39,.04), 0 8px 24px rgba(10,14,39,.06)',
      ...style,
    }}>
      <img src={src} alt={label||''} loading="lazy" decoding="async"
           style={{ width:'100%', height:'100%', objectFit:'cover', display:'block' }}/>
      {label && (
        <div style={{
          position:'absolute', left:10, top:10,
          padding:'4px 9px', borderRadius:999,
          background:'rgba(255,255,255,.85)', backdropFilter:'blur(8px)',
          WebkitBackdropFilter:'blur(8px)',
          fontSize:10.5, fontWeight:600, color:'#0A0E27', letterSpacing:'.02em',
        }}>{label}</div>
      )}
      {sample && (
        <div style={{
          position:'absolute', right:10, top:10,
          padding:'3px 8px', borderRadius:6,
          background:'rgba(10,14,39,.7)', color:'#fff',
          fontSize:9.5, fontWeight:600, letterSpacing:'.08em',
        }}>SAMPLE</div>
      )}
    </div>
  );
}

function VideoImg({ src, label, duration }) {
  return (
    <div style={{
      position:'relative', width:'100%', aspectRatio:'9/16',
      borderRadius:14, overflow:'hidden',
      background:'#F3F4F6',
      boxShadow:'0 1px 2px rgba(10,14,39,.04), 0 12px 30px rgba(10,14,39,.10)',
    }}>
      <img src={src} alt={label||''} loading="lazy" decoding="async"
           style={{ width:'100%', height:'100%', objectFit:'cover', display:'block' }}/>
      <div style={{
        position:'absolute', inset:0, display:'flex', alignItems:'center', justifyContent:'center',
      }}>
        <div style={{
          width:48, height:48, borderRadius:'50%',
          background:'rgba(255,255,255,.92)', display:'flex',
          alignItems:'center', justifyContent:'center',
          boxShadow:'0 8px 30px rgba(0,0,0,.25)',
        }}>
          <svg width="16" height="18" viewBox="0 0 18 20" fill="#0A0E27">
            <path d="M2 1 L16 10 L2 19 Z" />
          </svg>
        </div>
      </div>
      <div style={{
        position:'absolute', left:0, right:0, bottom:0, height:'40%',
        background:'linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,0))',
        pointerEvents:'none',
      }}/>
      <div style={{
        position:'absolute', left:12, bottom:10, color:'#fff',
        fontSize:11, fontWeight:600, letterSpacing:'.02em',
      }}>{label}</div>
      <div style={{
        position:'absolute', right:12, bottom:10, color:'#fff',
        fontSize:10, fontWeight:600, fontVariantNumeric:'tabular-nums',
        background:'rgba(0,0,0,.4)', padding:'2px 6px', borderRadius:4,
      }}>{duration}</div>
    </div>
  );
}

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "heroVariant": "A",
  "spotsLeft": 17,
  "showFAQ": true
}/*EDITMODE-END*/;

// ─── Copy variants ────────────────────────────────────────────────────────
const HERO_COPY = {
  A: {
    pill: 'Coming soon · 20 free spots',
    headline: ['Be your own', { serif: true, color: '#635BFF', text: 'AI photo studio.' }],
    sub: 'Upload 3 selfies. Get unlimited photos and short videos of yourself — same face, every time. New outfits, new scenes, no shoot day.',
    cta: 'Claim my free spot',
  },
  B: {
    pill: 'Early access · 3 months free',
    headline: ['Stop shooting.', { serif: true, color: '#EC4899', text: 'Start posting.' }],
    sub: 'Posiro turns 3 photos into a content engine — endless on-brand images and clips, ready in minutes. Built for creators who\u2019d rather earn than shoot.',
    cta: 'Get my 3 free months',
  },
  C: {
    pill: 'Limited beta · only 20 spots',
    headline: ['Your face.', 'Your rules.', { serif: true, color: '#F59E0B', text: 'Infinite content.' }],
    sub: 'Train Posiro on 3 photos and own a private AI version of yourself. Generate as much as you want — without ever booking another shoot.',
    cta: 'Reserve my spot',
  },
};

// ─── Pieces ───────────────────────────────────────────────────────────────
function Logo({ size = 24 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 26 26">
      <defs>
        <linearGradient id="lg" x1="0" y1="0" x2="1" y2="1">
          <stop offset="0%" stopColor="#635BFF"/>
          <stop offset="100%" stopColor="#EC4899"/>
        </linearGradient>
      </defs>
      <rect x="1" y="1" width="24" height="24" rx="7" fill="url(#lg)"/>
      <path d="M9 7 L9 19 M9 7 H15 Q18.5 7 18.5 11 Q18.5 14.5 15 14.5 H9" stroke="#fff" strokeWidth="2.2" fill="none" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  );
}

function Pill({ children, tone = 'indigo' }) {
  const tones = {
    indigo: { bg:'rgba(99,91,255,.10)', fg:'#4F46E5', dot:'#635BFF' },
    pink:   { bg:'rgba(236,72,153,.10)', fg:'#BE185D', dot:'#EC4899' },
    amber:  { bg:'rgba(245,158,11,.12)', fg:'#92400E', dot:'#F59E0B' },
  };
  const t = tones[tone];
  return (
    <span style={{
      display:'inline-flex', alignItems:'center', gap:7,
      padding:'6px 11px', borderRadius:999,
      background:t.bg, color:t.fg,
      fontSize:12, fontWeight:600, letterSpacing:'.01em',
    }}>
      <span style={{ width:6, height:6, borderRadius:'50%', background:t.dot, boxShadow:`0 0 0 4px ${t.bg}`, animation:'pulse 2s ease-in-out infinite' }}/>
      {children}
    </span>
  );
}

function Headline({ parts }) {
  return (
    <h1 style={{
      fontSize:'clamp(38px, 9.5vw, 68px)', lineHeight:1.04, letterSpacing:'-.025em',
      margin:'18px 0 16px', fontWeight:700, color:'#0A0E27',
    }}>
      {parts.map((p, i) => {
        if (typeof p === 'string') return <React.Fragment key={i}>{p}{i<parts.length-1 ? <br/> : null}</React.Fragment>;
        return <React.Fragment key={i}><span className="serif" style={{ color: p.color }}>{p.text}</span>{i<parts.length-1 ? <br/> : null}</React.Fragment>;
      })}
    </h1>
  );
}

const TALLY_FORM_ID = '4416qO';

function CTAForm({ ctaLabel, spotsLeft, compact = false }) {
  const [submitted, setSubmitted] = React.useState(false);
  const [submitterName, setSubmitterName] = React.useState('');

  // Get current hero variant label for A/B tracking
  const getVariantLabel = () => window.__posiroVariant || 'A';

  const openTally = () => {
    if (typeof Tally === 'undefined') {
      // Fallback: open form in new tab
      window.open(`https://tally.so/r/${TALLY_FORM_ID}?source=posiro.com&variant=${getVariantLabel()}`, '_blank');
      return;
    }
    Tally.openPopup(TALLY_FORM_ID, {
      layout: 'modal',
      hideTitle: true,
      overlay: true,
      autoClose: 3000,
      hiddenFields: {
        source: 'posiro.com',
        variant: getVariantLabel(),
      },
      onSubmit: (payload) => {
        // Extract name from submission for success message
        const nameField = payload.fields?.find(f => f.title === 'Name');
        setSubmitterName(nameField?.answer?.value || '');
        setSubmitted(true);
      },
    });
  };

  if (submitted) {
    return (
      <div style={{
        padding:'22px 20px', borderRadius:14,
        background:'linear-gradient(135deg, rgba(16,185,129,.08), rgba(99,91,255,.08))',
        border:'1px solid rgba(16,185,129,.25)',
        display:'flex', gap:14, alignItems:'flex-start',
      }}>
        <div style={{ flexShrink:0, width:36, height:36, borderRadius:'50%', background:'#10B981', display:'flex', alignItems:'center', justifyContent:'center' }}>
          <svg width="18" height="18" viewBox="0 0 18 18" fill="none"><path d="M4 9.5 L7.5 13 L14 5.5" stroke="#fff" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"/></svg>
        </div>
        <div>
          <div style={{ fontSize:16, fontWeight:600, color:'#0A0E27' }}>
            You&rsquo;re on the list{submitterName ? `, ${submitterName}` : ''}!
          </div>
          <div style={{ fontSize:14, color:'#6B7280', marginTop:4 }}>
            We&rsquo;ll email you the moment your spot is ready.
            Keep an eye on your inbox.
          </div>
        </div>
      </div>
    );
  }

  return (
    <div style={{ display:'grid', gap:10 }}>
      <button onClick={openTally} style={{
        height:54, border:0, borderRadius:12,
        background:'linear-gradient(135deg, #635BFF 0%, #8B5CF6 50%, #EC4899 100%)',
        color:'#fff', fontSize:16, fontWeight:600, letterSpacing:'.01em',
        cursor:'pointer', boxShadow:'0 8px 24px rgba(99,91,255,.30)',
        transition:'transform .12s ease',
      }}
      onTouchStart={(e)=>e.currentTarget.style.transform='scale(.98)'}
      onTouchEnd={(e)=>e.currentTarget.style.transform='scale(1)'}
      onMouseDown={(e)=>e.currentTarget.style.transform='scale(.98)'}
      onMouseUp={(e)=>e.currentTarget.style.transform='scale(1)'}
      onMouseLeave={(e)=>e.currentTarget.style.transform='scale(1)'}
      >
        {ctaLabel} →
      </button>
      <div style={{
        display:'flex', alignItems:'center', justifyContent:'center', gap:14,
        fontSize:12.5, color:'#6B7280', flexWrap:'wrap', marginTop:4,
      }}>
        <span style={{ display:'inline-flex', alignItems:'center', gap:5 }}>
          <Check/> No credit card
        </span>
        <span style={{ display:'inline-flex', alignItems:'center', gap:5 }}>
          <span style={{ width:6, height:6, borderRadius:'50%', background:'#EF4444', animation:'pulse 2s ease-in-out infinite' }}/>
          <b style={{ color:'#0A0E27' }}>{spotsLeft}/20</b> spots left
        </span>
      </div>
    </div>
  );
}
const inputStyle = {
  height:50, padding:'0 16px',
  border:'1px solid rgba(10,14,39,.12)', borderRadius:12,
  fontSize:16, fontFamily:'inherit', outline:'none',
  background:'#fff', color:'#0A0E27',
  width:'100%', WebkitAppearance:'none',
};
function Check() {
  return (
    <svg width="13" height="13" viewBox="0 0 13 13" fill="none">
      <circle cx="6.5" cy="6.5" r="6.5" fill="#10B981" opacity=".15"/>
      <path d="M3.5 6.7 L5.6 8.7 L9.5 4.5" stroke="#10B981" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  );
}
function Sparkle({ white }) {
  return (
    <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
      <path d="M7 0 L8.4 5.6 L14 7 L8.4 8.4 L7 14 L5.6 8.4 L0 7 L5.6 5.6 Z" fill={white ? '#fff' : '#635BFF'}/>
    </svg>
  );
}

// ─── Mobile nav (logo + waitlist anchor) ─────────────────────────────────
function Nav() {
  return (
    <header style={{
      position:'sticky', top:0, zIndex:50,
      backdropFilter:'blur(14px) saturate(160%)',
      WebkitBackdropFilter:'blur(14px) saturate(160%)',
      background:'rgba(251,250,248,.78)',
      borderBottom:'1px solid var(--line)',
    }}>
      <div style={{
        maxWidth:1100, margin:'0 auto', padding:'12px 20px',
        display:'flex', alignItems:'center', justifyContent:'space-between',
      }}>
        <div style={{ display:'flex', alignItems:'center', gap:8, fontWeight:700, fontSize:17, letterSpacing:'-.02em' }}>
          <Logo/> Posiro
        </div>
        <a href="#waitlist" style={{
          padding:'8px 14px', borderRadius:9,
          background:'#0A0E27', color:'#fff',
          fontSize:13, fontWeight:600,
        }}>Get early access</a>
      </div>
    </header>
  );
}

// ─── Hero ────────────────────────────────────────────────────────────────
function Hero({ variant, spotsLeft }) {
  const c = HERO_COPY[variant];
  return (
    <section style={{ position:'relative', overflow:'hidden' }}>
      <div className="mesh" />
      <div style={{
        position:'relative', zIndex:1,
        maxWidth:1100, margin:'0 auto',
        padding:'40px 20px 56px',
        display:'grid', gap:36,
      }} className="hero-grid">
        <div>
          <Pill tone={variant==='B'?'pink':variant==='C'?'amber':'indigo'}>{c.pill}</Pill>
          <Headline parts={c.headline}/>
          <p style={{
            fontSize:17, lineHeight:1.5, color:'#2D3148',
            margin:'0 0 28px', maxWidth:520,
          }}>{c.sub}</p>
          <div id="waitlist">
            <CTAForm ctaLabel={c.cta} spotsLeft={spotsLeft}/>
          </div>
        </div>
        <HeroVisual/>
      </div>
      <style>{`
        @media (min-width: 860px) {
          .hero-grid { grid-template-columns: 1.05fr 1fr; gap: 64px; align-items: center; padding: 64px 32px 80px !important; }
        }
      `}</style>
    </section>
  );
}

// Right-side / below-headline visual: prominent 3 inputs → arrow → 9 outputs
function HeroVisual() {
  return (
    <div style={{ position:'relative' }}>
      {/* INPUT row — large, labeled, raw selfie style */}
      <div>
        <div style={{
          display:'flex', alignItems:'center', gap:10, marginBottom:12, paddingLeft:2,
        }}>
          <div style={{
            display:'inline-flex', alignItems:'center', gap:6,
            padding:'4px 10px', borderRadius:6,
            background:'#0A0E27', color:'#fff',
            fontSize:10, fontWeight:700, letterSpacing:'.10em',
          }}>
            STEP 1 · YOU UPLOAD
          </div>
          <div style={{ fontSize:13, fontWeight:600, color:'#0A0E27' }}>3 selfies</div>
        </div>
        <div style={{
          display:'grid', gridTemplateColumns:'1fr 1fr 1fr', gap:10,
        }}>
          {INPUT_IMGS.map((s,i)=>(
            <div key={i} style={{
              position:'relative', width:'100%', aspectRatio:'1/1',
              borderRadius:14, overflow:'hidden',
              background:'#F3F4F6',
              border:'3px dashed rgba(99,91,255,.35)',
              transform: `rotate(${[-2.5, 1.2, -1.4][i]}deg)`,
              boxShadow:'0 4px 12px rgba(10,14,39,.06)',
            }}>
              <img src={s} alt="" loading="eager" decoding="async"
                   style={{ width:'100%', height:'100%', objectFit:'cover', display:'block' }}/>
              <div style={{
                position:'absolute', top:6, left:6,
                width:22, height:22, borderRadius:'50%',
                background:'#fff', color:'#0A0E27',
                fontSize:11, fontWeight:700,
                display:'flex', alignItems:'center', justifyContent:'center',
                boxShadow:'0 2px 6px rgba(10,14,39,.15)',
              }}>{i+1}</div>
            </div>
          ))}
        </div>
      </div>

      {/* Connector — arrow with "AI does the rest" */}
      <div style={{
        display:'flex', alignItems:'center', justifyContent:'center', gap:12,
        padding:'18px 0 14px',
      }}>
        <div style={{ flex:1, height:1, background:'linear-gradient(to right, transparent, rgba(99,91,255,.3))' }}/>
        <div style={{
          display:'inline-flex', alignItems:'center', gap:8,
          padding:'8px 14px', borderRadius:999,
          background:'linear-gradient(135deg, #635BFF 0%, #EC4899 100%)',
          color:'#fff', fontSize:12, fontWeight:700, letterSpacing:'.04em',
          boxShadow:'0 8px 20px rgba(99,91,255,.3)',
        }}>
          <Sparkle white/>
          POSIRO AI
          <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
            <path d="M2 7 H12 M8 3 L12 7 L8 11" stroke="#fff" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
          </svg>
        </div>
        <div style={{ flex:1, height:1, background:'linear-gradient(to left, transparent, rgba(236,72,153,.3))' }}/>
      </div>

      {/* OUTPUT grid — large, polished, labeled */}
      <div style={{
        background:'#fff', borderRadius:20, padding:16,
        boxShadow:'0 1px 3px rgba(10,14,39,.04), 0 30px 70px rgba(10,14,39,.12)',
        border:'1px solid rgba(10,14,39,.06)',
        position:'relative',
      }}>
        <div style={{ display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:12 }}>
          <div style={{ display:'flex', alignItems:'center', gap:10 }}>
            <div style={{
              display:'inline-flex', alignItems:'center', gap:6,
              padding:'4px 10px', borderRadius:6,
              background:'linear-gradient(135deg, #635BFF, #EC4899)', color:'#fff',
              fontSize:10, fontWeight:700, letterSpacing:'.10em',
            }}>
              STEP 2 · YOU GET
            </div>
            <div style={{ fontSize:13, fontWeight:600, color:'#0A0E27' }}>
              Unlimited photos & videos
            </div>
          </div>
          <div style={{
            fontSize:10.5, fontWeight:600, color:'#10B981',
            display:'flex', alignItems:'center', gap:5,
          }}>
            <span style={{ width:6, height:6, borderRadius:'50%', background:'#10B981', animation:'pulse 2s infinite' }}/>
            Live
          </div>
        </div>

        <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr 1fr', gap:8 }}>
          {OUTPUT_IMGS.map((o, i) => (
            <Img key={i} src={o.src} ratio="3/4" />
          ))}
        </div>

        <div style={{
          marginTop:14, padding:'12px 14px',
          background:'linear-gradient(90deg, rgba(99,91,255,.06), rgba(236,72,153,.06))',
          borderRadius:12, fontSize:12.5, color:'#0A0E27', fontWeight:500,
          display:'flex', alignItems:'center', gap:8, flexWrap:'wrap',
        }}>
          <Sparkle/>
          <span><b>Same face.</b> Different scenes, outfits, moods.</span>
          <span style={{ marginLeft:'auto', color:'#6B7280', fontWeight:500, fontSize:11.5 }}>
            Generated in &lt; 60s
          </span>
        </div>
      </div>

      {/* Floating count badge */}
      <div style={{
        position:'absolute', top:-12, right:-8, zIndex:4,
        background:'#0A0E27', color:'#fff',
        padding:'8px 14px', borderRadius:999,
        fontSize:12, fontWeight:700, letterSpacing:'.02em',
        boxShadow:'0 12px 30px rgba(10,14,39,.25)',
        display:'flex', alignItems:'center', gap:6,
        transform:'rotate(4deg)',
      }}>
        <span className="serif" style={{ fontSize:18, lineHeight:1, fontStyle:'normal' }}>3</span>
        <span style={{ opacity:.6 }}>→</span>
        <span className="serif" style={{ fontSize:18, lineHeight:1, fontStyle:'normal', color:'#FF80B5' }}>∞</span>
      </div>
    </div>
  );
}

// ─── How it works (compact, mobile-first) ───────────────────────────────
function HowItWorks() {
  const steps = [
    { n:'1', t:'Upload 3 photos', d:'Three clear selfies. That\u2019s the whole onboarding.' },
    { n:'2', t:'Train your AI twin', d:'~20 minutes. Posiro learns your face. Private to you.' },
    { n:'3', t:'Generate forever', d:'Type a scene. Photos in seconds, videos in minutes.' },
  ];
  return (
    <section style={{ padding:'56px 20px', background:'#fff' }}>
      <div style={{ maxWidth:1100, margin:'0 auto' }}>
        <Eyebrow>How it works</Eyebrow>
        <h2 style={H2}>Three photos in.<br/><span className="serif" style={{ color:'#635BFF' }}>Forever&rsquo;s worth</span> of content out.</h2>
        <div style={{ display:'grid', gap:14, marginTop:32 }} className="steps-grid">
          {steps.map((s, i)=>(
            <div key={i} style={{
              padding:'20px 22px', borderRadius:16,
              background:'linear-gradient(180deg, #FBFAF8 0%, #fff 100%)',
              border:'1px solid var(--line)',
              display:'flex', gap:16, alignItems:'flex-start',
            }}>
              <div style={{
                flexShrink:0,
                width:36, height:36, borderRadius:10,
                background:'linear-gradient(135deg, #EEF2FF, #FCE7F3)',
                display:'flex', alignItems:'center', justifyContent:'center',
                fontWeight:700, color:'#635BFF', fontSize:15,
              }}>{s.n}</div>
              <div>
                <h3 style={{ fontSize:17, fontWeight:600, letterSpacing:'-.01em', margin:'0 0 4px' }}>{s.t}</h3>
                <p style={{ margin:0, color:'#6B7280', fontSize:14, lineHeight:1.5 }}>{s.d}</p>
              </div>
            </div>
          ))}
        </div>
        <style>{`
          @media (min-width: 720px) {
            .steps-grid { grid-template-columns: repeat(3, 1fr); }
          }
        `}</style>
      </div>
    </section>
  );
}
const Eyebrow = ({ children }) => (
  <div style={{ fontSize:12, fontWeight:700, color:'#635BFF', letterSpacing:'.10em', textTransform:'uppercase', marginBottom:12 }}>{children}</div>
);
const H2 = {
  fontSize:'clamp(28px, 6vw, 44px)', fontWeight:700, lineHeight:1.08,
  letterSpacing:'-.02em', margin:0, color:'#0A0E27',
};

// ─── Sample marquee strip (mobile loves this) ────────────────────────────
function SampleMarquee() {
  const [tab, setTab] = React.useState('photos');
  // Doubled list for seamless infinite loop
  const photoList = [...OUTPUT_IMGS, ...OUTPUT_IMGS];
  const videoList = [...VIDEO_IMGS, ...VIDEO_IMGS, ...VIDEO_IMGS];
  return (
    <section style={{ padding:'56px 0', background:'var(--bg)' }}>
      <div style={{ padding:'0 20px', maxWidth:1100, margin:'0 auto 28px' }}>
        <Eyebrow>Sample outputs</Eyebrow>
        <h2 style={H2}>One person.<br/><span className="serif" style={{ color:'#EC4899' }}>A thousand looks.</span></h2>
        <p style={{ marginTop:14, fontSize:15.5, color:'#6B7280', lineHeight:1.55, maxWidth:560 }}>
          Every image and clip below was generated from the same 3 input photos.
          Same recognizable face — across every scene, outfit and mood.
        </p>
        <div style={{ marginTop:18, display:'inline-flex', background:'#fff', border:'1px solid var(--line)', borderRadius:10, padding:3, gap:2 }}>
          {[['photos','Photos'],['videos','Short videos']].map(([k,l])=>(
            <button key={k} onClick={()=>setTab(k)} style={{
              padding:'7px 14px', border:0, borderRadius:8,
              background: tab===k ? '#0A0E27' : 'transparent',
              color: tab===k ? '#fff' : '#2D3148',
              fontWeight:600, fontSize:13, cursor:'pointer',
            }}>{l}</button>
          ))}
        </div>
      </div>

      <div style={{ overflow:'hidden', maskImage:'linear-gradient(to right, transparent, #000 6%, #000 94%, transparent)', WebkitMaskImage:'linear-gradient(to right, transparent, #000 6%, #000 94%, transparent)' }}>
        {tab==='photos' ? (
          <div style={{
            display:'flex', gap:12, width:'max-content',
            animation:'marquee 50s linear infinite',
            padding:'4px 0',
          }}>
            {photoList.map((o, i) => (
              <div key={i} style={{ width:170, flexShrink:0 }}>
                <Img src={o.src} label={o.label} ratio="3/4" sample/>
              </div>
            ))}
          </div>
        ) : (
          <div style={{
            display:'flex', gap:12, width:'max-content',
            animation:'marquee 45s linear infinite',
            padding:'4px 0',
          }}>
            {videoList.map((v, i) => (
              <div key={i} style={{ width:160, flexShrink:0 }}>
                <VideoImg src={v.src} label={v.label} duration={v.duration}/>
              </div>
            ))}
          </div>
        )}
      </div>

      <div style={{ padding:'0 20px', maxWidth:1100, margin:'24px auto 0', textAlign:'center', fontSize:12.5, color:'#9CA3AF' }}>
        Real beta outputs. All generated from 3 input selfies.
      </div>
    </section>
  );
}

// ─── FAQ (compact accordion) ─────────────────────────────────────────────
function FAQ() {
  const items = [
    { q:'When does Posiro launch?', a:'We\u2019re targeting late spring 2026. Early testers get full access during beta and 3 months free after launch.' },
    { q:'Will I be charged anything?', a:'No. The first 20 testers pay $0 for the entire beta and 3 months after launch. No card required to join the waitlist.' },
    { q:'Is my data and likeness private?', a:'Yes. Your trained model is private to your account, not shared, not used to train anyone else\u2019s. One-click delete anytime.' },
    { q:'How many spots are left?', a:'We open 20 free spots. The counter on this page is live — once it hits zero, the waitlist moves to paid pricing at launch.' },
    { q:'Do I need any technical skills?', a:'None. If you can take a selfie and type a sentence, you can use Posiro.' },
  ];
  const [open, setOpen] = React.useState(-1);
  return (
    <section style={{ padding:'56px 20px', background:'#fff' }}>
      <div style={{ maxWidth:720, margin:'0 auto' }}>
        <Eyebrow>FAQ</Eyebrow>
        <h2 style={H2}>Quick answers.</h2>
        <div style={{ marginTop:28, borderTop:'1px solid var(--line)' }}>
          {items.map((it, i)=>(
            <div key={i} style={{ borderBottom:'1px solid var(--line)' }}>
              <button onClick={()=>setOpen(open===i?-1:i)} style={{
                width:'100%', padding:'18px 0', display:'flex', justifyContent:'space-between',
                alignItems:'center', background:'transparent', border:0, textAlign:'left', cursor:'pointer',
                fontSize:15.5, fontWeight:600, color:'#0A0E27', gap:14,
              }}>
                <span>{it.q}</span>
                <span style={{ flexShrink:0, color:'#635BFF', transform: open===i?'rotate(45deg)':'rotate(0)', transition:'transform .2s' }}>
                  <svg width="16" height="16" viewBox="0 0 18 18"><path d="M9 3 V15 M3 9 H15" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/></svg>
                </span>
              </button>
              {open===i && (
                <div style={{ paddingBottom:18, fontSize:14.5, color:'#6B7280', lineHeight:1.6 }}>
                  {it.a}
                </div>
              )}
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ─── Final CTA ───────────────────────────────────────────────────────────
function FinalCTA({ variant, spotsLeft }) {
  const c = HERO_COPY[variant];
  return (
    <section style={{ padding:'56px 20px 72px', background:'var(--bg)' }}>
      <div style={{
        maxWidth:720, margin:'0 auto',
        background:'linear-gradient(135deg, #0A0E27 0%, #1E2042 60%, #4F46E5 100%)',
        borderRadius:24, padding:'40px 28px', color:'#fff',
        position:'relative', overflow:'hidden',
      }}>
        <div style={{
          position:'absolute', top:-80, right:-80, width:280, height:280, borderRadius:'50%',
          background:'radial-gradient(circle, rgba(236,72,153,.4), transparent 70%)',
          pointerEvents:'none',
        }}/>
        <div style={{ position:'relative', zIndex:1 }}>
          <Pill tone="indigo">{spotsLeft} spots left · closes when full</Pill>
          <h2 style={{
            fontSize:'clamp(28px, 7vw, 44px)', fontWeight:700, lineHeight:1.08,
            letterSpacing:'-.02em', margin:'14px 0 14px', color:'#fff',
          }}>
            Be one of the <span className="serif" style={{ color:'#FF80B5' }}>first 20.</span>
          </h2>
          <p style={{ fontSize:15.5, color:'rgba(255,255,255,.75)', marginBottom:24, lineHeight:1.5 }}>
            Three months free. No card. No catch. Just the head start.
          </p>
          <CTAForm ctaLabel={c.cta} spotsLeft={spotsLeft}/>
        </div>
      </div>
    </section>
  );
}

function Footer() {
  return (
    <footer style={{ padding:'28px 20px 36px', background:'var(--bg)', borderTop:'1px solid var(--line)' }}>
      <div style={{
        maxWidth:1100, margin:'0 auto',
        display:'flex', justifyContent:'space-between', alignItems:'center', flexWrap:'wrap', gap:12,
      }}>
        <div style={{ display:'flex', alignItems:'center', gap:8, fontWeight:700, fontSize:15 }}>
          <Logo size={20}/> Posiro
        </div>
        <div style={{ fontSize:12, color:'#9CA3AF' }}>
          © 2026 Posiro · hello@posiro.com
        </div>
      </div>
    </footer>
  );
}

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

  // A/B test: assign random variant on first visit, persist in localStorage
  React.useEffect(() => {
    const key = 'posiro_ab_variant';
    let saved = localStorage.getItem(key);
    if (!saved || !['A','B','C'].includes(saved)) {
      saved = ['A','B','C'][Math.floor(Math.random() * 3)];
      localStorage.setItem(key, saved);
    }
    if (saved !== t.heroVariant) {
      setTweak('heroVariant', saved);
    }
  }, []);

  return (
    <div data-screen-label="Posiro Landing">
      <Nav/>
      <Hero variant={(window.__posiroVariant=t.heroVariant)} spotsLeft={t.spotsLeft}/>
      <HowItWorks/>
      <SampleMarquee/>
      {t.showFAQ && <FAQ/>}
      <FinalCTA variant={t.heroVariant} spotsLeft={t.spotsLeft}/>
      <Footer/>

      <TweaksPanel>
        <TweakSection label="A/B testing" />
        <TweakRadio
          label="Hero copy"
          value={t.heroVariant}
          options={[
            {value:'A', label:'A · AI studio'},
            {value:'B', label:'B · Stop shooting'},
            {value:'C', label:'C · Your face'},
          ]}
          onChange={(v)=>setTweak('heroVariant', v)}
        />
        <TweakSlider
          label="Spots left"
          value={t.spotsLeft}
          min={1} max={20}
          onChange={(v)=>setTweak('spotsLeft', v)}
        />
        <TweakSection label="Sections" />
        <TweakToggle label="Show FAQ" value={t.showFAQ} onChange={(v)=>setTweak('showFAQ', v)}/>
      </TweaksPanel>
    </div>
  );
}

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