// All 10 levels — Identity through Sponsor slot
// Each level owns its mood, copy, and field set; all share LevelShell.

// LEVEL 1 — Identity
function Level1({ data, setData, ...p }) {
  const set = (k) => (v) => setData({ ...data, [k]: v });
  const [sms, setSms] = React.useState(data.sms ?? true);
  React.useEffect(() => { setData({ ...data, sms }); }, [sms]);
  return (
    <LevelShell {...p} levelNum={1} textColor="#140602"
      mood="radial-gradient(circle at 90% 10%, rgba(255,200,0,0.4), transparent 45%), radial-gradient(circle at 10% 90%, rgba(207,152,67,0.22), transparent 50%), #F9F0CD"
      title={<>First —<br/>who's winning</>}
      titleAccent={{ text: 'the Bitcoin?', color: '#006FD6' }}
      subtitle="Basics. So we know where to send the coin."
      ctaLabel="Claim My Entry"
      bingoPose="thumbs" bingoPos="br">
      <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
        <div style={{ display: 'flex', gap: 8 }}>
          <div style={{ flex: 1 }}><TextField label="FIRST NAME" value={data.first} onChange={set('first')} placeholder="Jane"/></div>
          <div style={{ flex: 1 }}><TextField label="LAST NAME" value={data.last} onChange={set('last')} placeholder="Primal"/></div>
        </div>
        <TextField label="EMAIL" value={data.email} onChange={set('email')} type="email" placeholder="jane@example.com"/>
        <TextField label="PHONE" value={data.phone} onChange={set('phone')} type="tel" placeholder="(415) 555-0199"/>
        <TextField label="DATE OF BIRTH" value={data.dob} onChange={set('dob')} placeholder="MM / DD / YYYY"/>
        <div onClick={() => setSms(!sms)} style={{
          marginTop: 2, padding: '12px 14px',
          background: sms ? '#006FD6' : 'rgba(255,255,255,0.6)',
          color: sms ? '#fff' : '#140602',
          border: `2px solid ${sms ? '#006FD6' : 'rgba(20,6,2,0.12)'}`,
          borderRadius: 12, cursor: 'pointer',
          display: 'flex', alignItems: 'center', gap: 10,
          transition: 'all 160ms ease',
        }}>
          <div style={{
            width: 22, height: 22, borderRadius: 6,
            background: sms ? '#FFC800' : 'transparent',
            border: sms ? 'none' : '2px solid rgba(20,6,2,0.3)',
            display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0,
          }}>
            {sms && <svg width="12" height="12" viewBox="0 0 14 14"><path d="M2 7 L6 11 L12 3" stroke="#140602" strokeWidth="2.5" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>}
          </div>
          <div style={{ fontFamily: 'Inter', fontSize: 13, lineHeight: 1.35 }}>
            <b>Text me if I win.</b> Obviously.
          </div>
        </div>
        <div style={{
          padding: '10px 12px', background: 'rgba(20,6,2,0.04)', borderRadius: 10,
          fontFamily: 'Inter', fontSize: 10.5, lineHeight: 1.5, color: 'rgba(20,6,2,0.6)',
        }}>
          By tapping <b>Claim</b>, you agree we can text you if you win and occasionally drop fun Ape stuff in your inbox. <i>We're not that kind of ape.</i> 21+ to enter. See our{' '}
          <a href="#terms" onClick={(e) => { e.preventDefault(); console.log('Open: Official Rules'); }}
             style={{ color: '#006FD6', fontWeight: 600, textDecoration: 'underline' }}>Official Rules</a>,{' '}
          <a href="#terms" onClick={(e) => { e.preventDefault(); console.log('Open: Terms & Conditions'); }}
             style={{ color: '#006FD6', fontWeight: 600, textDecoration: 'underline' }}>Terms &amp; Conditions</a>, and{' '}
          <a href="#privacy" onClick={(e) => { e.preventDefault(); console.log('Open: Privacy Policy'); }}
             style={{ color: '#006FD6', fontWeight: 600, textDecoration: 'underline' }}>Privacy Policy</a>.
        </div>
      </div>
    </LevelShell>
  );
}

// LEVEL 2 — Demographics
function Level2({ data, setData, ...p }) {
  const set = (k) => (v) => setData({ ...data, [k]: v });
  return (
    <LevelShell {...p} levelNum={2} textColor="#fff"
      mood="linear-gradient(180deg, #003A6E 0%, #002447 100%)"
      title={<>Quick</>} titleAccent={{ text: 'vitals.', color: '#CF9843' }}
      subtitle="Paint us a picture. Skip what you want."
      ctaLabel="Continue" bingoPose="wave" bingoPos="br">
      <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
        <TextField dark label="ZIP CODE" value={data.zip} onChange={set('zip')} placeholder="94704"/>
        <SectionLabel color="rgba(255,232,166,0.7)">GENDER</SectionLabel>
        <ChipGroup accent="#CF9843" options={['Woman','Man','Non-binary','Prefer not to say']} selected={data.gender || []} setSelected={set('gender')}/>
        <SectionLabel color="rgba(255,232,166,0.7)">OCCUPATION</SectionLabel>
        <ChipGroup accent="#CF9843" options={[
          {id:'tech',label:'Tech',hint:'💻'},{id:'creative',label:'Creative',hint:'🎨'},
          {id:'finance',label:'Finance',hint:'💼'},{id:'health',label:'Healthcare',hint:'🩺'},
          {id:'edu',label:'Education',hint:'📚'},{id:'trades',label:'Trades',hint:'🔧'},
          {id:'food',label:'Food & Bev',hint:'🍳'},{id:'student',label:'Student',hint:'🎓'},
          {id:'retired',label:'Retired',hint:'🏖️'},{id:'other',label:'Other',hint:'✨'},
        ]} selected={data.occ || []} setSelected={set('occ')}/>
        <SectionLabel color="rgba(255,232,166,0.7)">HOUSEHOLD INCOME · OPTIONAL</SectionLabel>
        <ChipGroup accent="#CF9843" options={['<$50k','$50–100k','$100–200k','$200k+','Skip']}
          selected={data.income || []} setSelected={set('income')}/>
      </div>
    </LevelShell>
  );
}

// LEVEL 3 — Life Events
function Level3({ data, setData, ...p }) {
  return (
    <LevelShell {...p} levelNum={3} textColor="#003A6E"
      mood="linear-gradient(180deg, #44C8F5 0%, #7DDDF8 100%)"
      title={<>Anything big<br/>in the next</>}
      titleAccent={{ text: '12 months?', color: '#fff' }}
      subtitle="Picking the next chapter. No pressure."
      ctaLabel="Continue" bingoPose="peek" bingoPos="br"
      decor={<Clouds/>}>
      <ChipGroup accent="#FFC800" options={[
        {id:'move',label:'Moving',hint:'📦'},{id:'home',label:'Buying a home',hint:'🏠'},
        {id:'engaged',label:'Getting engaged',hint:'💍'},{id:'married',label:'Getting married',hint:'💒'},
        {id:'baby',label:'Having a baby',hint:'👶'},{id:'school',label:'Back to school',hint:'📖'},
        {id:'job',label:'New job',hint:'💼'},{id:'retire',label:'Retiring',hint:'🌴'},
        {id:'pet',label:'Getting a pet',hint:'🐶'},{id:'none',label:'Nothing wild, thanks',hint:'🧘'},
      ]} selected={data.events || []} setSelected={v => setData({ ...data, events: v })}/>
    </LevelShell>
  );
}

function Clouds() {
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden', pointerEvents: 'none', zIndex: 1 }}>
      {[{l:'5%',t:'22%',s:90,o:0.6},{l:'70%',t:'15%',s:130,o:0.5},{l:'40%',t:'55%',s:80,o:0.35},{l:'80%',t:'75%',s:100,o:0.45}].map((c,i)=>(
        <div key={i} style={{
          position:'absolute', left:c.l, top:c.t, width:c.s, height:c.s*0.55,
          background:'rgba(255,255,255,'+c.o+')', borderRadius:'50%',
          filter:'blur(2px)',
        }}/>
      ))}
    </div>
  );
}

