// instagram.jsx — Instagram tutorial with 5 tabs + posts/stories/reels

const IG_BG = '#fafafa';
const IG_BORDER = '#dbdbdb';
const IG_GRAY = '#737373';
const IG_INK = '#262626';

const IMG = 'project/images';
const PHOTOS = {
  mom:    `${IMG}/mom-profile.jpg`,
  saahil: `${IMG}/saahil-profile.jpg`,
  pooja:  `${IMG}/pooja-profile.jpg`,
  inder:  `${IMG}/inder-profile.jpg`,
  osher:  `${IMG}/osher-profile.jpg`,
  ucsf:   `${IMG}/ucsf-profile.svg`,
  massages: `${IMG}/post-massages.jpg`,
  // filler photos for grids / explore
  fillers: [1,2,3,4,5,6,7,8,9,10,11,12].map(i => `${IMG}/photo-${i}.jpg`),
};

// Every uploaded photo, shuffled once per page load. Sliced into the
// explore grid (9 tiles) + profile grid (6 tiles) so every photo
// appears at least once across the two — 13 unique → 15 slots.
function shuffle(arr) {
  const a = [...arr];
  for (let i = a.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [a[i], a[j]] = [a[j], a[i]];
  }
  return a;
}
const ALL_PHOTOS = shuffle([PHOTOS.massages, ...PHOTOS.fillers]);
const EXPLORE_PHOTOS = ALL_PHOTOS.slice(0, 9);
// Last 4 unique photos + 2 borrowed from the explore half (shuffled so they vary).
// Each grid stays dupe-free; a photo can appear in both grids.
const PROFILE_PHOTOS = [...ALL_PHOTOS.slice(9), ...shuffle(ALL_PHOTOS.slice(0, 9)).slice(0, 2)];

// ─── Inline icons (outline + filled) ───
const igIcon = {
  home: (filled) => filled
    ? <svg width="26" height="26" viewBox="0 0 24 24" fill="#000"><path d="M22 9.7L12 2 2 9.7v12h7v-7h6v7h7z"/></svg>
    : <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="2" strokeLinejoin="round"><path d="M3 10.5L12 3l9 7.5V21h-6v-6.5h-6V21H3z"/></svg>,
  reels: (filled) => filled
    ? <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="2"><rect x="3" y="3" width="18" height="18" rx="3" fill="#000"/><path d="M10 9l5 3-5 3z" fill="#fff"/></svg>
    : <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="1.8"><rect x="3" y="3" width="18" height="18" rx="3"/><path d="M3 9h6m6 0h6M9 3l-3 6m12-6l-3 6" /><path d="M10.5 9.5v5l4-2.5z" fill="#000" stroke="none"/></svg>,
  msg: (filled) => filled
    ? <svg width="26" height="26" viewBox="0 0 24 24" fill="#000"><path d="M2 2l20 8-9 3-3 9z"/></svg>
    : <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="1.8" strokeLinejoin="round"><path d="M3 3l18 7.5-8 2.5-2.5 8z"/></svg>,
  search: (filled) => filled
    ? <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="3"><circle cx="10.5" cy="10.5" r="6.5"/><path d="M16 16l5 5" strokeLinecap="round"/></svg>
    : <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="1.8"><circle cx="10.5" cy="10.5" r="6.5"/><path d="M16 16l5 5" strokeLinecap="round"/></svg>,
};

// ─── Bottom tab bar ───
function IGTabBar({ tab, setTab, dark = false }) {
  const items = [
    { id: 'home', icon: igIcon.home },
    { id: 'reels', icon: igIcon.reels },
    { id: 'msg', icon: igIcon.msg },
    { id: 'search', icon: igIcon.search },
  ];
  return (
    <div style={{
      position: 'absolute', bottom: 0, left: 0, right: 0, zIndex: 40,
      background: dark ? '#000' : '#fff',
      borderTop: dark ? '1px solid #222' : `1px solid ${IG_BORDER}`,
      display: 'flex', alignItems: 'center', justifyContent: 'space-around',
      padding: '10px 0 28px',
    }}>
      {items.map(it => (
        <button key={it.id} onClick={() => setTab(it.id)}
          style={{ background: 'none', border: 'none', padding: 6, cursor: 'pointer',
            filter: dark ? 'invert(1)' : 'none' }}>
          {it.icon(tab === it.id)}
        </button>
      ))}
      <button onClick={() => setTab('profile')}
        style={{ background: 'none', border: 'none', padding: 4, cursor: 'pointer' }}>
        <div style={{
          width: 26, height: 26, borderRadius: '50%',
          backgroundImage: `url(${PHOTOS.mom})`,
          backgroundSize: 'cover', backgroundPosition: 'center',
          border: tab === 'profile' ? '2px solid #000' : 'none',
        }}/>
      </button>
    </div>
  );
}

