/* ============================================================
   HOME PAGE
   ============================================================ */
function HomeHero() {
  const { nav } = useStore();
  const panels = BB.IMG.hero.panels;

  return (
    <section style={{ position: 'relative', width: '100%', height: '100svh', minHeight: 620, overflow: 'hidden', background: 'var(--cream-deep)' }}>

      {/* ── 4-panel static image grid ─────────────────── */}
      <div style={{ position: 'absolute', inset: 0, display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 3 }}>
        {panels.map((src, i) => (
          <div key={i} style={{ position: 'relative', overflow: 'hidden' }}>
            <Ph src={src} label="" style={{ position: 'absolute', inset: 0, animation: `kenburns ${20 + i * 3}s ease-in-out infinite alternate` }} />
            <div style={{ position: 'absolute', inset: 0, background: 'rgba(43,37,33,.28)' }} />
          </div>
        ))}
      </div>

      {/* ── Gradient overlays for text legibility ───── */}
      <div style={{ position: 'absolute', inset: 0, zIndex: 10, pointerEvents: 'none',
        background: 'radial-gradient(ellipse 90% 70% at 50% 50%, transparent 15%, rgba(43,37,33,.45) 100%)' }} />
      <div style={{ position: 'absolute', inset: 0, zIndex: 11, pointerEvents: 'none',
        background: 'linear-gradient(to bottom, rgba(43,37,33,.55) 0%, rgba(43,37,33,.22) 30%, rgba(43,37,33,.22) 65%, rgba(43,37,33,.62) 100%)' }} />

      {/* ── Content ──────────────────────────────────── */}
      <div style={{
        position: 'absolute', inset: 0, zIndex: 20,
        display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
        padding: 'clamp(90px,10vh,120px) clamp(24px,6vw,80px) clamp(70px,9vh,100px)',
        textAlign: 'center',
        pointerEvents: 'none'
      }}>
        <p style={{
          display: 'inline-flex', alignItems: 'center', gap: 14,
          fontFamily: 'var(--sans)', fontSize: 11, fontWeight: 500, letterSpacing: '.28em', textTransform: 'uppercase',
          color: 'rgba(255,255,255,.78)', marginBottom: 26,
          animation: 'fadeUpHero .9s .35s both'
        }}>
          <span style={{ display: 'block', width: 36, height: 1, background: 'linear-gradient(90deg, transparent, rgba(255,255,255,.6))' }} />
          Handmade to Order &nbsp;&bull;&nbsp; Custom Commissions &nbsp;&bull;&nbsp; Shipped Worldwide
          <span style={{ display: 'block', width: 36, height: 1, background: 'linear-gradient(90deg, rgba(255,255,255,.6), transparent)' }} />
        </p>

        <h1 style={{
          fontFamily: 'var(--serif)', fontWeight: 400, lineHeight: .96,
          fontSize: 'clamp(56px,9vw,132px)',
          letterSpacing: '-.02em', color: '#fff',
          maxWidth: 980, marginBottom: 22,
          animation: 'fadeUpHero 1.1s .7s both'
        }}>
          Made by hand,<br />
          <em style={{ fontStyle: 'italic', color: '#fff' }}>made to last.</em>
        </h1>

        <p style={{ fontSize: 'clamp(15px,1.6vw,19px)', color: 'rgba(255,255,255,.82)', maxWidth: 560, lineHeight: 1.7, marginBottom: 38, animation: 'fadeUpHero 1.1s 1s both' }}>
          {BB.BRAND.blurb}
        </p>

        <div style={{ display: 'flex', gap: 14, flexWrap: 'wrap', justifyContent: 'center', animation: 'fadeUpHero 1.1s 1.2s both', pointerEvents: 'auto' }}>
          <button className="btn btn-gold btn-lg" onClick={() => nav('shop')}>Shop the Collection &nbsp;→</button>
        </div>
      </div>

      <style>{`
        @keyframes kenburns {
          0%   { transform: scale(1.00) translate(0%,0%); }
          100% { transform: scale(1.09) translate(-1.5%,-1%); }
        }
        @keyframes fadeUpHero {
          from { opacity: 0; transform: translateY(28px); }
          to   { opacity: 1; transform: translateY(0); }
        }
      `}</style>
    </section>
  );
}

