/* Typeform-style Savings Calculator
   6 guided questions → annual hours saved + "what you would have banked last year"
   Flow: industry → team size → email hours → tools used → pain areas → current spend
   Output: giant hours/year number, dollar value, what-you-could-have-done cards */

const { useState, useMemo, useEffect } = React;

/* ─── Question definitions ─── */
const QUESTIONS = [
  {
    id: 'industry',
    kind: 'choice',
    label: 'Which best describes your firm?',
    sub: 'Pick one — drives our baseline numbers.',
    options: [
      { v:'accounting', t:'Accounting / bookkeeping', i:'calc' },
      { v:'insurance',  t:'Insurance agency',         i:'shield' },
      { v:'advisory',   t:'Financial advisory / RIA', i:'chart' },
      { v:'other',      t:'Other small business',     i:'puzzle' },
    ],
  },
  {
    id: 'team',
    kind: 'slider',
    label: "How many people are on your team?",
    sub: 'Include everyone who touches client work.',
    min: 1, max: 20, default: 5, unit: 'people',
  },
  {
    id: 'emailHours',
    kind: 'slider',
    label: "How many hours per week does your team spend on email + inbox triage?",
    sub: "Total across the whole team. Most 5-person firms say ~15 hrs/week.",
    min: 2, max: 60, default: 15, unit: 'hrs/week',
  },
  {
    id: 'crmUpdates',
    kind: 'slider',
    label: "Weekly hours on CRM updates, notes, and data entry?",
    sub: 'Typing client info, logging calls, updating deals.',
    min: 0, max: 40, default: 12, unit: 'hrs/week',
  },
  {
    id: 'painAreas',
    kind: 'multi',
    label: "What else eats your team's week?",
    sub: 'Pick all that apply. We only count what you check.',
    options: [
      { v:'invoicing',    t:'Invoicing + bookkeeping',       i:'bill',  hrs:7 },
      { v:'content',      t:'Content writing + posting',      i:'doc',   hrs:5 },
      { v:'research',     t:'Research + data pulls',         i:'eye',   hrs:6 },
      { v:'meetings',     t:'Meeting notes + follow-ups',    i:'phone', hrs:4 },
      { v:'reports',      t:'Report generation',             i:'chart', hrs:4 },
      { v:'proposals',    t:'Proposals + quotes',            i:'receipt', hrs:3 },
    ],
  },
  {
    id: 'currentSpend',
    kind: 'choice',
    label: "What does your firm currently spend on AI tools per month?",
    sub: "Everything — ChatGPT, Claude, Zapier, Make, agency tools.",
    options: [
      { v: 0,    t:'$0 — nothing yet',           i:'x' },
      { v: 100,  t:'~$100 — a few subscriptions', i:'bill' },
      { v: 400,  t:'~$400 — scattered tools',     i:'bill' },
      { v: 1000, t:'$1,000+ — we\'re paying a lot', i:'dollar' },
    ],
  },
];