// ─── Story ring ───
function StoryRing({ name, you, viewed, src }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4, minWidth: 70, position: 'relative' }}>
      <div style={{
        width: 64, height: 64, borderRadius: '50%',
        padding: viewed ? 1.5 : 2.5,
        background: viewed ? '#dbdbdb'
          : 'linear-gradient(45deg,#feda75 0%,#fa7e1e 30%,#d62976 60%,#962fbf 80%,#4f5bd5 100%)',
      }}>
        <div style={{
          width: '100%', height: '100%', borderRadius: '50%', border: '2px solid #fff',
          backgroundImage: src ? `url(${src})` : `linear-gradient(135deg, hsl(${name.charCodeAt(0)*7 % 360}, 60%, 70%), hsl(${name.charCodeAt(1)*9 % 360}, 65%, 55%))`,
          backgroundSize: 'cover', backgroundPosition: 'center',
        }}/>
      </div>
      {you && (
        <div style={{
          position: 'absolute', right: 8, bottom: 22,
          width: 18, height: 18, borderRadius: '50%', background: '#0095f6',
          color: '#fff', fontSize: 16, lineHeight: '14px', fontWeight: 300,
          display: 'flex', alignItems: 'center', justifyContent: 'center', border: '2px solid #fff',
        }}>+</div>
      )}
      <div style={{ fontSize: 11, color: IG_INK, maxWidth: 64, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
        {you ? 'Your story' : name}
      </div>
    </div>
  );
}

// ─── Home Feed ───
function IGHome() {
  return (
    <div style={{ height: '100%', overflow: 'auto', background: '#fff', paddingTop: 54 }}>
      {/* header */}
      <div style={{
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
        padding: '8px 14px', borderBottom: `0.5px solid ${IG_BORDER}`,
      }}>
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="2"><path d="M12 5v14M5 12h14" strokeLinecap="round"/></svg>
        <div style={{ fontFamily: 'Billabong, "Snell Roundhand", cursive', fontSize: 28, fontWeight: 400, fontStyle: 'italic' }}>Instagram</div>
        <div style={{ position: 'relative' }}>
          <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="1.8"><path d="M12 21s-7-5.5-7-11a4 4 0 017-2.5A4 4 0 0119 10c0 5.5-7 11-7 11z"/></svg>
          <div style={{ position: 'absolute', top: -2, right: -2, width: 8, height: 8, borderRadius: '50%', background: '#ff3040' }}/>
        </div>
      </div>
      {/* stories rail */}
      <div style={{ display: 'flex', gap: 2, padding: '12px 8px', overflowX: 'auto', borderBottom: `0.5px solid ${IG_BORDER}` }}>
        <StoryRing name="You" you src={PHOTOS.mom}/>
        <StoryRing name="pooja.aswani" src={PHOTOS.pooja}/>
        <StoryRing name="inder.og" src={PHOTOS.inder}/>
        <StoryRing name="osher_uc" src={PHOTOS.osher}/>
        <StoryRing name="saahil" viewed src={PHOTOS.saahil}/>
      </div>
      {/* one post */}
      <div style={{ padding: '10px 14px', display: 'flex', alignItems: 'center', gap: 10 }}>
        <div style={{ width: 32, height: 32, borderRadius: '50%', backgroundImage: `url(${PHOTOS.saahil})`, backgroundSize: 'cover', backgroundPosition: 'center' }}/>
        <div style={{ fontSize: 13, fontWeight: 600, color: IG_INK }}>saahilmishra20</div>
        <div style={{ flex: 1 }}/>
        <div style={{ fontSize: 18, color: IG_INK, letterSpacing: 2 }}>···</div>
      </div>
      <div style={{
        height: 320, backgroundImage: `url(${PHOTOS.massages})`,
        backgroundSize: 'cover', backgroundPosition: 'center',
      }}/>
      {/* actions */}
      <div style={{ display: 'flex', gap: 14, padding: '10px 14px', alignItems: 'center' }}>
        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="1.8"><path d="M12 21s-7-5.5-7-11a4 4 0 017-2.5A4 4 0 0119 10c0 5.5-7 11-7 11z"/></svg>
        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="1.8"><path d="M21 12a8 8 0 11-3-6.2L21 4l-1 4"/></svg>
        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="1.8"><path d="M3 21l18-9L3 3v7l13 2-13 2z"/></svg>
        <div style={{ flex: 1 }}/>
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="1.8"><path d="M6 3v18l6-4 6 4V3z"/></svg>
      </div>
      <div style={{ padding: '0 14px', fontSize: 13, color: IG_INK }}>
        <div style={{ fontWeight: 600 }}>1,247 likes</div>
        <div style={{ marginTop: 4 }}><b>saahilmishra20</b> just got massages with mom!</div>
        <div style={{ color: IG_GRAY, marginTop: 4, fontSize: 11 }}>2 HOURS AGO</div>
      </div>
    </div>
  );
}