// LEVEL 4 — Financial Intent
function Level4({ data, setData, ...p }) {
  return (
    <LevelShell {...p} levelNum={4} textColor="#fff"
      mood="linear-gradient(180deg, #006FD6 0%, #0052A0 100%)"
      title={<>Considering<br/>any of these in</>}
      titleAccent={{ text: 'the next 90 days?', color: '#CF9843' }}
      subtitle="We won't tell your bank. (But we might tell someone else.)"
      ctaLabel="Continue" ctaBg="#CF9843" ctaColor="#140602"
      bingoPose="wink" bingoPos="br">
      <ChipGroup accent="#FFC800" options={[
        {id:'bank',label:'New bank account',hint:'🏦'},{id:'crypto',label:'Try crypto',hint:'🪙'},
        {id:'invest',label:'Start investing',hint:'📈'},{id:'cc',label:'New credit card',hint:'💳'},
        {id:'refi',label:'Refinance debt',hint:'📄'},{id:'mortgage',label:'Get a mortgage',hint:'🔑'},
        {id:'insurance',label:'Buy insurance',hint:'🛡️'},{id:'hysa',label:'High-yield savings',hint:'💰'},
        {id:'robo',label:'Robo-advisor',hint:'🤖'},{id:'nope',label:'Staying put',hint:'🙅'},
      ]} selected={data.fin || []} setSelected={v=>setData({...data,fin:v})}/>
    </LevelShell>
  );
}