/* ─── Calculation ─── */
function calcSavings(answers) {
  const team = answers.team || 5;
  const industryMult = { accounting:1.0, insurance:0.95, advisory:1.1, other:0.9 }[answers.industry] || 1.0;
  const emailAutomation = 0.65; // 65% of email hours recoverable
  const crmAutomation = 0.80;   // 80% of CRM updates recoverable
  const painAutomation = 0.55;  // 55% of other pain-area hours recoverable
  const teamScale = Math.sqrt(team / 5); // scale factor — bigger teams amplify, non-linearly

  const painHoursWeekly = (answers.painAreas || []).reduce((sum, v) => {
    const opt = QUESTIONS[4].options.find(o => o.v === v);
    return sum + (opt ? opt.hrs : 0);
  }, 0);

  const emailSaved   = (answers.emailHours || 0) * emailAutomation * teamScale * industryMult;
  const crmSaved     = (answers.crmUpdates || 0) * crmAutomation   * teamScale * industryMult;
  const painSaved    = painHoursWeekly            * painAutomation  * teamScale * industryMult;

  const weeklyHours  = emailSaved + crmSaved + painSaved;
  const annualHours  = weeklyHours * 50; // 50 working weeks
  const hourlyRate   = { accounting:85, insurance:75, advisory:125, other:65 }[answers.industry] || 75;
  const annualDollars = annualHours * hourlyRate;

  // FTE equivalent (2080 hrs/year is one FTE)
  const fteEquivalent = annualHours / 2080;

  // Mammoth cost year 1: setup $4,995 + $1,500/mo × 12 = $22,995 (Growth plan)
  const mammothCost = 4995 + (1500 * 12);
  const netSavings = annualDollars - mammothCost;
  const roiMultiple = annualDollars / mammothCost;
  const paybackMonths = mammothCost / (annualDollars / 12);

  return {
    emailSaved: Math.round(emailSaved),
    crmSaved: Math.round(crmSaved),
    painSaved: Math.round(painSaved),
    weeklyHours: Math.round(weeklyHours),
    annualHours: Math.round(annualHours),
    hourlyRate,
    annualDollars: Math.round(annualDollars),
    fteEquivalent: fteEquivalent.toFixed(1),
    mammothCost,
    netSavings: Math.round(netSavings),
    roiMultiple: roiMultiple.toFixed(1),
    paybackMonths: paybackMonths.toFixed(1),
  };
}