function TrustStrip() {
  const items = [
    [I.truck, 'Worldwide Shipping', 'Multiple shipping options'],
    [I.shield, 'Secure dual-currency checkout', 'Multiple payment options'],
    [I.gift, '100% handmade', 'Every piece crafted to order'],
  ];
  return (
    <section style={{ borderBottom: '1px solid var(--line)', background: 'var(--ivory)' }}>
      <div className="container wide" style={{ display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems: 'center', gap: 48, flexWrap: 'wrap', padding: '34px var(--gutter)' }}>
        {items.map(([Icon, t, s], i) =>
        <div key={i} style={{ display: 'flex', gap: 14, alignItems: 'center' }}>
            <span style={{ width: 46, height: 46, flexShrink: 0, borderRadius: 100, background: 'var(--cream-deep)', display: 'grid', placeItems: 'center', color: 'var(--gold-deep)' }}>{Icon({ width: 22, height: 22 })}</span>
            <div style={{ lineHeight: 1.25 }}><div style={{ fontWeight: 500, fontSize: 14.5 }}>{t}</div><div style={{ fontSize: 12.5, color: 'var(--ink-soft)' }}>{s}</div></div>
          </div>
        )}
      </div>
    </section>);

}

function FeaturedCategories() {
  const { nav } = useStore();
  return (
    <section className="container wide" style={{ padding: 'clamp(64px,9vw,120px) var(--gutter)' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 16, marginBottom: 40 }}>
        <div>
          <p className="eyebrow">Shop by category</p>
          <h2 style={{ fontSize: 'clamp(34px,5vw,60px)', marginTop: 12 }}>Every detail, <em style={{ fontStyle: 'italic' }}>handmade</em></h2>
        </div>
        <button className="link-u" style={{ fontSize: 14 }} onClick={() => nav('shop')}>View all →</button>
      </div>
      <div className="cat-grid">
        {BB.categories.map((c, i) =>
        i === 5 ? null : (
        <Reveal key={c.id} delay={i % 3 + 1} className={`cat-tile ${i === 0 ? 'cat-feature' : ''}`} onClick={() => nav('shop', { cat: c.id })} style={{ cursor: 'pointer' }}>
            <Ph label={c.name} src={IMG.cats[c.id]} variant={c.tag} style={{ height: '100%', minHeight: 200, borderRadius: 'var(--r-lg)' }} />
            <div style={{ position: 'absolute', inset: 0, borderRadius: 'var(--r-lg)', background: 'linear-gradient(to top, rgba(43,37,33,.88) 0%, rgba(43,37,33,.5) 45%, transparent 70%)', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', padding: 22, color: 'var(--cream)' }}>
              <h3 style={{ fontSize: i === 0 ? 34 : 25, color: 'var(--cream)' }}>{c.name}</h3>
              {i === 0 && <p style={{ fontSize: 14.5, color: 'rgba(251,249,245,.85)', marginTop: 6, maxWidth: 360 }}>{c.blurb}</p>}
              <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7, fontSize: 12.5, letterSpacing: '.1em', textTransform: 'uppercase', marginTop: 12, color: 'var(--gold-soft)' }}>Shop now <I.arrow width={15} height={15} /></span>
            </div>
          </Reveal>
        )
        )}
      </div>
    </section>);

}

function Bestsellers() {
  const { nav } = useStore();
  const [tab, setTab] = useState('best');
  const list = BB.products.filter((p) => tab === 'best' ? p.tags.includes('best') : p.tags.includes('new')).slice(0, 4);
  return (
    <section style={{ background: 'var(--cream-deep)' }}>
      <div className="container wide" style={{ padding: 'clamp(64px,9vw,120px) var(--gutter)' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 18, marginBottom: 42 }}>
          <h2 style={{ fontSize: 'clamp(34px,5vw,60px)' }}>Loved <em style={{ fontStyle: 'italic' }}>again and again</em></h2>
          <div style={{ display: 'flex', gap: 8 }}>
            <button className={`chip ${tab === 'best' ? 'active' : ''}`} onClick={() => setTab('best')}>Bestsellers</button>
            <button className={`chip ${tab === 'new' ? 'active' : ''}`} onClick={() => setTab('new')}>New in</button>
          </div>
        </div>
        <div className="prod-grid">
          {list.map((p, i) => <ProductCard key={p.id} p={p} delay={i % 4 + 1} />)}
        </div>
        <div style={{ textAlign: 'center', marginTop: 48 }}>
          <button className="btn btn-outline btn-lg" onClick={() => nav('shop')}>Shop everything</button>
        </div>
      </div>
    </section>);

}