// ─── Reels ───
function IGReels() {
  return (
    <div style={{ height: '100%', background: '#000', position: 'relative', overflow: 'hidden' }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(180deg,#7aa3c8 0%,#a8b8a8 60%,#5a6a4a 100%)',
      }}/>
      {/* top header */}
      <div style={{
        position: 'absolute', top: 54, left: 0, right: 0, zIndex: 10,
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
        padding: '8px 16px', color: '#fff',
      }}>
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="2"><path d="M12 5v14M5 12h14" strokeLinecap="round"/></svg>
        <div style={{ display: 'flex', gap: 18, fontWeight: 700, fontSize: 18 }}>
          <span>Reels</span>
          <span style={{ opacity: 0.7, fontWeight: 500 }}>Friends</span>
        </div>
        <div style={{ width: 22 }}/>
      </div>
      {/* on-screen joke text */}
      <div style={{
        position: 'absolute', left: 20, right: 20, top: '28%',
        color: '#fff', textAlign: 'center',
        fontFamily: '"Geist", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif',
        fontWeight: 800, textTransform: 'uppercase',
        fontSize: 22, lineHeight: 1.2, letterSpacing: 0.4,
        textShadow: '0 2px 12px rgba(0,0,0,0.65), 0 0 3px rgba(0,0,0,0.8)',
      }}>
        <div>Studies show crime rates are the lowest on Mother's Day.</div>
        <div style={{ height: 32 }}/>
        <div style={{ fontSize: 19 }}>I think that says a lot about how many moms are out there committing crimes but can't today to have brunch with their kids.</div>
      </div>
      {/* caption */}
      <div style={{
        position: 'absolute', left: 16, right: 60, bottom: 100, color: '#fff',
        fontFamily: '-apple-system', fontSize: 13, lineHeight: 1.4,
      }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 8 }}>
          <div style={{
            width: 32, height: 32, borderRadius: '50%', padding: 1.5,
            background: 'linear-gradient(45deg,#feda75 0%,#fa7e1e 30%,#d62976 60%,#962fbf 80%,#4f5bd5 100%)',
            flexShrink: 0,
          }}>
            <div style={{
              width: '100%', height: '100%', borderRadius: '50%', border: '1.5px solid #000',
              background: 'linear-gradient(135deg,#ffb088,#d4665a)',
            }}/>
          </div>
          <span style={{ fontWeight: 600, fontSize: 14 }}>tracybordewyk</span>
          <svg width="14" height="14" viewBox="0 0 24 24"><circle cx="12" cy="12" r="11" fill="#4cb5f5"/><path d="M7 12l3.5 3.5L17 9" stroke="#fff" strokeWidth="2.8" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
          <span style={{ border: '1px solid #fff', padding: '3px 12px', borderRadius: 6, fontSize: 12, fontWeight: 600, flexShrink: 0 }}>Follow</span>
        </div>
        <div style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
          happy mother's day to all the law-abiding moms out there 💐
        </div>
      </div>
      {/* right rail */}
      <div style={{ position: 'absolute', right: 12, bottom: 110, display: 'flex', flexDirection: 'column', gap: 18, color: '#fff', alignItems: 'center', fontSize: 11 }}>
        {[['♡', '115K'], ['💬', '923'], ['↻', '3.1K'], ['↗', '134K']].map(([i, n]) => (
          <div key={n} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 2 }}>
            <div style={{ fontSize: 24, lineHeight: 1 }}>{i}</div>
            <div>{n}</div>
          </div>
        ))}
      </div>
    </div>
  );
}

