// markflord — landing page sections (editorial register).
// Reuses the Spine maker's mark from monograms.jsx. Dark default; paper toggle.

const { useState, useEffect, useRef } = React;

const isLight = () => document.documentElement.getAttribute('data-theme') === 'light';

// theme-aware mark wrapper (Spine is the lead direction)
function Mark({ size, forged }) {
  const [, force] = useState(0);
  useEffect(() => {
    const o = new MutationObserver(() => force((n) => n + 1));
    o.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] });
    return () => o.disconnect();
  }, []);
  return <MonoSerifMolten size={size} forged={forged} light={isLight()} />;
}

function Kicker({ children, style, className }) {
  return <div className={'meta' + (className ? ' ' + className : '')} style={{ color: 'var(--ember)', ...style }}>{children}</div>;
}

// ── Masthead ────────────────────────────────────────────────────────────────
const PRESENTATIONS = [
  ['Forge — Investor Deck', '/forge · interactive', '/forge'],
  ['Forge — One-pager', '/onepage · web', '/onepage'],
  ['Forge — The Thesis', '/thesis · XVI chapters', '/thesis'],
];

function Masthead({ theme, toggle }) {
  const [pres, setPres] = useState(false);
  const [menu, setMenu] = useState(false);
  useEffect(() => {
    const h = (e) => { if (!e.target.closest('.pres-wrap')) setPres(false); };
    document.addEventListener('click', h);
    return () => document.removeEventListener('click', h);
  }, []);
  const close = () => { setPres(false); setMenu(false); };
  return (
    <header style={{ position: 'sticky', top: 0, zIndex: 40, background: 'color-mix(in srgb, var(--bg) 92%, transparent)',
      backdropFilter: 'blur(10px)', borderBottom: '1px solid var(--hair)' }}>
      <div className="wrap" style={{ display: 'flex', alignItems: 'center', height: 68, gap: 24 }}>
        <a href="#top" onClick={close} style={{ display: 'flex', alignItems: 'center', gap: 13, textDecoration: 'none', color: 'var(--fg)' }}>
          <Mark size={34} forged={false} />
          <span className="cinzel" style={{ fontWeight: 600, fontSize: 17, letterSpacing: '0.18em' }}>MARK&nbsp;LORD</span>
        </a>
        <nav className="mast-desktop" style={{ display: 'flex', alignItems: 'center', gap: 26, marginLeft: 14, fontSize: 13, fontWeight: 500 }}>
          <a className="navlink" href="#maker">The Maker</a>
          <a className="navlink" href="#hyperion">Hyperion</a>
          <a className="navlink" href="#work">Work</a>
          <div className="pres-wrap" style={{ position: 'relative' }}>
            <button className="navlink" onClick={() => setPres(o => !o)} style={{ background: 'none', border: 0, padding: 0, font: 'inherit', fontWeight: 500, cursor: 'pointer', display: 'inline-flex', alignItems: 'center', gap: 6, color: pres ? 'var(--fg)' : undefined }}>
              Presentations <span style={{ fontSize: 8, opacity: 0.6, display: 'inline-block', transform: pres ? 'rotate(180deg)' : 'none', transition: 'transform .2s' }}>▼</span>
            </button>
            {pres && (
              <div className="pres-menu">
                {PRESENTATIONS.map(([t, sub, href]) => (
                  <a key={href} href={href} className="pres-item" onClick={close}>
                    <span className="serif" style={{ fontSize: 16, color: 'var(--fg)' }}>{t}</span>
                    <span className="meta-sm" style={{ color: 'var(--fg-3)' }}>{sub}</span>
                  </a>
                ))}
                <div className="meta-sm" style={{ color: 'var(--fg-3)', padding: '12px 16px' }}>More as the foundry grows →</div>
              </div>
            )}
          </div>
        </nav>
        <div style={{ flex: 1 }} />
        <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
          <a className="navlink mast-desktop" href="mailto:mark@dominusfoundry.com" style={{ fontSize: 13, fontWeight: 500 }}>Contact</a>
          <button className="toggle" onClick={toggle}>{theme === 'dark' ? '☀ Paper' : '☾ Ink'}</button>
          <button className="burger" aria-label="Menu" aria-expanded={menu} onClick={() => setMenu(o => !o)}>
            <span style={{ display: 'block', width: 16, height: 11, position: 'relative' }}>
              <span style={{ position: 'absolute', left: 0, right: 0, top: menu ? 5 : 0, height: 1.5, background: 'currentColor', transform: menu ? 'rotate(45deg)' : 'none', transition: 'all .2s' }} />
              <span style={{ position: 'absolute', left: 0, right: 0, top: 5, height: 1.5, background: 'currentColor', opacity: menu ? 0 : 1, transition: 'opacity .2s' }} />
              <span style={{ position: 'absolute', left: 0, right: 0, top: menu ? 5 : 10, height: 1.5, background: 'currentColor', transform: menu ? 'rotate(-45deg)' : 'none', transition: 'all .2s' }} />
            </span>
          </button>
        </div>
      </div>
      {menu && (
        <div className="mmenu">
          <a className="mm-link" href="#maker" onClick={close}>The Maker</a>
          <a className="mm-link" href="#hyperion" onClick={close}>Hyperion</a>
          <a className="mm-link" href="#work" onClick={close}>Work</a>
          <div className="mm-sec">Presentations</div>
          {PRESENTATIONS.map(([t, sub, href]) => (
            <a key={href} href={href} className="mm-link mm-sub" onClick={close}>{t}<span className="meta-sm" style={{ color: 'var(--fg-3)', marginLeft: 10 }}>{sub}</span></a>
          ))}
          <a className="mm-link" href="mailto:mark@dominusfoundry.com" onClick={close}>Contact</a>
        </div>
      )}
    </header>
  );
}

