/* Header + Hero variants — patient site */
const { useEffect: useEf, useState: useSt, useRef: useRf } = React;

function Header({ onOpenModal }) {
  const [scrolled, setScrolled] = useSt(false);
  useEf(() => {
    const onScroll = () => setScrolled(window.scrollY > 12);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  return (
    <header style={{
      position: "fixed", top: 0, left: 0, right: 0, zIndex: 50,
      background: scrolled ? "rgba(14, 11, 7, 0.62)" : "transparent",
      backdropFilter: scrolled ? "blur(18px) saturate(140%)" : "none",
      WebkitBackdropFilter: scrolled ? "blur(18px) saturate(140%)" : "none",
      borderBottom: scrolled ? "1px solid var(--on-dark-15)" : "1px solid transparent",
      transition: "background .35s ease, border-color .35s ease",
    }}>
      <div className="wrap" style={{
        display: "flex", alignItems: "center", justifyContent: "space-between",
        height: scrolled ? 64 : 80, transition: "height .35s ease",
      }}>
        <Wordmark color="var(--pearl)" />
        <nav className="hdr-nav" style={{ fontSize: 13, letterSpacing: "0.02em", textTransform: "uppercase", whiteSpace: "nowrap" }}>
          {[["The truth", "#science"], ["Routine", "#how"], ["The app", "#app"], ["Why 360", "#why"]].map(([l, h]) => (
            <a key={l} href={h} style={{ color: "var(--pearl)", opacity: 0.75 }}
              onMouseEnter={e => e.currentTarget.style.opacity = 1}
              onMouseLeave={e => e.currentTarget.style.opacity = 0.75}>{l}</a>
          ))}
        </nav>
        <div className="hdr-right" style={{ display: "flex", alignItems: "center", gap: 18 }}>
          <a href="dentists.html" className="hdr-dentists" style={{
            fontFamily: "var(--font-mono)", fontSize: 10,
            letterSpacing: "0.18em", textTransform: "uppercase",
            color: "var(--on-dark-60)", display: "inline-flex", alignItems: "center", gap: 6,
            paddingRight: 14, borderRight: "1px solid var(--on-dark-15)",
            whiteSpace: "nowrap",
          }}>For dentists <I.Arrow /></a>
          <button onClick={onOpenModal} className="btn btn--gold" style={{ padding: "11px 18px" }}>
            Find your dentist <I.Arrow />
          </button>
        </div>
      </div>
    </header>
  );
}

/* ---------- HERO A — Cinema / Cover Star ----------
   Full-bleed dark stage. Product placeholder centered, big italic
   headline overlaps. Cursor-following spotlight. Edition stamp.   */
function HeroA({ onOpenModal }) {
  const stageRef = useRf(null);
  useEf(() => {
    const el = stageRef.current; if (!el) return;
    const onMove = (e) => {
      const r = el.getBoundingClientRect();
      const x = ((e.clientX - r.left) / r.width) * 100;
      const y = ((e.clientY - r.top) / r.height) * 100;
      el.style.setProperty("--mx", `${x}%`);
      el.style.setProperty("--my", `${y}%`);
    };
    el.addEventListener("mousemove", onMove);
    return () => el.removeEventListener("mousemove", onMove);
  }, []);

  return (
    <section id="top" ref={stageRef} style={{
      position: "relative",
      minHeight: "100vh",
      paddingTop: 96, paddingBottom: 56,
      background: "var(--ink)",
      overflow: "hidden",
      isolation: "isolate",
    }}>
      {/* Spotlight */}
      <div aria-hidden="true" style={{
        position: "absolute", inset: 0, zIndex: 0,
        background: "radial-gradient(420px 360px at var(--mx, 50%) var(--my, 30%), rgba(212,176,122,0.22), transparent 70%)",
        transition: "background .25s ease",
      }} />
      {/* Ambient corner glow */}
      <div aria-hidden="true" style={{
        position: "absolute", left: "-12%", top: "-20%",
        width: "60%", height: "60%", zIndex: 0,
        background: "radial-gradient(closest-side, rgba(212,176,122,0.18), transparent 70%)",
        filter: "blur(20px)",
      }} />
      {/* Packaging-inspired shatter lines */}
      <ShatterLines stroke="rgba(246,239,227,0.07)" lines={32} seed={11} />

      <div className="wrap" style={{ position: "relative", zIndex: 2 }}>
        {/* Top masthead bar */}
        <Reveal delay={0}>
          <div style={{
            display: "flex", justifyContent: "space-between",
            alignItems: "center", paddingBottom: 24,
            borderBottom: "1px solid var(--on-dark-15)",
            gap: 16, flexWrap: "wrap",
          }}>
            <span className="eyebrow">— The truth about whitening</span>
            <span className="eyebrow" style={{ color: "var(--accent)" }}>★ Prescribed by dentists. Tracked by you. ★</span>
            <span className="eyebrow">20 years · UK</span>
          </div>
        </Reveal>
      </div>

      <div className="wrap" style={{
        position: "relative", zIndex: 2, marginTop: "clamp(40px, 7vw, 96px)",
      }}>
        <div style={{
          display: "grid",
          gridTemplateColumns: "minmax(0, 0.92fr) minmax(0, 1.08fr)",
          gap: "clamp(24px, 4vw, 72px)",
          alignItems: "center",
        }}>
          {/* Left coverlines */}
          <div style={{ display: "flex", flexDirection: "column", gap: 28 }}>
            <Reveal delay={120}>
              <h1 className="h-display" style={{
                fontSize: "clamp(58px, 7.4vw, 124px)",
                margin: 0,
              }}>
                <span>You've been</span><br/>
                <span>sold a </span><em style={{ color: "var(--accent)" }}>very</em><br/>
                <em style={{ color: "var(--accent)" }}>white lie.</em>
              </h1>
            </Reveal>
            <Reveal delay={260}>
              <p className="lead" style={{ maxWidth: 380, margin: 0 }}>
                Strips don't work. Charcoal doesn't work. The only thing that whitens
                teeth is peroxide — and peroxide is prescription-only in the UK.
                We've spent 20 years supplying the dentists who do it properly.
              </p>
            </Reveal>
            <Reveal delay={360} style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
              <button onClick={onOpenModal} className="btn btn--gold btn--big">Find your dentist <I.Arrow /></button>
              <a href="#science" className="btn btn--ghost btn--big">See how it works</a>
            </Reveal>
            {/* Compact stat row */}
            <Reveal delay={440}>
              <div style={{
                display: "flex", gap: "clamp(20px, 3vw, 40px)", flexWrap: "wrap",
                paddingTop: 26, marginTop: 6, borderTop: "1px solid var(--on-dark-15)",
              }}>
                {[["14", "days", "a standard course"], ["2", "ways", "one hour or overnight"], ["0", "drama", "near-zero sensitivity"]].map(([n, u, l]) => (
                  <div key={l}>
                    <div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
                      <span style={{ fontFamily: "var(--font-display)", fontSize: 40, color: "var(--pearl)", lineHeight: 1, letterSpacing: "-0.03em" }}>{n}</span>
                      <span style={{ fontFamily: "var(--font-display)", fontStyle: "italic", fontSize: 17, color: "var(--accent)" }}>{u}</span>
                    </div>
                    <div className="eyebrow" style={{ fontSize: 9, marginTop: 6 }}>{l}</div>
                  </div>
                ))}
              </div>
            </Reveal>
          </div>

          {/* Right — visual cluster: enlarged box + the app */}
          <Reveal delay={180} style={{ position: "relative" }}>
            <div style={{
              position: "relative",
              minHeight: "min(74vh, 700px)",
              display: "flex", alignItems: "center", justifyContent: "center",
            }}>
              {/* The kit — enlarged, anchored left of the cluster */}
              <div style={{
                position: "relative",
                width: "66%",
                transform: "translate(-8%, -4%)",
                filter: "drop-shadow(0 60px 80px rgba(0,0,0,0.6)) drop-shadow(0 0 70px rgba(212,176,122,0.2))",
              }}>
                <img src="uploads/kit-hero.png" alt="360 Whitening kit — four gel syringes and trays"
                  style={{ width: "100%", maxWidth: "none", height: "auto", display: "block" }} />
              </div>

              {/* The app — overlapping front-right */}
              <div style={{
                position: "absolute", right: "0%", bottom: "-8%",
                width: "40%", zIndex: 3,
                filter: "drop-shadow(0 50px 60px rgba(0,0,0,0.7))",
              }}>
                <img src="uploads/app-hero.png" alt="The 360 Whitening app — your daily whitening routine"
                  style={{ width: "100%", maxWidth: "none", height: "auto", display: "block" }} />
              </div>

              {/* Edition stamp — top-right corner */}
              <div style={{ position: "absolute", right: "1%", top: "0%", zIndex: 4 }}>
                <EditionStamp label="Edition 01" number="MMXXVI" angle={-6} />
              </div>

              {/* Caption pill */}
              <div style={{
                position: "absolute", left: "2%", bottom: "2%", zIndex: 4,
                background: "var(--ink)", color: "var(--pearl)",
                padding: "10px 18px", borderRadius: 999,
                fontFamily: "var(--font-mono)", fontSize: 10,
                letterSpacing: "0.22em", textTransform: "uppercase",
                border: "1px solid var(--on-dark-15)", whiteSpace: "nowrap",
              }}>
                <span style={{ color: "var(--accent)" }}>★</span> The Kit + the app <span style={{ color: "var(--accent)" }}>★</span>
              </div>
            </div>
          </Reveal>
        </div>
      </div>

      {/* Scroll hint */}
      <div style={{
        position: "absolute", left: "50%", bottom: 22,
        transform: "translateX(-50%)", zIndex: 3,
        fontFamily: "var(--font-mono)", fontSize: 10,
        letterSpacing: "0.24em", textTransform: "uppercase",
        color: "var(--on-dark-40)",
        display: "flex", alignItems: "center", gap: 10,
      }}>
        <span style={{ width: 24, height: 1, background: "var(--on-dark-40)" }} />
        scroll
        <span style={{ width: 24, height: 1, background: "var(--on-dark-40)" }} />
      </div>
    </section>
  );
}

function Stat({ n, unit, label }) {
  return (
    <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end", gap: 4 }}>
      <div style={{ display: "flex", alignItems: "baseline", gap: 8 }}>
        <span style={{
          fontFamily: "var(--font-display)", fontSize: 56, lineHeight: 1,
          letterSpacing: "-0.04em", color: "var(--pearl)",
          fontWeight: 360,
        }}>{n}</span>
        <span style={{
          fontFamily: "var(--font-display)", fontStyle: "italic",
          fontSize: 22, color: "var(--accent)",
          fontVariationSettings: '"opsz" 144, "SOFT" 100, "WONK" 1',
        }}>{unit}</span>
      </div>
      <span className="eyebrow" style={{ fontSize: 10 }}>{label}</span>
    </div>
  );
}

/* ---------- HERO B — Magazine Cover ----------
   Cream / champagne. Masthead at top with issue + date. Big serif
   coverlines down the left. Product photo block bottom-right with
   captioned cover-call. Sticker stamp top-right. */
function HeroB({ onOpenModal }) {
  return (
    <section id="top" style={{
      position: "relative",
      minHeight: "100vh",
      paddingTop: 96, paddingBottom: 56,
      background: "var(--pearl)",
      color: "var(--ink)",
      overflow: "hidden",
    }} className="on-light">
      <div className="wrap" style={{ position: "relative" }}>
        {/* Masthead */}
        <Reveal>
          <div style={{
            display: "flex", justifyContent: "space-between",
            alignItems: "baseline", borderBottom: "2px solid var(--ink)",
            paddingBottom: 16, marginBottom: 32,
            gap: 16, flexWrap: "wrap",
          }}>
            <span style={{
              fontFamily: "var(--font-display)", fontStyle: "italic",
              fontSize: "clamp(28px, 3.6vw, 52px)",
              fontVariationSettings: '"opsz" 144, "SOFT" 100, "WONK" 1',
              letterSpacing: "-0.025em",
              color: "var(--ink)",
            }}>360°</span>
            <span className="eyebrow" style={{ color: "var(--ink)", opacity: 0.7 }}>
              The truth about whitening · 20 years · UK
            </span>
            <span className="eyebrow" style={{ color: "var(--accent-deep)" }}>★ No shortcuts ★</span>
          </div>
        </Reveal>

        <div style={{
          display: "grid",
          gridTemplateColumns: "minmax(0, 1.05fr) minmax(0, 0.95fr)",
          gap: "clamp(24px, 4vw, 80px)",
          alignItems: "stretch",
          minHeight: "60vh",
        }}>
          {/* Left coverlines */}
          <div style={{ display: "flex", flexDirection: "column", justifyContent: "space-between" }}>
            <Reveal delay={120}>
              <h1 className="h-display" style={{
                fontSize: "clamp(64px, 9vw, 150px)",
                margin: 0,
                color: "var(--ink)",
              }}>
                A very<br/>
                <em style={{ color: "var(--accent-deep)" }}>white</em><br/>
                <em style={{ color: "var(--accent-deep)" }}>lie.</em>
              </h1>
            </Reveal>

            <div style={{ display: "flex", flexDirection: "column", gap: 16, maxWidth: 380 }}>
              <Reveal delay={260}>
                <Coverline n="01" t="The Lie" body="Strips, charcoal, LED — none of it whitens. Here's why." />
              </Reveal>
              <Reveal delay={320}>
                <Coverline n="02" t="The Truth" body="Prescription peroxide, custom trays, worn consistently." />
              </Reveal>
              <Reveal delay={380}>
                <Coverline n="03" t="The App" body="Your routine, guided and tracked, day by day." />
              </Reveal>
              <Reveal delay={460} style={{ marginTop: 12 }}>
                <button onClick={onOpenModal} className="btn btn--gold btn--big">
                  Find your dentist <I.Arrow />
                </button>
              </Reveal>
            </div>
          </div>

          {/* Right — product cover photo */}
          <Reveal delay={220} style={{ position: "relative" }}>
            <div style={{
              position: "relative",
              minHeight: 520, height: "100%",
              borderRadius: 6, overflow: "hidden",
              background: "var(--ink)",
              display: "grid", placeItems: "center",
              isolation: "isolate",
            }}>
              <ShatterLines stroke="rgba(246,239,227,0.08)" lines={26} seed={9} />
              <img src="uploads/008-web.png" alt="360 Whitening kit, open, showing the gel syringes and trays"
                style={{ width: "110%", maxWidth: "none", height: "auto", display: "block",
                  filter: "drop-shadow(0 40px 50px rgba(0,0,0,0.5))", position: "relative", zIndex: 1 }} />
            </div>
            <div style={{
              position: "absolute", left: -16, bottom: 24,
              writingMode: "vertical-rl",
              fontFamily: "var(--font-mono)", fontSize: 10,
              letterSpacing: "0.28em", textTransform: "uppercase",
              color: "var(--on-light-60)",
            }}>360 Whitening · Edition 01 · Cover photo</div>
            <div style={{
              position: "absolute", right: 18, top: 18,
            }}>
              <EditionStamp label="Sold out twice" number="N° 01" angle={6} />
            </div>
          </Reveal>
        </div>
      </div>
    </section>
  );
}

function Coverline({ n, t, body }) {
  return (
    <div style={{
      display: "grid", gridTemplateColumns: "auto 1fr",
      gap: 14, alignItems: "baseline",
      borderTop: "1px solid var(--on-light-15)",
      paddingTop: 12,
    }}>
      <span style={{
        fontFamily: "var(--font-mono)", fontSize: 10,
        letterSpacing: "0.2em", color: "var(--accent-deep)",
      }}>{n}</span>
      <div>
        <div style={{
          fontFamily: "var(--font-display)", fontStyle: "italic",
          fontSize: 22, color: "var(--ink)",
          fontVariationSettings: '"opsz" 120, "SOFT" 100, "WONK" 1',
        }}>{t}</div>
        <div style={{ fontSize: 14, color: "var(--on-light-60)", marginTop: 2 }}>{body}</div>
      </div>
    </div>
  );
}

Object.assign(window, { Header, HeroA, HeroB });
