// Home page — full of sections like a slide deck
const { useEffect: useEffectH, useState: useStateH, useRef: useRefH } = React;

function HomePage() {
  const { t } = useLang();
  const { setRoute } = useRoute();
  const h = t.home;

  return (
    <div>
      <HeroSection />
      <WhySection />
      <ServicesSection />
      <AdvantageSection />
      <ImpactSection />
      <CaseSection />
      <CTASection />
    </div>
  );
}

// ───────────────────────── HERO ─────────────────────────
// Helper: split text into per-character spans with staggered animation.
function KineticLine({ text, baseDelay = 0, perChar = 28, className = "", style = {} }) {
  const words = text.split(" ");
  let charIndex = 0;
  return (
    <span className={"kinetic-line " + className} style={style}>
      {words.map((word, wordIndex) => (
        <span key={wordIndex} className="kinetic-word">
          {word.split("").map((ch) => {
            const delay = baseDelay + charIndex * perChar;
            charIndex += 1;
            return (
              <span
                key={`${wordIndex}-${charIndex}`}
                className="ch"
                style={{ animationDelay: `${delay}ms` }}
              >
                {ch}
              </span>
            );
          })}
          {wordIndex < words.length - 1 ? <span className="kinetic-space">&nbsp;</span> : null}
        </span>
      ))}
    </span>
  );
}
// Helper: rotating word that cycles through a list, with in/out animation.
function RotatingWord({ words, interval = 2800, className = "", style = {} }) {
  const [idx, setIdx] = useStateH(0);
  const [phase, setPhase] = useStateH("in"); // "in" -> "out" -> swap -> "in"
  useEffectH(() => {
    let outTimer, swapTimer;
    const loop = setInterval(() => {
      setPhase("out");
      outTimer = setTimeout(() => {
        setIdx(i => (i + 1) % words.length);
        setPhase("in");
      }, 420);
    }, interval);
    return () => { clearInterval(loop); clearTimeout(outTimer); clearTimeout(swapTimer); };
  }, [words.length, interval]);
  return (
    <span className={"word-rotator " + className} style={style}>
      <span className={"wr-slot wr-" + phase} key={idx + "-" + phase}>{words[idx]}</span>
    </span>
  );
}

