// ════════════════════════════════════════════════════════════════
// Agentic Forge · Composite Team · v2 · 180s · 5 scenes
// Multi-surface: email → Slack → Figma/intel → IDE split → close
// All AF outputs render INLINE in each role's surface. No popups.
// ════════════════════════════════════════════════════════════════

const T = window.TOKENS;
const CT = {
  carbon: '#080c14', charcoal: '#1c1e24', line: '#2a2d35',
  bgDim: '#0f1218', white: '#fff', gray: '#a0a4ab', dim: '#6e7178',
  green: '#00da41', red: '#ff6b6b', amber: '#f4b400', blue: '#3b82f6',
  slackBg: '#1a1d21', slackHover: '#22252a', slackText: '#d1d2d3', slackLink: '#1d9bd1',
};
const ease = t => t<=0?0:t>=1?1:1-Math.pow(1-t,3);
const fade = (time, start, dur=0.2) => Math.max(0, Math.min(1, ease((time-start)/dur)));
const slideUp = (time, start, dur=0.2, dist=4) => (1 - fade(time, start, dur)) * dist;
// Gradient — display-size emphasized green text. Reference as the "gradient" style.
const gradientStyle = {
  background: 'linear-gradient(135deg, #00E87B 0%, #00da41 50%, #00B35A 100%)',
  WebkitBackgroundClip: 'text',
  WebkitTextFillColor: 'transparent',
  backgroundClip: 'text',
  textShadow: 'none',
};

// ─── Lower-third surface label ────────────────────────────────
function SurfaceLabel({ text, sceneStart }) {
  const time = useTime();
  const t = time - sceneStart;
  let o = 0;
  if (t < 0.2) o = t / 0.2;
  else if (t < 1.7) o = 1;
  else if (t < 1.9) o = 1 - (t - 1.7) / 0.2;
  o = Math.max(0, Math.min(1, o));
  if (o === 0) return null;
  return (
    <div style={{ position:'absolute', left:80, bottom:80, fontFamily:T.sans, fontWeight:400, fontSize:13, color:CT.gray, opacity:o, zIndex:60 }}>
      {text}
    </div>
  );
}

function AFChip({ skill, start = 0 }) {
  const time = useTime();
  const o = fade(time, start, 0.18);
  return (
    <div style={{
      display:'inline-flex', alignItems:'center', gap:8,
      background:CT.charcoal, borderLeft:`2px solid ${CT.green}`,
      borderRadius:4, padding:'4px 10px',
      fontFamily:T.sans, fontSize:11, fontWeight:500, color:CT.gray,
      opacity:o, transform:`translateY(${slideUp(time,start)}px)`,
    }}>
      <span style={{ width:6, height:6, borderRadius:3, background:CT.green }} />
      <span>Agentic Forge · {skill}</span>
    </div>
  );
}
function Card({ children, accent, start = 0, padding = 18, style }) {
  const time = useTime();
  const o = fade(time, start, 0.22);
  return (
    <div style={{
      position:'relative', background:CT.charcoal, border:`1px solid ${CT.line}`,
      borderRadius:12, padding, fontFamily:T.sans, color:CT.white,
      opacity:o, transform:`translateY(${slideUp(time,start)}px)`, overflow:'hidden',
      ...style,
    }}>
      {accent && <div style={{ position:'absolute', left:0, top:0, bottom:0, width:4, background:accent }} />}
      {children}
    </div>
  );
}

// ─── Subtitles ────────────────────────────────────────────────
const SUBS = [
  { t: 0.5, end: 5.0,   text: "Four roles at Ledgerline." },
  { t: 5.2, end: 11.0,  text: "They never coordinated directly. The framework absorbed it." },
  { t: 25.0, end: 32.0, text: "A customer success rep forwarded an email." },
  { t: 32.2, end: 40.0, text: "The framework captured intent, NFR dimensions, and deadline — from one paragraph." },
  { t: 42.5, end: 47.5, text: "Jessica is the PM." },
  { t: 47.7, end: 52.5, text: "She types a vague Slack message because that's how PMs talk." },
  { t: 52.7, end: 56.0, text: "The framework asks her to disambiguate." },
  { t: 82.5, end: 87.0, text: "Rachel attaches a Figma link." },
  { t: 87.2, end: 95.5, text: "The framework reads the design, maps the components, notices a missing state." },
  { t: 122.5, end: 128.5, text: "Two engineers, two branches, same file." },
  { t: 128.7, end: 135.0, text: "The framework saw the overlap before either of them did." },
  { t: 168.5, end: 174.0, text: "The substrate they coordinate through is the framework." },
  { t: 174.2, end: 178.0, text: "Not standups." },
];
function Subtitles() {
  const time = useTime();
  const active = SUBS.find(s => time >= s.t && time <= s.end);
  if (!active) return null;
  const words = active.text.split(' ');
  const lines = [];
  let cur = '';
  for (const w of words) {
    const next = cur ? cur + ' ' + w : w;
    if (next.length > 42) { lines.push(cur); cur = w; } else cur = next;
  }
  if (cur) lines.push(cur);
  return (
    <div style={{ position:'absolute', left:0, right:0, bottom:80, display:'flex', justifyContent:'center', pointerEvents:'none', zIndex:55 }}>
      <div style={{ background:'rgba(28, 30, 36, 0.78)', borderRadius:4, padding:'8px 14px', maxWidth:'70%' }}>
        {lines.map((l, i) => (
          <div key={i} style={{ fontFamily:T.sans, fontWeight:500, fontSize:22, color:'#fff', textAlign:'center', lineHeight:1.35 }}>{l}</div>
        ))}
      </div>
    </div>
  );
}

// ════════════════════════════════════════════════════════════════
// SCENE 1 — Email (Outlook web, dark mode) (0-42s)
// ════════════════════════════════════════════════════════════════
const OL = {
  bg: '#1f1f1f', panel: '#262626', chrome: '#2b2b2b',
  border: '#404040', hover: '#3a3a3a', accent: '#0078d4',
  text: '#ffffff', textDim: '#a0a0a0',
};

function OLWaffle() {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="#fff">
      {[0,1,2].flatMap(r => [0,1,2].map(c => (
        <rect key={`${r}-${c}`} x={c*5.5+1} y={r*5.5+1} width="3" height="3" rx="0.4"/>
      )))}
    </svg>
  );
}
function OLLogo() {
  return (
    <svg width="22" height="20" viewBox="0 0 22 20" fill="none">
      <rect x="0" y="3" width="14" height="14" rx="1.5" fill={OL.accent}/>
      <text x="7" y="13.5" fontFamily="Arial, sans-serif" fontSize="11" fontWeight="700" fill="#fff" textAnchor="middle">O</text>
      <path d="M14 6L22 4V16L14 14Z" fill="#50e6ff"/>
    </svg>
  );
}
function OLRailIcon({ kind }) {
  const s=20, sw=1.6, c='currentColor';
  switch(kind){
    case 'mail': return <svg width={s} height={s} viewBox="0 0 20 20" fill="none"><path d="M2.5 5h15v10h-15z" stroke={c} strokeWidth={sw}/><path d="M2.5 5l7.5 5.5L17.5 5" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
    case 'calendar': return <svg width={s} height={s} viewBox="0 0 20 20" fill="none"><rect x="2.5" y="4" width="15" height="13" rx="1" stroke={c} strokeWidth={sw}/><path d="M2.5 8h15M6 2.5v3M14 2.5v3" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'people': return <svg width={s} height={s} viewBox="0 0 20 20" fill="none"><circle cx="10" cy="7" r="3" stroke={c} strokeWidth={sw}/><path d="M3 17c0-3.3 3.1-6 7-6s7 2.7 7 6" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'todo': return <svg width={s} height={s} viewBox="0 0 20 20" fill="none"><rect x="2.5" y="2.5" width="15" height="15" rx="1.5" stroke={c} strokeWidth={sw}/><path d="M6 10l2.5 2.5L14 7" stroke={c} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/></svg>;
    case 'files': return <svg width={s} height={s} viewBox="0 0 20 20" fill="none"><path d="M4 2.5h7l5 5v10H4z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/><path d="M11 2.5v5h5" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
  }
}
function OLTopIcon({ kind }) {
  const s=16, sw=1.4, c='currentColor';
  switch(kind){
    case 'bell': return <svg width={s} height={s} viewBox="0 0 16 16" fill="none"><path d="M4 7c0-2.2 1.8-4 4-4s4 1.8 4 4v3l1 2H3l1-2V7z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/><path d="M7 13.5h2" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'gear': return <svg width={s} height={s} viewBox="0 0 16 16" fill="none"><circle cx="8" cy="8" r="2.2" stroke={c} strokeWidth={sw}/><path d="M8 2.5v1.5M8 12V13.5M2.5 8H4M12 8h1.5M4 4l1 1M11 11l1 1M4 12l1-1M11 5l1-1" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'help': return <svg width={s} height={s} viewBox="0 0 16 16" fill="none"><circle cx="8" cy="8" r="5.5" stroke={c} strokeWidth={sw}/><path d="M6.5 6.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5c0 .6-.4.95-.85 1.3-.5.4-.65.6-.65 1.2M8 11v.01" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
  }
}
function OLActionIcon({ kind }) {
  const s=14, sw=1.4, c='currentColor';
  switch(kind){
    case 'reply': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M5 3L1.5 6.5 5 10M1.5 6.5h6c2.5 0 4 1.5 4 4" stroke={c} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/></svg>;
    case 'reply-all': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M3 3L0 6l3 3M5 3L2 6l3 3M2 6h5.5c2 0 3.5 1.2 3.5 3.5" stroke={c} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/></svg>;
    case 'forward': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M9 3l3.5 3.5L9 10M12.5 6.5h-6c-2.5 0-4 1.5-4 4" stroke={c} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/></svg>;
    case 'delete': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M2.5 4h9M5 4V2.5h4V4M3.5 4l.5 8h6l.5-8" stroke={c} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/></svg>;
    case 'archive': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><rect x="1.5" y="2.5" width="11" height="2.8" rx="0.3" stroke={c} strokeWidth={sw}/><path d="M2.5 5.3v6.2h9V5.3" stroke={c} strokeWidth={sw}/><path d="M5.5 8h3" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'flag': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M3 1.5v11M3 2h7l-1.5 2.5L10 7H3" stroke={c} strokeWidth={sw} strokeLinejoin="round" strokeLinecap="round"/></svg>;
    case 'mark-unread': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M1.5 4h11v7h-11z" stroke={c} strokeWidth={sw}/><path d="M1.5 4l5.5 4 5.5-4" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
    case 'more': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><circle cx="3" cy="7" r="1" fill={c}/><circle cx="7" cy="7" r="1" fill={c}/><circle cx="11" cy="7" r="1" fill={c}/></svg>;
  }
}