// ── Hero ────────────────────────────────────────────────────────────────────
// Hero monogram — EXACTLY variant IV (Molten L) from the Monogram Motion page:
// Cinzel M (steel) + L (molten ember), looping forge via the shared .amk-* classes.
function HeroMark() {
  const u = 'heromk';
  const M = (fill, cls) => <text className={cls} x="112" y="152" fontSize="152" fontFamily="'Cinzel', serif" fontWeight="600" textAnchor="middle" fill={fill}>M</text>;
  const L = (fill, cls) => <text className={cls} x="192" y="176" fontSize="132" fontFamily="'Cinzel', serif" fontWeight="600" textAnchor="middle" fill={fill}>L</text>;
  return (
    <svg className="amk" viewBox="0 0 300 224" style={{ width: '100%', display: 'block', overflow: 'visible' }}>
      <defs>
        <linearGradient id={`${u}-steel`} x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor="#5A5142" /><stop offset="0.5" stopColor="#2C261C" /><stop offset="1" stopColor="#16110B" /></linearGradient>
        <linearGradient id={`${u}-ember`} x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor="#FFE6C2" /><stop offset="0.45" stopColor="#FF5B1F" /><stop offset="1" stopColor="#9A3408" /></linearGradient>
        <radialGradient id={`${u}-glow`} cx="0.5" cy="0.5" r="0.5"><stop offset="0" stopColor="#FF7A3D" stopOpacity="0.85" /><stop offset="0.6" stopColor="#FF5B1F" stopOpacity="0.3" /><stop offset="1" stopColor="#FF5B1F" stopOpacity="0" /></radialGradient>
        <radialGradient id={`${u}-flash`} cx="0.5" cy="0.5" r="0.5"><stop offset="0" stopColor="#FFFFFF" /><stop offset="0.4" stopColor="#FFE9C8" stopOpacity="0.9" /><stop offset="1" stopColor="#FF7A3D" stopOpacity="0" /></radialGradient>
        <filter id={`${u}-emb`} x="-30%" y="-30%" width="160%" height="170%"><feDropShadow dx="0" dy="3" stdDeviation="2.5" floodColor="#000" floodOpacity="0.55" /></filter>
      </defs>
      <ellipse className="amk-glow" cx="158" cy="150" rx="128" ry="86" fill={`url(#${u}-glow)`} />
      <g className="amk-m" filter={`url(#${u}-emb)`}>{M(`url(#${u}-steel)`)}</g>
      <g className="amk-l" filter={`url(#${u}-emb)`}>{L(`url(#${u}-ember)`)}</g>
      <g className="amk-hot">{M('#FFF6E8')}{L('#FFF6E8')}</g>
      <circle className="amk-flash" cx="158" cy="150" r="48" fill={`url(#${u}-flash)`} />
    </svg>
  );
}

