// Yookie landing v5 — i18n, snap-scroll, reveal animations, pinned CTAs
const { useState, useEffect, useRef, useLayoutEffect, useMemo } = React;
const { useTweaks, TweaksPanel, TweakSection, TweakColor } = window;
const { ServiceFragment, TimeChip, MasterPill, CalendarFragment, ConfirmToast, SearchFragment } = window.YookieFragments;
const I18N = window.YookieI18n;

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "accent": "#39D1FF"
}/*EDITMODE-END*/;

const TG_BOT = "https://t.me/yookie_bot";

// ============================================================================
// Hooks
// ============================================================================
function useIsMobile(bp = 960) {
  const [m, setM] = useState(() => typeof window !== 'undefined' && window.innerWidth <= bp);
  useEffect(() => {
    const onR = () => setM(window.innerWidth <= bp);
    window.addEventListener("resize", onR);
    return () => window.removeEventListener("resize", onR);
  }, [bp]);
  return m;
}

function useReveal(threshold = 0) {
  const ref = useRef(null);
  const [v, setV] = useState(false);
  useEffect(() => {
    const el = ref.current; if (!el) return;
    // Find scrollable ancestor (snap-container) — observer needs it as root
    let root = null;
    let p = el.parentElement;
    while (p) {
      if (p.classList && p.classList.contains('snap-container')) { root = p; break; }
      p = p.parentElement;
    }
    // Negative bottom margin so reveal fires only AFTER element is well into the viewport,
    // not while it's still offscreen below.
    const io = new IntersectionObserver(([e]) => {
      if (e.isIntersecting) { setV(true); io.disconnect(); }
    }, { threshold, root, rootMargin: "0px 0px -30% 0px" });
    io.observe(el);
    return () => io.disconnect();
  }, [threshold]);
  return [ref, v];
}

// Lang persistence
function useLang() {
  const [lang, setLang] = useState(() => {
    try {
      const saved = localStorage.getItem("yookie_lang");
      if (saved && I18N[saved]) return saved;
    } catch (e) {}
    return "ru";
  });
  useEffect(() => {
    try { localStorage.setItem("yookie_lang", lang); } catch (e) {}
    document.documentElement.lang = lang;
  }, [lang]);
  return [lang, setLang];
}

// Parallax bg
function useParallaxBG(scrollEl) {
  useEffect(() => {
    const el = document.querySelector('.bg-glow');
    if (!el) return;
    const target = scrollEl || window;
    const onScroll = () => {
      const y = (target.scrollTop ?? window.scrollY) * 0.04;
      el.style.transform = `translateY(${-y}px)`;
    };
    target.addEventListener("scroll", onScroll, { passive: true });
    return () => target.removeEventListener("scroll", onScroll);
  }, [scrollEl]);
}

// ============================================================================
// Magnetic button
// ============================================================================
function MagneticButton({ children, primary, isMobile, href, onClick, ...rest }) {
  const ref = useRef(null);
  const [t, setT] = useState({ x: 0, y: 0 });
  const Tag = href ? "a" : "button";
  const linkProps = href ? { href, target: "_blank", rel: "noopener noreferrer" } : { onClick };
  return (
    <Tag
      ref={ref}
      onMouseMove={(e) => {
        if (isMobile) return;
        const r = ref.current.getBoundingClientRect();
        const x = (e.clientX - r.left - r.width / 2) * 0.25;
        const y = (e.clientY - r.top - r.height / 2) * 0.4;
        setT({ x, y });
      }}
      onMouseLeave={() => setT({ x: 0, y: 0 })}
      className={primary ? "btn-primary" : "btn-ghost"}
      style={{
        transform: `translate(${t.x}px, ${t.y}px)`,
        transition: "transform .25s cubic-bezier(.2,.8,.2,1)",
        textDecoration: "none"
      }}
      {...linkProps}
      {...rest}>
      {children}
    </Tag>
  );
}

function YookieLogo({ size = 28 }) {
  return <img src="assets/logo.svg" alt="Yookie" style={{ height: size, width: "auto", display: "block" }} />;
}

