// Home page — structured for clarity, trust, and accessibility
function HomePage({ t, setPage, heroStyle }) {
  return (
    <div className="wn-home">
      <HomeHero t={t} setPage={setPage} heroStyle={heroStyle} />
      <HomeWelcome t={t} />
      <DailyDhammaTeaser t={t} setPage={setPage} />
      <EventsPreview t={t} setPage={setPage} />
      <HomeAbout t={t} setPage={setPage} />
      <HomePractice t={t} setPage={setPage} />
      <HomeCommunity t={t} setPage={setPage} />
      <HomeSupport t={t} setPage={setPage} />
      <HomeContactVisit t={t} setPage={setPage} />
    </div>
  );
}

// ─── Hero (dispatcher) ─────────────────────────────────────────────
function HomeHero({ t, setPage, heroStyle = "cinematic" }) {
  return heroStyle === "editorial"
    ? <HomeHeroEditorial t={t} setPage={setPage} />
    : <HomeHeroCinematic t={t} setPage={setPage} />;
}

// ─── Cinematic full-bleed hero ─────────────────────────────────────
function HomeHeroCinematic({ t, setPage }) {
  const h = t.hero;
  const lang = t.locale;
  return (
    <section
      aria-label={lang === "th" ? "หน้าแรกวัดไทยนอร์เวย์" : "Wat Thai Norway homepage hero"}
      style={{
        position: "relative",
        marginTop: "-88px",
        minHeight: "min(92svh, 900px)",
        display: "flex",
        alignItems: "flex-end",
        overflow: "hidden",
        backgroundColor: "#191107",
      }}
    >
      <div style={{ position: "absolute", inset: 0, zIndex: 0, overflow: "hidden" }}>
        <img
          className="wn-hero-photo"
          src="/assets/life/sakura-sign.jpg"
          alt={t.locale === "th" ? "ป้ายวัดไทยนอร์เวย์ท่ามกลางดอกซากุระ ที่ Frogner นอร์เวย์" : "Wat Thai Norway temple sign framed by cherry blossoms at Frogner, Norway"}
          style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: "44% 58%" }}
        />
      </div>

      <div style={{ position: "absolute", inset: 0, zIndex: 1, background: "linear-gradient(180deg, rgba(20,13,5,0.35) 0%, rgba(20,13,5,0.15) 40%, rgba(20,13,5,0.75) 85%, rgba(20,13,5,0.92) 100%)" }} />
      <div style={{ position: "absolute", inset: 0, zIndex: 1, background: "linear-gradient(90deg, rgba(20,13,5,0.72) 0%, rgba(20,13,5,0.2) 45%, rgba(20,13,5,0) 70%)" }} />

      <div className="wn-container wn-hero-pad" style={{ position: "relative", zIndex: 3, width: "100%", paddingTop: "120px", paddingBottom: "56px" }}>
        <div style={{ maxWidth: "680px" }}>
          <p className="wn-hero-eyebrow" style={{ fontFamily: "var(--font-body)", fontSize: "13px", letterSpacing: "0.2em", textTransform: "uppercase", color: "var(--accent)", marginBottom: "18px" }}>
            {h.eyebrow}
          </p>
          <h1 className="wn-hero-h1" style={{ fontFamily: "var(--font-display)", fontSize: "clamp(40px, 6vw, 72px)", fontWeight: 400, lineHeight: 1.06, letterSpacing: "-0.02em", color: "#fbf7ef", margin: 0, textShadow: "0 2px 40px rgba(0,0,0,0.4)" }}>
            {h.title}
          </h1>
          <p className="wn-hero-lede" style={{ fontFamily: "var(--font-body)", fontSize: "clamp(17px, 2.5vw, 20px)", lineHeight: 1.7, color: "rgba(251,247,239,0.9)", marginTop: "22px", maxWidth: "600px" }}>
            {h.lede}
          </p>
          <div className="wn-hero-cta" style={{ display: "flex", gap: "12px", marginTop: "32px", flexWrap: "wrap" }}>
            <BtnPrimary onClick={function () { setPage("calendar"); }}>{h.ctaPrimary}</BtnPrimary>
            <BtnLight onClick={function () { setPage("donate"); }}>{h.ctaSecondary}</BtnLight>
            <BtnLight onClick={function () { setPage("contact"); }}>{h.ctaTertiary}</BtnLight>
          </div>
          <div className="wn-hero-meta" style={{ marginTop: "36px", display: "flex", gap: "16px 32px", flexWrap: "wrap", borderTop: "1px solid rgba(251,247,239,0.18)", paddingTop: "20px" }}>
            {h.meta.map(function (m, i) {
              return (
                <div key={i} style={{ fontFamily: "var(--font-body)", fontSize: "13px", letterSpacing: "0.06em", color: "rgba(251,247,239,0.78)", display: "flex", alignItems: "center", gap: "8px" }}>
                  <span style={{ width: "4px", height: "4px", borderRadius: "50%", background: "var(--accent)" }} aria-hidden="true" />
                  {m}
                </div>
              );
            })}
          </div>
        </div>
      </div>
    </section>
  );
}

