// app.jsx — givemesomemoney.lol
// One-page, deadpan-honest donation site. You send money. You get nothing.

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "palette": ["#1a1410", "#f6f1e4", "#2f8a5f"],
  "vibe": "deadpan",
  "honestCounter": true,
  "showCoinRain": true,
  "headline": "GIVE ME SOME MONEY",
  "name": "Michael"
}/*EDITMODE-END*/;

// ── Copy banks keyed by vibe ────────────────────────────────────────────────
const COPY = {
  deadpan: {
    sub: "A website where you send money to a stranger. In exchange, you receive nothing. It's that simple.",
    cta: "Give me some money",
    smallprint: "No refunds. No receipts. No thank-you note. No nothing.",
    ticker: ["NO PRODUCT", "NO SERVICE", "NO FREE TIER", "NO PERK", "NO NEWSLETTER", "NO REFUND", "NO MERCH", "NO STREAM", "NO CALL", "NO REPLY"],
    tiersTitle: "Pick an amount. You will get nothing.",
    receiptHeader: "Receipt of nothing",
  },
  hyped: {
    sub: "THE WEBSITE OF THE CENTURY!! Send your money to a complete stranger and watch in real time as you receive ABSOLUTELY ZERO things in return!!!",
    cta: "YES! TAKE IT!",
    smallprint: "WOW! No refunds, no thank-you, no anything! INCREDIBLE!!",
    ticker: ["BIG!!!", "HUGE!!", "FREE NOTHING", "INSANE VALUE", "LIMITLESS NOTHING", "JUST DO IT", "WOW", "EPIC", "NOTHING!!"],
    tiersTitle: "PICK AN AMOUNT! GET NOTHING! LET'S GO!",
    receiptHeader: "OFFICIAL CERTIFICATE OF NOTHING",
  },
  hostile: {
    sub: "You are still reading this. Just send the money. You won't get anything. That is the entire premise. Why are you scrolling.",
    cta: "Fine. Take it.",
    smallprint: "Don't email me. Don't ask for anything. There is nothing.",
    ticker: ["STILL NOTHING", "STOP READING", "JUST SEND IT", "NO REFUND", "NO PRODUCT", "GO AWAY", "SEND IT", "OR DON'T"],
    tiersTitle: "Pick one. Hurry up.",
    receiptHeader: "We took your money",
  },
};

// ── Tiers ───────────────────────────────────────────────────────────────────
const TIERS = [
  { amt: 1,   name: "The Symbolic",      gets: "Nothing",                                 sub: "A clean, dignified nothing." },
  { amt: 5,   name: "The Coffee",        gets: "....not a thing",                                 sub: "What I would have spent on coffee. Now I have it." },
  { amt: 20,  name: "The Lunch",         gets: "Nothing",                                 sub: "I will eat. You will not be there." },
  { amt: 50,  name: "The Statement",     gets: "Two handfuls of nothing",                                 sub: "A statement piece of nothing." },
  { amt: 100, name: "The Patron",        gets: "Nothing",                                 sub: "You'll still get nothing. Just a richer nothing." },
  { amt: 500, name: "The Lapse",         gets: "Nothing, plus a question mark from your bank", sub: "A lapse in judgment, but make it generous." },
  { amt: 2500,name: "The Disappearance", gets: "Nothing. I will also disappear briefly.", sub: "Cannot be undone. Will not be acknowledged." },
  { amt: 10000,name: "The Taxable Amount", gets: "Nothing. But now I have to fill out tax paperwork.", sub: "IRS paperwork for me. Nothing for you." },
];

function pickTier(amt) {
  let best = TIERS[0];
  for (const t of TIERS) if (amt >= t.amt) best = t;
  return best;
}

const fmt$ = (n) => "$" + n.toLocaleString("en-US");

// ── Hooks ───────────────────────────────────────────────────────────────────

