/* A&M Kits — Components (hero, how-it-works, kits grid, drawer) */
const { useState, useEffect, useRef, useMemo } = React;

/* ─── HELPERS ─────────────────────────────────────────────────────────────── */
function DomainDot({ domain, size = 8 }) {
  const c = window.domainColor(domain);
  return <span style={{ width:size, height:size, borderRadius:'50%', background:c, display:'inline-block', flexShrink:0 }} />;
}

function SkillPill({ domain, label, onClick, active, dense }) {
  const c = window.domainColor(domain);
  return (
    <button onClick={onClick} style={{
      border:'none', cursor: onClick ? 'pointer' : 'default',
      background: active ? c : `${c}14`,
      color: active ? '#fff' : c,
      padding: dense ? '4px 10px' : '5px 12px',
      borderRadius:100, fontSize:12, fontWeight:600,
      fontFamily:'Plus Jakarta Sans', whiteSpace:'nowrap',
      letterSpacing:'-0.005em', lineHeight:1.3,
      transition:'all 0.15s ease',
    }}>{label}</button>
  );
}

function DomainGlyph({ domain }) {
  const c = window.domainColor(domain);
  const d = window.DOMAINS.find(x => x.id === domain);
  return (
    <span style={{ color:c, fontSize:14, lineHeight:1 }}>{d?.glyph || '◆'}</span>
  );
}

/* ─── TOAST ───────────────────────────────────────────────────────────────── */
function KitsToast({ msg, onDone }) {
  useEffect(() => {
    if (!msg) return;
    const t = setTimeout(onDone, 2600);
    return () => clearTimeout(t);
  }, [msg]);
  return (
    <div aria-live="polite" style={{
      position:'fixed', top:90, left:'50%', zIndex:300,
      transform: msg ? 'translate(-50%, 0)' : 'translate(-50%, -20px)',
      opacity: msg ? 1 : 0, pointerEvents:'none',
      transition:'all 0.3s cubic-bezier(0.16,1,0.3,1)',
    }}>
      {msg && (
        <div style={{
          background:'#1A1614', color:'#FDFCF8',
          padding:'14px 22px', borderRadius:100,
          fontFamily:'Plus Jakarta Sans', fontWeight:500, fontSize:14,
          boxShadow:'0 20px 48px -12px rgba(26,22,20,0.4)',
          display:'inline-flex', alignItems:'center', gap:10, whiteSpace:'nowrap', maxWidth:'90vw',
        }}>
          <span style={{ width:7, height:7, borderRadius:'50%', background:'#1D9E75' }}/>
          {msg}
        </div>
      )}
    </div>
  );
}

const KITS_WA = 'https://wa.me/919456815951?text=Hi%20I%20want%20to%20explore%20A%26M%20skill%20kits';