function EditorialSplit() {
  const { nav } = useStore();
  return (
    <section className="container wide" style={{ padding: 'clamp(64px,9vw,120px) var(--gutter)' }}>
      <div className="edit-split" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 'clamp(28px,5vw,72px)', alignItems: 'center' }}>
        <Reveal style={{ position: 'relative' }}>
          <Ph label="Behind the scenes in our studio" src={IMG.about.founder} variant="ph-gold" style={{ aspectRatio: '5/6', borderRadius: 'var(--r-xl)' }} />
          <div style={{ position: 'absolute', bottom: 24, right: -20, background: 'var(--ivory)', padding: '18px 22px', borderRadius: 'var(--r-md)', boxShadow: 'var(--shadow-md)', maxWidth: 230 }}>
            <p style={{ fontFamily: 'var(--serif)', fontStyle: 'italic', fontSize: 19, lineHeight: 1.35 }}>"Every little detail should feel intentional."</p>
            <p style={{ fontSize: 11, color: 'var(--ink-soft)', marginTop: 12, letterSpacing: '.12em' }}>— THE STUDIO TEAM</p>
          </div>
        </Reveal>
        <Reveal delay={2}>
          <p className="eyebrow">Made by hand</p>
          <h2 style={{ fontSize: 'clamp(32px,4.5vw,54px)', margin: '14px 0 20px' }}>Pieces made to be <em style={{ fontStyle: 'italic' }}>lived with</em></h2>
          <p style={{ fontSize: 16.5, color: 'var(--ink-soft)', lineHeight: 1.7, marginBottom: 18 }}>
            We started with a simple vision — that everyday objects deserve real craft. Today we design and hand-make candles, ceramics, textiles, stationery and leather goods, shipped worldwide.
          </p>
          <ul style={{ listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 12, marginBottom: 30 }}>
            {['100% handmade, made to order', 'Fully custom commissions — any colour, any scale', 'Carefully packed and shipped worldwide'].map((t) =>
            <li key={t} style={{ display: 'flex', gap: 12, alignItems: 'center', fontSize: 15.5 }}>
                <span style={{ width: 26, height: 26, borderRadius: 100, background: 'var(--sage-soft)', color: 'var(--sage-deep)', display: 'grid', placeItems: 'center', flexShrink: 0 }}><I.check width={15} height={15} /></span>{t}
              </li>
            )}
          </ul>
          <button className="btn btn-primary" onClick={() => nav('about')}>Our story</button>
        </Reveal>
      </div>
    </section>);

}