/* ─── Main page ─── */
function CalculatorPage() {
  const [step, setStep] = useState(0); // 0 = intro, 1-6 = questions, 7 = results
  const [answers, setAnswers] = useState({
    industry: null,
    team: 5,
    emailHours: 15,
    crmUpdates: 12,
    painAreas: [],
    currentSpend: null,
  });
  const [showConfetti, setShowConfetti] = useState(false);

  const totalSteps = QUESTIONS.length;
  const progress = step === 0 ? 0 : step > totalSteps ? 100 : ((step - 1) / totalSteps) * 100;

  const results = useMemo(() => calcSavings(answers), [answers]);

  const set = (id, v) => setAnswers(a => ({ ...a, [id]: v }));
  const toggleMulti = (id, v) => setAnswers(a => {
    const cur = a[id] || [];
    return { ...a, [id]: cur.includes(v) ? cur.filter(x => x !== v) : [...cur, v] };
  });

  const next = () => {
    if (step === totalSteps) {
      setStep(totalSteps + 1);
      setShowConfetti(true);
      setTimeout(() => setShowConfetti(false), 2500);
    } else {
      setStep(s => s + 1);
    }
  };
  const back = () => setStep(s => Math.max(0, s - 1));

  // keyboard nav
  useEffect(() => {
    const h = (e) => {
      if (e.key === 'Enter' && step > 0 && step <= totalSteps && canProceed()) next();
      if (e.key === 'ArrowLeft' && step > 0) back();
    };
    window.addEventListener('keydown', h);
    return () => window.removeEventListener('keydown', h);
  });

  const canProceed = () => {
    if (step === 0 || step > totalSteps) return true;
    const q = QUESTIONS[step - 1];
    const v = answers[q.id];
    if (q.kind === 'choice') return v !== null && v !== undefined;
    if (q.kind === 'multi') return Array.isArray(v) && v.length > 0;
    return true; // slider has default
  };

  const currentQ = step > 0 && step <= totalSteps ? QUESTIONS[step - 1] : null;

  return (
    <div className="m-root">
      <Header current="Calculator" />

      {/* Progress bar */}
      {step > 0 && step <= totalSteps && (
        <div style={{height:4, background:'var(--mist)', position:'sticky', top:72, zIndex:5}}>
          <div style={{width:`${progress}%`, height:'100%', background:'var(--russet)', transition:'width 0.4s cubic-bezier(.2,.8,.2,1)'}}/>
        </div>
      )}

      {/* Intro screen */}
      {step === 0 && (
        <section className="m-section" style={{minHeight:'70vh', display:'flex', alignItems:'center'}}>
          <div className="m-container" style={{textAlign:'center', maxWidth:780}}>
            <StampBadge color="var(--teal)">60-second calculator</StampBadge>
            <h1 style={{marginTop:24, marginBottom:20, textWrap:'balance', fontSize:'clamp(2.4rem, 5vw, 4rem)'}}>
              How many hours would you have <Underline>banked last year?</Underline>
            </h1>
            <p className="lead" style={{marginBottom:36}}>
              6 questions. No email required. See exactly what a 5-person firm like yours would have saved — in hours, dollars, and full-time employees.
            </p>
            <button onClick={next} className="m-btn m-btn-gold m-btn-lg" style={{fontSize:17}}>
              Start the 6 questions {Ico.arrow(20,'currentColor')}
            </button>
            <div style={{marginTop:20, fontSize:13, color:'var(--charcoal-soft)'}}>
              Press <kbd style={{padding:'2px 6px', background:'var(--mist)', borderRadius:4, fontFamily:'JetBrains Mono, monospace', fontSize:11}}>Enter</kbd> to advance · <kbd style={{padding:'2px 6px', background:'var(--mist)', borderRadius:4, fontFamily:'JetBrains Mono, monospace', fontSize:11}}>←</kbd> to go back
            </div>

            {/* Preview stat cards */}
            <div style={{marginTop:56, display:'grid', gridTemplateColumns:'repeat(3, 1fr)', gap:16, maxWidth:640, margin:'56px auto 0'}}>
              {[
                { n:'2,080', l:'median hrs saved/yr' },
                { n:'$127K', l:'median $ saved/yr' },
                { n:'8×',    l:'year-1 ROI' },
              ].map((s, i) => (
                <div key={i} style={{padding:'18px 20px', background:'var(--cream-2)', borderRadius:14, border:'1.5px dashed var(--mist-2)'}}>
                  <div style={{fontFamily:'var(--font-head)', fontSize:28, fontWeight:800, color:'var(--russet)', letterSpacing:'-0.02em'}}>{s.n}</div>
                  <div style={{fontSize:12, color:'var(--charcoal-soft)', marginTop:4}}>{s.l}</div>
                </div>
              ))}
            </div>
          </div>
        </section>
      )}

      {/* Question steps */}
      {currentQ && (
        <section className="m-section" style={{minHeight:'70vh', display:'flex', alignItems:'center'}} key={step}>
          <div className="m-container" style={{maxWidth:820}}>
            <div style={{fontFamily:'JetBrains Mono, monospace', fontSize:12, color:'var(--russet)', letterSpacing:'0.12em', marginBottom:16}}>
              QUESTION {step} OF {totalSteps}
            </div>
            <h2 style={{marginBottom:12, fontSize:'clamp(1.8rem, 3.2vw, 2.6rem)', textWrap:'balance'}}>
              {currentQ.label}
            </h2>
            <p className="lead" style={{marginBottom:40}}>{currentQ.sub}</p>

            {/* CHOICE */}
            {currentQ.kind === 'choice' && (
              <div style={{display:'grid', gridTemplateColumns:'1fr 1fr', gap:14, marginBottom:40}}>
                {currentQ.options.map((opt, i) => {
                  const selected = answers[currentQ.id] === opt.v;
                  return (
                    <button key={i} onClick={() => set(currentQ.id, opt.v)} style={{
                      padding:'18px 22px',
                      background: selected ? 'var(--russet)' : 'var(--white)',
                      border: `1.5px solid ${selected ? 'var(--russet)' : 'var(--mist-2)'}`,
                      borderRadius:14, cursor:'pointer',
                      display:'flex', alignItems:'center', gap:14,
                      textAlign:'left',
                      boxShadow: selected ? '4px 4px 0 var(--gold)' : 'none',
                      transition:'all 0.15s',
                    }}>
                      <div style={{width:42, height:42, borderRadius:10, background: selected ? 'var(--gold)' : 'var(--cream-2)', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>
                        {Ico[opt.i](22, selected ? 'var(--charcoal)' : 'var(--russet)')}
                      </div>
                      <span style={{fontFamily:'var(--font-head)', fontWeight:700, fontSize:16, color: selected ? 'var(--cream)' : 'var(--charcoal)', flex:1}}>{opt.t}</span>
                      <span style={{width:24, height:24, borderRadius:'50%', border: `2px solid ${selected ? 'var(--gold)' : 'var(--mist-2)'}`, background: selected ? 'var(--gold)' : 'transparent', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>
                        {selected && Ico.check(14, 'var(--charcoal)')}
                      </span>
                    </button>
                  );
                })}
              </div>
            )}

            {/* SLIDER */}
            {currentQ.kind === 'slider' && (
              <div style={{marginBottom:40}}>
                <div style={{display:'flex', justifyContent:'center', marginBottom:32}}>
                  <div style={{
                    fontFamily:'var(--font-head)', fontWeight:800,
                    fontSize:'clamp(4rem, 10vw, 7rem)',
                    color:'var(--russet)', letterSpacing:'-0.03em', lineHeight:1,
                    position:'relative',
                  }}>
                    {answers[currentQ.id]}
                    <span style={{fontSize:'0.3em', color:'var(--charcoal-soft)', marginLeft:12, fontWeight:600}}>{currentQ.unit}</span>
                  </div>
                </div>
                <div style={{padding:'0 12px'}}>
                  <input
                    type="range"
                    min={currentQ.min} max={currentQ.max}
                    value={answers[currentQ.id]}
                    onChange={(e) => set(currentQ.id, parseInt(e.target.value))}
                    className="m-slider"
                    style={{width:'100%'}}
                  />
                  <div style={{display:'flex', justifyContent:'space-between', marginTop:10, fontFamily:'JetBrains Mono, monospace', fontSize:12, color:'var(--charcoal-soft)'}}>
                    <span>{currentQ.min}</span>
                    <span>{currentQ.max}</span>
                  </div>
                </div>
              </div>
            )}

            {/* MULTI */}
            {currentQ.kind === 'multi' && (
              <div style={{display:'grid', gridTemplateColumns:'1fr 1fr', gap:14, marginBottom:40}}>
                {currentQ.options.map((opt, i) => {
                  const selected = (answers[currentQ.id] || []).includes(opt.v);
                  return (
                    <button key={i} onClick={() => toggleMulti(currentQ.id, opt.v)} style={{
                      padding:'16px 20px',
                      background: selected ? 'var(--teal-soft)' : 'var(--white)',
                      border: `1.5px solid ${selected ? 'var(--teal)' : 'var(--mist-2)'}`,
                      borderRadius:14, cursor:'pointer',
                      display:'flex', alignItems:'center', gap:12,
                      textAlign:'left',
                      transition:'all 0.15s',
                    }}>
                      <div style={{width:38, height:38, borderRadius:10, background: selected ? 'var(--teal)' : 'var(--cream-2)', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>
                        {Ico[opt.i](20, selected ? 'white' : 'var(--russet)')}
                      </div>
                      <div style={{flex:1}}>
                        <div style={{fontFamily:'var(--font-head)', fontWeight:700, fontSize:15, color:'var(--charcoal)'}}>{opt.t}</div>
                        <div style={{fontFamily:'JetBrains Mono, monospace', fontSize:11, color:'var(--charcoal-soft)'}}>~{opt.hrs} hrs/wk typical</div>
                      </div>
                      <span style={{width:22, height:22, borderRadius:6, border: `2px solid ${selected ? 'var(--teal)' : 'var(--mist-2)'}`, background: selected ? 'var(--teal)' : 'transparent', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>
                        {selected && Ico.check(12, 'white')}
                      </span>
                    </button>
                  );
                })}
              </div>
            )}

            {/* Nav */}
            <div style={{display:'flex', gap:12, alignItems:'center'}}>
              <button onClick={back} className="m-btn m-btn-ghost">{'← Back'}</button>
              <button
                onClick={next}
                disabled={!canProceed()}
                className="m-btn m-btn-gold m-btn-lg"
                style={{opacity: canProceed() ? 1 : 0.4, cursor: canProceed() ? 'pointer' : 'not-allowed'}}
              >
                {step === totalSteps ? 'See my results' : 'Next'} {Ico.arrow(18,'currentColor')}
              </button>
              <div style={{marginLeft:'auto', fontSize:12, color:'var(--charcoal-soft)', fontFamily:'JetBrains Mono, monospace'}}>
                press <kbd style={{padding:'2px 6px', background:'var(--mist)', borderRadius:4}}>Enter ↵</kbd>
              </div>
            </div>
          </div>
        </section>
      )}

      {/* Results */}
      {step > totalSteps && (
        <ResultsScreen results={results} answers={answers} onRestart={() => { setStep(0); }} showConfetti={showConfetti}/>
      )}

      {step > totalSteps && <Footer />}
    </div>
  );
}

/* ─── Results screen ─── */
function ResultsScreen({ results, answers, onRestart, showConfetti }) {
  const r = results;
  return (
    <>
      {showConfetti && <Confetti/>}

      {/* Hero number */}
      <section className="m-section" style={{paddingTop:40, paddingBottom:32}}>
        <div className="m-container" style={{textAlign:'center', maxWidth:900}}>
          <StampBadge color="var(--teal)">Your numbers</StampBadge>
          <h1 style={{marginTop:20, marginBottom:12, fontSize:'clamp(1.6rem, 3vw, 2.2rem)', color:'var(--charcoal-soft)', fontWeight:600}}>
            If you'd signed up 12 months ago, you would have banked
          </h1>
          <div style={{
            fontFamily:'var(--font-head)', fontWeight:800,
            fontSize:'clamp(5rem, 14vw, 11rem)',
            color:'var(--russet)', letterSpacing:'-0.04em', lineHeight:1,
            margin:'16px 0',
            textShadow:'6px 6px 0 var(--gold)',
          }}>
            {r.annualHours.toLocaleString()}
          </div>
          <div style={{fontFamily:'var(--font-head)', fontSize:'clamp(1.4rem, 2.4vw, 2rem)', fontWeight:700, color:'var(--charcoal)', marginBottom:8}}>
            hours.
          </div>
          <div style={{fontFamily:'Caveat, cursive', fontSize:22, color:'var(--russet)', transform:'rotate(-0.5deg)'}}>
            = roughly {r.fteEquivalent} full-time {r.fteEquivalent === '1.0' ? 'employee' : 'employees'}, recovered.
          </div>
        </div>
      </section>

      {/* Big stat grid */}
      <section className="m-section-sm">
        <div className="m-container">
          <div style={{display:'grid', gridTemplateColumns:'repeat(4, 1fr)', gap:16}}>
            {[
              { n:`$${r.annualDollars.toLocaleString()}`, l:`Dollar value · @$${r.hourlyRate}/hr`, c:'var(--russet)' },
              { n:`${r.roiMultiple}×`, l:'Year-1 ROI', c:'var(--teal)' },
              { n:`${r.paybackMonths} mo`, l:'Payback period', c:'var(--gold-deep)' },
              { n:`$${r.netSavings.toLocaleString()}`, l:'Net savings year 1', c:'#B85C3C' },
            ].map((s, i) => (
              <div key={i} style={{padding:28, background:'var(--white)', borderRadius:16, border:'1.5px solid var(--mist-2)', borderTop:`3px solid ${s.c}`}}>
                <div style={{fontFamily:'var(--font-head)', fontSize:34, fontWeight:800, color:s.c, letterSpacing:'-0.02em', lineHeight:1}}>{s.n}</div>
                <div style={{fontSize:13, color:'var(--charcoal-soft)', marginTop:8}}>{s.l}</div>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Breakdown */}
      <section className="m-section">
        <div className="m-container">
          <div style={{display:'grid', gridTemplateColumns:'1.1fr 1fr', gap:48, alignItems:'start'}}>
            <div>
              <StampBadge>Where the hours come from</StampBadge>
              <h2 style={{marginTop:16, marginBottom:20}}>Hours recovered, broken down</h2>
              <p style={{marginBottom:32, color:'var(--charcoal-soft)'}}>
                Based on the automation rates we measure across our client base. Not promises — actual observed recoveries.
              </p>
              <div style={{display:'grid', gap:20}}>
                {[
                  { l:'Email + inbox triage',  h:r.emailSaved * 50, pct:65, c:'var(--russet)' },
                  { l:'CRM updates + notes',   h:r.crmSaved * 50,   pct:80, c:'var(--teal)' },
                  { l:'Other pain areas',      h:r.painSaved * 50,  pct:55, c:'var(--gold-deep)' },
                ].map((row, i) => (
                  <div key={i}>
                    <div style={{display:'flex', justifyContent:'space-between', marginBottom:8, alignItems:'baseline'}}>
                      <span style={{fontFamily:'var(--font-head)', fontWeight:700, color:'var(--charcoal)'}}>{row.l}</span>
                      <div>
                        <span style={{fontFamily:'JetBrains Mono, monospace', fontWeight:700, color:row.c, fontSize:18}}>{Math.round(row.h).toLocaleString()} hrs/yr</span>
                        <span style={{fontSize:12, color:'var(--charcoal-soft)', marginLeft:8}}>({row.pct}% automated)</span>
                      </div>
                    </div>
                    <div style={{height:10, background:'var(--mist)', borderRadius:5, overflow:'hidden'}}>
                      <div style={{width:`${Math.min(100, (row.h / 1500) * 100)}%`, height:'100%', background:row.c, borderRadius:5, transition:'width 0.8s cubic-bezier(.2,.8,.2,1)'}}/>
                    </div>
                  </div>
                ))}
              </div>
            </div>

            <div>
              {/* What you could have done */}
              <div style={{padding:32, background:'var(--russet)', borderRadius:20, color:'var(--cream)', position:'relative', overflow:'hidden'}}>
                <div style={{position:'absolute', inset:0, opacity:0.08, backgroundImage:'repeating-linear-gradient(45deg, var(--cream) 0 1px, transparent 1px 14px)'}}/>
                <div style={{position:'relative'}}>
                  <div style={{fontFamily:'JetBrains Mono, monospace', fontSize:11, color:'var(--gold)', letterSpacing:'0.12em', textTransform:'uppercase', marginBottom:12}}>What {r.annualHours.toLocaleString()} hours means</div>
                  <h3 style={{color:'var(--cream)', marginBottom:20, fontSize:24}}>Instead of doing busywork, you could have…</h3>
                  <ul style={{listStyle:'none', padding:0, margin:0, display:'grid', gap:14}}>
                    {[
                      `Hired ${Math.floor(r.fteEquivalent)} fewer people`,
                      `Booked ${Math.round(r.annualHours / 8).toLocaleString()} client meetings`,
                      `Taken ${Math.round(r.annualHours / 40).toLocaleString()} weeks of vacation`,
                      `Closed ${Math.round(r.annualHours / 4).toLocaleString()} more billable-hour sprints`,
                    ].map((t, i) => (
                      <li key={i} style={{display:'flex', gap:12, alignItems:'center'}}>
                        <span style={{width:24, height:24, borderRadius:'50%', background:'var(--gold)', color:'var(--charcoal)', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0}}>{Ico.check(13, 'var(--charcoal)')}</span>
                        <span style={{color:'var(--cream)', fontSize:15}}>{t}</span>
                      </li>
                    ))}
                  </ul>
                </div>
              </div>

              {/* Cost comparison */}
              <div style={{marginTop:20, padding:24, background:'var(--cream-2)', borderRadius:16, border:'1.5px dashed var(--russet)'}}>
                <div style={{fontFamily:'JetBrains Mono, monospace', fontSize:11, color:'var(--russet)', letterSpacing:'0.12em', textTransform:'uppercase', marginBottom:12}}>The math</div>
                <div style={{display:'grid', gap:10, fontSize:15}}>
                  <div style={{display:'flex', justifyContent:'space-between'}}>
                    <span>Value recovered / year</span>
                    <span style={{fontFamily:'JetBrains Mono, monospace', fontWeight:700, color:'var(--teal)'}}>+${r.annualDollars.toLocaleString()}</span>
                  </div>
                  <div style={{display:'flex', justifyContent:'space-between'}}>
                    <span>Mammoth-dev · year 1 all-in</span>
                    <span style={{fontFamily:'JetBrains Mono, monospace', fontWeight:700, color:'var(--charcoal-soft)'}}>−${r.mammothCost.toLocaleString()}</span>
                  </div>
                  <div style={{height:1, background:'var(--russet)', opacity:0.3, margin:'4px 0'}}/>
                  <div style={{display:'flex', justifyContent:'space-between', fontFamily:'var(--font-head)', fontWeight:800, fontSize:18}}>
                    <span style={{color:'var(--charcoal)'}}>Net savings year 1</span>
                    <span style={{color:'var(--russet)'}}>${r.netSavings.toLocaleString()}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>

      {/* CTA + restart */}
      <section className="m-section m-section-mist">
        <div className="m-container" style={{maxWidth:720, textAlign:'center'}}>
          <StampBadge color="var(--gold-deep)">Next step</StampBadge>
          <h2 style={{marginTop:16, marginBottom:16, textWrap:'balance'}}>
            Ready to stop losing <Underline>{r.annualHours.toLocaleString()} hours</Underline> a year?
          </h2>
          <p className="lead" style={{marginBottom:28}}>
            15-minute intro call. No pitch. We'll confirm whether your numbers are conservative or generous — and tell you honestly if we can help.
          </p>
          <div className="m-row" style={{justifyContent:'center'}}>
            <a href="/book" className="m-btn m-btn-gold m-btn-lg">Book 15-min intro {Ico.arrow(18,'currentColor')}</a>
            <button onClick={onRestart} className="m-btn m-btn-ghost">Run numbers again</button>
          </div>

          {/* Share */}
          <div style={{marginTop:40, padding:20, background:'var(--white)', borderRadius:14, border:'1.5px solid var(--mist-2)', display:'inline-flex', alignItems:'center', gap:14}}>
            <span style={{fontSize:13, color:'var(--charcoal-soft)', fontFamily:'JetBrains Mono, monospace'}}>SHARE THIS RESULT</span>
            <button
              onClick={() => {
                const txt = `A 5-person firm like ours would recover ~${r.annualHours.toLocaleString()} hours/year with Mammoth-dev. Run your own: mammoth.dev/calculator`;
                if (navigator.clipboard) navigator.clipboard.writeText(txt);
              }}
              className="m-btn m-btn-russet" style={{padding:'6px 14px', fontSize:13}}>
              Copy summary
            </button>
          </div>
        </div>
      </section>
    </>
  );
}

/* ─── Confetti (simple) ─── */
function Confetti() {
  const pieces = Array.from({length:60}, (_, i) => ({
    left: Math.random() * 100,
    delay: Math.random() * 0.8,
    color: ['var(--russet)','var(--gold)','var(--teal)','#B85C3C','var(--gold-deep)'][i % 5],
    duration: 2 + Math.random() * 1.5,
    rot: Math.random() * 360,
  }));
  return (
    <>
      <style>{`
        @keyframes confetti-fall {
          0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
          100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
        }
      `}</style>
      <div style={{position:'fixed', inset:0, pointerEvents:'none', zIndex:100, overflow:'hidden'}}>
        {pieces.map((p, i) => (
          <div key={i} style={{
            position:'absolute', top:0, left:`${p.left}%`,
            width:10, height:14, background:p.color,
            transform:`rotate(${p.rot}deg)`,
            animation:`confetti-fall ${p.duration}s ${p.delay}s ease-in forwards`,
          }}/>
        ))}
      </div>
    </>
  );
}

Object.assign(window, { CalculatorPage });
