// ============================================================
// PRODOTTO — AiKo Engine
// Hero + Cosa fa + Pipeline + Phases + Memory + Compare + Use cases + Stack + CTA
// ============================================================
const { useState: useStateAK, useEffect: useEffectAK, useRef: useRefAK } = React;
const motionAK = new Proxy({}, { get: (_, p) => window.FramerMotion.motion[p] });
const useInViewAK = (...a) => window.FramerMotion.useInView(...a);

// ============================================================
// HERO prodotto
// ============================================================
function AikoHero() {
  const ref = useRefAK(null);
  const isInView = useInViewAK(ref, { once: true });
  return (
    <section ref={ref} style={{
      position: 'relative', overflow: 'hidden',
      padding: '160px 5% 90px',
      background: '#08080f',
    }}>
      <MatrixRain opacity={0.7} />
      <GamingGrid accent={colors.brandGold} />
      <Cartouche accent={colors.brandGold} text="AIKO · 知能" top={130} right={36} />
      <div style={{
        position: 'absolute', inset: 0,
        background: `
          radial-gradient(ellipse 60% 40% at 30% 30%, rgba(201,168,76,0.1), transparent 70%),
          radial-gradient(ellipse 40% 50% at 70% 70%, rgba(45,106,79,0.06), transparent 70%)
        `,
        pointerEvents: 'none',
      }} />

      <div style={{
        maxWidth: 1080, margin: '0 auto', position: 'relative', zIndex: 1,
        display: 'grid', gridTemplateColumns: '1.4fr 1fr', gap: 60, alignItems: 'center',
      }} className="aiko-hero-grid">
        <div>
          <motionAK.div
            initial={{ opacity: 0, y: -10 }}
            animate={isInView ? { opacity: 1, y: 0 } : {}}
            transition={{ duration: 0.6 }}
            style={{
              display: 'inline-flex', alignItems: 'center', gap: 10,
              padding: '6px 14px', marginBottom: 24,
              border: `1px solid rgba(201,168,76,0.3)`,
              borderRadius: 999, background: 'rgba(15,15,35,0.6)',
            }}
          >
            <span style={{
              fontSize: '0.6rem', padding: '2px 8px',
              background: `${colors.brandGoldMuted}25`,
              border: `1px solid ${colors.brandGoldMuted}50`,
              borderRadius: 20, color: colors.brandGold,
              fontWeight: 700, letterSpacing: 1.5,
              fontFamily: "'Courier Prime', monospace",
            }}>★ FLAGSHIP</span>
            <span style={{
              fontFamily: "'Courier Prime', monospace",
              fontSize: '0.7rem', color: colors.textGold,
              letterSpacing: 2, textTransform: 'uppercase', fontWeight: 600,
            }}>AI Orchestration Engine</span>
          </motionAK.div>

          <motionAK.div
            initial={{ opacity: 0, y: 24 }}
            animate={isInView ? { opacity: 1, y: 0 } : {}}
            transition={{ duration: 0.8, delay: 0.15 }}
            style={{ display: 'flex', alignItems: 'center', gap: 18, marginBottom: 18, flexWrap: 'wrap' }}
          >
            <AiKoLogo size={84} />
            <h1 style={{
              fontFamily: "'Orbitron', sans-serif",
              fontSize: 'clamp(2.8rem, 6vw, 5.2rem)',
              fontWeight: 900, letterSpacing: 6, lineHeight: 1, margin: 0,
              background: `linear-gradient(135deg, ${colors.brandGold}, ${colors.brandGoldMuted}, ${colors.brandEmerald})`,
              WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent',
            }}>AiKo</h1>
          </motionAK.div>

          <motionAK.p
            initial={{ opacity: 0, y: 16 }}
            animate={isInView ? { opacity: 1, y: 0 } : {}}
            transition={{ duration: 0.8, delay: 0.3 }}
            style={{
              fontFamily: "'Cinzel', serif",
              fontSize: 'clamp(1.2rem, 2vw, 1.6rem)',
              color: colors.textGold, fontStyle: 'italic',
              lineHeight: 1.4, marginBottom: 26, textWrap: 'balance',
            }}
          >Convergence, verified.</motionAK.p>

          <motionAK.p
            initial={{ opacity: 0, y: 16 }}
            animate={isInView ? { opacity: 1, y: 0 } : {}}
            transition={{ duration: 0.8, delay: 0.45 }}
            style={{
              fontSize: '1.05rem', color: '#c8c5bd',
              lineHeight: 1.75, marginBottom: 36, fontWeight: 300,
              maxWidth: 580, textWrap: 'pretty',
            }}
          >
            Pipeline di orchestrazione multi-agente AI,
            domain-specific per IBM i. Converte programmi RPG legacy in applicazioni
            web moderne con un'accuratezza del <span style={{ color: colors.textGold, fontWeight: 600 }}>95%</span>.
          </motionAK.p>

          <motionAK.div
            initial={{ opacity: 0, y: 16 }}
            animate={isInView ? { opacity: 1, y: 0 } : {}}
            transition={{ duration: 0.8, delay: 0.6 }}
            style={{ display: 'flex', gap: 14, flexWrap: 'wrap' }}
          >
            <a href="../contatti.html" style={{
              fontFamily: "'DM Sans', sans-serif",
              fontSize: '0.95rem', fontWeight: 600,
              padding: '14px 28px',
              background: `linear-gradient(135deg, ${colors.brandGold}, ${colors.brandGoldMuted})`,
              color: colors.bgPrimary, borderRadius: 6,
              textDecoration: 'none', letterSpacing: 0.5,
              boxShadow: `0 0 30px rgba(255,215,0,0.25)`,
              transition: 'all 0.3s',
              display: 'inline-flex', alignItems: 'center', gap: 10,
            }}
              onMouseEnter={e => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 6px 40px rgba(255,215,0,0.35)'; }}
              onMouseLeave={e => { e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = '0 0 30px rgba(255,215,0,0.25)'; }}
            >Richiedi una demo <Icon name="arrow-right" size={16} color={colors.bgPrimary} /></a>
            <a href="#pipeline" style={{
              fontFamily: "'DM Sans', sans-serif",
              fontSize: '0.95rem', fontWeight: 500,
              padding: '14px 28px',
              background: 'transparent', color: colors.textPrimary,
              border: `1px solid rgba(255,215,0,0.35)`,
              borderRadius: 6, textDecoration: 'none',
              letterSpacing: 0.5, transition: 'all 0.3s',
            }}
              onMouseEnter={e => { e.currentTarget.style.borderColor = colors.brandGold; e.currentTarget.style.color = colors.brandGold; }}
              onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255,215,0,0.35)'; e.currentTarget.style.color = colors.textPrimary; }}
            >Come funziona</a>
          </motionAK.div>
        </div>

        <motionAK.div
          initial={{ opacity: 0, scale: 0.9 }}
          animate={isInView ? { opacity: 1, scale: 1 } : {}}
          transition={{ duration: 1, delay: 0.4 }}
          style={{ display: 'flex', justifyContent: 'center' }}
          className="aiko-hero-logo"
        >
          <div style={{ position: 'relative', width: 320, height: 380 }}>
            {/* Hexagonal frame */}
            <div style={{
              position: 'absolute', inset: 0,
              clipPath: 'polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)',
              background: `linear-gradient(135deg, ${colors.brandGold}, ${colors.brandGoldMuted}, ${colors.brandEmerald})`,
              padding: 3,
            }}>
              <div style={{
                width: '100%', height: '100%',
                clipPath: 'polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)',
                background: '#08080f', position: 'relative', overflow: 'hidden',
              }}>
                <picture>
                  <source srcSet="../assets/aiko.webp" type="image/webp" />
                  <source srcSet="../assets/aiko.jpg" type="image/jpeg" />
                  <img src="../assets/aiko.jpg" alt="AiKo avatar" loading="lazy" decoding="async"
                    style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 20%' }}
                    onError={e => { e.currentTarget.style.display = 'none'; }} />
                </picture>
                {/* Scanline overlay */}
                <div style={{
                  position: 'absolute', inset: 0,
                  background: 'repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,215,0,0.06) 2px, rgba(255,215,0,0.06) 3px)',
                  pointerEvents: 'none',
                }} />
                {/* HUD corners */}
                <div style={{ position: 'absolute', top: 14, left: 14, width: 18, height: 18, borderTop: `2px solid ${colors.brandGold}`, borderLeft: `2px solid ${colors.brandGold}` }} />
                <div style={{ position: 'absolute', top: 14, right: 14, width: 18, height: 18, borderTop: `2px solid ${colors.brandGold}`, borderRight: `2px solid ${colors.brandGold}` }} />
                <div style={{ position: 'absolute', bottom: 14, left: 14, width: 18, height: 18, borderBottom: `2px solid ${colors.brandGold}`, borderLeft: `2px solid ${colors.brandGold}` }} />
                <div style={{ position: 'absolute', bottom: 14, right: 14, width: 18, height: 18, borderBottom: `2px solid ${colors.brandGold}`, borderRight: `2px solid ${colors.brandGold}` }} />
                {/* Status bar */}
                <div style={{
                  position: 'absolute', bottom: 0, left: 0, right: 0,
                  padding: '10px 18px',
                  background: 'linear-gradient(0deg, rgba(0,0,0,0.85), transparent)',
                  fontFamily: "'Courier Prime', monospace",
                  fontSize: '0.6rem', color: colors.brandGold,
                  letterSpacing: 1.5, display: 'flex', justifyContent: 'space-between',
                }}>
                  <span>★ ONLINE</span>
                  <span>SYS: 95%</span>
                </div>
              </div>
            </div>
            {/* Outer glow */}
            <div style={{
              position: 'absolute', inset: -60,
              background: `radial-gradient(circle, rgba(255,215,0,0.18), transparent 70%)`,
              zIndex: -1, pointerEvents: 'none',
            }} />
          </div>
        </motionAK.div>
      </div>

      <style>{`
        @media (max-width: 880px) {
          .aiko-hero-grid { grid-template-columns: 1fr !important; gap: 40px !important; }
          .aiko-hero-logo { order: -1; }
        }
      `}</style>
    </section>
  );
}