function Scene1({ sceneStart = 0 }) {
  const time = useTime();
  const replyT = sceneStart + 13;
  const cardT = sceneStart + 14;

  return (
    <div style={{ position:'absolute', inset:0, background:OL.bg, display:'flex', flexDirection:'column', fontFamily:T.sans }}>
      {/* ── TOP BAR ───────────────────────────────────────────── */}
      <div style={{ height:48, background:OL.chrome, borderBottom:`1px solid ${OL.border}`, display:'flex', alignItems:'center', padding:'0 8px', gap:8, flexShrink:0 }}>
        <div style={{ width:36, height:36, display:'flex', alignItems:'center', justifyContent:'center' }}><OLWaffle /></div>
        <div style={{ display:'flex', alignItems:'center', gap:8, paddingRight:12 }}>
          <OLLogo />
          <span style={{ fontSize:15, color:OL.text, fontWeight:600 }}>Outlook</span>
        </div>
        <div style={{ flex:1, display:'flex', justifyContent:'center', padding:'0 16px' }}>
          <div style={{ background:OL.hover, borderRadius:4, padding:'7px 12px', fontSize:13, color:OL.textDim, flex:1, maxWidth:720, display:'flex', alignItems:'center', gap:10 }}>
            <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
              <circle cx="6" cy="6" r="4" stroke={OL.textDim} strokeWidth="1.4"/>
              <path d="M9 9l3 3" stroke={OL.textDim} strokeWidth="1.4" strokeLinecap="round"/>
            </svg>
            <span>Search</span>
          </div>
        </div>
        <div style={{ display:'flex', alignItems:'center', gap:2, color:OL.text }}>
          {['bell','gear','help'].map(k => (
            <div key={k} style={{ width:36, height:36, display:'flex', alignItems:'center', justifyContent:'center' }}><OLTopIcon kind={k} /></div>
          ))}
        </div>
        <div style={{ width:32, height:32, borderRadius:16, background:'#3b5b7c', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, fontWeight:500, marginLeft:4 }}>J</div>
      </div>

      <div style={{ flex:1, display:'flex', minHeight:0 }}>
        {/* ── LEFT RAIL ───────────────────────────────────────── */}
        <div style={{ width:48, background:OL.panel, borderRight:`1px solid ${OL.border}`, display:'flex', flexDirection:'column', alignItems:'center', paddingTop:8, gap:2, flexShrink:0 }}>
          {[{k:'mail',active:true},{k:'calendar'},{k:'people'},{k:'todo'},{k:'files'}].map(it => (
            <div key={it.k} style={{ width:44, height:44, display:'flex', alignItems:'center', justifyContent:'center', color: it.active ? OL.accent : OL.text, position:'relative' }}>
              {it.active && <div style={{ position:'absolute', left:0, top:10, bottom:10, width:3, background:OL.accent, borderRadius:2 }} />}
              <OLRailIcon kind={it.k} />
            </div>
          ))}
        </div>

        {/* ── FOLDER PANE ─────────────────────────────────────── */}
        <div style={{ width:240, background:OL.panel, borderRight:`1px solid ${OL.border}`, flexShrink:0, padding:'12px 8px', display:'flex', flexDirection:'column', gap:16 }}>
          <div style={{ background:OL.accent, color:'#fff', borderRadius:4, padding:'8px 18px', fontSize:13, fontWeight:600, display:'inline-flex', alignItems:'center', gap:8, alignSelf:'flex-start' }}>
            <span style={{ fontSize:15, lineHeight:1, fontWeight:400 }}>+</span>
            <span>New mail</span>
          </div>
          <div>
            <div style={{ fontSize:11, color:OL.textDim, marginBottom:6, fontWeight:600, padding:'0 10px', letterSpacing:'0.05em' }}>FAVORITES</div>
            {['Inbox','Demand Capture','Sent Items','Drafts','Archive'].map((f, i) => (
              <div key={i} style={{
                padding:'7px 10px', borderRadius:4, fontSize:13,
                color: f === 'Demand Capture' ? OL.text : '#dcdcdc',
                background: f === 'Demand Capture' ? OL.hover : 'transparent',
                fontWeight: f === 'Demand Capture' ? 600 : 400, marginBottom:1,
                display:'flex', alignItems:'center', justifyContent:'space-between',
              }}>
                <span>{f}</span>
                {f === 'Inbox' && <span style={{ color:OL.textDim, fontSize:11 }}>4</span>}
              </div>
            ))}
          </div>
        </div>

        {/* ── MAIN CONTENT ────────────────────────────────────── */}
        <div style={{ flex:1, display:'flex', flexDirection:'column', minWidth:0 }}>
          {/* Focused / Other tabs */}
          <div style={{ height:40, background:OL.bg, borderBottom:`1px solid ${OL.border}`, display:'flex', alignItems:'stretch', padding:'0 28px', gap:24, flexShrink:0 }}>
            <div style={{ display:'flex', alignItems:'center', fontSize:13, color:OL.text, fontWeight:600, borderBottom:`2px solid ${OL.accent}`, marginBottom:-1 }}>Focused</div>
            <div style={{ display:'flex', alignItems:'center', fontSize:13, color:OL.textDim }}>Other</div>
            <div style={{ marginLeft:'auto', display:'flex', alignItems:'center', fontSize:12, color:OL.textDim, gap:4 }}>
              Filter <span style={{ fontSize:9 }}>▾</span>
            </div>
          </div>

          {/* Action toolbar */}
          <div style={{ height:44, background:OL.bg, borderBottom:`1px solid ${OL.border}`, display:'flex', alignItems:'center', padding:'0 28px', gap:4, flexShrink:0, color:OL.text }}>
            {[['reply','Reply'],['reply-all','Reply all'],['forward','Forward']].map(([k,label]) => (
              <div key={k} style={{ display:'flex', alignItems:'center', gap:6, padding:'6px 10px', borderRadius:4, fontSize:13 }}>
                <OLActionIcon kind={k} />
                <span>{label}</span>
              </div>
            ))}
            <div style={{ width:1, height:20, background:OL.border, margin:'0 8px' }} />
            {['delete','archive','flag','mark-unread','more'].map(k => (
              <div key={k} style={{ width:32, height:32, display:'flex', alignItems:'center', justifyContent:'center' }}><OLActionIcon kind={k} /></div>
            ))}
          </div>

          {/* Email content */}
          <div className="chat-scroll" style={{ flex:1, padding:'24px 36px', overflow:'auto' }}>
          <div style={{ fontFamily:T.sans, fontSize:22, color:CT.white, fontWeight:500, marginBottom:6, letterSpacing:'-0.01em' }}>
            Forwarded: Sterling &amp; Associates — EU expansion requirements
          </div>
          <div style={{ fontSize:12, color:CT.dim, marginBottom:24 }}>2 messages · today</div>

          {/* AF reply (top of thread) */}
          {time > replyT - 0.2 && (
            <div style={{ background:'#101319', border:`1px solid #1e2128`, borderRadius:10, padding:'18px 22px', marginBottom:16, opacity: fade(time, replyT, 0.3), transform:`translateY(${slideUp(time, replyT, 0.3, 8)}px)` }}>
              <div style={{ display:'flex', alignItems:'center', gap:10, marginBottom:14 }}>
                <div style={{ width:30, height:30, borderRadius:15, background:CT.charcoal, display:'flex', alignItems:'center', justifyContent:'center' }}>
                  <span style={{ width:9, height:9, borderRadius:5, background:CT.green }} />
                </div>
                <div style={{ flex:1 }}>
                  <div style={{ fontSize:14, color:CT.white, fontWeight:500 }}>Agentic Forge <span style={{ color:CT.dim, fontWeight:400, fontSize:12, marginLeft:6 }}>&lt;agentic-forge@ledgerline.com&gt;</span></div>
                  <div style={{ fontSize:12, color:CT.gray, marginTop:1 }}>to demand-capture@ledgerline.com · just now</div>
                </div>
              </div>

              <AFChip skill="demand-intake" start={cardT - 0.4} />
              <div style={{ fontSize:14, color:CT.white, marginTop:14, marginBottom:6 }}><span style={{ fontFamily:T.mono, fontWeight:500 }}>REQ-047</span> created (draft)</div>
              <div style={{ fontSize:13, color:CT.gray, marginBottom:16 }}>Source: email from Sterling &amp; Associates via customer-success</div>

              <Card start={cardT} padding={20} style={{ marginBottom:0 }}>
                <div style={{ fontSize:15, color:CT.white, fontWeight:500, marginBottom:4 }}>REQ-047 · EU VAT calculation in export</div>
                <div style={{ height:1, background:CT.line, margin:'10px 0 16px' }} />

                <div style={{ fontSize:12, color:CT.gray, marginBottom:6, fontWeight:500 }}>Intent</div>
                <div style={{ fontSize:13, color:CT.white, lineHeight:1.55, marginBottom:18 }}>Add EU VAT calculation to invoice export. VAT rates per country, automated.</div>

                <div style={{ fontSize:12, color:CT.gray, marginBottom:8, fontWeight:500 }}>NFR dimensions auto-flagged</div>
                <ul style={{ margin:0, paddingLeft:0, listStyle:'none', display:'flex', flexDirection:'column', gap:8, marginBottom:18 }}>
                  <li style={{ fontSize:13, color:CT.white, lineHeight:1.5 }}>· <span style={{ fontWeight:500 }}>Regulatory</span> <span style={{ color:CT.gray }}>— EU VAT rules vary by country and product type</span></li>
                  <li style={{ fontSize:13, color:CT.white, lineHeight:1.5 }}>· <span style={{ fontWeight:500 }}>Localization</span> <span style={{ color:CT.gray }}>— country selection, currency formatting per locale</span></li>
                  <li style={{ fontSize:13, color:CT.white, lineHeight:1.5 }}>· <span style={{ fontWeight:500 }}>Deadline</span> <span style={{ color:CT.gray }}>— Q3 European launch</span></li>
                </ul>

                <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap:14, paddingTop:14, borderTop:`1px solid ${CT.line}` }}>
                  <div>
                    <div style={{ fontSize:11, color:CT.gray, marginBottom:3 }}>Status</div>
                    <div style={{ fontSize:13, color:CT.white }}>draft, awaiting PM triage</div>
                    <div style={{ fontSize:11, color:CT.gray, marginTop:8, marginBottom:3 }}>Routed to</div>
                    <div style={{ fontSize:13, color:CT.green, fontFamily:T.mono }}>USER-jessica (PM)</div>
                  </div>
                  <div>
                    <div style={{ fontSize:11, color:CT.gray, marginBottom:3 }}>Customer context</div>
                    <div style={{ fontSize:13, color:CT.white }}>Sterling &amp; Associates · existing client</div>
                    <div style={{ fontSize:11, color:CT.gray, marginTop:8, marginBottom:3 }}>Account</div>
                    <div style={{ fontSize:13, color:CT.white, fontFamily:T.mono }}>ACCOUNT-014</div>
                  </div>
                </div>
              </Card>
            </div>
          )}

          {/* Original forwarded email */}
          <div style={{ background:'#101319', border:'1px solid #1e2128', borderRadius:10, padding:'18px 22px' }}>
            <div style={{ display:'flex', alignItems:'center', gap:10, marginBottom:14 }}>
              <div style={{ width:30, height:30, borderRadius:15, background:'#7a4d2a', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, fontWeight:500 }}>C</div>
              <div style={{ flex:1 }}>
                <div style={{ fontSize:14, color:CT.white, fontWeight:500 }}>Casey Park <span style={{ color:CT.dim, fontWeight:400, fontSize:12, marginLeft:6 }}>&lt;customer-success@ledgerline.com&gt;</span></div>
                <div style={{ fontSize:12, color:CT.gray, marginTop:1 }}>to demand-capture@ledgerline.com · 8:42 AM</div>
              </div>
            </div>
            <div style={{ fontSize:14, color:CT.white, lineHeight:1.65, marginBottom:14 }}>
              Hi team — forwarding an email from Sterling &amp; Associates. They're expanding to Germany and France next quarter and want EU tax calculations in the export module. Hard requirement before their European launch in Q3.
            </div>
            <div style={{ fontSize:14, color:CT.gray, marginBottom:14 }}>— Casey, Customer Success</div>

            <div style={{ borderLeft:`2px solid ${CT.line}`, paddingLeft:14, marginTop:18 }}>
              <div style={{ fontSize:12, color:CT.dim, marginBottom:8 }}>▼ Original message</div>
              <div style={{ fontSize:13, color:CT.gray, lineHeight:1.65, marginBottom:10 }}>
                We're expanding to Germany and France next quarter. We need EU tax calculations in the export module — VAT rates per country, automated. Hard requirement before our European launch in Q3.
              </div>
              <div style={{ fontSize:13, color:CT.dim }}>— Sterling &amp; Associates</div>
            </div>
          </div>
        </div>
      </div>
      </div>
      <SurfaceLabel text="in email" sceneStart={sceneStart} />
    </div>
  );
}

