// store-pages.jsx — extra storefront pages for MagicalKitten:
// Footer, Lifestyle band, About/The Artist, Bespoke, Checkout, Confirmation.
// Reads shared helpers from window (defined in store.jsx). Exports views to window.

const { money, TButton, SealDivider, StoreEnso, useIsNarrow, ImageSlot, MK_PRODUCTS } = window;

// ---- form field ----------------------------------------------------------
function Field({ t, label, placeholder, type = 'text', value, onChange, wide, half }) {
  return (
    <label style={{ display: 'block', gridColumn: wide ? '1 / -1' : 'auto' }}>
      <div style={{ fontSize: 10.5, letterSpacing: '0.16em', textTransform: 'uppercase', color: t.soft, marginBottom: 7 }}>{label}</div>
      <input type={type} placeholder={placeholder} value={value || ''} onChange={(e) => onChange && onChange(e.target.value)}
        style={{ width: '100%', padding: '13px 14px', border: `1px solid ${t.line}`, borderRadius: 3, background: t.light ? 'rgba(255,255,255,0.6)' : 'rgba(255,255,255,0.06)',
          color: t.accent, fontFamily: t.bodyFont, fontSize: 14.5, outline: 'none', transition: 'border .2s' }}
        onFocus={(e) => (e.currentTarget.style.borderColor = t.accent)}
        onBlur={(e) => (e.currentTarget.style.borderColor = t.line)} />
    </label>
  );
}

function SectionHead({ t, kicker, title, sub, center }) {
  return (
    <div style={{ textAlign: center ? 'center' : 'left', maxWidth: center ? 640 : 'none', margin: center ? '0 auto' : 0 }}>
      {kicker && <div style={{ fontSize: 11, letterSpacing: '0.32em', textTransform: 'uppercase', color: t.soft, marginBottom: 16 }}>{kicker}</div>}
      <h2 style={{ fontFamily: t.titleFont, fontSize: 'clamp(30px, 4.6vw, 46px)', fontWeight: 600, margin: 0, color: t.accent, lineHeight: 1.08 }}>{title}</h2>
      {sub && <p style={{ fontSize: 15, lineHeight: 1.8, color: t.soft, margin: '16px auto 0', maxWidth: 540 }}>{sub}</p>}
    </div>
  );
}

// ---- lifestyle band (home) ----------------------------------------------
function LifestyleBand({ t }) {
  const narrow = useIsNarrow(760);
  const shots = [
    { id: 'life-table', tall: true, cap: 'On the table — a set mid-game' },
    { id: 'life-hand', tall: false, cap: 'The hand-painted detail' },
    { id: 'life-case', tall: false, cap: 'The brass travelling case' },
  ];
  return (
    <div style={{ maxWidth: 1180, margin: '0 auto', padding: '20px 32px 70px' }}>
      <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr' : '1.3fr 1fr', gap: 18 }}>
        <div style={{ position: 'relative' }}>
          <ImageSlot id="life-table" w="100%" h={narrow ? 320 : 460} shape="rounded" radius={12} placeholder="Drop a lifestyle photo — a set in play" />
          <Caption t={t} text={shots[0].cap} />
        </div>
        <div style={{ display: 'grid', gridTemplateRows: '1fr 1fr', gap: 18 }}>
          {shots.slice(1).map((s) => (
            <div key={s.id} style={{ position: 'relative' }}>
              <ImageSlot id={s.id} w="100%" h={narrow ? 200 : 221} shape="rounded" radius={12} placeholder={`Drop a photo — ${s.cap.split('— ')[1] || s.cap}`} />
              <Caption t={t} text={s.cap} />
            </div>
          ))}
        </div>
      </div>
      <div style={{ textAlign: 'center', fontSize: 11, letterSpacing: '0.16em', textTransform: 'uppercase', color: t.soft, marginTop: 18 }}>
        Photography placeholders — drag in the artist’s real photos
      </div>
    </div>
  );
}
function Caption({ t, text }) {
  return <div style={{ fontSize: 11, letterSpacing: '0.12em', textTransform: 'uppercase', color: t.soft, marginTop: 10 }}>{text}</div>;
}

