/* ═══════════════════════════════════════════════════════════════
   HYPEREALM · MOBILE — iPhone portrait (390px canvas)
   Same ink-blot aesthetic as desktop, rechoreographed for vertical.
═══════════════════════════════════════════════════════════════ */
const { useRef, useEffect, useState, useMemo } = React;
const { motion, useScroll, useTransform, useSpring, useInView, AnimatePresence } = window.Motion || window.FramerMotion;

const SERIF="'Fraunces',serif";
const SANS ="'Inter Tight',sans-serif";
const MONO ="'JetBrains Mono',ui-monospace,monospace";

const P = {
  ink:'#0a0a10', coal:'#14141c', deepest:'#050508',
  teal:'#4a6a7a', tealDeep:'#2a4050',
  violet:'#504060', violetDeep:'#302038',
  coral:'#c87858', coralDeep:'#8c4838',
  paper:'#ebe8e0',
  paperMute:'rgba(235,232,224,0.58)',
  paperFaint:'rgba(235,232,224,0.3)',
};

/* ═══ INK BLOT ═══ organic smoke-blot */
function InkBlot({ color=P.teal, size=480, opacity=0.85, filter='inkSmoke', blur=14 }) {
  return (
    <div style={{
      position:'absolute', width:size, height:size, pointerEvents:'none',
      filter:`url(#${filter}) blur(${blur}px)`, opacity,
    }}>
      <div style={{width:'100%',height:'100%',
        background:`radial-gradient(circle at 50% 50%, ${color} 0%, ${color}dd 28%, ${color}77 52%, ${color}22 72%, transparent 88%)`,
        borderRadius:'50%'}}/>
    </div>
  );
}

function DriftingInk({ color, size=420, x=0, y=0, opacity=0.75, driftX=30, driftY=20, duration=16, filter='inkSmoke' }) {
  return (
    <motion.div
      style={{position:'absolute', left:x, top:y, translateX:'-50%', translateY:'-50%', pointerEvents:'none'}}
      animate={{ x:[0, driftX, -driftX*0.6, 0], y:[0, -driftY, driftY*0.4, 0], scale:[1, 1.1, 0.95, 1] }}
      transition={{ duration, repeat:Infinity, ease:'easeInOut' }}
    >
      <InkBlot color={color} size={size} opacity={opacity} filter={filter}/>
    </motion.div>
  );
}

function Grain({opacity=0.08}){
  return <div style={{position:'absolute',inset:0,pointerEvents:'none',opacity,mixBlendMode:'overlay',zIndex:50,
    backgroundImage:`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>")`}}/>;
}

function Vignette(){
  return <div style={{position:'absolute',inset:0,pointerEvents:'none',zIndex:40,
    background:'radial-gradient(ellipse 80% 60% at 50% 50%, transparent 35%, rgba(5,5,8,0.75) 100%)'}}/>;
}