/* ─── NAV ─────────────────────────────────────────────────────────────────── */
function Nav() {
  const [scrolled, setScrolled] = useState(false);
  const [mobileOpen, setMobileOpen] = useState(false);

  useEffect(() => {
    const fn = () => setScrolled(window.scrollY > 30);
    window.addEventListener('scroll', fn);
    return () => window.removeEventListener('scroll', fn);
  }, []);

  useEffect(() => {
    if (mobileOpen) {
      const prev = document.body.style.overflow;
      document.body.style.overflow = 'hidden';
      return () => { document.body.style.overflow = prev; };
    }
  }, [mobileOpen]);

  const scrollToTop = () => window.scrollTo({ top:0, behavior:'smooth' });
  const scrollToSection = (id) => {
    const el = document.getElementById(id);
    if (!el) return;
    const top = el.getBoundingClientRect().top + window.scrollY - 68;
    window.scrollTo({ top, behavior:'smooth' });
  };

  const LINKS = [
    { id:'home',   label:'Home',         active:true,  onClick: scrollToTop },
    { id:'kits',   label:'Kits',         active:false, onClick: () => scrollToSection('kits') },
    { id:'skills', label:'Skills Guide', active:false, href: 'skills-guide.html' },
    { id:'about',  label:'About',        active:false, href: 'about.html' },
  ];

  const linkStyle = (on) => ({
    color: on ? '#1A1614' : '#534B45',
    fontSize:14, fontWeight: on ? 700 : 500,
    fontFamily:'Plus Jakarta Sans',
    background:'transparent', border:'none', cursor:'pointer',
    padding:'4px 0',
    borderBottom: on ? '1.5px solid #C45B3A' : '1.5px solid transparent',
    transition:'color 0.18s',
  });

  return (
    <>
      <nav style={{
        position:'fixed', top:0, left:0, right:0, zIndex:100,
        padding:'0 clamp(20px,4vw,52px)', height:68,
        display:'flex', alignItems:'center', justifyContent:'space-between',
        background: scrolled ? 'rgba(253,252,248,0.92)' : 'transparent',
        backdropFilter: scrolled ? 'blur(14px) saturate(1.3)' : 'none',
        WebkitBackdropFilter: scrolled ? 'blur(14px) saturate(1.3)' : 'none',
        borderBottom: scrolled ? '1px solid rgba(26,22,20,0.06)' : '1px solid transparent',
        boxShadow: scrolled ? '0 1px 0 rgba(26,22,20,0.02)' : 'none',
        transition:'all 0.3s ease',
      }}>
        <button onClick={scrollToTop} aria-label="A&M World — top of page" style={{ background:'transparent', border:'none', cursor:'pointer', padding:0, display:'flex', alignItems:'center', gap:10 }}>
          <span style={{ width:30, height:30, borderRadius:'50%', background:'#1A1614', color:'#FDFCF8', display:'grid', placeItems:'center', fontFamily:'Instrument Serif', fontSize:18, lineHeight:1, paddingBottom:2 }}>A</span>
          <span style={{ fontFamily:'Plus Jakarta Sans', fontWeight:700, fontSize:15, letterSpacing:'-0.02em', color:'#1A1614' }}>A&amp;M <span style={{ fontWeight:400, fontStyle:'italic', fontFamily:'Instrument Serif', fontSize:18 }}>world</span></span>
        </button>

        <div className="am-nav-desktop" style={{ display:'flex', alignItems:'center', gap:30 }}>
          {LINKS.map(l => (
            l.href
              ? <a key={l.id} href={l.href} style={linkStyle(l.active)}
                  onMouseEnter={e => { if (!l.active) e.currentTarget.style.color = '#1A1614'; }}
                  onMouseLeave={e => { if (!l.active) e.currentTarget.style.color = '#534B45'; }}
                >{l.label}</a>
              : <button key={l.id} onClick={l.onClick} style={linkStyle(l.active)}
                  onMouseEnter={e => { if (!l.active) e.currentTarget.style.color = '#1A1614'; }}
                  onMouseLeave={e => { if (!l.active) e.currentTarget.style.color = '#534B45'; }}
                >{l.label}</button>
          ))}
          <a href={KITS_WA} target="_blank" rel="noopener" style={{
            background:'#1A1614', color:'#FDFCF8',
            padding:'10px 18px', borderRadius:100,
            fontSize:13, fontWeight:600, fontFamily:'Plus Jakarta Sans',
            display:'inline-flex', alignItems:'center', gap:6, whiteSpace:'nowrap',
          }}>Order on WhatsApp <span aria-hidden>→</span></a>
        </div>

        {/* Mobile hamburger */}
        <button className="am-nav-mobile-toggle" onClick={()=>setMobileOpen(o=>!o)} aria-label="Menu" style={{
          display:'none', background:'transparent', border:'none', cursor:'pointer',
          width:36, height:36, padding:0, position:'relative',
        }}>
          <span style={{ position:'absolute', left:8, right:8, height:1.5, background:'#1A1A1A', top: mobileOpen ? 17.25 : 12, transform: mobileOpen ? 'rotate(45deg)' : 'none', transition:'all 0.2s' }}/>
          <span style={{ position:'absolute', left:8, right:8, height:1.5, background:'#1A1A1A', top:17.25, opacity: mobileOpen ? 0 : 1, transition:'opacity 0.2s' }}/>
          <span style={{ position:'absolute', left:8, right:8, height:1.5, background:'#1A1A1A', top: mobileOpen ? 17.25 : 22.5, transform: mobileOpen ? 'rotate(-45deg)' : 'none', transition:'all 0.2s' }}/>
        </button>
      </nav>

      {/* Mobile menu */}
      {mobileOpen && (
        <div onClick={()=>setMobileOpen(false)} style={{
          position:'fixed', inset:'68px 0 0 0', zIndex:99,
          background:'rgba(253,252,248,0.98)', backdropFilter:'blur(10px)',
          padding:'40px clamp(20px,4vw,52px)',
          animation:'fadeIn 0.2s ease',
        }}>
          <nav style={{ display:'flex', flexDirection:'column', gap:6 }} onClick={e=>e.stopPropagation()}>
            {LINKS.map(l => (
              l.href
                ? <a key={l.id} href={l.href} style={{ fontFamily:'Instrument Serif', fontSize:36, lineHeight:1.2, color: l.active ? '#C45B3A' : '#1A1A1A', fontStyle: l.active ? 'italic' : 'normal', padding:'12px 0', borderBottom:'1px solid rgba(26,26,26,0.08)' }}>{l.label}</a>
                : <button key={l.id} onClick={()=>{ l.onClick && l.onClick(); setMobileOpen(false); }} style={{ fontFamily:'Instrument Serif', fontSize:36, lineHeight:1.2, color: l.active ? '#C45B3A' : '#1A1A1A', fontStyle: l.active ? 'italic' : 'normal', padding:'12px 0', borderBottom:'1px solid rgba(26,26,26,0.08)', background:'transparent', border:'none', borderBottom:'1px solid rgba(26,26,26,0.08)', cursor:'pointer', textAlign:'left', width:'100%' }}>{l.label}</button>
            ))}
            <a href={KITS_WA} target="_blank" rel="noopener" style={{
              marginTop:24, background:'#1A1A1A', color:'#FDFCF8',
              padding:'16px 24px', borderRadius:100, textAlign:'center',
              fontFamily:'Plus Jakarta Sans', fontWeight:600, fontSize:15,
            }}>Order on WhatsApp →</a>
          </nav>
        </div>
      )}
    </>
  );
}