function Hero() {
  return (
    <section id="top" style={{ position: 'relative', isolation: 'isolate', overflow: 'hidden', borderBottom: '1px solid var(--hair)' }}>
      <div className="embers" aria-hidden="true">
        {Array.from({ length: 16 }).map((_, i) => (
          <span key={i} className="ember-bit" style={{ left: (i * 53 % 100) + '%', width: 1.5 + (i % 3), height: 1.5 + (i % 3),
            animationDuration: (7 + (i % 5) * 1.5) + 's', animationDelay: -(i * 1.3) + 's' }} />
        ))}
      </div>
      <div style={{ position: 'absolute', inset: 0, zIndex: -1,
        background: 'radial-gradient(ellipse 60% 55% at 76% 30%, rgba(255,91,31,0.16) 0%, transparent 58%)' }} />
      <div className="wrap" style={{ padding: '70px 56px 64px' }}>
        <div className="hero-grid" style={{ display: 'grid', gridTemplateColumns: '1.15fr 0.85fr', gap: 48, alignItems: 'center' }}>
          {/* left — copy */}
          <div>
            <Kicker className="rise-in" style={{ transitionDelay: '.05s' }}>Founder · Systems Architect · Maker</Kicker>
            <h1 className="serif hero-h1 rise-in" style={{ transitionDelay: '.12s', margin: '20px 0 0', fontWeight: 400,
              fontSize: 'clamp(44px, 5.4vw, 76px)', lineHeight: 0.98, letterSpacing: '-0.035em', textWrap: 'balance' }}>
              I build the systems<br />businesses <span style={{ color: 'var(--ember)' }}>run on</span>.
            </h1>
            <p className="ital rise-in" style={{ transitionDelay: '.2s', fontSize: 'clamp(19px,2vw,23px)', color: 'var(--fg-2)',
              margin: '22px 0 0', maxWidth: 480, lineHeight: 1.4 }}>
              — and the software factory behind them.
            </p>
            <div className="rise-in" style={{ transitionDelay: '.3s', display: 'flex', alignItems: 'center', gap: 16, margin: '34px 0 0' }}>
              <div style={{ width: 40, height: 1, background: 'var(--ember)', boxShadow: '0 0 10px var(--ember)' }} />
              <span className="meta-sm" style={{ color: 'var(--fg-3)' }}>Forged, not printed · Owned software, not rented tools</span>
            </div>
          </div>
          {/* right — the mark, struck */}
          <div style={{ display: 'flex', justifyContent: 'center' }}>
            <div style={{ position: 'relative', display: 'grid', placeItems: 'center', padding: '14px 0' }}>
              <div style={{ position: 'absolute', width: 260, height: 260, borderRadius: '50%',
                background: 'radial-gradient(circle, rgba(255,91,31,0.22) 0%, transparent 62%)' }} />
              <div className="hero-mark" style={{ width: 230, position: 'relative' }}>
                <HeroMark />
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ── The Maker ─────────────────────────────────────────────────────────────
function Stat({ v, k }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 6, minWidth: 92 }}>
      <span className="serif" style={{ fontSize: 26, lineHeight: 1, color: 'var(--fg)', letterSpacing: '-0.01em' }}>{v}</span>
      <span className="meta-sm" style={{ color: 'var(--fg-3)' }}>{k}</span>
    </div>
  );
}

function VenturePlate({ name, role, href, ext }) {
  return (
    <a className="plate" href={href} target="_blank" rel="noreferrer"
      style={{ minHeight: 0, padding: '18px 20px', display: 'flex', flexDirection: 'column', gap: 8 }}>
      <span className="serif" style={{ fontSize: 20, color: 'var(--fg)', letterSpacing: '-0.01em', lineHeight: 1.12 }}>{name}</span>
      <span className="ital" style={{ fontSize: 14, lineHeight: 1.4, color: 'var(--fg-2)' }}>{role}</span>
      <span className="open meta-sm" style={{ color: 'var(--ember)', marginTop: 4, wordBreak: 'break-word' }}>{ext}</span>
    </a>
  );
}

