const { useState, useEffect, useRef } = React;

// ─── Reveal hook ──────────────────────────────────────────
function useReveal() {
  useEffect(() => {
    const obs = new IntersectionObserver((entries) => {
      entries.forEach((e) => {if (e.isIntersecting) {e.target.classList.add('visible');obs.unobserve(e.target);}});
    }, { threshold: 0, rootMargin: '0px 0px -8% 0px' });
    document.querySelectorAll('.fade-up').forEach((el) => obs.observe(el));
    return () => obs.disconnect();
  }, []);
}

// ─── Counter animation ────────────────────────────────────
function Counter({ value, prefix = '', suffix = '', duration = 2000, decimals = 0 }) {
  const [n, setN] = useState(0);
  const ref = useRef(null);
  const started = useRef(false);
  useEffect(() => {
    const obs = new IntersectionObserver((entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting && !started.current) {
          started.current = true;
          const start = performance.now();
          const tick = (t) => {
            const p = Math.min(1, (t - start) / duration);
            const eased = 1 - Math.pow(1 - p, 3);
            setN(value * eased);
            if (p < 1) requestAnimationFrame(tick);
          };
          requestAnimationFrame(tick);
        }
      });
    }, { threshold: 0.4 });
    if (ref.current) obs.observe(ref.current);
    return () => obs.disconnect();
  }, [value, duration]);
  const display = decimals > 0 ? n.toFixed(decimals) : Math.round(n).toLocaleString();
  return <span ref={ref}>{prefix}{display}{suffix}</span>;
}

