// Posts metadata + Article page renderer (used by individual article HTMLs).

const POSTS_META = [
  {
    id: 'ap-ib-tutoring-vancouver',
    href: 'articles/ap-ib-tutoring-vancouver.html',
    tag: 'Parent guide',
    title: 'How to tell if your child needs Vancouver AP and IB tutoring',
    date: 'May 2, 2026',
    dateISO: '2026-05-02',
    read: '6 min read',
    summary: 'Six clear signs your high-schooler is ready for advanced exam prep — and what to look for in a tutor before signing up.',
    cover: 'TranscriptCover',
  },
  {
    id: 'thirty-minute-routine',
    href: 'articles/thirty-minute-routine.html',
    tag: 'Study skills',
    title: 'The thirty-minute Keats Booklets routine that lifts BC letter grades',
    date: 'April 25, 2026',
    dateISO: '2026-04-25',
    read: '4 min read',
    summary: 'A simple weekday routine parents can run with their child, using the daily-practice section of any Keats Booklet.',
    cover: 'BookletsCover',
  },
  {
    id: 'bc-provincial-roadmap',
    href: 'articles/bc-provincial-roadmap.html',
    tag: 'BC curriculum',
    title: 'A stress-free parent roadmap to the BC Provincial Assessments',
    date: 'April 18, 2026',
    dateISO: '2026-04-18',
    read: '8 min read',
    summary: 'Grade-by-grade breakdown of what BC students face, when, and how families can prep without panic.',
    cover: 'RoadmapCover',
  },
];

window.POSTS_META = POSTS_META;

/* ─── Reusable article page renderer ─── */
// The host article HTML defines window.ARTICLE = { id, body: () => JSX }
// Then renders <ArticleApp/> from this file.

// Articles live at /blog/articles/foo.html — need ../../ to reach the project root
const ArticleNav = () => {
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 24);
    window.addEventListener('scroll', onScroll);
    return () => window.removeEventListener('scroll', onScroll);
  }, []);
  return (
    <header style={{
      position: 'fixed',
      top: 'max(16px, env(safe-area-inset-top))',
      left: 0, right: 0, zIndex: 50,
      display: 'flex', justifyContent: 'center', pointerEvents: 'none',
    }}>
      <div style={{
        pointerEvents: 'auto',
        display: 'flex', alignItems: 'center', gap: 24,
        background: scrolled ? 'rgba(13,21,48,0.85)' : 'rgba(13,21,48,0.55)',
        backdropFilter: 'saturate(180%) blur(18px)',
        WebkitBackdropFilter: 'saturate(180%) blur(18px)',
        border: '1px solid rgba(255,255,255,0.08)',
        borderRadius: 999,
        padding: '10px 14px 10px 20px',
        boxShadow: scrolled ? '0 10px 40px rgba(13,21,48,0.25)' : 'none',
        transition: 'all 0.4s var(--ease-out)',
      }}>
        <a href="../../" style={{display: 'flex', alignItems: 'center', gap: 10, color: '#fff', textDecoration: 'none'}}>
          <div style={{
            width: 38, height: 38, borderRadius: 10, background: '#fff',
            display: 'flex', alignItems: 'center', justifyContent: 'center', overflow: 'hidden',
          }}>
            <img src="../../shared-assets/keats-logo.jpeg" alt="Keats Learning Academy" style={{width: '100%', height: '100%', objectFit: 'cover'}}/>
          </div>
          <span style={{fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 17, letterSpacing: '-0.02em'}}>Keats Learning Academy</span>
        </a>
        <div style={{display: 'flex', alignItems: 'center', gap: 14, flexShrink: 0}}>
          <a href="../../" style={{color: 'rgba(255,255,255,0.82)', fontSize: 13.5, fontWeight: 500, whiteSpace: 'nowrap', padding: '8px 14px', borderRadius: 999, textDecoration: 'none'}}>← Back to site</a>
        </div>
      </div>
    </header>
  );
};

