// Chrome: Nav + Footer + reusable bits
const { useState, useEffect, useRef } = React;

const NAV_ITEMS = [
{ id: 'home', label: 'Accueil' },
{ id: 'domaines', label: 'Les 7 expertises' },
{ id: 'performance', label: 'Performance' },
{ id: 'continu', label: 'Continu' },
{ id: 'amenagement', label: 'Aménagement' },
{ id: 'equipement', label: 'Équipement' },
{ id: 'competences', label: 'Compétences' },
{ id: 'outils', label: 'Automatisation', isNew: true },
{ id: 'apropos', label: 'À propos' }];


function Nav({ route, navigate }) {
  const [open, setOpen] = useState(false);
  const [hidden, setHidden] = useState(false);
  const lastY = useRef(0);

  useEffect(() => {
    function onScroll() {
      const y = window.scrollY;
      setHidden(y > 200 && y > lastY.current);
      lastY.current = y;
    }
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  useEffect(() => { setOpen(false); }, [route]);

  useEffect(() => {
    function onKey(e) { if (e.key === 'Escape') setOpen(false); }
    document.addEventListener('keydown', onKey);
    return () => document.removeEventListener('keydown', onKey);
  }, []);

  useEffect(() => {
    const t = setTimeout(() => {
      document.querySelectorAll('.auto-scroll-hint').forEach(el => el.remove());

      function makeHint(isDark) {
        const c = isDark ? 'rgba(255,255,255,0.7)' : 'rgba(6,6,26,0.55)';
        const h = document.createElement('div');
        h.className = 'auto-scroll-hint scroll-hint-inner';
        h.style.cssText = 'position:absolute;bottom:22px;left:50%;transform:translateX(-50%);display:flex;flex-direction:column;align-items:center;gap:3px;z-index:20;pointer-events:none';
        h.innerHTML = `<span style="font-family:var(--f-mono);font-size:7px;letter-spacing:.22em;text-transform:uppercase;color:${c};display:block">SCROLL</span><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="${c}" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="animation:scrollBounce 1.9s ease-in-out infinite;display:block"><polyline points="6 9 12 15 18 9"/></svg>`;
        return h;
      }

      // Pages secondaires : main > section (toutes sauf celles qui ont déjà un hint)
      const main = document.querySelector('main');
      if (main) {
        Array.from(main.querySelectorAll(':scope > section')).forEach(section => {
          if (section.querySelector('.scroll-hint-inner')) return;
          const rgb = getComputedStyle(section).backgroundColor.match(/\d+/g);
          const isDark = section.querySelector('.bg-stars-light,.bg-grid-light') ||
            (rgb && (rgb[0]*299 + rgb[1]*587 + rgb[2]*114)/1000 < 128);
          if (getComputedStyle(section).position === 'static') section.style.position = 'relative';
          section.appendChild(makeHint(isDark));
        });
      }

      // Page home : hints gérés par V4Home (body portal, position:fixed)
    }, 500);
    return () => clearTimeout(t);
  }, [route]);

  function go(id) { setOpen(false); navigate(id); }

  const EXP = [
    { id: 'performance', num: '01', label: 'Performance',           kpi: '+22% TRS' },
    { id: 'continu',     num: '02', label: 'Amélioration continue', kpi: '+12 idées/mois' },
    { id: 'amenagement', num: '03', label: 'Aménagement',           kpi: '−45% trajets' },
    { id: 'equipement',  num: '04', label: 'Équipement',            kpi: '−30% arrêts' },
    { id: 'competences', num: '05', label: 'Compétences',           kpi: '×2 polyvalence' },
    { id: 'diagnostic',  num: '06', label: 'Diagnostic flash',      kpi: 'J+0 restitution' },
    { id: 'outils',      num: '07', label: 'Automatisation',        kpi: 'Déployé & en prod' },
  ];
  const OUTILS_NAV = [
    { id: 'cadulis',   label: 'Cadulis',   color: '#2563eb' },
    { id: 'kizeo',     label: 'Kizeo',     color: '#ea580c' },
    { id: 'skello',    label: 'SKELLO',    color: '#7c3aed' },
    { id: 'ebp',       label: 'EBP',       color: '#1e40af' },
    { id: 'pennylane', label: 'Pennylane', color: '#16a34a' },
  ];
  const SECT_NAV = [
    { id: 'plasturgie', label: 'Plasturgie' },
    { id: 'usinage',    label: 'Usinage' },
    { id: 'menuiserie', label: 'Menuiserie' },
  ];
  const PRIMARY = [
    { id: 'home',      label: 'Accueil',               sub: 'Page principale du site' },
    { id: 'domaines',  label: 'Les 7 expertises',       sub: 'Performance · Lean · Digital' },
    { id: 'logiciels', label: 'Nos outils numériques',  sub: '5 outils déployés en production' },
    { id: 'secteurs',  label: 'Nos secteurs',           sub: 'Plasturgie · Usinage · Menuiserie' },
    { id: 'apropos',   label: 'À propos',               sub: 'Benoît Tenailleau — 25 ans terrain' },
  ];

  return (
    <>
      {/* ── Barre nav ── */}
      <nav className={`nav ${hidden && !open ? 'is-hidden' : ''}`}
        style={open ? { background: 'var(--deep)', borderBottomColor: 'rgba(255,255,255,0.1)' } : {}}>
        <a className="nav-brand" href="#home" onClick={e => { e.preventDefault(); go('home'); }}
          style={open ? { color: '#fff' } : {}}>
          <img src={typeof window !== "undefined" && window.__resources && window.__resources.logoFull || "assets/logo-full.png"} alt="" className="brand-mark" />
          <div style={{ display:'flex', flexDirection:'column', gap:1 }}>
            <span style={{ lineHeight:1.15 }}>l&rsquo;Atelier<span style={{ color:'var(--yellow)', margin:'0 3px' }}>·</span>Perf</span>
            <span style={{ fontFamily:'var(--f-mono)', fontSize:8, fontWeight:400, letterSpacing:'0.2em', textTransform:'uppercase', color: open ? 'rgba(255,255,255,0.55)' : 'rgba(16,30,142,0.6)', lineHeight:1 }}>
              Optimisez&nbsp;·&nbsp;Innovez&nbsp;·&nbsp;Pour Performer
            </span>
          </div>
        </a>
        <div className="nav-links" style={open ? { display: 'none' } : {}}>
          <a className={`nav-link ${route === 'domaines' ? 'is-active' : ''}`}
            href="#domaines" onClick={e => { e.preventDefault(); navigate('domaines'); }}>
            Les 7 expertises
          </a>
          <a className={`nav-link ${['logiciels','cadulis','kizeo','skello','ebp','pennylane','outils'].includes(route) ? 'is-active' : ''}`}
            href="#logiciels" onClick={e => { e.preventDefault(); navigate('logiciels'); }}
            style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
            Nos outils
            <span style={{ fontFamily: 'var(--f-mono)', fontSize: 9, letterSpacing: '0.1em', padding: '2px 6px', borderRadius: 4, background: 'var(--electric)', color: '#fff' }}>NEW</span>
          </a>
          <a className={`nav-link ${['secteurs','plasturgie','usinage','menuiserie'].includes(route) ? 'is-active' : ''}`}
            href="#secteurs" onClick={e => { e.preventDefault(); navigate('secteurs'); }}>
            Nos secteurs
          </a>
          <a className={`nav-link ${route === 'apropos' ? 'is-active' : ''}`}
            href="#apropos" onClick={e => { e.preventDefault(); navigate('apropos'); }}>
            À propos
          </a>
        </div>
        <a href="#diagnostic" onClick={e => { e.preventDefault(); navigate('diagnostic'); }}
          className="nav-flash-diag"
          style={open ? { display:'none' } : { position:'absolute', left:'50%', transform:'translateX(-50%)', display:'inline-flex', alignItems:'center', gap:7, fontFamily:'var(--f-mono)', fontSize:9, fontWeight:700, letterSpacing:'0.13em', textTransform:'uppercase', padding:'7px 16px', borderRadius:999, background:'var(--yellow)', color:'#06061a', textDecoration:'none', whiteSpace:'nowrap', flexShrink:0 }}>
          <span className="pulse" style={{ width:5, height:5, background:'var(--ink)', borderRadius:'50%', flexShrink:0, boxShadow:'0 0 6px rgba(16,30,142,0.4)' }}/>
          DEMANDER MON FLASH DIAG OFFERT
        </a>
        <a className="nav-cta" href="#contact" onClick={e => { e.preventDefault(); navigate('contact'); }}
          style={open ? { display: 'none' } : {}}>
          <span>Contact</span>
          <svg className="arrow" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M5 12h14M13 5l7 7-7 7" /></svg>
        </a>
        <style>{`.nav-flash-diag { transition: opacity 200ms; } .nav-flash-diag:hover { opacity:0.82; } @media (max-width:860px) { .nav-flash-diag { display:none !important; } }`}</style>
        <button className="nav-burger" onClick={() => setOpen(o => !o)} aria-label={open ? 'Fermer le menu' : 'Ouvrir le menu'}
          style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', ...(open ? { color: '#fff' } : {}) }}>
          {open
            ? <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M18 6L6 18M6 6l12 12"/></svg>
            : <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M3 6h18M3 12h18M3 18h18"/></svg>
          }
        </button>
      </nav>

      {/* ── Mega-menu overlay ── */}
      {open && (
        <div style={{
          position: 'fixed', inset: 0, zIndex: 180,
          background: '#0d0d22', overflowY: 'auto',
          paddingTop: 64,
          animation: 'megaOpen 240ms cubic-bezier(0.16, 1, 0.3, 1)',
        }}>
          <div className="bg-stars-light" style={{ opacity: 0.3 }}></div>
          <div className="bg-glow" style={{ right: '-5%', top: '20%', width: 700, height: 700, background: 'radial-gradient(closest-side, rgba(94,76,255,0.28), transparent 70%)' }}></div>

          <div className="container" style={{ position: 'relative', zIndex: 2, paddingTop: 40, paddingBottom: 56 }}>
            <div style={{ display: 'grid', gridTemplateColumns: '5fr 7fr', gap: 0, minHeight: 'calc(100vh - 120px)' }} className="mega-grid">

              {/* ── Colonne gauche : nav primaire ── */}
              <div style={{ padding: '0 clamp(16px,4vw,56px) 32px 0', borderRight: '1px solid rgba(255,255,255,0.08)', display: 'flex', flexDirection: 'column' }}>
                <div style={{ fontFamily: 'var(--f-mono)', fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.28)', marginBottom: 20 }}>NAVIGATION</div>

                <div style={{ flex: 1 }}>
                  {PRIMARY.map((item, i) => (
                    <button key={item.id} onClick={() => go(item.id)}
                      style={{
                        display: 'flex', alignItems: 'flex-start', gap: 14, width: '100%',
                        padding: '14px 0', background: 'none', border: 'none',
                        borderBottom: '1px solid rgba(255,255,255,0.07)',
                        cursor: 'pointer', textAlign: 'left',
                        transition: 'padding-left 180ms ease',
                        animation: `megaItemIn 280ms ${i * 45}ms cubic-bezier(0.16,1,0.3,1) both`,
                      }}
                      onMouseEnter={e => { e.currentTarget.style.paddingLeft = '10px'; e.currentTarget.querySelector('.mi-arrow').style.color = 'var(--yellow)'; e.currentTarget.querySelector('.mi-label').style.color = 'var(--yellow)'; }}
                      onMouseLeave={e => { e.currentTarget.style.paddingLeft = '0'; e.currentTarget.querySelector('.mi-arrow').style.color = 'var(--electric-2)'; e.currentTarget.querySelector('.mi-label').style.color = route === item.id ? 'var(--yellow)' : '#fff'; }}>
                      <span className="mi-arrow" style={{ color: 'var(--electric-2)', fontSize: 16, marginTop: 3, lineHeight: 1, flexShrink: 0, transition: 'color 180ms' }}>→</span>
                      <div>
                        <div className="mi-label" style={{ fontFamily: 'var(--f-display)', fontWeight: 700, fontSize: 'clamp(17px,1.8vw,24px)', color: route === item.id ? 'var(--yellow)' : '#fff', lineHeight: 1.2, transition: 'color 180ms' }}>{item.label}</div>
                        <div style={{ fontFamily: 'var(--f-mono)', fontSize: 10, color: 'rgba(255,255,255,0.38)', marginTop: 3, letterSpacing: '0.06em' }}>{item.sub}</div>
                      </div>
                    </button>
                  ))}
                </div>

                {/* CTA + statut */}
                <div style={{ marginTop: 28 }}>
                  <button onClick={() => go('contact')} style={{
                    width: '100%', padding: '14px 20px', borderRadius: 12,
                    background: 'var(--yellow)', color: 'var(--text)',
                    fontFamily: 'var(--f-mono)', fontSize: 11, fontWeight: 700,
                    letterSpacing: '0.1em', textTransform: 'uppercase',
                    border: 'none', cursor: 'pointer',
                    display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
                  }}>
                    Démarrer un projet
                    <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M5 12h14M13 5l7 7-7 7"/></svg>
                  </button>
                  <div style={{ marginTop: 12, display: 'flex', alignItems: 'center', gap: 8, fontFamily: 'var(--f-mono)', fontSize: 9, color: 'rgba(255,255,255,0.32)', letterSpacing: '0.1em', textTransform: 'uppercase' }}>
                    <span style={{ width: 6, height: 6, borderRadius: '50%', background: 'var(--electric)', flexShrink: 0, boxShadow: '0 0 8px var(--electric)', animation: 'pulse 2s infinite' }}></span>
                    Vendée · Pays de la Loire · 1ère visite gratuite
                  </div>
                </div>
              </div>

              {/* ── Colonne droite : sous-navigation ── */}
              <div style={{ paddingLeft: 'clamp(16px,4vw,56px)', display: 'flex', flexDirection: 'column', gap: 28 }}>

                {/* 7 expertises */}
                <div>
                  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 14 }}>
                    <span style={{ fontFamily: 'var(--f-mono)', fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.3)' }}>LES 7 EXPERTISES</span>
                    <button onClick={() => go('domaines')} style={{ background: 'none', border: 'none', fontFamily: 'var(--f-mono)', fontSize: 9, color: 'var(--electric-2)', cursor: 'pointer', letterSpacing: '0.1em', textTransform: 'uppercase' }}>Voir tout →</button>
                  </div>
                  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 8 }} className="mega-exp-grid">
                    {EXP.map((e, i) => (
                      <button key={e.id} onClick={() => go(e.id)} style={{
                        background: 'rgba(255,255,255,0.04)', border: '1px solid rgba(255,255,255,0.08)',
                        borderRadius: 10, padding: '10px 12px', cursor: 'pointer', textAlign: 'left',
                        transition: 'background 130ms, border-color 130ms',
                        animation: `megaItemIn 300ms ${80 + i * 35}ms cubic-bezier(0.16,1,0.3,1) both`,
                      }}
                      onMouseEnter={ev => { ev.currentTarget.style.background = 'rgba(94,76,255,0.2)'; ev.currentTarget.style.borderColor = 'rgba(94,76,255,0.5)'; }}
                      onMouseLeave={ev => { ev.currentTarget.style.background = 'rgba(255,255,255,0.04)'; ev.currentTarget.style.borderColor = 'rgba(255,255,255,0.08)'; }}>
                        <div style={{ fontFamily: 'var(--f-mono)', fontSize: 8, color: 'var(--electric-2)', letterSpacing: '0.14em', marginBottom: 5 }}>{e.num}</div>
                        <div style={{ fontFamily: 'var(--f-display)', fontWeight: 700, fontSize: 13, color: '#fff', lineHeight: 1.2, marginBottom: 4 }}>{e.label}</div>
                        <div style={{ fontFamily: 'var(--f-mono)', fontSize: 8, color: 'rgba(255,255,255,0.32)', letterSpacing: '0.06em' }}>{e.kpi}</div>
                      </button>
                    ))}
                  </div>
                </div>

                {/* Outils */}
                <div style={{ borderTop: '1px solid rgba(255,255,255,0.08)', paddingTop: 20 }}>
                  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 12 }}>
                    <span style={{ fontFamily: 'var(--f-mono)', fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.3)' }}>NOS OUTILS NUMÉRIQUES</span>
                    <button onClick={() => go('logiciels')} style={{ background: 'none', border: 'none', fontFamily: 'var(--f-mono)', fontSize: 9, color: 'var(--electric-2)', cursor: 'pointer', letterSpacing: '0.1em', textTransform: 'uppercase' }}>Voir tout →</button>
                  </div>
                  <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
                    {OUTILS_NAV.map(t => (
                      <button key={t.id} onClick={() => go(t.id)} style={{
                        padding: '7px 16px', borderRadius: 999,
                        background: `${t.color}22`, border: `1px solid ${t.color}44`,
                        fontFamily: 'var(--f-mono)', fontSize: 10, fontWeight: 600,
                        color: '#fff', cursor: 'pointer',
                        transition: 'background 130ms, transform 130ms',
                      }}
                      onMouseEnter={ev => { ev.currentTarget.style.background = `${t.color}45`; ev.currentTarget.style.transform = 'translateY(-2px)'; }}
                      onMouseLeave={ev => { ev.currentTarget.style.background = `${t.color}22`; ev.currentTarget.style.transform = ''; }}>
                        {t.label}
                      </button>
                    ))}
                  </div>
                </div>

                {/* Secteurs */}
                <div style={{ borderTop: '1px solid rgba(255,255,255,0.08)', paddingTop: 20 }}>
                  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 12 }}>
                    <span style={{ fontFamily: 'var(--f-mono)', fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.3)' }}>NOS SECTEURS</span>
                    <button onClick={() => go('secteurs')} style={{ background: 'none', border: 'none', fontFamily: 'var(--f-mono)', fontSize: 9, color: 'var(--electric-2)', cursor: 'pointer', letterSpacing: '0.1em', textTransform: 'uppercase' }}>Voir tout →</button>
                  </div>
                  <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
                    {SECT_NAV.map(s => (
                      <button key={s.id} onClick={() => go(s.id)} style={{
                        padding: '7px 16px', borderRadius: 999,
                        background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.12)',
                        fontFamily: 'var(--f-mono)', fontSize: 10, fontWeight: 600,
                        color: 'rgba(255,255,255,0.8)', cursor: 'pointer',
                        transition: 'background 130ms, border-color 130ms',
                      }}
                      onMouseEnter={ev => { ev.currentTarget.style.background = 'rgba(255,255,255,0.16)'; ev.currentTarget.style.borderColor = 'rgba(255,255,255,0.3)'; }}
                      onMouseLeave={ev => { ev.currentTarget.style.background = 'rgba(255,255,255,0.06)'; ev.currentTarget.style.borderColor = 'rgba(255,255,255,0.12)'; }}>
                        {s.label}
                      </button>
                    ))}
                  </div>
                </div>
              </div>
            </div>
          </div>

          <style>{`
            @keyframes megaOpen { from { opacity: 0; } to { opacity: 1; } }
            @keyframes megaItemIn { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: translateX(0); } }
            @media (max-width: 800px) {
              .mega-grid { grid-template-columns: 1fr !important; }
              .mega-grid > div:first-child { border-right: none !important; border-bottom: 1px solid rgba(255,255,255,0.08); padding-right: 0 !important; padding-bottom: 28px !important; }
              .mega-grid > div:last-child { padding-left: 0 !important; }
              .mega-exp-grid { grid-template-columns: repeat(2,1fr) !important; }
            }
            @media (max-width: 480px) { .mega-exp-grid { grid-template-columns: 1fr !important; } }
          `}</style>
        </div>
      )}
    </>
  );
}