function useEasedCount(target, dur = 1400) {
  const [val, setVal] = React.useState(0);
  React.useEffect(() => {
    let raf, start;
    const from = 0;
    const to = target;
    const tick = (t) => {
      if (start == null) start = t;
      const p = Math.min(1, (t - start) / dur);
      const eased = 1 - Math.pow(1 - p, 3);
      setVal(Math.round(from + (to - from) * eased));
      if (p < 1) raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [target, dur]);
  return val;
}

// ── App ─────────────────────────────────────────────────────────────────────

function App() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const copy = COPY[t.vibe] || COPY.deadpan;
  const [amount, setAmount] = React.useState(20);
  const [coins, setCoins] = React.useState([]);
  const [receipt, setReceipt] = React.useState(null);
  const [clicks, setClicks] = React.useState(0);
  const [counterBoost, setCounterBoost] = React.useState(0);
  const [loading, setLoading] = React.useState(false);
  const accent = "#2f8a5f";

  const counterBase = t.honestCounter ? 0 : 18247;
  const counterTarget = counterBase + counterBoost;
  const live = useEasedCount(counterTarget, 1200);

  // On mount: check for Stripe redirect success params
  React.useEffect(() => {
    const params = new URLSearchParams(window.location.search);
    if (params.get("success") === "true") {
      const paidAmount = Number(params.get("amount")) || 20;
      // Clean URL without replacing history entry
      window.history.replaceState({}, "", "/");
      setCounterBoost((b) => b + paidAmount);
      setClicks((c) => c + 1);
      if (t.showCoinRain) spawnCoins(paidAmount);
      setReceipt({
        amount: paidAmount,
        tier: pickTier(paidAmount),
        id: (params.get("session_id") || "").slice(-8).toUpperCase() || Math.random().toString(36).slice(2, 10).toUpperCase(),
        ts: new Date(),
      });
    }
  }, []);

  const spawnCoins = (amt) => {
    const id = Date.now();
    const newCoins = Array.from({ length: 22 }, (_, i) => ({
      id: id + i,
      left: Math.random() * 100,
      dx: (Math.random() - 0.5) * 30,
      delay: Math.random() * 0.4,
      rot: 720 + Math.random() * 1440,
      dur: 1.4 + Math.random() * 0.9,
      size: 22 + Math.random() * 22,
      kind: Math.random() > 0.3 ? "coin" : "bill",
    }));
    setCoins((cur) => [...cur, ...newCoins]);
    setTimeout(() => {
      setCoins((cur) => cur.filter((c) => !newCoins.find((n) => n.id === c.id)));
    }, 2800);
  };

  const onGive = async (amt) => {
    if (loading) return;
    setLoading(true);
    try {
      const res = await fetch("/api/create-checkout-session", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ amount: amt }),
      });
      if (!res.ok) throw new Error(await res.text());
      const { url } = await res.json();
      window.location = url;
    } catch (err) {
      console.error("Checkout error:", err);
      setLoading(false);
      alert("Payment unavailable right now. Try again in a moment.");
    }
  };

  return (
    <div style={{ position: "relative" }}>
      <TopBar copy={copy} name={t.name} accent={accent} />
      <Hero
        headline={t.headline}
        sub={copy.sub}
        cta={copy.cta}
        smallprint={copy.smallprint}
        accent={accent}
        amount={amount}
        setAmount={setAmount}
        onGive={onGive}
        loading={loading}
      />
      <Ticker items={copy.ticker} accent={accent} />
      <Counter live={live} clicks={clicks} honest={t.honestCounter} accent={accent} />

      <Tiers title={copy.tiersTitle} onPick={(amt) => { setAmount(amt); onGive(amt); }} accent={accent} loading={loading} />
      <HowItWorks accent={accent} />
      <Testimonials accent={accent} />
      <FAQ accent={accent} />
      <CTAStrip cta={copy.cta} accent={accent} onGive={() => onGive(amount)} loading={loading} />
      <Footer name={t.name} />

      <CoinRain coins={coins} />
      {receipt && <ReceiptModal receipt={receipt} header={copy.receiptHeader} name={t.name} onClose={() => setReceipt(null)} />}
      {loading && <LoadingOverlay />}
    </div>
  );
}

// ── LoadingOverlay ──────────────────────────────────────────────────────────
function LoadingOverlay() {
  return (
    <div style={{
      position: "fixed", inset: 0, zIndex: 200,
      background: "rgba(246,241,228,0.72)",
      backdropFilter: "blur(4px)",
      WebkitBackdropFilter: "blur(4px)",
      display: "flex", alignItems: "center", justifyContent: "center",
      flexDirection: "column", gap: 18,
    }}>
      <div style={{
        width: 44, height: 44, borderRadius: "50%",
        border: "3px solid rgba(26,20,16,0.12)",
        borderTopColor: "#2f8a5f",
        animation: "spin 0.8s linear infinite",
      }} />
      <div style={{ fontFamily: "var(--mono)", fontSize: 13, opacity: 0.65 }}>
        Opening payment…
      </div>
    </div>
  );
}

// ── TopBar ──────────────────────────────────────────────────────────────────
function TopBar({ copy, name, accent }) {
  return (
    <header style={{
      display: "flex", alignItems: "center", justifyContent: "space-between",
      padding: "20px 32px", borderBottom: "0.5px solid var(--rule)",
      position: "sticky", top: 0, zIndex: 5,
      background: "rgba(246,241,228,0.78)", backdropFilter: "blur(10px)",
      WebkitBackdropFilter: "blur(10px)",
    }}>
      <div style={{ display: "flex", alignItems: "center", gap: 10, fontFamily: "var(--mono)", fontSize: 13, letterSpacing: "0.02em" }}>
        {/* <span style={{
          display: "inline-block", width: 10, height: 10, borderRadius: 99,
          background: accent, boxShadow: `0 0 0 3px ${accent}22`,
        }} /> */}
        <span style={{ fontWeight: 600 }}>givemesomemoney</span>
        <span style={{ opacity: 0.45 }}>.lol</span>
      </div>
      <nav style={{ display: "flex", gap: 26, fontSize: 14, fontFamily: "var(--mono)" }}>
        <a href="#how" style={navStyle}>how</a>
        <a href="#tiers" style={navStyle}>tiers</a>
        <a href="#faq" style={navStyle}>faq</a>
        <a href="#give" style={{ ...navStyle, color: accent, fontWeight: 600 }}>give →</a>
      </nav>
    </header>
  );
}
const navStyle = { textDecoration: "none", color: "var(--ink)", opacity: 0.75 };

