/* global React, PROJECTS, PERSONAL_EXTRA, projBySlug, byKind, pmono, Placeholder, BeforeAfter, SiteNav, ContactBand, SiteFooter */
// Work index + project templates (professional / personal / academic).

const KIND_BLURB = {
  Professional: 'Institutional-scale built work — higher-ed housing, wellness and education — carried from pre-design through construction administration.',
  Personal: 'Design-build remodels and ground-up residential work — designed, detailed and largely built by hand. The depth of the passion and the entrepreneur.',
  Academic: 'Competition, studio and thesis work — the conceptual range behind the built portfolio.',
};

// ── Work index ─────────────────────────────────────────────────
function WorkPage() {
  const [filter, setFilter] = React.useState('All');
  React.useEffect(() => { window.scrollTo(0, 0); }, []);
  const kinds = ['Professional', 'Personal', 'Academic'].filter((k) => filter === 'All' || filter === k);
  return (
    <div style={{ background:'var(--paper)', color:'var(--ink)', fontFamily:'var(--f-sans)' }}>
      <SiteNav active="work" />
      <section style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'clamp(48px,6vw,88px) var(--gutter) 0' }}>
        <span style={pmono({ color:'var(--accent)', letterSpacing:'0.22em', display:'inline-flex', alignItems:'center', gap:'12px' })}>
          <span style={{ width:'26px', height:'1px', background:'var(--accent)' }}></span>Selected Work
        </span>
        <h1 style={{ fontSize:'clamp(2.4rem,6vw,4.4rem)', fontWeight:800, letterSpacing:'-0.045em', lineHeight:0.94, margin:'0.3em 0 0' }}>
          Designed, detailed, built<span style={{ color:'var(--accent)' }}>.</span>
        </h1>
        <p style={{ maxWidth:'56ch', marginTop:'24px', fontSize:'18px', lineHeight:1.55, color:'var(--ink-2)' }}>
          Three bodies of work — institutional projects delivered with a firm, hands-on remodels built by hand, and the academic work that keeps the conceptual muscle warm.
        </p>
        <div style={{ display:'flex', gap:'8px', flexWrap:'wrap', marginTop:'40px', paddingTop:'26px', borderTop:'1px solid var(--line)' }}>
          {['All', 'Professional', 'Personal', 'Academic'].map((c) => {
            const on = c === filter;
            const count = c === 'All' ? PROJECTS.length : byKind(c).length;
            return (
              <button key={c} onClick={() => setFilter(c)} style={{
                ...pmono({ fontSize:'11px' }), cursor:'pointer',
                border:`1px solid ${on ? 'var(--ink)' : 'var(--line-strong)'}`,
                background: on ? 'var(--ink)' : 'transparent', color: on ? 'var(--paper)' : 'var(--ink-2)',
                padding:'10px 18px', transition:'all .15s',
              }}>{c} <span style={{ opacity:0.5, marginLeft:'4px' }}>{count}</span></button>
            );
          })}
        </div>
      </section>

      {kinds.map((kind) => (
        <section key={kind} style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'clamp(32px,4vw,52px) var(--gutter) 0' }}>
          <div style={{ display:'flex', justifyContent:'space-between', alignItems:'baseline', gap:'24px', flexWrap:'wrap', marginBottom:'22px' }}>
            <h2 style={{ fontSize:'clamp(1.3rem,2.4vw,1.9rem)', fontWeight:700, letterSpacing:'-0.02em', margin:0 }}>{kind}</h2>
            <p style={{ ...pmono({ color:'var(--muted)', fontSize:'10.5px' }), margin:0, maxWidth:'46ch', textAlign:'right', lineHeight:1.6, letterSpacing:'0.04em', textTransform:'none' }}>{KIND_BLURB[kind]}</p>
          </div>
          {kind === 'Academic' ? <AcademicGrid /> : (
            <div style={{ display:'grid', gridTemplateColumns:'repeat(auto-fill,minmax(340px,1fr))', gap:'1px', background:'var(--line)', border:'1px solid var(--line)' }}>
              {byKind(kind).map((p) => <ProjectCard key={p.slug} p={p} />)}
              {kind === 'Personal' && PERSONAL_EXTRA.map((p) => <ExtraCard key={p.name} p={p} />)}
            </div>
          )}
        </section>
      ))}

      <div style={{ height:'clamp(56px,7vw,96px)' }}></div>
      <ContactBand />
      <SiteFooter />
    </div>
  );
}

