function StatCell({ k, v, fg, sub, border, isLast, isFirst }) {
  const [hover, setHover] = React.useState(false);
  const padLeft = isFirst ? 0 : 24;
  return (
    <div className="rz-stat-cell" onMouseEnter={()=>setHover(true)} onMouseLeave={()=>setHover(false)}
         style={{
           padding:`28px 28px 28px ${padLeft}px`,
           borderRight: !isLast ? `1px solid ${border}` : 'none',
           position:'relative', cursor:'default'
         }}>
      <div style={{
        font:'700 36px/1 var(--rz-font-display)', color:fg, letterSpacing:'-0.01em',
        transform: hover ? 'translateY(-2px)' : 'translateY(0)',
        transition:'transform 320ms cubic-bezier(.22,1,.36,1)'
      }}>{k}</div>
      <div style={{ height:10 }}/>
      <div style={{ color:sub, transition:'color 240ms ease' }}>{v}</div>
      <span style={{
        position:'absolute', left:padLeft, right:28, bottom:-1, height:2,
        background:'#f73f34',
        transform: hover ? 'scaleX(1)' : 'scaleX(0)',
        transformOrigin:'left center',
        transition:'transform 380ms cubic-bezier(.22,1,.36,1)'
      }}/>
    </div>
  );
}

function Reveal({ children, delay = 0 }) {
  const ref = React.useRef(null);
  const [v, setV] = React.useState(false);
  React.useEffect(() => {
    const io = new IntersectionObserver(([e]) => { if (e.isIntersecting) setV(true); }, { threshold: 0.15 });
    if (ref.current) io.observe(ref.current);
    return () => io.disconnect();
  }, []);
  return (
    <div ref={ref} style={{
      opacity: v ? 1 : 0,
      transform: v ? 'translateY(0)' : 'translateY(16px)',
      transition: `opacity 600ms cubic-bezier(.22,1,.36,1) ${delay}ms, transform 600ms cubic-bezier(.22,1,.36,1) ${delay}ms`
    }}>{children}</div>
  );
}

// Section 2: bold feature heading + render to right, banner of info underneath
function StatementSection({ dark }) {
  const bg = dark ? '#161717' : '#D5D7D8';
  const fg = dark ? '#F9FAFB' : '#373C42';
  const sub = dark ? '#9aa0a6' : '#5D656E';
  const border = dark ? 'rgba(249,250,251,0.10)' : 'rgba(55,60,66,0.15)';
  const targetSrc = dark ? "assets/renders/2-whensportsmeetrobotics.png" : "assets/renders/2-light.png";
  const [imgSrc, setImgSrc] = React.useState(targetSrc);
  const [imgOpacity, setImgOpacity] = React.useState(1);
  React.useEffect(() => {
    setImgOpacity(0);
    const t = setTimeout(() => { setImgSrc(targetSrc); setImgOpacity(1); }, 620);
    return () => clearTimeout(t);
  }, [dark]);

  return (
    <section style={{ background:bg, padding:'140px 56px 80px', transition:'background 320ms ease 220ms', overflow:'hidden' }}>
      <div className="rz-statement-flex" style={{ position:'relative', minHeight:'70vh', display:'flex', alignItems:'center' }}>
        <div style={{ position:'relative', zIndex:2 }}>
          <Reveal>
            <div>
              <div style={{ font:'400 12px/1 var(--rz-font-mono)', color:sub, letterSpacing:'0.16em', marginBottom:24 }}>
                <span className="rz-accent-dot"/>01 / THE PROBLEM
              </div>
              <div className="rz-statement-heading" style={{ font:'700 88px/0.98 var(--rz-font-display)', color:fg, letterSpacing:'-0.02em' }}>
                When sports<br/>meets robotics.
              </div>
              <div style={{ height:32 }}/>
              <div style={{ font:'400 16px/1.6 var(--rz-font-mono)', color:sub, maxWidth:480 }}>
                The single-machine system used to resurface ice hasn't changed in 75 years. Heavy. Expensive. Slow. Every hour of ice time, fifteen minutes are lost to one machine completing one lap at a time.
              </div>
            </div>
          </Reveal>
        </div>
        <div className="rz-statement-image" style={{ position:'absolute', right:'-5%', top:'50%', transform:'translateY(-50%)', width:'60%', zIndex:1 }}>
          <Reveal delay={120}>
            <img src={imgSrc} style={{ width:'100%', height:'auto', transform:'scale(1.6)', transformOrigin:'center center', opacity:imgOpacity, transition:'opacity 220ms ease' }}/>
          </Reveal>
        </div>
      </div>

      {/* info banner underneath */}
      <div style={{ position:'relative', zIndex:2 }}>
        <Reveal delay={200}>
        <div className="rz-stats-banner" style={{
          marginTop:64, borderTop:`1px solid ${border}`, borderBottom:`1px solid ${border}`,
          display:'grid', gridTemplateColumns:'repeat(4, 1fr)',
          font:'400 13px/1.5 var(--rz-font-mono)', color:fg
        }}>
          {[
            ['5 min', 'resurfaces ice in five minutes'],
            ['$80K', 'up to additional monthly revenue'],
            ['$1.5B', 'global ice resurfacing market'],
            ['1–2 hr', 'recovered ice time per rink, per day']
          ].map(([k,v], i) => (
            <StatCell key={k} k={k} v={v} fg={fg} sub={sub} border={border} isLast={i === 3} isFirst={i === 0}/>
          ))}
        </div>
      </Reveal>
      </div>
    </section>
  );
}
window.StatementSection = StatementSection;
window.Reveal = Reveal;
