// METIO v2 — Dark premium landing.
// Visual: navy base (#111827→#1C2B40), violet #8B5CF6, cyan #06B6D4.
// Typography: Poppins (same as app). Glassmorphism, aurora orbs, scroll reveals.

const V2 = {
  bg1:'#0B1120', bg2:'#111827', bg3:'#162032', bg4:'#1C2B40',
  violet:'#8B5CF6', violetDeep:'#6D28D9',
  cyan:'#06B6D4', cyanDeep:'#0891B2',
  white:'#ffffff', mute:'rgba(255,255,255,.72)', dim:'rgba(255,255,255,.52)',
  line:'rgba(255,255,255,.08)',
};

// ─────────────────────────────────────────────────────────────
// Scroll reveal primitive
// ─────────────────────────────────────────────────────────────
function Reveal({children, delay=0, y=30, style={}}) {
  const ref = React.useRef(null);
  const [vis, setVis] = React.useState(false);
  React.useEffect(()=>{
    const io = new IntersectionObserver(([e])=>{
      if(e.isIntersecting){ setVis(true); io.disconnect(); }
    },{threshold:.12});
    if(ref.current) io.observe(ref.current);
    return ()=>io.disconnect();
  },[]);
  return (
    <div ref={ref} style={{
      opacity:vis?1:0, transform:vis?'translateY(0) scale(1)':`translateY(${y}px) scale(.98)`,
      transition:`opacity .9s cubic-bezier(.2,.7,.2,1) ${delay}ms, transform .9s cubic-bezier(.2,.7,.2,1) ${delay}ms`,
      ...style
    }}>{children}</div>
  );
}

// ─────────────────────────────────────────────────────────────
// Aurora background (orbs + mesh + grid + sport glyphs)
// ─────────────────────────────────────────────────────────────
function Aurora() {
  return (
    <div style={{position:'absolute',inset:0,overflow:'hidden',pointerEvents:'none'}}>
      <div style={{position:'absolute',inset:0,background:`radial-gradient(ellipse at top, ${V2.bg4} 0%, ${V2.bg2} 45%, ${V2.bg1} 100%)`}}/>
      {/* orbs */}
      <div style={{position:'absolute',top:'-10%',left:'10%',width:560,height:560,borderRadius:'50%',background:`radial-gradient(circle, ${V2.violet}55, transparent 65%)`,filter:'blur(70px)',animation:'orb1 22s ease-in-out infinite'}}/>
      <div style={{position:'absolute',top:'20%',right:'-8%',width:520,height:520,borderRadius:'50%',background:`radial-gradient(circle, ${V2.cyan}45, transparent 65%)`,filter:'blur(80px)',animation:'orb2 26s ease-in-out infinite'}}/>
      <div style={{position:'absolute',bottom:'-15%',left:'30%',width:600,height:600,borderRadius:'50%',background:`radial-gradient(circle, ${V2.violetDeep}40, transparent 70%)`,filter:'blur(90px)',animation:'orb3 30s ease-in-out infinite'}}/>
      {/* grid */}
      <div style={{position:'absolute',inset:0,backgroundImage:`linear-gradient(${V2.line} 1px, transparent 1px), linear-gradient(90deg, ${V2.line} 1px, transparent 1px)`,backgroundSize:'64px 64px',opacity:.5,maskImage:'radial-gradient(ellipse at center, #000 20%, transparent 70%)',WebkitMaskImage:'radial-gradient(ellipse at center, #000 20%, transparent 70%)'}}/>
      {/* sport glyphs scattered (subtle line-art) */}
      <SportGlyph x="6%" y="18%" rot={-12} icon="ball"/>
      <SportGlyph x="88%" y="12%" rot={20} icon="racket"/>
      <SportGlyph x="12%" y="72%" rot={15} icon="shoe"/>
      <SportGlyph x="85%" y="65%" rot={-8} icon="glove"/>
      <SportGlyph x="48%" y="88%" rot={0} icon="ribbon"/>
      <style>{`
        @keyframes orb1 { 0%,100%{transform:translate(0,0) scale(1)} 50%{transform:translate(60px,40px) scale(1.1)} }
        @keyframes orb2 { 0%,100%{transform:translate(0,0) scale(1)} 50%{transform:translate(-40px,60px) scale(1.15)} }
        @keyframes orb3 { 0%,100%{transform:translate(0,0) scale(1)} 50%{transform:translate(40px,-50px) scale(.9)} }
      `}</style>
    </div>
  );
}