// ============================================================================
// Lang selector
// ============================================================================
function LangSelector({ lang, setLang, dark }) {
  const [open, setOpen] = useState(false);
  const ref = useRef(null);
  useEffect(() => {
    const onClick = (e) => { if (ref.current && !ref.current.contains(e.target)) setOpen(false); };
    document.addEventListener("mousedown", onClick);
    return () => document.removeEventListener("mousedown", onClick);
  }, []);
  const langs = [
    { c: "ru", l: "Русский", s: "RU" },
    { c: "uz", l: "O‘zbekcha", s: "UZ" },
    { c: "en", l: "English", s: "EN" }
  ];
  const current = langs.find(l => l.c === lang) || langs[0];
  return (
    <div ref={ref} style={{ position: "relative" }}>
      <button className="lang-btn" onClick={() => setOpen(o => !o)}>
        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a14 14 0 010 18M12 3a14 14 0 000 18"/></svg>
        {current.s}
        <svg width="9" height="9" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M6 9l6 6 6-6"/></svg>
      </button>
      {open && (
        <div className="lang-pop">
          {langs.map(l => (
            <button key={l.c} onClick={() => { setLang(l.c); setOpen(false); }} className={lang === l.c ? "active" : ""}>
              <span>{l.l}</span>
              <span style={{ fontSize: 11, opacity: 0.5, fontWeight: 700, letterSpacing: 0.5 }}>{l.s}</span>
            </button>
          ))}
        </div>
      )}
    </div>
  );
}

// ============================================================================
// Nav
// ============================================================================
function Nav({ t, lang, setLang }) {
  const [open, setOpen] = useState(false);
  return (
    <>
      <header style={{
        position: "fixed", top: 14, left: 0, right: 0, zIndex: 100,
        display: "flex", justifyContent: "center", pointerEvents: "none",
        padding: "0 16px"
      }}>
        <nav style={{
          pointerEvents: "auto",
          display: "flex", alignItems: "center", gap: 8,
          padding: "8px 8px 8px 22px",
          borderRadius: 999,
          background: "rgba(11,14,18,0.7)",
          backdropFilter: "blur(20px)",
          WebkitBackdropFilter: "blur(20px)",
          border: "1px solid rgba(255,255,255,0.08)",
          maxWidth: "100%"
        }}>
          <YookieLogo size={22} />
          <div className="nav-links" style={{ display: "flex", gap: 4, marginLeft: 18, marginRight: 8 }}>
            {[
              { l: t.nav.idea, h: "#idea" },
              { l: t.nav.how, h: "#how" },
              { l: t.nav.why, h: "#why" },
              { l: t.nav.masters, h: "#masters" }
            ].map((item) =>
              <a key={item.h} href={item.h} style={{
                padding: "8px 14px", fontSize: 13.5, color: "rgba(255,255,255,0.75)",
                textDecoration: "none", borderRadius: 999, fontWeight: 500
              }}>{item.l}</a>
            )}
          </div>
          <LangSelector lang={lang} setLang={setLang} />
          <button onClick={() => setOpen(true)} className="show-mobile" style={{
            display: "none", height: 38, width: 38, marginLeft: 4,
            borderRadius: 999, background: "rgba(255,255,255,0.06)",
            border: "1px solid rgba(255,255,255,0.1)", color: "#fff",
            placeItems: "center", cursor: "pointer"
          }}>
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M4 7h16M4 12h16M4 17h16"/></svg>
          </button>
          <a href={TG_BOT} target="_blank" rel="noopener noreferrer" style={{
            height: 38, padding: "0 18px", borderRadius: 999,
            background: "var(--ac)", color: "#000", border: "none",
            fontSize: 13.5, fontWeight: 700, cursor: "pointer",
            display: "inline-flex", alignItems: "center", textDecoration: "none"
          }}>{t.nav.cta}</a>
        </nav>
      </header>

      {open && (
        <div onClick={() => setOpen(false)} style={{
          position: "fixed", inset: 0, zIndex: 200,
          background: "rgba(8,10,14,0.85)", backdropFilter: "blur(24px)",
          display: "flex", flexDirection: "column",
          padding: "80px 24px 40px"
        }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 40 }}>
            <YookieLogo size={26} />
            <button onClick={() => setOpen(false)} style={{
              width: 40, height: 40, borderRadius: 999,
              background: "rgba(255,255,255,0.06)", border: "1px solid rgba(255,255,255,0.1)",
              color: "#fff", display: "grid", placeItems: "center", cursor: "pointer"
            }}>
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4"><path d="M6 6l12 12M18 6L6 18"/></svg>
            </button>
          </div>
          <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
            {[
              { l: t.nav.idea, h: "#idea" },
              { l: t.nav.how, h: "#how" },
              { l: t.nav.why, h: "#why" },
              { l: t.nav.masters, h: "#masters" }
            ].map((item) =>
              <a key={item.h} href={item.h} onClick={() => setOpen(false)} style={{
                padding: "18px 4px", fontSize: 28, color: "#fff",
                textDecoration: "none", fontWeight: 600,
                fontFamily: "'Gilroy', sans-serif", letterSpacing: -0.5,
                borderBottom: "1px solid rgba(255,255,255,0.06)"
              }}>{item.l}</a>
            )}
          </div>
        </div>
      )}
    </>
  );
}

