// Variation C — "Cinematic"
// Full-bleed photography, sticky/scroll-driven hero with date reveal,
// horizontal-feeling event timeline, warm and quiet.

const { useState: uC, useEffect: eC, useRef: rC } = React;

function useScrollC() {
  const [y, setY] = uC(0);
  eC(() => {
    const fn = () => setY(window.scrollY);
    window.addEventListener("scroll", fn, { passive: true });
    return () => window.removeEventListener("scroll", fn);
  }, []);
  return y;
}

function useRevealC() {
  const ref = rC(null);
  const [s, setS] = uC(false);
  eC(() => {
    if (!ref.current) return;
    const r = ref.current.getBoundingClientRect();
    if (r.top < window.innerHeight && r.bottom > 0) {
      setS(true);
      return;
    }
    const io = new IntersectionObserver(
      ([e]) => e.isIntersecting && (setS(true), io.disconnect()),
      { threshold: 0.15, rootMargin: "0px 0px -10% 0px" }
    );
    io.observe(ref.current);
    return () => io.disconnect();
  }, []);
  return [ref, s];
}

function RevealC({ children, delay = 0, ...p }) {
  const [ref, s] = useRevealC();
  return (
    <div ref={ref} {...p} style={{
      ...p.style,
      opacity: s ? 1 : 0,
      transform: s ? "translateY(0)" : "translateY(24px)",
      transition: `opacity 1s ${delay}ms var(--ease-out), transform 1s ${delay}ms var(--ease-out)`,
    }}>{children}</div>
  );
}

function CountdownC({ lang }) {
  const [t, setT] = uC(() => TJ_countdown(TJ_DATE, lang));
  eC(() => {
    const id = setInterval(() => setT(TJ_countdown(TJ_DATE, lang)), 1000);
    return () => clearInterval(id);
  }, [lang]);
  const cell = (v, l, last) => (
    <div className="tjc-count-cell" style={{ display: "flex", flexDirection: "column", alignItems: "center", padding: "0 28px", borderRight: last ? "none" : "1px solid rgba(239,230,220,.3)" }}>
      <span className="v" style={{ fontFamily: "var(--f-display)", fontSize: 44, color: "var(--cream)", lineHeight: 1, fontVariantNumeric: "tabular-nums" }}>{TJ_pad(v)}</span>
      <span className="l" style={{ fontFamily: "var(--f-sans)", fontSize: 10, letterSpacing: ".3em", textTransform: "uppercase", color: "rgba(239,230,220,.6)", marginTop: 10 }}>{l}</span>
    </div>
  );
  return (
    <div style={{ display: "flex", alignItems: "center" }}>
      {cell(t.d, t.L.d)}
      {cell(t.h, t.L.h)}
      {cell(t.m, t.L.m)}
      {cell(t.s, t.L.s, true)}
    </div>
  );
}

