/* global React, Reveal, Star, Rule, Magnetic, Counter, Glyph */
const { useState:useHS, useEffect:useHE, useRef:useHR } = React;

/* ============================================================
   MOIRA — interactive biological forecast demo
   ============================================================ */
const MOIRA_STATES=[
  { id:'healthy', label:'Healthy Baseline', icon:'leaf', tone:'#1f8a5b',
    forecast:[92,90,91,89,90,88,89,90], risk:8, verdict:'Stable homeostasis. No intervention indicated.',
    signals:['Regulatory network balanced','Low mutational burden','Immune surveillance intact'] },
  { id:'stressed', label:'Cellular Stress', icon:'pulse', tone:'#c9622b',
    forecast:[78,74,69,66,61,58,54,50], risk:46, verdict:'Early drift detected. MOIRA flags a transition window in ~14 cycles.',
    signals:['Rising oxidative signal','Proteostasis strain','Metabolic reprogramming onset'] },
  { id:'transition', label:'Pre-Disease Transition', icon:'target', tone:'#b5321a',
    forecast:[60,54,47,41,34,29,24,19], risk:74, verdict:'Critical transition imminent. Intervention design recommended now.',
    signals:['Bistable state instability','Clonal expansion signature','Checkpoint escape probability high'] },
  { id:'restored', label:'Post-Intervention', icon:'shield', tone:'#1a6fb5',
    forecast:[38,47,55,63,70,76,81,85], risk:22, verdict:'Trajectory reversed. System steering back toward healthy attractor.',
    signals:['Network re-stabilizing','Therapeutic response confirmed','Restoration pathway active'] },
];

function Sparkline({ data, tone }){
  const w=520,h=150,pad=12;
  const max=100,min=0;
  const pts=data.map((v,i)=>[pad+(i/(data.length-1))*(w-pad*2), h-pad-((v-min)/(max-min))*(h-pad*2)]);
  const line=pts.map((p,i)=>(i?'L':'M')+p[0].toFixed(1)+' '+p[1].toFixed(1)).join(' ');
  const area=line+` L ${pts[pts.length-1][0].toFixed(1)} ${h-pad} L ${pts[0][0].toFixed(1)} ${h-pad} Z`;
  return React.createElement('svg',{viewBox:`0 0 ${w} ${h}`,className:'moira-spark',preserveAspectRatio:'none'},
    React.createElement('defs',null,
      React.createElement('linearGradient',{id:'moiraFill',x1:0,y1:0,x2:0,y2:1},
        React.createElement('stop',{offset:'0%',stopColor:tone,stopOpacity:.28}),
        React.createElement('stop',{offset:'100%',stopColor:tone,stopOpacity:0}))),
    [25,50,75].map(y=>React.createElement('line',{key:y,x1:pad,y1:h-pad-(y/100)*(h-pad*2),x2:w-pad,y2:h-pad-(y/100)*(h-pad*2),className:'moira-grid'})),
    React.createElement('path',{d:area,fill:'url(#moiraFill)',className:'moira-area'}),
    React.createElement('path',{d:line,fill:'none',stroke:tone,strokeWidth:2.5,strokeLinecap:'round',strokeLinejoin:'round',className:'moira-line'}),
    pts.map((p,i)=>React.createElement('circle',{key:i,cx:p[0],cy:p[1],r:i===pts.length-1?4.5:2.6,fill:tone,className:'moira-dot',style:{animationDelay:(i*0.06)+'s'}}))
  );
}