// ============================================================================
// HERO — pill lifted up so it doesn't cover headline
// ============================================================================
function Hero({ t }) {
  const isMobile = useIsMobile();
  const [mouse, setMouse] = useState({ x: 0, y: 0 });
  const [ref, inView] = useReveal(0.05);

  useEffect(() => {
    if (isMobile) return;
    const onMove = (e) => {
      const w = window.innerWidth, h = window.innerHeight;
      setMouse({ x: (e.clientX - w / 2) / w, y: (e.clientY - h / 2) / h });
    };
    window.addEventListener("mousemove", onMove);
    return () => window.removeEventListener("mousemove", onMove);
  }, [isMobile]);

  return (
    <section ref={ref} id="top" className="snap-section" style={{
      position: "relative", overflow: "hidden",
      display: "flex", alignItems: "center", justifyContent: "center",
      padding: isMobile ? "120px 20px 80px" : "120px 32px 100px"
    }}>
      {!isMobile && (
        <>
          {/* SearchFragment lifted to top-left */}
          <div style={{
            position: "absolute", left: "7%", top: "20%",
            transform: `translate(${mouse.x * -18}px, ${mouse.y * -12}px)`,
            transition: "transform .4s ease-out", zIndex: 2
          }}>
            <SearchFragment delay={0.4} placeholder={t.hero.searchPh} />
          </div>
          {/* Confirm right-top */}
          <div style={{
            position: "absolute", right: "7%", top: "26%",
            transform: `translate(${mouse.x * 22}px, ${mouse.y * 18}px)`,
            transition: "transform .4s ease-out", zIndex: 2
          }}>
            <ConfirmToast delay={0.7} />
          </div>
          {/* TimeChip — small, bottom-right under text safely */}
          <div style={{
            position: "absolute", right: "12%", bottom: "16%",
            transform: `translate(${mouse.x * 14}px, ${mouse.y * -10}px)`,
            transition: "transform .4s ease-out", zIndex: 2
          }}>
            <TimeChip time="12:30" selected delay={1.0} />
          </div>
        </>
      )}

      <div style={{ position: "relative", zIndex: 5, textAlign: "center", maxWidth: 1100 }}>
        <div className="hero-tag" style={{
          display: "inline-flex", alignItems: "center", gap: 8,
          padding: "6px 14px 6px 8px", borderRadius: 999,
          background: "rgba(57,209,255,0.08)",
          border: "1px solid rgba(57,209,255,0.25)",
          fontSize: 12.5, color: "var(--ac)", marginBottom: isMobile ? 24 : 32, fontWeight: 500
        }}>
          <span style={{ width: 6, height: 6, borderRadius: "50%", background: "var(--ac)", boxShadow: "0 0 12px var(--ac)" }} />
          {t.hero.tag}
        </div>
        <h1 style={{
          fontFamily: "'Gilroy', sans-serif",
          fontSize: isMobile ? "clamp(48px, 13vw, 76px)" : "clamp(64px, 9vw, 152px)",
          lineHeight: 0.92, letterSpacing: isMobile ? -2 : -3.5,
          margin: 0, color: "#fff", fontWeight: 600,
          textWrap: "balance"
        }}>
          <span className="hero-line line-1">{t.hero.l1}</span>{" "}
          <span className="hero-line line-2" style={{ color: "var(--ac)", fontFamily: "'Caveat', cursive", fontWeight: 700, letterSpacing: -2 }}>{t.hero.l2}</span>
          <br />
          <span className="hero-line line-3">{t.hero.l3}</span>
        </h1>
        <p className="hero-sub" style={{
          fontSize: isMobile ? 16 : "clamp(15px, 1.5vw, 19px)",
          lineHeight: 1.55, color: "rgba(255,255,255,0.6)",
          marginTop: isMobile ? 24 : 32, maxWidth: 560, marginLeft: "auto", marginRight: "auto",
          padding: isMobile ? "0 12px" : 0
        }}>
          {t.hero.sub}
        </p>
        <div className="hero-ctas" style={{
          display: "flex", gap: 12, marginTop: isMobile ? 32 : 40,
          justifyContent: "center", flexWrap: "wrap"
        }}>
          <MagneticButton primary isMobile={isMobile} href={TG_BOT}>
            {t.hero.cta1}
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4"><path d="M5 12h14M13 5l7 7-7 7" /></svg>
          </MagneticButton>
          <MagneticButton isMobile={isMobile} onClick={() => document.getElementById('how')?.scrollIntoView({ behavior: 'smooth', block: 'start' })}>
            <svg width="11" height="11" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z" /></svg>
            {t.hero.cta2}
          </MagneticButton>
        </div>

        {isMobile && (
          <div style={{
            marginTop: 56, display: "flex", justifyContent: "center",
            gap: 14, flexWrap: "wrap"
          }}>
            <div style={{ transform: "rotate(-3deg)" }}>
              <SearchFragment delay={0.4} placeholder={t.hero.searchPh} />
            </div>
          </div>
        )}
      </div>

      {!isMobile && (
        <div style={{
          position: "absolute", bottom: 32, left: "50%", transform: "translateX(-50%)",
          display: "flex", flexDirection: "column", alignItems: "center", gap: 10, opacity: 0.5
        }}>
          <span style={{ fontSize: 11, letterSpacing: 2, textTransform: "uppercase", color: "rgba(255,255,255,0.6)" }}>{t.hero.scroll}</span>
          <div style={{ width: 24, height: 38, border: "1.5px solid rgba(255,255,255,0.4)", borderRadius: 14, position: "relative" }}>
            <div className="scroll-dot" style={{
              position: "absolute", top: 6, left: "50%", transform: "translateX(-50%)",
              width: 4, height: 8, borderRadius: 2, background: "var(--ac)"
            }} />
          </div>
        </div>
      )}
    </section>
  );
}

