// home.jsx — Lumera homepage. Each numbered section corresponds to the brand brief.
const { useState, useEffect, useRef } = React;

const Home = ({ onNav, onOpenProduct, onAdd }) => {
  return (
    <main>
      <HeroSection onNav={onNav} onAdd={onAdd} />
      <PhilosophySection onNav={onNav} />
      <VideoTransition />
      <CollectionSection onNav={onNav} onOpenProduct={onOpenProduct} onAdd={onAdd} />
      <FeaturedProductSection onAdd={onAdd} onOpenProduct={onOpenProduct} />
      <ScienceSection />
      <SourcingSection onNav={onNav} />
      <RitualSection />
      <TestimonialsSection />
      <PressSection />
      <JournalSection />
      <NewsletterSection />
    </main>
  );
};

/* ─────────────────────────────────────────────────────────────
   1 · HERO — split layout. Type sits on bone, photograph on the
   right. No protection-wash legibility gamble.
   ───────────────────────────────────────────────────────────── */
const HeroSection = ({ onNav, onAdd }) => (
  <section style={{ padding: 0, background: "var(--bone)" }}>
    <div style={{
      display: "grid",
      gridTemplateColumns: "minmax(440px, 1fr) 1.15fr",
      minHeight: "min(92vh, 880px)",
      alignItems: "stretch",
    }}>
      {/* Type column */}
      <div style={{
        display: "flex", flexDirection: "column", justifyContent: "center",
        padding: "var(--s-10) var(--s-9)",
        background: "var(--bone)",
        position: "relative",
      }}>
        <Reveal>
          <Eyebrow style={{ marginBottom: "var(--s-6)" }}>
            <span style={{ color: "var(--champagne-d)" }}>◆</span>
            <span style={{ marginLeft: 10 }}>The Atelier Collection · Geneva</span>
          </Eyebrow>
        </Reveal>
        <Reveal delay={120}>
          <h1 style={{
            fontFamily: "var(--font-display)",
            fontWeight: 300,
            fontSize: "clamp(64px, 7.6vw, 120px)",
            letterSpacing: "-0.02em",
            lineHeight: 0.95,
            color: "var(--ink)",
            margin: 0,
            textWrap: "balance",
          }}>
            Skin,<br/>
            <span style={{ fontStyle: "italic", fontWeight: 300 }}>returned</span> to light.
          </h1>
        </Reveal>
        <Reveal delay={260}>
          <p style={{
            fontFamily: "var(--font-display)", fontStyle: "italic", fontWeight: 300,
            fontSize: "22px", lineHeight: 1.45, color: "var(--ink-2)",
            maxWidth: "30ch", margin: "var(--s-6) 0 var(--s-7)",
          }}>
            A small collection of considered formulations.<br/>Made in restraint. Felt in radiance.
          </p>
        </Reveal>
        <Reveal delay={380}>
          <div style={{ display: "flex", gap: "var(--s-4)", flexWrap: "wrap" }}>
            <Button onClick={() => onNav("shop")}>Discover the collection</Button>
            <Button variant="quiet">Read the philosophy</Button>
          </div>
        </Reveal>

        {/* Lower meta strip */}
        <div style={{
          position: "absolute", left: "var(--s-9)", right: "var(--s-9)", bottom: "var(--s-7)",
          display: "flex", justifyContent: "space-between", alignItems: "baseline",
          paddingTop: "var(--s-5)",
          borderTop: "0.5px solid var(--line)",
        }}>
          <Eyebrow>The Essentials · Six products</Eyebrow>
          <span style={{ fontFamily: "var(--font-display)", fontStyle: "italic", fontWeight: 300, fontSize: "15px", color: "var(--ink-3)" }}>
            Formulated in Geneva &middot; Sourced with conscience
          </span>
        </div>
      </div>

      {/* Image column */}
      <div style={{
        position: "relative",
        background: "var(--linen)",
        overflow: "hidden",
      }}>
        <img src="assets/hero.png" alt=""
          style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
        {/* small editorial overlay — sun mark + caption */}
        <div style={{
          position: "absolute", left: 0, right: 0, top: "var(--s-7)",
          display: "flex", justifyContent: "flex-end", paddingRight: "var(--s-7)",
        }}>
          <div style={{
            background: "rgba(26,22,18,0.0)",
            color: "var(--paper)",
            padding: "8px 14px",
            fontFamily: "var(--font-sans)",
            fontSize: "10px",
            letterSpacing: "0.32em",
            textTransform: "uppercase",
            mixBlendMode: "difference",
            opacity: 0.85,
          }}>Edition · MMXXVI</div>
        </div>
      </div>
    </div>
  </section>
);