function VariationC({ lang, accent }) {
  const c = TJ_CONTENT[lang];
  const y = useScrollC();
  const style = { "--rose": accent };

  // Parallax hero
  const heroScale = 1 + Math.min(0.08, y * 0.00012);
  const heroOpacity = Math.max(0, 1 - y / 900);
  const titleY = Math.min(60, y * 0.15);

  return (
    <div data-screen-label="Variation C — Cinematic" style={{ background: "var(--ink)", color: "var(--cream)", ...style }}>
      <style>{`
        .tjc-link { position:relative; color: var(--cream); opacity:.85; transition: opacity .3s; }
        .tjc-link:hover { opacity: 1; }
        .tjc-vignette::before { content:""; position:absolute; inset:0; background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,.5) 100%); pointer-events:none; }
        .tjc-cta {
          display: inline-flex; align-items: center; gap: 10px;
          padding: 11px 22px;
          background: var(--rose);
          color: var(--cream);
          font-family: var(--f-sans);
          font-size: 11px; font-weight: 600;
          letter-spacing: .14em; text-transform: uppercase;
          border-radius: 999px;
          box-shadow: 0 6px 20px -6px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.06) inset;
          transition: transform .25s var(--ease-out), background .25s, box-shadow .25s;
          white-space: nowrap;
        }
        .tjc-cta:hover { background: var(--rose-deep); transform: translateY(-1px); box-shadow: 0 10px 26px -8px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.08) inset; }
        .tjc-cta-arrow { transition: transform .3s var(--ease-out); display: inline-block; }
        .tjc-cta:hover .tjc-cta-arrow { transform: translateX(3px); }
        .tjc-cta-lg { display: inline-flex; align-items: center; gap: 12px; padding: 18px 40px; background: var(--rose); color: var(--cream); font-family: var(--f-sans); font-size: 12px; letter-spacing: .26em; text-transform: uppercase; font-weight: 600; border: 1px solid var(--rose); transition: all .3s var(--ease-out); box-shadow: 0 8px 24px -10px rgba(177, 74, 67, .45); }
        .tjc-cta-lg:hover { background: var(--rose-deep); border-color: var(--rose-deep); transform: translateY(-2px); box-shadow: 0 14px 32px -10px rgba(177, 74, 67, .55); }
        .tjc-cta-lg .arrow { transition: transform .3s var(--ease-out); display: inline-block; font-size: 14px; }
        .tjc-cta-lg:hover .arrow { transform: translate(4px, -3px); }

        /* ---------- MOBILE ---------- */
        @media (max-width: 760px) {
          .tjc-nav-links { display: none !important; }
          .tjc-nav { padding: 14px 20px !important; gap: 14px !important; }
          .tjc-cta { padding: 9px 16px !important; font-size: 10px !important; letter-spacing: .12em !important; }
          .tjc-cta-lg { padding: 14px 26px !important; font-size: 11px !important; letter-spacing: .2em !important; }

          .tjc-hero-inner { padding: 0 22px !important; }
          .tjc-hero-kicker { font-size: 10px !important; margin-bottom: 20px !important; }
          .tjc-hero-date-row { gap: 12px !important; margin-top: 22px !important; }
          .tjc-hero-date-row .line { width: 32px !important; }
          .tjc-hero-date { font-size: 16px !important; letter-spacing: .06em !important; }
          .tjc-hero-city { font-size: 10px !important; letter-spacing: .22em !important; margin-top: 10px !important; }
          .tjc-hero-bottom { padding: 16px 20px !important; flex-direction: column !important; gap: 10px !important; }
          .tjc-hero-bottom > div { font-size: 10px !important; letter-spacing: .2em !important; }
          .tjc-hero-scroll { display: none !important; }

          .tjc-count-cell { padding: 0 12px !important; }
          .tjc-count-cell .v { font-size: 28px !important; }
          .tjc-count-cell .l { font-size: 9px !important; letter-spacing: .2em !important; margin-top: 6px !important; }

          .tjc-section { padding: 80px 20px !important; }
          .tjc-photo-break { height: 42vh !important; }
          .tjc-photo-break-text { font-size: 26px !important; padding: 0 22px !important; line-height: 1.25 !important; }

          .tjc-event-row { grid-template-columns: 1fr !important; gap: 18px !important; padding: 28px 0 !important; }
          .tjc-event-date { font-size: 22px !important; }
          .tjc-event-name { font-size: 28px !important; margin-bottom: 14px !important; }

          .tjc-split { grid-template-columns: 1fr !important; }
          .tjc-split > div { padding: 70px 24px !important; min-height: auto !important; }

          .tjc-faq-q { font-size: 17px !important; }
          .tjc-faq-row button { padding: 20px 0 !important; gap: 16px !important; }

          .tjc-footer { padding: 80px 22px 50px !important; }
          .tjc-footer-sig { margin-top: 50px !important; }
        }
      `}</style>

      {/* NAV overlay */}
      <nav className="tjc-nav" style={{
        position: "fixed", top: 0, left: 0, right: 0, zIndex: 30,
        display: "flex", alignItems: "center", gap: 32,
        padding: "18px 32px",
        background: y > 200 ? "rgba(42,35,32,.82)" : "linear-gradient(180deg, rgba(0,0,0,.35), transparent)",
        backdropFilter: y > 200 ? "blur(12px)" : "none",
        transition: "background .4s, backdrop-filter .4s",
        color: "var(--cream)",
      }}>
        <div style={{ fontFamily: "var(--f-display)", fontStyle: "italic", fontSize: 18, flexShrink: 0 }}>
          T <span style={{ color: "var(--rose-wash)" }}>&</span> J
        </div>
        <div className="tjc-nav-links" style={{ display: "flex", gap: 22, fontSize: 10.5, letterSpacing: ".24em", textTransform: "uppercase" }}>
          {[["story", "#story"], ["events", "#events"], ["stay", "#stay"], ["gifts", "#gifts"], ["faq", "#faq"]].map(([k, href]) => (
            <a key={k} href={href} className="tjc-link">{c.nav[k]}</a>
          ))}
        </div>
        <div style={{ marginLeft: "auto" }}>
          <a
            href={TJ_LINKS.rsvp} target="_blank" rel="noreferrer"
            className="tjc-cta"
          >
            <span>{c.nav.rsvp}</span>
            <span className="tjc-cta-arrow" aria-hidden>→</span>
          </a>
        </div>
      </nav>

      {/* HERO — full-bleed photo, title layered */}
      <section style={{ position: "relative", height: "100vh", overflow: "hidden" }} className="tjc-vignette">
        <div style={{
          position: "absolute", inset: 0,
          transform: `scale(${heroScale}) translateY(${y * 0.2}px)`,
          transition: "transform .1s linear",
        }}>
          <img src="assets/hero.webp" alt="Tania y Juan"
               style={{ width: "100%", height: "100%", objectFit: "cover", filter: "brightness(.75) contrast(1.05)" }} />
        </div>
        <div style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(42,35,32,.2) 0%, rgba(42,35,32,0) 35%, rgba(42,35,32,.6) 100%)" }} />

        <div className="tjc-hero-inner" style={{
          position: "absolute", inset: 0, display: "flex", flexDirection: "column",
          justifyContent: "center", alignItems: "center", textAlign: "center",
          padding: "0 40px", opacity: heroOpacity,
          transform: `translateY(${-titleY}px)`,
        }}>
          <div className="tjc-hero-kicker" style={{ fontSize: 11, letterSpacing: ".4em", textTransform: "uppercase", color: "var(--rose-wash)", marginBottom: 30 }}>
            {c.hero.kicker}
          </div>
          <h1 style={{
            fontFamily: "var(--f-display)", fontWeight: 400,
            fontSize: "clamp(72px, 13vw, 200px)", margin: 0, lineHeight: .95,
            letterSpacing: "-.02em",
          }}>
            <span>Tania</span>{" "}
            <span style={{ fontStyle: "italic", color: "var(--rose-wash)" }}>&</span>{" "}
            <span>Juan</span>
          </h1>
          <div className="tjc-hero-date-row" style={{ display: "flex", alignItems: "center", gap: 20, marginTop: 30 }}>
            <span className="line" style={{ width: 60, height: 1, background: "var(--rose-wash)" }} />
            <span className="tjc-hero-date" style={{ fontFamily: "var(--f-display)", fontStyle: "italic", fontSize: 22, letterSpacing: ".1em" }}>{c.hero.date}</span>
            <span className="line" style={{ width: 60, height: 1, background: "var(--rose-wash)" }} />
          </div>
          <div className="tjc-hero-city" style={{ marginTop: 14, fontSize: 12, letterSpacing: ".32em", textTransform: "uppercase", color: "rgba(239,230,220,.75)" }}>
            {c.hero.city}
          </div>
        </div>

        {/* Bottom countdown strip */}
        <div className="tjc-hero-bottom" style={{
          position: "absolute", bottom: 0, left: 0, right: 0,
          padding: "24px 40px",
          display: "flex", justifyContent: "space-between", alignItems: "center",
          background: "linear-gradient(180deg, transparent, rgba(42,35,32,.6))",
        }}>
          <div style={{ fontSize: 11, letterSpacing: ".3em", textTransform: "uppercase", color: "rgba(239,230,220,.7)" }}>
            {c.hero.countdown}
          </div>
          <CountdownC lang={lang} />
          <div className="tjc-hero-scroll" style={{ fontSize: 11, letterSpacing: ".3em", textTransform: "uppercase", color: "rgba(239,230,220,.7)" }}>
            ↓ Scroll
          </div>
        </div>
      </section>

      {/* STORY — cream panel on dark */}
      <section id="story" className="tjc-section" style={{ background: "var(--cream)", color: "var(--ink)", padding: "140px 40px" }}>
        <div style={{ maxWidth: 960, margin: "0 auto", textAlign: "center" }}>
          <RevealC><div className="eyebrow">— {c.story.eyebrow} —</div></RevealC>
          <RevealC delay={120}>
            <h2 style={{ fontFamily: "var(--f-display)", fontSize: "clamp(42px, 5.6vw, 78px)", fontWeight: 400, margin: "20px 0 48px", letterSpacing: "-.01em", textWrap: "balance", lineHeight: 1.08 }}>
              {c.story.title}
            </h2>
          </RevealC>
          {c.story.body.map((p, i) => (
            <RevealC key={i} delay={220 + i * 100}>
              <p style={{
                fontFamily: "var(--f-display)", fontSize: 22, lineHeight: 1.6,
                color: i === c.story.body.length - 1 ? "var(--rose)" : "var(--ink-soft)",
                fontStyle: i === c.story.body.length - 1 ? "italic" : "normal",
                margin: "0 auto 20px", maxWidth: 720, textWrap: "pretty",
              }}>
                {p}
              </p>
            </RevealC>
          ))}
        </div>
      </section>

      {/* Full-bleed photo break */}
      <div className="tjc-photo-break" style={{ position: "relative", height: "60vh", overflow: "hidden", background: "var(--ink)" }}>
        <img src="assets/story-quote.jpg" alt=""
             style={{ width: "100%", height: "100%", objectFit: "cover", filter: "brightness(.55) saturate(1.05)", transform: `translateY(${Math.min(60, (y - 1400) * 0.1)}px)` }} />
        <div style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(42,35,32,.35) 0%, rgba(42,35,32,.15) 40%, rgba(42,35,32,.6) 100%)" }} />
        <div style={{ position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center" }}>
          <div style={{ textAlign: "center", color: "var(--cream)" }}>
            <div className="tjc-photo-break-text" style={{ fontFamily: "var(--f-display)", fontStyle: "italic", fontSize: "clamp(40px, 6vw, 84px)", lineHeight: 1.15, maxWidth: 900, padding: "0 40px", textWrap: "balance" }}>
              {lang === "es"
                ? "“Nueve años sumando personas que se volvieron casa.”"
                : "“Nine years gathering people who became home.”"}
            </div>
          </div>
        </div>
      </div>

      {/* EVENTS — vertical cinematic list */}
      <section id="events" className="tjc-section" style={{ background: "var(--ink)", color: "var(--cream)", padding: "140px 40px" }}>
        <div style={{ maxWidth: 1200, margin: "0 auto" }}>
          <div style={{ textAlign: "center", marginBottom: 100 }}>
            <RevealC><div className="eyebrow" style={{ color: "var(--rose-wash)" }}>— {c.events.eyebrow} —</div></RevealC>
            <RevealC delay={120}>
              <h2 style={{ fontFamily: "var(--f-display)", fontSize: "clamp(56px, 8vw, 120px)", fontWeight: 400, margin: "18px 0 0", letterSpacing: "-.02em", lineHeight: 1 }}>
                {c.events.title}
              </h2>
            </RevealC>
          </div>

          {c.events.list.map((ev, i) => <EventBlockC key={i} ev={ev} idx={i} />)}
        </div>
      </section>

      {/* STAY + GIFTS — two tone bands */}
      <section className="tjc-split" style={{ display: "grid", gridTemplateColumns: "1fr 1fr" }}>
        {[
          { id: "stay", data: c.stay, href: TJ_LINKS.stay, bg: "var(--cream)", fg: "var(--ink)", accent: "var(--rose)" },
          { id: "gifts", data: c.gifts, href: TJ_LINKS.gifts, bg: "var(--rose)", fg: "var(--cream)", accent: "var(--cream)" },
        ].map((b) => (
          <div key={b.id} id={b.id} style={{ background: b.bg, color: b.fg, padding: "120px 60px", minHeight: 500, display: "flex", flexDirection: "column", justifyContent: "center" }}>
            <RevealC>
              <div style={{ fontSize: 11, letterSpacing: ".32em", textTransform: "uppercase", color: b.accent, marginBottom: 16 }}>— {b.data.eyebrow}</div>
            </RevealC>
            <RevealC delay={100}>
              <h3 style={{ fontFamily: "var(--f-display)", fontSize: "clamp(40px, 4.5vw, 64px)", fontWeight: 400, margin: "0 0 24px", letterSpacing: "-.01em", textWrap: "balance" }}>
                {b.data.title}
              </h3>
            </RevealC>
            <RevealC delay={200}>
              <p style={{ fontSize: 16, lineHeight: 1.7, maxWidth: 480, opacity: .85, margin: "0 0 32px" }}>{b.data.body}</p>
            </RevealC>
            <RevealC delay={300}>
              <a href={b.href} target="_blank" rel="noreferrer"
                 style={{ fontSize: 12, letterSpacing: ".28em", textTransform: "uppercase", paddingBottom: 6, borderBottom: `1px solid ${b.accent}`, display: "inline-block", alignSelf: "flex-start", color: b.accent }}>
                {b.data.cta} &nbsp;→
              </a>
            </RevealC>
          </div>
        ))}
      </section>

      {/* FAQ */}
      <section id="faq" className="tjc-section" style={{ background: "var(--cream)", color: "var(--ink)", padding: "140px 40px" }}>
        <div style={{ maxWidth: 900, margin: "0 auto" }}>
          <RevealC><div className="eyebrow">— {c.faq.eyebrow}</div></RevealC>
          <RevealC delay={100}>
            <h2 style={{ fontFamily: "var(--f-display)", fontSize: "clamp(44px, 6vw, 84px)", fontWeight: 400, margin: "16px 0 64px", letterSpacing: "-.01em" }}>{c.faq.title}</h2>
          </RevealC>
          {c.faq.items.map((it, i) => <FaqRowC key={i} q={it.q} a={it.a} i={i} />)}
        </div>
      </section>

      {/* FOOTER */}
      <footer className="tjc-footer" style={{ padding: "120px 40px 60px", textAlign: "center", background: "var(--ink)", color: "var(--cream)" }}>
        <div>
          <a className="tjc-cta-lg" href={TJ_LINKS.rsvp} target="_blank" rel="noreferrer">
            <span>{c.nav.rsvp}</span>
            <span className="arrow" aria-hidden>↗</span>
          </a>
        </div>
        <div className="tjc-footer-sig" style={{ fontFamily: "var(--f-display)", fontStyle: "italic", fontSize: "clamp(56px, 9vw, 140px)", color: "var(--rose-wash)", letterSpacing: "-.02em", lineHeight: 1, marginTop: 80 }}>
          {c.footer.sig}
        </div>
        <div style={{ fontSize: 11, letterSpacing: ".32em", textTransform: "uppercase", marginTop: 24, opacity: .6 }}>{c.footer.tag}</div>
      </footer>
    </div>
  );
}

