/* global React, Reveal, Star, Glyph, Magnetic, PLATFORMS */
const { useState:useX2S, useEffect:useX2E, useRef:useX2R } = React;

/* ============================================================
   SCROLL PROGRESS BAR + BACK TO TOP
   ============================================================ */
function ScrollProgress(){
  const [p,setP]=useX2S(0);
  const [show,setShow]=useX2S(false);
  useX2E(()=>{
    const on=()=>{ const h=document.documentElement; const max=h.scrollHeight-h.clientHeight;
      const y=h.scrollTop||window.scrollY; setP(max>0?y/max:0); setShow(y>700); };
    on(); window.addEventListener('scroll',on,{passive:true}); window.addEventListener('resize',on);
    return ()=>{ window.removeEventListener('scroll',on); window.removeEventListener('resize',on); };
  },[]);
  return React.createElement(React.Fragment,null,
    React.createElement('div',{className:'scroll-progress'},
      React.createElement('div',{className:'scroll-progress-fill',style:{transform:`scaleX(${p})`}})),
    React.createElement('button',{className:`back-top ${show?'show':''}`,onClick:()=>window.scrollTo({top:0,behavior:'smooth'}),title:'Back to top'},
      React.createElement('svg',{viewBox:'0 0 24 24',width:20,height:20,fill:'none',stroke:'currentColor',strokeWidth:1.8,strokeLinecap:'round',strokeLinejoin:'round'},
        React.createElement('path',{d:'M12 19V5M6 11l6-6 6 6'})))
  );
}

/* ============================================================
   ROADMAP — AetherCore build timeline
   ============================================================ */
const ROADMAP=[
  { ph:'Phase I', yr:'2024', t:'Foundation', d:'Core RNA discovery engine and the first closed-loop platform come online.', done:true, icon:'dna2' },
  { ph:'Phase II', yr:'2025', t:'Intelligence', d:'Disease-state modeling and the biological reasoning layer reach production.', done:true, icon:'brain' },
  { ph:'Phase III', yr:'2026', t:'Integration', d:'Nine platforms unify under JANUS-X into one agentic operating system.', done:false, active:true, icon:'cpu' },
  { ph:'Phase IV', yr:'2028', t:'Translation', d:'Precision interventions move from in-silico design into clinical partnership.', done:false, icon:'scope' },
  { ph:'Phase V', yr:'2030+', t:'Restoration', d:'Restorative medicine — steering biological systems back toward health.', done:false, icon:'leaf' },
];
function Roadmap(){
  return React.createElement('section',{className:'section marble veined grain roadmap',id:'roadmap'},
    React.createElement('div',{className:'wrap'},
      React.createElement('div',{className:'eyebrow-row'},React.createElement(Reveal,{as:'span',className:'kicker center greek'},'The Roadmap')),
      React.createElement(Reveal,{as:'h2',className:'display h-lg center greek',delay:80,style:{marginTop:'18px'}},
        'The path we ',React.createElement('span',{className:'gild italic'},'are building.')),
      React.createElement('div',{className:'roadmap-track'},
        React.createElement('div',{className:'roadmap-line'}),
        ROADMAP.map((r,i)=>React.createElement(Reveal,{key:i,className:`roadmap-node ${r.done?'done':''} ${r.active?'active':''}`,delay:i*90},
          React.createElement('div',{className:'roadmap-dot'},
            r.done?React.createElement('span',{className:'roadmap-check'},'\u2713'):React.createElement(Glyph,{name:r.icon,width:18,height:18})),
          React.createElement('div',{className:'roadmap-card'},
            React.createElement('div',{className:'roadmap-ph'},r.ph,React.createElement('span',{className:'roadmap-yr'},r.yr)),
            React.createElement('div',{className:'roadmap-t'},r.t),
            React.createElement('p',{className:'roadmap-d'},r.d),
            r.active&&React.createElement('span',{className:'roadmap-badge'},'In progress'))))
      )
    )
  );
}

/* ============================================================
   PLATFORM COMPARISON MATRIX
   ============================================================ */
