// Experience, Skills, Projects, Certifications, Contact — balanced compact

function Experience() {
  const D = window.DATA;
  const [expanded, setExpanded] = React.useState(-1);

  return (
    <section id="experience" style={{ padding: '22px 48px', maxWidth: 1200, margin: '0 auto' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 12 }}>
        <SectionLabel num="02">Experience</SectionLabel>
        <span className="mono faint" style={{ fontSize: 10 }}>{D.experience.length} ROLES · 6 YRS</span>
      </div>

      <div style={{ borderTop: '1px solid var(--line)' }}>
        {D.experience.map((job, i) => {
          const isOpen = expanded === i;
          return (
            <div key={i} style={{
              borderBottom: '1px solid var(--line)',
              padding: '10px 0',
            }}>
              <div
                onClick={() => setExpanded(isOpen ? -1 : i)}
                style={{
                  cursor: 'pointer',
                  display: 'grid',
                  gridTemplateColumns: '110px 1fr auto',
                  gap: 18,
                  alignItems: 'baseline',
                }}
              >
                <div className="mono" style={{ fontSize: 10, color: 'var(--ink-muted)', paddingTop: 3 }}>
                  {job.period.split('—')[0].trim()}
                  <span className="faint" style={{ fontSize: 9, marginLeft: 6 }}>· {job.duration}</span>
                  {job.current && (
                    <div style={{ marginTop: 2, color: 'var(--accent)', fontSize: 9 }}>● CURRENT</div>
                  )}
                </div>

                <div>
                  <div className="serif" style={{ fontSize: 18, lineHeight: 1.2, letterSpacing: '-0.01em', marginBottom: 2 }}>
                    {job.role}
                  </div>
                  <div style={{ fontSize: 12, color: 'var(--ink-muted)', marginBottom: 5 }}>
                    <span style={{ color: 'var(--ink)', fontWeight: 500 }}>{job.company}</span>
                    {' · '}{job.location} · <span className="mono" style={{ fontSize: 10 }}>{job.type}</span>
                  </div>
                  <p style={{ fontSize: 12.5, lineHeight: 1.5, color: 'var(--ink)', marginBottom: 6, maxWidth: 720 }}>
                    {job.highlights[0]}
                  </p>
                  <div style={{ display: 'flex', flexWrap: 'wrap', gap: 4 }}>
                    {job.tags.map(t => (
                      <span key={t} className="mono" style={{
                        fontSize: 9,
                        padding: '2px 7px',
                        background: 'var(--bg-elevated)',
                        color: 'var(--ink-muted)',
                        borderRadius: 3,
                      }}>{t}</span>
                    ))}
                  </div>
                </div>

                <div style={{
                  fontFamily: 'var(--font-mono)',
                  fontSize: 14,
                  color: 'var(--ink-muted)',
                  transition: 'transform 0.2s',
                  transform: isOpen ? 'rotate(45deg)' : 'rotate(0)',
                  paddingTop: 2,
                }}>+</div>
              </div>

              <div style={{
                maxHeight: isOpen ? '1200px' : 0,
                overflow: 'hidden',
                transition: 'max-height 0.4s ease, opacity 0.3s',
                opacity: isOpen ? 1 : 0,
              }}>
                <div style={{
                  display: 'grid',
                  gridTemplateColumns: '110px 1fr',
                  gap: 18,
                  marginTop: 8,
                  paddingTop: 8,
                  borderTop: '1px dashed var(--line)',
                }}>
                  <div className="mono faint" style={{ fontSize: 9, letterSpacing: '0.1em' }}>MORE SCOPE</div>
                  <ul style={{ listStyle: 'none', padding: 0, margin: 0 }}>
                    {job.highlights.slice(1).map((h, j) => (
                      <li key={j} style={{
                        paddingLeft: 16,
                        position: 'relative',
                        marginBottom: 5,
                        fontSize: 12.5,
                        lineHeight: 1.5,
                        color: 'var(--ink)',
                      }}>
                        <span style={{
                          position: 'absolute', left: 0, top: 0,
                          color: 'var(--accent)',
                          fontFamily: 'var(--font-mono)',
                          fontSize: 10,
                        }}>→</span>
                        {h}
                      </li>
                    ))}
                  </ul>
                </div>
              </div>
            </div>
          );
        })}
      </div>

      <div style={{ marginTop: 0, display: 'flex', alignItems: 'center', gap: 18, padding: '10px 0', borderBottom: '1px solid var(--line)' }}>
        <div className="mono" style={{ fontSize: 10, color: 'var(--accent)', width: 110 }}>EDUCATION</div>
        <div style={{ flex: 1 }}>
          <div className="serif" style={{ fontSize: 15, marginBottom: 1 }}>{D.education.school}</div>
          <div style={{ fontSize: 12, color: 'var(--ink-muted)' }}>{D.education.degree}</div>
        </div>
        <div className="mono faint" style={{ fontSize: 11 }}>{D.education.period}</div>
      </div>
    </section>
  );
}