// ============================================================
// COSA FA — gaming ability cards (3D tilt + neon glow)
// ============================================================
function AbilityCard({ c, i, accent }) {
  const cardRef = useRefAK(null);
  const [tilt, setTilt] = useStateAK({ rx: 0, ry: 0, mx: 50, my: 50 });

  const handleMove = (e) => {
    const r = cardRef.current.getBoundingClientRect();
    const x = e.clientX - r.left, y = e.clientY - r.top;
    const ry = ((x / r.width) - 0.5) * 18;
    const rx = -((y / r.height) - 0.5) * 18;
    setTilt({ rx, ry, mx: (x / r.width) * 100, my: (y / r.height) * 100 });
  };
  const handleLeave = () => setTilt({ rx: 0, ry: 0, mx: 50, my: 50 });

  return (
    <motionAK.div
      initial={{ opacity: 0, y: 30 }}
      whileInView={{ opacity: 1, y: 0 }}
      viewport={{ once: true }}
      transition={{ delay: i * 0.1, duration: 0.6 }}
      style={{ perspective: 1200 }}
    >
      <div
        ref={cardRef}
        onMouseMove={handleMove}
        onMouseLeave={handleLeave}
        style={{
          padding: 28, position: 'relative', overflow: 'hidden',
          background: `linear-gradient(145deg, rgba(20,18,8,0.95), rgba(8,8,15,0.9))`,
          border: `1px solid rgba(201,168,76,0.3)`,
          borderRadius: 14,
          transformStyle: 'preserve-3d',
          transform: `rotateX(${tilt.rx}deg) rotateY(${tilt.ry}deg)`,
          transition: 'transform 0.15s ease-out, border-color 0.3s',
          cursor: 'pointer',
          boxShadow: `0 20px 60px -20px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,215,0,0.1) inset`,
          minHeight: 280,
        }}
        onMouseEnter={e => e.currentTarget.style.borderColor = accent}
      >
        {/* Hex grid background */}
        <div style={{
          position: 'absolute', inset: 0,
          backgroundImage: `radial-gradient(circle at ${tilt.mx}% ${tilt.my}%, ${accent}22, transparent 50%)`,
          pointerEvents: 'none', transition: 'background 0.2s',
        }} />
        <div style={{
          position: 'absolute', inset: 0,
          backgroundImage: `linear-gradient(90deg, ${accent}08 1px, transparent 1px), linear-gradient(0deg, ${accent}08 1px, transparent 1px)`,
          backgroundSize: '20px 20px',
          maskImage: 'radial-gradient(ellipse at center, black, transparent 80%)',
          WebkitMaskImage: 'radial-gradient(ellipse at center, black, transparent 80%)',
          opacity: 0.5,
        }} />
        {/* HUD corners */}
        <div style={{ position: 'absolute', top: 10, left: 10, width: 14, height: 14, borderTop: `2px solid ${accent}`, borderLeft: `2px solid ${accent}`, opacity: 0.7 }} />
        <div style={{ position: 'absolute', top: 10, right: 10, width: 14, height: 14, borderTop: `2px solid ${accent}`, borderRight: `2px solid ${accent}`, opacity: 0.7 }} />
        <div style={{ position: 'absolute', bottom: 10, left: 10, width: 14, height: 14, borderBottom: `2px solid ${accent}`, borderLeft: `2px solid ${accent}`, opacity: 0.7 }} />
        <div style={{ position: 'absolute', bottom: 10, right: 10, width: 14, height: 14, borderBottom: `2px solid ${accent}`, borderRight: `2px solid ${accent}`, opacity: 0.7 }} />

        {/* Top scan line */}
        <div style={{
          position: 'absolute', top: 0, left: 0, right: 0, height: 2,
          background: `linear-gradient(90deg, transparent, ${accent}, transparent)`,
          boxShadow: `0 0 12px ${accent}`,
        }} />

        <div style={{ position: 'relative', zIndex: 2, transform: 'translateZ(40px)' }}>
          {/* Ability badge */}
          <div style={{
            display: 'inline-flex', alignItems: 'center', gap: 8,
            padding: '4px 10px', marginBottom: 18,
            background: 'rgba(0,0,0,0.4)', border: `1px solid ${accent}50`,
            borderRadius: 4, fontFamily: "'Courier Prime', monospace",
            fontSize: '0.6rem', color: accent, letterSpacing: 2, fontWeight: 700,
          }}>
            <span style={{ width: 6, height: 6, borderRadius: '50%', background: accent, boxShadow: `0 0 8px ${accent}` }} />
            SKILL_{String(i + 1).padStart(2, '0')}
          </div>

          {/* Hexagonal icon */}
          <div style={{
            width: 64, height: 72, marginBottom: 18, position: 'relative',
          }}>
            <div style={{
              position: 'absolute', inset: 0,
              clipPath: 'polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)',
              background: `linear-gradient(135deg, ${accent}, ${accent}66)`,
              padding: 2,
            }}>
              <div style={{
                width: '100%', height: '100%',
                clipPath: 'polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)',
                background: 'rgba(8,8,15,0.95)',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
              }}>
                <Icon name={c.icon} size={28} color={accent} />
              </div>
            </div>
            <div style={{
              position: 'absolute', inset: -6,
              background: `radial-gradient(circle, ${accent}30, transparent 60%)`,
              zIndex: -1,
            }} />
          </div>

          <h3 style={{
            fontFamily: "'Orbitron', sans-serif",
            fontSize: '1.05rem', color: colors.textPrimary,
            fontWeight: 700, marginBottom: 12, letterSpacing: 1.5,
            textTransform: 'uppercase',
          }}>{c.title}</h3>
          <p style={{
            fontSize: '0.88rem', color: colors.textMuted,
            lineHeight: 1.7, fontWeight: 300,
          }}>{c.desc}</p>
        </div>
      </div>
    </motionAK.div>
  );
}

function AikoWhatItDoes() {
  const abilities = [
    { icon: 'cpu', title: 'Conversione assistita', desc: 'AiKo legge il sorgente RPG, ne capisce la business logic e genera codice moderno equivalente. L\'umano approva.' },
    { icon: 'shield-check', title: 'Domain-specific', desc: 'Non è un prompt generico: è una pipeline costruita su pattern RPG/ILE/DB2 reali, codificati e versionati.' },
    { icon: 'infinity', title: 'Zero disruption', desc: 'La modernizzazione avviene modulo per modulo. La produzione non si ferma. La logica resta dove funziona.' },
  ];
  return (
    <AnimatedSection style={{
      padding: '110px 5%', background: '#08080f', position: 'relative', overflow: 'hidden',
    }}>
      {/* Subtle gaming grid */}
      <div style={{
        position: 'absolute', inset: 0,
        backgroundImage: `linear-gradient(${colors.brandGold}08 1px, transparent 1px), linear-gradient(90deg, ${colors.brandGold}08 1px, transparent 1px)`,
        backgroundSize: '60px 60px',
        maskImage: 'radial-gradient(ellipse 60% 50% at center, black, transparent)',
        WebkitMaskImage: 'radial-gradient(ellipse 60% 50% at center, black, transparent)',
      }} />

      <div style={{ maxWidth: 1080, margin: '0 auto', position: 'relative' }}>
        <div style={{ textAlign: 'center', marginBottom: 60 }}>
          <div style={{
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.72rem', color: colors.textGold,
            letterSpacing: 3, textTransform: 'uppercase',
            marginBottom: 16, fontWeight: 600,
          }}>// SKILL_TREE.exe</div>
          <h2 style={{
            fontFamily: "'Cinzel', serif",
            fontSize: 'clamp(1.9rem, 3.4vw, 2.7rem)',
            color: colors.textPrimary, fontWeight: 500,
            lineHeight: 1.3, marginBottom: 20, textWrap: 'balance',
          }}>
            Trasforma codice RPG che tiene in piedi aziende intere<br />
            <span style={{ color: colors.textGold, fontStyle: 'italic' }}>in applicazioni web moderne, modulo per modulo.</span>
          </h2>
        </div>

        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))',
          gap: 24,
        }}>
          {abilities.map((c, i) => (
            <AbilityCard key={i} c={c} i={i} accent={colors.brandGold} />
          ))}
        </div>
      </div>
    </AnimatedSection>
  );
}