/* ═══ MOBILE CHROME — top bar + sheet nav ═══ */
function Chrome(){
  const [scrolled, setScrolled] = useState(false);
  const [menuOpen, setMenuOpen] = useState(false);
  useEffect(() => {
    const h = () => setScrolled(window.scrollY > 40);
    window.addEventListener('scroll', h);
    return () => window.removeEventListener('scroll', h);
  }, []);
  useEffect(() => {
    document.body.style.overflow = menuOpen ? 'hidden' : '';
  }, [menuOpen]);
  const go = (id) => { document.getElementById(id)?.scrollIntoView({behavior:'smooth'}); setMenuOpen(false); };

  return (
    <>
      {/* top bar */}
      <div style={{position:'fixed',top:0,left:0,right:0,height:52,display:'flex',alignItems:'center',justifyContent:'space-between',padding:'0 20px',zIndex:200,
        background: scrolled || menuOpen ? 'rgba(10,10,16,0.82)' : 'transparent',
        backdropFilter: scrolled || menuOpen ? 'blur(20px) saturate(1.4)' : 'none',
        borderBottom: scrolled && !menuOpen ? '1px solid rgba(235,232,224,0.06)' : '1px solid transparent',
        transition:'background 0.35s, border-color 0.35s'}}>
        <span style={{fontFamily:SANS,fontSize:10,fontWeight:400,letterSpacing:'0.38em',textTransform:'uppercase',color:P.paper}}>HYPEREALM</span>
        <button onClick={()=>setMenuOpen(v=>!v)} aria-label="Menu" style={{background:'none',border:'none',padding:8,margin:-8,cursor:'pointer',display:'flex',flexDirection:'column',gap:4,width:32,height:32,alignItems:'flex-end',justifyContent:'center'}}>
          <span style={{width:menuOpen?18:18,height:1,background:P.paper,transition:'transform 0.3s',transform:menuOpen?'translateY(2.5px) rotate(45deg)':'none',transformOrigin:'center'}}/>
          <span style={{width:menuOpen?18:12,height:1,background:P.paper,transition:'transform 0.3s, width 0.3s',transform:menuOpen?'translateY(-2.5px) rotate(-45deg)':'none',transformOrigin:'center'}}/>
        </button>
      </div>

      {/* sheet nav */}
      <AnimatePresence>
        {menuOpen && (
          <motion.div
            initial={{opacity:0}} animate={{opacity:1}} exit={{opacity:0}}
            transition={{duration:0.4, ease:[0.16,1,0.3,1]}}
            style={{position:'fixed',inset:0,zIndex:199,background:'rgba(5,5,8,0.96)',backdropFilter:'blur(30px)',display:'flex',flexDirection:'column',paddingTop:52}}>
            <DriftingInk color={P.teal} size={500} x="50%" y="40%" opacity={0.35} driftX={40} driftY={30} duration={20}/>
            <DriftingInk color={P.coralDeep} size={380} x="30%" y="80%" opacity={0.3} driftX={30} driftY={20} duration={24}/>
            <Grain opacity={0.05}/>
            <div style={{position:'relative',zIndex:5,flex:1,display:'flex',flexDirection:'column',justifyContent:'center',padding:'0 32px',gap:6}}>
              {[['Problem','manifesto'],['What we build','venues'],['Why Us','why-us'],['Subscribe','waitlist']].map(([l,id],i)=>(
                <motion.div key={id}
                  initial={{opacity:0,x:-20}} animate={{opacity:1,x:0}}
                  transition={{duration:0.5, delay:0.1+i*0.06, ease:[0.16,1,0.3,1]}}
                  onClick={()=>go(id)}
                  style={{fontFamily:SANS,fontWeight:200,fontSize:38,letterSpacing:'-0.02em',color:P.paper,padding:'14px 0',borderBottom:'1px solid rgba(235,232,224,0.08)',cursor:'pointer'}}>
                  {l}
                </motion.div>
              ))}
            </div>
            <div style={{padding:'0 32px 48px',fontFamily:MONO,fontSize:9,letterSpacing:'0.28em',textTransform:'uppercase',color:P.paperFaint,display:'flex',justifyContent:'space-between'}}>
              <span>MMXXVI</span>
              <span>Opening 2027</span>
            </div>
          </motion.div>
        )}
      </AnimatePresence>

      {/* bottom status rail */}
      <div style={{position:'fixed',bottom:0,left:0,right:0,height:26,display:'flex',alignItems:'center',justifyContent:'space-between',padding:'0 16px',borderTop:'1px solid rgba(235,232,224,0.06)',background:'rgba(10,10,16,0.78)',backdropFilter:'blur(12px)',zIndex:95,fontFamily:MONO,fontSize:8,letterSpacing:'0.24em',textTransform:'uppercase',color:P.paperFaint}}>
        <span>Hyperealm</span>
        <span>Built and run by operators</span>
        <span>In stealth · 2027</span>
      </div>
    </>
  );
}

function ScrollBar() {
  const { scrollYProgress } = useScroll();
  const scaleX = useSpring(scrollYProgress, { stiffness:100, damping:30 });
  return <motion.div style={{position:'fixed',top:0,left:0,right:0,height:1.5,background:'linear-gradient(90deg, #4a6a7a, #ebe8e0, #c87858)',transformOrigin:'0%',scaleX,zIndex:201}}/>;
}