function Maker() {
  return (
    <section id="maker" className="wrap" style={{ padding: '64px 56px 24px', borderTop: '1px solid var(--hair)' }}>
      <div className="maker-grid" style={{ display: 'grid', gridTemplateColumns: '400px 1fr', gap: 56, alignItems: 'start' }}>
        {/* portrait */}
        <figure style={{ margin: 0 }}>
          <div style={{ position: 'relative', border: '1px solid var(--hair-2)', overflow: 'hidden', background: '#0E0C08' }}>
            <img className="maker-port" src="assets/mark-lord.png" alt="Mark Lord" style={{ display: 'block', width: '100%', height: 520, objectFit: 'cover', objectPosition: 'center 12%',
              filter: 'grayscale(0.38) sepia(0.26) saturate(1) contrast(1.05) brightness(1.06)' }} />
            <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(180deg, transparent 58%, rgba(14,12,8,0.72) 100%)' }} />
            <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(ellipse 90% 45% at 72% 6%, rgba(255,91,31,0.13), transparent 60%)', mixBlendMode: 'screen' }} />
            {[['top','left'],['top','right'],['bottom','left'],['bottom','right']].map(([v,h],i) => (
              <span key={i} style={{ position:'absolute', [v]:10, [h]:10, width:13, height:13,
                borderTop: v==='top'?'1.5px solid var(--ember)':'none', borderBottom: v==='bottom'?'1.5px solid var(--ember)':'none',
                borderLeft: h==='left'?'1.5px solid var(--ember)':'none', borderRight: h==='right'?'1.5px solid var(--ember)':'none', opacity:0.9 }} />
            ))}
            <div style={{ position: 'absolute', left: 18, right: 18, bottom: 16, display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
              <span className="cinzel" style={{ fontSize: 16, fontWeight: 600, letterSpacing: '0.16em', color: 'var(--cream)' }}>MARK&nbsp;LORD</span>
              <span className="meta-sm" style={{ color: 'rgba(243,238,228,0.6)' }}>ALBUQUERQUE · NM</span>
            </div>
          </div>
          {/* connect — LinkedIn, directly under the portrait */}
          <a href="https://www.linkedin.com/in/mark-f-lord/" target="_blank" rel="noopener noreferrer"
             className="meta-sm" style={{ display: 'inline-flex', alignItems: 'center', gap: 9, marginTop: 16, color: 'var(--ember)', textDecoration: 'none', letterSpacing: '0.14em' }}>
            <svg width="15" height="15" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.238-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z"/></svg>
            CONNECT ON LINKEDIN
          </a>
          {/* facts ledger — under the portrait, to balance the column */}
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '22px 20px', marginTop: 22, paddingTop: 22, borderTop: '1px solid var(--hair)' }}>
            <Stat v="MMXXV" k="CALLORD · SECURITY &amp; AV" />
            <Stat v="MMXXV" k="DOMINUS FOUNDRY · SOFTWARE" />
            <Stat v="XVI" k="PROVISIONAL PATENTS" />
            <Stat v="ABQ · NM" k="BASE OF OPERATIONS" />
          </div>
        </figure>
        {/* bio */}
        <div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 14, marginBottom: 16 }}>
            <span className="ital" style={{ fontSize: 13, color: 'var(--ember)' }}>i.</span>
            <span style={{ width: 28, height: 1, background: 'var(--hair-2)' }} />
            <span className="meta" style={{ color: 'var(--fg-3)' }}>The Maker</span>
          </div>
          <h2 className="serif" style={{ margin: '0 0 22px', fontWeight: 400, fontSize: 'clamp(28px,3vw,42px)', letterSpacing: '-0.025em', lineHeight: 1.02, textWrap: 'balance' }}>
            An operator long before I was a founder.
          </h2>
          <p className="serif" style={{ margin: '0 0 16px', fontSize: 'clamp(16px,1.4vw,18px)', lineHeight: 1.6, color: 'var(--fg-2)', maxWidth: 640 }}>
            I started in storefronts, not server rooms — two Cold Stone Creamery shops in Albuquerque before I was old enough to know better. Then eighteen months in the labs, on the team that helped bring LED lighting into the world we now take for granted.
          </p>
          <p className="serif" style={{ margin: '0 0 18px', fontSize: 'clamp(16px,1.4vw,18px)', lineHeight: 1.6, color: 'var(--fg-2)', maxWidth: 640 }}>
            Most of the years since I spent in sales and business development — learning, in a few hundred rooms, exactly what the work needs and what the tools keep getting wrong. In 2025 I built two companies to answer it:
            <span style={{ color: 'var(--fg)' }}> CalLord</span>, a commercial security &amp; AV integration firm, and
            <span style={{ color: 'var(--fg)' }}> Dominus Foundry</span>, the software factory behind the trade. CalLord is the proving ground; the Foundry is where the tools get forged.
          </p>
          <p className="ital" style={{ margin: 0, fontSize: 16, lineHeight: 1.5, color: 'var(--fg-2)' }}>
            Built alongside Bri Lord, steward of the work — <span style={{ color: 'var(--fg)' }}>Fide et Familia.</span> By faith and family.
          </p>
          {/* ventures */}
          <div className="meta-sm" style={{ color: 'var(--fg-3)', marginTop: 32, marginBottom: 12, paddingTop: 24, borderTop: '1px solid var(--hair)' }}>Ventures</div>
          <div className="vrow" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 1, background: 'var(--hair)', border: '1px solid var(--hair-2)' }}>
            <VenturePlate name="CalLord Unified Technologies" role="Commercial security &amp; AV integration — Forge's exclusive AV partner." href="https://callordut.com" ext="CALLORDUT.COM ↗" />
            <VenturePlate name="Dominus Foundry" role="The software factory — Forge, Hyperion, the chest." href="https://buildwithforge.app" ext="BUILDWITHFORGE.APP ↗" />
          </div>
        </div>
      </div>
    </section>
  );
}