function HeroSection() {
  const { t, lang } = useLang();
  const { setRoute } = useRoute();
  const h = t.home;
  const [pointer, setPointer] = useStateH({ x: 0, y: 0 });

  const handleMove = (event) => {
    const rect = event.currentTarget.getBoundingClientRect();
    const x = ((event.clientX - rect.left) / rect.width - 0.5) * 12;
    const y = ((event.clientY - rect.top) / rect.height - 0.5) * 8;
    setPointer({ x, y });
  };

  return (
    <section
      className="ewv-hero"
      onMouseMove={handleMove}
      onMouseLeave={() => setPointer({ x: 0, y: 0 })}
      style={{
        position: "relative",
        minHeight: "94svh",
        background: "var(--graphite)",
        color: "var(--ivory)",
        overflow: "hidden",
        "--mx": `${pointer.x}px`,
        "--my": `${pointer.y}px`,
      }}
    >
      <HeroIntro />

      <div style={{ position: "absolute", inset: 0 }}>
        <HeroImage />
      </div>

      <div className="ewv-hero-edge" style={{
        position: "absolute", left: 24, top: "50%",
        transform: "translateY(-50%) rotate(-90deg)", transformOrigin: "left top",
        fontSize: 10, letterSpacing: "0.34em", textTransform: "uppercase",
        color: "rgba(242,239,232,0.42)", whiteSpace: "nowrap",
      }}>
        EW / VG / STRATEGY SYSTEM {new Date().getFullYear()}
      </div>

      <div className="ewv-hero-content" style={{
        position: "relative", zIndex: 2,
        maxWidth: 1440, margin: "0 auto",
        padding: "132px 80px 42px",
        minHeight: "94svh",
        display: "grid",
        gridTemplateRows: "1fr auto",
        gap: 40,
      }}>
        <div className="ewv-hero-title-wrap" style={{
          display: "grid",
          gridTemplateColumns: "minmax(0, 0.98fr) minmax(280px, 0.72fr)",
          gap: 72,
          alignItems: "center",
        }}>
          <div style={{ maxWidth: 760 }}>
            <div className="hero-text-shadow-soft" style={{
              display: "flex", alignItems: "center", gap: 16,
              fontSize: 11, letterSpacing: "0.24em", textTransform: "uppercase",
              color: "rgba(242,239,232,0.76)", marginBottom: 30,
            }}>
              <span className="eyebrow-line-anim" />
              <span style={{ opacity: 0, animation: "fadeIn 0.7s ease 0.55s forwards" }}>{h.eyebrow}</span>
            </div>

            <h1 className="serif ewv-hero-title hero-text-shadow" style={{
              margin: 0,
              fontSize: lang === "zh" ? "clamp(46px, 6vw, 86px)" : "clamp(50px, 6.3vw, 96px)",
              lineHeight: 0.98,
              fontWeight: 400,
              letterSpacing: 0,
            }}>
              <span style={{ display: "block", color: "var(--ivory)" }}>
                <KineticLine text={h.heroTitle[0]} baseDelay={360} perChar={18} />
              </span>
              <span style={{ display: "block", fontStyle: "italic", color: "rgba(242,239,232,0.9)" }}>
                <KineticLine text={h.heroTitle[1]} baseDelay={760} perChar={20} />
              </span>
              <span className="gold-underline" />
              <span style={{ display: "block", color: "rgba(242,239,232,0.96)", marginTop: 8 }}>
                <KineticLine text={h.heroTitle[2]} baseDelay={1180} perChar={18} />
              </span>
            </h1>
          </div>

          <Reveal delay={1450}>
            <div className="ewv-hero-sub-wrap" style={{
              maxWidth: 450,
              paddingLeft: 30,
              borderLeft: "1px solid rgba(242,239,232,0.24)",
            }}>
              <div className="ewv-hero-sub hero-text-shadow-soft" style={{
                fontSize: 12, letterSpacing: "0.18em", textTransform: "uppercase",
                color: "rgba(242,239,232,0.78)", marginBottom: 18, fontWeight: 600,
              }}>{h.heroSub}</div>
              <p className="ewv-hero-desc hero-text-shadow-soft" style={{
                fontSize: 16, lineHeight: 1.7,
                color: "rgba(242,239,232,0.82)",
                margin: 0,
              }}>{h.heroDesc}</p>
              <div className="ewv-hero-actions" style={{ marginTop: 34, display: "flex", gap: 14, alignItems: "center", flexWrap: "wrap" }}>
                <button onClick={() => setRoute("contact")}
                  style={{
                    padding: "14px 24px", fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase",
                    background: "var(--ivory)", color: "var(--navy)",
                    fontWeight: 700,
                    border: "1px solid var(--ivory)",
                    transition: "all 200ms",
                  }}
                  onMouseEnter={e => { e.currentTarget.style.background = "transparent"; e.currentTarget.style.color = "var(--ivory)"; }}
                  onMouseLeave={e => { e.currentTarget.style.background = "var(--ivory)"; e.currentTarget.style.color = "var(--navy)"; }}>
                  {t.cta.book} -&gt;
                </button>
                <button onClick={() => setRoute("services")}
                  style={{
                    padding: "14px 22px", fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase",
                    background: "rgba(242,239,232,0.04)", color: "var(--ivory)",
                    border: "1px solid rgba(242,239,232,0.24)",
                    transition: "all 200ms",
                  }}
                  onMouseEnter={e => { e.currentTarget.style.borderColor = "rgba(242,239,232,0.76)"; }}
                  onMouseLeave={e => { e.currentTarget.style.borderColor = "rgba(242,239,232,0.24)"; }}>
                  {t.nav.services}
                </button>
              </div>
            </div>
          </Reveal>
        </div>

        <Reveal delay={1700}>
          <div className="ewv-hero-meta" style={{
            display: "grid",
            gridTemplateColumns: "repeat(3, minmax(0, 1fr)) auto",
            gap: 24,
            paddingTop: 22,
            borderTop: "1px solid rgba(242,239,232,0.18)",
            color: "rgba(242,239,232,0.64)",
          }}>
            {h.heroMeta.map((item, i) => (
              <div key={i} style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase" }}>{item}</div>
            ))}
            <div className="ewv-hero-scroll" style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "rgba(242,239,232,0.52)" }}>
              {t.cta.scroll}
            </div>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