// ============================================================
// PIPELINE
// ============================================================
function AikoPipeline() {
  const ref = useRefAK(null);
  const isInView = useInViewAK(ref, { once: true, margin: '-100px' });

  const pipeline = [
    { id: 1, label: 'Analisi Sorgente', icon: 'search-code',
      desc: 'L\'Analyst produce analisi backend e frontend dettagliate, con vincoli ancorati al blueprint.',
      output: 'analisi backend · analisi frontend' },
    { id: 2, label: 'Generazione Codice', icon: 'cpu',
      desc: 'Il Backend Developer converte RPG, compila, legge spool, corregge iterativamente.',
      output: 'modulo.rpgle compilato · 95% pass rate' },
    { id: 3, label: 'Review & Deploy', icon: 'rocket',
      desc: 'Approvazione umana, Frontend Developer genera pagina React, deploy staging.',
      output: 'page.jsx · staging URL · audit log' },
    { id: 4, label: 'Documentazione', icon: 'file-text',
      desc: 'Il Docs Writer redige documentazione tecnica e operativa del modulo: API, contratti dati, runbook, note per chi mantiene.',
      output: 'docs tecniche · manuale operativo · changelog' },
  ];

  return (
    <AnimatedSection id="pipeline" style={{
      padding: '110px 5%', background: '#08080f', position: 'relative', overflow: 'hidden',
    }}>
      {/* Arena floor — radial vignette + grid */}
      <div style={{
        position: 'absolute', inset: 0,
        background: `radial-gradient(ellipse 70% 50% at 50% 50%, rgba(201,168,76,0.08), transparent 70%)`,
        pointerEvents: 'none',
      }} />
      <div style={{
        position: 'absolute', inset: 0,
        backgroundImage: `linear-gradient(${colors.brandGold}10 1px, transparent 1px), linear-gradient(90deg, ${colors.brandGold}10 1px, transparent 1px)`,
        backgroundSize: '40px 40px',
        maskImage: 'radial-gradient(ellipse 70% 60% at center, black, transparent)',
        WebkitMaskImage: 'radial-gradient(ellipse 70% 60% at center, black, transparent)',
        opacity: 0.4,
      }} />

      <div ref={ref} style={{ maxWidth: 1180, margin: '0 auto', position: 'relative' }}>
        <SectionHeading
          eyebrow="// EXEC_PIPELINE.run"
          title="Pipeline a 4 stadi"
          sub="Human-in-the-loop. L'umano approva, l'AI esegue. Quattro stadi orchestrati, dall'analisi alla documentazione."
        />

        {/* HUD frame */}
        <div style={{
          padding: '50px 32px 36px', marginTop: 60,
          background: 'linear-gradient(180deg, rgba(15,15,35,0.7), rgba(8,8,15,0.95))',
          border: `1px solid rgba(201,168,76,0.3)`,
          borderRadius: 16, position: 'relative',
          boxShadow: `0 0 0 1px rgba(255,215,0,0.05) inset, 0 30px 80px -30px rgba(0,0,0,0.7)`,
        }}>
          {/* HUD top bar */}
          <div style={{
            position: 'absolute', top: 14, left: 20, right: 20,
            display: 'flex', justifyContent: 'space-between', alignItems: 'center',
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.6rem', color: colors.textDim,
            letterSpacing: 1.8,
          }}>
            <span style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
              <span style={{
                width: 6, height: 6, borderRadius: '50%', background: colors.brandGreen,
                boxShadow: `0 0 8px ${colors.brandGreen}`,
                animation: 'aiko-pulse 1.4s ease-in-out infinite',
              }} />
              SYS://PIPELINE.STATUS = ACTIVE
            </span>
            <span>HUMAN-IN-THE-LOOP</span>
          </div>
          {/* HUD corners */}
          <div style={{ position: 'absolute', top: 8, left: 8, width: 14, height: 14, borderTop: `2px solid ${colors.brandGold}`, borderLeft: `2px solid ${colors.brandGold}` }} />
          <div style={{ position: 'absolute', top: 8, right: 8, width: 14, height: 14, borderTop: `2px solid ${colors.brandGold}`, borderRight: `2px solid ${colors.brandGold}` }} />
          <div style={{ position: 'absolute', bottom: 8, left: 8, width: 14, height: 14, borderBottom: `2px solid ${colors.brandGold}`, borderLeft: `2px solid ${colors.brandGold}` }} />
          <div style={{ position: 'absolute', bottom: 8, right: 8, width: 14, height: 14, borderBottom: `2px solid ${colors.brandGold}`, borderRight: `2px solid ${colors.brandGold}` }} />

          <div style={{
            display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)',
            gap: 28, position: 'relative', marginTop: 14,
          }} className="pipeline-grid">
            {pipeline.map((step, i) => (
              <React.Fragment key={step.id}>
                <motionAK.div
                  initial={{ opacity: 0, y: 30 }}
                  animate={isInView ? { opacity: 1, y: 0 } : {}}
                  transition={{ delay: i * 0.25, duration: 0.6 }}
                  whileHover={{ y: -4 }}
                  style={{
                    padding: 24, textAlign: 'center', position: 'relative',
                    background: `linear-gradient(180deg, rgba(20,18,8,0.9), rgba(8,8,15,0.95))`,
                    border: `1px solid ${colors.brandGold}40`,
                    borderRadius: 10, overflow: 'hidden',
                    transition: 'border-color 0.3s, box-shadow 0.3s',
                    cursor: 'default',
                  }}
                  onMouseEnter={e => { e.currentTarget.style.borderColor = colors.brandGold; e.currentTarget.style.boxShadow = `0 0 30px ${colors.brandGold}30`; }}
                  onMouseLeave={e => { e.currentTarget.style.borderColor = `${colors.brandGold}40`; e.currentTarget.style.boxShadow = 'none'; }}
                >
                  {/* Glow halo behind icon */}
                  <div style={{
                    position: 'absolute', top: -30, left: '50%',
                    transform: 'translateX(-50%)',
                    width: 140, height: 140, borderRadius: '50%',
                    background: `radial-gradient(circle, ${colors.brandGold}15, transparent 60%)`,
                    pointerEvents: 'none',
                  }} />

                  {/* Hex icon with rotating ring */}
                  <div style={{
                    width: 76, height: 84, margin: '0 auto 16px', position: 'relative',
                  }}>
                    <svg width="100%" height="100%" viewBox="0 0 76 84"
                      style={{
                        position: 'absolute', inset: 0,
                        animation: `aiko-rotate ${10 + i * 2}s linear infinite`,
                      }}>
                      <circle cx="38" cy="42" r="36" fill="none"
                        stroke={colors.brandGold} strokeWidth="0.8"
                        strokeDasharray="3 6" opacity="0.5" />
                    </svg>
                    <div style={{
                      position: 'absolute', inset: 8,
                      clipPath: 'polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)',
                      background: `linear-gradient(135deg, ${colors.brandGold}, ${colors.brandGoldMuted})`,
                      padding: 2,
                    }}>
                      <div style={{
                        width: '100%', height: '100%',
                        clipPath: 'polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)',
                        background: '#08080f',
                        display: 'flex', alignItems: 'center', justifyContent: 'center',
                      }}>
                        <Icon name={step.icon} size={28} color={colors.brandGold} />
                      </div>
                    </div>
                  </div>

                  <div style={{
                    fontFamily: "'Orbitron', sans-serif",
                    fontSize: '0.6rem', color: colors.brandGold,
                    letterSpacing: 3, marginBottom: 6, fontWeight: 700,
                  }}>STAGE_{String(step.id).padStart(2, '0')}</div>
                  <h4 style={{
                    fontFamily: "'Orbitron', sans-serif",
                    fontSize: '1rem', fontWeight: 700,
                    color: colors.textPrimary, marginBottom: 8,
                    letterSpacing: 1, textTransform: 'uppercase',
                  }}>{step.label}</h4>

                  {/* Loading bar with time */}
                  <div style={{
                    margin: '0 auto 14px', maxWidth: 140,
                    height: 4, background: 'rgba(255,255,255,0.05)',
                    borderRadius: 2, overflow: 'hidden', position: 'relative',
                  }}>
                    <div style={{
                      position: 'absolute', inset: 0,
                      background: `linear-gradient(90deg, ${colors.brandGold}, ${colors.brandGoldMuted})`,
                      transform: isInView ? 'translateX(0)' : 'translateX(-100%)',
                      transition: `transform 1.4s ease-out ${i * 0.25 + 0.6}s`,
                      boxShadow: `0 0 8px ${colors.brandGold}`,
                    }} />
                  </div>
                  <div style={{
                    fontSize: '0.7rem', color: colors.textGold,
                    fontFamily: "'Courier Prime', monospace",
                    marginBottom: 14, letterSpacing: 1.5,
                    minHeight: 14,
                  }} />

                  <p style={{
                    fontSize: '0.78rem', color: colors.textMuted,
                    lineHeight: 1.65, fontWeight: 300, marginBottom: 16,
                    minHeight: 60,
                  }}>{step.desc}</p>

                  <div style={{
                    fontFamily: "'Courier Prime', monospace",
                    fontSize: '0.62rem', color: colors.brandGreen,
                    padding: '10px 12px',
                    background: `${colors.brandGreen}08`,
                    border: `1px solid ${colors.brandGreen}25`,
                    borderRadius: 4, letterSpacing: 0.5,
                    textAlign: 'left', wordBreak: 'break-word',
                  }}>
                    <span style={{ color: colors.textDim }}>OUTPUT &gt; </span>
                    {step.output}
                  </div>
                </motionAK.div>

                {i < pipeline.length - 1 && (
                  <div className="pipeline-arrow" style={{
                    position: 'absolute',
                    top: '50%', left: `${25 * (i + 1)}%`,
                    transform: 'translate(-50%, -50%)',
                    pointerEvents: 'none', width: 60, height: 60,
                    display: 'flex', alignItems: 'center', justifyContent: 'center',
                  }}>
                    <svg width="60" height="40" viewBox="0 0 60 40" style={{ overflow: 'visible' }}>
                      <defs>
                        <linearGradient id={`arr-aiko-${i}`} x1="0" x2="1">
                          <stop offset="0" stopColor={colors.brandGold} stopOpacity="0.1" />
                          <stop offset="0.5" stopColor={colors.brandGold} stopOpacity="0.9" />
                          <stop offset="1" stopColor={colors.brandGold} stopOpacity="0.1" />
                        </linearGradient>
                      </defs>
                      {/* Base line */}
                      <line x1="0" y1="20" x2="60" y2="20"
                        stroke={`url(#arr-aiko-${i})`} strokeWidth="1.5" />
                      {/* Animated dashes */}
                      <line x1="0" y1="20" x2="60" y2="20"
                        stroke={colors.brandGold} strokeWidth="2"
                        strokeDasharray="8 8" opacity="0.8"
                        style={{ animation: 'dash-flow-aiko 0.8s linear infinite' }} />
                      {/* Packet */}
                      <circle r="3" fill={colors.brandGold}
                        style={{ filter: `drop-shadow(0 0 6px ${colors.brandGold})` }}>
                        <animateMotion dur="1.4s" repeatCount="indefinite"
                          path="M 0 20 L 60 20" />
                      </circle>
                      <circle r="2" fill={colors.brandGreen}
                        style={{ filter: `drop-shadow(0 0 5px ${colors.brandGreen})` }}>
                        <animateMotion dur="1.4s" begin="0.7s" repeatCount="indefinite"
                          path="M 0 20 L 60 20" />
                      </circle>
                    </svg>
                  </div>
                )}
              </React.Fragment>
            ))}
          </div>

          {/* HUD footer with telemetry */}
          <div style={{
            marginTop: 30, paddingTop: 18,
            borderTop: `1px dashed ${colors.brandGold}25`,
            display: 'flex', justifyContent: 'space-between', alignItems: 'center',
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.62rem', color: colors.textDim,
            letterSpacing: 1.2, flexWrap: 'wrap', gap: 10,
          }}>
            <span>◢ HUMAN-IN-THE-LOOP: required at gate 03</span>
            <span style={{ color: colors.brandGold }}>ACCURACY: 95.0% ● CONVERGENCE: 3-phase loop</span>
          </div>
        </div>
      </div>

      <style>{`
        @keyframes dash-flow-aiko {
          to { stroke-dashoffset: -16; }
        }
        @keyframes aiko-rotate {
          from { transform: rotate(0deg); }
          to { transform: rotate(360deg); }
        }
        @keyframes aiko-pulse {
          0%, 100% { opacity: 1; transform: scale(1); }
          50% { opacity: 0.5; transform: scale(1.3); }
        }
        @media (max-width: 980px) {
          .pipeline-grid { grid-template-columns: 1fr 1fr !important; }
          .pipeline-arrow { display: none !important; }
        }
        @media (max-width: 700px) {
          .pipeline-grid { grid-template-columns: 1fr !important; }
          .pipeline-arrow { display: none !important; }
        }
      `}</style>
    </AnimatedSection>
  );
}