// ── Hyperion — proprietary instrument, counterweight to The Maker ──────────
function HyperionScan() {
  const w = 440, h = 372, rows = 22, cols = 19;
  const seed = (i) => { const x = Math.sin(i * 9301 + 49297) * 233280; return x - Math.floor(x); };
  const dots = [];
  for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) {
    const u = c / (cols - 1), v = r / (rows - 1);
    const px = u * w, pitch = Math.abs(u - 0.5) * -h * 0.16, py = v * h * 0.66 + h * 0.18 + pitch;
    const dx = u - 0.5, dy = v - 0.5, dist = Math.sqrt(dx * dx + dy * dy), fall = Math.max(0, 1 - dist * 1.35);
    const j = (seed(r * cols + c) - 0.5) * 4, a = Math.pow(fall, 1.2) * (0.32 + seed(r * cols + c + 1) * 0.55);
    dots.push(<circle key={r + '-' + c} cx={(px + j).toFixed(1)} cy={(py + j * 0.6).toFixed(1)} r={(0.9 + v * 0.7).toFixed(2)} fill="#F3EEE4" opacity={a.toFixed(2)} />);
  }
  const hi = [[0.30, 0.40, 'VENT'], [0.63, 0.35, 'HVAC'], [0.78, 0.58, 'SKYLIGHT']];
  return (
    <svg viewBox={`0 0 ${w} ${h}`} preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
      {dots}
      {hi.map(([x, y, l], i) => (
        <g key={i}>
          <circle cx={x * w} cy={y * h} r="11" fill="none" stroke="#FF5B1F" strokeWidth="1" opacity="0.9" />
          <circle cx={x * w} cy={y * h} r="2.4" fill="#FF5B1F" />
          <text x={x * w + 15} y={y * h - 7} fill="#FF5B1F" fontFamily="'JetBrains Mono', monospace" fontSize="8" letterSpacing="0.08em">{l}</text>
        </g>
      ))}
    </svg>
  );
}

// Loads the LiDAR clip via fetch→blob→object URL so it plays even where the
// static host doesn't serve HTTP range requests (and offline once bundled).
function HyperionVideo() {
  const ref = React.useRef(null);
  React.useEffect(() => {
    let url; const el = ref.current; let off = false;
    fetch('assets/hyperion-lidar.mp4').then((r) => r.blob()).then((b) => {
      if (off) return; url = URL.createObjectURL(b);
      if (el) { el.src = url; el.play && el.play().catch(() => {}); }
    }).catch(() => {});
    return () => { off = true; if (url) URL.revokeObjectURL(url); };
  }, []);
  return <video ref={ref} autoPlay loop muted playsInline
    style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', display: 'block' }} />;
}

