const bpFont = { mono: '500 10.5px var(--font-mono)', body: (s, w = 400) => `${w} ${s}px/1.45 var(--font-body)`, head: (s) => `600 ${s}px/1.3 var(--font-display)` };

function BpStage({ children }) {
  return <div style={{ height: '100%', minHeight: 0, position: 'relative', borderRadius: 14, border: '1px solid var(--yk-lavender)', background: 'var(--yk-light)', backgroundImage: 'radial-gradient(#D7DCEF 1px, transparent 1px)', backgroundSize: '14px 14px', overflow: 'hidden', padding: 16, boxSizing: 'border-box', display: 'flex', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'center', gap: 14 }}>{children}</div>;
}
function BpWindow({ title, children, style }) {
  return (
    <div style={{ background: '#fff', border: '1px solid var(--border-default)', borderRadius: 10, boxShadow: 'var(--shadow-md)', overflow: 'hidden', display: 'flex', flexDirection: 'column', minWidth: 0, ...style }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '8px 12px', borderBottom: '1px solid var(--border-default)', background: '#FAFBFF' }}>
        {[0, 1, 2].map((i) => <span key={i} style={{ width: 8, height: 8, borderRadius: 8, background: '#E2E8F0' }} />)}
        <span style={{ marginLeft: 8, font: bpFont.mono, color: 'var(--yk-charcoal)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{title}</span>
      </div>
      {children}
    </div>
  );
}
function BpPhone({ children, dark, style }) {
  return (
    <div style={{ width: 196, flexShrink: 0, height: 380, borderRadius: 30, padding: 7, background: '#0F0D2E', boxShadow: 'var(--shadow-lg)', boxSizing: 'border-box', ...style }}>
      <div style={{ height: '100%', borderRadius: 24, overflow: 'hidden', background: dark ? 'var(--yk-indigo)' : '#fff', display: 'flex', flexDirection: 'column', position: 'relative' }}>
        <span style={{ position: 'absolute', top: 7, left: '50%', transform: 'translateX(-50%)', width: 56, height: 14, borderRadius: 10, background: '#0F0D2E', zIndex: 2 }} />
        {children}
      </div>
    </div>
  );
}
function useTick(ms, n, live) {
  const [k, setK] = React.useState(0);
  React.useEffect(() => { if (!live) return; setK(0); const t = setInterval(() => setK((x) => Math.min(x + 1, n)), ms); return () => clearInterval(t); }, [live]);
  return live ? k : n;
}
function Bubble({ me, children, show = true, tone }) {
  return <div style={{ alignSelf: me ? 'flex-end' : 'flex-start', maxWidth: '82%', padding: '7px 10px', borderRadius: me ? '12px 12px 3px 12px' : '12px 12px 12px 3px', background: tone || (me ? 'var(--yk-violet)' : '#fff'), color: me ? '#fff' : 'var(--yk-indigo)', border: me ? 0 : '1px solid var(--yk-lavender)', font: bpFont.body(11.5), opacity: show ? 1 : 0, transform: show ? 'none' : 'translateY(6px)', transition: 'all .4s cubic-bezier(.22,1,.36,1)' }}>{children}</div>;
}

/* 1 — Inbound voice qualification */
function VoiceScreen({ live, wide }) {
  const { Icon } = DS;
  const k = useTick(1400, 5, live);
  const lines = [[0, 'Hi, this is Yantrrk Assist for Mehta Interiors. How can I help?'], [1, 'I need a quote for a 3BHK in Pune, starting next month.'], [0, 'Got it. Budget range? I can book a site visit with Priya.'], [1, 'Around 12 lakh. Thursday works.']];
  return (
    <BpStage>
      {wide && <BpPhone dark>
        <div style={{ padding: '34px 14px 14px', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 8, height: '100%', boxSizing: 'border-box', color: '#fff' }}>
          <span style={{ font: bpFont.mono, color: '#A5F3FC' }}>INBOUND · 00:{String(14 + k * 9).padStart(2, '0')}</span>
          <div style={{ font: bpFont.head(14) }}>Voice Agent</div>
          <div style={{ width: 74, height: 74, borderRadius: 74, marginTop: 10, display: 'grid', placeItems: 'center', background: 'linear-gradient(135deg,#7C3AED,#2563EB 50%,#06B6D4)', boxShadow: '0 0 0 8px rgba(124,58,237,.18), 0 0 0 16px rgba(6,182,212,.08)' }}><Icon name="audio-lines" size={30} color="#fff" /></div>
          <span style={{ font: bpFont.body(11), color: '#C7C4F2', marginTop: 6 }}>{k >= 4 ? 'Booking slot…' : 'Listening'}</span>
          <div style={{ marginTop: 6 }}><Waveform bars={22} height={30} /></div>
          <div style={{ marginTop: 'auto', display: 'flex', gap: 14 }}>
            <span style={{ width: 38, height: 38, borderRadius: 38, display: 'grid', placeItems: 'center', background: 'rgba(255,255,255,.12)' }}><Icon name="mic-off" size={16} color="#fff" /></span>
            <span style={{ width: 38, height: 38, borderRadius: 38, display: 'grid', placeItems: 'center', background: '#E11D48' }}><Icon name="phone-off" size={16} color="#fff" /></span>
          </div>
        </div>
      </BpPhone>}
      <div style={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 10, maxWidth: 300 }}>
        <div style={{ background: '#fff', border: '1px solid var(--yk-lavender)', borderRadius: 12, padding: 12, display: 'flex', flexDirection: 'column', gap: 7 }}>
          <span style={{ font: bpFont.mono, color: 'var(--yk-violet)' }}>LIVE TRANSCRIPT</span>
          {lines.map(([me, t], i) => <Bubble key={i} me={!me} show={k > i} tone={me ? '#F1F5FF' : undefined}>{t}</Bubble>)}
        </div>
        <div style={{ background: '#fff', border: '1px solid ' + (k >= 5 ? 'rgba(124,58,237,.45)' : 'var(--yk-lavender)'), borderRadius: 12, padding: 12, display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '4px 10px', transition: 'border-color .4s' }}>
          <span style={{ gridRow: 'span 2', width: 32, height: 32, borderRadius: 8, display: 'grid', placeItems: 'center', background: k >= 5 ? 'var(--yk-violet)' : 'var(--yk-lavender)', color: k >= 5 ? '#fff' : 'var(--yk-violet)', transition: 'all .4s' }}><Icon name="calendar-check" size={16} /></span>
          <span style={{ font: bpFont.head(12.5), color: 'var(--yk-indigo)' }}>{k >= 5 ? 'Site visit booked · Thu 11:30' : 'Qualifying lead…'}</span>
          <span style={{ font: bpFont.mono, color: 'var(--yk-charcoal)' }}>{k >= 5 ? 'CRM deal #4821 · Owner: Priya S.' : 'score 0.' + (40 + k * 11)}</span>
        </div>
      </div>
    </BpStage>
  );
}