const MATRIX_ROWS=[
  { cap:'Multi-omic analysis', p:['plexis','kosmos','moira','istos'] },
  { cap:'Disease forecasting', p:['fasi','moira','kytos'] },
  { cap:'Therapeutic design', p:['klothos','epanafero'] },
  { cap:'Reasoning / knowledge', p:['kosmos','janus'] },
  { cap:'Spatial / tissue', p:['istos','kytos'] },
  { cap:'Agentic orchestration', p:['janus','moira'] },
];
function Matrix(){
  const heads=PLATFORMS.slice(0,9);
  return React.createElement('section',{className:'section marble-deep veined matrix-sec',id:'matrix'},
    React.createElement('div',{className:'wrap'},
      React.createElement('div',{className:'eyebrow-row'},React.createElement(Reveal,{as:'span',className:'kicker center greek'},'Capability Matrix')),
      React.createElement(Reveal,{as:'h2',className:'display h-lg center greek',delay:80,style:{marginTop:'18px'}},
        'Which engine does ',React.createElement('span',{className:'gild italic'},'what.')),
      React.createElement(Reveal,{className:'matrix-scroll',delay:140},
        React.createElement('table',{className:'matrix'},
          React.createElement('thead',null,
            React.createElement('tr',null,
              React.createElement('th',{className:'matrix-corner'},'Capability'),
              heads.map(h=>React.createElement('th',{key:h.id,className:'matrix-h'},
                React.createElement('span',{className:'matrix-h-ic'},React.createElement(Glyph,{name:h.icon,width:16,height:16})),
                React.createElement('span',null,h.name.replace(' RNA','')))))),
          React.createElement('tbody',null,
            MATRIX_ROWS.map((row,ri)=>React.createElement('tr',{key:ri},
              React.createElement('td',{className:'matrix-cap'},row.cap),
              heads.map(h=>React.createElement('td',{key:h.id,className:'matrix-cell'},
                row.p.includes(h.id)?React.createElement('span',{className:'matrix-yes'},React.createElement(Star,{size:11})):React.createElement('span',{className:'matrix-no'},'\u00b7'))))))
        ))
    )
  );
}

/* ============================================================
   FAQ ACCORDION
   ============================================================ */
const FAQS=[
  ['What is AetherCore Labs?','A biological intelligence company building an operating system for biology — nine platforms that predict, prevent, and restore disease.'],
  ['What is the Academy?','A free learning environment where you explore the science of every disease and learn to build science apps with AI, with courses, flashcards, quizzes, and projects.'],
  ['Is the literature real?','Yes. Every reading link runs a live query against PubMed, Nature, Europe PMC, ClinicalTrials, and more — nothing is fabricated.'],
  ['Do I need an account?','You can sign in with Google, GitHub, or email. Your progress, notes, and saved items are stored privately in your browser.'],
  ['What is MOIRA?','MOIRA is our biological foresight engine — it models the hidden forces shaping cellular destiny and forecasts disease trajectories before they become clinically apparent.'],
  ['How do I partner or join?','Use the Contact button anywhere on the site, or explore open roles in the Careers section. We\u2019d love to hear from you.'],
];
function FAQ(){
  const [open,setOpen]=useX2S(0);
  return React.createElement('section',{className:'section marble veined grain faq-sec',id:'faq'},
    React.createElement('div',{className:'wrap wrap-narrow'},
      React.createElement('div',{className:'eyebrow-row'},React.createElement(Reveal,{as:'span',className:'kicker center greek'},'Questions')),
      React.createElement(Reveal,{as:'h2',className:'display h-lg center greek',delay:80,style:{marginTop:'18px',marginBottom:'44px'}},
        'Frequently ',React.createElement('span',{className:'gild italic'},'asked.')),
      React.createElement('div',{className:'faq-list'},
        FAQS.map((f,i)=>React.createElement(Reveal,{key:i,className:`faq-item ${open===i?'open':''}`,delay:i*50},
          React.createElement('button',{className:'faq-q',onClick:()=>setOpen(open===i?-1:i)},
            React.createElement('span',null,f[0]),
            React.createElement('span',{className:'faq-plus'},open===i?'\u2212':'+')),
          React.createElement('div',{className:'faq-a',style:{maxHeight:open===i?'220px':'0'}},
            React.createElement('p',null,f[1])))))
    )
  );
}

/* ============================================================
   NEWSLETTER CAPTURE (mailto)
   ============================================================ */
function Newsletter(){
  const [email,setEmail]=useX2S('');
  const [sent,setSent]=useX2S(false);
  const submit=(e)=>{ e.preventDefault();
    if(!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) return;
    window.location.href='mailto:kJOSHI2@bidmc.harvard.edu?subject='+encodeURIComponent('AETHERCORE LABS')+'&body='+encodeURIComponent('Please add me to the AetherCore Labs newsletter.\n\nEmail: '+email);
    setSent(true);
  };
  return React.createElement('section',{className:'section marble-deep veined news-sec',id:'newsletter'},
    React.createElement('div',{className:'wrap wrap-narrow center'},
      React.createElement(Reveal,{className:'news-inner glass'},
        React.createElement('div',{className:'news-star'},React.createElement(Star,{size:24})),
        React.createElement('h2',{className:'display news-h greek'},'Stay on the ',React.createElement('span',{className:'gild italic'},'frontier.')),
        React.createElement('p',{className:'news-d'},'Occasional dispatches on new platforms, publications, and breakthroughs. No noise.'),
        sent
          ? React.createElement('div',{className:'news-thanks'},React.createElement(Star,{size:14}),'Thank you — check your email client to confirm.')
          : React.createElement('form',{className:'news-form',onSubmit:submit},
              React.createElement('input',{type:'email',className:'news-input',placeholder:'you@lab.edu',value:email,onChange:e=>setEmail(e.target.value)}),
              React.createElement('button',{type:'submit',className:'btn btn-gold'},'Subscribe',React.createElement(Glyph,{name:'arrow',className:'arr',width:16,height:16})))
      )
    )
  );
}

Object.assign(window,{ ScrollProgress, Roadmap, Matrix, FAQ, Newsletter });