// ════════════════════════════════════════════════════════════════
// SCENE 2 — Slack (42-82s)
// ════════════════════════════════════════════════════════════════
function SlackNavIcon({ kind }) {
  const s=18, sw=1.6, c='currentColor';
  switch(kind){
    case 'home': return <svg width={s} height={s} viewBox="0 0 18 18" fill="none"><path d="M3 8L9 3l6 5v7H3V8z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/><path d="M7 15v-4h4v4" stroke={c} strokeWidth={sw}/></svg>;
    case 'dm': return <svg width={s} height={s} viewBox="0 0 18 18" fill="none"><path d="M3 4h12v8H8l-3 3v-3H3V4z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
    case 'activity': return <svg width={s} height={s} viewBox="0 0 18 18" fill="none"><path d="M5 8c0-2.2 1.8-4 4-4s4 1.8 4 4v3l1 2H4l1-2V8z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/><path d="M8 14.5h2" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'later': return <svg width={s} height={s} viewBox="0 0 18 18" fill="none"><circle cx="9" cy="9" r="6" stroke={c} strokeWidth={sw}/><path d="M9 6v3l2 1.5" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'more': return <svg width={s} height={s} viewBox="0 0 18 18" fill="none"><circle cx="9" cy="3.5" r="1" fill={c}/><circle cx="9" cy="9" r="1" fill={c}/><circle cx="9" cy="14.5" r="1" fill={c}/></svg>;
  }
}
function SlackComposeIcon({ kind }) {
  const s=14, sw=1.4, c='currentColor';
  switch(kind){
    case 'link': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M6 8l2-2M5 3.5h-1.5c-1.1 0-2 .9-2 2s.9 2 2 2H6M8 10.5h1.5c1.1 0 2-.9 2-2s-.9-2-2-2H8" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'ol': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M5 4h7M5 7h7M5 10h7" stroke={c} strokeWidth={sw} strokeLinecap="round"/><text x="1" y="5" fontSize="3.5" fill={c} fontFamily="sans-serif">1</text><text x="1" y="8" fontSize="3.5" fill={c} fontFamily="sans-serif">2</text><text x="1" y="11" fontSize="3.5" fill={c} fontFamily="sans-serif">3</text></svg>;
    case 'ul': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M5 4h7M5 7h7M5 10h7" stroke={c} strokeWidth={sw} strokeLinecap="round"/><circle cx="2" cy="4" r="0.8" fill={c}/><circle cx="2" cy="7" r="0.8" fill={c}/><circle cx="2" cy="10" r="0.8" fill={c}/></svg>;
    case 'code': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M4 4L1.5 7L4 10M10 4l2.5 3-2.5 3" stroke={c} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/></svg>;
    case 'plus': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><circle cx="7" cy="7" r="5.5" stroke={c} strokeWidth={sw}/><path d="M7 4.5v5M4.5 7h5" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'video': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><rect x="1" y="4" width="8" height="6" rx="1" stroke={c} strokeWidth={sw}/><path d="M9 6l4-2v6l-4-2z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
    case 'mic': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><rect x="5" y="1.5" width="4" height="7" rx="2" stroke={c} strokeWidth={sw}/><path d="M3 7c0 2.2 1.8 4 4 4s4-1.8 4-4M7 11v2" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'emoji': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><circle cx="7" cy="7" r="5.5" stroke={c} strokeWidth={sw}/><circle cx="5" cy="6" r="0.7" fill={c}/><circle cx="9" cy="6" r="0.7" fill={c}/><path d="M4.5 9c.5 1 1.5 1.5 2.5 1.5s2-.5 2.5-1.5" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'mention': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><circle cx="7" cy="7" r="2.3" stroke={c} strokeWidth={sw}/><path d="M9.3 7v1.4c0 1 .8 1.5 1.5 1.5s1.5-.5 1.5-1.5C12.3 4 9.8 1.5 7 1.5S1.5 4 1.5 7s2.5 5.5 5.5 5.5c1.4 0 2.5-.4 3.4-1" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'send': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M2 7L12.5 2 9 12 7 8 2 7z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
  }
}
function Scene2({ sceneStart = 42 }) {
  const time = useTime();
  const reply1T = sceneStart + 6;
  const card1T = sceneStart + 7;
  const jessReplyT = sceneStart + 20;
  const reply2T = sceneStart + 26;

  return (
    <div style={{ position:'absolute', inset:0, background:CT.slackBg, display:'flex', flexDirection:'column' }}>
      {/* ── TOP BAR ──────────────────────────────────────── */}
      <div style={{ height:44, background:'#101214', borderBottom:'1px solid #2c2d30', display:'flex', alignItems:'center', padding:'0 16px', gap:8, flexShrink:0 }}>
        <div style={{ display:'flex', alignItems:'center', gap:2, color:'#abadb1' }}>
          <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M9 3L5 7l4 4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg></div>
          <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M5 3l4 4-4 4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg></div>
          <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><svg width="12" height="12" viewBox="0 0 12 12" fill="none"><path d="M3 4.5l3 3 3-3" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg></div>
        </div>
        <div style={{ flex:1, display:'flex', justifyContent:'center', padding:'0 16px' }}>
          <div style={{ background:'#222529', border:'1px solid #2c2d30', borderRadius:6, padding:'6px 12px', fontSize:13, color:'#abadb1', flex:1, maxWidth:760, display:'flex', alignItems:'center', gap:8 }}>
            <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
              <circle cx="6" cy="6" r="4" stroke="#abadb1" strokeWidth="1.4"/>
              <path d="M9 9l3 3" stroke="#abadb1" strokeWidth="1.4" strokeLinecap="round"/>
            </svg>
            <span>Search Ledgerline</span>
          </div>
        </div>
        <div style={{ display:'flex', alignItems:'center', gap:2, color:'#abadb1' }}>
          <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><circle cx="7" cy="7" r="5" stroke="currentColor" strokeWidth="1.4"/><path d="M5.5 5.5c0-.8.7-1.5 1.5-1.5s1.5.7 1.5 1.5c0 .5-.3.8-.7 1.1-.4.3-.6.5-.6 1M7 10v.01" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/></svg></div>
        </div>
      </div>

      <div style={{ flex:1, display:'flex', minHeight:0 }}>
        {/* ── WORKSPACE RAIL ──────────────────────────────── */}
        <div style={{ width:68, background:'#19171d', borderRight:'1px solid #2c2d30', flexShrink:0, display:'flex', flexDirection:'column', alignItems:'center', paddingTop:12, gap:8 }}>
          <div style={{ width:36, height:36, borderRadius:8, background:'#350d36', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:18, fontWeight:700 }}>L</div>
          <div style={{ width:36, height:36, borderRadius:8, border:'1px dashed #4a4a4a', color:'#9a9a9a', display:'flex', alignItems:'center', justifyContent:'center', fontSize:16 }}>+</div>
          <div style={{ width:32, height:1, background:'#2c2d30', margin:'8px 0 4px' }} />
          {[{k:'home',label:'Home',active:true},{k:'dm',label:'DMs'},{k:'activity',label:'Activity'},{k:'later',label:'Later'},{k:'more',label:'More'}].map(it => (
            <div key={it.k} style={{ width:52, display:'flex', flexDirection:'column', alignItems:'center', color: it.active ? '#fff' : '#abadb1', gap:4, marginBottom:8 }}>
              <SlackNavIcon kind={it.k} />
              <span style={{ fontSize:10, fontWeight:500 }}>{it.label}</span>
            </div>
          ))}
          <div style={{ flex:1 }} />
          <div style={{ width:32, height:32, borderRadius:16, background:'#3b5b7c', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, fontWeight:500, marginBottom:14 }}>J</div>
        </div>

        {/* sidebar */}
        <div style={{ width:240, background:'#19171d', borderRight:'1px solid #2c2d30', flexShrink:0, padding:'18px 14px', color:CT.slackText }}>
          <div style={{ fontSize:15, fontWeight:600, marginBottom:18 }}>Ledgerline</div>
          <div style={{ fontSize:13, color:'#abadb1', marginBottom:6, fontWeight:500 }}>Channels</div>
          {['general','engineering','design','#product-engineering','random'].map((c, i) => {
            const active = c === '#product-engineering';
            return (
              <div key={i} style={{
                padding:'4px 10px', borderRadius:4, fontSize:14,
                color: active ? '#fff' : '#abadb1',
                background: active ? '#1164a3' : 'transparent', marginBottom:1,
              }}>
                # {c.replace('#','')}
              </div>
            );
          })}
        </div>

        {/* main channel */}
        <div style={{ flex:1, display:'flex', flexDirection:'column' }}>
          <div style={{ height:50, borderBottom:'1px solid #2c2d30', display:'flex', alignItems:'center', padding:'0 24px', flexShrink:0 }}>
            <div style={{ fontSize:15, color:'#fff', fontWeight:600 }}># product-engineering</div>
            <div style={{ marginLeft:14, fontSize:12, color:CT.slackText }}>14 members</div>
          </div>

          <div style={{ flex:1, padding:'18px 24px', overflow:'auto' }}>
            {/* Jessica's original */}
            <div style={{ display:'flex', gap:10, marginBottom:16 }}>
              <div style={{ width:36, height:36, borderRadius:5, background:'#b8336a', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:14, fontWeight:600, flexShrink:0 }}>J</div>
              <div style={{ flex:1 }}>
                <div style={{ display:'flex', alignItems:'baseline', gap:8 }}>
                  <span style={{ fontSize:15, color:'#fff', fontWeight:700 }}>Jessica Chen</span>
                  <span style={{ fontSize:12, color:'#abadb1' }}>9:47 AM</span>
                </div>
                <div style={{ fontSize:15, color:CT.slackText, marginTop:3, lineHeight:1.5 }}>hey can we make the dashboard faster? clients keep complaining</div>
              </div>
            </div>

            {/* Thread reply 1 — Agentic Forge bot */}
            {time > reply1T - 0.2 && (
              <div style={{ display:'flex', gap:10, marginLeft:46, paddingLeft:14, borderLeft:'2px solid #3c3f44', marginBottom:14, opacity: fade(time, reply1T, 0.25), transform:`translateY(${slideUp(time, reply1T, 0.25, 6)}px)` }}>
                <div style={{ width:36, height:36, borderRadius:5, background:CT.charcoal, display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0 }}>
                  <span style={{ width:11, height:11, borderRadius:6, background:CT.green }} />
                </div>
                <div style={{ flex:1 }}>
                  <div style={{ display:'flex', alignItems:'baseline', gap:8 }}>
                    <span style={{ fontSize:15, color:'#fff', fontWeight:700 }}>Agentic Forge</span>
                    <span style={{ fontSize:9, background:'#3c3f44', color:CT.slackText, padding:'1px 4px', borderRadius:2, fontWeight:700, letterSpacing:'0.04em' }}>APP</span>
                    <span style={{ fontSize:12, color:'#abadb1' }}>9:47 AM</span>
                  </div>
                  <div style={{ marginTop:6 }}>
                    <AFChip skill="demand-intake" start={reply1T + 0.2} />
                    <div style={{ marginTop:10 }}>
                      <Card start={card1T} padding={16}>
                        <div style={{ fontSize:13.5, color:CT.white, lineHeight:1.6, marginBottom:14 }}>
                          I have a related item: <span style={{ fontFamily:T.mono, fontWeight:500 }}>STORY-044</span> (Dashboard loading optimization, High priority, blocked by <span style={{ fontFamily:T.mono, fontWeight:500 }}>DECISION-019</span> on caching strategy for 21 days).
                        </div>
                        <div style={{ fontSize:13.5, color:CT.white, marginBottom:8 }}>Are you reporting:</div>
                        <div style={{ display:'flex', flexDirection:'column', gap:6, marginBottom:6 }}>
                          <div style={{ fontSize:13.5, color:CT.white, lineHeight:1.55 }}>(a) New customer feedback to add to STORY-044's context, or</div>
                          <div style={{ fontSize:13.5, color:CT.white, lineHeight:1.55 }}>(b) Pressure to break the DECISION-019 blocker?</div>
                        </div>
                        <div style={{ fontSize:13, color:CT.gray, marginTop:10 }}>Pick one and I'll route accordingly.</div>
                      </Card>
                    </div>
                  </div>
                </div>
              </div>
            )}

            {/* Jessica reply */}
            {time > jessReplyT - 0.2 && (
              <div style={{ display:'flex', gap:10, marginLeft:46, paddingLeft:14, borderLeft:'2px solid #3c3f44', marginBottom:14, opacity: fade(time, jessReplyT, 0.25), transform:`translateY(${slideUp(time, jessReplyT, 0.25, 6)}px)` }}>
                <div style={{ width:36, height:36, borderRadius:5, background:'#b8336a', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:14, fontWeight:600, flexShrink:0 }}>J</div>
                <div style={{ flex:1 }}>
                  <div style={{ display:'flex', alignItems:'baseline', gap:8 }}>
                    <span style={{ fontSize:15, color:'#fff', fontWeight:700 }}>Jessica Chen</span>
                    <span style={{ fontSize:12, color:'#abadb1' }}>9:48 AM</span>
                  </div>
                  <div style={{ fontSize:15, color:CT.slackText, marginTop:3 }}>b. need to unblock that</div>
                </div>
              </div>
            )}

            {/* AF reply 2 */}
            {time > reply2T - 0.2 && (
              <div style={{ display:'flex', gap:10, marginLeft:46, paddingLeft:14, borderLeft:'2px solid #3c3f44', opacity: fade(time, reply2T, 0.25), transform:`translateY(${slideUp(time, reply2T, 0.25, 6)}px)` }}>
                <div style={{ width:36, height:36, borderRadius:5, background:CT.charcoal, display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0 }}>
                  <span style={{ width:11, height:11, borderRadius:6, background:CT.green }} />
                </div>
                <div style={{ flex:1 }}>
                  <div style={{ display:'flex', alignItems:'baseline', gap:8 }}>
                    <span style={{ fontSize:15, color:'#fff', fontWeight:700 }}>Agentic Forge</span>
                    <span style={{ fontSize:9, background:'#3c3f44', color:CT.slackText, padding:'1px 4px', borderRadius:2, fontWeight:700 }}>APP</span>
                    <span style={{ fontSize:12, color:'#abadb1' }}>9:48 AM</span>
                  </div>
                  <div style={{ marginTop:6 }}>
                    <AFChip skill="escalation routed" start={reply2T + 0.2} />
                    <div style={{ marginTop:10 }}>
                      <Card start={reply2T + 0.6} accent={CT.green} padding={16}>
                        <div style={{ fontSize:13.5, color:CT.white, lineHeight:1.65, marginBottom:10 }}>
                          Recorded. Notifying decision owner <span style={{ fontFamily:T.mono }}>USER-alex</span> (CTO) of escalation.
                        </div>
                        <div style={{ fontSize:13.5, color:CT.white, lineHeight:1.65 }}>
                          <span style={{ fontFamily:T.mono, fontWeight:500 }}>DECISION-019</span> will appear at top of Alex's intelligence surface tomorrow morning with escalation flag and cost-of-delay update <span style={{ color:CT.red }}>($31K/week, now 21 days)</span>.
                        </div>
                      </Card>
                    </div>
                  </div>
                </div>
              </div>
            )}
          </div>

          {/* ── COMPOSE BOX ───────────────────────────────── */}
          <div style={{ padding:'0 20px 20px', flexShrink:0 }}>
            <div style={{ border:'1px solid #565856', borderRadius:8, background:'#222529', overflow:'hidden' }}>
              <div style={{ display:'flex', alignItems:'center', gap:2, padding:'6px 10px', borderBottom:'1px solid #2c2d30', color:'#abadb1' }}>
                <div style={{ width:28, height:24, display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, fontWeight:700 }}>B</div>
                <div style={{ width:28, height:24, display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, fontStyle:'italic' }}>I</div>
                <div style={{ width:28, height:24, display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, textDecoration:'line-through' }}>S</div>
                <div style={{ width:1, height:16, background:'#3c3f44', margin:'0 6px' }} />
                {['link','ol','ul','code'].map(k => (
                  <div key={k} style={{ width:28, height:24, display:'flex', alignItems:'center', justifyContent:'center' }}><SlackComposeIcon kind={k} /></div>
                ))}
              </div>
              <div style={{ padding:'14px', fontSize:14, color:'#9a9a9a' }}>Message #product-engineering</div>
              <div style={{ display:'flex', alignItems:'center', gap:4, padding:'6px 10px', color:'#abadb1' }}>
                {['plus','video','mic','emoji','mention'].map(k => (
                  <div key={k} style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><SlackComposeIcon kind={k} /></div>
                ))}
                <div style={{ flex:1 }} />
                <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><SlackComposeIcon kind="send" /></div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <SurfaceLabel text="in Slack" sceneStart={sceneStart} />
    </div>
  );
}