function HeroIntro() {
  return (
    <div className="ewv-intro-curtain" aria-hidden style={{
      position: "absolute", inset: 0, zIndex: 20,
      background: "linear-gradient(90deg, rgba(17,22,26,0.98), rgba(26,32,36,0.96))",
      pointerEvents: "none",
      display: "grid", placeItems: "center",
    }}>
      <div style={{
        width: "min(760px, 84vw)",
        display: "grid",
        placeItems: "center",
        textAlign: "center",
      }}>
        <div className="ewv-intro-word serif" style={{
          fontSize: "clamp(28px, 5vw, 62px)", lineHeight: 1,
          color: "var(--ivory)", fontWeight: 400,
        }}>Eastwest Vanguard</div>
        <div className="ewv-intro-rule" style={{
          height: 1, width: "min(560px, 78vw)", margin: "22px auto 0",
          background: "linear-gradient(90deg, rgba(242,239,232,0), rgba(242,239,232,0.88), rgba(183,163,109,0.2))",
        }} />
      </div>
    </div>
  );
}
function WhySection() {
  const { t } = useLang();
  const h = t.home;
  return (
    <section className="ewv-section-pad" style={{
      background: "var(--paper)", padding: "140px 0",
      position: "relative", overflow: "hidden",
    }}>
      {/* Right-edge gilded landscape decoration — more visible */}
      <div aria-hidden style={{
        position: "absolute", right: 0, top: "12%",
        width: "38%", height: "72%",
        backgroundImage: "url('uploads/ewv-tea-studio-luxury.png')",
        backgroundSize: "cover",
        backgroundPosition: "center",
        opacity: 0.16,
        filter: "saturate(0.55) contrast(0.95)",
        pointerEvents: "none",
        maskImage: "linear-gradient(90deg, transparent 0%, black 48%, black 100%)",
        WebkitMaskImage: "linear-gradient(90deg, transparent 0%, black 48%, black 100%)",
      }} />
      {/* Subtle gold accent dot pattern at top */}
      <div aria-hidden style={{
        position: "absolute", left: "8%", top: "10%", width: 260, height: 1,
        background: "linear-gradient(90deg, rgba(183,163,109,0.55), rgba(183,163,109,0))",
        pointerEvents: "none",
      }} />
      <div className="ewv-container" style={{ maxWidth: 1440, margin: "0 auto", padding: "0 80px", position: "relative" }}>
        <Reveal>
          <div className="ewv-section-head" style={{
            display: "grid", gridTemplateColumns: "1fr 1.4fr", gap: 80,
            paddingBottom: 64, alignItems: "end",
          }}>
            <div>
              <SectionEyebrow color="var(--rust)">{h.whySection}</SectionEyebrow>
              <h2 className="serif" style={{
                fontSize: "clamp(40px, 4.6vw, 64px)", lineHeight: 1.04,
                margin: "20px 0 0", fontWeight: 400, letterSpacing: 0,
                color: "var(--text-strong)",
              }}>{h.whyTitle}</h2>
            </div>
            <p className="ewv-section-lead" style={{
              fontSize: 18, lineHeight: 1.55,
              color: "var(--text-mute)", margin: 0, maxWidth: 540,
            }}>{h.whyDesc}</p>
          </div>
        </Reveal>

        <Divider />

        <div>
          {h.whyItems.map((it, i) => (
            <Reveal key={i} delay={i * 80}>
              <WhyRow item={it} last={i === h.whyItems.length - 1} />
            </Reveal>
          ))}
        </div>
      </div>
    </section>
  );
}

function WhyRow({ item, last }) {
  const [hover, setHover] = useState(false);
  return (
    <div
      className="ewv-why-row"
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        display: "grid",
        gridTemplateColumns: "auto 1fr 1.4fr auto",
        gap: 48, padding: "36px 0",
        borderBottom: last ? "none" : "1px solid var(--line)",
        alignItems: "baseline",
        cursor: "pointer",
        transition: "background 200ms, margin-left 200ms",
        background: hover ? "rgba(201,162,74,0.04)" : "transparent",
        marginLeft: hover ? 12 : 0,
      }}>
      <div className="serif mono-num ewv-why-num" style={{
        fontSize: 24, color: "var(--gold)", letterSpacing: "0.04em",
        minWidth: 60,
      }}>{item.n}</div>
      <h3 className="serif ewv-why-title" style={{
        fontSize: "clamp(22px, 2.2vw, 30px)", lineHeight: 1.15,
        margin: 0, fontWeight: 500, letterSpacing: 0,
        color: "var(--text-strong)",
      }}>{item.t}</h3>
      <p className="ewv-why-desc" style={{
        fontSize: 15, lineHeight: 1.6,
        color: "var(--text-mute)", margin: 0,
      }}>{item.d}</p>
      <div className="ewv-why-arrow" style={{
        fontSize: 18, color: "var(--gold)",
        transform: hover ? "translateX(6px)" : "translateX(0)",
        transition: "transform 200ms",
      }}>→</div>
    </div>
  );
}