// ============================================================================
// IDEA
// ============================================================================
function Idea({ t }) {
  const isMobile = useIsMobile();
  const [ref, inView] = useReveal(0.2);
  return (
    <section ref={ref} id="idea" className="snap-section" style={{
      position: "relative", display: "flex", alignItems: "center", justifyContent: "center",
      overflow: "hidden", padding: isMobile ? "100px 20px" : "140px 32px"
    }}>
      <div className={`reveal-blur ${inView ? "in" : ""}`} style={{ maxWidth: 1100, textAlign: "center", position: "relative", zIndex: 2 }}>
        <div style={{
          fontSize: 12.5, letterSpacing: 3, textTransform: "uppercase",
          color: "rgba(255,255,255,0.45)", fontWeight: 600, marginBottom: 28
        }}>{t.idea.kicker}</div>
        <h2 style={{
          fontFamily: "'Gilroy', sans-serif",
          fontSize: isMobile ? "clamp(36px, 9vw, 56px)" : "clamp(40px, 5.5vw, 96px)",
          lineHeight: 1.05, letterSpacing: isMobile ? -1.5 : -2.4,
          margin: 0, fontWeight: 600,
          color: "#fff",
          textWrap: "balance"
        }}>
          {t.idea.h1}<br />
          {t.idea.h2a} <span style={{ color: "var(--ac)", fontFamily: "'Caveat', cursive", fontWeight: 700 }}>{t.idea.h2b}</span> {t.idea.h2c}<br />
          {t.idea.h3}
        </h2>
        <div className={`reveal-scale ${inView ? "in" : ""}`} style={{
          marginTop: isMobile ? 40 : 56,
          display: "inline-flex", gap: isMobile ? 20 : 32,
          padding: isMobile ? "16px 22px" : "20px 32px", borderRadius: 999,
          background: "rgba(255,255,255,0.03)", border: "1px solid rgba(255,255,255,0.08)",
          backdropFilter: "blur(12px)",
          flexWrap: "wrap", justifyContent: "center",
          transitionDelay: ".25s"
        }}>
          {t.idea.stats.map((s, i) =>
            <div key={i} style={{ display: "flex", alignItems: "baseline", gap: 8 }}>
              <span style={{
                fontFamily: "'Gilroy', sans-serif",
                fontSize: isMobile ? 28 : 36, fontWeight: 600, letterSpacing: -1,
                color: "var(--ac)"
              }}>{s[0]}</span>
              <span style={{ fontSize: 13, color: "rgba(255,255,255,0.6)" }}>{s[1]}</span>
            </div>
          )}
        </div>
      </div>
    </section>
  );
}

