/* global React */
const { useEffect: vrE, useRef: vrR, useState: vrS } = React;

/* ── VR Live ─────────────────────────────────────────── */
function VRSoon() {
  const I = window.IMAGES || {};
  const [tilt, setTilt] = vrS({ x: 0, y: 0 });
  const vrRef = vrR(null);

  vrE(() => {
    const el = vrRef.current;
    if (!el) return;
    const onMove = (e) => {
      const r = el.getBoundingClientRect();
      setTilt({
        x: (e.clientY - (r.top  + r.height / 2)) / 50,
        y: (e.clientX - (r.left + r.width  / 2)) / 50,
      });
    };
    const onLeave = () => setTilt({ x: 0, y: 0 });
    el.addEventListener('mousemove', onMove);
    el.addEventListener('mouseleave', onLeave);
    return () => {
      el.removeEventListener('mousemove', onMove);
      el.removeEventListener('mouseleave', onLeave);
    };
  }, []);

  return (
    <section id="vr-soon" style={{
      position: 'relative',
      padding: '160px 0',
      background: 'var(--ink)',
      color: 'var(--bg)',
      overflow: 'hidden',
    }}>
      {/* ambient glows */}
      <div style={{ position: 'absolute', inset: 0, pointerEvents: 'none', background: 'radial-gradient(ellipse 700px 500px at 28% 55%, rgba(201,181,138,0.13), transparent 60%)' }} />
      <div style={{ position: 'absolute', inset: 0, pointerEvents: 'none', background: 'radial-gradient(ellipse 500px 400px at 80% 20%, rgba(107,124,90,0.1), transparent 60%)' }} />

      <div style={{ position: 'relative', maxWidth: 1400, margin: '0 auto', padding: '0 32px' }}>

        {/* Section tag — LIVE */}
        <FadeUp>
          <div style={{ display: 'flex', alignItems: 'center', gap: 14, marginBottom: 60 }}>
            <span className="mono" style={{ fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', color: 'rgba(239,234,224,0.55)' }}>
              — 04 / Virtual Reality
            </span>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 8, padding: '5px 14px', border: '1px solid rgba(239,234,224,0.25)', borderRadius: 999 }}>
              <span style={{ width: 6, height: 6, borderRadius: '50%', background: '#4ade80', boxShadow: '0 0 10px #4ade80' }} className="vr-live-dot" />
              <span className="mono" style={{ fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase' }}>Live Now · WebXR</span>
            </span>
          </div>
        </FadeUp>

        {/* Main grid — visual LEFT, text RIGHT */}
        <div className="ar-stack" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 80, alignItems: 'center' }}>

          {/* LEFT — headset + iPad */}
          <div ref={vrRef} style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: 640, perspective: 1600 }}>
            <FadeUp delay={0.15}>
              <div style={{ position: 'relative', width: 560, height: 580 }}>

                {/* ── VR Headset (420 × 252) ── */}
                <div style={{
                  position: 'absolute',
                  top: '46%', left: '48%',
                  transform: `translate(-58%, -50%) rotateX(${tilt.x}deg) rotateY(${tilt.y}deg)`,
                  transition: 'transform .4s cubic-bezier(.22,1,.36,1)',
                  transformStyle: 'preserve-3d',
                  width: 420, height: 252,
                }}>
                  {/* body */}
                  <div style={{
                    position: 'absolute', inset: 0,
                    background: 'linear-gradient(155deg, #2e2b24 0%, #1a1814 55%, #141210 100%)',
                    borderRadius: 40,
                    border: '1px solid rgba(239,234,224,0.09)',
                    boxShadow: '0 60px 120px rgba(0,0,0,0.7), 0 0 0 1px rgba(239,234,224,0.05), inset 0 1px 0 rgba(239,234,224,0.07)',
                  }}>
                    {/* left lens */}
                    <div style={{
                      position: 'absolute', left: 26, top: '50%', transform: 'translateY(-50%)',
                      width: 136, height: 104,
                      borderRadius: 22,
                      background: '#0a0908',
                      border: '1px solid rgba(239,234,224,0.08)',
                      display: 'grid', placeItems: 'center',
                      overflow: 'hidden',
                    }}>
                      <div style={{ position: 'absolute', inset: 0, backgroundImage: `url(${I.archLight})`, backgroundSize: 'cover', backgroundPosition: 'center', opacity: 0.4, filter: 'blur(1px)' }} />
                      <div style={{ position: 'relative', zIndex: 2, width: 88, height: 66, borderRadius: 14, border: '1px solid rgba(201,181,138,0.35)', background: 'rgba(201,181,138,0.06)', display: 'grid', placeItems: 'center' }}>
                        <div style={{ width: 28, height: 28, borderRadius: '50%', border: '1.5px solid rgba(201,181,138,0.65)', boxShadow: '0 0 18px rgba(201,181,138,0.4)' }} />
                      </div>
                    </div>

                    {/* right lens */}
                    <div style={{
                      position: 'absolute', right: 26, top: '50%', transform: 'translateY(-50%)',
                      width: 136, height: 104,
                      borderRadius: 22,
                      background: '#0a0908',
                      border: '1px solid rgba(239,234,224,0.08)',
                      display: 'grid', placeItems: 'center',
                      overflow: 'hidden',
                    }}>
                      <div style={{ position: 'absolute', inset: 0, backgroundImage: `url(${I.archLight})`, backgroundSize: 'cover', backgroundPosition: 'center', opacity: 0.4, filter: 'blur(1px)' }} />
                      <div style={{ position: 'relative', zIndex: 2, width: 88, height: 66, borderRadius: 14, border: '1px solid rgba(201,181,138,0.35)', background: 'rgba(201,181,138,0.06)', display: 'grid', placeItems: 'center' }}>
                        <div style={{ width: 28, height: 28, borderRadius: '50%', border: '1.5px solid rgba(201,181,138,0.65)', boxShadow: '0 0 18px rgba(201,181,138,0.4)' }} />
                      </div>
                    </div>

                    {/* bridge */}
                    <div style={{ position: 'absolute', left: '50%', top: '50%', transform: 'translate(-50%,-50%)', width: 32, height: 16, borderRadius: 999, background: 'rgba(239,234,224,0.05)' }} />

                    {/* gold accent stripe */}
                    <div style={{ position: 'absolute', top: 14, left: '50%', transform: 'translateX(-50%)', width: 120, height: 1, background: 'linear-gradient(90deg,transparent,rgba(201,181,138,0.75),transparent)' }} />

                    {/* live LED */}
                    <div style={{ position: 'absolute', bottom: 14, right: 20, width: 8, height: 8, borderRadius: '50%', background: '#4ade80', boxShadow: '0 0 12px rgba(74,222,128,0.9)' }} className="vr-live-dot" />

                    {/* wordmark */}
                    <div style={{ position: 'absolute', bottom: 12, left: 20 }}>
                      <span className="mono" style={{ fontSize: 8, letterSpacing: '0.22em', textTransform: 'uppercase', color: 'rgba(239,234,224,0.28)' }}>AURA · WebXR</span>
                    </div>
                  </div>

                  {/* left strap */}
                  <div style={{ position: 'absolute', left: -56, top: '50%', transform: 'translateY(-50%)', width: 58, height: 82, background: 'linear-gradient(to left, rgba(42,38,32,0.75), transparent)', borderRadius: '18px 0 0 18px', borderTop: '1px solid rgba(239,234,224,0.05)', borderBottom: '1px solid rgba(239,234,224,0.05)', borderLeft: '1px solid rgba(239,234,224,0.07)' }} />
                  {/* right strap */}
                  <div style={{ position: 'absolute', right: -56, top: '50%', transform: 'translateY(-50%)', width: 58, height: 82, background: 'linear-gradient(to right, rgba(42,38,32,0.75), transparent)', borderRadius: '0 18px 18px 0', borderTop: '1px solid rgba(239,234,224,0.05)', borderBottom: '1px solid rgba(239,234,224,0.05)', borderRight: '1px solid rgba(239,234,224,0.07)' }} />
                </div>

                {/* ── iPad (200 × 268) floating bottom-right ── */}
                <div className="vr-ipad-float" style={{
                  position: 'absolute', bottom: 0, right: 0,
                  width: 200, height: 268,
                  background: '#18160F',
                  borderRadius: 24,
                  border: '1px solid rgba(239,234,224,0.14)',
                  boxShadow: '0 32px 80px rgba(0,0,0,0.6)',
                  padding: 7,
                  overflow: 'hidden',
                }}>
                  {/* home bar */}
                  <div style={{ position: 'absolute', bottom: 10, left: '50%', transform: 'translateX(-50%)', width: 48, height: 4, borderRadius: 999, background: 'rgba(239,234,224,0.2)', zIndex: 4 }} />
                  {/* camera */}
                  <div style={{ position: 'absolute', top: 10, left: '50%', transform: 'translateX(-50%)', width: 7, height: 7, borderRadius: '50%', background: 'rgba(239,234,224,0.12)', zIndex: 4 }} />
                  {/* screen */}
                  <div style={{ width: '100%', height: '100%', borderRadius: 18, overflow: 'hidden', position: 'relative', backgroundImage: `url(${I.loftBerlin})`, backgroundSize: 'cover', backgroundPosition: 'center' }}>
                    <div style={{ position: 'absolute', inset: 0, background: 'rgba(10,9,8,0.45)' }} />
                    {/* status bar */}
                    <div style={{ position: 'absolute', top: 14, left: 14, right: 14, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
                      <span className="mono" style={{ fontSize: 8, letterSpacing: '0.14em', textTransform: 'uppercase', color: '#4ade80', background: 'rgba(0,0,0,0.35)', backdropFilter: 'blur(6px)', padding: '4px 8px', borderRadius: 6 }}>● Live VR</span>
                      <span className="mono" style={{ fontSize: 8, letterSpacing: '0.12em', textTransform: 'uppercase', color: 'rgba(239,234,224,0.5)', background: 'rgba(0,0,0,0.35)', backdropFilter: 'blur(6px)', padding: '4px 8px', borderRadius: 6 }}>iPad</span>
                    </div>
                    {/* bottom card */}
                    <div style={{ position: 'absolute', left: 12, right: 12, bottom: 24, background: 'rgba(20,18,14,0.62)', backdropFilter: 'blur(12px)', borderRadius: 14, padding: '14px 14px', border: '1px solid rgba(255,253,248,0.07)' }}>
                      <div className="mono" style={{ fontSize: 8, letterSpacing: '0.14em', textTransform: 'uppercase', color: '#C9B58A', marginBottom: 6 }}>Penthouse 02</div>
                      <div className="serif" style={{ fontSize: 15, color: '#fff', lineHeight: 1.2, marginBottom: 8 }}>Mirror headset view</div>
                      <div style={{ display: 'flex', gap: 6 }}>
                        <span style={{ width: 22, height: 22, borderRadius: 6, background: '#C9B58A' }} />
                        <span style={{ width: 22, height: 22, borderRadius: 6, background: '#5a554a' }} />
                        <span style={{ width: 22, height: 22, borderRadius: 6, background: '#c8d2bc' }} />
                      </div>
                    </div>
                  </div>
                </div>

                {/* floating callouts */}
                <div className="vr-callout-float" style={{ position: 'absolute', top: '10%', right: '1%', padding: '7px 13px', borderRadius: 999, border: '1px solid rgba(239,234,224,0.18)', background: 'rgba(255,253,248,0.05)', backdropFilter: 'blur(8px)' }}>
                  <span className="mono" style={{ fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase', color: '#C9B58A' }}>⌖ 6DoF tracked</span>
                </div>
                <div className="vr-callout-float" style={{ position: 'absolute', top: '34%', left: '0%', padding: '7px 13px', borderRadius: 999, border: '1px solid rgba(239,234,224,0.18)', background: 'rgba(255,253,248,0.05)', backdropFilter: 'blur(8px)', animationDelay: '1.4s' }}>
                  <span className="mono" style={{ fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'rgba(239,234,224,0.65)' }}>◈ Spatial audio</span>
                </div>
                <div className="vr-callout-float" style={{ position: 'absolute', bottom: '10%', left: '2%', padding: '7px 13px', borderRadius: 999, border: '1px solid rgba(239,234,224,0.18)', background: 'rgba(255,253,248,0.05)', backdropFilter: 'blur(8px)', animationDelay: '2.6s' }}>
                  <span className="mono" style={{ fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'rgba(239,234,224,0.65)' }}>◎ iPad mirroring</span>
                </div>

              </div>
            </FadeUp>
          </div>

          {/* RIGHT — copy */}
          <div>
            <h2 className="serif kerning-tight" style={{ fontSize: 'clamp(44px, 6vw, 96px)', lineHeight: 0.95, marginBottom: 32 }}>
              <Reveal text="Step inside." />
              <br />
              <span style={{ fontStyle: 'italic', color: '#C9B58A' }}>
                <Reveal text="Fully." baseDelay={0.2} />
              </span>
            </h2>

            <FadeUp delay={0.3}>
              <p style={{ color: 'rgba(239,234,224,0.7)', fontSize: 16, lineHeight: 1.7, marginBottom: 40 }}>
                Put on the headset and walk the floor plan in real scale — or mirror the session live to an iPad for clients in the room. Every wall, surface and shadow rendered at 1:1 and available right now through any WebXR browser.
              </p>
            </FadeUp>

            <FadeUp delay={0.45}>
              <div className="ar-features" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 24, marginBottom: 48 }}>
                {[
                  ['VR headset', 'Meta Quest, Vision Pro, Pico — any WebXR device, no sideloading.'],
                  ['iPad & tablet', 'Full spatial session on iPad Pro. Mirror or hand off to headset in one tap.'],
                  ['Spatial audio', 'Sound mapped per surface. Step into the kitchen — hear the acoustics change.'],
                  ['6DoF tracking', 'Walk, crouch, reach. Your real movements map directly into the rendered space.'],
                ].map(([t, d], i) => (
                  <div key={i}>
                    <div className="mono" style={{ fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', color: '#C9B58A', marginBottom: 8 }}>0{i + 1}</div>
                    <div className="serif" style={{ fontSize: 22, lineHeight: 1.15, marginBottom: 6 }}>{t}</div>
                    <div style={{ fontSize: 12, color: 'rgba(239,234,224,0.55)', lineHeight: 1.6 }}>{d}</div>
                  </div>
                ))}
              </div>
            </FadeUp>

            <FadeUp delay={0.6}>
              <div style={{ display: 'flex', gap: 14, flexWrap: 'wrap' }}>
                <Magnetic strength={0.25}>
                  <a href="/experience" className="btn-primary" data-cursor="click" style={{ background: '#C9B58A', color: '#15140F' }}>
                    Enter VR Experience
                    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
                      <path d="M5 12h14M13 6l6 6-6 6" />
                    </svg>
                  </a>
                </Magnetic>
                <Magnetic strength={0.25}>
                  <a href="mailto:auraworld4u@gmail.com" className="btn-primary" data-cursor="click" style={{ background: 'transparent', color: 'var(--bg)', border: '1px solid rgba(239,234,224,0.3)' }}>
                    Request a demo
                  </a>
                </Magnetic>
              </div>
              <div className="mono" style={{ fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', color: 'rgba(239,234,224,0.4)', marginTop: 18 }}>
                · Works in browser · No install · WebXR
              </div>
            </FadeUp>
          </div>

        </div>
      </div>

      <style>{`
        @keyframes vrLivePulse { 0%,100%{ transform:scale(1);opacity:1 } 50%{ transform:scale(2.2);opacity:0 } }
        .vr-live-dot { animation: vrLivePulse 2s ease-out infinite; }
        @keyframes vrCalloutFloat { 0%,100%{ transform:translateY(0) } 50%{ transform:translateY(-9px) } }
        .vr-callout-float { animation: vrCalloutFloat 4.5s ease-in-out infinite; }
        @keyframes vrIpadFloat { 0%,100%{ transform:translateY(0) } 50%{ transform:translateY(-8px) } }
        .vr-ipad-float { animation: vrIpadFloat 5.5s ease-in-out infinite; }
      `}</style>
    </section>
  );
}

window.VRSoon = VRSoon;