// ─── Messages ───
function IGMessages() {
  const dms = [
    { name: 'Pooja Aswani', msg: 'Sent 2h ago', src: PHOTOS.pooja },
    { name: 'Inder OG', msg: 'Sent 5h ago', src: PHOTOS.inder },
    { name: 'UCSF', msg: 'Seen 1d ago', src: PHOTOS.ucsf },
    { name: 'Osher Center', msg: 'You\'re now friends. Say hi!', src: PHOTOS.osher },
    { name: 'Saahil ♥', msg: 'love you mom!', src: PHOTOS.saahil },
  ];
  return (
    <div style={{ height: '100%', background: '#fff', overflow: 'auto', paddingTop: 54 }}>
      <div style={{ padding: '6px 14px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <div style={{ width: 24 }}/>
        <div style={{ fontWeight: 700, fontSize: 16, color: IG_INK }}>lebron_of_moms ▾</div>
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="1.8"><path d="M16 4l4 4-12 12H4v-4z"/></svg>
      </div>
      <div style={{ padding: '4px 14px' }}>
        <div style={{ background: '#efefef', borderRadius: 10, padding: '8px 12px', display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, color: IG_GRAY }}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#737373" strokeWidth="2"><circle cx="11" cy="11" r="7"/><path d="M16 16l5 5"/></svg>
          Search or ask Meta AI
        </div>
      </div>
      {/* notes / friend stories */}
      <div style={{ display: 'flex', gap: 10, padding: '12px 14px', overflowX: 'auto' }}>
        {[
          { n: 'You', src: PHOTOS.mom },
          { n: 'Pooja', src: PHOTOS.pooja },
          { n: 'Inder', src: PHOTOS.inder },
          { n: 'Map', src: null },
        ].map(({ n, src }, i) => (
          <div key={n} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', minWidth: 64, gap: 4 }}>
            <div style={{ position: 'relative' }}>
              <div style={{
                width: 56, height: 56, borderRadius: '50%',
                backgroundImage: src ? `url(${src})` : 'linear-gradient(135deg,#7aa3c8,#5a6a4a)',
                backgroundSize: 'cover', backgroundPosition: 'center',
              }}/>
            </div>
            <div style={{ fontSize: 11, color: IG_INK }}>{n}</div>
          </div>
        ))}
      </div>
      <div style={{ padding: '10px 14px', display: 'flex', justifyContent: 'space-between' }}>
        <div style={{ fontWeight: 700, color: IG_INK, fontSize: 15 }}>Messages</div>
        <div style={{ fontSize: 13, color: IG_GRAY }}>Requests</div>
      </div>
      {dms.map((d, i) => (
        <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '8px 14px' }}>
          <div style={{
            width: 44, height: 44, borderRadius: '50%',
            backgroundImage: d.src ? `url(${d.src})` : `linear-gradient(135deg, hsl(${i*55},60%,70%), hsl(${i*55+30},60%,50%))`,
            backgroundSize: 'cover', backgroundPosition: 'center',
          }}/>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 13, fontWeight: 600, color: IG_INK }}>{d.name}</div>
            <div style={{ fontSize: 12, color: IG_GRAY }}>{d.msg}</div>
          </div>
          <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#737373" strokeWidth="1.5"><rect x="3" y="6" width="14" height="12" rx="2"/><path d="M17 10l4-2v8l-4-2z"/></svg>
        </div>
      ))}
    </div>
  );
}