// ════════════════════════════════════════════════════════════════
// SCENE 3 — Figma → story comment thread (82-122s)
// ════════════════════════════════════════════════════════════════
function Scene3({ sceneStart = 82 }) {
  const time = useTime();
  const figmaPhase = time < sceneStart + 8;

  return figmaPhase ? <Scene3Figma sceneStart={sceneStart} /> : <Scene3Story sceneStart={sceneStart} />;
}

function FigmaLogo() {
  return (
    <svg width="14" height="20" viewBox="0 0 14 20" fill="none">
      <path d="M0 3.33C0 1.49 1.49 0 3.33 0H7v6.67H3.33C1.49 6.67 0 5.18 0 3.33z" fill="#f24e1e"/>
      <path d="M7 0h3.67c1.84 0 3.33 1.49 3.33 3.33s-1.49 3.33-3.33 3.33H7V0z" fill="#ff7262"/>
      <path d="M0 10c0-1.84 1.49-3.33 3.33-3.33H7v6.67H3.33C1.49 13.33 0 11.84 0 10z" fill="#a259ff"/>
      <circle cx="10.67" cy="10" r="3.33" fill="#1abcfe"/>
      <circle cx="3.33" cy="16.67" r="3.33" fill="#0acf83"/>
    </svg>
  );
}
function FigmaToolIcon({ kind }) {
  const s=14, sw=1.6, c='currentColor';
  switch(kind){
    case 'move': return <svg width={s} height={s} viewBox="0 0 14 14" fill={c}><path d="M2 1l4 11 1.5-4 4-1.5L2 1z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
    case 'frame': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M4 1v12M10 1v12M1 4h12M1 10h12" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'shape': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><rect x="2" y="2" width="10" height="10" rx="1" stroke={c} strokeWidth={sw}/></svg>;
    case 'pen': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M2 12l8-8 2 2-8 8H2v-2z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
    case 'text': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M2 3h10M7 3v9" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
    case 'hand': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M5 6V3.5a1.2 1.2 0 0 1 2.4 0V6M7.4 6V2.8a1.2 1.2 0 0 1 2.4 0V6M9.8 6V4a1.2 1.2 0 0 1 2.4 0v5.5c0 2-1.2 3.5-3.4 3.5H6.5L3 9.5l.8-.8 1.2.7V4.5a1.2 1.2 0 0 1 2.4 0V6" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
    case 'comment': return <svg width={s} height={s} viewBox="0 0 14 14" fill="none"><path d="M2 3h10v7H7l-3 2v-2H2V3z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
  }
}
function FigmaLayerIcon({ kind }) {
  const s=10, sw=1.3, c='currentColor';
  switch(kind){
    case 'frame': return <svg width={s} height={s} viewBox="0 0 10 10" fill="none"><rect x="1" y="1" width="8" height="8" stroke={c} strokeWidth={sw}/></svg>;
    case 'component': return <svg width={s} height={s} viewBox="0 0 10 10" fill="none"><path d="M5 1l4 4-4 4-4-4 4-4z" stroke={c} strokeWidth={sw} strokeLinejoin="round"/></svg>;
    case 'text': return <svg width={s} height={s} viewBox="0 0 10 10" fill="none"><path d="M2 2h6M5 2v7" stroke={c} strokeWidth={sw} strokeLinecap="round"/></svg>;
  }
}
function Scene3Figma({ sceneStart }) {
  const time = useTime();
  return (
    <div style={{ position:'absolute', inset:0, background:'#1e1e1e', display:'flex', flexDirection:'column' }}>
      {/* ── FIGMA TOP BAR ─────────────────────────────────── */}
      <div style={{ height:44, background:'#2c2c2c', borderBottom:'1px solid #383838', display:'flex', alignItems:'center', padding:'0 12px', gap:10, flexShrink:0 }}>
        <div style={{ display:'flex', alignItems:'center', gap:10 }}>
          <FigmaLogo />
          <svg width="10" height="10" viewBox="0 0 10 10" fill="none"><path d="M2 4l3 3 3-3" stroke="#bbb" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg>
          <div style={{ fontSize:13, color:'#fff', fontWeight:500 }}>Ledgerline · Manual retry button v3</div>
        </div>
        <div style={{ flex:1 }} />
        <div style={{ display:'flex', alignItems:'center', gap:8 }}>
          <div style={{ display:'flex' }}>
            {[{bg:'#b8336a',l:'J'},{bg:'#7a4d2a',l:'C'},{bg:'#3b5b7c',l:'A'}].map((a, i) => (
              <div key={i} style={{ width:26, height:26, borderRadius:13, background:a.bg, color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:11, fontWeight:600, border:'2px solid #2c2c2c', marginLeft: i === 0 ? 0 : -8 }}>{a.l}</div>
            ))}
          </div>
          <div style={{ width:32, height:32, display:'flex', alignItems:'center', justifyContent:'center', color:'#bbb' }}>
            <FigmaToolIcon kind="comment" />
          </div>
          <div style={{ background:'#0d99ff', color:'#fff', padding:'5px 14px', borderRadius:4, fontSize:13, fontWeight:500 }}>Share</div>
        </div>
      </div>

      <div style={{ flex:1, display:'flex', minHeight:0 }}>
        {/* ── LEFT SIDEBAR ─────────────────────────────────── */}
        <div style={{ width:240, background:'#2c2c2c', borderRight:'1px solid #383838', display:'flex', flexDirection:'column', flexShrink:0 }}>
          <div style={{ display:'flex', borderBottom:'1px solid #383838', flexShrink:0 }}>
            <div style={{ flex:1, padding:'10px 0', textAlign:'center', fontSize:12, color:'#fff', fontWeight:500, borderBottom:'2px solid #fff', marginBottom:-1 }}>File</div>
            <div style={{ flex:1, padding:'10px 0', textAlign:'center', fontSize:12, color:'#888' }}>Assets</div>
          </div>
          <div style={{ padding:'10px 14px', borderBottom:'1px solid #383838', flexShrink:0 }}>
            <div style={{ fontSize:10, color:'#888', marginBottom:6, display:'flex', alignItems:'center', gap:4, letterSpacing:'0.05em' }}>
              <span style={{ fontSize:9 }}>▾</span> PAGES
            </div>
            <div style={{ fontSize:12, color:'#fff', padding:'3px 8px', background:'#383838', borderRadius:3 }}>Page 1</div>
          </div>
          <div style={{ padding:'10px 14px', flex:1, overflow:'auto' }}>
            <div style={{ fontSize:10, color:'#888', marginBottom:6, display:'flex', alignItems:'center', gap:4, letterSpacing:'0.05em' }}>
              <span style={{ fontSize:9 }}>▾</span> LAYERS
            </div>
            {[
              {d:0, k:'frame', n:'Frame · STORY-046'},
              {d:1, k:'component', n:'RetryButton'},
              {d:2, k:'frame', n:'default'},
              {d:2, k:'frame', n:'hover'},
              {d:2, k:'frame', n:'active'},
              {d:2, k:'frame', n:'disabled'},
              {d:2, k:'frame', n:'loading'},
              {d:1, k:'frame', n:'ConfirmationModal'},
              {d:1, k:'text', n:'FailureReasonText'},
            ].map((l, i) => (
              <div key={i} style={{ display:'flex', alignItems:'center', gap:6, padding:'3px 0', paddingLeft: l.d * 14, fontSize:12, color:'#ccc' }}>
                <span style={{ color: l.k === 'component' ? '#a259ff' : '#888', display:'flex' }}><FigmaLayerIcon kind={l.k} /></span>
                <span>{l.n}</span>
              </div>
            ))}
          </div>
        </div>

        {/* canvas */}
        <div style={{ flex:1, background:'#1e1e1e', position:'relative', display:'flex', alignItems:'center', justifyContent:'center', padding:24, overflow:'hidden' }}>
          <div style={{ display:'grid', gridTemplateColumns:'repeat(3, 1fr)', gap:36 }}>
            {[
              ['default','Retry'], ['hover','Retry'], ['active','Retry'],
              ['disabled','Retry'], ['loading','Retrying…'], ['modal','Confirm retry?'],
            ].map(([state, label], i) => (
              <div key={i} style={{ display:'flex', flexDirection:'column', alignItems:'center', gap:10 }}>
                <div style={{ fontSize:11, color:'#888', fontFamily:T.mono }}>{state}</div>
                {state === 'modal' ? (
                  <div style={{ width:200, padding:18, background:'#fff', borderRadius:6, boxShadow:'0 8px 24px rgba(0,0,0,0.4)' }}>
                    <div style={{ fontSize:13, color:'#222', fontWeight:600, marginBottom:8 }}>{label}</div>
                    <div style={{ fontSize:11, color:'#666', marginBottom:14 }}>Failure reason text shown here…</div>
                    <div style={{ display:'flex', gap:6, justifyContent:'flex-end' }}>
                      <div style={{ fontSize:11, padding:'4px 10px', borderRadius:4, color:'#666' }}>Cancel</div>
                      <div style={{ fontSize:11, padding:'4px 10px', borderRadius:4, background:'#f4b400', color:'#fff' }}>Retry</div>
                    </div>
                  </div>
                ) : (
                  <div style={{
                    background: state === 'disabled' ? '#3a3a3a' : (state === 'active' ? '#c89b00' : '#f4b400'),
                    color: state === 'disabled' ? '#777' : '#fff',
                    padding:'8px 18px', borderRadius:5, fontSize:13, fontWeight:500,
                    border: state === 'hover' ? '2px solid #fff' : '2px solid transparent',
                    opacity: state === 'loading' ? 0.85 : 1,
                  }}>{label}</div>
                )}
              </div>
            ))}
          </div>

          {/* cursor + share dialog appearing */}
          {time > sceneStart + 4 && (
            <div style={{ position:'absolute', top:60, right:60, background:'#2c2c2c', border:'1px solid #444', borderRadius:8, padding:'12px 14px', width:280, opacity: fade(time, sceneStart + 4, 0.3) }}>
              <div style={{ fontSize:12, color:'#bbb', marginBottom:8 }}>Share with developers</div>
              <div style={{ background:'#1e1e1e', border:'1px solid #444', borderRadius:4, padding:'7px 10px', fontSize:11, color:'#fff', fontFamily:T.mono, marginBottom:8 }}>figma.com/file/Lx7…/STORY-046</div>
              <div style={{ fontSize:11, color:'#0acf83' }}>✓ Copied</div>
            </div>
          )}

          {/* ── FLOATING TOOLBAR (bottom center) ─────────── */}
          <div style={{ position:'absolute', bottom:16, left:'50%', transform:'translateX(-50%)', background:'#2c2c2c', border:'1px solid #444', borderRadius:8, padding:6, display:'flex', alignItems:'center', gap:2, boxShadow:'0 4px 16px rgba(0,0,0,0.4)' }}>
            {[{k:'move',active:true},{k:'frame'},{k:'shape'},{k:'pen'},{k:'text'},{k:'comment'}].map(t => (
              <div key={t.k} style={{ width:36, height:36, display:'flex', alignItems:'center', justifyContent:'center', borderRadius:6, background: t.active ? '#0d99ff' : 'transparent', color: t.active ? '#fff' : '#bbb' }}>
                <FigmaToolIcon kind={t.k} />
              </div>
            ))}
          </div>
        </div>

        {/* right — figma comments */}
        <div style={{ width:240, background:'#2c2c2c', borderLeft:'1px solid #383838', padding:'12px 10px' }}>
          <div style={{ fontSize:12, fontWeight:500, color:'#fff', marginBottom:10 }}>Comments</div>
          <div style={{ fontSize:11, color:'#888' }}>No comments yet</div>
        </div>
      </div>
      <SurfaceLabel text="in Figma" sceneStart={sceneStart} />
    </div>
  );
}