const ArticleHeader = ({post}) => (
  <section style={{
    background: 'var(--ink)', color: '#fff',
    paddingTop: 130, paddingBottom: 56,
    position: 'relative', overflow: 'hidden',
  }}>
    <div style={{
      position: 'absolute', inset: 0,
      background: 'radial-gradient(ellipse at 80% 20%, rgba(217, 162, 74, 0.18), transparent 55%), radial-gradient(ellipse at 10% 90%, rgba(33, 52, 110, 0.45), transparent 60%)',
    }}/>
    <div className="container" style={{position: 'relative', zIndex: 2, maxWidth: 880}}>
      <a href="../" style={{
        display: 'inline-flex', alignItems: 'center', gap: 8,
        fontFamily: 'var(--font-mono)', fontSize: 12, letterSpacing: '0.18em',
        textTransform: 'uppercase', color: 'var(--gold-300)', marginBottom: 24,
        textDecoration: 'none',
      }}>
        <svg width="12" height="12" viewBox="0 0 12 12" aria-hidden="true"><path d="M11 6H1M5 2L1 6l4 4" stroke="currentColor" strokeWidth="1.6" fill="none" strokeLinecap="round"/></svg>
        Back to the blog
      </a>
      <div style={{
        display: 'flex', gap: 14, alignItems: 'center', flexWrap: 'wrap',
        fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.18em',
        color: 'rgba(255,255,255,0.7)', textTransform: 'uppercase', marginBottom: 22,
      }}>
        <span style={{padding: '4px 10px', background: 'rgba(217,162,74,0.18)', color: 'var(--gold-300)', borderRadius: 999, border: '1px solid rgba(217,162,74,0.4)'}}>
          {post.tag}
        </span>
        <time dateTime={post.dateISO}>{post.date}</time>
        <span aria-hidden="true">·</span>
        <span>{post.read}</span>
      </div>
      <h1 style={{
        fontFamily: 'var(--font-display)', fontWeight: 700,
        fontSize: 'clamp(34px, 4.6vw, 58px)', lineHeight: 1.05,
        letterSpacing: '-0.03em', margin: 0,
      }}>{post.title}</h1>
      <p style={{
        fontSize: 18, lineHeight: 1.55, color: 'rgba(255,255,255,0.78)',
        margin: '20px 0 0', maxWidth: 700,
      }}>{post.summary}</p>
    </div>
  </section>
);

const ArticleHero = ({cover}) => (
  <div style={{maxWidth: 980, margin: '-40px auto 0', padding: '0 24px', position: 'relative', zIndex: 3}}>
    <div style={{borderRadius: 18, overflow: 'hidden', boxShadow: '0 30px 60px -28px rgba(13,21,48,0.4)'}}>
      <Cover name={cover} tall/>
    </div>
  </div>
);

const ArticleBody = ({children}) => (
  <article style={{
    maxWidth: 720, margin: '0 auto', padding: '64px 24px 80px',
    fontFamily: 'var(--font-body, Inter, system-ui, sans-serif)',
    color: 'var(--ink)',
  }}>
    <style>{`
      .article-body p { font-size: 17.5px; line-height: 1.75; color: #2a3252; margin: 0 0 22px; }
      .article-body p:first-of-type::first-line { font-weight: 500; }
      .article-body h2 {
        font-family: var(--font-display); font-weight: 700;
        font-size: clamp(24px, 3vw, 32px); line-height: 1.2; letter-spacing: -0.025em;
        color: var(--ink); margin: 56px 0 18px;
      }
      .article-body h3 {
        font-family: var(--font-display); font-weight: 600;
        font-size: 20px; line-height: 1.3; letter-spacing: -0.015em;
        color: var(--ink); margin: 36px 0 12px;
      }
      .article-body ul, .article-body ol { padding-left: 22px; margin: 0 0 22px; }
      .article-body li { font-size: 17px; line-height: 1.7; color: #2a3252; margin-bottom: 8px; }
      .article-body strong { color: var(--ink); font-weight: 600; }
      .article-body blockquote {
        border-left: 3px solid var(--gold-500);
        padding: 8px 24px; margin: 32px 0;
        font-style: italic; font-family: var(--font-display);
        font-size: 20px; line-height: 1.5; color: var(--navy-700);
      }
      .article-body a { color: var(--navy-700); text-decoration: underline; text-underline-offset: 3px; }
      .article-body .callout {
        background: var(--paper); border: 1px solid var(--line);
        border-radius: 14px; padding: 24px 28px; margin: 36px 0;
      }
      .article-body .callout-label {
        font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.18em;
        text-transform: uppercase; color: var(--gold-700, #a47129); margin-bottom: 10px;
      }
      .article-body .callout p:last-child { margin-bottom: 0; }
    `}</style>
    <div className="article-body">{children}</div>
  </article>
);