function SportGlyph({x,y,rot=0,icon}) {
  const paths = {
    ball: <g><circle cx="30" cy="30" r="26"/><path d="M30 4c8 10 8 42 0 52M4 30c10-8 42-8 52 0M10 12c14 4 24 14 28 28M50 12c-14 4-24 14-28 28"/></g>,
    racket: <g><ellipse cx="20" cy="20" rx="14" ry="16"/><path d="M31 30l20 20M28 34l18 18"/><path d="M10 14h20M10 20h20M10 26h20M14 10v20M20 10v20M26 10v20"/></g>,
    shoe: <g><path d="M4 38c0-6 4-12 12-14l10-4c6-2 12 0 16 4l8 8c4 4 6 8 6 12v4H4z"/><path d="M20 24l4 6M30 22l4 6M40 26l4 6"/></g>,
    glove: <g><path d="M18 10c0-4 4-6 8-6s8 2 8 6v14h4c4 0 8 4 8 8v20c0 4-4 8-8 8H22c-4 0-8-4-8-8V30c0-4 2-6 4-6z"/><path d="M18 30c0-2-4-4-8-4s-6 2-6 4v6c0 2 2 4 6 4s8-2 8-4"/></g>,
    ribbon: <g><path d="M8 30c8-12 16-12 24 0s16 12 24 0"/><path d="M8 40c8-12 16-12 24 0s16 12 24 0"/><path d="M8 20c8-12 16-12 24 0s16 12 24 0"/></g>,
  };
  return (
    <svg width="110" height="110" viewBox="0 0 60 60" style={{position:'absolute',left:x,top:y,transform:`rotate(${rot}deg)`,opacity:.06,stroke:'#fff',fill:'none',strokeWidth:1.2}}>
      {paths[icon]}
    </svg>
  );
}

// ─────────────────────────────────────────────────────────────
// Glass surface
// ─────────────────────────────────────────────────────────────
function Glass({children, style={}, radius=20, glow}) {
  return (
    <div style={{
      position:'relative', borderRadius:radius, overflow:'hidden',
      background:'rgba(255,255,255,.04)',
      backdropFilter:'blur(18px) saturate(140%)',
      WebkitBackdropFilter:'blur(18px) saturate(140%)',
      border:'1px solid rgba(255,255,255,.08)',
      boxShadow: glow ? `0 30px 60px -30px ${glow}66, inset 0 1px 0 rgba(255,255,255,.08)` : 'inset 0 1px 0 rgba(255,255,255,.06)',
      ...style,
    }}>
      <div style={{position:'absolute',top:0,left:0,right:0,height:1,background:`linear-gradient(90deg, transparent, ${V2.violet}80, ${V2.cyan}80, transparent)`,opacity:.6}}/>
      {children}
    </div>
  );
}

function GradientText({children,style={}}) {
  return (
    <span style={{background:`linear-gradient(135deg, ${V2.violet} 0%, ${V2.cyan} 100%)`,WebkitBackgroundClip:'text',WebkitTextFillColor:'transparent',backgroundClip:'text',...style}}>{children}</span>
  );
}

function ButtonPrimary({children, onClick, big}) {
  return (
    <button onClick={onClick} style={{
      position:'relative', padding:big?'16px 28px':'13px 22px', borderRadius:14,
      background:`linear-gradient(135deg, ${V2.violet}, ${V2.violetDeep})`,
      color:'#fff', border:'none', fontWeight:700, fontSize:big?16:14,
      cursor:'pointer', fontFamily:'Poppins,system-ui,sans-serif',
      boxShadow:`0 20px 40px -12px ${V2.violet}80, inset 0 1px 0 rgba(255,255,255,.3)`,
      letterSpacing:'-.01em', display:'inline-flex', alignItems:'center', gap:10,
      transition:'transform .2s, box-shadow .2s',
    }}
    onMouseEnter={e=>{e.currentTarget.style.transform='translateY(-2px)';e.currentTarget.style.boxShadow=`0 28px 50px -12px ${V2.violet}a0, inset 0 1px 0 rgba(255,255,255,.3)`}}
    onMouseLeave={e=>{e.currentTarget.style.transform='';e.currentTarget.style.boxShadow=`0 20px 40px -12px ${V2.violet}80, inset 0 1px 0 rgba(255,255,255,.3)`}}
    >
      <span style={{position:'absolute',inset:0,borderRadius:14,background:`linear-gradient(135deg, transparent, rgba(255,255,255,.2), transparent)`,opacity:0,transition:'opacity .3s',pointerEvents:'none'}}/>
      {children}
    </button>
  );
}