// ───────────────────────── SERVICES ─────────────────────────
function ServicesSection() {
  const { t } = useLang();
  const { setRoute } = useRoute();
  const h = t.home;
  const parRef = useParallax(18);
  return (
    <section className="ewv-section-pad" style={{
      background: "var(--navy)", color: "var(--ivory)", padding: "140px 0",
      position: "relative", overflow: "hidden",
    }}>
      {/* Cross-sea bridge silhouette — narrow band in the clean bottom area, never under cards/text */}
      <div aria-hidden ref={parRef} style={{
        position: "absolute", left: 0, right: 0, bottom: "-8%", height: "34%",
        backgroundImage: "url('uploads/ewv-bridge-luxury.png')",
        backgroundSize: "cover",
        backgroundPosition: "center 55%",
        opacity: 0.24,
        filter: "saturate(0.7) contrast(1.04)",
        pointerEvents: "none", willChange: "transform",
        maskImage: "linear-gradient(180deg, transparent 0%, black 30%, black 100%)",
        WebkitMaskImage: "linear-gradient(180deg, transparent 0%, black 30%, black 100%)",
      }} />
      {/* Warm corner glow (east) */}
      <div aria-hidden style={{
        position: "absolute", right: "-8%", top: "-8%", width: "55%", height: "60%",
        background: "linear-gradient(135deg, rgba(183,163,109,0.14) 0%, rgba(183,163,109,0) 48%)",
        pointerEvents: "none",
      }} />
      {/* Cool corner glow (west) */}
      <div aria-hidden style={{
        position: "absolute", left: "-8%", bottom: "0%", width: "55%", height: "55%",
        background: "linear-gradient(45deg, rgba(110,131,125,0.16) 0%, rgba(110,131,125,0) 50%)",
        pointerEvents: "none",
      }} />
      <div className="ewv-container" style={{ maxWidth: 1440, margin: "0 auto", padding: "0 80px", position: "relative" }}>
        <Reveal>
          <div className="ewv-section-head" style={{
            display: "grid", gridTemplateColumns: "1fr 1.4fr", gap: 80,
            paddingBottom: 80, alignItems: "end",
          }}>
            <div>
              <SectionEyebrow color="var(--gold)">{h.servicesSection}</SectionEyebrow>
              <h2 className="serif" style={{
                fontSize: "clamp(40px, 4.6vw, 64px)", lineHeight: 1.04,
                margin: "20px 0 0", fontWeight: 400, letterSpacing: 0,
                color: "var(--ivory)",
              }}>{h.servicesTitle}</h2>
            </div>
            <p className="ewv-section-lead" style={{
              fontSize: 18, lineHeight: 1.55,
              color: "rgba(245,239,227,0.72)", margin: 0, maxWidth: 540,
            }}>{h.servicesDesc}</p>
          </div>
        </Reveal>

        <div className="ewv-services-grid" style={{
          display: "grid", gridTemplateColumns: "repeat(2, 1fr)",
          gap: "1px", background: "rgba(245,239,227,0.16)",
          border: "1px solid rgba(245,239,227,0.16)",
        }}>
          {h.services.map((svc, i) => (
            <Reveal key={i} delay={i * 100}>
              <ServiceCard svc={svc} idx={i + 1} />
            </Reveal>
          ))}
        </div>

        <Reveal delay={400}>
          <div style={{ marginTop: 56, display: "flex", justifyContent: "center" }}>
            <button onClick={() => setRoute("services")}
              style={{
                padding: "14px 26px", fontSize: 12, letterSpacing: "0.14em", textTransform: "uppercase",
                background: "transparent", color: "var(--ivory)",
                border: "1px solid rgba(245,239,227,0.4)",
              }}>{t.cta.learn} →</button>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

function ServiceCard({ svc, idx }) {
  const { t } = useLang();
  const [hover, setHover] = useState(false);
  return (
    <div
      className="ewv-service-card"
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        padding: "48px 44px",
        background: hover ? "rgba(110,131,125,0.12)" : "rgba(26,32,36,0.94)",
        transition: "background 240ms, transform 240ms",
        transform: hover ? "translateY(-2px)" : "translateY(0)",
        minHeight: 320,
        display: "flex", flexDirection: "column",
      }}>
      <div style={{
        display: "flex", justifyContent: "space-between", alignItems: "center",
        marginBottom: 28, paddingBottom: 20,
        borderBottom: "1px solid rgba(245,239,227,0.16)",
      }}>
        <div className="serif mono-num" style={{ fontSize: 16, color: "var(--gold)", letterSpacing: "0.08em" }}>
          0{idx} / 04
        </div>
        <div style={{ fontSize: 11, letterSpacing: "0.2em", color: "rgba(245,239,227,0.5)" }}>
          {hover ? `${t.cta.engage} →` : ""}
        </div>
      </div>
      <h3 className="serif" style={{
        fontSize: "clamp(28px, 2.8vw, 38px)", lineHeight: 1.1,
        margin: "0 0 24px", fontWeight: 500, letterSpacing: 0,
      }}>{svc.k}</h3>
      <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "grid", gap: 10, marginTop: "auto" }}>
        {svc.items.map((it, j) => (
          <li key={j} style={{
            fontSize: 14, color: "rgba(245,239,227,0.78)",
            paddingLeft: 18, position: "relative",
          }}>
            <span style={{
              position: "absolute", left: 0, top: "0.7em",
              width: 8, height: 1, background: "var(--gold)",
            }} />
            {it}
          </li>
        ))}
      </ul>
    </div>
  );
}