function Skills() {
  const D = window.DATA;
  const categories = Object.keys(D.skills);

  return (
    <section id="skills" style={{ padding: '22px 48px', maxWidth: 1200, margin: '0 auto' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 12 }}>
        <SectionLabel num="03">Toolbelt</SectionLabel>
        <span className="mono faint" style={{ fontSize: 10 }}>{categories.length} CATEGORIES</span>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: '14px 32px' }} className="grid-3">
        {categories.map((cat, i) => (
          <div key={cat}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 6, paddingBottom: 4, borderBottom: '1px solid var(--line)' }}>
              <span className="mono" style={{ fontSize: 9, color: 'var(--accent)' }}>
                {String(i + 1).padStart(2, '0')}
              </span>
              <span className="mono" style={{ fontSize: 10, letterSpacing: '0.08em', fontWeight: 500 }}>
                {cat.toUpperCase()}
              </span>
            </div>
            <div style={{ display: 'flex', flexWrap: 'wrap', gap: 3 }}>
              {D.skills[cat].map(s => (
                <span key={s} style={{
                  fontSize: 11,
                  padding: '2px 7px',
                  background: 'var(--paper-tint)',
                  border: '1px solid var(--line)',
                  borderRadius: 3,
                  color: 'var(--ink)',
                  whiteSpace: 'nowrap',
                }}>{s}</span>
              ))}
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

function Projects({ onOpenProject }) {
  const D = window.DATA;

  return (
    <section id="projects" style={{ padding: '22px 48px', maxWidth: 1200, margin: '0 auto' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 12 }}>
        <SectionLabel num="04">Selected Projects</SectionLabel>
        <span className="mono faint" style={{ fontSize: 10 }}>CLICK ROW FOR DOSSIER</span>
      </div>

      <div style={{ borderTop: '1px solid var(--line)' }}>
        {D.projects.map((p, i) => (
          <div
            key={i}
            onClick={() => onOpenProject(p)}
            style={{
              borderBottom: '1px solid var(--line)',
              padding: '10px 10px',
              cursor: 'pointer',
              transition: 'background 0.15s',
              display: 'grid',
              gridTemplateColumns: '34px 1fr 200px 110px 24px',
              gap: 14,
              alignItems: 'center',
            }}
            onMouseEnter={(e) => {
              e.currentTarget.style.background = 'var(--paper-tint)';
              e.currentTarget.querySelector('.proj-arrow').style.transform = 'translateX(4px)';
            }}
            onMouseLeave={(e) => {
              e.currentTarget.style.background = 'transparent';
              e.currentTarget.querySelector('.proj-arrow').style.transform = 'translateX(0)';
            }}
          >
            <div className="mono faint" style={{ fontSize: 10 }}>
              {String(i + 1).padStart(2, '0')}
            </div>

            <div>
              <div className="serif" style={{ fontSize: 16, lineHeight: 1.2, letterSpacing: '-0.01em', marginBottom: 2 }}>
                {p.name}
              </div>
              <div style={{ fontSize: 11.5, color: 'var(--ink-muted)' }}>
                {p.client}
              </div>
            </div>

            <div style={{ display: 'flex', flexWrap: 'wrap', gap: 3 }}>
              {p.systems.slice(0, 3).map(s => (
                <span key={s} className="mono" style={{
                  fontSize: 9,
                  padding: '2px 6px',
                  border: '1px solid var(--line)',
                  borderRadius: 3,
                  color: 'var(--ink-muted)',
                }}>{s}</span>
              ))}
            </div>

            <div style={{ textAlign: 'right' }}>
              <div className="serif" style={{ fontSize: 14, color: 'var(--ink)' }}>{p.value}</div>
              <div className="mono faint" style={{ fontSize: 9 }}>{p.year} · {p.scope}</div>
            </div>

            <div className="proj-arrow mono" style={{
              fontSize: 13,
              color: 'var(--accent)',
              transition: 'transform 0.2s',
              textAlign: 'right',
            }}>→</div>
          </div>
        ))}
      </div>

      <div style={{ marginTop: 8, textAlign: 'center' }}>
        <span className="mono faint" style={{ fontSize: 10 }}>// MORE AVAILABLE ON REQUEST — NDA APPLIES TO CLIENT-SPECIFIC DRAWINGS</span>
      </div>
    </section>
  );
}

function Certifications() {
  const D = window.DATA;
  return (
    <section style={{ padding: '22px 48px', maxWidth: 1200, margin: '0 auto' }}>
      <SectionLabel num="05">Certifications</SectionLabel>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))', gap: 8, marginTop: 12 }}>
        {D.certifications.map((c, i) => (
          <div key={i} style={{
            padding: '10px 12px',
            background: 'var(--paper-tint)',
            border: '1px solid var(--line)',
            borderRadius: 'var(--radius)',
            position: 'relative',
          }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
              <div style={{
                width: 22, height: 22,
                border: '1px solid var(--ink)',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                fontFamily: 'var(--font-serif)',
                fontStyle: 'italic',
                fontSize: 12,
                color: 'var(--accent)',
              }}>✓</div>
              <div className="mono faint" style={{ fontSize: 9 }}>#{c.id}</div>
            </div>
            <div className="serif" style={{ fontSize: 13.5, lineHeight: 1.2, marginBottom: 3 }}>{c.name}</div>
            <div style={{ fontSize: 11, color: 'var(--ink-muted)', marginBottom: 6 }}>{c.issuer}</div>
            <div style={{ display: 'flex', gap: 14, paddingTop: 6, borderTop: '1px dashed var(--line)' }}>
              <div>
                <div className="mono faint" style={{ fontSize: 8, marginBottom: 1 }}>ISSUED</div>
                <div className="mono" style={{ fontSize: 10 }}>{c.date}</div>
              </div>
              {c.expires && (
                <div>
                  <div className="mono faint" style={{ fontSize: 8, marginBottom: 1 }}>EXPIRES</div>
                  <div className="mono" style={{ fontSize: 10 }}>{c.expires}</div>
                </div>
              )}
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

function Contact() {
  const D = window.DATA;
  return (
    <section id="contact" style={{ padding: '12px 48px 14px', maxWidth: 1200, margin: '0 auto' }}>
      <div style={{
        background: '#0e0e0c',
        color: '#f5f5f0',
        padding: '24px 28px',
        borderRadius: 'var(--radius-lg)',
        position: 'relative',
        overflow: 'hidden',
      }}>
        <div style={{
          position: 'absolute',
          inset: 0,
          backgroundImage: `linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
                            linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px)`,
          backgroundSize: '32px 32px',
          pointerEvents: 'none',
        }} />

        <div style={{ position: 'relative' }}>
          <div className="mono" style={{ fontSize: 10, color: 'var(--accent-soft)', letterSpacing: '0.15em', marginBottom: 10 }}>
            // 06 · LET'S TALK
          </div>
          <h2 className="serif" style={{
            fontSize: 'clamp(26px, 3.6vw, 44px)',
            lineHeight: 1.05,
            letterSpacing: '-0.02em',
            marginBottom: 12,
            maxWidth: 900,
            color: '#f5f5f0',
          }}>
            Need a low-voltage partner that <em style={{ color: 'var(--accent-soft)' }}>reads the plans</em> before pricing them?
          </h2>
          <p style={{ fontSize: 13.5, lineHeight: 1.5, color: 'rgba(245,245,240,0.75)', maxWidth: 640, marginBottom: 16 }}>
            GCs, integrators, and owners — Calidad does design-build, bid spec, and service work across the U.S. Send me the drawings, I'll send back an honest scope.
          </p>

          <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', marginBottom: 18 }}>
            <a href={`mailto:${D.email}`} className="btn" style={{ background: 'var(--accent)', borderColor: 'var(--accent)', color: 'white' }}>
              Send email →
            </a>
            <a href={`https://${D.calendly}`} className="btn secondary" style={{ color: '#f5f5f0', borderColor: 'rgba(245,245,240,0.3)', background: 'transparent' }}>
              Schedule a call
            </a>
          </div>

          <div style={{
            display: 'grid',
            gridTemplateColumns: 'repeat(auto-fit, minmax(160px, 1fr))',
            gap: 14,
            paddingTop: 14,
            borderTop: '1px solid rgba(245,245,240,0.1)',
          }}>
            <div>
              <div className="mono" style={{ fontSize: 9, color: 'var(--accent-soft)', marginBottom: 3 }}>EMAIL</div>
              <div style={{ fontSize: 12, color: '#f5f5f0' }}>{D.email}</div>
            </div>
            <div>
              <div className="mono" style={{ fontSize: 9, color: 'var(--accent-soft)', marginBottom: 3 }}>LINKEDIN</div>
              <div style={{ fontSize: 12, color: '#f5f5f0' }}>{D.linkedin}</div>
            </div>
            <div>
              <div className="mono" style={{ fontSize: 9, color: 'var(--accent-soft)', marginBottom: 3 }}>BASED</div>
              <div style={{ fontSize: 12, color: '#f5f5f0' }}>Rizal, PH · Remote U.S.</div>
            </div>
            <div>
              <div className="mono" style={{ fontSize: 9, color: 'var(--accent-soft)', marginBottom: 3 }}>RESPONSE</div>
              <div style={{ fontSize: 12, color: '#f5f5f0' }}>Within 24h</div>
            </div>
          </div>
        </div>
      </div>

      <div style={{ marginTop: 24, display: 'flex', justifyContent: 'space-between', fontSize: 11, fontFamily: 'var(--font-mono)', color: 'var(--ink-faint)', letterSpacing: '0.1em', textTransform: 'uppercase' }}>
        <span>© 2026 Edanuele Corleto</span>
        <span>Drawn in HTML · Rev C · {new Date().toLocaleDateString('en-US', { month: 'short', year: 'numeric' })}</span>
      </div>
    </section>
  );
}

function ScrollSpy({ theme, onToggleTheme }) {
  const sections = [
    { id: 'about', label: 'About' },
    { id: 'experience', label: 'Experience' },
    { id: 'skills', label: 'Skills' },
    { id: 'projects', label: 'Projects' },
    { id: 'contact', label: 'Contact' },
  ];
  const [visible, setVisible] = React.useState(false);
  const [active, setActive] = React.useState('about');
  const [open, setOpen] = React.useState(false);

  React.useEffect(() => {
    const onScroll = () => {
      setVisible(window.scrollY > 500);
      let current = sections[0].id;
      for (const s of sections) {
        const el = document.getElementById(s.id);
        if (el && el.getBoundingClientRect().top < 200) current = s.id;
      }
      setActive(current);
    };
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  const activeLabel = sections.find(s => s.id === active)?.label || 'About';

  return (
    <div style={{
      position: 'fixed', top: 20, right: 20, zIndex: 90,
      opacity: visible ? 1 : 0,
      transform: visible ? 'translateY(0)' : 'translateY(-12px)',
      transition: 'opacity 0.3s ease, transform 0.3s ease',
      pointerEvents: visible ? 'auto' : 'none',
    }}>
      <div
        onMouseEnter={() => setOpen(true)}
        onMouseLeave={() => setOpen(false)}
        style={{
          background: 'var(--bg)',
          border: '1px solid var(--line-strong)',
          borderRadius: 999,
          boxShadow: '0 6px 20px rgba(0,0,0,0.08)',
          padding: '7px 4px 7px 16px',
          display: 'flex', alignItems: 'center', gap: 12,
          fontFamily: 'var(--font-mono)',
          fontSize: 11, letterSpacing: '0.08em',
          textTransform: 'uppercase', color: 'var(--ink)',
          cursor: 'pointer',
        }}
      >
        <span style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
          <span style={{
            width: 6, height: 6, borderRadius: '50%',
            background: 'var(--accent)',
            boxShadow: '0 0 0 3px rgba(194,106,10,0.15)',
          }} />
          {activeLabel}
        </span>

        <div style={{
          maxWidth: open ? 340 : 0,
          overflow: 'hidden',
          transition: 'max-width 0.3s ease',
          display: 'flex', alignItems: 'center',
        }}>
          <span style={{ width: 1, height: 14, background: 'var(--line)', margin: '0 7px' }} />
          <div style={{ display: 'flex', gap: 3 }}>
            {sections.map(s => (
              <a key={s.id} href={`#${s.id}`} style={{
                padding: '5px 9px',
                borderRadius: 999,
                color: active === s.id ? 'var(--bg)' : 'var(--ink-muted)',
                background: active === s.id ? 'var(--ink)' : 'transparent',
                fontSize: 10, letterSpacing: '0.08em',
                whiteSpace: 'nowrap', transition: 'all 0.2s',
              }}>{s.label}</a>
            ))}
          </div>
        </div>

        <div style={{
          width: 18, height: 22,
          display: open ? 'none' : 'flex',
          alignItems: 'center', justifyContent: 'center',
          color: 'var(--ink-muted)', fontSize: 12, letterSpacing: 1,
        }}>···</div>

        <span style={{ width: 1, height: 14, background: 'var(--line)' }} />
        <button
          onClick={(e) => { e.stopPropagation(); onToggleTheme(); }}
          aria-label="Toggle dark mode"
          style={{
            padding: '4px 9px 4px 7px',
            borderRadius: 999, background: 'transparent',
            border: 'none', color: 'var(--ink-muted)',
            fontSize: 13, cursor: 'pointer',
            fontFamily: 'var(--font-mono)',
            display: 'flex', alignItems: 'center',
          }}
        >{theme === 'ink' ? '☀' : '☾'}</button>
      </div>
    </div>
  );
}

function HobbyTicker() {
  const facts = [
    "// titanium embedded in both wrists — basically half iron man, half wolverine",
    "// builds things with AI for fun, not just for work",
    "// certified cat person",
    "// lucky husband to an amazing wife",
    "// flies FPV drones — simulation only, walls are expensive",
    "// MMORPG is the only correct genre of game",
    "// first touched a computer at age 5 and never recovered",
  ];

  const [idx, setIdx] = React.useState(0);
  const [visible, setVisible] = React.useState(true);

  React.useEffect(() => {
    const cycle = setInterval(() => {
      setVisible(false);
      setTimeout(() => {
        setIdx(i => (i + 1) % facts.length);
        setVisible(true);
      }, 500);
    }, 3000);
    return () => clearInterval(cycle);
  }, []);

  return (
    <div style={{
      maxWidth: 1200, margin: '0 auto',
      padding: '6px 48px 14px',
      display: 'flex', alignItems: 'center', gap: 12,
    }}>
      <span style={{
        width: 6, height: 6, borderRadius: '50%',
        background: 'var(--accent)',
        flexShrink: 0,
        boxShadow: '0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent)',
      }} />
      <span style={{
        fontFamily: 'var(--font-mono)',
        fontSize: 11,
        color: 'var(--ink-muted)',
        letterSpacing: '0.04em',
        opacity: visible ? 1 : 0,
        transition: 'opacity 0.4s ease',
        userSelect: 'none',
      }}>{facts[idx]}</span>
    </div>
  );
}

function Builds() {
  const D = window.DATA;
  const builds = D.builds || [];
  const [activeScreenshot, setActiveScreenshot] = React.useState({});
  const [lightbox, setLightbox] = React.useState(null); // { shots, name, index, position } | null
  const touch = React.useRef(null);

  const prevShot = (i, len) => setActiveScreenshot(prev => ({ ...prev, [i]: Math.max((prev[i] || 0) - 1, 0) }));
  const nextShot = (i, len) => setActiveScreenshot(prev => ({ ...prev, [i]: Math.min((prev[i] || 0) + 1, len - 1) }));

  const lbPrev = () => setLightbox(lb => lb ? { ...lb, index: Math.max(0, lb.index - 1) } : lb);
  const lbNext = () => setLightbox(lb => lb ? { ...lb, index: Math.min(lb.shots.length - 1, lb.index + 1) } : lb);

  // Touch swipe: past a ~40px horizontal drag, fire onLeft (swipe left) or onRight
  const swipe = (onLeft, onRight) => ({
    onTouchStart: e => { touch.current = e.touches[0].clientX; },
    onTouchEnd: e => {
      if (touch.current == null) return;
      const dx = e.changedTouches[0].clientX - touch.current;
      touch.current = null;
      if (dx <= -40) onLeft();
      else if (dx >= 40) onRight();
    },
  });

  React.useEffect(() => {
    if (!lightbox) return;
    document.body.classList.add('modal-open');
    const onKey = e => {
      if (e.key === 'Escape') setLightbox(null);
      else if (e.key === 'ArrowRight') lbNext();
      else if (e.key === 'ArrowLeft') lbPrev();
    };
    window.addEventListener('keydown', onKey);
    return () => { document.body.classList.remove('modal-open'); window.removeEventListener('keydown', onKey); };
  }, [lightbox]);

  if (!builds.length) return null;

  return (
    <section id="builds" style={{ padding: '22px 48px', maxWidth: 1200, margin: '0 auto' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 4 }}>
        <SectionLabel num="06">Side Builds</SectionLabel>
        <span className="mono faint" style={{ fontSize: 10 }}>BUILT FOR FUN</span>
      </div>
      <p style={{ fontSize: 13, color: 'var(--ink-muted)', marginBottom: 18, maxWidth: 560, lineHeight: 1.5 }}>
        Things I build outside of work. Security pays the bills — this is what I do when I'm curious about something and just want to ship it.
      </p>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 16 }} className="grid-2">
        {builds.map((b, i) => {
          const activeIdx = activeScreenshot[i] || 0;
          const shots = b.screenshots || [];
          const hasPrev = activeIdx > 0;
          const hasNext = activeIdx < shots.length - 1;

          return (
            <div key={i} style={{
              border: '1px solid var(--line)',
              borderRadius: 'var(--radius-lg)',
              background: 'var(--paper-tint)',
              overflow: 'hidden',
              transition: 'border-color 0.2s, box-shadow 0.2s',
            }}
              onMouseEnter={e => { e.currentTarget.style.borderColor = 'var(--line-strong)'; e.currentTarget.style.boxShadow = '0 6px 24px rgba(0,0,0,0.06)'; }}
              onMouseLeave={e => { e.currentTarget.style.borderColor = 'var(--line)'; e.currentTarget.style.boxShadow = 'none'; }}
            >
              {/* Screenshot area */}
              <div style={{ position: 'relative', background: 'var(--bg-elevated)', overflow: 'hidden', height: 200 }}
                {...(shots.length > 1 ? swipe(() => nextShot(i, shots.length), () => prevShot(i, shots.length)) : {})}
              >
                {shots.length > 0 ? (
                  <img
                    key={activeIdx}
                    src={shots[activeIdx]}
                    alt={b.name}
                    onClick={() => setLightbox({ shots, name: b.name, index: activeIdx, position: b.shotPosition || 'top' })}
                    style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: b.shotPosition || 'top', display: 'block', cursor: 'zoom-in', animation: 'fadeIn 0.25s ease' }}
                  />
                ) : (
                  <div style={{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 48 }}>🦆</div>
                )}

                {/* Expand hint */}
                {shots.length > 0 && (
                  <div style={{
                    position: 'absolute', top: 10, right: 10,
                    width: 24, height: 24, borderRadius: 5,
                    background: 'rgba(14,14,12,0.55)', color: 'white',
                    display: 'flex', alignItems: 'center', justifyContent: 'center',
                    fontSize: 12, pointerEvents: 'none', backdropFilter: 'blur(4px)',
                  }}>⤢</div>
                )}

                {/* Status badge */}
                <div style={{
                  position: 'absolute', top: 10, left: 10,
                  background: b.status === 'Live' ? 'var(--accent)' : 'rgba(14,14,12,0.65)',
                  color: 'white', fontFamily: 'var(--font-mono)',
                  fontSize: 9, letterSpacing: '0.12em',
                  padding: '3px 9px', borderRadius: 3,
                  backdropFilter: 'blur(4px)',
                }}>{b.status === 'Live' ? '● LIVE' : '■ PRIVATE'}</div>

                {/* Arrow nav — only when multiple shots */}
                {shots.length > 1 && (
                  <>
                    <button onClick={() => prevShot(i, shots.length)} disabled={!hasPrev} style={{
                      position: 'absolute', left: 10, top: '50%', transform: 'translateY(-50%)',
                      width: 30, height: 30, borderRadius: '50%',
                      background: hasPrev ? 'rgba(255,255,255,0.92)' : 'rgba(255,255,255,0.35)',
                      border: '1px solid rgba(0,0,0,0.08)',
                      color: hasPrev ? 'var(--ink)' : 'rgba(0,0,0,0.25)',
                      fontFamily: 'var(--font-mono)', fontSize: 13,
                      cursor: hasPrev ? 'pointer' : 'default',
                      display: 'flex', alignItems: 'center', justifyContent: 'center',
                      boxShadow: hasPrev ? '0 2px 8px rgba(0,0,0,0.12)' : 'none',
                      transition: 'all 0.15s',
                    }}>‹</button>
                    <button onClick={() => nextShot(i, shots.length)} disabled={!hasNext} style={{
                      position: 'absolute', right: 10, top: '50%', transform: 'translateY(-50%)',
                      width: 30, height: 30, borderRadius: '50%',
                      background: hasNext ? 'rgba(255,255,255,0.92)' : 'rgba(255,255,255,0.35)',
                      border: '1px solid rgba(0,0,0,0.08)',
                      color: hasNext ? 'var(--ink)' : 'rgba(0,0,0,0.25)',
                      fontFamily: 'var(--font-mono)', fontSize: 13,
                      cursor: hasNext ? 'pointer' : 'default',
                      display: 'flex', alignItems: 'center', justifyContent: 'center',
                      boxShadow: hasNext ? '0 2px 8px rgba(0,0,0,0.12)' : 'none',
                      transition: 'all 0.15s',
                    }}>›</button>
                    {/* Dot indicators */}
                    <div style={{ position: 'absolute', bottom: 10, left: '50%', transform: 'translateX(-50%)', display: 'flex', gap: 5 }}>
                      {shots.map((_, si) => (
                        <div key={si} onClick={() => setActiveScreenshot(prev => ({ ...prev, [i]: si }))} style={{
                          width: si === activeIdx ? 16 : 5, height: 5,
                          borderRadius: 999,
                          background: si === activeIdx ? 'white' : 'rgba(255,255,255,0.45)',
                          cursor: 'pointer',
                          transition: 'all 0.25s ease',
                          boxShadow: '0 1px 3px rgba(0,0,0,0.2)',
                        }} />
                      ))}
                    </div>
                  </>
                )}
              </div>

              {/* Content */}
              <div style={{ padding: '16px 18px 18px' }}>
                <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 3 }}>
                  <div className="serif" style={{ fontSize: 18, letterSpacing: '-0.01em', lineHeight: 1.15 }}>{b.name}</div>
                  {b.stores ? (
                    <div style={{ display: 'flex', gap: 6, flexShrink: 0, marginLeft: 10 }}>
                      {b.stores.map(s => (
                        <a key={s.label} href={s.url} target="_blank" rel="noopener noreferrer"
                          style={{
                            fontFamily: 'var(--font-mono)', fontSize: 9,
                            color: 'var(--accent)', letterSpacing: '0.08em',
                            border: '1px solid var(--accent)', borderRadius: 3,
                            padding: '3px 9px', whiteSpace: 'nowrap',
                            textDecoration: 'none', transition: 'all 0.15s',
                          }}
                          onMouseEnter={e => { e.currentTarget.style.background = 'var(--accent)'; e.currentTarget.style.color = 'white'; }}
                          onMouseLeave={e => { e.currentTarget.style.background = 'transparent'; e.currentTarget.style.color = 'var(--accent)'; }}
                        >{s.label}</a>
                      ))}
                    </div>
                  ) : b.link ? (
                    <a href={b.link} target="_blank" rel="noopener noreferrer"
                      style={{
                        fontFamily: 'var(--font-mono)', fontSize: 9,
                        color: 'var(--accent)', letterSpacing: '0.08em',
                        border: '1px solid var(--accent)', borderRadius: 3,
                        padding: '3px 9px', whiteSpace: 'nowrap',
                        textDecoration: 'none', transition: 'all 0.15s',
                        flexShrink: 0, marginLeft: 10,
                      }}
                      onMouseEnter={e => { e.currentTarget.style.background = 'var(--accent)'; e.currentTarget.style.color = 'white'; }}
                      onMouseLeave={e => { e.currentTarget.style.background = 'transparent'; e.currentTarget.style.color = 'var(--accent)'; }}
                    >{b.linkLabel}</a>
                  ) : (
                    <span style={{
                      fontFamily: 'var(--font-mono)', fontSize: 9,
                      color: 'var(--ink-faint)', letterSpacing: '0.08em',
                      border: '1px solid var(--line)', borderRadius: 3,
                      padding: '3px 9px', whiteSpace: 'nowrap',
                      flexShrink: 0, marginLeft: 10,
                    }}>Private</span>
                  )}
                </div>
                <div style={{ fontSize: 11.5, color: 'var(--ink-muted)', marginBottom: 8, lineHeight: 1.45 }}>{b.tagline}</div>
                <p style={{ fontSize: 12.5, lineHeight: 1.5, color: 'var(--ink)', marginBottom: 12 }}>{b.description}</p>
                <div style={{ display: 'flex', flexWrap: 'wrap', gap: 4 }}>
                  {b.platform.map(t => (
                    <span key={t} className="mono" style={{
                      fontSize: 9, padding: '2px 7px',
                      background: 'var(--bg-elevated)',
                      border: '1px solid var(--line)',
                      borderRadius: 3, color: 'var(--ink-muted)',
                    }}>{t}</span>
                  ))}
                </div>
              </div>
            </div>
          );
        })}
      </div>

      {/* Lightbox — click a build screenshot to enlarge; swipe on mobile, arrows/keys on desktop */}
      {lightbox && (
        <div
          onClick={() => setLightbox(null)}
          {...(lightbox.shots.length > 1 ? swipe(lbNext, lbPrev) : {})}
          style={{
            position: 'fixed', inset: 0, zIndex: 300,
            background: 'rgba(10,14,10,0.92)',
            backdropFilter: 'blur(6px)', WebkitBackdropFilter: 'blur(6px)',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            padding: '48px 20px', animation: 'fadeIn 0.2s ease',
          }}
        >
          <button onClick={() => setLightbox(null)} aria-label="Close" style={{
            position: 'absolute', top: 18, right: 18, width: 40, height: 40,
            borderRadius: '50%', border: '1px solid rgba(255,255,255,0.25)',
            background: 'rgba(255,255,255,0.06)', color: 'white',
            fontFamily: 'var(--font-mono)', fontSize: 20, cursor: 'pointer', zIndex: 2,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
          }}>×</button>

          <img
            key={lightbox.index}
            src={lightbox.shots[lightbox.index]}
            alt={lightbox.name}
            onClick={e => e.stopPropagation()}
            style={{
              maxWidth: 'min(900px, 94vw)', maxHeight: '86vh',
              width: 'auto', height: 'auto', objectFit: 'contain',
              borderRadius: 14, boxShadow: '0 30px 80px rgba(0,0,0,0.5)',
              animation: 'fadeIn 0.2s ease',
            }}
          />

          {lightbox.shots.length > 1 && (
            <>
              <button onClick={e => { e.stopPropagation(); lbPrev(); }} disabled={lightbox.index === 0} aria-label="Previous" style={{
                position: 'absolute', left: 'max(16px, 4vw)', top: '50%', transform: 'translateY(-50%)',
                width: 46, height: 46, borderRadius: '50%',
                border: '1px solid rgba(255,255,255,0.22)', background: 'rgba(255,255,255,0.08)',
                color: lightbox.index === 0 ? 'rgba(255,255,255,0.3)' : 'white',
                fontFamily: 'var(--font-mono)', fontSize: 20,
                cursor: lightbox.index === 0 ? 'default' : 'pointer',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
              }}>‹</button>
              <button onClick={e => { e.stopPropagation(); lbNext(); }} disabled={lightbox.index === lightbox.shots.length - 1} aria-label="Next" style={{
                position: 'absolute', right: 'max(16px, 4vw)', top: '50%', transform: 'translateY(-50%)',
                width: 46, height: 46, borderRadius: '50%',
                border: '1px solid rgba(255,255,255,0.22)', background: 'rgba(255,255,255,0.08)',
                color: lightbox.index === lightbox.shots.length - 1 ? 'rgba(255,255,255,0.3)' : 'white',
                fontFamily: 'var(--font-mono)', fontSize: 20,
                cursor: lightbox.index === lightbox.shots.length - 1 ? 'default' : 'pointer',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
              }}>›</button>

              <div onClick={e => e.stopPropagation()} style={{
                position: 'absolute', bottom: 20, left: '50%', transform: 'translateX(-50%)',
                display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 10,
              }}>
                <div style={{ display: 'flex', gap: 6 }}>
                  {lightbox.shots.map((_, si) => (
                    <div key={si} onClick={() => setLightbox(lb => ({ ...lb, index: si }))} style={{
                      width: si === lightbox.index ? 20 : 6, height: 6, borderRadius: 999,
                      background: si === lightbox.index ? 'white' : 'rgba(255,255,255,0.4)',
                      cursor: 'pointer', transition: 'all 0.25s ease',
                    }} />
                  ))}
                </div>
                <div className="mono" style={{ fontSize: 10, color: 'rgba(255,255,255,0.6)', letterSpacing: '0.1em' }}>
                  {String(lightbox.index + 1).padStart(2, '0')} / {String(lightbox.shots.length).padStart(2, '0')} · SWIPE OR ← →
                </div>
              </div>
            </>
          )}
        </div>
      )}
    </section>
  );
}

Object.assign(window, { Experience, Skills, Projects, Certifications, Contact, ScrollSpy, HobbyTicker, Builds });