// ─── Editorial split hero (alternate) ──────────────────────────────
function HomeHeroEditorial({ t, setPage }) {
  // We push the header negative-y by placing hero at top with translucent bg
  const h = t.hero;
  return (
    <section style={{ paddingTop: "16px", paddingBottom: "80px", position: "relative", marginTop: "-80px" }}>
      <div className="wn-container wn-r2" style={{ display: "grid", gridTemplateColumns: "1.05fr 0.95fr", gap: "64px", alignItems: "end", minHeight: "calc(100vh - 40px)", paddingTop: "120px", paddingBottom: "40px" }}>
        <div>
          <Eyebrow>{h.eyebrow}</Eyebrow>
          <h1 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(56px, 7vw, 104px)", fontWeight: 400, lineHeight: 1.0, letterSpacing: "-0.015em", color: "var(--ink)", margin: 0, whiteSpace: "pre-line" }}>
            {h.title}
          </h1>
          <p style={{ fontFamily: "var(--font-body)", fontSize: "18px", lineHeight: 1.6, color: "var(--muted)", marginTop: "32px", maxWidth: "520px" }}>
            {h.lede}
          </p>
          <div style={{ display: "flex", gap: "16px", marginTop: "40px", flexWrap: "wrap" }}>
            <button
              onClick={() => setPage("contact")}
              style={{ backgroundColor: "var(--ink)", color: "var(--bg)", border: "none", padding: "16px 28px", borderRadius: "999px", fontFamily: "var(--font-body)", fontSize: "14px", letterSpacing: "0.04em", cursor: "pointer", display: "flex", alignItems: "center", gap: "10px" }}
            >
              <span style={{ width: "6px", height: "6px", borderRadius: "50%", background: "var(--accent)" }} />
              {h.ctaPrimary}
            </button>
            <button
              onClick={() => setPage("calendar")}
              style={{ backgroundColor: "transparent", color: "var(--ink)", border: "1px solid var(--ink)", padding: "16px 28px", borderRadius: "999px", fontFamily: "var(--font-body)", fontSize: "14px", letterSpacing: "0.04em", cursor: "pointer" }}
            >
              {h.ctaSecondary} →
            </button>
          </div>
          <div style={{ marginTop: "64px", display: "flex", gap: "40px", flexWrap: "wrap" }}>
            {h.meta.map((m, i) => (
              <div key={i} style={{ fontFamily: "var(--font-body)", fontSize: "12px", letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--muted)", display: "flex", alignItems: "center", gap: "10px" }}>
                <span style={{ width: "4px", height: "4px", borderRadius: "50%", background: "var(--accent)" }} />
                {m}
              </div>
            ))}
          </div>
        </div>

        <div style={{ position: "relative" }}>
          <img
            src="/assets/life/sakura-sign.jpg"
            alt="วัดไทยนอร์เวย์ — Wat Thai Norway"
            style={{ display: "block", width: "100%", aspectRatio: "4 / 3", objectFit: "cover" }}
          />
          {/* Frame ornament corner */}
          <div style={{ position: "absolute", top: "-12px", left: "-12px", width: "48px", height: "48px", borderTop: "1px solid var(--accent)", borderLeft: "1px solid var(--accent)" }} />
          <div style={{ position: "absolute", bottom: "-12px", right: "-12px", width: "48px", height: "48px", borderBottom: "1px solid var(--accent)", borderRight: "1px solid var(--accent)" }} />
          <div style={{ position: "absolute", bottom: "24px", left: "24px", padding: "16px 22px", background: "rgba(20, 14, 6, 0.78)", color: "var(--bg)", backdropFilter: "blur(6px)" }}>
            <div style={{ fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--accent)", marginBottom: "4px" }}>
              ☉ + ☽
            </div>
            <div style={{ fontFamily: "var(--font-display)", fontSize: "18px", lineHeight: 1.2 }}>{t.quickLinks.title}</div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ─── Mobile-first action hub ───────────────────────────────────────
function HomeActionHub({ t, setPage }) {
  const hub = t.actionHub;
  const actionThemes = [
    { bg: "var(--nordic-soft)", ink: "var(--nordic)", border: "rgba(49,90,115,0.20)", dot: "var(--nordic)" },
    { bg: "var(--sakura-soft)", ink: "var(--sakura)", border: "rgba(185,111,127,0.24)", dot: "var(--sakura)" },
    { bg: "var(--ink)", ink: "var(--bg)", border: "var(--ink)", dot: "var(--accent)" },
  ];
  return (
    <section style={{ paddingTop: "70px", paddingBottom: "32px", background: "linear-gradient(180deg, var(--bg) 0%, var(--sakura-soft) 48%, var(--bg-deep) 100%)" }}>
      <div className="wn-container">
        <div className="wn-r2" style={{ display: "grid", gridTemplateColumns: "0.82fr 1.18fr", gap: "44px", alignItems: "end" }}>
          <div>
            <Eyebrow>{hub.eyebrow}</Eyebrow>
            <SectionTitle size="md">{hub.title}</SectionTitle>
            <p style={{ fontFamily: "var(--font-body)", fontSize: "15px", lineHeight: 1.7, color: "var(--muted)", marginTop: "18px", maxWidth: "420px" }}>
              {hub.body}
            </p>
          </div>

          <div className="wn-action-grid" style={{ display: "grid", gridTemplateColumns: "repeat(3, minmax(0, 1fr))", gap: "14px" }}>
            {hub.items.map((item, i) => {
              const theme = actionThemes[i] || actionThemes[0];
              const dark = i === 2;
              return (
                <button
                  key={item.title}
                  onClick={() => setPage(item.page)}
                  className="wn-action-card"
                  style={{
                    textAlign: "left",
                    minHeight: "188px",
                    padding: "22px",
                    background: theme.bg,
                    color: dark ? "var(--bg)" : "var(--ink)",
                    border: "1px solid " + theme.border,
                    cursor: "pointer",
                    display: "flex",
                    flexDirection: "column",
                    justifyContent: "space-between",
                    gap: "18px",
                    boxShadow: dark ? "0 18px 44px rgba(43,33,24,0.16)" : "0 12px 34px rgba(43,33,24,0.06)",
                  }}
                >
                  <span style={{ width: "34px", height: "34px", borderRadius: "50%", border: "1px solid " + (dark ? "rgba(250,247,242,0.34)" : theme.border), display: "inline-flex", alignItems: "center", justifyContent: "center", color: dark ? "var(--accent)" : theme.ink, fontFamily: "var(--font-display)", fontSize: "17px" }}>
                    {String(i + 1).padStart(2, "0")}
                  </span>
                  <span>
                    <span style={{ display: "block", fontFamily: "var(--font-display)", fontSize: "24px", lineHeight: 1.15, letterSpacing: "-0.01em" }}>
                      {item.title}
                    </span>
                    <span style={{ display: "block", fontFamily: "var(--font-body)", fontSize: "13px", lineHeight: 1.55, color: dark ? "rgba(250,247,242,0.72)" : "var(--muted)", marginTop: "8px" }}>
                      {item.body}
                    </span>
                  </span>
                  <span style={{ display: "inline-flex", alignItems: "center", gap: "8px", fontFamily: "var(--font-body)", fontSize: "12px", letterSpacing: "0.08em", textTransform: "uppercase", color: dark ? "var(--accent)" : theme.ink }}>
                    <span style={{ width: "6px", height: "6px", borderRadius: "50%", background: theme.dot }} />
                    {item.action} <span>→</span>
                  </span>
                </button>
              );
            })}
          </div>
        </div>
      </div>
    </section>
  );
}

// ─── Today's services band ─────────────────────────────────────────
function HomeTodayBar({ t }) {
  return (
    <section style={{ borderTop: "1px solid var(--line)", borderBottom: "1px solid var(--line)", paddingTop: "32px", paddingBottom: "32px" }}>
      <div className="wn-container wn-r-today" style={{ display: "grid", gridTemplateColumns: "auto 1fr 1fr 1fr", gap: "48px", alignItems: "center" }}>
        <div style={{ fontFamily: "var(--font-body)", fontSize: "11px", letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--muted)" }}>
          {t.quickLinks.title}
        </div>
        {t.quickLinks.items.map((q, i) => (
          <div key={i} style={{ display: "flex", alignItems: "baseline", gap: "16px" }}>
            <div style={{ fontFamily: "var(--font-display)", fontSize: "28px", color: "var(--accent)", lineHeight: 1 }}>{q.time}</div>
            <div>
              <div style={{ fontFamily: "var(--font-body)", fontSize: "14px", color: "var(--ink)" }}>{q.label}</div>
              <div style={{ fontFamily: "var(--font-body)", fontSize: "11px", letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--muted)", marginTop: "2px" }}>{q.note}</div>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ─── Welcome / about preview ───────────────────────────────────────
function HomeWelcome({ t }) {
  const w = t.welcome;
  return (
    <section className="wn-home-section" style={{ padding: "clamp(56px, 8vw, 80px) 0", background: "var(--bg)" }}>
      <div className="wn-container" style={{ maxWidth: "820px", textAlign: "center" }}>
        <Eyebrow>{w.eyebrow}</Eyebrow>
        <h2 className="wn-h2" style={{ margin: "0 0 20px" }}>{w.title}</h2>
        <p className="wn-lead" style={{ margin: "0 auto", maxWidth: "68ch" }}>{w.body}</p>
      </div>
    </section>
  );
}

// ─── Events preview ─────────────────────────────────────────────────
function HomeEvents({ t, setPage }) {
  const lang = t.locale;
  const items = window.EVENT_BANK.slice(0, 2);
  return (
    <section style={{ paddingTop: "100px", paddingBottom: "100px", backgroundColor: "var(--bg-deep)" }}>
      <div className="wn-container">
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "end", marginBottom: "56px", gap: "32px", flexWrap: "wrap" }}>
          <div>
            <Eyebrow>{t.eventsSection.eyebrow}</Eyebrow>
            <SectionTitle size="md">{t.eventsSection.title}</SectionTitle>
          </div>
          <button onClick={() => setPage("calendar")} style={{ background: "none", border: "none", cursor: "pointer", fontFamily: "var(--font-body)", fontSize: "14px", color: "var(--ink)", borderBottom: "1px solid var(--accent)", padding: "4px 0", letterSpacing: "0.02em" }}>
            {t.eventsSection.viewAll} →
          </button>
        </div>
        <div className="wn-r2" style={{ display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: "32px" }}>
          {items.map((e) => (
            <article key={e.id} style={{ borderTop: "1px solid var(--line)", paddingTop: "28px", display: "flex", flexDirection: "column", minHeight: "320px" }}>
              <div style={{ display: "flex", alignItems: "baseline", gap: "12px", marginBottom: "20px" }}>
                <div style={{ fontFamily: "var(--font-display)", fontSize: "48px", lineHeight: 1, color: "var(--ink)" }}>
                  {e.dateNum}
                </div>
                <div>
                  <div style={{ fontFamily: "var(--font-body)", fontSize: "11px", letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--accent)" }}>
                    {e.monthKey[lang]}
                  </div>
                  <div style={{ fontFamily: "var(--font-body)", fontSize: "11px", letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--muted)", marginTop: "2px" }}>
                    {e.weekday[lang]} · {e.time}
                  </div>
                </div>
                {e.moon && (
                  <div style={{ marginLeft: "auto", color: "var(--accent)" }}>
                    <MoonIcon kind={e.moon} size={22} />
                  </div>
                )}
              </div>
              <h3 style={{ fontFamily: "var(--font-display)", fontSize: "24px", fontWeight: 400, lineHeight: 1.25, color: "var(--ink)", margin: 0 }}>
                {e.title[lang]}
              </h3>
              <p style={{ fontFamily: "var(--font-body)", fontSize: "14px", lineHeight: 1.6, color: "var(--muted)", marginTop: "12px", marginBottom: 0 }}>
                {e.body[lang]}
              </p>
              <div style={{ marginTop: "auto", paddingTop: "20px", display: "flex", gap: "12px", alignItems: "center" }}>
                {e.live && (
                  <span style={{ display: "inline-flex", alignItems: "center", gap: "6px", fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--accent)" }}>
                    <span style={{ width: "6px", height: "6px", borderRadius: "50%", background: "var(--accent)", animation: "wn-pulse 1.6s infinite" }} />
                    Live
                  </span>
                )}
                <span style={{ fontFamily: "var(--font-body)", fontSize: "12px", letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--muted)" }}>
                  {t.calendar.legendCeremony}
                </span>
              </div>
            </article>
          ))}
        </div>
      </div>
    </section>
  );
}

// ─── Temple life gallery (festivals + community) ───────────────────
function HomeLife({ t }) {
  const L = t.life;
  const [feature, ...rest] = L.items;

  const Tile = ({ item, minH }) => (
    <figure style={{ position: "relative", margin: 0, overflow: "hidden", height: "100%", minHeight: minH }}>
      <img
        src={item.img}
        alt={item.caption}
        style={{ display: "block", width: "100%", height: "100%", objectFit: "cover" }}
      />
      <figcaption style={{
        position: "absolute",
        inset: 0,
        display: "flex",
        flexDirection: "column",
        justifyContent: "flex-end",
        padding: "22px",
        background: "linear-gradient(to top, rgba(20,14,6,0.82) 0%, rgba(20,14,6,0.18) 42%, rgba(20,14,6,0) 70%)",
      }}>
        <div style={{ fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--accent)", marginBottom: "7px", display: "flex", alignItems: "center", gap: "9px" }}>
          <span style={{ width: "16px", height: "1px", background: "var(--accent)", flexShrink: 0 }} />
          {item.tag}
        </div>
        <div style={{ fontFamily: "var(--font-display)", fontSize: "clamp(16px, 1.5vw, 19px)", lineHeight: 1.3, color: "var(--bg)", letterSpacing: "-0.005em", textWrap: "pretty" }}>
          {item.caption}
        </div>
      </figcaption>
    </figure>
  );

  return (
    <section style={{ paddingTop: "120px", paddingBottom: "120px", background: "linear-gradient(180deg, var(--bg) 0%, rgba(247,231,231,0.58) 100%)" }}>
      <div className="wn-container">
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "end", marginBottom: "56px", gap: "48px", flexWrap: "wrap" }}>
          <div style={{ maxWidth: "560px" }}>
            <Eyebrow>{L.eyebrow}</Eyebrow>
            <SectionTitle size="md" style={{ whiteSpace: "pre-line" }}>{L.title}</SectionTitle>
          </div>
          <p style={{ fontFamily: "var(--font-body)", fontSize: "15px", lineHeight: 1.75, color: "var(--muted)", margin: 0, maxWidth: "420px", textWrap: "pretty" }}>
            {L.body}
          </p>
        </div>

        {/* Feature (portrait) + 3-up strip */}
        <div className="wn-r2" style={{ display: "grid", gridTemplateColumns: "minmax(0, 5fr) minmax(0, 7fr)", gap: "20px", alignItems: "stretch" }}>
          {/* Tall feature */}
          <div style={{ position: "relative" }}>
            <Tile item={feature} minH="540px" />
            <div style={{ position: "absolute", top: "-10px", left: "-10px", width: "40px", height: "40px", borderTop: "1px solid var(--accent)", borderLeft: "1px solid var(--accent)" }} />
          </div>

          {/* Right cluster: one wide on top, two below */}
          <div style={{ display: "grid", gridTemplateRows: "1.15fr 1fr", gap: "20px" }}>
            <Tile item={rest[0]} minH="240px" />
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "20px" }}>
              <Tile item={rest[1]} minH="240px" />
              <Tile item={rest[2]} minH="240px" />
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

window.HomeLife = HomeLife;

// ─── Official updates: curated highlights + Facebook page feed ─────
function HomeUpdates({ t }) {
  const u = t.updates;
  const facebookFeeds = [
    {
      label: u.feedMain,
      href: "https://www.facebook.com/watthainorway",
      src: "https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Fwatthainorway&tabs=timeline&width=360&height=520&small_header=false&adapt_container_width=true&hide_cover=false&show_facepile=false",
    },
    {
      label: u.feedBergen,
      href: "https://www.facebook.com/profile.php?id=100064747836523",
      src: "https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Fprofile.php%3Fid%3D100064747836523&tabs=timeline&width=360&height=520&small_header=false&adapt_container_width=true&hide_cover=false&show_facepile=false",
    },
  ];
  return (
    <section style={{ paddingTop: "96px", paddingBottom: "96px", background: "linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%)" }}>
      <div className="wn-container">
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "end", gap: "24px", flexWrap: "wrap", marginBottom: "38px" }}>
          <div>
            <Eyebrow>{u.eyebrow}</Eyebrow>
            <SectionTitle size="md">{u.title}</SectionTitle>
            <p style={{ fontFamily: "var(--font-body)", fontSize: "15px", lineHeight: 1.7, color: "var(--muted)", marginTop: "18px", maxWidth: "620px" }}>
              {u.body}
            </p>
          </div>
          <a href="https://www.facebook.com/watthainorway" target="_blank" rel="noopener noreferrer" style={{ background: "var(--ink)", color: "var(--bg)", border: "none", padding: "13px 22px", borderRadius: "999px", fontFamily: "var(--font-body)", fontSize: "13px", letterSpacing: "0.04em", textDecoration: "none", whiteSpace: "nowrap", display: "inline-flex", alignItems: "center", gap: "8px" }}>
            <span style={{ width: "6px", height: "6px", borderRadius: "50%", background: "var(--accent)" }} />
            {u.openFacebook} →
          </a>
        </div>

        <div className="wn-updates-layout" style={{ display: "grid", gridTemplateColumns: "0.9fr 1.35fr", gap: "34px", alignItems: "start" }}>
          <div style={{ display: "grid", gridTemplateColumns: "1fr", gap: "14px" }}>
            {u.items.map((item, i) => (
              <article key={item.title} style={{ display: "grid", gridTemplateColumns: i === 0 ? "1fr" : "168px 1fr", gap: "18px", alignItems: "stretch", border: "1px solid var(--line)", background: "var(--bg)", overflow: "hidden" }}>
                <img
                  src={item.img}
                  alt={item.title}
                  loading="lazy"
                  style={{ width: "100%", height: "100%", minHeight: i === 0 ? "250px" : "132px", objectFit: "cover", aspectRatio: i === 0 ? "16 / 9" : "4 / 3" }}
                />
                <div style={{ padding: i === 0 ? "22px 24px 24px" : "18px 18px 18px 0", display: "flex", flexDirection: "column", justifyContent: "center" }}>
                  <div style={{ fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.2em", textTransform: "uppercase", color: "var(--accent)", marginBottom: "8px" }}>
                    {item.tag}
                  </div>
                  <h3 style={{ fontFamily: "var(--font-display)", fontSize: i === 0 ? "30px" : "22px", fontWeight: 400, lineHeight: 1.16, color: "var(--ink)", margin: 0 }}>
                    {item.title}
                  </h3>
                  <p style={{ fontFamily: "var(--font-body)", fontSize: "13px", lineHeight: 1.6, color: "var(--muted)", marginTop: "8px", marginBottom: 0 }}>
                    {item.body}
                  </p>
                </div>
              </article>
            ))}
          </div>

          <div className="wn-facebook-feed-grid" style={{ display: "grid", gridTemplateColumns: "repeat(2, minmax(0, 1fr))", gap: "14px" }}>
            {facebookFeeds.map((feed) => (
              <div key={feed.label} style={{ border: "1px solid var(--line)", background: "var(--bg)", padding: "12px", boxShadow: "0 18px 48px rgba(43,33,24,0.08)", minWidth: 0 }}>
                <div style={{ fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.18em", textTransform: "uppercase", color: "var(--muted)", marginBottom: "10px", display: "flex", justifyContent: "space-between", gap: "10px" }}>
                  <span>{feed.label}</span>
                  <span>Facebook</span>
                </div>
                <div style={{ width: "100%", overflow: "hidden", background: "var(--bg-deep)" }}>
                  <iframe
                    title={`Facebook — ${feed.label}`}
                    src={feed.src}
                    width="360"
                    height="520"
                    style={{ display: "block", border: "none", width: "100%", maxWidth: "360px", margin: "0 auto" }}
                    scrolling="no"
                    frameBorder="0"
                    allowFullScreen={true}
                    allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share"
                    loading="lazy"
                  ></iframe>
                </div>
                <a href={feed.href} target="_blank" rel="noopener noreferrer" style={{ marginTop: "10px", color: "var(--nordic)", fontFamily: "var(--font-body)", fontSize: "12px", textDecoration: "none", display: "inline-flex", alignItems: "center", gap: "6px" }}>
                  {u.openFacebook} →
                </a>
              </div>
            ))}
            <p style={{ gridColumn: "1 / -1", fontFamily: "var(--font-body)", fontSize: "12px", lineHeight: 1.55, color: "var(--muted)", margin: "0 2px" }}>
              {u.facebookNote}
            </p>
          </div>
        </div>
      </div>
    </section>
  );
}

// ─── Livestream module ─────────────────────────────────────────────
function HomeLivestream({ t }) {
  const nextEvent = window.EVENT_BANK[0];
  return (
    <section style={{ paddingTop: "140px", paddingBottom: "140px" }}>
      <div className="wn-container wn-r2" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "96px", alignItems: "center" }}>
        <div style={{ position: "relative" }}>
          <div style={{ position: "relative", overflow: "hidden" }}>
            <img
              src="/assets/life/chanting.jpg"
              alt={t.locale === "th" ? "พระสงฆ์ทำวัตรสวดมนต์" : "Monks chanting during a ceremony"}
              style={{ display: "block", width: "100%", aspectRatio: "16 / 10", objectFit: "cover" }}
            />
            {/* Play button overlay */}
            <div style={{ position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center" }}>
              <div style={{ width: "84px", height: "84px", borderRadius: "999px", border: "1px solid rgba(201,162,39,0.9)", display: "flex", alignItems: "center", justifyContent: "center", backdropFilter: "blur(4px)", background: "rgba(43,29,16,0.45)" }}>
                <div style={{ width: 0, height: 0, borderTop: "12px solid transparent", borderBottom: "12px solid transparent", borderLeft: "18px solid var(--accent)", marginLeft: "5px" }} />
              </div>
            </div>
            <div style={{ position: "absolute", top: "20px", left: "20px", display: "flex", alignItems: "center", gap: "8px", padding: "6px 12px", background: "rgba(49, 90, 115, 0.9)", color: "#fff", fontFamily: "var(--font-body)", fontSize: "11px", letterSpacing: "0.22em", textTransform: "uppercase" }}>
              Facebook
            </div>
          </div>
          <div style={{ position: "absolute", top: "-12px", left: "-12px", width: "48px", height: "48px", borderTop: "1px solid var(--accent)", borderLeft: "1px solid var(--accent)" }} />
          <div style={{ position: "absolute", bottom: "-12px", right: "-12px", width: "48px", height: "48px", borderBottom: "1px solid var(--accent)", borderRight: "1px solid var(--accent)" }} />
        </div>
        <div>
          <Eyebrow>{t.livestream.eyebrow}</Eyebrow>
          <SectionTitle size="md">{t.livestream.title}</SectionTitle>
          <p style={{ fontFamily: "var(--font-body)", fontSize: "16px", lineHeight: 1.7, color: "var(--muted)", marginTop: "24px", maxWidth: "440px" }}>
            {t.livestream.body}
          </p>
          <div style={{ marginTop: "40px", padding: "24px 28px", border: "1px solid var(--line)", background: "var(--bg)", maxWidth: "440px" }}>
            <div style={{ fontFamily: "var(--font-body)", fontSize: "11px", letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--accent)", marginBottom: "8px" }}>
              {t.livestream.next}
            </div>
            <div style={{ fontFamily: "var(--font-display)", fontSize: "22px", color: "var(--ink)", lineHeight: 1.2 }}>
              {nextEvent.title[t.locale]}
            </div>
            <div style={{ fontFamily: "var(--font-body)", fontSize: "13px", color: "var(--muted)", marginTop: "6px" }}>
              {nextEvent.dateKey[t.locale]} · {nextEvent.time}
            </div>
          </div>
          <a href="https://www.facebook.com/watthainorway" target="_blank" rel="noopener noreferrer" style={{ marginTop: "32px", backgroundColor: "var(--ink)", color: "var(--bg)", border: "none", padding: "16px 28px", borderRadius: "999px", fontFamily: "var(--font-body)", fontSize: "14px", letterSpacing: "0.04em", cursor: "pointer", display: "inline-flex", alignItems: "center", gap: "10px", textDecoration: "none" }}>
            {t.livestream.watch}
          </a>
        </div>
      </div>
    </section>
  );
}

// ─── Donate teaser (compact) ──────────────────────────────────────
function HomeDonate({ t, setPage }) {
  return (
    <section style={{ paddingTop: "60px", paddingBottom: "60px", backgroundColor: "var(--ink)", color: "var(--bg)" }}>
      <div className="wn-container wn-r-donatebar" style={{ display: "grid", gridTemplateColumns: "1fr auto auto auto", gap: "32px", alignItems: "center" }}>
        <div>
          <div style={{ fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--accent)", marginBottom: "8px" }}>
            {t.donateSection.eyebrow}
          </div>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(22px, 2.2vw, 28px)", fontWeight: 400, lineHeight: 1.2, margin: 0, maxWidth: "520px" }}>
            {t.donateSection.title}
          </h2>
        </div>
        <button onClick={() => setPage("donate")} style={{ textAlign: "left", padding: "14px 22px", background: "transparent", color: "var(--bg)", border: "1px solid rgba(255,255,255,0.2)", cursor: "pointer", fontFamily: "var(--font-body)" }}>
          <div style={{ fontSize: "9px", letterSpacing: "0.22em", textTransform: "uppercase", opacity: 0.5 }}>{t.locale === "th" ? "บัญชีธนาคาร" : t.locale === "no" ? "Kontonr" : "Bank account"}</div>
          <div style={{ fontFamily: "var(--font-display)", fontSize: "20px", marginTop: "2px", fontVariantNumeric: "tabular-nums" }}>1286.44.70120</div>
        </button>
        <button onClick={() => setPage("donate")} style={{ background: "var(--accent)", color: "var(--ink)", border: "none", padding: "16px 28px", borderRadius: "999px", fontFamily: "var(--font-body)", fontSize: "13px", letterSpacing: "0.04em", cursor: "pointer", display: "inline-flex", alignItems: "center", gap: "10px", whiteSpace: "nowrap" }}>
          {t.donateSection.bankCta}
          <span>→</span>
        </button>
        <a href="mailto:donation@watthainorway.com" style={{ background: "transparent", color: "var(--bg)", border: "1px solid rgba(255,255,255,0.3)", padding: "16px 24px", borderRadius: "999px", fontFamily: "var(--font-body)", fontSize: "13px", letterSpacing: "0.04em", cursor: "pointer", whiteSpace: "nowrap", textDecoration: "none", display: "inline-flex", alignItems: "center" }}>
          {t.donateSection.emailCta}
        </a>
      </div>
    </section>
  );
}

// ─── Visit / map (compact) ─────────────────────────────────────────
function HomeVisit({ t }) {
  return (
    <section style={{ paddingTop: "32px", paddingBottom: "32px" }}>
      <div className="wn-container">
        <div style={{ border: "1px solid rgba(49,90,115,0.18)", background: "var(--nordic-soft)", padding: "22px 28px", display: "flex", alignItems: "center", justifyContent: "space-between", gap: "24px 40px", flexWrap: "wrap" }}>
          <div style={{ display: "flex", alignItems: "center", gap: "18px", flexWrap: "wrap" }}>
            <span style={{ fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--nordic)", whiteSpace: "nowrap" }}>
              {t.visit.eyebrow}
            </span>
            <span style={{ width: "1px", height: "18px", background: "var(--line)" }} />
            <address style={{ fontStyle: "normal", fontFamily: "var(--font-body)", fontSize: "14px", color: "var(--ink)", lineHeight: 1.4 }}>
              Wat Thai Norge · Trondheimsvegen 582 · 2016 Frogner
            </address>
          </div>
          <div style={{ display: "flex", alignItems: "center", gap: "20px", flexWrap: "wrap" }}>
            <a href="tel:+4763820103" style={{ color: "var(--ink)", textDecoration: "none", fontFamily: "var(--font-body)", fontSize: "14px", fontVariantNumeric: "tabular-nums", whiteSpace: "nowrap" }}>
              +47 63 82 01 03
            </a>
          </div>
        </div>
      </div>
    </section>
  );
}

// ─── Secondary actions: support + newsletter, intentionally low prominence ──
function HomeSecondaryActions({ t, setPage }) {
  const [email, setEmail] = useState("");
  const [submitted, setSubmitted] = useState(false);
  const lang = t.locale;
  return (
    <section style={{ paddingTop: "28px", paddingBottom: "34px", backgroundColor: "var(--bg)" }}>
      <div className="wn-container">
        <div className="wn-r2" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "14px", alignItems: "stretch" }}>
          <div style={{ border: "1px solid var(--line)", background: "rgba(201,162,39,0.06)", padding: "20px 22px", display: "flex", alignItems: "center", justifyContent: "space-between", gap: "18px", flexWrap: "wrap" }}>
            <div style={{ minWidth: "220px", flex: "1 1 260px" }}>
              <div style={{ fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.2em", textTransform: "uppercase", color: "var(--accent)", marginBottom: "6px" }}>
                {t.donateSection.eyebrow}
              </div>
              <div style={{ fontFamily: "var(--font-display)", fontSize: "22px", lineHeight: 1.2, color: "var(--ink)" }}>
                {lang === "th" ? "ร่วมทำบุญกับวัด" : lang === "no" ? "Vil du støtte tempelet?" : "Would you like to support the temple?"}
              </div>
              <div style={{ fontFamily: "var(--font-body)", fontSize: "13px", lineHeight: 1.55, color: "var(--muted)", marginTop: "6px" }}>
                {lang === "th" ? "ดูบัญชี วัตถุประสงค์ และวิธีขอใบเสร็จได้ที่หน้าทำบุญ" : lang === "no" ? "Se konto, formål og kvittering på gavesiden." : "See bank details, purposes and receipt information on the donation page."}
              </div>
            </div>
            <button
              onClick={() => setPage("donate")}
              style={{ background: "transparent", color: "var(--ink)", border: "1px solid rgba(201,162,39,0.45)", padding: "11px 18px", borderRadius: "999px", fontFamily: "var(--font-body)", fontSize: "13px", letterSpacing: "0.04em", cursor: "pointer", whiteSpace: "nowrap" }}
            >
              {t.nav.donate} →
            </button>
          </div>

          <form
            onSubmit={(e) => {
              e.preventDefault();
              if (!email) return;
              const subject = encodeURIComponent(lang === "th" ? "สมัครรับข่าวสารวัดไทยนอร์เวย์" : lang === "no" ? "Påmelding nyhetsbrev" : "Wat Thai Norway newsletter signup");
              const body = encodeURIComponent((lang === "th" ? "ขอสมัครรับข่าวสารของวัด ที่อีเมล: " : lang === "no" ? "Jeg ønsker å motta nyhetsbrev. E-post: " : "Please add this email to the temple newsletter: ") + email);
              window.location.href = `mailto:info@watthainorway.com?subject=${subject}&body=${body}`;
              setSubmitted(true);
            }}
            style={{ border: "1px solid var(--line)", background: "var(--bg-deep)", padding: "20px 22px", display: "flex", alignItems: "center", justifyContent: "space-between", gap: "16px", flexWrap: "wrap" }}
          >
            <div style={{ minWidth: "220px", flex: "1 1 260px" }}>
              <div style={{ fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.2em", textTransform: "uppercase", color: "var(--muted)", marginBottom: "6px" }}>
                {t.newsletter.eyebrow}
              </div>
              <div style={{ fontFamily: "var(--font-display)", fontSize: "22px", lineHeight: 1.2, color: "var(--ink)" }}>
                {t.newsletter.title}
              </div>
              <div style={{ fontFamily: "var(--font-body)", fontSize: "12px", lineHeight: 1.55, color: "var(--muted)", marginTop: "6px" }}>
                {submitted ? (lang === "th" ? "เปิดแอปอีเมลให้แล้ว กดส่งเพื่อยืนยัน" : lang === "no" ? "E-postprogrammet åpnes. Trykk send for å fullføre." : "Email app opened. Press send to confirm.") : t.newsletter.consent}
              </div>
            </div>
            <div style={{ display: "flex", alignItems: "center", gap: "8px", flex: "1 1 260px", maxWidth: "360px" }}>
              <input
                type="email"
                required
                placeholder={t.newsletter.placeholder}
                value={email}
                onChange={(e) => setEmail(e.target.value)}
                style={{ minWidth: 0, flex: 1, background: "var(--bg)", border: "1px solid var(--line)", borderRadius: "999px", outline: "none", fontFamily: "var(--font-body)", fontSize: "14px", color: "var(--ink)", padding: "12px 14px" }}
              />
              <button type="submit" style={{ background: "var(--ink)", color: "var(--bg)", border: "none", padding: "12px 16px", borderRadius: "999px", fontFamily: "var(--font-body)", fontSize: "12px", letterSpacing: "0.04em", cursor: "pointer", whiteSpace: "nowrap" }}>
                {submitted ? "✓" : t.newsletter.submit}
              </button>
            </div>
          </form>
        </div>
      </div>
    </section>
  );
}

function MapPanel() {
  return (
    <div style={{ position: "relative", aspectRatio: "5 / 4", background: "#ece7df", overflow: "hidden", border: "1px solid var(--line)" }}>
      <svg viewBox="0 0 500 400" style={{ position: "absolute", inset: 0, width: "100%", height: "100%" }}>
        {/* River */}
        <path d="M 0,120 Q 120,90 200,160 T 500,200" stroke="#cfd7d5" strokeWidth="22" fill="none" strokeLinecap="round" opacity="0.7" />
        {/* Roads */}
        <g stroke="#d3ccba" strokeWidth="2" fill="none">
          <path d="M 0,80 L 500,90" />
          <path d="M 0,260 L 500,250" />
          <path d="M 0,340 L 500,330" />
          <path d="M 80,0 L 90,400" />
          <path d="M 220,0 L 230,400" />
          <path d="M 380,0 L 370,400" />
        </g>
        {/* Sub roads */}
        <g stroke="#dcd5c3" strokeWidth="1" fill="none">
          <path d="M 0,170 L 500,170" />
          <path d="M 0,210 L 500,210" />
          <path d="M 150,0 L 150,400" />
          <path d="M 300,0 L 300,400" />
        </g>
        {/* Park */}
        <rect x="320" y="100" width="100" height="80" fill="#dde4d3" />
        {/* Buildings */}
        <g fill="#c8c1ad">
          <rect x="100" y="100" width="40" height="40" />
          <rect x="160" y="280" width="40" height="40" />
          <rect x="240" y="100" width="30" height="50" />
          <rect x="400" y="220" width="60" height="50" />
        </g>
        {/* Temple marker */}
        <g transform="translate(250,200)">
          <circle r="22" fill="var(--accent)" opacity="0.18" />
          <circle r="12" fill="var(--accent)" opacity="0.32" />
          <circle r="5" fill="var(--accent)" />
        </g>
      </svg>
      <div style={{ position: "absolute", bottom: "20px", left: "20px", padding: "12px 16px", background: "var(--bg)", border: "1px solid var(--line)", display: "flex", alignItems: "center", gap: "12px" }}>
        <span style={{ width: "10px", height: "10px", borderRadius: "50%", background: "var(--accent)" }} />
        <div>
          <div style={{ fontFamily: "var(--font-display)", fontSize: "14px", color: "var(--ink)" }}>Wat Thai Norge</div>
          <div style={{ fontFamily: "var(--font-body)", fontSize: "11px", color: "var(--muted)", letterSpacing: "0.08em", textTransform: "uppercase" }}>Trondheimsvegen 582 · Frogner</div>
        </div>
      </div>
      <div style={{ position: "absolute", top: "20px", right: "20px", display: "flex", flexDirection: "column", gap: "6px" }}>
        {["+", "−"].map((s) => (
          <div key={s} style={{ width: "32px", height: "32px", background: "var(--bg)", border: "1px solid var(--line)", display: "flex", alignItems: "center", justifyContent: "center", fontFamily: "var(--font-body)", color: "var(--ink)", fontSize: "16px" }}>
            {s}
          </div>
        ))}
      </div>
      <div style={{ position: "absolute", top: "16px", left: "16px", fontFamily: "var(--font-body)", fontSize: "10px", letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--muted)" }}>
        N ↑
      </div>
    </div>
  );
}

// ─── Newsletter ─────────────────────────────────────────────────────
function HomeNewsletter({ t }) {
  const [email, setEmail] = useState("");
  const [submitted, setSubmitted] = useState(false);
  const lang = t.locale;
  return (
    <section style={{ paddingTop: "80px", paddingBottom: "0", backgroundColor: "var(--bg-deep)" }}>
      <div className="wn-container" style={{ paddingTop: "100px", paddingBottom: "100px", borderTop: "1px solid var(--line)", borderBottom: "1px solid var(--line)" }}>
        <div className="wn-r2" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "64px", alignItems: "center" }}>
          <div>
            <Eyebrow>{t.newsletter.eyebrow}</Eyebrow>
            <SectionTitle size="md">{t.newsletter.title}</SectionTitle>
            <p style={{ fontFamily: "var(--font-body)", fontSize: "15px", lineHeight: 1.7, color: "var(--muted)", marginTop: "24px", maxWidth: "440px" }}>
              {t.newsletter.body}
            </p>
          </div>
          <form
            onSubmit={(e) => {
              e.preventDefault();
              if (!email) return;
              const subject = encodeURIComponent(lang === "th" ? "สมัครรับข่าวสารวัดไทยนอร์เวย์" : lang === "no" ? "Påmelding nyhetsbrev" : "Wat Thai Norway newsletter signup");
              const body = encodeURIComponent((lang === "th" ? "ขอสมัครรับข่าวสารของวัด ที่อีเมล: " : lang === "no" ? "Jeg ønsker å motta nyhetsbrev. E-post: " : "Please add this email to the temple newsletter: ") + email);
              window.location.href = `mailto:info@watthainorway.com?subject=${subject}&body=${body}`;
              setSubmitted(true);
            }}
            style={{ display: "flex", flexDirection: "column", gap: "16px" }}
          >
            <div style={{ display: "flex", borderBottom: "1px solid var(--ink)", paddingBottom: "12px" }}>
              <input
                type="email"
                required
                placeholder={t.newsletter.placeholder}
                value={email}
                onChange={(e) => setEmail(e.target.value)}
                style={{ flex: 1, background: "transparent", border: "none", outline: "none", fontFamily: "var(--font-body)", fontSize: "18px", color: "var(--ink)", padding: "10px 0" }}
              />
              <button type="submit" style={{ background: "var(--ink)", color: "var(--bg)", border: "none", padding: "10px 24px", borderRadius: "999px", fontFamily: "var(--font-body)", fontSize: "13px", letterSpacing: "0.04em", cursor: "pointer" }}>
                {submitted ? "✓" : t.newsletter.submit}
              </button>
            </div>
            <div style={{ fontFamily: "var(--font-body)", fontSize: "12px", color: "var(--muted)" }}>
              {submitted ? "✓ " + (lang === "th" ? "เปิดแอปอีเมลให้แล้ว - กดส่งเพื่อยืนยันการสมัคร" : lang === "no" ? "E-postprogrammet åpnes - trykk send for å fullføre." : "Email app opened - press send to confirm.") : t.newsletter.consent}
            </div>
          </form>
        </div>
      </div>
    </section>
  );
}

window.HomePage = HomePage;