function ProjectCard({ p }) {
  return (
    <a href={`#/work/${p.slug}`} className="proj-card" style={{ display:'block', textDecoration:'none', color:'var(--ink)', background:'var(--paper)' }}>
      <div style={{ position:'relative', aspectRatio:'4 / 3', overflow:'hidden', background:'var(--ink)' }}>
        <img src={p.img} alt="" style={{ width:'100%', height:'100%', objectFit:'cover' }} className="proj-img" />
        <span style={{ position:'absolute', top:0, left:0, ...pmono({ fontSize:'11px' }), color:'#fff', background:'var(--accent)', padding:'5px 10px' }}>{p.n}</span>
      </div>
      <div style={{ padding:'22px 24px 26px' }}>
        <div style={{ fontWeight:700, fontSize:'1.3rem', letterSpacing:'-0.02em' }}>{p.name}</div>
        <p style={{ margin:'10px 0 0', color:'var(--ink-2)', fontSize:'14.5px', lineHeight:1.5 }}>{p.tag}</p>
        {p.details && <div style={pmono({ color:'var(--muted)', fontSize:'10px', marginTop:'16px' })}>{p.details[0][1]}</div>}
      </div>
    </a>
  );
}

function ExtraCard({ p }) {
  return (
    <div style={{ background:'var(--paper)' }}>
      <div style={{ position:'relative', aspectRatio:'4 / 3', overflow:'hidden', background:'var(--ink)' }}>
        <img src={p.img} alt="" style={{ width:'100%', height:'100%', objectFit:'cover' }} />
        <span style={{ position:'absolute', top:0, left:0, ...pmono({ fontSize:'10px' }), color:'var(--ink)', background:'var(--paper)', padding:'5px 10px' }}>Additional</span>
      </div>
      <div style={{ padding:'22px 24px 26px' }}>
        <div style={{ fontWeight:700, fontSize:'1.15rem', letterSpacing:'-0.02em' }}>{p.name}</div>
        <p style={{ margin:'10px 0 0', color:'var(--ink-2)', fontSize:'14px', lineHeight:1.5 }}>{p.blurb}</p>
      </div>
    </div>
  );
}

// Academic grid — thesis featured large, the rest as a supporting row.
function AcademicGrid() {
  const thesis = projBySlug('temporary-architecture');
  const rest = byKind('Academic').filter((p) => p.slug !== 'temporary-architecture');
  return (
    <div style={{ display:'grid', gap:'1px', background:'var(--line)', border:'1px solid var(--line)' }}>
      <a href={`#/work/${thesis.slug}`} className="proj-card" style={{ display:'grid', gridTemplateColumns:'1.25fr 1fr', textDecoration:'none', color:'var(--ink)', background:'var(--paper)' }}>
        <div style={{ position:'relative', overflow:'hidden', background:'var(--ink)', minHeight:'260px' }}>
          <img src={thesis.img} alt="" className="proj-img" style={{ position:'absolute', inset:0, width:'100%', height:'100%', objectFit:'cover' }} />
          <span style={{ position:'absolute', top:0, left:0, ...pmono({ fontSize:'11px' }), color:'#fff', background:'var(--accent)', padding:'6px 12px' }}>Master&rsquo;s Thesis</span>
        </div>
        <div style={{ padding:'clamp(24px,3vw,44px)', display:'flex', flexDirection:'column', justifyContent:'center' }}>
          <div style={{ fontWeight:800, fontSize:'clamp(1.5rem,2.4vw,2.1rem)', letterSpacing:'-0.03em', lineHeight:1.02 }}>{thesis.name}</div>
          <p style={{ margin:'14px 0 20px', color:'var(--ink-2)', fontSize:'15.5px', lineHeight:1.6, maxWidth:'40ch' }}>{thesis.tag}</p>
          <span style={pmono({ color:'var(--accent)', fontSize:'11px' })}>Read the thesis →</span>
        </div>
      </a>
      <div style={{ display:'grid', gridTemplateColumns:'repeat(auto-fit,minmax(230px,1fr))', gap:'1px', background:'var(--line)' }}>
        {rest.map((p) => (
          <a key={p.slug} href={`#/work/${p.slug}`} className="proj-card" style={{ display:'block', textDecoration:'none', color:'var(--ink)', background:'var(--paper)' }}>
            <div style={{ position:'relative', aspectRatio:'4 / 3', overflow:'hidden', background:'var(--ink)' }}>
              <img src={p.img} alt="" className="proj-img" style={{ width:'100%', height:'100%', objectFit:'cover' }} />
            </div>
            <div style={{ padding:'16px 18px 20px' }}>
              <div style={pmono({ color:'var(--accent)', fontSize:'9.5px', marginBottom:'6px' })}>{p.subtitle}</div>
              <div style={{ fontWeight:700, fontSize:'1.05rem', letterSpacing:'-0.01em' }}>{p.name}</div>
            </div>
          </a>
        ))}
      </div>
    </div>
  );
}