// LEVEL 5 — Big-Ticket
function Level5({ data, setData, ...p }) {
  const car = data.car;
  return (
    <LevelShell {...p} levelNum={5} textColor="#FFC800"
      mood="linear-gradient(180deg, #1A0E06 0%, #140602 100%)"
      title={<>Big purchases</>}
      titleAccent={{ text: 'incoming?', color: '#fff' }}
      subtitle="Dream a little. Data is in dreams."
      ctaLabel="Continue" bingoPose="thumbs" bingoPos="br">
      <SectionLabel color="rgba(255,200,0,0.7)">BUYING A CAR IN 12 MO?</SectionLabel>
      <PillChoice options={['Yes','Maybe','No']} value={data.car} setValue={v=>setData({...data,car:v})} accent="#FFC800"/>
      {(car === 'Yes' || car === 'Maybe') && (<>
        <SectionLabel color="rgba(255,200,0,0.7)">WHICH TYPE</SectionLabel>
        <ChipGroup accent="#FFC800" options={[
          {id:'ev',label:'EV',hint:'⚡'},{id:'truck',label:'Truck',hint:'🛻'},
          {id:'suv',label:'SUV',hint:'🚙'},{id:'sedan',label:'Sedan',hint:'🚗'},
          {id:'hybrid',label:'Hybrid',hint:'🌿'},{id:'luxe',label:'Luxury',hint:'✨'},
        ]} selected={data.carType||[]} setSelected={v=>setData({...data,carType:v})}/>
      </>)}
      <SectionLabel color="rgba(255,200,0,0.7)">OTHER BIG BUYS IN 12 MO</SectionLabel>
      <ChipGroup accent="#FFC800" options={[
        {id:'furn',label:'Furniture',hint:'🛋️'},{id:'reno',label:'Home reno',hint:'🔨'},
        {id:'appl',label:'Major appliance',hint:'🧊'},{id:'phone',label:'New phone',hint:'📱'},
        {id:'laptop',label:'Laptop',hint:'💻'},{id:'wear',label:'Wearable',hint:'⌚'},
      ]} selected={data.bigBuys||[]} setSelected={v=>setData({...data,bigBuys:v})}/>
    </LevelShell>
  );
}

// LEVEL 6 — Travel + Lifestyle
function Level6({ data, setData, ...p }) {
  return (
    <LevelShell {...p} levelNum={6} textColor="#140602"
      mood="radial-gradient(circle at 20% 10%, rgba(68,200,245,0.5), transparent 50%), radial-gradient(circle at 80% 90%, rgba(255,200,0,0.3), transparent 50%), #F9F0CD"
      title={<>Travel &</>}
      titleAccent={{ text: 'you.', color: '#006FD6' }}
      subtitle="Beaches, barbells, bedtimes. All of it."
      ctaLabel="Continue" bingoPose="wave" bingoPos="br">
      <SectionLabel>TRAVEL · NEXT 6 MONTHS</SectionLabel>
      <ChipGroup accent="#44C8F5" options={[
        {id:'dom',label:'Domestic',hint:'🇺🇸'},{id:'intl',label:'International',hint:'🌍'},
        {id:'fest',label:'Festival',hint:'🎪'},{id:'cruise',label:'Cruise',hint:'🚢'},
        {id:'work',label:'Work travel',hint:'💼'},{id:'stay',label:'Staying home',hint:'🛋️'},
      ]} selected={data.travel||[]} setSelected={v=>setData({...data,travel:v})}/>
      <SectionLabel>HEALTH & LIFESTYLE GOALS</SectionLabel>
      <ChipGroup accent="#FFC800" options={[
        {id:'gym',label:'Gym',hint:'🏋️'},{id:'therapy',label:'Therapy',hint:'🧠'},
        {id:'diet',label:'Dietary change',hint:'🥗'},{id:'alc',label:'Cut alcohol',hint:'🫧'},
        {id:'sleep',label:'Better sleep',hint:'😴'},{id:'social',label:'Quit social',hint:'📵'},
        {id:'run',label:'Running',hint:'🏃'},{id:'meditate',label:'Meditation',hint:'🧘'},
      ]} selected={data.life||[]} setSelected={v=>setData({...data,life:v})}/>
    </LevelShell>
  );
}