function ButtonGhost({children, onClick, big}) {
  return (
    <button onClick={onClick} style={{
      padding:big?'16px 26px':'13px 20px', borderRadius:14,
      background:'rgba(255,255,255,.04)', backdropFilter:'blur(14px)',
      color:'#fff', border:'1px solid rgba(255,255,255,.14)',
      fontWeight:600, fontSize:big?16:14, cursor:'pointer',
      fontFamily:'Poppins,system-ui,sans-serif',
      display:'inline-flex', alignItems:'center', gap:10,
      transition:'all .2s',
    }}
    onMouseEnter={e=>{e.currentTarget.style.background='rgba(255,255,255,.09)';e.currentTarget.style.borderColor='rgba(255,255,255,.24)'}}
    onMouseLeave={e=>{e.currentTarget.style.background='rgba(255,255,255,.04)';e.currentTarget.style.borderColor='rgba(255,255,255,.14)'}}
    >{children}</button>
  );
}

// ─────────────────────────────────────────────────────────────
// NAV
// ─────────────────────────────────────────────────────────────
function Nav() {
  return (
    <nav style={{position:'fixed',top:18,left:'50%',transform:'translateX(-50%)',zIndex:50,width:'min(1180px, calc(100% - 32px))'}}>
      <Glass radius={16} style={{padding:'10px 14px 10px 18px',display:'flex',alignItems:'center',gap:18}}>
        <div style={{display:'flex',alignItems:'center',gap:10}}>
          <div style={{width:32,height:32,borderRadius:9,background:`linear-gradient(135deg,${V2.violet},${V2.cyan})`,display:'grid',placeItems:'center',color:'#fff',fontWeight:900,fontSize:15,boxShadow:`0 6px 18px -6px ${V2.violet}80`}}>M</div>
          <div style={{fontWeight:800,fontSize:17,letterSpacing:'.04em',color:'#fff'}}>METIO</div>
        </div>
        <div style={{flex:1,display:'flex',gap:24,justifyContent:'center'}} className="navlinks">
          {['Functii','Sporturi','Clienti','Preturi'].map(l=>(
            <a key={l} href={`#${l}`} style={{color:V2.mute,fontSize:13,fontWeight:500,textDecoration:'none',transition:'color .2s'}} onMouseEnter={e=>e.currentTarget.style.color='#fff'} onMouseLeave={e=>e.currentTarget.style.color=V2.mute}>{l}</a>
          ))}
        </div>
        <button className="nav-login" style={{padding:'8px 14px',borderRadius:10,background:'transparent',border:'1px solid rgba(255,255,255,.14)',color:'#fff',fontSize:13,fontWeight:600,cursor:'pointer',fontFamily:'inherit'}}>Autentificare</button>
        <span className="nav-cta-wrap"><ButtonPrimary>Incearca gratuit</ButtonPrimary></span>
      </Glass>
    </nav>
  );
}