// ── Project router ─────────────────────────────────────────────
function ProjectPage({ slug }) {
  const p = projBySlug(slug);
  React.useEffect(() => { window.scrollTo(0, 0); }, [slug]);
  if (!p) return <NotFound />;
  if (p.kind === 'Professional') return <ProfessionalProject p={p} />;
  if (p.kind === 'Personal') return <PersonalProject p={p} />;
  if (p.slug === 'temporary-architecture') return <ThesisProject p={p} />;
  return <AcademicProject p={p} />;
}

// Shared hero + prev/next within the same kind.
function ProjectHero({ p, tagline }) {
  return (
    <div style={{ position:'relative', height:'clamp(360px,56vh,600px)', background:'var(--ink)', overflow:'hidden' }} className="print-hero">
      <img src={p.img} alt="" style={{ width:'100%', height:'100%', objectFit:'cover', opacity:0.92 }} />
      <div style={{ position:'absolute', inset:0, background:'linear-gradient(to top, rgba(8,7,5,0.90) 0%, rgba(8,7,5,0.55) 32%, rgba(8,7,5,0.12) 64%, rgba(8,7,5,0.30) 100%)' }}></div>
      <div style={{ position:'absolute', left:0, right:0, bottom:0 }}>
        <div style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'0 var(--gutter) clamp(28px,4vw,52px)' }}>
          <div style={pmono({ color:'#fff', fontSize:'12px', marginBottom:'14px', display:'inline-flex', alignItems:'center', gap:'10px', textShadow:'0 1px 12px rgba(8,7,5,0.6)' })}><span style={{ width:'22px', height:'2px', background:'var(--accent)' }}></span>{p.kind} · {p.n}</div>
          <h1 style={{ color:'#fff', fontSize:'clamp(2.2rem,6vw,4.4rem)', fontWeight:800, letterSpacing:'-0.045em', lineHeight:0.96, margin:0, maxWidth:'20ch', textShadow:'0 2px 24px rgba(8,7,5,0.45)' }}>{p.name}</h1>
          {p.subtitle && <div style={{ color:'rgba(255,255,255,0.92)', fontSize:'clamp(1rem,1.8vw,1.4rem)', marginTop:'14px', fontWeight:500, textShadow:'0 1px 16px rgba(8,7,5,0.5)' }}>{p.subtitle}</div>}
          {tagline && <p style={{ color:'rgba(255,255,255,0.82)', fontSize:'16px', marginTop:'14px', maxWidth:'52ch', lineHeight:1.5, textShadow:'0 1px 14px rgba(8,7,5,0.5)' }}>{tagline}</p>}
        </div>
      </div>
    </div>
  );
}

