/* CareNav site — Hero + Problem (chaos) + Connecting Dots */

/* Type-led animated hero. Phrase types in word by word. */
window.SiteHero = function SiteHero({ audience }) {
  const isMobile = useIsMobile();
  const [step, setStep] = React.useState(0);
  React.useEffect(() => {
    const t = setInterval(() => setStep(s => Math.min(s + 1, 6)), 320);
    return () => clearInterval(t);
  }, []);

  const headline = {
    patients: ['Cancer', 'is', 'overwhelming.', 'CareNav', 'is', 'not.'],
    clinicians: ['Your', 'patients,', 'fully', 'supported', 'between', 'visits.'],
    hospitals: ['One', 'partner.', 'Every', 'patient.', 'Every', 'journey.'],
    insurers: ['Better', 'outcomes.', 'Lower', 'costs.', 'Happier', 'members.'],
  }[audience] || ['Cancer', 'is', 'overwhelming.', 'CareNav', 'is', 'not.'];

  const subline = {
    patients: 'A real human navigator beside you, every step of the way — connecting the dots so you don\'t have to.',
    clinicians: 'CareNav handles the coordination, follow-ups, and patient education that fall through the cracks — so you can focus on care.',
    hospitals: 'Reduce missed appointments, improve outcomes, and lift patient satisfaction with a custodian for the entire cancer journey.',
    insurers: 'A measurably better experience for your members at a lower total cost of care. Evidence-based, outcome-aligned.',
  }[audience] || '';

  return (
    <section style={{ position: 'relative', overflow: 'hidden', background: 'var(--cn-cream-100)', padding: isMobile ? '56px 20px 48px' : '120px 32px 80px' }}>
      {/* Ambient mark — hidden on mobile (it overflows and competes with the headline) */}
      {!isMobile && (
        <div style={{ position: 'absolute', right: '-8%', top: '20%', opacity: 0.08, pointerEvents: 'none' }}>
          <CNLogoMark size={760} color="var(--cn-forest-700)"/>
        </div>
      )}
      <div style={{ position: 'relative', maxWidth: 1280, margin: '0 auto', display: 'grid', gridTemplateColumns: isMobile ? '1fr' : '1.4fr 1fr', gap: isMobile ? 32 : 80, alignItems: 'center' }}>
        <div>
          <div style={{ fontFamily: 'var(--cn-font-mono)', fontSize: isMobile ? 10 : 11, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'var(--cn-coral-700)', fontWeight: 600 }}>The trusted custodian of cancer journeys</div>
          <h1 style={{
            fontFamily: 'var(--cn-font-display)',
            fontSize: isMobile ? 'clamp(40px, 11vw, 56px)' : 'clamp(56px, 7vw, 112px)',
            fontWeight: 400,
            letterSpacing: '-0.03em', lineHeight: 0.96, color: 'var(--cn-forest-900)',
            margin: isMobile ? '14px 0 0' : '24px 0 0', textWrap: 'balance',
          }}>
            {headline.map((w, i) => {
              const visible = i < step;
              const isAccent = (audience === 'patients' && i === 2) || (audience === 'clinicians' && i === 4) || (audience === 'hospitals' && i === 1) || (audience === 'insurers' && i === 3);
              return (
                <span key={`${audience}-${i}`} style={{
                  display: 'inline-block',
                  opacity: visible ? 1 : 0,
                  transform: visible ? 'translateY(0)' : 'translateY(12px)',
                  filter: visible ? 'blur(0)' : 'blur(8px)',
                  transition: `all 600ms cubic-bezier(0.2, 0.8, 0.2, 1) ${i * 80}ms`,
                  fontStyle: isAccent ? 'italic' : 'normal',
                  color: isAccent ? 'var(--cn-coral-700)' : 'inherit',
                  marginRight: '0.28em',
                }}>{w}</span>
              );
            })}
          </h1>
          <p style={{
            opacity: step >= 5 ? 1 : 0, transition: 'opacity 700ms 800ms',
            fontFamily: 'var(--cn-font-sans)', fontSize: isMobile ? 16 : 19, lineHeight: 1.55, color: 'var(--cn-ink-700)',
            maxWidth: 560, marginTop: isMobile ? 20 : 32, textWrap: 'pretty',
          }}>{subline}</p>
          <div style={{ display: 'flex', gap: 10, marginTop: isMobile ? 24 : 36, flexWrap: 'wrap', opacity: step >= 6 ? 1 : 0, transition: 'opacity 700ms 1100ms' }}>
            <button onClick={() => window.scrollToId && window.scrollToId('contact')} style={{ background: 'var(--cn-forest-800)', color: 'var(--cn-cream-100)', border: 'none', padding: isMobile ? '12px 18px' : '14px 24px', borderRadius: 999, fontFamily: 'var(--cn-font-sans)', fontSize: isMobile ? 13 : 14, fontWeight: 600, cursor: 'pointer', whiteSpace: 'nowrap' }}>
              {audience === 'patients' && 'Ask your provider'}
              {audience === 'clinicians' && 'Refer a patient'}
              {audience === 'hospitals' && 'Book a demo'}
              {audience === 'insurers' && 'Partner with us'}
            </button>
            <button onClick={() => window.scrollToId && window.scrollToId('how-it-works')} style={{ background: 'transparent', color: 'var(--cn-forest-800)', border: '1px solid var(--cn-forest-800)', padding: isMobile ? '12px 18px' : '14px 24px', borderRadius: 999, fontFamily: 'var(--cn-font-sans)', fontSize: isMobile ? 13 : 14, fontWeight: 500, cursor: 'pointer', whiteSpace: 'nowrap' }}>
              See how it works ↓
            </button>
          </div>
        </div>
        {/* Right: large hero mark with sketch fill */}
        <div style={{ position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: isMobile ? 220 : 480 }}>
          <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(circle at 60% 40%, rgba(200,97,71,0.18), transparent 60%)' }}/>
          <div style={{ position: 'relative', filter: 'drop-shadow(0 30px 80px rgba(11,63,50,0.15))', maxWidth: '100%' }}>
            <svg viewBox="0 0 140 100" width={isMobile ? 280 : 460} style={{ overflow: 'visible', maxWidth: '100%', height: 'auto' }}>
              <path d="M 72 18 C 60 11, 43 12, 31 24 C 18 37, 17 58, 31 72 C 43 84, 64 82, 74 68 C 81 58, 80 44, 91 37 C 103 29, 121 37, 121 56 L 121 76"
                fill="none" stroke="var(--cn-forest-700)" strokeWidth="15.2" strokeLinecap="round" strokeLinejoin="round"
                style={{ strokeDasharray: 600, strokeDashoffset: step > 0 ? 0 : 600, transition: 'stroke-dashoffset 4800ms cubic-bezier(0.45, 0.05, 0.25, 1) 400ms' }}/>
            </svg>
          </div>
        </div>
      </div>
    </section>
  );
};