/* ── Bespoke entry point ─────────────────────────────────── */
function BespokeSection() {
  const { nav } = useStore();
  return (
    <section style={{ background: 'var(--cream-deep)', padding: 'clamp(64px,9vw,110px) var(--gutter)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
      <div className="container wide">
        <div style={{ textAlign: 'center', marginBottom: 48 }}>
          <p className="eyebrow">Beyond the catalogue</p>
          <h2 style={{ fontSize: 'clamp(36px,5.5vw,66px)', marginTop: 12 }}>
            Built exactly <em style={{ fontStyle: 'italic' }}>for you.</em>
          </h2>
          <p style={{ fontSize: 16, color: 'var(--ink-soft)', maxWidth: 520, margin: '14px auto 0', lineHeight: 1.75 }}>
            Choose a ready-made package or start a bespoke commission — either way, we build it around your vision.
          </p>
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20 }}>
          {/* Packages card */}
          <Reveal delay={1}>
            <div
              onClick={() => nav('packages')}
              style={{ background: 'var(--ivory)', border: '1px solid var(--line)', borderRadius: 'var(--r-xl)', padding: 'clamp(28px,4vw,48px)', cursor: 'pointer', transition: 'transform .4s cubic-bezier(.2,.8,.2,1), box-shadow .4s', display: 'flex', flexDirection: 'column', gap: 18 }}
              onMouseEnter={e => { e.currentTarget.style.transform='translateY(-5px)'; e.currentTarget.style.boxShadow='var(--shadow-lg)'; }}
              onMouseLeave={e => { e.currentTarget.style.transform='none'; e.currentTarget.style.boxShadow='none'; }}>
              <div style={{ width: 52, height: 52, borderRadius: 'var(--r-md)', background: 'var(--gold-soft)', display: 'grid', placeItems: 'center', color: 'var(--gold-deep)' }}>
                <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M4 11h16v9H4zM4 8h16v3H4zM12 8v12M12 8c-1-3-5-3-5-1s4 1 5 1Zm0 0c1-3 5-3 5-1s-4 1-5 1Z" strokeLinejoin="round"/></svg>
              </div>
              <div>
                <p style={{ fontSize: 11, letterSpacing: '.2em', textTransform: 'uppercase', color: 'var(--gold-deep)', marginBottom: 8, fontWeight: 500 }}>Packages</p>
                <h3 style={{ fontSize: 'clamp(24px,3vw,36px)', color: 'var(--ink)', marginBottom: 10, lineHeight: 1.1 }}>Fixed price,<br/><em style={{ fontStyle: 'italic' }}>clear deliverables.</em></h3>
                <p style={{ fontSize: 15, color: 'var(--ink-soft)', lineHeight: 1.7 }}>Three pre-configured packages. Pick a tier, tell us your preferences, and we handle the rest.</p>
              </div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 'auto' }}>
                <span style={{ fontSize: 12, letterSpacing: '.12em', textTransform: 'uppercase', color: 'var(--ink-soft)', fontWeight: 500 }}>View packages</span>
                <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="var(--ink-soft)" strokeWidth="2"><path d="M5 12h14M13 6l6 6-6 6" strokeLinecap="round" strokeLinejoin="round"/></svg>
              </div>
            </div>
          </Reveal>

          {/* Custom Order card */}
          <Reveal delay={2}>
            <div
              onClick={() => nav('custom-order')}
              style={{ background: 'var(--ink)', border: '1px solid var(--ink)', borderRadius: 'var(--r-xl)', padding: 'clamp(28px,4vw,48px)', cursor: 'pointer', transition: 'transform .4s cubic-bezier(.2,.8,.2,1)', display: 'flex', flexDirection: 'column', gap: 18 }}
              onMouseEnter={e => { e.currentTarget.style.transform='translateY(-5px)'; }}
              onMouseLeave={e => { e.currentTarget.style.transform='none'; }}>
              <div style={{ width: 52, height: 52, borderRadius: 'var(--r-md)', background: 'linear-gradient(135deg,var(--gold-deep),var(--gold))', display: 'grid', placeItems: 'center', color: '#fff' }}>
                <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="m18.5 2.5 3 3L12 15l-4 1 1-4 9.5-9.5Z"/></svg>
              </div>
              <div>
                <p style={{ fontSize: 11, letterSpacing: '.2em', textTransform: 'uppercase', color: 'rgba(255,255,255,.5)', marginBottom: 8, fontWeight: 500 }}>Custom Order</p>
                <h3 style={{ fontSize: 'clamp(24px,3vw,36px)', color: '#fff', marginBottom: 10, lineHeight: 1.1 }}>Your vision,<br/><em style={{ fontStyle: 'italic' }}>priced to match.</em></h3>
                <p style={{ fontSize: 15, color: 'rgba(255,255,255,.62)', lineHeight: 1.7 }}>Have something specific in mind? Submit a brief — text, links, images — and we'll quote you personally.</p>
              </div>
              <div style={{ display: 'flex', gap: 10, marginTop: 4, flexWrap: 'wrap' }}>
                {['Any scale','48h quote'].map(t => (
                  <div key={t} style={{ background: 'rgba(255,255,255,.1)', borderRadius: 100, padding: '6px 14px', fontSize: 12, color: 'rgba(255,255,255,.7)', fontWeight: 500 }}>{t}</div>
                ))}
              </div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 'auto' }}>
                <span style={{ fontSize: 12, letterSpacing: '.12em', textTransform: 'uppercase', color: 'rgba(255,255,255,.5)', fontWeight: 500 }}>Start a brief</span>
                <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,.5)" strokeWidth="2"><path d="M5 12h14M13 6l6 6-6 6" strokeLinecap="round" strokeLinejoin="round"/></svg>
              </div>
            </div>
          </Reveal>
        </div>

        {/* Booking CTA */}
        <div style={{ marginTop: 20, border: '1px solid var(--line)', background: 'var(--ivory)', borderRadius: 'var(--r-lg)', padding: '20px 28px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 16 }}>
          <div>
            <p style={{ fontSize: 15, color: 'var(--ink-soft)', lineHeight: 1.6 }}>Not sure where to start? <strong style={{ color: 'var(--ink)' }}>Book a free 30-minute call</strong> — we'll recommend the right option.</p>
          </div>
          <button className="btn btn-outline" onClick={() => nav('booking')}>Book a free call</button>
        </div>
      </div>
    </section>
  );
}


