// ─────────────────────────────────────────────────────────────────
// Phase 2 · Gear tab — Store Hub + Takedown Store (browse / PDP / cart / confirmation)
// 6 screens, dark-default, 430×884.
// Module color: --module-store (#1D8EC7) — navigational tints only.
// ─────────────────────────────────────────────────────────────────

// ── Shared: search input + filter pill row ──────────────────────
const StoreTopbar = ({ title, onBack, right }) => (
  <div style={{ paddingTop: 56, paddingLeft: 20, paddingRight: 20, paddingBottom: 12, borderBottom: "1px solid var(--border-subtle)", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
    <div style={{ display: "flex", alignItems: "center", gap: 12, minWidth: 0 }}>
      {onBack && (
        <button onClick={onBack} style={{ background: "transparent", border: "none", color: "var(--text-primary)", padding: 0, cursor: "pointer" }}>
          <I.ArrowLeft size={22} />
        </button>
      )}
      <div style={{ minWidth: 0 }}>
        <Overline style={{ color: "var(--module-store)" }}>MODULE · GEAR</Overline>
        <div className="t-h4" style={{ marginTop: 2 }}>{title}</div>
      </div>
    </div>
    {right}
  </div>
);

// ── STH-1 · Gear Hub (Gear tab landing) ─────────────────────────
const GearHubScreen = ({ onTab }) => (
  <div style={{ position: "absolute", inset: 0, background: "var(--bg-primary)", display: "flex", flexDirection: "column" }}>
    <StoreTopbar
      title="Gear"
      right={
        <button style={{ background: "transparent", border: "none", color: "var(--text-primary)", padding: 4, cursor: "pointer", position: "relative" }}>
          <I.CartIcon size={22} />
          <span style={{ position: "absolute", top: 0, right: 0, minWidth: 14, height: 14, padding: "0 4px", background: "var(--accent)", color: "#fff", borderRadius: 99, fontSize: 9, fontWeight: 700, display: "flex", alignItems: "center", justifyContent: "center" }}>2</span>
        </button>
      }
    />

    <div style={{ flex: 1, overflow: "auto" }} className="no-scrollbar">
      {/* Search */}
      <div style={{ padding: "12px 20px 0" }}>
        <div style={{ display: "flex", alignItems: "center", gap: 10, height: 44, padding: "0 14px", border: "1px solid var(--border-default)", borderRadius: "var(--r-sm)" }}>
          <I.Search size={16} style={{ color: "var(--text-secondary)" }} />
          <span className="t-body" style={{ color: "var(--text-tertiary)" }}>Search singlets, fabrics, brands</span>
        </div>
      </div>

      {/* Featured drop hero */}
      <div style={{ padding: "16px 20px 0" }}>
        <Overline style={{ color: "var(--accent)" }}>SPONSOR DROP · LIVE</Overline>
        <div style={{ position: "relative", height: 200, marginTop: 10, borderRadius: "var(--r-sm)", overflow: "hidden" }}>
          <PhotoPlaceholder kind="arena" style={{ position: "absolute", inset: 0 }} />
          <CornerMark corner="TL" /><CornerMark corner="TR" /><CornerMark corner="BL" /><CornerMark corner="BR" />
          <div style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, transparent 40%, rgba(0,0,0,0.72) 100%)" }} />
          <div style={{ position: "absolute", left: 14, bottom: 14, right: 14, color: "#fff" }}>
            <Overline style={{ color: "rgba(255,255,255,0.6)" }}>Spartan Combat × TKDN · 48H</Overline>
            <div className="t-h4" style={{ marginTop: 4 }}>Open Mat capsule.</div>
            <div className="t-caption-lg" style={{ marginTop: 2, color: "rgba(255,255,255,0.7)" }}>4 cuts. Limited print run. Ends Friday.</div>
          </div>
        </div>
      </div>

      {/* Hub tiles */}
      <div style={{ padding: "20px 20px 0" }}>
        <Overline style={{ color: "var(--text-secondary)" }}>BROWSE</Overline>
        <div style={{ marginTop: 10, display: "grid", gridTemplateColumns: "1fr 1fr", gap: 10 }}>
          {[
            { k: "TKDN-STORE", t: "Takedown Store", s: "12 cuts · in stock" },
            { k: "DESIGNER", t: "Custom Designer", s: "Build · ship in 14d", tint: "var(--module-builder)" },
            { k: "TEAM-STORES", t: "Team Stores", s: "Order for your room" },
            { k: "ATH-STORES", t: "Athlete Stores", s: "Sponsor your roster" },
          ].map((tile) => (
            <div key={tile.k} style={{ position: "relative", border: "1px solid var(--border-subtle)", borderRadius: "var(--r-sm)", padding: 16, minHeight: 96, display: "flex", flexDirection: "column", justifyContent: "space-between" }}>
              <div style={{ position: "absolute", top: 0, left: 12, right: 12, height: 2, background: tile.tint || "var(--module-store)" }} />
              <Overline style={{ color: "var(--text-tertiary)" }}>{tile.k}</Overline>
              <div>
                <div className="t-body-bold">{tile.t}</div>
                <div className="t-caption-lg" style={{ color: "var(--text-secondary)", marginTop: 2 }}>{tile.s}</div>
              </div>
            </div>
          ))}
        </div>
      </div>

      {/* Order strip */}
      <div style={{ padding: "20px 20px 0" }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
          <Overline style={{ color: "var(--text-secondary)" }}>YOUR ORDERS</Overline>
          <span className="t-caption-lg" style={{ color: "var(--text-tertiary)" }}>VIEW ALL</span>
        </div>
        <div style={{ marginTop: 10, padding: 14, borderLeft: "3px solid var(--module-store)", background: "var(--surface-card)", border: "1px solid var(--border-subtle)", borderRadius: "var(--r-sm)" }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
            <Overline style={{ color: "var(--text-tertiary)" }}>ORDER · #4421</Overline>
            <Overline style={{ color: "var(--module-store)" }}>STITCHING · D6</Overline>
          </div>
          <div className="t-body-bold" style={{ marginTop: 6 }}>NCAA Loadout · TD-SGL-014</div>
          <div className="t-caption-lg" style={{ color: "var(--text-secondary)", marginTop: 2 }}>Ships May 22 · ETA May 26</div>
        </div>
      </div>

      {/* New arrivals row */}
      <div style={{ padding: "24px 0 100px 20px" }}>
        <Overline style={{ color: "var(--text-secondary)" }}>NEW ARRIVALS</Overline>
        <div style={{ marginTop: 10, display: "flex", gap: 10, overflowX: "auto" }} className="no-scrollbar">
          {[
            { c: "TD-SGL-015", n: "Clutch", p: "$78" },
            { c: "TD-FS-008", n: "Fader Short", p: "$54" },
            { c: "TD-RG-002", n: "Rashguard LS", p: "$62" },
            { c: "TD-SGL-016", n: "Trials", p: "$82" },
          ].map((p) => (
            <div key={p.c} style={{ flex: "0 0 140px", border: "1px solid var(--border-subtle)", borderRadius: "var(--r-sm)", overflow: "hidden" }}>
              <div style={{ position: "relative", height: 140, background: "var(--bg-tertiary)" }}>
                <PhotoPlaceholder kind="canvas" style={{ position: "absolute", inset: 0 }} />
                <CornerMark corner="TL" /><CornerMark corner="BR" />
              </div>
              <div style={{ padding: "10px 12px" }}>
                <Overline style={{ color: "var(--text-tertiary)" }}>{p.c}</Overline>
                <div className="t-body-bold" style={{ marginTop: 4 }}>{p.n}</div>
                <div className="t-caption-lg" style={{ color: "var(--text-secondary)", marginTop: 2 }}>{p.p}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </div>

    <TabBar active="store" onChange={onTab} />
  </div>
);

// ── STH-2 · Sponsor Drops (secondary hub) ───────────────────────
const SponsorDropsScreen = () => (
  <div style={{ position: "absolute", inset: 0, background: "var(--bg-primary)", display: "flex", flexDirection: "column" }}>
    <StoreTopbar title="Sponsor Drops" onBack={() => {}} />
    <div style={{ flex: 1, overflow: "auto", padding: "12px 20px 32px" }} className="no-scrollbar">
      {/* Filter pills */}
      <div style={{ display: "flex", gap: 6, marginBottom: 16, flexWrap: "wrap" }}>
        {["ALL", "LIVE", "ENDING SOON", "TEAM", "SOLO"].map((t, i) => (
          <Tag key={t} active={i === 0}>{t}</Tag>
        ))}
      </div>

      {[
        { brand: "Spartan Combat", co: "× TKDN", title: "Open Mat capsule.", body: "4 cuts. Limited print run.", tag: "LIVE · 48H", ph: "arena" },
        { brand: "ASICS WR", co: "AUTH", title: "Trials Q3 shoe drop.", body: "GEL-Snapdown · 200 pairs.", tag: "ENDS FRI", ph: "mat" },
        { brand: "DAKE", co: "× TKDN", title: "Champ singlet reissue.", body: "Cael cut. Black/red colorway.", tag: "LIVE · 12D", ph: "athlete" },
        { brand: "HOMETOWN", co: "× IOWA HAWKS", title: "Carver capsule.", body: "Team store · members only.", tag: "TEAM", ph: "gym" },
      ].map((d) => (
        <div key={d.brand} style={{ marginBottom: 16, border: "1px solid var(--border-subtle)", borderRadius: "var(--r-sm)", overflow: "hidden" }}>
          <div style={{ position: "relative", height: 160, background: "var(--bg-tertiary)" }}>
            <PhotoPlaceholder kind={d.ph} style={{ position: "absolute", inset: 0 }} />
            <CornerMark corner="TL" /><CornerMark corner="BR" />
            <div style={{ position: "absolute", top: 12, right: 12, padding: "4px 8px", background: "rgba(13,8,8,0.72)", border: "1px solid rgba(255,255,255,0.2)", borderRadius: "var(--r-xs)" }}>
              <Overline style={{ color: "#fff" }}>{d.tag}</Overline>
            </div>
          </div>
          <div style={{ padding: 14, borderTop: "2px solid var(--module-store)" }}>
            <Overline style={{ color: "var(--text-tertiary)" }}>{d.brand} <span style={{ color: "var(--text-secondary)" }}>{d.co}</span></Overline>
            <div className="t-h5" style={{ marginTop: 6 }}>{d.title}</div>
            <div className="t-caption-lg" style={{ color: "var(--text-secondary)", marginTop: 2 }}>{d.body}</div>
          </div>
        </div>
      ))}
    </div>
  </div>
);

// ── GEN-1 · Takedown Store (browse) ─────────────────────────────
const TakedownStoreBrowseScreen = ({ onOpenPDP }) => (
  <div style={{ position: "absolute", inset: 0, background: "var(--bg-primary)", display: "flex", flexDirection: "column" }}>
    <StoreTopbar title="Takedown Store" onBack={() => {}} right={
      <button style={{ background: "transparent", border: "none", color: "var(--text-primary)", padding: 4, cursor: "pointer" }}>
        <I.Filter size={20} />
      </button>
    } />

    <div style={{ flex: 1, overflow: "auto" }} className="no-scrollbar">
      {/* Category pills */}
      <div style={{ display: "flex", gap: 6, padding: "12px 20px 4px", overflowX: "auto" }} className="no-scrollbar">
        {["ALL", "SINGLETS", "FIGHT SHORTS", "RASHGUARDS", "SHOES", "WARM-UPS", "TEES"].map((t, i) => (
          <div key={t} style={{ flexShrink: 0 }}>
            <Tag active={i === 0}>{t}</Tag>
          </div>
        ))}
      </div>

      {/* Meta */}
      <div style={{ padding: "8px 20px 4px", display: "flex", justifyContent: "space-between" }}>
        <Overline style={{ color: "var(--text-tertiary)" }}>48 RESULTS</Overline>
        <Overline style={{ color: "var(--text-secondary)" }}>SORT · NEW</Overline>
      </div>

      {/* Product grid */}
      <div style={{ padding: "8px 20px 32px", display: "grid", gridTemplateColumns: "1fr 1fr", gap: 10 }}>
        {[
          { c: "TD-SGL-015", n: "Clutch", p: "$78", k: "athlete", colors: ["#0D0808","#FFFFFF","#C61D1D"] },
          { c: "TD-SGL-014", n: "NCAA Loadout", p: "$82", k: "canvas", colors: ["#1D8EC7","#0D0808","#FFFFFF"], note: "BEST SELLER" },
          { c: "TD-FS-008", n: "Fader Short", p: "$54", k: "mat", colors: ["#0D0808","#3A3030"] },
          { c: "TD-RG-002", n: "Rashguard LS", p: "$62", k: "athlete", colors: ["#0D0808","#FFFFFF","#1A3A6C"] },
          { c: "TD-SGL-009", n: "Trials", p: "$82", k: "arena", colors: ["#FFFFFF","#0D0808","#C61D1D"] },
          { c: "TD-SGL-016", n: "Cael Reissue", p: "$110", k: "gym", colors: ["#0D0808","#C61D1D"], note: "DROP · 12D" },
        ].map((p, i) => (
          <div key={p.c} onClick={i === 0 ? onOpenPDP : undefined} style={{ border: "1px solid var(--border-subtle)", borderRadius: "var(--r-sm)", overflow: "hidden", cursor: i === 0 ? "pointer" : "default" }}>
            <div style={{ position: "relative", height: 180, background: "var(--bg-tertiary)" }}>
              <PhotoPlaceholder kind={p.k} style={{ position: "absolute", inset: 0 }} />
              <CornerMark corner="TL" /><CornerMark corner="BR" />
              {p.note && (
                <div style={{ position: "absolute", top: 8, left: 8, padding: "3px 6px", background: "rgba(13,8,8,0.78)", border: "1px solid rgba(255,255,255,0.18)" }}>
                  <Overline style={{ color: "#fff", fontSize: 9 }}>{p.note}</Overline>
                </div>
              )}
            </div>
            <div style={{ padding: "10px 12px" }}>
              <Overline style={{ color: "var(--text-tertiary)" }}>{p.c}</Overline>
              <div className="t-body-bold" style={{ marginTop: 4 }}>{p.n}</div>
              <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 6 }}>
                <div style={{ display: "flex", gap: 3 }}>
                  {p.colors.map((c, ci) => (
                    <span key={ci} style={{ width: 10, height: 10, background: c, border: "1px solid var(--border-subtle)" }} />
                  ))}
                </div>
                <span className="t-caption-lg" style={{ color: "var(--text-primary)", fontWeight: 600 }}>{p.p}</span>
              </div>
            </div>
          </div>
        ))}
      </div>
    </div>
  </div>
);

// ── GEN-2 · Product Detail Page ─────────────────────────────────
const ProductDetailScreen = ({ onBack, onAddToCart }) => {
  const [color, setColor] = React.useState(0);
  const [size, setSize] = React.useState("M");
  const colors = [
    { n: "Black/Red", hex: ["#0D0808", "#C61D1D"] },
    { n: "White/Ink", hex: ["#FFFFFF", "#0D0808"] },
    { n: "Navy", hex: ["#1A3A6C", "#FFFFFF"] },
  ];
  return (
    <div style={{ position: "absolute", inset: 0, background: "var(--bg-primary)", display: "flex", flexDirection: "column" }}>
      <div style={{ flex: 1, overflow: "auto" }} className="no-scrollbar">
        {/* Hero with floating back */}
        <div style={{ position: "relative", height: 420, background: "var(--bg-tertiary)" }}>
          <PhotoPlaceholder kind="canvas" style={{ position: "absolute", inset: 0 }} />
          <CornerMark corner="TL" color="#fff" /><CornerMark corner="TR" color="#fff" /><CornerMark corner="BL" color="#fff" /><CornerMark corner="BR" color="#fff" />
          <button onClick={onBack} style={{ position: "absolute", top: 56, left: 16, width: 36, height: 36, background: "rgba(13,8,8,0.7)", border: "1px solid rgba(255,255,255,0.2)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer" }}>
            <I.ArrowLeft size={18} />
          </button>
          <button style={{ position: "absolute", top: 56, right: 16, width: 36, height: 36, background: "rgba(13,8,8,0.7)", border: "1px solid rgba(255,255,255,0.2)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer" }}>
            <I.Bookmark size={18} />
          </button>
          {/* Pager dots */}
          <div style={{ position: "absolute", bottom: 16, left: 0, right: 0, display: "flex", justifyContent: "center", gap: 6 }}>
            {[0,1,2,3].map((d) => (
              <span key={d} style={{ width: d === 0 ? 16 : 6, height: 2, background: d === 0 ? "#fff" : "rgba(255,255,255,0.4)" }} />
            ))}
          </div>
        </div>

        {/* Title block */}
        <div style={{ padding: "20px 20px 0" }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
            <Overline style={{ color: "var(--module-store)" }}>TD-SGL-015 · CLUTCH</Overline>
            <span className="t-caption-lg" style={{ color: "var(--text-tertiary)" }}>★ 4.8 · 142</span>
          </div>
          <div className="t-h3" style={{ marginTop: 6 }}>Clutch Singlet</div>
          <div className="t-h5" style={{ marginTop: 8, color: "var(--text-primary)" }}>$78</div>
          <div className="t-caption-lg" style={{ color: "var(--text-secondary)", marginTop: 2 }}>or 4 × $19.50 — Affirm at checkout</div>
        </div>

        <Hairline style={{ margin: "20px 20px 0" }} />

        {/* Color picker */}
        <div style={{ padding: "20px 20px 0" }}>
          <div style={{ display: "flex", justifyContent: "space-between" }}>
            <Overline style={{ color: "var(--text-secondary)" }}>COLOR</Overline>
            <Overline style={{ color: "var(--text-tertiary)" }}>{colors[color].n}</Overline>
          </div>
          <div style={{ display: "flex", gap: 10, marginTop: 10 }}>
            {colors.map((c, i) => (
              <button key={c.n} onClick={() => setColor(i)} style={{ width: 56, height: 56, padding: 0, border: i === color ? "2px solid var(--text-primary)" : "1px solid var(--border-subtle)", borderRadius: "var(--r-sm)", background: "transparent", cursor: "pointer", display: "flex", overflow: "hidden" }}>
                {c.hex.map((h, hi) => (
                  <span key={hi} style={{ flex: 1, background: h }} />
                ))}
              </button>
            ))}
          </div>
        </div>

        {/* Size grid */}
        <div style={{ padding: "20px 20px 0" }}>
          <div style={{ display: "flex", justifyContent: "space-between" }}>
            <Overline style={{ color: "var(--text-secondary)" }}>SIZE · WRESTLING</Overline>
            <Overline style={{ color: "var(--module-store)" }}>SIZE GUIDE</Overline>
          </div>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 6, marginTop: 10 }}>
            {["YS","YM","YL","XS","S","M","L","XL","2XL","3XL"].map((s) => {
              const oos = s === "3XL";
              return (
                <button key={s} disabled={oos} onClick={() => setSize(s)}
                  style={{
                    height: 44, padding: 0, background: "transparent",
                    border: size === s ? "2px solid var(--text-primary)" : "1px solid var(--border-default)",
                    color: oos ? "var(--text-tertiary)" : "var(--text-primary)",
                    fontFamily: "inherit", fontSize: 13, fontWeight: 600,
                    borderRadius: "var(--r-sm)",
                    cursor: oos ? "not-allowed" : "pointer",
                    position: "relative",
                  }}>
                  {s}
                  {oos && <span style={{ position: "absolute", inset: "50% 6px auto 6px", height: 1, background: "var(--text-tertiary)" }} />}
                </button>
              );
            })}
          </div>
        </div>

        {/* Spec sheet */}
        <div style={{ padding: "24px 20px 0" }}>
          <Overline style={{ color: "var(--text-secondary)" }}>SPEC</Overline>
          <div style={{ marginTop: 8 }}>
            {[
              ["FABRIC", "240 GSM · Pro Series"],
              ["CUT", "Athletic · single-piece"],
              ["WEIGHT", "210g (size M)"],
              ["MADE IN", "Hudson, OH"],
              ["SHIPS", "1-2 days"],
            ].map(([l, v]) => (
              <div key={l} style={{ display: "flex", justifyContent: "space-between", padding: "12px 0", borderBottom: "1px solid var(--border-subtle)" }}>
                <Overline style={{ color: "var(--text-tertiary)" }}>{l}</Overline>
                <span className="t-body-bold">{v}</span>
              </div>
            ))}
          </div>
        </div>

        {/* Reviews preview */}
        <div style={{ padding: "24px 20px 100px" }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
            <Overline style={{ color: "var(--text-secondary)" }}>REVIEWS · 142</Overline>
            <Overline style={{ color: "var(--module-store)" }}>SEE ALL</Overline>
          </div>
          <div style={{ marginTop: 12, padding: 14, border: "1px solid var(--border-subtle)", borderRadius: "var(--r-sm)" }}>
            <div style={{ display: "flex", justifyContent: "space-between" }}>
              <span className="t-body-bold">★★★★★</span>
              <Overline style={{ color: "var(--text-tertiary)" }}>D. KIM · 65 FS</Overline>
            </div>
            <p className="t-body" style={{ color: "var(--text-secondary)", marginTop: 8 }}>
              Cut is right. Stretches in the shoulders but holds shape. Wore it through nationals - no pilling.
            </p>
          </div>
        </div>
      </div>

      {/* Sticky bottom */}
      <div style={{ padding: "12px 20px 32px", background: "var(--bg-primary)", borderTop: "1px solid var(--border-subtle)", display: "flex", gap: 10, alignItems: "center" }}>
        <div style={{ flex: "0 0 auto" }}>
          <Overline style={{ color: "var(--text-tertiary)" }}>TOTAL</Overline>
          <div className="t-h5">$78</div>
        </div>
        <div style={{ flex: 1 }}>
          <Button label="ADD TO CART" onClick={onAddToCart} fullWidth size="large" tone="mono" rightIcon={<I.ArrowRight />} />
        </div>
      </div>
    </div>
  );
};

// ── GEN-3 · Cart ─────────────────────────────────────────────────
const CartScreen = ({ onBack, onCheckout }) => {
  const items = [
    { c: "TD-SGL-015", n: "Clutch", v: "Black/Red · M", p: 78, q: 1, k: "canvas" },
    { c: "TD-FS-008", n: "Fader Short", v: "Ink · L", p: 54, q: 2, k: "mat" },
  ];
  const subtotal = items.reduce((s, i) => s + i.p * i.q, 0);
  const ship = 8;
  const tax = Math.round(subtotal * 0.08);
  const total = subtotal + ship + tax;
  return (
    <div style={{ position: "absolute", inset: 0, background: "var(--bg-primary)", display: "flex", flexDirection: "column" }}>
      <StoreTopbar title="Cart" onBack={onBack} />
      <div style={{ flex: 1, overflow: "auto", padding: "12px 20px 32px" }} className="no-scrollbar">
        {/* Items */}
        {items.map((it) => (
          <div key={it.c} style={{ display: "flex", gap: 12, padding: "14px 0", borderBottom: "1px solid var(--border-subtle)" }}>
            <div style={{ position: "relative", width: 80, height: 100, background: "var(--bg-tertiary)", flexShrink: 0 }}>
              <PhotoPlaceholder kind={it.k} style={{ position: "absolute", inset: 0 }} />
              <CornerMark corner="TL" /><CornerMark corner="BR" />
            </div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <Overline style={{ color: "var(--text-tertiary)" }}>{it.c}</Overline>
              <div className="t-body-bold" style={{ marginTop: 2 }}>{it.n}</div>
              <div className="t-caption-lg" style={{ color: "var(--text-secondary)", marginTop: 2 }}>{it.v}</div>
              <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 10 }}>
                <div style={{ display: "flex", alignItems: "center", border: "1px solid var(--border-default)", borderRadius: "var(--r-sm)" }}>
                  <button style={{ width: 28, height: 28, background: "transparent", border: "none", color: "var(--text-primary)", cursor: "pointer", fontSize: 16 }}>−</button>
                  <span style={{ minWidth: 24, textAlign: "center", fontWeight: 600 }}>{it.q}</span>
                  <button style={{ width: 28, height: 28, background: "transparent", border: "none", color: "var(--text-primary)", cursor: "pointer", fontSize: 16 }}>+</button>
                </div>
                <span className="t-body-bold">${it.p * it.q}</span>
              </div>
            </div>
          </div>
        ))}

        {/* Promo */}
        <div style={{ marginTop: 16, padding: 14, border: "1px dashed var(--border-default)", borderRadius: "var(--r-sm)", display: "flex", alignItems: "center", justifyContent: "space-between" }}>
          <div>
            <Overline style={{ color: "var(--text-tertiary)" }}>PROMO · GYM CODE</Overline>
            <div className="t-caption-lg" style={{ color: "var(--text-secondary)", marginTop: 2 }}>Add a room or affiliate code</div>
          </div>
          <I.Plus size={18} />
        </div>

        {/* Totals */}
        <div style={{ marginTop: 24 }}>
          {[
            ["SUBTOTAL", `$${subtotal}`],
            ["SHIPPING", `$${ship}`],
            ["TAX", `$${tax}`],
          ].map(([l, v]) => (
            <div key={l} style={{ display: "flex", justifyContent: "space-between", padding: "10px 0", borderBottom: "1px solid var(--border-subtle)" }}>
              <Overline style={{ color: "var(--text-tertiary)" }}>{l}</Overline>
              <span className="t-body">{v}</span>
            </div>
          ))}
          <div style={{ display: "flex", justifyContent: "space-between", padding: "16px 0 0", alignItems: "baseline" }}>
            <Overline style={{ color: "var(--text-secondary)" }}>TOTAL</Overline>
            <span className="t-h4">${total}</span>
          </div>
          <div className="t-caption-lg" style={{ color: "var(--text-tertiary)", marginTop: 4, textAlign: "right" }}>
            or 4 × ${(total/4).toFixed(2)} — Affirm
          </div>
        </div>
      </div>

      <div style={{ padding: "12px 20px 32px", background: "var(--bg-primary)", borderTop: "1px solid var(--border-subtle)" }}>
        <Button label={`CHECKOUT · $${total}`} onClick={onCheckout} fullWidth size="large" tone="mono" rightIcon={<I.ArrowRight />} />
      </div>
    </div>
  );
};

// ── GEN-4 · Order Confirmation ──────────────────────────────────
const OrderConfirmationScreen = ({ onContinue, onTrack }) => (
  <div style={{ position: "absolute", inset: 0, background: "var(--bg-primary)", display: "flex", flexDirection: "column" }}>
    <div style={{ paddingTop: 56, paddingLeft: 20, paddingRight: 20, paddingBottom: 14, borderBottom: "1px solid var(--border-subtle)", display: "flex", justifyContent: "flex-end" }}>
      <button onClick={onContinue} style={{ background: "transparent", border: "none", color: "var(--text-primary)", padding: 4, cursor: "pointer" }}>
        <I.X size={22} />
      </button>
    </div>

    <div style={{ flex: 1, overflow: "auto", padding: "32px 20px" }} className="no-scrollbar">
      {/* Receipt header card */}
      <div style={{ position: "relative", padding: "32px 24px", border: "2px solid var(--border-strong)", borderRadius: "var(--r-sm)" }}>
        <CornerMark corner="TL" /><CornerMark corner="TR" /><CornerMark corner="BL" /><CornerMark corner="BR" />
        <Overline style={{ color: "var(--accent)" }}>ORDER CONFIRMED</Overline>
        <div className="t-h2" style={{ marginTop: 10 }}>You're set.</div>
        <p className="t-body-lg" style={{ color: "var(--text-secondary)", marginTop: 8 }}>
          Receipt is in your inbox. We'll text shipping updates.
        </p>
        <Hairline style={{ margin: "20px 0" }} />
        <div style={{ display: "flex", justifyContent: "space-between", padding: "6px 0" }}>
          <Overline style={{ color: "var(--text-tertiary)" }}>ORDER #</Overline>
          <span className="t-body-bold" style={{ fontFamily: "monospace", letterSpacing: "0.04em" }}>TKDN-4429</span>
        </div>
        <div style={{ display: "flex", justifyContent: "space-between", padding: "6px 0" }}>
          <Overline style={{ color: "var(--text-tertiary)" }}>SHIP TO</Overline>
          <span className="t-body-bold">A. Rivera · 65043</span>
        </div>
        <div style={{ display: "flex", justifyContent: "space-between", padding: "6px 0" }}>
          <Overline style={{ color: "var(--text-tertiary)" }}>ETA</Overline>
          <span className="t-body-bold">Mon, May 26</span>
        </div>
        <div style={{ display: "flex", justifyContent: "space-between", padding: "6px 0" }}>
          <Overline style={{ color: "var(--text-tertiary)" }}>TOTAL</Overline>
          <span className="t-body-bold">$200.96</span>
        </div>
      </div>

      {/* Pipeline */}
      <Overline style={{ color: "var(--text-secondary)", marginTop: 28 }}>PIPELINE</Overline>
      <div style={{ marginTop: 12, position: "relative" }}>
        {/* Vertical rule */}
        <div style={{ position: "absolute", left: 6, top: 8, bottom: 8, width: 1, background: "var(--border-subtle)" }} />
        {[
          { l: "Order placed", t: "now", on: true },
          { l: "Stitching", t: "day 1-6", on: false },
          { l: "Quality check", t: "day 7", on: false },
          { l: "Shipped", t: "day 8", on: false },
        ].map((s) => (
          <div key={s.l} style={{ display: "flex", gap: 14, padding: "10px 0", alignItems: "center" }}>
            <span style={{ width: 13, height: 13, borderRadius: 99, border: "2px solid var(--module-store)", background: s.on ? "var(--module-store)" : "var(--bg-primary)", flexShrink: 0, zIndex: 1 }} />
            <div style={{ flex: 1 }}>
              <div className="t-body-bold" style={{ color: s.on ? "var(--text-primary)" : "var(--text-secondary)" }}>{s.l}</div>
              <Overline style={{ color: "var(--text-tertiary)" }}>{s.t}</Overline>
            </div>
          </div>
        ))}
      </div>
    </div>

    <div style={{ padding: "12px 20px 32px", background: "var(--bg-primary)", borderTop: "1px solid var(--border-subtle)", display: "flex", gap: 10 }}>
      <div style={{ flex: 1 }}>
        <Button label="KEEP SHOPPING" onClick={onContinue} fullWidth size="large" tone="mono" variant="secondary" />
      </div>
      <div style={{ flex: 1 }}>
        <Button label="TRACK ORDER" onClick={onTrack} fullWidth size="large" tone="mono" rightIcon={<I.ArrowRight />} />
      </div>
    </div>
  </div>
);

Object.assign(window, {
  GearHubScreen,
  SponsorDropsScreen,
  TakedownStoreBrowseScreen,
  ProductDetailScreen,
  CartScreen,
  OrderConfirmationScreen,
});
