// METIO v2 — Light premium SaaS landing.
// Visual: clean #F8FAFF base, gradient #2563EB→#7C3AED, green #10B981, Poppins.

const V2 = {
  bg1:'#F8FAFF', bg2:'#EFF4FF', bg3:'#E8EFFF', bg4:'#DDE8FF',
  primary:'#2563EB', primaryDeep:'#1D4ED8',
  violet:'#7C3AED', violetDeep:'#6D28D9',
  cyan:'#2563EB', cyanDeep:'#1D4ED8',
  green:'#10B981', red:'#F87171',
  white:'#ffffff',
  text:'#0F172A', mute:'#475569', dim:'#94A3B8',
  line:'rgba(37,99,235,.1)',
};

// ─────────────────────────────────────────────────────────────
// 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 (light gradient + subtle orbs + grid)
// ─────────────────────────────────────────────────────────────
function Aurora() {
  return (
    <div style={{position:'absolute',inset:0,overflow:'hidden',pointerEvents:'none'}}>
      <div style={{position:'absolute',inset:0,background:`linear-gradient(160deg, ${V2.bg4} 0%, ${V2.bg2} 40%, ${V2.bg1} 100%)`}}/>
      <div style={{position:'absolute',top:'-20%',left:'-5%',width:700,height:700,borderRadius:'50%',background:`radial-gradient(circle, rgba(37,99,235,.18), transparent 60%)`,filter:'blur(80px)',animation:'orb1 22s ease-in-out infinite'}}/>
      <div style={{position:'absolute',top:'15%',right:'-8%',width:600,height:600,borderRadius:'50%',background:`radial-gradient(circle, rgba(124,58,237,.14), transparent 60%)`,filter:'blur(90px)',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, rgba(37,99,235,.1), transparent 70%)`,filter:'blur(100px)',animation:'orb3 30s ease-in-out infinite'}}/>
      <div style={{position:'absolute',inset:0,backgroundImage:`linear-gradient(rgba(37,99,235,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(37,99,235,.05) 1px, transparent 1px)`,backgroundSize:'64px 64px',maskImage:'radial-gradient(ellipse at center, #000 20%, transparent 70%)',WebkitMaskImage:'radial-gradient(ellipse at center, #000 20%, transparent 70%)'}}/>
      <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:.09,stroke:V2.primary,fill:'none',strokeWidth:1.2}}>
      {paths[icon]}
    </svg>
  );
}

// ─────────────────────────────────────────────────────────────
// Card surface
// ─────────────────────────────────────────────────────────────
function Glass({children, style={}, radius=20, glow}) {
  return (
    <div style={{
      position:'relative', borderRadius:radius, overflow:'hidden',
      background:'#ffffff',
      border:'1px solid rgba(37,99,235,.1)',
      boxShadow: glow ? `0 20px 50px -15px ${glow}25, 0 2px 8px rgba(37,99,235,.06)` : '0 2px 12px rgba(37,99,235,.07), 0 1px 2px rgba(0,0,0,.04)',
      ...style,
    }}>
      <div style={{position:'absolute',top:0,left:0,right:0,height:2,background:`linear-gradient(90deg, transparent, ${V2.primary}60, ${V2.violet}60, transparent)`,opacity:.8}}/>
      {children}
    </div>
  );
}

function GradientText({children,style={}}) {
  return (
    <span style={{background:`linear-gradient(135deg, ${V2.primary} 0%, ${V2.violet} 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.primary}, ${V2.violet})`,
      color:'#fff', border:'none', fontWeight:700, fontSize:big?16:14,
      cursor:'pointer', fontFamily:'Poppins,system-ui,sans-serif',
      boxShadow:`0 8px 24px -6px ${V2.primary}60`,
      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 16px 36px -8px ${V2.primary}80`}}
    onMouseLeave={e=>{e.currentTarget.style.transform='';e.currentTarget.style.boxShadow=`0 8px 24px -6px ${V2.primary}60`}}
    >
      {children}
    </button>
  );
}