function Footer({ navigate }) {
  return (
    <footer className="footer">
      <div className="footer-inner container">
        <div className="footer-grid">
          <div>
            <div className="nav-brand" style={{ fontSize: 20, marginBottom: 16 }}>
              <img src={(typeof window !== "undefined" && window.__resources && window.__resources.logoBadge) || "assets/logo-badge.png"} alt="" className="brand-mark" style={{ width: 40, height: 40, borderRadius: 8 }} />
              <span>l&rsquo;Atelier<span style={{ color: 'var(--yellow)' }}> </span>Perf</span>
            </div>
            <p style={{ color: 'rgba(255,255,255,0.7)', maxWidth: 360, fontSize: 14, lineHeight: 1.7 }}>
              Partenaire opérationnel pour les industriels, artisans, commerçants et entreprises de services — du diagnostic à la mise en place sur le terrain, jusqu&rsquo;à ce que vos équipes tournent en autonomie.
            </p>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 10, marginTop: 24 }}>
              {[
                { label: "L'Atelier Perf",     href: 'https://www.linkedin.com/company/l-atelier-perf/?viewAsMember=true' },
                { label: 'Benoît Tenailleau',  href: 'https://www.linkedin.com/in/benoit-tenailleau-l-atelier-perf-091183239/' },
              ].map((s) =>
                <a key={s.label} href={s.href} target="_blank" rel="noopener noreferrer" style={{
                  display: 'inline-flex', alignItems: 'center', gap: 8,
                  fontFamily: 'var(--f-mono)', fontSize: 11, color: 'rgba(255,255,255,0.65)',
                  textDecoration: 'none', transition: 'color 180ms',
                }}
                onMouseEnter={(e) => e.currentTarget.style.color = '#fff'}
                onMouseLeave={(e) => e.currentTarget.style.color = 'rgba(255,255,255,0.65)'}>
                  <svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor" style={{ flexShrink: 0 }}>
                    <path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
                  </svg>
                  {s.label}
                </a>
              )}
            </div>
          </div>
          <div>
            <h4>7 Expertises</h4>
            <ul>
              <li><a href="#performance" onClick={(e) => {e.preventDefault();navigate('performance');}}>Performance</a></li>
              <li><a href="#continu" onClick={(e) => {e.preventDefault();navigate('continu');}}>Amélioration continue</a></li>
              <li><a href="#amenagement" onClick={(e) => {e.preventDefault();navigate('amenagement');}}>Aménagement atelier</a></li>
              <li><a href="#equipement" onClick={(e) => {e.preventDefault();navigate('equipement');}}>Équipement</a></li>
              <li><a href="#competences" onClick={(e) => {e.preventDefault();navigate('competences');}}>Formation terrain</a></li>
              <li><a href="#diagnostic" onClick={(e) => {e.preventDefault();navigate('diagnostic');}}>Diagnostic flash</a></li>
              <li><a href="#outils" onClick={(e) => {e.preventDefault();navigate('outils');}}>Automatisation &amp; Outils</a></li>
            </ul>
          </div>
          <div>
            <h4>Nos outils numériques</h4>
            <ul>
              <li><a href="#cadulis" onClick={(e) => {e.preventDefault();navigate('cadulis');}}>Cadulis — Planification terrain</a></li>
              <li><a href="#kizeo" onClick={(e) => {e.preventDefault();navigate('kizeo');}}>Kizeo Forms — Formulaires</a></li>
              <li><a href="#skello" onClick={(e) => {e.preventDefault();navigate('skello');}}>SKELLO — Planning équipes</a></li>
              <li><a href="#ebp" onClick={(e) => {e.preventDefault();navigate('ebp');}}>EBP — Gestion PME</a></li>
              <li><a href="#pennylane" onClick={(e) => {e.preventDefault();navigate('pennylane');}}>Pennylane — Gestion financière</a></li>
            </ul>
          </div>
          <div>
            <h4>Nos secteurs</h4>
            <ul>
              <li><a href="#secteurs" onClick={(e) => {e.preventDefault();navigate('secteurs');}}>Vue d&rsquo;ensemble</a></li>
              <li><a href="#plasturgie" onClick={(e) => {e.preventDefault();navigate('plasturgie');}}>Plasturgie</a></li>
              <li><a href="#usinage" onClick={(e) => {e.preventDefault();navigate('usinage');}}>Usinage</a></li>
              <li><a href="#menuiserie" onClick={(e) => {e.preventDefault();navigate('menuiserie');}}>Menuiserie industrielle</a></li>
              <li style={{ marginTop: 12 }}><a href="#vendee" onClick={(e) => {e.preventDefault();navigate('vendee');}} style={{ opacity: 0.7 }}>Vendée (85)</a></li>
              <li><a href="#pays-de-la-loire" onClick={(e) => {e.preventDefault();navigate('pays-de-la-loire');}} style={{ opacity: 0.7 }}>Pays de la Loire</a></li>
            </ul>
          </div>
          <div>
            <h4>Contact</h4>
            <ul>
              <li><a href="mailto:b.tenailleau@atelierperf.fr">b.tenailleau@atelierperf.fr</a></li>
              <li><a href="tel:+33685685336">+33 6 85 68 53 36</a></li>
              <li>Vendée · Pays de la Loire</li>
              <li>Déplacements toute France</li>
              <li style={{ marginTop: 12 }}>
                <a href="#apropos" onClick={(e) => {e.preventDefault();navigate('apropos');}} style={{ opacity: 0.7 }}>À propos</a>
              </li>
              <li><a href="#contact" onClick={(e) => {e.preventDefault();navigate('contact');}} style={{ opacity: 0.7 }}>Contact</a></li>
            </ul>
            <div style={{ marginTop: 16, paddingTop: 12, borderTop: '1px solid rgba(255,255,255,0.1)', fontSize: 10, color: 'rgba(255,255,255,0.45)', fontFamily: 'var(--f-mono)', letterSpacing: '0.1em' }}>
              ADHÉRENT PROXINNOV
            </div>
          </div>
        </div>
        <div className="footer-meta">
          <span>© 2026 ATELIER PERF — TOUS DROITS RÉSERVÉS</span>
          <span>v1.0 · AUCUN GASPILLAGE DÉTECTÉ</span>
        </div>
      </div>
      <div className="footer-bigtype" style={{ position:'absolute', top:0, bottom:0, left:0, right:0, display:'flex', alignItems:'center', justifyContent:'center', fontSize:'clamp(60px,14vw,200px)', padding:0, pointerEvents:'none', zIndex:0, overflow:'hidden' }}>ATELIER·PERF</div>
    </footer>);

}

