/* global React */
const { useState: useStateS, useEffect: useEffectS, useRef: useRefS } = React;

/* ============================================
   IntersectionObserver hook for reveal
   ============================================ */
function useReveal(threshold = 0.2) {
  const ref = useRefS(null);
  const [seen, setSeen] = useStateS(false);
  useEffectS(() => {
    const el = ref.current;
    if (!el) return;
    const io = new IntersectionObserver(([e]) => {
      if (e.isIntersecting) { setSeen(true); io.disconnect(); }
    }, { threshold });
    io.observe(el);
    return () => io.disconnect();
  }, [threshold]);
  return [ref, seen];
}

/* ============================================
   STATS ROW
   ============================================ */
function StatsRow() {
  const [ref, seen] = useReveal(0.3);
  const anchor = { value: '<50ms', label: 'Decision latency target', context: 'fraud detection, in production' };
  const satellites = [
    { value: '87%', label: 'Avg. process time reduction' },
    { value: '40yr', label: 'Document corpus indexed' },
    { value: '3', label: 'Languages — AZ · RU · EN' },
  ];
  return (
    <section ref={ref} data-bg="elevated" className="stats-anchor-section" style={{ paddingTop: 'clamp(120px, 18vh, 200px)', paddingBottom: 'clamp(120px, 18vh, 200px)' }}>
      <div className="container">
        <div className={`section-hairline reveal${seen ? ' in' : ''}`} style={{ marginBottom: 64, transform: seen ? 'scaleX(1)' : 'scaleX(0)', transition: 'transform 1200ms var(--ease-out-expo)' }} />
        <div className="stats-anchor-grid" style={{
          display: 'grid',
          gridTemplateColumns: '1.4fr 1fr',
          gap: 80,
          alignItems: 'flex-start',
        }}>
          {/* Anchor */}
          <div className={`reveal${seen ? ' in' : ''}`} style={{ position: 'relative', transitionDelay: '120ms' }}>
            <div className="eyebrow" style={{ marginBottom: 28 }}>ANCHOR METRIC</div>
            <div className="serif stats-anchor-num" style={{
              fontSize: 'clamp(120px, 18vw, 240px)',
              color: 'var(--accent-ice)',
              lineHeight: 0.92,
              letterSpacing: '-0.04em',
              textShadow: '0 0 60px rgba(168, 197, 232, 0.22)',
              fontFeatureSettings: '"ss01"',
            }}>{anchor.value}</div>
            <div style={{
              fontFamily: 'var(--font-serif)',
              fontSize: 'clamp(20px, 2vw, 28px)',
              color: 'var(--text-primary)',
              marginTop: 24,
              maxWidth: 420,
              lineHeight: 1.25,
              letterSpacing: '-0.01em',
            }}>{anchor.label}.</div>
            <div style={{
              fontFamily: 'var(--font-mono)',
              fontSize: 11,
              color: 'var(--text-tertiary)',
              textTransform: 'uppercase',
              letterSpacing: '0.12em',
              marginTop: 14,
            }}>{anchor.context}</div>
          </div>

          {/* Satellites */}
          <div className={`reveal${seen ? ' in' : ''}`} style={{ display: 'flex', flexDirection: 'column', gap: 0, paddingTop: 12, transitionDelay: '240ms' }}>
            <div style={{ height: 1, background: 'var(--border-glass)' }} />
            {satellites.map((s, i) => (
              <div key={s.label} style={{
                display: 'grid',
                gridTemplateColumns: '1fr auto',
                alignItems: 'baseline',
                gap: 24,
                padding: '28px 0 28px',
                borderBottom: '1px solid var(--border-glass)',
              }}>
                <div>
                  <div style={{
                    fontFamily: 'var(--font-mono)',
                    fontSize: 10,
                    color: 'var(--text-tertiary)',
                    textTransform: 'uppercase',
                    letterSpacing: '0.14em',
                    marginBottom: 8,
                  }}>{String(i + 1).padStart(2, '0')}</div>
                  <div style={{
                    fontFamily: 'var(--font-mono)',
                    fontSize: 12,
                    color: 'var(--text-secondary)',
                    textTransform: 'uppercase',
                    letterSpacing: '0.08em',
                  }}>{s.label}</div>
                </div>
                <div className="serif stats-sat-num" style={{
                  fontSize: 'clamp(36px, 4vw, 56px)',
                  color: 'var(--text-primary)',
                  lineHeight: 1,
                  letterSpacing: '-0.02em',
                }}>{s.value}</div>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

/* ============================================
   PRODUCT SHOWCASE — full-bleed horizontal
   ============================================ */
function ProductShowcase() {
  const trackRef = useRefS(null);
  const wrapRef = useRefS(null);
  const [paused, setPaused] = useStateS(false);
  const offset = useRefS(0);
  const dragging = useRefS(false);
  const dragStart = useRefS({ x: 0, off: 0 });

  // Auto-pan runs on ALL viewports (desktop + mobile). Speed is 24px/s on mobile, 30px/s on desktop.
  useEffectS(() => {
    const isTouchDevice = window.matchMedia('(hover: none)').matches;
    const speed = isTouchDevice ? 24 : 30;
    let raf;
    let last = performance.now();
    const tick = (now) => {
      const dt = now - last;
      last = now;
      if (!paused && !dragging.current) {
        offset.current -= (speed / 1000) * dt;
        if (trackRef.current) {
          const halfWidth = trackRef.current.scrollWidth / 2;
          if (-offset.current >= halfWidth) offset.current += halfWidth;
          trackRef.current.style.transform = `translateX(${offset.current}px)`;
        }
      }
      raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [paused]);

  // Mouse drag (desktop) + touch drag (mobile) — both pause then resume auto-pan
  useEffectS(() => {
    const wrap = wrapRef.current;
    if (!wrap) return;
    const onDown = (e) => {
      dragging.current = true;
      const x = e.clientX ?? e.touches?.[0]?.clientX;
      dragStart.current = { x, off: offset.current };
      wrap.style.cursor = 'grabbing';
    };
    const onMove = (e) => {
      if (!dragging.current) return;
      const x = e.clientX ?? e.touches?.[0]?.clientX;
      if (x === undefined) return;
      offset.current = dragStart.current.off + (x - dragStart.current.x);
      if (trackRef.current) {
        const halfWidth = trackRef.current.scrollWidth / 2;
        while (-offset.current >= halfWidth) offset.current += halfWidth;
        while (offset.current > 0) offset.current -= halfWidth;
        trackRef.current.style.transform = `translateX(${offset.current}px)`;
      }
    };
    const onUp = () => { dragging.current = false; wrap.style.cursor = 'grab'; };
    wrap.addEventListener('mousedown', onDown);
    window.addEventListener('mousemove', onMove);
    window.addEventListener('mouseup', onUp);
    wrap.addEventListener('touchstart', onDown, { passive: true });
    window.addEventListener('touchmove', onMove, { passive: true });
    window.addEventListener('touchend', onUp);
    return () => {
      wrap.removeEventListener('mousedown', onDown);
      window.removeEventListener('mousemove', onMove);
      window.removeEventListener('mouseup', onUp);
      wrap.removeEventListener('touchstart', onDown);
      window.removeEventListener('touchmove', onMove);
      window.removeEventListener('touchend', onUp);
    };
  }, []);

  const mocks = [
    <window.MockKYC key="kyc" />,
    <window.MockClaims key="claims" />,
    <window.MockNeft key="neft" />,
    <window.MockEnerji key="enerji" />,
    <window.MockFintex key="fintex" />,
    <window.MockVizual key="vizual" />,
    <window.MockStudio key="studio" />,
    <window.MockTwin key="twin" />,
  ];

  return (
    <section style={{ paddingTop: 80, paddingBottom: 120, overflow: 'hidden' }}>
      <div className="container" style={{ marginBottom: 60 }}>
        <div className="eyebrow" style={{ marginBottom: 16 }}>SHOWCASE — IN PRODUCTION</div>
        <h2 className="serif section-h2" style={{
          fontSize: 'clamp(40px, 5vw, 64px)',
          letterSpacing: '-0.025em',
          lineHeight: 1.05,
          maxWidth: 900,
        }}>
          Real interfaces. <em style={{ color: 'var(--accent-ice)', fontStyle: 'italic' }}>Real users.</em> Real production load.
        </h2>
      </div>
      <div
        ref={wrapRef}
        className="showcase-wrap"
        onMouseEnter={() => setPaused(true)}
        onMouseLeave={() => setPaused(false)}
        style={{
          width: '100%',
          overflow: 'hidden',
          cursor: 'grab',
          maskImage: 'linear-gradient(90deg, transparent, black 4%, black 96%, transparent)',
          WebkitMaskImage: 'linear-gradient(90deg, transparent, black 4%, black 96%, transparent)',
          touchAction: 'pan-y',
        }}
      >
        <div ref={trackRef} className="showcase-track" style={{
          display: 'flex',
          gap: 24,
          padding: '20px 24px',
          willChange: 'transform',
          userSelect: 'none',
          WebkitUserSelect: 'none',
        }}>
          {[...mocks, ...mocks].map((m, i) => <div key={i}>{m}</div>)}
        </div>
      </div>
      <div className="container" style={{ marginTop: 24, display: 'flex', justifyContent: 'space-between', fontFamily: 'var(--font-mono)', fontSize: 11, textTransform: 'uppercase', letterSpacing: '0.1em', color: 'var(--text-tertiary)' }}>
        <span>← Drag to explore · auto-pan</span>
        <span>8 production interfaces</span>
      </div>
    </section>
  );
}

/* ============================================
   TYPOGRAPHIC BREAK — full viewport
   ============================================ */
function TypoBreak() {
  const [ref, seen] = useReveal(0.3);
  return (
    <section ref={ref} data-bg="deep" style={{
      minHeight: '100vh',
      display: 'flex',
      alignItems: 'center',
      paddingTop: 80,
      paddingBottom: 80,
      position: 'relative',
    }}>
      <div className="container" style={{ width: '100%' }}>
        <div className={`reveal-stagger typo-break${seen ? ' in' : ''}`} style={{
          fontFamily: 'var(--font-serif)',
          fontSize: 'clamp(64px, 13vw, 180px)',
          lineHeight: 0.95,
          letterSpacing: '-0.035em',
          color: 'var(--text-primary)',
        }}>
          <div>We don't do</div>
          <div>
            <em className="slop-text" style={{
              fontStyle: 'italic',
              color: 'transparent',
              background: 'url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'400\' height=\'200\'><filter id=\'n\'><feTurbulence type=\'fractalNoise\' baseFrequency=\'1.4\' numOctaves=\'2\'/><feColorMatrix values=\'0 0 0 0 0.66 0 0 0 0 0.77 0 0 0 0 0.91 0 0 0 0.6 0\'/></filter><rect width=\'100%\' height=\'100%\' filter=\'url(%23n)\' fill=\'%23000\'/></svg>")',
              backgroundSize: 'cover',
              WebkitBackgroundClip: 'text',
              backgroundClip: 'text',
              animation: 'noiseShift 0.8s steps(4) infinite',
            }}>[generic AI slop]</em>.
          </div>
          <div style={{ marginTop: '0.4em' }}>We ship agents</div>
          <div>
            <em style={{
              fontStyle: 'italic',
              color: 'var(--accent-ice)',
              textShadow: '0 0 60px rgba(168, 197, 232, 0.4)',
            }}>to production.</em>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ============================================
   INDUSTRIES BENTO
   ============================================ */
function IndustriesBento() {
  const [ref, seen] = useReveal(0.15);
  const [isLight, setIsLight] = useStateS(false);

  useEffectS(() => {
    const mq = window.matchMedia('(hover: none), (max-width: 767px), (prefers-reduced-motion: reduce)');
    const onChange = () => setIsLight(mq.matches);
    onChange();
    if (mq.addEventListener) mq.addEventListener('change', onChange);
    else mq.addListener(onChange);
    return () => {
      if (mq.removeEventListener) mq.removeEventListener('change', onChange);
      else mq.removeListener(onChange);
    };
  }, []);

  // Pipeline data sensor flow component
  const dotCount = isLight ? 3 : 8;
  const animateDots = !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  const Pipeline = () => (
    <svg viewBox="0 0 600 280" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
      <defs>
        <linearGradient id="pipeMain" x1="0" x2="1">
          <stop offset="0%" stopColor="#1a2540" />
          <stop offset="50%" stopColor="#2a3a5e" />
          <stop offset="100%" stopColor="#1a2540" />
        </linearGradient>
      </defs>
      <line x1="0" x2="600" y1="140" y2="140" stroke="url(#pipeMain)" strokeWidth="46" />
      <line x1="0" x2="600" y1="140" y2="140" stroke="rgba(168,197,232,0.3)" strokeWidth="1" />
      <line x1="0" x2="600" y1="118" y2="118" stroke="rgba(168,197,232,0.15)" strokeWidth="1" />
      <line x1="0" x2="600" y1="162" y2="162" stroke="rgba(168,197,232,0.15)" strokeWidth="1" />
      {/* junctions with glow */}
      {[120, 280, 440].map((x, i) => (
        <g key={i}>
          <circle cx={x} cy={140} r="14" fill="rgba(168,197,232,0.15)" stroke="rgba(168,197,232,0.5)" />
          <circle cx={x} cy={140} r="4" fill="#C4DBF0">
            {animateDots && <animate attributeName="opacity" values="1;0.3;1" dur="3s" begin={`${i * 0.6}s`} repeatCount="indefinite" />}
          </circle>
        </g>
      ))}
      {/* flowing data dots */}
      {[...Array(dotCount)].map((_, i) => (
        <circle key={i} cx="0" cy="140" r="2.5" fill="#A8C5E8">
          {animateDots && <animate attributeName="cx" from="-20" to="620" dur="6s" begin={`${i * 0.7}s`} repeatCount="indefinite" />}
          {animateDots && <animate attributeName="opacity" values="0;1;1;0" keyTimes="0;0.05;0.95;1" dur="6s" begin={`${i * 0.7}s`} repeatCount="indefinite" />}
        </circle>
      ))}
    </svg>
  );

  const tiles = [
    {
      id: 'oil',
      span: 'large',
      label: 'OIL & GAS',
      title: 'Pipeline intelligence at scale',
      desc: 'Document RAG over a 40-year corpus. Defect CV on edge. HSE extraction.',
      visual: <SeismicVisual />,
      height: 380,
    },
    {
      id: 'banking',
      span: 'medium',
      label: 'BANKING',
      title: 'KYC in 90 seconds',
      desc: 'Multilingual onboarding, ready for compliance sign-off.',
      visual: <BankingBlueprint />,
      height: 380,
    },
    {
      id: 'insurance',
      span: 'medium',
      label: 'INSURANCE',
      title: 'Claim triage in days, not weeks',
      desc: 'Hospital docs → fast-track / standard / investigate.',
      visual: <DocumentStack />,
      height: 280,
    },
    {
      id: 'fintech',
      span: 'small',
      label: 'FINTECH',
      title: 'Sub-50ms fraud',
      desc: 'Auditable. Explainable.',
      visual: <FintechBars />,
      height: 280,
    },
    {
      id: 'energy',
      span: 'small',
      label: 'ENERGY',
      title: '72-hour grid forecast',
      desc: '8% lower error.',
      visual: <TopoLines />,
      height: 280,
    },
  ];

  return (
    <section ref={ref} style={{ paddingTop: 120, paddingBottom: 140 }}>
      <div className="container">
        <div className={`section-hairline`} style={{ marginBottom: 60, transform: seen ? 'scaleX(1)' : 'scaleX(0)', transition: 'transform 1200ms var(--ease-out-expo)' }} />
        <div className="industries-head" style={{ marginBottom: 64, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 60, alignItems: 'end' }}>
          <div>
            <div className="eyebrow" style={{ marginBottom: 16 }}>INDUSTRIES — WHERE WE SHIP</div>
            <h2 className="serif section-h2" style={{
              fontSize: 'clamp(40px, 5vw, 64px)',
              letterSpacing: '-0.025em',
              lineHeight: 1.05,
            }}>
              Built for the <em style={{ color: 'var(--accent-ice)', fontStyle: 'italic' }}>Caspian's</em> regulated work.
            </h2>
          </div>
          <p style={{ color: 'var(--text-secondary)', fontSize: 17, maxWidth: 460, justifySelf: 'end' }}>
            Real product, real data, real operators. Five sectors. Production deployments.
          </p>
        </div>
        <div className={`reveal-stagger bento-grid${seen ? ' in' : ''}`} style={{
          display: 'grid',
          gridTemplateColumns: 'repeat(6, 1fr)',
          gap: 16,
        }}>
          {tiles.map(tile => (
            <BentoTile key={tile.id} kind={tile.id} span={tile.span} label={tile.label} title={tile.title} desc={tile.desc} visual={tile.visual} height={tile.height} />
          ))}
        </div>
      </div>
    </section>
  );
}

/* Bento tile — distinct chrome per sector (no shared glass-interactive) */
function BentoTile({ span, label, title, desc, visual, height, kind }) {
  const colSpan = span === 'large' ? 4 : span === 'medium' ? 3 : 2;

  // Each tile has its own composed chrome
  const chrome = {
    oil: {
      // Full-bleed seismic background, text overlaid, no glass scrim
      background: 'linear-gradient(180deg, #060810 0%, #0c1430 50%, #060810 100%)',
      border: '1px solid var(--border-glass)',
      boxShadow: 'inset 0 1px 0 0 rgba(168, 197, 232, 0.08)',
    },
    banking: {
      // Blueprint-style — schematic background with technical caption look
      background: 'linear-gradient(135deg, #08101e 0%, #0a0e16 100%)',
      border: '1px dashed rgba(168, 197, 232, 0.18)',
      backgroundImage: 'linear-gradient(135deg, #08101e 0%, #0a0e16 100%), repeating-linear-gradient(0deg, transparent 0, transparent 19px, rgba(168, 197, 232, 0.04) 19px, rgba(168, 197, 232, 0.04) 20px)',
      backgroundBlendMode: 'screen',
    },
    insurance: {
      // Stack of overlapping document edges
      background: '#0a0e16',
      border: '1px solid var(--border-glass)',
    },
    fintech: {
      // No card frame — just hairline top/bottom
      background: 'transparent',
      border: 'none',
      borderTop: '1px solid var(--border-glass)',
      borderBottom: '1px solid var(--border-glass)',
      borderRadius: 0,
    },
    energy: {
      // Topographic contour bg
      background: 'linear-gradient(135deg, #0a0e16 0%, #08101a 100%)',
      border: '1px solid var(--border-glass)',
    },
  };

  const isFintech = kind === 'fintech';
  return (
    <a href="#agents"
      className={`bento-tile bento-${kind}`}
      style={{
        gridColumn: `span ${colSpan}`,
        height,
        position: 'relative',
        overflow: 'hidden',
        display: 'flex',
        flexDirection: 'column',
        justifyContent: kind === 'oil' ? 'flex-end' : 'space-between',
        padding: kind === 'fintech' ? '20px 24px' : 24,
        borderRadius: isFintech ? 0 : 14,
        textDecoration: 'none',
        color: 'inherit',
        ...chrome[kind],
      }}>
      <div style={{ position: 'absolute', inset: 0, opacity: kind === 'oil' ? 0.85 : 0.7 }}>{visual}</div>
      {/* per-tile scrim differs */}
      {kind === 'oil' && (
        <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(180deg, transparent 35%, rgba(4, 6, 10, 0.92) 100%)' }} />
      )}
      {kind === 'insurance' && (
        <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(270deg, transparent 40%, rgba(4, 6, 10, 0.9) 100%)' }} />
      )}
      {kind === 'energy' && (
        <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(0deg, rgba(4, 6, 10, 0.7) 0%, transparent 60%)' }} />
      )}

      {/* Banking: blueprint margin caption layout */}
      {kind === 'banking' && (
        <div style={{ position: 'relative', zIndex: 2, display: 'flex', flexDirection: 'column', height: '100%', justifyContent: 'space-between' }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, color: 'var(--accent-ice)', letterSpacing: '0.18em' }}>{label}</span>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: 9, color: 'var(--text-tertiary)' }}>FIG-01 · KYC PIPELINE</span>
          </div>
          <div style={{ marginTop: 'auto', borderTop: '1px dashed rgba(168, 197, 232, 0.25)', paddingTop: 14, display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', gap: 16 }}>
            <div>
              <h3 className="serif bento-title" style={{ fontSize: span === 'large' ? 36 : 28, letterSpacing: '-0.02em', lineHeight: 1.05, marginBottom: 6 }}>{title}</h3>
              <p style={{ color: 'var(--text-secondary)', fontSize: 14 }}>{desc}</p>
            </div>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, color: 'var(--accent-ice)', whiteSpace: 'nowrap', letterSpacing: '0.1em' }}>SEE → /use-cases</span>
          </div>
        </div>
      )}

      {/* Fintech: minimal — chart + hairline */}
      {kind === 'fintech' && (
        <div style={{ position: 'relative', zIndex: 2, display: 'flex', flexDirection: 'column', height: '100%' }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, color: 'var(--accent-ice)', letterSpacing: '0.18em' }}>{label}</span>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: 9, color: 'var(--text-tertiary)' }}>TX/H · 24H</span>
          </div>
          <h3 className="serif bento-title" style={{ fontSize: 22, letterSpacing: '-0.015em', marginTop: 12, lineHeight: 1.1 }}>{title}</h3>
          <p style={{ color: 'var(--text-secondary)', fontSize: 13, marginTop: 4 }}>{desc}</p>
        </div>
      )}

      {/* Insurance: right-justified text */}
      {kind === 'insurance' && (
        <div style={{ position: 'relative', zIndex: 2, marginLeft: 'auto', maxWidth: '60%', textAlign: 'right' }}>
          <div className="eyebrow" style={{ marginBottom: 8, color: 'var(--accent-ice)' }}>{label}</div>
          <h3 className="serif bento-title" style={{ fontSize: 26, letterSpacing: '-0.02em', lineHeight: 1.08, marginBottom: 6 }}>{title}</h3>
          <p style={{ color: 'var(--text-secondary)', fontSize: 13 }}>{desc}</p>
        </div>
      )}

      {/* Energy: standard composition with topo background */}
      {kind === 'energy' && (
        <div style={{ position: 'relative', zIndex: 2 }}>
          <div className="eyebrow" style={{ marginBottom: 8, color: 'var(--accent-ice)' }}>{label}</div>
          <h3 className="serif bento-title" style={{ fontSize: 22, letterSpacing: '-0.015em', lineHeight: 1.08, marginBottom: 6 }}>{title}</h3>
          <p style={{ color: 'var(--text-secondary)', fontSize: 13 }}>{desc}</p>
        </div>
      )}

      {/* Oil: bottom-anchored text with kicker on top corner */}
      {kind === 'oil' && (
        <>
          <div style={{ position: 'absolute', top: 24, left: 24, right: 24, zIndex: 2, display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
            <span className="eyebrow" style={{ color: 'var(--accent-ice)' }}>{label}</span>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, color: 'var(--text-tertiary)' }}>40yr · multilingual</span>
          </div>
          <div style={{ position: 'relative', zIndex: 2 }}>
            <h3 className="serif bento-title" style={{ fontSize: 40, letterSpacing: '-0.025em', lineHeight: 1.0, marginBottom: 10 }}>{title}</h3>
            <p style={{ color: 'var(--text-secondary)', fontSize: 15, marginBottom: 14, maxWidth: 380 }}>{desc}</p>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11, textTransform: 'uppercase', letterSpacing: '0.12em', color: 'var(--accent-ice)', borderBottom: '1px solid var(--accent-ice)', paddingBottom: 2 }}>See use cases →</span>
          </div>
        </>
      )}
    </a>
  );
}

/* ============================================
   BENTO VISUALS — bespoke per sector
   ============================================ */

/* Oil & Gas: seismic strata as full-bleed background image */
function SeismicVisual() {
  return (
    <div className="bento-amb-drift-x" style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <svg viewBox="0 0 720 380" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%' }}>
        <defs>
          <linearGradient id="strata1" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0%" stopColor="rgba(168,197,232,0.25)" />
            <stop offset="50%" stopColor="rgba(196,219,240,0.15)" />
            <stop offset="100%" stopColor="rgba(168,197,232,0.05)" />
          </linearGradient>
        </defs>
        {/* layered seismic strata */}
        {Array.from({ length: 24 }).map((_, i) => {
          const y = i * 18 + 30;
          const amp = 8 + (i % 4) * 4;
          const offsets = Array.from({ length: 13 }).map((__, j) => Math.sin((j + i * 0.4) * 0.6) * amp);
          const d = `M -10 ${y} ` + offsets.map((o, j) => `L ${j * 60} ${y + o}`).join(' ') + ` L 730 ${y + offsets[12]}`;
          return <path key={i} d={d} stroke={`rgba(168,197,232,${0.05 + (i % 3) * 0.04})`} strokeWidth={i % 6 === 0 ? 1.4 : 0.6} fill="none" />;
        })}
        {/* Well markers */}
        {[[120, 180], [280, 220], [440, 200], [560, 250]].map(([x, y], i) => (
          <g key={i}>
            <line x1={x} y1={y} x2={x} y2={380} stroke="rgba(232,212,168,0.4)" strokeWidth="1" strokeDasharray="2,3" />
            <circle cx={x} cy={y} r="3" fill="#E8D4A8" />
          </g>
        ))}
      </svg>
    </div>
  );
}

/* Banking: blueprint schematic of KYC pipeline */
function BankingBlueprint() {
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <svg viewBox="0 0 600 380" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%', opacity: 0.9 }}>
        <defs>
          <pattern id="bp-grid" width="20" height="20" patternUnits="userSpaceOnUse">
            <path d="M 20 0 L 0 0 0 20" fill="none" stroke="rgba(168,197,232,0.06)" strokeWidth="0.5" />
          </pattern>
        </defs>
        <rect width="600" height="380" fill="url(#bp-grid)" />
        {/* Pipeline boxes */}
        {[
          [60, 'INGEST'], [180, 'OCR'], [300, 'NER'], [420, 'SCREEN'], [540, 'DECIDE'],
        ].map(([x, l], i) => (
          <g key={l}>
            <rect x={x - 32} y="160" width="64" height="40" fill="rgba(8,12,20,0.6)" stroke="rgba(168,197,232,0.4)" strokeWidth="1" strokeDasharray="3,2" />
            <text x={x} y="184" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="9" fill="rgba(168,197,232,0.85)" letterSpacing="0.1em">{l}</text>
            {i < 4 && <line x1={x + 32} y1="180" x2={x + 88} y2="180" stroke="rgba(168,197,232,0.3)" strokeWidth="1" markerEnd="url(#arrow1)" />}
          </g>
        ))}
        <defs>
          <marker id="arrow1" viewBox="0 0 8 8" refX="6" refY="4" markerWidth="6" markerHeight="6" orient="auto">
            <path d="M 0 0 L 8 4 L 0 8 z" fill="rgba(168,197,232,0.5)" />
          </marker>
        </defs>
        {/* dimension lines (hover-revealed) */}
        <g data-bp-fade="">
          <line x1="28" y1="240" x2="572" y2="240" stroke="rgba(168,197,232,0.4)" strokeWidth="0.5" />
          <line x1="28" y1="232" x2="28" y2="248" stroke="rgba(168,197,232,0.4)" strokeWidth="0.5" />
          <line x1="572" y1="232" x2="572" y2="248" stroke="rgba(168,197,232,0.4)" strokeWidth="0.5" />
          <text x="300" y="260" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="9" fill="rgba(168,197,232,0.7)" letterSpacing="0.15em">90s · END-TO-END</text>
        </g>
        {/* annotations */}
        <text x="60" y="140" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="7" fill="rgba(168,197,232,0.4)">A.</text>
        <text x="540" y="140" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="7" fill="rgba(168,197,232,0.4)">E.</text>
      </svg>
    </div>
  );
}

