/* card.jsx, the Yoshi debit card. Pushed from the Accounts tab.
   Two states: no card yet (intro + "Activate" → PIN setup) and an issued card
   with the full detail surface: tap-to-flip card (masked number, Face ID / PIN
   reveal), freeze, add to wallet, rewards, give-your-agent-a-card, statements,
   report lost. Virtual-only — no physical card.
   Card face matches the brand mockup: light card, Yoshi wordmark + recursive
   Y mark, VISA DEBIT, cardholder name. The number lives in-app, not on the face. */

const CardToggle = ({ on, onChange }) =>
<button className="press" role="switch" aria-checked={on} onClick={() => onChange(!on)}
style={{ width: 44, height: 25, padding: 0, position: "relative", background: on ? "var(--signal-neg)" : "var(--rule-2)", border: "none", borderRadius: 999, cursor: "pointer", flex: "none", transition: "background 180ms ease" }}>
    <span style={{ position: "absolute", top: 2.5, left: on ? 21.5 : 2.5, width: 20, height: 20, borderRadius: "50%", background: "#fff", transition: "left 180ms var(--ease)", boxShadow: "0 1px 3px rgba(0,0,0,0.3)" }} />
  </button>;


/* The card face, light, per the brand mockup. Number is intentionally absent. */
const CARD_NUM = "4862 2241 9930 2291";
const CARD_LAST4 = "2291";
const CARD_EXP = "09/29";
const CARD_CVV = "418";

