// variation-a.jsx — DARK PREMIUM (academia / fitness premium vibe)
// Black canvas, big condensed type, yellow energy accents, red CTA reserves.

// Stable string hash → 0..1 used to vary the placeholder per preparation type.
function paHash(s) {
  let h = 0;
  for (let i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) | 0;
  return Math.abs(h % 1000) / 1000;
}

// Resolve the best image src for an item + selected type, if any.
function paResolvePhoto(item, variant) {
  if (!item) return null;
  if (variant && item.photosByType && item.photosByType[variant]) return item.photosByType[variant];
  if (item.photo) return item.photo;
  return null;
}

// Cache of <img>s that have successfully loaded, so subsequent renders skip
// the placeholder flash entirely.
const PA_LOADED = new Set();
// Cache of srcs that failed to load — fall back to the placeholder forever.
const PA_FAILED = new Set();

// Preload every preparation image for an item the moment the user opens it,
// so toggling between types swaps instantly from the browser cache.
function paPreloadItem(item) {
  if (!item) return;
  const srcs = new Set();
  if (item.photo) srcs.add(item.photo);
  if (item.photosByType) Object.values(item.photosByType).forEach((s) => s && srcs.add(s));
  srcs.forEach((src) => {
    if (PA_LOADED.has(src) || PA_FAILED.has(src)) return;
    const img = new Image();
    img.onload = () => PA_LOADED.add(src);
    img.onerror = () => PA_FAILED.add(src);
    img.src = src;
  });
}

const PaPhoto = ({ item, hue, label, variant, ratio = '1/1', radius = 18 }) => {
  const src = paResolvePhoto(item, variant);
  // Track loaded/failed at module scope so changing variant doesn't reset.
  const [, force] = React.useReducer((x) => x + 1, 0);
  const failed = src ? PA_FAILED.has(src) : true;
  const loaded = src ? PA_LOADED.has(src) : false;

  // Placeholder visuals — used as background until <img> loads (or always if it fails).
  const v = variant ? paHash(variant) : 0;
  const hueShift = (v * 26 - 13);
  const lightShift = (v * 0.08 - 0.04);
  const angle = 90 + Math.round(v * 180);
  const effHue = (hue || 30) + hueShift;
  const displayLabel = variant ? variant : label;

  const showImg = src && !failed;
  // Neutral dark bg while loading (so we don't flash colored placeholder
  // *behind* the image while it decodes the first time).
  const bg = (showImg && !loaded)
    ? '#1a1a1a'
    : `linear-gradient(${angle}deg, oklch(${0.28 + lightShift} 0.05 ${effHue}), oklch(${0.18 + lightShift} 0.03 ${effHue}))`;

  return (
    <div style={{
      aspectRatio: ratio,
      width: '100%',
      borderRadius: radius,
      background: bg,
      position: 'relative',
      overflow: 'hidden',
      display: 'flex', alignItems: 'flex-end', justifyContent: 'flex-start',
      padding: 14,
    }}>
      {/* Real image — always rendered (no key, no unmount on variant change).
          Browser swaps it instantly from cache thanks to paPreloadItem above. */}
      {showImg && (
        <img
          src={src}
          alt={displayLabel}
          onLoad={() => { PA_LOADED.add(src); force(); }}
          onError={() => { PA_FAILED.add(src); force(); }}
          style={{
            position: 'absolute', inset: 0,
            width: '100%', height: '100%',
            objectFit: 'cover', borderRadius: 'inherit',
            display: 'block',
          }}
        />
      )}

      {/* Placeholder decorations + label (only when no image) */}
      {!showImg && (
        <React.Fragment>
          <div style={{
            position: 'absolute', inset: 0,
            background: `repeating-linear-gradient(${45 + Math.round(v * 90)}deg, transparent 0 12px, rgba(255,255,255,0.03) 12px 13px)`,
          }} />
          <div style={{
            position: 'absolute', inset: 0,
            background: `radial-gradient(circle at ${30 + Math.round(v * 50)}% ${20 + Math.round(v * 50)}%, oklch(0.45 0.18 ${effHue} / 0.45), transparent 60%)`,
          }} />
          <span style={{
            position: 'relative', zIndex: 2,
            fontFamily: 'ui-monospace, SFMono-Regular, monospace',
            fontSize: 9, letterSpacing: '0.15em',
            color: 'rgba(255,255,255,0.55)',
            textTransform: 'uppercase',
            whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', maxWidth: '90%',
          }}>· {displayLabel}</span>
        </React.Fragment>
      )}
    </div>
  );
};