// ───────────────────────── ADVANTAGE ─────────────────────────
function AdvantageSection() {
  const { t, lang } = useLang();
  const h = t.home;
  return (
    <section className="ewv-section-pad" style={{
      background: "linear-gradient(180deg, var(--paper) 0%, #EEF1ED 100%)", color: "var(--text-strong)",
      padding: "160px 0", position: "relative", overflow: "hidden",
    }}>
      {/* Modern ink wash — subtle full-section texture */}
      <div aria-hidden style={{
        position: "absolute", inset: 0,
        backgroundImage: "url('uploads/ink-modern.jpg')",
        backgroundSize: "cover", backgroundPosition: "center",
        opacity: 0.07,
        mixBlendMode: "multiply",
        pointerEvents: "none",
      }} />
      {/* Decorative giant numeral */}
      <div className="serif ewv-adv-decor" style={{
        position: "absolute", right: -40, top: -60,
        fontSize: 520, lineHeight: 1, color: "rgba(110,131,125,0.08)",
        fontStyle: "italic", pointerEvents: "none", fontWeight: 400,
      }}>4</div>

      <div className="ewv-container" style={{ maxWidth: 1440, margin: "0 auto", padding: "0 80px", position: "relative" }}>
        <div className="ewv-adv-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1.2fr", gap: 100, alignItems: "start" }}>
          <Reveal>
            <div>
              <SectionEyebrow color="var(--rust)">{h.advSection}</SectionEyebrow>
              <h2 className="serif" style={{
                fontSize: "clamp(44px, 5.2vw, 76px)", lineHeight: 1, margin: "20px 0 32px",
                fontWeight: 400, letterSpacing: 0,
              }}>
                {lang === "zh" ? (
                  <React.Fragment>
                    <span>我们的</span>
                    <span style={{ fontStyle: "italic", color: "var(--gold)" }}>独特</span>
                    <br />优势。
                  </React.Fragment>
                ) : (
                  <React.Fragment>
                    <span>Our </span>
                    <span style={{ fontStyle: "italic", color: "var(--gold)" }}>unique</span>
                    <br />advantage.
                  </React.Fragment>
                )}
              </h2>
              <p style={{ fontSize: 18, lineHeight: 1.55, color: "var(--text-mute)", maxWidth: 460, margin: 0 }}>
                {h.advLead}
              </p>
            </div>
          </Reveal>

          <Reveal delay={200}>
            <div>
              <div className="ewv-adv-inner" style={{
                display: "grid", gridTemplateColumns: "1fr 1fr",
                gap: 1, background: "var(--line)",
                border: "1px solid var(--line)",
              }}>
                {h.advItems.map((item, i) => (
                  <div key={i} className="ewv-adv-item" style={{
                    background: "rgba(248,246,241,0.88)",
                    padding: "40px 32px",
                    minHeight: 160,
                    display: "flex", flexDirection: "column", justifyContent: "space-between",
                  }}>
                    <div className="serif mono-num" style={{
                      fontSize: 14, color: "var(--gold)", letterSpacing: "0.1em",
                    }}>0{i + 1}</div>
                    <div className="serif ewv-adv-item-title" style={{
                      fontSize: "clamp(22px, 2.2vw, 30px)",
                      lineHeight: 1.1, fontWeight: 500,
                      color: "var(--text-strong)", letterSpacing: 0,
                    }}>{item}</div>
                  </div>
                ))}
              </div>
              <p className="serif ewv-adv-foot" style={{
                marginTop: 36, fontSize: 16, lineHeight: 1.6,
                color: "var(--text)", maxWidth: 560,
                fontStyle: "italic",
              }}>"{h.advFoot}"</p>
            </div>
          </Reveal>
        </div>
      </div>
    </section>
  );
}

