/* eslint-disable */
// === Abra Caixas — Mobile gamified components ===
const { useState, useEffect, useRef, useMemo } = React;

// Where every CTA in the LP sends the user. Change in one place if the domain ever moves.
const REGISTER_URL = "https://abracaixas.com/auth/register";

// ---------- Icons (clean stroke) ----------
function Icon({ name, size = 16, ...rest }) {
  const c = { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", ...rest };
  switch (name) {
    case "box": return <svg {...c}><path d="m21 8-9 4-9-4 9-4 9 4Z" /><path d="m3 8 9 4v9" /><path d="m21 8-9 4v9" /></svg>;
    case "arrow": return <svg {...c}><path d="M5 12h14" /><path d="m13 5 7 7-7 7" /></svg>;
    case "play": return <svg {...c}><polygon points="6 4 20 12 6 20 6 4" /></svg>;
    case "flame": return <svg {...c}><path d="M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z" /></svg>;
    case "bolt": return <svg {...c}><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" /></svg>;
    case "shield": return <svg {...c}><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z" /><path d="m9 12 2 2 4-4" /></svg>;
    case "truck": return <svg {...c}><path d="M14 18V6H2v12h2" /><path d="M14 8h4l4 4v6h-4" /><circle cx="7" cy="18" r="2" /><circle cx="17" cy="18" r="2" /></svg>;
    case "lock": return <svg {...c}><rect width="18" height="11" x="3" y="11" rx="2" /><path d="M7 11V7a5 5 0 0 1 10 0v4" /></svg>;
    case "check": return <svg {...c}><polyline points="20 6 9 17 4 12" /></svg>;
    case "checkBig": return <svg {...c} viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" /><polyline points="16 9 11 14 8 11" /></svg>;
    case "plus": return <svg {...c}><path d="M12 5v14" /><path d="M5 12h14" /></svg>;
    case "users": return <svg {...c}><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" /><circle cx="9" cy="7" r="4" /><path d="M22 21v-2a4 4 0 0 0-3-3.87" /><path d="M16 3.13a4 4 0 0 1 0 7.75" /></svg>;
    case "target": return <svg {...c}><circle cx="12" cy="12" r="10" /><circle cx="12" cy="12" r="6" /><circle cx="12" cy="12" r="2" /></svg>;
    case "trophy": return <svg {...c}><path d="M6 9H4.5a2.5 2.5 0 0 1 0-5H6" /><path d="M18 9h1.5a2.5 2.5 0 0 0 0-5H18" /><path d="M4 22h16" /><path d="M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22" /><path d="M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22" /><path d="M18 2H6v7a6 6 0 0 0 12 0V2Z" /></svg>;
    case "calendar": return <svg {...c}><rect x="3" y="4" width="18" height="18" rx="2" /><line x1="16" x2="16" y1="2" y2="6" /><line x1="8" x2="8" y1="2" y2="6" /><line x1="3" x2="21" y1="10" y2="10" /></svg>;
    case "spark": return <svg {...c}><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" /><path d="M20 3v4" /><path d="M22 5h-4" /><path d="M4 17v2" /><path d="M5 18H3" /></svg>;
    case "clock": return <svg {...c}><circle cx="12" cy="12" r="10" /><polyline points="12 6 12 12 16 14" /></svg>;
    case "card": return <svg {...c}><rect width="20" height="14" x="2" y="5" rx="2" /><line x1="2" x2="22" y1="10" y2="10" /></svg>;
    case "phone": return <svg {...c}><rect width="14" height="20" x="5" y="2" rx="2" ry="2" /><line x1="12" x2="12.01" y1="18" y2="18" /></svg>;
    case "more": return <svg {...c}><circle cx="12" cy="5" r="1" /><circle cx="12" cy="12" r="1" /><circle cx="12" cy="19" r="1" /></svg>;
    case "pix": return <svg {...c} viewBox="0 0 24 24"><path d="M12 2 L22 12 L12 22 L2 12 Z" /><path d="M7 12 L12 7 L17 12 L12 17 Z" /></svg>;
    case "cart": return <svg {...c}><circle cx="9" cy="21" r="1" /><circle cx="20" cy="21" r="1" /><path d="M1 1h4l2.7 13.4a2 2 0 0 0 2 1.6h9.7a2 2 0 0 0 2-1.6L23 6H6" /></svg>;
    case "close": return <svg {...c}><path d="M18 6 6 18M6 6l12 12" /></svg>;
    case "login": return <svg {...c}><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4" /><polyline points="10 17 15 12 10 7" /><line x1="15" y1="12" x2="3" y2="12" /></svg>;
    case "userPlus": return <svg {...c}><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" /><circle cx="9" cy="7" r="4" /><line x1="19" y1="8" x2="19" y2="14" /><line x1="22" y1="11" x2="16" y2="11" /></svg>;
    default: return null;
  }
}

// ---------- Logo glyph ----------
function Logo() {
  return (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none">
      <path d="M3 7l9-4 9 4-9 4-9-4z" stroke="#fff" strokeWidth="2" strokeLinejoin="round" />
      <path d="M3 7v10l9 4" stroke="#fff" strokeWidth="2" strokeLinejoin="round" />
      <path d="M21 7v10l-9 4" stroke="#fff" strokeWidth="2" strokeLinejoin="round" />
      <circle cx="12" cy="13.5" r="1.5" fill="#fff" />
    </svg>
  );
}

// ---------- Box data with rarities ----------
const BOXES = [
  { id: "premium", name: "Caixa Premium", price: "49,99", img: "assets/box-premium.png", tint: "rgba(255,185,56,0.28)", rarity: "legendary", openers: 8421, featured: true },
  { id: "eletronicos", name: "Eletrônicos", price: "14,99", img: "assets/box-eletronicos.png", tint: "rgba(24,176,236,0.28)", rarity: "epic", openers: 24210 },
  { id: "gifts", name: "Gift Cards", price: "9,99", img: "assets/box-gifts.png", tint: "rgba(255,76,76,0.22)", rarity: "rare", openers: 32108 },
  { id: "apple", name: "Apple Box", price: "29,99", img: "assets/box-apple.png", tint: "rgba(20,184,166,0.22)", rarity: "epic", openers: 18204 },
  { id: "churrasco", name: "Churrasco", price: "12,99", img: "assets/box-churrasco.png", tint: "rgba(34,197,94,0.22)", rarity: "rare", openers: 14002 },
  { id: "beauty", name: "Beauty Box", price: "11,99", img: "assets/box-beauty.png", tint: "rgba(244,114,182,0.22)", rarity: "rare", openers: 11550 },
];

const FIRST_NAMES = ["Lucas", "Beatriz", "Rafael", "Mariana", "Diego", "Camila", "Thiago", "Júlia", "Pedro", "Larissa", "Gabriel", "Fernanda", "Igor", "Amanda", "Vinícius", "Bianca"];
const PRIZES = [
  { n: "iPhone 15 Pro", r: "legendary", v: "R$ 9.499" },
  { n: "PlayStation 5", r: "legendary", v: "R$ 4.299" },
  { n: "AirPods Pro 2", r: "epic", v: "R$ 2.099" },
  { n: "Gift R$ 500", r: "rare", v: "R$ 500" },
  { n: "Apple Watch", r: "epic", v: "R$ 3.299" },
  { n: "Voucher CVC R$2.500", r: "legendary", v: "R$ 2.500" },
  { n: "Echo Dot 5", r: "common", v: "R$ 249" },
  { n: "Kindle 11", r: "rare", v: "R$ 549" },
  { n: "Drone DJI Mini", r: "mythic", v: "R$ 3.799" },
  { n: "Notebook Gamer", r: "mythic", v: "R$ 7.999" },
];

// ---------- Top bar / HUD ----------
function TopBar() {
  return (
    <div className="topbar">
      <div className="topbar-row1">
        <a href="#" className="brand" aria-label="Abra Caixas">
          <img className="brand-logo" src="assets/logo.png" alt="Abra Caixas" />
        </a>
      </div>
    </div>
  );
}

// ---------- Intro animation ----------
const PRODUCTS = [
  { src: "assets/products/iphone.png", x: -90, y: -150, rot: -22, delay: 0.00, scale: 1.10 },
  { src: "assets/products/watch.png", x: 90, y: -150, rot: 20, delay: 0.06, scale: 1.05 },
  { src: "assets/products/xbox-gamepass.png", x: 0, y: -180, rot: -4, delay: 0.12, scale: 1.15 },
  { src: "assets/products/carmed-cola.png", x: -140, y: -30, rot: -28, delay: 0.18, scale: 0.95 },
  { src: "assets/products/lip-honey.png", x: 140, y: -30, rot: 24, delay: 0.22, scale: 0.95 },
  { src: "assets/products/carmed-doce.png", x: -130, y: 80, rot: -18, delay: 0.28, scale: 0.90 },
  { src: "assets/products/carmed-fini.png", x: 130, y: 80, rot: 16, delay: 0.32, scale: 0.90 },
];

function IntroSequence({ phase }) {
  const phases = ["shake", "click", "open", "text", "carousel"];
  const idx = phases.indexOf(phase);
  const cls = [
    "intro",
    "intro-" + phase,
    ...phases.slice(0, idx + 1).map(p => "has-" + p),
  ].join(" ");

  return (
    <div className={cls}>
      <div className="intro-rays"></div>
      <div className="intro-flash"></div>

      {/* CSS-built gift box (cyan + gold ribbon) */}
      <div className="gift-box">
        <div className="gift-glow"></div>

        <div className="gift-body">
          <div className="gift-body-shine"></div>
          <div className="gift-ribbon-v"></div>
          <div className="gift-ribbon-h"></div>
        </div>

        <div className="gift-lid">
          <div className="gift-lid-top">
            <div className="gift-ribbon-v"></div>
            <div className="gift-ribbon-h"></div>
            <div className="gift-bow">
              <span className="bow-l"></span>
              <span className="bow-r"></span>
              <span className="bow-c"></span>
              <span className="bow-tail bow-tail-l"></span>
              <span className="bow-tail bow-tail-r"></span>
            </div>
          </div>
        </div>
      </div>

      {/* Cursor */}
      <div className="intro-cursor">
        <svg width="32" height="36" viewBox="0 0 24 28" fill="#fff" stroke="#001220" strokeWidth="1.5" strokeLinejoin="round">
          <path d="M3 2 L3 22 L8 17 L11.5 26 L15 24.5 L11.5 16 L19 16 Z" />
        </svg>
        <span className="intro-cursor-ripple"></span>
        <span className="intro-cursor-ripple r2"></span>
      </div>

      {/* Real products erupting */}
      <div className="intro-prizes-img">
        {PRODUCTS.map((p, i) => (
          <div
            key={i}
            className="intro-prize-card"
            style={{
              "--tx": p.x + "px",
              "--ty": p.y + "px",
              "--rot": p.rot + "deg",
              "--sc": p.scale,
              "--delay": p.delay + "s",
            }}
          >
            <img src={p.src} alt="" />
          </div>
        ))}
      </div>

      {/* Sparks */}
      <div className="intro-sparks">
        {Array.from({ length: 14 }, (_, i) => (
          <span
            key={i}
            className="intro-spark"
            style={{
              "--ang": (i * (360 / 14)) + "deg",
              "--dist": (90 + (i % 3) * 30) + "px",
              "--delay": (0.02 * i) + "s",
            }}
          ></span>
        ))}
      </div>

      {/* Final message */}
      <div className="intro-message">
        <p>
          Você compra uma caixa<br />
          e recebe um <span className="hl">produto surpresa</span>.
        </p>
      </div>
    </div>
  );
}

// ---------- Hero ----------
function useLiveCounter(start = 2418, minMs = 1200, maxMs = 3400) {
  const [n, setN] = useState(start);
  useEffect(() => {
    let timer;
    const tick = () => {
      setN(v => v + (1 + Math.floor(Math.random() * 2))); // +1 or +2
      timer = setTimeout(tick, minMs + Math.random() * (maxMs - minMs));
    };
    timer = setTimeout(tick, minMs + Math.random() * (maxMs - minMs));
    return () => clearTimeout(timer);
  }, [minMs, maxMs]);
  return n;
}

function Hero() {
  const [phase, setPhase] = useState("shake"); // shake → click → open → text → carousel
  const [idx, setIdx] = useState(0);
  const [animate, setAnimate] = useState(true);
  const liveCount = useLiveCounter(2418);
  const N = BOXES.length;

  // Intro sequence timeline
  useEffect(() => {
    const timers = [
      setTimeout(() => setPhase("click"), 1400),
      setTimeout(() => setPhase("open"), 2200),
      setTimeout(() => setPhase("text"), 3900),
      setTimeout(() => setPhase("carousel"), 6800),
    ];
    return () => timers.forEach(clearTimeout);
  }, []);

  // Carousel: only start cycling once intro is over
  useEffect(() => {
    if (phase !== "carousel") return;
    const t = setInterval(() => setIdx(i => i + 1), 2600);
    return () => clearInterval(t);
  }, [phase]);

  // Seamless loop: when we transition into the clone at position N, snap back to 0
  useEffect(() => {
    if (idx === N) {
      const t = setTimeout(() => {
        setAnimate(false);
        setIdx(0);
        requestAnimationFrame(() => requestAnimationFrame(() => setAnimate(true)));
      }, 760);
      return () => clearTimeout(t);
    }
  }, [idx, N]);

  const trackList = [...BOXES, BOXES[0]]; // clone first at end
  const featured = BOXES[idx % N];
  const showCarousel = phase === "carousel";

  return (
    <section className="hero" style={{ "--featured-tint": featured.tint }}>
      <span className="hero-eyebrow">
        <span className="dot"></span>
        <span className="live-count" key={liveCount}>{liveCount.toLocaleString("pt-BR")}</span> caixas abertas hoje
      </span>
      <h1 className="display hero-title">
        Compre. Abra.
        <span className="accent">Surpreenda-se.</span>
      </h1>
      <p className="hero-sub">Caixas surpresa com produtos reais entregues na sua casa em até 10 dias.</p>

      <div className="hero-stage">
        <div className="hero-stage-bg"></div>
        <div className="hero-ring"></div>
        <div className="hero-ring r2"></div>

        <div className="sparkle" style={{ top: "12%", left: "30%", animationDelay: "0s" }}></div>
        <div className="sparkle" style={{ top: "25%", left: "70%", animationDelay: "0.4s" }}></div>
        <div className="sparkle" style={{ top: "60%", left: "18%", animationDelay: "0.8s" }}></div>
        <div className="sparkle" style={{ top: "78%", left: "62%", animationDelay: "1.2s" }}></div>
        <div className="sparkle" style={{ top: "40%", left: "84%", animationDelay: "1.6s" }}></div>
        <div className="sparkle" style={{ top: "20%", left: "10%", animationDelay: "0.6s" }}></div>

        {!showCarousel && <IntroSequence phase={phase} />}

        {showCarousel && (
          <div className="hero-carousel">
            <div
              className="hero-track"
              style={{
                transform: `translateX(-${idx * 100}%)`,
                transition: animate ? "transform 0.72s cubic-bezier(.62,.04,.18,1.01)" : "none",
              }}
            >
              {trackList.map((b, i) => (
                <div className="hero-slide" key={i}>
                  <img src={b.img} alt={b.name} />
                </div>
              ))}
            </div>
          </div>
        )}

        {showCarousel && (
          <div className="hero-dots">
            {BOXES.map((b, i) => (
              <span key={i} className={"hero-dot" + ((idx % N) === i ? " active" : "")}></span>
            ))}
          </div>
        )}
      </div>

      <div style={{ position: "relative" }}>
        <ConfettiLayer />
        <div className="hero-cta" style={{ position: "relative", zIndex: 2 }}>
          <a className="btn-cta" href={REGISTER_URL}>
            <Icon name="box" size={20} />
            Abrir minha primeira caixa grátis
          </a>
        </div>
      </div>

      <div className="hero-meta">
        <div className="meta-chip">
          <span className="ico"><Icon name="truck" size={18} /></span>
          <span><span className="label">Frete</span><span className="value">Grátis</span></span>
        </div>
        <div className="meta-chip">
          <span className="ico"><Icon name="bolt" size={18} /></span>
          <span><span className="label">Entrega</span><span className="value">Até 10 dias</span></span>
        </div>
        <div className="meta-chip">
          <span className="ico"><Icon name="shield" size={18} /></span>
          <span><span className="label">Garantia</span><span className="value">7 dias</span></span>
        </div>
        <div className="meta-chip">
          <span className="ico"><Icon name="lock" size={18} /></span>
          <span><span className="label">Pagamento</span><span className="value">Pix</span></span>
        </div>
      </div>
    </section>
  );
}

// ---------- Drop rates ----------
function DropRates() {
  const rates = [
    { name: "Comum", pct: "62.00%", color: "var(--r-common)" },
    { name: "Raro", pct: "24.50%", color: "var(--r-rare)" },
    { name: "Épico", pct: "9.80%", color: "var(--r-epic)" },
    { name: "Lendário", pct: "3.20%", color: "var(--r-legendary)" },
    { name: "Mítico", pct: "0.50%", color: "var(--r-mythic)" },
  ];
  return (
    <div className="droprates">
      <div className="droprates-head">
        <span>Drop rates — Eletrônicos</span>
        <span className="audit"><Icon name="checkBig" size={12} /> Auditado</span>
      </div>
      {rates.map(r => (
        <div className="droprate-row" key={r.name}>
          <span className="dot" style={{ background: r.color }}></span>
          <span style={{ fontWeight: 600 }}>{r.name}</span>
          <span className="pct" style={{ color: r.color }}>{r.pct}</span>
        </div>
      ))}
    </div>
  );
}

// ---------- Live drops feed ----------
function LiveDrops() {
  const [drops, setDrops] = useState(() => Array.from({ length: 4 }, (_, i) => makeDrop(i)));
  useEffect(() => {
    const t = setInterval(() => {
      setDrops(prev => [makeDrop(Date.now()), ...prev].slice(0, 4));
    }, 3800);
    return () => clearInterval(t);
  }, []);
  function makeDrop(seed) {
    const n = FIRST_NAMES[Math.floor(Math.random() * FIRST_NAMES.length)];
    const p = PRIZES[Math.floor(Math.random() * PRIZES.length)];
    const surname = String.fromCharCode(65 + Math.floor(Math.random() * 26)) + ".";
    return { id: seed + Math.random(), who: `${n} ${surname}`, prize: p, when: "agora" };
  }
  return (
    <div className="live-strip">
      <div className="live-head">
        <span className="pulse"></span>
        ao vivo · ganhos agora
      </div>
      {drops.map((d, i) => (
        <div className="drop-row" key={d.id}>
          <div className="av">{d.who.split(" ").map(x => x[0]).join("")}</div>
          <div className="info">
            <div className="who">{d.who}</div>
            <div className="got">ganhou <span className={"prize " + d.prize.r}>{d.prize.n}</span></div>
          </div>
          <span className="when">{i === 0 ? "agora" : `${i * 2 + 1}min`}</span>
        </div>
      ))}
    </div>
  );
}

// ---------- Featured caixa (limited) ----------
function FeaturedDeal() {
  const [time, setTime] = useState({ h: 4, m: 12, s: 38 });
  useEffect(() => {
    const t = setInterval(() => {
      setTime(({ h, m, s }) => {
        s -= 1;
        if (s < 0) { s = 59; m -= 1; }
        if (m < 0) { m = 59; h -= 1; }
        if (h < 0) { h = 0; m = 0; s = 0; }
        return { h, m, s };
      });
    }, 1000);
    return () => clearInterval(t);
  }, []);
  const fmt = (n) => String(n).padStart(2, "0");
  return (
    <div className="featured">
      <div className="featured-badge">
        <Icon name="flame" size={11} /> EM ALTA
      </div>
      <div className="featured-row">
        <div className="featured-img">
          <img src="assets/box-premium.png" alt="Caixa Premium" />
        </div>
        <div>
          <h3>Caixa Premium</h3>
          <p className="featured-sub">Top do catálogo. iPhone, viagens, ouro.</p>
          <div className="countdown">
            <Icon name="clock" size={14} />
            {fmt(time.h)}:{fmt(time.m)}:{fmt(time.s)}
          </div>
          <a className="featured-cta" href={REGISTER_URL}>
            <Icon name="box" size={14} />
            Abrir por R$ 49,99
          </a>
        </div>
      </div>
      <div className="featured-progress">
        <div></div>
      </div>
      <div className="featured-progress-label">
        <span>146 / 200 caixas abertas hoje</span>
        <span>73%</span>
      </div>
    </div>
  );
}

// ---------- Box card ----------
function BoxCard({ box }) {
  return (
    <div className="box-card" data-rarity={box.rarity} style={{ "--card-tint": box.tint }}>
      <div className="box-card-glow"></div>
      <span className="rarity-tag" data-r={box.rarity}>{box.rarity}</span>
      <div className="box-img">
        <img src={box.img} alt={box.name} />
      </div>
      <div className="box-name">{box.name}</div>
      <div className="box-bottom">
        <div className="box-price">
          <span className="cur">R$</span>{box.price}
        </div>
        <div className="box-openers">
          <Icon name="users" size={10} />
          {(box.openers / 1000).toFixed(1)}k
        </div>
      </div>
    </div>
  );
}

function BoxesSection() {
  return (
    <section className="section">
      <div className="section-head">
        <div>
          <div className="section-kicker">Catálogo · 12 caixas</div>
          <h2 className="section-title">Escolha sua caixa</h2>
        </div>
        <button className="section-link">Ver tudo <Icon name="arrow" size={12} /></button>
      </div>
      <div className="box-grid">
        {BOXES.map(b => <BoxCard box={b} key={b.id} />)}
      </div>
    </section>
  );
}

// ---------- Daily missions ----------
function Missions() {
  const missions = [
    { t: "Abra sua primeira caixa do dia", done: true, prog: "1/1", xp: 50, icon: "box" },
    { t: "Abra 3 caixas em sequência", done: false, prog: "1/3", percent: 33, xp: 150, icon: "spark" },
    { t: "Convide um amigo e ganhe XP duplo", done: false, prog: "0/1", percent: 0, xp: 300, icon: "users" },
  ];
  return (
    <section className="section">
      <div className="section-head">
        <div>
          <div className="section-kicker">Renova em 11h 24m</div>
          <h2 className="section-title">Missões diárias</h2>
        </div>
        <span className="section-link" style={{ color: "var(--cta)", cursor: "default" }}>
          +500 XP hoje
        </span>
      </div>
      <div className="missions">
        {missions.map((m, i) => (
          <div className={"mission" + (m.done ? " completed" : "")} key={i}>
            <div className="mission-icon">
              {m.done ? <Icon name="check" size={18} /> : <Icon name={m.icon} size={18} />}
            </div>
            <div>
              <p className="mission-title">{m.t}</p>
              <div className="mission-progress-bar">
                <div style={{ width: (m.done ? 100 : (m.percent || 0)) + "%" }}></div>
              </div>
              <div className="mission-meta">{m.prog} {m.done && "· Concluída"}</div>
            </div>
            <div className="mission-reward">
              <span className="mission-xp">+{m.xp} XP</span>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ---------- Leaderboard ----------
function Leaderboard() {
  const list = [
    { rank: 1, name: "@_marquinhos21", prize: "iPhone 15 Pro Max", amount: "R$ 11.499" },
    { rank: 2, name: "@biancaray", prize: "PlayStation 5 Pro", amount: "R$ 5.799" },
    { rank: 3, name: "@ph_drops", prize: "MacBook Air M3", amount: "R$ 9.999" },
    { rank: 4, name: "@dudugamer", prize: "Apple Watch Ultra", amount: "R$ 7.299" },
    { rank: 5, name: "@nathy.rmt", prize: "Voucher Viagem", amount: "R$ 4.500" },
  ];
  return (
    <section className="section">
      <div className="section-head">
        <div>
          <div className="section-kicker">Semana · Top 5</div>
          <h2 className="section-title">Maiores ganhos</h2>
        </div>
        <button className="section-link">Ranking <Icon name="arrow" size={12} /></button>
      </div>
      <div className="leaderboard">
        {list.map(it => (
          <div className="lb-row" data-rank={it.rank} key={it.rank}>
            <div className="lb-rank">{it.rank.toString().padStart(2, "0")}</div>
            <div className="lb-av">{it.name.replace("@", "").slice(0, 2).toUpperCase()}</div>
            <div className="lb-info">
              <div className="lb-name">{it.name}</div>
              <div className="lb-prize">{it.prize}</div>
            </div>
            <div className="lb-amount">{it.amount}</div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ---------- How it works ----------
function HowItWorks() {
  const steps = [
    { n: "1", t: "Escolha a caixa", d: "Mais de 12 temas — eletrônicos, gifts, apple, beauty…" },
    { n: "2", t: "Confirme no Pix", d: "Pagamento instantâneo. Cartão e boleto também rolam." },
    { n: "3", t: "Receba em casa", d: "Frete grátis, rastreio em tempo real, até 10 dias úteis." },
  ];
  return (
    <section className="section">
      <div className="section-head">
        <div>
          <div className="section-kicker">Como rola</div>
          <h2 className="section-title">3 passos, sem segredo</h2>
        </div>
      </div>
      <div className="how">
        {steps.map(s => (
          <div className="how-step" key={s.n}>
            <div className="num">{s.n}</div>
            <div>
              <h4>{s.t}</h4>
              <p>{s.d}</p>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ---------- Trust ----------
function Trust() {
  const items = [
    { ico: "truck", t: "Frete sempre grátis", x: "Em todo o território nacional, sem mínimo." },
    { ico: "shield", t: "Produtos lacrados", x: "Tudo novo, com nota fiscal e garantia." },
    { ico: "lock", t: "Pagamento seguro", x: "Criptografia + antifraude em todas as compras." },
    { ico: "bolt", t: "Entrega rastreada", x: "Acompanhe o status em tempo real no app." },
  ];
  return (
    <section className="section">
      <div className="section-head">
        <div>
          <div className="section-kicker">Por que confiar</div>
          <h2 className="section-title">Sem trolagem.</h2>
        </div>
      </div>
      <div className="trust-strip">
        {items.map(it => (
          <div className="trust-item" key={it.t}>
            <span className="ico"><Icon name={it.ico} size={18} /></span>
            <span className="tt">{it.t}</span>
            <span className="tx">{it.x}</span>
          </div>
        ))}
      </div>
    </section>
  );
}

// ---------- FAQ ----------
function FAQ() {
  const items = [
    { q: "É confiável mesmo?", a: "Sim. Operamos com CNPJ ativo, nota fiscal em todo pedido, drop rates auditados e exibidos publicamente em cada caixa. Você sabe exatamente o que tá comprando." },
    { q: "Quanto tempo até receber?", a: "Entrega em até 10 dias úteis pra todo Brasil, com frete grátis. Pedidos confirmados até 14h saem no mesmo dia." },
    { q: "E se vier algo que eu não quero?", a: "Todo produto chega novo e lacrado, com 7 dias pra arrependimento (CDC) + 30 dias contra defeito de fabricação. Trocas pelo app em 1 minuto." },
    { q: "Posso pagar no Pix?", a: "Pode. Pix aprova em segundos, cartão em até 12x e boleto em 1 dia útil." },
  ];
  const [open, setOpen] = useState(0);
  return (
    <section className="section">
      <div className="section-head">
        <div>
          <div className="section-kicker">FAQ</div>
          <h2 className="section-title">Perguntas frequentes</h2>
        </div>
      </div>
      <div className="faq">
        {items.map((it, i) => (
          <div className={"faq-item" + (open === i ? " open" : "")} key={i}>
            <button className="faq-q" onClick={() => setOpen(open === i ? -1 : i)}>
              <span>{it.q}</span>
              <span className="ico"><Icon name="plus" size={12} /></span>
            </button>
            {open === i && <div className="faq-a">{it.a}</div>}
          </div>
        ))}
      </div>
    </section>
  );
}

// ---------- Sticky ticker / live conversion ----------
const TICKER_MSGS = [
  { type: "purchase", who: "Lucas R.", item: "Caixa Eletrônicos" },
  { type: "win", who: "Mariana S.", item: "iPhone 17", rare: true, emoji: "📱" },
  { type: "purchase", who: "Felipe T.", item: "Caixa Premium" },
  { type: "win", who: "João A.", item: "Apple Watch Series 10", rare: true, emoji: "⌚" },
  { type: "purchase", who: "Camila B.", item: "Caixa Apple" },
  { type: "win", who: "Bia G.", item: "Carmed Coca-Cola", emoji: "💄" },
  { type: "purchase", who: "Diego M.", item: "Caixa Beauty" },
  { type: "win", who: "Ana P.", item: "Xbox Game Pass 12M", emoji: "🎮" },
  { type: "purchase", who: "Pedro V.", item: "Caixa Gifts" },
  { type: "win", who: "Larissa D.", item: "AirPods Pro 3", rare: true, emoji: "🎧" },
  { type: "purchase", who: "Thiago N.", item: "Caixa Eletrônicos" },
  { type: "win", who: "Beatriz F.", item: "Lip Honey Candy", emoji: "🍯" },
];

function LiveTicker() {
  const [visible, setVisible] = useState(false);
  const [idx, setIdx] = useState(0);

  useEffect(() => {
    const t = setTimeout(() => setVisible(true), 2800);
    return () => clearTimeout(t);
  }, []);

  useEffect(() => {
    if (!visible) return;
    const t = setInterval(() => setIdx(i => (i + 1) % TICKER_MSGS.length), 4000);
    return () => clearInterval(t);
  }, [visible]);

  if (!visible) return null;
  const msg = TICKER_MSGS[idx];
  const isWin = msg.type === "win";

  return (
    <div className="ticker-wrap">
      <div
        key={idx}
        className={"ticker" + (msg.rare ? " ticker-rare" : "") + (isWin ? " ticker-win" : "")}
      >
        <div className="ticker-icon">
          {isWin
            ? <span className="ticker-emoji">{msg.emoji}</span>
            : <Icon name="cart" size={15} />}
          {msg.rare && <span className="rare-dot"></span>}
        </div>
        <div className="ticker-body">
          <div className="ticker-title">
            {isWin ? (
              <><strong>{msg.who}</strong> ganhou <span className="ticker-item">{msg.item}</span></>
            ) : (
              <><span className="ticker-event">Nova caixa comprada</span></>
            )}
          </div>
          <div className="ticker-sub">
            {isWin ? "agora mesmo" : `${msg.who} · ${msg.item}`}
          </div>
        </div>
      </div>
    </div>
  );
}

// ---------- Conversion popup (bottom sheet) ----------
function ConversionPopup({ onClose }) {
  return (
    <>
      <div className="popup-backdrop" onClick={onClose}></div>
      <div className="popup-sheet">
        <button className="popup-close" onClick={onClose} aria-label="Fechar">
          <Icon name="close" size={14} />
        </button>
        <div className="popup-handle"></div>
        <div className="popup-icon">
          <img src="assets/logo.png" alt="" />
          <span className="popup-icon-shine"></span>
        </div>
        <span className="popup-eyebrow">
          <span className="dot"></span>
          Oferta de boas-vindas
        </span>
        <h3>Criar conta e<br />Girar Caixa <span className="hl">Grátis</span></h3>
        <p>Cadastre-se em 30 segundos e ganhe sua primeira caixa por nossa conta.</p>
        <a className="popup-cta" href={REGISTER_URL}>
          <Icon name="box" size={18} />
          Criar conta agora
        </a>
      </div>
    </>
  );
}
function Dock() {
  return (
    <div className="dock">
      <div className="dock-info">
        <div>Caixa em alta</div>
        <div className="v">R$ 14,99</div>
      </div>
      <a className="dock-cta" href={REGISTER_URL}>
        <Icon name="box" size={18} />
        Abrir caixa agora
      </a>
    </div>
  );
}

// ---------- Confetti background piece ----------
function ConfettiLayer() {
  const colors = ["#18B0EC", "#FF7A1A", "#FFB938", "#B85CFF", "#16C784"];
  const pieces = useMemo(() => Array.from({ length: 14 }, (_, i) => ({
    left: Math.random() * 100,
    delay: Math.random() * 6,
    duration: 5 + Math.random() * 3,
    color: colors[i % colors.length],
    rot: Math.random() * 360,
  })), []);
  return (
    <div style={{ position: "absolute", inset: 0, overflow: "hidden", pointerEvents: "none", zIndex: 1 }}>
      {pieces.map((p, i) => (
        <span className="confetti" key={i} style={{
          left: p.left + "%",
          top: "20%",
          background: p.color,
          animationDelay: p.delay + "s",
          animationDuration: p.duration + "s",
          transform: `rotate(${p.rot}deg)`,
        }}></span>
      ))}
    </div>
  );
}

Object.assign(window, {
  TopBar, Hero, DropRates, LiveDrops, FeaturedDeal, BoxesSection, Missions,
  Leaderboard, HowItWorks, Trust, FAQ, Dock, ConfettiLayer, Icon,
  LiveTicker, ConversionPopup
});