function Scene3Story({ sceneStart }) {
  const time = useTime();
  const subSceneStart = sceneStart + 8;
  const pasteT = subSceneStart + 1.5;
  const commentT = subSceneStart + 4;
  const cardT = subSceneStart + 5;
  const rachelT = subSceneStart + 24;

  return (
    <div style={{ position:'absolute', inset:0, background:CT.carbon, display:'flex', flexDirection:'column' }}>
      <BrowserBar url="forge.ledgerline.com/work/STORY-046" />
      <div style={{ flex:1, display:'flex', minHeight:0 }}>
        <div style={{ width:48, background:CT.bgDim, borderRight:`1px solid ${CT.line}`, flexShrink:0 }} />

        <div style={{ flex:1, padding:'24px 36px', overflow:'auto' }}>
          <div style={{ fontSize:13, color:CT.gray, marginBottom:6 }}>
            <span>Work</span><span style={{ margin:'0 8px', color:CT.dim }}>›</span>
            <span style={{ fontFamily:T.mono, color:CT.white }}>STORY-046</span>
          </div>
          <div style={{ fontSize:24, color:CT.white, fontWeight:500, marginBottom:18, letterSpacing:'-0.01em' }}>Manual retry button</div>

          {/* attachment bar */}
          <Card padding={14} style={{ marginBottom:22 }}>
            <div style={{ display:'flex', alignItems:'center', gap:12 }}>
              <div style={{ fontSize:12, color:CT.gray }}>Attached design</div>
              <div style={{ flex:1, background:CT.bgDim, border:`1px solid ${CT.line}`, borderRadius:4, padding:'6px 10px', fontSize:12, fontFamily:T.mono, color: time > pasteT ? CT.white : CT.dim }}>
                {time > pasteT ? 'figma.com/file/Lx7…/STORY-046' : 'Paste a Figma URL…'}
              </div>
              {time > pasteT && time < pasteT + 1.5 && (
                <div style={{ display:'flex', gap:4 }}>
                  {[0,1,2].map(i => <div key={i} style={{ width:5, height:5, borderRadius:3, background:CT.green, opacity: 0.4 + 0.6 * (0.5 + 0.5 * Math.sin(time*5 - i*0.7)) }} />)}
                </div>
              )}
              {time > pasteT + 1.5 && <div style={{ fontSize:12, color:CT.green }}>✓ Linked</div>}
            </div>
          </Card>

          <div style={{ fontSize:14, color:CT.white, fontWeight:500, marginBottom:14 }}>Comments</div>

          {/* AF comment */}
          {time > commentT - 0.2 && (
            <div style={{ display:'flex', gap:12, marginBottom:18, opacity: fade(time, commentT, 0.3), transform:`translateY(${slideUp(time, commentT, 0.3, 6)}px)` }}>
              <div style={{ width:34, height:34, borderRadius:17, background:CT.charcoal, display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0 }}>
                <span style={{ width:10, height:10, borderRadius:5, background:CT.green }} />
              </div>
              <div style={{ flex:1 }}>
                <div style={{ display:'flex', alignItems:'baseline', gap:8, marginBottom:8 }}>
                  <span style={{ fontSize:14, color:CT.white, fontWeight:500 }}>Agentic Forge</span>
                  <span style={{ fontSize:12, color:CT.gray }}>just now</span>
                </div>
                <AFChip skill="design-asset-decomposition" start={commentT + 0.1} />
                <div style={{ fontSize:14, color:CT.white, marginTop:12, marginBottom:14 }}>Design decomposed for STORY-046.</div>

                <Card start={cardT} padding={20} style={{ maxWidth:680 }}>
                  <div style={{ fontSize:13, color:CT.gray, marginBottom:8, fontWeight:500 }}>Components identified</div>
                  <div style={{ display:'flex', flexDirection:'column', gap:10, marginBottom:18 }}>
                    <Comp name="RetryButton" detail="matches design system: Button.Warning" />
                    <Comp name="FailureReasonText" detail="NEW component · flag for design system review" warn />
                    <Comp name="ConfirmationModal" detail="matches design system: Modal.Confirm" />
                  </div>

                  <div style={{ height:1, background:CT.line, marginBottom:14 }} />

                  <div style={{ fontSize:13, color:CT.gray, marginBottom:6, fontWeight:500 }}>States visible</div>
                  <div style={{ fontSize:13, color:CT.white, fontFamily:T.mono, marginBottom:18 }}>default · hover · active · disabled · loading</div>

                  <div style={{ height:1, background:CT.line, marginBottom:14 }} />

                  <div style={{ display:'flex', alignItems:'flex-start', gap:8, marginBottom:10 }}>
                    <span style={{ fontSize:14, color:CT.red }}>⚠</span>
                    <div style={{ fontSize:14, color:CT.white }}>
                      <span style={{ color:CT.red, fontWeight:500 }}>Missing</span> state: <span style={{ fontWeight:500 }}>error</span>
                    </div>
                  </div>
                  <div style={{ fontSize:13, color:CT.gray, lineHeight:1.6, paddingLeft:22, marginBottom:14 }}>
                    No artboard for the case where retry itself fails (retry of retry).
                  </div>
                  <div style={{ fontSize:13, color:CT.gray, lineHeight:1.6, paddingLeft:22 }}>
                    <span style={{ color:CT.white, fontWeight:500 }}>Suggestion: </span>render the same modal with an updated failure count and a "contact support" link.
                  </div>
                </Card>
              </div>
            </div>
          )}

          {/* Rachel reply */}
          {time > rachelT - 0.2 && (
            <div style={{ display:'flex', gap:12, opacity: fade(time, rachelT, 0.3), transform:`translateY(${slideUp(time, rachelT, 0.3, 6)}px)` }}>
              <div style={{ width:34, height:34, borderRadius:17, background:'#7e3b8c', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, fontWeight:500, flexShrink:0 }}>R</div>
              <div style={{ flex:1 }}>
                <div style={{ display:'flex', alignItems:'baseline', gap:8, marginBottom:6 }}>
                  <span style={{ fontSize:14, color:CT.white, fontWeight:500 }}>Rachel Kim</span>
                  <span style={{ fontSize:12, color:CT.gray }}>just now</span>
                </div>
                <div style={{ fontSize:14, color:CT.white, lineHeight:1.55 }}>good catch — I'll update the figma. exactly what I'd want for the failed-retry path</div>
              </div>
            </div>
          )}
        </div>
      </div>
      <SurfaceLabel text="in the framework · STORY-046" sceneStart={subSceneStart} />
    </div>
  );
}

