/* global React */

const DC = {
  bg: '#0B0C0E',
  bg1: '#141518',
  bg2: '#191A1D',
  bone: '#E6DCCB',
  softBone: 'rgba(230,220,203,0.72)',
  grey: '#8A8A86',
  mute: '#52524F',
  border: '#1F2024',
  borderHi: '#33353A',
  cyan: '#59A3B3',
  cyanHi: '#7EBFCD',
  brass: '#B9A37E',
  brassHi: '#D4BC95',
  ok: '#6FB89B',
};

const DF = {
  display: "'Manrope', system-ui, sans-serif",
  sans: "'Inter', system-ui, sans-serif",
  mono: "'Inter', system-ui, sans-serif",
  serif: "'Cormorant Garamond', Georgia, serif",
};

const dease = 'cubic-bezier(0.2,0.7,0.2,1)';
const dwrap = { width: 'min(1160px, calc(100% - 48px))', margin: '0 auto' };

function useIsNarrow(breakpoint = 900) {
  const getValue = () => (typeof window !== 'undefined' ? window.innerWidth < breakpoint : false);
  const [isNarrow, setIsNarrow] = React.useState(getValue);
  React.useEffect(() => {
    function onResize() { setIsNarrow(getValue()); }
    onResize();
    window.addEventListener('resize', onResize);
    return () => window.removeEventListener('resize', onResize);
  }, [breakpoint]);
  return isNarrow;
}

const pageData = {
  'how-it-works': {
    navLabel: 'How It Works',
    eyebrow: 'Workflow',
    title: 'Stop sorting. Start using.',
    intro: 'Your audience is already filming the show. But without a system, that footage ends up scattered across DMs and social tags, making it impossible to use for your next campaign. Showgaze gives you a clean, organized folder of synced footage, ready to cut.',
    facts: ['Organized folders', 'Synced to desk audio', 'Production-ready'],
    heroPanel: {
      kicker: 'The Outcome',
      title: 'A clean handover package, not an inbox full of Google Drive links.',
      body: 'We collect the raw clips, filter out the dark and shaky ones, and deliver a timeline that your editor can actually use. You get the crowd energy without the administrative mess.',
    },
    flow: [
      { step: 'Collect', note: 'A dedicated, frictionless upload path for the audience' },
      { step: 'Sort', note: 'Incoming clips are manually reviewed and filtered' },
      { step: 'Sync', note: 'Every usable clip is aligned to your reference audio' },
      { step: 'Deliver', note: 'A production-ready folder handed directly to your editor' },
    ],
    cards: [
      {
        title: 'Reduce the after-show scramble.',
        body: 'Stop chasing clips across platforms. We set up a dedicated collection path that automatically sorts incoming footage before you even look at it.',
        image: '/assets/images/industrial_aperture.png',
        imageAlt: 'Flat vector industrial aperture infrastructure sorting incoming footage streams',
      },
      {
        title: 'Everything is synced.',
        body: 'Every clip is aligned to the reference audio using our custom sync engine. Your editor doesn\'t waste hours matching waveforms.',
      },
      {
        title: 'Built for repeatable runs.',
        body: 'When you are managing multiple dates, consistency matters. This infrastructure is designed to scale quietly behind the scenes without adding friction to your existing team.',
      },
    ],
    splitSections: [
      {
        title: 'Organized from the ground up',
        body: 'We turn chaotic audience behavior into a structured asset delivery. You receive neatly arranged files that fit directly into professional post-production workflows.',
        stat: 'Better event follow-up starts with better collection discipline.',
        graphic: 'future-mosaic',
      },
      {
        title: 'Useful when the room is part of the story',
        body: 'If the energy in the crowd matters to the way the show is remembered, it makes sense to build a better path for the footage that captures it. Phone footage stays central, with any planned capture sitting around it rather than replacing it.',
        stat: 'Some of the most memorable event footage is not captured from the cleanest angle.',
        graphic: 'venue-space',
      },
    ],
    board: {
      title: 'What we need to get started',
      intro: 'The intent is to keep the input simple. We only need a few basics from the organiser side.',
      items: [
        'Basic event details and expected use',
        'Permission to share the upload path at the event',
        'Reference or desk audio when it helps the job',
        'A clear sense of what the output is meant to do after the show',
      ],
    },
  },
};

const navItems = [
  { href: '/how-it-works', label: 'How it works', key: 'how-it-works' },
];

function dAccentTone(pageKey) {
  return pageKey === 'pricing'
    ? { color: DC.brass, glow: 'rgba(185,163,126,0.14)', line: 'rgba(185,163,126,0.32)' }
    : { color: DC.cyan, glow: 'rgba(89,163,179,0.14)', line: 'rgba(89,163,179,0.32)' };
}

function DMark({ size = 20 }) {
  return (
    <img
      src="/assets/logo/mark-cream-512.png"
      alt="Showgaze mark"
      style={{ width: size * 1.8, height: size, objectFit: 'contain', objectPosition: 'left center', display: 'block' }}
    />
  );
}