/* ─── HERO ────────────────────────────────────────────────────────────────── */
function Hero() {
  const stats = [
    { n:'28',  l:'products'           },
    { n:'10',  l:'skill kits'         },
    { n:'9',   l:'developmental domains' },
    { n:'0–12',l:'ages covered'       },
  ];
  return (
    <section style={{ padding:'140px clamp(20px,4vw,52px) 60px', position:'relative', overflow:'hidden' }}>
      {/* decorative dots */}
      <div aria-hidden style={{ position:'absolute', inset:0, backgroundImage:'radial-gradient(rgba(26,22,20,0.05) 1px, transparent 1px)', backgroundSize:'28px 28px', maskImage:'radial-gradient(ellipse 70% 60% at 70% 40%, #000 30%, transparent 80%)', WebkitMaskImage:'radial-gradient(ellipse 70% 60% at 70% 40%, #000 30%, transparent 80%)', pointerEvents:'none' }}/>

      <div style={{ maxWidth:1240, margin:'0 auto', position:'relative' }}>
        <div style={{ display:'inline-flex', alignItems:'center', gap:10, padding:'7px 14px', borderRadius:100, border:'1px solid rgba(26,22,20,0.12)', background:'rgba(255,255,255,0.6)', marginBottom:36, fontSize:12, fontWeight:600, color:'#534B45', fontFamily:'Plus Jakarta Sans', letterSpacing:'0.02em' }}>
          <span style={{ width:7, height:7, borderRadius:'50%', background:'#1D9E75' }}/>
          A&amp;M World · for better moments
        </div>

        <h1 style={{
          fontFamily:'Instrument Serif',
          fontSize:'clamp(54px, 8.5vw, 132px)',
          lineHeight:0.95, letterSpacing:'-0.025em',
          color:'#1A1614', fontWeight:400, marginBottom:32,
          maxWidth:1100,
        }}>
          Every toy <em style={{ fontStyle:'italic', color:'#D85A30' }}>builds</em> a&nbsp;skill.
        </h1>

        <p style={{
          fontFamily:'Plus Jakarta Sans', fontSize:'clamp(17px, 1.7vw, 21px)',
          color:'#534B45', lineHeight:1.55, maxWidth:640,
          marginBottom:44, fontWeight:400,
        }}>
          We don't sell toys — we sell skill-building <em style={{ fontFamily:'Instrument Serif', fontSize:'1.12em', fontStyle:'italic', color:'#1A1614' }}>systems</em>.
          Each kit is engineered to develop the specific cognitive, motor, and
          social-emotional skills your child needs.
        </p>

        <div style={{ display:'flex', gap:12, flexWrap:'wrap', marginBottom:72 }}>
          <a href="#kits" style={{
            background:'#1A1614', color:'#FDFCF8',
            padding:'15px 28px', borderRadius:100,
            fontSize:15, fontWeight:600, fontFamily:'Plus Jakarta Sans',
            display:'inline-flex', alignItems:'center', gap:10,
          }}>Explore Kits <span aria-hidden style={{ fontSize:16 }}>→</span></a>
          <a href="#products" style={{
            background:'transparent', color:'#1A1614',
            border:'1px solid rgba(26,22,20,0.18)',
            padding:'15px 28px', borderRadius:100,
            fontSize:15, fontWeight:600, fontFamily:'Plus Jakarta Sans',
          }}>Shop by Skill</a>
        </div>

        {/* Stats strip */}
        <div style={{ display:'grid', gridTemplateColumns:'repeat(auto-fit, minmax(180px,1fr))', gap:0, borderTop:'1px solid rgba(26,22,20,0.1)', borderBottom:'1px solid rgba(26,22,20,0.1)' }}>
          {stats.map((s,i) => (
            <div key={i} style={{ padding:'24px 24px 24px 0', borderRight: i<stats.length-1 ? '1px solid rgba(26,22,20,0.1)' : 'none', paddingLeft: i>0 ? 24 : 0 }}>
              <div style={{ fontFamily:'Instrument Serif', fontSize:48, fontWeight:400, lineHeight:1, color:'#1A1614', letterSpacing:'-0.02em' }}>{s.n}</div>
              <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:13, color:'#7A6F68', marginTop:8, fontWeight:500 }}>{s.l}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ─── HOW IT WORKS ────────────────────────────────────────────────────────── */
function HowItWorks() {
  const steps = [
    { n:'01', t:'Understand the skill', b:"Every child develops 178 skills from birth to age 13 — motor, cognitive, emotional, creative. Our Skills Guide helps you understand which ones matter at your child's age." },
    { n:'02', t:'Choose the right kit', b:'Each kit bundles 3–5 wooden toys that develop a specific skill from different angles — like a workout programme for the brain. One toy starts a skill. A kit builds it.' },
    { n:'03', t:'Watch them grow',      b:'The skills are embedded in the play mechanic. Your child develops hand-eye coordination, logical reasoning, or emotional intelligence naturally — while having fun.' },
  ];
  return (
    <section id="how-it-works" style={{ padding:'90px clamp(20px,4vw,52px)', borderTop:'1px solid rgba(26,22,20,0.08)' }}>
      <div style={{ maxWidth:1240, margin:'0 auto' }}>
        <div style={{ display:'flex', alignItems:'baseline', gap:14, marginBottom:48 }}>
          <span style={{ display:'inline-flex', alignItems:'center', gap:8, fontFamily:'Plus Jakarta Sans', fontSize:12, color:'#7A6F68', textTransform:'uppercase', letterSpacing:'0.12em', fontWeight:600 }}>
            <span style={{ width:7, height:7, borderRadius:'50%', background:'#1D9E75' }}/>
            How it works
          </span>
          <span style={{ flex:1, height:1, background:'rgba(26,22,20,0.1)' }}/>
        </div>

        <h2 style={{ fontFamily:'Instrument Serif', fontWeight:400, fontSize:'clamp(36px,4.6vw,60px)', letterSpacing:'-0.025em', lineHeight:1.02, color:'#1A1614', marginBottom:48, maxWidth:900 }}>
          Skills <em style={{ color:'#D85A30', fontStyle:'italic' }}>first</em>. Toys second.
        </h2>

        <div className="how-grid" style={{ display:'grid', gridTemplateColumns:'repeat(3, 1fr)', gap:24 }}>
          {steps.map((s, i) => (
            <div key={i} style={{
              background:'#fff', borderRadius:24,
              border:'1px solid rgba(26,22,20,0.08)',
              padding:'32px 28px',
              boxShadow:'0 1px 2px rgba(26,22,20,0.03)',
            }}>
              <div style={{ display:'inline-flex', alignItems:'center', justifyContent:'center', width:44, height:44, borderRadius:'50%', background:'#FDFCF8', border:'1px solid rgba(26,22,20,0.1)', fontFamily:'Instrument Serif', fontSize:18, fontStyle:'italic', color:'#D85A30', marginBottom:22 }}>{s.n}</div>
              <h3 style={{ fontFamily:'Instrument Serif', fontSize:'clamp(26px,2.5vw,32px)', fontWeight:400, letterSpacing:'-0.018em', color:'#1A1614', marginBottom:14, lineHeight:1.1 }}>{s.t}</h3>
              <p style={{ fontFamily:'Plus Jakarta Sans', fontSize:14.5, color:'#534B45', lineHeight:1.6 }}>{s.b}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ─── FILTER BAR (sticky) ─────────────────────────────────────────────────── */
function FilterBar({ activeDomains, toggleDomain, ageBucket, setAgeBucket, kitCount, productCount }) {
  return (
    <div id="filter-bar" style={{
      position:'sticky', top:0, zIndex:50,
      background:'rgba(253,252,248,0.94)', backdropFilter:'blur(12px) saturate(1.3)',
      borderTop:'1px solid rgba(26,22,20,0.08)',
      borderBottom:'1px solid rgba(26,22,20,0.08)',
      padding:'14px clamp(20px,4vw,52px)',
    }}>
      <div style={{ maxWidth:1240, margin:'0 auto', display:'flex', flexDirection:'column', gap:12 }}>
        {/* row 1 — counts + age */}
        <div style={{ display:'flex', justifyContent:'space-between', alignItems:'center', gap:12, flexWrap:'wrap' }}>
          <div style={{ display:'flex', gap:14, alignItems:'center', fontFamily:'Plus Jakarta Sans', fontSize:13, color:'#534B45' }}>
            <a href="#kits" style={{ display:'inline-flex', alignItems:'center', gap:6, fontWeight:600 }}>
              Kits <span style={{ opacity:0.55, fontVariantNumeric:'tabular-nums' }}>{kitCount}</span>
            </a>
            <span style={{ opacity:0.3 }}>·</span>
            <a href="#products" style={{ display:'inline-flex', alignItems:'center', gap:6, fontWeight:600 }}>
              Products <span style={{ opacity:0.55, fontVariantNumeric:'tabular-nums' }}>{productCount}</span>
            </a>
          </div>
          <div style={{ display:'flex', gap:6, alignItems:'center', flexWrap:'wrap' }}>
            <span style={{ fontFamily:'Plus Jakarta Sans', fontSize:12, color:'#7A6F68', fontWeight:600, marginRight:4 }}>Age</span>
            {[null, ...window.AGE_BUCKETS.map(a=>a.id)].map(a => (
              <button key={a||'all'} onClick={()=>setAgeBucket(a)} style={{
                border:'1px solid '+(ageBucket===a ? '#1A1614' : 'rgba(26,22,20,0.14)'),
                background: ageBucket===a ? '#1A1614' : 'transparent',
                color: ageBucket===a ? '#FDFCF8' : '#534B45',
                padding:'5px 12px', borderRadius:100, cursor:'pointer',
                fontSize:12, fontWeight:600, fontFamily:'Plus Jakarta Sans',
                transition:'all 0.15s',
              }}>{a || 'All'}</button>
            ))}
          </div>
        </div>
        {/* row 2 — domain pills */}
        <div style={{ display:'flex', gap:6, overflowX:'auto', paddingBottom:2 }} className="no-scrollbar">
          <button onClick={()=>toggleDomain('__clear__')} style={{
            border:'1px solid '+(activeDomains.size===0 ? '#1A1614' : 'rgba(26,22,20,0.14)'),
            background: activeDomains.size===0 ? '#1A1614' : 'transparent',
            color: activeDomains.size===0 ? '#FDFCF8' : '#534B45',
            padding:'6px 14px', borderRadius:100, cursor:'pointer',
            fontSize:13, fontWeight:600, fontFamily:'Plus Jakarta Sans',
            whiteSpace:'nowrap', transition:'all 0.15s',
          }}>All skills</button>
          {window.DOMAINS.map(d => {
            const on = activeDomains.has(d.id);
            return (
              <button key={d.id} onClick={()=>toggleDomain(d.id)} style={{
                border:`1px solid ${on ? d.color : 'rgba(26,22,20,0.14)'}`,
                background: on ? `${d.color}14` : 'transparent',
                color: on ? d.color : '#534B45',
                padding:'6px 14px', borderRadius:100, cursor:'pointer',
                fontSize:13, fontWeight:600, fontFamily:'Plus Jakarta Sans',
                whiteSpace:'nowrap', display:'inline-flex', alignItems:'center', gap:7,
                transition:'all 0.15s',
              }}>
                <span style={{ color:d.color }}>{d.glyph}</span> {d.id}
              </button>
            );
          })}
        </div>
      </div>
    </div>
  );
}

/* ─── KIT PRICES ──────────────────────────────────────────────────────────── */
const KIT_PRICES = {
  'KIT-LOG-01': '₹1,999',
  'KIT-MTH-01': '₹1,999',
  'KIT-SCH-01': '₹1,999',
  'KIT-EQ-01':  '₹2,499',
  'KIT-HEH-01': '₹2,499',
  'KIT-TT-01':  '₹2,999',
  'KIT-FAM-01': '₹3,499',
  'KIT-SPA-01': '₹1,499',
  'KIT-EXP-01': '₹2,499',
  'KIT-MUS-01': '₹1,999',
};

/* ─── KIT CARD ────────────────────────────────────────────────────────────── */
function KitCard({ kit, onOpen }) {
  const c = window.domainColor(kit.domain);
  const products = kit.products.map(window.productById).filter(Boolean);
  const [hover, setHover] = useState(false);

  return (
    <article
      onMouseEnter={()=>setHover(true)} onMouseLeave={()=>setHover(false)}
      onClick={()=>onOpen(kit)}
      style={{
        background:'#FFFFFF',
        borderRadius:28, overflow:'hidden', cursor:'pointer',
        border:'1px solid rgba(26,22,20,0.08)',
        boxShadow: hover
          ? '0 24px 48px -16px rgba(26,22,20,0.15), 0 0 0 1px '+c+'30'
          : '0 1px 2px rgba(26,22,20,0.04)',
        transform: hover ? 'translateY(-4px)' : 'none',
        transition:'all 0.35s cubic-bezier(0.4,0,0.2,1)',
        display:'flex', flexDirection:'column',
      }}>
      {/* header band */}
      <div style={{ padding:'24px 28px 0', display:'flex', justifyContent:'space-between', alignItems:'flex-start', gap:12 }}>
        <div style={{ display:'inline-flex', alignItems:'center', gap:7, background:`${c}14`, color:c, padding:'5px 11px', borderRadius:100, fontFamily:'Plus Jakarta Sans', fontWeight:600, fontSize:11.5, letterSpacing:'0.03em' }}>
          <span>{(window.DOMAINS.find(d=>d.id===kit.domain)||{}).glyph}</span>
          {kit.domain.toUpperCase()}
        </div>
        <div style={{ textAlign:'right', flexShrink:0, whiteSpace:'nowrap' }}>
          <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:11, color:'#7A6F68', fontWeight:600, textTransform:'uppercase', letterSpacing:'0.08em', whiteSpace:'nowrap' }}>{kit.type}</div>
          <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:13, color:'#1A1614', fontWeight:600, marginTop:2, whiteSpace:'nowrap' }}>{kit.ages}</div>
        </div>
      </div>

      {/* title block */}
      <div style={{ padding:'18px 28px 22px' }}>
        <div style={{ fontFamily:'Instrument Serif', fontSize:18, fontStyle:'italic', color:c, marginBottom:6 }}>{kit.tagline}</div>
        <h3 style={{ fontFamily:'Instrument Serif', fontWeight:400, fontSize:'clamp(28px,2.6vw,36px)', letterSpacing:'-0.02em', lineHeight:1.05, color:'#1A1614', marginBottom:14 }}>{kit.name}</h3>
        <p style={{ fontFamily:'Plus Jakarta Sans', fontSize:14.5, color:'#534B45', lineHeight:1.6 }}>{kit.pitch}</p>
      </div>

      {/* product thumbnail strip */}
      <div style={{ padding:'0 28px 22px' }}>
        <div style={{ display:'flex', gap:8 }}>
          {products.slice(0,5).map((p, i) => (
            <div key={p.id} style={{
              flex:1, aspectRatio:'1/1', borderRadius:14, overflow:'hidden',
              background:'#F5F1E8', position:'relative',
              transform: hover ? `translateY(-${i*1.5}px)` : 'none',
              transition:`transform 0.4s ${i*0.04}s cubic-bezier(0.4,0,0.2,1)`,
            }}>
              <img src={window.IMG_BASE + p.img} alt={p.name} loading="lazy"
                style={{ width:'100%', height:'100%', objectFit:'cover', mixBlendMode:'multiply' }}
                onError={(e)=>{ e.currentTarget.style.display='none'; }}
              />
            </div>
          ))}
        </div>
      </div>

      {/* skill tags */}
      <div style={{ padding:'0 28px 22px', display:'flex', gap:5, flexWrap:'wrap' }}>
        {kit.skillTags.slice(0,4).map(t => (
          <span key={t} style={{
            background:'rgba(26,22,20,0.04)', color:'#534B45',
            padding:'4px 10px', borderRadius:100, fontFamily:'Plus Jakarta Sans',
            fontSize:11.5, fontWeight:600,
          }}>{t}</span>
        ))}
        {kit.skillTags.length > 4 && (
          <span style={{ padding:'4px 10px', color:'#7A6F68', fontFamily:'Plus Jakarta Sans', fontSize:11.5, fontWeight:600 }}>+{kit.skillTags.length-4}</span>
        )}
      </div>

      {/* price line */}
      <div style={{
        display:'flex', alignItems:'baseline', gap:10,
        padding:'14px 0 4px', margin:'0 28px',
        borderTop:'1px solid #F0EDE8', marginTop:14,
      }}>
        <span style={{
          fontFamily:"'Playfair Display', serif",
          fontSize:26, fontWeight:700, color:'#1A1A1A', letterSpacing:'-0.02em',
        }}>{KIT_PRICES[kit.id] || ''}</span>
        <span style={{
          fontFamily:"'Plus Jakarta Sans', sans-serif",
          fontSize:12, color:'#6B6B6B', fontWeight:400,
        }}>free delivery across India</span>
      </div>

      {/* footer — skills count + buy buttons */}
      <div style={{
        marginTop:'auto',
        padding:'18px 28px 24px',
        borderTop:'1px solid rgba(26,22,20,0.06)',
        background: hover ? `${c}08` : 'rgba(26,22,20,0.015)',
        transition:'background 0.3s',
      }}>
        <div style={{ display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:14 }}>
          <div>
            <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:11, color:'#7A6F68', fontWeight:600, textTransform:'uppercase', letterSpacing:'0.06em' }}>Skills covered</div>
            <div style={{ fontFamily:'Instrument Serif', fontSize:24, color:'#1A1614', fontWeight:400, marginTop:2 }}>{kit.skillCount}</div>
          </div>
          <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:12, color:'#7A6F68', fontStyle:'italic' }}>Tap for details</div>
        </div>
        <a href={kit.paymentUrl} target="_blank" rel="noopener"
          onClick={e => e.stopPropagation()}
          style={{
            display:'block', width:'100%', textAlign:'center',
            background:'#1A1614', color:'#FDFCF8',
            padding:'13px 20px', borderRadius:100,
            fontFamily:'Plus Jakarta Sans', fontWeight:600, fontSize:14,
            marginBottom:8, boxSizing:'border-box',
          }}>Buy This Kit →</a>
        <a href={`https://wa.me/919456815951?text=${encodeURIComponent(kit.waMsg)}`} target="_blank" rel="noopener"
          onClick={e => e.stopPropagation()}
          style={{
            display:'block', width:'100%', textAlign:'center',
            background:'transparent', color:'#534B45',
            border:'1px solid rgba(26,22,20,0.18)',
            padding:'10px 20px', borderRadius:100,
            fontFamily:'Plus Jakarta Sans', fontWeight:500, fontSize:13,
            boxSizing:'border-box',
          }}>Have questions? WhatsApp us</a>
      </div>
    </article>
  );
}