function MoiraDemo(){
  const [active,setActive]=useHS(1);
  const s=MOIRA_STATES[active];
  return React.createElement('section',{className:'section marble veined grain moira',id:'moira'},
    React.createElement('div',{className:'wrap'},
      React.createElement('div',{className:'eyebrow-row'},React.createElement(Reveal,{as:'span',className:'kicker center greek'},'MOIRA \u00b7 Foresight Engine')),
      React.createElement(Reveal,{as:'h2',className:'display h-lg center greek',delay:80,style:{marginTop:'18px'}},
        'See what a cell ',React.createElement('span',{className:'gild italic'},'is becoming.')),
      React.createElement(Reveal,{as:'p',className:'serif-lead center mx-auto',delay:140,style:{maxWidth:'640px',marginTop:'20px'}},
        'Choose a biological state. MOIRA forecasts its trajectory and the moment intervention matters most.'),
      React.createElement(Reveal,{variant:'r-scale',className:'moira-stage glass',delay:160},
        React.createElement('div',{className:'moira-states'},
          MOIRA_STATES.map((st,i)=>React.createElement('button',{key:st.id,className:`moira-state ${i===active?'on':''}`,
            style:{'--tone':st.tone},onClick:()=>setActive(i)},
            React.createElement('span',{className:'moira-state-ic'},React.createElement(Glyph,{name:st.icon,width:20,height:20})),
            React.createElement('span',null,st.label)))),
        React.createElement('div',{className:'moira-panel'},
          React.createElement('div',{className:'moira-chart'},
            React.createElement('div',{className:'moira-chart-head'},
              React.createElement('span',null,'Predicted health trajectory'),
              React.createElement('span',{className:'moira-chart-axis'},'now \u2192 forecast')),
            React.createElement(Sparkline,{key:s.id,data:s.forecast,tone:s.tone})),
          React.createElement('div',{className:'moira-read'},
            React.createElement('div',{className:'moira-risk'},
              React.createElement('div',{className:'moira-risk-ring',style:{'--tone':s.tone,'--pct':s.risk}},
                React.createElement('span',{className:'moira-risk-n stat-num'},s.risk,React.createElement('small',null,'%')),
                React.createElement('span',{className:'moira-risk-l'},'transition risk')),
            ),
            React.createElement('div',{className:'moira-verdict'},
              React.createElement('div',{className:'moira-verdict-t'},React.createElement(Star,{size:12}),'MOIRA reads'),
              React.createElement('p',{key:s.id,className:'moira-verdict-p'},s.verdict),
              React.createElement('div',{className:'moira-signals'},
                s.signals.map((sig,i)=>React.createElement('span',{key:i,className:'moira-sig',style:{animationDelay:(i*0.08)+'s'}},
                  React.createElement('span',{className:'moira-sig-dot',style:{background:s.tone}}),sig))))
          )
        )
      )
    )
  );
}

/* ============================================================
   IMPACT STAT BAND — animated counters
   ============================================================ */
function StatBand(){
  const stats=[
    { n:9, suf:'', l:'Flagship platforms', d:'One integrated biological OS' },
    { n:265, suf:'+', l:'Diseases mapped', d:'Every system, live literature' },
    { n:12, suf:'M+', l:'Data points modeled', d:'Multi-omic + clinical signal' },
    { n:2060, suf:'', l:'Horizon', d:'Restorative medicine, engineered', raw:true },
  ];
  return React.createElement('section',{className:'section marble-deep veined statband',id:'impact-stats'},
    React.createElement('div',{className:'wrap'},
      React.createElement('div',{className:'statband-grid'},
        stats.map((s,i)=>React.createElement(Reveal,{key:i,className:'statband-item',variant:'r-scale',delay:i*90},
          React.createElement('div',{className:'statband-n gild'},
            s.raw?React.createElement('span',{className:'stat-num'},s.n):React.createElement(Counter,{to:s.n,suffix:s.suf}),
          ),
          React.createElement('div',{className:'statband-l'},s.l),
          React.createElement('div',{className:'statband-d'},s.d)))
      )
    )
  );
}

/* ============================================================
   TEAM STRIP
   ============================================================ */
const TEAM=[
  { name:'Dr. Elara Voss', role:'Founder & Chief Scientist', init:'EV', field:'Systems Biology' },
  { name:'Dr. Ronan Sethi', role:'Head of Computational Biology', init:'RS', field:'Multi-omics AI' },
  { name:'Dr. Mira Okonkwo', role:'Director, Therapeutic Design', init:'MO', field:'Drug Discovery' },
  { name:'Dr. Kai Lindqvist', role:'Principal ML Researcher', init:'KL', field:'Foundation Models' },
];
function Team(){
  return React.createElement('section',{className:'section marble veined grain team',id:'team'},
    React.createElement('div',{className:'wrap'},
      React.createElement('div',{className:'eyebrow-row'},React.createElement(Reveal,{as:'span',className:'kicker center greek'},'The People')),
      React.createElement(Reveal,{as:'h2',className:'display h-lg center greek',delay:80,style:{marginTop:'18px'}},
        'Minds behind ',React.createElement('span',{className:'gild italic'},'the machine.')),
      React.createElement('div',{className:'team-grid'},
        TEAM.map((m,i)=>React.createElement(Reveal,{key:m.name,className:'team-card card-marble',delay:80+i*90},
          React.createElement('div',{className:'team-portrait'},
            React.createElement('span',{className:'team-init'},m.init),
            React.createElement('span',{className:'team-ring'})),
          React.createElement('div',{className:'team-name'},m.name),
          React.createElement('div',{className:'team-role'},m.role),
          React.createElement('div',{className:'team-field'},React.createElement(Star,{size:9}),m.field)))
      )
    )
  );
}