/* Insurance: stack of overlapping document edges */
function DocumentStack() {
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <svg viewBox="0 0 480 280" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%' }}>
        {/* stacked papers */}
        {[
          { x: 30, y: 50, rot: -6, c: 'rgba(232,168,181,0.14)', tag: 'INV' },
          { x: 90, y: 35, rot: -3, c: 'rgba(232,212,168,0.16)', tag: 'STD' },
          { x: 150, y: 20, rot: 0, c: 'rgba(168,197,232,0.18)', tag: 'STD' },
          { x: 210, y: 30, rot: 3, c: 'rgba(168,232,197,0.18)', tag: 'FAST' },
          { x: 270, y: 45, rot: 6, c: 'rgba(168,232,197,0.14)', tag: 'FAST' },
        ].map((p, i) => (
          <g key={i} transform={`translate(${p.x}, ${p.y}) rotate(${p.rot} 70 100)`}>
            <rect className="doc-stack-edge" data-doc-i={i} x="0" y="0" width="140" height="200" fill={p.c} stroke="rgba(168,197,232,0.3)" strokeWidth="0.8" />
            <line x1="14" y1="22" x2="120" y2="22" stroke="rgba(168,197,232,0.25)" strokeWidth="0.6" />
            <line x1="14" y1="34" x2="100" y2="34" stroke="rgba(168,197,232,0.18)" strokeWidth="0.6" />
            <line x1="14" y1="46" x2="120" y2="46" stroke="rgba(168,197,232,0.18)" strokeWidth="0.6" />
            <line x1="14" y1="58" x2="80" y2="58" stroke="rgba(168,197,232,0.14)" strokeWidth="0.6" />
            <text x="70" y="184" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="10" fill="rgba(168,197,232,0.6)" letterSpacing="0.1em">{p.tag}</text>
          </g>
        ))}
      </svg>
    </div>
  );
}

