/* global React, ReactDOM, I18N */
const { useState, useEffect, useRef } = React;

// ------- tiny helpers -------
function useLang() {
  const [lang, setLang] = useState(() => {
    const saved = localStorage.getItem("tokyoToMin.lang");
    if (saved && I18N[saved]) return saved;
    return "ja";
  });
  useEffect(() => {
    localStorage.setItem("tokyoToMin.lang", lang);
    document.body.setAttribute("data-lang", lang);
    document.documentElement.lang = lang;
  }, [lang]);
  return [lang, setLang];
}
function useReveal() {
  useEffect(() => {
    const io = new IntersectionObserver(
      (entries) => {
        entries.forEach((e) => {
          if (e.isIntersecting) {
            e.target.classList.add("in");
            io.unobserve(e.target);
          }
        });
      },
      { threshold: 0.12 }
    );
    document.querySelectorAll(".reveal").forEach((el) => io.observe(el));
    return () => io.disconnect();
  }, []);
}

// ------- icons -------
const Icon = {
  Menu: () => (<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M3 6h18M3 12h18M3 18h18"/></svg>),
  Close: () => (<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M5 5l14 14M19 5L5 19"/></svg>),
  Arrow: () => (<span className="arrow" aria-hidden>→</span>),
  Line: () => (<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M19.365 9.863c.349 0 .63.285.631.631 0 .345-.282.63-.631.63H17.61v1.125h1.755c.349 0 .63.283.63.63 0 .344-.282.629-.63.629h-2.386c-.345 0-.627-.285-.627-.629V8.108c0-.345.282-.63.63-.63h2.386c.346 0 .627.285.627.63 0 .349-.281.63-.63.63H17.61v1.125h1.755zm-3.855 3.016c0 .27-.174.51-.432.596-.064.021-.133.031-.199.031-.211 0-.391-.09-.51-.25l-2.443-3.317v2.94c0 .344-.279.629-.631.629-.346 0-.626-.285-.626-.629V8.108c0-.27.173-.51.43-.595.06-.023.136-.033.194-.033.195 0 .375.104.495.254l2.462 3.33V8.108c0-.345.282-.63.63-.63.345 0 .63.285.63.63v4.771zm-5.741 0c0 .344-.282.629-.631.629-.345 0-.627-.285-.627-.629V8.108c0-.345.282-.63.63-.63.346 0 .628.285.628.63v4.771zm-2.466.629H4.917c-.345 0-.63-.285-.63-.629V8.108c0-.345.285-.63.63-.63.348 0 .63.285.63.63v4.141h1.756c.348 0 .629.283.629.63 0 .344-.282.629-.629.629M24 10.314C24 4.943 18.615.572 12 .572S0 4.943 0 10.314c0 4.811 4.27 8.842 10.035 9.608.391.082.923.258 1.058.59.12.301.079.766.038 1.08l-.164 1.02c-.045.301-.24 1.186 1.049.645 1.291-.539 6.916-4.078 9.436-6.975C23.176 14.393 24 12.458 24 10.314"/></svg>),
  Check: () => (<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3"><path d="M4 12l6 6L20 6"/></svg>),
  Globe: () => (<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="10"/><path d="M2 12h20M12 2a15 15 0 0 1 0 20M12 2a15 15 0 0 0 0 20"/></svg>),
};

// ------- brand mark (5 petals representing 5 founders, inside Tokyo's circle) -------
function BrandMark() {
  return (
    <svg viewBox="0 0 40 40" aria-hidden>
      <g fill="none" stroke="currentColor" strokeWidth="1.5">
        <circle cx="20" cy="20" r="14"/>
      </g>
      <g fill="currentColor">
        <circle cx="20" cy="20" r="3"/>
        {[0,72,144,216,288].map((a,i) => {
          const rad = (a - 90) * Math.PI / 180;
          const x = 20 + Math.cos(rad) * 9;
          const y = 20 + Math.sin(rad) * 9;
          return <circle key={i} cx={x} cy={y} r="1.6"/>;
        })}
      </g>
    </svg>
  );
}

// ------- skyline silhouette -------
function Skyline() {
  return (
    <svg className="skyline" viewBox="0 0 600 200" preserveAspectRatio="none" aria-hidden>
      <defs>
        <linearGradient id="sky-g" x1="0" x2="0" y1="0" y2="1">
          <stop offset="0" stopColor="#0a2a21" stopOpacity="0"/>
          <stop offset="1" stopColor="#05140f" stopOpacity="1"/>
        </linearGradient>
      </defs>
      <rect x="0" y="120" width="600" height="80" fill="url(#sky-g)"/>
      {/* Tokyo skyline-ish silhouettes */}
      <g fill="#05140f" opacity="0.9">
        <polygon points="0,200 0,140 20,140 20,130 45,130 45,110 60,110 60,140 90,140 90,100 110,100 110,140 140,140 140,120 165,120 165,90 180,90 180,70 200,70 200,90 215,90 215,140 260,140 260,115 290,115 290,140 320,140 320,95 345,95 345,70 360,70 360,50 370,50 370,70 385,70 385,140 420,140 420,120 455,120 455,105 480,105 480,130 510,130 510,115 540,115 540,140 600,140 600,200"/>
      </g>
      {/* Tokyo Tower hint */}
      <g stroke="#c8a24b" strokeWidth="0.8" fill="none" opacity="0.5">
        <line x1="370" y1="30" x2="370" y2="50"/>
        <path d="M365 50 L370 30 L375 50"/>
      </g>
    </svg>
  );
}

// ------- QR placeholder -------
function QRMark() {
  // decorative QR-like grid
  const size = 21;
  const pattern = [];
  // deterministic pseudo-random pattern seeded by index
  for (let r = 0; r < size; r++) {
    for (let c = 0; c < size; c++) {
      const onCorner =
        (r < 7 && c < 7) ||
        (r < 7 && c >= size - 7) ||
        (r >= size - 7 && c < 7);
      if (onCorner) {
        const inRing =
          ((r === 0 || r === 6) && c <= 6) ||
          ((c === 0 || c === 6) && r <= 6) ||
          ((r === size - 1 || r === size - 7) && c <= 6) ||
          ((c === 0 || c === 6) && r >= size - 7) ||
          ((r === 0 || r === 6) && c >= size - 7) ||
          ((c === size - 1 || c === size - 7) && r <= 6);
        const inCenter =
          (r >= 2 && r <= 4 && c >= 2 && c <= 4) ||
          (r >= 2 && r <= 4 && c >= size - 5 && c <= size - 3) ||
          (r >= size - 5 && r <= size - 3 && c >= 2 && c <= 4);
        pattern.push({ r, c, on: inRing || inCenter });
        continue;
      }
      // simple pseudo-random
      const v = ((r * 73 + c * 131 + r * c) % 7);
      pattern.push({ r, c, on: v < 3 });
    }
  }
  const cell = 100 / size;
  return (
    <svg viewBox="0 0 100 100" style={{width:"78%", height:"78%"}} aria-hidden>
      <rect width="100" height="100" fill="#fff"/>
      {pattern.map((p,i) =>
        p.on ? <rect key={i} x={p.c*cell} y={p.r*cell} width={cell*1.02} height={cell*1.02} fill="#0c1a14"/> : null
      )}
      {/* Tokyo-green center mark */}
      <circle cx="50" cy="50" r="7" fill="#fff"/>
      <circle cx="50" cy="50" r="5" fill="#14543f"/>
    </svg>
  );
}

// ------- Seal / circular mark -------
function Seal() {
  return (
    <svg viewBox="0 0 100 100" aria-hidden>
      <defs>
        <path id="sealArc" d="M 50,50 m -38,0 a 38,38 0 1,1 76,0 a 38,38 0 1,1 -76,0" />
      </defs>
      <circle cx="50" cy="50" r="46" fill="none" stroke="#c8a24b" strokeWidth="0.7"/>
      <circle cx="50" cy="50" r="38" fill="none" stroke="#c8a24b" strokeWidth="0.7"/>
      <text fill="#c8a24b" fontFamily="Inter, sans-serif" fontSize="6.5" letterSpacing="2">
        <textPath href="#sealArc" startOffset="0">TOKYO · METROPOLITAN · ASSOCIATION · IN · THAILAND · EST · 2026 ·</textPath>
      </text>
      <g transform="translate(50,50)">
        <circle r="14" fill="none" stroke="#c8a24b" strokeWidth="0.6"/>
        <g fill="#c8a24b">
          <circle r="3"/>
          {[0,72,144,216,288].map((a,i) => {
            const rad = (a-90)*Math.PI/180;
            return <circle key={i} cx={Math.cos(rad)*9} cy={Math.sin(rad)*9} r="1.6"/>;
          })}
        </g>
      </g>
    </svg>
  );
}

// ------- Header -------
function Header({ lang, setLang, t }) {
  const [scrolled, setScrolled] = useState(false);
  const [mobileOpen, setMobileOpen] = useState(false);
  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 40);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  const nav = [
    ["#about", t.nav.about],
    ["#qualify", t.nav.qualify || (lang === "ja" ? "参加資格" : lang === "th" ? "เงื่อนไข" : "Eligibility")],
    ["#officers", t.nav.officers],
    ["reports.html", t.nav.activities],
    ["#events", t.nav.events],
    ["#join", t.nav.join],
    ["#news", t.nav.news],
  ];

  return (
    <>
      <header className={`header ${scrolled ? "scrolled" : ""}`}>
        <div className="header-inner">
          <a href="#top" className="brand">
            <span className="brand-mark"><BrandMark/></span>
            <span className="brand-text">
              <div className="jp">在タイ東京都民会</div>
              <div className="en">Tokyo Met. Assoc. in Thailand</div>
            </span>
          </a>
          <nav className="nav">
            {nav.map(([href, label]) => (
              <a key={href} href={href}>{label}</a>
            ))}
          </nav>
          <div className="header-actions">
            <div className="lang-switch" role="tablist" aria-label="Language">
              {["ja","en","th"].map((code) => (
                <button
                  key={code}
                  className={lang === code ? "on" : ""}
                  onClick={() => setLang(code)}
                >
                  {code.toUpperCase()}
                </button>
              ))}
            </div>
            <button className="menu-btn" onClick={() => setMobileOpen(true)} aria-label="Menu">
              <Icon.Menu/>
            </button>
          </div>
        </div>
      </header>

      <div className={`mobile-nav ${mobileOpen ? "open" : ""}`}>
        <button className="close-btn" onClick={() => setMobileOpen(false)} aria-label="Close"><Icon.Close/></button>
        {nav.map(([href, label]) => (
          <a key={href} href={href} onClick={() => setMobileOpen(false)}>{label}</a>
        ))}
      </div>
    </>
  );
}

// ------- Hero -------
function Hero({ t }) {
  return (
    <section className="hero" id="top">
      <div className="container">
        <div className="hero-grid">
          <div className="hero-copy reveal">
            <div className="hero-eyebrow">
              <span className="dot"/>
              <span>{t.hero.eyebrow}</span>
            </div>
            <h1>
              <span className="line">{t.hero.title1}</span>
              <span className="line line-2">{t.hero.title2}</span>
            </h1>
            <p className="hero-sub">{t.hero.subtitle}</p>
            <div className="hero-ctas">
              <a href="#join" className="btn btn-primary btn-lg"><Icon.Line/> {t.hero.cta1}</a>
              <a href="#events" className="btn btn-ghost btn-lg">{t.hero.cta2} <Icon.Arrow/></a>
            </div>
          </div>
          <div className="hero-visual reveal">
            <div className="panel hero-img-panel">
              <img src="assets/hero-main.png" alt="バンコクで &ldquo;東京&rdquo; と繋がろう — 在タイ東京都民会" />
            </div>
          </div>
        </div>

        <div className="hero-stats">
          {[
            [t.hero.stat1Value, t.hero.stat1Label],
            [t.hero.stat2Value, t.hero.stat2Label],
            [t.hero.stat3Value, t.hero.stat3Label],
            [t.hero.stat4Value, t.hero.stat4Label],
          ].map(([v,l], i) => (
            <div key={i} className="stat">
              <div className="v">{v}</div>
              <div className="l">{l}</div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function Marquee({ words }) {
  const loop = [...words, ...words];
  return (
    <div className="marquee" aria-hidden>
      <div className="marquee-track">
        {loop.map((w, i) => <span key={i}>{w}</span>)}
      </div>
    </div>
  );
}

// ------- About -------
function About({ t }) {
  return (
    <section className="section about" id="about">
      <div className="container">
        <div className="section-head reveal">
          <div className="kicker">{t.about.kicker}</div>
        </div>
        <div className="about-grid">
          <div className="reveal">
            <h2 className="about-lead">{t.about.title}</h2>
            <p style={{marginTop: 18, fontSize: 17, color: "var(--green-800)", fontWeight: 500}}>{t.about.lead}</p>
          </div>
          <div className="about-body reveal">
            {t.about.body.map((p, i) => <p key={i}>{p}</p>)}
          </div>
        </div>
        <div className="pillars">
          {t.about.pillars.map((p, i) => (
            <div key={i} className="pillar reveal" style={{transitionDelay: `${i*60}ms`}}>
              <div className="n">{p.n}</div>
              <h3>{p.t}</h3>
              <p>{p.d}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ------- Qualify -------
function Qualify({ t }) {
  if (!t.qualify) return null;
  return (
    <section className="section qualify" id="qualify">
      <div className="container">
        <div className="section-head reveal">
          <div className="kicker">{t.qualify.kicker}</div>
          <h2>{t.qualify.title}</h2>
          <p className="lead">{t.qualify.lead}</p>
        </div>
        <div className="rules">
          {t.qualify.rules.map((r, i) => (
            <div key={i} className="rule reveal" style={{transitionDelay: `${i*80}ms`}}>
              <div className="rule-icon"><RuleIcon kind={r.icon}/></div>
              <div>
                <h3>{r.t}</h3>
                <p>{r.d}</p>
              </div>
            </div>
          ))}
        </div>
        <p className="qualify-note reveal">{t.qualify.note}</p>
      </div>
    </section>
  );
}

function RuleIcon({ kind }) {
  const stroke = "#c8a24b";
  const sw = 1.6;
  const common = { width: 26, height: 26, viewBox: "0 0 24 24", fill: "none", stroke, strokeWidth: sw, strokeLinecap: "round", strokeLinejoin: "round" };
  switch (kind) {
    case "live": // 東京在住経験
      return (
        <svg {...common} aria-hidden>
          <path d="M3 11l9-7 9 7"/>
          <path d="M5 10v10h14V10"/>
          <path d="M10 20v-5h4v5"/>
        </svg>
      );
    case "office": // 本社・支社が在京
      return (
        <svg {...common} aria-hidden>
          <rect x="4" y="3" width="16" height="18" rx="1"/>
          <path d="M8 7h2M8 11h2M8 15h2M14 7h2M14 11h2M14 15h2"/>
          <path d="M10 21v-3h4v3"/>
        </svg>
      );
    case "pass": // 東京を通過
      return (
        <svg {...common} aria-hidden>
          <rect x="5" y="3" width="14" height="16" rx="3"/>
          <path d="M5 9h14"/>
          <path d="M5 15h14"/>
          <circle cx="9" cy="17" r="0.8" fill={stroke} stroke="none"/>
          <circle cx="15" cy="17" r="0.8" fill={stroke} stroke="none"/>
          <path d="M9 21l-2 2M15 21l2 2"/>
        </svg>
      );
    case "name": // 都知事の名前が言える
      return (
        <svg {...common} aria-hidden>
          <path d="M4 5h16v11H8l-4 4z"/>
          <path d="M8 10h8M8 13h5"/>
        </svg>
      );
    default:
      return null;
  }
}

// ------- Officers -------
function Officers({ t }) {
  return (
    <section className="section officers" id="officers">
      <div className="container">
        <div className="section-head reveal">
          <div className="kicker">{t.officers.kicker}</div>
          <h2>{t.officers.title}</h2>
          <p className="lead">{t.officers.lead}</p>
        </div>
        <div className="officers-grid reveal">
          {t.officers.list.map((o, i) => (
            <div key={i} className="officer">
              <div className="officer-avatar">{o.initial}</div>
              <div>
                <div className="role">{o.role}</div>
                <div className="name">{o.name}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ------- Activities -------
function Activities({ t, lang }) {
  return (
    <section className="section activities" id="activities">
      <div className="container">
        <div className="section-head reveal">
          <div className="kicker">{t.activities.kicker}</div>
          <h2>{t.activities.title}</h2>
          <p className="lead">{t.activities.lead}</p>
        </div>
        <div className="activities-list reveal">
          {t.activities.items.map((a, i) => {
            const Tag = a.href ? "a" : "article";
            return (
              <Tag key={i} className="activity" {...(a.href ? {href: a.href} : {})}>
                <div className="date">{a.date}</div>
                <div className="tag">{a.tag}</div>
                <div>
                  <h3>{a.title}</h3>
                  <p>{a.excerpt}</p>
                  {a.href && <span className="activity-cta">{lang === "ja" ? "活動報告を見る →" : lang === "th" ? "ดูรายงาน →" : "Read report →"}</span>}
                </div>
              </Tag>
            );
          })}
        </div>
      </div>
    </section>
  );
}

// ------- Events -------
function Events({ t }) {
  const n = t.events.next;
  return (
    <section className="section events" id="events">
      <div className="container">
        <div className="section-head reveal">
          <div className="kicker">{t.events.kicker}</div>
          <h2>{t.events.title}</h2>
          <p className="lead">{t.events.lead}</p>
        </div>

        <article className="next-card reveal">
          <div className="next-top">
            <div className="next-datebox">
              <div className="next-eyebrow">{n.eyebrow}</div>
              <div className="next-num">{n.num}</div>
              <div className="next-weekday">{n.weekday} · {n.date}</div>
              <div className="next-datefull">{n.dateDisplay}</div>
              <div className="next-timerange">{n.timeRange}</div>
            </div>
            <div className="next-main">
              <h3>{n.title}</h3>
              <p>{n.body}</p>
            </div>
          </div>

          <div className="next-meta">
            <div className="next-meta-cell">
              <div className="next-meta-label">Venue</div>
              <div className="next-meta-value">{n.venue}</div>
              <div className="next-meta-sub">{n.venueSub}</div>
            </div>
            <div className="next-meta-cell">
              <div className="next-meta-label">Fee</div>
              <div className="next-meta-value">{n.fee}</div>
              <div className="next-meta-sub">{n.feeSub}</div>
            </div>
            <div className="next-meta-cell">
              <div className="next-meta-label">Capacity</div>
              <div className="next-meta-value">{n.capacity}</div>
              <div className="next-meta-sub">{n.capacitySub}</div>
            </div>
          </div>

          <div className="next-bottom">
            <div className="next-timeline">
              <div className="next-timeline-label">{n.timelineLabel}</div>
              <ol>
                {n.timeline.map((row, i) => (
                  <li key={i}>
                    <span className="t">{row.t}</span>
                    <span className="d">{row.d}</span>
                  </li>
                ))}
              </ol>
            </div>
            <div className="next-cta">
              <a href="#join" className="btn btn-accent btn-lg"><Icon.Line/> {n.ctaPrimary}</a>
              <a href="reports.html" className="btn btn-ghost-dark btn-lg">{n.ctaSecondary} <Icon.Arrow/></a>
            </div>
          </div>
        </article>

        <div className="events-note reveal">{t.events.note}</div>
      </div>
    </section>
  );
}

// ------- Join -------
function Join({ t }) {
  const plan = t.join.plans[0];
  return (
    <section className="section join" id="join">
      <div className="container">
        <div className="section-head reveal">
          <div className="kicker">{t.join.kicker}</div>
          <h2>{t.join.title}</h2>
          <p className="lead">{t.join.lead}</p>
        </div>
        <div className="join-grid">
          <ol className="steps reveal">
            {t.join.steps.map((s, i) => (
              <li key={i} className="step">
                <div className="n">{s.n}</div>
                <div>
                  <h3>{s.t}</h3>
                  <p>{s.d}</p>
                </div>
              </li>
            ))}
          </ol>
          <div className="plan-card reveal">
            <div className="plan-label">{plan.name}</div>
            <div className="plan-name">{t.join.lead.split(/[。.]/)[0]}</div>
            <div className="price-row">
              <div className="price">{plan.price}</div>
              <div className="unit">{plan.unit}</div>
            </div>
            <ul>
              {plan.features.map((f, i) => <li key={i}>{f}</li>)}
            </ul>
            <div className="line-id-row">
              <div>
                <div className="line-id-label">{t.join.lineLabel}</div>
                <div className="line-id-val">{t.join.lineId}</div>
              </div>
              <a href="https://line.me/R/ti/p/@703nfbjm" className="btn btn-accent" target="_blank" rel="noopener">
                <Icon.Line/>
              </a>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ------- News -------
function News({ t }) {
  return (
    <section className="section news" id="news">
      <div className="container">
        <div className="section-head reveal">
          <div className="kicker">{t.news.kicker}</div>
          <h2>{t.news.title}</h2>
        </div>
        <div className="news-grid reveal">
          {t.news.items.map((n, i) => (
            <a key={i} className="news-item" href={n.href || "#"}>
              <div className="date">{n.date}</div>
              <div className="tag">{n.tag}</div>
              <div className="title">{n.title}</div>
              <div className="arrow">→</div>
            </a>
          ))}
        </div>
      </div>
    </section>
  );
}

// ------- Contact -------
function Contact({ t }) {
  return (
    <section className="section contact" id="contact">
      <div className="container">
        <div className="section-head reveal">
          <div className="kicker">{t.contact.kicker}</div>
          <h2>{t.contact.title}</h2>
          <p className="lead">{t.contact.lead}</p>
        </div>
        <div className="contact-grid">
          <div className="contact-info reveal">
            <div className="contact-row">
              <div className="key">LINE ID</div>
              <div className="val">
                <a href="https://line.me/R/ti/p/@703nfbjm" target="_blank" rel="noopener">@703nfbjm</a>
              </div>
            </div>
            <div className="contact-row">
              <div className="key">{t.contact.addrLabel}</div>
              <div className="val">{t.contact.addr}</div>
            </div>
            <div className="contact-row">
              <div className="key">Hours</div>
              <div className="val">{t.contact.hours}</div>
            </div>
          </div>
          <div className="qr-card reveal">
            <div className="qr"><img src="assets/line-qr.png" alt="LINE QR"/></div>
            <div className="qr-label">{t.join.lineLabel}</div>
            <div className="qr-val">@703nfbjm</div>
            <a href="https://line.me/R/ti/p/@703nfbjm" className="btn" target="_blank" rel="noopener">
              <Icon.Line/> LINE で友だち追加
            </a>
          </div>
        </div>
      </div>
    </section>
  );
}

// ------- Footer -------
function Footer({ t, lang, setLang }) {
  return (
    <footer className="footer">
      <div className="container">
        <div className="footer-grid">
          <div className="footer-brand">
            <div className="brand">
              <span className="brand-mark" style={{background:"rgba(255,255,255,0.08)", color:"#fff"}}><BrandMark/></span>
              <span className="brand-text">
                <div className="jp">在タイ東京都民会</div>
                <div className="en" style={{color:"rgba(255,255,255,.6)"}}>Tokyo Met. Assoc. in Thailand</div>
              </span>
            </div>
            <div className="tagline">{t.footer.tagline}</div>
          </div>
          <div>
            <h4>{t.footer.nav}</h4>
            <ul>
              <li><a href="#about">{t.nav.about}</a></li>
              <li><a href="#officers">{t.nav.officers}</a></li>
              <li><a href="#events">{t.nav.events}</a></li>
              <li><a href="#join">{t.nav.join}</a></li>
            </ul>
          </div>
          <div>
            <h4>{t.footer.social}</h4>
            <ul>
              <li><a href="https://line.me/R/ti/p/@703nfbjm" target="_blank" rel="noopener">LINE @703nfbjm</a></li>
              <li><a href="#contact">{t.nav.contact}</a></li>
            </ul>
          </div>
          <div>
            <h4>Language</h4>
            <ul>
              {["ja","en","th"].map((code) => (
                <li key={code}>
                  <a href="#" onClick={(e) => { e.preventDefault(); setLang(code); }}
                     style={{color: lang===code ? "var(--accent)" : undefined}}>
                    {I18N[code].meta.langFull}
                  </a>
                </li>
              ))}
            </ul>
          </div>
        </div>
        <div className="footer-bottom">
          <div>{t.footer.copyright}</div>
          <div>EST. MARCH 2026 · BANGKOK · 在タイ</div>
        </div>
      </div>
    </footer>
  );
}

// ------- App -------
function App() {
  const [lang, setLang] = useLang();
  const t = I18N[lang];
  useReveal();

  // re-observe on lang switch (new nodes)
  useEffect(() => {
    const io = new IntersectionObserver(
      (entries) => {
        entries.forEach((e) => {
          if (e.isIntersecting) {
            e.target.classList.add("in");
            io.unobserve(e.target);
          }
        });
      },
      { threshold: 0.1 }
    );
    document.querySelectorAll(".reveal:not(.in)").forEach((el) => io.observe(el));
    return () => io.disconnect();
  }, [lang]);

  return (
    <>
      <Header lang={lang} setLang={setLang} t={t}/>
      <Hero t={t}/>
      <Marquee words={t.hero.marquee}/>
      <About t={t}/>
      <Qualify t={t}/>
      <Officers t={t}/>
      <Activities t={t} lang={lang}/>
      <Events t={t}/>
      <Join t={t}/>
      <News t={t}/>
      <Contact t={t}/>
      <Footer t={t} lang={lang} setLang={setLang}/>
    </>
  );
}

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