const RelatedPosts = ({currentId}) => {
  const others = POSTS_META.filter(p => p.id !== currentId).slice(0, 2);
  return (
    <section style={{padding: '64px 0 96px', background: 'var(--paper)', borderTop: '1px solid var(--line)'}}>
      <div className="container" style={{maxWidth: 1100}}>
        <div style={{
          fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.22em',
          textTransform: 'uppercase', color: 'var(--ink-soft)', opacity: 0.7, marginBottom: 24,
        }}>Keep reading</div>
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 24,
        }} className="related-grid">
          {others.map(p => (
            <a key={p.id} href={`${p.id}.html`} style={{
              display: 'flex', flexDirection: 'column',
              background: '#fff', border: '1px solid var(--line)', borderRadius: 16,
              overflow: 'hidden', textDecoration: 'none', color: 'inherit',
              transition: 'transform 0.4s var(--ease-out), box-shadow 0.4s var(--ease-out)',
            }}
            onMouseEnter={e => { e.currentTarget.style.transform = 'translateY(-6px)'; e.currentTarget.style.boxShadow = '0 20px 40px -22px rgba(13,21,48,0.25)'; }}
            onMouseLeave={e => { e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = 'none'; }}
            >
              <Cover name={p.cover}/>
              <div style={{padding: 24, display: 'flex', flexDirection: 'column', gap: 10, flex: 1}}>
                <div style={{
                  display: 'flex', justifyContent: 'space-between',
                  fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.15em',
                  color: 'var(--navy-500)', textTransform: 'uppercase',
                }}>
                  <span>{p.tag}</span><span>{p.read}</span>
                </div>
                <h3 style={{
                  fontFamily: 'var(--font-display)', fontWeight: 600,
                  fontSize: 19, lineHeight: 1.3, letterSpacing: '-0.02em',
                  margin: 0, color: 'var(--ink)',
                }}>{p.title}</h3>
              </div>
            </a>
          ))}
        </div>
      </div>
      <style>{`
        @media (max-width: 760px) { .related-grid { grid-template-columns: 1fr !important; } }
      `}</style>
    </section>
  );
};

const ArticleCTA = () => (
  <section style={{padding: '80px 0', background: 'var(--ink)', color: '#fff', position: 'relative', overflow: 'hidden'}}>
    <div style={{
      position: 'absolute', inset: 0,
      background: 'radial-gradient(ellipse at 90% 10%, rgba(217, 162, 74, 0.18), transparent 55%)',
    }}/>
    <div className="container" style={{position: 'relative', zIndex: 2, maxWidth: 760, textAlign: 'center'}}>
      <h2 style={{
        fontFamily: 'var(--font-display)', fontWeight: 700,
        fontSize: 'clamp(28px, 3.8vw, 42px)', lineHeight: 1.1,
        letterSpacing: '-0.025em', margin: 0,
      }}>
        Ready to put this into practice?{' '}
        <span style={{fontStyle: 'italic', color: 'var(--gold-300)'}}>We can help.</span>
      </h2>
      <p style={{fontSize: 16, lineHeight: 1.6, color: 'rgba(255,255,255,0.78)', maxWidth: 540, margin: '18px auto 28px'}}>
        Book a half-price private 1-on-1 trial with an expert tutor, or a free placement assessment for our Lynn Valley group classes.
      </p>
      <a href="../../#contact" style={{
        display: 'inline-flex', alignItems: 'center', gap: 10,
        padding: '14px 24px', borderRadius: 999,
        background: 'var(--gold-500)', color: 'var(--ink)',
        fontSize: 15, fontWeight: 700,
      }}>
        Book a trial
        <svg width="13" height="13" viewBox="0 0 12 12" aria-hidden="true"><path d="M1 6h10M7 2l4 4-4 4" stroke="currentColor" strokeWidth="1.8" fill="none" strokeLinecap="round"/></svg>
      </a>
    </div>
  </section>
);

const ArticleApp = () => {
  const post = POSTS_META.find(p => p.id === window.ARTICLE.id);
  if (!post) return <div style={{padding: 80, textAlign: 'center'}}>Article not found.</div>;
  const Body = window.ARTICLE.body;
  return (
    <>
      <ArticleNav/>
      <ArticleHeader post={post}/>
      <ArticleHero cover={post.cover}/>
      <ArticleBody><Body/></ArticleBody>
      <ArticleCTA/>
      <RelatedPosts currentId={post.id}/>
      <ArticleFooter/>
    </>
  );
};