// ── Hero ────────────────────────────────────────────────────────────────────
function Hero({ headline, sub, cta, smallprint, accent, amount, setAmount, onGive, loading }) {
  const presets = [1, 5, 20, 50, 100, 500];
  const tier = pickTier(amount);
  return (
    <section id="give" style={{
      maxWidth: 1180, margin: "0 auto", padding: "64px 32px 32px",
      display: "grid", gridTemplateColumns: "1fr", gap: 48,
    }}>
      <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-start" }}>
        {/* <div style={{
          display: "inline-flex", alignItems: "center", gap: 8,
          padding: "6px 12px", borderRadius: 999,
          background: "#fff", border: "0.5px solid var(--rule)",
          fontFamily: "var(--mono)", fontSize: 12, letterSpacing: "0.04em",
          textTransform: "uppercase", marginBottom: 28,
        }}>
          <span style={{ width: 6, height: 6, borderRadius: 99, background: accent, animation: "pulseGlow 2s infinite" }} />
          Live & accepting funds
        </div> */}

        <h1 style={{
          fontFamily: "var(--serif)", fontWeight: 400,
          fontSize: "clamp(64px, 13vw, 200px)",
          lineHeight: 0.92, letterSpacing: "-0.02em",
          margin: 0, color: "var(--ink)",
          textWrap: "balance",
        }}>
          {headline.split(" ").map((w, i, arr) => (
            <React.Fragment key={i}>
              {i === arr.length - 1 ? (
                <span style={{ fontStyle: "italic", color: accent }}>{w}</span>
              ) : w}
              {i < arr.length - 1 ? " " : ""}
            </React.Fragment>
          ))}
        </h1>

        <p style={{
          fontFamily: "var(--serif)", fontSize: "clamp(20px, 2.2vw, 28px)",
          lineHeight: 1.35, maxWidth: 720, margin: "28px 0 0",
          color: "var(--ink-soft)", fontStyle: "italic",
        }}>
          {sub}
        </p>
      </div>

      {/* Amount picker */}
      <div style={{
        display: "grid", gridTemplateColumns: "minmax(0,1fr) auto", gap: 32,
        alignItems: "end", borderTop: "0.5px solid var(--rule)", paddingTop: 36,
      }}>
        <div>
          <div style={{ display: "flex", alignItems: "baseline", justifyContent: "space-between", marginBottom: 12 }}>
            <div style={{ fontFamily: "var(--mono)", fontSize: 12, letterSpacing: "0.06em", textTransform: "uppercase", opacity: 0.55 }}>
              Choose your amount
            </div>
            <div style={{ fontFamily: "var(--mono)", fontSize: 12, opacity: 0.55 }}>
              You will receive · <span style={{ color: "var(--ink)", fontWeight: 600 }}>{tier.gets}</span>
            </div>
          </div>
          <div style={{ display: "flex", alignItems: "center", gap: 14, flexWrap: "wrap" }}>
            <div style={{
              fontFamily: "var(--serif)", fontSize: "clamp(56px, 8vw, 96px)",
              lineHeight: 1, letterSpacing: "-0.02em",
            }}>
              ${amount.toLocaleString()}
            </div>
          </div>

          <input
            type="range" min={1} max={10000} step={1} value={Math.min(amount, 10000)}
            onChange={(e) => setAmount(Number(e.target.value))}
            style={{ width: "100%", marginTop: 18, accentColor: accent }}
          />

          <div style={{ display: "flex", gap: 8, marginTop: 18, flexWrap: "wrap" }}>
            {presets.map((p) => (
              <button key={p} onClick={() => setAmount(p)}
                style={{
                  fontFamily: "var(--mono)", fontSize: 13,
                  padding: "8px 14px", borderRadius: 999,
                  border: amount === p ? `1px solid var(--ink)` : `0.5px solid var(--rule)`,
                  background: amount === p ? "var(--ink)" : "#fff",
                  color: amount === p ? "#fff" : "var(--ink)",
                  cursor: "pointer", transition: "all 0.12s",
                }}>
                ${p}
              </button>
            ))}
          </div>
        </div>

        <BigButton label={cta} onClick={() => onGive(amount)} accent={accent} loading={loading} />
      </div>

      <div style={{ fontFamily: "var(--mono)", fontSize: 12, opacity: 0.55, marginTop: -16 }}>
        {smallprint}
      </div>
    </section>
  );
}

// ── BigButton ───────────────────────────────────────────────────────────────
function BigButton({ label, onClick, accent, loading }) {
  const [hover, setHover] = React.useState(false);
  return (
    <button
      onClick={onClick}
      disabled={loading}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        appearance: "none", border: "none", cursor: loading ? "default" : "pointer",
        fontFamily: "var(--serif)", fontStyle: "italic", fontWeight: 400,
        fontSize: "clamp(28px, 3.4vw, 44px)",
        lineHeight: 1, letterSpacing: "-0.01em",
        padding: "26px 38px", borderRadius: 999,
        background: accent, color: "#fff",
        opacity: loading ? 0.7 : 1,
        transform: hover && !loading ? "translateY(-2px) rotate(-1.2deg) scale(1.03)" : "translateY(0) rotate(0) scale(1)",
        transition: "transform 0.18s cubic-bezier(.3,1.4,.5,1), box-shadow 0.18s, opacity 0.15s",
        boxShadow: hover && !loading
          ? `0 22px 0 -6px var(--ink), 0 30px 60px -10px ${accent}99`
          : `0 14px 0 -4px var(--ink), 0 18px 40px -10px ${accent}55`,
        whiteSpace: "nowrap",
      }}>
      {label} →
    </button>
  );
}