// ─── Search / Explore grid ───
function IGSearch() {
  const labels = ['904K','148K','1.9M','224K','720K','511K','252K','789K','1.2M'];
  const tiles = labels.map((l, i) => ({ src: EXPLORE_PHOTOS[i], l }));
  return (
    <div style={{ height: '100%', background: '#fff', overflow: 'auto', paddingTop: 54 }}>
      <div style={{ padding: '6px 14px' }}>
        <div style={{ background: '#efefef', borderRadius: 10, padding: '10px 12px', display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, color: IG_GRAY }}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#737373" strokeWidth="2"><circle cx="11" cy="11" r="7"/><path d="M16 16l5 5"/></svg>
          Search with Meta AI
        </div>
      </div>
      <div style={{ display: 'flex', gap: 6, padding: '8px 14px', overflowX: 'auto' }}>
        {['For you', '+', 'Eyes', 'Healing', 'Yoga'].map((t, i) => (
          <div key={t} style={{ padding: '6px 14px', borderRadius: 999, background: i === 0 ? '#000' : '#efefef', color: i === 0 ? '#fff' : IG_INK, fontSize: 12, whiteSpace: 'nowrap' }}>{t}</div>
        ))}
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 2, padding: '0 2px' }}>
        {tiles.map((t, i) => (
          <div key={i} style={{
            aspectRatio: '1/1.4',
            backgroundImage: `url(${t.src})`, backgroundSize: 'cover', backgroundPosition: 'center',
            position: 'relative',
          }}>
            <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(180deg,transparent 60%,rgba(0,0,0,0.4))' }}/>
            <div style={{ position: 'absolute', bottom: 6, left: 8, color: '#fff', fontSize: 11, opacity: 0.95, textShadow: '0 1px 2px rgba(0,0,0,0.4)' }}>▶ {t.l}</div>
          </div>
        ))}
      </div>
    </div>
  );
}

// ─── Profile ───
function IGProfile({ momName }) {
  return (
    <div style={{ height: '100%', background: '#fff', overflow: 'auto', paddingTop: 54 }}>
      <div style={{ padding: '6px 14px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="2"><path d="M12 5v14M5 12h14" strokeLinecap="round"/></svg>
        <div style={{ fontWeight: 700, fontSize: 15, color: IG_INK }}>🔒 lebron_of_moms ▾</div>
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="2"><path d="M4 6h16M4 12h16M4 18h16" strokeLinecap="round"/></svg>
      </div>
      <div style={{ display: 'flex', alignItems: 'center', gap: 18, padding: '14px 18px' }}>
        <div style={{ position: 'relative' }}>
          <div style={{ width: 86, height: 86, borderRadius: '50%', backgroundImage: `url(${PHOTOS.mom})`, backgroundSize: 'cover', backgroundPosition: 'center' }}/>
          <div style={{ position: 'absolute', bottom: 0, right: 0, width: 22, height: 22, borderRadius: '50%', background: '#0095f6', color: '#fff', display: 'flex', alignItems: 'center', justifyContent: 'center', fontWeight: 300, border: '2px solid #fff' }}>+</div>
        </div>
        <div style={{ display: 'flex', gap: 22, flex: 1, justifyContent: 'space-around' }}>
          {[['12', 'posts'], ['1,279', 'followers'], ['1,326', 'following']].map(([n, l]) => (
            <div key={l} style={{ textAlign: 'center' }}>
              <div style={{ fontWeight: 700, fontSize: 17, color: IG_INK }}>{n}</div>
              <div style={{ fontSize: 12, color: IG_INK }}>{l}</div>
            </div>
          ))}
        </div>
      </div>
      <div style={{ padding: '0 18px' }}>
        <div style={{ fontWeight: 600, color: IG_INK, fontSize: 14 }}>{momName}</div>
        <div style={{ color: IG_GRAY, fontSize: 13, marginTop: 2 }}>SF · radiation oncologist · Osher Center · ♥</div>
      </div>
      <div style={{ display: 'flex', gap: 6, padding: '14px 18px' }}>
        <div style={{ flex: 1, padding: '6px 0', borderRadius: 8, background: '#efefef', textAlign: 'center', fontSize: 13, fontWeight: 600 }}>Edit profile</div>
        <div style={{ flex: 1, padding: '6px 0', borderRadius: 8, background: '#efefef', textAlign: 'center', fontSize: 13, fontWeight: 600 }}>Share profile</div>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 2, marginTop: 4 }}>
        {PROFILE_PHOTOS.map((src, i) => (
          <div key={i} style={{ aspectRatio: '1/1', backgroundImage: `url(${src})`, backgroundSize: 'cover', backgroundPosition: 'center' }}/>
        ))}
      </div>
    </div>
  );
}