function Testimonials() {
  const [i, setI] = useState(0);
  const t = BB.testimonials;
  useEffect(() => { const id = setInterval(() => setI((p) => (p + 1) % t.length), 5500); return () => clearInterval(id); }, []);
  return (
    <section style={{ background: 'linear-gradient(160deg, var(--sage-soft), var(--cream))' }}>
      <div className="container" style={{ padding: 'clamp(64px,9vw,120px) var(--gutter)', textAlign: 'center', maxWidth: 860 }}>
        <p className="eyebrow">What customers say</p>
        <div style={{ position: 'relative', minHeight: 220, marginTop: 24 }}>
          {t.map((item, idx) =>
          <blockquote key={idx} style={{ position: idx === i ? 'relative' : 'absolute', inset: 0, opacity: idx === i ? 1 : 0, transition: 'opacity .7s', pointerEvents: idx === i ? 'auto' : 'none' }}>
              <p style={{ fontFamily: 'var(--serif)', fontSize: 'clamp(22px,3.5vw,38px)', lineHeight: 1.35, fontStyle: 'italic' }}>"{item.quote}"</p>
              <div style={{ marginTop: 26, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 8 }}>
                <Stars value={5} size={16} />
                <div style={{ fontWeight: 600, fontSize: 15 }}>{item.name}</div>
                <div style={{ fontSize: 13, color: 'var(--ink-soft)' }}>{item.role}</div>
              </div>
            </blockquote>
          )}
        </div>
        <div style={{ display: 'flex', gap: 8, justifyContent: 'center', marginTop: 30 }}>
          {t.map((_, idx) => <button key={idx} onClick={() => setI(idx)} aria-label={`Testimonial ${idx + 1}`} style={{ width: idx === i ? 28 : 9, height: 9, borderRadius: 100, background: idx === i ? 'var(--gold)' : 'var(--line)', transition: 'all .4s' }} />)}
        </div>
      </div>
    </section>);

}

function SocialSection() {
  return (
    <section className="container wide" style={{ padding: 'clamp(56px,8vw,100px) var(--gutter)' }}>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 'clamp(32px,5vw,72px)', alignItems: 'center' }}>
        <div>
          <p className="eyebrow">{BB.BRAND.social}</p>
          <h2 style={{ fontSize: 'clamp(30px,4.5vw,52px)', margin: '14px 0 16px' }}>See the process <em style={{ fontStyle: 'italic' }}>behind every piece</em></h2>
          <p style={{ fontSize: 16, color: 'var(--ink-soft)', lineHeight: 1.7, marginBottom: 28 }}>
            Behind-the-scenes process, studio life and new arrivals on our social channels — updated weekly.
          </p>
          <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
            <a href="#" className="btn btn-primary">
              <I.tiktok width={17} height={17} /> Follow on TikTok
            </a>
            <a href="#" className="btn btn-outline"><I.ig width={17} height={17} /> Instagram</a>
          </div>
        </div>
        <div className="social-grid">
          {IMG.social.map((src, i) =>
          <Reveal key={i} delay={i % 3 + 1} style={{ position: 'relative' }} className="social-tile">
              <Ph label="studio" src={src} style={{ aspectRatio: '1', borderRadius: 'var(--r-md)' }} />
              <div className="social-ov" style={{ position: 'absolute', inset: 0, background: 'rgba(140,74,44,.48)', borderRadius: 'var(--r-md)', display: 'grid', placeItems: 'center', opacity: 0, transition: 'opacity .35s' }}>
                <I.ig width={26} height={26} style={{ color: 'var(--cream)' }} />
              </div>
            </Reveal>
          )}
        </div>
      </div>
    </section>);

}

function HomePage() {
  return (
    <>
      <HomeHero />
      <TrustStrip />
      <FeaturedCategories />
      <Bestsellers />
      <EditorialSplit />
      <BespokeSection />
      <Testimonials />
      <SocialSection />
      <Newsletter />
    </>);

}

Object.assign(window, { HomePage });