function PaHeader({ cart, onCartTap }) {
  return (
    <div style={{
      padding: 'calc(env(safe-area-inset-top, 12px) + 16px) 24px 16px',
      display: 'flex', alignItems: 'center', justifyContent: 'space-between',
    }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
        <img src="assets/logo.png" alt="Anabólica" style={{ width: 36, height: 36, objectFit: 'contain' }} />
        <div>
          <div style={{ fontSize: 11, fontWeight: 500, color: '#F5B225', letterSpacing: '0.14em', textTransform: 'uppercase' }}>Anabólica</div>
          <div style={{ fontSize: 10, color: 'rgba(255,255,255,0.45)', letterSpacing: '0.04em', marginTop: 1 }}>Dieta congelada</div>
        </div>
      </div>
      <button onClick={onCartTap} style={{
        appearance: 'none', cursor: 'pointer',
        width: 36, height: 36, borderRadius: 18,
        background: 'rgba(255,255,255,0.06)', border: '0.5px solid rgba(255,255,255,0.12)',
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        position: 'relative',
      }}>
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
          <circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
          <path d="M1 1h4l2.7 13.4a2 2 0 0 0 2 1.6h9.7a2 2 0 0 0 2-1.6L23 6H6"/>
        </svg>
        {cart.length > 0 && (
          <div style={{
            position: 'absolute', top: -2, right: -2, minWidth: 16, height: 16, padding: '0 4px',
            borderRadius: 10, background: '#CC1617',
            color: '#fff', fontSize: 9, fontWeight: 700,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
          }}>{cart.reduce((s, c) => s + c.qty, 0)}</div>
        )}
      </button>
    </div>
  );
}

function PaHero() {
  return (
    <div style={{ padding: '8px 24px 28px' }}>
      <div style={{
        fontSize: 11, color: '#F5B225', fontWeight: 600,
        letterSpacing: '0.16em', textTransform: 'uppercase', marginBottom: 10,
      }}>
        Florianópolis · São José · Palhoça
      </div>
      <h1 style={{
        margin: 0,
        fontFamily: '"Inter Tight", Inter, system-ui, sans-serif',
        fontWeight: 800,
        fontSize: 44, lineHeight: 0.95,
        letterSpacing: '-0.035em',
        color: '#fff',
      }}>
        Monte sua<br/>
        <span style={{ color: '#F5B225' }}>marmita.</span>
      </h1>
      <p style={{
        margin: '14px 0 0',
        fontSize: 13, lineHeight: 1.5,
        color: 'rgba(255,255,255,0.55)',
        maxWidth: 280,
      }}>
        Sem lactose, sem conservantes, sem óleo de soja. Mínimo 6 marmitas — frete grátis acima de 14.
      </p>
    </div>
  );
}

function PaSizeBar() {
  const sizes = [
    { label: '320g', prot: '120g', carb: '120g', leg: '80g' },
    { label: '500g', prot: '200g', carb: '200g', leg: '100g' },
    { label: '600g', prot: '250g', carb: '250g', leg: '100g' },
  ];
  return (
    <div style={{
      margin: '0 24px 24px',
      padding: '14px 10px',
      background: 'rgba(255,255,255,0.04)',
      border: '0.5px solid rgba(255,255,255,0.08)',
      borderRadius: 14,
      display: 'flex', alignItems: 'stretch', justifyContent: 'space-between',
    }}>
      {sizes.map((s, i) => (
        <React.Fragment key={s.label}>
          {i > 0 && <div style={{ width: 0.5, background: 'rgba(255,255,255,0.1)' }} />}
          <div style={{ flex: 1, textAlign: 'center', padding: '0 4px' }}>
            <div style={{
              fontFamily: '"Inter Tight", Inter, sans-serif',
              fontSize: 18, fontWeight: 700, color: '#fff', letterSpacing: '-0.02em',
            }}>{s.label}</div>
            <div style={{
              fontSize: 10, color: 'rgba(255,255,255,0.5)',
              lineHeight: 1.45, marginTop: 4,
            }}>
              <div>{s.prot} <span style={{ opacity: 0.7 }}>Prot</span></div>
              <div>{s.carb} <span style={{ opacity: 0.7 }}>Carb</span></div>
              <div>{s.leg} <span style={{ opacity: 0.7 }}>Leg</span></div>
            </div>
          </div>
        </React.Fragment>
      ))}
    </div>
  );
}

function PaProteinCard({ item, onTap, accent }) {
  return (
    <button onClick={onTap} style={{
      appearance: 'none', border: 0, padding: 0,
      width: '100%', textAlign: 'left',
      background: 'rgba(255,255,255,0.03)',
      border: '0.5px solid rgba(255,255,255,0.08)',
      borderRadius: 22,
      overflow: 'hidden',
      cursor: 'pointer',
      transition: 'transform 0.18s, border-color 0.18s',
    }}
    onMouseEnter={(e) => { e.currentTarget.style.borderColor = 'rgba(245,178,37,0.4)'; }}
    onMouseLeave={(e) => { e.currentTarget.style.borderColor = 'rgba(255,255,255,0.08)'; }}
    >
      <div style={{ display: 'flex', alignItems: 'stretch', gap: 0 }}>
        <div style={{ width: 96, padding: 10 }}>
          <PaPhoto item={item} hue={item.photoHue} label={item.photoLabel} radius={14} />
        </div>
        <div style={{
          flex: 1, padding: '14px 16px 14px 4px',
          display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
        }}>
          <div>
            <div style={{
              fontFamily: '"Inter Tight", Inter, sans-serif',
              fontSize: 21, fontWeight: 700, color: '#fff', letterSpacing: '-0.02em',
              lineHeight: 1,
            }}>{item.name}</div>
            <div style={{
              fontSize: 11, color: 'rgba(255,255,255,0.5)',
              marginTop: 5, lineHeight: 1.35,
            }}>
              {item.types.slice(0, 3).join(' · ')}{item.types.length > 3 ? '…' : ''}
            </div>
          </div>
          <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', marginTop: 10 }}>
            <div>
              <div style={{ fontSize: 9, color: 'rgba(255,255,255,0.4)', letterSpacing: '0.1em', textTransform: 'uppercase' }}>a partir de</div>
              <div style={{
                fontFamily: '"Inter Tight", Inter, sans-serif',
                fontSize: 16, fontWeight: 700, color: '#F5B225', letterSpacing: '-0.01em',
                marginTop: 1,
              }}>{brl(item.sizes[0].price)}</div>
            </div>
            <div style={{
              width: 30, height: 30, borderRadius: 15,
              background: '#F5B225',
              display: 'flex', alignItems: 'center', justifyContent: 'center',
            }}>
              <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#1A1A1A" strokeWidth="2.5" strokeLinecap="round">
                <path d="M5 12h14M13 6l6 6-6 6"/>
              </svg>
            </div>
          </div>
        </div>
      </div>
    </button>
  );
}

function PaBuilder({ item, onClose, onAdd }) {
  const [type, setType] = React.useState(item.types[0]);
  const [size, setSize] = React.useState(item.sizes[1]); // default 500g
  const [carb, setCarb] = React.useState(CARBS[0]);
  const [vegs, setVegs] = React.useState(['Brócolis', 'Cenoura']);
  const [qty, setQty] = React.useState(1);

  // Preload every preparation photo for this item the moment the builder opens
  // so swapping types feels instant (no flash, no loading state).
  React.useEffect(() => { paPreloadItem(item); }, [item]);

  const toggleVeg = (v) => {
    if (vegs.includes(v)) setVegs(vegs.filter(x => x !== v));
    else if (vegs.length < 3) setVegs([...vegs, v]);
  };

  const total = size.price * qty;

  return (
    <div style={{
      position: 'absolute', inset: 0, zIndex: 50,
      background: '#0a0a0a',
      display: 'flex', flexDirection: 'column',
      animation: 'paSlide .32s cubic-bezier(.2,.7,.1,1)',
      overflow: 'hidden',
    }}>
      <style>{`@keyframes paSlide { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }`}</style>

      {/* Close button — fixed, stays put while content scrolls */}
      <button onClick={onClose} style={{
        position: 'absolute', top: 'calc(env(safe-area-inset-top, 12px) + 14px)', right: 16, zIndex: 5,
        appearance: 'none', border: 0, cursor: 'pointer',
        width: 38, height: 38, borderRadius: 19,
        background: 'rgba(20,20,20,0.72)',
        backdropFilter: 'blur(12px)', WebkitBackdropFilter: 'blur(12px)',
        display: 'flex', alignItems: 'center', justifyContent: 'center',
      }}>
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="2" strokeLinecap="round">
          <path d="M6 6l12 12M18 6L6 18"/>
        </svg>
      </button>

      {/* Scrollable area — hero photo + options scroll together */}
      <div style={{ flex: 1, overflowY: 'auto', WebkitOverflowScrolling: 'touch' }}>
        {/* Hero photo */}
        <div style={{ padding: 'calc(env(safe-area-inset-top, 12px) + 14px) 24px 0' }}>
          <div style={{ width: '100%' }}>
            <PaPhoto item={item} hue={item.photoHue} label={item.photoLabel} variant={type} ratio="16/10" radius={22} />
          </div>
          <div style={{ padding: '20px 0 0' }}>
            <div style={{ fontSize: 10, color: '#F5B225', letterSpacing: '0.14em', textTransform: 'uppercase', fontWeight: 600 }}>
              {item.tagline}
            </div>
            <h2 style={{
              margin: '6px 0 0',
              fontFamily: '"Inter Tight", Inter, sans-serif',
              fontSize: 32, fontWeight: 800, letterSpacing: '-0.03em',
              color: '#fff', lineHeight: 1,
            }}>{item.name}</h2>
          </div>
        </div>

        {/* Options */}
        <div style={{ padding: '24px 24px 12px' }}>
        <PaSection label="Tipo">
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
            {item.types.map(t => (
              <PaChip key={t} active={type === t} onClick={() => setType(t)}>{t}</PaChip>
            ))}
          </div>
        </PaSection>

        <PaSection label="Tamanho">
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 8 }}>
            {item.sizes.map(s => {
              const active = size.label === s.label;
              const info = SIZE_INFO[s.label];
              return (
                <button key={s.label} onClick={() => setSize(s)} style={{
                  appearance: 'none', cursor: 'pointer', textAlign: 'left',
                  padding: '12px 12px 12px',
                  background: active ? '#F5B225' : 'rgba(255,255,255,0.04)',
                  border: '0.5px solid ' + (active ? '#F5B225' : 'rgba(255,255,255,0.1)'),
                  borderRadius: 14, color: active ? '#1A1A1A' : '#fff',
                  transition: 'all .15s',
                }}>
                  <div style={{ fontSize: 16, fontWeight: 700, letterSpacing: '-0.02em', fontFamily: '"Inter Tight", Inter, sans-serif' }}>{s.label}</div>
                  <div style={{
                    fontSize: 10, opacity: active ? 0.75 : 0.55, marginTop: 4,
                    lineHeight: 1.4, letterSpacing: '0.01em',
                  }}>
                    <div>{info.proteina} <span style={{ opacity: 0.7 }}>Prot</span></div>
                    <div>{info.carbo} <span style={{ opacity: 0.7 }}>Carb</span></div>
                    <div>{info.legumes} <span style={{ opacity: 0.7 }}>Leg</span></div>
                  </div>
                  <div style={{ fontSize: 12, fontWeight: 600, marginTop: 8, opacity: active ? 0.85 : 0.65 }}>{brl(s.price)}</div>
                </button>
              );
            })}
          </div>
        </PaSection>

        <PaSection label="Carboidrato">
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
            {CARBS.map(c => (
              <PaChip key={c} active={carb === c} onClick={() => setCarb(c)}>{c}</PaChip>
            ))}
          </div>
        </PaSection>

        <PaSection label="Legumes" hint={`${vegs.length}/3`}>
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
            {VEGGIES.map(v => {
              const active = vegs.includes(v);
              const disabled = !active && vegs.length >= 3;
              return (
                <PaChip key={v} active={active} disabled={disabled} onClick={() => toggleVeg(v)}>
                  {active && <span style={{ marginRight: 6 }}>✓</span>}{v}
                </PaChip>
              );
            })}
          </div>
        </PaSection>

        <PaSection label="Quantidade">
          <div style={{
            display: 'flex', alignItems: 'center', justifyContent: 'space-between',
            padding: '6px 6px 6px 18px',
            background: 'rgba(255,255,255,0.04)',
            border: '0.5px solid rgba(255,255,255,0.1)',
            borderRadius: 14,
          }}>
            <div>
              <div style={{ fontSize: 12, color: 'rgba(255,255,255,0.55)' }}>Total desta marmita</div>
              <div style={{ fontFamily: '"Inter Tight", Inter, sans-serif', fontSize: 22, fontWeight: 700, color: '#fff', letterSpacing: '-0.02em' }}>{brl(total)}</div>
            </div>
            <div style={{ display: 'flex', alignItems: 'center', gap: 0 }}>
              <PaStepBtn onClick={() => setQty(Math.max(1, qty - 1))}>−</PaStepBtn>
              <div style={{
                width: 42, textAlign: 'center',
                fontFamily: '"Inter Tight", Inter, sans-serif', fontSize: 18, fontWeight: 700, color: '#fff',
              }}>{qty}</div>
              <PaStepBtn onClick={() => setQty(qty + 1)}>+</PaStepBtn>
            </div>
          </div>
        </PaSection>
        </div>
      </div>

      {/* CTA */}
      <div style={{
        padding: '14px 24px 28px',
        background: 'linear-gradient(to top, #0a0a0a 60%, rgba(10,10,10,0))',
      }}>
        <button onClick={() => onAdd({ item, type, size, carb, vegs, qty })} style={{
          width: '100%', appearance: 'none', cursor: 'pointer',
          height: 56, borderRadius: 28,
          background: '#F5B225', border: 0,
          color: '#1A1A1A',
          fontFamily: '"Inter Tight", Inter, sans-serif', fontSize: 16, fontWeight: 700, letterSpacing: '-0.01em',
          display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
        }}>
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#1A1A1A" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
            <path d="M12 5v14M5 12h14"/>
          </svg>
          Adicionar ao pedido · {brl(total)}
        </button>
      </div>
    </div>
  );
}

