// Variant E — Brutal Mono, hi-fi standalone build for maroun.au
// Paper + ink + magenta. Terminal whoami. Crab AI drawer.

const { useState, useEffect, useRef } = React;

const INK = '#0a0a0a';
const PAPER = '#f5f3ec';
const PAPER_DIM = '#ebe8df';
const ACCENT = '#ff2bd6';

// ─────────────────────────────────────────────────────────────
// RESPONSIVE HOOK
// ─────────────────────────────────────────────────────────────
function useIsMobile(breakpoint = 768) {
  const [isMobile, setIsMobile] = useState(() => window.innerWidth < breakpoint);
  useEffect(() => {
    function onResize() { setIsMobile(window.innerWidth < breakpoint); }
    window.addEventListener('resize', onResize);
    return () => window.removeEventListener('resize', onResize);
  }, [breakpoint]);
  return isMobile;
}

// ─────────────────────────────────────────────────────────────
// TOP BAR
// ─────────────────────────────────────────────────────────────
// ─────────────────────────────────────────────────────────────
// GLOBAL AUDIO — singleton that persists across navigation
// ─────────────────────────────────────────────────────────────
const globalAudio = (() => {
  const audio = new Audio();
  audio.preload = 'metadata';
  return {
    el: audio,
    tracks: [],
    idx: 0,
    playing: false,
    userInteracted: false,
    loaded: false,
    listeners: new Set(),
    notify() { this.listeners.forEach(fn => fn()); },
    init() {
      if (this.loaded) return;
      this.loaded = true;
      fetch('audio-web/manifest.json')
        .then(r => r.json())
        .then(list => {
          const tgIdx = list.findIndex(t => t.includes('top-gun-anthem'));
          const first = tgIdx >= 0 ? list.splice(tgIdx, 1)[0] : null;
          for (let i = list.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [list[i], list[j]] = [list[j], list[i]];
          }
          if (first) list.unshift(first);
          this.tracks = list;
          this.el.src = list[0] || '';
          this.notify();
        }).catch(() => {});
      this.el.addEventListener('ended', () => this.skip(1));
      this.el.addEventListener('timeupdate', () => this.notify());
      this.el.addEventListener('loadedmetadata', () => this.notify());
      // autoplay on first interaction
      const onInteract = () => {
        if (this.userInteracted) return;
        this.userInteracted = true;
        if (this.idx === 0) this.el.currentTime = 13;
        this.el.play().then(() => { this.playing = true; this.notify(); }).catch(() => {});
        window.removeEventListener('click', onInteract);
        window.removeEventListener('keydown', onInteract);
      };
      window.addEventListener('click', onInteract);
      window.addEventListener('keydown', onInteract);
    },
    skip(dir) {
      if (!this.tracks.length) return;
      this.idx = (this.idx + dir + this.tracks.length) % this.tracks.length;
      this.el.src = this.tracks[this.idx];
      this.el.load();
      if (this.playing || this.userInteracted) {
        this.el.play().then(() => { this.playing = true; this.notify(); }).catch(() => {});
      }
      this.notify();
    },
    toggle() {
      if (!this.userInteracted) this.userInteracted = true;
      if (this.playing) { this.el.pause(); this.playing = false; }
      else { this.el.play().then(() => { this.playing = true; }).catch(() => {}); }
      this.notify();
    },
  };
})();

function useAudio() {
  const [, forceUpdate] = useState(0);
  useEffect(() => {
    globalAudio.init();
    const cb = () => forceUpdate(n => n + 1);
    globalAudio.listeners.add(cb);
    return () => globalAudio.listeners.delete(cb);
  }, []);
  const a = globalAudio;
  const trackName = a.tracks[a.idx] ? a.tracks[a.idx].replace('audio-web/', '').replace('.opus', '').replace(/-/g, ' ').toUpperCase() : '---';
  return { playing: a.playing, trackName, elapsed: a.el.currentTime || 0, duration: a.el.duration || 0, skip: d => a.skip(d), toggle: () => a.toggle() };
}