/* 2 — Multi-channel follow-up */
function FollowUpScreen({ live, wide }) {
  const { Icon } = DS;
  const k = useTick(1300, 4, live);
  const seq = [['message-circle', 'WhatsApp', 'Day 0 · 10:02', 'Delivered'], ['mail', 'Email', 'Day 1 · 09:00', k >= 3 ? 'Cancelled' : 'Scheduled'], ['smartphone', 'SMS', 'Day 3 · 18:00', k >= 3 ? 'Cancelled' : 'Scheduled']];
  return (
    <BpStage>
      <BpPhone style={!wide ? { height: 340 } : null}>
        <div style={{ padding: '28px 10px 8px', background: '#075E54', color: '#fff', display: 'flex', alignItems: 'center', gap: 8 }}>
          <span style={{ width: 26, height: 26, borderRadius: 26, background: '#fff', color: '#075E54', display: 'grid', placeItems: 'center', font: bpFont.head(11) }}>MI</span>
          <div style={{ minWidth: 0 }}><div style={{ font: bpFont.head(12) }}>Mehta Interiors</div><div style={{ font: bpFont.body(9.5), opacity: 0.8 }}>Business account</div></div>
        </div>
        <div style={{ flex: 1, background: '#ECE5DD', padding: 10, display: 'flex', flexDirection: 'column', gap: 7 }}>
          <Bubble tone="#fff" show>Hi Rahul, your quote for the 3BHK is ready. Shall I share the PDF here?</Bubble>
          <Bubble me show={k >= 2} tone="#DCF8C6"><span style={{ color: '#111' }}>Yes please, and can we start on the 15th?</span></Bubble>
          <Bubble tone="#fff" show={k >= 3}>Sharing now. Priya will confirm the 15th by 4 pm.</Bubble>
        </div>
      </BpPhone>
      {wide && <div style={{ flex: 1, minWidth: 0, maxWidth: 270, display: 'flex', flexDirection: 'column', gap: 8 }}>
        <span style={{ font: bpFont.mono, color: 'var(--yk-violet)' }}>SEQUENCE · QUOTE_SENT</span>
        {seq.map(([ic, ch, when, st]) => (
          <div key={ch} style={{ background: '#fff', border: '1px solid var(--yk-lavender)', borderRadius: 10, padding: '9px 11px', display: 'flex', alignItems: 'center', gap: 10, opacity: st === 'Cancelled' ? 0.55 : 1, transition: 'opacity .4s' }}>
            <Icon name={ic} size={16} color="var(--yk-violet)" />
            <div style={{ flex: 1, minWidth: 0 }}><div style={{ font: bpFont.head(12.5), color: 'var(--yk-indigo)', textDecoration: st === 'Cancelled' ? 'line-through' : 'none' }}>{ch}</div><div style={{ font: bpFont.mono, color: 'var(--yk-charcoal)' }}>{when}</div></div>
            <span style={{ font: bpFont.mono, padding: '2px 7px', borderRadius: 99, background: st === 'Delivered' ? '#E0F7FB' : st === 'Cancelled' ? '#F1F5F9' : 'var(--yk-lavender)', color: st === 'Delivered' ? 'var(--yk-sky-700)' : 'var(--yk-indigo)' }}>{st}</span>
          </div>
        ))}
        <div style={{ borderRadius: 10, padding: '10px 11px', background: k >= 3 ? 'var(--yk-indigo)' : '#fff', color: k >= 3 ? '#fff' : 'var(--yk-charcoal)', border: '1px solid ' + (k >= 3 ? 'transparent' : 'var(--yk-lavender)'), display: 'flex', gap: 9, alignItems: 'center', transition: 'all .4s' }}>
          <Icon name="user-round-check" size={16} color={k >= 3 ? '#A5F3FC' : 'var(--yk-charcoal)'} />
          <span style={{ font: bpFont.body(12, 500) }}>{k >= 3 ? 'Reply detected · routed to Priya S.' : 'Waiting for reply…'}</span>
        </div>
      </div>}
    </BpStage>
  );
}