const CardArt = ({ frozen, holder, dim, interactive, flipped, onFlip, revealed, onReveal, onCopy }) => {
  const mark = window.__resources && window.__resources.logoBlack || "assets/logo-mark-black.png";
  const wordmark = window.__resources && window.__resources.wordmarkBlack || "assets/logo-wordmark-black.png";
  const face = { position: "absolute", inset: 0, borderRadius: 16, overflow: "hidden", display: "flex", flexDirection: "column", backfaceVisibility: "hidden", WebkitBackfaceVisibility: "hidden" };
  const flipHint = (label) =>
    <span style={{ position: "absolute", bottom: 11, right: 12, display: "flex", alignItems: "center", gap: 5, fontFamily: "var(--f-display)", fontSize: 9, fontWeight: 600, letterSpacing: "0.04em", textTransform: "uppercase", color: "#9a9a92" }}>
      <Icon name="swap" size={12} stroke={1.5} color="#9a9a92" />{label}
    </span>;

  return (
    <div style={{ perspective: 1500 }}>
      <div onClick={interactive ? onFlip : undefined}
        style={{ position: "relative", aspectRatio: "1.586 / 1", borderRadius: 16, boxShadow: "0 12px 32px -16px rgba(0,0,0,0.45)", transformStyle: "preserve-3d", transition: "transform 640ms cubic-bezier(0.16,1,0.30,1)", transform: flipped ? "rotateY(180deg)" : "none", cursor: interactive ? "pointer" : "default" }}>

        {/* ---------- FRONT ---------- */}
        <div style={{ ...face, padding: "16px 18px", background: "linear-gradient(152deg, #f7f6f2 0%, #ebe9e2 58%, #dddbd2 100%)", opacity: dim ? 0.96 : 1 }}>
          <div style={{ position: "absolute", inset: 0, backgroundImage: "repeating-radial-gradient(circle at 50% 47%, rgba(110,110,98,0.055) 0 1px, transparent 1px 10px)", pointerEvents: "none" }} />
          <img src={mark} alt="" style={{ position: "absolute", left: "50%", top: "53%", transform: "translate(-50%,-50%)", height: "60%", width: "auto", opacity: 0.4, filter: "grayscale(1)" }} />
          <div style={{ position: "relative", display: "flex", alignItems: "flex-start" }}>
            <img src={wordmark} alt="Yoshi" style={{ height: 17, width: "auto", opacity: 0.62 }} />
            <div style={{ marginLeft: "auto", textAlign: "right", lineHeight: 1 }}>
              <div style={{ fontFamily: "var(--f-display)", fontSize: 17, fontWeight: 800, fontStyle: "italic", letterSpacing: "0.01em", color: "#73736c" }}>VISA</div>
              <div style={{ fontFamily: "var(--f-display)", fontSize: 8.5, fontWeight: 700, letterSpacing: "0.16em", color: "#8c8c84", marginTop: 2 }}>DEBIT</div>
            </div>
          </div>
          <div style={{ position: "relative", marginTop: "auto", display: "flex", alignItems: "flex-end" }}>
            <div style={{ fontFamily: "var(--f-display)", fontSize: 13.5, fontWeight: 600, letterSpacing: "0.04em", color: "#55554f" }}>{holder}</div>
            <span style={{ marginLeft: "auto", fontFamily: "var(--f-mono)", fontSize: 12, color: "#8c8c84", letterSpacing: "0.08em" }}>•• {CARD_LAST4}</span>
          </div>
          {interactive && flipHint("Tap to flip")}
          {frozen &&
          <div style={{ position: "absolute", inset: 0, background: "repeating-linear-gradient(135deg, rgba(40,40,36,0.20) 0 10px, rgba(40,40,36,0.30) 10px 20px)", display: "grid", placeItems: "center" }}>
            <span style={{ fontFamily: "var(--f-display)", fontSize: 11, fontWeight: 700, letterSpacing: "0.16em", textTransform: "uppercase", color: "#3a3a34", background: "rgba(255,255,255,0.85)", padding: "5px 12px" }}>Frozen</span>
          </div>}
        </div>

        {/* ---------- BACK ---------- */}
        <div style={{ ...face, transform: "rotateY(180deg)", background: "linear-gradient(152deg, #f4f3ef 0%, #e6e4dc 100%)" }}>
          {/* magnetic stripe */}
          <div style={{ height: "26%", marginTop: 16, background: "#26251f" }} />
          <div style={{ position: "relative", flex: 1, padding: "12px 18px 14px", display: "flex", flexDirection: "column" }}>
            {/* number */}
            <div style={{ fontFamily: "var(--f-display)", fontSize: 8.5, fontWeight: 700, letterSpacing: "0.12em", textTransform: "uppercase", color: "#9a9a92" }}>Card number</div>
            <div style={{ display: "flex", alignItems: "center", gap: 10, marginTop: 4 }}>
              <span style={{ fontFamily: "var(--f-mono)", fontSize: 15, letterSpacing: "0.06em", color: "#3a3a34", fontVariantNumeric: "tabular-nums" }}>
                {revealed ? CARD_NUM : `•••• •••• •••• ${CARD_LAST4}`}
              </span>
              {revealed
                ? <button className="press" onClick={(e) => { e.stopPropagation(); onCopy && onCopy(); }} aria-label="Copy card number" style={{ marginLeft: "auto", background: "none", border: "none", display: "flex", color: "#73736c", padding: 2, cursor: "pointer" }}><Icon name="receipt" size={15} /></button>
                : <button className="press" onClick={(e) => { e.stopPropagation(); onReveal && onReveal(); }} style={{ marginLeft: "auto", display: "flex", alignItems: "center", gap: 5, background: "rgba(255,255,255,0.6)", border: "1px solid rgba(0,0,0,0.12)", borderRadius: 999, padding: "4px 10px", cursor: "pointer", fontFamily: "var(--f-display)", fontSize: 10, fontWeight: 600, color: "#55554f" }}><Icon name="shield" size={12} stroke={1.5} color="#55554f" />Reveal</button>}
            </div>
            {/* exp + cvv */}
            <div style={{ display: "flex", gap: 26, marginTop: 14 }}>
              <div>
                <div style={{ fontFamily: "var(--f-display)", fontSize: 8.5, fontWeight: 700, letterSpacing: "0.12em", textTransform: "uppercase", color: "#9a9a92" }}>Exp</div>
                <div style={{ fontFamily: "var(--f-mono)", fontSize: 13, color: "#3a3a34", marginTop: 3 }}>{CARD_EXP}</div>
              </div>
              <div>
                <div style={{ fontFamily: "var(--f-display)", fontSize: 8.5, fontWeight: 700, letterSpacing: "0.12em", textTransform: "uppercase", color: "#9a9a92" }}>CVV</div>
                <div style={{ fontFamily: "var(--f-mono)", fontSize: 13, color: "#3a3a34", marginTop: 3 }}>{revealed ? CARD_CVV : "•••"}</div>
              </div>
              <div style={{ marginLeft: "auto", alignSelf: "flex-end", textAlign: "right" }}>
                <div style={{ fontFamily: "var(--f-display)", fontSize: 8, color: "#9a9a92", letterSpacing: "0.04em" }}>Yoshi debit</div>
              </div>
            </div>
          </div>
          {interactive && flipHint("Tap to flip")}
        </div>

      </div>
    </div>);

};