/* ═══ OPENING HERO — vertical, full-viewport ═══ */
function OpeningHero() {
  const ref = useRef(null);
  const { scrollYProgress } = useScroll({ target: ref, offset: ['start start', 'end start'] });
  const titleOpacity = useTransform(scrollYProgress, [0, 0.7], [1, 0]);
  const titleY = useTransform(scrollYProgress, [0, 1], ['0%', '-20%']);
  const blotScale = useTransform(scrollYProgress, [0, 1], [1, 1.3]);
  return (
    <section ref={ref} style={{position:'relative',minHeight:'100vh',background:P.deepest,overflow:'hidden',display:'flex',alignItems:'center',justifyContent:'center'}}>
      <video autoPlay muted loop playsInline webkit-playsinline="true" x5-playsinline="true" preload="auto" controls={false} disablePictureInPicture disableRemotePlayback style={{position:'absolute',inset:0,width:'100%',height:'100%',objectFit:'cover',objectPosition:'center center',opacity:0.6,zIndex:0,filter:'saturate(0.8) contrast(1.02)',pointerEvents:'none'}}>
        <source src="/hero-venue-bg-mobile.mp4" type="video/mp4"/>
      </video>
      <div style={{position:'absolute',inset:0,background:'radial-gradient(ellipse 90% 80% at 50% 50%, rgba(10,10,16,0.25) 0%, rgba(5,5,8,0.7) 100%)',zIndex:1}}/>
      <motion.div style={{position:'absolute',left:'50%',top:'50%',scale:blotScale,zIndex:2}}>
        <DriftingInk color={P.teal} size={520} x={0} y={0} opacity={0.6} driftX={40} driftY={30} duration={22}/>
        <DriftingInk color={P.violetDeep} size={420} x={-60} y={-40} opacity={0.55} driftX={50} driftY={35} duration={26}/>
        <DriftingInk color={P.coralDeep} size={260} x={70} y={60} opacity={0.5} driftX={30} driftY={20} duration={18} filter="inkSmokeMild"/>
      </motion.div>
      <Vignette/>
      <Grain opacity={0.09}/>

      <motion.div style={{position:'relative',zIndex:10,textAlign:'center',padding:'0 24px',y:titleY,opacity:titleOpacity, width:'100%'}}>
        <motion.h1
          initial={{opacity:0, y:20, filter:'blur(10px)'}}
          animate={{opacity:1, y:0, filter:'blur(0px)'}}
          transition={{duration:2.2, ease:[0.16,1,0.3,1], delay:0.5}}
          className="gradient-text"
          style={{
            fontFamily:SANS, fontWeight:200,
            fontSize:'clamp(40px,11vw,64px)',
            lineHeight:0.94, letterSpacing:'0.12em',
            textTransform:'uppercase', margin:0,
          }}>
          HYPEREALM
        </motion.h1>

        <motion.div
          initial={{opacity:0, y:16}}
          animate={{opacity:1, y:0}}
          transition={{duration:1.6, ease:[0.16,1,0.3,1], delay:1.4}}
          style={{marginTop:40,fontFamily:SANS,fontWeight:300,fontSize:19,lineHeight:1.38,letterSpacing:'-0.012em',color:P.paperMute,padding:'0 8px'}}>
          The AI operating layer for <span style={{fontFamily:SERIF,fontStyle:'italic',fontWeight:300,color:P.paper}}>physical-experience venues</span>.
        </motion.div>

        <motion.div
          initial={{opacity:0}}
          animate={{opacity:1}}
          transition={{duration:1.2, delay:2.2}}
          style={{marginTop:64, fontFamily:MONO,fontSize:9,letterSpacing:'0.38em',textTransform:'uppercase',color:P.paperFaint}}>
          ↓
        </motion.div>
      </motion.div>
    </section>
  );
}

/* ═══ GIANT WORD ═══ */
function DisplayWord({ children, size='clamp(54px,14vw,96px)', variant='teal', tracking='0.08em', weight=200 }) {
  const ref = useRef(null);
  const inView = useInView(ref, { once:true, margin:'-15% 0px' });
  const cls = variant==='teal' ? 'gradient-text-teal' : variant==='coral' ? 'gradient-text-coral' : 'gradient-text';
  return (
    <h2 ref={ref} className={cls} style={{
      fontFamily:SANS, fontWeight:weight,
      fontSize:size, lineHeight:0.92, letterSpacing:tracking,
      textTransform:'uppercase', margin:0, textAlign:'center',
      opacity: inView ? 1 : 0,
      transform: inView ? 'translateY(0) scale(1)' : 'translateY(30px) scale(0.98)',
      transition:'opacity 1.6s cubic-bezier(0.19,1,0.22,1), transform 1.6s cubic-bezier(0.19,1,0.22,1)',
      filter:'url(#inkSmokeSoft)',
    }}>{children}</h2>
  );
}

/* ═══ WORD BAND — single giant word ═══ */
function WordBand({ id, word, sub, eyebrow, blotColor=P.teal, blotColor2=P.violet, variant='teal', size }) {
  const ref = useRef(null);
  const { scrollYProgress } = useScroll({ target: ref, offset: ['start end', 'end start'] });
  const wordOpacity = useTransform(scrollYProgress, [0.1, 0.35, 0.7, 0.95], [0, 1, 1, 0.25]);
  const wordY = useTransform(scrollYProgress, [0.1, 0.5], ['4%','0%']);
  const blotScale = useTransform(scrollYProgress, [0, 0.5, 1], [0.8, 1.1, 0.9]);
  return (
    <section id={id} ref={ref} style={{position:'relative',minHeight:'90vh',background:P.deepest,overflow:'hidden',display:'flex',alignItems:'center',justifyContent:'center'}}>
      <motion.div style={{position:'absolute',left:'50%',top:'50%',scale:blotScale}}>
        <DriftingInk color={blotColor} size={460} x={0} y={0} opacity={0.6} driftX={35} driftY={25} duration={22}/>
        <DriftingInk color={blotColor2} size={340} x={50} y={-40} opacity={0.45} driftX={40} driftY={30} duration={26}/>
      </motion.div>
      <Vignette/>
      <Grain opacity={0.08}/>
      <motion.div style={{position:'relative',zIndex:10,textAlign:'center',padding:'0 24px',y:wordY,opacity:wordOpacity,width:'100%'}}>
        {eyebrow && (
          <div style={{fontFamily:MONO,fontSize:9.5,letterSpacing:'0.38em',textTransform:'uppercase',color:P.paperMute,marginBottom:32}}>
            {eyebrow}
          </div>
        )}
        <DisplayWord variant={variant} size={size || "clamp(54px,14vw,96px)"} tracking="0.08em">
          {word}
        </DisplayWord>
        {sub && (
          <motion.div
            initial={{opacity:0,y:16}}
            whileInView={{opacity:1,y:0}}
            viewport={{once:true,margin:'-15%'}}
            transition={{duration:1.4, ease:[0.16,1,0.3,1], delay:0.5}}
            style={{marginTop:32,fontFamily:SERIF,fontStyle:'italic',fontWeight:300,fontSize:19,lineHeight:1.4,letterSpacing:'-0.015em',color:P.paperMute,padding:'0 16px'}}>
            {sub}
          </motion.div>
        )}
      </motion.div>
    </section>
  );
}