// ── Ticker ──────────────────────────────────────────────────────────────────
function Ticker({ items, accent }) {
  const repeated = [...items, ...items, ...items, ...items];
  return (
    <section style={{
      borderTop: "0.5px solid var(--rule)", borderBottom: "0.5px solid var(--rule)",
      background: "var(--ink)", color: "var(--bg)",
      padding: "18px 0", overflow: "hidden",
      marginTop: 24,
    }}>
      <div className="marquee-mask" style={{ overflow: "hidden", whiteSpace: "nowrap" }}>
        <div style={{
          display: "inline-flex", gap: 0,
          animation: "scrollX 38s linear infinite",
          fontFamily: "var(--serif)", fontStyle: "italic",
          fontSize: "clamp(34px, 5vw, 64px)", letterSpacing: "-0.01em",
        }}>
          {repeated.map((it, i) => (
            <span key={i} style={{ padding: "0 28px", display: "inline-flex", alignItems: "center", gap: 28 }}>
              {it}
              <span style={{ display: "inline-block", width: 10, height: 10, borderRadius: 99, background: accent }} />
            </span>
          ))}
        </div>
      </div>
    </section>
  );
}

// ── Counter ─────────────────────────────────────────────────────────────────
function Counter({ live, clicks, honest, accent }) {
  return (
    <section style={{ maxWidth: 1180, margin: "0 auto", padding: "80px 32px" }}>
      <div style={{
        display: "grid", gridTemplateColumns: "1.2fr 1fr", gap: 64,
        alignItems: "center",
      }}>
        <div>
          <div style={{ fontFamily: "var(--mono)", fontSize: 12, letterSpacing: "0.06em", textTransform: "uppercase", opacity: 0.55, marginBottom: 14 }}>
            Running total (this session)
          </div>
          <div style={{
            fontFamily: "var(--serif)", fontSize: "clamp(72px, 12vw, 180px)",
            lineHeight: 1, letterSpacing: "-0.03em",
            display: "flex", alignItems: "baseline", gap: 4,
          }}>
            <span style={{ color: accent }}>$</span>
            <span style={{ fontVariantNumeric: "tabular-nums" }}>{live.toLocaleString()}</span>
          </div>
          <div style={{ fontFamily: "var(--mono)", fontSize: 13, opacity: 0.6, marginTop: 14, maxWidth: 480 }}>
            {honest
              ? "An honest counter. Starts at zero. Goes up only when you pay. Nobody else is donating. It's just you."
              : "A number going up. It is not verifiable. It is, however, going up."}
          </div>
        </div>
        <div style={{
          background: "#fff", border: "0.5px solid var(--rule)", borderRadius: 18,
          padding: 28, fontFamily: "var(--mono)", fontSize: 13,
          boxShadow: "0 1px 0 rgba(0,0,0,0.03)",
        }}>
          <Row k="Your payments" v={clicks} />
          <Row k="Things you received" v="None" />
          <Row k="Things you will receive" v="None" />
          <Row k="Refund processed" v="Never" />
          <Row k="Recipient updated by email" v="They were not" />
          {/* <Row k="Status" v={<span style={{ color: accent, fontWeight: 600 }}>● live</span>} /> */}
        </div>
      </div>
    </section>
  );
}
function Row({ k, v }) {
  return (
    <div style={{
      display: "flex", justifyContent: "space-between", gap: 16,
      padding: "10px 0", borderBottom: "0.5px dashed var(--rule)",
    }}>
      <span style={{ opacity: 0.55 }}>{k}</span>
      <span style={{ fontWeight: 600 }}>{v}</span>
    </div>
  );
}

// ── GoalMeter ────────────────────────────────────────────────────────────────
function GoalMeter({ accent }) {
  const [total, setTotal] = React.useState(null);
  const CAP = 10000;

  // React.useEffect(() => {
  //   fetch("/api/total")
  //     .then((r) => r.json())
  //     .then((d) => setTotal(d.total))
  //     .catch(() => {}); // fail silently during local dev
  // }, []);

  if (!total) return null; // hide when null, 0, NaN, or undefined

  const over = total >= CAP;
  const pct = Math.min(100, (total / CAP) * 100);

  return (
    <div style={{ maxWidth: 1180, margin: "0 auto", padding: "0 32px 80px" }}>
      <div style={{
        padding: "18px 24px",
        background: "#fff",
        border: "0.5px solid var(--rule)",
        borderRadius: 14,
        fontFamily: "var(--mono)", fontSize: 13,
        display: "flex", alignItems: "center", gap: 24, flexWrap: "wrap",
      }}>
        <div style={{ flex: 1, minWidth: 200 }}>
          <span style={{ fontWeight: 600 }}>{fmt$(Math.floor(total))}</span>
          <span style={{ opacity: 0.55 }}> received so far. </span>
          {over
            ? <span>We have exceeded the recommended amount. This is fine.</span>
            : <span style={{ opacity: 0.7 }}>Ideally this stays under {fmt$(CAP)}.</span>
          }
        </div>
        <div style={{
          flex: "0 0 180px", height: 3,
          background: "rgba(26,20,16,0.10)", borderRadius: 99, overflow: "hidden",
        }}>
          <div style={{
            height: "100%",
            width: `${pct}%`,
            background: over ? "oklch(0.62 0.21 28)" : accent,
            borderRadius: 99,
            transition: "width 1.4s cubic-bezier(.2,1,.4,1)",
          }} />
        </div>
      </div>
    </div>
  );
}

