/* Soph deck — slides 9–12: the upgrade, pricing, the close.
   Reframed away from "investor defence." Brand Lift is now framed as
   "what good looks like later" — the upgrade ahead, not the wedge.
   Footers: page label only. */

(function () {
  const { C, fonts, TYPE_SCALE, SPACING, Frame, Eyebrow, Wordmark, FootNote } = window.SoSlides;
  const { useSlideEnter, useCountUp, enterStyle, drawStyle } = window.SoAnim;

  // ══════════════════════════════════════════════════════════════════════
  // SLIDE 9 — Brand Lift, demoted to "what good looks like later."
  // The chart is small, the framing is forward — not a courtroom.
  // ══════════════════════════════════════════════════════════════════════
  function Slide09() {
    const on = useSlideEnter(8);
    const lift = useCountUp(on, 8.3, { dur: 1400, decimals: 1 });
    const w = 720, h = 240, pad = 32;
    const control = [22, 23, 22, 24, 23, 25, 24];
    const exposed = [22, 25, 28, 32, 36, 38, 41];
    const max = 50, min = 18;
    const x = i => pad + (i / (control.length - 1)) * (w - pad * 2);
    const y = v => h - pad - ((v - min) / (max - min)) * (h - pad * 2);
    const path = (a) => a.map((v, i) => `${i === 0 ? 'M' : 'L'}${x(i)},${y(v)}`).join(' ');
    const PATH_LEN = 1100;

    return (
      <Frame style={{ position: 'relative' }}>
        <div style={{ ...enterStyle(on, { dur: 500 }) }}>
          <Eyebrow>What good looks like, later</Eyebrow>
          <h2 style={{ fontFamily: fonts.display, fontSize: TYPE_SCALE.title, fontWeight: 700, letterSpacing: '-0.02em', marginTop: 24, marginBottom: 0, lineHeight: 1.05 }}>
            Brand Lift, when you&rsquo;re ready.
          </h2>
        </div>

        <div style={{ marginTop: 48, display: 'grid', gridTemplateColumns: '1.3fr 1fr', gap: 32, maxWidth: 1680, alignItems: 'stretch' }}>
          <div style={{ background: C.paper, border: `1px solid ${C.rule}`, borderRadius: 12, padding: '28px 32px', boxShadow: '0 4px 8px -2px rgb(0 0 0 / 0.05)', ...enterStyle(on, { y: 16, delay: 200, dur: 600 }) }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
              <div style={{ fontFamily: fonts.body, fontSize: 13, color: C.mute, letterSpacing: '0.06em', textTransform: 'uppercase' }}>Aided awareness &middot; exposed vs control</div>
              <div style={{ display: 'flex', gap: 16, fontFamily: fonts.body, fontSize: 12, color: C.mute }}>
                <span style={{ display: 'flex', alignItems: 'center', gap: 6 }}><span style={{ width: 14, height: 2, background: C.mute }} /> Control</span>
                <span style={{ display: 'flex', alignItems: 'center', gap: 6 }}><span style={{ width: 14, height: 2, background: C.accent }} /> Exposed</span>
              </div>
            </div>
            <svg viewBox={`0 0 ${w} ${h}`} style={{ width: '100%', height: 'auto', marginTop: 18 }}>
              {[20, 30, 40].map(v => (
                <g key={v}>
                  <line x1={pad} x2={w - pad} y1={y(v)} y2={y(v)} stroke={C.hairline} strokeDasharray="3 4" />
                  <text x={pad - 8} y={y(v) + 4} fontSize="11" fill={C.mute} textAnchor="end" fontFamily={fonts.body}>{v}%</text>
                </g>
              ))}
              <path d={path(control)} stroke={C.mute} strokeWidth="2" fill="none" style={drawStyle(on, PATH_LEN, { delay: 600, dur: 1200 })} />
              <path d={path(exposed)} stroke={C.accent} strokeWidth="3" fill="none" style={drawStyle(on, PATH_LEN, { delay: 900, dur: 1500 })} />
              {control.map((v, i) => <circle key={`c${i}`} cx={x(i)} cy={y(v)} r="3" fill={C.mute} style={{ opacity: on ? 1 : 0, transition: `opacity 300ms ease ${1300 + i * 60}ms` }} />)}
              {exposed.map((v, i) => <circle key={`e${i}`} cx={x(i)} cy={y(v)} r="4" fill={C.accent} style={{ opacity: on ? 1 : 0, transition: `opacity 300ms ease ${1500 + i * 60}ms` }} />)}
              {['D1','D3','D5','D7','D9','D11','D14'].map((d, i) => (
                <text key={d} x={x(i)} y={h - 8} fontSize="11" fill={C.mute} textAnchor="middle" fontFamily={fonts.body}>{d}</text>
              ))}
            </svg>
          </div>

          <div style={{ background: C.carbon, color: C.paper, borderRadius: 12, padding: '36px 40px', display: 'flex', flexDirection: 'column', justifyContent: 'center', ...enterStyle(on, { y: 16, delay: 400, dur: 600 }) }}>
            <div style={{ fontFamily: fonts.body, fontSize: 13, color: 'hsl(0, 0%, 60%)', letterSpacing: '0.06em', textTransform: 'uppercase' }}>The number you&rsquo;ll quote</div>
            <div style={{ fontFamily: fonts.display, fontSize: 168, fontWeight: 700, lineHeight: 0.9, letterSpacing: '-0.04em', marginTop: 14, fontVariantNumeric: 'tabular-nums' }}>
              <span style={{ color: C.accent }}>+{lift}</span><span style={{ color: 'hsl(0, 0%, 70%)', fontSize: 60, fontWeight: 400, marginLeft: 8 }}>pts</span>
            </div>
            <div style={{ fontFamily: fonts.body, fontSize: 18, color: 'hsl(0, 0%, 80%)', marginTop: 18, lineHeight: 1.5 }}>
              Same methodology the big brands use.<br/>On a starter budget.
            </div>
          </div>
        </div>
        <FootNote left="09" />
      </Frame>
    );
  }

  // ══════════════════════════════════════════════════════════════════════
  // SLIDE 10 — Why us over an agency. Lifted directly from the doc:
  // control, visibility, cost. Warts-and-all transparency.
  // ══════════════════════════════════════════════════════════════════════
  function Slide10() {
    const on = useSlideEnter(9);
    const rows = [
      { dim: 'Control',     them: 'Theirs',           you: 'Yours' },
      { dim: 'Visibility',  them: 'Edited summaries', you: 'Warts and all' },
      { dim: 'Cost',        them: '£4,000/mo',        you: '£99/mo' },
    ];
    return (
      <Frame bg={C.bone} style={{ position: 'relative' }}>
        <div style={{ ...enterStyle(on, { dur: 500 }) }}>
          <Eyebrow>Versus a managed service</Eyebrow>
          <h2 style={{ fontFamily: fonts.display, fontSize: TYPE_SCALE.title, fontWeight: 700, letterSpacing: '-0.02em', marginTop: 24, marginBottom: 0, lineHeight: 1.05 }}>
            Same expertise.<br/>Without the asymmetry.
          </h2>
        </div>

        <div style={{ marginTop: 56, maxWidth: 1680, ...enterStyle(on, { y: 16, delay: 250, dur: 600 }) }}>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1.2fr 1.2fr', gap: 0, fontFamily: fonts.body, fontSize: 13, color: C.mute, letterSpacing: '0.08em', textTransform: 'uppercase', padding: '16px 0', borderBottom: `1px solid ${C.rule}` }}>
            <div></div>
            <div>An agency</div>
            <div style={{ color: C.ink }}>Justify</div>
          </div>
          {rows.map((r, i) => (
            <div key={i} style={{ display: 'grid', gridTemplateColumns: '1fr 1.2fr 1.2fr', gap: 0, padding: '24px 0', borderBottom: `1px solid ${C.hairline}`, alignItems: 'baseline', ...enterStyle(on, { y: 8, delay: 400 + i * 150, dur: 500 }) }}>
              <div style={{ fontFamily: fonts.display, fontSize: 36, fontWeight: 400, color: C.ink, letterSpacing: '-0.01em' }}>{r.dim}</div>
              <div style={{ fontFamily: fonts.display, fontSize: 36, fontWeight: 400, color: C.mute, letterSpacing: '-0.01em' }}>{r.them}</div>
              <div style={{ fontFamily: fonts.display, fontSize: 36, fontWeight: 700, color: C.ink, letterSpacing: '-0.015em' }}>{r.you}</div>
            </div>
          ))}
        </div>
        <FootNote left="10" />
      </Frame>
    );
  }

  // ══════════════════════════════════════════════════════════════════════
  // SLIDE 11 — Pricing. Less framing, fewer words on the right.
  // ══════════════════════════════════════════════════════════════════════
  function Slide11() {
    const on = useSlideEnter(10);
    const price = useCountUp(on, 99, { dur: 1100 });
    const inc = [
      'Discover 300M+ creators',
      'Trust Score on every profile',
      'Outreach + campaign canvas',
      '0% creator commission',
    ];
    return (
      <Frame style={{ position: 'relative' }}>
        <div style={{ ...enterStyle(on, { dur: 500 }) }}>
          <Eyebrow>Starter</Eyebrow>
          <h2 style={{ fontFamily: fonts.display, fontSize: TYPE_SCALE.title, fontWeight: 700, letterSpacing: '-0.02em', marginTop: 24, marginBottom: 0, lineHeight: 1.1 }}>
            £99 a month. 30 days free.
          </h2>
        </div>

        <div style={{ marginTop: 56, display: 'grid', gridTemplateColumns: '1.2fr 1fr', gap: 40, maxWidth: 1680, alignItems: 'center' }}>
          <div style={{ background: C.bone, border: `1px solid ${C.rule}`, borderRadius: 16, padding: '44px 48px', boxShadow: '0 12px 24px -8px rgb(0 0 0 / 0.08)', ...enterStyle(on, { y: 16, delay: 200, dur: 600 }) }}>
            <div style={{ display: 'flex', alignItems: 'baseline', gap: 4 }}>
              <span style={{ fontFamily: fonts.display, fontSize: 64, fontWeight: 400, color: C.mute }}>£</span>
              <span style={{ fontFamily: fonts.display, fontSize: 200, fontWeight: 700, color: C.ink, letterSpacing: '-0.04em', lineHeight: 0.9, fontVariantNumeric: 'tabular-nums' }}>{price}</span>
              <span style={{ fontFamily: fonts.body, fontSize: 24, color: C.mute, marginLeft: 16, whiteSpace: 'nowrap' }}>/ mo</span>
            </div>
            <div style={{ marginTop: 32, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16 }}>
              {inc.map((i, k) => (
                <div key={k} style={{ display: 'flex', alignItems: 'baseline', gap: 12, ...enterStyle(on, { delay: 600 + k * 100, dur: 400 }) }}>
                  <div style={{ color: C.success, fontSize: 18, transform: 'translateY(-1px)' }}>✓</div>
                  <div style={{ fontFamily: fonts.body, fontSize: 18, color: C.ink }}>{i}</div>
                </div>
              ))}
            </div>
          </div>

          <div style={enterStyle(on, { y: 16, delay: 400, dur: 600 })}>
            <div style={{ fontFamily: fonts.display, fontSize: 56, fontWeight: 400, lineHeight: 1.15, letterSpacing: '-0.015em', color: C.ink }}>
              Less than <span style={{ fontWeight: 700 }}>one bad post.</span>
            </div>
            <div style={{ marginTop: 32, fontFamily: fonts.body, fontSize: TYPE_SCALE.body, color: C.graphite }}>
              Month-to-month. Cancel anytime.
            </div>
          </div>
        </div>
        <FootNote left="11" />
      </Frame>
    );
  }

  // ══════════════════════════════════════════════════════════════════════
  // SLIDE 12 — The ask.
  // ══════════════════════════════════════════════════════════════════════
  function Slide12() {
    const on = useSlideEnter(11);
    return (
      <Frame bg={C.carbon} ink={C.paper} style={{ position: 'relative', justifyContent: 'space-between' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', ...enterStyle(on, { y: 0, dur: 500 }) }}>
          <Wordmark inverted size={32} />
          <Eyebrow color="hsl(0, 0%, 60%)">The ask</Eyebrow>
        </div>

        <div>
          <h2 style={{ fontFamily: fonts.display, fontSize: 152, fontWeight: 400, letterSpacing: '-0.03em', lineHeight: 0.98, color: C.paper, margin: 0, ...enterStyle(on, { y: 20, delay: 200, dur: 800 }) }}>
            Run your <span style={{ fontWeight: 700 }}>next campaign</span><br/>on Justify.
          </h2>
          <p style={{ fontFamily: fonts.body, fontSize: TYPE_SCALE.lede, fontWeight: 400, color: 'hsl(0, 0%, 75%)', marginTop: 36, maxWidth: 1300, lineHeight: 1.4, ...enterStyle(on, { delay: 700, dur: 600 }) }}>
            30 days free. No card.
          </p>
        </div>

        <div style={{ display: 'flex', alignItems: 'center', gap: 24, ...enterStyle(on, { y: 12, delay: 1100, dur: 600 }) }}>
          <a style={{
            display: 'inline-flex', alignItems: 'center', gap: 10,
            background: C.accent, color: C.ink, fontFamily: fonts.body, fontSize: 18, fontWeight: 600,
            padding: '18px 28px', borderRadius: 999, textDecoration: 'none',
          }}>justify.app/sign-up
            {/* Inlined from public/icons/light/faArrowRightLight.svg (official set).
                Inline so currentColor matches the link colour without an extra fetch. */}
            <svg aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" style={{ width: 16, height: 12 }}>
              <path fill="currentColor" d="M443.3 267.3c6.2-6.2 6.2-16.4 0-22.6l-176-176c-6.2-6.2-16.4-6.2-22.6 0s-6.2 16.4 0 22.6L393.4 240 16 240c-8.8 0-16 7.2-16 16s7.2 16 16 16l377.4 0L244.7 420.7c-6.2 6.2-6.2 16.4 0 22.6s16.4 6.2 22.6 0l176-176z"/>
            </svg>
          </a>
          <span style={{ fontFamily: fonts.body, fontSize: 18, color: 'hsl(0, 0%, 65%)' }}>or — what would you need to see, to say yes?</span>
        </div>

        <div style={{
          position: 'absolute', left: SPACING.padX, right: SPACING.padX, bottom: 44,
          display: 'flex', justifyContent: 'space-between',
          fontFamily: fonts.body, fontSize: TYPE_SCALE.micro, color: 'hsl(0, 0%, 50%)', letterSpacing: '0.04em',
        }}>
          <span>12</span><span></span>
        </div>
      </Frame>
    );
  }

  Object.assign(window.SoSlides, { Slide09, Slide10, Slide11, Slide12 });
})();