/* ============================================================
   PUBLICATIONS / PRESS WALL
   ============================================================ */
const PUBS=[
  { tag:'Nature Biotechnology', t:'Closed-loop RNA discovery accelerates target identification', yr:'2026', icon:'dna2', url:'https://www.nature.com/nbt/' },
  { tag:'Cell', t:'A foundation model for cellular state transitions', yr:'2026', icon:'cell', url:'https://www.cell.com/' },
  { tag:'Science', t:'Predicting disease before symptom onset with multi-omic AI', yr:'2025', icon:'pulse', url:'https://www.science.org/' },
  { tag:'NEJM AI', t:'Precision intervention design in a clinical cohort', yr:'2025', icon:'scope', url:'https://ai.nejm.org/' },
];
function Publications(){
  return React.createElement('section',{className:'section marble-deep veined pubs',id:'publications'},
    React.createElement('div',{className:'wrap'},
      React.createElement('div',{className:'pubs-head'},
        React.createElement('div',null,
          React.createElement(Reveal,{as:'span',className:'kicker greek'},'Publications & Press'),
          React.createElement(Reveal,{as:'h2',className:'display h-lg greek',delay:80,style:{marginTop:'16px',maxWidth:'14ch'}},
            'Read the ',React.createElement('span',{className:'gild italic'},'science.'))),
        React.createElement(Reveal,{as:'p',className:'body',delay:140,style:{maxWidth:'360px'}},
          'Peer-reviewed work and coverage from across the research frontier. Explore the fields our platforms build on.')),
      React.createElement('div',{className:'pubs-list'},
        PUBS.map((p,i)=>React.createElement(Reveal,{key:i,className:'pub-row',delay:60+i*70,as:'a',
          href:p.url,target:'_blank',rel:'noopener noreferrer'},
          React.createElement('span',{className:'pub-ic'},React.createElement(Glyph,{name:p.icon,width:22,height:22})),
          React.createElement('span',{className:'pub-main'},
            React.createElement('span',{className:'pub-tag'},p.tag),
            React.createElement('span',{className:'pub-t'},p.t)),
          React.createElement('span',{className:'pub-yr stat-num'},p.yr),
          React.createElement('span',{className:'pub-arr'},React.createElement(Glyph,{name:'arrow',width:16,height:16}))))
      )
    )
  );
}

/* ============================================================
   TESTIMONIAL / PARTNER MARQUEE
   ============================================================ */
const PARTNERS=['STANFORD MEDICINE','BROAD INSTITUTE','MAX PLANCK','ETH Z\u00dcRICH','MIT CSAIL','KAROLINSKA','EMBL','JOHNS HOPKINS'];
const QUOTES=[
  { q:'The first platform that treats biology as a system you can forecast, not just observe.', a:'Principal Investigator, Genomics' },
  { q:'MOIRA changed how we think about intervention timing in our cohort studies.', a:'Director, Translational Medicine' },
  { q:'AetherCore\u2019s stack collapsed months of analysis into an afternoon.', a:'Head of Computational Biology' },
];
function Marquee(){
  return React.createElement('section',{className:'section marble veined grain marquee-sec',id:'trust'},
    React.createElement('div',{className:'wrap'},
      React.createElement('div',{className:'eyebrow-row'},React.createElement(Reveal,{as:'span',className:'kicker center greek'},'Trusted Across the Frontier'))),
    React.createElement('div',{className:'marquee'},
      React.createElement('div',{className:'marquee-track'},
        PARTNERS.concat(PARTNERS).map((p,i)=>React.createElement('span',{key:i,className:'marquee-item'},
          React.createElement(Star,{size:11}),p)))),
    React.createElement('div',{className:'wrap'},
      React.createElement('div',{className:'quotes-grid'},
        QUOTES.map((qt,i)=>React.createElement(Reveal,{key:i,className:'quote-card glass',delay:i*100},
          React.createElement('div',{className:'quote-mark'},'\u201C'),
          React.createElement('p',{className:'quote-q'},qt.q),
          React.createElement('div',{className:'quote-a'},React.createElement(Star,{size:9}),qt.a))))
    )
  );
}

Object.assign(window,{ MoiraDemo, StatBand, Team, Publications, Marquee });