function DetailsBlock({ details }) {
  return (
    <section style={{ borderBottom:'1px solid var(--line)' }}>
      <div style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'clamp(28px,3vw,40px) var(--gutter)' }}>
        <div style={pmono({ color:'var(--muted)', marginBottom:'20px' })}>Project Details</div>
        <div style={{ display:'grid', gridTemplateColumns:'repeat(auto-fit,minmax(170px,1fr))', gap:'24px 32px' }}>
          {details.map(([k, v]) => (
            <div key={k}>
              <div style={pmono({ color:'var(--accent)', fontSize:'10px', marginBottom:'7px' })}>{k}</div>
              <div style={{ fontFamily:'var(--f-mono)', fontSize:'13.5px', color:'var(--ink)', letterSpacing:'0.01em', lineHeight:1.5 }}>{v}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function NextProject({ p }) {
  const pool = byKind(p.kind);
  const idx = pool.findIndex((x) => x.slug === p.slug);
  const next = pool[(idx + 1) % pool.length];
  if (!next || next.slug === p.slug) return null;
  return (
    <a href={`#/work/${next.slug}`} style={{ display:'block', textDecoration:'none', background:'var(--dark)', color:'var(--on-dark)' }} className="next-proj">
      <div style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'clamp(40px,5vw,72px) var(--gutter)', display:'grid', gridTemplateColumns:'1fr auto', gap:'32px', alignItems:'center' }}>
        <div>
          <div style={pmono({ color:'var(--accent)', marginBottom:'14px' })}>Next in {p.kind} →</div>
          <div style={{ fontSize:'clamp(1.6rem,4vw,3rem)', fontWeight:800, letterSpacing:'-0.04em', lineHeight:1 }}>{next.name}</div>
          <div style={pmono({ color:'var(--on-dark-muted)', fontSize:'11px', marginTop:'14px' })}>{next.subtitle}</div>
        </div>
        <div className="next-thumb" style={{ width:'clamp(120px,18vw,200px)', aspectRatio:'4 / 3', overflow:'hidden', flexShrink:0 }}>
          <img src={next.img} alt="" style={{ width:'100%', height:'100%', objectFit:'cover', transition:'transform .5s cubic-bezier(.2,.7,.3,1)' }} />
        </div>
      </div>
    </a>
  );
}

function Section({ num, label, title, note, children, bg }) {
  return (
    <section style={{ borderBottom:'1px solid var(--line)', background: bg || 'transparent' }}>
      <div style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'clamp(44px,6vw,84px) var(--gutter)' }}>
        <div style={{ marginBottom:note ? '14px' : '32px' }}>
          <div style={pmono({ color:'var(--muted)', fontSize:'10px', marginBottom:'12px', display:'flex', alignItems:'center', gap:'10px' })}>
            <span style={{ color:'var(--accent)' }}>{num}</span>
            <span style={{ width:'16px', height:'1px', background:'var(--line-strong)' }}></span>
            <span>{label}</span>
          </div>
          <h2 style={{ fontSize:'clamp(1.5rem,3vw,2.2rem)', fontWeight:700, letterSpacing:'-0.03em', margin:0, lineHeight:1.05 }}>{title}</h2>
        </div>
        {note && <p style={{ maxWidth:'62ch', margin:'0 0 32px', color:'var(--ink-2)', fontSize:'15.5px', lineHeight:1.55 }}>{note}</p>}
        {children}
      </div>
    </section>
  );
}

