/* A&M World — Skills Guide App */
const { useState, useEffect } = React;

const DOMAIN_INFO = [
  {
    id: 'Cognitive',
    headline: 'The thinking',
    emphasis: 'brain',
    tagline: 'Logic · Memory · Reasoning',
    description: 'Deductive reasoning, working memory, spatial intelligence, number sense, and planning. The cognitive domain covers every skill that happens when your child thinks their way through a challenge. It\'s the most product-rich domain in our catalogue — because it\'s the foundation of academic and professional success.',
    keySkills: ['Deductive Reasoning', 'Working Memory', 'Spatial Reasoning', 'Number Sense', 'Pattern Recognition', 'Planning & Strategy', 'Decision-Making', 'Probability'],
  },
  {
    id: 'Sensory',
    headline: 'Reading',
    emphasis: 'the world',
    tagline: 'Sound · Touch · Force',
    description: 'Auditory discrimination, force modulation, tactile discrimination, and visual tracking. Before complex cognitive skills can form, the brain must learn to accurately interpret sensory input. Sensory development peaks in the first 5 years — and the right toys accelerate it dramatically.',
    keySkills: ['Auditory Discrimination', 'Force Modulation', 'Visual Tracking', 'Tactile Discrimination', 'Rhythm & Beat', 'Cause & Effect'],
  },
  {
    id: 'Motor',
    headline: 'Hands that',
    emphasis: 'think',
    tagline: 'Fine Motor · Coordination · Strength',
    description: 'Hand-eye coordination, fine motor control, bilateral hand use, and arm strength. Physical skills are the invisible foundation for everything else — writing, drawing, sports, and every form of self-expression. Children with strong motor foundations learn faster across every domain.',
    keySkills: ['Hand-Eye Coordination', 'Fine Motor Control', 'Bilateral Hand Use', 'Pincer Grasp', 'Arm Strength', 'In-Hand Manipulation'],
  },
  {
    id: 'Language',
    headline: 'The',
    emphasis: 'word-builder',
    tagline: 'Literacy · Phonics · Vocabulary',
    description: 'Letter recognition, phonics, spelling, vocabulary, and sequencing. Language skills compound — every word a child learns makes the next word easier. Multisensory language tools (3D letters, physical spelling games) consistently outperform screens in every developmental study we\'ve reviewed.',
    keySkills: ['Letter Recognition', 'Phonics & Spelling', 'Vocabulary', 'Sequencing', 'Number Sense', 'Reading Readiness'],
  },
  {
    id: 'Social-Emotional',
    headline: 'The operating',
    emphasis: 'system',
    tagline: 'Emotions · Empathy · Resilience',
    description: 'Emotion identification, empathy, frustration tolerance, and theory of mind. These are the skills that determine how your child navigates relationships, handles setbacks, and reads other people. Social-emotional intelligence is the strongest predictor of long-term life satisfaction — above IQ, grades, or income.',
    keySkills: ['Emotion Identification', 'Empathy', 'Theory of Mind', 'Frustration Tolerance', 'Turn-Taking', 'Competitive Resilience', 'Emotional Vocabulary'],
  },
  {
    id: 'Creative',
    headline: 'The imagination',
    emphasis: 'engine',
    tagline: 'Pretend Play · Narrative · Open-Ended',
    description: 'Pretend play, narrative construction, and open-ended exploration. Creative skills are how children rehearse real-world scenarios, process emotions, and build the cognitive flexibility to think in new ways. Creativity is not a talent — it\'s a skill that develops with the right kind of play.',
    keySkills: ['Pretend Play', 'Narrative Construction', 'Open-Ended Exploration', 'Role Play', 'Colour Recognition', 'Sequencing'],
  },
  {
    id: 'Life Skills',
    headline: 'Ready for the',
    emphasis: 'real world',
    tagline: 'Time · Classification · Independence',
    description: 'Time-telling, classification, sorting, and practical independence. Life skills are the often-underrated foundation of childhood competence. When children can tell time, sort objects, and follow routines independently, they develop agency — the belief that they can affect their world.',
    keySkills: ['Time-Telling', 'Classification', 'Colour Recognition', 'Shape Recognition', 'Sorting & Categorising', 'Number Sense'],
  },
];