// ============================================================================
// PROBLEM/SOLUTION
// ============================================================================
function ProblemSolution({ t }) {
  const isMobile = useIsMobile();
  const [ref, inView] = useReveal(0.15);
  return (
    <section ref={ref} className="snap-section" style={{
      position: "relative", display: "flex", alignItems: "center", justifyContent: "center",
      overflow: "hidden", padding: isMobile ? "80px 20px" : "120px 32px"
    }}>
      <div className="grid-2" style={{
        maxWidth: 1320, width: "100%",
        display: "grid", gridTemplateColumns: "1fr 1fr",
        gap: 60, alignItems: "center"
      }}>
        <div className={`reveal-left ${inView ? "in" : ""}`}>
          <div style={{ fontSize: 12.5, letterSpacing: 2, textTransform: "uppercase", color: "rgba(255,255,255,0.45)", fontWeight: 600 }}>{t.ps.kickerLeft}</div>
          <h3 style={{
            fontFamily: "'Gilroy', sans-serif",
            fontSize: isMobile ? "clamp(36px, 9vw, 56px)" : "clamp(40px, 5vw, 80px)",
            lineHeight: 1.0, letterSpacing: isMobile ? -1.5 : -2,
            margin: "16px 0 32px", fontWeight: 600, color: "#fff"
          }}>
            {t.ps.titleLeft[0]}<br />{t.ps.titleLeft[1]}
          </h3>
          <div className={`stagger ${inView ? "in" : ""}`} style={{ display: "flex", flexDirection: "column", gap: 12 }}>
            {t.ps.problems.map((x, i) =>
              <div key={i} style={{
                display: "flex", alignItems: "center", gap: 14,
                padding: "16px 20px", background: "rgba(255,255,255,0.02)",
                border: "1px solid rgba(255,255,255,0.06)", borderRadius: 14
              }}>
                <span style={{
                  fontSize: 11, fontWeight: 700, color: "rgba(255,255,255,0.3)",
                  fontFeatureSettings: '"tnum"', width: 24
                }}>0{i + 1}</span>
                <div style={{ flex: 1 }}>
                  <div style={{ fontSize: 16, fontWeight: 600, color: "rgba(255,255,255,0.85)" }}>{x.t}</div>
                  <div style={{ fontSize: 12.5, color: "rgba(255,255,255,0.45)", marginTop: 2 }}>{x.d}</div>
                </div>
              </div>
            )}
          </div>
        </div>

        <div className={`reveal-right ${inView ? "in" : ""}`} style={{ transitionDelay: ".15s" }}>
          <div style={{ fontSize: 12.5, letterSpacing: 2, textTransform: "uppercase", color: "var(--ac)", fontWeight: 600 }}>{t.ps.kickerRight}</div>
          <h3 style={{
            fontFamily: "'Gilroy', sans-serif",
            fontSize: isMobile ? "clamp(36px, 9vw, 56px)" : "clamp(40px, 5vw, 80px)",
            lineHeight: 1.0, letterSpacing: isMobile ? -1.5 : -2,
            margin: "16px 0 32px", fontWeight: 600, color: "#fff"
          }}>
            {t.ps.titleRightA}<br /><span style={{ color: "var(--ac)", fontFamily: "'Caveat', cursive", fontWeight: 700 }}>{t.ps.titleRightB}</span>
          </h3>
          <div className={`stagger ${inView ? "in" : ""}`} style={{ display: "flex", flexDirection: "column", gap: 12 }}>
            {t.ps.solutions.map((x, i) =>
              <div key={i} style={{
                display: "flex", alignItems: "center", gap: 14,
                padding: "16px 20px", background: "rgba(57,209,255,0.04)",
                border: "1px solid rgba(57,209,255,0.18)", borderRadius: 14
              }}>
                <span style={{
                  width: 28, height: 28, borderRadius: 8, background: "var(--ac)",
                  display: "grid", placeItems: "center", flexShrink: 0
                }}>
                  <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="3"><path d="M5 12l5 5 9-11" /></svg>
                </span>
                <div style={{ flex: 1 }}>
                  <div style={{ fontSize: 16, fontWeight: 600, color: "#fff" }}>{x.t}</div>
                  <div style={{ fontSize: 12.5, color: "rgba(255,255,255,0.55)", marginTop: 2 }}>{x.d}</div>
                </div>
              </div>
            )}
          </div>
        </div>
      </div>
    </section>
  );
}

