const { useState, useRef, useEffect } = React;

/* ── data ───────────────────────────────────────────── */
const FORMSPREE = "https://formspree.io/f/mnjlwwnw";

const COLORS = [
  { id: "Red",      hex: "#c8102e", img: "images/shirt-red.png" },
  { id: "Royal",    hex: "#1d4ed8", img: "images/shirt-royal.png" },
  { id: "Sky Blue", hex: "#5ea8dd", img: "images/shirt-carolina.png" },
  { id: "Navy",     hex: "#16264f", img: "images/shirt-navy.png" },
  { id: "White",    hex: "#f4f1ea", img: "images/shirt-white.png" },
];
const SIZES = ["S", "M", "L", "XL", "2XL", "3XL"];
const STATES = ["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming","Washington D.C."];

const SLIDES = [
  { img:"images/duo.png", idx:"Look 01", title:"Wear It Together",
    copy:"Matching sets for the whole crew. Him in red, her in royal — same drop, same energy, from the backyard cookout to the stands.",
    tags:[["Couples + family",1],["5 colors",0],["S–3XL",0]] },
  { img:"images/collection.png", idx:"Look 02", title:"Map on the Back",
    copy:"Carry the whole country home. A clean line-map of Liberia\u2014every county\u2014printed across the back. Front stays classic.",
    tags:[["Back: Liberia map",1],["Front + back",0],["Caps too",0]] },
  { img:"images/collection.png", idx:"Look 03", title:"Name & Number",
    copy:"Jersey energy. Your name arched over your number on the back\u2014\u201CORIGINAL T. 26.\u201D Rep your family, your county, your crew.",
    tags:[["Custom name",1],["Custom number",1],["Back print",0]] },
  { img:"images/look-night.png", idx:"Look 04", title:"Day to Night",
    copy:"Carolina blue for the cookout, navy for the night out. Same drop, every mood\u2014from the backyard to the bridge.",
    tags:[["Carolina + Navy",0],["Unisex fit",0],["Soft cotton",0]] },
  { img:"images/look-colors.png", idx:"Look 05", title:"Pick Your Color",
    copy:"Red, white, navy, sky blue — classic front, crisp print, built to last wash after wash. Pick the color that's yours.",
    tags:[["Every color",0],["Front print",0],["Made to order",1]] },
];

const CUSTOM = [
  { t:"Color", d:"Red, Royal, Sky Blue, Navy or White.",
    p:<><circle cx="12" cy="12" r="9"/><path d="M12 3v18M3 12h18"/></> },
  { t:"Size", d:"S through 3XL, unisex cut.",
    p:<><path d="M4 7l4-3 4 3 4-3 4 3v3l-3 1v9H7v-9l-3-1z"/></> },
  { t:"Name", d:"Your name across the back.",
    p:<><path d="M4 7V5h16v2M9 19h6M12 5v14"/></> },
  { t:"Number", d:"Pick your number, jersey-style.",
    p:<><path d="M8 8a4 4 0 1 1 5 6l-5 4h8"/></> },
  { t:"Map", d:"Liberia map printed on the back.",
    p:<><path d="M9 4l6 2 6-2v14l-6 2-6-2-6 2V6z"/><path d="M9 4v14M15 6v14"/></> },
];