// LEVEL 7 — Media + Subscriptions
function Level7({ data, setData, ...p }) {
  return (
    <LevelShell {...p} levelNum={7} textColor="#fff"
      mood="linear-gradient(180deg, #003A6E 0%, #002447 100%)"
      title={<>What's on your</>}
      titleAccent={{ text: 'lock screen?', color: '#FFC800' }}
      subtitle="Subs you have, considering, or about to cancel."
      ctaLabel="Continue" ctaBg="#FFC800" bingoPose="peek" bingoPos="br">
      <ChipGroup accent="#FFC800" options={[
        {id:'spotify',label:'Spotify',hint:'🎧'},{id:'apple',label:'Apple Music',hint:'🎵'},
        {id:'netflix',label:'Netflix',hint:'🍿'},{id:'hulu',label:'Hulu',hint:'📺'},
        {id:'ytp',label:'YouTube Premium',hint:'▶️'},{id:'audible',label:'Audible',hint:'🎙️'},
        {id:'strava',label:'Strava',hint:'🏃'},{id:'whoop',label:'Whoop',hint:'⌚'},
        {id:'nyt',label:'NYT',hint:'📰'},{id:'substack',label:'Substack',hint:'✉️'},
        {id:'max',label:'Max',hint:'🎬'},{id:'disney',label:'Disney+',hint:'🏰'},
      ]} selected={data.media||[]} setSelected={v=>setData({...data,media:v})}/>
    </LevelShell>
  );
}

// LEVEL 8 — Brand Affinity
function Level8({ data, setData, ...p }) {
  return (
    <LevelShell {...p} levelNum={8} textColor="#003A6E"
      mood="linear-gradient(180deg, #44C8F5 0%, #78D8F7 100%)"
      title={<>Who else<br/>lives in</>}
      titleAccent={{ text: 'your fridge?', color: '#fff' }}
      subtitle="Tap all that apply. We won't judge. Much."
      ctaLabel="Continue" bingoPose="wink" bingoPos="br"
      decor={<Bubbles/>}>
      <ChipGroup accent="#FFC800" options={[
        {id:'ld',label:'Liquid Death',hint:'💀'},{id:'cel',label:'Celsius',hint:'⚡'},
        {id:'prime',label:'Prime',hint:'🧢'},{id:'oli',label:'Olipop',hint:'🍒'},
        {id:'poppi',label:'Poppi',hint:'🌈'},{id:'rb',label:'Red Bull',hint:'🐂'},
        {id:'topo',label:'Topo Chico',hint:'🫧'},{id:'ab',label:'Athletic Brewing',hint:'🍺'},
        {id:'lc',label:'La Croix',hint:'🌀'},{id:'kom',label:'Kombucha',hint:'🍄'},
        {id:'water',label:'Water (boring)',hint:'💧'},{id:'nob',label:'None of your business',hint:'🤫'},
      ]} selected={data.brands||[]} setSelected={v=>setData({...data,brands:v})}/>
    </LevelShell>
  );
}

function Bubbles() {
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden', pointerEvents: 'none', zIndex: 1 }}>
      {[{l:'8%',t:'30%',s:40,o:0.3},{l:'82%',t:'22%',s:60,o:0.25},{l:'74%',t:'55%',s:28,o:0.4},{l:'6%',t:'72%',s:80,o:0.2},{l:'88%',t:'82%',s:50,o:0.25}].map((b,i)=>(
        <div key={i} style={{
          position:'absolute', left:b.l, top:b.t, width:b.s, height:b.s,
          borderRadius:'50%', background:'rgba(255,255,255,0.6)', opacity:b.o,
          boxShadow:'inset -4px -4px 8px rgba(0,0,0,0.08), inset 4px 4px 8px rgba(255,255,255,0.5)',
        }}/>
      ))}
    </div>
  );
}