function Comp({ name, detail, warn }) {
  return (
    <div>
      <div style={{ fontSize:13, color:warn ? CT.amber : CT.white, fontWeight:500, marginBottom:2, fontFamily:T.mono }}>· {name}</div>
      <div style={{ fontSize:12, color:CT.gray, paddingLeft:14, lineHeight:1.5 }}>{detail}</div>
    </div>
  );
}
function BrowserBar({ url }) {
  return (
    <div style={{ height:42, background:'#14171d', borderBottom:'1px solid #1e2128', display:'flex', alignItems:'center', padding:'0 14px', gap:14, flexShrink:0 }}>
      <div style={{ display:'flex', gap:8 }}>
        <div style={{ width:12, height:12, borderRadius:6, background:'#ff5f57' }} />
        <div style={{ width:12, height:12, borderRadius:6, background:'#febc2e' }} />
        <div style={{ width:12, height:12, borderRadius:6, background:'#28c840' }} />
      </div>
      <div style={{ flex:1, display:'flex', justifyContent:'center' }}>
        <div style={{ background:'#0a0d12', border:'1px solid #1e2128', borderRadius:6, padding:'5px 14px', fontSize:12, color:CT.gray, fontFamily:T.mono, minWidth:480, textAlign:'center' }}>
          <span style={{ color:CT.dim }}>🔒 </span>{url}
        </div>
      </div>
      <div style={{ width:60 }} />
    </div>
  );
}

// ════════════════════════════════════════════════════════════════
// SCENE 4 — IDE split + Slack DM + intel cut (122-168s)
// ════════════════════════════════════════════════════════════════
function Scene4({ sceneStart = 122 }) {
  const time = useTime();
  // 0-34: split IDE; 34-48: slack DM; 48-58: split IDE resolution; 58-end: intel cut
  // Adjusted: scene is 46s
  const phaseT = time - sceneStart;
  if (phaseT < 18) return <Scene4IDE sceneStart={sceneStart} mode="conflict" />;
  if (phaseT < 32) return <Scene4SlackDM sceneStart={sceneStart + 18} />;
  if (phaseT < 40) return <Scene4IDE sceneStart={sceneStart + 32} mode="resolved" />;
  return <Scene4Intel sceneStart={sceneStart + 40} />;
}