/* ── small helpers ─────────────────────────────────── */
const Star = ({ s = 13 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor"><path d="M12 2l2.9 6.3L22 9.2l-5 4.7 1.3 6.9L12 17.5 5.7 20.8 7 13.9 2 9.2l7.1-.9z"/></svg>
);

/* ── brand emblem (expanded logo mark) ─────────────── */
const Emblem = ({ className = "" }) => (
  <svg className={className} viewBox="0 0 64 64" fill="none" aria-hidden="true">
    <circle cx="32" cy="32" r="30" fill="var(--lib-red)" stroke="var(--amber)" strokeWidth="2.5"/>
    <circle cx="32" cy="32" r="24.5" fill="none" stroke="rgba(255,255,255,.25)" strokeWidth="1"/>
    <path d="M32 9.5l1.7 3.6 3.9.5-2.9 2.7.8 3.9L32 18.3l-3.5 1.9.8-3.9-2.9-2.7 3.9-.5z" fill="#fff"/>
    <text x="32" y="46" textAnchor="middle" fill="#fff" style={{ fontFamily:"'Fraunces',serif", fontWeight:900, fontSize:25, fontVariationSettings:"'opsz' 72" }}>26</text>
  </svg>
);

/* ── hero sparkle motion ───────────────────────────── */
const Sparks = () => {
  const pts = React.useMemo(() => Array.from({ length: 26 }, () => ({
    top: (Math.random() * 96).toFixed(1), left: (Math.random() * 98).toFixed(1),
    d: (Math.random() * 3 + 2).toFixed(2), delay: (Math.random() * 3.4).toFixed(2),
    cls: ["", "r", "b"][Math.floor(Math.random() * 3)], sz: (Math.random() * 5 + 3).toFixed(1),
  })), []);
  return (
    <div className="sparks" aria-hidden="true">
      {pts.map((p, i) => (
        <span key={i} className={"spark " + p.cls}
          style={{ top: p.top + "%", left: p.left + "%", width: p.sz + "px", height: p.sz + "px", animationDuration: p.d + "s", animationDelay: p.delay + "s" }} />
      ))}
    </div>
  );
};

/* ── scrolling marquee ─────────────────────────────── */
const MARQUEE = ["Print on demand", "Pay as you go", "No pre-print", "Your name. Your number.", "Map on the back", "Ships to your state", "$35\u2013$50 each", "One gear. Two events."];
const Marquee = () => {
  const row = [...MARQUEE, ...MARQUEE];
  return (
    <div className="marquee" aria-hidden="true">
      <div className="marquee-track">
        {row.map((t, i) => (
          <div className="mi" key={i}><span><b className="s"><Star s={11} /></b>{t}</span></div>
        ))}
      </div>
    </div>
  );
};

/* ── countdown to game day ─────────────────────────── */
function Countdown() {
  const target = React.useMemo(() => new Date("2026-07-25T19:00:00-05:00").getTime(), []);
  const [now, setNow] = useState(Date.now());
  useEffect(() => {
    const t = setInterval(() => setNow(Date.now()), 1000);
    return () => clearInterval(t);
  }, []);
  let diff = Math.max(0, target - now);
  const d = Math.floor(diff / 86400000); diff -= d * 86400000;
  const h = Math.floor(diff / 3600000); diff -= h * 3600000;
  const m = Math.floor(diff / 60000); diff -= m * 60000;
  const s = Math.floor(diff / 1000);
  const pad = x => String(x).padStart(2, "0");
  const units = [[d, "Days"], [pad(h), "Hours"], [pad(m), "Min"], [pad(s), "Sec"]];
  return (
    <div className="count">
      {units.map(([n, l], i) => (
        <div className="u" key={i}><div className="n">{n}</div><div className="ul">{l}</div></div>
      ))}
    </div>
  );
}

/* ── popup CTA ─────────────────────────────────────── */
function PopupCTA() {
  const [show, setShow] = useState(false);
  const [closed, setClosed] = useState(false);
  useEffect(() => {
    if (closed) { setShow(false); return; }
    const onScroll = () => {
      const y = window.scrollY;
      const req = document.getElementById("request");
      const foot = document.querySelector(".footer");
      const reqTop = req ? req.getBoundingClientRect().top : 99999;
      const footTop = foot ? foot.getBoundingClientRect().top : 99999;
      const overForm = reqTop < window.innerHeight * 0.7 && reqTop > -(req ? req.offsetHeight : 0);
      const atFooter = footTop < window.innerHeight * 0.9;
      setShow(y > 760 && !overForm && !atFooter);
    };
    window.addEventListener("scroll", onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener("scroll", onScroll);
  }, [closed]);
  return (
    <div className={"popup" + (show ? " show" : "")} role="dialog" aria-label="Request your shirt">
      <button className="x" onClick={() => setClosed(true)} aria-label="Dismiss">&times;</button>
      <div className="pimg"><img src="images/shirt-royal.png" alt="" /></div>
      <div className="pc">
        <div className="t">Your shirt's <em>waiting</em>.</div>
        <div className="s">Made to order — request before the match. $35–$50.</div>
        <a href="#request" onClick={() => setClosed(true)}>Request yours <Star s={11} /></a>
      </div>
    </div>
  );
}

/* ── scroll-reveal hook ────────────────────────────── */
function useReveal() {
  useEffect(() => {
    const els = document.querySelectorAll(".reveal");
    if (!("IntersectionObserver" in window)) { els.forEach(e => e.classList.add("in")); return; }
    const io = new IntersectionObserver((ents) => {
      ents.forEach(e => { if (e.isIntersecting) { e.target.classList.add("in"); io.unobserve(e.target); } });
    }, { threshold: 0.12, rootMargin: "0px 0px -7% 0px" });
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  }, []);
}

/* ── carousel ──────────────────────────────────────── */
function Carousel() {
  const [i, setI] = useState(0);
  const n = SLIDES.length;
  const go = d => setI(p => (p + d + n) % n);
  useEffect(() => {
    const t = setInterval(() => setI(p => (p + 1) % n), 6000);
    return () => clearInterval(t);
  }, [n]);
  return (
    <div className="carousel">
      <div className="cstage">
        {SLIDES.map((s, k) => (
          <div className={"cslide" + (k === i ? " active" : "")} key={k}>
            <img src={s.img} alt={s.title} />
            <div className="cslide-info">
              <span className="idx">{s.idx}</span>
              <h3>{s.title}</h3>
              <p>{s.copy}</p>
              <div className="tags">
                {s.tags.map((t, j) => <span className={"tag" + (t[1] ? " amber" : "")} key={j}>{t[0]}</span>)}
              </div>
            </div>
          </div>
        ))}
      </div>
      <div className="cnav">
        <div className="dots">
          {SLIDES.map((_, k) => (
            <button className={"dot-b" + (k === i ? " on" : "")} key={k} onClick={() => setI(k)} aria-label={"slide " + (k+1)} />
          ))}
        </div>
        <div className="arrows">
          <button className="arrow" onClick={() => go(-1)} aria-label="previous">‹</button>
          <button className="arrow" onClick={() => go(1)} aria-label="next">›</button>
        </div>
      </div>
    </div>
  );
}

/* ── request form ──────────────────────────────────── */
function RequestForm() {
  const [color, setColor] = useState("Red");
  const [size, setSize] = useState("L");
  const [qty, setQty] = useState(1);
  const [name, setName] = useState("");
  const [number, setNumber] = useState("");
  const [map, setMap] = useState(false);
  const [done, setDone] = useState(false);
  const [busy, setBusy] = useState(false);
  const [err, setErr] = useState("");

  async function submit(e) {
    e.preventDefault();
    setErr("");
    const f = e.target;
    const email = f.email.value.trim();
    const state = f.ship_state.value;
    if (!email) { setErr("Please add an email so we can send your price."); return; }
    if (!state) { setErr("Please pick the state we'd ship to."); return; }
    setBusy(true);
    const data = {
      email,
      ship_state: state,
      color, size, quantity: qty,
      name_on_back: name || "—",
      number_on_back: number || "—",
      map_on_back: map ? "Yes" : "No",
      notes: f.notes.value || "—",
      _subject: `MY26TH request · ${color} ${size} → ${state}`,
    };
    try {
      const r = await fetch(FORMSPREE, {
        method: "POST",
        headers: { "Content-Type": "application/json", Accept: "application/json" },
        body: JSON.stringify(data),
      });
      if (r.ok) setDone(true);
      else setErr("Something went wrong. Email hello@pozadigital.com and we'll sort it.");
    } catch {
      setErr("Network hiccup. Try again, or email hello@pozadigital.com.");
    } finally { setBusy(false); }
  }

  if (done) return (
    <div className="success">
      <div className="ck"><svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><path d="M20 6L9 17l-5-5"/></svg></div>
      <h3>Request received.</h3>
      <p>We'll email your exact price within <b style={{color:"var(--cream)"}}>1–2 days</b> with a simple way to pay. Nothing is printed until you say go — pay as you go, then we print and ship to your state.</p>
      <div className="pill">Your range: <b>$35–$50</b> · print on demand</div>
    </div>
  );

  return (
    <form onSubmit={submit} noValidate>
      <div className="field">
        <label>Email <span className="req">*</span></label>
        <input type="email" name="email" placeholder="you@email.com" required />
      </div>

      <div className="row2">
        <div className="field">
          <label>Shirt color <span className="req">*</span></label>
          <select value={color} onChange={e => setColor(e.target.value)}>
            {COLORS.map(c => <option key={c.id}>{c.id}</option>)}
          </select>
        </div>
        <div className="field">
          <label>Size <span className="req">*</span></label>
          <select value={size} onChange={e => setSize(e.target.value)}>
            {SIZES.map(s => <option key={s}>{s}</option>)}
          </select>
        </div>
      </div>

      <div className="row3">
        <div className="field">
          <label>Name <span className="opt">/ back</span></label>
          <input type="text" maxLength="14" value={name} onChange={e => setName(e.target.value)} placeholder="Optional" />
        </div>
        <div className="field">
          <label>Number <span className="opt">/ back</span></label>
          <input type="text" maxLength="2" value={number} onChange={e => setNumber(e.target.value.replace(/[^0-9]/g,""))} placeholder="26" />
        </div>
        <div className="field">
          <label>Qty</label>
          <input type="number" min="1" max="50" value={qty} onChange={e => setQty(Math.max(1, +e.target.value || 1))} />
        </div>
      </div>

      <div className="field">
        <label>Map on the back</label>
        <div className={"toggle-row" + (map ? " on" : "")} onClick={() => setMap(m => !m)}>
          <div className="tg"></div>
          <div className="t-txt"><b>Print the Liberia map</b><span>Full county line-map across the back</span></div>
        </div>
      </div>

      <div className="field">
        <label>Ship to <span className="req">*</span> <span className="opt">/ state only — full address comes later</span></label>
        <select name="ship_state" defaultValue="">
          <option value="" disabled>Select your state…</option>
          {STATES.map(s => <option key={s}>{s}</option>)}
        </select>
      </div>

      <div className="field">
        <label>Anything else <span className="opt">/ optional</span></label>
        <textarea name="notes" placeholder="County, group order, a county flag on the sleeve — tell us."></textarea>
      </div>

      <div className="form-note">
        <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="9"/><path d="M12 8h.01M11 12h1v4h1"/></svg>
        <span>No payment now. We reply with your exact price ($35–$50) and a pay link. Only serious requests get printed — pay as you go.</span>
      </div>

      {err && <div className="fs-err">{err}</div>}

      <div className="submit-row">
        <button type="submit" className="btn btn-red" disabled={busy}>
          {busy ? "Sending…" : "Request my shirt"}
          {!busy && <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>}
        </button>
        <span style={{fontSize:13, color:"var(--cream-muted)"}}>Print on demand · ships to your state</span>
      </div>
    </form>
  );

  // (preview state is read by parent via context-free lift — see App)
}

/* ── App ───────────────────────────────────────────── */
function App() {
  // lifted preview state shared between form + preview
  const [pv, setPv] = useState({ color: "Red", size: "L", name: "", number: "", map: false });
  useReveal();

  return (
    <React.Fragment>
      {/* ribbon */}
      <div className="ribbon">
        <span>A <b>LibPrintz</b> drop</span><span className="dot"></span>
        <span>Powered by <b>POZA Digital</b></span><span className="dot"></span>
        <span><b>Print on demand</b> · pay as you go</span>
      </div>

      {/* nav */}
      <nav className="nav"><div className="wrap nav-in">
        <a href="#top" className="brand">
          <Emblem className="emblem" />
          <span style={{ display:"flex", flexDirection:"column", justifyContent:"center" }}>
            <span className="wm"><span className="my">MY</span><span className="num">26</span><span className="th">TH</span></span>
            <span className="tagline">Liberia Independence Drop</span>
          </span>
        </a>
        <div className="nav-cta">
          <span className="pod-pill"><span className="blip"></span>Print on demand</span>
          <a href="#request" className="btn btn-primary">Request a shirt</a>
        </div>
      </div></nav>

      {/* hero */}
      <header className="hero" id="top">
        <div className="hero-flag" style={{ backgroundImage: "url('images/flag.png')" }}></div>
        <Sparks />
        <div className="wrap hero-in">
          <div className="hero-top">
            <div className="eyebrow">One gear <span style={{color:"var(--lib-red)"}}>·</span> two events</div>
            <h1><span className="out">MY</span><span className="red">26</span>TH</h1>
          </div>
          <div className="gameday-frame">
            <img src="images/gameday.png" alt="Game Day x Independence Day — Minnesota United v Liberia, Allianz Field, July 25 2026, Twin Cities" />
          </div>
          <div className="hero-bottom">
            <p className="hero-sub">The <b>July 26th Liberia Independence</b> tee — built for the Twin Cities. Wear it to <b>Minnesota United v Liberia</b> on the 25th, wear it home on the 26th. Your color, your size, your name and number, the map on your back.</p>
            <div className="hero-actions">
              <a href="#request" className="btn btn-red">Request your shirt <Star s={13} /></a>
              <a href="#catalog" className="btn btn-secondary">See the catalog</a>
            </div>
            <div className="price-tag"><b>$35–$50</b> each · price emailed after you ask · print on demand only</div>
          </div>
        </div>
      </header>

      <Marquee />

      {/* catalog */}
      <section className="section" id="catalog"><div className="wrap">
        <div className="sec-head reveal">
          <div>
            <div className="eyebrow">The catalog</div>
            <h2>One design.<br/>Endless ways to wear it.</h2>
          </div>
          <p>Every shirt is made to order. Browse the looks, then tell us how you want yours built.</p>
        </div>
        <div className="reveal d1"><Carousel /></div>
      </div></section>

      {/* customizer chips */}
      <section className="section" style={{paddingTop:0}}><div className="wrap">
        <div className="sec-head reveal">
          <div>
            <div className="eyebrow">Built your way</div>
            <h2>Five things you choose.</h2>
          </div>
          <p>Highly customizable, zero guesswork. Pick any combination — we print exactly that, one shirt at a time.</p>
        </div>
        <div className="custom-grid">
          {CUSTOM.map((c, k) => (
            <div className={"cust-card reveal d" + (k + 1)} key={k}>
              <svg className="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">{c.p}</svg>
              <h4>{c.t}</h4>
              <p>{c.d}</p>
            </div>
          ))}
        </div>
      </div></section>

      {/* form */}
      <section className="section form-sec" id="request"><div className="wrap">
        <div className="sec-head reveal">
          <div>
            <div className="eyebrow">Request a shirt</div>
            <h2>Tell us how you want it.</h2>
          </div>
          <p>This is the only step. We reply with your price and a pay link — nothing prints until you're in.</p>
        </div>
        <div className="form-grid reveal d1">
          <div className="preview-col">
            <div className="preview-card">
              <div className="lbl">Live preview</div>
              <div style={{marginTop:14}}>
                <img src={(COLORS.find(c => c.id === pv.color) || COLORS[0]).img} alt={pv.color + " tee"}
                  style={{ width:"100%", maxWidth:308, margin:"0 auto", display:"block", filter:"drop-shadow(0 18px 30px rgba(0,0,0,.55))" }} />
              </div>
              <div className="swatches">
                {COLORS.map(c => (
                  <div key={c.id} className={"sw" + (pv.color === c.id ? " on" : "")} style={{ background: c.hex, border: c.id==="White"?"2px solid var(--border-dim)":undefined }}
                    title={c.id} onClick={() => setPv(p => ({ ...p, color: c.id }))} />
                ))}
              </div>
              <div className="meta">
                <span><b>{pv.color}</b> · {pv.size}</span>
                {pv.name && <span>Name: <b>{pv.name.toUpperCase()}</b></span>}
                {pv.number && <span>No. <b>{pv.number}</b></span>}
                {pv.map && <span><b>+ Map</b></span>}
              </div>
              <div className="pv-back">Front shown — your <b>name, number &amp; map</b> print on the back.</div>
            </div>
          </div>
          <div>
            <LiveForm pv={pv} setPv={setPv} />
          </div>
        </div>
      </div></section>

      {/* game CTA band */}
      <section className="cta-band">
        <div className="stripes"></div>
        <div className="wrap cta-in reveal">
          <div className="eyebrow">Allianz Field · July 25 → Independence Day · July 26</div>
          <h2>Don't show up<br/>without <em>yours</em>.</h2>
          <p>Kickoff is close. One shirt for the match and the 26th — made to order, in your colors, your name on the back. Request now so it prints in time.</p>
          <Countdown />
          <div style={{ marginTop:10, fontSize:12.5, letterSpacing:".15em", textTransform:"uppercase", color:"#9fc0ff" }}>Until kickoff at Allianz Field</div>
          <a href="#request" className="btn btn-primary">Request your shirt <Star s={13} /></a>
        </div>
      </section>

      {/* footer */}
      <footer className="footer"><div className="wrap">
        <div className="foot-big">MY<span className="red">26</span>TH</div>
        <div className="foot-cols reveal">
          <div className="foot-eco">
            <div className="lock"><span className="my">MY</span><span className="num">26</span><span className="th">TH</span></div>
            <p>The Liberia Independence drop. Made to order, printed in the Twin Cities, shipped to your state. No pre-print, no leftover stock — pay as you go.</p>
          </div>
          <div className="col">
            <h5>The drop</h5>
            <a href="#catalog">Catalog</a>
            <a href="#request">Request a shirt</a>
            <a href="#request">Color · Size · Name</a>
            <a href="#request">Number · Map</a>
          </div>
          <div className="col">
            <h5>Two events</h5>
            <p>MNUFC v Liberia</p>
            <p>Allianz Field · Jul 25</p>
            <p>Independence Day</p>
            <p>July 26, 2026</p>
          </div>
          <div className="col">
            <h5>Get details</h5>
            <a href="mailto:hello@pozadigital.com">hello@pozadigital.com</a>
            <p>Print on demand</p>
            <p>$35–$50 per shirt</p>
            <p>Ships across the U.S.</p>
          </div>
        </div>
        <div className="foot-bottom">
          <div className="chips">
            <span>Print on demand</span><span>Pay as you go</span><span>No pre-print</span><span>Made to order</span>
          </div>
          <span>A LibPrintz drop, built by <span className="poza-mark"><span className="p">POZA</span><span className="d">digital</span></span> · We print. You prosper.</span>
        </div>
      </div></footer>

      <PopupCTA />
    </React.Fragment>
  );
}

/* LiveForm wraps RequestForm fields but syncs to preview state */
function LiveForm({ pv, setPv }) {
  const [done, setDone] = useState(false);
  const [busy, setBusy] = useState(false);
  const [err, setErr] = useState("");
  const set = patch => setPv(p => ({ ...p, ...patch }));

  async function submit(e) {
    e.preventDefault();
    setErr("");
    const f = e.target;
    const email = f.email.value.trim();
    const state = f.ship_state.value;
    if (!email) { setErr("Please add an email so we can send your price."); return; }
    if (!state) { setErr("Please pick the state we'd ship to."); return; }
    setBusy(true);
    const data = {
      email, ship_state: state,
      color: pv.color, size: pv.size, quantity: pv.qty || 1,
      name_on_back: pv.name || "\u2014",
      number_on_back: pv.number || "\u2014",
      map_on_back: pv.map ? "Yes" : "No",
      notes: f.notes.value || "\u2014",
      _subject: `MY26TH request \u00b7 ${pv.color} ${pv.size} \u2192 ${state}`,
    };
    try {
      const r = await fetch(FORMSPREE, { method:"POST", headers:{ "Content-Type":"application/json", Accept:"application/json" }, body: JSON.stringify(data) });
      if (r.ok) setDone(true);
      else setErr("Something went wrong. Email hello@pozadigital.com and we'll sort it.");
    } catch { setErr("Network hiccup. Try again, or email hello@pozadigital.com."); }
    finally { setBusy(false); }
  }

  if (done) return (
    <div className="success">
      <div className="ck"><svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><path d="M20 6L9 17l-5-5"/></svg></div>
      <h3>Request received.</h3>
      <p>We'll email your exact price within <b style={{color:"var(--cream)"}}>1–2 days</b> with a simple way to pay. Nothing prints until you say go — pay as you go, then we make it and ship to <b style={{color:"var(--cream)"}}>{pv.shipState || "your state"}</b>.</p>
      <div className="pill">Your range: <b>$35–$50</b> · print on demand</div>
    </div>
  );

  return (
    <form onSubmit={submit} noValidate>
      <div className="field">
        <label>Email <span className="req">*</span></label>
        <input type="email" name="email" placeholder="you@email.com" required />
      </div>
      <div className="row2">
        <div className="field">
          <label>Shirt color <span className="req">*</span></label>
          <select value={pv.color} onChange={e => set({ color: e.target.value })}>
            {COLORS.map(c => <option key={c.id}>{c.id}</option>)}
          </select>
        </div>
        <div className="field">
          <label>Size <span className="req">*</span></label>
          <select value={pv.size} onChange={e => set({ size: e.target.value })}>
            {SIZES.map(s => <option key={s}>{s}</option>)}
          </select>
        </div>
      </div>
      <div className="row3">
        <div className="field">
          <label>Name <span className="opt">/ back</span></label>
          <input type="text" maxLength="14" value={pv.name} onChange={e => set({ name: e.target.value })} placeholder="Optional" />
        </div>
        <div className="field">
          <label>Number <span className="opt">/ back</span></label>
          <input type="text" maxLength="2" value={pv.number} onChange={e => set({ number: e.target.value.replace(/[^0-9]/g, "") })} placeholder="26" />
        </div>
        <div className="field">
          <label>Qty</label>
          <input type="number" min="1" max="50" value={pv.qty || 1} onChange={e => set({ qty: Math.max(1, +e.target.value || 1) })} />
        </div>
      </div>
      <div className="field">
        <label>Map on the back</label>
        <div className={"toggle-row" + (pv.map ? " on" : "")} onClick={() => set({ map: !pv.map })}>
          <div className="tg"></div>
          <div className="t-txt"><b>Print the Liberia map</b><span>Full county line-map across the back</span></div>
        </div>
      </div>
      <div className="field">
        <label>Ship to <span className="req">*</span> <span className="opt">/ state only — full address comes later</span></label>
        <select name="ship_state" defaultValue="" onChange={e => set({ shipState: e.target.value })}>
          <option value="" disabled>Select your state…</option>
          {STATES.map(s => <option key={s}>{s}</option>)}
        </select>
      </div>
      <div className="field">
        <label>Anything else <span className="opt">/ optional</span></label>
        <textarea name="notes" placeholder="County, group order, a county flag on the sleeve — tell us."></textarea>
      </div>
      <div className="form-note">
        <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="9"/><path d="M12 16v-5M12 8h.01"/></svg>
        <span>No payment now. We reply with your exact price ($35–$50) and a pay link. Only serious requests get printed — pay as you go.</span>
      </div>
      {err && <div className="fs-err">{err}</div>}
      <div className="submit-row">
        <button type="submit" className="btn btn-red" disabled={busy}>
          {busy ? "Sending…" : "Request my shirt"}
          {!busy && <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>}
        </button>
        <span style={{ fontSize:13, color:"var(--cream-muted)" }}>Print on demand · ships to your state</span>
      </div>
    </form>
  );
}

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