// ── Professional template ──────────────────────────────────────
function ProfessionalProject({ p }) {
  return (
    <div style={{ background:'var(--paper)', color:'var(--ink)', fontFamily:'var(--f-sans)' }}>
      <SiteNav active="work" />
      <ProjectHero p={p} tagline={p.tag} />
      <DetailsBlock details={p.details} />

      <Section num="01" label="Overview" title={p.subtitle}>
        <div style={{ display:'grid', gridTemplateColumns: p.gallery && p.gallery.length ? '1.15fr 1fr' : '1fr', gap:'clamp(28px,4vw,56px)', alignItems:'start' }} className="pro-overview">
          <div style={{ display:'grid', gap:'18px', maxWidth:'64ch' }}>
            {p.desc.map((para, i) => <p key={i} style={{ margin:0, fontSize:'16px', lineHeight:1.65, color:'var(--ink-2)' }}>{para}</p>)}
          </div>
          {p.gallery && p.gallery.length > 0 && (
            <div style={{ display:'grid', gap:'16px', position:'sticky', top:'88px' }}>
              {p.gallery.map(([src, cap]) => (
                <figure key={cap} style={{ margin:0 }}>
                  <div style={{ aspectRatio:'4 / 3', overflow:'hidden', background:'var(--ink)' }}>
                    <img src={src} alt={cap} style={{ width:'100%', height:'100%', objectFit:'cover' }} />
                  </div>
                  <figcaption style={pmono({ color:'var(--muted)', fontSize:'9.5px', marginTop:'10px' })}>{cap}</figcaption>
                </figure>
              ))}
            </div>
          )}
        </div>
      </Section>

      <GallerySection num="02" p={p} />

      <Section num="03" label="My Role" title="Roles &amp; Responsibilities"
        note="What I actually did on this project — from pre-design through construction administration.">
        <div style={{ display:'grid', gridTemplateColumns:`repeat(${p.roles.length === 4 ? 4 : 'auto-fit'},minmax(230px,1fr))`, gap:'1px', background:'var(--line)', border:'1px solid var(--line)' }} className="roles-grid">
          {p.roles.map((r, i) => (
            <div key={r.title} style={{ background:'var(--paper)', padding:'28px 24px' }}>
              <div style={pmono({ color:'var(--accent)', fontSize:'10px', marginBottom:'4px' })}>{String(i + 1).padStart(2, '0')}</div>
              <div style={{ fontWeight:700, fontSize:'17px', letterSpacing:'-0.01em', marginBottom:'16px' }}>{r.title}</div>
              <ul style={{ margin:0, padding:0, listStyle:'none', display:'grid', gap:'12px' }}>
                {r.bullets.map((b, j) => (
                  <li key={j} style={{ display:'grid', gridTemplateColumns:'14px 1fr', gap:'8px', fontSize:'13.5px', lineHeight:1.5, color:'var(--ink-2)' }}>
                    <span style={{ color:'var(--accent)' }}>—</span><span>{b}</span>
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </div>
      </Section>

      {p.credit && <CreditLine text={p.credit} />}
      <NextProject p={p} />
      <ContactBand />
      <SiteFooter />
    </div>
  );
}

// ── Personal template (Vision / Before-After / Narrative / Renderings) ──
function PersonalProject({ p }) {
  let n = 0; const next = () => String(++n).padStart(2, '0');
  return (
    <div style={{ background:'var(--paper)', color:'var(--ink)', fontFamily:'var(--f-sans)' }}>
      <SiteNav active="work" />
      <ProjectHero p={p} tagline={p.tag} />
      <DetailsBlock details={p.details} />

      {p.designGoals && (
        <section style={{ borderBottom:'1px solid var(--line)', background:'var(--paper-2)' }}>
          <div style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'clamp(28px,3vw,40px) var(--gutter)' }}>
            <div style={pmono({ color:'var(--muted)', marginBottom:'18px' })}>Design Goals</div>
            <div style={{ display:'flex', flexWrap:'wrap', gap:'10px' }}>
              {p.designGoals.map((g) => (
                <span key={g} style={{ ...pmono({ fontSize:'11px', color:'var(--ink)' }), border:'1px solid var(--line-strong)', background:'var(--paper)', padding:'10px 16px', letterSpacing:'0.08em' }}>{g}</span>
              ))}
            </div>
          </div>
        </section>
      )}

      {p.vision && (
        <Section num={next()} label="Pre-Design" title="The Vision">
          <p style={{ maxWidth:'68ch', margin:0, fontSize:'17px', lineHeight:1.7, color:'var(--ink-2)' }}>{p.vision}</p>
        </Section>
      )}

      {p.beforeAfter && (() => {
        const pairs = Array.isArray(p.beforeAfter) ? p.beforeAfter : [p.beforeAfter];
        const row = p.beforeAfterLayout === 'row' && pairs.length > 1;
        return (
        <Section num={next()} label="The Transformation" title="Before &amp; After"
          note="Drag the handle to wipe between the original condition and the finished result.">
          <div style={ row
            ? { display:'grid', gridTemplateColumns:'repeat(auto-fit,minmax(300px,1fr))', gap:'24px', alignItems:'start' }
            : { display:'flex', flexDirection:'column', gap:'40px' } }>
            {pairs.map((ba, i) => (
              <div key={i}>
                <BeforeAfter {...ba} height={row ? 'clamp(460px,46vw,760px)' : undefined} />
                {ba.caption && <p style={pmono({ color:'var(--muted)', fontSize:'10px', marginTop:'14px', letterSpacing:'0.08em', textTransform:'none' })}>{ba.caption}</p>}
              </div>
            ))}
          </div>
        </Section>
        );
      })()}

      {p.renderings && (
        <Section num={next()} label="Design Development" title="Renderings">
          <div style={{ display:'grid', gridTemplateColumns:'repeat(auto-fit,minmax(300px,1fr))', gap:'16px' }}>
            {p.renderings.map(([src, cap, thumbs]) => (
              <figure key={cap} style={{ margin:0 }}>
                <div style={{ aspectRatio:'4 / 3', overflow:'hidden', background:'var(--ink)' }}>
                  <img src={src} alt={cap} style={{ width:'100%', height:'100%', objectFit:'cover' }} />
                </div>
                <figcaption style={pmono({ color:'var(--muted)', fontSize:'9.5px', marginTop:'10px' })}>{cap}</figcaption>
                {thumbs && thumbs.length > 0 && (
                  <div style={{ display:'grid', gridTemplateColumns:`repeat(${thumbs.length}, 1fr)`, gap:'10px', marginTop:'12px' }}>
                    {thumbs.map(([tsrc, tcap]) => (
                      <figure key={tcap} style={{ margin:0 }}>
                        <div style={{ aspectRatio:'4 / 3', overflow:'hidden', background:'var(--ink)', border:'1px solid var(--line)' }}>
                          <img src={tsrc} alt={tcap} style={{ width:'100%', height:'100%', objectFit:'cover' }} />
                        </div>
                        <figcaption style={pmono({ color:'var(--muted)', fontSize:'8px', marginTop:'7px', letterSpacing:'0.1em' })}>{tcap}</figcaption>
                      </figure>
                    ))}
                  </div>
                )}
              </figure>
            ))}
          </div>
        </Section>
      )}

      {p.narrative && (
        <Section num={next()} label="In My Words" title="The Narrative" bg="var(--paper-2)">
          <div style={{ display:'grid', gap:'20px', maxWidth:'70ch' }}>
            {p.narrative.map((para, i) => <p key={i} style={{ margin:0, fontSize:'16.5px', lineHeight:1.7, color:'var(--ink-2)' }}>{para}</p>)}
          </div>
        </Section>
      )}

      <GallerySection num={next()} p={p} title="The Reveal" label="Finished Spaces"
        note="Suggested finished photography — drop in the reveal shots (kitchen, baths, living spaces) that show the transformation paid off." />

      {p.credit && <CreditLine text={p.credit} />}
      <NextProject p={p} />
      <ContactBand />
      <SiteFooter />
    </div>
  );
}

// ── Thesis (rich academic) ─────────────────────────────────────
function ThesisProject({ p }) {
  return (
    <div style={{ background:'var(--paper)', color:'var(--ink)', fontFamily:'var(--f-sans)' }}>
      <SiteNav active="work" />
      <ProjectHero p={p} tagline={p.tag} />
      <DetailsBlock details={p.details} />
      <Section num="01" label="The Argument" title="Temporary Architecture">
        <div style={{ display:'grid', gap:'18px', maxWidth:'66ch' }}>
          {p.desc.map((para, i) => <p key={i} style={{ margin:0, fontSize:'16.5px', lineHeight:1.7, color:'var(--ink-2)' }}>{para}</p>)}
        </div>
      </Section>
      <section style={{ borderBottom:'1px solid var(--line)' }}>
        <div style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'0 var(--gutter) clamp(44px,6vw,84px)' }}>
          <div style={{ aspectRatio:'16 / 9', overflow:'hidden', background:'var(--ink)' }}>
            <img src={p.img} alt="" style={{ width:'100%', height:'100%', objectFit:'cover' }} />
          </div>
          <p style={pmono({ color:'var(--muted)', fontSize:'9.5px', marginTop:'12px' })}>Tower massing studied in its urban context model.</p>
        </div>
      </section>
      <GallerySection num="02" p={p} label="Imagery" title="Thesis Documentation"
        note="Suggested boards and model photography — drop in the drawings, diagrams and section model that carry the argument." />
      {p.credit && <CreditLine text={p.credit} />}
      <NextProject p={p} />
      <ContactBand />
      <SiteFooter />
    </div>
  );
}

// ── Simple academic detail ─────────────────────────────────────
function AcademicProject({ p }) {
  return (
    <div style={{ background:'var(--paper)', color:'var(--ink)', fontFamily:'var(--f-sans)' }}>
      <SiteNav active="work" />
      <ProjectHero p={p} tagline={p.tag} />
      <section>
        <div style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'clamp(40px,5vw,72px) var(--gutter)' }}>
          <div style={{ aspectRatio:'16 / 9', overflow:'hidden', background:'var(--ink)' }}>
            <img src={p.img} alt="" style={{ width:'100%', height:'100%', objectFit:'cover' }} />
          </div>
          <p style={{ maxWidth:'58ch', margin:'28px 0 0', fontSize:'16.5px', lineHeight:1.6, color:'var(--ink-2)' }}>{p.tag}</p>
          <a href="#/work" style={{ ...pmono({ color:'var(--accent)', fontSize:'11px', textDecoration:'none' }), display:'inline-block', marginTop:'24px' }}>← Back to work</a>
        </div>
      </section>
      <NextProject p={p} />
      <ContactBand />
      <SiteFooter />
    </div>
  );
}