// ============================================================================
// HOW IT WORKS
// ============================================================================
function HowItWorks({ t }) {
  const isMobile = useIsMobile();
  const [ref, inView] = useReveal(0.2);

  return (
    <section ref={ref} id="how" className="snap-section" style={{
      position: "relative", display: "flex", alignItems: "center", justifyContent: "center",
      overflow: "hidden", padding: isMobile ? "80px 20px" : "120px 32px"
    }}>
      <div style={{ maxWidth: 1320, width: "100%" }}>
        <div className={`reveal ${inView ? "in" : ""}`} style={{ marginBottom: isMobile ? 40 : 64, display: "flex", alignItems: "end", justifyContent: "space-between", gap: 40, flexWrap: "wrap" }}>
          <div>
            <div style={{ fontSize: 12.5, letterSpacing: 2, textTransform: "uppercase", color: "rgba(255,255,255,0.45)", fontWeight: 600 }}>{t.how.kicker}</div>
            <h2 style={{
              fontFamily: "'Gilroy', sans-serif",
              fontSize: isMobile ? "clamp(36px, 9vw, 56px)" : "clamp(48px, 6vw, 88px)",
              lineHeight: 0.98, letterSpacing: isMobile ? -1.5 : -2,
              margin: "16px 0 0", fontWeight: 600, color: "#fff"
            }}>
              {t.how.titleA}<br /><span style={{ color: "var(--ac)", fontFamily: "'Caveat', cursive", fontWeight: 700 }}>{t.how.titleB}</span>
            </h2>
          </div>
          <p style={{
            fontSize: isMobile ? 15 : 17, color: "rgba(255,255,255,0.55)",
            maxWidth: 360, lineHeight: 1.55, margin: 0
          }}>
            {t.how.sub}
          </p>
        </div>

        <div className={`steps-row stagger ${inView ? "in" : ""}`} style={{
          background: "rgba(255,255,255,0.02)",
          border: "1px solid rgba(255,255,255,0.06)",
          borderRadius: isMobile ? 20 : 28,
          padding: isMobile ? 8 : 0,
          backdropFilter: "blur(12px)"
        }}>
          {t.how.steps.map((s, i) =>
            <div key={i} className="step" style={{
              padding: isMobile ? "20px 16px" : undefined
            }}>
              <div className="step-num">
                <span className="dot" />
                STEP 0{i + 1}
              </div>
              <div className="step-title">{s.t}</div>
              <p className="step-desc">{s.d}</p>
            </div>
          )}
        </div>

        {!isMobile && (
          <div className={`reveal ${inView ? "in" : ""}`} style={{
            marginTop: 40, display: "flex", alignItems: "center", justifyContent: "center",
            gap: 20, flexWrap: "wrap", transitionDelay: ".5s"
          }}>
            <div style={{ transform: "rotate(-3deg)" }}><SearchFragment delay={0.5} placeholder={t.hero.searchPh} /></div>
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.3)" strokeWidth="2"><path d="M5 12h14M13 5l7 7-7 7"/></svg>
            <div><TimeChip time="12:30" selected delay={0.7} /></div>
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.3)" strokeWidth="2"><path d="M5 12h14M13 5l7 7-7 7"/></svg>
            <div style={{ transform: "rotate(2deg)" }}><ConfirmToast delay={0.9} /></div>
          </div>
        )}
      </div>
    </section>
  );
}

// ============================================================================
// WHY
// ============================================================================
function Why({ t }) {
  const isMobile = useIsMobile();
  const [ref, inView] = useReveal(0.12);
  const symbols = ["⚡", "👁", "↻", "💬"];
  const spans = [2, 1, 1, 2];
  return (
    <section ref={ref} id="why" className="snap-section" style={{
      position: "relative", display: "flex", alignItems: "center", justifyContent: "center",
      overflow: "hidden", padding: isMobile ? "80px 20px" : "120px 32px"
    }}>
      <div style={{ maxWidth: 1320, width: "100%" }}>
        <h2 className={`reveal ${inView ? "in" : ""}`} style={{
          fontFamily: "'Gilroy', sans-serif",
          fontSize: isMobile ? "clamp(36px, 9vw, 56px)" : "clamp(48px, 6vw, 88px)",
          lineHeight: 0.98, letterSpacing: isMobile ? -1.5 : -2,
          margin: "0 0 48px", fontWeight: 600, color: "#fff", maxWidth: 700
        }}>
          {t.why.titleA} <span style={{ color: "var(--ac)", fontFamily: "'Caveat', cursive", fontWeight: 700 }}>{t.why.titleB}</span>
        </h2>
        <div className={`why-grid stagger ${inView ? "in" : ""}`}>
          {t.why.cards.map((c, i) =>
            <div key={i} className="why-card" style={{ gridColumn: `span ${spans[i]}` }}>
              <div className="why-sym">{symbols[i]}</div>
              <div style={{ marginTop: 24 }}>
                <div style={{ fontSize: isMobile ? 24 : "clamp(22px, 2.5vw, 32px)", fontWeight: 600, color: "#fff", letterSpacing: -0.6, fontFamily: "'Gilroy', sans-serif" }}>{c.t}</div>
                <div style={{ fontSize: 15, color: "rgba(255,255,255,0.55)", marginTop: 8, lineHeight: 1.55, maxWidth: 480 }}>{c.d}</div>
              </div>
              <div className="why-glow" />
            </div>
          )}
        </div>
      </div>
    </section>
  );
}