// ---- About / The Artist --------------------------------------------------
function AboutView({ t, onNav }) {
  const narrow = useIsNarrow(820);
  const steps = [
    { n: '01', k: 'Paint', d: 'Every suit is brushed by hand — dots, bamboo, characters — in small batches of colour mixed to the house recipe.', tile: { suit: 'char', value: 3 } },
    { n: '02', k: 'Pour', d: 'Tiles are cast in resin around each painted face, then left to cure for a week before they leave the mould.', tile: { suit: 'dot', value: 5 } },
    { n: '03', k: 'Polish', d: 'Each tile is sanded and hand-polished to the soft, warm edge that only finishing by hand can give.', tile: { suit: 'bamboo', value: 1 } },
    { n: '04', k: 'Seal', d: 'The finished set is stamped with our seal and numbered — then yours, if it’s made to order.', tile: { suit: 'cat', value: 1, rainbow: true } },
  ];
  return (
    <div>
      {/* hero */}
      <div style={{ maxWidth: 1180, margin: '0 auto', padding: '56px 32px 30px' }}>
        <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr' : '1fr 1fr', gap: narrow ? 32 : 60, alignItems: 'center' }}>
          <div>
            <div style={{ fontSize: 11, letterSpacing: '0.32em', textTransform: 'uppercase', color: t.soft, marginBottom: 18 }}>The hand behind the tiles</div>
            <h1 style={{ fontFamily: t.titleFont, fontSize: 'clamp(40px, 6vw, 64px)', lineHeight: 1.04, fontWeight: 600, margin: 0, color: t.accent }}>
              One artist,<br />one brush,<br /><span style={{ fontStyle: 'italic' }}>every tile.</span>
            </h1>
            <p style={{ fontSize: 15.5, lineHeight: 1.85, color: t.soft, marginTop: 24, maxWidth: 440 }}>
              MagicalKitten began at a single kitchen table, with a jar of brushes and a love of the game. Every set we sell is still painted by the same hand — no transfers, no printing, no two exactly alike.
            </p>
            <p style={{ fontSize: 15.5, lineHeight: 1.85, color: t.soft, marginTop: 20, maxWidth: 440 }}>
              The rainbow kitten that gives the house its name started as a private joke on a one-bamboo tile. It stayed, and became our signature.
            </p>
          </div>
          <div style={{ position: 'relative' }}>
            <ImageSlot id="about-portrait" w="100%" h={narrow ? 360 : 480} shape="rounded" radius={14} placeholder="Drop the artist’s portrait" />
            <div style={{ position: 'absolute', bottom: 16, left: 16 }}>
              <Seal chars={['貓']} fill={t.sealFill} ink={t.sealInk} size={42} rotate={-7} />
            </div>
          </div>
        </div>
      </div>

      <div style={{ padding: '24px 0 8px' }}><SealDivider t={t} char="藝" /></div>

      {/* process */}
      <div style={{ maxWidth: 1180, margin: '0 auto', padding: '40px 32px 20px' }}>
        <SectionHead t={t} kicker="How a set is made" title="Four steps, by hand" center />
        <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr' : 'repeat(4, 1fr)', gap: 22, marginTop: 40 }}>
          {steps.map((s) => (
            <div key={s.n} style={{ background: t.cardBg, border: `1px solid ${t.line}`, borderRadius: 10, padding: '26px 22px', textAlign: 'center' }}>
              <div style={{ height: 120, display: 'flex', alignItems: 'center', justifyContent: 'center' }}><Tile {...s.tile} w={72} lift={false} /></div>
              <div style={{ fontFamily: t.titleFont, fontSize: 15, letterSpacing: '0.2em', color: t.soft, marginTop: 10 }}>{s.n}</div>
              <div style={{ fontFamily: t.titleFont, fontSize: 24, color: t.accent, marginTop: 4 }}>{s.k}</div>
              <p style={{ fontSize: 13.5, lineHeight: 1.7, color: t.soft, marginTop: 10 }}>{s.d}</p>
            </div>
          ))}
        </div>
      </div>

      {/* studio shots */}
      <div style={{ maxWidth: 1180, margin: '0 auto', padding: '40px 32px 80px' }}>
        <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr' : '1fr 1fr', gap: 18 }}>
          <ImageSlot id="about-studio-1" w="100%" h={narrow ? 240 : 320} shape="rounded" radius={12} placeholder="Drop a studio photo — the workbench" />
          <ImageSlot id="about-studio-2" w="100%" h={narrow ? 240 : 320} shape="rounded" radius={12} placeholder="Drop a studio photo — painting a tile" />
        </div>
        <div style={{ textAlign: 'center', marginTop: 40 }}>
          <TButton t={t} onClick={() => onNav('bespoke')}>Commission your own set</TButton>
        </div>
      </div>
    </div>
  );
}