// ───────────────────────── IMPACT ─────────────────────────
function ImpactSection() {
  const { t } = useLang();
  const h = t.home;
  const parRef = useParallax(34);
  return (
    <section className="ewv-section-pad" style={{
      background: "linear-gradient(180deg, #1A2024 0%, #11161A 100%)",
      color: "var(--ivory)", padding: "160px 0",
      position: "relative", overflow: "hidden",
    }}>
      {/* Distant night-market lantern photograph as base atmosphere */}
      <div aria-hidden ref={parRef} style={{
        position: "absolute", left: 0, right: 0, top: "-10%", height: "120%",
        backgroundImage: "url('uploads/ewv-case-forum-luxury.jpg')",
        backgroundSize: "cover", backgroundPosition: "center",
        opacity: 0.34,
        filter: "grayscale(0.2) brightness(0.96) saturate(0.62)",
        pointerEvents: "none", willChange: "transform",
      }} />
      {/* Auspicious clouds at top */}
      <div aria-hidden style={{
        position: "absolute", left: 0, right: 0, top: 0, height: "35%",
        backgroundImage: "url('uploads/clouds.jpg')",
        backgroundSize: "cover", backgroundPosition: "center top",
        opacity: 0.04,
        pointerEvents: "none",
        maskImage: "linear-gradient(180deg, black 0%, transparent 100%)",
        WebkitMaskImage: "linear-gradient(180deg, black 0%, transparent 100%)",
      }} />
      {/* Lighter navy tint — let warmth come through */}
      <div aria-hidden style={{
        position: "absolute", inset: 0,
        background: "linear-gradient(180deg, rgba(17,22,26,0.60) 0%, rgba(17,22,26,0.78) 100%)",
        pointerEvents: "none",
      }} />
      {/* Lantern dots — kept on top of imagery for sparkle */}
      <div style={{ display: "none", position: "absolute", inset: 0, pointerEvents: "none" }}>
        {Array.from({ length: 30 }).map((_, i) => {
          const x = (i * 137) % 100;
          const y = (i * 73) % 100;
          const s = 1 + ((i * 17) % 3);
          return <div key={i} style={{
            position: "absolute", left: `${x}%`, top: `${y}%`,
            width: s, height: s, borderRadius: "50%",
            background: "var(--gold)", opacity: 0.3 + ((i * 7) % 60) / 100,
          }} />;
        })}
      </div>

      <div className="ewv-container" style={{ maxWidth: 1440, margin: "0 auto", padding: "0 80px", position: "relative" }}>
        <Reveal>
          <div style={{ textAlign: "center", marginBottom: 96 }}>
            <SectionEyebrow color="var(--gold)">{h.impactSection}</SectionEyebrow>
            <h2 className="serif" style={{
              fontSize: "clamp(40px, 5vw, 72px)", lineHeight: 1.04,
              margin: "24px auto 24px", fontWeight: 400, letterSpacing: 0,
              maxWidth: 1000,
            }}>{h.impactTitle}</h2>
            <p style={{
              fontSize: 17, lineHeight: 1.6,
              color: "rgba(245,239,227,0.74)",
              maxWidth: 720, margin: "0 auto",
            }}>{h.impactDesc}</p>
          </div>
        </Reveal>

        <div className="ewv-impact-stats" style={{
          display: "grid", gridTemplateColumns: "repeat(4, 1fr)",
          gap: 48,
          paddingTop: 56,
          borderTop: "1px solid rgba(245,239,227,0.2)",
        }}>
          {h.impactStats.map((s, i) => (
            <Reveal key={i} delay={i * 120}>
              <div style={{ textAlign: "left" }}>
                <NumberDisplay value={s.n} />
                <div style={{
                  marginTop: 16, fontSize: 13, lineHeight: 1.4,
                  color: "rgba(245,239,227,0.7)",
                  letterSpacing: "0.04em",
                  maxWidth: 220,
                }}>{s.l}</div>
              </div>
            </Reveal>
          ))}
        </div>
      </div>
    </section>
  );
}