// ============================================================
// PIPELINE PHASES + CONSTITUTIONAL MEMORY
// ============================================================
function AikoFiveDimRlaif() {
  const phases = [
    { code: 'ANALYSIS',     stages: ['Architect', 'Reinforcer', 'Analyst'] },
    { code: 'CONTRACT',     stages: ['Validator', 'Contract Freezer'] },
    { code: 'BACKEND',      stages: ['Backend IBMi', 'Source Verifier'] },
    { code: 'FRONTEND',     stages: ['Frontend'] },
    { code: 'VERIFICATION', stages: ['E2E Tester', 'Doc Tech', 'Doc Ops', 'Learner'] },
  ];
  return (
    <AnimatedSection style={{
      padding: '110px 5%', background: colors.bgSecondary,
    }}>
      <div style={{ maxWidth: 1080, margin: '0 auto' }}>
        <div style={{
          display: 'grid', gridTemplateColumns: '1fr 1fr',
          gap: 28,
        }} className="aiko-2col">
          <motionAK.div
            initial={{ opacity: 0, x: -20 }}
            whileInView={{ opacity: 1, x: 0 }}
            viewport={{ once: true }}
            transition={{ duration: 0.6 }}
            style={{
              padding: 32,
              background: 'rgba(255,255,255,0.02)',
              border: `1px solid rgba(201,168,76,0.2)`,
              borderRadius: 12, position: 'relative',
            }}
          >
            <div style={{
              fontFamily: "'Courier Prime', monospace",
              fontSize: '0.7rem', color: colors.brandGold,
              letterSpacing: 2, textTransform: 'uppercase',
              marginBottom: 6, fontWeight: 600,
            }}>12 stage · 5 fasi</div>
            <h3 style={{
              fontFamily: "'Cinzel', serif",
              fontSize: '1.4rem', color: colors.textPrimary,
              marginBottom: 20, fontWeight: 500,
            }}>Una catena di dodici agent</h3>

            <PipelinePhases phases={phases} />

            <p style={{
              fontSize: '0.85rem', color: colors.textMuted,
              lineHeight: 1.7, fontWeight: 300, marginTop: 16,
            }}>
              Ogni stage lavora su un blueprint condiviso e passa il testimone
              al successivo. Quando un E2E test fallisce,
              <span style={{ color: colors.brandGold }}> la regressione torna allo stage responsabile</span> e il flusso riprende da lì.
            </p>
          </motionAK.div>

          <motionAK.div
            initial={{ opacity: 0, x: 20 }}
            whileInView={{ opacity: 1, x: 0 }}
            viewport={{ once: true }}
            transition={{ duration: 0.6 }}
            style={{
              padding: 32,
              background: 'rgba(45,106,79,0.04)',
              border: `1px solid rgba(45,106,79,0.3)`,
              borderRadius: 12, position: 'relative',
            }}
          >
            <div style={{
              fontFamily: "'Courier Prime', monospace",
              fontSize: '0.7rem', color: colors.brandEmerald,
              letterSpacing: 2, textTransform: 'uppercase',
              marginBottom: 6, fontWeight: 600,
            }}>Constitutional Memory · self-distilling context</div>
            <h3 style={{
              fontFamily: "'Cinzel', serif",
              fontSize: '1.4rem', color: colors.textPrimary,
              marginBottom: 20, fontWeight: 500,
            }}>Il modello scrive i propri vincoli</h3>

            <MemoryTerminal />

            <p style={{
              fontSize: '0.85rem', color: colors.textMuted,
              lineHeight: 1.7, fontWeight: 300,
            }}>
              Ogni pipeline distilla regole nella memoria del cliente.
              <span style={{ color: colors.brandGold }}> La conversione successiva le rispetta come vincolo</span>.
              Nessun fine-tuning: il contesto è l'asset.
            </p>
          </motionAK.div>
        </div>
      </div>

      <style>{`
        @media (max-width: 880px) {
          .aiko-2col { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </AnimatedSection>
  );
}

function PipelinePhases({ phases }) {
  // Flatten stage list to compute global indices
  const totalStages = phases.reduce((acc, p) => acc + p.stages.length, 0);
  const phaseRanges = (() => {
    let acc = 0;
    return phases.map(p => {
      const start = acc;
      acc += p.stages.length;
      return { start, end: acc - 1 };
    });
  })();

  // Animated execution head: 0..totalStages-1 = active stage, totalStages..totalStages+2 = "all done" pause
  const [pos, setPos] = useStateAK(0);
  useEffectAK(() => {
    const id = setInterval(() => {
      setPos(p => (p + 1) % (totalStages + 3));
    }, 850);
    return () => clearInterval(id);
  }, [totalStages]);

  const safePos = Math.min(pos, totalStages);
  const allDone = pos >= totalStages;

  return (
    <div>
      {/* Runtime header bar */}
      <div style={{
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
        padding: '7px 12px', marginBottom: 10,
        background: 'rgba(15,15,35,0.6)',
        border: `1px solid rgba(201,168,76,0.18)`,
        borderRadius: 6,
        fontFamily: "'Courier Prime', monospace",
        fontSize: '0.62rem',
        letterSpacing: 1.4,
      }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 8, color: allDone ? colors.brandGold : colors.brandEmerald }}>
          <span style={{
            display: 'inline-block', width: 8, height: 8, borderRadius: '50%',
            background: allDone ? colors.brandGold : colors.brandGreen,
            boxShadow: `0 0 8px ${allDone ? colors.brandGold : colors.brandGreen}`,
            animation: 'aikoLedPulse 0.9s infinite',
          }}/>
          {allDone ? 'PIPELINE · CONVERGED' : 'RUNTIME · LIVE'}
        </div>
        <div style={{ color: colors.brandGold, fontWeight: 600 }}>
          STAGE {String(allDone ? totalStages : safePos + 1).padStart(2,'0')}/{totalStages}
        </div>
      </div>

      <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
        {phases.map((p, i) => {
          const range = phaseRanges[i];
          let status = 'pending';
          if (allDone || pos > range.end) status = 'done';
          else if (pos >= range.start && pos <= range.end) status = 'running';

          const ledColor = status === 'running' ? colors.brandGreen
            : status === 'done' ? colors.brandGold
            : '#3a3a52';
          const labelColor = status === 'pending' ? colors.textDim : colors.brandGold;
          const phaseBg = status === 'running' ? 'rgba(45,106,79,0.12)'
            : status === 'done' ? 'rgba(201,168,76,0.06)'
            : 'rgba(201,168,76,0.02)';
          const phaseBorder = status === 'running' ? 'rgba(45,106,79,0.5)'
            : status === 'done' ? 'rgba(201,168,76,0.28)'
            : 'rgba(201,168,76,0.12)';
          const phaseBorderL = status === 'running' ? colors.brandEmerald
            : status === 'done' ? colors.brandGold
            : 'rgba(201,168,76,0.25)';

          return (
            <div key={p.code}>
              <div style={{
                display: 'grid',
                gridTemplateColumns: '12px 92px 1fr',
                alignItems: 'center',
                gap: 10,
                padding: '7px 12px',
                background: phaseBg,
                border: `1px solid ${phaseBorder}`,
                borderLeft: `2px solid ${phaseBorderL}`,
                borderRadius: 6,
                boxShadow: status === 'running' ? `0 0 14px rgba(45,106,79,0.25)` : 'none',
                transition: 'background 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease',
              }}>
                <span style={{
                  display: 'inline-block', width: 8, height: 8, borderRadius: '50%',
                  background: ledColor,
                  boxShadow: status === 'running' ? `0 0 8px ${ledColor}` : status === 'done' ? `0 0 4px ${ledColor}` : 'none',
                  animation: status === 'running' ? 'aikoLedPulse 0.7s infinite' : 'none',
                  transition: 'background 0.3s ease',
                }}/>
                <div style={{
                  fontFamily: "'Courier Prime', monospace",
                  fontSize: '0.6rem',
                  letterSpacing: 1.4,
                  color: labelColor,
                  fontWeight: 600,
                  transition: 'color 0.3s ease',
                }}>
                  0{i + 1} · {p.code}
                </div>
                <div style={{ display: 'flex', flexWrap: 'wrap', gap: 5, minHeight: 24, alignItems: 'center' }}>
                  {p.stages.map((s, j) => {
                    const stageGlobal = range.start + j;
                    const isActive = !allDone && pos === stageGlobal;
                    const isDone = allDone || pos > stageGlobal;
                    const stageColor = isActive ? colors.brandEmerald
                      : isDone ? colors.brandGold
                      : colors.textMuted;
                    const stageBg = isActive ? 'rgba(45,106,79,0.22)' : 'rgba(15,15,35,0.55)';
                    const stageBorder = isActive ? 'rgba(45,106,79,0.55)'
                      : isDone ? 'rgba(201,168,76,0.28)'
                      : 'rgba(201,168,76,0.16)';
                    const marker = isDone ? '✓' : isActive ? '▸' : '·';
                    return (
                      <span key={s} style={{
                        fontFamily: "'Courier Prime', monospace",
                        fontSize: '0.7rem',
                        lineHeight: '16px',
                        color: stageColor,
                        background: stageBg,
                        border: `1px solid ${stageBorder}`,
                        padding: '2px 8px',
                        borderRadius: 3,
                        whiteSpace: 'nowrap',
                        display: 'inline-flex',
                        alignItems: 'center',
                        transition: 'background 0.3s ease, border-color 0.3s ease, color 0.3s ease',
                      }}>
                        <span style={{
                          display: 'inline-block',
                          width: 10,
                          height: 14,
                          lineHeight: '14px',
                          textAlign: 'center',
                          overflow: 'hidden',
                          marginRight: 4,
                          color: isActive ? colors.brandGreen : isDone ? colors.brandGold : colors.textDim,
                        }}>{marker}</span>
                        {s}
                      </span>
                    );
                  })}
                </div>
              </div>
              {i < phases.length - 1 && (
                <PipelineConnector active={!allDone && pos === phaseRanges[i].end + 1 - 1} done={allDone || pos > phaseRanges[i].end} />
              )}
            </div>
          );
        })}
      </div>

      <style>{`
        @keyframes aikoLedPulse {
          0%, 100% { opacity: 1; }
          50% { opacity: 0.35; }
        }
        @keyframes aikoArrowPulse {
          0%, 100% { transform: translateY(0); opacity: 0.4; }
          50% { transform: translateY(2px); opacity: 1; }
        }
        @keyframes aikoDataDot {
          0% { transform: translateY(-4px); opacity: 0; }
          40% { opacity: 1; }
          100% { transform: translateY(8px); opacity: 0; }
        }
      `}</style>
    </div>
  );
}

function PipelineConnector({ done }) {
  return (
    <div style={{
      height: 14,
      position: 'relative',
      paddingLeft: 28,
      display: 'flex', alignItems: 'center',
      fontFamily: "'Courier Prime', monospace",
      fontSize: '0.7rem',
      color: done ? colors.brandGold : colors.textDim,
      transition: 'color 0.4s ease',
    }}>
      <span style={{
        animation: done ? 'none' : 'aikoArrowPulse 1.2s infinite',
        opacity: done ? 0.7 : 0.5,
      }}>↓</span>
      {done && (
        <span style={{
          marginLeft: 8,
          width: 4, height: 4, borderRadius: '50%',
          background: colors.brandGold,
          boxShadow: `0 0 6px ${colors.brandGold}`,
          animation: 'aikoDataDot 1s infinite',
        }}/>
      )}
    </div>
  );
}

// ============================================================
// MEMORY TERMINAL — typewriter effect
// ============================================================
function MemoryTerminal() {
  const lines = [
    { text: '// MEMORY · client signature',                           tone: 'dim' },
    { text: '[LEARNER] distilling 12 entries',                        tone: 'emerald' },
    { text: '+ COALESCE on every nullable column',                    tone: 'gold' },
    { text: '+ admin endpoint: POST /api/admin/<module>/<action>',    tone: 'gold' },
    { text: '+ flat body, no legacy wrappers',                        tone: 'gold' },
    { text: '✓ 3 new rules · dedup against 89 existing',              tone: 'goldBright' },
  ];

  const [lineIdx, setLineIdx] = useStateAK(0);
  const [charIdx, setCharIdx] = useStateAK(0);

  useEffectAK(() => {
    const current = lines[lineIdx];
    if (!current) {
      // All lines done — pause then loop
      const t = setTimeout(() => { setLineIdx(0); setCharIdx(0); }, 2800);
      return () => clearTimeout(t);
    }
    if (charIdx < current.text.length) {
      const speed = current.tone === 'dim' ? 22 : 28;
      const t = setTimeout(() => setCharIdx(c => c + 1), speed);
      return () => clearTimeout(t);
    }
    const t = setTimeout(() => { setLineIdx(i => i + 1); setCharIdx(0); }, 280);
    return () => clearTimeout(t);
  }, [lineIdx, charIdx]);

  const toneColor = (tone) => ({
    dim:        colors.textDim,
    emerald:    colors.brandEmerald,
    gold:       colors.textGold,
    goldBright: colors.brandGold,
  }[tone] || colors.textGold);

  const visibleLines = lines.slice(0, lineIdx + 1);
  const cursorActive = lineIdx < lines.length;

  return (
    <div style={{
      padding: '14px 18px 18px', background: 'rgba(8,8,18,0.85)',
      borderRadius: 8, marginBottom: 20,
      fontFamily: "'Courier Prime', monospace",
      fontSize: '0.78rem', lineHeight: 1.8,
      color: colors.textGold,
      border: `1px solid rgba(255,215,0,0.12)`,
      position: 'relative',
      minHeight: 260,
      overflow: 'hidden',
      boxShadow: 'inset 0 0 30px rgba(45,106,79,0.06)',
    }}>
      {/* CRT scanlines */}
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        backgroundImage: 'repeating-linear-gradient(0deg, rgba(45,106,79,0.05) 0px, rgba(45,106,79,0.05) 1px, transparent 1px, transparent 3px)',
        opacity: 0.7,
      }}/>
      {/* Top bar */}
      <div style={{
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
        marginBottom: 10, paddingBottom: 8,
        borderBottom: '1px solid rgba(201,168,76,0.14)',
        fontSize: '0.6rem', letterSpacing: 1.4,
        position: 'relative',
      }}>
        <span style={{ display: 'flex', alignItems: 'center', gap: 7, color: '#ff5c5c' }}>
          <span style={{
            width: 7, height: 7, borderRadius: '50%',
            background: '#ff4444',
            boxShadow: '0 0 7px #ff4444',
            animation: 'aikoLedPulse 0.85s infinite',
          }}/>
          REC · MEMORY.LOG
        </span>
        <span style={{ color: colors.textDim }}>
          {lineIdx >= lines.length - 1 && charIdx >= (lines[lines.length-1]?.text.length ?? 0)
            ? 'CONVERGED'
            : 'WRITING...'}
        </span>
      </div>

      <div style={{ position: 'relative' }}>
        {visibleLines.map((l, i) => {
          const isCurrent = i === lineIdx;
          const text = isCurrent ? l.text.slice(0, charIdx) : l.text;
          return (
            <div key={i} style={{ color: toneColor(l.tone), minHeight: '1.4em' }}>
              {text}
              {isCurrent && cursorActive && (
                <span style={{
                  display: 'inline-block',
                  width: 7, height: '0.95em',
                  background: colors.brandGold,
                  marginLeft: 2,
                  verticalAlign: 'text-bottom',
                  animation: 'aikoCursorBlink 0.55s steps(2) infinite',
                }}/>
              )}
            </div>
          );
        })}
      </div>

      <style>{`
        @keyframes aikoCursorBlink { 50% { opacity: 0; } }
      `}</style>
    </div>
  );
}

// ============================================================
// TASK TYPES — pipeline configurabile
// ============================================================
function AikoTaskTypes() {
  const types = [
    { code: 'conversion', label: 'Conversion', desc: 'Programmi RPG legacy convertiti in web. Pipeline completa con compile su IBM i, source-verifier e regression re-loop.', accent: colors.brandGold },
    { code: 'feature', label: 'Feature', desc: 'Nuova funzionalità su codebase esistente. Catena ridotta: analyst → backend → frontend → e2e.', accent: colors.brandGoldMuted },
    { code: 'new-rpg', label: 'New RPG', desc: 'Nuovo programma SQLRPGLE da zero, con compile + deploy + registrazione menu via MCP IBM i.', accent: colors.brandEmerald },
    { code: 'standalone', label: 'Standalone', desc: 'Progetto indipendente, fuori dall\'ecosistema Lumiere/Kodari. Solo analisi + frontend.', accent: '#a855f7' },
    { code: 'crud-gen', label: 'CRUD Gen', desc: 'Schema DB → schermate CRUD admin. Mapper-DB raggruppa tabelle in unità UI (master-detail, wizard, simple-crud).', accent: '#3aafff' },
  ];
  return (
    <AnimatedSection style={{
      padding: '110px 5%', background: '#08080f', position: 'relative', overflow: 'hidden',
    }}>
      <div style={{
        position: 'absolute', inset: 0,
        backgroundImage: `linear-gradient(${colors.brandGold}08 1px, transparent 1px), linear-gradient(90deg, ${colors.brandGold}08 1px, transparent 1px)`,
        backgroundSize: '60px 60px',
        maskImage: 'radial-gradient(ellipse 60% 50% at center, black, transparent)',
        WebkitMaskImage: 'radial-gradient(ellipse 60% 50% at center, black, transparent)',
      }} />
      <div style={{ maxWidth: 1080, margin: '0 auto', position: 'relative' }}>
        <SectionHeading
          eyebrow="// TASK_TYPE.cfg"
          title="Cinque modalità, una pipeline"
          sub="AiKo non fa solo conversione. La stessa orchestrazione si adatta a feature nuove, programmi RPG da zero, progetti standalone o generazione CRUD da schema DB."
        />
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))',
          gap: 16, marginTop: 56,
        }}>
          {types.map((t, i) => (
            <motionAK.div key={t.code}
              initial={{ opacity: 0, y: 20 }}
              whileInView={{ opacity: 1, y: 0 }}
              viewport={{ once: true }}
              transition={{ delay: i * 0.07, duration: 0.5 }}
              whileHover={{ y: -4 }}
              style={{
                padding: 22,
                background: `linear-gradient(155deg, ${t.accent}10, rgba(8,8,15,0.95))`,
                border: `1px solid ${t.accent}40`,
                borderRadius: 10, position: 'relative', overflow: 'hidden',
                transition: 'border-color 0.3s, box-shadow 0.3s',
              }}
              onMouseEnter={e => { e.currentTarget.style.borderColor = t.accent; e.currentTarget.style.boxShadow = `0 0 30px ${t.accent}30`; }}
              onMouseLeave={e => { e.currentTarget.style.borderColor = `${t.accent}40`; e.currentTarget.style.boxShadow = 'none'; }}
            >
              <div style={{
                position: 'absolute', top: 0, left: 0, right: 0, height: 2,
                background: `linear-gradient(90deg, transparent, ${t.accent}, transparent)`,
              }} />
              <div style={{
                fontFamily: "'Courier Prime', monospace",
                fontSize: '0.62rem', color: t.accent,
                letterSpacing: 2, marginBottom: 10, fontWeight: 700,
              }}>{`{${t.code}}`}</div>
              <h3 style={{
                fontFamily: "'Orbitron', sans-serif",
                fontSize: '0.95rem', color: colors.textPrimary,
                fontWeight: 700, marginBottom: 10, letterSpacing: 1,
                textTransform: 'uppercase',
              }}>{t.label}</h3>
              <p style={{
                fontSize: '0.82rem', color: colors.textMuted,
                lineHeight: 1.65, fontWeight: 300,
              }}>{t.desc}</p>
            </motionAK.div>
          ))}
        </div>

        {/* Tree-mapping callout */}
        <motionAK.div
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          transition={{ duration: 0.6 }}
          style={{
            marginTop: 28, padding: '22px 26px',
            background: 'rgba(168,85,247,0.05)',
            border: `1px solid rgba(168,85,247,0.35)`,
            borderRadius: 10,
            display: 'flex', alignItems: 'flex-start', gap: 18, flexWrap: 'wrap',
          }}
        >
          <div style={{
            width: 44, height: 44, flexShrink: 0,
            borderRadius: 8,
            background: 'rgba(168,85,247,0.12)',
            border: '1px solid rgba(168,85,247,0.4)',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
          }}>
            <Icon name="git-branch" size={20} color="#a855f7" />
          </div>
          <div style={{ flex: 1, minWidth: 240 }}>
            <div style={{
              fontFamily: "'Courier Prime', monospace",
              fontSize: '0.62rem', color: '#a855f7',
              letterSpacing: 2, marginBottom: 6, fontWeight: 700,
            }}>{'{tree-mapping}'} · BONUS</div>
            <h3 style={{
              fontFamily: "'Orbitron', sans-serif",
              fontSize: '1rem', color: colors.textPrimary,
              fontWeight: 700, marginBottom: 8, letterSpacing: 1,
              textTransform: 'uppercase',
            }}>Reverse-engineering 5250 interattivo</h3>
            <p style={{
              fontSize: '0.85rem', color: colors.textMuted,
              lineHeight: 1.7, fontWeight: 300, margin: 0,
            }}>
              Modalità separata che ricostruisce l'albero delle chiamate interattive (F-keys, opzioni subfile) fino a 8 livelli di profondità.
              Produce un grafo di progetto con classificazione UI semantica (modale vs pagina, lookup vs drill-down) e identificazione dei componenti condivisi —
              prima di lanciare la conversione di massa.
            </p>
          </div>
        </motionAK.div>
      </div>
    </AnimatedSection>
  );
}

// ============================================================
// WaveColumn / MemoryShard — gaming HUD building blocks
// ============================================================
function WaveColumn({ num, status, statusColor, programs, dim }) {
  return (
    <div style={{
      padding: '14px 14px 16px',
      background: dim ? 'rgba(15,15,15,0.4)' : 'rgba(20,18,8,0.7)',
      border: `1px solid ${statusColor}55`,
      borderRadius: 8,
      position: 'relative',
      opacity: dim ? 0.7 : 1,
      boxShadow: dim ? 'none' : `inset 0 0 20px ${statusColor}10`,
    }}>
      {/* corner notch */}
      <div style={{
        position: 'absolute', top: -1, right: -1,
        width: 14, height: 14,
        borderTop: `2px solid ${statusColor}`,
        borderRight: `2px solid ${statusColor}`,
      }} />
      <div style={{
        position: 'absolute', bottom: -1, left: -1,
        width: 14, height: 14,
        borderBottom: `2px solid ${statusColor}`,
        borderLeft: `2px solid ${statusColor}`,
      }} />

      {/* Header */}
      <div style={{
        display: 'flex', justifyContent: 'space-between',
        alignItems: 'baseline', marginBottom: 12,
        paddingBottom: 8,
        borderBottom: `1px dashed ${statusColor}30`,
      }}>
        <div>
          <div style={{
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.55rem', color: colors.textDim,
            letterSpacing: 1.5,
          }}>WAVE</div>
          <div style={{
            fontFamily: "'Orbitron', sans-serif",
            fontSize: '1.5rem', color: statusColor,
            fontWeight: 800, letterSpacing: 1, lineHeight: 1,
            textShadow: dim ? 'none' : `0 0 12px ${statusColor}80`,
          }}>{num}</div>
        </div>
        <div style={{
          fontFamily: "'Courier Prime', monospace",
          fontSize: '0.6rem', color: statusColor,
          letterSpacing: 1.5, fontWeight: 700,
          padding: '3px 7px',
          background: `${statusColor}15`,
          border: `1px solid ${statusColor}50`,
          borderRadius: 3,
        }}>{status}</div>
      </div>

      {/* Programs */}
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
        {programs.map(p => (
          <ProgramCard key={p.name} {...p} />
        ))}
      </div>
    </div>
  );
}

function ProgramCard({ name, pct, state }) {
  const stateColor = state === 'done' ? colors.brandEmerald
    : state === 'active' ? colors.brandGold
    : colors.textDim;
  const stateGlyph = state === 'done' ? '✓'
    : state === 'active' ? '◉'
    : '○';
  return (
    <div style={{
      padding: '7px 9px',
      background: 'rgba(0,0,0,0.4)',
      border: `1px solid ${stateColor}40`,
      borderRadius: 4,
    }}>
      <div style={{
        display: 'flex', alignItems: 'center', gap: 6,
        marginBottom: 5,
      }}>
        <span style={{
          color: stateColor,
          fontSize: '0.7rem',
          animation: state === 'active' ? 'aiko-pulse 1.4s ease-in-out infinite' : 'none',
        }}>{stateGlyph}</span>
        <span style={{
          fontFamily: "'Courier Prime', monospace",
          fontSize: '0.68rem', color: colors.textPrimary,
          letterSpacing: 0.3, flex: 1,
          fontWeight: state === 'queued' ? 300 : 500,
        }}>{name}</span>
        <span style={{
          fontFamily: "'Courier Prime', monospace",
          fontSize: '0.6rem', color: stateColor,
          fontWeight: 700,
        }}>{pct}%</span>
      </div>
      {/* HP/XP bar */}
      <div style={{
        height: 3, background: 'rgba(255,255,255,0.06)',
        borderRadius: 2, overflow: 'hidden', position: 'relative',
      }}>
        <div style={{
          height: '100%', width: `${pct}%`,
          background: `linear-gradient(90deg, ${stateColor}, ${stateColor}cc)`,
          boxShadow: `0 0 6px ${stateColor}`,
          transition: 'width 1s ease-out',
        }} />
      </div>
    </div>
  );
}

function MemoryShard({ label, pending }) {
  const c = pending ? colors.textDim : colors.brandEmerald;
  return (
    <div style={{
      display: 'flex', flexDirection: 'column',
      alignItems: 'center', justifyContent: 'center',
      gap: 6, position: 'relative', minWidth: 56,
    }}>
      {/* Diamond shard */}
      <div style={{
        width: 28, height: 28,
        transform: 'rotate(45deg)',
        background: `linear-gradient(135deg, ${c}40, ${c}10)`,
        border: `1.5px solid ${c}`,
        boxShadow: pending ? 'none' : `0 0 16px ${c}80, inset 0 0 8px ${c}40`,
        animation: pending ? 'none' : 'aiko-rotate 6s linear infinite',
        position: 'relative',
      }}>
        <div style={{
          position: 'absolute', inset: 4,
          border: `1px solid ${c}60`,
        }} />
      </div>
      <div style={{
        fontFamily: "'Courier Prime', monospace",
        fontSize: '0.55rem', color: c,
        letterSpacing: 1.2, fontWeight: 700, textAlign: 'center',
      }}>{label}</div>
      <div style={{
        fontFamily: "'Courier Prime', monospace",
        fontSize: '0.5rem', color: pending ? colors.textDim : colors.brandEmerald,
        letterSpacing: 1, opacity: 0.8,
      }}>{pending ? 'LOCKED' : '+XP'}</div>
    </div>
  );
}

// ============================================================
// MULTI-PIPELINE — Projects + Mapper + Waves
// ============================================================
function AikoProjects() {
  const features = [
    { icon: 'git-fork', title: 'Mapper agent', desc: 'Analizza CALL/CALLP, copy member, display file. Costruisce un grafo di dipendenze con ordinamento topologico in wave parallele.' },
    { icon: 'layers', title: 'Wave execution', desc: 'I programmi senza dipendenze partono in parallelo (wave 1). Le wave successive aspettano il completamento delle precedenti.' },
    { icon: 'brain', title: 'Memory Merger', desc: 'Fra una wave e l\'altra, un agente dedicato consolida i learning di pipeline nel MEMORY.md del cliente. La wave successiva parte già più informata.' },
    { icon: 'sliders-horizontal', title: 'Stage selector', desc: 'Per progetto si scelgono quali stadi includere (e.g. saltare docs, e2e). Max parallelismo modificabile a runtime.' },
  ];
  return (
    <AnimatedSection style={{
      padding: '110px 5%', background: colors.bgSecondary,
    }}>
      <div style={{ maxWidth: 1080, margin: '0 auto' }}>
        <SectionHeading
          eyebrow="// PROJECT_ORCHESTRATION"
          title="Da un programma a un intero gestionale"
          sub="Un progetto AiKo coordina N pipeline in parallelo, rispettando le dipendenze fra programmi RPG. La conoscenza si accumula da una wave all'altra."
        />

        {/* Wave diagram — gaming HUD */}
        <motionAK.div
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          transition={{ duration: 0.6 }}
          style={{
            marginTop: 56, padding: '0',
            background: 'linear-gradient(155deg, rgba(15,15,35,0.85), rgba(8,8,15,0.95))',
            border: `1px solid ${colors.brandGold}40`,
            borderRadius: 14, position: 'relative', overflow: 'hidden',
            boxShadow: `0 0 60px ${colors.brandGold}10, inset 0 0 40px rgba(201,168,76,0.04)`,
          }}
        >
          {/* Scanline overlay */}
          <div style={{
            position: 'absolute', inset: 0, pointerEvents: 'none',
            background: 'repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(201,168,76,0.025) 2px, rgba(201,168,76,0.025) 3px)',
          }} />

          {/* HUD Top bar */}
          <div style={{
            display: 'flex', justifyContent: 'space-between', alignItems: 'center',
            padding: '14px 22px',
            borderBottom: `1px solid ${colors.brandGold}25`,
            background: `linear-gradient(90deg, ${colors.brandGold}10, transparent)`,
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.65rem', letterSpacing: 1.5,
            position: 'relative', flexWrap: 'wrap', gap: 8,
          }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10, color: colors.brandGold }}>
              <span style={{
                width: 8, height: 8, borderRadius: '50%',
                background: colors.brandEmerald,
                boxShadow: `0 0 8px ${colors.brandEmerald}`,
                animation: 'aiko-pulse 1.4s ease-in-out infinite',
              }} />
              <span style={{ fontWeight: 700 }}>◢ MISSION ACTIVE</span>
              <span style={{ color: colors.textDim }}>// project_alpha</span>
            </div>
            <div style={{ display: 'flex', gap: 18, color: colors.textGold }}>
              <span>DEPS <span style={{ color: colors.textPrimary }}>6/6</span></span>
              <span>PARALLEL <span style={{ color: colors.textPrimary }}>×3</span></span>
              <span>SHARDS <span style={{ color: colors.brandEmerald }}>+2</span></span>
            </div>
          </div>

          {/* Wave grid */}
          <div style={{ padding: '28px 26px', position: 'relative' }}>
            <div style={{
              display: 'grid', gridTemplateColumns: '1fr auto 1fr auto 1fr',
              gap: 18, alignItems: 'stretch',
            }} className="wave-grid">

              {/* WAVE 01 — completed */}
              <WaveColumn
                num="01" status="CLEARED" statusColor={colors.brandEmerald}
                programs={[
                  { name: 'PROG01.SQLRPGLE', pct: 100, state: 'done' },
                  { name: 'PROG02.RPG', pct: 100, state: 'done' },
                  { name: 'PROG03.SQLRPGLE', pct: 100, state: 'done' },
                ]}
              />

              <MemoryShard label="SHARD α" />

              {/* WAVE 02 — in progress */}
              <WaveColumn
                num="02" status="IN PROGRESS" statusColor={colors.brandGold}
                programs={[
                  { name: 'PROG04.SQLRPGLE', pct: 100, state: 'done' },
                  { name: 'PROG05.RPG', pct: 62, state: 'active' },
                ]}
              />

              <MemoryShard label="SHARD β" pending />

              {/* WAVE 03 — queued */}
              <WaveColumn
                num="03" status="QUEUED" statusColor={colors.textDim} dim
                programs={[
                  { name: 'PROG06.SQLRPGLE', pct: 0, state: 'queued' },
                ]}
              />
            </div>
          </div>

          {/* HUD bottom */}
          <div style={{
            padding: '12px 22px',
            borderTop: `1px dashed ${colors.brandGold}30`,
            background: 'rgba(0,0,0,0.3)',
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.62rem', color: colors.textDim,
            letterSpacing: 1.2, display: 'flex',
            justifyContent: 'space-between', flexWrap: 'wrap', gap: 8,
          }}>
            <span>◢ MAPPER builds dependency graph · waves enforce topological order</span>
            <span style={{ color: colors.brandEmerald }}>◢ MEMORY consolidates between waves · +XP on next run</span>
          </div>
        </motionAK.div>

        {/* Features */}
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))',
          gap: 16, marginTop: 32,
        }}>
          {features.map((f, i) => (
            <motionAK.div key={i}
              initial={{ opacity: 0, y: 16 }}
              whileInView={{ opacity: 1, y: 0 }}
              viewport={{ once: true }}
              transition={{ delay: i * 0.08, duration: 0.45 }}
              style={{
                padding: 20,
                background: 'rgba(255,255,255,0.02)',
                border: `1px solid rgba(201,168,76,0.18)`,
                borderRadius: 10,
              }}
            >
              <Icon name={f.icon} size={22} color={colors.brandGold} style={{ marginBottom: 12 }} />
              <h4 style={{
                fontFamily: "'DM Sans', sans-serif",
                fontSize: '0.95rem', color: colors.textPrimary,
                fontWeight: 600, marginBottom: 8,
              }}>{f.title}</h4>
              <p style={{
                fontSize: '0.82rem', color: colors.textMuted,
                lineHeight: 1.65, fontWeight: 300,
              }}>{f.desc}</p>
            </motionAK.div>
          ))}
        </div>
      </div>
      <style>{`
        @media (max-width: 880px) {
          .wave-grid { grid-template-columns: 1fr !important; gap: 12px !important; }
        }
      `}</style>
    </AnimatedSection>
  );
}

// ============================================================
// HUMAN-IN-THE-LOOP CONTROLS
// ============================================================
function AikoHitlControls() {
  const controls = [
    { icon: 'check-check', label: 'Approve', desc: 'Il revisore approva lo stadio e la pipeline avanza. Auto-approve attivabile per stadi a basso rischio.' },
    { icon: 'undo-2', label: 'Reject + feedback', desc: 'Rigetto con motivazione: l\'agente riprende dalla session, integra il feedback, riproduce.' },
    { icon: 'rotate-ccw', label: 'Retry', desc: 'Stadio in errore: rollback a pending e respawn da capo. Sessione fresca, prompt invariato.' },
    { icon: 'skip-forward', label: 'Skip', desc: 'Marca lo stadio fallito come completed e fa proseguire la pipeline. Utile su passaggi non bloccanti.' },
    { icon: 'rewind', label: 'Rollback regressivo', desc: 'L\'E2E tester individua chi è responsabile di un bug: rollback automatico fino a quello stadio per re-loop.' },
    { icon: 'message-square-warning', label: 'Unblock', desc: 'L\'agente segnala uno stato BLOCKED quando ha bisogno di input umano. Risposta dell\'utente → resume.' },
  ];
  return (
    <AnimatedSection style={{
      padding: '110px 5%', background: '#08080f', position: 'relative', overflow: 'hidden',
    }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: 'repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(201,168,76,0.018) 3px, rgba(201,168,76,0.018) 4px)',
        pointerEvents: 'none',
      }} />
      <div style={{ maxWidth: 1080, margin: '0 auto', position: 'relative' }}>
        <SectionHeading
          eyebrow="// HUMAN_IN_THE_LOOP"
          title="L'umano resta al volante"
          sub="Sei controlli dedicati al revisore. AiKo non sostituisce: orchestra. Ogni stadio è ispezionabile, ogni decisione è reversibile."
        />
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(260px, 1fr))',
          gap: 16, marginTop: 56,
        }}>
          {controls.map((c, i) => (
            <motionAK.div key={c.label}
              initial={{ opacity: 0, y: 16 }}
              whileInView={{ opacity: 1, y: 0 }}
              viewport={{ once: true }}
              transition={{ delay: i * 0.06, duration: 0.45 }}
              style={{
                padding: 22,
                background: 'linear-gradient(145deg, rgba(20,18,8,0.9), rgba(8,8,15,0.95))',
                border: `1px solid rgba(201,168,76,0.25)`,
                borderRadius: 10,
                display: 'flex', alignItems: 'flex-start', gap: 14,
              }}
            >
              <div style={{
                width: 36, height: 36, flexShrink: 0,
                borderRadius: 6,
                background: `${colors.brandGold}10`,
                border: `1px solid ${colors.brandGold}40`,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
              }}>
                <Icon name={c.icon} size={18} color={colors.brandGold} />
              </div>
              <div>
                <div style={{
                  fontFamily: "'Orbitron', sans-serif",
                  fontSize: '0.78rem', color: colors.textPrimary,
                  fontWeight: 700, marginBottom: 6,
                  letterSpacing: 1, textTransform: 'uppercase',
                }}>{c.label}</div>
                <p style={{
                  fontSize: '0.8rem', color: colors.textMuted,
                  lineHeight: 1.6, fontWeight: 300, margin: 0,
                }}>{c.desc}</p>
              </div>
            </motionAK.div>
          ))}
        </div>
      </div>
    </AnimatedSection>
  );
}

// ============================================================
// USE CASES
// ============================================================
function AikoUseCases() {
  const cases = [
    {
      tier: 'BOSS',
      tierColor: colors.brandGold,
      title: 'Modernizzazione UI di gestionale ERP',
      problem: 'Centinaia di programmi RPG con interfaccia 5250 ancora in produzione.',
      solution: 'AiKo converte modulo per modulo in pagine React mantenendo la business logic intatta.',
      kpi: 'Modernizzazione incrementale, zero downtime',
      stats: { difficulty: 5, xp: '60K', time: '6w' },
    },
    {
      tier: 'ELITE',
      tierColor: colors.brandEmerald,
      title: 'Apertura backend IBM i a mobile/web',
      problem: 'Logica di business preziosa, ma chiusa nel green-screen.',
      solution: 'La pipeline AiKo genera anche le proposte API REST, esposte poi via Kodari Bridge.',
      kpi: 'API REST documentate generate da analisi automatica',
      stats: { difficulty: 4, xp: '40K', time: '4w' },
    },
    {
      tier: 'LEGENDARY',
      tierColor: '#a855f7',
      title: 'Continuità operativa a fronte di skill shortage',
      problem: 'I developer RPG vanno in pensione, sostituirli è quasi impossibile.',
      solution: 'AiKo codifica i pattern in MD versionati: il know-how diventa asset, non persona.',
      kpi: 'Pattern proprietario riusabile, IP protetto',
      stats: { difficulty: 5, xp: '∞', time: 'permanent' },
    },
  ];
  return (
    <AnimatedSection style={{
      padding: '110px 5%', background: '#08080f', position: 'relative', overflow: 'hidden',
    }}>
      {/* Scan line atmosphere */}
      <div style={{
        position: 'absolute', inset: 0,
        background: 'repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(255,215,0,0.018) 3px, rgba(255,215,0,0.018) 4px)',
        pointerEvents: 'none',
      }} />
      <div style={{ maxWidth: 1080, margin: '0 auto', position: 'relative' }}>
        <SectionHeading
          eyebrow="// MISSION_LOG.dat"
          title="Quando AiKo fa la differenza"
        />
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))',
          gap: 20, marginTop: 56,
        }}>
          {cases.map((c, i) => (
            <motionAK.div key={i}
              initial={{ opacity: 0, y: 24 }}
              whileInView={{ opacity: 1, y: 0 }}
              viewport={{ once: true }}
              transition={{ delay: i * 0.1, duration: 0.5 }}
              whileHover={{ y: -6 }}
              style={{
                padding: 28,
                background: `linear-gradient(155deg, ${c.tierColor}10, rgba(8,8,15,0.95))`,
                border: `1px solid ${c.tierColor}40`,
                borderRadius: 14, position: 'relative',
                display: 'flex', flexDirection: 'column',
                boxShadow: `0 0 0 1px ${c.tierColor}10 inset, 0 20px 50px -20px rgba(0,0,0,0.6)`,
                transition: 'border-color 0.3s, box-shadow 0.3s',
                overflow: 'hidden',
              }}
              onMouseEnter={e => { e.currentTarget.style.borderColor = c.tierColor; e.currentTarget.style.boxShadow = `0 0 0 1px ${c.tierColor}40 inset, 0 0 40px ${c.tierColor}30, 0 20px 50px -20px rgba(0,0,0,0.6)`; }}
              onMouseLeave={e => { e.currentTarget.style.borderColor = `${c.tierColor}40`; e.currentTarget.style.boxShadow = `0 0 0 1px ${c.tierColor}10 inset, 0 20px 50px -20px rgba(0,0,0,0.6)`; }}
            >
              {/* Glow corner */}
              <div style={{
                position: 'absolute', top: -50, right: -50,
                width: 130, height: 130, borderRadius: '50%',
                background: `radial-gradient(circle, ${c.tierColor}40, transparent 70%)`,
                pointerEvents: 'none',
              }} />

              {/* Tier ribbon */}
              <div style={{
                display: 'flex', alignItems: 'center', justifyContent: 'space-between',
                marginBottom: 16,
              }}>
                <div style={{
                  fontFamily: "'Orbitron', sans-serif",
                  fontSize: '0.65rem', color: c.tierColor,
                  letterSpacing: 3, fontWeight: 800,
                  padding: '4px 10px',
                  background: `${c.tierColor}15`,
                  border: `1px solid ${c.tierColor}50`,
                  borderRadius: 4,
                }}>★ {c.tier}</div>
                <div style={{
                  fontFamily: "'Courier Prime', monospace",
                  fontSize: '0.6rem', color: colors.textDim,
                  letterSpacing: 1.5,
                }}>QUEST_{String(i + 1).padStart(3, '0')}</div>
              </div>

              <h3 style={{
                fontFamily: "'Orbitron', sans-serif",
                fontSize: '1rem', color: colors.textPrimary,
                fontWeight: 700, marginBottom: 18, lineHeight: 1.35,
                letterSpacing: 0.5,
              }}>{c.title}</h3>

              {/* Stats bar */}
              <div style={{
                display: 'flex', gap: 12, marginBottom: 18,
                padding: '10px 12px', background: 'rgba(0,0,0,0.4)',
                borderRadius: 6, border: `1px solid ${c.tierColor}20`,
                fontFamily: "'Courier Prime', monospace", fontSize: '0.65rem',
              }}>
                <div style={{ flex: 1 }}>
                  <div style={{ color: colors.textDim, marginBottom: 3, letterSpacing: 1 }}>DIFF</div>
                  <div style={{ display: 'flex', gap: 2 }}>
                    {Array.from({ length: 5 }).map((_, k) => (
                      <div key={k} style={{
                        width: 8, height: 4,
                        background: k < c.stats.difficulty ? c.tierColor : 'rgba(255,255,255,0.08)',
                        boxShadow: k < c.stats.difficulty ? `0 0 6px ${c.tierColor}` : 'none',
                      }} />
                    ))}
                  </div>
                </div>
                <div style={{ width: 1, background: 'rgba(255,255,255,0.06)' }} />
                <div style={{ flex: 1 }}>
                  <div style={{ color: colors.textDim, marginBottom: 3, letterSpacing: 1 }}>XP</div>
                  <div style={{ color: c.tierColor, fontWeight: 700 }}>+{c.stats.xp}</div>
                </div>
              </div>

              <div style={{
                fontSize: '0.65rem', color: '#ff6b6b',
                fontFamily: "'Courier Prime', monospace",
                textTransform: 'uppercase', letterSpacing: 1.5, marginBottom: 6, fontWeight: 600,
              }}>▼ THREAT</div>
              <p style={{
                fontSize: '0.85rem', color: colors.textMuted,
                lineHeight: 1.65, fontWeight: 300, marginBottom: 14,
              }}>{c.problem}</p>
              <div style={{
                fontSize: '0.65rem', color: colors.brandGreen,
                fontFamily: "'Courier Prime', monospace",
                textTransform: 'uppercase', letterSpacing: 1.5, marginBottom: 6, fontWeight: 600,
              }}>▲ STRATEGY</div>
              <p style={{
                fontSize: '0.85rem', color: colors.textMuted,
                lineHeight: 1.65, fontWeight: 300, marginBottom: 18, flex: 1,
              }}>{c.solution}</p>
              <div style={{
                padding: '12px 14px',
                background: `linear-gradient(90deg, ${c.tierColor}20, ${c.tierColor}05)`,
                border: `1px solid ${c.tierColor}50`,
                borderRadius: 6, fontSize: '0.78rem',
                color: c.tierColor, fontWeight: 600,
                display: 'flex', alignItems: 'center', gap: 8,
                fontFamily: "'Courier Prime', monospace", letterSpacing: 0.5,
              }}>
                <span style={{
                  width: 14, height: 14, borderRadius: 3,
                  background: c.tierColor, color: '#08080f',
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                  fontSize: '0.7rem', fontWeight: 900,
                  boxShadow: `0 0 10px ${c.tierColor}`,
                }}>✓</span>
                {c.kpi}
              </div>
            </motionAK.div>
          ))}
        </div>
      </div>
    </AnimatedSection>
  );
}

// ============================================================
// COMPARE TABLE (riusato da V1)
// ============================================================
function AikoCompare() {
  const compRows = [
    { dim: 'Modello', generic: 'Prompt generico', aiko: 'Pipeline multi-agente domain-specific IBM i' },
    { dim: 'Accuratezza', generic: '40-60% (dipende dal prompt)', aiko: '95% verificato su codice reale enterprise' },
    { dim: 'Dominio', generic: 'Generico, non conosce DB2/400, ILE', aiko: 'Costruito su 30+ anni di pattern RPG reali' },
    { dim: 'Scalabilità', generic: 'Manuale, non replicabile', aiko: 'Pipeline automatizzata, 1.000+ programmi' },
    { dim: 'Proprietà IP', generic: 'Know-how nel prompt (volatile)', aiko: 'Pattern MD codificati, asset aziendale' },
    { dim: 'Apprendimento', generic: '—', aiko: 'Constitutional memory: il modello scrive i propri vincoli' },
  ];
  return (
    <AnimatedSection style={{
      padding: '110px 5%', background: colors.bgSecondary,
    }}>
      <div style={{ maxWidth: 1080, margin: '0 auto' }}>
        <SectionHeading
          eyebrow="// Confronto"
          title="Approccio generico vs AiKo Engine"
          sub="Sei dimensioni a confronto."
        />

        <div style={{
          marginTop: 56,
          border: `1px solid rgba(255,215,0,0.15)`,
          borderRadius: 12, overflow: 'hidden',
          background: 'rgba(15,15,35,0.5)',
        }}>
          <div style={{
            display: 'grid', gridTemplateColumns: '1fr 1.4fr 1.4fr',
            padding: '14px 20px',
            background: 'rgba(255,215,0,0.04)',
            borderBottom: `1px solid rgba(255,215,0,0.15)`,
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.7rem', textTransform: 'uppercase',
            letterSpacing: 1.5, fontWeight: 600,
            color: colors.textGold,
          }} className="comp-header">
            <div>Dimensione</div>
            <div style={{ color: colors.textDim }}>Approccio Generico</div>
            <div style={{ color: colors.brandGold }}>★ AiKo Engine</div>
          </div>
          {compRows.map((row, i) => (
            <motionAK.div key={i}
              initial={{ opacity: 0 }}
              whileInView={{ opacity: 1 }}
              viewport={{ once: true }}
              transition={{ delay: i * 0.05 }}
              className="comp-row"
              style={{
                display: 'grid', gridTemplateColumns: '1fr 1.4fr 1.4fr',
                padding: '16px 20px',
                borderBottom: i < compRows.length - 1 ? `1px solid rgba(255,255,255,0.04)` : 'none',
                alignItems: 'center', gap: 16,
              }}
            >
              <div style={{ fontWeight: 600, color: colors.textPrimary, fontSize: '0.85rem' }}>{row.dim}</div>
              <div style={{ fontSize: '0.85rem', color: colors.textDim, fontWeight: 300 }}>{row.generic}</div>
              <div style={{
                fontSize: '0.85rem', color: colors.brandGold, fontWeight: 400,
                display: 'flex', alignItems: 'flex-start', gap: 8,
              }}>
                <Icon name="check" size={14} color={colors.brandGreen} style={{ marginTop: 3, flexShrink: 0 }} />
                <span>{row.aiko}</span>
              </div>
            </motionAK.div>
          ))}
        </div>
      </div>

      <style>{`
        @media (max-width: 700px) {
          .comp-header, .comp-row { grid-template-columns: 1fr !important; gap: 6px !important; }
          .comp-row { padding: 14px 16px !important; }
        }
      `}</style>
    </AnimatedSection>
  );
}

// ============================================================
// METRICS — quote-able
// ============================================================
function AikoMetrics() {
  const ref = useRefAK(null);
  const isInView = useInViewAK(ref, { once: true });
  return (
    <AnimatedSection style={{
      padding: '90px 5%', background: colors.bgPrimary,
    }}>
      <div ref={ref} style={{ maxWidth: 1080, margin: '0 auto' }}>
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))',
          gap: 16,
        }}>
          {[
            { val: '95', suf: '%', label: 'Accuratezza', sub: 'su codice enterprise' },
            { val: '10', suf: 'x', label: 'Velocità', sub: 'vs approccio manuale' },
            { val: '12', suf: '', label: 'Stage', sub: 'pipeline orchestrata' },
          ].map((m, i) => (
            <MetricBlock key={i} {...m} delay={i * 0.1} triggered={isInView} />
          ))}
        </div>
      </div>
    </AnimatedSection>
  );
}

function MetricBlock({ val, suf, label, sub, delay, triggered }) {
  const num = useCounterAnimation(parseInt(val), 2200, triggered);
  return (
    <motionAK.div
      initial={{ opacity: 0, y: 20 }}
      whileInView={{ opacity: 1, y: 0 }}
      viewport={{ once: true }}
      transition={{ delay, duration: 0.5 }}
      style={{
        padding: '24px 20px', textAlign: 'center',
        background: 'rgba(255,255,255,0.02)',
        border: `1px solid rgba(201,168,76,0.2)`,
        borderRadius: 10, position: 'relative', overflow: 'hidden',
      }}
    >
      <div style={{
        fontFamily: "'Cinzel', serif",
        fontSize: 'clamp(2.2rem, 4vw, 3rem)',
        fontWeight: 600,
        background: `linear-gradient(135deg, ${colors.brandGold}, ${colors.brandGoldMuted})`,
        WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent',
        lineHeight: 1, marginBottom: 6,
      }}>{num}{suf}</div>
      <div style={{
        fontSize: '0.85rem', color: colors.textPrimary,
        fontWeight: 500, marginBottom: 4,
      }}>{label}</div>
      <div style={{
        fontSize: '0.7rem', color: colors.textDim,
        fontFamily: "'Courier Prime', monospace", letterSpacing: 0.5,
      }}>{sub}</div>
    </motionAK.div>
  );
}

// ============================================================
// CROSS-LINK ALTRI BRAND
// ============================================================
function AikoCrossLinks() {
  const others = [
    { name: 'Kodari', role: 'Backend / API Gateway', href: 'kodari.html', Logo: KodariLogo, color: colors.brandGreen },
    { name: 'Lumiere', role: 'Frontend Enterprise', href: 'lumiere.html', Logo: LumiereLogo, color: colors.brandGold },
    { name: 'Lestage', role: 'File Flow Orchestration', href: 'lestage.html', Logo: LestageLogo, color: colors.brandAmber },
  ];
  return (
    <AnimatedSection style={{
      padding: '90px 5%', background: colors.bgSecondary,
    }}>
      <div style={{ maxWidth: 1080, margin: '0 auto' }}>
        <div style={{ textAlign: 'center', marginBottom: 40 }}>
          <div style={{
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.72rem', color: colors.textGold,
            letterSpacing: 3, textTransform: 'uppercase',
            marginBottom: 16, fontWeight: 600,
          }}>// Ecosistema</div>
          <h2 style={{
            fontFamily: "'Cinzel', serif",
            fontSize: 'clamp(1.6rem, 2.6vw, 2.1rem)',
            color: colors.textPrimary, fontWeight: 500,
            marginBottom: 14,
          }}>AiKo non lavora da sola</h2>
          <p style={{
            color: colors.textMuted, lineHeight: 1.7,
            fontWeight: 300, maxWidth: 640, margin: '0 auto',
          }}>
            La pipeline genera output che vengono eseguiti, esposti e orchestrati dagli altri brand dell'ecosistema.
          </p>
        </div>

        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))',
          gap: 16,
        }}>
          {others.map(o => (
            <a key={o.name} href={o.href} style={{
              padding: 20,
              background: 'rgba(255,255,255,0.02)',
              border: `1px solid rgba(255,255,255,0.06)`,
              borderRadius: 10,
              display: 'flex', alignItems: 'center', gap: 16,
              textDecoration: 'none', transition: 'all 0.3s',
            }}
              onMouseEnter={e => { e.currentTarget.style.borderColor = o.color; e.currentTarget.style.background = `${o.color}08`; }}
              onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255,255,255,0.06)'; e.currentTarget.style.background = 'rgba(255,255,255,0.02)'; }}
            >
              <o.Logo size={48} />
              <div style={{ flex: 1 }}>
                <div style={{ color: o.color, fontWeight: 600, fontSize: '1rem', marginBottom: 2 }}>{o.name}</div>
                <div style={{ color: colors.textDim, fontSize: '0.78rem', fontFamily: "'Courier Prime', monospace" }}>{o.role}</div>
              </div>
              <Icon name="arrow-right" size={16} color={o.color} />
            </a>
          ))}
        </div>

        <div style={{ textAlign: 'center', marginTop: 36 }}>
          <a href="../index.html#prodotti" style={{
            fontSize: '0.85rem', color: colors.textMuted, textDecoration: 'none',
            fontFamily: "'Courier Prime', monospace", letterSpacing: 1,
          }}
            onMouseEnter={e => e.currentTarget.style.color = colors.brandGold}
            onMouseLeave={e => e.currentTarget.style.color = colors.textMuted}
          >← Torna alla panoramica ecosistema</a>
        </div>
      </div>
    </AnimatedSection>
  );
}

// ============================================================
// CTA
// ============================================================
function AikoCta() {
  return (
    <AnimatedSection style={{
      padding: '110px 5%', background: colors.bgPrimary,
      position: 'relative', overflow: 'hidden',
    }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: `
          radial-gradient(ellipse 50% 40% at 80% 30%, rgba(255,215,0,0.06), transparent 70%),
          radial-gradient(ellipse 40% 50% at 10% 80%, rgba(45,106,79,0.06), transparent 70%)
        `,
        pointerEvents: 'none',
      }} />
      <div style={{ maxWidth: 760, margin: '0 auto', textAlign: 'center', position: 'relative' }}>
        <AiKoLogo size={80} />
        <h2 style={{
          fontFamily: "'Cinzel', serif",
          fontSize: 'clamp(1.9rem, 3.6vw, 2.7rem)',
          color: colors.textPrimary, fontWeight: 500,
          lineHeight: 1.3, margin: '28px 0 20px', textWrap: 'balance',
        }}>
          Vediamo AiKo all'opera<br />
          <span style={{ color: colors.textGold, fontStyle: 'italic' }}>sul vostro codice</span>
        </h2>
        <p style={{
          fontSize: '1rem', color: colors.textMuted,
          lineHeight: 1.7, fontWeight: 300, marginBottom: 32,
          maxWidth: 560, margin: '0 auto 32px',
        }}>
          Mandateci uno o due programmi RPG rappresentativi: vi mostriamo l'analisi della pipeline e la conversione in app web moderna.
        </p>
        <a href="../contatti.html" style={{
          fontFamily: "'DM Sans', sans-serif",
          fontSize: '0.95rem', fontWeight: 600,
          padding: '15px 32px',
          background: `linear-gradient(135deg, ${colors.brandGold}, ${colors.brandGoldMuted})`,
          color: colors.bgPrimary, borderRadius: 6, textDecoration: 'none',
          letterSpacing: 0.5,
          boxShadow: `0 0 30px rgba(255,215,0,0.25)`,
          transition: 'all 0.3s',
          display: 'inline-flex', alignItems: 'center', gap: 10,
        }}
          onMouseEnter={e => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 6px 40px rgba(255,215,0,0.35)'; }}
          onMouseLeave={e => { e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = '0 0 30px rgba(255,215,0,0.25)'; }}
        >Richiedi una demo gratuita <Icon name="arrow-right" size={16} color={colors.bgPrimary} /></a>
      </div>
    </AnimatedSection>
  );
}

// ============================================================
// APP
// ============================================================
function AikoApp() {
  return (
    <React.Fragment>
      <SiteNav depth={1} current="aiko" />
      <main>
        <AikoHero />
        <AikoWhatItDoes />
        <AikoPipeline />
        <AikoFiveDimRlaif />
        <AikoTaskTypes />
        <AikoProjects />
        <AikoHitlControls />
        <AikoUseCases />
        <AikoCompare />
        <AikoMetrics />
        <AikoCrossLinks />
        <AikoCta />
      </main>
      <SiteFooter depth={1} />
    </React.Fragment>
  );
}

function mountAiko() {
  const ready =
    typeof colors !== 'undefined' &&
    typeof CompassLogo !== 'undefined' &&
    typeof SiteNav !== 'undefined' &&
    typeof SiteFooter !== 'undefined' &&
    window.FramerMotion &&
    window.lucide;
  if (!ready) return setTimeout(mountAiko, 50);

  const root = ReactDOM.createRoot(document.getElementById('app'));
  root.render(<AikoApp />);

  if (window.lucide) {
    const observer = new MutationObserver(() => window.lucide.createIcons());
    observer.observe(document.body, { childList: true, subtree: true });
    window.lucide.createIcons();
  }
}
mountAiko();