// ─── Scroll progress ──────────────────────────────────────
function ScrollBar() {
  const [w, setW] = useState(0);
  useEffect(() => {
    const onScroll = () => {
      const h = document.documentElement.scrollHeight - window.innerHeight;
      setW(h > 0 ? window.scrollY / h * 100 : 0);
    };
    window.addEventListener('scroll', onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener('scroll', onScroll);
  }, []);
  return <div className="scroll-bar" style={{ width: w + '%' }} />;
}

// ─── Navigation ───────────────────────────────────────────
function Nav() {
  const [scrolled, setScrolled] = useState(false);
  const [open, setOpen] = useState(false);
  const [active, setActive] = useState('');
  useEffect(() => {
    const onS = () => setScrolled(window.scrollY > 60);
    window.addEventListener('scroll', onS, { passive: true });
    return () => window.removeEventListener('scroll', onS);
  }, []);
  useEffect(() => {
    const ids = ['how-it-works', 'the-opportunity', 'our-process', 'the-terminal', 'invest'];
    const obs = new IntersectionObserver((entries) => {
      entries.forEach((e) => {if (e.isIntersecting) setActive(e.target.id);});
    }, { rootMargin: '-40% 0px -55% 0px' });
    ids.forEach((id) => {const el = document.getElementById(id);if (el) obs.observe(el);});
    return () => obs.disconnect();
  }, []);

  const links = [
  { id: 'how-it-works', label: 'How It Works' },
  { id: 'the-opportunity', label: 'The Opportunity' },
  { id: 'our-process', label: 'Our Process' },
  { id: 'the-terminal', label: 'The Terminal' },
  { id: 'invest', label: 'Invest' }];


  return (
    <nav style={{
      position: 'fixed', top: 0, left: 0, right: 0, height: 72, zIndex: 100,
      background: scrolled ? 'rgba(7,9,15,0.85)' : 'transparent',
      backdropFilter: scrolled ? 'blur(20px)' : 'none',
      WebkitBackdropFilter: scrolled ? 'blur(20px)' : 'none',
      borderBottom: scrolled ? '1px solid var(--bd)' : '1px solid transparent',
      transition: 'all .3s ease'
    }}>
      <div className="mx-auto flex items-center justify-between h-full px-6 lg:px-10" style={{ maxWidth: 1400 }}>
        <a href="#top" style={{ textDecoration: 'none', display: 'inline-flex', alignItems: 'center' }}>
          <img src="uploads/terminal-logo-stacked-gold%20(1).svg" alt="The Terminal · by RePrime Group" style={{ height: 52, width: 'auto', display: 'block' }} />
        </a>

        <div className="hidden lg:flex items-center gap-8">
          {links.map((l) =>
          <a key={l.id} href={'#' + l.id} className={'nav-link ' + (active === l.id ? 'active' : '')}>{l.label}</a>
          )}
        </div>

        <div className="hidden md:flex items-center" style={{ gap: 10 }}>
          <a href="https://api.whatsapp.com/send/?phone=17546101495" target="_blank" rel="noopener noreferrer" title="WhatsApp Adir · +1 (754) 610-1495" aria-label="WhatsApp Adir · +1 (754) 610-1495"
            style={{
              display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
              width: 36, height: 36, borderRadius: 8,
              background: 'rgba(37,211,102,0.08)', border: '1px solid rgba(37,211,102,0.3)',
              textDecoration: 'none', color: '#25D366', flexShrink: 0,
              transition: 'background .2s ease',
            }}
            onMouseEnter={(e) => { e.currentTarget.style.background = 'rgba(37,211,102,0.18)'; }}
            onMouseLeave={(e) => { e.currentTarget.style.background = 'rgba(37,211,102,0.08)'; }}
          >
            <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
              <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.768.967-.941 1.165-.173.198-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/>
            </svg>
          </a>
          <a href="https://scheduler.zoom.us/gideon-gratsiani/schedule-with-gideon-czf4njv8" target="_blank" rel="noopener noreferrer" className="btn-outline"
            style={{ textDecoration: 'none', whiteSpace: 'nowrap', padding: '8px 14px', fontSize: 13 }}>
            Schedule a Call
          </a>
          <a href="https://www.reprimeterminal.com/en/join" target="_blank" rel="noopener noreferrer" className="btn-gold"
            style={{ textDecoration: 'none', whiteSpace: 'nowrap', padding: '8px 16px', fontSize: 13 }}>
            Apply for Membership
          </a>
        </div>

        <button className="lg:hidden flex flex-col gap-1.5" onClick={() => setOpen(!open)} aria-label="Menu">
          <span style={{ width: 22, height: 2, background: 'var(--gold)', transition: 'transform .2s', transform: open ? 'rotate(45deg) translate(4px,4px)' : 'none' }} />
          <span style={{ width: 22, height: 2, background: 'var(--gold)', opacity: open ? 0 : 1 }} />
          <span style={{ width: 22, height: 2, background: 'var(--gold)', transition: 'transform .2s', transform: open ? 'rotate(-45deg) translate(4px,-4px)' : 'none' }} />
        </button>
      </div>

      {open &&
      <div className="lg:hidden" style={{ background: 'rgba(7,9,15,0.97)', backdropFilter: 'blur(20px)', borderTop: '1px solid var(--bd)' }}>
          <div className="flex flex-col p-6 gap-4">
            {links.map((l) =>
          <a key={l.id} href={'#' + l.id} className="nav-link" onClick={() => setOpen(false)}>{l.label}</a>
          )}
            <div className="flex flex-wrap gap-3 pt-4">
              <a href="https://api.whatsapp.com/send/?phone=17546101495" target="_blank" rel="noopener noreferrer" className="btn-outline" style={{ textDecoration: 'none' }}>WhatsApp Adir</a>
              <a href="https://scheduler.zoom.us/gideon-gratsiani/schedule-with-gideon-czf4njv8" target="_blank" rel="noopener noreferrer" className="btn-outline" style={{ textDecoration: 'none' }}>Schedule a Call</a>
              <a href="https://reprimeterminal.com/login" target="_blank" rel="noopener noreferrer" className="btn-outline" style={{ textDecoration: 'none' }}>Log In</a>
              <a href="https://www.reprimeterminal.com/en/join" target="_blank" rel="noopener noreferrer" className="btn-gold" style={{ textDecoration: 'none' }}>Apply for Membership</a>
            </div>
          </div>
        </div>
      }
    </nav>);

}

// ─── Hero ─────────────────────────────────────────────────
function HeroVideo() {
  const ref = useRef(null);
  const [videoReady, setVideoReady] = useState(false);
  useEffect(() => {
    const v = ref.current;
    if (!v) return;
    const src = 'https://stream.mux.com/26MgMTFdAPfoK9klfmXbZIzM006OQVvmeRk6OKTRqIrk.m3u8';
    let hls;
    const tryPlay = () => {v.play().catch(() => {});};
    const markReady = () => setVideoReady(true);
    v.addEventListener('canplaythrough', markReady);
    v.addEventListener('playing', markReady);
    v.addEventListener('loadeddata', markReady);
    const fallback = setTimeout(markReady, 4000);
    if (v.canPlayType('application/vnd.apple.mpegurl')) {
      v.src = src;
      v.addEventListener('loadedmetadata', tryPlay, { once: true });
    } else if (window.Hls && window.Hls.isSupported()) {
      hls = new window.Hls({
        capLevelToPlayerSize: false,
        maxBufferLength: 30,
        maxMaxBufferLength: 60,
        abrEwmaDefaultEstimate: 5000000,
      });
      hls.loadSource(src);
      hls.attachMedia(v);
      hls.on(window.Hls.Events.MANIFEST_PARSED, () => {
        if (hls.levels && hls.levels.length) {
          const top = hls.levels.length - 1;
          hls.startLevel = top;
          hls.currentLevel = top;
        }
        tryPlay();
      });
    }
    // Also try on first user interaction in case autoplay is blocked
    const onAny = () => {tryPlay();};
    document.addEventListener('click', onAny, { once: true });
    document.addEventListener('scroll', onAny, { once: true, passive: true });
    document.addEventListener('mousemove', onAny, { once: true });
    return () => {
      clearTimeout(fallback);
      v.removeEventListener('canplaythrough', markReady);
      v.removeEventListener('playing', markReady);
      v.removeEventListener('loadeddata', markReady);
      if (hls) hls.destroy();
      document.removeEventListener('click', onAny);
      document.removeEventListener('scroll', onAny);
      document.removeEventListener('mousemove', onAny);
    };
  }, []);
  return (
    <>
      <video ref={ref} autoPlay muted loop playsInline preload="auto"
      style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', zIndex: 0 }} />
      <div style={{
        position: 'absolute', inset: 0, zIndex: 0, background: '#000',
        opacity: videoReady ? 0 : 1,
        transition: 'opacity 1s ease',
        pointerEvents: 'none',
      }} />
    </>);

}

function Hero() {
  return (
    <section id="top" style={{ position: 'relative', minHeight: '100vh', overflow: 'hidden', background: '#050709' }}>
      <HeroVideo />
      {/* Subtle mesh + shimmer over video */}
      <div style={{ position: 'absolute', inset: 0, zIndex: 1, mixBlendMode: 'screen', opacity: 0.4, pointerEvents: 'none', overflow: 'hidden' }}>
        {[...Array(14)].map((_, i) =>
        <div key={i} style={{
          position: 'absolute',
          top: Math.sin(i * 1.7) * 40 + 50 + '%',
          left: i * 53 % 97 + '%',
          width: 2, height: 2, borderRadius: '50%',
          background: i % 4 === 0 ? 'var(--gold)' : 'rgba(201,169,98,0.5)',
          boxShadow: i % 4 === 0 ? '0 0 12px rgba(201,169,98,0.7)' : 'none',
          opacity: 0.3 + i % 5 * 0.12,
          animation: `pulseDot ${2.5 + i % 4}s ease-in-out infinite`,
          animationDelay: i * 0.2 + 's'
        }} />
        )}
        <div className="scan" />
      </div>

      {/* Gradient overlay — darker at bottom for text legibility, lighter middle to show video */}
      <div style={{ position: 'absolute', inset: 0, zIndex: 1,
        background: 'linear-gradient(to top, #07090F 0%, rgba(7,9,15,0.92) 18%, rgba(7,9,15,0.55) 50%, rgba(7,9,15,0.35) 75%, rgba(7,9,15,0.6) 100%)' }} />
      <div style={{ position: 'absolute', inset: 0, zIndex: 1, background: 'rgba(7,9,15,0.15)' }} />

      {/* Subtle grid */}
      <div style={{
        position: 'absolute', inset: 0, zIndex: 1, opacity: 0.25,
        backgroundImage: `linear-gradient(rgba(201,169,98,0.04) 1px, transparent 1px), linear-gradient(90deg, rgba(201,169,98,0.04) 1px, transparent 1px)`,
        backgroundSize: '80px 80px',
        maskImage: 'radial-gradient(ellipse at center, black 30%, transparent 75%)',
        WebkitMaskImage: 'radial-gradient(ellipse at center, black 30%, transparent 75%)'
      }} />

      <div className="mx-auto px-6 lg:px-10" style={{ position: 'relative', zIndex: 2, maxWidth: 1400, paddingTop: '24vh', paddingBottom: '10vh' }}>
        {/* Status bar */}
        <div className="fade-up flex flex-wrap items-center gap-x-5 gap-y-2 mb-10" style={{ fontFamily: 'DM Sans', fontWeight: 500, fontSize: 11, letterSpacing: '.18em', textTransform: 'uppercase' }}>
          <span style={{ color: 'var(--gold)' }}>The Terminal</span>
          <span style={{ color: 'var(--tx-3)' }}>·</span>
          <span className="flex items-center gap-2" style={{ color: 'var(--tx-3)' }}>
            <span className="pulse" style={{ width: 7, height: 7, borderRadius: '50%', background: '#C9A962', boxShadow: '0 0 10px rgba(201,169,98,0.4)' }} />
            Live Pipeline
          </span>
          <span style={{ color: 'var(--tx-3)' }}>·</span>
          <span style={{ color: 'var(--tx-3)' }}>Nationwide</span>
        </div>

        {/* Heading */}
        <h1 className="fade-up h-display" style={{ fontSize: 'clamp(3rem, 6.2vw, 6rem)', maxWidth: 1100, transitionDelay: '.15s' }}>
          Full-Transparency<br />
          Commercial Real Estate<br />
          <span>Investing,&nbsp;</span>
          <span style={{ fontStyle: 'italic', color: 'var(--gold)' }}>Powered by AI</span>
        </h1>

        {/* Description */}
        <div className="fade-up mt-10" style={{ maxWidth: 560, transitionDelay: '.3s' }}>
          <p style={{ fontSize: 17, color: 'var(--tx-2)', lineHeight: 1.7, margin: 0 }}>
            Every deal. Every document. Every metric. From sourcing to close — see exactly what we see.
          </p>
          <p style={{ fontSize: 17, color: 'var(--tx-2)', lineHeight: 1.7, marginTop: 18 }}>
            The Terminal gives investors direct access to our entire acquisition pipeline with complete transparency, so you can make informed decisions on your own timeline.
          </p>
        </div>

        {/* CTAs */}
        <div className="fade-up flex flex-wrap items-center gap-4 mt-10" style={{ transitionDelay: '.45s' }}>
          <a href="https://www.reprimeterminal.com/en/join" target="_blank" rel="noopener noreferrer" className="btn-gold" style={{ textDecoration: 'none' }}>Apply for Membership &nbsp;→</a>
          <a href="https://reprimeterminal.com/login" target="_blank" rel="noopener noreferrer" className="btn-outline flex items-center gap-2" style={{ textDecoration: 'none' }}>
            <span style={{ color: 'var(--gold)' }}>↪</span> Investor Login
          </a>
          <a href="https://scheduler.zoom.us/gideon-gratsiani/schedule-with-gideon-czf4njv8" target="_blank" rel="noopener noreferrer" className="btn-glass flex items-center gap-2" style={{ textDecoration: 'none' }}>
            <span style={{ color: 'var(--gold)' }}>◷</span> Schedule a Call
          </a>
        </div>

        {/* Video frame */}
        <div className="fade-up corner-bracket mx-auto mt-16" style={{ maxWidth: 980, aspectRatio: '16/9', background: '#0A0D12', border: '1px solid rgba(255,255,255,0.06)', borderRadius: 14, position: 'relative', overflow: 'hidden', transitionDelay: '.6s' }}>
          <span className="br-bl" /><span className="br-br" />
          <div style={{ position: 'absolute', inset: 0, opacity: 0.2, backgroundImage: 'repeating-linear-gradient(0deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 4px)' }} />
          <div className="absolute" style={{ top: 18, left: 24, fontFamily: 'JetBrains Mono', fontSize: 11, color: 'var(--tx-3)', letterSpacing: '.06em' }}>REC // OVERVIEW.MP4</div>
          <div className="absolute flex items-center gap-2" style={{ top: 18, right: 24, fontFamily: 'JetBrains Mono', fontSize: 11, color: 'var(--tx-3)', letterSpacing: '.06em' }}>
            <span className="pulse" style={{ width: 7, height: 7, borderRadius: '50%', background: 'var(--live)' }} /> COMING SOON
          </div>
          <div className="absolute" style={{ inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
            <div style={{
              width: 74, height: 74, borderRadius: '50%',
              border: '1px solid rgba(201,169,98,0.4)',
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              background: 'rgba(201,169,98,0.05)',
              boxShadow: '0 0 60px rgba(201,169,98,0.15)'
            }}>
              <div style={{ width: 0, height: 0, borderTop: '10px solid transparent', borderBottom: '10px solid transparent', borderLeft: '16px solid var(--gold)', marginLeft: 5 }} />
            </div>
          </div>
          <div className="absolute" style={{ bottom: 18, left: 0, right: 0, textAlign: 'center', fontFamily: 'DM Sans', fontSize: 13, color: 'var(--tx-3)' }}>
            Video Overview · Coming Soon
          </div>
        </div>
      </div>
    </section>);

}

// ─── What is the Terminal ─────────────────────────────────
function useFadeInTerminal(delay = 0) {
  const ref = useRef(null);
  const [visible, setVisible] = useState(false);
  useEffect(() => {
    const observer = new IntersectionObserver(
      ([entry]) => { if (entry.isIntersecting) setVisible(true); },
      { threshold: 0.12 }
    );
    if (ref.current) observer.observe(ref.current);
    return () => observer.disconnect();
  }, []);
  return {
    ref,
    style: {
      opacity: visible ? 1 : 0,
      transform: visible ? "translateY(0)" : "translateY(40px)",
      transition: `opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1) ${delay}s, transform 0.8s cubic-bezier(0.16, 1, 0.3, 1) ${delay}s`,
    },
  };
}

function WhatIsTerminal() {
  const stackRef = useRef(null);
  const [mouse, setMouse] = useState({ x: 0, y: 0 });

  useEffect(() => {
    const handleMove = (e) => {
      if (!stackRef.current) return;
      const rect = stackRef.current.getBoundingClientRect();
      const x = ((e.clientX - rect.left) / rect.width - 0.5) * 2;
      const y = ((e.clientY - rect.top) / rect.height - 0.5) * 2;
      setMouse({ x, y });
    };
    window.addEventListener("mousemove", handleMove);
    return () => window.removeEventListener("mousemove", handleMove);
  }, []);

  const fade1 = useFadeInTerminal(0);
  const fade2 = useFadeInTerminal(0.1);
  const fade3 = useFadeInTerminal(0.15);
  const fade4 = useFadeInTerminal(0.2);
  const fade5 = useFadeInTerminal(0.1);

  const glassCard = {
    background: "rgba(255,255,255,0.03)",
    backdropFilter: "blur(20px)",
    WebkitBackdropFilter: "blur(20px)",
    border: "1px solid rgba(255,255,255,0.08)",
    borderRadius: 16,
    padding: 32,
  };

  const layerCardBase = {
    position: "absolute",
    borderRadius: 14,
    border: "1px solid rgba(255,255,255,0.06)",
    overflow: "hidden",
    transition: "transform 0.4s cubic-bezier(0.16, 1, 0.3, 1)",
  };

  return (
    <section
      id="how-it-works"
      style={{
        background: "#0D1117",
        padding: "120px 24px",
        fontFamily: "'DM Sans', sans-serif",
        position: "relative",
        overflow: "hidden",
      }}>

      <link
        href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600&family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
        rel="stylesheet" />

      <div
        style={{
          position: "absolute",
          top: "20%",
          right: "-10%",
          width: 600,
          height: 600,
          borderRadius: "50%",
          background: "radial-gradient(circle, rgba(201,169,98,0.04) 0%, transparent 70%)",
          pointerEvents: "none",
        }} />

      <div style={{ maxWidth: 1400, margin: "0 auto", position: "relative" }}>
        {/* TOP: Two-column — Copy + 3D Visual */}
        <div
          style={{
            display: "grid",
            gridTemplateColumns: "1fr 1fr",
            gap: 80,
            alignItems: "start",
            marginBottom: 80,
          }}>
          {/* LEFT: Copy */}
          <div ref={fade1.ref} style={fade1.style}>
            <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 24 }}>
              <div style={{ width: 32, height: 1, background: "linear-gradient(90deg, #C9A962, transparent)" }} />
              <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 11, letterSpacing: "0.15em", color: "#C9A962", textTransform: "uppercase" }}>
                The Platform
              </span>
            </div>

            <h2 style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: "clamp(2.4rem, 4.5vw, 3.8rem)", fontWeight: 600, color: "#F2F0ED", lineHeight: 1.08, margin: "0 0 36px 0", letterSpacing: "-0.02em" }}>
              What Is{" "}
              <span style={{ fontStyle: "italic", color: "#C9A962" }}>The Terminal</span>
            </h2>

            <div style={{ display: "flex", flexDirection: "column", gap: 20 }}>
              <p style={{ fontSize: 16, color: "#B8B5AE", lineHeight: 1.8, margin: 0 }}>
                The Terminal is not a product. It is the entire technology and operations ecosystem of RePrime Group — every system, every workflow, every AI tool, every data pipeline, and every investor-facing interface, unified under one institutional platform.
              </p>
              <p style={{ fontSize: 16, color: "#B8B5AE", lineHeight: 1.8, margin: 0 }}>
                Behind what investors see is a machine running 24/7: multi-model AI pipelines analyzing every deal through Claude, OpenAI, Gemini, and Perplexity in parallel. Hundreds of automated workflows processing emails, scraping properties, analyzing documents, and updating deal data in real-time. A nationwide property monitoring network covering 3,100+ counties. A tenant risk intelligence engine. Lending partnerships returning debt quotes in minutes. All of it running simultaneously, all of it feeding into the deals you see on your screen.
              </p>
              <p style={{ fontSize: 16, color: "#B8B5AE", lineHeight: 1.8, margin: 0 }}>
                The Terminal exists because we are building the infrastructure to dominate commercial real estate acquisition at scale — and we want our investors right there with us. Every piece of technology we've developed, every AI model we've trained, every workflow we've automated, every data source we've connected — it's all at your fingertips through one platform. You don't just invest alongside us. You see exactly how we operate, in real-time, with the same intelligence our team uses to close deals.
              </p>
            </div>
          </div>

          {/* RIGHT: 3D Layered Card Stack */}
          <div ref={stackRef} style={{ position: "relative", height: 480, perspective: "1200px", ...fade2.style }}>
            <div ref={fade2.ref} style={{ width: "100%", height: "100%" }}>
              {/* Layer 1 (Back): INFRASTRUCTURE */}
              <div style={{
                ...layerCardBase,
                width: "88%", height: "72%", top: 0, right: 0,
                background: "linear-gradient(135deg, rgba(30,58,95,0.2) 0%, rgba(13,17,23,0.6) 100%)",
                border: "1px solid rgba(30,58,95,0.2)",
                transform: `rotateY(${mouse.x * -2}deg) rotateX(${mouse.y * 2}deg) translateZ(-60px) translateY(${mouse.y * -5}px)`,
                zIndex: 1,
              }}>
                <div style={{ padding: "20px 24px" }}>
                  <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 9, letterSpacing: "0.15em", color: "rgba(201,169,98,0.3)", textTransform: "uppercase", marginBottom: 16 }}>
                    Layer 01 · Infrastructure
                  </div>
                  <svg width="100%" height="80" viewBox="0 0 300 80" style={{ opacity: 0.15 }}>
                    {[[30, 20], [90, 45], [150, 15], [210, 55], [270, 30]].map(([x, y], i) => (
                      <g key={i}>
                        <circle cx={x} cy={y} r="6" fill="#C9A962" />
                        {i < 4 && (
                          <line x1={x + 6} y1={y} x2={[90, 150, 210, 270][i] - 6} y2={[45, 15, 55, 30][i]} stroke="#C9A962" strokeWidth="1" strokeDasharray="3,3" />
                        )}
                      </g>
                    ))}
                  </svg>
                  <div style={{ display: "flex", gap: 16, marginTop: 12, opacity: 0.2 }}>
                    {["n8n", "Supabase", "APIs", "Scraping"].map((t) => (
                      <span key={t} style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 8, color: "#C9A962", letterSpacing: "0.1em", textTransform: "uppercase" }}>{t}</span>
                    ))}
                  </div>
                </div>
              </div>

              {/* Layer 2 (Middle): INTELLIGENCE */}
              <div style={{
                ...layerCardBase,
                width: "82%", height: "68%", top: "12%", right: "4%",
                background: "linear-gradient(135deg, rgba(30,58,95,0.3) 0%, rgba(13,17,23,0.7) 100%)",
                border: "1px solid rgba(255,255,255,0.06)",
                backdropFilter: "blur(8px)",
                WebkitBackdropFilter: "blur(8px)",
                transform: `rotateY(${mouse.x * -3}deg) rotateX(${mouse.y * 3}deg) translateZ(-30px) translateY(${mouse.y * -8}px)`,
                zIndex: 2,
              }}>
                <div style={{ padding: "20px 24px" }}>
                  <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 9, letterSpacing: "0.15em", color: "rgba(201,169,98,0.4)", textTransform: "uppercase", marginBottom: 14 }}>
                    Layer 02 · Intelligence
                  </div>
                  <div style={{ display: "flex", flexDirection: "column", gap: 8, opacity: 0.25 }}>
                    {[
                      { label: "Tenant Risk", w: "72%", color: "#4ADE80" },
                      { label: "Market Data", w: "88%", color: "#C9A962" },
                      { label: "Lease Score", w: "64%", color: "#4ADE80" },
                      { label: "Foot Traffic", w: "81%", color: "#C9A962" },
                    ].map((bar) => (
                      <div key={bar.label}>
                        <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 3 }}>
                          <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 8, color: "#6B6860", textTransform: "uppercase", letterSpacing: "0.08em" }}>{bar.label}</span>
                        </div>
                        <div style={{ height: 3, borderRadius: 2, background: "rgba(255,255,255,0.06)" }}>
                          <div style={{ height: "100%", width: bar.w, borderRadius: 2, background: bar.color }} />
                        </div>
                      </div>
                    ))}
                  </div>
                  <div style={{ display: "flex", gap: 16, marginTop: 14, opacity: 0.25 }}>
                    {["Claude", "OpenAI", "Gemini", "Perplexity"].map((t) => (
                      <span key={t} style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 8, color: "#C9A962", letterSpacing: "0.1em", textTransform: "uppercase" }}>{t}</span>
                    ))}
                  </div>
                </div>
              </div>

              {/* Layer 3 (Front): DEAL CARD */}
              <div style={{
                ...layerCardBase,
                width: "78%", height: "auto", bottom: 0, right: "8%",
                background: "linear-gradient(135deg, rgba(20,27,36,0.95) 0%, rgba(13,17,23,0.98) 100%)",
                border: "1px solid rgba(201,169,98,0.15)",
                backdropFilter: "blur(20px)",
                WebkitBackdropFilter: "blur(20px)",
                boxShadow: "0 20px 60px rgba(0,0,0,0.4), 0 0 40px rgba(201,169,98,0.06)",
                transform: `rotateY(${mouse.x * -4}deg) rotateX(${mouse.y * 4}deg) translateZ(0px) translateY(${mouse.y * -12}px)`,
                zIndex: 3,
              }}>
                <div style={{ padding: "24px 28px" }}>
                  <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 4 }}>
                    <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 10, color: "#6B6860", letterSpacing: "0.1em", textTransform: "uppercase" }}>TERM-0142</span>
                    <div style={{ display: "flex", alignItems: "center", gap: 6 }}>
                      <div style={{ width: 6, height: 6, borderRadius: "50%", background: "#4ADE80", animation: "pulse 2s ease-in-out infinite" }} />
                      <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 9, color: "#4ADE80", letterSpacing: "0.08em" }}>LIVE</span>
                    </div>
                  </div>

                  <h3 style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 24, fontWeight: 600, color: "#F2F0ED", margin: "0 0 4px 0" }}>
                    Anchor Plaza Center
                  </h3>
                  <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 10, color: "#6B6860", letterSpacing: "0.08em", textTransform: "uppercase", marginBottom: 20 }}>
                    Grocery-Anchored Retail · 142,300 SF · Marion, IA
                  </div>

                  <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 16, padding: "16px 0", borderTop: "1px solid rgba(255,255,255,0.06)", borderBottom: "1px solid rgba(255,255,255,0.06)" }}>
                    {[
                      { label: "Cap Rate", value: "8.6%", color: "#4ADE80" },
                      { label: "Cash-on-Cash", value: "14.2%", color: "#4ADE80" },
                      { label: "Occupancy", value: "94%", color: "#F2F0ED" },
                    ].map((m) => (
                      <div key={m.label} style={{ textAlign: "center" }}>
                        <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 9, color: "#6B6860", letterSpacing: "0.08em", textTransform: "uppercase", marginBottom: 4 }}>{m.label}</div>
                        <div style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 22, fontWeight: 600, color: m.color }}>{m.value}</div>
                      </div>
                    ))}
                  </div>

                  <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 16 }}>
                    <div>
                      <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 9, color: "#6B6860", letterSpacing: "0.08em", textTransform: "uppercase", marginBottom: 4 }}>AI Confidence</div>
                      <div style={{ display: "flex", alignItems: "center", gap: 6 }}>
                        <div style={{ width: 8, height: 8, borderRadius: "50%", background: "#4ADE80" }} />
                        <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 12, color: "#4ADE80", fontWeight: 500 }}>HIGH</span>
                      </div>
                    </div>
                    <div style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 10, color: "#C9A962", letterSpacing: "0.05em", padding: "6px 14px", borderRadius: 6, border: "1px solid rgba(201,169,98,0.25)", cursor: "default" }}>
                      View Deal →
                    </div>
                  </div>
                </div>
              </div>

              {/* Layer labels */}
              <div style={{ position: "absolute", left: -20, top: 0, height: "100%", display: "flex", flexDirection: "column", justifyContent: "space-between", paddingTop: 20, paddingBottom: 40, zIndex: 10 }}>
                {[
                  { label: "Infrastructure", opacity: 0.2 },
                  { label: "Intelligence", opacity: 0.35 },
                  { label: "Your View", opacity: 0.7 },
                ].map((l) => (
                  <div key={l.label} style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 9, color: "#C9A962", letterSpacing: "0.12em", textTransform: "uppercase", opacity: l.opacity, writingMode: "vertical-rl", transform: "rotate(180deg)" }}>
                    {l.label}
                  </div>
                ))}
              </div>
            </div>
          </div>
        </div>

        {/* THREE PILLAR CARDS */}
        <div ref={fade3.ref} style={{ ...fade3.style, display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 20, marginBottom: 40 }}>
          {[
            { num: "01", label: "What You See", body: "The Marketplace and Official Terminal. Live deal pipeline, full documentation, AI-generated analysis, investment options, and real-time updates. Complete transparency into every active deal." },
            { num: "02", label: "What Powers It", body: "Multi-model AI running Claude, OpenAI, Gemini, and Perplexity in parallel. Hundreds of automated workflows. Nationwide property scraping. Tenant risk scoring. 50-page lease analysis in minutes. Lending quotes in 10 minutes." },
            { num: "03", label: "What It Means for You", body: "Faster decisions. Better data. Full transparency. Deals analyzed and underwritten before most buyers have opened the email. Five closing methods. The ability to move at the speed this market demands." },
          ].map((card) => (
            <div
              key={card.num}
              style={{ ...glassCard, borderTop: "2px solid rgba(201,169,98,0.3)", padding: "28px 28px 32px", transition: "border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease", cursor: "default" }}
              onMouseEnter={(e) => {
                e.currentTarget.style.borderTopColor = "#C9A962";
                e.currentTarget.style.boxShadow = "0 0 40px rgba(201,169,98,0.06)";
                e.currentTarget.style.transform = "translateY(-4px)";
              }}
              onMouseLeave={(e) => {
                e.currentTarget.style.borderTopColor = "rgba(201,169,98,0.3)";
                e.currentTarget.style.boxShadow = "none";
                e.currentTarget.style.transform = "translateY(0)";
              }}>
              <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 16 }}>
                <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 10, letterSpacing: "0.12em", color: "#C9A962", textTransform: "uppercase" }}>{card.label}</span>
                <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 11, color: "rgba(201,169,98,0.4)" }}>/{card.num}</span>
              </div>
              <p style={{ fontSize: 14, color: "#B8B5AE", lineHeight: 1.7, margin: 0 }}>{card.body}</p>
            </div>
          ))}
        </div>

        {/* MARKETPLACE vs TERMINAL CARDS */}
        <div ref={fade4.ref} style={{ ...fade4.style, display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20, marginBottom: 20 }}>
          <div
            style={{ ...glassCard, transition: "border-color 0.3s ease, box-shadow 0.3s ease", cursor: "default" }}
            onMouseEnter={(e) => {
              e.currentTarget.style.borderColor = "rgba(201,169,98,0.2)";
              e.currentTarget.style.boxShadow = "0 0 30px rgba(201,169,98,0.04)";
            }}
            onMouseLeave={(e) => {
              e.currentTarget.style.borderColor = "rgba(255,255,255,0.08)";
              e.currentTarget.style.boxShadow = "none";
            }}>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 20 }}>
              <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 10, letterSpacing: "0.12em", color: "#6B6860", textTransform: "uppercase" }}>The Marketplace</span>
              <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 13, color: "#C9A962" }}>/01</span>
            </div>
            <h3 style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 22, fontWeight: 500, color: "#F2F0ED", margin: "0 0 16px 0", lineHeight: 1.3 }}>
              Pre-contract pipeline. Direction at the source.
            </h3>
            <p style={{ fontSize: 14, color: "#B8B5AE", lineHeight: 1.7, margin: 0 }}>
              Every property that enters our negotiation pipeline gets listed in the Marketplace. Investors see deals from the earliest stages — providing direction on pricing and asset preferences before we even go to contract. This gives you visibility into what's coming and the ability to tell us what you're looking for.
            </p>
          </div>

          <div
            style={{ ...glassCard, transition: "border-color 0.3s ease, box-shadow 0.3s ease", cursor: "default" }}
            onMouseEnter={(e) => {
              e.currentTarget.style.borderColor = "rgba(201,169,98,0.2)";
              e.currentTarget.style.boxShadow = "0 0 30px rgba(201,169,98,0.04)";
            }}
            onMouseLeave={(e) => {
              e.currentTarget.style.borderColor = "rgba(255,255,255,0.08)";
              e.currentTarget.style.boxShadow = "none";
            }}>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 20 }}>
              <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 10, letterSpacing: "0.12em", color: "#6B6860", textTransform: "uppercase" }}>The Terminal</span>
              <span style={{ fontFamily: "'JetBrains Mono', monospace", fontSize: 13, color: "#C9A962" }}>/02</span>
            </div>
            <h3 style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 22, fontWeight: 500, color: "#F2F0ED", margin: "0 0 16px 0", lineHeight: 1.3 }}>
              Under contract. Every document. Real-time.
            </h3>
            <p style={{ fontSize: 14, color: "#B8B5AE", lineHeight: 1.7, margin: 0 }}>
              Deals under contract live in the Terminal with full transparency. Every financial model. Every tenant report. Every lease analysis. Every market comparison. Every document — updated in real-time. You see exactly what our team sees, from the moment a deal is secured to the day it generates returns.
            </p>
          </div>
        </div>

        {/* HOW YOU PARTICIPATE */}
        <div ref={fade5.ref} style={{ ...fade5.style, ...glassCard, borderColor: "rgba(201,169,98,0.12)" }}>
          <h3 style={{ fontFamily: "'Cormorant Garamond', serif", fontSize: 24, fontWeight: 500, color: "#F2F0ED", margin: "0 0 16px 0" }}>
            How You Participate
          </h3>
          <p style={{ fontSize: 15, color: "#B8B5AE", lineHeight: 1.75, margin: 0, maxWidth: 900 }}>
            There are two ways to invest through the Terminal. You can acquire a deal directly from RePrime — essentially purchasing the property through our platform. Or you can enter a GP/LP partnership structure where RePrime manages the asset and you participate as a limited partner. Every deal in the Terminal includes the full information you need to evaluate either option.
          </p>
        </div>

        <div style={{ height: 1, marginTop: 80, background: "linear-gradient(90deg, transparent, rgba(201,169,98,0.3), transparent)" }} />
      </div>

      <style>{`
        @keyframes pulse {
          0%, 100% { opacity: 1; }
          50% { opacity: 0.4; }
        }
        @media (max-width: 1024px) {
          #how-it-works > div > div:first-child {
            grid-template-columns: 1fr !important;
          }
          #how-it-works [style*="grid-template-columns: 1fr 1fr 1fr"] {
            grid-template-columns: 1fr !important;
          }
          #how-it-works [style*="grid-template-columns: 1fr 1fr"] {
            grid-template-columns: 1fr !important;
          }
        }
      `}</style>
    </section>);

}