// ---- Bespoke -------------------------------------------------------------
function BespokeView({ t }) {
  const narrow = useIsNarrow(820);
  const [form, setForm] = React.useState({});
  const [sent, setSent] = React.useState(false);
  const [busy, setBusy] = React.useState(false);
  const [err, setErr] = React.useState('');
  const set = (k) => (v) => setForm((f) => ({ ...f, [k]: v }));
  const submit = async () => {
    if (busy) return;
    setErr(''); setBusy(true);
    try {
      const r = await fetch('/api/enquiry', {
        method: 'POST', headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ name: form.name, email: form.email, base: form.base, note: form.note }),
      });
      const data = await r.json().catch(() => ({}));
      if (!r.ok) throw new Error(data.error || 'Something went wrong — please try again.');
      setSent(true);
    } catch (e) {
      setErr(e.message === 'Failed to fetch' ? 'Network error — please try again.' : e.message);
    } finally { setBusy(false); }
  };
  const steps = [
    { n: '01', k: 'Consult', d: 'Tell us how you play and who it’s for. We’ll talk colours, characters and case.' },
    { n: '02', k: 'Design', d: 'We paint a sample tile and send it to you, then refine until it’s exactly right.' },
    { n: '03', k: 'Craft', d: 'Your set is painted, poured and finished over roughly eight weeks, then sealed and numbered.' },
  ];
  return (
    <div>
      <div style={{ maxWidth: 1180, margin: '0 auto', padding: '56px 32px 20px', textAlign: 'center', position: 'relative' }}>
        <div style={{ fontSize: 11, letterSpacing: '0.32em', textTransform: 'uppercase', color: t.soft, marginBottom: 18 }}>Made to order</div>
        <h1 style={{ fontFamily: t.titleFont, fontSize: 'clamp(40px, 6.4vw, 68px)', lineHeight: 1.03, fontWeight: 600, margin: 0, color: t.accent }}>
          A set made only<br /><span style={{ fontStyle: 'italic' }}>for you.</span>
        </h1>
        <p style={{ maxWidth: 500, margin: '20px auto 0', fontSize: 15.5, lineHeight: 1.8, color: t.soft }}>
          Choose your suits, your colours, your case and your seal. We paint a one-of-a-kind set by hand and number it to you.
        </p>
        <div style={{ position: 'relative', display: 'inline-block', margin: '30px 0 0', padding: '20px 50px' }}>
          <StoreEnso color={t.ensoColor} />
          <div style={{ position: 'relative', display: 'flex', alignItems: 'flex-end', justifyContent: 'center', gap: 12, height: 180 }}>
            <Tile suit="char" value={8} w={70} tilt={-7} style={{ alignSelf: 'center' }} />
            <Tile suit="cat" value={1} w={112} rainbow />
            <Tile suit="dragon" value="green" w={70} tilt={7} style={{ alignSelf: 'center' }} />
          </div>
        </div>
      </div>

      {/* steps */}
      <div style={{ maxWidth: 1180, margin: '0 auto', padding: '20px 32px 10px' }}>
        <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr' : 'repeat(3, 1fr)', gap: 20 }}>
          {steps.map((s) => (
            <div key={s.n} style={{ padding: '24px 6px' }}>
              <div style={{ fontFamily: t.titleFont, fontSize: 40, color: t.faintText || t.soft, opacity: 0.7 }}>{s.n}</div>
              <div style={{ width: 26, height: 2, background: t.button, margin: '12px 0 14px' }} />
              <div style={{ fontFamily: t.titleFont, fontSize: 24, color: t.accent }}>{s.k}</div>
              <p style={{ fontSize: 14, lineHeight: 1.7, color: t.soft, marginTop: 8 }}>{s.d}</p>
            </div>
          ))}
        </div>
      </div>

      <div style={{ padding: '20px 0 8px' }}><SealDivider t={t} char="訂" /></div>

      {/* inquiry */}
      <div style={{ maxWidth: 1180, margin: '0 auto', padding: '40px 32px 80px' }}>
        <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr' : '0.9fr 1.1fr', gap: narrow ? 32 : 56, alignItems: 'start' }}>
          <div>
            <ImageSlot id="bespoke-detail" w="100%" h={narrow ? 280 : 420} shape="rounded" radius={14} placeholder="Drop a photo of a bespoke set" />
          </div>
          <div style={{ background: t.cardBg, border: `1px solid ${t.line}`, borderRadius: 12, padding: narrow ? '28px 22px' : '40px 36px' }}>
            {sent ? (
              <div style={{ textAlign: 'center', padding: '40px 10px' }}>
                <Seal chars={['謝']} fill={t.sealFill} ink={t.sealInk} size={56} rotate={-6} />
                <h3 style={{ fontFamily: t.titleFont, fontSize: 30, color: t.accent, margin: '20px 0 8px' }}>Thank you</h3>
                <p style={{ fontSize: 14.5, lineHeight: 1.7, color: t.soft, maxWidth: 360, margin: '0 auto' }}>
                  Your enquiry is with the studio. We’ll be in touch within two days to begin your commission.
                </p>
              </div>
            ) : (
              <React.Fragment>
                <h3 style={{ fontFamily: t.titleFont, fontSize: 28, color: t.accent, margin: '0 0 6px' }}>Begin a commission</h3>
                <p style={{ fontSize: 13.5, color: t.soft, margin: '0 0 22px' }}>No obligation — we’ll reply with ideas and a quote.</p>
                <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr' : '1fr 1fr', gap: 16 }}>
                  <Field t={t} label="Your name" placeholder="Jane Doe" value={form.name} onChange={set('name')} />
                  <Field t={t} label="Email" type="email" placeholder="jane@email.com" value={form.email} onChange={set('email')} />
                  <Field t={t} label="A starting set" placeholder="e.g. The Rainbow Kitten" value={form.base} onChange={set('base')} wide />
                  <label style={{ display: 'block', gridColumn: '1 / -1' }}>
                    <div style={{ fontSize: 10.5, letterSpacing: '0.16em', textTransform: 'uppercase', color: t.soft, marginBottom: 7 }}>What do you have in mind?</div>
                    <textarea value={form.note || ''} onChange={(e) => set('note')(e.target.value)} rows={4} placeholder="Colours, characters, a monogram, an occasion…"
                      style={{ width: '100%', padding: '13px 14px', border: `1px solid ${t.line}`, borderRadius: 3, background: t.light ? 'rgba(255,255,255,0.6)' : 'rgba(255,255,255,0.06)', color: t.accent, fontFamily: t.bodyFont, fontSize: 14.5, outline: 'none', resize: 'vertical' }} />
                  </label>
                </div>
                <div style={{ marginTop: 22 }}>
                  <TButton t={t} onClick={submit} style={{ width: '100%', opacity: busy ? 0.6 : 1, pointerEvents: busy ? 'none' : 'auto' }}>{busy ? 'Sending…' : 'Send enquiry'}</TButton>
                  {err && <div style={{ fontSize: 12.5, color: '#a82318', textAlign: 'center', marginTop: 10 }}>{err}</div>}
                </div>
              </React.Fragment>
            )}
          </div>
        </div>
      </div>
    </div>
  );
}