function PaSection({ label, hint, children }) {
  return (
    <div style={{ marginBottom: 22 }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 12 }}>
        <div style={{ fontSize: 11, color: 'rgba(255,255,255,0.55)', letterSpacing: '0.14em', textTransform: 'uppercase', fontWeight: 600 }}>{label}</div>
        {hint && <div style={{ fontSize: 11, color: '#F5B225', fontVariantNumeric: 'tabular-nums' }}>{hint}</div>}
      </div>
      {children}
    </div>
  );
}

function PaChip({ active, disabled, onClick, children }) {
  return (
    <button onClick={onClick} disabled={disabled} style={{
      appearance: 'none', cursor: disabled ? 'not-allowed' : 'pointer',
      padding: '9px 14px',
      background: active ? '#fff' : 'rgba(255,255,255,0.05)',
      border: '0.5px solid ' + (active ? '#fff' : 'rgba(255,255,255,0.1)'),
      borderRadius: 999,
      color: active ? '#1A1A1A' : (disabled ? 'rgba(255,255,255,0.25)' : '#fff'),
      fontSize: 13, fontWeight: active ? 600 : 500,
      letterSpacing: '-0.005em',
      transition: 'all .15s',
    }}>{children}</button>
  );
}

function PaStepBtn({ children, onClick }) {
  return (
    <button onClick={onClick} style={{
      appearance: 'none', cursor: 'pointer',
      width: 38, height: 38, borderRadius: 19,
      background: 'rgba(255,255,255,0.08)', border: 0,
      color: '#fff', fontSize: 18, fontWeight: 500,
      display: 'flex', alignItems: 'center', justifyContent: 'center',
    }}>{children}</button>
  );
}

