// Hero — ONE cinematic version with scroll-driven split
// Marco slides left, Valeria slides right as user scrolls
// Real background photo, dramatic overlay, bold red accent

function Hero(){
  const { t } = useLang();
  const y = useScrollY();
  const mouse = useMouseParallax(0.012);
  const [mounted, setMounted] = React.useState(false);
  React.useEffect(() => { const t = setTimeout(() => setMounted(true), 50); return () => clearTimeout(t); }, []);

  // Scroll progress 0 → 1 over first 100vh
  const vh = typeof window !== 'undefined' ? window.innerHeight : 800;
  const p = Math.min(1, Math.max(0, y / (vh * 0.9)));

  // Split: Marco slides left, Valeria slides right
  const splitMarco = -p * 60;    // vw
  const splitValeria = p * 60;
  const ampSpread = p * 30;
  const fadeText = Math.max(0, 1 - p*1.2);
  const zoomBg = 1 + p * 0.06;

  return (
    <section data-screen-label="01 Hero" style={{
      position:'relative', minHeight:'100vh', background:'var(--ink)', color:'var(--cream)',
      overflow:'hidden',
    }}>
      {/* Background photo — zooms & darkens on scroll */}
      <div style={{position:'absolute', inset:'-5% -2%', transform:`scale(${zoomBg}) translate(${mouse.x*0.5}px, ${y*0.15}px)`, transition:'transform .1s linear'}}>
        <img src={PHOTOS.hero_main} alt=""
          style={{width:'100%', height:'110%', objectFit:'cover', filter:'contrast(1.15) saturate(0.75) brightness(0.55)'}}/>
      </div>

      {/* red wash overlay that intensifies with scroll */}
      <div style={{position:'absolute', inset:0,
        background:`linear-gradient(180deg, rgba(10,6,5,${.45 + p*.2}) 0%, rgba(10,6,5,${.2+p*.3}) 40%, rgba(139,10,26,${.15 + p*.25}) 100%)`,
      }}/>
      <div style={{position:'absolute', inset:0,
        background:`radial-gradient(ellipse at center, transparent 30%, rgba(10,6,5,${.4+p*.3}) 100%)`,
      }}/>

      {/* film grain — heavy */}
      <div style={{
        position:'absolute', inset:0, pointerEvents:'none', opacity:.42, mixBlendMode:'overlay',
        backgroundImage: `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' seed='4'/><feColorMatrix values='0 0 0 0 0.12  0 0 0 0 0.06  0 0 0 0 0.05  0 0 0 0.95 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>")`,
      }}/>
      {/* second grain layer for texture depth */}
      <div style={{
        position:'absolute', inset:0, pointerEvents:'none', opacity:.22, mixBlendMode:'soft-light',
        backgroundImage: `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n2'><feTurbulence type='fractalNoise' baseFrequency='1.6' numOctaves='2' seed='9'/><feColorMatrix values='0 0 0 0 0.5  0 0 0 0 0.3  0 0 0 0 0.2  0 0 0 0.9 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n2)'/></svg>")`,
      }}/>

      {/* MAIN COMPOSITION */}
      <div style={{
        position:'relative', zIndex:3, minHeight:'100vh',
        display:'flex', flexDirection:'column', justifyContent:'center', alignItems:'center',
        padding:'0 4vw',
      }}>
        {/* Marco — slides left on scroll */}
        <h1 className="display hero-name" style={{
          fontSize:'clamp(110px, 22vw, 360px)', lineHeight:.82, fontWeight:200,
          fontStyle:'italic', fontVariationSettings:'"SOFT" 100, "opsz" 144',
          letterSpacing:'-.045em', color:'var(--cream)',
          transform: `translateX(${mounted ? splitMarco : -20}vw) translateY(${y*-0.05}px)`,
          opacity: mounted ? 1 : 0, whiteSpace:'nowrap',
          transition: mounted ? 'transform .05s linear' : 'transform 1.8s cubic-bezier(.2,.7,.2,1), opacity 1.5s',
          textShadow:'0 2px 20px rgba(0,0,0,.4)',
          willChange:'transform',
        }}>
          {CONFIG.couple.name1}
        </h1>

        {/* ampersand — stays centered, pulses with scroll */}
        <div style={{
          margin: `calc(${-2 - p*4}vw) 0`, position:'relative', zIndex:5,
          transform: `scale(${1 + p*0.4}) rotate(${p*8}deg)`,
          transition:'transform .1s linear',
          opacity: mounted ? 1 : 0,
        }}>
          <span className="script" style={{
            fontSize:'clamp(80px, 16vw, 240px)', lineHeight:1, color:'var(--passion)',
            textShadow:'0 4px 30px rgba(139,10,26,.5)',
            display:'inline-block',
          }}>
            &amp;
          </span>
        </div>

        {/* Valeria — slides right */}
        <h1 className="display hero-name" style={{
          fontSize:'clamp(110px, 22vw, 360px)', lineHeight:.82, fontWeight:200,
          fontStyle:'italic', fontVariationSettings:'"SOFT" 100, "opsz" 144',
          letterSpacing:'-.045em', color:'var(--cream)',
          transform: `translateX(${mounted ? splitValeria : 20}vw) translateY(${y*-0.05}px)`,
          opacity: mounted ? 1 : 0, whiteSpace:'nowrap', textAlign:'right',
          transition: mounted ? 'transform .05s linear' : 'transform 1.8s cubic-bezier(.2,.7,.2,1) .2s, opacity 1.5s .2s',
          textShadow:'0 2px 20px rgba(0,0,0,.4)',
          willChange:'transform',
        }}>
          {CONFIG.couple.name2}
        </h1>

        {/* Under-hero subtitle — reveals as names separate */}
        <div style={{
          marginTop:'clamp(30px, 6vh, 80px)', textAlign:'center',
          opacity: Math.min(1, p*2.2), transform: `translateY(${Math.max(0, (1-p*2)*30)}px)`,
          transition:'opacity .3s, transform .3s',
        }}>
          <div className="italiana" style={{fontSize:11, letterSpacing:6, opacity:.7, color:'var(--cream-2)'}}>
            {t('hero.subtitle')}
          </div>
        </div>
      </div>

      {/* Corners */}
      <div className="italiana hero-corner" style={{
        position:'absolute', left:'3vw', bottom:'3vh', fontSize:10, letterSpacing:3,
        color:'var(--cream-2)', opacity: mounted ? .6 * fadeText : 0, zIndex:4,
        transition:'opacity 1s',
      }}>
        {t('hero.date_line')}
      </div>
      <div className="italiana hero-corner" style={{
        position:'absolute', right:'3vw', bottom:'3vh', fontSize:10, letterSpacing:3,
        color:'var(--cream-2)', opacity: mounted ? .5 * fadeText : 0, zIndex:4,
        transition:'opacity 1s',
      }}>
        {t('hero.coordinates')}
      </div>

      {/* Scroll cue */}
      <div style={{
        position:'absolute', left:'50%', top:'calc(100vh - 70px)',
        opacity: mounted ? .55 * fadeText : 0, zIndex:5,
        animation:'drift 4s ease-in-out infinite', transition:'opacity 1s',
      }}>
        <div className="italiana" style={{fontSize:9, letterSpacing:4, color:'var(--cream)', textAlign:'center'}}>SCORRI</div>
        <div style={{width:1, height:44, background:'var(--cream)', margin:'8px auto 0', opacity:.5}}/>
      </div>
    </section>
  );
}

window.Hero = Hero;