// ── Tiers ───────────────────────────────────────────────────────────────────
function Tiers({ title, onPick, accent, loading }) {
  return (
    <section id="tiers" style={{
      borderTop: "0.5px solid var(--rule)",
      padding: "96px 32px",
      maxWidth: 1280, margin: "0 auto",
    }}>
      <div style={{ display: "flex", alignItems: "baseline", justifyContent: "space-between", flexWrap: "wrap", gap: 18, marginBottom: 48 }}>
        <h2 style={{
          fontFamily: "var(--serif)", fontWeight: 400,
          fontSize: "clamp(40px, 6vw, 80px)", margin: 0,
          letterSpacing: "-0.02em", lineHeight: 0.98,
          maxWidth: 900, textWrap: "balance",
        }}>{title}</h2>
        <div style={{ fontFamily: "var(--mono)", fontSize: 12, opacity: 0.55, textTransform: "uppercase", letterSpacing: "0.06em" }}>
          All tiers · 0 perks
        </div>
      </div>

      <div style={{
        display: "grid",
        gridTemplateColumns: "repeat(auto-fill, minmax(260px, 1fr))",
        gap: 14,
      }}>
        {TIERS.map((t, i) => (
          <TierCard key={t.amt} tier={t} idx={i} onPick={onPick} accent={accent} loading={loading} />
        ))}
      </div>
    </section>
  );
}

function TierCard({ tier, idx, onPick, accent, loading }) {
  const [hover, setHover] = React.useState(false);
  const featured = tier.amt === 100;
  return (
    <div
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        background: featured ? "var(--ink)" : "#fff",
        color: featured ? "var(--bg)" : "var(--ink)",
        border: featured ? "0.5px solid var(--ink)" : "0.5px solid var(--rule)",
        borderRadius: 18, padding: 22,
        display: "flex", flexDirection: "column", gap: 14,
        minHeight: 280,
        transform: hover ? "translateY(-4px)" : "translateY(0)",
        transition: "transform 0.18s, box-shadow 0.18s",
        boxShadow: hover ? "0 18px 36px -16px rgba(0,0,0,0.25)" : "0 1px 0 rgba(0,0,0,0.02)",
        position: "relative", overflow: "hidden",
      }}>
      {featured && (
        <div style={{
          position: "absolute", top: 14, right: 14,
          fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.08em",
          textTransform: "uppercase", padding: "4px 8px", borderRadius: 99,
          background: accent, color: "#fff", fontWeight: 600,
        }}>most popular*</div>
      )}
      <div style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.08em", textTransform: "uppercase", opacity: 0.55 }}>
        Tier 0{idx + 1}
      </div>
      <div style={{
        fontFamily: "var(--serif)", fontSize: 56, lineHeight: 1,
        letterSpacing: "-0.02em",
      }}>
        {fmt$(tier.amt)}
      </div>
      <div style={{ fontFamily: "var(--serif)", fontStyle: "italic", fontSize: 22, lineHeight: 1.2 }}>
        {tier.name}
      </div>
      <div style={{ fontSize: 14, opacity: 0.75, flex: 1, textWrap: "pretty" }}>
        {tier.sub}
      </div>
      <div style={{
        display: "flex", alignItems: "center", gap: 8,
        fontFamily: "var(--mono)", fontSize: 12,
        padding: "10px 0", borderTop: featured ? "0.5px solid rgba(255,255,255,0.18)" : "0.5px dashed var(--rule)",
      }}>
        <span style={{ opacity: 0.6 }}>You get:</span>
        <span style={{ fontWeight: 600 }}>{tier.gets}</span>
      </div>
      <button
        onClick={() => onPick(tier.amt)}
        disabled={loading}
        style={{
          appearance: "none", cursor: loading ? "default" : "pointer",
          background: featured ? accent : "var(--ink)",
          color: "#fff", border: "none",
          padding: "12px 16px", borderRadius: 99,
          fontFamily: "var(--mono)", fontSize: 13, fontWeight: 600,
          letterSpacing: "0.02em",
          opacity: loading ? 0.7 : 1,
          transition: "transform 0.12s, opacity 0.15s",
        }}
        onMouseDown={(e) => { if (!loading) e.currentTarget.style.transform = "scale(0.97)"; }}
        onMouseUp={(e) => e.currentTarget.style.transform = "scale(1)"}
      >
        Send {fmt$(tier.amt)} →
      </button>
    </div>
  );
}