const MIN_ORDER = 6;
const FREE_SHIPPING = 14;
const SHIPPING_FEE = 19;

function paCartStats(cart) {
  const subtotal = cart.reduce((s, c) => s + c.size.price * c.qty, 0);
  const count = cart.reduce((s, c) => s + c.qty, 0);
  const remainingMin = Math.max(0, MIN_ORDER - count);
  const remainingFree = Math.max(0, FREE_SHIPPING - count);
  const shipping = count >= FREE_SHIPPING ? 0 : SHIPPING_FEE;
  const total = subtotal + (count >= MIN_ORDER ? shipping : 0);
  return { subtotal, count, remainingMin, remainingFree, shipping, total };
}

function PaCheckoutBar({ cart, onTap }) {
  const { subtotal, count, remainingMin, remainingFree } = paCartStats(cart);

  // Progress visualization toward free shipping (across full 0→14)
  const progress = Math.min(1, count / FREE_SHIPPING);
  const minMark = MIN_ORDER / FREE_SHIPPING; // 6/14 ≈ 0.43

  let caption;
  if (count === 0) caption = 'Toque uma marmita para começar';
  else if (remainingMin > 0) caption = `Faltam ${remainingMin} para o mínimo`;
  else if (remainingFree > 0) caption = `Faltam ${remainingFree} para frete grátis`;
  else caption = `${count} marmitas · frete grátis 🎉`;

  return (
    <div style={{
      position: 'absolute', bottom: 0, left: 0, right: 0, zIndex: 30,
      padding: '14px 16px 30px',
      background: 'linear-gradient(to top, #000 65%, rgba(0,0,0,0))',
      pointerEvents: 'none',
    }}>
      <button onClick={onTap} disabled={count === 0} style={{
        pointerEvents: 'auto',
        width: '100%', appearance: 'none', cursor: count > 0 ? 'pointer' : 'default', textAlign: 'left',
        background: '#1A1A1A',
        border: '0.5px solid rgba(255,255,255,0.1)',
        borderRadius: 22,
        padding: '12px 14px 14px 18px',
        boxShadow: '0 20px 50px rgba(0,0,0,0.5)',
        transition: 'transform .15s',
      }}>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
          <div style={{ minWidth: 0, flex: 1 }}>
            <div style={{
              fontSize: 10, color: count >= FREE_SHIPPING ? '#F5B225' : 'rgba(255,255,255,0.55)',
              letterSpacing: '0.1em', textTransform: 'uppercase', fontWeight: 600,
              whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
            }}>{caption}</div>
            <div style={{
              fontFamily: '"Inter Tight", Inter, sans-serif',
              fontSize: 22, fontWeight: 700, color: '#fff', letterSpacing: '-0.02em',
              marginTop: 1,
            }}>{brl(subtotal)}</div>
          </div>
          <div style={{
            display: 'flex', alignItems: 'center', gap: 10,
            background: count >= MIN_ORDER ? '#F5B225' : 'rgba(255,255,255,0.08)',
            color: count >= MIN_ORDER ? '#1A1A1A' : 'rgba(255,255,255,0.55)',
            height: 46, padding: '0 8px 0 16px', borderRadius: 23,
            fontFamily: '"Inter Tight", Inter, sans-serif',
            fontSize: 14, fontWeight: 700,
          }}>
            <span>Ver pedido</span>
            <div style={{
              width: 30, height: 30, borderRadius: 15,
              background: count >= MIN_ORDER ? 'rgba(26,26,26,0.12)' : 'rgba(255,255,255,0.06)',
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              fontVariantNumeric: 'tabular-nums', fontSize: 13,
            }}>{count}</div>
          </div>
        </div>

        {/* Progress track */}
        <div style={{ position: 'relative', height: 4, marginTop: 12, borderRadius: 2, background: 'rgba(255,255,255,0.08)', overflow: 'visible' }}>
          <div style={{
            position: 'absolute', left: 0, top: 0, bottom: 0,
            width: `${progress * 100}%`,
            background: count >= FREE_SHIPPING ? '#F5B225' : 'linear-gradient(to right, #D99A0F, #F5B225)',
            borderRadius: 2,
            transition: 'width .35s cubic-bezier(.2,.7,.1,1)',
          }} />
          {/* Mín marker */}
          <div style={{
            position: 'absolute', left: `${minMark * 100}%`, top: -3, width: 2, height: 10,
            background: count >= MIN_ORDER ? '#F5B225' : 'rgba(255,255,255,0.3)',
            borderRadius: 1, transform: 'translateX(-1px)',
          }} />
          {/* End flag */}
          <div style={{
            position: 'absolute', right: -2, top: -4, width: 12, height: 12, borderRadius: 6,
            background: count >= FREE_SHIPPING ? '#F5B225' : '#1A1A1A',
            border: '0.5px solid ' + (count >= FREE_SHIPPING ? '#F5B225' : 'rgba(255,255,255,0.25)'),
          }} />
        </div>
        <div style={{
          display: 'flex', justifyContent: 'space-between',
          marginTop: 5, fontSize: 9, letterSpacing: '0.08em',
          color: 'rgba(255,255,255,0.45)', fontFamily: 'ui-monospace, monospace',
        }}>
          <span>0</span>
          <span style={{ color: count >= MIN_ORDER ? '#F5B225' : 'rgba(255,255,255,0.45)' }}>mín {MIN_ORDER}</span>
          <span style={{ color: count >= FREE_SHIPPING ? '#F5B225' : 'rgba(255,255,255,0.45)' }}>frete grátis {FREE_SHIPPING}</span>
        </div>
      </button>
    </div>
  );
}