/* ─────────────────────────────────────────────────────────────
   2 · PHILOSOPHY
   ───────────────────────────────────────────────────────────── */
const PhilosophySection = ({ onNav }) => (
  <section style={{ padding: "var(--s-11) var(--s-7)", background: "var(--bone)" }}>
    <div style={{ maxWidth: 1280, margin: "0 auto" }}>
      {/* Top label */}
      <Reveal>
        <div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: "var(--s-5)", marginBottom: "var(--s-9)" }}>
          <span style={{ height: 1, background: "var(--line-strong)", flex: "0 0 60px" }}></span>
          <Eyebrow>Our principle &middot; Section i</Eyebrow>
          <span style={{ height: 1, background: "var(--line-strong)", flex: "0 0 60px" }}></span>
        </div>
      </Reveal>

      <div style={{ display: "grid", gridTemplateColumns: "1.05fr 1fr", gap: "var(--s-10)", alignItems: "center" }}>
        <div>
          <Reveal>
            <h2 style={{
              fontFamily: "var(--font-display)", fontWeight: 300,
              fontSize: "clamp(48px, 5.6vw, 84px)",
              letterSpacing: "-0.02em", lineHeight: 1.0,
              color: "var(--ink)", margin: 0, textWrap: "balance",
              maxWidth: "16ch",
            }}>
              Luxury is what you <span style={{ fontStyle: "italic" }}>leave out</span>.
            </h2>
          </Reveal>

          <Reveal delay={120}>
            <p style={{
              fontFamily: "var(--font-display)", fontStyle: "italic", fontWeight: 300,
              fontSize: "22px", lineHeight: 1.55, color: "var(--ink-2)",
              margin: "var(--s-7) 0 var(--s-5)", maxWidth: "34ch",
            }}>
              Lumera is a house of skincare built on a single principle: that the skin, given the right inputs and nothing more, knows how to return to its quietest, most luminous state.
            </p>
          </Reveal>

          <Reveal delay={220}>
            <p style={{
              fontFamily: "var(--font-sans)", fontSize: "16px",
              color: "var(--ink-2)", lineHeight: 1.75, maxWidth: "42ch",
              margin: "0 0 var(--s-4)",
            }}>
              Six products. No noise. Only what works.
            </p>
            <p style={{
              fontFamily: "var(--font-sans)", fontSize: "16px",
              color: "var(--ink-2)", lineHeight: 1.75, maxWidth: "42ch",
              margin: "0 0 var(--s-4)",
            }}>
              We formulate slowly. We disclose everything. We do not chase trends, and we do not release a product until it meets a threshold of measurable performance.
            </p>
            <p style={{
              fontFamily: "var(--font-sans)", fontSize: "16px",
              color: "var(--ink-2)", lineHeight: 1.75, maxWidth: "42ch",
              margin: 0,
            }}>
              What we leave out is as deliberate as what we include.
            </p>
          </Reveal>

          <Reveal delay={320}>
            <div style={{ marginTop: "var(--s-7)" }}>
              <ArrowLink onClick={() => onNav("house")}>Read our full philosophy</ArrowLink>
            </div>
          </Reveal>
        </div>

        <Reveal delay={150}>
          <div style={{
            aspectRatio: "4 / 5",
            borderRadius: "2px",
            overflow: "hidden",
            background: "var(--linen)",
            position: "relative",
          }}>
            <img src="assets/philosophy.png" alt=""
              style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
            <div style={{
              position: "absolute", left: 0, right: 0, bottom: 0,
              padding: "var(--s-7) var(--s-6) var(--s-5)",
              background: "linear-gradient(to top, rgba(26,22,18,0.55), rgba(26,22,18,0))",
              color: "var(--paper)",
            }}>
              <div style={{ fontFamily: "var(--font-display)", fontStyle: "italic", fontWeight: 300, fontSize: "16px", lineHeight: 1.5, maxWidth: "30ch" }}>
                "A balm that begins as solid and finishes as silk. Worn nightly, it returns the skin to its quietest state."
              </div>
            </div>
          </div>
        </Reveal>
      </div>
    </div>
  </section>
);

/* ─────────────────────────────────────────────────────────────
   2.5 · VIDEO TRANSITION — the cinematic golden-drop moment.
   Full-bleed noir frame. The video is the entire section.
   ───────────────────────────────────────────────────────────── */