/* ---- security gate · Face ID or PIN before revealing card details --------- */
const SecurityGate = ({ onSuccess, onCancel }) => {
  const [mode, setMode] = useState("faceid"); // faceid | pin
  const [authing, setAuthing] = useState(false);
  const [pin, setPin] = useState("");

  const runFace = () => { setAuthing(true); setTimeout(() => { setAuthing(false); onSuccess(); }, 1150); };
  const pinKey = (k) => {
    if (k === "⌫") { setPin((p) => p.slice(0, -1)); return; }
    if (pin.length >= 4) return;
    const next = pin + k;
    setPin(next);
    if (next.length === 4) setTimeout(() => onSuccess(), 220);
  };

  return (
    <div style={{ position: "absolute", inset: 0, zIndex: 60, background: "color-mix(in srgb, var(--bg) 90%, transparent)", backdropFilter: "blur(8px)", WebkitBackdropFilter: "blur(8px)", display: "flex", flexDirection: "column", animation: "fade-swap 200ms ease both" }}>
      <div style={{ display: "flex", justifyContent: "flex-end", padding: "12px 14px" }}>
        <button className="press" onClick={onCancel} aria-label="Cancel" style={{ background: "none", border: "none", display: "flex", color: "var(--ink-3)", padding: 4, cursor: "pointer" }}><Icon name="close" size={20} /></button>
      </div>

      {mode === "faceid" ? (
        <div style={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", gap: 20, padding: "0 24px 40px", textAlign: "center" }}>
          <div style={{ position: "relative", width: 86, height: 86, display: "grid", placeItems: "center" }}>
            {authing && <span style={{ position: "absolute", inset: 0, border: "1.5px solid var(--accent)", borderRadius: 20, animation: "ring-out 950ms ease-out infinite" }} />}
            <div style={{ width: 76, height: 76, border: `1.5px solid ${authing ? "var(--accent)" : "var(--rule-2)"}`, borderRadius: 20, display: "grid", placeItems: "center", transition: "border-color 200ms ease" }}>
              <Icon name="shield" size={34} stroke={1.4} color={authing ? "var(--accent)" : "var(--ink-2)"} />
            </div>
          </div>
          <div>
            <div style={{ fontFamily: "var(--f-display)", fontSize: 18, fontWeight: 600, letterSpacing: "-0.02em" }}>{authing ? "Authenticating…" : "Reveal card details"}</div>
            <div style={{ fontFamily: "var(--f-display)", fontSize: 12.5, color: "var(--ink-2)", marginTop: 7, lineHeight: 1.5, maxWidth: 250 }}>Confirm with Face ID to show your full card number and CVV.</div>
          </div>
          <div style={{ width: "100%", maxWidth: 300 }}>
            <Btn full onClick={runFace} disabled={authing}>{authing ? "Confirming…" : "Confirm with Face ID"}</Btn>
            <Btn kind="ghost" full onClick={() => setMode("pin")} style={{ marginTop: 8 }} disabled={authing}>Enter PIN instead</Btn>
          </div>
        </div>
      ) : (
        <div style={{ flex: 1, display: "flex", flexDirection: "column", minHeight: 0 }}>
          <div style={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", textAlign: "center", padding: "0 24px" }}>
            <div style={{ fontFamily: "var(--f-display)", fontSize: 18, fontWeight: 600, letterSpacing: "-0.02em" }}>Enter your card PIN</div>
            <div style={{ fontFamily: "var(--f-display)", fontSize: 12.5, color: "var(--ink-2)", marginTop: 7, lineHeight: 1.5, maxWidth: 250 }}>Verify it's you to reveal card details.</div>
            <div style={{ marginTop: 28 }}><PinDots filled={pin.length} len={4} /></div>
            <button className="press" onClick={() => { setPin(""); setMode("faceid"); }} style={{ marginTop: 22, background: "none", border: "none", fontFamily: "var(--f-display)", fontSize: 12.5, fontWeight: 600, color: "var(--accent)", cursor: "pointer" }}>Use Face ID instead</button>
          </div>
          <PinPad onKey={pinKey} />
        </div>
      )}
    </div>);
};

const CardActionTile = ({ icon, label, on, onClick }) =>
<button className="press" onClick={onClick} style={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", gap: 6, padding: "12px 4px 10px", borderRadius: 12, background: on ? "color-mix(in srgb, var(--signal-neg) 12%, var(--bg-card))" : "var(--bg-card)", border: `1px solid ${on ? "var(--signal-neg)" : "var(--rule)"}`, cursor: "pointer" }}>
    <Icon name={icon} size={20} stroke={1.5} color={on ? "var(--signal-neg)" : "var(--ink)"} />
    <span style={{ fontFamily: "var(--f-display)", fontSize: 10.5, fontWeight: 600, color: on ? "var(--signal-neg)" : "var(--ink-2)", letterSpacing: "0.01em" }}>{label}</span>
  </button>;


const CardRow = ({ icon, name, sub, right, onClick, danger, last }) =>
<button className="press" onClick={onClick} style={{ width: "100%", display: "grid", gridTemplateColumns: "32px 1fr auto", gap: 12, alignItems: "center", padding: "13px 16px", background: "none", border: "none", borderBottom: last ? "none" : "1px solid var(--rule)", textAlign: "left", cursor: "pointer" }}>
    <span style={{ width: 32, height: 32, display: "grid", placeItems: "center" }}><Icon name={icon} size={18} stroke={1.5} color={danger ? "var(--signal-danger)" : "var(--ink)"} /></span>
    <div style={{ minWidth: 0 }}>
      <div style={{ fontFamily: "var(--f-display)", fontSize: 14, fontWeight: 500, color: danger ? "var(--signal-danger)" : "var(--ink)" }}>{name}</div>
      {sub && <div style={{ fontFamily: "var(--f-display)", fontSize: 11.5, color: "var(--ink-3)", marginTop: 3 }}>{sub}</div>}
    </div>
    {right !== undefined ? right : <Icon name="back" size={15} color="var(--ink-3)" style={{ transform: "scaleX(-1)" }} />}
  </button>;


/* ---- no card yet · intro + provision ------------------------------------- */
const CardBenefit = ({ icon, title, sub }) =>
<div style={{ display: "flex", gap: 12, alignItems: "flex-start", padding: "11px 0", borderBottom: "1px solid var(--rule)" }}>
    <span style={{ width: 30, height: 30, flex: "none", border: "1px solid var(--rule-2)", display: "grid", placeItems: "center" }}><Icon name={icon} size={16} stroke={1.5} color="var(--ink)" /></span>
    <div style={{ minWidth: 0 }}>
      <div style={{ fontFamily: "var(--f-display)", fontSize: 13.5, fontWeight: 600 }}>{title}</div>
      <div style={{ fontFamily: "var(--f-display)", fontSize: 11.5, color: "var(--ink-3)", marginTop: 3, lineHeight: 1.45 }}>{sub}</div>
    </div>
  </div>;


const CardIntro = ({ onGet, holder }) =>
<div style={{ flex: 1, display: "flex", flexDirection: "column", minHeight: 0 }}>
    <div className="scroll" style={{ padding: "16px 18px 16px" }}>
      <div style={{ position: "relative" }}>
        <CardArt holder={holder} dim />
        <span style={{ position: "absolute", top: 12, left: 12, fontFamily: "var(--f-display)", fontSize: 8.5, fontWeight: 700, letterSpacing: "0.1em", textTransform: "uppercase", color: "#55554f", background: "rgba(255,255,255,0.8)", padding: "3px 8px" }}>Preview</span>
      </div>
      <div style={{ fontFamily: "var(--f-display)", fontSize: 21, fontWeight: 600, letterSpacing: "-0.025em", marginTop: 18 }}>Your Yoshi debit card</div>
      <div style={{ fontFamily: "var(--f-display)", fontSize: 13, color: "var(--ink-2)", marginTop: 6, lineHeight: 1.5 }}>One card on your unified balance. </div>
      <div style={{ marginTop: 16 }}>
        <CardBenefit icon="trade" title="1.5% back on everything" sub="Paid to Checking every month" />
        <CardBenefit icon="shield" title="Freeze and set limits in a tap" sub="Per-day and ATM caps you control" />
        <CardBenefit icon="bolt" title="Give your agent a card" sub="A scoped virtual card Yoshi can spend on, inside your caps" />
      </div>
    </div>
    <div style={{ flex: "none", padding: "12px 18px 28px", borderTop: "1px solid var(--rule)" }}>
      <Btn full onClick={onGet}>Activate <Icon name="arrow" size={18} color="var(--accent-ink)" /></Btn>
      <div style={{ fontFamily: "var(--f-display)", fontSize: 10.5, color: "var(--ink-3)", textAlign: "center", marginTop: 10, lineHeight: 1.4 }}>Set a PIN to activate · issued instantly · no fees · FDIC-insured to applicable limits.</div>
    </div>
  </div>;


/* ---- PIN setup · enter → confirm, before the card activates --------------- */
const PinDots = ({ filled, len, error }) =>
<div style={{ display: "flex", gap: 18, justifyContent: "center" }}>
    {Array.from({ length: len }).map((_, i) =>
  <span key={i} style={{ width: 14, height: 14, borderRadius: 999, border: `1.5px solid ${error ? "var(--signal-neg)" : "var(--ink)"}`, background: i < filled ? error ? "var(--signal-neg)" : "var(--ink)" : "transparent", transition: "background 120ms, border-color 120ms" }} />
  )}
  </div>;

const PinPad = ({ onKey }) => {
  const keys = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "", "0", "⌫"];
  return (
    <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 1, background: "var(--rule)" }}>
      {keys.map((k, i) => k === "" ?
      <span key={i} style={{ background: "var(--bg)" }} /> :
      <button key={i} className="press" onClick={() => onKey(k)} style={{ padding: "17px 0", background: "var(--bg)", border: "none", fontFamily: "var(--f-display)", fontSize: 23, fontWeight: 500, color: "var(--ink)", cursor: "pointer" }}>{k}</button>
      )}
    </div>);
};