// ---- Checkout ------------------------------------------------------------
function CheckoutView({ t, items, onNav, onPlace }) {
  const narrow = useIsNarrow(900);
  const [form, setForm] = React.useState({});
  const [busy, setBusy] = React.useState(false);
  const [err, setErr] = React.useState('');
  const set = (k) => (v) => setForm((f) => ({ ...f, [k]: v }));
  const lines = items.map(({ id, qty }) => ({ p: MK_PRODUCTS.find((x) => x.id === id), qty })).filter((l) => l.p);
  const subtotal = lines.reduce((s, l) => s + l.p.price * l.qty, 0);
  const shipping = subtotal > 0 ? 60 : 0;
  const total = subtotal + shipping;

  // Card fields (demo-only) are intentionally never sent to the server.
  const submit = async () => {
    if (busy) return;
    setErr(''); setBusy(true);
    try {
      const r = await fetch('/api/order', {
        method: 'POST', headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          email: form.email, fn: form.fn, ln: form.ln, addr: form.addr,
          city: form.city, zip: form.zip, country: form.country,
          items: items.map(({ id, qty }) => ({ id, qty })),
        }),
      });
      const data = await r.json().catch(() => ({}));
      if (!r.ok) throw new Error(data.error || 'Something went wrong — please try again.');
      onPlace({ id: data.id, total: data.total });
    } catch (e) {
      setErr(e.message === 'Failed to fetch' ? 'Network error — please try again.' : e.message);
      setBusy(false);
    }
  };

  if (lines.length === 0) {
    return (
      <div style={{ maxWidth: 700, margin: '0 auto', padding: '90px 32px', textAlign: 'center' }}>
        <Seal chars={['空']} fill={t.sealFill} ink={t.sealInk} size={52} rotate={-6} />
        <h1 style={{ fontFamily: t.titleFont, fontSize: 40, color: t.accent, margin: '20px 0 10px' }}>Your bag is empty</h1>
        <p style={{ fontSize: 15, color: t.soft, marginBottom: 28 }}>Add a set to begin checkout.</p>
        <TButton t={t} onClick={() => onNav('shop')}>Browse the collection</TButton>
      </div>
    );
  }

  return (
    <div style={{ maxWidth: 1100, margin: '0 auto', padding: '44px 32px 90px' }}>
      <a className="v1-link" href="#" onClick={(e) => { e.preventDefault(); onNav('shop'); }} style={{ fontSize: 11, letterSpacing: '0.14em', textTransform: 'uppercase', color: t.soft, textDecoration: 'none' }}>← Continue shopping</a>
      <h1 style={{ fontFamily: t.titleFont, fontSize: 'clamp(34px, 5vw, 48px)', color: t.accent, margin: '14px 0 30px', fontWeight: 600 }}>Checkout</h1>
      <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr' : '1.3fr 0.9fr', gap: narrow ? 36 : 56, alignItems: 'start' }}>
        {/* forms */}
        <div>
          <FormBlock t={t} title="Contact">
            <Field t={t} label="Email" type="email" placeholder="jane@email.com" value={form.email} onChange={set('email')} wide />
          </FormBlock>
          <FormBlock t={t} title="Shipping address">
            <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr' : '1fr 1fr', gap: 16 }}>
              <Field t={t} label="First name" value={form.fn} onChange={set('fn')} />
              <Field t={t} label="Last name" value={form.ln} onChange={set('ln')} />
              <Field t={t} label="Address" value={form.addr} onChange={set('addr')} wide />
              <Field t={t} label="City" value={form.city} onChange={set('city')} />
              <Field t={t} label="Postcode" value={form.zip} onChange={set('zip')} />
              <Field t={t} label="Country" value={form.country} onChange={set('country')} wide />
            </div>
          </FormBlock>
          <FormBlock t={t} title="Payment" note="Demo only — no card is charged.">
            <Field t={t} label="Card number" placeholder="0000 0000 0000 0000" value={form.card} onChange={set('card')} wide />
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16, marginTop: 16 }}>
              <Field t={t} label="Expiry" placeholder="MM / YY" value={form.exp} onChange={set('exp')} />
              <Field t={t} label="CVC" placeholder="123" value={form.cvc} onChange={set('cvc')} />
            </div>
          </FormBlock>
        </div>
        {/* summary */}
        <div style={{ background: t.cardBg, border: `1px solid ${t.line}`, borderRadius: 12, padding: '26px 24px', position: narrow ? 'static' : 'sticky', top: 90 }}>
          <div style={{ fontFamily: t.titleFont, fontSize: 22, color: t.accent, marginBottom: 16 }}>Your order</div>
          {lines.map((l) => (
            <div key={l.p.id} style={{ display: 'flex', gap: 12, padding: '12px 0', borderBottom: `1px solid ${t.faint}` }}>
              <div style={{ width: 44, height: 60, borderRadius: 5, background: t.faint, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
                <Tile {...l.p.tile} w={32} lift={false} />
              </div>
              <div style={{ flex: 1 }}>
                <div style={{ fontFamily: t.titleFont, fontSize: 16, color: t.accent }}>{l.p.name}</div>
                <div style={{ fontSize: 12, color: t.soft }}>Qty {l.qty}</div>
              </div>
              <div style={{ fontSize: 13.5, color: t.accent }}>{money(l.p.price * l.qty)}</div>
            </div>
          ))}
          <Row t={t} k="Subtotal" v={money(subtotal)} />
          <Row t={t} k="Shipping & insured" v={money(shipping)} />
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', paddingTop: 14, marginTop: 6, borderTop: `1px solid ${t.line}` }}>
            <span style={{ fontSize: 13, letterSpacing: '0.1em', textTransform: 'uppercase', color: t.soft }}>Total</span>
            <span style={{ fontFamily: t.titleFont, fontSize: 26, color: t.accent }}>{money(total)}</span>
          </div>
          <div style={{ marginTop: 20 }}>
            <TButton t={t} onClick={submit} style={{ width: '100%', opacity: busy ? 0.6 : 1, pointerEvents: busy ? 'none' : 'auto' }}>{busy ? 'Placing order…' : 'Place order'}</TButton>
            {err && <div style={{ fontSize: 12.5, color: '#a82318', textAlign: 'center', marginTop: 10 }}>{err}</div>}
          </div>
          <div style={{ fontSize: 11.5, color: t.soft, textAlign: 'center', marginTop: 12, lineHeight: 1.5 }}>Hand-finished &amp; shipped within 6–8 weeks · Free returns</div>
        </div>
      </div>
    </div>
  );
}
function FormBlock({ t, title, note, children }) {
  return (
    <div style={{ marginBottom: 28 }}>
      <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 14 }}>
        <div style={{ fontFamily: t.titleFont, fontSize: 20, color: t.accent }}>{title}</div>
        {note && <div style={{ fontSize: 11.5, color: t.soft }}>{note}</div>}
      </div>
      {children}
    </div>
  );
}
function Row({ t, k, v }) {
  return (
    <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 13.5, color: t.soft, paddingTop: 12 }}>
      <span>{k}</span><span style={{ color: t.accent }}>{v}</span>
    </div>
  );
}