function PaCartModal({ cart, setCart, onClose, onCheckout }) {
  const { subtotal, count, remainingMin, remainingFree, shipping, total } = paCartStats(cart);
  const progress = Math.min(1, count / FREE_SHIPPING);

  const updateQty = (idx, delta) => {
    setCart((prev) => {
      const next = [...prev];
      const newQty = next[idx].qty + delta;
      if (newQty <= 0) next.splice(idx, 1);
      else next[idx] = { ...next[idx], qty: newQty };
      return next;
    });
  };

  return (
    <div style={{
      position: 'absolute', inset: 0, zIndex: 60,
      background: 'rgba(0,0,0,0.55)',
      display: 'flex', flexDirection: 'column',
      animation: 'paCartFade .25s ease',
    }} onClick={onClose}>
      <style>{`
        @keyframes paCartFade { from { background: rgba(0,0,0,0); } to { background: rgba(0,0,0,0.55); } }
        @keyframes paCartDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
      `}</style>
      <div onClick={(e) => e.stopPropagation()} style={{
        background: '#181818',
        borderRadius: '0 0 28px 28px',
        maxHeight: '94%',
        display: 'flex', flexDirection: 'column',
        animation: 'paCartDown .35s cubic-bezier(.2,.7,.1,1)',
        overflow: 'hidden',
        border: '0.5px solid rgba(255,255,255,0.12)',
        borderTop: 'none',
        boxShadow: '0 24px 80px rgba(0,0,0,0.9), 0 0 0 1px rgba(255,255,255,0.06) inset',
      }}>
        {/* Header */}
        <div style={{ padding: '54px 22px 12px', display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 16 }}>
          <div style={{ flex: 1 }}>
            <div style={{
              fontSize: 10, color: '#F5B225',
              letterSpacing: '0.16em', textTransform: 'uppercase', fontWeight: 600,
            }}>Seu pedido</div>
            <h2 style={{
              margin: '4px 0 0',
              fontFamily: '"Inter Tight", Inter, sans-serif',
              fontSize: 30, fontWeight: 800, letterSpacing: '-0.03em',
              color: '#fff', lineHeight: 1,
            }}>{count > 0 ? `${count} ${count === 1 ? 'marmita' : 'marmitas'}` : 'Carrinho'}</h2>
          </div>
          <button onClick={onClose} style={{
            appearance: 'none', border: 0, cursor: 'pointer',
            width: 36, height: 36, borderRadius: 18,
            background: 'rgba(255,255,255,0.08)',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
          }}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="2" strokeLinecap="round">
              <path d="M6 6l12 12M18 6L6 18"/>
            </svg>
          </button>
        </div>

        {/* Free shipping banner */}
        <div style={{ padding: '12px 22px 18px' }}>
          <div style={{
            border: '0.5px solid ' + (count >= FREE_SHIPPING ? 'rgba(245,178,37,0.4)' : 'rgba(255,255,255,0.1)'),
            background: count >= FREE_SHIPPING ? 'rgba(245,178,37,0.08)' : 'rgba(255,255,255,0.03)',
            borderRadius: 16, padding: '14px 16px',
          }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
              <div style={{
                width: 32, height: 32, borderRadius: 16, flex: '0 0 auto',
                background: count >= FREE_SHIPPING ? '#F5B225' : 'rgba(255,255,255,0.08)',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
              }}>
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none"
                  stroke={count >= FREE_SHIPPING ? '#1A1A1A' : '#F5B225'} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
                  <rect x="1" y="6" width="15" height="11" rx="1"/>
                  <path d="M16 9h4l3 4v4h-7z"/>
                  <circle cx="6" cy="19" r="2"/>
                  <circle cx="18" cy="19" r="2"/>
                </svg>
              </div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{
                  fontFamily: '"Inter Tight", Inter, sans-serif',
                  fontSize: 14, fontWeight: 700, color: '#fff', letterSpacing: '-0.01em', lineHeight: 1.15,
                }}>
                  {count >= FREE_SHIPPING
                    ? 'Você ganhou frete grátis!'
                    : count >= MIN_ORDER
                    ? `Faltam ${remainingFree} para frete grátis`
                    : `Adicione ${remainingMin} para fechar o mínimo`}
                </div>
                <div style={{ fontSize: 11, color: 'rgba(255,255,255,0.5)', marginTop: 2 }}>
                  {count >= FREE_SHIPPING ? 'Aplicado automaticamente' : `Frete grátis a partir de ${FREE_SHIPPING} marmitas`}
                </div>
              </div>
            </div>
            <div style={{ position: 'relative', height: 4, marginTop: 12, borderRadius: 2, background: 'rgba(255,255,255,0.08)' }}>
              <div style={{
                position: 'absolute', left: 0, top: 0, bottom: 0,
                width: `${progress * 100}%`,
                background: count >= FREE_SHIPPING ? '#F5B225' : 'linear-gradient(to right, #D99A0F, #F5B225)',
                borderRadius: 2,
                transition: 'width .35s cubic-bezier(.2,.7,.1,1)',
              }} />
              <div style={{
                position: 'absolute', left: `${(MIN_ORDER / FREE_SHIPPING) * 100}%`, top: -3, width: 2, height: 10,
                background: count >= MIN_ORDER ? '#F5B225' : 'rgba(255,255,255,0.3)',
                borderRadius: 1, transform: 'translateX(-1px)',
              }} />
            </div>
          </div>
        </div>

        {/* Item list */}
        <div style={{ flex: 1, overflowY: 'auto', padding: '0 22px 12px' }}>
          {cart.length === 0 ? (
            <div style={{
              padding: '50px 0', textAlign: 'center',
              color: 'rgba(255,255,255,0.4)', fontSize: 13,
            }}>
              Seu carrinho está vazio.<br/>
              <span style={{ fontSize: 11 }}>Volte e escolha uma proteína para começar.</span>
            </div>
          ) : (
            <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
              {cart.map((line, i) => (
                <PaCartLine key={i} line={line}
                  onMinus={() => updateQty(i, -1)}
                  onPlus={() => updateQty(i, +1)} />
              ))}
            </div>
          )}

          {/* Totals */}
          {cart.length > 0 && (
            <div style={{ marginTop: 18, padding: '4px 4px 0' }}>
              <PaTotalRow label="Subtotal" value={brl(subtotal)} />
              <PaTotalRow
                label={`Frete${count < MIN_ORDER ? ' (após mínimo)' : ''}`}
                value={shipping === 0
                  ? <span style={{ color: '#F5B225' }}>Grátis</span>
                  : <>
                    {count >= FREE_SHIPPING ? null : null}
                    {brl(SHIPPING_FEE)}
                  </>}
                strike={count >= FREE_SHIPPING}
              />
              <div style={{ height: 0.5, background: 'rgba(255,255,255,0.1)', margin: '10px 0 8px' }} />
              <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between' }}>
                <span style={{ fontSize: 12, color: 'rgba(255,255,255,0.6)', letterSpacing: '0.06em', textTransform: 'uppercase', fontWeight: 600 }}>Total</span>
                <span style={{
                  fontFamily: '"Inter Tight", Inter, sans-serif',
                  fontSize: 26, fontWeight: 800, color: '#fff', letterSpacing: '-0.025em',
                }}>{count >= MIN_ORDER ? brl(total) : brl(subtotal)}</span>
              </div>
              {count < MIN_ORDER && (
                <div style={{ fontSize: 10.5, color: 'rgba(255,255,255,0.4)', marginTop: 4, textAlign: 'right' }}>
                  Frete será somado quando você atingir o mínimo
                </div>
              )}
            </div>
          )}
        </div>

        {/* CTA */}
        <div style={{
          padding: '12px 22px 26px',
          borderTop: '0.5px solid rgba(255,255,255,0.06)',
          background: '#181818',
        }}>
          <button onClick={() => count >= MIN_ORDER ? onCheckout() : onClose()} style={{
            width: '100%', appearance: 'none', cursor: 'pointer',
            height: 54, borderRadius: 27,
            background: count >= MIN_ORDER ? '#25D366' : 'rgba(255,255,255,0.06)',
            border: 0,
            color: count >= MIN_ORDER ? '#06301a' : 'rgba(255,255,255,0.45)',
            fontFamily: '"Inter Tight", Inter, sans-serif', fontSize: 15, fontWeight: 700,
            letterSpacing: '-0.005em',
            display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
          }}>
            {count >= MIN_ORDER ? (
              <>
                <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
                  <path d="M17.5 14.4c-.3-.1-1.8-.9-2-1s-.5-.1-.7.1c-.2.3-.8 1-1 1.2-.2.2-.4.2-.7.1-.3-.1-1.3-.5-2.4-1.5-.9-.8-1.5-1.8-1.7-2.1-.2-.3 0-.5.1-.6.1-.1.3-.4.4-.5.1-.2.2-.3.3-.5.1-.2 0-.4 0-.5C9.7 9 9.1 7.5 8.9 7c-.2-.5-.4-.4-.6-.4h-.5c-.2 0-.5.1-.7.4-.2.3-.9.9-.9 2.2 0 1.3.9 2.5 1 2.7.1.2 1.8 2.8 4.4 3.9.6.3 1.1.4 1.5.5.6.2 1.2.2 1.6.1.5-.1 1.5-.6 1.7-1.2.2-.6.2-1.1.1-1.2 0-.1-.2-.2-.5-.3zM12 2C6.5 2 2 6.5 2 12c0 1.8.5 3.5 1.3 4.9L2 22l5.3-1.3C8.7 21.5 10.3 22 12 22c5.5 0 10-4.5 10-10S17.5 2 12 2z"/>
                </svg>
                Finalizar no WhatsApp · {brl(total)}
              </>
            ) : (
              <>Continuar escolhendo</>
            )}
          </button>
        </div>
      </div>
    </div>
  );
}