const CardPinSetup = ({ onDone }) => {
  const LEN = 4;
  const [phase, setPhase] = useState("set"); // set | confirm
  const [first, setFirst] = useState("");
  const [pin, setPin] = useState("");
  const [error, setError] = useState(false);

  const press = (k) => {
    if (error) {setError(false);}
    if (k === "⌫") {setPin((p) => p.slice(0, -1));return;}
    if (pin.length >= LEN) return;
    const next = pin + k;
    setPin(next);
    if (next.length === LEN) {
      setTimeout(() => {
        if (phase === "set") {setFirst(next);setPin("");setPhase("confirm");} else
        if (next === first) {onDone();} else
        {setError(true);setPin("");setPhase("set");setFirst("");}
      }, 180);
    }
  };

  const heading = error ? "PINs didn't match" : phase === "set" ? "Set your card PIN" : "Confirm your PIN";
  const sub = error ? "Let's try that again — choose a 4-digit PIN." : phase === "set" ? "Choose a 4-digit PIN for ATMs and in-store payments." : "Enter the same four digits once more.";

  return (
    <div style={{ flex: 1, display: "flex", flexDirection: "column", minHeight: 0 }}>
      <div style={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", padding: "24px 24px 8px", textAlign: "center" }}>
        <span style={{ width: 46, height: 46, flex: "none", border: "1px solid var(--rule-2)", borderRadius: 999, display: "grid", placeItems: "center", marginBottom: 18 }}>
          <Icon name="shield" size={20} stroke={1.5} color={error ? "var(--signal-neg)" : "var(--ink)"} />
        </span>
        <div style={{ fontFamily: "var(--f-display)", fontSize: 19, fontWeight: 600, letterSpacing: "-0.02em", color: error ? "var(--signal-neg)" : "var(--ink)" }}>{heading}</div>
        <div style={{ fontFamily: "var(--f-display)", fontSize: 12.5, color: "var(--ink-2)", marginTop: 7, lineHeight: 1.5, maxWidth: 260 }}>{sub}</div>
        <div style={{ marginTop: 30 }}><PinDots filled={pin.length} len={LEN} error={error} /></div>
      </div>
      <div style={{ flex: "none" }}>
        <div style={{ fontFamily: "var(--f-display)", fontSize: 10.5, color: "var(--ink-3)", textAlign: "center", padding: "0 24px 12px", lineHeight: 1.4 }}>Avoid an obvious PIN like 1234 or your birth year.</div>
        <PinPad onKey={press} />
      </div>
    </div>);

};

const CardDetail = ({ nav, flash, hasCard, onGetCard }) => {
  const [frozen, setFrozen] = useState(false);
  const [flipped, setFlipped] = useState(false);
  const [revealed, setRevealed] = useState(false);
  const [auth, setAuth] = useState(false); // security gate for reveal
  const [step, setStep] = useState("intro"); // intro | pin (pre-issue activation)
  const f = flash || (() => {});
  const holder = window.PROFILE && window.PROFILE.name || "Rivka Lipson";

  const freeze = (v) => {setFrozen(v);f(v ? "Card frozen" : "Card unfrozen");};
  const copyNumber = () => {try {navigator.clipboard && navigator.clipboard.writeText("4862224199302291");} catch (e) {}f("Card number copied");};
  const toggleFlip = () => setFlipped((v) => { if (v) setRevealed(false); return !v; });
  const agentCard = () => {
    nav.ask("Give Yoshi a card to spend on.",
    "Done, well, almost. I’ll mint a virtual card scoped to a monthly cap and a set of merchants, and it runs as a standing automation inside your trust ladder. Tell me the cap (say “$400/month for cloud and SaaS”) and I’ll set it up for you to approve. You can freeze it anytime.");
  };

  if (!hasCard) {
    return (
      <div style={{ flex: 1, display: "flex", flexDirection: "column", minHeight: 0 }} data-screen-label="Card">
        {step === "pin" ?
        <>
            <NavBar title="Set a PIN" onBack={() => setStep("intro")} />
            <CardPinSetup onDone={() => {onGetCard && onGetCard();f("Card activated · PIN set");}} />
          </> :

        <>
            <NavBar title="Card" onBack={() => nav.pop()} />
            <CardIntro holder={holder} onGet={() => setStep("pin")} />
          </>
        }
      </div>);

  }

  return (
    <div style={{ flex: 1, display: "flex", flexDirection: "column", minHeight: 0 }} data-screen-label="Card">
      <NavBar title="Card" sub="Yoshi debit · ••2291" onBack={() => nav.pop()} />

      <div className="scroll" style={{ padding: "14px 18px 26px" }}>
        <CardArt frozen={frozen} holder={holder} interactive flipped={flipped} onFlip={toggleFlip}
          revealed={revealed} onReveal={() => setAuth(true)} onCopy={copyNumber} />

        {frozen &&
        <div style={{ display: "flex", gap: 8, marginTop: 12, padding: "10px 12px", background: "color-mix(in srgb, var(--signal-neg) 10%, var(--bg-2))", border: "1px solid color-mix(in srgb, var(--signal-neg) 35%, transparent)", alignItems: "center" }}>
            <Icon name="shield" size={15} color="var(--signal-neg)" stroke={1.5} />
            <span style={{ fontFamily: "var(--f-display)", fontSize: 11.5, color: "var(--ink-2)" }}>Card is frozen. New charges and withdrawals are blocked.</span>
          </div>
        }

        {/* quick actions */}
        <div style={{ display: "flex", gap: 8, marginTop: 14 }}>
          <CardActionTile icon="swap" label={flipped ? "Front" : "Details"} on={flipped} onClick={toggleFlip} />
          <CardActionTile icon="plus" label="Add to Pay" onClick={() => f("Added to Apple Wallet")} />
          <CardActionTile icon={frozen ? "check" : "shield"} label={frozen ? "Unfreeze" : "Freeze"} on={frozen} onClick={() => freeze(!frozen)} />
        </div>

        {/* rewards */}
        <Eyebrow style={{ margin: "22px 0 8px" }}>Rewards</Eyebrow>
        <div style={{ border: "1px solid var(--rule)", borderRadius: 12, padding: "14px 15px", display: "flex", alignItems: "center", gap: 14 }}>
          <div>
            <div style={{ fontFamily: "var(--f-display)", fontSize: 10, fontWeight: 600, letterSpacing: "0.08em", textTransform: "uppercase", color: "var(--ink-3)" }}>Back this month</div>
            <div style={{ marginTop: 3 }}><Money value={42.18} size={22} weight={500} color="var(--accent-pos)" /></div>
          </div>
          <div style={{ marginLeft: "auto", textAlign: "right" }}>
            <div style={{ fontFamily: "var(--f-mono)", fontSize: 13, color: "var(--ink-2)" }}>1.5%</div>
            <div style={{ fontFamily: "var(--f-display)", fontSize: 10.5, color: "var(--ink-3)", marginTop: 3 }}>on everything · paid to Checking</div>
          </div>
        </div>

        {/* manage */}
        <Eyebrow style={{ margin: "22px 0 8px" }}>Manage</Eyebrow>
        <div style={{ border: "1px solid var(--rule)", borderRadius: 12, overflow: "hidden" }}>
          <CardRow icon="bolt" name="Give Yoshi a card" sub="A virtual card scoped to a monthly cap, approved once" onClick={agentCard} />
          <CardRow icon="gear" name="Spending limits" sub="$5,000 / day · $1,000 ATM" onClick={() => f("Limits open")} />
          <CardRow icon="receipt" name="Card statements" onClick={() => nav.tab && nav.tab("profile")} last />
        </div>

        {/* danger */}
        <div style={{ marginTop: 22, border: "1px solid var(--rule)", borderRadius: 12, overflow: "hidden" }}>
          <CardRow icon="close" name="Report lost or compromised" sub="Freeze + issue a new card number" danger
          onClick={() => {setFrozen(true);f("Reported · a new card number is on the way");}} last />
        </div>

        <div style={{ fontFamily: "var(--f-display)", fontSize: 10.5, color: "var(--ink-3)", marginTop: 36, lineHeight: 1.6 }}>
          Your virtual card works online right away. The Yoshi debit card draws from Checking. Credit is coming soon.
        </div>
      </div>

      {auth &&
      <SecurityGate
        onSuccess={() => { setAuth(false); setRevealed(true); setFlipped(true); f("Card details revealed"); }}
        onCancel={() => setAuth(false)} />}
    </div>);

};

window.CardDetail = CardDetail;