function CassettePlayer({ isHome }) {
  const { playing, trackName, elapsed, duration, skip, toggle } = useAudio();

  function fmt(s) {
    if (!s || isNaN(s)) return '0:00';
    const m = Math.floor(s / 60);
    const sec = Math.floor(s % 60);
    return `${m}:${sec.toString().padStart(2, '0')}`;
  }

  const pct = duration > 0 ? (elapsed / duration) * 100 : 0;
  const fg = isHome ? PAPER : INK;
  const btnStyle = {
    background: 'transparent', border: 'none', color: fg,
    fontFamily: 'var(--mono)', fontSize: 13, cursor: 'pointer',
    padding: '2px 4px', display: 'flex', alignItems: 'center',
  };

  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 8, fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.1em', color: fg, borderLeft: `1px solid ${fg}33`, paddingLeft: 14, marginLeft: 14 }}>
      {/* spinning disc */}
      <div style={{
        width: 22, height: 22, borderRadius: '50%', flexShrink: 0,
        background: `conic-gradient(${INK}, ${INK}88, ${INK}, ${INK}88, ${INK})`,
        border: `2px solid ${ACCENT}`,
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        animation: playing ? 'spin 2s linear infinite' : 'none',
      }}>
        <div style={{ width: 5, height: 5, borderRadius: '50%', background: ACCENT }} />
      </div>
      {/* controls */}
      <button onClick={() => skip(-1)} style={btnStyle} title="Previous">⏮</button>
      <button onClick={toggle} style={{ ...btnStyle, fontSize: 15, color: ACCENT }} title={playing ? 'Pause' : 'Play'}>{playing ? '⏸' : '▶'}</button>
      <button onClick={() => skip(1)} style={btnStyle} title="Next">⏭</button>
      {/* track info */}
      <div style={{ display: 'flex', flexDirection: 'column', gap: 2, minWidth: 160 }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
          <span style={{ fontSize: 9, letterSpacing: '0.15em', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', maxWidth: 130 }}>{trackName}</span>
          <span style={{ fontSize: 9, opacity: 0.5, color: fg }}>{fmt(elapsed)}/{fmt(duration)}</span>
        </div>
        {/* progress bar */}
        <div style={{ height: 3, background: `${fg}22`, position: 'relative' }}>
          <div style={{ height: '100%', width: `${pct}%`, background: ACCENT, transition: 'width 0.3s linear' }} />
        </div>
      </div>
    </div>
  );
}

function BurgerMenu({ page, onNavigate, onClose }) {
  const navItems = [['01', 'WORK', 'work'], ['02', 'ABOUT', 'about'], ['03', 'ORIGIN', 'origin'], ['04', 'WRITING', 'blog'], ['05', 'LENS', 'lens'], ['06', 'COMMS', 'comms']];
  useEffect(() => {
    const onKey = e => { if (e.key === 'Escape') onClose(); };
    window.addEventListener('keydown', onKey);
    document.body.style.overflow = 'hidden';
    return () => { window.removeEventListener('keydown', onKey); document.body.style.overflow = ''; };
  }, []);
  return (
    <div style={{ position: 'fixed', inset: 0, zIndex: 100, background: INK, color: PAPER, display: 'flex', flexDirection: 'column', padding: '24px 28px' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 40 }}>
        <span style={{ fontWeight: 900, fontSize: 22, letterSpacing: '-0.04em' }}>MAROUN<span style={{ color: ACCENT }}>/</span>AU</span>
        <button onClick={onClose} style={{ background: 'transparent', border: `2px solid ${PAPER}`, color: PAPER, width: 44, height: 44, fontSize: 22, cursor: 'pointer', fontFamily: 'var(--mono)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>X</button>
      </div>
      <nav style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: 0 }}>
        {navItems.map(([n, k, id]) => (
          <a key={k} href="#" onClick={e => { e.preventDefault(); onNavigate(id); onClose(); }} style={{
            color: page === id ? ACCENT : PAPER, textDecoration: 'none',
            fontFamily: 'var(--mono)', fontSize: 28, fontWeight: 700, letterSpacing: '0.1em',
            padding: '18px 0', borderBottom: `1px solid ${PAPER}22`,
            display: 'flex', gap: 14, alignItems: 'baseline',
          }}>
            <span style={{ color: ACCENT, fontSize: 14, fontWeight: 400 }}>{n}</span>
            <span>[{k}]</span>
          </a>
        ))}
      </nav>
      <div style={{ borderTop: `1px solid ${PAPER}22`, paddingTop: 20 }}>
        <CassettePlayer isHome={true} />
      </div>
    </div>
  );
}

function TopBar({ page, onNavigate }) {
  const isMobile = useIsMobile();
  const [menuOpen, setMenuOpen] = useState(false);
  const [t, setT] = useState(new Date());
  useEffect(() => {
    const id = setInterval(() => setT(new Date()), 1000);
    return () => clearInterval(id);
  }, []);
  const hhmmss = t.toTimeString().slice(0, 8);
  return (
    <>
    <header style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: isMobile ? '12px 16px' : '16px 28px', position: 'sticky', top: 0, background: PAPER, zIndex: 10, borderBottom: (page === 'home' || page === 'origin') ? 'none' : `2px solid ${INK}` }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: isMobile ? 8 : 14 }}>
        <a onClick={() => onNavigate('home')} href="#" style={{ fontWeight: 900, fontSize: isMobile ? 18 : 22, letterSpacing: '-0.04em', textDecoration: 'none', color: INK }}>MAROUN<span style={{ color: ACCENT }}>/</span>AU</a>
        {!isMobile && (
          <div style={{ fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.2em', opacity: 0.55, borderLeft: `1px solid ${INK}33`, paddingLeft: 14 }}>
            v2.0 · SYD · {hhmmss}
          </div>
        )}
      </div>
      {isMobile ? (
        <button onClick={() => setMenuOpen(true)} style={{ background: 'transparent', border: `2px solid ${INK}`, color: INK, width: 40, height: 40, fontSize: 18, cursor: 'pointer', fontFamily: 'var(--mono)', display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'column', gap: 4, padding: 0 }}>
          <span style={{ display: 'block', width: 18, height: 2, background: INK }} />
          <span style={{ display: 'block', width: 18, height: 2, background: INK }} />
          <span style={{ display: 'block', width: 18, height: 2, background: INK }} />
        </button>
      ) : (
        <nav style={{ display: 'flex', alignItems: 'center', gap: 26, fontFamily: 'var(--mono)', fontSize: 12, letterSpacing: '0.15em' }}>
          {[['01', 'WORK', 'work'], ['02', 'ABOUT', 'about'], ['03', 'ORIGIN', 'origin'], ['04', 'WRITING', 'blog'], ['05', 'LENS', 'lens'], ['06', 'COMMS', 'comms']].map(([n, k, id]) => (
            <a key={k} href="#" onClick={e => { e.preventDefault(); onNavigate(id); }} onMouseEnter={() => retroAudio.blip()} style={{ color: page === id ? ACCENT : INK, textDecoration: 'none', display: 'flex', gap: 6, alignItems: 'baseline' }}>
              <span style={{ color: ACCENT, fontSize: 10 }}>{n}</span>
              <span>[{k}]</span>
            </a>
          ))}
          <CassettePlayer isHome={false} />
          <button onClick={() => { const e = new KeyboardEvent('keydown', { key: '/' }); window.dispatchEvent(e); }} style={{ background: 'transparent', border: `1px solid ${INK}33`, color: INK, fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.1em', padding: '4px 8px', cursor: 'pointer', opacity: 0.4, transition: 'opacity 150ms' }} onMouseEnter={e => e.currentTarget.style.opacity = '0.8'} onMouseLeave={e => e.currentTarget.style.opacity = '0.4'} title="Command palette (/ or ⌘K)">/</button>
        </nav>
      )}
    </header>
    {menuOpen && <BurgerMenu page={page} onNavigate={onNavigate} onClose={() => setMenuOpen(false)} />}
    </>
  );
}


// ─────────────────────────────────────────────────────────────
// HERO
// ─────────────────────────────────────────────────────────────
const aboutText = [
  `I grew up on the analog-to-digital seam. Mechanical engineering first, then systems, the internet, cloud, and now a generation of software that writes, reasons, and operates alongside us. Twenty plus years in, and I am as comfortable in the engine room as I am in the boardroom.`,
  `These days I lead technology at FDJ United. Around 300 people across Sydney, Stockholm, Paris, London, and the Balkans, building and running our Sportsbook Platform. Cloud-native, cloud-agnostic, live across regulated markets. The job, really, is to keep it fast, resilient, cost-honest, and ready for whatever the regulators, the customers, and the next wave of AI throw at it.`,
  `I lead hands-on, and I make no apology for it. I read the code. I sit with the on-call engineer when something is on fire. I open the dashboards myself rather than wait for someone to put them on a slide. Not because the team needs supervising, but because the job loses its meaning the moment you stop touching the thing you are responsible for. The best engineers can feel when a leader has been there recently, and when they have not.`,
  `What I am most interested in now is what comes next, and how to take an organisation there. Leaders who grew up in my era have a useful head start. We built from scratch because there was no other option. We troubleshot raw, without Stack Overflow, without a copilot, without an LLM to rubber-duck against at midnight. We learned the layers by breaking them, and then we learned how to lead the people who do. That grounding is what makes this moment so interesting to me. AI does not replace the instincts built in the past era, it amplifies them, and the organisations that will win are the ones led by people who can tell the difference between a demo and a system that holds.`,
  `I have spent the last few years proving this: restructuring toward leaner, AI-amplified teams, shipping faster through regulated markets, and rewiring how a 300-person global organisation delivers. The difference between chasing AI as a trend and leading through the transition with results to show for it.`,
  `A lot of that thinking is shaped outside the day job. I tinker after hours, read more than I should, and enjoy staying close to the craft.`,
  `I am a technologist at heart, but the older I get the more convinced I am that the technology is the easy part. People build the culture, and the culture builds the organisations and the products worth being part of. Get that right and the rest tends to follow.`,
];

const dossierStats = [
  { label: 'YEARS', value: '25+', pct: 85, color: '#00e5ff' },
  { label: 'CREW', value: '300+', pct: 90, color: '#76ff03' },
  { label: 'AI AGENTS', value: '13', pct: 45, color: ACCENT },
  { label: 'REGIONS', value: '5', pct: 35, color: '#ffea00' },
];

const dossierCerts = [
  { icon: '☁', label: 'AWS Architect' },
  { icon: '⚡', label: 'Azure' },
  { icon: '◈', label: 'MCSE' },
  { icon: '◉', label: 'CCNA' },
];

const dossierComms = [
  { icon: 'in', label: 'LinkedIn', href: 'https://www.linkedin.com/in/marounau' },
  { icon: '◐', label: 'GitHub', href: 'https://github.com/whyicode' },
  { icon: '◎', label: 'Instagram', href: '#' },
];

function AboutModal({ onClose }) {
  const isMobile = useIsMobile();
  useEffect(() => {
    const onKey = e => { if (e.key === 'Escape') onClose(); };
    window.addEventListener('keydown', onKey);
    return () => window.removeEventListener('keydown', onKey);
  }, []);

  const mono = { fontFamily: 'var(--mono)' };
  const cyan = '#00e5ff';
  const sectionTitle = { ...mono, fontSize: 16, fontWeight: 700, letterSpacing: '0.25em', color: cyan, marginBottom: 16 };
  const rule = { borderTop: `1px solid ${cyan}33`, marginTop: 18, paddingTop: 18 };

  return (
    <div style={{ position: 'fixed', inset: 0, zIndex: 100, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
      {/* backdrop */}
      <div onClick={onClose} style={{ position: 'absolute', inset: 0, background: `${INK}88`, backdropFilter: 'blur(20px)', WebkitBackdropFilter: 'blur(20px)' }} />
      {/* modal */}
      <div style={{ position: 'relative', width: isMobile ? '100vw' : 'min(1100px, 92vw)', maxHeight: isMobile ? '100vh' : '88vh', height: isMobile ? '100vh' : 'auto', overflow: 'auto', background: `${INK}26`, backdropFilter: 'blur(24px)', WebkitBackdropFilter: 'blur(24px)', border: isMobile ? 'none' : `1px solid ${cyan}33`, color: PAPER, ...mono, padding: isMobile ? '20px 16px' : '32px 36px' }}>
        {/* close button */}
        <button onClick={onClose} style={{ position: 'absolute', top: 16, right: 16, width: 28, height: 28, background: 'transparent', border: `1px solid ${cyan}55`, color: cyan, ...mono, fontSize: 14, fontWeight: 700, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>×</button>

        {/* top bar */}
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
            <span style={{ width: 8, height: 8, background: cyan, display: 'inline-block' }} />
            <span style={{ fontSize: 14, letterSpacing: '0.3em', color: cyan, fontWeight: 700 }}>CLASSIFIED DOSSIER</span>
          </div>
          <div style={{ fontSize: 12, letterSpacing: '0.2em', opacity: 0.7, marginRight: 40 }}>STATUS: <span style={{ color: '#76ff03' }}>ACTIVE</span></div>
        </div>

        {/* identity row */}
        <div style={{ display: 'flex', flexDirection: isMobile ? 'column' : 'row', alignItems: isMobile ? 'flex-start' : 'center', gap: isMobile ? 14 : 20, marginBottom: 28, paddingBottom: 24, borderBottom: `1px solid ${cyan}22` }}>
          <div style={{ position: 'relative', width: isMobile ? 60 : 90, height: isMobile ? 60 : 90, border: `2px solid ${cyan}55`, overflow: 'hidden', flexShrink: 0 }}>
            <img src="portrait.png" alt="Maroun" style={{ width: '100%', height: '100%', objectFit: 'cover', imageRendering: 'pixelated' }} />
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: isMobile ? 16 : 24, fontWeight: 700, letterSpacing: '0.15em', marginBottom: 4 }}>MAROUN ABOU MAROUN</div>
            <div style={{ fontSize: isMobile ? 12 : 14, opacity: 0.7, marginBottom: 2 }}>Engineer · Leader · Builder</div>
            <div style={{ fontSize: isMobile ? 11 : 12, opacity: 0.6 }}>Call Sign: <span style={{ color: ACCENT, fontWeight: 700 }}>MAVERICK</span></div>
            <div style={{ fontSize: 11, opacity: 0.5, marginTop: 4 }}>Sydney, Australia · Global Operations</div>
          </div>
          {!isMobile && (
          <div style={{ border: `1px solid ${cyan}44`, padding: '12px 18px', textAlign: 'center', flexShrink: 0 }}>
            <div style={{ fontSize: 22, fontWeight: 700, color: cyan }}>P1</div>
            <div style={{ fontSize: 9, letterSpacing: '0.2em', opacity: 0.7, marginTop: 2 }}>COMMANDING<br/>OFFICER</div>
          </div>
          )}
        </div>

        {/* two column layout */}
        <div style={{ display: 'grid', gridTemplateColumns: isMobile ? '1fr' : '1fr 280px', gap: isMobile ? 24 : 36 }}>
          {/* left — service record */}
          <div>
            <div style={sectionTitle}>SERVICE RECORD</div>
            {aboutText.map((p, i) => (
              <p key={i} style={{ fontSize: 14, lineHeight: 1.75, opacity: 0.8, margin: 0, marginBottom: 16, fontFamily: 'var(--sans)' }}>{p}</p>
            ))}
          </div>

          {/* right — stats, clearance, comms */}
          <div>
            {/* stats */}
            <div style={sectionTitle}>STATS</div>
            {dossierStats.map((s, i) => (
              <div key={s.label} style={{ marginBottom: 14 }}>
                <div style={{ fontSize: 24, fontWeight: 700, color: s.color, lineHeight: 1 }}>{s.value}</div>
                <div style={{ height: 4, background: `${PAPER}11`, marginTop: 4, marginBottom: 4, position: 'relative' }}>
                  <div style={{ height: '100%', width: `${s.pct}%`, background: s.color }} />
                </div>
                <div style={{ fontSize: 11, letterSpacing: '0.2em', opacity: 0.5 }}>{s.label}</div>
                {i < dossierStats.length - 1 && <div style={{ borderBottom: `1px solid ${PAPER}11`, marginTop: 10 }} />}
              </div>
            ))}

            {/* clearance */}
            <div style={{ ...rule }}>
              <div style={sectionTitle}>CLEARANCE</div>
              <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
                {dossierCerts.map(c => (
                  <span key={c.label} style={{ padding: '6px 12px', border: `1px solid ${cyan}55`, fontSize: 12, letterSpacing: '0.1em', display: 'inline-flex', alignItems: 'center', gap: 6 }}>
                    <span>{c.icon}</span> {c.label}
                  </span>
                ))}
              </div>
            </div>

            {/* comms */}
            <div style={{ ...rule }}>
              <div style={sectionTitle}>COMMS</div>
              <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
                {dossierComms.map(c => (
                  <a key={c.label} href={c.href} target={c.href.startsWith('http') ? '_blank' : undefined} rel="noreferrer" style={{ padding: '6px 12px', border: `1px solid ${ACCENT}55`, fontSize: 12, letterSpacing: '0.1em', color: PAPER, textDecoration: 'none', display: 'inline-flex', alignItems: 'center', gap: 6 }}>
                    <span style={{ color: ACCENT }}>{c.icon}</span> {c.label}
                  </a>
                ))}
              </div>
            </div>
          </div>
        </div>

        {/* bottom rule */}
        <div style={{ marginTop: 28, paddingTop: 14, borderTop: `1px solid ${cyan}22`, fontSize: 10, letterSpacing: '0.25em', opacity: 0.3, display: 'flex', justifyContent: 'space-between' }}>
          <span>// END OF DOSSIER</span>
          <span>CLASSIFICATION: OPEN</span>
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// TIME-AWARE GREETING
// ─────────────────────────────────────────────────────────────
function useGreeting() {
  const h = new Date().getHours();
  if (h < 5) return 'LATE NIGHT';
  if (h < 12) return 'GOOD MORNING';
  if (h < 17) return 'GOOD AFTERNOON';
  if (h < 21) return 'GOOD EVENING';
  return 'LATE NIGHT';
}

// ─────────────────────────────────────────────────────────────
// TYPEWRITER EFFECT
// ─────────────────────────────────────────────────────────────
function Typewriter({ text, speed = 35, delay = 0 }) {
  const [displayed, setDisplayed] = useState('');
  const [started, setStarted] = useState(false);
  useEffect(() => {
    const t = setTimeout(() => setStarted(true), delay);
    return () => clearTimeout(t);
  }, [delay]);
  useEffect(() => {
    if (!started) return;
    if (displayed.length >= text.length) return;
    const t = setTimeout(() => setDisplayed(text.slice(0, displayed.length + 1)), speed);
    return () => clearTimeout(t);
  }, [started, displayed, text, speed]);
  return (
    <span>
      {displayed}
      <span style={{ borderRight: '2px solid', borderColor: ACCENT, marginLeft: 2, animation: 'typeBlink 0.8s steps(1) infinite' }}>&nbsp;</span>
    </span>
  );
}

// ─────────────────────────────────────────────────────────────
// AMBIENT PIXEL PARTICLES
// ─────────────────────────────────────────────────────────────
function PixelParticles() {
  const particles = useRef([]);
  if (particles.current.length === 0) {
    particles.current = Array.from({ length: 18 }, (_, i) => ({
      id: i,
      left: Math.random() * 100,
      size: 2 + Math.random() * 4,
      duration: 12 + Math.random() * 18,
      delay: Math.random() * 15,
      opacity: 0.15 + Math.random() * 0.3,
    }));
  }
  return (
    <div style={{ position: 'absolute', inset: 0, overflow: 'hidden', pointerEvents: 'none', zIndex: 1 }}>
      {particles.current.map(p => (
        <div key={p.id} style={{
          position: 'absolute', bottom: -10, left: `${p.left}%`,
          width: p.size, height: p.size, background: ACCENT,
          opacity: p.opacity,
          animation: `floatParticle ${p.duration}s linear ${p.delay}s infinite`,
        }} />
      ))}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// MOUSE PARALLAX HOOK
// ─────────────────────────────────────────────────────────────
function useMouseParallax(strength = 15) {
  const [offset, setOffset] = useState({ x: 0, y: 0 });
  useEffect(() => {
    function onMove(e) {
      const cx = (e.clientX / window.innerWidth - 0.5) * 2;
      const cy = (e.clientY / window.innerHeight - 0.5) * 2;
      setOffset({ x: -cx * strength, y: -cy * strength });
    }
    window.addEventListener('mousemove', onMove);
    return () => window.removeEventListener('mousemove', onMove);
  }, [strength]);
  return offset;
}

// ─────────────────────────────────────────────────────────────
// COMMAND PALETTE
// ─────────────────────────────────────────────────────────────
function CommandPalette({ onNavigate, onClose }) {
  const [query, setQuery] = useState('');
  const inputRef = useRef(null);
  const commands = [
    { key: 'home', label: 'HOME', desc: 'Back to the front page', icon: '⌂' },
    { key: 'work', label: 'WORK', desc: 'Career log · 20+ years', icon: '◆' },
    { key: 'about', label: 'ABOUT', desc: '$ whoami --verbose', icon: '◈' },
    { key: 'origin', label: 'ORIGIN', desc: 'Signal history · era selector', icon: '◉' },
    { key: 'blog', label: 'WRITING', desc: 'Articles · LinkedIn · long-form', icon: '▤' },
    { key: 'lens', label: 'LENS', desc: 'Instagram · curated feed', icon: '◎' },
    { key: 'comms', label: 'COMMS', desc: 'Say hi · open channel', icon: '▸' },
  ];
  const filtered = commands.filter(c =>
    c.label.toLowerCase().includes(query.toLowerCase()) ||
    c.desc.toLowerCase().includes(query.toLowerCase())
  );
  const [selected, setSelected] = useState(0);

  useEffect(() => {
    inputRef.current?.focus();
    const onKey = e => {
      if (e.key === 'Escape') onClose();
      if (e.key === 'ArrowDown') { e.preventDefault(); setSelected(s => Math.min(s + 1, filtered.length - 1)); }
      if (e.key === 'ArrowUp') { e.preventDefault(); setSelected(s => Math.max(s - 1, 0)); }
      if (e.key === 'Enter' && filtered[selected]) { onNavigate(filtered[selected].key); onClose(); }
    };
    window.addEventListener('keydown', onKey);
    document.body.style.overflow = 'hidden';
    return () => { window.removeEventListener('keydown', onKey); document.body.style.overflow = ''; };
  }, [filtered.length, selected]);

  useEffect(() => { setSelected(0); }, [query]);

  return (
    <div style={{ position: 'fixed', inset: 0, zIndex: 200, display: 'flex', alignItems: 'flex-start', justifyContent: 'center', paddingTop: '18vh' }}>
      <div onClick={onClose} style={{ position: 'absolute', inset: 0, background: `${INK}77`, backdropFilter: 'blur(8px)', WebkitBackdropFilter: 'blur(8px)' }} />
      <div style={{ position: 'relative', width: 'min(520px, 90vw)', background: INK, border: `2px solid ${ACCENT}`, color: PAPER, fontFamily: 'var(--mono)' }}>
        {/* input */}
        <div style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '14px 18px', borderBottom: `1px solid ${ACCENT}44` }}>
          <span style={{ color: ACCENT, fontSize: 16 }}>/</span>
          <input ref={inputRef} value={query} onChange={e => setQuery(e.target.value)} placeholder="type a command..." style={{
            flex: 1, background: 'transparent', border: 'none', outline: 'none',
            color: PAPER, fontFamily: 'var(--mono)', fontSize: 15, letterSpacing: '0.05em',
          }} />
          <span style={{ fontSize: 10, opacity: 0.4, letterSpacing: '0.15em' }}>ESC</span>
        </div>
        {/* results */}
        <div style={{ maxHeight: 320, overflow: 'auto' }}>
          {filtered.map((c, i) => (
            <div key={c.key} onClick={() => { onNavigate(c.key); onClose(); }}
              onMouseEnter={() => setSelected(i)}
              style={{
                display: 'flex', alignItems: 'center', gap: 14, padding: '12px 18px',
                cursor: 'pointer', transition: 'background 100ms',
                background: i === selected ? `${ACCENT}22` : 'transparent',
                borderLeft: i === selected ? `3px solid ${ACCENT}` : '3px solid transparent',
              }}>
              <span style={{ fontSize: 16, opacity: 0.6, width: 24, textAlign: 'center' }}>{c.icon}</span>
              <div style={{ flex: 1 }}>
                <span style={{ fontSize: 13, fontWeight: 700, letterSpacing: '0.15em' }}>{c.label}</span>
                <span style={{ fontSize: 11, opacity: 0.5, marginLeft: 12 }}>{c.desc}</span>
              </div>
              <span style={{ fontSize: 10, opacity: 0.3, letterSpacing: '0.1em' }}>↵</span>
            </div>
          ))}
          {filtered.length === 0 && (
            <div style={{ padding: '20px 18px', fontSize: 12, opacity: 0.4 }}>no matching commands</div>
          )}
        </div>
        {/* hint bar */}
        <div style={{ padding: '8px 18px', borderTop: `1px solid ${ACCENT}22`, fontSize: 9, opacity: 0.35, letterSpacing: '0.2em', display: 'flex', gap: 18 }}>
          <span>↑↓ navigate</span><span>↵ select</span><span>esc close</span>
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// RETRO HOVER SOUNDS (Web Audio API — no files needed)
// ─────────────────────────────────────────────────────────────
const retroAudio = (() => {
  let ctx = null;
  function getCtx() {
    if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();
    return ctx;
  }
  return {
    blip() {
      try {
        const c = getCtx();
        const osc = c.createOscillator();
        const gain = c.createGain();
        osc.connect(gain);
        gain.connect(c.destination);
        osc.type = 'square';
        osc.frequency.setValueAtTime(800, c.currentTime);
        osc.frequency.exponentialRampToValueAtTime(1200, c.currentTime + 0.03);
        gain.gain.setValueAtTime(0.08, c.currentTime);
        gain.gain.exponentialRampToValueAtTime(0.001, c.currentTime + 0.06);
        osc.start(c.currentTime);
        osc.stop(c.currentTime + 0.06);
      } catch (e) {}
    },
    click() {
      try {
        const c = getCtx();
        const osc = c.createOscillator();
        const gain = c.createGain();
        osc.connect(gain);
        gain.connect(c.destination);
        osc.type = 'square';
        osc.frequency.setValueAtTime(1400, c.currentTime);
        osc.frequency.exponentialRampToValueAtTime(600, c.currentTime + 0.04);
        gain.gain.setValueAtTime(0.06, c.currentTime);
        gain.gain.exponentialRampToValueAtTime(0.001, c.currentTime + 0.04);
        osc.start(c.currentTime);
        osc.stop(c.currentTime + 0.04);
      } catch (e) {}
    },
    nav() {
      try {
        const c = getCtx();
        const osc = c.createOscillator();
        const gain = c.createGain();
        osc.connect(gain);
        gain.connect(c.destination);
        osc.type = 'square';
        osc.frequency.setValueAtTime(400, c.currentTime);
        osc.frequency.exponentialRampToValueAtTime(900, c.currentTime + 0.05);
        osc.frequency.exponentialRampToValueAtTime(1100, c.currentTime + 0.1);
        gain.gain.setValueAtTime(0.07, c.currentTime);
        gain.gain.exponentialRampToValueAtTime(0.001, c.currentTime + 0.12);
        osc.start(c.currentTime);
        osc.stop(c.currentTime + 0.12);
      } catch (e) {}
    },
  };
})();

// ─────────────────────────────────────────────────────────────
// TECH RADAR — current stack with intensity
// ─────────────────────────────────────────────────────────────
const techStack = [
  { name: 'AI / LLMs', level: 5 },
  { name: 'Agentic Systems', level: 5 },
  { name: 'Cloud Architecture', level: 5 },
  { name: 'Kubernetes', level: 4 },
  { name: 'Platform Engineering', level: 5 },
  { name: 'Python', level: 4 },
  { name: 'TypeScript', level: 3 },
  { name: 'Go', level: 3 },
  { name: 'React', level: 3 },
  { name: 'AWS', level: 5 },
  { name: 'Azure', level: 4 },
  { name: 'Terraform', level: 4 },
  { name: 'CI/CD', level: 4 },
  { name: 'Grafana', level: 4 },
  { name: 'System Design', level: 5 },
  { name: 'Org Design', level: 5 },
];

// ─────────────────────────────────────────────────────────────
// PAGE TRANSITION OVERLAY
// ─────────────────────────────────────────────────────────────
function PageTransition({ active }) {
  if (!active) return null;
  return (
    <div style={{ position: 'fixed', inset: 0, zIndex: 150, pointerEvents: 'none' }}>
      {/* scanline wipe */}
      <div style={{
        position: 'absolute', left: 0, right: 0, height: 4, background: ACCENT,
        boxShadow: `0 0 20px ${ACCENT}, 0 0 60px ${ACCENT}55`,
        animation: 'scanWipe 0.35s ease-in-out forwards',
      }} />
      {/* ink flash */}
      <div style={{
        position: 'absolute', inset: 0, background: INK,
        animation: 'introFadeOut 0.4s ease forwards',
        opacity: 0.3,
      }} />
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// FAVICON ANIMATION
// ─────────────────────────────────────────────────────────────
function useFaviconAnimation() {
  useEffect(() => {
    const frames = [
      { char: 'M', color: '#ff2bd6' },
      { char: '▸', color: '#00e5ff' },
      { char: '◆', color: '#ff2bd6' },
      { char: '_', color: '#76ff03' },
    ];
    let i = 0;
    const link = document.getElementById('favicon');
    if (!link) return;
    const id = setInterval(() => {
      i = (i + 1) % frames.length;
      const f = frames[i];
      link.href = `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><rect width='32' height='32' fill='%230a0a0a'/><text x='4' y='24' font-size='22' fill='${encodeURIComponent(f.color)}'>${f.char}</text></svg>`;
    }, 2000);
    return () => clearInterval(id);
  }, []);
}

// ─────────────────────────────────────────────────────────────
// VISITOR COUNTER (localStorage-based)
// ─────────────────────────────────────────────────────────────
function useVisitorCount() {
  const [count, setCount] = useState(0);
  useEffect(() => {
    const key = 'maroun_au_visits';
    const stored = parseInt(localStorage.getItem(key) || '0');
    const isNew = !sessionStorage.getItem('maroun_au_counted');
    const next = isNew ? stored + 1 : stored;
    if (isNew) {
      localStorage.setItem(key, next);
      sessionStorage.setItem('maroun_au_counted', '1');
    }
    setCount(next);
  }, []);
  return count;
}

// ─────────────────────────────────────────────────────────────
// ANIMATED SLIDE COUNTER
// ─────────────────────────────────────────────────────────────
function SlideCounter({ value, total }) {
  const [displayVal, setDisplayVal] = useState(value);
  const [rolling, setRolling] = useState(false);
  useEffect(() => {
    setRolling(true);
    const t = setTimeout(() => { setDisplayVal(value); setRolling(false); }, 150);
    return () => clearTimeout(t);
  }, [value]);
  return (
    <span style={{ display: 'inline-flex', alignItems: 'center', fontFamily: 'var(--mono)', fontSize: 11, letterSpacing: '0.2em', color: PAPER, opacity: 0.7, textShadow: '0 1px 4px rgba(0,0,0,0.8)' }}>
      <span style={{ display: 'inline-block', overflow: 'hidden', height: '1.2em', verticalAlign: 'bottom' }}>
        <span style={{ display: 'inline-block', animation: rolling ? 'numberRoll 0.15s ease-out' : 'none' }}>
          {String(displayVal + 1).padStart(2, '0')}
        </span>
      </span>
      {' / '}
      {String(total).padStart(2, '0')}
    </span>
  );
}

// ─────────────────────────────────────────────────────────────
// FILM GRAIN OVERLAY
// ─────────────────────────────────────────────────────────────
function FilmGrain() {
  return (
    <div style={{
      position: 'absolute', inset: -50, zIndex: 3, pointerEvents: 'none',
      opacity: 0.06,
      backgroundImage: `url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`,
      backgroundSize: '128px 128px',
      animation: 'grain 0.4s steps(1) infinite',
    }} />
  );
}

// ─────────────────────────────────────────────────────────────
// KONAMI CODE EASTER EGG
// ─────────────────────────────────────────────────────────────
const KONAMI = ['ArrowUp','ArrowUp','ArrowDown','ArrowDown','ArrowLeft','ArrowRight','ArrowLeft','ArrowRight','b','a'];

function useKonamiCode() {
  const [triggered, setTriggered] = useState(false);
  const pos = useRef(0);
  useEffect(() => {
    function onKey(e) {
      if (e.key === KONAMI[pos.current]) {
        pos.current++;
        if (pos.current === KONAMI.length) {
          setTriggered(true);
          pos.current = 0;
        }
      } else {
        pos.current = e.key === KONAMI[0] ? 1 : 0;
      }
    }
    window.addEventListener('keydown', onKey);
    return () => window.removeEventListener('keydown', onKey);
  }, []);
  return [triggered, () => setTriggered(false)];
}

function KonamiEasterEgg({ onDismiss }) {
  const [lines, setLines] = useState([]);
  const bootSequence = [
    '    **** COMMODORE 64 BASIC V2 ****',
    '',
    ' 64K RAM SYSTEM  38911 BASIC BYTES FREE',
    '',
    'READY.',
    'LOAD "MAROUN.AU",8,1',
    '',
    'SEARCHING FOR MAROUN.AU',
    'LOADING',
    'READY.',
    'RUN',
    '',
    '> HELLO, WORLD.',
    '> YOU FOUND THE SECRET.',
    '> MAROUN HAS BEEN CODING SINCE THE C64 ERA.',
    '> THAT\'S NOT A METAPHOR. HE ACTUALLY HAD ONE.',
    '',
    '> PRESS ANY KEY TO RETURN...',
  ];

  useEffect(() => {
    let i = 0;
    const id = setInterval(() => {
      if (i < bootSequence.length) {
        setLines(l => [...l, bootSequence[i]]);
        i++;
      } else {
        clearInterval(id);
      }
    }, 180);
    const onKey = (e) => {
      if (i >= bootSequence.length) onDismiss();
    };
    window.addEventListener('keydown', onKey);
    return () => { clearInterval(id); window.removeEventListener('keydown', onKey); };
  }, []);

  return (
    <div onClick={onDismiss} style={{
      position: 'fixed', inset: 0, zIndex: 300, background: '#4040e0',
      color: '#a0a0ff', fontFamily: 'var(--mono)', fontSize: 16, lineHeight: 1.8,
      padding: '40px 60px', cursor: 'pointer', overflow: 'hidden',
      animation: 'konamiFlash 0.3s ease',
    }}>
      {lines.map((l, i) => (
        <div key={i} style={{ color: l.startsWith('>') ? '#fff' : '#a0a0ff' }}>{l || '\u00A0'}</div>
      ))}
      <span className="blink" style={{ color: '#a0a0ff' }}>█</span>
    </div>
  );
}

function Hero({ onNavigate, introDone = true }) {
  const isMobile = useIsMobile();
  const [media, setMedia] = useState([]);
  const [current, setCurrent] = useState(0);
  const [showAbout, setShowAbout] = useState(false);
  const [glitching, setGlitching] = useState(false);
  const greeting = useGreeting();
  // const parallax = useMouseParallax(isMobile ? 0 : 12);
  const parallax = { x: 0, y: 0 };

  useEffect(() => {
    Promise.all([
      fetch('img/manifest.json').then(r => r.json()).catch(() => []),
      fetch('video/manifest.json').then(r => r.json()).catch(() => []),
    ]).then(([imgList, vidList]) => {
      const videoMap = {};
      vidList.forEach(v => { if (v.replaces) videoMap[v.replaces] = v; });
      const merged = imgList.map(imgSrc => {
        if (videoMap[imgSrc]) return { type: 'video', src: videoMap[imgSrc].src, webm: videoMap[imgSrc].webm, poster: imgSrc };
        return { type: 'image', src: imgSrc };
      });
      vidList.forEach(v => {
        if (!v.replaces) merged.push({ type: 'video', src: v.src, webm: v.webm });
      });
      const c64Idx = merged.findIndex(m => m.src && m.src.includes('hero-c64'));
      const first = c64Idx >= 0 ? merged.splice(c64Idx, 1)[0] : null;
      const v2Idx = merged.findIndex(m => m.src && m.src.includes('hero-vid-2'));
      const second = v2Idx >= 0 ? merged.splice(v2Idx, 1)[0] : null;
      for (let i = merged.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [merged[i], merged[j]] = [merged[j], merged[i]];
      }
      if (second) merged.unshift(second);
      if (first) merged.unshift(first);
      setMedia(merged);
    });
  }, []);

  useEffect(() => {
    if (introDone) setCurrent(0);
  }, [introDone]);

  // Glitch transition on slide change
  function glitchTransition(next) {
    setGlitching(true);
    setTimeout(() => {
      setCurrent(next);
      setTimeout(() => setGlitching(false), 200);
    }, 150);
  }

  useEffect(() => {
    if (!introDone || media.length < 2) return;
    const item = media[current];
    const duration = item && item.type === 'video' ? 7000 : 10000;
    const id = setTimeout(() => setCurrent(c => (c + 1) % media.length), duration);
    return () => clearTimeout(id);
  }, [media, current, introDone]);

  const heroSubtitle = 'I build teams that build platforms. 25 years from a Commodore 64 to cloud-native, AI-augmented, globally distributed.';

  const mediaStyle = (i) => ({
    position: 'absolute', inset: -20, width: 'calc(100% + 40px)', height: 'calc(100% + 40px)',
    objectFit: 'cover',
    opacity: i === current ? 1 : 0,
    transition: 'opacity 1.2s ease-in-out',
    transform: `translate(${parallax.x}px, ${parallax.y}px)`,
  });

  return (
    <>
    <section style={{ position: 'relative', background: PAPER, height: '100%', display: 'flex', flexDirection: 'column' }}>
      <div style={{ position: 'relative', flex: 1, background: INK, color: PAPER, overflow: 'hidden' }}>
        {/* hero background media — with parallax */}
        {media.map((item, i) => (
          item.type === 'video' ? (
            <video key={item.src} poster={item.poster} autoPlay muted loop playsInline style={mediaStyle(i)}>
              {item.webm && <source src={item.webm} type="video/webm" />}
              <source src={item.src} type="video/mp4" />
            </video>
          ) : (
            <img key={item.src} src={item.src} alt="" style={mediaStyle(i)} />
          )
        ))}

        {/* vignette + bottom fade */}
        <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.6) 100%)' }} />
        <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(to top, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.15) 35%, transparent 60%)' }} />
        <div style={{ position: 'absolute', inset: 0, background: `linear-gradient(to bottom, ${PAPER} 0%, ${PAPER}e6 2%, ${PAPER}aa 5%, ${PAPER}66 10%, ${PAPER}33 18%, ${PAPER}11 28%, transparent 40%)` }} />
        {/* CRT scanlines */}
        <div style={{ position: 'absolute', inset: 0, backgroundImage: `repeating-linear-gradient(to bottom, rgba(0,0,0,0.25) 0 1px, transparent 1px 3px)`, pointerEvents: 'none', zIndex: 1, WebkitMaskImage: 'linear-gradient(to bottom, transparent 0%, black 20%)', maskImage: 'linear-gradient(to bottom, transparent 0%, black 20%)' }} />
        {/* film grain */}
        <FilmGrain />

        {/* top hud */}
        {!isMobile && (
        <>
        <div style={{ position: 'absolute', top: 18, left: 22, display: 'flex', gap: 14, fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.25em', opacity: 0.4, zIndex: 4 }}>
          <span>► 00:00:12:04</span>
          <span style={{ color: ACCENT }}>● REC</span>
          <span>CH.01</span>
        </div>
        <div style={{ position: 'absolute', top: 18, right: 22, fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.25em', opacity: 0.4, textAlign: 'right', zIndex: 4 }}>
          LAT -33.86 · LON 151.20<br/>MAROUN.AU / 2026
        </div>
        </>
        )}

        {/* corner ticks */}
        {!isMobile && ['tl', 'tr', 'bl', 'br'].map(c => {
          const pos = {
            tl: { top: 10, left: 10, borderTop: `2px solid ${ACCENT}`, borderLeft: `2px solid ${ACCENT}` },
            tr: { top: 10, right: 10, borderTop: `2px solid ${ACCENT}`, borderRight: `2px solid ${ACCENT}` },
            bl: { bottom: 10, left: 10, borderBottom: `2px solid ${ACCENT}`, borderLeft: `2px solid ${ACCENT}` },
            br: { bottom: 10, right: 10, borderBottom: `2px solid ${ACCENT}`, borderRight: `2px solid ${ACCENT}` },
          }[c];
          return <div key={c} style={{ position: 'absolute', width: 16, height: 16, ...pos, zIndex: 4 }} />;
        })}

        {/* bottom-left H1 + CTA */}
        <div style={{ position: 'absolute', left: isMobile ? 12 : 40, right: isMobile ? 12 : 'auto', bottom: isMobile ? 12 : 40, maxWidth: isMobile ? 'none' : 580, zIndex: 5, background: `${INK}55`, backdropFilter: 'blur(8px)', WebkitBackdropFilter: 'blur(8px)', padding: isMobile ? '18px 16px' : '28px 32px', border: `1px solid ${PAPER}15` }}>
          <div style={{ fontFamily: 'var(--mono)', fontSize: isMobile ? 9 : 11, letterSpacing: '0.3em', color: ACCENT, marginBottom: isMobile ? 10 : 18, textShadow: '0 1px 6px rgba(0,0,0,0.8)' }}>
            INDEX / 001 · {greeting} ░░
          </div>
          <h1 style={{ fontSize: isMobile ? 'clamp(28px, 8vw, 42px)' : 'clamp(42px, 5.5vw, 90px)', lineHeight: 1, fontWeight: 900, letterSpacing: '-0.04em', margin: 0, marginBottom: isMobile ? 10 : 18, textShadow: '0 2px 20px rgba(0,0,0,0.7)' }}>
            ENGINEER <span style={{ opacity: 0.55 }}>LEADER</span> BUILDER
          </h1>
          {!isMobile && (
            <div style={{ fontSize: 15, opacity: 0.85, marginBottom: 24, lineHeight: 1.5, textShadow: '0 1px 8px rgba(0,0,0,0.9)' }}>
              {heroSubtitle}
            </div>
          )}
          <a href="#" onClick={e => { e.preventDefault(); setShowAbout(true); }} onMouseEnter={() => retroAudio.click()} style={{ ...primaryCta, padding: isMobile ? '14px 18px' : '18px 26px', fontSize: isMobile ? 12 : 14 }}>GET TO KNOW ME <span style={{ marginLeft: 8 }}>→</span></a>
        </div>

        {/* media nav — bottom right */}
        {!isMobile && (
        <div style={{ position: 'absolute', right: 40, bottom: 40, display: 'flex', alignItems: 'center', gap: 10, zIndex: 5 }}>
          <button onClick={() => setCurrent((current - 1 + media.length) % media.length)} style={{ width: 36, height: 36, background: `${INK}55`, border: `1px solid ${PAPER}33`, color: PAPER, fontSize: 18, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--mono)' }}>←</button>
          <SlideCounter value={current} total={media.length} />
          <button onClick={() => setCurrent((current + 1) % media.length)} style={{ width: 36, height: 36, background: `${INK}55`, border: `1px solid ${PAPER}33`, color: PAPER, fontSize: 18, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--mono)' }}>→</button>
        </div>
        )}
      </div>

    </section>
    {showAbout && <AboutModal onClose={() => setShowAbout(false)} />}
    </>
  );
}

const primaryCta = {
  padding: '18px 26px', background: ACCENT, color: PAPER,
  border: `2px solid ${ACCENT}`, fontFamily: 'inherit',
  fontWeight: 800, fontSize: 14, letterSpacing: '0.15em',
  cursor: 'pointer', textDecoration: 'none',
  display: 'inline-flex', alignItems: 'center',
};
const secondaryCta = {
  padding: '12px 18px', background: 'transparent', color: PAPER,
  border: `2px solid ${PAPER}`, fontFamily: 'inherit',
  fontSize: 12, letterSpacing: '0.1em',
  cursor: 'pointer',
  display: 'inline-flex', alignItems: 'center', gap: 12,
};

// ─────────────────────────────────────────────────────────────
// SECTION HEAD
// ─────────────────────────────────────────────────────────────
function SectionHead({ num, title, sub, id }) {
  const isMobile = useIsMobile();
  return (
    <div id={id} style={{ display: 'flex', alignItems: 'baseline', gap: isMobile ? 10 : 20, padding: isMobile ? '10px 16px' : '12px 28px', background: INK, color: PAPER, fontFamily: 'var(--mono)', fontSize: isMobile ? 10 : 12, letterSpacing: '0.2em', borderTop: `2px solid ${INK}`, borderBottom: `2px solid ${INK}`, flexWrap: isMobile ? 'wrap' : 'nowrap' }}>
      <span>{num}</span>
      <span style={{ color: PAPER }}>{title}</span>
      <span style={{ color: ACCENT }}>//</span>
      <span style={{ opacity: 0.55 }}>{sub}</span>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// WORK — career log
// ─────────────────────────────────────────────────────────────
const employers = [
  {
    company: 'FDJ United', years: '2016 → Present', logo: 'img/logos/fdj.png',
    summary: 'A decade-long journey from team lead to directing 300+ engineers across five cities. Built a cloud-native sportsbook platform, led the pivot to AI-native operations, and scaled through a major acquisition.',
    roles: [
      { t: '2024 →', role: 'Director of Engineering', note: '300+ people across Sydney / Stockholm / Paris / London / Balkans. Building a cloud-native, multi-region Sportsbook platform.', stack: 'cloud-native · ai-augmented' },
      { t: '2022-24', role: 'Head of Engineering', note: 'Led 200+ engineers across global locations. Shipping innovative products for regulated markets. Pioneered the pivot towards AI and agentic AI, optimising delivery and operations.', stack: 'leadership · delivery · ai' },
      { t: '2020-22', role: 'Head of Technology', note: 'Global strategic technology leadership across engineering org.', stack: 'platform · strategy · global' },
      { t: '2018-20', role: 'IT Operations Manager', note: 'Global operational leadership across engineering & infrastructure.', stack: 'infra · ops · global' },
      { t: '2016-18', role: 'Technology Team Lead', note: 'Tech-lead role in what would become a 10-year journey.', stack: 'team · delivery' },
    ],
  },
  {
    company: 'MicroChannel Services', years: '2015 — 2016', logo: 'img/logos/microchannel.png',
    summary: 'Technology leadership across MSP client engagements throughout APAC.',
    roles: [
      { t: '2015-16', role: 'Technology Manager', note: 'Led technology across client-delivery engagements for clients within MicroChannel\'s MSP business throughout APAC.', stack: 'consulting' },
    ],
  },
  {
    company: 'Caterpillar Inc.', years: '2010 — 2015', logo: 'img/logos/caterpillar.png',
    summary: 'Engineering leadership in the heavy-industry software space. Asset management and forecasting systems deployed to CAT suppliers and operators globally.',
    roles: [
      { t: '2011-15', role: 'Engineering Manager', note: 'Engineering management in the heavy-industry software space.', stack: 'systems · teams' },
      { t: '2010-11', role: 'Senior Technical Lead', note: 'Implementation of asset management and forecasting systems to CAT suppliers and operators across the globe.', stack: 'tech-lead' },
    ],
  },
  {
    company: 'Brilliance Financial Technology', years: '2009 — 2010', logo: 'img/logos/brilliance.png',
    summary: 'Pricing and risk systems in the fintech space.',
    roles: [
      { t: '2009-10', role: 'Senior Business Analyst', note: 'Pricing & risk systems.', stack: 'fintech · risk' },
    ],
  },
  {
    company: 'Reckon', years: '2003 — 2010', logo: 'img/logos/reckon.png',
    summary: 'Where it all started. Seven years growing from software engineer to presales technical consultant across the APAC region.',
    roles: [
      { t: '2006-10', role: 'Presales Technical Consultant', note: 'Technical presales across the APAC region.', stack: 'presales' },
      { t: '2004-06', role: 'Technical Consultant', note: 'Client-facing technical consulting.', stack: 'consulting' },
      { t: '2003-04', role: 'Software Engineer', note: 'Where it all started.', stack: 'engineering' },
    ],
  },
];

function Work() {
  const isMobile = useIsMobile();
  const [open, setOpen] = useState(0);
  return (
    <>
      <SectionHead id="work" num="01" title="CAREER" sub={`${employers.length} employers · 20+ years · tail -f /history`} />
      <section style={{ flex: 1, borderBottom: `2px solid ${INK}` }}>
        {employers.map((emp, i) => {
          const isOpen = open === i;
          return (
            <div key={i} style={{ borderTop: i === 0 ? 'none' : `2px solid ${INK}` }}>
              {/* employer header */}
              <button onClick={() => setOpen(isOpen ? -1 : i)} style={{
                display: 'flex', alignItems: isMobile ? 'flex-start' : 'center', gap: isMobile ? 12 : 18, width: '100%',
                padding: isMobile ? '12px 16px' : '14px 28px', background: isOpen ? INK : 'transparent',
                color: isOpen ? PAPER : INK, border: 'none', cursor: 'pointer',
                textAlign: 'left', transition: 'all 180ms', fontFamily: 'inherit',
              }}>
                <div style={{ width: isMobile ? 36 : 44, height: isMobile ? 36 : 44, flexShrink: 0, border: `2px solid ${isOpen ? ACCENT : INK}`, display: 'flex', alignItems: 'center', justifyContent: 'center', background: isOpen ? INK : PAPER, transition: 'all 180ms' }}>
                  <img src={emp.logo} alt="" style={{ width: isMobile ? 22 : 28, height: isMobile ? 22 : 28, objectFit: 'contain', filter: isOpen ? 'brightness(0) invert(1)' : 'grayscale(1) contrast(1.2)', transition: 'filter 180ms' }} />
                </div>
                <div style={{ flex: 1, minWidth: 0 }}>
                  <div style={{ display: 'flex', alignItems: 'baseline', gap: isMobile ? 8 : 14, marginBottom: 4, flexWrap: isMobile ? 'wrap' : 'nowrap' }}>
                    <span style={{ fontWeight: 900, fontSize: isMobile ? 16 : 'clamp(20px, 2.5vw, 30px)', letterSpacing: '-0.03em' }}>{emp.company}</span>
                    <span style={{ fontFamily: 'var(--mono)', fontSize: isMobile ? 9 : 11, letterSpacing: '0.2em', color: ACCENT }}>{emp.years}</span>
                    <span style={{ fontFamily: 'var(--mono)', fontSize: isMobile ? 9 : 10, opacity: 0.4, letterSpacing: '0.15em' }}>{emp.roles.length} {emp.roles.length === 1 ? 'role' : 'roles'}</span>
                  </div>
                  {!isMobile && <div style={{ fontSize: 14, opacity: 0.6, lineHeight: 1.5, maxWidth: 800 }}>{emp.summary}</div>}
                </div>
                <span style={{ fontFamily: 'var(--mono)', fontSize: 22, color: ACCENT, transition: 'transform 240ms', transform: isOpen ? 'rotate(90deg)' : 'rotate(0deg)', flexShrink: 0 }}>▸</span>
              </button>

              {/* expanded roles */}
              <div style={{ maxHeight: isOpen ? 2000 : 0, overflow: 'hidden', transition: 'max-height 300ms ease-in-out' }}>
                {emp.roles.map((r, j) => (
                  <a key={j} href="https://www.linkedin.com/in/marounau" target="_blank" rel="noreferrer" style={{
                    display: isMobile ? 'block' : 'flex', alignItems: 'baseline', gap: 14,
                    padding: isMobile ? '12px 16px' : '14px 28px 14px 82px',
                    background: j % 2 === 0 ? PAPER_DIM : PAPER,
                    borderTop: `1px solid ${INK}15`,
                    textDecoration: 'none', color: INK,
                    transition: 'padding-left 180ms',
                  }}
                    onMouseEnter={e => { if (!isMobile) e.currentTarget.style.paddingLeft = '96px'; }}
                    onMouseLeave={e => { if (!isMobile) e.currentTarget.style.paddingLeft = '82px'; }}
                  >
                    <div style={isMobile ? { display: 'flex', alignItems: 'baseline', gap: 10, marginBottom: 4 } : { display: 'contents' }}>
                      <span style={{ fontFamily: 'var(--mono)', fontSize: isMobile ? 10 : 11, color: ACCENT, letterSpacing: '0.15em', minWidth: isMobile ? 'auto' : 70 }}>{r.t}</span>
                      <span style={{ fontWeight: 800, fontSize: isMobile ? 15 : 17, letterSpacing: '-0.01em', minWidth: isMobile ? 'auto' : 240 }}>{r.role}</span>
                    </div>
                    <span style={{ fontSize: isMobile ? 12 : 13, opacity: 0.55, flex: 1, lineHeight: 1.5, display: isMobile ? 'block' : 'inline', marginBottom: isMobile ? 6 : 0 }}>{r.note}</span>
                    <div style={isMobile ? { display: 'flex', alignItems: 'center', justifyContent: 'space-between' } : { display: 'contents' }}>
                      <span style={{ fontFamily: 'var(--mono)', fontSize: isMobile ? 9 : 10, opacity: 0.4, letterSpacing: '0.12em', padding: '3px 8px', border: `1px solid ${INK}22` }}>{r.stack}</span>
                      <span style={{ fontSize: 16, color: ACCENT, marginLeft: 8 }}>↗</span>
                    </div>
                  </a>
                ))}
              </div>
            </div>
          );
        })}
      </section>
    </>
  );
}

// ─────────────────────────────────────────────────────────────
// SELECTED WORK — 3 project cards
// ─────────────────────────────────────────────────────────────
const projects = [
  { n: '001', title: '[PROJECT ONE]', kind: 'PRODUCT · 2025', blurb: 'one-line description of what it is and what it did.', tag: 'FEATURED' },
  { n: '002', title: '[PROJECT TWO]', kind: 'TOOL · 2024',   blurb: 'one-line description of what it is and what it did.' },
  { n: '003', title: '[PROJECT THREE]', kind: 'EXPERIMENT · 2024', blurb: 'one-line description of what it is and what it did.' },
];

function SelectedWork() {
  const isMobile = useIsMobile();
  return (
    <>
      <SectionHead num="02" title="SELECTED" sub="3 of ~14 · case studies on request" />
      <section style={{ padding: isMobile ? 12 : 22, borderBottom: `2px solid ${INK}`, display: 'grid', gridTemplateColumns: isMobile ? '1fr' : '1.3fr 1fr 1fr', gap: 12 }}>
        {projects.map((p, i) => (
          <a key={i} href="#" style={{
            position: 'relative', border: `2px solid ${INK}`, background: PAPER,
            padding: isMobile ? 16 : 22, textDecoration: 'none', color: INK,
            aspectRatio: isMobile ? 'auto' : (i === 0 ? 'auto' : '1 / 0.9'),
            minHeight: isMobile ? 'auto' : (i === 0 ? 360 : 'auto'),
            display: 'flex', flexDirection: 'column',
            overflow: 'hidden',
          }}>
            {/* placeholder image area */}
            <div style={{ flex: 1, border: `1px solid ${INK}`, background: 'repeating-linear-gradient(45deg, rgba(0,0,0,0.06) 0 2px, transparent 2px 12px)', marginBottom: 12, position: 'relative', minHeight: 120 }}>
              <div style={{ position: 'absolute', top: 8, left: 10, fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.2em' }}>{p.n}.JPG</div>
              {p.tag && <div style={{ position: 'absolute', top: 8, right: 10, fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.2em', color: PAPER, background: ACCENT, padding: '3px 8px' }}>{p.tag}</div>}
            </div>
            <div style={{ fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.25em', color: ACCENT, marginBottom: 6 }}>{p.kind}</div>
            <div style={{ fontSize: isMobile ? 22 : (i === 0 ? 38 : 24), fontWeight: 800, letterSpacing: '-0.02em', lineHeight: 1, marginBottom: 10 }}>{p.title}</div>
            <div style={{ fontSize: 13, opacity: 0.65, marginBottom: 14 }}>{p.blurb}</div>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', borderTop: `1px solid ${INK}`, paddingTop: 10, fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.2em' }}>
              <span style={{ opacity: 0.6 }}>READ · CASE STUDY</span>
              <span style={{ fontSize: 18 }}>↗</span>
            </div>
          </a>
        ))}
      </section>
    </>
  );
}

// ─────────────────────────────────────────────────────────────
// ASK TERMINAL — interactive Q&A about Maroun
// ─────────────────────────────────────────────────────────────
const marounFacts = {
  name: 'Maroun Maroun (Maroun Abou Maroun)',
  role: 'Director of Engineering at FDJ United (La Française des Jeux)',
  location: 'Sydney, Australia',
  leading: 'Data, Product, Engineering, Technology, and Delivery across Sydney, London, Stockholm, Paris and the Balkans. ~300 people.',
  building: 'Cloud-native, cloud-agnostic platforms. Streamlining processes and business units with agentic tooling and automation.',
  origin: 'Mechanical engineering → systems → internet → cloud → agentic AI. 20+ years.',
  languages: 'Arabic, English, limited Spanish',
  belief: 'The technology is the easy part. People build the culture, and the culture builds the organisations and products worth being part of.',
  ai: 'Pioneered the pivot towards AI and agentic AI at FDJ United, optimising delivery and operations. Building lean, agentic-first organisations.',
  experience: 'Started at Reckon in 2003 as Software Engineer. Caterpillar Inc for heavy-industry systems. MicroChannel Services MSP across APAC. Then FDJ United (Kindred) from 2016, progressing from Team Lead to IT Operations Manager to Head of Technology to Head of Engineering to Director of Engineering.',
  contact: 'LinkedIn: /in/marounau · Email: hi@maroun.au · Instagram: @maroun.au',
  interests: 'Engineering leadership, AI transformation, agentic workflows, cloud architecture, culture design, hands-on coding.',
};

function AskTerminal() {
  const [input, setInput] = useState('');
  const [history, setHistory] = useState([]);

  function answer(q) {
    const ql = q.toLowerCase();
    const kb = Object.entries(marounFacts);
    // Find best match
    let best = null;
    let bestScore = 0;
    for (const [key, val] of kb) {
      const words = key.split(/\s+/).concat(val.toLowerCase().split(/\s+/));
      const qwords = ql.split(/\s+/);
      let score = 0;
      for (const w of qwords) {
        if (w.length < 3) continue;
        if (key.includes(w)) score += 3;
        if (val.toLowerCase().includes(w)) score += 2;
      }
      if (score > bestScore) { bestScore = score; best = val; }
    }
    if (bestScore > 2) return best;
    // Greetings
    if (ql.match(/^(hi|hello|hey|g'day)/)) return 'g\'day! ask me anything about maroun. try: role, experience, ai, contact, or belief.';
    if (ql.match(/who|about/)) return `${marounFacts.name}. ${marounFacts.role}. Based in ${marounFacts.location}. ${marounFacts.origin}`;
    return 'try asking about: role, experience, ai, building, belief, contact, or languages.';
  }

  function onSubmit(e) {
    e.preventDefault();
    const q = input.trim();
    if (!q) return;
    setInput('');
    const a = answer(q);
    setHistory(h => [...h, { q, a }]);
  }

  return (
    <div style={{ marginTop: 14, borderTop: `1px dashed ${ACCENT}44`, paddingTop: 14 }}>
      {history.map((h, i) => (
        <div key={i} style={{ marginBottom: 10 }}>
          <div style={{ color: ACCENT, fontSize: 12 }}>&gt; {h.q}</div>
          <div style={{ fontSize: 12, opacity: 0.8, lineHeight: 1.6, marginTop: 4 }}>{h.a}</div>
        </div>
      ))}
      <form onSubmit={onSubmit} style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
        <span style={{ color: ACCENT, fontSize: 14 }}>&gt;</span>
        <input
          value={input}
          onChange={e => setInput(e.target.value)}
          placeholder="ask me anything..."
          style={{
            flex: 1, background: 'transparent', border: 'none', outline: 'none',
            color: PAPER, fontFamily: 'var(--mono)', fontSize: 14, padding: '4px 0',
          }}
        />
        <span className="blink" style={{ color: ACCENT, fontSize: 14, opacity: 0.9 }}>▌</span>
      </form>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// ABOUT — $ whoami terminal
// ─────────────────────────────────────────────────────────────
function About() {
  const isMobile = useIsMobile();
  return (
    <>
      <SectionHead id="about" num="03" title="ABOUT" sub="$ whoami --verbose" />
      <section style={{ flex: 1, padding: isMobile ? '12px 16px' : '18px 28px', borderBottom: `2px solid ${INK}`, display: 'flex', flexDirection: 'column' }}>
        <div style={{ marginBottom: isMobile ? 10 : 14, fontSize: isMobile ? 15 : 'clamp(17px, 1.6vw, 22px)', lineHeight: 1.3, letterSpacing: '-0.01em', fontWeight: 500 }}>
          <span style={{ color: ACCENT, fontFamily: 'var(--mono)', fontSize: isMobile ? 9 : 11, letterSpacing: '0.25em', display: 'block', marginBottom: 8 }}>&gt; cat ./summary.txt</span>
          I grew up on the analog-to-digital seam. Mechanical engineering first, then systems, the internet, cloud, and now a generation of software that writes, reasons, and operates alongside us. <span style={{ opacity: 0.55 }}>Twenty-plus years in, and I'm as comfortable in the engine room as I am in the boardroom. Today I'm focused on streamlining teams, processes, and businesses through Agentic workflows and automation.</span>
        </div>

        {/* portrait + terminal — 2-column layout */}
        <div style={{ flex: 1, display: 'grid', gridTemplateColumns: isMobile ? '1fr' : '280px 1fr', gap: 0, border: `2px solid ${INK}` }}>
          {/* portrait */}
          <div style={{ position: 'relative', overflow: 'hidden', background: INK, borderRight: isMobile ? 'none' : `2px solid ${INK}`, borderBottom: isMobile ? `2px solid ${INK}` : 'none' }}>
            <img src="portrait.png" alt="Maroun" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block', imageRendering: 'pixelated' }} />
            <div style={{ position: 'absolute', top: 12, right: 12, display: 'flex', alignItems: 'center', gap: 8, fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.25em', color: PAPER, textShadow: '0 1px 2px rgba(0,0,0,0.8)' }}>
              <span style={{ width: 8, height: 8, borderRadius: '50%', background: ACCENT, boxShadow: `0 0 10px ${ACCENT}`, animation: 'pulse 1.6s ease-in-out infinite' }} />
              LIVE
            </div>
            {[
              { top: 8, left: 8, bt: 2, bl: 2 },
              { top: 8, right: 8, bt: 2, br: 2 },
              { bottom: 44, left: 8, bb: 2, bl: 2 },
              { bottom: 44, right: 8, bb: 2, br: 2 },
            ].map((c, i) => (
              <div key={i} style={{
                position: 'absolute', width: 14, height: 14,
                top: c.top, left: c.left, right: c.right, bottom: c.bottom,
                borderTop: c.bt ? `2px solid ${ACCENT}` : 'none',
                borderBottom: c.bb ? `2px solid ${ACCENT}` : 'none',
                borderLeft: c.bl ? `2px solid ${ACCENT}` : 'none',
                borderRight: c.br ? `2px solid ${ACCENT}` : 'none',
              }} />
            ))}
            <div style={{ position: 'absolute', left: 0, right: 0, bottom: 0, background: INK, color: PAPER, padding: '8px 12px', fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.22em', display: 'flex', justifyContent: 'space-between', borderTop: `2px solid ${ACCENT}` }}>
              <span>PORTRAIT.001</span>
              <span style={{ opacity: 0.6 }}>SYD / AU</span>
            </div>
          </div>

          {/* terminal card */}
          <div style={{ background: INK, color: PAPER, padding: isMobile ? '10px 10px' : '12px 14px', fontFamily: 'var(--mono)' }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8, paddingBottom: 6, marginBottom: 8, borderBottom: `1px dashed ${ACCENT}88`, fontSize: 9, letterSpacing: '0.2em' }}>
              <span style={{ width: 8, height: 8, border: `1px solid ${ACCENT}` }} />
              <span style={{ width: 8, height: 8, border: `1px solid ${PAPER}` }} />
              <span style={{ width: 8, height: 8, border: `1px solid ${PAPER}` }} />
              <span style={{ marginLeft: 10, opacity: 0.7 }}>maroun@au : ~/about</span>
              <span style={{ marginLeft: 'auto', color: ACCENT }}>● LIVE</span>
            </div>
            <div style={{ color: ACCENT, marginBottom: 6, fontSize: 11 }}>$ whoami --verbose</div>
            <pre style={{ fontSize: isMobile ? 9 : 11, lineHeight: 1.5, whiteSpace: 'pre-wrap', margin: 0, color: PAPER, fontFamily: 'var(--mono)' }}>
{`> name      : Maroun Maroun
> based     : sydney, au ( -33.86, 151.20 )
> role      : director of engineering
> @         : fdj united · la française des jeux
> leading   : data, product, engineering,
             technology, delivery across
             sydney, london, stockholm,
             paris and the balkans
> building  : cloud-native, cloud-agnostic
             platforms. streamlining processes
             and business units with agentic
             tooling and automation.
> status    : `}<span style={{ color: ACCENT }}>building_and_leading</span>{`
> languages : arabic · english · limited spanish
> origin    : mech eng → systems → internet →
             cloud → agentic ai
> belief    : the technology is the easy part.
             people build the culture.
> ask       : `}<a href="#comms" style={{ color: ACCENT, textDecoration: 'underline' }}>say hi ↗</a>
            </pre>
            <AskTerminal />
          </div>
        </div>

        {/* beliefs row */}
        <div style={{ display: 'grid', gridTemplateColumns: isMobile ? '1fr' : 'repeat(3, 1fr)', gap: 0, border: `2px solid ${INK}`, borderTop: 'none' }}>
          {[
            { k: 'ON LEADING', v: 'I read the code. I sit with the on-call engineer when something is on fire. I open the dashboards myself.' },
            { k: 'ON AI', v: 'I\'ve built through every transition — analog to digital, on-prem to cloud, monolith to micro. AI makes good engineers dangerous. I ship it, not demo it.' },
            { k: 'ON CULTURE', v: 'The technology is the easy part. People build the culture, and the culture builds the products worth being part of.' },
          ].map(({ k, v }, i) => (
            <div key={k} style={{ padding: isMobile ? '8px 12px' : '10px 14px', borderRight: isMobile ? 'none' : (i < 2 ? `1px solid ${INK}` : 'none'), borderBottom: isMobile && i < 2 ? `1px solid ${INK}` : 'none' }}>
              <div style={{ fontFamily: 'var(--mono)', fontSize: 9, letterSpacing: '0.25em', color: ACCENT, marginBottom: 4 }}>// {k}</div>
              <div style={{ fontSize: 12, lineHeight: 1.35 }}>{v}</div>
            </div>
          ))}
        </div>

        {/* tech radar */}
        <div style={{ border: `2px solid ${INK}`, borderTop: 'none', padding: isMobile ? '8px 12px' : '10px 14px' }}>
          <div style={{ fontFamily: 'var(--mono)', fontSize: 9, letterSpacing: '0.25em', color: ACCENT, marginBottom: 6 }}>// TECH RADAR</div>
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 4 }}>
            {techStack.map(t => (
              <span key={t.name} onMouseEnter={() => retroAudio.blip()} style={{
                fontFamily: 'var(--mono)', fontSize: 9, letterSpacing: '0.08em',
                padding: '3px 8px', border: `1px solid ${INK}`,
                background: t.level >= 5 ? INK : t.level >= 4 ? `${INK}cc` : `${INK}55`,
                color: t.level >= 4 ? PAPER : INK,
                opacity: 0.4 + t.level * 0.12,
                transition: 'all 150ms', cursor: 'default',
              }}>{t.name}</span>
            ))}
          </div>
        </div>
      </section>
    </>
  );
}

// ─────────────────────────────────────────────────────────────
// LENS
// ─────────────────────────────────────────────────────────────
function Lens() {
  const isMobile = useIsMobile();
  const [posts, setPosts] = useState([]);

  useEffect(() => {
    fetch('img/lens/manifest.json')
      .then(r => r.json())
      .then(setPosts)
      .catch(() => {});
  }, []);

  return (
    <>
      <SectionHead id="lens" num="04" title="LENS" sub="IG · curated feed" />
      <section style={{ flex: 1, padding: isMobile ? 12 : 22, borderBottom: `2px solid ${INK}` }}>
        <div style={{ display: 'flex', gap: 12, marginBottom: 14, fontFamily: 'var(--mono)', fontSize: isMobile ? 9 : 11, letterSpacing: '0.2em', flexWrap: isMobile ? 'wrap' : 'nowrap' }}>
          <span style={{ padding: '6px 12px', background: INK, color: PAPER, border: `1px solid ${INK}` }}>[INSTAGRAM]</span>
          <span style={{ marginLeft: isMobile ? 0 : 'auto', opacity: 0.5 }}>{posts.length} posts · @maroun.au · follow to see more</span>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: isMobile ? 'repeat(2, 1fr)' : 'repeat(4, 1fr)', gap: 4 }}>
          {posts.map((post, i) => (
            <a key={i} href="https://www.instagram.com/maroun.au/" target="_blank" rel="noreferrer" style={{
              position: 'relative', cursor: 'pointer', overflow: 'hidden',
              aspectRatio: '1/1', display: 'block', textDecoration: 'none',
            }}
              onMouseEnter={e => { e.currentTarget.querySelector('.lens-overlay').style.opacity = 1; }}
              onMouseLeave={e => { e.currentTarget.querySelector('.lens-overlay').style.opacity = 0; }}
            >
              <img src={post.src} alt="" loading="lazy" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block', filter: 'blur(12px) saturate(0.6)', transform: 'scale(1.1)' }} />
              <div className="lens-overlay" style={{
                position: 'absolute', inset: 0, background: `${INK}aa`,
                display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
                gap: 8, opacity: 0, transition: 'opacity 180ms',
              }}>
                <span style={{ fontFamily: 'var(--mono)', fontSize: 11, letterSpacing: '0.2em', color: ACCENT, fontWeight: 700 }}>FOLLOW ON IG ↗</span>
                <span style={{ fontFamily: 'var(--mono)', fontSize: 9, letterSpacing: '0.15em', color: PAPER, opacity: 0.6 }}>@maroun.au</span>
              </div>
            </a>
          ))}
        </div>
      </section>
    </>
  );
}

// ─────────────────────────────────────────────────────────────
// COMMS
// ─────────────────────────────────────────────────────────────
const channels = [
  { ch: '/ch.01', k: 'LINKEDIN',  v: '/in/marounau',             href: 'https://www.linkedin.com/in/marounau' },
  { ch: '/ch.02', k: 'GITHUB',    v: '@whyicode',                href: 'https://github.com/whyicode' },
  { ch: '/ch.03', k: 'INSTAGRAM', v: '@maroun.au',               href: '#' },
  { ch: '/ch.04', k: 'EMAIL',     v: 'hi@maroun.au',             href: 'mailto:hi@maroun.au' },
];

function Comms() {
  const isMobile = useIsMobile();
  return (
    <>
      <SectionHead id="comms" num="05" title="COMMS" sub="open channel · reply < 24h" />
      <section style={{ flex: 1, padding: isMobile ? '16px 16px' : '28px 28px', borderBottom: `2px solid ${INK}`, display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
        <div style={{ fontSize: isMobile ? 'clamp(40px, 11vw, 72px)' : 'clamp(64px, 9vw, 120px)', fontWeight: 900, letterSpacing: '-0.06em', lineHeight: 0.82, marginBottom: isMobile ? 14 : 20 }}>
          SAY HI<span style={{ color: ACCENT }}>.</span>
        </div>
        <div style={{ borderTop: `2px solid ${INK}` }}>
          {channels.map((c, i) => (
            <a key={c.k} href={c.href} target={c.href.startsWith('http') ? '_blank' : undefined} rel="noreferrer" style={{
              display: 'grid', gridTemplateColumns: isMobile ? '1fr 30px' : '100px 220px 1fr 40px',
              padding: isMobile ? '12px 4px' : '16px 4px', borderBottom: `1px solid ${INK}`,
              textDecoration: 'none', color: INK, alignItems: isMobile ? 'center' : 'baseline',
              transition: 'padding 180ms', gap: isMobile ? 4 : 0,
            }}
              onMouseEnter={e => { if (!isMobile) e.currentTarget.style.paddingLeft = '24px'; }}
              onMouseLeave={e => { if (!isMobile) e.currentTarget.style.paddingLeft = '4px'; }}
            >
              {isMobile ? (
                <>
                  <div>
                    <div style={{ display: 'flex', alignItems: 'baseline', gap: 10, marginBottom: 2 }}>
                      <span style={{ fontFamily: 'var(--mono)', fontSize: 10, color: ACCENT, letterSpacing: '0.2em' }}>{c.ch}</span>
                      <span style={{ fontWeight: 800, fontSize: 18, letterSpacing: '-0.02em' }}>{c.k}</span>
                    </div>
                    <span style={{ fontFamily: 'var(--mono)', fontSize: 11, opacity: 0.7 }}>{c.v}</span>
                  </div>
                  <span style={{ textAlign: 'right', fontSize: 18, color: ACCENT }}>→</span>
                </>
              ) : (
                <>
                  <span style={{ fontFamily: 'var(--mono)', fontSize: 12, color: ACCENT, letterSpacing: '0.2em' }}>{c.ch}</span>
                  <span style={{ fontWeight: 800, fontSize: 22, letterSpacing: '-0.02em' }}>{c.k}</span>
                  <span style={{ fontFamily: 'var(--mono)', fontSize: 14, opacity: 0.7 }}>{c.v}</span>
                  <span style={{ textAlign: 'right', fontSize: 22, color: ACCENT }}>→</span>
                </>
              )}
            </a>
          ))}
        </div>
      </section>
    </>
  );
}

// ─────────────────────────────────────────────────────────────
// BLOG — LinkedIn articles
// ─────────────────────────────────────────────────────────────
function Blog() {
  const isMobile = useIsMobile();
  const [articles, setArticles] = useState([]);
  const [hovered, setHovered] = useState(null);

  useEffect(() => {
    fetch('img/blog/manifest.json')
      .then(r => r.json())
      .then(setArticles)
      .catch(() => {});
  }, []);

  return (
    <>
      <SectionHead id="blog" num="04" title="WRITING" sub="articles · linkedin · long-form" />
      <section style={{ flex: 1, padding: isMobile ? '16px 16px' : '28px 28px', borderBottom: `2px solid ${INK}` }}>
        <div style={{ display: 'flex', gap: 12, marginBottom: isMobile ? 14 : 20, fontFamily: 'var(--mono)', fontSize: isMobile ? 9 : 11, letterSpacing: '0.2em', flexWrap: isMobile ? 'wrap' : 'nowrap' }}>
          <span style={{ padding: '6px 12px', background: INK, color: PAPER, border: `1px solid ${INK}` }}>[ARTICLES]</span>
          <span style={{ marginLeft: isMobile ? 0 : 'auto', opacity: 0.5 }}>{articles.length} published · linkedin</span>
        </div>
        <div style={{ borderTop: `2px solid ${INK}` }}>
          {articles.map((a, i) => (
            <a key={i} href={a.url} target="_blank" rel="noreferrer" style={{
              display: 'grid', gridTemplateColumns: isMobile ? '1fr' : '140px 1fr auto', gap: isMobile ? 10 : 18,
              padding: isMobile ? '12px 0' : '18px 0', borderBottom: `1px solid ${INK}`,
              textDecoration: 'none', color: INK, alignItems: isMobile ? 'start' : 'center',
              transition: 'padding 180ms',
              paddingLeft: !isMobile && hovered === i ? 20 : 0,
            }}
              onMouseEnter={() => setHovered(i)}
              onMouseLeave={() => setHovered(null)}
            >
              <div style={{ width: isMobile ? '100%' : 140, height: isMobile ? 120 : 80, overflow: 'hidden', border: `1px solid ${INK}`, flexShrink: 0 }}>
                <img src={a.src} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block', filter: hovered === i ? 'none' : 'grayscale(0.8)', transition: 'filter 180ms' }} />
              </div>
              <div>
                <div style={{ fontFamily: 'var(--mono)', fontSize: 10, letterSpacing: '0.2em', color: ACCENT, marginBottom: 8 }}>//{String(i + 1).padStart(2, '0')}</div>
                <div style={{ fontSize: isMobile ? 16 : 20, fontWeight: 800, letterSpacing: '-0.02em', lineHeight: 1.3, marginBottom: 6 }}>{a.title}</div>
                {a.snippet && <div style={{ fontFamily: 'var(--mono)', fontSize: isMobile ? 11 : 12, opacity: 0.55, lineHeight: 1.5, maxWidth: 600 }}>{a.snippet.slice(0, isMobile ? 80 : 120)}...</div>}
              </div>
              <span style={{ fontSize: 22, color: hovered === i ? ACCENT : INK, transition: 'color 180ms', display: isMobile ? 'none' : 'block' }}>→</span>
            </a>
          ))}
        </div>
      </section>
    </>
  );
}

// ─────────────────────────────────────────────────────────────
// ORIGIN — Signal History era selector
// ─────────────────────────────────────────────────────────────
const originEras = [
  { img: 'img/origin-era1.jpg', year: '████ — 1995', label: 'ANALOG ERA', color: '#39ff14',
    desc: 'Born at the edge of two worlds. Cassette tapes rewinding in the deck, VHS tracking lines on the TV, rotary phones, and encyclopedias that weighed more than me. My first computer was a Commodore 64. Loading games from tape meant waiting ten minutes and hoping nothing crashed. Technology had weight. It had texture. Every interaction was physical. You turned dials, flipped switches, and blew into cartridges. That era taught patience, resourcefulness, and the magic of making something work with your hands.',
    tags: ['CASSETTE','VHS','CRT','C64','ANALOG','CARTRIDGE'] },
  { img: 'img/origin-era2.jpg', year: '1995 — 2005', label: 'DIGITAL DAWN', color: '#00e5ff',
    desc: 'The modem screamed, and the world opened up. Dial-up internet, GeoCities pages built in Notepad, IRC channels at 2am, and the first time a webpage I made went live. Floppy disks gave way to CD-ROMs. LAN parties meant dragging CRT monitors to a mate\'s house. I learned HTML before I learned to drive. This was the era of discovery, where every click led somewhere unexpected. From Netscape to broadband, from static pages to dynamic systems, I did not just witness the birth of the digital world. I grew up inside it.',
    tags: ['DIAL-UP','IRC','HTML','LAN','NETSCAPE','GEOCITIES'] },
  { img: 'img/origin-era3.jpg', year: '2005 — 2020', label: 'SCALE ERA', color: '#0077ff',
    desc: 'Desktop apps became cloud services. Small teams became global organisations. I went from writing code to leading the people who write the code. This era was about scale in every dimension: infrastructure that spans continents, platforms serving millions, teams across a dozen time zones. Kubernetes, Grafana dashboards, 3am incident calls, and the satisfaction of a clean deploy on a Friday afternoon. I learned that technology is the easy part. The real challenge is building organisations that can move fast without breaking trust.',
    tags: ['CLOUD','DEVOPS','K8S','GLOBAL','AWS','SCALE'] },
  { img: 'img/origin-era4.jpg', year: '2020 — NOW', label: 'AUTONOMOUS ERA', color: ACCENT,
    desc: 'The tools started thinking back. AI went from a research paper to a daily collaborator. I now lead with AI-native thinking, building agentic systems where autonomous workflows handle what used to take entire teams. The same curiosity that was sparked by a Commodore 64 now drives how I think about cognitive automation, organisational design in the AI era, and the future of human-machine collaboration. The frontier is not coming. It is here.',
    tags: ['AI-NATIVE','AGENTIC','LLM','AUTONOMOUS','AGENTS','FUTURE'] },
  { img: 'img/hangar-zone5.webp', year: 'NOW → ████', label: 'CONVERGENCE ERA', color: '#ffd700',
    desc: 'The lines are dissolving. Between human and machine. Between builder and operator. Between local and everywhere. AI agents don\'t just assist anymore. They reason, collaborate, and ship. The engineer of tomorrow won\'t write more code; they\'ll architect intent and govern outcomes. Organisations will be smaller, faster, and more leveraged than anything we\'ve built before. The real question is no longer what technology can do. It\'s what we choose to point it at. Climate, health, equity, education. The tools are ready. The species needs to catch up. I\'ve spent 25 years building through every transition. This next one is the biggest, and I intend to be in the room where it\'s shaped.',
    tags: ['AGENTS','AGI','CLIMATE-TECH','INTENT-DRIVEN','POST-CODE','CONVERGENCE'] },
];

function Origin() {
  const isMobile = useIsMobile();
  const [era, setEra] = useState(0);
  const [fading, setFading] = useState(false);

  function switchEra(idx) {
    if (idx === era || fading) return;
    setFading(true);
    setTimeout(() => {
      setEra(idx);
      setFading(false);
    }, 400);
  }

  const e = originEras[era];
  const progressPct = ((era + 1) / originEras.length) * 100;

  return (
    <section style={{ position: 'relative', flex: 1, background: INK, color: PAPER, overflow: 'hidden' }}>
      {/* background images — crossfade */}
      {originEras.map((item, i) => (
        <div key={item.label} style={{
          position: 'absolute', inset: 0, zIndex: 0,
          backgroundImage: `url(${item.img})`, backgroundSize: 'cover', backgroundPosition: 'center',
          opacity: i === era ? 1 : 0, transition: 'opacity 0.8s ease',
        }} />
      ))}
      {/* overlays — match hero treatment */}
      <div style={{ position: 'absolute', inset: 0, zIndex: 1, background: 'radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.6) 100%)' }} />
      <div style={{ position: 'absolute', inset: 0, zIndex: 1, background: 'linear-gradient(to top, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.15) 35%, transparent 60%)' }} />
      <div style={{ position: 'absolute', inset: 0, zIndex: 1, background: `linear-gradient(to bottom, ${PAPER} 0%, ${PAPER}f2 4%, ${PAPER}dd 8%, ${PAPER}aa 14%, ${PAPER}66 22%, ${PAPER}33 32%, ${PAPER}11 42%, transparent 55%)` }} />
      <div style={{ position: 'absolute', inset: 0, zIndex: 1, backgroundImage: 'repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.15) 2px, rgba(0,0,0,0.15) 4px)', pointerEvents: 'none', WebkitMaskImage: 'linear-gradient(to bottom, transparent 0%, black 20%)', maskImage: 'linear-gradient(to bottom, transparent 0%, black 20%)' }} />

      {/* side arrows */}
      <button onClick={() => switchEra((era - 1 + originEras.length) % originEras.length)} style={{
        position: 'absolute', left: isMobile ? 8 : 28, top: '50%', transform: 'translateY(-50%)', zIndex: 5,
        width: isMobile ? 32 : 44, height: isMobile ? 60 : 120, background: `${INK}33`, backdropFilter: 'blur(6px)',
        border: `1px solid ${PAPER}22`, color: PAPER, fontSize: isMobile ? 20 : 28, cursor: 'pointer',
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        transition: 'all 0.2s',
      }}
        onMouseEnter={e => { e.currentTarget.style.background = `${INK}66`; e.currentTarget.style.borderColor = `${PAPER}55`; }}
        onMouseLeave={e => { e.currentTarget.style.background = `${INK}33`; e.currentTarget.style.borderColor = `${PAPER}22`; }}
      >‹</button>
      <button onClick={() => switchEra((era + 1) % originEras.length)} style={{
        position: 'absolute', right: isMobile ? 8 : 28, top: '50%', transform: 'translateY(-50%)', zIndex: 5,
        width: isMobile ? 32 : 44, height: isMobile ? 60 : 120, background: `${INK}33`, backdropFilter: 'blur(6px)',
        border: `1px solid ${PAPER}22`, color: PAPER, fontSize: isMobile ? 20 : 28, cursor: 'pointer',
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        transition: 'all 0.2s',
      }}
        onMouseEnter={e => { e.currentTarget.style.background = `${INK}66`; e.currentTarget.style.borderColor = `${PAPER}55`; }}
        onMouseLeave={e => { e.currentTarget.style.background = `${INK}33`; e.currentTarget.style.borderColor = `${PAPER}22`; }}
      >›</button>

      {/* content */}
      <div style={{ position: 'relative', zIndex: 2, maxWidth: 1100, margin: '0 auto', padding: isMobile ? '28px 16px' : '36px 28px', textAlign: 'center' }}>
        {/* spacer */}
        <div style={{ height: isMobile ? '2vh' : '4vh' }} />

        {/* content backdrop */}
        <div style={{ background: `${INK}66`, backdropFilter: 'blur(10px)', WebkitBackdropFilter: 'blur(10px)', border: `1px solid ${PAPER}11`, padding: isMobile ? '24px 16px' : '32px 40px', maxWidth: 800, margin: '0 auto' }}>

        <p style={{ fontFamily: 'var(--mono)', fontSize: isMobile ? 9 : 11, letterSpacing: '0.3em', color: ACCENT, marginBottom: 24, marginTop: 0 }}>SELECT YOUR ERA</p>

        {/* era progress bar */}
        <div style={{ maxWidth: 500, margin: '0 auto 24px' }}>
          <div style={{ position: 'relative', height: 6, background: `${PAPER}11`, border: `1px solid ${PAPER}15` }}>
            <div style={{ height: '100%', background: `linear-gradient(90deg, #39ff14 0%, #00e5ff 25%, #0077ff 50%, ${ACCENT} 75%, #ffd700 100%)`, width: `${progressPct}%`, transition: 'width 0.6s ease', boxShadow: `0 0 8px ${e.color}44` }} />
            <div style={{ position: 'absolute', top: 14, left: 0, right: 0, display: 'flex', justifyContent: 'space-around' }}>
              {['I','II','III','IV','V'].map((n, i) => (
                <span key={n} onClick={() => switchEra(i)} style={{
                  fontFamily: 'var(--mono)', fontSize: 9, letterSpacing: '0.1em', cursor: 'pointer',
                  color: i === era ? e.color : `${PAPER}44`,
                  textShadow: i === era ? `0 0 6px ${e.color}66` : 'none',
                  transition: 'all 0.2s',
                }}>{n}</span>
              ))}
            </div>
          </div>
        </div>

        {/* era info */}
        <div style={{ transition: 'opacity 0.3s ease', opacity: fading ? 0 : 1, marginBottom: 24 }}>
          {/* year + label */}
          <div style={{ display: 'flex', justifyContent: 'center', gap: 18, alignItems: 'center', marginBottom: 14 }}>
            <span style={{ fontFamily: 'var(--mono)', fontSize: 12, letterSpacing: '0.2em', color: e.color, textShadow: `0 0 8px ${e.color}88` }}>{e.year}</span>
            <span style={{ fontFamily: 'var(--mono)', fontSize: 14, letterSpacing: '0.25em', fontWeight: 700, textShadow: `0 0 12px ${PAPER}44` }}>{e.label}</span>
          </div>
          {/* description */}
          <p style={{ fontSize: 'clamp(13px, 1.4vw, 16px)', lineHeight: 2, maxWidth: 700, margin: '0 auto 20px', opacity: 0.85, textShadow: '0 2px 6px rgba(0,0,0,0.9)' }}>
            {e.desc}
          </p>
          {/* tags */}
          <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', justifyContent: 'center' }}>
            {e.tags.map(t => (
              <span key={t} style={{
                fontFamily: 'var(--mono)', fontSize: 8, padding: '3px 10px', letterSpacing: '0.15em',
                background: `${e.color}1f`, border: `1px solid ${e.color}4d`, color: `${e.color}cc`,
                transition: 'all 0.3s',
              }}>{t}</span>
            ))}
          </div>
        </div>

        {/* dot nav */}
        <div style={{ display: 'flex', gap: 10, justifyContent: 'center', marginTop: 24 }}>
          {originEras.map((_, i) => (
            <button key={i} onClick={() => switchEra(i)} style={{
              width: 28, height: 28, background: i === era ? `${e.color}26` : `${PAPER}0f`,
              border: `2px solid ${i === era ? e.color : PAPER + '26'}`, color: i === era ? e.color : `${PAPER}55`,
              fontFamily: 'var(--mono)', fontSize: 8, cursor: 'pointer',
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              transition: 'all 0.15s', boxShadow: i === era ? `0 0 10px ${e.color}4d` : 'none',
            }}>{i + 1}</button>
          ))}
        </div>

        {/* manifesto line */}
        <div style={{ marginTop: 24, padding: '18px 24px', background: `${PAPER}08`, border: `1px solid ${PAPER}15`, textAlign: 'center' }}>
          <p style={{ fontFamily: 'var(--mono)', fontSize: 13, letterSpacing: '0.1em', lineHeight: 1.8, opacity: 0.9 }}>
            The analog world taught discipline. The digital world unlocked scale. AI is redefining leverage.{' '}
            <span style={{ color: ACCENT, fontWeight: 700 }}>Two worlds made me. I'm building the third.</span>
          </p>
        </div>

        </div>{/* end content backdrop */}
      </div>
    </section>
  );
}

// ─────────────────────────────────────────────────────────────
// FOOTER
// ─────────────────────────────────────────────────────────────
function Footer() {
  const isMobile = useIsMobile();
  const visits = useVisitorCount();
  return (
    <footer style={{ padding: isMobile ? '12px 16px 10px' : '14px 28px 12px', background: INK, color: PAPER, fontFamily: 'var(--mono)', fontSize: 12 }}>
      <div style={{ display: 'flex', alignItems: isMobile ? 'flex-start' : 'center', justifyContent: 'space-between', flexWrap: isMobile ? 'wrap' : 'nowrap', gap: isMobile ? 12 : 20 }}>
        {/* wordmark */}
        <div style={{ fontSize: isMobile ? 28 : 42, fontWeight: 900, letterSpacing: '-0.06em', lineHeight: 1, flexShrink: 0 }}>
          MAROUN<span style={{ color: ACCENT }}>.</span>AU
        </div>
        {/* bio */}
        <div style={{ opacity: 0.6, fontSize: 11, lineHeight: 1.5, maxWidth: 320, flexShrink: 1 }}>
          Director of Engineering at FDJ United. Building lean, agentic-first organisations across five cities. Sydney / AU.
        </div>
        {/* meta */}
        <div style={{ display: 'flex', gap: isMobile ? 12 : 20, alignItems: 'center', fontSize: 10, letterSpacing: '0.15em', opacity: 0.5, flexShrink: 0, flexWrap: 'wrap' }}>
          <span>© 2026</span>
          <span>no cookies</span>
          <span style={{ border: `1px solid ${PAPER}33`, padding: '2px 8px', letterSpacing: '0.2em' }}>VISITS: {String(visits).padStart(6, '0')}</span>
          <span>{'(\\/)~~~~(\\/)'}</span>
        </div>
      </div>
    </footer>
  );
}

// ─────────────────────────────────────────────────────────────
// CRAB TERMINAL — right-side drawer with window.claude chat
// ─────────────────────────────────────────────────────────────

// ─────────────────────────────────────────────────────────────
// APP
// ─────────────────────────────────────────────────────────────
// INTRO SPLASH
// ─────────────────────────────────────────────────────────────
const introVideos = [
  { mp4: 'video/intro.mp4', webm: 'video/intro.webm' },
  { mp4: 'video/intro-2.mp4', webm: 'video/intro-2.webm' },
  { mp4: 'video/intro-3.mp4', webm: 'video/intro-3.webm' },
  { mp4: 'video/intro-4.mp4', webm: 'video/intro-4.webm' },
];

function Intro({ onEnter }) {
  const [exiting, setExiting] = useState(false);
  const [vid] = useState(() => {
    // Avoid repeating the last video
    const lastIdx = parseInt(sessionStorage.getItem('introVid') || '-1');
    let candidates = introVideos.map((v, i) => i).filter(i => i !== lastIdx);
    if (!candidates.length) candidates = introVideos.map((v, i) => i);
    const pick = candidates[Math.floor(Math.random() * candidates.length)];
    sessionStorage.setItem('introVid', pick);
    const v = introVideos[pick];
    return { mp4: v.mp4, webm: v.webm };
  });

  function startAudio() {
    globalAudio.init();
    if (!globalAudio.userInteracted) {
      globalAudio.userInteracted = true;
      if (globalAudio.el.src) {
        if (globalAudio.idx === 0) globalAudio.el.currentTime = 13;
        globalAudio.el.play().then(() => { globalAudio.playing = true; globalAudio.notify(); }).catch(() => {});
      }
    }
  }

  function enter(fromClick) {
    if (exiting) return;
    setExiting(true);
    if (fromClick) startAudio();
    setTimeout(onEnter, 1200);
  }

  return (
    <div onClick={() => enter(true)} style={{
      position: 'fixed', inset: 0, zIndex: 200, background: INK,
      overflow: 'hidden', cursor: 'pointer',
      animation: exiting ? 'introFadeOut 1.2s ease forwards' : undefined,
    }}>
      <video autoPlay muted playsInline onEnded={() => enter(false)} style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }}>
        <source src={vid.webm} type="video/webm" />
        <source src={vid.mp4} type="video/mp4" />
      </video>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
function App() {
  const [showIntro, setShowIntro] = useState(() => !window.location.hash || window.location.hash === '#');
  const [page, setPage] = useState('home');
  const [showPalette, setShowPalette] = useState(false);
  const [konami, dismissKonami] = useKonamiCode();
  const [transitioning, setTransitioning] = useState(false);
  useFaviconAnimation();

  function navigate(p) {
    if (p === page) return;
    setPage(p);
    window.scrollTo(0, 0);
    window.history.pushState(null, '', p === 'home' ? '#' : `#${p}`);
  }

  // Handle browser back/forward
  useEffect(() => {
    function onHash() {
      const h = window.location.hash.slice(1);
      setPage(h && ['work', 'about', 'origin', 'blog', 'lens', 'comms'].includes(h) ? h : 'home');
    }
    window.addEventListener('hashchange', onHash);
    onHash();
    return () => window.removeEventListener('hashchange', onHash);
  }, []);

  // Command palette shortcut: / or Ctrl+K
  useEffect(() => {
    function onKey(e) {
      if (e.key === '/' && !e.ctrlKey && !e.metaKey && document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA') {
        e.preventDefault();
        setShowPalette(true);
      }
      if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
        e.preventDefault();
        setShowPalette(p => !p);
      }
    }
    window.addEventListener('keydown', onKey);
    return () => window.removeEventListener('keydown', onKey);
  }, []);

  const pages = { work: Work, about: About, origin: Origin, blog: Blog, lens: Lens, comms: Comms };
  const PageComponent = pages[page];

  return (
    <>
    {showIntro && <Intro onEnter={() => setShowIntro(false)} />}
    {showPalette && <CommandPalette onNavigate={navigate} onClose={() => setShowPalette(false)} />}
    {konami && <KonamiEasterEgg onDismiss={dismissKonami} />}
    <PageTransition active={transitioning} />
    <div style={{ display: 'flex', flexDirection: 'column', height: '100%', overflow: 'hidden' }}>
      <TopBar page={page} onNavigate={navigate} />
      <main style={{ flex: 1, overflow: page === 'home' ? 'hidden' : 'auto' }}>
        {page === 'home' ? (
          <Hero onNavigate={navigate} introDone={!showIntro} />
        ) : (
          <div style={{ display: 'flex', flexDirection: 'column', minHeight: '100%' }}>
            <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
              <PageComponent />
            </div>
            <Footer />
          </div>
        )}
      </main>
    </div>
    </>
  );
}

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