// ---- Confirmation --------------------------------------------------------
function ConfirmationView({ t, order, onNav }) {
  const narrow = useIsNarrow(640);
  return (
    <div style={{ maxWidth: 720, margin: '0 auto', padding: '80px 32px 100px', textAlign: 'center' }}>
      <div style={{ position: 'relative', display: 'inline-block', padding: '10px 40px', marginBottom: 72 }}>
        <StoreEnso color={t.ensoColor} />
        <div style={{ position: 'relative', height: 150, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <Tile suit="cat" value={1} w={104} rainbow />
        </div>
      </div>
      <div style={{ fontSize: 11, letterSpacing: '0.32em', textTransform: 'uppercase', color: t.soft, marginBottom: 14 }}>Order confirmed</div>
      <h1 style={{ fontFamily: t.titleFont, fontSize: 'clamp(36px, 5.4vw, 54px)', color: t.accent, margin: 0, fontWeight: 600 }}>Thank you — it’s in good hands.</h1>
      <p style={{ fontSize: 15.5, lineHeight: 1.8, color: t.soft, maxWidth: 480, margin: '18px auto 0' }}>
        Your set will be painted and finished by hand, then sealed and sent. We’ve emailed your receipt and will share progress from the studio along the way.
      </p>
      <div style={{ display: 'inline-flex', gap: narrow ? 26 : 40, margin: '34px 0', padding: '18px 34px', border: `1px solid ${t.line}`, borderRadius: 10, background: t.cardBg }}>
        <div><div style={{ fontSize: 10.5, letterSpacing: '0.16em', textTransform: 'uppercase', color: t.soft }}>Order</div><div style={{ fontFamily: t.titleFont, fontSize: 22, color: t.accent, marginTop: 4, whiteSpace: 'nowrap' }}>{order.id}</div></div>
        <div><div style={{ fontSize: 10.5, letterSpacing: '0.16em', textTransform: 'uppercase', color: t.soft }}>Total</div><div style={{ fontFamily: t.titleFont, fontSize: 22, color: t.accent, marginTop: 4, whiteSpace: 'nowrap' }}>{money(order.total)}</div></div>
        <div><div style={{ fontSize: 10.5, letterSpacing: '0.16em', textTransform: 'uppercase', color: t.soft }}>Ships</div><div style={{ fontFamily: t.titleFont, fontSize: 22, color: t.accent, marginTop: 4, whiteSpace: 'nowrap' }}>6–8 wks</div></div>
      </div>
      <div><TButton t={t} onClick={() => onNav('shop')}>Continue shopping</TButton></div>
    </div>
  );
}

// ---- Footer --------------------------------------------------------------
function Footer({ t, onNav }) {
  const narrow = useIsNarrow(760);
  const [email, setEmail] = React.useState('');
  const [subbed, setSubbed] = React.useState(false);
  const [joinBusy, setJoinBusy] = React.useState(false);
  const join = async () => {
    if (!email || joinBusy) return;
    setJoinBusy(true);
    try {
      const r = await fetch('/api/newsletter', {
        method: 'POST', headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ email }),
      });
      if (r.ok) setSubbed(true);
    } catch (e) {} finally { setJoinBusy(false); }
  };
  const col = (title, links) => (
    <div>
      <div style={{ fontSize: 11, letterSpacing: '0.18em', textTransform: 'uppercase', color: t.accent, marginBottom: 16, opacity: 0.8 }}>{title}</div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
        {links.map(([label, go]) => (
          <a key={label} className="v1-link" href="#" onClick={(e) => { e.preventDefault(); go && onNav(go); }}
            style={{ fontSize: 13.5, color: t.soft, textDecoration: 'none' }}>{label}</a>
        ))}
      </div>
    </div>
  );
  return (
    <div style={{ borderTop: `1px solid ${t.line}`, background: t.light ? 'color-mix(in srgb, ' + t.bgFlat + ' 94%, #000)' : 'rgba(0,0,0,0.18)' }}>
      <div style={{ maxWidth: 1180, margin: '0 auto', padding: '56px 32px 28px' }}>
        <div style={{ display: 'grid', gridTemplateColumns: narrow ? '1fr 1fr' : '1.4fr 1fr 1fr 1.4fr', gap: narrow ? 32 : 40 }}>
          <div style={{ gridColumn: narrow ? '1 / -1' : 'auto' }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 14 }}>
              <Seal chars={['貓']} fill={t.sealFill} ink={t.sealInk} size={30} rotate={-6} />
              <div style={{ fontSize: 13, letterSpacing: '0.3em', fontWeight: 500, color: t.accent }}>MAGICAL KITTEN</div>
            </div>
            <p style={{ fontSize: 13.5, lineHeight: 1.7, color: t.soft, maxWidth: 280 }}>Hand-painted heirloom mahjong, made to order in our atelier since 1924.</p>
          </div>
          {col('The Collection', [['All sets', 'shop'], ['Signature', 'shop'], ['Bespoke', 'bespoke']])}
          {col('The House', [['Our story', 'about'], ['The artist', 'about'], ['Commissions', 'bespoke']])}
          <div>
            <div style={{ fontSize: 11, letterSpacing: '0.18em', textTransform: 'uppercase', color: t.accent, marginBottom: 16, opacity: 0.8 }}>The Parlour Letter</div>
            {subbed ? (
              <div style={{ fontSize: 13.5, color: t.soft }}>Thank you — see you at the table.</div>
            ) : (
              <React.Fragment>
                <p style={{ fontSize: 13.5, lineHeight: 1.6, color: t.soft, marginBottom: 12 }}>New sets and studio notes, now and then.</p>
                <div style={{ display: 'flex', gap: 8 }}>
                  <input value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Email address"
                    style={{ flex: 1, padding: '11px 12px', border: `1px solid ${t.line}`, borderRadius: 3, background: 'transparent', color: t.accent, fontFamily: t.bodyFont, fontSize: 13.5, outline: 'none' }} />
                  <button onClick={join} style={{ cursor: 'pointer', border: 'none', background: t.button, color: t.buttonText, padding: '0 16px', borderRadius: 3, fontSize: 12, letterSpacing: '0.08em', textTransform: 'uppercase', opacity: joinBusy ? 0.6 : 1 }}>{joinBusy ? '…' : 'Join'}</button>
                </div>
              </React.Fragment>
            )}
          </div>
        </div>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: 12, marginTop: 44, paddingTop: 22, borderTop: `1px solid ${t.faint}` }}>
          <div style={{ fontSize: 11.5, letterSpacing: '0.08em', color: t.soft }}>© 2026 MagicalKitten · Hand-painted mahjong</div>
          <div style={{ display: 'flex', gap: 22, fontSize: 11.5, letterSpacing: '0.08em', textTransform: 'uppercase', color: t.soft }}>
            <a className="v1-link" href="#" onClick={(e) => e.preventDefault()} style={{ color: 'inherit', textDecoration: 'none' }}>Shipping</a>
            <a className="v1-link" href="#" onClick={(e) => e.preventDefault()} style={{ color: 'inherit', textDecoration: 'none' }}>Returns</a>
            <a className="v1-link" href="#" onClick={(e) => e.preventDefault()} style={{ color: 'inherit', textDecoration: 'none' }}>Contact</a>
          </div>
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { AboutView, BespokeView, CheckoutView, ConfirmationView, Footer, LifestyleBand });