function Hyperion() {
  return (
    <section id="hyperion" className="wrap" style={{ padding: '64px 56px 24px', borderTop: '1px solid var(--hair)' }}>
      <div className="hyp-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 56, alignItems: 'center' }}>
        {/* text — left (counterweight: portrait was on the left above) */}
        <div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 14, marginBottom: 16 }}>
            <span className="ital" style={{ fontSize: 13, color: 'var(--ember)' }}>ii.</span>
            <span style={{ width: 28, height: 1, background: 'var(--hair-2)' }} />
            <span className="meta" style={{ color: 'var(--fg-3)' }}>Hyperion · Proprietary</span>
          </div>
          <h2 className="serif" style={{ margin: '0 0 20px', fontWeight: 400, fontSize: 'clamp(28px,3.2vw,46px)', letterSpacing: '-0.025em', lineHeight: 1.02, textWrap: 'balance' }}>
            The instrument no one else has.
          </h2>
          <p className="serif" style={{ margin: '0 0 16px', fontSize: 'clamp(16px,1.4vw,18px)', lineHeight: 1.6, color: 'var(--fg-2)', maxWidth: 520 }}>
            Hyperion is iOS-native spatial-AI scanning — point a phone at a roof and hold a measured estimate sixty seconds later. Built in the field, protected by patent, and shipped on no one else's stack.
          </p>
          <p className="ital" style={{ margin: '0 0 24px', fontSize: 16, color: 'var(--fg-2)' }}>
            Owned, not licensed. <span style={{ color: 'var(--fg)' }}>One of one.</span>
          </p>
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: '22px 40px', margin: '0 0 26px', paddingTop: 22, borderTop: '1px solid var(--hair)' }}>
            <Stat v="60s" k="SCAN TO ESTIMATE" />
            <Stat v="iOS" k="NATIVE · iPADOS" />
            <Stat v="XVI" k="PATENTS · PROTECTED" />
            <Stat v="1 / 1" k="ONE OF A KIND" />
          </div>
          <a href="#work" style={{ display: 'inline-flex', alignItems: 'center', gap: 10, fontFamily: "'JetBrains Mono', monospace", fontSize: 10, letterSpacing: '0.22em', textTransform: 'uppercase', color: 'var(--ember)', textDecoration: 'none', borderBottom: '1px solid var(--ember)', paddingBottom: 4 }}>
            Open the Hyperion chapter →
          </a>
        </div>
        {/* scan — right */}
        <div className="hyp-scan">
          <HyperionVideo />
          {[['top', 'left'], ['top', 'right'], ['bottom', 'left'], ['bottom', 'right']].map(([vv, hh], i) => (
            <span key={i} style={{ position: 'absolute', [vv]: 10, [hh]: 10, width: 14, height: 14,
              borderTop: vv === 'top' ? '1.5px solid var(--ember)' : 'none', borderBottom: vv === 'bottom' ? '1.5px solid var(--ember)' : 'none',
              borderLeft: hh === 'left' ? '1.5px solid var(--ember)' : 'none', borderRight: hh === 'right' ? '1.5px solid var(--ember)' : 'none', opacity: 0.85 }} />
          ))}
          <div style={{ position: 'absolute', top: 14, left: 16, display: 'flex', alignItems: 'center', gap: 8 }}>
            <span className="live-dot" /><span className="meta-sm" style={{ color: 'rgba(243,238,228,0.78)' }}>HYPERION · LIVE</span>
          </div>
          <div style={{ position: 'absolute', left: 16, right: 16, bottom: 14, display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end',
            background: 'rgba(10,8,6,0.55)', border: '1px solid var(--hair)', backdropFilter: 'blur(6px)', padding: '10px 13px' }}>
            <div>
              <div className="meta-sm" style={{ color: 'var(--ember)', marginBottom: 5 }}>SCAN COMPLETE · 47s</div>
              <div style={{ fontFamily: "'Fraunces', serif", fontSize: 16, color: 'var(--cream)' }}>4,820 sq ft · 1/12 pitch</div>
            </div>
            <span className="meta-sm" style={{ color: 'var(--fg-3)' }}>iPADOS</span>
          </div>
        </div>
      </div>
    </section>
  );
}

// ── Work plates ──────────────────────────────────────────────────────────────
const WORK = [
  { n: 'I', fam: 'Forge', title: 'Investor Deck', voice: 'The case, the numbers, the moat — for the room.', meta: 'INTERACTIVE · /FORGE', span: 1, href: '/forge' },
  { n: 'II', fam: 'Forge', title: 'The One-pager', voice: 'The whole platform on a single plate.', meta: 'WEB · ONE PAGE', span: 1, href: '/onepage' },
  { n: 'III', fam: 'Forge', title: 'The Thesis', voice: 'Sixteen chapters on why the old tools were lying.', meta: 'FULL THESIS · XVI', span: 1, href: '/thesis' },
  { n: 'IV', fam: 'Hyperion', title: 'Spatial-AI Scanning', voice: 'Scan a roof, hold an estimate. Sixty seconds.', meta: 'iOS-NATIVE · LIVE', span: 2 },
  { n: 'V', fam: 'DominusOS', title: 'First Principles', voice: 'The public case for owned, not rented.', meta: 'PUBLIC THESIS', span: 1 },
];