// ─── Concept card: posts vs stories vs reels ───
function ContentTypesCard() {
  const types = [
    { name: 'Posts', desc: 'Photos or videos that live on your profile forever. People can like and comment.', accent: '#d4665a', icon: '◧' },
    { name: 'Stories', desc: 'Photos or videos that disappear after 24 hours. Casual — like a daily diary.', accent: '#7d8c6a', icon: '○' },
    { name: 'Reels', desc: 'Short vertical videos meant to entertain — like TikToks. Anyone can see them.', accent: '#1f1a14', icon: '▶' },
  ];
  return (
    <div style={{
      width: 380, background: 'var(--paper)', border: '1px solid var(--line)', borderRadius: 18,
      padding: 26, display: 'flex', flexDirection: 'column', gap: 18,
    }}>
      <div style={{ fontFamily: 'var(--mono)', fontSize: 10.5, letterSpacing: '0.18em', textTransform: 'uppercase', color: 'var(--ink-3)' }}>Cheat sheet</div>
      <div style={{ fontFamily: 'var(--serif)', fontSize: 28, lineHeight: 1.1, letterSpacing: '-0.01em' }}>
        Posts <em style={{ color: 'var(--coral)', fontStyle: 'italic' }}>vs</em> Stories <em style={{ color: 'var(--coral)', fontStyle: 'italic' }}>vs</em> Reels
      </div>
      {types.map(t => (
        <div key={t.name} style={{ display: 'grid', gridTemplateColumns: '36px 1fr', gap: 14, paddingTop: 12, borderTop: '1px solid var(--line)' }}>
          <div style={{ width: 36, height: 36, borderRadius: 10, background: t.accent, color: '#fff', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 18 }}>{t.icon}</div>
          <div>
            <div style={{ fontFamily: 'var(--serif)', fontSize: 20 }}>{t.name}</div>
            <div style={{ fontSize: 13, lineHeight: 1.5, color: 'var(--ink-2)', marginTop: 4 }}>{t.desc}</div>
          </div>
        </div>
      ))}
    </div>
  );
}

// ─── Main ───
function InstagramLesson() {
  const [step, setStep] = React.useState(0);
  const [tab, setTab] = React.useState('home');

  const steps = [
    { title: 'The five tabs', desc: 'Instagram has five main pages, all reachable from the bar at the bottom. Tap any one to switch.', tab: 'home' },
    { title: 'Home — your feed', desc: 'Posts and stories from people you follow. Stories sit in a row up top; posts scroll below.', tab: 'home' },
    { title: 'Reels — short videos', desc: 'Bite-sized vertical videos. Swipe up for the next one. Anyone\'s reel can show up here.', tab: 'reels' },
    { title: 'Messages — DMs', desc: 'Texts with friends, plus their "notes" up top. Tap the camera icon next to a name to send a photo.', tab: 'msg' },
    { title: 'Search — the explore page', desc: 'A grid of posts and reels Instagram thinks you\'ll like. Search a username at the top to find someone.', tab: 'search' },
    { title: 'Profile — your space', desc: 'Your posts, follower count, and bio. Tap Edit profile to change your name, photo, or bio.', tab: 'profile' },
    { title: 'Posts vs Stories vs Reels', desc: 'These are the three things you can post. They live in different places and last for different times — see the card on the right.', tab: 'concept' },
  ];

  React.useEffect(() => { if (steps[step].tab !== 'concept') setTab(steps[step].tab); }, [step]);

  const screen =
    tab === 'home' ? <IGHome/> :
    tab === 'reels' ? <IGReels/> :
    tab === 'msg' ? <IGMessages/> :
    tab === 'search' ? <IGSearch/> :
    <IGProfile momName="Mom"/>;

  const isConcept = steps[step].tab === 'concept';

  return (
    <div className="page page-fade lesson-page">
      <LessonHead num="Lesson I" title={<>Instagram, <em>without the noise.</em></>} sub="Five tabs, three kinds of posts. Once you know those, the whole app makes sense." eyebrow="Approx · 4 min" time="iPhone · iOS 26"/>
      <div className="lesson">
        <StepsPanel steps={steps} current={step} setCurrent={setStep}/>
        <div className="mock">
          {isConcept ? (
            <ContentTypesCard/>
          ) : (
            <div className="mock-scaler" style={{ width: 420*0.81, height: 880*0.81 }}>
              <div style={{ width: 420, height: 880, transform: 'scale(0.81)', transformOrigin: 'top left' }}>
              <IOSDevice width={420} height={880} dark={tab === 'reels'}>
                <div style={{ position: 'relative', height: '100%' }}>
                  {screen}
                  <IGTabBar tab={tab} setTab={setTab} dark={tab === 'reels'}/>
                </div>
              </IOSDevice>
              </div>
            </div>
          )}
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { InstagramLesson });