// === Reveal-on-scroll helper ===
function useReveal() {
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => {
        if (e.isIntersecting) {
          e.target.classList.add('is-in');
          io.unobserve(e.target);
        }
      });
    }, { threshold: 0.12, rootMargin: '0px 0px -40px 0px' });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return ref;
}

function Reveal({ children, className = '', stagger, ...rest }) {
  const ref = useReveal();
  const cls = stagger ? 'reveal-stagger' : 'reveal';
  return <div ref={ref} className={`${cls} ${className}`} {...rest}>{children}</div>;
}

// === Card mouse-follow effect (cyberscope-y glow) ===
function MagCard({ children, className = '', ...rest }) {
  const ref = useRef(null);
  function onMove(e) {
    const r = ref.current.getBoundingClientRect();
    ref.current.style.setProperty('--mx', (e.clientX - r.left) / r.width * 100 + '%');
    ref.current.style.setProperty('--my', (e.clientY - r.top) / r.height * 100 + '%');
  }
  return <div ref={ref} className={`card ${className}`} onMouseMove={onMove} {...rest}>{children}</div>;
}

// Eyebrow tag with bracket markers
function Eyebrow({ children, dot = true }) {
  return (
    <span className="eyebrow">
      {dot && <span className="pulse"></span>}
      {children}
    </span>);
}