// LEVEL 9 — Psychographic
function Level9({ data, setData, ...p }) {
  return (
    <LevelShell {...p} levelNum={9} textColor="#fff"
      mood="linear-gradient(180deg, #006FD6 0%, #003A6E 100%)"
      title={<>Which of these</>}
      titleAccent={{ text: 'is you?', color: '#44C8F5' }}
      subtitle="Pick as many as fit. Be honest. Or don't."
      ctaLabel="Continue" bingoPose="thumbs" bingoPos="br">
      <ChipGroup accent="#44C8F5" options={[
        {id:'creator',label:'Creator',hint:'🎬'},{id:'well',label:'Wellness-focused',hint:'🌿'},
        {id:'sust',label:'Sustainability-driven',hint:'♻️'},{id:'adv',label:'Adventure-seeker',hint:'🏔️'},
        {id:'comm',label:'Community-builder',hint:'🫶'},{id:'trad',label:'Traditional',hint:'🏛️'},
        {id:'mini',label:'Minimalist',hint:'◻️'},{id:'maxi',label:'Maximalist',hint:'✨'},
        {id:'early',label:'Early adopter',hint:'🚀'},{id:'chill',label:'Professional chiller',hint:'🛋️'},
      ]} selected={data.psy||[]} setSelected={v=>setData({...data,psy:v})}/>
    </LevelShell>
  );
}

// LEVEL 10 — Sponsor-reserved
function Level10({ data, setData, ...p }) {
  return (
    <LevelShell {...p} levelNum={10} textColor="#fff"
      mood="linear-gradient(180deg, #006FD6 0%, #0052A0 100%)"
      title={<>A word from</>}
      titleAccent={{ text: 'our sponsor.', color: '#FFC800' }}
      subtitle="Last stretch. Answer these and the coin is yours to chase."
      ctaLabel="Finish → Bank Entries" ctaBg="#FFC800" bingoPose="wave" bingoPos="br">
      <div style={{
        padding: '10px 12px', marginBottom: 10,
        background: 'rgba(255,255,255,0.08)',
        border: '1px dashed rgba(255,232,166,0.5)',
        borderRadius: 10,
        fontFamily: 'JetBrains Mono, monospace', fontSize: 10, letterSpacing: 1.5,
        color: '#FFE8A6',
      }}>
        SPONSORED BY <b>[BRAND]</b> · RESERVED SLOT
      </div>

      <SectionLabel color="rgba(255,232,166,0.7)">[SPONSOR QUESTION 1]</SectionLabel>
      <div style={{
        padding: 14, background: 'rgba(255,255,255,0.05)',
        border: '2px dashed rgba(255,255,255,0.2)', borderRadius: 12, marginBottom: 12,
      }}>
        <div style={{ fontFamily: 'Anton', fontSize: 18, letterSpacing: 0.5, marginBottom: 10 }}>
          Which of these have you tried?
        </div>
        <ChipGroup accent="#FFC800" options={[
          {id:'a',label:'Option A',hint:'①'},{id:'b',label:'Option B',hint:'②'},
          {id:'c',label:'Option C',hint:'③'},{id:'d',label:'Option D',hint:'④'},
        ]} selected={data.sp1||[]} setSelected={v=>setData({...data,sp1:v})}/>
      </div>

      <SectionLabel color="rgba(255,232,166,0.7)">[SPONSOR QUESTION 2]</SectionLabel>
      <div style={{
        padding: 14, background: 'rgba(255,255,255,0.05)',
        border: '2px dashed rgba(255,255,255,0.2)', borderRadius: 12,
      }}>
        <div style={{ fontFamily: 'Anton', fontSize: 18, letterSpacing: 0.5, marginBottom: 10 }}>
          How likely are you to recommend?
        </div>
        <PillChoice options={['1','2','3','4','5']} value={data.sp2} setValue={v=>setData({...data,sp2:v})} accent="#FFC800"/>
      </div>
    </LevelShell>
  );
}

window.Level1 = Level1; window.Level2 = Level2; window.Level3 = Level3;
window.Level4 = Level4; window.Level5 = Level5; window.Level6 = Level6;
window.Level7 = Level7; window.Level8 = Level8; window.Level9 = Level9;
window.Level10 = Level10;