/* ─── Nav ────────────────────────────────────────────────────────────────── */
function DHeader({ currentKey }) {
  const [logoHover, setLogoHover] = React.useState(false);
  
  return (
    <header style={{ position: 'sticky', top: 0, zIndex: 20, background: 'rgba(11,12,14,0.92)', backdropFilter: 'blur(20px)', WebkitBackdropFilter: 'blur(20px)', borderBottom: `1px solid ${DC.border}` }}>
      <div style={{ ...dwrap, minHeight: 60, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 18, paddingTop: 8, paddingBottom: 8, flexWrap: 'wrap' }}>
        <a 
          href="/" 
          style={{ 
            display: 'flex', 
            alignItems: 'center', 
            gap: 10, 
            textDecoration: 'none', 
            color: logoHover ? DC.cyan : DC.bone, 
            flexShrink: 0,
            transition: 'color 200ms ease-out'
          }}
          onMouseEnter={() => setLogoHover(true)}
          onMouseLeave={() => setLogoHover(false)}
        >
          <div style={{
            opacity: logoHover ? 0.8 : 1,
            transition: 'opacity 200ms ease-out'
          }}>
            <DMark size={18} />
          </div>
          <span style={{ fontFamily: DF.display, fontSize: 17 }}>Showgaze</span>
        </a>
        <nav style={{ display: 'flex', alignItems: 'center', gap: 4, flexWrap: 'wrap', justifyContent: 'flex-end' }}>
          {navItems.map((item) => {
            const active = item.key === currentKey;
            return (
              <a key={item.key} href={item.href} style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.16em', textTransform: 'uppercase', textDecoration: 'none', color: active ? DC.bone : DC.grey, padding: '7px 10px', borderRadius: 2, border: `1px solid ${active ? DC.borderHi : 'transparent'}`, background: active ? 'rgba(255,255,255,0.03)' : 'transparent', transition: `color 120ms ${dease}` }}>
                {item.label}
              </a>
            );
          })}
          <a href="/apply/" style={{ marginLeft: 8, fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.18em', textTransform: 'uppercase', textDecoration: 'none', color: DC.bg, background: DC.cyan, border: `1px solid ${DC.cyan}`, borderRadius: 2, padding: '8px 12px', transition: 'background 200ms ease-out' }}
             onMouseEnter={(e) => { e.currentTarget.style.background = DC.cyanHi; }}
             onMouseLeave={(e) => { e.currentTarget.style.background = DC.cyan; }}>
            Apply now
          </a>
        </nav>
      </div>
    </header>
  );
}

function DFactRow({ facts, accent }) {
  return (
    <div style={{ display: 'flex', flexWrap: 'wrap', gap: '8px 16px', alignItems: 'center' }}>
      {facts.map((fact, i) => (
        <React.Fragment key={fact}>
          {i > 0 && <span aria-hidden="true" style={{ width: 14, height: 1, background: accent.line, display: 'inline-block' }} />}
          <span style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.14em', textTransform: 'uppercase', color: DC.mute }}>{fact}</span>
        </React.Fragment>
      ))}
    </div>
  );
}

/* ─── Hero ───────────────────────────────────────────────────────────────── */
function DHero({ pageKey, page }) {
  const accent = dAccentTone(pageKey);
  const isNarrow = useIsNarrow(880);
  return (
    <section style={{ position: 'relative', overflow: 'hidden', borderBottom: `1px solid ${DC.border}` }}>
      <div aria-hidden="true" style={{ position: 'absolute', inset: 0, background: `radial-gradient(ellipse at 8% 18%, ${accent.glow} 0, rgba(0,0,0,0) 36%), radial-gradient(ellipse at 92% 8%, rgba(255,255,255,0.03) 0, rgba(0,0,0,0) 28%)`, pointerEvents: 'none' }} />
      <div style={{ ...dwrap, position: 'relative', padding: '80px 0 68px', display: 'grid', gridTemplateColumns: isNarrow ? '1fr' : 'minmax(0, 1.15fr) minmax(260px, 0.85fr)', gap: '48px 56px', alignItems: 'center' }}>
        <div className="dp-up">
          <div style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.24em', textTransform: 'uppercase', color: accent.color, marginBottom: 20 }}>{page.eyebrow}</div>
          <h1 style={{ margin: '0 0 20px', fontFamily: DF.display, fontSize: 'clamp(32px, 4.8vw, 62px)', lineHeight: 1.05, letterSpacing: '-0.01em', color: DC.bone, fontWeight: 400, maxWidth: 720 }}>{page.title}</h1>
          <p style={{ margin: '0 0 28px', fontFamily: DF.sans, fontSize: 'clamp(15px, 1.3vw, 17px)', lineHeight: 1.84, color: DC.softBone, maxWidth: 660 }}>{page.intro}</p>
          <DFactRow facts={page.facts} accent={accent} />
        </div>
        <div className="dp-up dp-up--2" style={{ borderLeft: isNarrow ? 'none' : `1px solid ${accent.line}`, paddingLeft: isNarrow ? 0 : 36, paddingTop: isNarrow ? 28 : 0, borderTop: isNarrow ? `1px solid ${DC.border}` : 'none' }}>
          <style>{`
            @keyframes dp-hero-float {
              0%, 100% { transform: translateY(0); }
              50% { transform: translateY(-6px); }
            }
          `}</style>
          <div style={{
            position: 'relative',
            width: '100%',
            aspectRatio: '16/9',
            marginBottom: 32,
            borderRadius: 4,
            background: DC.bg1,
            border: `1px solid ${DC.border}`,
            overflow: 'hidden',
            boxShadow: `0 12px 40px rgba(0,0,0,0.6), inset 0 0 0 1px rgba(255,255,255,0.03)`,
            animation: 'dp-hero-float 8s ease-in-out infinite'
          }}>
            <div style={{ position: 'absolute', inset: 0, background: `radial-gradient(circle at 50% 0%, ${accent.glow}, transparent 70%)`, opacity: 0.6, mixBlendMode: 'screen', zIndex: 2, pointerEvents: 'none' }} />
            <img src="/assets/images/hero_infrastructure.png" alt="Showgaze technical infrastructure" style={{ display: 'block', width: '100%', height: '100%', objectFit: 'cover', opacity: 0.85, filter: 'saturate(0.55) contrast(1.05)' }} />
          </div>
          <div style={{ fontFamily: DF.mono, fontSize: 8, letterSpacing: '0.22em', textTransform: 'uppercase', color: accent.color, marginBottom: 18 }}>{page.heroPanel.kicker}</div>
          <blockquote style={{ margin: '0 0 22px', padding: 0, fontFamily: DF.display, fontSize: 'clamp(20px, 2vw, 28px)', lineHeight: 1.22, fontStyle: 'italic', fontWeight: 400, color: DC.bone }}>{page.heroPanel.title}</blockquote>
          <div style={{ width: 36, height: 1, background: accent.line, marginBottom: 22 }} />
          <p style={{ margin: 0, fontFamily: DF.sans, fontSize: 14, lineHeight: 1.82, color: DC.grey }}>{page.heroPanel.body}</p>
        </div>
      </div>
    </section>
  );
}

/* ─── Editorial block ────────────────────────────────────────────────────── */
function DEditorialBlock({ pageKey, page }) {
  const accent = dAccentTone(pageKey);
  const isNarrow = useIsNarrow(760);
  const [primary, ...supporting] = page.cards;
  return (
    <section style={{ borderBottom: `1px solid ${DC.border}` }}>
      <div style={{ ...dwrap, padding: '40px 0' }}>
        <div style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase', color: accent.color, marginBottom: 28 }}>The case</div>
        {primary.image ? (
          <div style={{ display: 'grid', gridTemplateColumns: isNarrow ? '1fr' : '1.2fr 0.8fr', gap: '32px 48px', alignItems: 'center', marginBottom: 40 }}>
            <div>
              <h2 style={{ margin: '0 0 16px', fontFamily: DF.display, fontSize: 'clamp(26px, 3.4vw, 46px)', lineHeight: 1.08, fontWeight: 400, color: DC.bone }}>{primary.title}</h2>
              <p style={{ margin: 0, fontFamily: DF.sans, fontSize: 'clamp(15px, 1.3vw, 17px)', lineHeight: 1.84, color: DC.grey }}>{primary.body}</p>
            </div>
            <div style={{ 
              background: 'rgba(25, 26, 29, 0.55)', 
              border: '1px solid rgba(230, 220, 203, 0.08)', 
              borderRadius: 4, 
              padding: 16, 
              display: 'flex', 
              alignItems: 'center', 
              justifyContent: 'center',
              overflow: 'hidden'
            }}>
              <img 
                src={primary.image} 
                alt={primary.imageAlt || ''} 
                style={{ 
                  display: 'block', 
                  width: '100%', 
                  aspectRatio: '21 / 9', 
                  maxHeight: 280, 
                  objectFit: 'cover', 
                  opacity: 0.85,
                  borderRadius: 2
                }} 
              />
            </div>
          </div>
        ) : (
          <>
            <h2 style={{ margin: '0 0 16px', fontFamily: DF.display, fontSize: 'clamp(26px, 3.4vw, 46px)', lineHeight: 1.08, fontWeight: 400, color: DC.bone, maxWidth: 860 }}>{primary.title}</h2>
            <p style={{ margin: 0, fontFamily: DF.sans, fontSize: 'clamp(15px, 1.3vw, 17px)', lineHeight: 1.84, color: DC.grey, maxWidth: 680 }}>{primary.body}</p>
          </>
        )}
        <div style={{ height: 1, background: DC.border, margin: primary.image ? '0 0 40px' : '40px 0' }} />
        <div style={{ display: 'grid', gridTemplateColumns: isNarrow ? '1fr' : '1fr 1fr', gap: isNarrow ? 32 : '0 56px' }}>
          {supporting.map((card, i) => (
            <div key={card.title} style={{ paddingLeft: 20, borderLeft: `1px solid ${i === 0 ? accent.line : DC.borderHi}` }}>
              <h3 style={{ margin: '0 0 10px', fontFamily: DF.display, fontSize: 'clamp(20px, 1.8vw, 24px)', lineHeight: 1.18, fontWeight: 400, color: DC.bone }}>{card.title}</h3>
              <p style={{ margin: 0, fontFamily: DF.sans, fontSize: 14, lineHeight: 1.82, color: DC.grey }}>{card.body}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ─── Flow layout (how-it-works) ─────────────────────────────────────────── */
function DFlow({ pageKey, page }) {
  const accent = dAccentTone(pageKey);
  const isNarrow = useIsNarrow(900);
  return (
    <section style={{ borderBottom: `1px solid ${DC.border}` }}>
      <div style={{ ...dwrap, padding: '80px 0' }}>
        <div style={{ display: 'grid', gridTemplateColumns: isNarrow ? '1fr' : '1fr 1.2fr', gap: isNarrow ? '64px' : '96px', alignItems: 'center' }}>
          
          <div>
            <div style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase', color: accent.color, marginBottom: 40 }}>The process</div>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 48 }}>
              {page.flow.map((s, i) => (
                <div key={s.step} style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
                  <div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
                    <div style={{ width: 24, height: 24, borderRadius: '50%', border: `1px solid ${accent.color}`, display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: DF.mono, fontSize: 10, color: accent.color }}>
                      {i + 1}
                    </div>
                    <div style={{ fontFamily: DF.display, fontSize: 'clamp(24px, 2.4vw, 32px)', fontWeight: 400, color: DC.bone, lineHeight: 1 }}>{s.step}</div>
                  </div>
                  <div style={{ fontFamily: DF.sans, fontSize: 14, lineHeight: 1.64, color: DC.grey, paddingLeft: 40 }}>{s.note}</div>
                </div>
              ))}
            </div>
          </div>

          <div style={{ 
            position: 'relative', 
            width: '100%', 
            aspectRatio: '1/1', 
            borderRadius: 8, 
            background: DC.bg1, 
            border: `1px solid ${DC.border}`, 
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center',
            padding: 32,
            boxShadow: `0 24px 64px rgba(0,0,0,0.6), inset 0 0 0 1px rgba(255,255,255,0.02)` 
          }}>
            <img src="/assets/images/pipeline_signage.png" alt="Technical process pipeline blueprint" style={{ display: 'block', width: '100%', height: '100%', objectFit: 'contain', opacity: 0.9, filter: 'saturate(0.55) contrast(1.1)' }} />
          </div>

        </div>
        <div style={{ marginTop: 80, display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 240px), 1fr))', gap: '28px 48px' }}>
          {page.cards.map((card, i) => (
            <div key={card.title} style={{ paddingLeft: 18, borderLeft: `1px solid ${i === 0 ? accent.line : DC.borderHi}` }}>
              <p style={{ margin: '0 0 6px', fontFamily: DF.sans, fontSize: 14, fontWeight: 500, color: DC.softBone, lineHeight: 1.4 }}>{card.title}</p>
              <p style={{ margin: 0, fontFamily: DF.sans, fontSize: 13, lineHeight: 1.78, color: DC.grey }}>{card.body}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ─── Pricing document rows ──────────────────────────────────────────────── */
function DPricingMatrix({ page }) {
  return (
    <section style={{ borderBottom: `1px solid ${DC.border}` }}>
      <div style={{ ...dwrap, padding: '40px 0' }}>
        <div style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase', color: DC.brass, marginBottom: 40 }}>Package direction</div>
        <div>
          {page.pricing.map((plan) => {
            const tone = plan.accent === 'brass' ? DC.brass : plan.accent === 'cyan' ? DC.cyan : DC.bone;
            return (
              <div key={plan.tier} style={{ paddingTop: 32, paddingBottom: 36, borderTop: `1px solid ${DC.border}` }}>
                <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 12 }}>
                  <h2 style={{ margin: 0, fontFamily: DF.display, fontSize: 'clamp(22px, 2.6vw, 34px)', fontWeight: 400, color: DC.bone, lineHeight: 1.1 }}>{plan.tier}</h2>
                  <div style={{ width: 6, height: 6, borderRadius: '50%', background: tone, flexShrink: 0, marginBottom: 4 }} />
                </div>
                <p style={{ margin: '0 0 18px', fontFamily: DF.sans, fontSize: 15, lineHeight: 1.82, color: DC.grey, maxWidth: 680 }}>{plan.body}</p>
                <div style={{ display: 'flex', flexWrap: 'wrap', gap: '4px 0', alignItems: 'center' }}>
                  {plan.bullets.map((bullet, i) => (
                    <React.Fragment key={bullet}>
                      {i > 0 && <span style={{ fontFamily: DF.mono, fontSize: 9, color: DC.mute, margin: '0 10px' }}>·</span>}
                      <span style={{ fontFamily: DF.sans, fontSize: 13, color: DC.softBone }}>{bullet}</span>
                    </React.Fragment>
                  ))}
                </div>
              </div>
            );
          })}
          <div style={{ height: 1, background: DC.border }} />
        </div>
      </div>
    </section>
  );
}

/* ─── Interactive Showcase (Replaces stacked DSplitSections) ─────────────── */
function DInteractiveShowcase({ pageKey, sections }) {
  const [activeIndex, setActiveIndex] = React.useState(0);
  const accent = dAccentTone(pageKey);
  const isNarrow = useIsNarrow(900);
  
  if (!sections || sections.length === 0) return null;
  
  const activeSection = sections[activeIndex];

  return (
    <section style={{ borderBottom: `1px solid ${DC.border}` }}>
      <div style={{ ...dwrap, padding: '40px 0' }}>
        <div style={{ display: 'grid', gridTemplateColumns: isNarrow ? '1fr' : '320px 1fr', gap: isNarrow ? 40 : 80 }}>
          
          {/* Navigation / Tabs */}
          <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }} role="tablist">
            <div style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase', color: accent.color, marginBottom: 16 }}>Key Features</div>
            {sections.map((sec, idx) => {
              const isActive = idx === activeIndex;
              return (
                <button
                  key={sec.title}
                  role="tab"
                  aria-selected={isActive}
                  onClick={() => setActiveIndex(idx)}
                  style={{
                    all: 'unset',
                    boxSizing: 'border-box',
                    cursor: 'pointer',
                    padding: '16px 20px',
                    borderRadius: 4,
                    borderLeft: `2px solid ${isActive ? accent.color : 'transparent'}`,
                    background: isActive ? DC.bg1 : 'transparent',
                    transition: 'all 200ms ease-out',
                    display: 'flex',
                    flexDirection: 'column',
                    gap: 6,
                    outline: 'none'
                  }}
                  onFocus={(e) => Object.assign(e.target.style, { boxShadow: `0 0 0 2px ${accent.line}` })}
                  onBlur={(e) => Object.assign(e.target.style, { boxShadow: 'none' })}
                  onMouseEnter={(e) => {
                    if (!isActive) e.currentTarget.style.background = 'rgba(230, 220, 203, 0.03)';
                  }}
                  onMouseLeave={(e) => {
                    if (!isActive) e.currentTarget.style.background = 'transparent';
                  }}
                >
                  <span style={{ fontFamily: DF.display, fontSize: 20, color: isActive ? DC.bone : DC.softBone, transition: 'color 200ms ease-out' }}>
                    {sec.title}
                  </span>
                  {isActive && (
                    <span style={{ fontFamily: DF.sans, fontSize: 13, color: DC.grey, lineHeight: 1.5, animation: 'dp-fade-in 300ms ease-out' }}>
                      {sec.body.slice(0, 60)}...
                    </span>
                  )}
                </button>
              );
            })}
          </div>

          {/* Active Content Area */}
          <div 
            role="tabpanel" 
            style={{ 
              display: 'flex', 
              flexDirection: 'column',
              animation: 'dp-fade-in 300ms ease-out',
              minHeight: isNarrow ? 'auto' : 500
            }}
            key={activeIndex}
          >
            <div style={{ display: 'flex', flexDirection: 'column', gap: 32, flexGrow: 1 }}>
              <div>
                <h2 style={{ margin: '0 0 16px', fontFamily: DF.display, fontSize: 'clamp(28px, 3.2vw, 44px)', lineHeight: 1.08, fontWeight: 400, color: DC.bone }}>
                  {activeSection.title}
                </h2>
                <p style={{ margin: 0, fontFamily: DF.sans, fontSize: 'clamp(15px, 1.4vw, 17px)', lineHeight: 1.84, color: DC.grey, maxWidth: 640 }}>
                  {activeSection.body}
                </p>
                {activeSection.stat && (
                  <div style={{ marginTop: 24, paddingLeft: 18, borderLeft: `2px solid ${accent.color}`, fontFamily: DF.display, fontStyle: 'italic', fontSize: 'clamp(15px, 1.4vw, 18px)', lineHeight: 1.52, color: DC.softBone }}>
                    {activeSection.stat}
                  </div>
                )}
              </div>
              
              <div style={{ marginTop: 'auto' }}>
                {activeSection.graphic
                  ? <DSplitGraphic type={activeSection.graphic} accent={accent} />
                  : (
                    <div style={{ overflow: 'hidden', borderRadius: 4, background: DC.bg1, border: `1px solid ${DC.border}`, width: '100%', maxHeight: isNarrow ? 300 : 400 }}>
                      <img
                        src={activeSection.image}
                        alt={activeSection.imageAlt}
                        style={{ display: 'block', width: '100%', height: '100%', objectFit: 'cover' }}
                      />
                    </div>
                  )
                }
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ─── CSS visual panels — animated, no product screenshots ──────────────── */

/* Scattered text fragments — each fragment floats on its own slow cycle */
function GPromoScatter({ accent }) {
  const frags = [
    { t: '37 clips',        x: '10%', y: '14%', size: 36, op: 0.88, font: DF.display, upper: false, cls: 'dp-float-b', delay: '0s'   },
    { t: 'UNTAGGED',        x: '58%', y: '10%', size: 8,  op: 0.38, font: DF.mono,    upper: true,  cls: 'dp-float-a', delay: '1.2s' },
    { t: '4 days late',     x: '54%', y: '28%', size: 13, op: 0.42, font: DF.sans,    upper: false, cls: 'dp-float-c', delay: '0.6s' },
    { t: 'still arriving',  x: '6%',  y: '52%', size: 10, op: 0.30, font: DF.mono,    upper: true,  cls: 'dp-float-a', delay: '3.1s' },
    { t: 'from 3 channels', x: '38%', y: '65%', size: 12, op: 0.40, font: DF.sans,    upper: false, cls: 'dp-float-b', delay: '2.0s' },
    { t: 'which cut?',      x: '12%', y: '80%', size: 11, op: 0.28, font: DF.sans,    upper: false, cls: 'dp-float-c', delay: '4.3s' },
    { t: 'TAGGED WRONG',    x: '62%', y: '74%', size: 8,  op: 0.25, font: DF.mono,    upper: true,  cls: 'dp-float-b', delay: '1.7s' },
    { t: 'not synced yet',  x: '30%', y: '44%', size: 10, op: 0.22, font: DF.sans,    upper: false, cls: 'dp-float-a', delay: '5.0s' },
  ];
  return (
    <div style={{ position: 'relative', width: '100%', paddingBottom: '75%', background: DC.bg1, overflow: 'hidden', borderRadius: 4 }}>
      <div aria-hidden="true" style={{ position: 'absolute', inset: 0, background: `radial-gradient(ellipse at 20% 30%, ${accent.glow} 0, transparent 55%)`, pointerEvents: 'none' }} />
      {frags.map((f, i) => (
        <div key={i} aria-hidden="true" className={f.cls} style={{ position: 'absolute', left: f.x, top: f.y, fontFamily: f.font, fontSize: f.size, color: DC.bone, opacity: f.op, textTransform: f.upper ? 'uppercase' : 'none', letterSpacing: f.upper ? '0.14em' : 0, lineHeight: 1, whiteSpace: 'nowrap', pointerEvents: 'none', animationDelay: f.delay }}>
          {f.t}
        </div>
      ))}
      <div aria-hidden="true" style={{ position: 'absolute', top: '38%', left: '8%', right: '8%', height: 1, background: `linear-gradient(90deg, transparent, ${DC.border} 15%, ${DC.border} 85%, transparent)` }} />
      <div aria-hidden="true" style={{ position: 'absolute', bottom: 20, right: 20, fontFamily: DF.mono, fontSize: 8, color: DC.mute, letterSpacing: '0.16em', textTransform: 'uppercase' }}>Before</div>
    </div>
  );
}

/* Cinematic room representation */
function GVenueImage({ accent }) {
  return (
    <div style={{ position: 'relative', width: '100%', paddingBottom: '75%', background: DC.bg1, overflow: 'hidden', borderRadius: 4, border: `1px solid ${DC.border}` }}>
      <style>{`
        @keyframes dp-ken-burns {
          0% { transform: scale(1); }
          100% { transform: scale(1.05); }
        }
      `}</style>
      <div style={{ position: 'absolute', inset: 0, background: `radial-gradient(circle at 50% 50%, ${accent.glow}, transparent 80%)`, opacity: 0.4, mixBlendMode: 'screen', zIndex: 2, pointerEvents: 'none' }} />
      <img src="/assets/images/feature_room_v2.png" alt="Industrial venue environment" style={{ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', objectFit: 'cover', opacity: 0.85, filter: 'saturate(0.55) contrast(1.05)', animation: 'dp-ken-burns 20s ease-in-out infinite alternate' }} />
      <div aria-hidden="true" style={{ position: 'absolute', bottom: 20, right: 20, zIndex: 3, fontFamily: DF.mono, fontSize: 8, color: DC.bone, letterSpacing: '0.16em', textTransform: 'uppercase', background: 'rgba(11,12,14,0.6)', padding: '4px 8px', borderRadius: 2 }}>Physical Infrastructure</div>
    </div>
  );
}

/* Typographic path — staggered entry, pulsing arrows */
function GArtistPath({ accent }) {
  const steps = ['Fan footage', 'Collected', 'Something useful'];
  return (
    <div style={{ position: 'relative', width: '100%', paddingBottom: '75%', background: DC.bg1, overflow: 'hidden', borderRadius: 4 }}>
      <div style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', justifyContent: 'center', padding: '28px 32px' }}>
        <div style={{ fontFamily: DF.mono, fontSize: 8, letterSpacing: '0.2em', textTransform: 'uppercase', color: DC.mute, marginBottom: 24, animation: 'dp-fade-in 400ms both' }}>
          The path
        </div>
        {steps.map((step, i) => (
          <React.Fragment key={step}>
            <div style={{ fontFamily: DF.display, fontSize: 'clamp(18px, 2.4vw, 26px)', color: i === 2 ? DC.softBone : DC.bone, lineHeight: 1.1, fontStyle: i === 2 ? 'italic' : 'normal', animation: `dp-up 500ms ${i * 130 + 80}ms both` }}>
              {step}
            </div>
            {i < steps.length - 1 && (
              <div aria-hidden="true" className="dp-arrow-pulse" style={{ fontFamily: DF.mono, fontSize: 14, color: accent.color, margin: '12px 0', lineHeight: 1, animationDelay: `${i * 500}ms` }}>↓</div>
            )}
          </React.Fragment>
        ))}
        <div style={{ width: 32, height: 1, background: accent.line, marginTop: 24, animation: 'dp-fade-in 500ms 500ms both' }} />
      </div>
    </div>
  );
}

/* QR gesture — scan line sweeps across on repeat */
function GHowCollect({ accent }) {
  const filled = new Set([0,1,2,3,4,5,6,7,13,14,20,21,27,28,29,30,31,32,33,34,8,15,22,42,43,44,46,47,48,36,37,43,44,45,46,38,39,40,41,47,35,41,48]);
  return (
    <div style={{ position: 'relative', width: '100%', paddingBottom: '75%', background: DC.bg1, overflow: 'hidden', borderRadius: 4 }}>
      <div style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 18 }}>
        <div style={{ fontFamily: DF.mono, fontSize: 8, letterSpacing: '0.2em', textTransform: 'uppercase', color: DC.mute, animation: 'dp-fade-in 400ms both' }}>
          Contribute your clip
        </div>
        <div style={{ position: 'relative', background: DC.bone, padding: 10, borderRadius: 4, display: 'grid', gridTemplateColumns: 'repeat(7, 10px)', gap: 2, animation: 'dp-up 500ms 100ms both', overflow: 'hidden' }}>
          {Array.from({ length: 49 }).map((_, i) => (
            <div key={i} style={{ width: 10, height: 10, borderRadius: 1, background: filled.has(i) ? DC.bg : 'transparent' }} />
          ))}
          <div aria-hidden="true" style={{ position: 'absolute', left: 4, right: 4, height: 2, borderRadius: 1, background: `linear-gradient(90deg, transparent, ${accent.color}, transparent)`, opacity: 0.9, animation: 'dp-scan 2.4s ease-in-out infinite' }} />
        </div>
        <div style={{ fontFamily: DF.sans, fontSize: 12, color: DC.grey, animation: 'dp-fade-in 400ms 300ms both' }}>Scan to send footage</div>
        <div style={{ fontFamily: DF.mono, fontSize: 8, letterSpacing: '0.14em', textTransform: 'uppercase', color: accent.color, background: `${accent.color}18`, border: `1px solid ${accent.line}`, borderRadius: 2, padding: '6px 12px', animation: 'dp-up 400ms 400ms both' }}>
          Upload clips
        </div>
      </div>
    </div>
  );
}

/* Pricing — staggered text reveal */
function GPricingCore({ accent }) {
  return (
    <div style={{ position: 'relative', width: '100%', paddingBottom: '75%', background: DC.bg1, overflow: 'hidden', borderRadius: 4 }}>
      <div style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', justifyContent: 'center', padding: '28px 32px' }}>
        <div style={{ fontFamily: DF.mono, fontSize: 8, letterSpacing: '0.2em', textTransform: 'uppercase', color: accent.color, marginBottom: 20, animation: 'dp-fade-in 400ms both' }}>Simple Recap</div>
        {[['Collect.', false, '80ms'], ['Review.', false, '200ms'], ['Deliver.', true, '320ms']].map(([text, italic, delay]) => (
          <div key={text} style={{ fontFamily: DF.display, fontSize: 'clamp(28px, 3.8vw, 48px)', lineHeight: 1, color: italic ? DC.softBone : DC.bone, fontStyle: italic ? 'italic' : 'normal', animation: `dp-up 500ms ${delay} both` }}>
            {text}
          </div>
        ))}
        <div style={{ width: 36, height: 1, background: accent.line, margin: '20px 0 18px', animation: 'dp-fade-in 400ms 450ms both' }} />
        <div style={{ fontFamily: DF.sans, fontSize: 13, lineHeight: 1.7, color: DC.grey, maxWidth: 260, animation: 'dp-fade-in 400ms 520ms both' }}>
          The lightest path. Most shows only need this.
        </div>
      </div>
    </div>
  );
}

/* Mosaic — grid of glowing tiles that assemble */
function GFutureMosaic({ accent }) {
  const grid = Array.from({ length: 48 });
  return (
    <div style={{ position: 'relative', width: '100%', paddingBottom: '75%', background: DC.bg1, overflow: 'hidden', borderRadius: 4 }}>
      <div style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(6, 1fr)', gap: 2, width: '30%', aspectRatio: '2/3', padding: 2 }}>
          {grid.map((_, i) => {
            const delay = (i % 6 + Math.floor(i / 6)) * 0.1 + Math.random() * 0.5;
            const isAccent = Math.random() > 0.8;
            return (
              <div key={i} style={{ background: isAccent ? accent.color : DC.bone, borderRadius: 1, animation: `dp-fade-in 600ms ${delay}s both` }} />
            );
          })}
        </div>
        <div aria-hidden="true" style={{ position: 'absolute', bottom: 20, right: 20, fontFamily: DF.mono, fontSize: 8, color: DC.mute, letterSpacing: '0.16em', textTransform: 'uppercase' }}>Mosaic Concept</div>
      </div>
    </div>
  );
}

function DSplitGraphic({ type, accent }) {
  switch (type) {
    case 'promo-scatter':  return <GPromoScatter accent={accent} />;
    case 'venue-space':    return <GVenueImage   accent={accent} />;
    case 'artist-path':    return <GArtistPath   accent={accent} />;
    case 'how-collect':    return <GHowCollect   accent={accent} />;
    case 'pricing-core':   return <GPricingCore  accent={accent} />;
    case 'future-mosaic':  return <GFutureMosaic accent={accent} />;
    default: return null;
  }
}

/* ─── Split section ───────────────────────────────────────────────────────── */
function DSplitSection({ pageKey, section, reverse }) {
  const accent = dAccentTone(pageKey);
  const isNarrow = useIsNarrow(880);
  const hasVisual = section.graphic || section.image;

  /* Wide (no visual) — full editorial text column */
  if (!hasVisual || section.wide) {
    return (
      <section style={{ borderBottom: `1px solid ${DC.border}` }}>
        <div style={{ ...dwrap, padding: '72px 0 80px', maxWidth: 'min(820px, calc(100% - 48px))', margin: '0 auto' }}>
          <h2 style={{ margin: '0 0 18px', fontFamily: DF.display, fontSize: 'clamp(26px, 3vw, 40px)', lineHeight: 1.08, fontWeight: 400, color: DC.bone }}>{section.title}</h2>
          <p style={{ margin: '0 0 32px', fontFamily: DF.sans, fontSize: 'clamp(15px, 1.3vw, 17px)', lineHeight: 1.84, color: DC.grey }}>{section.body}</p>
          <div style={{ height: 1, background: DC.border, marginBottom: 32 }} />
          <p style={{ margin: 0, fontFamily: DF.display, fontStyle: 'italic', fontSize: 'clamp(18px, 2vw, 26px)', lineHeight: 1.38, color: DC.softBone }}>{section.stat}</p>
        </div>
      </section>
    );
  }

  /* Two-column with visual */
  return (
    <section style={{ borderBottom: `1px solid ${DC.border}` }}>
      <div style={{ ...dwrap, padding: '72px 0 80px', display: 'grid', gridTemplateColumns: isNarrow ? '1fr' : '1fr 1fr', gap: '36px 60px', alignItems: 'center' }}>
        <div style={{ order: reverse ? 2 : 1 }}>
          <h2 style={{ margin: '0 0 18px', fontFamily: DF.display, fontSize: 'clamp(24px, 2.6vw, 36px)', lineHeight: 1.1, fontWeight: 400, color: DC.bone, maxWidth: 540 }}>{section.title}</h2>
          <p style={{ margin: '0 0 28px', fontFamily: DF.sans, fontSize: 15, lineHeight: 1.84, color: DC.grey, maxWidth: 540 }}>{section.body}</p>
          <div style={{ paddingLeft: 18, borderLeft: `2px solid ${accent.color}`, fontFamily: DF.display, fontStyle: 'italic', fontSize: 'clamp(15px, 1.4vw, 18px)', lineHeight: 1.52, color: DC.softBone, maxWidth: 480 }}>
            {section.stat}
          </div>
        </div>
        <div style={{ order: reverse ? 1 : 2 }}>
          {section.graphic
            ? <DSplitGraphic type={section.graphic} accent={accent} />
            : (
              <div style={{ overflow: 'hidden', borderRadius: 4, background: DC.bg1, border: `1px solid ${DC.border}` }}>
                <img
                  src={section.image}
                  alt={section.imageAlt}
                  style={{ display: 'block', width: '100%', aspectRatio: '3 / 2', objectFit: 'cover' }}
                />
              </div>
            )
          }
        </div>
      </div>
    </section>
  );
}

/* ─── Board — document rows ──────────────────────────────────────────────── */
function DBoard({ pageKey, board }) {
  const accent = dAccentTone(pageKey);
  const isNarrow = useIsNarrow(800);
  return (
    <section style={{ borderBottom: `1px solid ${DC.border}` }}>
      <div style={{ ...dwrap, padding: '80px 0' }}>
        <div style={{ display: 'grid', gridTemplateColumns: isNarrow ? '1fr' : '0.9fr 1.1fr', gap: isNarrow ? '64px' : '96px', alignItems: 'center' }}>
          <div>
            <div style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase', color: accent.color, marginBottom: 14 }}>Checklist</div>
            <h2 style={{ margin: '0 0 16px', fontFamily: DF.display, fontSize: 'clamp(28px, 3.2vw, 42px)', lineHeight: 1.1, fontWeight: 400, color: DC.bone }}>{board.title}</h2>
            <p style={{ margin: '0 0 40px', fontFamily: DF.sans, fontSize: 15, lineHeight: 1.82, color: DC.grey }}>{board.intro}</p>
            <div>
              {board.items.map((item, i) => (
                <div key={item} style={{ display: 'grid', gridTemplateColumns: '28px minmax(0, 1fr)', gap: '0 16px', alignItems: 'baseline', padding: '16px 0', borderTop: `1px solid ${DC.border}` }}>
                  <div style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.1em', color: DC.mute }}>{String(i + 1).padStart(2, '0')}</div>
                  <div style={{ fontFamily: DF.sans, fontSize: 15, lineHeight: 1.74, color: DC.bone }}>{item}</div>
                </div>
              ))}
              <div style={{ height: 1, background: DC.border }} />
            </div>
          </div>
          <div style={{ 
            position: 'relative', 
            width: '100%', 
            aspectRatio: '3/4', 
            borderRadius: 8, 
            background: DC.bg1, 
            border: `1px solid ${DC.border}`, 
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center',
            padding: 32,
            boxShadow: `0 24px 64px rgba(0,0,0,0.6), inset 0 0 0 1px rgba(255,255,255,0.02)` 
          }}>
            <img src="/assets/images/manifest_signage.png" alt="Requirements manifest document" style={{ display: 'block', width: '100%', height: '100%', objectFit: 'contain', opacity: 0.9, filter: 'saturate(0.55) contrast(1.1)' }} />
          </div>
        </div>
      </div>
    </section>
  );
}

/* ─── Automated Scrubbing Dial ───────────────────────────────────────────── */
function AutomatedScrubbingDial() {
  const isNarrow = useIsNarrow(600);
  return (
    <div style={{ position: 'relative', width: '100%', maxWidth: 560, marginBottom: 48 }}>
      <style>{`
        @keyframes scrub-dial {
          0% { transform: translateX(0%); opacity: 0; }
          5% { transform: translateX(0%); opacity: 1; }
          15% { transform: translateX(0%); opacity: 1; }
          30% { transform: translateX(100%); opacity: 1; }
          65% { transform: translateX(100%); opacity: 1; }
          80% { transform: translateX(200%); opacity: 1; }
          90% { transform: translateX(200%); opacity: 1; }
          95%, 100% { transform: translateX(200%); opacity: 0; }
        }
        @keyframes pulse-zone-0 {
          0% { opacity: 0.3; color: #8A8A86; }
          5%, 15% { opacity: 1; color: #E6DCCB; }
          30%, 100% { opacity: 0.3; color: #8A8A86; }
        }
        @keyframes pulse-zone-1 {
          0%, 15% { opacity: 0.3; color: #8A8A86; }
          30%, 65% { opacity: 1; color: #E6DCCB; }
          80%, 100% { opacity: 0.3; color: #8A8A86; }
        }
        @keyframes pulse-zone-2 {
          0%, 65% { opacity: 0.3; color: #8A8A86; }
          80%, 90% { opacity: 1; color: #E6DCCB; }
          95%, 100% { opacity: 0.3; color: #8A8A86; }
        }
      `}</style>
      
      {/* The Track */}
      <div style={{ 
        display: 'flex', 
        border: `1px solid ${DC.borderHi}`, 
        borderRadius: 4, 
        overflow: 'hidden',
        background: DC.bg1,
        position: 'relative'
      }}>
        {/* The Playhead */}
        <div style={{
          position: 'absolute',
          top: 0,
          left: 0,
          width: '33.333%',
          height: '100%',
          background: 'transparent',
          border: `1px solid ${DC.cyan}`,
          boxShadow: `inset 0 0 10px ${DC.cyan}20, 0 0 10px ${DC.cyan}20`,
          animation: 'scrub-dial 6s infinite cubic-bezier(0.65, 0, 0.35, 1)',
          zIndex: 2,
          pointerEvents: 'none',
          borderRadius: 2
        }} />

        {['ARCHIVE', 'SYNC', 'FINAL CUT'].map((label, i) => (
          <div key={label} style={{ 
            flex: 1, 
            padding: '16px 12px', 
            textAlign: 'center',
            position: 'relative',
            borderRight: i < 2 ? `1px solid ${DC.borderHi}` : 'none',
            fontFamily: DF.mono,
            fontSize: isNarrow ? 9 : 10,
            letterSpacing: '0.18em',
            animation: `pulse-zone-${i} 6s infinite`
          }}>
            {label}
            {/* Visual indicators */}
            <div style={{ marginTop: 12, display: 'flex', gap: 4, justifyContent: 'center', opacity: 0.5 }}>
              {i === 0 && (
                <>
                  <div style={{ width: 16, height: 4, background: DC.grey, borderRadius: 2, opacity: 0.5 }} />
                  <div style={{ width: 8, height: 4, background: DC.grey, borderRadius: 2, opacity: 0.3 }} />
                  <div style={{ width: 20, height: 4, background: DC.grey, borderRadius: 2, opacity: 0.8 }} />
                </>
              )}
              {i === 1 && (
                <>
                  <div style={{ width: 44, height: 4, background: DC.softBone, borderRadius: 2 }} />
                </>
              )}
              {i === 2 && (
                <>
                  <div style={{ width: 44, height: 4, background: DC.cyan, borderRadius: 2, boxShadow: `0 0 8px ${DC.cyan}40` }} />
                </>
              )}
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

/* ─── Closing CTA ────────────────────────────────────────────────────────── */
function DClosingCta() {
  const isNarrow = useIsNarrow(800);
  return (
    <section>
      <div style={{ ...dwrap, padding: '60px 0' }}>
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
          <AutomatedScrubbingDial />
          
          <div style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase', color: DC.cyan, marginBottom: 18 }}>Next step</div>
          <h2 style={{ margin: '0 0 14px', fontFamily: DF.display, fontSize: 'clamp(24px, 2.8vw, 38px)', lineHeight: 1.1, fontWeight: 400, color: DC.bone, maxWidth: 560 }}>
            If the footage is already there, the next question is what it should become.
          </h2>
          <p style={{ margin: '0 0 32px', fontFamily: DF.sans, fontSize: 18, lineHeight: 1.8, color: DC.softBone, maxWidth: 520 }}>
            Tell us about the event and what you want to get out of the footage.
          </p>
          
          <div style={{ display: 'flex', gap: 24, flexWrap: 'wrap', alignItems: 'center' }}>
            <a href="/apply/" style={{ textDecoration: 'none', fontFamily: DF.mono, fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', background: DC.bone, color: DC.bg, borderRadius: 2, padding: '14px 24px', fontWeight: 600 }}>Apply now</a>
            <a href="mailto:hello@showgaze.app" style={{ textDecoration: 'none', fontFamily: DF.mono, fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', background: 'transparent', color: DC.cyan, border: 'none', padding: '14px 0' }}>hello@showgaze.app</a>
          </div>
        </div>
      </div>
    </section>
  );
}

function DFooter() {
  return (
    <footer style={{ borderTop: `1px solid ${DC.border}` }}>
      <div style={{ ...dwrap, padding: '22px 0 28px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 9 }}>
          <DMark size={14} />
          <span style={{ fontFamily: DF.display, fontSize: 14, color: DC.bone }}>Showgaze</span>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 20, flexWrap: 'wrap' }}>
          {[['Bio', '/about/'], ['Privacy', '/privacy.html'], ['Terms', '/terms.html']].map(([label, href]) => (
            <a key={label} href={href} style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.16em', textTransform: 'uppercase', color: DC.mute, textDecoration: 'none' }}>{label}</a>
          ))}
          <span style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.16em', textTransform: 'uppercase', color: DC.mute }}>© 2026 Showgaze</span>
        </div>
      </div>
    </footer>
  );
}

/* ─── Page shell (Zero-Scroll App Interface) ─────────────────────────────── */
function DiscoveryPage({ pageKey }) {
  const page = pageData[pageKey];
  if (!page) {
    return (
      <div style={{ height: '100vh', background: DC.bg, color: DC.bone, display: 'flex', flexDirection: 'column' }}>
        <DHeader currentKey="" />
        <main style={{ ...dwrap, flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <h1 style={{ fontFamily: DF.display, fontSize: 42, fontWeight: 400 }}>Page not found.</h1>
        </main>
      </div>
    );
  }

  const isFlow = pageKey === 'how-it-works';
  const accent = dAccentTone(pageKey);
  const isNarrow = useIsNarrow(900);

  const chapters = [
    { id: 'intro', label: 'Overview', render: () => <DHero pageKey={pageKey} page={page} /> },
    ...(page.pricing 
      ? [{ id: 'pricing', label: 'Pricing', render: () => <DPricingMatrix page={page} /> }]
      : isFlow 
        ? [{ id: 'flow', label: 'The Process', render: () => <DFlow pageKey={pageKey} page={page} /> }]
        : [{ id: 'case', label: 'The Case', render: () => <DEditorialBlock pageKey={pageKey} page={page} /> }]
    ),
    ...(page.splitSections && page.splitSections.length > 0 
      ? [{ id: 'features', label: 'Features', render: () => <DInteractiveShowcase pageKey={pageKey} sections={page.splitSections} /> }]
      : []
    ),
    { id: 'board', label: 'Requirements', render: () => <DBoard pageKey={pageKey} board={page.board} /> },
    { id: 'cta', label: 'Next Steps', render: () => <DClosingCta /> },
  ];

  const [activeIdx, setActiveIdx] = React.useState(0);
  const ActiveComponent = chapters[activeIdx].render;

  return (
    <div style={{ background: DC.bg, color: DC.bone, height: '100vh', overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>
      <DHeader currentKey={pageKey} />
      
      <main style={{ flex: 1, display: 'flex', flexDirection: isNarrow ? 'column' : 'row', overflow: 'hidden' }}>
        {/* App Sidebar Navigation */}
        <div style={{ 
          width: isNarrow ? '100%' : '240px', 
          borderRight: isNarrow ? 'none' : `1px solid ${DC.border}`,
          borderBottom: isNarrow ? `1px solid ${DC.border}` : 'none',
          padding: isNarrow ? '12px 20px' : '40px 24px',
          display: 'flex',
          flexDirection: isNarrow ? 'row' : 'column',
          gap: 8,
          overflowX: isNarrow ? 'auto' : 'visible',
          overflowY: 'auto',
          flexShrink: 0,
          background: DC.bg1
        }}>
          <div style={{ fontFamily: DF.mono, fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase', color: accent.color, marginBottom: isNarrow ? 0 : 24, display: isNarrow ? 'none' : 'block' }}>
            Navigation
          </div>
          {chapters.map((chap, idx) => {
            const isActive = idx === activeIdx;
            return (
              <button
                key={chap.id}
                onClick={() => setActiveIdx(idx)}
                style={{
                  all: 'unset',
                  cursor: 'pointer',
                  padding: '10px 14px',
                  borderRadius: 4,
                  background: isActive ? 'rgba(230, 220, 203, 0.05)' : 'transparent',
                  borderLeft: isNarrow ? 'none' : `2px solid ${isActive ? accent.color : 'transparent'}`,
                  borderBottom: isNarrow ? `2px solid ${isActive ? accent.color : 'transparent'}` : 'none',
                  color: isActive ? DC.bone : DC.grey,
                  fontFamily: DF.sans,
                  fontSize: 14,
                  transition: 'all 200ms ease-out',
                  whiteSpace: 'nowrap',
                }}
                onMouseEnter={(e) => { if (!isActive) e.currentTarget.style.color = DC.softBone; }}
                onMouseLeave={(e) => { if (!isActive) e.currentTarget.style.color = DC.grey; }}
              >
                {chap.label}
              </button>
            );
          })}
        </div>

        {/* Stage Content */}
        <div style={{ 
          flex: 1, 
          overflowY: 'auto', /* Internal scroll fallback only if window is extremely short */
          position: 'relative',
          display: 'flex',
          flexDirection: 'column'
        }}>
          <div 
            key={activeIdx} 
            style={{ 
              animation: 'dp-fade-in 300ms ease-out',
              flex: 1,
              display: 'flex',
              flexDirection: 'column',
              justifyContent: 'center'
            }}
          >
            <ActiveComponent />
          </div>
          <div style={{ marginTop: 'auto' }}>
            <DFooter />
          </div>
        </div>
      </main>
    </div>
  );
}

window.DiscoveryPage = DiscoveryPage;