function IDEHalf({ name, branch, lines, color, isMaria, conflictT, resolvedT, mode }) {
  const time = useTime();
  return (
    <div style={{ flex:1, display:'flex', flexDirection:'column', background:'#1e1e1e', minWidth:0 }}>
      {/* tab bar */}
      <div style={{ height:32, background:'#252526', borderBottom:'1px solid #181818', display:'flex', alignItems:'center', flexShrink:0 }}>
        <div style={{ padding:'6px 14px', background:'#1e1e1e', fontSize:12, color:'#fff', borderRight:'1px solid #181818' }}>auth.ts <span style={{ color:'#f4b400', marginLeft:6 }}>●</span></div>
      </div>
      {/* header */}
      <div style={{ padding:'10px 16px', borderBottom:'1px solid #181818', display:'flex', alignItems:'center', gap:10, flexShrink:0 }}>
        <div style={{ width:24, height:24, borderRadius:12, background:color, color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:11, fontWeight:600 }}>{name[0]}</div>
        <div>
          <div style={{ fontSize:12, color:'#fff', fontWeight:500 }}>{name}</div>
          <div style={{ fontSize:10, color:'#888', fontFamily:T.mono }}>{branch}</div>
        </div>
      </div>
      {/* code */}
      <div style={{ flex:1, padding:'12px 14px', fontFamily:T.mono, fontSize:11.5, color:'#d4d4d4', lineHeight:1.55, overflow:'hidden', display:'flex' }}>
        <div style={{ color:'#555', textAlign:'right', paddingRight:10, userSelect:'none' }}>
          {lines.map((_, i) => <div key={i}>{i + 22}</div>)}
        </div>
        <div style={{ flex:1 }}>
          {lines.map((l, i) => (
            <div key={i} style={{ background: l.hl ? 'rgba(244, 180, 0, 0.08)' : 'transparent', paddingLeft:6 }}>
              <span style={{ color:l.kw ? '#569cd6' : '#d4d4d4' }}>{l.text}</span>
            </div>
          ))}
        </div>
      </div>

      {/* Copilot Chat panel */}
      <div style={{ height:280, background:'#252526', borderTop:'1px solid #181818', flexShrink:0, display:'flex', flexDirection:'column' }}>
        <div style={{ padding:'7px 14px', fontSize:11, color:'#aaa', borderBottom:'1px solid #181818', display:'flex', alignItems:'center', gap:8 }}>
          <span>Copilot Chat</span>
          <span style={{ marginLeft:'auto', display:'flex', alignItems:'center', gap:6, color:CT.green, fontSize:10 }}>
            <span style={{ width:5, height:5, borderRadius:3, background:CT.green }} />
            Agentic Forge connected
          </span>
        </div>

        <div style={{ flex:1, padding:'12px 14px', overflow:'hidden' }}>
          {mode === 'conflict' && time > conflictT - 0.2 && (
            <div style={{ opacity: fade(time, conflictT, 0.25), transform:`translateY(${slideUp(time, conflictT, 0.25, 6)}px)` }}>
              <AFChip skill="conflict-detection" start={conflictT + 0.1} />
              <div style={{ fontSize:12, color:CT.white, marginTop:10, marginBottom:10 }}>
                In-flight conflict detected (severity: <span style={{ color:CT.red, fontWeight:500 }}>HIGH</span>).
              </div>
              <Card start={conflictT + 0.5} padding={12} style={{ fontSize:11 }}>
                <div style={{ fontSize:11.5, color:CT.white, fontFamily:T.mono, marginBottom:8 }}>src/middleware/auth.ts</div>
                <div style={{ height:1, background:CT.line, marginBottom:10 }} />
                <div style={{ fontSize:10.5, color:CT.gray, marginBottom:2 }}>Carlos</div>
                <div style={{ fontSize:10.5, color:CT.white, fontFamily:T.mono, marginBottom:1 }}>feature/STORY-035-fastify-auth</div>
                <div style={{ fontSize:10.5, color:CT.gray, marginBottom:8 }}>147 lines changed</div>
                <div style={{ fontSize:10.5, color:CT.gray, marginBottom:2 }}>Maria</div>
                <div style={{ fontSize:10.5, color:CT.white, fontFamily:T.mono, marginBottom:1 }}>feature/STORY-035-helper-fns</div>
                <div style={{ fontSize:10.5, color:CT.gray, marginBottom:10 }}>38 lines changed</div>
                <div style={{ height:1, background:CT.line, marginBottom:10 }} />
                <div style={{ fontSize:10.5, color:CT.amber, marginBottom:2 }}>Overlap: lines 24–67</div>
                <div style={{ fontSize:10.5, color:CT.gray, marginBottom:10 }}>Both branches modify the same regions.</div>
                <div style={{ fontSize:10.5, color:CT.gray, marginBottom:2 }}>Suggested action</div>
                <div style={{ fontSize:11, color:CT.green, fontWeight:500 }}>Sync now to avoid rework at merge time.</div>
              </Card>
            </div>
          )}
          {mode === 'resolved' && (
            <div style={{ opacity: fade(time, resolvedT, 0.3) }}>
              <AFChip skill="work coordination updated" start={resolvedT + 0.1} />
              <div style={{ fontSize:12, color:CT.white, marginTop:12, lineHeight:1.6 }}>
                {isMaria ? (
                  <>You've been reassigned to <span style={{ fontFamily:T.mono }}>STORY-052</span> (test fixtures).<br/>Carlos will complete <span style={{ fontFamily:T.mono }}>STORY-035</span> first.<br/>Your <span style={{ fontFamily:T.mono }}>STORY-035-helper-fns</span> branch parked, will rebase at completion.</>
                ) : (
                  <>You'll complete <span style={{ fontFamily:T.mono }}>STORY-035</span> first.<br/>Maria reassigned to <span style={{ fontFamily:T.mono }}>STORY-052</span> (test fixtures).<br/>Her <span style={{ fontFamily:T.mono }}>STORY-035-helper-fns</span> branch parked, will rebase at completion.</>
                )}
              </div>
              <div style={{ fontSize:13, color:CT.green, fontWeight:500, marginTop:12 }}>Conflict cleared.</div>
            </div>
          )}
        </div>
      </div>
    </div>
  );
}

const carlosLines = [
  { text:'export class AuthMiddleware {' },
  { text:'  async handle(req, reply) {', hl:true },
  { text:'    const token = req.headers.authorization?', hl:true },
  { text:'      .replace("Bearer ", "");', hl:true },
  { text:'    if (!token) return reply.code(401);', hl:true },
  { text:'    const decoded = await verify(token, SECRET);', hl:true },
  { text:'    req.user = decoded;', hl:true },
  { text:'  }', hl:true },
  { text:'}' },
  { text:'' },
  { text:'export function requireRole(role) {' },
  { text:'  return async (req, reply) => {' },
  { text:'    if (req.user?.role !== role)' },
];
const mariaLines = [
  { text:'function extractToken(req) {' },
  { text:'  return req.headers.authorization?', hl:true },
  { text:'    .replace("Bearer ", "");', hl:true },
  { text:'}', hl:true },
  { text:'' },
  { text:'function checkScope(token, scope) {' },
  { text:'  return token.scopes?.includes(scope);' },
  { text:'}' },
  { text:'' },
  { text:'export async function authMiddleware(req, reply) {', hl:true },
  { text:'  const token = extractToken(req);', hl:true },
  { text:'  if (!token) return reply.code(401);', hl:true },
  { text:'  // ...' },
];

function Scene4IDE({ sceneStart, mode }) {
  return (
    <div style={{ position:'absolute', inset:0, background:'#1e1e1e', display:'flex', flexDirection:'column' }}>
      {/* unified VS Code chrome */}
      <div style={{ height:36, background:'#3c3c3c', display:'flex', alignItems:'center', padding:'0 14px', flexShrink:0 }}>
        <div style={{ display:'flex', gap:7 }}>
          <div style={{ width:11, height:11, borderRadius:6, background:'#ff5f57' }} />
          <div style={{ width:11, height:11, borderRadius:6, background:'#febc2e' }} />
          <div style={{ width:11, height:11, borderRadius:6, background:'#28c840' }} />
        </div>
        <div style={{ marginLeft:18, fontSize:12, color:'#ccc' }}>auth.ts — Ledgerline / platform</div>
      </div>
      <div style={{ flex:1, display:'flex', minHeight:0 }}>
        <IDEHalf name="Carlos Mendoza" branch="feature/STORY-035-fastify-auth" lines={carlosLines} color="#5b8def" mode={mode}
          conflictT={sceneStart + 6} resolvedT={sceneStart + 1} />
        <div style={{ width:1, background:'#181818' }} />
        <IDEHalf name="Maria Liu" branch="feature/STORY-035-helper-fns" lines={mariaLines} color="#22c55e" isMaria mode={mode}
          conflictT={sceneStart + 6} resolvedT={sceneStart + 1} />
      </div>
      <SurfaceLabel text="in VS Code · 2 engineers" sceneStart={sceneStart} />
    </div>
  );
}