// ============================================================================
// FOR MASTERS
// ============================================================================
function ForMasters({ t }) {
  const isMobile = useIsMobile();
  const [ref, inView] = useReveal(0.15);
  return (
    <section ref={ref} id="masters" className="snap-section" style={{
      position: "relative", display: "flex", alignItems: "center", justifyContent: "center",
      overflow: "hidden", padding: isMobile ? "80px 20px" : "120px 32px"
    }}>
      <div className="grid-2" style={{
        maxWidth: 1320, width: "100%",
        display: "grid", gridTemplateColumns: "1.1fr 1fr",
        gap: 60, alignItems: "center"
      }}>
        <div className={`reveal-left ${inView ? "in" : ""}`}>
          <div style={{ fontSize: 12.5, letterSpacing: 2, textTransform: "uppercase", color: "var(--ac)", fontWeight: 600 }}>{t.masters.kicker}</div>
          <h2 style={{
            fontFamily: "'Gilroy', sans-serif",
            fontSize: isMobile ? "clamp(36px, 9vw, 56px)" : "clamp(44px, 5.5vw, 84px)",
            lineHeight: 0.98, letterSpacing: isMobile ? -1.5 : -2,
            margin: "16px 0 24px", fontWeight: 600, color: "#fff"
          }}>
            {t.masters.titleA}<br />{t.masters.titleB}<br /><span style={{ color: "var(--ac)", fontFamily: "'Caveat', cursive", fontWeight: 700 }}>{t.masters.titleC}</span>
          </h2>
          <p style={{
            fontSize: isMobile ? 15.5 : 17, color: "rgba(255,255,255,0.6)",
            maxWidth: 460, lineHeight: 1.55, margin: "0 0 28px"
          }}>
            {t.masters.sub}
          </p>
          <div className={`stagger ${inView ? "in" : ""}`} style={{ display: "flex", flexDirection: "column", gap: 10, marginBottom: 36 }}>
            {t.masters.bullets.map((p, i) =>
              <div key={i} style={{ display: "flex", alignItems: "center", gap: 12, fontSize: 15.5, color: "rgba(255,255,255,0.85)" }}>
                <span style={{ width: 22, height: 22, borderRadius: "50%", background: "rgba(57,209,255,0.12)", display: "grid", placeItems: "center", flexShrink: 0 }}>
                  <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="var(--ac)" strokeWidth="3"><path d="M5 12l5 5 9-11" /></svg>
                </span>
                {p}
              </div>
            )}
          </div>
          <MagneticButton primary isMobile={isMobile} href={TG_BOT}>
            {t.masters.cta}
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4"><path d="M5 12h14M13 5l7 7-7 7" /></svg>
          </MagneticButton>
        </div>

        <div className={`reveal-scale ${inView ? "in" : ""}`} style={{
          position: "relative",
          height: isMobile ? 420 : 480,
          transitionDelay: ".15s"
        }}>
          <div style={{
            position: "absolute", top: "8%", left: 0, right: 0,
            background: "rgba(255,255,255,0.03)",
            border: "1px solid rgba(255,255,255,0.08)",
            borderRadius: 20, padding: 24,
            backdropFilter: "blur(12px)",
            boxShadow: "0 40px 80px -30px rgba(0,0,0,0.6)"
          }}>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 16 }}>
              <div>
                <div style={{ fontSize: 12, color: "rgba(255,255,255,0.5)" }}>{t.masters.today}</div>
                <div style={{ fontSize: 22, fontWeight: 700, marginTop: 2, fontFamily: "'Gilroy', sans-serif", letterSpacing: -0.5 }}>{t.masters.booksToday}</div>
              </div>
              <div style={{
                fontSize: 11, padding: "5px 10px", borderRadius: 999,
                background: "rgba(57,209,255,0.12)", color: "var(--ac)", fontWeight: 700
              }}>{t.masters.growth}</div>
            </div>
            <div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
              {[
                { ti: "10:00", n: "Юлия С.", s: t.masters.services.manicure, st: "active" },
                { ti: "11:30", n: "Дарья В.", s: t.masters.services.brows, st: "ok" },
                { ti: "13:00", n: "Анна И.", s: t.masters.services.manicure, st: "ok" },
                { ti: "15:00", n: "Мария Р.", s: t.masters.services.coloring, st: "ok" }
              ].map((r, i) =>
                <div key={i} style={{
                  display: "flex", alignItems: "center", gap: 14,
                  padding: "10px 14px",
                  background: r.st === "active" ? "rgba(57,209,255,0.1)" : "rgba(255,255,255,0.02)",
                  border: r.st === "active" ? "1px solid rgba(57,209,255,0.3)" : "1px solid rgba(255,255,255,0.05)",
                  borderRadius: 12
                }}>
                  <div style={{ fontSize: 13, fontWeight: 700, color: r.st === "active" ? "var(--ac)" : "rgba(255,255,255,0.85)", width: 42 }}>{r.ti}</div>
                  <div style={{ flex: 1 }}>
                    <div style={{ fontSize: 13.5, fontWeight: 500 }}>{r.n}</div>
                    <div style={{ fontSize: 11.5, color: "rgba(255,255,255,0.5)" }}>{r.s}</div>
                  </div>
                  {r.st === "active" &&
                    <span style={{ fontSize: 10.5, fontWeight: 700, color: "var(--ac)", padding: "3px 7px", borderRadius: 6, background: "rgba(57,209,255,0.15)" }}>{t.masters.now}</span>
                  }
                </div>
              )}
            </div>
          </div>
          <div style={{ position: "absolute", top: -10, right: isMobile ? 0 : -16, animation: "bobA 4s ease-in-out infinite" }}>
            <ConfirmToast delay={0} />
          </div>
          <div style={{ position: "absolute", bottom: -10, left: isMobile ? 0 : -20, animation: "bobC 5.5s ease-in-out infinite" }}>
            <MasterPill name={t.masters.you} craft={t.masters.newClients} rating="—" hue={200} delay={0} />
          </div>
        </div>
      </div>
    </section>
  );
}