function PlatformCard({ num, label, title, body }) {
  return (
    <div className="glass hover-card fade-up p-10" style={{ position: 'relative' }}>
      <div className="absolute" style={{ top: 24, right: 28, fontFamily: 'JetBrains Mono', fontSize: 13, color: 'var(--gold)' }}>{num}</div>
      <div style={{ fontFamily: 'JetBrains Mono', fontSize: 11, letterSpacing: '.14em', textTransform: 'uppercase', color: 'var(--tx-3)' }}>{label}</div>
      <h3 className="font-serif mt-4" style={{ fontWeight: 500, fontSize: 24, color: 'var(--tx-1)', lineHeight: 1.25 }}>{title}</h3>
      <p className="body-copy mt-4" style={{ fontSize: 15 }}>{body}</p>
    </div>);

}

function CardStack() {
  return (
    <div style={{ position: 'relative', height: 380, perspective: 1200 }}>
      <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(circle at 50% 50%, rgba(201,169,98,0.15), transparent 60%)', filter: 'blur(20px)' }} />
      {[2, 1, 0].map((i) =>
      <div key={i} className="float-anim" style={{
        position: 'absolute',
        top: 30 + i * 36,
        left: 30 + i * 30,
        right: 30 - i * 30,
        height: 280,
        background: 'rgba(20,27,36,0.7)',
        backdropFilter: 'blur(12px)',
        border: '1px solid ' + (i === 0 ? 'rgba(201,169,98,0.3)' : 'rgba(255,255,255,0.08)'),
        borderRadius: 14,
        transform: `rotateZ(${-3 + i * 1.5}deg) rotateY(${-8}deg)`,
        transformOrigin: 'center',
        boxShadow: i === 0 ? '0 30px 80px rgba(0,0,0,0.5), 0 0 60px rgba(201,169,98,0.08)' : '0 20px 50px rgba(0,0,0,0.4)',
        padding: 24,
        animationDelay: i * 0.3 + 's'
      }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
            <div style={{ fontFamily: 'JetBrains Mono', fontSize: 10, color: 'var(--tx-3)', letterSpacing: '.1em' }}>
              {i === 0 ? 'TERM-0142' : i === 1 ? 'TERM-0141' : 'TERM-0140'}
            </div>
            <div style={{ width: 6, height: 6, borderRadius: '50%', background: i === 0 ? 'var(--success)' : 'var(--warn)' }} />
          </div>
          <div style={{ fontFamily: 'Cormorant Garamond', fontSize: 18, color: 'var(--tx-1)', fontWeight: 500, marginBottom: 8 }}>
            {i === 0 ? 'Anchor Plaza Center' : i === 1 ? 'Northwood Apartments' : 'Industrial Park 19'}
          </div>
          <div style={{ fontFamily: 'JetBrains Mono', fontSize: 10, color: 'var(--tx-3)', marginBottom: 18 }}>
            {i === 0 ? 'RETAIL · 142,300 SF · MARION, IA' : i === 1 ? 'MULTIFAMILY · 248 UNITS · IL' : 'INDUSTRIAL · 410,500 SF · OH'}
          </div>
          {[1, 2, 3].map((j) =>
        <div key={j} style={{ height: 6, background: 'rgba(255,255,255,0.04)', borderRadius: 3, marginBottom: 10 }}>
              <div style={{ height: 6, background: 'rgba(201,169,98,0.35)', width: 60 - j * 15 + '%', borderRadius: 3 }} />
            </div>
        )}
          <div style={{ marginTop: 24, display: 'flex', justifyContent: 'space-between', fontFamily: 'JetBrains Mono', fontSize: 10, color: 'var(--tx-3)' }}>
            <span>CAP RATE</span>
            <span style={{ color: 'var(--gold)' }}>{i === 0 ? '8.6%' : i === 1 ? '7.9%' : '9.1%'}</span>
          </div>
        </div>
      )}
    </div>);

}

// ─── Maturity Bar Chart ───────────────────────────────────
function MaturityChart() {
  const ref = useRef(null);
  const [show, setShow] = useState(false);
  useEffect(() => {
    const obs = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) { setShow(true); obs.disconnect(); } });
    }, { threshold: 0.3 });
    if (ref.current) obs.observe(ref.current);
    return () => obs.disconnect();
  }, []);
  const data = [
    { yr: '2024', amt: '$441B', val: 441 },
    { yr: '2025', amt: '$486B', val: 486 },
    { yr: '2026', amt: '$891B', val: 891, peak: true },
    { yr: '2027', amt: '$382B', val: 382 },
  ];
  const max = 891;
  return (
    <div ref={ref} className="glass fade-up p-10 mt-12" style={{ background: 'rgba(7,9,15,0.6)' }}>
      <div className="flex items-end justify-between gap-6" style={{ height: 360 }}>
        {data.map((d, i) => {
          const h = show ? (d.val / max) * 280 : 0;
          return (
            <div key={i} className="flex-1 flex flex-col items-center justify-end" style={{ height: '100%' }}>
              {d.peak && (
                <div className="mb-2" style={{ fontFamily: 'JetBrains Mono', fontSize: 10, color: '#EF4444', letterSpacing: '.16em', textTransform: 'uppercase', fontWeight: 600 }}>
                  ▼ The Tsunami Year
                </div>
              )}
              <div style={{
                fontFamily: 'Cormorant Garamond', fontSize: d.peak ? 26 : 20,
                color: d.peak ? 'var(--gold-l)' : 'var(--tx-1)', fontWeight: 600,
                marginBottom: 8, opacity: show ? 1 : 0, transition: 'opacity 1s ease', transitionDelay: (1.2 + i * 0.1) + 's'
              }}>{d.amt}</div>
              <div style={{
                width: '85%', maxWidth: 140,
                height: h, transition: `height 1.4s cubic-bezier(.16,1,.3,1) ${i * 0.15}s`,
                background: d.peak
                  ? 'linear-gradient(180deg, #D4B978 0%, #C9A962 100%)'
                  : 'linear-gradient(180deg, rgba(201,169,98,0.85) 0%, rgba(201,169,98,0.55) 100%)',
                boxShadow: d.peak ? '0 0 40px rgba(201,169,98,0.4), inset 0 0 20px rgba(255,255,255,0.1)' : '0 0 20px rgba(201,169,98,0.15)',
                borderRadius: '4px 4px 0 0',
                border: d.peak ? '1px solid rgba(212,185,120,0.6)' : '1px solid rgba(201,169,98,0.3)',
                animation: d.peak && show ? 'pulseDot 3s ease-in-out infinite' : 'none'
              }} />
              <div style={{ width: '85%', maxWidth: 140, height: 1, background: 'rgba(201,169,98,0.3)' }} />
              <div style={{ marginTop: 12, fontFamily: 'JetBrains Mono', fontSize: 13, color: d.peak ? 'var(--gold)' : 'var(--tx-2)', letterSpacing: '.1em', fontWeight: d.peak ? 600 : 400 }}>{d.yr}</div>
            </div>
          );
        })}
      </div>
      <div className="mt-6 text-center" style={{ fontFamily: 'JetBrains Mono', fontSize: 11, color: 'var(--tx-3)', letterSpacing: '.08em' }}>
        Source: Mortgage Bankers Association — $2.2 Trillion in CRE Maturities
      </div>
    </div>
  );
}