function Plate({ item }) {
  return (
    <a className="plate" href={item.soon ? undefined : (item.href || '#work')} style={{ gridColumn: 'span ' + item.span, minHeight: 224,
      display: 'flex', flexDirection: 'column', cursor: item.soon ? 'default' : 'pointer' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
        <span className="serif plate-num" style={{ fontSize: 34, lineHeight: 1, color: 'var(--fg-3)', letterSpacing: '0.02em' }}>{item.n}</span>
        <span className="meta-sm" style={{ color: 'var(--ember)' }}>{item.fam}</span>
      </div>
      <div style={{ flex: 1 }} />
      <div>
        <div className="serif" style={{ fontSize: item.span === 2 ? 34 : 27, fontWeight: 400, letterSpacing: '-0.02em',
          lineHeight: 1.05, color: 'var(--fg)', marginBottom: 10 }}>{item.title}</div>
        <p className="ital" style={{ margin: 0, fontSize: 15.5, lineHeight: 1.45, color: 'var(--fg-2)', maxWidth: item.span === 2 ? 440 : 320 }}>{item.voice}</p>
      </div>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginTop: 20,
        paddingTop: 14, borderTop: '1px solid var(--hair)' }}>
        <span className="meta-sm" style={{ color: 'var(--fg-3)' }}>{item.meta}</span>
        <span className="open meta-sm" style={{ color: item.soon ? 'var(--fg-3)' : 'var(--fg-2)' }}>{item.soon ? 'SOON' : 'OPEN →'}</span>
      </div>
    </a>
  );
}

function Work() {
  return (
    <section id="work" className="wrap" style={{ padding: '64px 56px 30px' }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 14, marginBottom: 8 }}>
        <span className="ital" style={{ fontSize: 13, color: 'var(--ember)' }}>iii.</span>
        <span style={{ width: 28, height: 1, background: 'var(--hair-2)' }} />
        <span className="meta" style={{ color: 'var(--fg-3)' }}>The Index — every link a forged plate</span>
      </div>
      <h2 className="serif" style={{ margin: '0 0 32px', fontWeight: 400, fontSize: 'clamp(30px,3.4vw,46px)',
        letterSpacing: '-0.025em', lineHeight: 1 }}>The work, struck into steel.</h2>
      <div className="work-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 1,
        background: 'var(--hair)', border: '1px solid var(--hair-2)' }}>
        {WORK.map((it) => <Plate key={it.n} item={it} />)}
      </div>
    </section>
  );
}

// ── Contact + Footer ─────────────────────────────────────────────────────────
function Footer() {
  return (
    <footer className="wrap" style={{ padding: '40px 56px 56px' }}>
      <div className="molten" style={{ marginBottom: 34 }} />
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 24 }}>
        <div>
          <div className="meta-sm" style={{ color: 'var(--fg-3)', marginBottom: 12 }}>The door is open</div>
          <a className="email serif" href="mailto:mark@dominusfoundry.com" style={{ fontSize: 'clamp(20px,2.6vw,30px)', letterSpacing: '-0.02em' }}>mark@dominusfoundry.com</a>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 16, textAlign: 'right' }}>
          <div>
            <div className="ital" style={{ fontSize: 16, color: 'var(--fg)', letterSpacing: '0.04em' }}>Fide et Familia</div>
            <div className="meta-sm" style={{ color: 'var(--fg-3)', marginTop: 6 }}>MARK LORD · MMXXVI</div>
          </div>
          <Mark size={40} forged={false} />
        </div>
      </div>
    </footer>
  );
}

function Site() {
  const [theme, setTheme] = useState(document.documentElement.getAttribute('data-theme') || 'dark');
  const toggle = () => setTheme((t) => {
    const n = t === 'dark' ? 'light' : 'dark';
    document.documentElement.setAttribute('data-theme', n);
    try { localStorage.setItem('ml-theme', n); } catch {}
    return n;
  });
  return (
    <div style={{ minHeight: '100vh' }}>
      <Masthead theme={theme} toggle={toggle} />
      <Hero />
      <Maker />
      <Hyperion />
      <Work />
      <Footer />
    </div>
  );
}

window.Site = Site;