// ─────────────────────────────────────────────────────────────
// HERO
// ─────────────────────────────────────────────────────────────
function Hero() {
  return (
    <section className="hero-section" style={{position:'relative',padding:'140px 24px 100px',display:'flex',flexDirection:'column',alignItems:'center',overflow:'hidden'}}>
      <Aurora/>
      <div style={{position:'relative',zIndex:2,maxWidth:1180,width:'100%',display:'flex',flexDirection:'column',alignItems:'center',textAlign:'center'}}>
        <Reveal>
          <div style={{display:'inline-flex',alignItems:'center',gap:8,padding:'6px 12px 6px 8px',borderRadius:99,background:'rgba(139,92,246,.08)',border:`1px solid ${V2.violet}40`,marginBottom:28}}>
            <div style={{width:20,height:20,borderRadius:99,background:`linear-gradient(135deg,${V2.violet},${V2.cyan})`,display:'grid',placeItems:'center',fontSize:11}}>✦</div>
            <span style={{fontSize:12,fontWeight:600,color:V2.white,letterSpacing:'.02em'}}>Management complet pentru clubul tau sportiv</span>
          </div>
        </Reveal>

        <Reveal delay={80}>
          <h1 style={{fontSize:'clamp(44px,7.5vw,96px)',fontWeight:800,lineHeight:.98,letterSpacing:'-.035em',color:'#fff',margin:'0 0 22px',maxWidth:1000}}>
            Clubul tau.<br/><GradientText>Organizat perfect.</GradientText>
          </h1>
        </Reveal>

        <Reveal delay={160}>
          <p style={{fontSize:'clamp(18px,1.6vw,21px)',color:V2.mute,maxWidth:640,margin:'0 0 36px',lineHeight:1.55,fontWeight:400}}>
            tii evidenta elevilor, prezentelor si platilor — totul dintr-o aplicatie simpla, de pe telefon. Pentru orice club sportiv.
          </p>
        </Reveal>

        <Reveal delay={240}>
          <div style={{display:'flex',gap:12,flexWrap:'wrap',justifyContent:'center'}}>
            <ButtonPrimary big>
              Incearca gratuit
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M5 12h14M13 5l7 7-7 7" stroke="#fff" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/></svg>
            </ButtonPrimary>
            <ButtonGhost big>
              <svg width="14" height="14" viewBox="0 0 24 24" fill="#fff"><path d="M8 5v14l11-7z"/></svg>
              Vezi demo
            </ButtonGhost>
          </div>
        </Reveal>

        <Reveal delay={340}>
          <div style={{marginTop:28,display:'flex',alignItems:'center',gap:10,color:V2.dim,fontSize:13}}>
            <div style={{display:'flex'}}>
              {['#8B5CF6','#06B6D4','#F472B6','#FBBF24','#34D399'].map((c,i)=>(
                <div key={i} style={{width:26,height:26,borderRadius:99,background:`linear-gradient(135deg,${c},${c}80)`,border:'2px solid #0B1120',marginLeft:i>0?-8:0}}/>
              ))}
            </div>
            <span>Folosit de <span style={{color:'#fff',fontWeight:700}}>127+ cluburi sportive</span> din Romania</span>
          </div>
        </Reveal>

      </div>
    </section>
  );
}

function PhoneFrame({src, rotate=0, width=300, glow='#8B5CF6', label}) {
  // Extra height = safe area strip (44px scaled to frame width)
  const safeArea = Math.round(width * 44 / 260);
  const h = width * 2.16 + safeArea;
  return (
    <div style={{position:'relative',transform:`rotate(${rotate}deg) perspective(1200px) rotateY(${rotate>0?'-4deg':rotate<0?'4deg':'0'})`,transition:'transform .6s'}}>
      <div style={{position:'absolute',inset:-20,background:`radial-gradient(ellipse at center, ${glow}45, transparent 60%)`,filter:'blur(30px)'}}/>
      <div style={{position:'relative',width,height:h,borderRadius:46,padding:9,background:'linear-gradient(180deg,#2A2F3A,#0F1419)',boxShadow:'0 60px 120px -30px rgba(0,0,0,.8), 0 0 0 1px rgba(255,255,255,.08), inset 0 0 0 1px rgba(255,255,255,.05)'}}>
        <div style={{position:'relative',width:'100%',height:'100%',borderRadius:38,overflow:'hidden',background:'#0B1120',display:'flex',flexDirection:'column'}}>
          {/* iOS safe area strip — exactly like on a real iPhone */}
          <div style={{
            height: safeArea, flexShrink:0,
            background:'linear-gradient(180deg,#0a0a12 60%,#12121e 100%)',
            display:'flex',alignItems:'center',justifyContent:'center',
          }}>
            <div style={{width:Math.round(width*88/260),height:Math.round(width*24/260),borderRadius:99,background:'#000'}}/>
          </div>
          {/* Full screenshot — no crop top or bottom */}
          <img src={src} style={{width:'100%',flex:1,objectFit:'cover',objectPosition:'top',display:'block',minHeight:0}}/>
        </div>
      </div>
      {label && (
        <div style={{marginTop:14,padding:'7px 14px',borderRadius:99,background:'rgba(255,255,255,.04)',backdropFilter:'blur(14px)',border:'1px solid rgba(255,255,255,.1)',color:'#fff',fontSize:12,fontWeight:600,textAlign:'center',display:'inline-block'}}>{label}</div>
      )}
    </div>
  );
}

Object.assign(window, { V2, Reveal, Aurora, Glass, GradientText, ButtonPrimary, ButtonGhost, Nav, Hero, PhoneFrame });