// ─── Math Comparison ──────────────────────────────────────
function MathComparison() {
  const left = [
    ['Purchase Price', '$100,000,000'],
    ['Cap Rate', '3.0%'],
    ['Loan Amount (75% LTV)', '$75,000,000'],
    ['Interest Rate', '3.0%'],
    ['Annual Debt Service', '$2,250,000'],
    ['Net Operating Income', '$3,000,000'],
    ['Cash Flow', '$750,000'],
    ['Equity Position', '$25,000,000'],
  ];
  const right = [
    ['Property Value (7% cap)', '$42,857,143', false],
    ['Loan Balance', '$75,000,000', false],
    ['Interest Rate', '7.0%', false],
    ['Annual Debt Service', '$5,250,000', false],
    ['Net Operating Income', '$3,000,000', false],
    ['Cash Flow', '−$2,250,000', true],
    ['Equity Position', '−$32,142,857', true],
    ['Lender Loss', '$32,142,857', true],
  ];
  return (
    <div className="fade-up mt-16">
      <div style={{ fontFamily: 'JetBrains Mono', fontSize: 11, letterSpacing: '.18em', textTransform: 'uppercase', color: 'var(--tx-3)', marginBottom: 24 }}>
        — Why Banks Are Forced to Sell
      </div>
      <div className="grid lg:grid-cols-[1fr_auto_1fr] gap-6 items-stretch">
        <div className="glass p-8" style={{ borderColor: 'rgba(74,222,128,0.18)' }}>
          <div style={{ fontFamily: 'JetBrains Mono', fontSize: 11, letterSpacing: '.16em', color: 'var(--gold)', fontWeight: 600 }}>2021 · ACQUISITION</div>
          <div className="font-serif mt-2" style={{ fontSize: 22, color: 'var(--tx-1)', fontWeight: 500 }}>Sunshine, low rates, easy money.</div>
          <div className="mt-6 flex flex-col gap-3">
            {left.map(([k, v]) => (
              <div key={k} className="flex justify-between items-baseline" style={{ borderBottom: '1px solid rgba(255,255,255,0.04)', paddingBottom: 10 }}>
                <span style={{ fontFamily: 'DM Sans', fontSize: 13, color: 'var(--tx-3)' }}>{k}</span>
                <span style={{ fontFamily: 'JetBrains Mono', fontSize: 14, color: 'var(--success)', fontWeight: 500 }}>{v}</span>
              </div>
            ))}
          </div>
        </div>
        <div className="hidden lg:flex items-center justify-center" style={{ width: 80 }}>
          <div style={{ position: 'relative' }}>
            <div style={{ fontFamily: 'JetBrains Mono', fontSize: 9, color: 'var(--tx-3)', letterSpacing: '.18em', textAlign: 'center', marginBottom: 8 }}>5 YEARS LATER</div>
            <div style={{ width: 80, height: 1, background: 'linear-gradient(90deg, var(--success), var(--gold), #EF4444)' }} />
            <div style={{ position: 'absolute', right: -2, top: 13, fontSize: 24, color: '#EF4444', lineHeight: 0 }}>▶</div>
          </div>
        </div>
        <div className="glass p-8" style={{ borderColor: 'rgba(239,68,68,0.25)', background: 'linear-gradient(180deg, rgba(239,68,68,0.04), rgba(255,255,255,0.02))' }}>
          <div style={{ fontFamily: 'JetBrains Mono', fontSize: 11, letterSpacing: '.16em', color: '#EF4444', fontWeight: 600 }}>2026 · MATURITY</div>
          <div className="font-serif mt-2" style={{ fontSize: 22, color: 'var(--tx-1)', fontWeight: 500 }}>The bill comes due.</div>
          <div className="mt-6 flex flex-col gap-3">
            {right.map(([k, v, red]) => (
              <div key={k} className="flex justify-between items-baseline" style={{ borderBottom: '1px solid rgba(255,255,255,0.04)', paddingBottom: 10 }}>
                <span style={{ fontFamily: 'DM Sans', fontSize: 13, color: 'var(--tx-3)' }}>{k}</span>
                <span style={{ fontFamily: 'JetBrains Mono', fontSize: 14, color: red ? '#EF4444' : 'var(--tx-1)', fontWeight: red ? 700 : 500 }}>{v}</span>
              </div>
            ))}
          </div>
          <div className="mt-6 text-center" style={{ fontFamily: 'JetBrains Mono', fontSize: 11, letterSpacing: '.18em', color: '#EF4444', textTransform: 'uppercase', fontWeight: 600 }}>
            × Multiply by Thousands of Properties
          </div>
        </div>
      </div>
    </div>
  );
}