/* 3 — Executive dashboard */
function DashboardScreen({ live }) {
  const k = useTick(250, 12, live);
  const bars = [42, 55, 48, 63, 58, 71, 66, 78, 74, 86, 81, 92];
  const [hv, setHv] = React.useState(null);
  return (
    <BpStage>
      <BpWindow title="ops.mehta-interiors.in/leadership" style={{ width: '100%', maxWidth: 560 }}>
        <div style={{ padding: 14, display: 'flex', flexDirection: 'column', gap: 12 }}>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0,1fr))', gap: 8 }}>
            {[['Open pipeline', '₹1.84 Cr', '+6.2%'], ['Jobs on site', '27', '3 at risk'], ['Avg. collection', '18 days', '−2 days']].map(([l, v, d]) => (
              <div key={l} style={{ border: '1px solid var(--yk-lavender)', borderRadius: 8, padding: '8px 10px', minWidth: 0 }}>
                <div style={{ font: bpFont.body(10.5), color: 'var(--yk-charcoal)' }}>{l}</div>
                <div style={{ font: bpFont.head(17), color: 'var(--yk-indigo)' }}>{v}</div>
                <div style={{ font: bpFont.mono, color: 'var(--yk-sky-700)' }}>{d}</div>
              </div>
            ))}
          </div>
          <div style={{ border: '1px solid var(--yk-lavender)', borderRadius: 8, padding: 10 }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', font: bpFont.mono, color: 'var(--yk-charcoal)' }}><span>BOOKED REVENUE · 12 WK</span><span style={{ color: 'var(--yk-violet)' }}>{hv != null ? `W${hv + 1}: ₹${(bars[hv] * 0.21).toFixed(1)} L` : 'hover a bar'}</span></div>
            <div style={{ display: 'flex', alignItems: 'flex-end', gap: 5, height: 92, marginTop: 8 }}>
              {bars.map((b, i) => <span key={i} onMouseEnter={() => setHv(i)} onMouseLeave={() => setHv(null)} style={{ flex: 1, height: (i < k ? b : 4) + '%', borderRadius: '3px 3px 0 0', background: hv === i ? 'var(--yk-violet)' : i === bars.length - 1 ? 'linear-gradient(#7C3AED,#06B6D4)' : '#C9C4F5', transition: 'height .5s cubic-bezier(.22,1,.36,1), background .2s', cursor: 'pointer' }} />)}
            </div>
          </div>
          <div style={{ display: 'grid', gap: 0 }}>
            {[['Wakad 3BHK', 'Carpentry', 'On track'], ['Baner Office', 'Electrical', 'Delayed 2d'], ['Aundh Villa', 'Handover', 'On track']].map(([p, s, st]) => (
              <div key={p} style={{ display: 'grid', gridTemplateColumns: '1.3fr 1fr auto', gap: 8, padding: '6px 2px', borderTop: '1px solid var(--yk-lavender)', font: bpFont.body(11.5), color: 'var(--yk-indigo)' }}>
                <span>{p}</span><span style={{ color: 'var(--yk-charcoal)' }}>{s}</span>
                <span style={{ font: bpFont.mono, padding: '1px 7px', borderRadius: 99, background: st === 'On track' ? '#E0F7FB' : '#FFF1E6', color: st === 'On track' ? 'var(--yk-sky-700)' : '#B45309' }}>{st}</span>
              </div>
            ))}
          </div>
        </div>
      </BpWindow>
    </BpStage>
  );
}