// ───────────────────────── CASE STUDIES ─────────────────────────
function CaseSection() {
  const { t } = useLang();
  const { setRoute } = useRoute();
  const h = t.home;
  return (
    <section className="ewv-section-pad" style={{ background: "var(--paper)", padding: "140px 0" }}>
      <div className="ewv-container" style={{ maxWidth: 1440, margin: "0 auto", padding: "0 80px" }}>
        <Reveal>
          <div className="ewv-section-head" style={{
            display: "grid", gridTemplateColumns: "1fr 1.4fr", gap: 80,
            paddingBottom: 64, alignItems: "end",
          }}>
            <div>
              <SectionEyebrow color="var(--rust)">{h.caseSection}</SectionEyebrow>
              <h2 className="serif" style={{
                fontSize: "clamp(40px, 4.6vw, 64px)", lineHeight: 1.04,
                margin: "20px 0 0", fontWeight: 400, letterSpacing: 0,
                color: "var(--text-strong)",
              }}>{h.caseTitle}</h2>
            </div>
            <p className="ewv-section-lead" style={{
              fontSize: 18, lineHeight: 1.55,
              color: "var(--text-mute)", margin: 0, maxWidth: 460,
            }}>{h.caseDesc}</p>
          </div>
        </Reveal>

        <div className="ewv-cases-grid" style={{
          display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 24,
        }}>
          {h.cases.map((c, i) => (
            <Reveal key={i} delay={i * 80}>
              <CaseCard c={c} idx={i} />
            </Reveal>
          ))}
        </div>

        <Reveal delay={400}>
          <div style={{ marginTop: 56, display: "flex", justifyContent: "center" }}>
            <button onClick={() => setRoute("cases")}
              style={{
                padding: "14px 26px", fontSize: 12, letterSpacing: "0.14em", textTransform: "uppercase",
                background: "transparent", color: "var(--navy)",
                border: "1px solid var(--navy)",
              }}>{t.cta.learn} →</button>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

function CaseCard({ c, idx }) {
  const [hover, setHover] = useState(false);
  // Real photo per case + tonal gradient overlay for color rhythm
  const images = [
    { img: "uploads/ewv-case-restaurant-luxury.jpg", tint: "linear-gradient(180deg, rgba(17,22,26,0.02) 0%, rgba(17,22,26,0.36) 100%)" },
    { img: "uploads/ewv-case-retail-luxury.jpg", tint: "linear-gradient(180deg, rgba(17,22,26,0.04) 0%, rgba(110,131,125,0.32) 100%)" },
    { img: "uploads/ewv-case-culture-luxury.jpg", tint: "linear-gradient(180deg, rgba(17,22,26,0.02) 0%, rgba(124,70,64,0.28) 100%)" },
    { img: "uploads/ewv-case-forum-luxury.jpg", tint: "linear-gradient(180deg, rgba(17,22,26,0.04) 0%, rgba(17,22,26,0.34) 100%)" },
  ];
  const visual = images[idx % images.length];
  return (
    <div
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        border: "1px solid var(--line)",
        background: "var(--paper)",
        transition: "transform 220ms, box-shadow 220ms",
        transform: hover ? "translateY(-6px)" : "translateY(0)",
        boxShadow: hover ? "0 24px 40px -20px rgba(10,24,48,0.22)" : "none",
        cursor: "pointer",
        overflow: "hidden",
      }}>
      {/* Visual */}
      <div className="ewv-case-visual" style={{
        height: 220, position: "relative", overflow: "hidden",
        background: "var(--navy)",
      }}>
        <div style={{
          position: "absolute", inset: 0,
          backgroundImage: `url('${visual.img}')`,
          backgroundSize: "cover",
          backgroundPosition: "center",
          filter: "saturate(0.74) contrast(1.03)",
          transform: hover ? "scale(1.06)" : "scale(1)",
          transition: "transform 600ms cubic-bezier(.2,.7,.2,1)",
        }} />
        <div style={{
          position: "absolute", inset: 0,
          background: visual.tint,
        }} />
        <div style={{
          position: "absolute", left: 20, top: 20,
          fontSize: 10, letterSpacing: "0.22em", textTransform: "uppercase",
          color: "rgba(255,255,255,0.95)",
          padding: "5px 10px", border: "1px solid rgba(255,255,255,0.55)",
          backdropFilter: "blur(4px)",
          background: "rgba(10,24,48,0.18)",
        }}>{c.tag}</div>
        <div className="serif mono-num" style={{
          position: "absolute", right: 20, bottom: 16,
          fontSize: 48, lineHeight: 1, color: "rgba(255,255,255,0.92)",
          fontStyle: "italic", fontWeight: 400,
          textShadow: "0 2px 12px rgba(0,0,0,0.4)",
        }}>0{idx + 1}</div>
      </div>
      {/* Body */}
      <div style={{ padding: "28px 24px 32px" }}>
        <h4 className="serif" style={{
          fontSize: 20, lineHeight: 1.25, margin: "0 0 20px",
          fontWeight: 500, color: "var(--text-strong)", letterSpacing: 0,
          minHeight: 56,
        }}>{c.t}</h4>
        <div style={{
          paddingTop: 16, borderTop: "1px solid var(--line)",
          display: "flex", justifyContent: "space-between", alignItems: "center",
        }}>
          <div style={{ fontSize: 13, color: "var(--gold)", fontWeight: 600, letterSpacing: "0.02em" }}>
            {c.r}
          </div>
          <div style={{ fontSize: 13, color: "var(--text-mute)" }}>→</div>
        </div>
      </div>
    </div>
  );
}