function EventBlockC({ ev, idx }) {
  const [ref, shown] = useRevealC();
  return (
    <div ref={ref} style={{
      opacity: shown ? 1 : 0, transform: shown ? "none" : "translateY(30px)",
      transition: `all 1s ${idx * 120}ms var(--ease-out)`,
      padding: "48px 0", borderTop: "1px solid rgba(239,230,220,.15)",
      borderBottom: idx === 2 ? "1px solid rgba(239,230,220,.15)" : "none",
    }}>
      <div className="tjc-event-row" style={{ display: "grid", gridTemplateColumns: "200px 1fr 1fr", gap: 60, alignItems: "start" }}>
        <div>
          <div className="tjc-event-date" style={{ fontFamily: "var(--f-display)", fontStyle: "italic", fontSize: 28, color: "var(--rose-wash)" }}>{ev.day}</div>
          <div style={{ fontSize: 11, letterSpacing: ".3em", textTransform: "uppercase", color: "rgba(239,230,220,.65)", marginTop: 6 }}>{ev.date}</div>
          <div style={{ fontFamily: "var(--f-display)", fontSize: 20, marginTop: 18 }}>{ev.time}</div>
        </div>
        <div>
          <h3 className="tjc-event-name" style={{ fontFamily: "var(--f-display)", fontSize: "clamp(32px, 3.5vw, 52px)", fontWeight: 400, letterSpacing: "-.01em", margin: "0 0 20px", lineHeight: 1.05 }}>
            {ev.name}
          </h3>
          <p style={{ fontSize: 15, lineHeight: 1.7, color: "rgba(239,230,220,.8)", margin: 0 }}>{ev.desc}</p>
          {ev.place && <p style={{ fontSize: 13, color: "var(--rose-wash)", marginTop: 14, fontStyle: "italic", fontFamily: "var(--f-display)" }}>📍 {ev.place}</p>}
        </div>
        <div>
          <div style={{ fontSize: 11, letterSpacing: ".3em", textTransform: "uppercase", color: "var(--rose-wash)", marginBottom: 12 }}>Dress code</div>
          <p style={{ fontSize: 14, lineHeight: 1.6, margin: "0 0 12px" }}>{ev.dress}</p>
          {ev.extras?.map((x, j) => (
            <div key={j} style={{ marginTop: 14, fontSize: 13, lineHeight: 1.6, color: "rgba(239,230,220,.75)" }}>
              <span style={{ color: "var(--rose-wash)", fontWeight: 600 }}>{x.h}.</span> {x.p}
            </div>
          ))}
          {ev.moodboard && (
            <a href={TJ_LINKS.moodboard} target="_blank" rel="noreferrer"
               style={{ display: "inline-block", marginTop: 18, fontSize: 12, color: "var(--rose-wash)", borderBottom: "1px solid var(--rose-wash)", paddingBottom: 2, letterSpacing: ".15em", textTransform: "uppercase" }}>
              {ev.moodboard} ↗
            </a>
          )}
          {ev.note && (
            <p style={{ fontSize: 12, lineHeight: 1.6, color: "rgba(239,230,220,.6)", marginTop: 18, paddingTop: 14, borderTop: "1px solid rgba(239,230,220,.15)", fontStyle: "italic", fontFamily: "var(--f-display)" }}>{ev.note}</p>
          )}
        </div>
      </div>
    </div>
  );
}

function FaqRowC({ q, a, i }) {
  const [open, setOpen] = uC(i === 0);
  return (
    <div className="tjc-faq-row" style={{ borderTop: "1px solid var(--line)", borderBottom: i === 4 ? "1px solid var(--line)" : "none" }}>
      <button onClick={() => setOpen(!open)} style={{ width: "100%", textAlign: "left", padding: "26px 0", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
        <span className="tjc-faq-q" style={{ fontFamily: "var(--f-display)", fontSize: 22, fontWeight: 400 }}>{q}</span>
        <span style={{ color: "var(--rose)", fontSize: 26, transition: "transform .3s", transform: open ? "rotate(45deg)" : "none" }}>+</span>
      </button>
      <div style={{ maxHeight: open ? 200 : 0, overflow: "hidden", transition: "max-height .4s var(--ease-out)" }}>
        <p style={{ fontSize: 15, lineHeight: 1.7, color: "var(--ink-soft)", margin: "0 0 26px", maxWidth: 680, textWrap: "pretty" }}>{a}</p>
      </div>
    </div>
  );
}

window.VariationC = VariationC;