/* 4 — Legacy modernisation */
function LegacyScreen({ live, wide }) {
  const k = useTick(900, 6, live);
  const reqs = ['GET /v1/customers/8812', 'GET /v1/invoices?cust=8812', 'POST /v1/orders', 'GET /v1/stock/SKU-221'];
  return (
    <BpStage>
      <div style={{ display: 'grid', gridTemplateColumns: wide ? '1fr auto 1fr' : '1fr', gap: 12, alignItems: 'center', width: '100%' }}>
        <div style={{ background: '#0B1020', borderRadius: 8, padding: 12, font: '500 10.5px/1.6 var(--font-mono)', color: '#86EFAC', boxShadow: 'var(--shadow-md)', minWidth: 0, overflow: 'hidden' }}>
          <div style={{ color: '#94A3B8' }}>ERP v4.2 · CUSTMAST</div>
          <div>CUST NO : 8812</div><div>NAME    : RAHUL DESAI</div><div>CITY    : PUNE</div><div>BAL DUE : 42,300.00</div><div>F3=EXIT  F5=REFRESH</div>
        </div>
        <div style={{ display: 'flex', flexDirection: wide ? 'column' : 'row', alignItems: 'center', gap: 6 }}>
          <span style={{ font: bpFont.mono, color: 'var(--yk-violet)', padding: '4px 8px', borderRadius: 99, background: '#fff', border: '1px solid var(--yk-lavender)' }}>API GATEWAY</span>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 3, width: 168 }}>
            {reqs.map((r, i) => <span key={r} style={{ font: '500 9.5px var(--font-mono)', color: 'var(--yk-indigo)', background: '#fff', border: '1px solid var(--yk-lavender)', borderRadius: 5, padding: '3px 6px', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', opacity: i < k ? 1 : 0.25, transition: 'opacity .3s' }}><span style={{ color: 'var(--yk-sky-700)' }}>200</span> {r}</span>)}
          </div>
        </div>
        <BpWindow title="app.mehta-interiors.in/customers/8812">
          <div style={{ padding: 12, display: 'flex', flexDirection: 'column', gap: 8 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><span style={{ width: 28, height: 28, borderRadius: 28, background: 'var(--yk-lavender)', color: 'var(--yk-violet)', display: 'grid', placeItems: 'center', font: bpFont.head(11) }}>RD</span><div><div style={{ font: bpFont.head(13), color: 'var(--yk-indigo)' }}>Rahul Desai</div><div style={{ font: bpFont.body(10.5), color: 'var(--yk-charcoal)' }}>Pune · since 2019</div></div></div>
            {[['Balance due', '₹42,300'], ['Open orders', '2'], ['Last invoice', '14 Nov']].map(([a, b]) => <div key={a} style={{ display: 'flex', justifyContent: 'space-between', font: bpFont.body(11.5), color: 'var(--yk-charcoal)', borderTop: '1px solid var(--yk-lavender)', paddingTop: 6 }}><span>{a}</span><b style={{ color: 'var(--yk-indigo)', fontWeight: 600 }}>{b}</b></div>)}
            <span style={{ font: bpFont.mono, color: k >= 6 ? 'var(--yk-sky-700)' : 'var(--yk-charcoal)' }}>{k >= 6 ? '✓ parallel run: 0 diffs' : 'parallel run: comparing…'}</span>
          </div>
        </BpWindow>
      </div>
    </BpStage>
  );
}

/* 5 — Back-office approval */
function ApprovalScreen({ wide }) {
  const { Icon } = DS;
  const [st, setSt] = React.useState('pending');
  const fields = [['Vendor', 'Shree Plywood Co.'], ['Invoice no.', 'SPC/24-25/1187'], ['Amount', '₹1,48,250.00'], ['PO match', 'PO-3310 · 100%'], ['GST', '27AAKCS1192M1Z4']];
  return (
    <BpStage>
      {wide && <div style={{ width: 170, flexShrink: 0, background: '#fff', borderRadius: 6, boxShadow: 'var(--shadow-md)', padding: 14, display: 'flex', flexDirection: 'column', gap: 6, transform: 'rotate(-2deg)' }}>
        <div style={{ font: bpFont.head(11), color: 'var(--yk-indigo)' }}>TAX INVOICE</div>
        {[70, 90, 55, 80].map((w, i) => <span key={i} style={{ height: 5, width: w + '%', borderRadius: 3, background: i === 1 ? 'rgba(6,182,212,.45)' : '#E2E8F0' }} />)}
        <div style={{ height: 1, background: '#E2E8F0', margin: '4px 0' }} />
        {[0, 1, 2, 3, 4].map((i) => <div key={i} style={{ display: 'flex', gap: 6 }}><span style={{ height: 5, flex: 2, borderRadius: 3, background: '#E2E8F0' }} /><span style={{ height: 5, flex: 1, borderRadius: 3, background: '#E2E8F0' }} /></div>)}
        <span style={{ height: 7, width: '45%', alignSelf: 'flex-end', borderRadius: 3, background: 'rgba(124,58,237,.4)', marginTop: 6 }} />
      </div>}
      <div style={{ flex: 1, minWidth: 0, maxWidth: 320, background: '#fff', border: '1px solid ' + (st === 'approved' ? 'rgba(124,58,237,.45)' : 'var(--yk-lavender)'), borderRadius: 12, boxShadow: 'var(--shadow-md)', overflow: 'hidden' }}>
        <div style={{ padding: '10px 14px', borderBottom: '1px solid var(--yk-lavender)', display: 'flex', alignItems: 'center', gap: 8 }}>
          <Icon name="shield-check" size={16} color="var(--yk-violet)" />
          <span style={{ font: bpFont.head(13), color: 'var(--yk-indigo)', flex: 1 }}>Approval required</span>
          <span style={{ font: bpFont.mono, padding: '2px 8px', borderRadius: 99, background: st === 'approved' ? 'var(--yk-violet)' : st === 'edit' ? '#FFF1E6' : 'var(--yk-lavender)', color: st === 'approved' ? '#fff' : st === 'edit' ? '#B45309' : 'var(--yk-indigo)' }}>{st === 'approved' ? 'APPROVED' : st === 'edit' ? 'EDIT REQUESTED' : 'PENDING'}</span>
        </div>
        <div style={{ padding: '8px 14px', display: 'grid', gap: 0 }}>
          {fields.map(([a, b]) => <div key={a} style={{ display: 'flex', justifyContent: 'space-between', gap: 10, padding: '5px 0', borderBottom: '1px dashed var(--yk-lavender)', font: bpFont.body(11.5), color: 'var(--yk-charcoal)' }}><span>{a}</span><span style={{ color: 'var(--yk-indigo)', fontWeight: 500, textAlign: 'right' }}>{b}</span></div>)}
          <div style={{ font: bpFont.mono, color: 'var(--yk-charcoal)', padding: '7px 0 2px' }}>Extracted · confidence 0.97 · assignee: A. Kulkarni</div>
        </div>
        <div style={{ padding: '10px 14px', display: 'flex', gap: 8, borderTop: '1px solid var(--yk-lavender)', background: '#FAFBFF' }}>
          <button type="button" onClick={() => setSt('approved')} style={{ flex: 1, padding: '8px 10px', border: 0, borderRadius: 8, background: 'var(--yk-violet)', color: '#fff', font: bpFont.body(12, 600), cursor: 'pointer' }}>Approve</button>
          <button type="button" onClick={() => setSt('edit')} style={{ flex: 1, padding: '8px 10px', border: '1px solid var(--yk-indigo)', borderRadius: 8, background: '#fff', color: 'var(--yk-indigo)', font: bpFont.body(12, 600), cursor: 'pointer' }}>Request edit</button>
        </div>
        <div style={{ padding: '8px 14px', font: bpFont.mono, color: st === 'approved' ? 'var(--yk-sky-700)' : 'var(--yk-charcoal)', borderTop: '1px solid var(--yk-lavender)' }}>{st === 'approved' ? '→ Posted to ERP · filed to /Finance/2024-25/Nov' : st === 'edit' ? '→ Returned to AP team with note' : '→ Waiting on approver'}</div>
      </div>
    </BpStage>
  );
}

/* 6 — Content ops desk: Reel generation → review → Instagram upload */
const REEL_SCENES = [
  ['0:00', 'Your 3BHK,', 'ready in 45 days?', 'linear-gradient(160deg,#1E1B4B,#4C1D95)'],
  ['0:03', 'Modular kitchen', 'installed in 2 days', 'linear-gradient(160deg,#0E7490,#1E1B4B)'],
  ['0:15', 'Before → After', 'Wakad, Pune', 'linear-gradient(160deg,#7C3AED,#2563EB)'],
  ['0:25', 'Free site visit', 'Link in bio', 'linear-gradient(160deg,#1E1B4B,#0891B2)'],
];
function ReelPlayer({ published, reduce }) {
  const { Icon } = DS;
  const [t, setT] = React.useState(0);
  React.useEffect(() => { if (reduce) return; const id = setInterval(() => setT((x) => (x + 1) % 400), 50); return () => clearInterval(id); }, [reduce]);
  const sc = Math.floor(t / 100), p = (t % 100) / 100, S = REEL_SCENES[sc];
  return (
    <div style={{ position: 'relative', flex: 1, overflow: 'hidden', background: '#000' }}>
      {REEL_SCENES.map((x, i) => <div key={i} style={{ position: 'absolute', inset: 0, background: x[3], opacity: i === sc ? 1 : 0, transform: i === sc ? `scale(${1 + p * 0.08})` : 'scale(1)', transition: 'opacity .45s' }}>
        <div style={{ position: 'absolute', inset: 0, backgroundImage: 'radial-gradient(rgba(255,255,255,.08) 1px, transparent 1px)', backgroundSize: '12px 12px' }} />
      </div>)}
      <div style={{ position: 'absolute', top: 30, left: 10, right: 10, display: 'flex', gap: 3 }}>{REEL_SCENES.map((_, i) => <span key={i} style={{ flex: 1, height: 2, borderRadius: 2, background: 'rgba(255,255,255,.3)', overflow: 'hidden' }}><span style={{ display: 'block', height: '100%', background: '#fff', width: i < sc ? '100%' : i === sc ? p * 100 + '%' : 0 }} /></span>)}</div>
      <div style={{ position: 'absolute', top: 40, left: 10, right: 10, display: 'flex', justifyContent: 'space-between', alignItems: 'center', color: '#fff' }}><span style={{ font: '600 13px var(--font-display)' }}>Reels</span><Icon name="camera" size={15} color="#fff" /></div>
      <div key={sc} style={{ position: 'absolute', left: 14, right: 44, top: '34%', color: '#fff', animation: 'yk-fade-up .45s cubic-bezier(.22,1,.36,1) both' }}>
        <div style={{ font: '700 19px/1.15 var(--font-display)', letterSpacing: '-.02em' }}>{S[1]}</div>
        <div style={{ font: '600 13px/1.3 var(--font-body)', marginTop: 4, color: '#A5F3FC' }}>{S[2]}</div>
      </div>
      <div style={{ position: 'absolute', right: 8, bottom: 62, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 11, color: '#fff' }}>
        {[['heart', published ? '1.2k' : '—'], ['message-circle', published ? '48' : '—'], ['send', ''], ['bookmark', '']].map(([ic, c]) => <span key={ic} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 1 }}><Icon name={ic} size={17} color="#fff" />{c && <span style={{ font: '500 9px var(--font-body)' }}>{c}</span>}</span>)}
      </div>
      <div style={{ position: 'absolute', left: 10, right: 40, bottom: 12, color: '#fff', display: 'grid', gap: 4 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}><span style={{ width: 20, height: 20, borderRadius: 20, background: 'linear-gradient(135deg,#7C3AED,#06B6D4)', border: '1.5px solid #fff', display: 'grid', placeItems: 'center', font: '700 8px var(--font-body)' }}>MI</span><span style={{ font: '600 10.5px var(--font-body)' }}>mehta.interiors</span><span style={{ font: '600 9px var(--font-body)', border: '1px solid rgba(255,255,255,.7)', borderRadius: 4, padding: '1px 5px' }}>Follow</span></div>
        <div style={{ font: '400 10px/1.35 var(--font-body)', opacity: 0.95 }}>3BHK turnkey in 45 days. Book a free site visit.</div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 5, font: '400 9.5px var(--font-body)', opacity: 0.85 }}><Icon name="music-2" size={10} color="#fff" />Original audio · {S[0]}</div>
      </div>
      {!published && <span style={{ position: 'absolute', top: 60, left: 10, whiteSpace: 'nowrap', font: '600 9px var(--font-mono)', color: '#1E1B4B', background: '#FDE68A', borderRadius: 4, padding: '2px 6px' }}>PREVIEW · NOT LIVE</span>}
    </div>
  );
}
function ContentScreen({ live, wide }) {
  const { Icon } = DS;
  const reduce = useReducedMotion();
  const [ok, setOk] = React.useState(false);
  const [gen, setGen] = React.useState(0);
  const [up, setUp] = React.useState(0);
  React.useEffect(() => { if (!live) return; setGen(0); const id = setInterval(() => setGen((g) => Math.min(100, g + 4)), 90); return () => clearInterval(id); }, [live]);
  React.useEffect(() => { if (!ok) { setUp(0); return; } const id = setInterval(() => setUp((u) => Math.min(100, u + 5)), 80); return () => clearInterval(id); }, [ok]);
  const published = ok && up >= 100;
  const steps = [
    ['file-text', 'Script drafted', 'Hook, 4 scenes, CTA · 0:28', 'done'],
    ['wand-sparkles', 'Voiceover + captions', gen < 100 ? `Rendering ${gen}%` : '1080×1920 · captions burned in', gen < 100 ? 'run' : 'done'],
    ['user-check', 'Human review', ok ? 'Approved by Riya (editor)' : 'Waiting for editor', ok ? 'done' : gen < 100 ? 'idle' : 'wait'],
    ['upload', 'Upload to Instagram', !ok ? 'Starts after approval' : up < 100 ? `Uploading ${up}%` : 'Shared to Reels + feed', !ok ? 'idle' : up < 100 ? 'run' : 'done'],
  ];
  return (
    <BpStage>
      <BpPhone style={!wide ? { height: 360 } : null}><ReelPlayer published={published} reduce={reduce} /></BpPhone>
      <div style={{ flex: wide ? 1 : '1 1 100%', minWidth: 0, maxWidth: wide ? 300 : 420, background: '#fff', border: '1px solid var(--yk-lavender)', borderRadius: 12, boxShadow: 'var(--shadow-md)', padding: 14, display: 'flex', flexDirection: 'column', gap: 9 }}>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}><span style={{ font: bpFont.head(13), color: 'var(--yk-indigo)' }}>Reel pipeline</span><span style={{ font: bpFont.mono, color: published ? 'var(--yk-sky-700)' : 'var(--yk-charcoal)' }}>{published ? '● LIVE' : 'REEL-0142'}</span></div>
        {steps.map(([ic, t, d, st], i) => (
          <div key={t} style={{ display: 'grid', gridTemplateColumns: '28px 1fr', gap: 9, alignItems: 'start', opacity: st === 'idle' ? 0.5 : 1, transition: 'opacity .3s' }}>
            <span style={{ width: 28, height: 28, borderRadius: 8, display: 'grid', placeItems: 'center', background: st === 'done' ? 'var(--yk-lavender)' : st === 'run' || st === 'wait' ? 'var(--yk-indigo)' : '#F1F5F9', color: st === 'run' || st === 'wait' ? '#fff' : 'var(--yk-violet)' }}><Icon name={st === 'done' ? 'check' : ic} size={14} /></span>
            <div style={{ minWidth: 0 }}>
              <div style={{ font: bpFont.body(12, 600), color: 'var(--yk-indigo)' }}>{t}</div>
              <div style={{ font: bpFont.mono, color: 'var(--yk-charcoal)' }}>{d}</div>
              {st === 'run' && <div style={{ height: 4, borderRadius: 4, background: 'var(--yk-lavender)', marginTop: 4, overflow: 'hidden' }}><span style={{ display: 'block', height: '100%', width: (i === 1 ? gen : up) + '%', background: 'linear-gradient(90deg,#7C3AED,#06B6D4)', transition: 'width .1s linear' }} /></div>}
              {i === 2 && gen >= 100 && <button type="button" role="switch" aria-checked={ok} onClick={() => setOk(!ok)} style={{ marginTop: 6, display: 'flex', alignItems: 'center', gap: 8, border: 0, background: 'none', padding: 0, cursor: 'pointer' }}>
                <span style={{ width: 32, height: 18, borderRadius: 18, background: ok ? 'var(--yk-violet)' : '#CBD5E1', position: 'relative', transition: 'background .25s', flexShrink: 0 }}><span style={{ position: 'absolute', top: 2, left: ok ? 16 : 2, width: 14, height: 14, borderRadius: 14, background: '#fff', transition: 'left .25s cubic-bezier(.22,1,.36,1)' }} /></span>
                <span style={{ font: bpFont.body(11.5, 600), color: ok ? 'var(--yk-violet)' : 'var(--yk-indigo)' }}>{ok ? 'Approved for publishing' : 'Approve to publish'}</span>
              </button>}
            </div>
          </div>
        ))}
        {published && <div style={{ marginTop: 'auto', display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 6, animation: 'yk-fade-up .4s cubic-bezier(.22,1,.36,1) both' }}>{[['Plays', '8.4k'], ['Saves', '312'], ['Leads', '19']].map(([l, v]) => <div key={l} style={{ border: '1px solid var(--yk-lavender)', borderRadius: 8, padding: '6px 8px' }}><div style={{ font: bpFont.mono, color: 'var(--yk-charcoal)' }}>{l}</div><div style={{ font: bpFont.head(14), color: 'var(--yk-indigo)' }}>{v}</div></div>)}</div>}
      </div>
    </BpStage>
  );
}

const BLUEPRINT_SCREENS = [VoiceScreen, FollowUpScreen, DashboardScreen, LegacyScreen, ApprovalScreen, ContentScreen];
Object.assign(window, { BLUEPRINT_SCREENS });