/* ═══ CASCADE STATEMENT — vertical, reveal line-by-line ═══ */
function CascadeStatement({ eyebrow, lines, blotColor=P.teal, blotColor2=P.violet }) {
  const ref = useRef(null);
  const { scrollYProgress } = useScroll({ target: ref, offset: ['start end', 'end start'] });
  const blotScale = useTransform(scrollYProgress, [0, 0.5, 1], [0.85, 1.15, 0.95]);
  return (
    <section ref={ref} style={{position:'relative',minHeight:'auto',background:P.deepest,overflow:'hidden',display:'flex',alignItems:'center',padding:'140px 24px 80px'}}>
      <motion.div style={{position:'absolute',right:'-10%',top:'40%',scale:blotScale}}>
        <DriftingInk color={blotColor} size={500} x={0} y={0} opacity={0.5} driftX={40} driftY={30} duration={26}/>
        <DriftingInk color={blotColor2} size={320} x={-40} y={60} opacity={0.4} driftX={30} driftY={20} duration={22}/>
      </motion.div>
      <Grain opacity={0.08}/>
      <Vignette/>
      <div style={{position:'relative',zIndex:10,width:'100%'}}>
        {eyebrow && (
          <div style={{fontFamily:MONO,fontSize:9.5,letterSpacing:'0.38em',textTransform:'uppercase',color:P.paperFaint,marginBottom:56}}>
            {eyebrow}
          </div>
        )}
        <div style={{display:'flex',flexDirection:'column',gap:14}}>
          {lines.map((L,i) => (
            <motion.div key={i}
              initial={{opacity:0, y:18, filter:'blur(10px)'}}
              whileInView={{opacity:1, y:0, filter:'blur(0px)'}}
              viewport={{once:true, margin:'-10%'}}
              transition={{duration:1.6, delay:i*0.18, ease:[0.19,1,0.22,1]}}
              style={{
                fontFamily:SANS, fontWeight:200,
                fontSize:'clamp(36px,10vw,56px)',
                lineHeight:0.98, letterSpacing:'0.06em',
                textTransform:'uppercase',
                paddingLeft: L.indent ? `${L.indent*0.6}vw` : 0,
                color: L.muted ? P.paperFaint : P.paper,
                fontStyle: L.italic ? 'italic' : 'normal',
              }}
              className={L.gradient ? 'gradient-text-teal' : ''}>
              {L.text}
            </motion.div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ═══ MANIFESTO — headline + 3 paragraphs, stacked ═══ */
function Manifesto() {
  const ref = useRef(null);
  const { scrollYProgress } = useScroll({ target: ref, offset: ['start 80%', 'end 40%'] });
  const headline = "The experience economy is running on legacy software.";
  const words = headline.split(' ');
  const paragraphs = [
    { text:"Arcades, immersive rooms, escape venues, family entertainment centers: the places people go to feel something together. The software that runs them was built for taking bookings, not for operating a business.", emphasized:false },
    { text:"A single venue runs on a dozen systems that don't talk to each other. Bookings in one tool, payments in another, scheduling in a spreadsheet, equipment logs on paper. Money leaks in the seams, and the manager spends the night reconciling instead of running the floor.", emphasized:false },
    { text:"Generic AI helps, but it has never run a room at 7pm on a Friday. It doesn't know the unit economics of a venue or how guests behave inside one. That knowledge is not in a model anyone can rent. It is earned on the floor.", emphasized:false },
    { text:"So we run the venues ourselves and build the software inside them. Every tool is proven against a real P&L before it goes anywhere else.", emphasized:false },
  ];
  return (
    <section id="manifesto" ref={ref} style={{position:'relative',background:P.ink,padding:'140px 24px 140px',borderTop:'1px solid rgba(235,232,224,0.05)',borderBottom:'1px solid rgba(235,232,224,0.05)',overflow:'hidden'}}>
      <DriftingInk color={P.violetDeep} size={420} x="75%" y="20%" opacity={0.32} driftX={40} driftY={30} duration={24}/>
      <Grain opacity={0.06}/>
      <div style={{position:'relative',zIndex:2}}>
        <div style={{fontFamily:MONO,fontSize:9.5,letterSpacing:'0.38em',textTransform:'uppercase',color:P.paperFaint,marginBottom:56}}>
          The Problem
        </div>
        <p style={{fontFamily:SERIF,fontWeight:300,fontSize:'clamp(30px,8.5vw,44px)',lineHeight:1.1,letterSpacing:'-0.02em',margin:0,color:P.paper,textWrap:'balance'}}>
          {words.map((w, i) => {
            const s = (i/words.length)*0.6;
            const e = ((i+1)/words.length)*0.6;
            const op = useTransform(scrollYProgress, [s,e], [0.16, 1]);
            return <motion.span key={i} style={{opacity:op, marginRight:'0.26em', display:'inline-block'}}>{w}</motion.span>;
          })}
        </p>
        <div style={{marginTop:72,display:'flex',flexDirection:'column',gap:28}}>
          {paragraphs.map((p,i) => (
            <motion.p key={i}
              initial={{opacity:0,y:20}}
              whileInView={{opacity:1,y:0}}
              viewport={{once:true,margin:'-6%'}}
              transition={{duration:1, ease:[0.16,1,0.3,1], delay:i*0.08}}
              style={{
                fontFamily: p.emphasized ? SERIF : "'Source Serif 4',serif",
                fontStyle: p.emphasized ? 'italic' : 'normal',
                fontSize: p.emphasized ? 'clamp(22px,6.5vw,30px)' : 17,
                lineHeight: p.emphasized ? 1.25 : 1.72,
                color: p.emphasized ? P.paper : P.paperMute,
                margin:0,
                fontWeight: p.emphasized ? 300 : 400,
                letterSpacing: p.emphasized ? '-0.018em' : 0,
                marginTop: p.emphasized ? 12 : 0,
              }}>
              {p.text}
            </motion.p>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ═══ PILLARS — stacked cards, one per viewport ═══ */
const pillarsData = [
  { n:'01', id:'venues', title:'Owned', sub:'Operator · Built',
    lead:'We hold the franchise, sign the lease, and run the floor.',
    body:"The software ships to a venue we own and operate before it reaches anyone else. Because we run the room, we own the operational truth it generates — how it really runs, what breaks, when demand spikes. That record compounds with every venue we open, and no vendor selling to rooms they don't own can buy it.",
    blot:P.teal, blotDeep:P.tealDeep, accent:P.teal },
  { n:'02', id:'intelligence', title:'System', sub:'AI-Native · OS',
    lead:'Booking, payments, labor, equipment, and demand in one operating layer.',
    body:"Instead of a dozen disconnected apps, one operator supervises the room while the AI does the work underneath: it watches, it proposes, a person approves, it acts. Fewer people run the venue and more guests fill it.",
    blot:P.violet, blotDeep:P.violetDeep, accent:P.violet },
  { n:'03', id:'expansion', title:'Portfolio', sub:'Built to · Travel',
    lead:'Proven on our own venues, then the ones we open next.',
    body:"What works in the first room becomes the day-one setup for the second and third. Built to run a portfolio across markets, not a single demo.",
    blot:P.coral, blotDeep:P.coralDeep, accent:P.coral },
];

function Pillars() {
  return (
    <section style={{position:'relative',background:P.ink,padding:'120px 24px 80px',borderBottom:'1px solid rgba(235,232,224,0.05)'}}>
      <div style={{fontFamily:MONO,fontSize:9.5,letterSpacing:'0.38em',textTransform:'uppercase',color:P.paperFaint,marginBottom:20}}>
        Our Approach
      </div>
      <h2 style={{fontFamily:SANS,fontWeight:200,fontSize:'clamp(34px,9vw,52px)',lineHeight:1.04,letterSpacing:'-0.025em',margin:'0 0 72px',color:P.paper,textWrap:'balance'}}>
        How it<br/><span style={{fontFamily:SERIF,fontStyle:'italic',fontWeight:300}}>works.</span>
      </h2>
      {pillarsData.map((p,i) => <Pillar key={i} p={p} i={i}/>)}
    </section>
  );
}

function Pillar({ p, i }) {
  const ref = useRef(null);
  const { scrollYProgress } = useScroll({ target: ref, offset: ['start end', 'end start'] });
  const blotScale = useTransform(scrollYProgress, [0, 0.5, 1], [0.85, 1.05, 0.9]);
  return (
    <motion.div ref={ref} id={p.id}
      initial={{opacity:0, y:40}}
      whileInView={{opacity:1, y:0}}
      viewport={{once:true, margin:'-8%'}}
      transition={{duration:1, ease:[0.16,1,0.3,1]}}
      style={{position:'relative', padding:'72px 0 72px', borderTop:'1px solid rgba(235,232,224,0.08)'}}>
      {/* blot behind the title */}
      <motion.div style={{position:'absolute',right:-60,top:30,scale:blotScale,opacity:0.7,pointerEvents:'none'}}>
        <DriftingInk color={p.blot} size={280} x={0} y={0} opacity={0.6} driftX={30} driftY={20} duration={18}/>
        <DriftingInk color={p.blotDeep} size={180} x={40} y={-30} opacity={0.5} driftX={20} driftY={15} duration={14}/>
      </motion.div>
      <div style={{position:'relative',zIndex:2}}>
        <div style={{display:'flex',alignItems:'baseline',gap:16,marginBottom:24}}>
          <div style={{fontFamily:SERIF,fontStyle:'italic',fontWeight:300,fontSize:52,lineHeight:1,color:p.accent,filter:'url(#inkSmokeSoft)'}}>
            {p.n}
          </div>
          <div style={{fontFamily:MONO,fontSize:9,letterSpacing:'0.28em',textTransform:'uppercase',color:P.paperFaint}}>
            {p.sub}
          </div>
        </div>
        <h3 className="gradient-text-teal" style={{fontFamily:SANS,fontWeight:200,fontSize:'clamp(52px,15vw,84px)',letterSpacing:'0.06em',lineHeight:0.96,margin:'0 0 32px',textTransform:'uppercase'}}>
          {p.title}
        </h3>
        <p style={{fontFamily:SERIF,fontStyle:'italic',fontWeight:300,fontSize:22,lineHeight:1.32,color:P.paper,margin:'0 0 20px',letterSpacing:'-0.015em'}}>
          {p.lead}
        </p>
        <p style={{fontFamily:"'Source Serif 4',serif",fontSize:17,lineHeight:1.72,color:P.paperMute,margin:0,fontWeight:400}}>
          {p.body}
        </p>
      </div>
    </motion.div>
  );
}

/* ═══ WHY US ═══ — anonymous founding team intersection flex */
function ThirdSpace() {
  const ref = useRef(null);
  const { scrollYProgress } = useScroll({ target: ref, offset: ['start end', 'end start'] });
  const blotY = useTransform(scrollYProgress, [0,1], ['-25%','25%']);
  const blotOp = useTransform(scrollYProgress, [0,0.4,0.8,1], [0.2,0.65,0.55,0.2]);
  return (
    <section id="why-us" ref={ref} style={{position:'relative',background:P.ink,padding:'140px 24px',borderBottom:'1px solid rgba(235,232,224,0.05)',overflow:'hidden'}}>
      <motion.div style={{position:'absolute', right:'-20%', top:'25%', y:blotY, opacity:blotOp}}>
        <DriftingInk color={P.teal} size={520} x={0} y={0} opacity={1} driftX={40} driftY={30} duration={28}/>
      </motion.div>
      <Grain opacity={0.06}/>
      <div style={{position:'relative',zIndex:2}}>
        <div style={{fontFamily:MONO,fontSize:9.5,letterSpacing:'0.38em',textTransform:'uppercase',color:P.paperFaint,marginBottom:48}}>
          Why Us
        </div>
        <h2 style={{fontFamily:SANS,fontWeight:200,fontSize:'clamp(34px,9vw,52px)',lineHeight:1.04,letterSpacing:'-0.025em',margin:'0 0 64px',color:P.paper,textWrap:'balance'}}>
          Why this<br/><span style={{fontFamily:SERIF,fontStyle:'italic',fontWeight:300,color:P.paper}}>team.</span>
        </h2>
        <div style={{display:'flex',flexDirection:'column',gap:28}}>
          {[
            "Founder background: ex-FAANG engineering, a multi-unit franchise operator, native across US and Asian markets, and a builder raised inside this generation's culture.",
            "A decade building at FAANG scale, a franchise held and operated first-hand, and software written from inside the business instead of studied from outside it.",
          ].map((t,i) => (
            <motion.p key={i}
              initial={{opacity:0, y:20}}
              whileInView={{opacity:1, y:0}}
              viewport={{once:true, margin:'-6%'}}
              transition={{duration:1, delay:i*0.09, ease:[0.16,1,0.3,1]}}
              style={{fontFamily:"'Source Serif 4',serif",fontSize:17,lineHeight:1.74,color:P.paperMute,margin:0,fontWeight:400}}>
              {t}
            </motion.p>
          ))}
          <motion.p
            initial={{opacity:0, y:20}}
            whileInView={{opacity:1, y:0}}
            viewport={{once:true, margin:'-6%'}}
            transition={{duration:1, delay:0.3, ease:[0.16,1,0.3,1]}}
            style={{fontFamily:"'Source Serif 4',serif",fontSize:17,lineHeight:1.74,color:P.paperMute,margin:'16px 0 0',fontWeight:400}}>
            If you're building or investing in this space, <a href="mailto:contact@hyperealm.co" style={{color:P.paper,textDecoration:'none',borderBottom:`1px solid ${P.paperFaint}`,paddingBottom:1}}>contact@hyperealm.co</a>
          </motion.p>
        </div>
      </div>
    </section>
  );
}

/* ═══ 2027 YEAR REVEAL ═══ */
function YearReveal() {
  const ref = useRef(null);
  const { scrollYProgress } = useScroll({ target: ref, offset: ['start end', 'end start'] });
  const blotX = useTransform(scrollYProgress, [0,1], ['-15%','15%']);
  const blotScale = useTransform(scrollYProgress, [0,0.5,1], [0.7, 1.2, 0.9]);
  return (
    <section ref={ref} style={{position:'relative',minHeight:'90vh',background:P.deepest,overflow:'hidden',display:'flex',alignItems:'center',justifyContent:'center'}}>
      <motion.div style={{position:'absolute',left:'50%',top:'50%',x:blotX,scale:blotScale}}>
        <DriftingInk color={P.coralDeep} size={440} x={0} y={0} opacity={0.7} driftX={50} driftY={35} duration={22}/>
        <DriftingInk color={P.tealDeep} size={320} x={-70} y={40} opacity={0.55} driftX={40} driftY={30} duration={26}/>
      </motion.div>
      <Grain opacity={0.08}/>
      <Vignette/>
      <div style={{position:'relative',zIndex:10,textAlign:'center',width:'100%',padding:'0 16px'}}>
        <motion.div
          initial={{opacity:0}}
          whileInView={{opacity:0.6}}
          viewport={{once:true, margin:'-15%'}}
          transition={{duration:1.6, delay:0.2}}
          style={{fontFamily:MONO,fontSize:10,letterSpacing:'0.5em',textTransform:'uppercase',color:P.paper,marginBottom:32}}>
          What's Next
        </motion.div>
        <motion.h2
          initial={{opacity:0, y:30, filter:'blur(18px)'}}
          whileInView={{opacity:1, y:0, filter:'blur(0px)'}}
          viewport={{once:true, margin:'-15%'}}
          transition={{duration:2, ease:[0.19,1,0.22,1]}}
          className="gradient-text-coral"
          style={{fontFamily:SANS,fontWeight:200,fontSize:'clamp(120px,36vw,180px)',lineHeight:0.88,letterSpacing:0,margin:0,filter:'url(#inkSmokeSoft)'}}>
          2027
        </motion.h2>
        <motion.div
          initial={{opacity:0, y:10}}
          whileInView={{opacity:0.6, y:0}}
          viewport={{once:true, margin:'-15%'}}
          transition={{duration:1.4, ease:[0.16,1,0.3,1], delay:1.2}}
          style={{marginTop:24,fontFamily:SERIF,fontStyle:'italic',fontWeight:300,fontSize:18,letterSpacing:'-0.01em',color:P.paperMute}}>
          The first room.
        </motion.div>
      </div>
    </section>
  );
}

/* ═══ WAITLIST ═══ */
function Waitlist() {
  const [email, setEmail] = useState('');
  const [submitted, setSubmitted] = useState(false);
  const [sending, setSending] = useState(false);
  const [error, setError] = useState('');
  const onSubmit = async (e) => {
    e.preventDefault();
    if (!email || sending) return;
    setSending(true); setError('');
    try {
      const r = await fetch('/api/waitlist', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ email }),
      });
      if (r.ok) setSubmitted(true);
      else { const j = await r.json().catch(()=>({})); setError(j.error || 'Something went wrong'); }
    } catch { setError('Network error'); }
    finally { setSending(false); }
  };
  return (
    <section id="waitlist" style={{position:'relative',minHeight:'90vh',background:P.ink,padding:'120px 24px 100px',overflow:'hidden',display:'flex',alignItems:'center',justifyContent:'center'}}>
      <DriftingInk color={P.teal} size={420} x="25%" y="45%" opacity={0.4} driftX={40} driftY={30} duration={24}/>
      <DriftingInk color={P.coralDeep} size={380} x="75%" y="55%" opacity={0.4} driftX={50} driftY={35} duration={28}/>
      <Grain opacity={0.08}/>
      <Vignette/>
      <div style={{textAlign:'center',position:'relative',zIndex:5,width:'100%'}}>
        <div style={{fontFamily:MONO,fontSize:9.5,letterSpacing:'0.38em',textTransform:'uppercase',color:P.paperMute,marginBottom:36}}>
          Enter the list
        </div>
        <h3 style={{fontFamily:SANS,fontWeight:200,fontSize:'clamp(36px,10vw,54px)',lineHeight:1.0,letterSpacing:'-0.025em',margin:0,color:P.paper,textWrap:'balance'}}>
          Built in private.<br/>
          <span style={{fontFamily:SERIF,fontStyle:'italic',fontWeight:300,color:P.paper}}>The list sees it first.</span>
        </h3>
        <form onSubmit={onSubmit} style={{marginTop:64}}>
          <AnimatePresence mode="wait">
            {!submitted ? (
              <motion.div key="form" exit={{opacity:0,y:-10}} style={{display:'flex',flexDirection:'column',gap:12}}>
                <input value={email} onChange={e=>setEmail(e.target.value)} placeholder="you@domain.com" type="email" required disabled={sending}
                  style={{background:'rgba(235,232,224,0.04)',border:'1px solid rgba(235,232,224,0.22)',borderRadius:999,padding:'16px 22px',fontFamily:SANS,fontSize:15,color:P.paper,letterSpacing:'0.01em',width:'100%'}}/>
                <button type="submit" disabled={sending} style={{fontFamily:SANS,fontSize:11,letterSpacing:'0.22em',textTransform:'uppercase',color:P.ink,background:P.paper,padding:'16px 22px',borderRadius:999,fontWeight:500,border:'none',cursor:sending?'wait':'pointer',width:'100%',opacity:sending?0.6:1}}>{sending?'Sending…':'Request Access →'}</button>
              </motion.div>
            ) : (
              <motion.div key="done" initial={{opacity:0,y:10}} animate={{opacity:1,y:0}}
                style={{fontFamily:SERIF,fontStyle:'italic',fontWeight:300,fontSize:19,color:P.paper,letterSpacing:'-0.015em',lineHeight:1.4,padding:'0 16px'}}>
                You're on the list. We only write when there's something real to show.
              </motion.div>
            )}
          </AnimatePresence>
          {error && <div style={{marginTop:12,fontFamily:MONO,fontSize:10,color:P.coral,letterSpacing:'0.04em'}}>{error}</div>}
        </form>
        <div style={{marginTop:32,fontFamily:MONO,fontSize:9,letterSpacing:'0.26em',textTransform:'uppercase',color:P.paperFaint,lineHeight:1.8}}>
          Or write us directly<br/>
          <a href="mailto:contact@hyperealm.co" style={{color:P.paperMute,textDecoration:'none',borderBottom:`1px solid ${P.paperFaint}`,letterSpacing:'0.04em',textTransform:'none',fontSize:12}}>contact@hyperealm.co</a>
        </div>
      </div>
    </section>
  );
}

/* ═══ FOOTER ═══ */
function Footer() {
  return (
    <footer style={{background:P.deepest,padding:'56px 24px 56px',borderTop:'1px solid rgba(235,232,224,0.06)'}}>
      <div style={{fontFamily:SANS,fontWeight:400,fontSize:11,letterSpacing:'0.38em',textTransform:'uppercase',color:P.paper,marginBottom:20}}>
        HYPEREALM
      </div>
      <p style={{fontFamily:SANS,fontSize:14,lineHeight:1.68,color:P.paperMute,margin:0,fontWeight:300}}>
        The operating system for physical-experience venues. Built by operators. Proven on owned venues. In stealth.
      </p>
      <div style={{marginTop:32,fontFamily:SERIF,fontStyle:'italic',fontWeight:300,fontSize:16,color:P.paperFaint,letterSpacing:'-0.01em'}}>
        ⌘ 超域 · Hyperealm
      </div>

      <div style={{marginTop:48,display:'grid',gridTemplateColumns:'1fr 1fr',gap:32}}>
        {[
          { t:'Company',  l:[
            { x:'Problem', muted:false },
            { x:'What we build', muted:false },
            { x:'Why Us', muted:false },
          ]},
          { t:'Contact', l:[
            { x:'contact@hyperealm.co', muted:false },
            { x:'New York', muted:false },
          ]},
        ].map((c,i) => (
          <div key={i}>
            <div style={{fontFamily:MONO,fontSize:9,letterSpacing:'0.28em',textTransform:'uppercase',color:P.paperFaint,marginBottom:14}}>{c.t}</div>
            <div style={{display:'flex',flexDirection:'column',gap:9}}>
              {c.l.map(item => (
                <span key={item.x} style={{
                  fontFamily:SANS, fontSize:12.5, fontWeight:300,
                  color: item.muted ? 'rgba(235,232,224,0.22)' : P.paperMute,
                }}>{item.x}</span>
              ))}
            </div>
          </div>
        ))}
      </div>

      <div style={{marginTop:48,paddingTop:24,borderTop:'1px solid rgba(235,232,224,0.06)',display:'flex',flexDirection:'column',gap:8,fontFamily:MONO,fontSize:8.5,letterSpacing:'0.26em',textTransform:'uppercase',color:P.paperFaint}}>
        <span>© 2026 Hyperealm, Inc.</span>
        <span>Hypermode Holdings</span>
      </div>
    </footer>
  );
}

/* ═══ MAIN ═══ */
function App() {
  return (
    <>
      <ScrollBar/>
      <Chrome/>
      <OpeningHero/>

      <CascadeStatement
        eyebrow="Thesis"
        lines={[
          { text:'Built by' },
          { text:'operators.', indent:5, italic:true },
          { text:'AI-native', indent:2 },
          { text:'layer', indent:4 },
          { text:'at scale.', indent:8, italic:true },
        ]}
        blotColor={P.teal} blotColor2={P.violetDeep}
      />

      <Manifesto/>

      <CascadeStatement
        eyebrow="Why now"
        lines={[
          { text:'As AI makes' },
          { text:'the screen', indent:3, italic:true },
          { text:'infinite,', indent:6, italic:true },
          { text:'the room', indent:2 },
          { text:'becomes scarce.', indent:7, italic:true },
        ]}
        blotColor={P.coral} blotColor2={P.tealDeep}
      />

      <Pillars/>

      <ThirdSpace/>

      <YearReveal/>

      <Waitlist/>

      <Footer/>
    </>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<App/>);