// ── HowItWorks ──────────────────────────────────────────────────────────────
function HowItWorks({ accent }) {
  const steps = [
    { n: "01", t: "You click the button", d: "Any button. They all do the same thing." },
    { n: "02", t: "Your money is taken", d: "Quickly, efficiently, and with no fanfare." },
    { n: "03", t: "You receive nothing", d: "This is not a bug. This is the whole point." },
  ];
  return (
    <section id="how" style={{
      background: "var(--ink)", color: "var(--bg)",
      padding: "112px 32px",
    }}>
      <div style={{ maxWidth: 1180, margin: "0 auto" }}>
        <div style={{ fontFamily: "var(--mono)", fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", opacity: 0.55, marginBottom: 18 }}>
          How it works
        </div>
        <h2 style={{
          fontFamily: "var(--serif)", fontWeight: 400, margin: 0,
          fontSize: "clamp(44px, 7vw, 96px)", lineHeight: 0.98,
          letterSpacing: "-0.02em", maxWidth: 900, textWrap: "balance",
        }}>
          A radically simple <span style={{ fontStyle: "italic", color: accent }}>three-step</span> process.
        </h2>
        <div style={{
          display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 32,
          marginTop: 72,
        }}>
          {steps.map((s, i) => (
            <div key={i} style={{ animation: `fadeUp 0.6s ${i * 0.1}s both` }}>
              <div style={{
                fontFamily: "var(--mono)", fontSize: 14, color: accent,
                marginBottom: 16,
              }}>
                {s.n}
              </div>
              <div style={{
                fontFamily: "var(--serif)", fontSize: 36, lineHeight: 1.1,
                letterSpacing: "-0.01em", marginBottom: 12,
                textWrap: "balance",
              }}>
                {s.t}
              </div>
              <div style={{ fontSize: 16, opacity: 0.7, textWrap: "pretty", maxWidth: 280 }}>
                {s.d}
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ── Testimonials ────────────────────────────────────────────────────────────
function Testimonials({ accent }) {
  const quotes = [
    { q: "I sent $40. Nothing happened. Exactly as advertised. Five stars.", a: "Marcus T.", role: "sent $40, received nothing" },
    { q: "The cleanest financial transaction of my life. No spam, no follow-up email, no nothing.", a: "Priya R.", role: "sent $12, received nothing" },
    { q: "I keep coming back. I'm not sure why. I have given this man $340 over six visits.", a: "Anon.", role: "sent $340, received nothing" },
    { q: "My therapist says this is the healthiest parasocial relationship I've ever had.", a: "Jules D.", role: "sent $5, received nothing" },
  ];
  return (
    <section style={{
      padding: "112px 32px",
      borderTop: "0.5px solid var(--rule)",
    }}>
      <div style={{ maxWidth: 1180, margin: "0 auto" }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", flexWrap: "wrap", gap: 12, marginBottom: 56 }}>
          <h2 style={{
            fontFamily: "var(--serif)", fontWeight: 400, margin: 0,
            fontSize: "clamp(40px, 6vw, 80px)", lineHeight: 0.98,
            letterSpacing: "-0.02em", textWrap: "balance", maxWidth: 800,
          }}>
            What people say after receiving <span style={{ fontStyle: "italic", color: accent }}>nothing</span>.
          </h2>
          <div style={{ fontFamily: "var(--mono)", fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", opacity: 0.55 }}>
            ★ ★ ★ ★ ★ · Verified Nothings
          </div>
        </div>
        <div style={{
          display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(280px, 1fr))",
          gap: 18,
        }}>
          {quotes.map((q, i) => (
            <figure key={i} style={{
              margin: 0, padding: 28,
              background: i % 2 === 0 ? "#fff" : "transparent",
              border: "0.5px solid var(--rule)",
              borderRadius: 18,
              display: "flex", flexDirection: "column", gap: 22,
            }}>
              <blockquote style={{
                margin: 0,
                fontFamily: "var(--serif)", fontStyle: "italic",
                fontSize: 22, lineHeight: 1.3, textWrap: "pretty",
              }}>
                "{q.q}"
              </blockquote>
              <figcaption style={{ display: "flex", alignItems: "center", gap: 12, fontFamily: "var(--mono)", fontSize: 12 }}>
                <span className="placeholder-img" style={{
                  width: 36, height: 36, borderRadius: 99, flexShrink: 0,
                }} />
                <div>
                  <div style={{ fontWeight: 600 }}>{q.a}</div>
                  <div style={{ opacity: 0.55 }}>{q.role}</div>
                </div>
              </figcaption>
            </figure>
          ))}
        </div>
      </div>
    </section>
  );
}

// ── FAQ ─────────────────────────────────────────────────────────────────────
function FAQ({ accent }) {
  const items = [
    { q: "Do I get anything?", a: "No." },
    { q: "Is this a scam?", a: "No. A scam implies you were expecting something. You should not be expecting anything." },
    { q: "Is this tax-deductible?", a: "No. Please don't try." },
    { q: "Can I get a refund?", a: "No. The money is gone. It is somewhere else now. It is somewhere warm and well-fed." },
    { q: "What do you spend it on?", a: "Mostly groceries. Some on a place to live. A small amount on a fancy coffee about which I will not tell you." },
    { q: "Why are you doing this?", a: "Honestly, mostly to see if it works. My name is Michael. I build things on the internet, and occasionally I run small experiments to understand how the world actually works. This is one of them." },
    { q: "Will you remember me?", a: "Briefly, and then no." },
    { q: "Can I get a thank-you note?", a: "No. That would be a thing, and the whole premise is that you receive zero things." },
  ];
  const [open, setOpen] = React.useState(0);
  return (
    <section id="faq" style={{
      padding: "112px 32px",
      borderTop: "0.5px solid var(--rule)",
      background: "var(--bg)",
    }}>
      <div style={{ maxWidth: 980, margin: "0 auto" }}>
        <div style={{ fontFamily: "var(--mono)", fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", opacity: 0.55, marginBottom: 18 }}>
          Frequently asked / answered
        </div>
        <h2 style={{
          fontFamily: "var(--serif)", fontWeight: 400, margin: "0 0 56px",
          fontSize: "clamp(40px, 6vw, 80px)", lineHeight: 0.98,
          letterSpacing: "-0.02em", textWrap: "balance",
        }}>
          The answer is almost always <span style={{ fontStyle: "italic", color: accent }}>no</span>.
        </h2>
        <div style={{ borderTop: "0.5px solid var(--rule)" }}>
          {items.map((it, i) => {
            const isOpen = open === i;
            return (
              <div key={i} style={{ borderBottom: "0.5px solid var(--rule)" }}>
                <button onClick={() => setOpen(isOpen ? -1 : i)}
                  style={{
                    width: "100%", textAlign: "left", appearance: "none",
                    background: "transparent", border: "none", cursor: "pointer",
                    padding: "26px 0", display: "flex", justifyContent: "space-between",
                    alignItems: "center", gap: 24, color: "inherit",
                  }}>
                  <span style={{
                    fontFamily: "var(--serif)", fontSize: "clamp(22px, 2.4vw, 30px)",
                    fontStyle: isOpen ? "italic" : "normal",
                    lineHeight: 1.2, letterSpacing: "-0.01em",
                  }}>{it.q}</span>
                  <span style={{
                    fontFamily: "var(--mono)", fontSize: 13, opacity: 0.55,
                    transform: isOpen ? "rotate(45deg)" : "rotate(0)",
                    transition: "transform 0.18s", display: "inline-block",
                  }}>+</span>
                </button>
                <div style={{
                  maxHeight: isOpen ? 200 : 0, overflow: "hidden",
                  transition: "max-height 0.28s ease, opacity 0.2s",
                  opacity: isOpen ? 1 : 0,
                }}>
                  <div style={{
                    paddingBottom: 24, fontSize: 17, lineHeight: 1.5,
                    color: "var(--ink-soft)", maxWidth: 700, textWrap: "pretty",
                  }}>
                    {it.a}
                  </div>
                </div>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}

// ── CTA Strip ───────────────────────────────────────────────────────────────
function CTAStrip({ cta, accent, onGive, loading }) {
  return (
    <section style={{
      padding: "120px 32px", textAlign: "center",
      background: "var(--ink)", color: "var(--bg)",
      position: "relative", overflow: "hidden",
    }}>
      <div style={{
        position: "absolute", inset: 0,
        background: `radial-gradient(circle at 50% 120%, ${accent}55, transparent 60%)`,
        pointerEvents: "none",
      }} />
      <div style={{ position: "relative" }}>
        <div style={{ fontFamily: "var(--mono)", fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", opacity: 0.6, marginBottom: 22 }}>
          One last chance to receive nothing
        </div>
        <h2 style={{
          fontFamily: "var(--serif)", fontWeight: 400, margin: 0,
          fontSize: "clamp(56px, 10vw, 144px)",
          lineHeight: 0.95, letterSpacing: "-0.02em",
          textWrap: "balance",
        }}>
          Go on. <span style={{ fontStyle: "italic", color: accent }}>Send it.</span>
        </h2>
        <div style={{ marginTop: 56, display: "flex", justifyContent: "center" }}>
          <BigButton label={cta} onClick={onGive} accent={accent} loading={loading} />
        </div>
      </div>
    </section>
  );
}

// ── Footer ──────────────────────────────────────────────────────────────────
function Footer({ name }) {
  return (
    <footer style={{
      padding: "48px 32px", borderTop: "0.5px solid var(--rule)",
      display: "flex", justifyContent: "space-between", flexWrap: "wrap", gap: 20,
      fontFamily: "var(--mono)", fontSize: 12, opacity: 0.7,
    }}>
      <div>© {new Date().getFullYear()} {name}. No rights granted.</div>
      <div>givemesomemoney.lol · made with no obligation</div>
    </footer>
  );
}

// ── CoinRain ────────────────────────────────────────────────────────────────
function CoinRain({ coins }) {
  return (
    <div style={{
      position: "fixed", inset: 0, pointerEvents: "none",
      zIndex: 50, overflow: "hidden",
    }}>
      {coins.map((c) => (
        <div key={c.id}
          style={{
            position: "absolute", top: "-10vh", left: `${c.left}vw`,
            width: c.size, height: c.size,
            animation: `coinSpin ${c.dur}s ${c.delay}s cubic-bezier(.4,.2,.7,1) forwards`,
            "--dx": `${c.dx}vw`, "--rot": `${c.rot}deg`,
          }}>
          {c.kind === "coin" ? (
            <div style={{
              width: "100%", height: "100%", borderRadius: "50%",
              background: "radial-gradient(circle at 35% 30%, #ffe98a, #d4a017 70%, #8a6708)",
              border: "1.5px solid #6b4f06",
              display: "flex", alignItems: "center", justifyContent: "center",
              color: "#6b4f06", fontFamily: "var(--serif)", fontWeight: 700,
              fontSize: c.size * 0.55, lineHeight: 1,
              boxShadow: "inset 0 -3px 6px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.2)",
            }}>$</div>
          ) : (
            <div style={{
              width: "100%", height: c.size * 0.55,
              background: "linear-gradient(135deg, #b8d4a8, #6fa05a 70%, #3e6b30)",
              border: "1.5px solid #2d4b22",
              borderRadius: 3,
              display: "flex", alignItems: "center", justifyContent: "center",
              color: "#2d4b22", fontFamily: "var(--serif)", fontWeight: 700,
              fontSize: c.size * 0.35, lineHeight: 1,
            }}>$</div>
          )}
        </div>
      ))}
    </div>
  );
}

// ── ReceiptModal ────────────────────────────────────────────────────────────
function ReceiptModal({ receipt, header, name, onClose }) {
  const receiptRef = React.useRef(null);

  const handleDownload = async () => {
    const el = receiptRef.current;
    if (!el || typeof domtoimage === "undefined") return;
    // Remove wavy clip temporarily so the PNG has clean rectangular edges
    const origClip = el.style.clipPath;
    el.style.clipPath = "none";
    try {
      const dataUrl = await domtoimage.toPng(el, { bgcolor: "#fbf7e9", scale: 2 });
      el.style.clipPath = origClip;
      const a = document.createElement("a");
      a.href = dataUrl;
      a.download = `receipt-of-nothing-${receipt.id}.png`;
      a.click();
    } catch (err) {
      el.style.clipPath = origClip;
      console.error("Download failed:", err);
    }
  };

  const handleTweet = () => {
    const text = `I just sent ${fmt$(receipt.amount)} to a stranger on the internet and received nothing (ref #${receipt.id}). Exactly as advertised. givemesomemoney.lol`;
    window.open(`https://x.com/intent/tweet?text=${encodeURIComponent(text)}`, "_blank");
  };

  return (
    <div
      onClick={onClose}
      style={{
        position: "fixed", inset: 0, zIndex: 100,
        background: "rgba(26,20,16,0.45)",
        display: "flex", alignItems: "center", justifyContent: "center",
        padding: 24,
        animation: "fadeUp 0.18s",
      }}>
      <div
        ref={receiptRef}
        onClick={(e) => e.stopPropagation()}
        style={{
          background: "#fbf7e9",
          width: "min(440px, 100%)",
          padding: "36px 36px 24px",
          fontFamily: "var(--mono)", fontSize: 13,
          boxShadow: "0 30px 80px -10px rgba(0,0,0,0.4)",
          position: "relative",
          clipPath: "polygon(0% 0%, 100% 0%, 100% calc(100% - 12px), 95% 100%, 90% calc(100% - 12px), 85% 100%, 80% calc(100% - 12px), 75% 100%, 70% calc(100% - 12px), 65% 100%, 60% calc(100% - 12px), 55% 100%, 50% calc(100% - 12px), 45% 100%, 40% calc(100% - 12px), 35% 100%, 30% calc(100% - 12px), 25% 100%, 20% calc(100% - 12px), 15% 100%, 10% calc(100% - 12px), 5% 100%, 0% calc(100% - 12px))",
        }}>
        <div style={{ textAlign: "center", borderBottom: "1px dashed var(--rule)", paddingBottom: 18 }}>
          <div style={{ fontFamily: "var(--serif)", fontSize: 28, lineHeight: 1, letterSpacing: "-0.01em" }}>
            {header}
          </div>
          <div style={{ marginTop: 6, opacity: 0.6, fontSize: 11, letterSpacing: "0.06em", textTransform: "uppercase" }}>
            givemesomemoney.lol
          </div>
        </div>
        <div style={{ padding: "18px 0", display: "flex", flexDirection: "column", gap: 8 }}>
          <Rcpt k="DATE" v={receipt.ts.toLocaleDateString()} />
          <Rcpt k="TIME" v={receipt.ts.toLocaleTimeString()} />
          <Rcpt k="REF" v={"#" + receipt.id} />
          <Rcpt k="RECIPIENT" v={name.length > 24 ? "the guy" : name} />
        </div>
        <div style={{ borderTop: "1px dashed var(--rule)", borderBottom: "1px dashed var(--rule)", padding: "14px 0", display: "flex", flexDirection: "column", gap: 6 }}>
          <Rcpt k={receipt.tier.name} v={fmt$(receipt.amount)} bold />
          <Rcpt k="You received" v={receipt.tier.gets} />
          <Rcpt k="Adjustments" v={fmt$(0)} />
          <Rcpt k="Tax" v={fmt$(0)} />
        </div>
        <div style={{ padding: "16px 0", textAlign: "right" }}>
          <div style={{ fontFamily: "var(--serif)", fontSize: 36, lineHeight: 1 }}>
            TOTAL <span style={{ color: "var(--accent)" }}>{fmt$(receipt.amount)}</span>
          </div>
        </div>
        <div style={{
          textAlign: "center", fontStyle: "italic",
          fontFamily: "var(--serif)", fontSize: 17,
          padding: "12px 0", borderTop: "1px dashed var(--rule)",
        }}>
          Thank you for your nothing.
        </div>
        <div style={{ display: "flex", gap: 8, marginTop: 14 }}>
          <button
            onClick={handleDownload}
            style={{
              flex: 1, appearance: "none", cursor: "pointer",
              background: "transparent", color: "var(--ink)",
              border: "0.5px solid var(--rule)",
              padding: "10px 12px", borderRadius: 6,
              fontFamily: "var(--mono)", fontSize: 12, fontWeight: 500,
              letterSpacing: "0.03em",
            }}>
            ↓ Save receipt
          </button>
          <button
            onClick={handleTweet}
            style={{
              flex: 1, appearance: "none", cursor: "pointer",
              background: "transparent", color: "var(--ink)",
              border: "0.5px solid var(--rule)",
              padding: "10px 12px", borderRadius: 6,
              fontFamily: "var(--mono)", fontSize: 12, fontWeight: 500,
              letterSpacing: "0.03em",
            }}>
            Share on X ↗
          </button>
        </div>
        <button
          onClick={onClose}
          style={{
            marginTop: 8, width: "100%",
            appearance: "none", cursor: "pointer",
            background: "var(--ink)", color: "#fff", border: "none",
            padding: "12px 16px", borderRadius: 6,
            fontFamily: "var(--mono)", fontSize: 13, fontWeight: 600,
            letterSpacing: "0.04em", textTransform: "uppercase",
          }}>
          Receive nothing & close
        </button>
      </div>
    </div>
  );
}
function Rcpt({ k, v, bold }) {
  return (
    <div style={{ display: "flex", justifyContent: "space-between", gap: 12 }}>
      <span style={{ opacity: 0.65 }}>{k}</span>
      <span style={{ fontWeight: bold ? 700 : 500, textAlign: "right" }}>{v}</span>
    </div>
  );
}

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