function Scene4SlackDM({ sceneStart }) {
  const time = useTime();
  const m1T = sceneStart + 1;
  const m2T = sceneStart + 6;
  return (
    <div style={{ position:'absolute', inset:0, background:CT.slackBg, display:'flex', flexDirection:'column' }}>
      {/* ── TOP BAR ──────────────────────────────────────── */}
      <div style={{ height:44, background:'#101214', borderBottom:'1px solid #2c2d30', display:'flex', alignItems:'center', padding:'0 16px', gap:8, flexShrink:0 }}>
        <div style={{ display:'flex', alignItems:'center', gap:2, color:'#abadb1' }}>
          <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M9 3L5 7l4 4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg></div>
          <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M5 3l4 4-4 4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg></div>
          <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><svg width="12" height="12" viewBox="0 0 12 12" fill="none"><path d="M3 4.5l3 3 3-3" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg></div>
        </div>
        <div style={{ flex:1, display:'flex', justifyContent:'center', padding:'0 16px' }}>
          <div style={{ background:'#222529', border:'1px solid #2c2d30', borderRadius:6, padding:'6px 12px', fontSize:13, color:'#abadb1', flex:1, maxWidth:760, display:'flex', alignItems:'center', gap:8 }}>
            <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
              <circle cx="6" cy="6" r="4" stroke="#abadb1" strokeWidth="1.4"/>
              <path d="M9 9l3 3" stroke="#abadb1" strokeWidth="1.4" strokeLinecap="round"/>
            </svg>
            <span>Search Ledgerline</span>
          </div>
        </div>
        <div style={{ display:'flex', alignItems:'center', gap:2, color:'#abadb1' }}>
          <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><circle cx="7" cy="7" r="5" stroke="currentColor" strokeWidth="1.4"/><path d="M5.5 5.5c0-.8.7-1.5 1.5-1.5s1.5.7 1.5 1.5c0 .5-.3.8-.7 1.1-.4.3-.6.5-.6 1M7 10v.01" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/></svg></div>
        </div>
      </div>

      <div style={{ flex:1, display:'flex', minHeight:0 }}>
        {/* ── WORKSPACE RAIL ─────────────────────────────── */}
        <div style={{ width:68, background:'#19171d', borderRight:'1px solid #2c2d30', flexShrink:0, display:'flex', flexDirection:'column', alignItems:'center', paddingTop:12, gap:8 }}>
          <div style={{ width:36, height:36, borderRadius:8, background:'#350d36', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:18, fontWeight:700 }}>L</div>
          <div style={{ width:36, height:36, borderRadius:8, border:'1px dashed #4a4a4a', color:'#9a9a9a', display:'flex', alignItems:'center', justifyContent:'center', fontSize:16 }}>+</div>
          <div style={{ width:32, height:1, background:'#2c2d30', margin:'8px 0 4px' }} />
          {[{k:'home',label:'Home'},{k:'dm',label:'DMs',active:true},{k:'activity',label:'Activity'},{k:'later',label:'Later'},{k:'more',label:'More'}].map(it => (
            <div key={it.k} style={{ width:52, display:'flex', flexDirection:'column', alignItems:'center', color: it.active ? '#fff' : '#abadb1', gap:4, marginBottom:8 }}>
              <SlackNavIcon kind={it.k} />
              <span style={{ fontSize:10, fontWeight:500 }}>{it.label}</span>
            </div>
          ))}
          <div style={{ flex:1 }} />
          <div style={{ width:32, height:32, borderRadius:16, background:'#5b8def', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, fontWeight:500, marginBottom:14 }}>C</div>
        </div>

        {/* ── SIDEBAR (DM focused) ──────────────────────── */}
        <div style={{ width:240, background:'#19171d', borderRight:'1px solid #2c2d30', flexShrink:0, padding:'18px 14px', color:CT.slackText }}>
          <div style={{ fontSize:15, fontWeight:600, marginBottom:18, display:'flex', alignItems:'center', gap:4, color:'#fff' }}>
            Ledgerline
            <svg width="10" height="10" viewBox="0 0 10 10" fill="none"><path d="M2 4l3 3 3-3" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg>
          </div>
          <div style={{ fontSize:13, color:'#abadb1', marginBottom:6, fontWeight:500 }}>Direct messages</div>
          {[
            {name:'Maria Liu', initial:'M', bg:'#22c55e', online:true, active:true},
            {name:'Jessica Chen', initial:'J', bg:'#b8336a', online:true},
            {name:'Casey Park', initial:'C', bg:'#7a4d2a', online:false},
            {name:'Alex Rivera', initial:'A', bg:'#3b5b7c', online:false},
          ].map((u, i) => (
            <div key={i} style={{
              padding:'4px 10px', borderRadius:4, fontSize:14,
              color: u.active ? '#fff' : '#abadb1',
              background: u.active ? '#1164a3' : 'transparent', marginBottom:1,
              display:'flex', alignItems:'center', gap:8,
            }}>
              <div style={{ position:'relative', width:18, height:18, flexShrink:0 }}>
                <div style={{ width:18, height:18, borderRadius:3, background:u.bg, color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:10, fontWeight:600 }}>{u.initial}</div>
                {u.online && <div style={{ position:'absolute', bottom:-2, right:-2, width:8, height:8, borderRadius:4, background:'#2bac76', border:'2px solid #19171d' }} />}
              </div>
              <span>{u.name}</span>
            </div>
          ))}
        </div>

        {/* ── MAIN DM ──────────────────────────────────── */}
        <div style={{ flex:1, display:'flex', flexDirection:'column' }}>
          {/* DM header */}
          <div style={{ height:50, borderBottom:'1px solid #2c2d30', display:'flex', alignItems:'center', padding:'0 24px', gap:10, flexShrink:0 }}>
            <div style={{ width:24, height:24, borderRadius:3, background:'#22c55e', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:11, fontWeight:600 }}>M</div>
            <div style={{ fontSize:15, color:'#fff', fontWeight:600 }}>Maria Liu</div>
            <div style={{ fontSize:12, color:'#abadb1' }}>· Active</div>
          </div>

          {/* Messages */}
          <div className="chat-scroll" style={{ flex:1, padding:'40px 80px', overflow:'auto' }}>
            {time > m1T - 0.2 && (
              <div style={{ display:'flex', gap:12, marginBottom:24, opacity: fade(time, m1T, 0.3), transform:`translateY(${slideUp(time, m1T, 0.3, 8)}px)` }}>
                <div style={{ width:40, height:40, borderRadius:5, background:'#5b8def', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:15, fontWeight:600 }}>C</div>
                <div>
                  <div style={{ display:'flex', alignItems:'baseline', gap:8 }}>
                    <span style={{ fontSize:15, color:'#fff', fontWeight:700 }}>Carlos Mendoza</span>
                    <span style={{ fontSize:12, color:'#abadb1' }}>2:14 PM</span>
                  </div>
                  <div style={{ fontSize:15, color:CT.slackText, marginTop:4, lineHeight:1.55 }}>ugh — maria let's sync, I'll be done with the structural piece in 2h then yours should rebase clean</div>
                </div>
              </div>
            )}
            {time > m2T - 0.2 && (
              <div style={{ display:'flex', gap:12, opacity: fade(time, m2T, 0.3), transform:`translateY(${slideUp(time, m2T, 0.3, 8)}px)` }}>
                <div style={{ width:40, height:40, borderRadius:5, background:'#22c55e', color:'#fff', display:'flex', alignItems:'center', justifyContent:'center', fontSize:15, fontWeight:600 }}>M</div>
                <div>
                  <div style={{ display:'flex', alignItems:'baseline', gap:8 }}>
                    <span style={{ fontSize:15, color:'#fff', fontWeight:700 }}>Maria Liu</span>
                    <span style={{ fontSize:12, color:'#abadb1' }}>2:14 PM</span>
                  </div>
                  <div style={{ fontSize:15, color:CT.slackText, marginTop:4, lineHeight:1.55 }}>sounds good — I'll pause and pick up the test fixtures task in the meantime</div>
                </div>
              </div>
            )}
          </div>

          {/* ── COMPOSE BOX ──────────────────────────────── */}
          <div style={{ padding:'0 20px 20px', flexShrink:0 }}>
            <div style={{ border:'1px solid #565856', borderRadius:8, background:'#222529', overflow:'hidden' }}>
              <div style={{ display:'flex', alignItems:'center', gap:2, padding:'6px 10px', borderBottom:'1px solid #2c2d30', color:'#abadb1' }}>
                <div style={{ width:28, height:24, display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, fontWeight:700 }}>B</div>
                <div style={{ width:28, height:24, display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, fontStyle:'italic' }}>I</div>
                <div style={{ width:28, height:24, display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, textDecoration:'line-through' }}>S</div>
                <div style={{ width:1, height:16, background:'#3c3f44', margin:'0 6px' }} />
                {['link','ol','ul','code'].map(k => (
                  <div key={k} style={{ width:28, height:24, display:'flex', alignItems:'center', justifyContent:'center' }}><SlackComposeIcon kind={k} /></div>
                ))}
              </div>
              <div style={{ padding:'14px', fontSize:14, color:'#9a9a9a' }}>Message Maria Liu</div>
              <div style={{ display:'flex', alignItems:'center', gap:4, padding:'6px 10px', color:'#abadb1' }}>
                {['plus','video','mic','emoji','mention'].map(k => (
                  <div key={k} style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><SlackComposeIcon kind={k} /></div>
                ))}
                <div style={{ flex:1 }} />
                <div style={{ width:28, height:28, display:'flex', alignItems:'center', justifyContent:'center' }}><SlackComposeIcon kind="send" /></div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <SurfaceLabel text="Slack DM · Carlos × Maria" sceneStart={sceneStart} />
    </div>
  );
}

function Scene4Intel({ sceneStart }) {
  const time = useTime();
  return (
    <div style={{ position:'absolute', inset:0, background:CT.carbon, display:'flex', flexDirection:'column' }}>
      <BrowserBar url="forge.ledgerline.com/intelligence" />
      <div style={{ flex:1, padding:'30px 40px', overflow:'hidden' }}>
        <div style={{ fontSize:18, color:CT.white, fontWeight:500, marginBottom:14, opacity: fade(time, sceneStart + 0.3, 0.3) }}>Activity</div>
        <Card start={sceneStart + 0.5} padding={16} style={{ maxWidth:600 }}>
          <div style={{ display:'flex', alignItems:'flex-start', gap:14 }}>
            <div style={{ fontSize:12, color:CT.gray, fontFamily:T.mono, paddingTop:1 }}>2:14 PM</div>
            <div style={{ flex:1 }}>
              <div style={{ fontSize:14, color:CT.green, fontWeight:500, marginBottom:5 }}>Conflict resolved</div>
              <div style={{ fontSize:13, color:CT.white, marginBottom:3 }}>Carlos × Maria · <span style={{ fontFamily:T.mono }}>src/middleware/auth.ts</span></div>
              <div style={{ fontSize:13, color:CT.gray }}>Maria reassigned to <span style={{ fontFamily:T.mono, color:CT.white }}>STORY-052</span></div>
            </div>
          </div>
        </Card>
      </div>
      <SurfaceLabel text="in the framework · activity" sceneStart={sceneStart} />
    </div>
  );
}

// ════════════════════════════════════════════════════════════════
// SCENE 5 — Closing card (168-180s)
// ════════════════════════════════════════════════════════════════
function Scene5({ sceneStart = 168 }) {
  const time = useTime();
  const a = fade(time, sceneStart + 0.3, 0.6);
  const b = fade(time, sceneStart + 4.0, 0.7);
  const c = fade(time, sceneStart + 6.5, 0.7);
  const bgO = fade(time, sceneStart, 0.6);
  const lines = [
    ['Customer success', 'forwarded an email.'],
    ['A PM', 'sent a vague Slack message.'],
    ['A designer', 'attached a Figma link.'],
    ['Two engineers', 'touched the same file.'],
  ];
  return (
    <div style={{ position:'absolute', inset:0, background:CT.carbon, display:'flex', alignItems:'center', justifyContent:'center', textAlign:'center' }}>
      <div style={{ position:'absolute', inset:0, background:'url(/assets/images/bg_hero.jpg) center/cover no-repeat', opacity:bgO }} />
      <div style={{ position:'relative', display:'flex', flexDirection:'column', alignItems:'center', gap:48, textShadow:'0 2px 12px rgba(0,0,0,0.7)' }}>
        <div style={{ display:'flex', flexDirection:'column', gap:8, opacity:a, transform:`translateY(${(1-a)*8}px)` }}>
          {lines.map(([role, action], i) => (
            <div key={i} style={{ fontSize:26, fontWeight:100, color:CT.white, lineHeight:1.5 }}>
              <span style={{ fontWeight:500 }}>{role}</span> {action}
            </div>
          ))}
        </div>
        <div style={{ fontSize:30, fontWeight:500, color:CT.white, lineHeight:1.45, opacity:b, transform:`translateY(${(1-b)*8}px)`, maxWidth:760 }}>
          None of them coordinated with each other.<br/>
          <span style={gradientStyle}>They coordinated through the framework.</span>
        </div>
      </div>
      <div style={{ position:'absolute', bottom:80, left:0, right:0, display:'flex', flexDirection:'column', alignItems:'center', gap:24, opacity:c }}>
        <span style={{ fontSize:19, fontWeight:500, ...gradientStyle }}>Agentic Forge</span>
        <img src="/assets/logo.svg" alt="Quantivex" style={{ height:28, display:'block' }} />
      </div>
    </div>
  );
}

// ════════════════════════════════════════════════════════════════
function App() {
  return (
    <DemoStage duration={180} captions={[]}>
      <Sprite start={0}    end={42} ><Scene1 sceneStart={0} /></Sprite>
      <Sprite start={42}   end={82} ><Scene2 sceneStart={42} /></Sprite>
      <Sprite start={82}   end={122}><Scene3 sceneStart={82} /></Sprite>
      <Sprite start={122}  end={168}><Scene4 sceneStart={122} /></Sprite>
      <Sprite start={168}  end={180}><Scene5 sceneStart={168} /></Sprite>
      {/* <Subtitles /> — disabled: no voiceover. Re-enable when audio lands. */}
    </DemoStage>
  );
}
ReactDOM.createRoot(document.getElementById('root')).render(<App />);