// ============================================================================
// FINAL CTA
// ============================================================================
function FinalCTA({ t }) {
  const isMobile = useIsMobile();
  const [ref, inView] = useReveal(0.2);
  return (
    <section ref={ref} className="snap-section" style={{
      position: "relative", display: "flex", alignItems: "center", justifyContent: "center",
      overflow: "hidden", padding: isMobile ? "100px 20px 60px" : "160px 32px 100px"
    }}>
      <div className={`reveal-blur ${inView ? "in" : ""}`} style={{ maxWidth: 1100, textAlign: "center", position: "relative", zIndex: 2, width: "100%" }}>
        <h2 style={{
          fontFamily: "'Gilroy', sans-serif",
          fontSize: isMobile ? "clamp(56px, 16vw, 96px)" : "clamp(64px, 10vw, 180px)",
          lineHeight: 0.92, letterSpacing: isMobile ? -2.5 : -4,
          margin: 0, fontWeight: 600, color: "#fff"
        }}>
          {t.final.titleA}<br />
          <span style={{ color: "var(--ac)", fontFamily: "'Caveat', cursive", fontWeight: 700, letterSpacing: -2 }}>{t.final.titleB}</span>
        </h2>
        <p style={{
          fontSize: isMobile ? 16 : 18, color: "rgba(255,255,255,0.6)",
          maxWidth: 540, margin: isMobile ? "24px auto 0" : "32px auto 0", lineHeight: 1.55
        }}>
          {t.final.sub}
        </p>
        <div style={{ display: "flex", gap: 12, justifyContent: "center", marginTop: 40, flexWrap: "wrap" }}>
          <MagneticButton primary isMobile={isMobile} href={TG_BOT}>
            {t.final.cta1}
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4"><path d="M5 12h14M13 5l7 7-7 7" /></svg>
          </MagneticButton>
          <MagneticButton isMobile={isMobile} href={TG_BOT}>{t.final.cta2}</MagneticButton>
        </div>

        <div style={{
          marginTop: isMobile ? 60 : 100,
          display: "flex", justifyContent: "space-between", alignItems: "center",
          color: "rgba(255,255,255,0.5)", fontSize: 12.5,
          paddingTop: 28, borderTop: "1px solid rgba(255,255,255,0.06)"
        }}>
          <YookieLogo size={22} />
          <span>{t.final.copyright}</span>
        </div>
      </div>
    </section>
  );
}

// ============================================================================
// App
// ============================================================================
function App() {
  const [tweaks, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const [lang, setLang] = useLang();
  const t = I18N[lang];
  const isMobile = useIsMobile();
  const containerRef = useRef(null);

  useParallaxBG(containerRef.current);

  useEffect(() => {
    document.documentElement.style.setProperty("--ac", tweaks.accent);
  }, [tweaks]);

  const accentPresets = [
    { v: "#39D1FF", l: "Cyan" },
    { v: "#A78BFA", l: "Lilac" },
    { v: "#34D399", l: "Mint" },
    { v: "#F59E0B", l: "Amber" },
    { v: "#FF6B9D", l: "Rose" }
  ];

  return (
    <div>
      <Nav t={t} lang={lang} setLang={setLang} />
      <main ref={containerRef} className={isMobile ? "" : "snap-container"}>
        <Hero t={t} />
        <Idea t={t} />
        <ProblemSolution t={t} />
        <HowItWorks t={t} />
        <Why t={t} />
        <ForMasters t={t} />
        <FinalCTA t={t} />
      </main>

      <TweaksPanel title={t.tweaks.title} defaultPos={{ right: 20, bottom: 20 }}>
        <TweakSection title={t.tweaks.accent}>
          <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
            {accentPresets.map((p) =>
              <button key={p.v} onClick={() => setTweak("accent", p.v)} style={{
                width: 36, height: 36, borderRadius: 10,
                border: tweaks.accent === p.v ? "2px solid #fff" : "2px solid transparent",
                background: p.v, cursor: "pointer", padding: 2
              }} title={p.l} />
            )}
          </div>
          <TweakColor label={t.tweaks.custom} value={tweaks.accent} onChange={(v) => setTweak("accent", v)} />
        </TweakSection>
      </TweaksPanel>
    </div>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