// ───────────────────────── CTA ─────────────────────────
function CTASection() {
  const { t } = useLang();
  const { setRoute } = useRoute();
  const h = t.home;
  const parRef = useParallax(30);
  return (
    <section className="ewv-cta-pad" data-cta-bridge style={{
      background: "var(--navy)", color: "var(--ivory)",
      padding: "180px 0", position: "relative", overflow: "hidden",
    }}>
      {/* Conference / negotiation photo — root of the "closing" experience */}
      <div aria-hidden ref={parRef} style={{
        position: "absolute", left: 0, right: 0, top: "-10%", height: "120%",
        backgroundImage: "url('uploads/ewv-case-forum-luxury.jpg')",
        backgroundSize: "cover", backgroundPosition: "center 30%",
        opacity: 0.58,
        filter: "saturate(1.0) contrast(1.05) brightness(1.08)",
        pointerEvents: "none", willChange: "transform",
      }} />
      {/* Lighter navy gradient — let conference image show through */}
      <div aria-hidden style={{
        position: "absolute", inset: 0,
        background: "linear-gradient(180deg, rgba(10,24,48,0.28) 0%, rgba(10,24,48,0.45) 60%, rgba(10,24,48,0.72) 100%)",
        pointerEvents: "none",
      }} />
      {/* Decorative east/west glow split */}
      <div aria-hidden style={{
        position: "absolute", inset: 0,
        background: "radial-gradient(ellipse at 80% 30%, rgba(201,162,74,0.28) 0%, transparent 55%), radial-gradient(ellipse at 20% 70%, rgba(143,179,217,0.18) 0%, transparent 55%)",
        pointerEvents: "none",
      }} />

      <div className="ewv-container" style={{ maxWidth: 1440, margin: "0 auto", padding: "0 80px", position: "relative" }}>
        <Reveal>
          <div style={{ maxWidth: 1100 }}>
            <h2 className="serif ewv-cta-title" style={{
              fontSize: "clamp(56px, 7.4vw, 120px)", lineHeight: 0.98,
              margin: "0 0 40px", fontWeight: 400, letterSpacing: 0,
            }}>
              {h.ctaTitle.map((line, i) => (
                <div key={i} style={{
                  fontStyle: i === 1 ? "italic" : "normal",
                  color: i === 1 ? "var(--gold)" : "var(--ivory)",
                }}>{line}</div>
              ))}
            </h2>
            <p className="ewv-cta-sub" style={{
              fontSize: 19, lineHeight: 1.55,
              color: "rgba(245,239,227,0.76)",
              maxWidth: 600, margin: "0 0 48px",
            }}>{h.ctaSub}</p>
            <button onClick={() => setRoute("contact")}
              style={{
                padding: "20px 36px", fontSize: 13, letterSpacing: "0.16em", textTransform: "uppercase",
                background: "var(--gold)", color: "var(--navy)",
                fontWeight: 700,
                border: "1px solid var(--gold)",
              }}>{t.cta.schedule} →</button>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

Object.assign(window, {
  HomePage,
});