function PaCartLine({ line, onMinus, onPlus }) {
  const { item, type, size, carb, vegs, qty } = line;
  const lineTotal = size.price * qty;
  return (
    <div style={{
      background: 'rgba(255,255,255,0.03)',
      border: '0.5px solid rgba(255,255,255,0.08)',
      borderRadius: 16,
      padding: 10,
      display: 'flex', gap: 12,
    }}>
      <div style={{ width: 64, flex: '0 0 auto' }}>
        <PaPhoto item={item} hue={item.photoHue} label={item.photoLabel} variant={type} radius={10} />
      </div>
      <div style={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', justifyContent: 'space-between' }}>
        <div>
          <div style={{
            fontFamily: '"Inter Tight", Inter, sans-serif',
            fontSize: 15, fontWeight: 700, color: '#fff', letterSpacing: '-0.015em',
            lineHeight: 1.1,
          }}>{item.name}</div>
          <div style={{
            fontSize: 10.5, color: 'rgba(255,255,255,0.5)', marginTop: 4, lineHeight: 1.4,
          }}>
            {size.label} · {type}<br/>
            {carb} · {vegs.length > 0 ? vegs.join(', ') : 'sem legumes'}
          </div>
        </div>
        <div style={{
          fontFamily: '"Inter Tight", Inter, sans-serif',
          fontSize: 13, fontWeight: 700, color: '#F5B225', letterSpacing: '-0.005em',
          marginTop: 8,
        }}>{brl(lineTotal)} <span style={{ color: 'rgba(255,255,255,0.35)', fontWeight: 500, fontSize: 11 }}>· {qty}× {brl(size.price)}</span></div>
      </div>
      <div style={{
        flex: '0 0 auto', display: 'flex', flexDirection: 'column',
        alignItems: 'center', justifyContent: 'center', gap: 4,
      }}>
        <button onClick={onPlus} style={paCartStepStyle}>+</button>
        <div style={{
          fontFamily: '"Inter Tight", Inter, sans-serif',
          fontSize: 13, fontWeight: 700, color: '#fff', width: 22, textAlign: 'center',
          fontVariantNumeric: 'tabular-nums',
        }}>{qty}</div>
        <button onClick={onMinus} style={paCartStepStyle}>−</button>
      </div>
    </div>
  );
}

const paCartStepStyle = {
  appearance: 'none', cursor: 'pointer',
  width: 26, height: 26, borderRadius: 13,
  background: 'rgba(255,255,255,0.08)', border: 0,
  color: '#fff', fontSize: 14, fontWeight: 500,
  display: 'flex', alignItems: 'center', justifyContent: 'center',
};

function PaTotalRow({ label, value, strike }) {
  return (
    <div style={{
      display: 'flex', justifyContent: 'space-between', alignItems: 'baseline',
      padding: '4px 0',
    }}>
      <span style={{ fontSize: 13, color: 'rgba(255,255,255,0.65)' }}>{label}</span>
      <span style={{
        fontFamily: '"Inter Tight", Inter, sans-serif',
        fontSize: 14, fontWeight: 600, color: '#fff',
        textDecoration: strike ? 'line-through' : 'none',
        opacity: strike ? 0.4 : 1,
      }}>{value}</span>
    </div>
  );
}

const WHATSAPP_NUMBER = '5548991185288'; // 48 99118-5288

function paBuildWhatsappMessage(cart) {
  const { subtotal, count, shipping, total } = paCartStats(cart);
  const lines = [];
  lines.push('*Pedido Anabólica* 🐓');
  lines.push('');
  lines.push(`_${count} ${count === 1 ? 'marmita' : 'marmitas'}_`);
  lines.push('');
  cart.forEach((c, i) => {
    const lineTotal = c.size.price * c.qty;
    lines.push(`*${i + 1}. ${c.item.name} — ${c.type}*`);
    lines.push(`   ${c.size.label} · ${c.qty}× ${brl(c.size.price)}`);
    lines.push(`   Carbo: ${c.carb}`);
    lines.push(`   Legumes: ${c.vegs.length > 0 ? c.vegs.join(', ') : 'sem legumes'}`);
    lines.push(`   *${brl(lineTotal)}*`);
    lines.push('');
  });
  lines.push('━━━━━━━━━━━━━');
  lines.push(`Subtotal: ${brl(subtotal)}`);
  lines.push(`Frete: ${shipping === 0 ? 'Grátis 🎉' : brl(shipping)}`);
  lines.push(`*Total: ${brl(total)}*`);
  lines.push('');
  lines.push('_Pode confirmar meu pedido?_ 🙏');
  return lines.join('\n');
}

function paOpenWhatsapp(cart) {
  const msg = paBuildWhatsappMessage(cart);
  const url = `https://wa.me/${WHATSAPP_NUMBER}?text=${encodeURIComponent(msg)}`;
  window.open(url, '_blank', 'noopener');
}

function paSeedCart(mode) {
  if (mode === 'half') {
    return [
      { item: MENU[0], type: 'Moída', size: MENU[0].sizes[1], carb: 'Arroz branco', vegs: ['Brócolis', 'Cenoura'], qty: 3 },
      { item: MENU[1], type: 'Desfiado', size: MENU[1].sizes[1], carb: 'Macarrão penne', vegs: ['Brócolis'], qty: 2 },
    ];
  }
  if (mode === 'full') {
    return [
      { item: MENU[0], type: 'Em tiras', size: MENU[0].sizes[1], carb: 'Arroz branco', vegs: ['Brócolis', 'Cenoura'], qty: 4 },
      { item: MENU[1], type: 'Grelhado c/ cebola e pimentão', size: MENU[1].sizes[2], carb: 'Purê de batata doce', vegs: ['Couve-flor', 'Brócolis'], qty: 4 },
      { item: MENU[3], type: 'Grelhada', size: MENU[3].sizes[0], carb: 'Nhoque de batata doce roxa', vegs: ['Ervilhas'], qty: 3 },
      { item: MENU[4], type: 'Grelhado', size: MENU[4].sizes[1], carb: 'Purê de aipim', vegs: ['Brócolis', 'Beterraba'], qty: 3 },
    ];
  }
  return [];
}

function PaCelebration({ onDone }) {
  React.useEffect(() => {
    const t = setTimeout(onDone, 2600);
    return () => clearTimeout(t);
  }, [onDone]);

  // Pre-compute 14 confetti particles with random offsets/delays
  const particles = React.useMemo(() => (
    Array.from({ length: 14 }, (_, i) => ({
      id: i,
      x: (Math.random() * 2 - 1) * 180,
      y: -120 - Math.random() * 80,
      rot: Math.random() * 360,
      delay: Math.random() * 0.25,
      color: i % 3 === 0 ? '#fff' : '#F5B225',
    }))
  ), []);

  return (
    <div style={{
      position: 'absolute', inset: 0, zIndex: 80,
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      pointerEvents: 'none',
    }}>
      <style>{`
        @keyframes paCelebPop {
          0% { transform: scale(0.6); opacity: 0; }
          15% { transform: scale(1.08); opacity: 1; }
          25% { transform: scale(1); }
          80% { transform: scale(1); opacity: 1; }
          100% { transform: scale(0.96); opacity: 0; }
        }
        @keyframes paConfetti {
          0% { transform: translate(0,0) rotate(0deg); opacity: 0; }
          15% { opacity: 1; }
          100% { transform: translate(var(--tx), var(--ty)) rotate(var(--tr)); opacity: 0; }
        }
        @keyframes paFlash {
          0% { opacity: 0; }
          20% { opacity: 1; }
          100% { opacity: 0; }
        }
      `}</style>

      {/* Subtle background flash */}
      <div style={{
        position: 'absolute', inset: 0,
        background: 'radial-gradient(circle at center, rgba(245,178,37,0.18), transparent 60%)',
        animation: 'paFlash 2.6s ease-out forwards',
      }} />

      {/* Confetti particles */}
      {particles.map(p => (
        <div key={p.id} style={{
          position: 'absolute',
          width: 8, height: 8, borderRadius: 2,
          background: p.color,
          '--tx': `${p.x}px`, '--ty': `${p.y}px`, '--tr': `${p.rot}deg`,
          animation: `paConfetti 2.2s cubic-bezier(.2,.7,.2,1) ${p.delay}s forwards`,
          opacity: 0,
        }} />
      ))}

      {/* Center card */}
      <div style={{
        position: 'relative',
        animation: 'paCelebPop 2.6s cubic-bezier(.2,.7,.2,1) forwards',
        background: '#F5B225',
        color: '#1A1A1A',
        padding: '20px 28px',
        borderRadius: 22,
        textAlign: 'center',
        boxShadow: '0 20px 60px rgba(245,178,37,0.4), 0 0 0 1px rgba(255,255,255,0.1) inset',
        maxWidth: 320,
      }}>
        <div style={{ fontSize: 32, lineHeight: 1, marginBottom: 6 }}>🎉</div>
        <div style={{
          fontFamily: '"Inter Tight", Inter, sans-serif',
          fontSize: 22, fontWeight: 800, letterSpacing: '-0.02em',
          lineHeight: 1.05,
        }}>Parabéns!</div>
        <div style={{
          fontSize: 12, fontWeight: 600, marginTop: 4,
          letterSpacing: '0.04em', textTransform: 'uppercase',
          opacity: 0.75,
        }}>Você ganhou frete grátis</div>
      </div>
    </div>
  );
}

function VariationA({ tweaks }) {
  const [active, setActive] = React.useState(null);
  const [cart, setCart] = React.useState(() => paSeedCart(tweaks.demoCart));
  const [showCart, setShowCart] = React.useState(!!tweaks.openCart);
  const [celebrating, setCelebrating] = React.useState(false);

  // Reseed when the demoCart tweak changes
  const lastSeed = React.useRef(tweaks.demoCart);
  React.useEffect(() => {
    if (lastSeed.current !== tweaks.demoCart) {
      lastSeed.current = tweaks.demoCart;
      setCart(paSeedCart(tweaks.demoCart));
    }
  }, [tweaks.demoCart]);

  // Trigger celebration the moment the user crosses the free-shipping threshold
  // (only on upward transition — won't refire if you bounce around the line).
  const prevCount = React.useRef(cart.reduce((s, c) => s + c.qty, 0));
  React.useEffect(() => {
    const count = cart.reduce((s, c) => s + c.qty, 0);
    if (prevCount.current < FREE_SHIPPING && count >= FREE_SHIPPING) {
      setCelebrating(true);
    }
    prevCount.current = count;
  }, [cart]);

  const onAdd = (line) => {
    setCart([...cart, line]);
    setActive(null);
  };

  // Density spacing
  const density = tweaks.density || 'regular';
  const cardGap = density === 'compact' ? 8 : density === 'comfy' ? 16 : 12;

  return (
    <div style={{
      position: 'relative',
      width: '100%', height: '100%',
      background: '#0a0a0a',
      color: '#fff',
      fontFamily: tweaks.fontFamily === 'serif'
        ? '"Fraunces", "Times New Roman", serif'
        : '"Inter", -apple-system, system-ui, sans-serif',
      overflow: 'hidden',
    }}>
      {/* Scrollable */}
      <div style={{ height: '100%', overflowY: 'auto', paddingBottom: 150 }}>
        <PaHeader cart={cart} onCartTap={() => cart.length > 0 && setShowCart(true)} />
        <PaHero />
        <div style={{ padding: '0 24px 30px', display: 'flex', flexDirection: 'column', gap: cardGap }}>
          <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', marginBottom: 4 }}>
            <h2 style={{
              margin: 0,
              fontFamily: '"Inter Tight", Inter, sans-serif',
              fontSize: 22, fontWeight: 700, letterSpacing: '-0.025em', color: '#fff',
            }}>Proteínas</h2>
            <div style={{ fontSize: 11, color: 'rgba(255,255,255,0.45)', letterSpacing: '0.06em' }}>{MENU.length} opções</div>
          </div>
          {MENU.map(item => (
            <PaProteinCard key={item.id} item={item} onTap={() => setActive(item)} accent={tweaks.primary} />
          ))}
        </div>

        <div style={{ padding: '0 24px 40px', textAlign: 'center' }}>
          <div style={{ height: 0.5, background: 'rgba(255,255,255,0.1)', marginBottom: 24 }} />
          <div style={{
            fontSize: 11, color: '#F5B225', letterSpacing: '0.16em',
            textTransform: 'uppercase', fontWeight: 700, marginBottom: 8,
          }}>Dieta Personalizada</div>
          <div style={{
            fontSize: 13, color: 'rgba(255,255,255,0.55)', lineHeight: 1.5,
            marginBottom: 18,
          }}>Personalize de acordo com seu plano alimentar</div>
          <button
            onClick={() => {
              const msg = 'Olá! Gostaria de personalizar minhas marmitas de acordo com meu plano alimentar. Pode me ajudar?';
              window.open(`https://wa.me/${WHATSAPP_NUMBER}?text=${encodeURIComponent(msg)}`, '_blank', 'noopener');
            }}
            style={{
              appearance: 'none', cursor: 'pointer',
              width: '100%', height: 52, borderRadius: 26,
              background: '#25D366', border: 0,
              color: '#06301a',
              fontFamily: '"Inter Tight", Inter, sans-serif',
              fontSize: 13, fontWeight: 700, letterSpacing: '0.02em',
              display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
            }}>
            <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
              <path d="M17.5 14.4c-.3-.1-1.8-.9-2-1s-.5-.1-.7.1c-.2.3-.8 1-1 1.2-.2.2-.4.2-.7.1-.3-.1-1.3-.5-2.4-1.5-.9-.8-1.5-1.8-1.7-2.1-.2-.3 0-.5.1-.6.1-.1.3-.4.4-.5.1-.2.2-.3.3-.5.1-.2 0-.4 0-.5C9.7 9 9.1 7.5 8.9 7c-.2-.5-.4-.4-.6-.4h-.5c-.2 0-.5.1-.7.4-.2.3-.9.9-.9 2.2 0 1.3.9 2.5 1 2.7.1.2 1.8 2.8 4.4 3.9.6.3 1.1.4 1.5.5.6.2 1.2.2 1.6.1.5-.1 1.5-.6 1.7-1.2.2-.6.2-1.1.1-1.2 0-.1-.2-.2-.5-.3zM12 2C6.5 2 2 6.5 2 12c0 1.8.5 3.5 1.3 4.9L2 22l5.3-1.3C8.7 21.5 10.3 22 12 22c5.5 0 10-4.5 10-10S17.5 2 12 2z"/>
            </svg>
            Clique aqui para personalizar
          </button>
        </div>
      </div>

      <PaCheckoutBar cart={cart} onTap={() => setShowCart(true)} />

      {active && (
        <PaBuilder item={active} onClose={() => setActive(null)} onAdd={onAdd} />
      )}

      {showCart && (
        <PaCartModal
          cart={cart}
          setCart={setCart}
          onClose={() => setShowCart(false)}
          onCheckout={() => paOpenWhatsapp(cart)}
        />
      )}

      {celebrating && <PaCelebration onDone={() => setCelebrating(false)} />}
    </div>
  );
}

window.VariationA = VariationA;