// ─── Trophy Carnage ───────────────────────────────────────
function TrophyCarnage() {
  // Each card uses an abstract architectural SVG pattern as a placeholder background
  // until real building photographs are dropped in. The dark overlay keeps text
  // legible no matter what's behind it.
  const props = [
    { name: '311 S. Wacker',          loc: 'Chicago, IL',        pct: '−85%', sale: 'Sold $45M  ·  Peak $302M',   img: 'uploads/311%20S%20Wacker%20Chicago%2C%20IL.jpg' },
    { name: 'Market Center',          loc: 'San Francisco, CA',  pct: '−76%', sale: 'Sold $177M ·  Peak $722M',   img: 'uploads/Market%20Center%20San%20Francisco%20CA.jpg' },
    { name: 'One Financial Center',   loc: 'Boston, MA',         pct: '−64%', sale: 'Sold $396M ·  Peak $1.1B',   img: 'uploads/One%20Financial%20Center%20Boston%20MA.webp' },
    { name: '1221 Ave of Americas',   loc: 'New York, NY',       pct: '−60%', sale: 'Sold $880M ·  Peak $2.2B',   img: 'uploads/1221%20Ave%20of%20Americas%20New%20York%20NY.png' },
    { name: '600 W. Chicago',         loc: 'Chicago, IL',        pct: '−82%', sale: 'Sold $88.7M ·  Peak $510M',  img: 'uploads/600%20W%20Chicago%20Chicago%20IL.jpg' },
  ];
  return (
    <div className="fade-up mt-24">
      <div className="flex items-baseline justify-between flex-wrap gap-3" style={{ marginBottom: 28 }}>
        <div style={{ fontFamily: 'JetBrains Mono', fontSize: 11, letterSpacing: '.18em', textTransform: 'uppercase', color: 'var(--tx-3)' }}>
          — Trophy Property Carnage
        </div>
        <div className="font-serif" style={{ fontStyle: 'italic', fontSize: 15, color: 'var(--gold)' }}>
          Completed transactions. Not projections.
        </div>
      </div>
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-5">
        {props.map((p, i) => (
          <div key={i} className="hover-card" style={{
            position: 'relative', aspectRatio: '3 / 4', minHeight: 360,
            borderRadius: 14, overflow: 'hidden',
            border: '1px solid rgba(239,68,68,0.18)',
            background: '#141B24',
          }}>
            <div style={{
              position: 'absolute', inset: 0,
              backgroundImage: `url("${p.img}")`,
              backgroundSize: 'cover',
              backgroundPosition: 'center center',
              backgroundRepeat: 'no-repeat',
            }}/>
            {/* Dark overlay per spec */}
            <div style={{ position: 'absolute', inset: 0, background: 'rgba(7,9,15,0.75)' }}/>
            {/* Subtle red wash to reinforce distress */}
            <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(180deg, rgba(239,68,68,0) 0%, rgba(239,68,68,0.08) 100%)' }}/>
            {/* Content */}
            <div style={{ position: 'absolute', inset: 0, padding: 22, display: 'flex', flexDirection: 'column', justifyContent: 'space-between' }}>
              <div>
                <div style={{ fontFamily: 'JetBrains Mono', fontSize: 9.5, letterSpacing: '.18em', color: 'rgba(239,68,68,0.85)', fontWeight: 600 }}>
                  ● DISTRESSED SALE
                </div>
                <div className="font-serif" style={{ fontSize: 19, color: 'var(--tx-1)', fontWeight: 600, lineHeight: 1.2, marginTop: 12, textShadow: '0 2px 8px rgba(0,0,0,0.6)' }}>
                  {p.name}
                </div>
                <div style={{ fontFamily: 'JetBrains Mono', fontSize: 10.5, color: 'var(--tx-2)', letterSpacing: '.08em', marginTop: 4 }}>
                  {p.loc}
                </div>
              </div>
              <div>
                <div className="font-serif" style={{
                  fontSize: 'clamp(56px, 7vw, 78px)', fontWeight: 700, color: '#EF4444',
                  lineHeight: 0.95, letterSpacing: '-0.04em',
                  textShadow: '0 4px 24px rgba(239,68,68,0.35)',
                }}>
                  {p.pct}
                </div>
                <div style={{ height: 1, background: 'linear-gradient(90deg, rgba(239,68,68,0.5), transparent)', marginTop: 14, marginBottom: 12 }}/>
                <div style={{ fontFamily: 'JetBrains Mono', fontSize: 11, color: 'var(--tx-1)', lineHeight: 1.5, fontWeight: 500 }}>
                  {p.sale}
                </div>
              </div>
            </div>
          </div>
        ))}
      </div>
      <div className="mt-6" style={{ fontFamily: 'JetBrains Mono', fontSize: 11, color: 'var(--tx-3)', letterSpacing: '.04em', lineHeight: 1.6 }}>
        Source: Public transaction records. Full analysis available in the Maturity Wall Intelligence Briefing.
      </div>
    </div>
  );
}