function ButtonGhost({children, onClick, big}) {
  return (
    <button onClick={onClick} style={{
      padding:big?'15px 26px':'12px 20px', borderRadius:14,
      background:'#ffffff',
      color:V2.primary, border:`1.5px solid ${V2.primary}40`,
      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=V2.bg2;e.currentTarget.style.borderColor=V2.primary}}
    onMouseLeave={e=>{e.currentTarget.style.background='#ffffff';e.currentTarget.style.borderColor=`${V2.primary}40`}}
    >{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))'}}>
      <div style={{
        borderRadius:16, padding:'10px 14px 10px 18px', display:'flex', alignItems:'center', gap:18,
        background:'rgba(255,255,255,.92)', backdropFilter:'blur(20px)', WebkitBackdropFilter:'blur(20px)',
        border:'1px solid rgba(37,99,235,.1)',
        boxShadow:'0 4px 20px rgba(37,99,235,.08), 0 1px 4px rgba(0,0,0,.04)',
      }}>
        <a href="#" onClick={e=>{e.preventDefault();window.scrollTo({top:0,behavior:'smooth'})}} style={{display:'flex',alignItems:'center',gap:10,textDecoration:'none',cursor:'pointer'}}>
          <svg width="32" height="32" viewBox="0 0 96 96" xmlns="http://www.w3.org/2000/svg" style={{flexShrink:0,filter:`drop-shadow(0 4px 8px ${V2.primary}50)`}}>
            <defs><linearGradient id="navLogo" x1="0" y1="0" x2="1" y2="1"><stop offset="0%" stopColor="#2563EB"/><stop offset="100%" stopColor="#7C3AED"/></linearGradient></defs>
            <rect width="96" height="96" rx="22" fill="url(#navLogo)"/>
            <polyline points="18,74 18,24 48,58 78,24 78,74" fill="none" stroke="white" strokeWidth="13" strokeLinejoin="round" strokeLinecap="round"/>
          </svg>
          <div style={{fontWeight:800,fontSize:17,letterSpacing:'.04em',color:V2.text}}>METIO</div>
        </a>
        <div style={{flex:1,display:'flex',gap:24,justifyContent:'center'}} className="navlinks">
          {[{l:'Functii',href:'#Functii'},{l:'Clienti',href:'#Clienti'},{l:'Preturi',href:'#Contact'}].map(({l,href})=>(
            <a key={l} href={href} style={{color:V2.mute,fontSize:13,fontWeight:500,textDecoration:'none',transition:'color .2s'}} onMouseEnter={e=>e.currentTarget.style.color=V2.text} onMouseLeave={e=>e.currentTarget.style.color=V2.mute}>{l}</a>
          ))}
        </div>
        <button className="nav-login" onClick={()=>window.location.href='/account'} style={{padding:'8px 14px',borderRadius:10,background:'transparent',border:`1px solid ${V2.primary}30`,color:V2.primary,fontSize:13,fontWeight:600,cursor:'pointer',fontFamily:'inherit'}}>Autentificare</button>
        <span className="nav-cta-wrap"><ButtonPrimary onClick={()=>window.location.href='/register'}>Încearcă gratuit</ButtonPrimary></span>
      </div>
    </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:`${V2.primary}10`,border:`1px solid ${V2.primary}25`,marginBottom:28}}>
            <div style={{width:20,height:20,borderRadius:99,background:`linear-gradient(135deg,${V2.primary},${V2.violet})`,display:'grid',placeItems:'center',fontSize:11,color:'#fff'}}>✦</div>
            <span style={{fontSize:12,fontWeight:600,color:V2.primary,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:V2.text,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 onClick={()=>window.location.href='/register'}>
              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>
          </div>
        </Reveal>

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

      </div>
    </section>
  );
}

function PhoneFrame({src, rotate=0, width=300, glow='#2563EB', label}) {
  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}25, transparent 60%)`,filter:'blur(30px)'}}/>
      <div style={{position:'relative',width,height:h,borderRadius:46,padding:9,background:'linear-gradient(180deg,#2A2F3A,#0F1419)',boxShadow:`0 32px 64px -16px ${glow}30, 0 16px 48px -24px rgba(0,0,0,.25), 0 0 0 1px rgba(255,255,255,.08)`}}>
        <div style={{position:'relative',width:'100%',height:'100%',borderRadius:38,overflow:'hidden',background:'#0B1120',display:'flex',flexDirection:'column'}}>
          <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>
          <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:'#ffffff',border:`1px solid ${V2.primary}20`,color:V2.mute,fontSize:12,fontWeight:600,textAlign:'center',display:'inline-block',boxShadow:'0 2px 8px rgba(37,99,235,.08)'}}>{label}</div>
      )}
    </div>
  );
}

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