/* ─── KIT DRAWER ──────────────────────────────────────────────────────────── */
function KitDrawer({ kit, onClose }) {
  useEffect(() => {
    if (!kit) return;
    const prev = document.body.style.overflow;
    document.body.style.overflow = 'hidden';
    const onKey = e => { if (e.key === 'Escape') onClose(); };
    window.addEventListener('keydown', onKey);
    return () => { document.body.style.overflow = prev; window.removeEventListener('keydown', onKey); };
  }, [kit]);

  if (!kit) return null;
  const c = window.domainColor(kit.domain);
  const products = kit.products.map(window.productById).filter(Boolean);

  return (
    <div onClick={onClose} style={{
      position:'fixed', inset:0, zIndex:200,
      background:'rgba(26,22,20,0.45)', backdropFilter:'blur(4px)',
      display:'flex', justifyContent:'flex-end',
      animation:'fadeIn 0.25s ease',
    }}>
      <div onClick={e=>e.stopPropagation()} style={{
        width:'min(720px, 100%)', background:'#FDFCF8',
        height:'100%', overflowY:'auto',
        animation:'slideIn 0.35s cubic-bezier(0.16,1,0.3,1)',
        position:'relative',
      }}>
        {/* close */}
        <button onClick={onClose} style={{
          position:'sticky', top:16, marginLeft:'calc(100% - 56px)', float:'right',
          width:40, height:40, borderRadius:'50%', border:'1px solid rgba(26,22,20,0.12)',
          background:'#fff', cursor:'pointer', fontSize:18, color:'#1A1614',
          display:'grid', placeItems:'center', zIndex:2,
        }}>×</button>

        {/* header */}
        <div style={{ padding:'40px 48px 24px' }}>
          <div style={{ display:'inline-flex', alignItems:'center', gap:7, background:`${c}14`, color:c, padding:'5px 12px', borderRadius:100, fontFamily:'Plus Jakarta Sans', fontWeight:600, fontSize:11.5, letterSpacing:'0.05em', marginBottom:18 }}>
            <span>{(window.DOMAINS.find(d=>d.id===kit.domain)||{}).glyph}</span>
            {kit.domain.toUpperCase()} · {kit.type.toUpperCase()}
          </div>
          <div style={{ fontFamily:'Instrument Serif', fontSize:22, fontStyle:'italic', color:c, marginBottom:4 }}>{kit.tagline}</div>
          <h2 style={{ fontFamily:'Instrument Serif', fontWeight:400, fontSize:'clamp(40px,5vw,60px)', letterSpacing:'-0.02em', lineHeight:1, color:'#1A1614', marginBottom:18 }}>{kit.name}</h2>
          <div style={{ display:'flex', gap:18, alignItems:'center', flexWrap:'wrap', marginBottom:22, fontFamily:'Plus Jakarta Sans', fontSize:13, color:'#534B45', fontWeight:500 }}>
            <span><strong style={{ color:'#1A1614' }}>{kit.ages}</strong> · ages</span>
            <span>·</span>
            <span><strong style={{ color:'#1A1614' }}>{products.length} toys</strong> · in kit</span>
            <span>·</span>
            <span><strong style={{ color:'#1A1614' }}>{kit.skillCount} skills</strong> · developed</span>
          </div>
          <p style={{ fontFamily:'Plus Jakarta Sans', fontSize:17, color:'#534B45', lineHeight:1.6 }}>{kit.pitch}</p>
        </div>

        {/* skills */}
        <div style={{ padding:'0 48px 32px' }}>
          <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:12, color:'#7A6F68', fontWeight:600, textTransform:'uppercase', letterSpacing:'0.1em', marginBottom:14 }}>Skills you'll build</div>
          <div style={{ display:'flex', gap:6, flexWrap:'wrap' }}>
            {kit.skillTags.map(t => (
              <span key={t} style={{
                background:`${c}10`, color:c,
                padding:'7px 14px', borderRadius:100,
                fontFamily:'Plus Jakarta Sans', fontWeight:600, fontSize:13,
              }}>{t}</span>
            ))}
          </div>
        </div>

        {/* products in kit */}
        <div style={{ padding:'0 48px 40px' }}>
          <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:12, color:'#7A6F68', fontWeight:600, textTransform:'uppercase', letterSpacing:'0.1em', marginBottom:18 }}>What's inside · {products.length} toys</div>
          <div style={{ display:'flex', flexDirection:'column', gap:14 }}>
            {products.map((p, i) => {
              const pc = window.domainColor(p.domain);
              return (
                <div key={p.id} style={{
                  display:'grid', gridTemplateColumns:'120px 1fr', gap:18,
                  padding:14, borderRadius:18,
                  background:'#fff', border:'1px solid rgba(26,22,20,0.06)',
                }}>
                  <div style={{ aspectRatio:'1/1', borderRadius:12, overflow:'hidden', background:'#F5F1E8' }}>
                    <img src={window.IMG_BASE + p.img} alt={p.name}
                      style={{ width:'100%', height:'100%', objectFit:'cover', mixBlendMode:'multiply' }}
                      onError={(e)=>{ e.currentTarget.style.display='none'; }}
                    />
                  </div>
                  <div style={{ display:'flex', flexDirection:'column', justifyContent:'space-between', padding:'4px 4px 4px 0' }}>
                    <div>
                      <div style={{ display:'flex', alignItems:'center', gap:7, marginBottom:6 }}>
                        <DomainDot domain={p.domain} />
                        <span style={{ fontFamily:'Plus Jakarta Sans', fontSize:11, color:pc, fontWeight:600, textTransform:'uppercase', letterSpacing:'0.06em' }}>{p.primarySkill}</span>
                      </div>
                      <h4 style={{ fontFamily:'Instrument Serif', fontWeight:400, fontSize:22, letterSpacing:'-0.015em', color:'#1A1614', marginBottom:6, lineHeight:1.15 }}>{p.name}</h4>
                      <p style={{ fontFamily:'Plus Jakarta Sans', fontSize:13, color:'#534B45', lineHeight:1.55 }}>{p.why}</p>
                    </div>
                    <div style={{ marginTop:10, display:'flex', justifyContent:'space-between', alignItems:'center' }}>
                      <span style={{ fontFamily:'Plus Jakarta Sans', fontSize:12, color:'#7A6F68', fontWeight:600 }}>Ages {p.ages}</span>
                      <span style={{ fontFamily:'Instrument Serif', fontSize:18, fontStyle:'italic', color:pc }}>{p.score}</span>
                    </div>
                  </div>
                </div>
              );
            })}
          </div>
        </div>

        {/* CTA bottom */}
        <div style={{ padding:'24px 48px 48px', borderTop:'1px solid rgba(26,22,20,0.08)', position:'sticky', bottom:0, background:'rgba(253,252,248,0.95)', backdropFilter:'blur(10px)' }}>
          <a href={kit.paymentUrl} target="_blank" rel="noopener" style={{
            display:'block', textAlign:'center',
            background:'#1A1614', color:'#FDFCF8',
            padding:'16px 28px', borderRadius:100,
            fontFamily:'Plus Jakarta Sans', fontWeight:600, fontSize:15,
            marginBottom:10,
          }}>Buy This Kit →</a>
          <a href={`https://wa.me/919456815951?text=${encodeURIComponent(kit.waMsg)}`} target="_blank" rel="noopener" style={{
            display:'block', textAlign:'center',
            background:'transparent', color:'#1A1614',
            border:'1px solid rgba(26,22,20,0.18)',
            padding:'14px 28px', borderRadius:100,
            fontFamily:'Plus Jakarta Sans', fontWeight:500, fontSize:14,
          }}>Have questions? WhatsApp us</a>
        </div>
      </div>
    </div>
  );
}

window.AMComponents = { Nav, KitsToast, Hero, HowItWorks, FilterBar, KitCard, KitDrawer, DomainDot, SkillPill };