/* PROBLEM: chaos of fragmented care.
   Animated grid of conflicting "noise" — appointments, portals, bills, calls — that the user scrolls into.
   Items pile in then settle into a cluttered grid. */
window.SiteProblem = function SiteProblem() {
  const isMobile = useIsMobile();
  const [ref, inView] = useInView({ threshold: 0.3, once: true });
  // Bigger square post-its, packed and overlapping. (x,y) = top-left in % of garden.
  // size in px, r = rotation deg.
  const noises = [
    { t: 'Appointment reminder', s: 'Oncologist · Tue 9:30', kind: 'sms', x: 4, y: 6, size: 220, r: -7 },
    { t: 'Pre-auth needed', s: 'Insurer · 3 forms', kind: 'mail', x: 22, y: 14, size: 200, r: 5 },
    { t: 'Specialist referral', s: 'Surgeon · Johannesburg', kind: 'note', x: 38, y: 4, size: 220, r: -4 },
    { t: 'Co-payment due', s: 'R 4,820 · 7 days', kind: 'bill', x: 56, y: 10, size: 200, r: 8 },
    { t: '"Ask your doctor"', s: 'Forum · 47 replies', kind: 'note', x: 72, y: 4, size: 210, r: -6 },
    { t: 'Different portal', s: 'Laboratory · register?', kind: 'alert', x: 14, y: 30, size: 210, r: 4 },
    { t: 'Bill #4421', s: 'Outstanding R 18,420', kind: 'bill', x: 32, y: 36, size: 220, r: -8 },
    { t: 'Lab results ready', s: '2 unread', kind: 'sms', x: 50, y: 32, size: 200, r: 6 },
    { t: 'New form', s: 'Consent · 14 pages', kind: 'mail', x: 66, y: 38, size: 220, r: -3 },
    { t: 'Side-effect log', s: 'Update daily', kind: 'note', x: 82, y: 30, size: 200, r: 7 },
    { t: 'Missed call', s: "Doctor's receptionist", kind: 'alert', x: 6, y: 56, size: 210, r: -5 },
    { t: 'Rescheduled', s: 'Radiology Thu → Mon', kind: 'sms', x: 24, y: 60, size: 220, r: 9 },
    { t: 'Medical aid query', s: 'Outstanding · reply?', kind: 'mail', x: 42, y: 56, size: 210, r: -4 },
    { t: 'Prescription refill', s: 'Out of stock', kind: 'alert', x: 60, y: 62, size: 200, r: 3 },
    { t: 'Hospital admission', s: 'Pre-admit forms', kind: 'note', x: 76, y: 56, size: 220, r: -7 },
  ];
  const colors = {
    sms: ['var(--cn-forest-100)', 'var(--cn-forest-800)'],
    alert: ['var(--cn-coral-100)', 'var(--cn-coral-700)'],
    mail: ['var(--cn-cream-200)', 'var(--cn-ink-700)'],
    note: ['#FEF3C7', '#92400E'],
    bill: ['#FEE2E2', '#991B1B'],
  };
  return (
    <section ref={ref} style={{ background: 'var(--cn-ink-900)', color: 'var(--cn-cream-100)', padding: isMobile ? '64px 20px' : '120px 32px', position: 'relative', overflow: 'hidden' }}>
      <div style={{ maxWidth: 1280, margin: '0 auto' }}>
        <div style={{ maxWidth: 720 }}>
          <div style={{ fontFamily: 'var(--cn-font-mono)', fontSize: isMobile ? 10 : 11, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'var(--cn-coral-300)', fontWeight: 600 }}>The problem</div>
          <h2 style={{ fontFamily: 'var(--cn-font-display)', fontSize: isMobile ? 'clamp(32px, 9vw, 44px)' : 'clamp(40px, 5vw, 72px)', fontWeight: 400, letterSpacing: '-0.025em', color: 'var(--cn-cream-100)', margin: '14px 0 20px', lineHeight: 1.05, textWrap: 'balance' }}>
            Care today is <span style={{ fontStyle: 'italic', color: 'var(--cn-coral-300)' }}>fragmented</span>. Families fill the gaps.
          </h2>
          <p style={{ fontFamily: 'var(--cn-font-sans)', fontSize: isMobile ? 15 : 18, lineHeight: 1.6, color: 'var(--cn-cream-300)', textWrap: 'pretty' }}>
            Between specialists, portals, paperwork and waiting rooms, families do an unpaid second job: chasing referrals, decoding bills, remembering what one doctor said before the next appointment.
          </p>
        </div>
        {/* Noise garden — desktop: absolute-positioned overlapping post-its. Mobile: 2-col tiled grid with subtle rotation. */}
        {isMobile ? (
          <div style={{ position: 'relative', marginTop: 32, borderRadius: 16, background: 'rgba(255,255,255,0.03)', border: '1px solid rgba(255,255,255,0.08)', padding: 16 }}>
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
              {noises.map((n, i) => {
                const [bg, fg] = colors[n.kind];
                const rot = ((i % 4) - 1.5) * 1.4;
                return (
                  <div key={i} style={{
                    background: bg, color: fg,
                    padding: '12px 12px', borderRadius: 4,
                    fontFamily: 'var(--cn-font-sans)',
                    transform: inView ? `rotate(${rot}deg)` : `rotate(${rot}deg) translateY(-40px)`,
                    opacity: inView ? 1 : 0,
                    transition: `all 700ms cubic-bezier(0.34, 1.4, 0.64, 1) ${i * 50}ms`,
                    boxShadow: '0 8px 16px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3)',
                    minHeight: 96,
                    display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
                  }}>
                    <div>
                      <div style={{ fontWeight: 600, fontSize: 13, lineHeight: 1.2, letterSpacing: '-0.01em' }}>{n.t}</div>
                      <div style={{ opacity: 0.72, marginTop: 4, fontSize: 11, fontWeight: 500 }}>{n.s}</div>
                    </div>
                    <div style={{ fontFamily: 'var(--cn-font-mono)', fontSize: 8, letterSpacing: '0.16em', textTransform: 'uppercase', opacity: 0.45, fontWeight: 600, marginTop: 8 }}>
                      {n.kind === 'sms' && 'SMS'}
                      {n.kind === 'alert' && 'Alert'}
                      {n.kind === 'mail' && 'Email'}
                      {n.kind === 'note' && 'Note'}
                      {n.kind === 'bill' && 'Statement'}
                    </div>
                  </div>
                );
              })}
            </div>
            <div style={{
              marginTop: 28, textAlign: 'center',
              opacity: inView ? 1 : 0,
              transition: 'opacity 1200ms cubic-bezier(0.2, 0.8, 0.2, 1) 800ms',
            }}>
              <div style={{ fontFamily: 'var(--cn-font-mono)', fontSize: 12, letterSpacing: '0.24em', textTransform: 'uppercase', color: 'var(--cn-coral-300)', fontWeight: 700 }}>
                And all of this
              </div>
              <div style={{
                fontFamily: 'var(--cn-font-display)', fontStyle: 'italic',
                fontSize: 'clamp(32px, 9vw, 44px)', fontWeight: 400,
                color: 'var(--cn-cream-100)', lineHeight: 1.0, letterSpacing: '-0.025em',
                marginTop: 8, textWrap: 'balance',
              }}>
                lands on <span style={{ color: 'var(--cn-coral-300)' }}>one</span> person.
              </div>
            </div>
          </div>
        ) : (
          <div style={{ position: 'relative', marginTop: 64, height: 720, borderRadius: 24, background: 'rgba(255,255,255,0.03)', border: '1px solid rgba(255,255,255,0.08)', overflow: 'hidden' }}>
            {noises.map((n, i) => {
              const [bg, fg] = colors[n.kind];
              return (
                <div key={i} style={{
                  position: 'absolute',
                  left: `${n.x}%`, top: `${n.y}%`,
                  width: n.size, height: n.size,
                  background: bg, color: fg,
                  padding: '18px 20px', borderRadius: 4,
                  fontFamily: 'var(--cn-font-sans)',
                  transform: inView ? `rotate(${n.r}deg)` : `rotate(${n.r}deg) translateY(${-260 - i * 24}px)`,
                  opacity: inView ? 1 : 0,
                  transition: `all 900ms cubic-bezier(0.34, 1.4, 0.64, 1) ${i * 70}ms`,
                  boxShadow: '0 14px 30px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3)',
                  display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
                  zIndex: i,
                }}>
                  <div>
                    <div style={{ fontWeight: 600, fontSize: 18, lineHeight: 1.2, letterSpacing: '-0.01em' }}>{n.t}</div>
                    <div style={{ opacity: 0.72, marginTop: 6, fontSize: 13, fontWeight: 500 }}>{n.s}</div>
                  </div>
                  <div style={{ fontFamily: 'var(--cn-font-mono)', fontSize: 9, letterSpacing: '0.16em', textTransform: 'uppercase', opacity: 0.45, fontWeight: 600 }}>
                    {n.kind === 'sms' && 'SMS'}
                    {n.kind === 'alert' && 'Alert'}
                    {n.kind === 'mail' && 'Email'}
                    {n.kind === 'note' && 'Note'}
                    {n.kind === 'bill' && 'Statement'}
                  </div>
                </div>
              );
            })}
            {/* Bold overlay callout — sits on top of the chaos */}
            <div style={{
              position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center',
              pointerEvents: 'none', zIndex: 100,
              opacity: inView ? 1 : 0,
              transition: 'opacity 1200ms cubic-bezier(0.2, 0.8, 0.2, 1) 1500ms',
            }}>
              {/* Subtle dim behind the text so it lifts off the cards */}
              <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(ellipse 60% 50% at 50% 50%, rgba(20,28,30,0.78), rgba(20,28,30,0) 75%)' }}/>
              <div style={{ position: 'relative', textAlign: 'center', padding: '0 32px', maxWidth: 880 }}>
                <div style={{ fontFamily: 'var(--cn-font-mono)', fontSize: 22, letterSpacing: '0.24em', textTransform: 'uppercase', color: 'var(--cn-coral-300)', fontWeight: 700 }}>
                  And all of this
                </div>
                <div style={{
                  fontFamily: 'var(--cn-font-display)', fontStyle: 'italic',
                  fontSize: 'clamp(48px, 7vw, 96px)', fontWeight: 400,
                  color: 'var(--cn-cream-100)', lineHeight: 1.0, letterSpacing: '-0.025em',
                  marginTop: 16, textWrap: 'balance',
                  textShadow: '0 8px 40px rgba(0,0,0,0.6)',
                }}>
                  lands on <span style={{ color: 'var(--cn-coral-300)' }}>one</span> person.
                </div>
              </div>
            </div>
          </div>
        )}
      </div>
    </section>
  );
};