// ─── Maturity Wall (The Opportunity) ──────────────────────
function MaturityWall() {
  const stats = [
  { label: 'Total Maturities', value: '$2.2T', sub: '2024–2027' },
  { label: '2026 Peak Year', value: '$891B', sub: 'Largest single-year CRE maturity in history' },
  { label: 'Institutional Dry Powder', value: '$300B+', sub: 'Raised for distressed CRE' },
  { label: 'Regional Bank Exposure', value: '70%', sub: 'Of all CRE debt held by 4,700 regional banks' }];

  return (
    <section id="the-opportunity" style={{ background: 'var(--bg-1)', padding: '140px 0', position: 'relative' }}>
      <div className="mx-auto px-6 lg:px-10" style={{ maxWidth: 1400 }}>
        <div className="fade-up section-label">The Opportunity</div>
        <h2 className="fade-up h-display mt-6" style={{ fontSize: 'clamp(2.5rem, 5vw, 4.2rem)', maxWidth: 1000 }}>
          The $2.2 Trillion <span style={{ fontStyle: 'italic', color: 'var(--gold)' }}>Maturity Wall</span>
        </h2>
        <p className="fade-up body-copy mt-8" style={{ maxWidth: 720 }}>
          Between 2024 and 2027, $2.2 trillion in commercial real estate loans are contractually set to mature — the largest refinancing challenge in history. This isn't a projection or a theory. The loans have already been written, and their maturity dates are already locked. What's unfolding right now is potentially the most significant real estate dislocation since 2008 — and the institutions with the most experience are already moving.
        </p>

        <div className="grid md:grid-cols-2 lg:grid-cols-4 gap-px mt-16 fade-up" style={{ background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.06)', borderRadius: 14, overflow: 'hidden' }}>
          {stats.map((s, i) =>
          <div key={i} className="p-8 text-center" style={{ background: 'var(--bg-2)' }}>
              <div style={{ fontFamily: 'JetBrains Mono', fontSize: 10, letterSpacing: '.16em', textTransform: 'uppercase', color: 'var(--tx-3)' }}>{s.label}</div>
              <div className="metric-num mt-5" style={{ fontSize: 'clamp(2.4rem, 3.6vw, 3.4rem)' }}>{s.value}</div>
              <div className="mt-3" style={{ fontFamily: 'DM Sans', fontSize: 13, color: 'var(--tx-3)', maxWidth: 220, margin: '12px auto 0' }}>{s.sub}</div>
            </div>
          )}
        </div>

        <div className="divider-gold mt-16" />

        <MaturityChart />

        <MathComparison />

        <TrophyCarnage />

        <div className="grid lg:grid-cols-2 gap-x-16 gap-y-6 mt-20">
          <div className="fade-up body-copy" style={{ maxWidth: 680 }}>
            <p>Properties purchased during the low-rate era at compressed cap rates now face a mathematical impossibility: buildings bought at 3% cap rates with loans at 3% interest are now worth far less than their outstanding loan balances at today's rates. Owners lose 100% of equity. Lenders face massive losses. This is not theoretical — trophy properties in New York, Chicago, San Francisco, and Boston have already sold at 60–85% discounts to peak valuations. These are completed transactions.</p>
            <p style={{ marginTop: 18 }}>January 1, 2026 marks a regulatory catalyst — the end of "extend and pretend." Mandatory mark-to-market requirements, quarterly property reappraisals, and elimination of interest-only modifications will force banks to recognize losses they've been deferring for years. The cascade of forced sales, restructurings, and loan liquidations will accelerate through 2026 and 2027.</p>
          </div>
          <div className="fade-up body-copy" style={{ maxWidth: 680, transitionDelay: '.15s' }}>
            <p>The largest private equity firms in the world — Brookfield, Blackstone, Apollo, Oaktree, KKR — have collectively raised over $300 billion in dry powder specifically for this cycle. They are already deploying capital into distressed commercial real estate. The opportunity is not future tense. It is happening now.</p>
            <div className="mt-10 flex flex-col md:flex-row md:items-end gap-8 justify-between" style={{ borderTop: '1px solid var(--bd)', paddingTop: 32 }}>
              <p className="font-serif" style={{ fontStyle: 'italic', fontSize: 22, color: 'var(--gold)', maxWidth: 460, lineHeight: 1.4, margin: 0 }}>
                "The greatest commercial real estate wealth transfer in American history is already in progress. The Terminal is how you participate."
              </p>
              <a href="https://drive.google.com/file/d/1fgq4h9Ym0C9XqBHQJ0YEKHm6RwtbkeJ5/view?usp=sharing" target="_blank" rel="noopener noreferrer" style={{
                fontFamily: 'JetBrains Mono', fontSize: 13, letterSpacing: '.1em', color: '#07090F',
                textDecoration: 'none', whiteSpace: 'nowrap', textTransform: 'uppercase', fontWeight: 700,
                background: '#C9A962', padding: '14px 26px', borderRadius: 8,
                boxShadow: '0 0 30px rgba(201,169,98,0.2)', display: 'inline-block', alignSelf: 'flex-start',
              }}>
                Download the Briefing &nbsp;→
              </a>
            </div>
          </div>
        </div>
      </div>
    </section>);

}

Object.assign(window, { useReveal, Counter, ScrollBar, Nav, Hero, WhatIsTerminal, MaturityWall, MaturityChart, MathComparison, TrophyCarnage });