// Labeled placeholder gallery — communicates exactly what photography would add value.
function GallerySection({ num, p, title = 'Project Gallery', label = 'Imagery', note = 'Suggested photography to round out the story — drop a real image into each slot (interiors, details and key spaces a recruiter wants to see).' }) {
  const images = p.images || [];
  const slots = p.imageSlots || [];
  if (!images.length && !slots.length) return null;
  const useReal = images.length > 0;
  return (
    <Section num={num} label={label} title={title} note={useReal ? (p.galleryNote || note) : note}>
      <div style={{ display:'grid', gridTemplateColumns:'repeat(auto-fill,minmax(258px,1fr))', gap:'16px' }}>
        {useReal
          ? images.map(([src, cap], i) => (
              <figure key={i} style={{ margin:0 }}>
                <div style={{ aspectRatio:'4 / 3', overflow:'hidden', background:'var(--ink)' }}>
                  <img src={src} alt={cap} style={{ width:'100%', height:'100%', objectFit:'cover' }} />
                </div>
                <figcaption style={pmono({ color:'var(--muted)', fontSize:'9.5px', marginTop:'10px' })}>{cap}</figcaption>
              </figure>
            ))
          : slots.map(([lbl, kind], i) => (
              <Placeholder key={i} label={lbl} kind={kind || 'Add photo'} ratio="4 / 3" />
            ))}
      </div>
    </Section>
  );
}

function CreditLine({ text }) {
  return (
    <div style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'22px var(--gutter)' }}>
      <p style={pmono({ color:'var(--muted)', fontSize:'9.5px', letterSpacing:'0.08em', textTransform:'none', margin:0 })}>{text}</p>
    </div>
  );
}

function NotFound() {
  return (
    <div style={{ background:'var(--paper)', color:'var(--ink)', minHeight:'100vh', fontFamily:'var(--f-sans)' }}>
      <SiteNav active="" />
      <div style={{ maxWidth:'var(--maxw)', margin:'0 auto', padding:'120px var(--gutter)' }}>
        <span style={pmono({ color:'var(--accent)' })}>404</span>
        <h1 style={{ fontSize:'clamp(2rem,5vw,3.5rem)', fontWeight:800, letterSpacing:'-0.04em', marginTop:'16px' }}>This page isn&rsquo;t in the set.</h1>
        <a href="#/" style={pmono({ color:'var(--accent)', fontSize:'12px', textDecoration:'none' })}>← Back home</a>
      </div>
    </div>
  );
}

Object.assign(window, { WorkPage, ProjectPage, NotFound });