const VideoTransition = () => {
  const videoRef = useRef(null);
  const sectionRef = useRef(null);

  // Always-on autoplay. IntersectionObserver pause is optional and skipped
  // here because the iframe sandbox swallows IO callbacks.
  useEffect(() => {
    const v = videoRef.current;
    if (!v) return;
    v.muted = true;
    const tryPlay = () => v.play().catch(() => {});
    tryPlay();
    v.addEventListener("loadedmetadata", tryPlay);
    v.addEventListener("canplay", tryPlay);
    return () => {
      v.removeEventListener("loadedmetadata", tryPlay);
      v.removeEventListener("canplay", tryPlay);
    };
  }, []);

  return (
    <section ref={sectionRef} style={{
      padding: 0,
      background: "var(--noir)",
      color: "var(--paper)",
      position: "relative",
      overflow: "hidden",
    }}>
      {/* Video as full-bleed backdrop */}
      <div style={{ position: "relative", width: "100%", height: "min(86vh, 760px)", overflow: "hidden" }}>
        <video
          ref={videoRef}
          src="assets/lumera-serum-drop.mp4"
          autoPlay muted loop playsInline preload="auto"
          style={{
            position: "absolute", inset: 0,
            width: "100%", height: "100%",
            objectFit: "cover",
            display: "block",
            opacity: 0.96,
          }}
        />
        {/* Edge vignette: keeps focus on the drop, ensures caption reads */}
        <div style={{
          position: "absolute", inset: 0,
          background: "radial-gradient(ellipse at center, rgba(26,22,18,0) 35%, rgba(26,22,18,0.55) 100%)",
          pointerEvents: "none",
        }} />
        {/* Bottom protection wash — guarantees caption legibility */}
        <div style={{
          position: "absolute", inset: 0,
          background: "linear-gradient(to bottom, rgba(26,22,18,0.30) 0%, rgba(26,22,18,0) 24%, rgba(26,22,18,0) 60%, rgba(26,22,18,0.72) 100%)",
          pointerEvents: "none",
        }} />

        {/* Top eyebrow */}
        <div style={{
          position: "absolute", top: "var(--s-8)", left: 0, right: 0,
          display: "flex", justifyContent: "center", alignItems: "center", gap: "var(--s-5)",
          color: "var(--paper)",
        }}>
          <span style={{ height: 1, background: "rgba(250,248,243,0.32)", flex: "0 0 80px" }}></span>
          <Eyebrow color="var(--paper)" style={{ opacity: 0.92 }}>An interlude · The formulation</Eyebrow>
          <span style={{ height: 1, background: "rgba(250,248,243,0.32)", flex: "0 0 80px" }}></span>
        </div>

        {/* Centerline poetry — kept small so the video is the hero */}
        <div style={{
          position: "absolute", inset: 0,
          display: "flex", flexDirection: "column", justifyContent: "flex-end",
          padding: "0 var(--s-9) var(--s-9)",
          maxWidth: 1440, margin: "0 auto",
          color: "var(--paper)",
        }}>
          <div style={{ display: "grid", gridTemplateColumns: "1fr auto", alignItems: "end", gap: "var(--s-7)" }}>
            <h2 style={{
              fontFamily: "var(--font-display)",
              fontWeight: 300,
              fontStyle: "italic",
              fontSize: "clamp(40px, 4.8vw, 72px)",
              letterSpacing: "-0.01em",
              lineHeight: 1.05,
              color: "var(--paper)",
              margin: 0,
              textWrap: "balance",
              maxWidth: "18ch",
            }}>
              A single drop.<br/>The whole intention.
            </h2>
            <div style={{ textAlign: "right" }}>
              <Eyebrow color="rgba(250,248,243,0.78)" style={{ marginBottom: 6 }}>Halo Renewal Serum</Eyebrow>
              <div style={{ fontFamily: "var(--font-display)", fontStyle: "italic", fontWeight: 300, fontSize: "16px", color: "rgba(250,248,243,0.78)", lineHeight: 1.5, maxWidth: "26ch" }}>
                0.1 percent encapsulated retinaldehyde.<br/>Four years of formulation. One drop.
              </div>
            </div>
          </div>
        </div>

        {/* Side scale-marker (subtle filmstrip cue) */}
        <div style={{
          position: "absolute", left: "var(--s-6)", top: "50%", transform: "translateY(-50%)",
          display: "flex", flexDirection: "column", alignItems: "center", gap: 12,
          color: "rgba(250,248,243,0.5)",
          fontFamily: "var(--font-sans)", fontSize: "9px",
          letterSpacing: "0.32em", textTransform: "uppercase",
        }}>
          <span style={{ writingMode: "vertical-rl", transform: "rotate(180deg)" }}>Interlude — 00:08</span>
          <span style={{ width: 1, height: 60, background: "rgba(250,248,243,0.32)" }}></span>
          <span style={{ width: 6, height: 6, background: "var(--champagne)", transform: "rotate(45deg)" }}></span>
        </div>
      </div>
    </section>
  );
};

window.Home = Home;
window.HeroSection = HeroSection;
window.PhilosophySection = PhilosophySection;
window.VideoTransition = VideoTransition;