/* ─── HERO ────────────────────────────────────────────────────────────────── */
function SkillsHero() {
  return (
    <section style={{ padding:'140px clamp(20px,4vw,52px) 80px', position:'relative', overflow:'hidden', background:'#FDFCF8' }}>
      <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 80% 60% at 80% 40%, #000 30%, transparent 80%)', WebkitMaskImage:'radial-gradient(ellipse 80% 60% at 80% 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' }}/>
          Skills Guide · A&amp;M World
        </div>

        <h1 style={{ fontFamily:'Instrument Serif', fontSize:'clamp(54px, 8vw, 120px)', lineHeight:0.95, letterSpacing:'-0.025em', color:'#1A1614', fontWeight:400, marginBottom:32, maxWidth:1000 }}>
          178 skills.<br/>9 domains.<br/><em style={{ color:'#D85A30' }}>Every toy, mapped.</em>
        </h1>

        <p style={{ fontFamily:'Plus Jakarta Sans', fontSize:'clamp(16px,1.7vw,20px)', color:'#534B45', lineHeight:1.65, maxWidth:600, marginBottom:48 }}>
          Most toys say "educational". We name the <em style={{ fontFamily:'Instrument Serif', fontStyle:'italic', fontSize:'1.1em', color:'#1A1614' }}>exact skill</em> each toy develops — the same skills paediatricians and developmental psychologists measure. This is how we build kits that actually work.
        </p>

        <div style={{ display:'flex', gap:8, flexWrap:'wrap', marginBottom:56 }}>
          {window.DOMAINS.map(d => (
            <a key={d.id} href={'#domain-' + d.id.toLowerCase().replace(/\s+/g, '-')} style={{
              display:'inline-flex', alignItems:'center', gap:7,
              background:d.color + '14', color:d.color,
              padding:'8px 16px', borderRadius:100,
              fontFamily:'Plus Jakarta Sans', fontSize:13, fontWeight:600,
              border:'1px solid ' + d.color + '30',
              transition:'all 0.18s',
            }}
              onMouseEnter={e => { e.currentTarget.style.background = d.color + '26'; }}
              onMouseLeave={e => { e.currentTarget.style.background = d.color + '14'; }}
            >
              <span>{d.glyph}</span> {d.id}
            </a>
          ))}
        </div>

        <div className="sg-stats-strip" style={{ display:'grid', gridTemplateColumns:'repeat(4, 1fr)', gap:0, borderTop:'1px solid rgba(26,22,20,0.1)', borderBottom:'1px solid rgba(26,22,20,0.1)' }}>
          {[
            { n:'178', l:'skills mapped' },
            { n:'7',   l:'developmental domains' },
            { n:'28',  l:'products scored' },
            { n:'10',  l:'curated skill kits' },
          ].map((s, i, arr) => (
            <div key={i} style={{ padding:'24px 24px 24px 0', borderRight: i < arr.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>
  );
}

/* ─── DOMAIN SECTION ─────────────────────────────────────────────────────── */
function DomainSection({ info, bg }) {
  const c = window.domainColor(info.id);
  const domainObj = window.DOMAINS.find(d => d.id === info.id);
  const products = window.PRODUCTS.filter(p => p.domain === info.id);
  const kits = window.KITS.filter(k => k.domain === info.id);
  const anchorId = 'domain-' + info.id.toLowerCase().replace(/\s+/g, '-');

  return (
    <section id={anchorId} style={{ padding:'96px clamp(20px,4vw,52px)', background: bg, borderTop:'1px solid rgba(26,22,20,0.08)' }}>
      <div style={{ maxWidth:1240, margin:'0 auto' }}>
        <div className="sg-domain-layout" style={{ display:'grid', gridTemplateColumns:'minmax(0,1.3fr) minmax(0,1fr)', gap:52, alignItems:'start', marginBottom:52 }}>
          {/* left: headline + description */}
          <div>
            <div style={{ display:'inline-flex', alignItems:'center', gap:9, background:c + '14', color:c, padding:'6px 14px', borderRadius:100, fontFamily:'Plus Jakarta Sans', fontWeight:700, fontSize:11, letterSpacing:'0.1em', textTransform:'uppercase', marginBottom:22 }}>
              <span style={{ fontSize:14 }}>{domainObj?.glyph}</span>
              {info.id}
            </div>
            <h2 style={{ fontFamily:'Instrument Serif', fontWeight:400, fontSize:'clamp(40px,5vw,64px)', letterSpacing:'-0.025em', lineHeight:0.98, color:'#1A1614', marginBottom:12 }}>
              {info.headline} <em style={{ fontStyle:'italic', color:c }}>{info.emphasis}</em>
            </h2>
            <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:13, color:c, fontWeight:600, letterSpacing:'0.06em', marginBottom:20 }}>{info.tagline}</div>
            <p style={{ fontFamily:'Plus Jakarta Sans', fontSize:16, color:'#534B45', lineHeight:1.65 }}>{info.description}</p>
          </div>

          {/* right: skills + kits */}
          <div>
            <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:11, color:'#7A6F68', textTransform:'uppercase', letterSpacing:'0.12em', fontWeight:600, marginBottom:12 }}>Key skills in this domain</div>
            <div style={{ display:'flex', flexWrap:'wrap', gap:7, marginBottom:28 }}>
              {info.keySkills.map(sk => (
                <span key={sk} style={{
                  background:c + '10', color:c,
                  padding:'6px 14px', borderRadius:100,
                  fontFamily:'Plus Jakarta Sans', fontSize:12, fontWeight:600,
                  border:'1px solid ' + c + '22',
                }}>{sk}</span>
              ))}
            </div>

            {kits.length > 0 && (
              <>
                <div style={{ fontFamily:'Plus Jakarta Sans', fontSize:11, color:'#7A6F68', textTransform:'uppercase', letterSpacing:'0.12em', fontWeight:600, marginBottom:10 }}>
                  Featured kit{kits.length > 1 ? 's' : ''}
                </div>
                {kits.map(k => (
                  <a key={k.id} href="kits.html" style={{
                    display:'flex', alignItems:'center', gap:10,
                    padding:'12px 16px', borderRadius:14, marginBottom:7,
                    background:'rgba(26,22,20,0.03)', border:'1px solid rgba(26,22,20,0.07)',
                    fontFamily:'Plus Jakarta Sans', fontSize:13, fontWeight:600, color:'#1A1614',
                    transition:'all 0.15s',
                  }}
                    onMouseEnter={e => { e.currentTarget.style.background = c + '0A'; e.currentTarget.style.borderColor = c + '30'; }}
                    onMouseLeave={e => { e.currentTarget.style.background = 'rgba(26,22,20,0.03)'; e.currentTarget.style.borderColor = 'rgba(26,22,20,0.07)'; }}
                  >
                    <span style={{ color:c }}>{domainObj?.glyph}</span>
                    <span style={{ flex:1 }}>{k.name}</span>
                    <span style={{ fontFamily:'Plus Jakarta Sans', fontSize:11, color:'#7A6F68', fontWeight:500, background:'rgba(26,22,20,0.05)', padding:'3px 9px', borderRadius:100 }}>{k.ages}</span>
                    <span style={{ color:'#7A6F68', fontSize:13 }}>→</span>
                  </a>
                ))}
              </>
            )}
          </div>
        </div>

        {/* products in this domain */}
        {products.length > 0 && (
          <>
            <div style={{ display:'flex', alignItems:'center', gap:12, marginBottom:20 }}>
              <span style={{ fontFamily:'Plus Jakarta Sans', fontSize:11, color:'#7A6F68', textTransform:'uppercase', letterSpacing:'0.12em', fontWeight:600 }}>
                {products.length} product{products.length !== 1 ? 's' : ''} in this domain
              </span>
              <span style={{ flex:1, height:1, background:'rgba(26,22,20,0.08)' }}/>
            </div>
            <div style={{ display:'grid', gridTemplateColumns:'repeat(auto-fill, minmax(260px,1fr))', gap:18 }}>
              {products.map(p => <window.AMSections.ProductCard key={p.id} p={p} />)}
            </div>
          </>
        )}
      </div>
    </section>
  );
}

/* ─── HOW WE SCORE ───────────────────────────────────────────────────────── */
function HowWeScore() {
  return (
    <section style={{ padding:'100px clamp(20px,4vw,52px)', background:'#1A1614', color:'#FDFCF8' }}>
      <div style={{ maxWidth:1240, margin:'0 auto' }}>
        <div style={{ display:'flex', alignItems:'baseline', gap:14, marginBottom:48 }}>
          <span style={{ fontFamily:'Plus Jakarta Sans', fontSize:12, color:'#A89D94', textTransform:'uppercase', letterSpacing:'0.12em', fontWeight:600 }}>Our methodology</span>
          <span style={{ flex:1, height:1, background:'rgba(253,252,248,0.18)' }}/>
        </div>
        <h2 style={{ fontFamily:'Instrument Serif', fontWeight:400, fontSize:'clamp(40px,5.5vw,72px)', letterSpacing:'-0.025em', lineHeight:0.98, marginBottom:18, maxWidth:900 }}>
          How we <em style={{ color:'#D85A30', fontStyle:'italic' }}>score</em> every toy.
        </h2>
        <p style={{ fontFamily:'Plus Jakarta Sans', fontSize:17, color:'rgba(253,252,248,0.7)', maxWidth:560, lineHeight:1.55, marginBottom:60 }}>
          Every product in our catalogue passes a 5-question evaluation. Most toys fail at least one. Products that score 3/5 or below don't make the cut.
        </p>

        <div className="why-grid" style={{ display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap:0, borderTop:'1px solid rgba(253,252,248,0.12)' }}>
          {[
            { n:'01', q:'Does the child DO something?', b:'Not passive — the child acts, decides, manipulates. Watching something happen is not development.' },
            { n:'02', q:'Does it give FEEDBACK?',        b:'Self-correcting: the child sees right and wrong. No adult needed to evaluate the outcome.' },
            { n:'03', q:'Can it get HARDER?',            b:'The same toy challenges a 3-year-old and a 7-year-old differently. Progression is built in.' },
            { n:'04', q:'Does it use MULTIPLE skills?',  b:'Fine motor + counting + planning in one toy. Multi-skill toys build faster than single-skill ones.' },
            { n:'05', q:'Will they RETURN to it?',       b:'Replay value. If a child only plays once, the skill investment is shallow. Return = deep practice.' },
          ].map((item, i) => (
            <div key={i} style={{ padding:'32px 28px 32px 0', borderRight: i % 3 < 2 ? '1px solid rgba(253,252,248,0.12)' : 'none', paddingLeft: i % 3 > 0 ? 28 : 0, borderTop: i >= 3 ? '1px solid rgba(253,252,248,0.12)' : 'none', paddingTop: i >= 3 ? 32 : 32 }}>
              <div style={{ fontFamily:'Instrument Serif', fontSize:16, fontStyle:'italic', color:'#D85A30', marginBottom:14 }}>{item.n}</div>
              <h3 style={{ fontFamily:'Instrument Serif', fontSize:'clamp(20px,2vw,26px)', fontWeight:400, color:'#FDFCF8', letterSpacing:'-0.015em', lineHeight:1.15, marginBottom:12 }}>{item.q}</h3>
              <p style={{ fontFamily:'Plus Jakarta Sans', fontSize:14, color:'rgba(253,252,248,0.65)', lineHeight:1.6 }}>{item.b}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ─── APP ─────────────────────────────────────────────────────────────────── */
function App() {
  const { AMHeader, AMFooter } = window.AMShared;
  const { CTAFooter, ByAge } = window.AMSections;

  useEffect(() => {
    function handleHash() {
      const h = (window.location.hash || '').replace('#', '');
      if (!h) return;
      setTimeout(() => {
        const el = document.getElementById(h);
        if (!el) return;
        const top = el.getBoundingClientRect().top + window.scrollY - 68;
        window.scrollTo({ top, behavior:'smooth' });
      }, 100);
    }
    handleHash();
    window.addEventListener('hashchange', handleHash);
    return () => window.removeEventListener('hashchange', handleHash);
  }, []);

  const bgs = ['#FDFCF8', '#F5F1E8', '#FDFCF8', '#F5F1E8', '#FDFCF8', '#F5F1E8', '#FDFCF8'];

  return (
    <div data-screen-label="Skills Guide — A&M World">
      <AMHeader active="skills" />
      <SkillsHero />
      {DOMAIN_INFO.map((info, i) => (
        <DomainSection key={info.id} info={info} bg={bgs[i]} />
      ))}
      <HowWeScore />
      <ByAge />
      <CTAFooter />
      <AMFooter page="skills" />
    </div>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<App />);