// Article-specific footer with ../../ paths (articles are 2 levels deep)
const ArticleFooterCol = ({title, links}) => (
  <div>
    <div style={{fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.18em', color: 'rgba(255,255,255,0.45)', textTransform: 'uppercase', marginBottom: 16}}>{title}</div>
    <div style={{display: 'flex', flexDirection: 'column', gap: 10}}>
      {links.map(l => {
        const external = l.href.startsWith('http');
        return (
          <a key={l.label} href={l.href} onClick={l.onClick}
             {...(external ? {target: '_blank', rel: 'noopener'} : {})}
             style={{color: 'rgba(255,255,255,0.7)', fontSize: 14, textDecoration: 'none'}}>
            {l.label}
          </a>
        );
      })}
    </div>
  </div>
);

const ArticleFooter = () => (
  <footer style={{background: 'var(--navy-950)', color: 'rgba(255,255,255,0.7)', padding: '80px 0 40px'}}>
    <div className="container">
      <div style={{display: 'grid', gridTemplateColumns: 'minmax(0, 1.4fr) repeat(4, minmax(0, 1fr))', gap: 40}} className="footer-grid">
        <div>
          <div style={{display: 'flex', alignItems: 'center', gap: 10, color: '#fff', marginBottom: 20}}>
            <div style={{width: 36, height: 36, borderRadius: 8, overflow: 'hidden', background: '#fff'}}>
              <img src="../../shared-assets/keats-logo.jpeg" alt="Keats Learning Academy" style={{width: '100%', height: '100%', objectFit: 'cover'}}/>
            </div>
            <span style={{fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 19, letterSpacing: '-0.02em'}}>Keats Learning Academy</span>
          </div>
          <p style={{fontSize: 14, lineHeight: 1.6, maxWidth: 320, margin: 0}}>
            A modern tutoring academy built for curious minds, caring parents, and the space between. Est. 2025 · Vancouver.
          </p>
          <div style={{marginTop: 24, fontSize: 13, lineHeight: 1.7}}>
            <strong style={{color: '#fff', fontWeight: 600}}>North Vancouver</strong><br/>
            1258 Lynn Valley Rd #103<br/>
            North Vancouver, BC V7J 2A3<br/>
            <br/>
            {/* Kitsilano · coming soon line temporarily removed pre-launch. */}
            <a href="tel:+17784880188" style={{color: 'var(--gold-300)', fontWeight: 600}}>+1 (778) 488-0188</a><br/>
            <a href="mailto:admin@keatslearningacademy.com" style={{color: 'var(--gold-300)'}}>admin@keatslearningacademy.com</a>
          </div>
        </div>
        <ArticleFooterCol title="Programs" links={[
          {label: 'Private One-on-One Tutoring', href: '../../private-tutoring-north-vancouver/'},
          {label: 'Group Tutoring K–12', href: '../../group-tutoring-north-vancouver/'},
          {label: 'Special Needs Tutoring', href: '../../tutoring-for-adhd/'},
          {label: 'AP & IB Exam Prep', href: '../../ap-ib-tutoring-north-vancouver/'},
        ]}/>
        <ArticleFooterCol title="Company" links={[
          {label: 'About us', href: '../../about-us/'},
          {label: 'Meet the tutors', href: '../../tutors/'},
          {label: 'Careers', href: '../../careers/'},
        ]}/>
        <ArticleFooterCol title="Resources" links={[
          {label: 'Resources', href: '../../blog/'},
          {label: 'Referral program', href: '../../referral/'},
        ]}/>
        <ArticleFooterCol title="Connect" links={[
          {label: 'Parent sign-in', href: '#', onClick: (e) => { e.preventDefault(); window.dispatchEvent(new CustomEvent('keats:open-signin')); }},
          {label: 'Instagram', href: 'https://www.instagram.com/keats_academy/'},
          {label: 'LinkedIn', href: 'https://www.linkedin.com/company/keatsedu/'},
          {label: 'YouTube', href: 'https://www.youtube.com/@Asal-keatsacademy'},
        ]}/>
      </div>
      <div style={{marginTop: 64, paddingTop: 24, borderTop: '1px solid rgba(255,255,255,0.1)', display: 'flex', justifyContent: 'space-between', flexWrap: 'wrap', gap: 16, fontSize: 12, color: 'rgba(255,255,255,0.5)'}}>
        <div>© 2026 Keats Learning Academy. All rights reserved.</div>
        <div style={{display: 'flex', gap: 24}}>
          <a href="../../privacy-policy/" style={{color: 'rgba(255,255,255,0.5)', textDecoration: 'none'}}>Privacy</a>
          <a href="../../terms-conditions/" style={{color: 'rgba(255,255,255,0.5)', textDecoration: 'none'}}>Terms</a>
          <a href="../../refund-policy/" style={{color: 'rgba(255,255,255,0.5)', textDecoration: 'none'}}>Refund policy</a>
          <a href="../../accessibility/" style={{color: 'rgba(255,255,255,0.5)', textDecoration: 'none'}}>Accessibility</a>
          <a href="../../cookies/" style={{color: 'rgba(255,255,255,0.5)', textDecoration: 'none'}}>Cookie settings</a>
        </div>
      </div>
    </div>
  </footer>
);

window.ArticleApp = ArticleApp;