// Scroll indicator — animated chevron, absolute at bottom of hero sections
function ScrollHint({ dark = false }) {
  const c = dark ? 'rgba(255,255,255,0.32)' : 'rgba(6,6,26,0.28)';
  return (
    <div className="scroll-hint-inner" style={{
      position: 'absolute', bottom: 18, left: '50%', transform: 'translateX(-50%)',
      display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 2,
      zIndex: 10, pointerEvents: 'none',
    }}>
      <span style={{ fontFamily: 'var(--f-mono)', fontSize: 7, letterSpacing: '0.22em', textTransform: 'uppercase', color: c }}>SCROLL</span>
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" style={{ animation: 'scrollBounce 1.9s ease-in-out infinite' }}>
        <polyline points="6 9 12 15 18 9"/>
      </svg>
    </div>
  );
}

// CTA banner reused on every page
function CTABanner({ navigate }) {
  return (
    <section className="section-pad-sm">
      <div className="container">
        <Reveal>
          <div style={{
            position: 'relative',
            borderRadius: 36,
            padding: 'clamp(28px, 4vw, 48px) clamp(32px, 5vw, 72px)',
            background: 'linear-gradient(135deg, var(--electric) 0%, var(--deep) 100%)',
            overflow: 'hidden',
            color: '#fff'
          }}>
            <div className="bg-stars-light"></div>
            <div className="bg-glow" style={{ right: -200, top: -200, background: 'radial-gradient(closest-side, rgba(251,220,116,0.4), transparent 70%)' }}></div>
            <div style={{ position: 'relative', display: 'grid', gridTemplateColumns: '1fr auto', gap: 48, alignItems: 'center' }} className="cta-grid">
              <div>
                <div style={{ marginBottom: 16 }}>
                  <span className="eyebrow" style={{ color: 'rgba(255,255,255,0.7)' }}>
                    <span className="pulse" style={{ background: 'var(--yellow)', boxShadow: '0 0 12px var(--yellow)' }}></span>
                    NOUS CONTACTER
                  </span>
                </div>
                <h2 className="display display-l" style={{ margin: 0 }}>
                  Une question ?<br />
                  <span style={{ color: 'var(--yellow)' }}>Un projet ?</span>
                </h2>
              </div>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
                <a href="#contact" onClick={(e) => {e.preventDefault();navigate('contact');}} style={{
                  display: 'inline-flex', alignItems: 'center', gap: 10,
                  padding: '16px 28px', borderRadius: 999,
                  fontFamily: 'var(--f-mono)', fontSize: 13, letterSpacing: '0.1em',
                  textTransform: 'uppercase', fontWeight: 600,
                  background: 'var(--yellow)', color: 'var(--text)',
                  transition: 'transform 200ms, box-shadow 200ms'
                }} onMouseEnter={(e) => {e.currentTarget.style.transform = 'translateY(-2px)';e.currentTarget.style.boxShadow = '0 12px 30px rgba(251,220,116,0.5)';}}
                onMouseLeave={(e) => {e.currentTarget.style.transform = '';e.currentTarget.style.boxShadow = '';}}>
                  Démarrer un projet <svg className="arrow" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M5 12h14M13 5l7 7-7 7" /></svg>
                </a>
                <a href="mailto:b.tenailleau@atelierperf.fr" style={{
                  display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 10,
                  padding: '16px 28px', borderRadius: 999,
                  fontFamily: 'var(--f-mono)', fontSize: 13, letterSpacing: '0.03em',
                  fontWeight: 500,
                  background: 'rgba(255,255,255,0.12)', color: '#fff',
                  border: '1px solid rgba(255,255,255,0.22)'
                }}>
                  b.tenailleau@atelierperf.fr
                </a>
              </div>
            </div>
          </div>
        </Reveal>
      </div>
      <style>{`
        @media (max-width: 760px) {
          .cta-grid { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </section>);

}

// ====== Modal carte — overlay plein écran ======
function CardModal({ id, onClose, navigate }) {
  const data = window.SERVICE_PAGES && window.SERVICE_PAGES[id];
  const svc  = window.SERVICES && window.SERVICES.find(s => s.id === id);
  const ref  = useRef(null);

  // Fermer à Escape
  useEffect(() => {
    function onKey(e) { if (e.key === 'Escape') onClose(); }
    document.addEventListener('keydown', onKey);
    return () => document.removeEventListener('keydown', onKey);
  }, []);

  if (!data) return null;

  return (
    <div
      style={{
        position: 'fixed', inset: 0, zIndex: 500,
        background: 'rgba(6,6,26,0.82)',
        backdropFilter: 'blur(10px)',
        WebkitBackdropFilter: 'blur(10px)',
        display: 'flex', alignItems: 'flex-start', justifyContent: 'center',
        padding: 'clamp(16px, 4vw, 48px)',
        overflowY: 'auto',
        animation: 'modalFadeIn 280ms cubic-bezier(0.2, 0.7, 0.2, 1)',
      }}
    >
      <div
        ref={ref}
        style={{
          background: '#fff', borderRadius: 32,
          width: '100%', maxWidth: 860,
          padding: 'clamp(28px, 5vw, 56px)',
          position: 'relative',
          marginTop: 72,
          animation: 'modalSlideUp 320ms cubic-bezier(0.2, 0.7, 0.2, 1)',
          boxShadow: '0 48px 120px rgba(6,6,26,0.5)',
        }}
      >
        {/* Boutons fermer + en savoir plus */}
        <div style={{ position: 'absolute', top: 20, right: 20, display: 'flex', gap: 8, alignItems: 'center' }}>
          {navigate && id !== 'domaines' && (
            <button onClick={() => { navigate(id); onClose(); }} style={{
              height: 40, borderRadius: 999, padding: '0 18px',
              background: 'var(--electric)', color: '#fff',
              fontFamily: 'var(--f-mono)', fontSize: 11, fontWeight: 600, letterSpacing: '0.1em',
              border: 'none', cursor: 'pointer',
              display: 'flex', alignItems: 'center', gap: 6,
              transition: 'background 200ms, color 200ms',
            }}
            onMouseEnter={(e) => { e.currentTarget.style.background = 'var(--yellow)'; e.currentTarget.style.color = 'var(--text)'; }}
            onMouseLeave={(e) => { e.currentTarget.style.background = 'var(--electric)'; e.currentTarget.style.color = '#fff'; }}>
              En savoir plus
              <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M5 12h14M13 5l7 7-7 7"/></svg>
            </button>
          )}
          <button onClick={onClose} style={{
            width: 40, height: 40, borderRadius: '50%',
            border: '1px solid var(--line-2)', background: 'var(--ink-2)',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            cursor: 'pointer', transition: 'background 200ms',
          }} onMouseEnter={(e) => e.currentTarget.style.background = 'var(--ink-3)'}
             onMouseLeave={(e) => e.currentTarget.style.background = 'var(--ink-2)'}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
          </button>
        </div>

        {/* En-tête */}
        <div style={{ display: 'flex', alignItems: 'baseline', gap: 20, flexWrap: 'wrap', marginBottom: 20 }}>
          <span style={{ fontFamily: 'var(--f-mono)', fontWeight: 700, fontSize: 'clamp(24px, 3.5vw, 40px)', color: 'var(--electric)', letterSpacing: '-0.02em' }}>
            {svc ? svc.num : ''}
          </span>
          <h2 className="display" style={{ fontSize: 'clamp(24px, 3.5vw, 44px)', margin: 0 }}>
            {svc ? svc.title : id}
          </h2>
          {svc && (
            <div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
              {svc.chips.map(c => (
                <span key={c} style={{
                  fontFamily: 'var(--f-mono)', fontSize: 10, letterSpacing: '0.12em',
                  textTransform: 'uppercase', color: 'var(--electric)',
                  padding: '4px 10px', border: '1px solid rgba(94,76,255,0.35)',
                  borderRadius: 999, background: 'rgba(94,76,255,0.06)',
                }}>{c}</span>
              ))}
            </div>
          )}
        </div>

        {/* Intro */}
        <p style={{
          fontSize: 16, color: 'var(--muted)', lineHeight: 1.75,
          margin: '0 0 28px',
          borderLeft: '3px solid var(--electric)', paddingLeft: 18,
        }}>{data.intro}</p>

        {/* Piliers */}
        {data.pillars && (
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 12, marginBottom: 28 }} className="modal-pillars">
            {data.pillars.map((p, i) => (
              <div key={i} style={{
                padding: '14px 18px',
                background: 'rgba(16,30,142,0.03)',
                border: '1px solid var(--line-2)', borderRadius: 14,
              }}>
                <div style={{ fontFamily: 'var(--f-mono)', fontSize: 10, color: 'var(--electric)', letterSpacing: '0.1em', marginBottom: 6 }}>{p.num}</div>
                <div className="display" style={{ fontSize: 16, fontWeight: 700, marginBottom: 4, lineHeight: 1.1 }}>{p.title}</div>
                <div style={{ fontSize: 12, color: 'var(--muted)', lineHeight: 1.55 }}>{p.desc}</div>
              </div>
            ))}
          </div>
        )}

        {/* Stats */}
        {data.ctas && (
          <div style={{ display: 'flex', gap: 10, flexWrap: 'wrap', paddingTop: 20, borderTop: '1px solid var(--line-2)' }}>
            {data.ctas.map((c, i) => (
              <div key={i} style={{
                padding: '10px 20px', background: 'var(--ink-2)',
                border: '1px solid var(--line-2)', borderRadius: 12,
                display: 'flex', flexDirection: 'column',
              }}>
                <span className="display" style={{ fontSize: 22, color: 'var(--deep)', fontWeight: 700, lineHeight: 1 }}>{c.value}</span>
                <span style={{ fontFamily: 'var(--f-mono)', fontSize: 9, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--muted)', marginTop: 4 }}>{c.label}</span>
              </div>
            ))}
            <div style={{ marginLeft: 'auto', display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' }}>
              {data.pdfUrl && (
                <a href={data.pdfUrl} download style={{
                  display: 'inline-flex', alignItems: 'center', gap: 6,
                  fontFamily: 'var(--f-mono)', fontSize: 10, letterSpacing: '0.1em',
                  color: 'var(--electric)', textDecoration: 'none',
                  padding: '6px 14px', border: '1px solid rgba(94,76,255,0.35)',
                  borderRadius: 999, background: 'rgba(94,76,255,0.05)',
                  transition: 'background 200ms',
                }}
                onMouseEnter={(e) => e.currentTarget.style.background = 'rgba(94,76,255,0.12)'}
                onMouseLeave={(e) => e.currentTarget.style.background = 'rgba(94,76,255,0.05)'}>
                  ↓ Flyer PDF
                </a>
              )}
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, fontFamily: 'var(--f-mono)', fontSize: 11, color: 'var(--muted-2)', letterSpacing: '0.1em', textTransform: 'uppercase' }}>
                <span className="pulse" style={{ width: 6, height: 6, background: 'var(--electric)', borderRadius: '50%', boxShadow: '0 0 10px var(--electric)' }}></span>
                Vendée · Pays de la Loire
              </div>
            </div>
          </div>
        )}
      </div>
      <style>{`
        @keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
        @keyframes modalSlideUp { from { opacity: 0; transform: translateY(40px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
        @media (max-width: 680px) { .modal-pillars { grid-template-columns: 1fr !important; } }
        @media (max-width: 960px) { .modal-pillars { grid-template-columns: repeat(2, 1fr) !important; } }
      `}</style>
    </div>
  );
}

function FlashDiagPopup({ navigate }) {
  const [phase, setPhase] = useState('in');

  useEffect(() => {
    if (sessionStorage.getItem('fdp-shown')) { setPhase('gone'); return; }
    sessionStorage.setItem('fdp-shown', '1');
    const t1 = setTimeout(() => setPhase('out'), 2600);
    const t2 = setTimeout(() => setPhase('gone'), 3200);
    return () => { clearTimeout(t1); clearTimeout(t2); };
  }, []);

  if (phase === 'gone') return null;

  const dismiss = () => { setPhase('out'); setTimeout(() => setPhase('gone'), 600); };

  return (
    <div onClick={dismiss} style={{
      position:'fixed', inset:0, zIndex:9999,
      display:'flex', alignItems:'center', justifyContent:'center', padding:24,
      background:'rgba(6,6,26,0.72)', backdropFilter:'blur(5px)',
      animation: phase === 'out' ? 'fdp-out 0.6s ease forwards' : 'fdp-in 0.4s cubic-bezier(.22,1,.36,1)',
    }}>
      <style>{`
        @keyframes fdp-in  { from { opacity:0; transform:scale(0.88) translateY(20px) } to { opacity:1; transform:scale(1) translateY(0) } }
        @keyframes fdp-out { to   { opacity:0; transform:scale(0.94) translateY(10px) } }
        @keyframes fdp-bar { from { transform:scaleX(1) } to { transform:scaleX(0) } }
      `}</style>
      <div onClick={e => e.stopPropagation()} style={{
        maxWidth:480, width:'100%', borderRadius:18,
        background:'linear-gradient(135deg, var(--deep) 0%, var(--electric) 100%)',
        padding:'24px 26px 20px', position:'relative', overflow:'hidden',
        boxShadow:'0 28px 70px rgba(16,30,142,0.45)',
      }}>
        <div style={{ position:'absolute', width:200, height:200, borderRadius:'50%', right:-60, top:-80, background:'radial-gradient(closest-side,rgba(94,76,255,0.45),transparent 70%)', filter:'blur(20px)', pointerEvents:'none' }}/>
        <div style={{ position:'absolute', width:130, height:130, borderRadius:'50%', left:-40, bottom:-50, background:'radial-gradient(closest-side,rgba(251,220,116,0.22),transparent 70%)', filter:'blur(18px)', pointerEvents:'none' }}/>

        <button onClick={dismiss} style={{ position:'absolute', top:12, right:12, background:'rgba(255,255,255,0.12)', border:'none', color:'rgba(255,255,255,0.75)', cursor:'pointer', width:28, height:28, borderRadius:'50%', fontSize:18, display:'flex', alignItems:'center', justifyContent:'center', zIndex:2, lineHeight:1 }}>×</button>

        <div style={{ position:'relative', zIndex:1, display:'inline-flex', alignItems:'center', gap:5, background:'var(--yellow)', color:'var(--ink)', fontFamily:'var(--f-mono)', fontSize:9, fontWeight:700, letterSpacing:'0.16em', textTransform:'uppercase', padding:'4px 12px', borderRadius:999, marginBottom:14 }}>
          <span style={{ width:4, height:4, background:'var(--ink)', borderRadius:'50%', flexShrink:0 }}/>
          OFFRE DÉCOUVERTE
        </div>

        <div style={{ fontFamily:'var(--f-display)', fontWeight:700, fontSize:'clamp(20px,3vw,28px)', lineHeight:1, letterSpacing:'-0.03em', color:'#fff', position:'relative', zIndex:1, marginBottom:10 }}>
          Visite Flash Diag <span style={{ fontStyle:'italic', fontWeight:500, color:'var(--yellow)' }}>offerte</span>
        </div>
        <div style={{ width:30, height:2, background:'rgba(255,255,255,0.22)', marginBottom:14, position:'relative', zIndex:1 }}/>

        <div style={{ display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap:10, position:'relative', zIndex:1, marginBottom:20 }}>
          {[['⏱','1-2h sur site'],['💬','Restitution le jour même'],['✓','Zéro engagement']].map(([icon,t],i) => (
            <div key={i} style={{ display:'flex', flexDirection:'column', alignItems:'center', gap:6, textAlign:'center', fontSize:12, fontWeight:500, color:'rgba(255,255,255,0.9)', lineHeight:1.3 }}>
              <div style={{ width:28, height:28, borderRadius:8, background:'rgba(255,255,255,0.12)', border:'1px solid rgba(255,255,255,0.22)', display:'flex', alignItems:'center', justifyContent:'center', fontSize:13, color:'var(--yellow)' }}>{icon}</div>
              {t}
            </div>
          ))}
        </div>

        <button onClick={() => { dismiss(); navigate('contact'); }} className="btn btn-primary" style={{ position:'relative', zIndex:1, fontSize:14, padding:'12px 24px', width:'100%', justifyContent:'center' }}>
          Demander ma visite gratuite
          <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M5 12h14M13 5l7 7-7 7"/></svg>
        </button>

        <div style={{ position:'absolute', bottom:0, left:0, right:0, height:3, transformOrigin:'left', background:'rgba(255,255,255,0.28)', animation:'fdp-bar 2.6s linear forwards' }}/>
      </div>
    </div>
  );
}

Object.assign(window, { Nav, Footer, useReveal, Reveal, MagCard, Eyebrow, CTABanner, NAV_ITEMS, CardModal, ScrollHint, FlashDiagPopup });

// CSS animation for ScrollHint
(function () {
  var s = document.createElement('style');
  s.textContent = '@keyframes scrollBounce{0%,100%{transform:translateY(0);opacity:0.45}50%{transform:translateY(5px);opacity:1}}';
  document.head.appendChild(s);
})();

// ====== Magnetic button effect (Cyberscope-style) ======
(function () {
  const SELECTORS = '.btn-primary, .nav-cta, .btn-electric';
  const STRENGTH  = 0.28;
  const RADIUS    = 90;

  function applyMagnetic(btn) {
    if (btn._mag) return;
    btn._mag = true;
    btn.style.transition = 'transform 400ms cubic-bezier(0.2, 0.7, 0.2, 1)';

    btn.addEventListener('mousemove', function (e) {
      const r  = btn.getBoundingClientRect();
      const cx = r.left + r.width  / 2;
      const cy = r.top  + r.height / 2;
      const dx = e.clientX - cx;
      const dy = e.clientY - cy;
      const dist = Math.sqrt(dx * dx + dy * dy);
      if (dist < RADIUS) {
        const pull = (1 - dist / RADIUS) * STRENGTH;
        btn.style.transform = `translate(${dx * pull}px, ${dy * pull}px)`;
      }
    });
    btn.addEventListener('mouseleave', function () {
      btn.style.transform = '';
    });
  }

  function scan() {
    document.querySelectorAll(SELECTORS).forEach(applyMagnetic);
  }

  // Apply after React renders
  const mo = new MutationObserver(scan);
  document.addEventListener('DOMContentLoaded', function () {
    scan();
    mo.observe(document.body, { childList: true, subtree: true });
  });
  // Safety net if DOM already ready
  if (document.readyState !== 'loading') {
    scan();
    mo.observe(document.body, { childList: true, subtree: true });
  }
})();