/* Fintech: compact bar chart of transactions per hour */
function FintechBars() {
  const bars = [12, 18, 22, 28, 36, 44, 52, 58, 62, 68, 71, 74, 76, 73, 68, 60, 52, 44, 38, 32, 28, 22, 18, 14];
  const max = Math.max(...bars);
  return (
    <div style={{ position: 'absolute', inset: 0, padding: '60px 24px 20px', display: 'flex', alignItems: 'flex-end', gap: 2 }}>
      {bars.map((b, i) => (
        <div key={i} className={i === 12 ? 'bento-amb-pulse' : ''} style={{
          flex: 1,
          height: `${(b / max) * 100}%`,
          background: i === 12 ? 'var(--accent-ice-bright)' : 'rgba(168,197,232,0.35)',
          borderRadius: '1px 1px 0 0',
          transformOrigin: 'bottom center',
        }} />
      ))}
    </div>
  );
}

/* Energy: topographic contour lines */
function TopoLines() {
  return (
    <div className="bento-amb-drift-x-slow" style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
      <svg viewBox="0 0 480 280" preserveAspectRatio="xMidYMid slice" style={{ width: '100%', height: '100%' }}>
        {Array.from({ length: 14 }).map((_, i) => {
          const r = 60 + i * 22;
          const isHi = i === 7;
          return <ellipse
            key={i}
            className={isHi ? 'topo-ring-hilite' : ''}
            cx="240" cy="140"
            rx={r * 1.15} ry={r * 0.55}
            fill="none"
            stroke={isHi ? '#E8D4A8' : 'rgba(168,197,232,0.12)'}
            strokeWidth={isHi ? 1.2 : 0.6}
          />;
        })}
        {/* solar farm marker — highlighted shape */}
        <g>
          <polygon points="180,150 240,130 300,150 240,170" fill="rgba(232,212,168,0.4)" stroke="#E8D4A8" strokeWidth="1.2" />
          <text x="240" y="200" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="8" fill="rgba(232,212,168,0.7)" letterSpacing="0.15em">PIRALLAHI · 147MW</text>
        </g>
      </svg>
    </div>
  );
}

Object.assign(window, { StatsRow, ProductShowcase, TypoBreak, IndustriesBento, useReveal });