/* SATIEN v2 — Components */

const { useState, useEffect, useRef } = React;

/* ─── Reveal hooks ─── */

function useReveal() {
  useEffect(() => {
    const els = document.querySelectorAll('[data-reveal], [data-reveal-words]');
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => {if (e.isIntersecting) {e.target.classList.add('in');io.unobserve(e.target);}});
    }, { threshold: 0.12, rootMargin: '0px 0px -8% 0px' });
    els.forEach((el) => io.observe(el));
    return () => io.disconnect();
  }, []);
}

/* ─── Cap SVG (placeholder cap rendered as SVG) ─── */

function CapSVG({ tone = 'cream' }) {
  const fill = tone === 'dark' ? '#1B1812' : '#2A2520';
  const brim = tone === 'dark' ? '#0F0D09' : '#1B1812';
  return (
    <svg viewBox="0 0 480 360" xmlns="http://www.w3.org/2000/svg">
      <defs>
        <radialGradient id="capLight" cx="50%" cy="35%" r="60%">
          <stop offset="0%" stopColor="rgba(255,255,255,0.18)" />
          <stop offset="100%" stopColor="rgba(255,255,255,0)" />
        </radialGradient>
        <linearGradient id="liner" x1="0" x2="0" y1="0" y2="1">
          <stop offset="0%" stopColor="#D9BD7A" />
          <stop offset="100%" stopColor="#A07A2C" />
        </linearGradient>
      </defs>
      {/* shadow */}
      <ellipse cx="240" cy="320" rx="170" ry="14" fill="rgba(20,17,11,0.18)" />
      {/* crown */}
      <path d="M 110 230 C 110 130, 370 130, 370 230 L 370 250 L 110 250 Z" fill={fill} />
      {/* crown highlight */}
      <path d="M 110 230 C 110 130, 370 130, 370 230 L 370 250 L 110 250 Z" fill="url(#capLight)" />
      {/* liner peek */}
      <path d="M 132 244 C 220 252, 260 252, 348 244 L 348 256 C 260 264, 220 264, 132 256 Z" fill="url(#liner)" opacity="0.85" />
      {/* brim */}
      <path d="M 92 246 C 200 268, 280 268, 388 246 L 388 262 C 280 286, 200 286, 92 262 Z" fill={brim} />
      {/* button */}
      <circle cx="240" cy="138" r="6" fill={brim} />
    </svg>);

}

/* ─── Nav ─── */

function Nav() {
  const [scrolled, setScrolled] = useState(false);
  const { cartUrl, cartCount, openCart } = useShopifyProduct();
  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 24);
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  // Swaps the CTA once the product section itself is on screen — no point
  // telling someone already there to go "order", and by then they're the
  // ones who'd actually want the cart.
  const [inProductSection, setInProductSection] = useState(false);
  useEffect(() => {
    const el = document.getElementById('produit');
    if (!el) return;
    const io = new IntersectionObserver(([entry]) => setInProductSection(entry.isIntersecting), { threshold: 0.15 });
    io.observe(el);
    return () => io.disconnect();
  }, []);

  const showCart = inProductSection && cartCount > 0;

  return (
    <nav className={`nav ${scrolled ? 'scrolled' : ''}`}>
      <div className="nav-brand"><Editable id="nav.brand">Soyeux</Editable></div>
      <div className="nav-links">
        <a href="#produit"><Editable id="nav.link1">Le Soyeux</Editable></a>
        <a href="#bienfaits"><Editable id="nav.link2">Bienfaits</Editable></a>
        <a href="#methode"><Editable id="nav.link3">Méthode</Editable></a>
        <a href="#avis"><Editable id="nav.link4">Avis</Editable></a>
        <a href="#faq"><Editable id="nav.link5">FAQ</Editable></a>
      </div>
      <div className="nav-cta">
        {showCart ?
        <a
          href={cartUrl || '#produit'}
          className="btn btn-primary btn-sm"
          onClick={(e) => { e.preventDefault(); openCart(); }}>
          <Editable id="nav.viewCart">Voir le panier</Editable> ({cartCount})
        </a> :
        <a href="#produit" className="btn btn-primary btn-sm"><Editable id="nav.cta">Commander</Editable></a>}
      </div>
    </nav>);

}

/* ─── Cart drawer (desktop) ─── */

function CloseIcon() {
  return (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M18 6L6 18M6 6l12 12"/></svg>
  );
}

const CART_PERKS_GOAL_AMOUNT = 50;
// Real value of the free-shipping + wash-bag perks — shared with the
// product page's "2 Soyeux" pack picker so both stay in sync.
const CART_SHIPPING_VALUE = 3.99;
const CART_WASHBAG_VALUE = 10.99;

function CartDrawer() {
  const {
    cartOpen, closeCart, cartLines, cartSubtotal, cartUrl,
    updateCartLine, removeCartLine, cartLoading, cartError, formatPrice,
    washBagVariantId,
  } = useShopifyProduct();

  // The wash bag always sorts after the real products, regardless of
  // where the cart API happens to place it (observed first, not last).
  const sortedCartLines = washBagVariantId
    ? [...cartLines].sort((a, b) => (a.variantId === washBagVariantId ? 1 : 0) - (b.variantId === washBagVariantId ? 1 : 0))
    : cartLines;

  // Free shipping + wash bag kick in at 50€ spent, however that's reached —
  // the "2 Soyeux" pack, separate adds, or any mix of quantities.
  const subtotalAmount = cartSubtotal ? parseFloat(cartSubtotal.amount) : 0;
  const subtotalCurrency = cartSubtotal ? cartSubtotal.currencyCode : 'EUR';
  const perksUnlocked = subtotalAmount >= CART_PERKS_GOAL_AMOUNT;
  const perksRemainingAmount = Math.max(0, CART_PERKS_GOAL_AMOUNT - subtotalAmount);
  const perksRemainingLabel = formatPrice(perksRemainingAmount, subtotalCurrency);
  const perksProgressPct = Math.min(100, (subtotalAmount / CART_PERKS_GOAL_AMOUNT) * 100);
  const shippingValueLabel = formatPrice(CART_SHIPPING_VALUE, subtotalCurrency);
  const washBagValueLabel = formatPrice(CART_WASHBAG_VALUE, subtotalCurrency);

  useEffect(() => {
    if (!cartOpen) return;
    const onKey = (e) => { if (e.key === 'Escape') closeCart(); };
    document.addEventListener('keydown', onKey);
    const prevOverflow = document.body.style.overflow;
    document.body.style.overflow = 'hidden';
    return () => {
      document.removeEventListener('keydown', onKey);
      document.body.style.overflow = prevOverflow;
    };
  }, [cartOpen]);

  const changeQty = (line, next) => {
    if (next < 1) removeCartLine(line.lineId);
    else updateCartLine(line.lineId, next);
  };

  return (
    <>
      <div className={'cart-overlay' + (cartOpen ? ' is-open' : '')} onClick={closeCart} />
      <aside className={'cart-drawer' + (cartOpen ? ' is-open' : '')} aria-hidden={!cartOpen}>
        <div className="cart-drawer-head">
          <h3><Editable id="cart.title">Ton panier</Editable></h3>
          <button type="button" className="cart-drawer-close" onClick={closeCart} aria-label="Fermer le panier">
            <CloseIcon />
          </button>
        </div>

        {cartLines.length > 0 &&
        <div className={'cart-drawer-progress' + (perksUnlocked ? ' is-complete' : '')}>
          <p className="cart-drawer-progress-headline">
            {perksUnlocked ?
            <><CheckIcon /> <Editable id="cart.progressUnlocked">Tes cadeaux sont débloqués !</Editable></> :

            <>
              <Editable id="cart.progressPre">Encore</Editable> <strong>{perksRemainingLabel}</strong> <Editable id="cart.progressPost">et tu débloques :</Editable>
            </>}
          </p>

          <div className="cart-drawer-progress-track">
            <div className="cart-drawer-progress-fill" style={{ width: perksProgressPct + '%' }} />
          </div>
          <div className="cart-drawer-progress-scale">
            <span>0&nbsp;€</span>
            <span>{CART_PERKS_GOAL_AMOUNT}&nbsp;€</span>
          </div>

          <div className="cart-drawer-progress-perks">
            <div className={'product-pack-perk-row cart-drawer-progress-perk' + (perksUnlocked ? '' : ' is-locked')}>
              <TruckIcon />
              <span className="product-pack-perk-text"><Editable id="cart.perkShipping">Livraison offerte</Editable></span>
              {perksUnlocked ?
              <>
                <span className="product-pack-perk-was">{shippingValueLabel}</span>
                <span className="product-pack-perk-pill"><Editable id="cart.perkOffertLabel">Offert</Editable></span>
              </> :
              <span className="cart-drawer-progress-perk-locked"><Editable id="cart.perkLockedLabel">Dès</Editable> {CART_PERKS_GOAL_AMOUNT}&nbsp;€</span>}
            </div>
            <div className={'product-pack-perk-row cart-drawer-progress-perk' + (perksUnlocked ? '' : ' is-locked')}>
              <GiftIcon />
              <span className="product-pack-perk-text"><Editable id="cart.perkWashbag">Filet de lavage pour soie</Editable></span>
              {perksUnlocked ?
              <>
                <span className="product-pack-perk-was">{washBagValueLabel}</span>
                <span className="product-pack-perk-pill"><Editable id="cart.perkOffertLabel">Offert</Editable></span>
              </> :
              <span className="cart-drawer-progress-perk-locked"><Editable id="cart.perkLockedLabel">Dès</Editable> {CART_PERKS_GOAL_AMOUNT}&nbsp;€</span>}
            </div>
          </div>
        </div>
        }

        {cartError &&
        <p className="cart-drawer-error">{cartError}</p>
        }

        <div className="cart-drawer-body">
          {cartLines.length === 0 ?
          <p className="cart-drawer-empty"><Editable id="cart.empty">Ton panier est vide.</Editable></p> :
          sortedCartLines.map((line) => {
            const isWashBag = line.variantId === washBagVariantId;
            return (
            <div className="cart-line" key={line.lineId}>
              {line.image &&
              <span className="cart-line-img"><img src={line.image} alt="" /></span>
              }
              <div className="cart-line-info">
                <span className="cart-line-title">{line.title}</span>
                {line.color && <span className="cart-line-color">{line.color}</span>}
                <div className="cart-line-qty">
                  <button type="button" onClick={() => changeQty(line, line.quantity - 1)} disabled={cartLoading} aria-label="Diminuer la quantité">−</button>
                  <span>{line.quantity}</span>
                  <button type="button" onClick={() => changeQty(line, line.quantity + 1)} disabled={cartLoading} aria-label="Augmenter la quantité">+</button>
                </div>
              </div>
              <div className="cart-line-right">
                {isWashBag ?
                <span className="cart-line-price">
                  <span className="cart-line-price-was">{washBagValueLabel}</span>
                  <span className="cart-line-price-free">{formatPrice(0, line.price.currencyCode)}</span>
                </span> :
                <span className="cart-line-price">{formatPrice(parseFloat(line.price.amount) * line.quantity, line.price.currencyCode)}</span>}
                <button type="button" className="cart-line-remove" onClick={() => removeCartLine(line.lineId)} disabled={cartLoading} aria-label="Retirer cet article">
                  <CloseIcon />
                </button>
              </div>
            </div>
            );
          })}
        </div>

        {cartLines.length > 0 &&
        <div className="cart-drawer-foot">
          <div className="cart-drawer-subtotal">
            <span><Editable id="cart.subtotalLabel">Sous-total</Editable></span>
            <span>{cartSubtotal ? formatPrice(cartSubtotal.amount, cartSubtotal.currencyCode) : ''}</span>
          </div>
          <a href={cartUrl || '#'} className="btn btn-primary cart-drawer-checkout">
            <Editable id="cart.checkoutLabel">Passer la commande</Editable>
          </a>
        </div>
        }
      </aside>
    </>
  );
}

/* ─── Hero ─── */

function Hero() {
  const { product, selectedVariant, loading, formatPrice } = useShopifyProduct();
  const priceNode = (selectedVariant && selectedVariant.price) || (product && product.priceRange && product.priceRange.minVariantPrice);
  const priceLabel = loading ? '···' : priceNode ? formatPrice(priceNode.amount, priceNode.currencyCode) : '29,99€';
  return (
    <header className="hero">
      <div className="wrap">
        <div className="hero-eyebrow eyebrow eyebrow-rule eyebrow-gold" data-reveal>
          <Editable id="hero.eyebrow">pour tes cheveux, pas contre eux</Editable>
        </div>
        <h1 className="hero-display h-display" data-reveal>
          <span className="word"><Editable id="hero.word1">La soie</Editable></span>
          <span className="word italic-accent"><Editable id="hero.word2">directement</Editable></span>
          <span className="word"><Editable id="hero.word3">dans toutes</Editable></span>
          <span className="word"><Editable id="hero.word4">tes casquettes.</Editable></span>
        </h1>

        <div className="hero-cta" data-reveal data-reveal-delay="2">
          <a href="#produit" className="btn btn-primary"><Editable id="hero.cta1">DÉCOUVRIR LE SOYEUX</Editable> · {priceLabel}</a>
        </div>

        <div className="hero-quiet body-sm" data-reveal data-reveal-delay="3">
          <a href="#methode" className="hero-quiet-link"><Editable id="hero.cta2">Voir la démo</Editable></a>
          <span className="dot" />
          <span><Editable id="hero.quiet1">Livraison offerte dès 50€</Editable></span>
          <span className="dot" />
          <span><Editable id="hero.quiet2">S'adapte à la plupart des casquettes</Editable></span>
          <span className="dot" />
          <span><Editable id="hero.quiet3">Garantie 14 jours</Editable></span>
        </div>
      </div>
    </header>);

}

/* ─── Marquee ─── */

function Marquee() {
  const items = [
  'Nike', 'Adidas', 'New Era', 'Vans', 'Carhartt', 'Von Dutch',
  'Ralph Lauren', '47 Brand', 'Snapback', 'Dad hat', 'Trucker'];

  const seg =
  <span className="seg">
      {items.map((it, i) =>
    <React.Fragment key={i}>
          <span className="marquee-item">{it}</span>
          <span className="marquee-dot" />
        </React.Fragment>
    )}
    </span>;

  return (
    <section className="marquee" aria-label="Compatibilité">
      <div className="marquee-track">
        {seg}{seg}{seg}{seg}{seg}{seg}
      </div>
    </section>);

}

/* ─── Phrase choc ─── */

function Choc() {
  return (
    <section className="choc">
      <div className="wrap">
        <div className="choc-eyebrow eyebrow eyebrow-rule" data-reveal><Editable id="choc.eyebrow">le constat</Editable></div>
        <h2 className="h-display" data-reveal data-reveal-delay="1">
          <Editable id="choc.pre">Tes casquettes</Editable> <span className="italic-accent"><Editable id="choc.strike">abîment</Editable></span> <Editable id="choc.post">tes cheveux.</Editable>
        </h2>
        <p className="choc-lede lede" data-reveal data-reveal-delay="2">
          <Editable id="choc.lede">Coton brut, polyester râpeux, mailles serrées — la doublure intérieure d'une casquette est tout sauf douce pour la fibre capillaire. On l'a remplacée par de la soie mulberry naturelle.</Editable>
        </p>
      </div>
    </section>);

}

/* ─── Produit (présentation) ─── */

// Two photos per silk color: the product shot, then a lifestyle/benefits
// visual. The color switch (product-visual-alt) always jumps to the other
// color's first photo; the dots below step through a color's own photos.
// The benefits visual has its own mobile variant (bigger type, fewer items —
// the desktop one is unreadable once shrunk to phone width).
const PRODUCT_MAIN_BY_COLOR = { noir: 'produit-1', blanc: 'produit-2' };

function colorSwatchHex(colorName) {
  const c = (colorName || '').toLowerCase();
  if (c.includes('noir') || c.includes('black')) return '#161310';
  if (c.includes('blanc') || c.includes('white')) return '#F8F2E4';
  return '#C9A24A';
}

function productImages(colorName) {
  const c = (colorName || '').toLowerCase();
  const main = (c.includes('noir') || c.includes('black')) ? PRODUCT_MAIN_BY_COLOR.noir
    : (c.includes('blanc') || c.includes('white')) ? PRODUCT_MAIN_BY_COLOR.blanc
    : PRODUCT_MAIN_BY_COLOR.noir;
  return [main, main + '-2'];
}

// Descriptive alt text for a product image id (e.g. "produit-1",
// "produit-2-2") — for screen readers and image search, since <image-slot>
// otherwise ships alt="" on every photo.
function productImageAlt(id) {
  // Exact match on the base id is the product shot; anything else is that
  // color's "-2" suffixed companion slide (the shared "why silk" graphic).
  // Checking endsWith('-2') instead would misfire on "produit-2" itself.
  const isMainPhoto = id === PRODUCT_MAIN_BY_COLOR.noir || id === PRODUCT_MAIN_BY_COLOR.blanc;
  const color = id.startsWith(PRODUCT_MAIN_BY_COLOR.blanc) ? 'blanc' : 'noir';
  return isMainPhoto
    ? `Le Soyeux, doublure amovible en soie mulberry, coloris ${color}`
    : 'Pourquoi la soie change tout — bienfaits du Soyeux pour tes cheveux';
}

function CheckIcon() {
  return (
    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M20 6L9 17l-5-5"/></svg>
  );
}

function TruckIcon() {
  return (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <rect x="2" y="6" width="12" height="11"/>
      <path d="M14 10h4l4 3.5V17h-8z"/>
      <circle cx="6.5" cy="19" r="1.6"/>
      <circle cx="17.5" cy="19" r="1.6"/>
    </svg>
  );
}

function GiftIcon() {
  return (
    <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <rect x="3" y="8" width="18" height="13" rx="1.5"/>
      <path d="M3 12h18"/>
      <path d="M12 8v13"/>
      <path d="M12 8C9 8 7.5 6.8 7.5 5.2 7.5 3.9 8.5 3 9.7 3 11.3 3 12 5 12 8z"/>
      <path d="M12 8c3 0 4.5-1.2 4.5-2.8C16.5 3.9 15.5 3 14.3 3 12.7 3 12 5 12 8z"/>
    </svg>
  );
}

function SecurePaymentIcon() {
  return (
    <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <rect x="2" y="5" width="20" height="14" rx="2"/>
      <path d="M2 10h20"/>
      <path d="M16.5 15.5l1.5 1.5 3-3"/>
    </svg>
  );
}
function MailIcon() {
  return (
    <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <rect x="2" y="4" width="20" height="16" rx="2"/>
      <path d="M2 6l10 7 10-7"/>
    </svg>
  );
}

/* Real France outline (Wikimedia Commons, public domain, no departments) —
   traced path, not a redrawn approximation. */
function FranceMapIcon() {
  return (
    <svg width="39" height="40" viewBox="0 0 507 520" fill="currentColor" aria-hidden="true">
      <path d="M 204.3125,99.211183 L 198.65625,98.054933 L 194.75,95.117433 L 195.71875,89.648683 L 200.40625,82.617433 L 208.40625,78.304933 L 218.1875,74.804933 L 233.03125,71.086183 L 241.40625,64.648683 L 249.03125,55.273683 L 254.3125,58.398683 L 254.3125,56.429933 L 250,52.523683 L 250.59375,45.304933 L 250.59375,18.929933 L 259.1875,12.304933 L 270.53125,10.148683 L 280.28125,8.586183 L 286.53125,5.648683 L 289.0625,10.742433 L 289.84375,13.679933 L 288.5,15.804933 L 288.5,19.148683 L 289.65625,21.273683 L 292.40625,21.273683 L 294.34375,23.429933 L 294.9375,25.586183 L 296.5,27.523683 L 298.84375,27.523683 L 301.1875,24.617433 L 306.0625,23.054933 L 308.59375,22.836183 L 309,25.179933 L 310.15625,25.179933 L 310.375,26.367433 L 312.125,27.148683 L 312.3125,34.961183 L 313.09375,37.492433 L 315.84375,37.898683 L 317.1875,39.242433 L 321.09375,37.492433 L 322.46875,39.054933 L 324.8125,38.679933 L 327.9375,42.367433 L 327.75,49.211183 L 329.125,49.211183 L 330.28125,47.273683 L 341.21875,46.679933 L 347.46875,51.554933 L 348.25,53.117433 L 345.3125,55.273683 L 345.3125,57.992433 L 344.34375,58.992433 L 348.0625,59.961183 L 348.65625,63.679933 L 344.75,66.023683 L 344.9375,67.961183 L 352.9375,67.961183 L 355.6875,70.117433 L 358.03125,69.148683 L 362.3125,67.773683 L 364.65625,66.211183 L 364.65625,63.867433 L 364.65625,62.117433 L 366.40625,60.336183 L 368.375,57.429933 L 371.3125,57.429933 L 372.09375,57.992433 L 372.09375,61.523683 L 369.9375,63.461183 L 371.3125,64.648683 L 370.53125,66.586183 L 369.9375,68.742433 L 373.0625,70.711183 L 373.0625,72.461183 L 372.28125,73.242433 L 372.65625,77.742433 L 378.90625,78.523683 L 380.6875,79.679933 L 381.65625,82.211183 L 387.125,82.804933 L 388.6875,83.992433 L 389.46875,87.898683 L 392,88.273683 L 393.5625,89.836183 L 394.34375,93.554933 L 395.53125,93.554933 L 396.6875,92.367433 L 400,92.179933 L 402.34375,90.023683 L 406.84375,90.023683 L 410.375,93.929933 L 413.5,93.929933 L 414.65625,95.117433 L 417.96875,95.117433 L 418.5625,94.148683 L 420.90625,92.179933 L 423.84375,91.992433 L 426.5625,94.336183 L 428.53125,94.336183 L 429.125,93.929933 L 431.0625,93.929933 L 435.15625,95.898683 L 437.125,97.836183 L 437.3125,102.52368 L 440.0625,103.71118 L 440.0625,106.42993 L 441.21875,106.83618 L 443.1875,110.55493 L 446.5,110.14868 L 446.6875,107.80493 L 449.4375,106.64868 C 449.65565,106.77743 451.42823,107.80494 452.34375,107.80493 C 452.36378,107.80493 452.41248,107.80363 452.4375,107.80493 C 452.44093,107.80479 452.46591,107.80494 452.46875,107.80493 C 452.48002,107.8107 452.52058,107.83076 452.53125,107.83618 C 452.55512,107.84316 452.59646,107.85577 452.625,107.86743 C 452.66355,107.8842 452.71729,107.91257 452.75,107.92993 C 453.59437,108.40056 454.55551,110.09675 454.6875,110.33618 L 456.65625,111.71118 L 463.28125,111.52368 L 466.03125,108.99243 L 470.71875,108.58618 L 472.09375,110.74243 L 476,113.08618 L 477.34375,115.02368 L 477.75,114.89868 L 481.46875,113.86743 L 483.59375,113.86743 L 485.15625,115.61743 L 488.09375,113.86743 L 492.40625,116.02368 L 497.28125,116.58618 L 500,118.74243 L 497.28125,119.33618 L 495.53125,124.02368 L 495.90625,127.33618 L 494.15625,129.08618 L 492.59375,129.08618 L 490.625,131.64868 L 490.625,133.99243 L 485.5625,137.67993 L 484.96875,144.33618 L 482.625,151.96118 L 483.21875,157.61743 L 478.125,167.58618 L 478.34375,173.83618 L 480.28125,176.55493 L 478.53125,179.08618 L 478.53125,182.99243 L 477.5625,185.33618 L 477.5625,190.24243 L 476,192.36743 L 477.34375,195.49243 L 479.90625,198.42993 L 477.9375,200.96118 L 477.75,205.27368 L 474.03125,208.21118 L 466.8125,208.39868 L 465.4375,207.21118 L 465.84375,205.08618 L 460.9375,205.86743 L 455.875,211.71118 L 456.0625,212.49243 L 460.75,211.52368 L 462.125,212.89868 L 459.59375,216.02368 L 457.4375,216.99243 L 458.40625,219.33618 L 452.15625,226.55493 L 449.4375,227.92993 L 449.21875,231.64868 L 446.5,234.17993 L 443.5625,235.55493 L 439.28125,237.67993 L 439.65625,247.05493 L 427.5625,258.39868 L 427.34375,259.77368 L 429.3125,260.55493 L 426.375,264.05493 L 426,268.14868 L 429.6875,270.11743 L 430.09375,271.27368 L 427.15625,274.99243 L 428.34375,275.77368 L 428.125,277.74243 L 424.625,278.11743 L 422.28125,279.49243 L 422.28125,283.21118 L 428.71875,283.21118 L 431.25,280.86743 L 435.15625,278.30493 L 433.03125,276.55493 L 432.8125,274.80493 L 434.78125,270.49243 L 436.9375,270.30493 L 438.09375,272.05493 L 442.40625,268.55493 L 446.875,267.77368 L 453.53125,267.77368 L 453.71875,270.30493 L 457.25,274.02368 L 457.25,276.74243 L 455.09375,279.08618 L 455.28125,280.64868 L 459,282.42993 L 459,285.33618 L 459,287.11743 L 460.375,286.33618 L 464.65625,290.80493 L 465.0625,295.11743 L 464.28125,297.05493 L 457.625,299.80493 L 457.53125,303.21118 L 457.4375,306.42993 L 460.375,309.77368 C 460.375,309.77368 463.28125,309.56275 464.0625,309.36743 C 464.06534,309.36744 464.09022,309.36735 464.09375,309.36743 C 464.0967,309.36736 464.12209,309.36728 464.125,309.36743 C 464.12784,309.36739 464.15269,309.36755 464.15625,309.36743 C 464.15608,309.3693 464.1562,309.3917 464.15625,309.39868 C 464.1591,309.39861 464.18393,309.3989 464.1875,309.39868 C 464.19264,309.40331 464.21374,309.42448 464.21875,309.42993 C 464.23155,309.44637 464.26544,309.49673 464.28125,309.52368 C 464.78377,310.59893 464.46875,316.58618 464.46875,316.58618 L 469.75,319.71118 L 470.53125,322.46118 L 473.0625,323.42993 L 470.3125,328.11743 L 471.3125,329.67993 L 470.71875,332.99243 L 465.625,334.96118 L 464.65625,336.11743 L 462.125,337.49243 L 461.9375,339.83618 L 459.78125,339.83618 L 457.625,338.46118 L 451.78125,340.80493 L 451.84375,340.92993 L 453.125,343.74243 L 454.125,345.71118 L 457.03125,346.67993 L 457.8125,352.52368 L 462.90625,355.08618 L 465.625,354.67993 L 467.78125,355.46118 L 468.375,361.11743 L 471.09375,362.49243 L 471.09375,364.24243 L 468.96875,364.05493 L 466.625,366.58618 L 467.1875,369.33618 L 463.6875,373.05493 L 462.90625,374.80493 L 463.875,377.33618 L 465.84375,377.92993 L 467.40625,379.30493 L 464.65625,379.67993 L 464.65625,383.58618 L 468.75,386.11743 L 468.75,389.64868 L 471.6875,389.64868 L 476.78125,391.02368 L 481.84375,395.11743 L 484.78125,395.11743 L 493.96875,391.80493 L 496.875,391.58618 L 497.65625,394.14868 L 498.65625,395.89868 L 499.21875,398.83618 L 498.0625,403.11743 L 493.75,404.49243 L 494.34375,407.42993 L 491.40625,409.96118 L 493.375,414.46118 L 489.84375,416.58618 L 489.65625,418.74243 L 486.15625,418.74243 L 482.25,422.27368 L 477.75,422.64868 L 477.5625,428.71118 L 475.59375,428.30493 L 474.21875,430.08618 L 470.3125,429.30493 L 470.125,433.77368 L 466.8125,437.49243 L 461.15625,438.27368 L 460.75,441.39868 L 459.1875,443.55493 L 456.0625,445.49243 L 460.15625,445.30493 L 460.15625,450.39868 L 457.03125,451.74243 L 454.3125,450.96118 L 453.125,452.74243 L 449.03125,452.74243 L 447.46875,454.08618 L 447.09375,456.64868 L 445.71875,457.61743 L 444.75,456.42993 L 443.5625,456.05493 L 440.625,455.08618 L 438.09375,456.83618 L 438.5,459.36743 L 439.65625,460.55493 L 434.96875,460.33618 L 436.9375,459.36743 L 437.125,457.80493 L 431.0625,457.21118 L 427.5625,459.36743 L 425.59375,460.74243 L 423.4375,460.33618 L 422.46875,456.42993 L 418.96875,454.86743 L 417.96875,453.52368 L 413.28125,451.96118 L 403.71875,451.96118 L 404.90625,450.58618 L 405.6875,448.61743 L 401.375,448.42993 L 404.5,445.71118 L 403.90625,443.92993 L 401,445.11743 L 389.84375,444.92993 L 388.09375,441.21118 L 384.375,439.64868 L 382.03125,441.58618 L 385.5625,444.92993 L 378.90625,446.08618 L 370.53125,444.33618 L 372.46875,441.02368 L 375.40625,441.02368 L 373.84375,439.46118 L 365.625,438.86743 L 359.4375,438.58618 L 357.03125,438.46118 L 352.5625,438.67993 L 352.5625,434.77368 L 349.5625,434.55493 L 346.875,434.36743 L 340.25,439.05493 L 329.6875,447.46118 L 327.9375,449.61743 L 322.46875,449.80493 L 321.6875,451.55493 L 314.65625,453.71118 L 314.53125,454.77368 L 314.28125,456.83618 L 312.3125,458.77368 L 309.375,461.11743 L 306.0625,457.99243 L 304.5,460.55493 L 306.46875,463.46118 L 308.8125,463.27368 L 308.59375,469.71118 L 308.75,475.30493 L 309.1875,492.36743 L 311.9375,493.55493 L 313.5,495.71118 L 313.5,498.83618 L 310.375,498.61743 L 307.8125,495.89868 L 303.71875,495.89868 L 300.78125,496.86743 L 298.84375,499.39868 L 292.96875,500.77368 L 292.78125,503.52368 L 291.625,504.08618 L 290.25,503.11743 L 288.875,503.11743 L 287.3125,505.08618 L 281.84375,500.39868 L 275.40625,498.24243 L 271.3125,499.02368 L 267.96875,503.11743 L 265.625,503.52368 L 262.5,500.77368 L 262.3125,497.27368 L 256.46875,495.71118 L 253.53125,492.96118 L 253.1875,490.89868 L 252.5625,487.30493 L 243.96875,486.11743 L 241.03125,487.30493 L 237.71875,482.02368 L 229.3125,482.42993 L 226,478.11743 L 223.4375,478.11743 L 217.40625,476.96118 L 216.34375,476.36743 L 212.3125,474.02368 L 209.59375,473.61743 L 209.1875,483.21118 L 201.25,482.67993 L 197.46875,482.42993 L 195.71875,481.64868 L 194.34375,483.99243 L 190.625,482.99243 L 187.90625,479.86743 L 181.46875,482.61743 L 178.90625,482.61743 L 175.78125,480.08618 L 175.40625,477.74243 L 171.5,474.80493 L 168.1875,472.83618 L 167.6875,473.11743 L 164.28125,474.99243 L 162.5,475.96118 L 161.53125,474.99243 L 159.59375,475.39868 L 157.4375,476.55493 L 155.46875,474.21118 L 150.40625,470.30493 L 150,466.21118 L 142.59375,466.21118 L 138.09375,463.46118 L 133.40625,462.67993 L 131.84375,460.55493 L 128.34375,460.55493 L 126.96875,458.58618 L 127.15625,456.05493 L 125.40625,457.99243 L 124.8125,460.92993 L 121.6875,459.96118 L 119.9375,457.99243 L 120.125,456.24243 L 122.875,454.86743 L 122.875,451.17993 L 124.21875,449.99243 L 123.65625,447.64868 L 121.3125,447.05493 L 117.59375,445.49243 L 116.8125,447.27368 L 114.0625,447.05493 L 113.875,444.52368 L 110.375,444.33618 L 108.03125,442.17993 L 108.03125,440.02368 L 110.5625,439.64868 L 114.0625,438.27368 L 118.5625,432.80493 L 119.375,431.36743 L 122.28125,426.36743 L 123.4375,421.67993 L 124.8125,415.02368 L 129.3125,397.83618 L 132.79688,379.17993 L 132.8125,374.61743 L 134.96875,371.67993 L 135.375,368.74243 L 137.3125,367.96118 L 138.09375,369.14868 L 142.96875,368.92993 L 141.8125,367.36743 L 141.40625,366.21118 L 137.5,362.67993 L 134.78125,366.21118 L 133.40625,370.71118 L 133.59375,367.36743 L 135.375,354.49243 L 137.90625,337.89868 L 138.875,321.49243 L 142,316.80493 L 143.96875,316.99243 L 143.75,321.08618 L 153.71875,330.08618 L 156.46875,340.80493 L 157.4375,345.49243 L 158.40625,343.92993 L 158.03125,338.27368 L 156.65625,332.61743 L 156.375,331.36743 L 154.90625,324.61743 L 148.65625,318.36743 L 146.5,317.96118 L 146.3125,316.02368 L 143.5625,314.46118 L 139.46875,311.11743 L 137.125,311.33618 L 136.71875,307.02368 L 135.9375,302.74243 L 135.5625,299.02368 L 131.0625,295.71118 L 131.46875,288.86743 L 134.1875,292.17993 L 137.5,292.58618 L 137.90625,297.27368 L 138.875,298.05493 L 139.46875,299.39868 L 137.71875,301.74243 L 138.09375,303.30493 L 140.84375,303.30493 L 140.25,302.33618 L 140.0625,299.61743 L 142.40625,299.80493 L 143.375,295.49243 L 141.625,292.96118 L 142.40625,291.80493 L 144.75,292.17993 L 144.9375,290.02368 L 143.1875,289.24243 L 142.1875,286.52368 L 139.46875,285.92993 L 138.6875,284.17993 L 134.59375,284.36743 L 132.4375,282.61743 L 129.6875,280.86743 L 126.96875,280.86743 L 124.8125,277.74243 L 128.125,276.55493 L 130.46875,278.11743 L 130.875,280.08618 L 134.78125,280.46118 L 136.34375,282.21118 L 139.28125,281.83618 L 139.65625,279.86743 L 142.78125,277.33618 L 141.34375,276.02368 L 140.25,274.99243 L 140.0625,277.74243 L 135.75,275.58618 L 133.8125,272.64868 L 129.5,272.64868 L 127.75,268.74243 L 123.25,268.74243 L 119.34375,264.83618 L 115.4375,262.89868 L 111.71875,251.74243 L 109.96875,251.74243 L 110.15625,249.99243 L 104.125,244.14868 L 104.3125,239.46118 L 110.25,231.80493 L 105.28125,226.96118 L 101,227.74243 L 100.59375,224.80493 L 102.9375,224.80493 L 105.09375,222.64868 L 104.3125,220.89868 L 104.125,218.92993 L 107.625,217.17993 L 104.3125,217.17993 L 101.78125,219.92993 L 98.25,219.92993 L 96.09375,217.17993 L 95.71875,218.74243 L 92,217.96118 L 89.84375,216.80493 L 91.8125,214.05493 L 91.03125,212.49243 L 90.25,211.71118 L 93.96875,208.39868 L 92.78125,207.57056 L 92.40625,205.64868 L 93.75,204.49243 L 91.03125,203.89868 L 80.46875,204.86743 L 78.71875,202.14868 L 76.375,201.36743 L 77.9375,199.39868 L 80.875,200.77368 L 83.40625,201.55493 L 84.375,199.99243 L 82.4375,197.64868 L 79.90625,197.05493 L 80.46875,198.42993 L 77.75,198.83618 L 75.59375,195.89868 L 76.78125,198.61743 L 75.59375,200.58618 L 73.0625,198.42993 L 72.46875,197.05493 L 71.6875,199.39868 L 69.34375,198.83618 L 69.34375,202.33618 L 70.53125,203.89868 L 69.34375,205.27368 L 67,203.52368 L 67.40625,200.96118 L 67.78125,198.42993 L 66.625,196.27368 L 63.09375,192.77368 L 60.375,191.58618 L 60.9375,189.46118 L 59.78125,191.21118 L 56.65625,190.42993 L 54.390625,186.82056 L 51.78125,186.71118 L 48.4375,186.11743 L 47.09375,184.17993 L 46.875,185.33618 L 41.40625,184.96118 L 38.875,180.86743 L 38.09375,177.52368 L 38.09375,180.86743 L 36.15625,181.24243 L 33.03125,179.49243 L 31.25,179.67993 L 29.5,178.89868 L 31.25,181.24243 L 30.28125,182.99243 L 25.78125,183.21118 L 21.6875,182.42993 L 23.0625,179.67993 L 22.09375,174.61743 L 17.96875,169.92993 L 15.4375,170.11743 L 13.6875,168.55493 L 11.53125,168.74243 L 9.59375,167.58618 L 10.9375,165.80493 L 17.59375,165.42993 L 21.5,164.83618 L 23.84375,164.83618 L 26.375,165.02368 L 27.5625,162.89868 L 26.78125,159.77368 L 24.8125,159.36743 L 20.71875,157.02368 L 18.5625,160.33618 L 17.59375,161.11743 L 17.78125,155.86743 L 14.28125,154.67993 L 17,151.55493 L 21.5,153.71118 L 25.21875,154.67993 L 29.90625,154.86743 L 30.09375,153.71118 L 25.78125,153.52368 L 26.5625,150.77368 L 22.65625,152.52368 L 22.28125,150.58618 L 26.5625,146.49243 L 21.6875,149.99243 L 14.28125,150.96118 L 13.6875,150.17993 L 12.5,151.36743 L 9.375,150.96118 L 10.15625,146.67993 L 9.1875,144.92993 L 12.3125,142.36743 L 9.96875,140.61743 L 12.71875,137.30493 L 17.96875,137.11743 L 18.375,134.77368 L 19.9375,133.99243 L 21.3125,134.96118 L 24.4375,134.77368 L 24.4375,133.39868 L 28.90625,132.80493 L 29.3125,134.96118 L 31.84375,134.36743 L 32.625,132.42993 L 36.9375,132.02368 L 39.28125,132.99243 L 41.40625,130.64868 L 41.8125,135.14868 L 44.15625,134.77368 L 44.53125,136.52368 L 46.09375,136.52368 L 46.09375,132.61743 L 51.5625,132.42993 L 54.84375,134.33618 L 57.625,130.64868 L 56.0625,128.52368 L 60.15625,125.77368 L 63.28125,128.11743 L 64.28125,126.74243 L 68.75,126.17993 L 70.53125,124.80493 L 71.6875,127.52368 L 72.28125,125.58618 L 76.1875,125.58618 L 76,127.74243 L 78.125,127.92993 L 77.9375,131.05493 L 80.6875,131.64868 L 80.6875,134.96118 L 84.375,137.67993 L 84,141.21118 L 88.09375,143.14868 L 88.09375,146.67993 L 89.65625,146.67993 L 89.65625,144.71118 L 96.875,140.80493 L 98.0625,138.46118 L 101.5625,139.05493 L 103.90625,137.30493 L 103.90625,141.21118 L 105.28125,139.64868 L 107.25,140.24243 L 107.4375,142.96118 L 109.78125,142.77368 L 110.15625,140.61743 L 113.875,141.02368 L 115.125,139.61743 L 117,137.49243 L 121.6875,137.67993 L 119.34375,140.80493 L 122.875,142.96118 L 132.46875,142.96118 L 136.15625,142.96118 L 138.28125,141.99243 L 137.90625,140.02368 L 133.59375,139.05493 L 130.875,132.02368 L 133.40625,126.96118 L 133.40625,121.49243 L 131.0625,116.80493 L 131.0625,109.77368 L 130.09375,108.39868 L 129.125,103.89868 L 124.625,98.836183 L 123.25,95.711183 L 123.65625,91.992433 L 123.0625,91.586183 L 122.09375,90.617433 L 123.65625,88.679933 L 123.65625,84.367433 L 119.53125,81.054933 L 120.3125,79.086183 L 127.5625,81.242433 L 132.625,84.554933 L 137.125,81.429933 L 145.53125,81.836183 L 147.46875,87.117433 L 145.3125,87.117433 L 143.75,91.023683 L 148.84375,97.054933 L 149.03125,101.74243 L 150.875,101.27368 L 156.65625,99.804933 L 160.375,101.74243 L 176.375,104.08618 L 183.03125,107.80493 L 191.40625,104.49243 L 198.84375,100.17993 L 203.40625,99.367433"/>
    </svg>
  );
}
function FeatherIcon() {
  return (
    <svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <path d="M20.5 3.5c-4 0-13 2-15 9-1 3.5 1 6 4 5 7-2 9-11 9-14z"/>
      <path d="M14 9.5L4 20.5"/>
      <path d="M14.5 14.5H10"/>
    </svg>
  );
}

// Purchase-critical questions pulled from the main FAQ (defined in
// components-2.jsx, available by the time Product() renders) and answered
// again right next to the CTA, mirroring their FAQS[i] indices so edits
// made in the main FAQ section stay in sync here.
const MINI_FAQ_INDICES = [0, 1, 2, 4];

function Product() {
  const {
    product, loading, error,
    variants, selectedVariant, selectedVariantId, setSelectedVariantId,
    variantColor, addToCart, cartUrl, cartCount, cartLoading, cartError, openCart, formatPrice,
  } = useShopifyProduct();
  const [justAdded, setJustAdded] = useState(false);
  const { isMobile } = useContent();

  const currentColor = selectedVariant ? variantColor(selectedVariant) : null;
  const otherVariant = variants.find((v) => v.id !== selectedVariantId);
  const otherColor = otherVariant ? variantColor(otherVariant) : null;
  const baseImages = productImages(currentColor);
  // The other color's photo is always slide 2, ahead of the "why silk"
  // slide shared by both colors. On mobile there's no alt-color thumbnail
  // (removed — too cramped next to the carousel) so this slide is the only
  // way to peek at it; on desktop the thumbnail jumps straight to it too.
  const currentImages = otherColor
    ? [baseImages[0], productImages(otherColor)[0], baseImages[1]]
    : baseImages;
  const [slideIndex, setSlideIndex] = useState(0);
  const [controlsShown, setControlsShown] = useState(false);
  useEffect(() => { setSlideIndex(0); }, [currentColor]);
  const currentImageId = currentImages[slideIndex];
  const allImageIds = [productImages('noir'), productImages('blanc')].flat();
  const goToSlide = (i) => setSlideIndex(((i % currentImages.length) + currentImages.length) % currentImages.length);
  const nextSlide = () => goToSlide(slideIndex + 1);
  const prevSlide = () => goToSlide(slideIndex - 1);
  // The small floating thumbnail toggles between the two color photos
  // (slide 0 ↔ slide 1): it shows whichever color ISN'T on screen, so it
  // always offers a way back. It disappears on slide 2 ("why silk"), which
  // isn't color-specific.
  const altThumbColor = slideIndex === 0 ? otherColor : slideIndex === 1 ? currentColor : null;
  const altThumbTargetSlide = slideIndex === 0 ? 1 : 0;

  // Touch swipe between photos — a horizontal drag past the threshold steps
  // the slide; anything shorter (or more vertical, i.e. a page scroll) is
  // left alone so scrolling past the product image still works.
  const touchRef = useRef(null);
  const onTouchStart = (e) => {
    const t = e.touches[0];
    touchRef.current = { x: t.clientX, y: t.clientY };
  };
  const onTouchEnd = (e) => {
    const start = touchRef.current;
    touchRef.current = null;
    if (!start) return;
    const t = e.changedTouches[0];
    const dx = t.clientX - start.x, dy = t.clientY - start.y;
    if (Math.abs(dx) > 40 && Math.abs(dx) > Math.abs(dy) * 1.5) {
      if (dx < 0) nextSlide(); else prevSlide();
    }
  };

  const priceNode = (selectedVariant && selectedVariant.price) || (product && product.priceRange && product.priceRange.minVariantPrice);
  const priceLabel = loading ? '···' : priceNode ? formatPrice(priceNode.amount, priceNode.currencyCode) : '29,99€';
  const outOfStock = !!selectedVariant && !selectedVariant.availableForSale;
  const lowStock = !!selectedVariant &&
    selectedVariant.availableForSale &&
    typeof selectedVariant.quantityAvailable === 'number' &&
    selectedVariant.quantityAvailable > 0 &&
    selectedVariant.quantityAvailable <= 5;
  const stockClass = outOfStock ? 'is-out' : lowStock ? 'is-low' : '';

  const [qty, setQty] = useState(1);
  useEffect(() => { setQty(1); }, [selectedVariantId]);
  const maxQty = (selectedVariant && typeof selectedVariant.quantityAvailable === 'number' && selectedVariant.quantityAvailable > 0)
    ? selectedVariant.quantityAvailable
    : 99;
  const unitAmount = priceNode ? parseFloat(priceNode.amount) : null;
  const hasUnitAmount = !loading && unitAmount != null && !Number.isNaN(unitAmount);
  const ctaPriceLabel = hasUnitAmount ? formatPrice(unitAmount * qty, priceNode.currencyCode) : priceLabel;
  const pack2PriceLabel = hasUnitAmount ? formatPrice(unitAmount * 2, priceNode.currencyCode) : priceLabel;

  // The 2-pack lets each unit be a different color — defaults to one of
  // each so the picker starts on a useful mix rather than two of the same.
  const [packColor1, setPackColor1] = useState(null);
  const [packColor2, setPackColor2] = useState(null);
  useEffect(() => {
    if (variants.length >= 2 && !packColor1 && !packColor2) {
      setPackColor1(variantColor(variants[0]));
      setPackColor2(variantColor(variants[1]));
    }
  }, [variants]);
  const packVariant1 = variants.find((v) => variantColor(v) === packColor1) || selectedVariant;
  const packVariant2 = variants.find((v) => variantColor(v) === packColor2) || selectedVariant;
  const packLines = (packVariant1 && packVariant2) ? (
    packVariant1.id === packVariant2.id
      ? [{ variantId: packVariant1.id, quantity: 2 }]
      : [{ variantId: packVariant1.id, quantity: 1 }, { variantId: packVariant2.id, quantity: 1 }]
  ) : null;
  // The wash bag itself is NOT added here — useShopifyProduct auto-adds it
  // to the cart (as its own real-priced line) whenever the subtotal crosses
  // the same 50€ threshold the cart drawer's perks banner uses, regardless
  // of how the cart got there. Adding it here too would just race that
  // effect for no benefit.

  // Real value of the 2-pack perks (free shipping + wash bag) — shown
  // struck through next to each OFFERT pill, not a fabricated product
  // discount.
  const shippingValue = CART_SHIPPING_VALUE;
  const washBagValue = CART_WASHBAG_VALUE;
  const packSavingsAmount = shippingValue + washBagValue;
  const packSavingsLabel = priceNode ? formatPrice(packSavingsAmount, priceNode.currencyCode) : `${packSavingsAmount}€`;
  const shippingValueLabel = priceNode ? formatPrice(shippingValue, priceNode.currencyCode) : `${shippingValue}€`;
  const washBagValueLabel = priceNode ? formatPrice(washBagValue, priceNode.currencyCode) : `${washBagValue}€`;

  const [openFaq, setOpenFaq] = useState(-1);

  // Sticky mobile buy bar: shown once the real CTA button has scrolled
  // above the viewport, so there's always a way to buy within thumb reach.
  const ctaRef = useRef(null);
  const [showStickyBar, setShowStickyBar] = useState(false);
  useEffect(() => {
    const el = ctaRef.current;
    if (!el) return;
    const io = new IntersectionObserver(([entry]) => {
      setShowStickyBar(!entry.isIntersecting && entry.boundingClientRect.top < 0);
    }, { threshold: 0 });
    io.observe(el);
    return () => io.disconnect();
  }, []);

  return (
    <section id="produit">
      <span className="section-num">— 01</span>
      <div className="wrap">
        <div className="product">
          {isMobile &&
          <div className="product-heading-mobile" data-reveal>
            <span className="eyebrow eyebrow-gold"><Editable id="product.eyebrow">Le Soyeux · objet</Editable></span>
            <h2 className="h-1">
              <Editable id="product.headingPre">Un seul accessoire, pour</Editable> <span className="italic-accent"><Editable id="product.headingItalic">toutes</Editable></span> <Editable id="product.headingPost">tes casquettes.</Editable>
            </h2>
          </div>
          }
          <div className="product-visuals" data-reveal>
            <div
              className={'product-visual' + (controlsShown ? ' controls-shown' : '')}
              onClick={() => currentImages.length > 1 && setControlsShown((v) => !v)}
              onTouchStart={onTouchStart}
              onTouchEnd={onTouchEnd}>
              {allImageIds.map((id) =>
              <div className={'carousel-slide' + (id === currentImageId ? ' is-active' : '')} key={id}>
                  <image-slot id={id} alt={productImageAlt(id)} shape="rect" placeholder="Photo produit"></image-slot>
                </div>
              )}
              {currentImages.length > 1 && <>
              <button
                type="button"
                className="carousel-arrow prev"
                onClick={(e) => { e.stopPropagation(); prevSlide(); }}
                aria-label="Photo précédente">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 18l-6-6 6-6"/></svg>
              </button>
              <button
                type="button"
                className="carousel-arrow next"
                onClick={(e) => { e.stopPropagation(); nextSlide(); }}
                aria-label="Photo suivante">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M9 18l6-6-6-6"/></svg>
              </button>
              <div className="carousel-dots" role="tablist" aria-label="Photos du produit">
                {currentImages.map((id, i) =>
                <button
                  type="button"
                  key={id}
                  className={'carousel-dot' + (i === slideIndex ? ' is-active' : '')}
                  aria-label={`Photo ${i + 1}`}
                  aria-selected={i === slideIndex}
                  onClick={(e) => { e.stopPropagation(); setSlideIndex(i); }}></button>
                )}
              </div>
              </>}
              {otherVariant && altThumbColor &&
              <button
                type="button"
                className="product-visual-alt"
                onClick={(e) => { e.stopPropagation(); goToSlide(altThumbTargetSlide); }}
                aria-label={`Voir en ${altThumbColor}`}>
                  <image-slot id={productImages(altThumbColor)[0]} alt={`Voir le Soyeux en ${altThumbColor}`} shape="rect" placeholder="Photo produit"></image-slot>
                  <span className="product-visual-alt-label">{altThumbColor}</span>
                </button>
              }
            </div>
          </div>

          <div className="product-text" data-reveal data-reveal-delay="1">
            {!isMobile &&
            <>
              <span className="eyebrow eyebrow-gold"><Editable id="product.eyebrow">Le Soyeux · objet</Editable></span>
              <h2 className="h-1">
                <Editable id="product.headingPre">Un seul accessoire, pour</Editable> <span className="italic-accent"><Editable id="product.headingItalic">toutes</Editable></span> <Editable id="product.headingPost">tes casquettes.</Editable>
              </h2>
            </>
            }
            <p className="lede product-description">
              <Editable id="product.description">Un liner en pure soie mulberry 6A, certifiée Oeko-Tex. S'installe en quelques secondes sous la bande intérieure de n'importe quelle casquette.</Editable>
            </p>

            <ul className="product-benefits-list">
              <li><CheckIcon /><Editable id="product.benefit0">Moins de transpiration sous la casquette</Editable></li>
              <li><CheckIcon /><Editable id="product.benefit1">Coiffure protégée, même après plusieurs heures</Editable></li>
              <li><CheckIcon /><Editable id="product.benefit2">Invisible une fois la casquette portée</Editable></li>
              <li><CheckIcon /><Editable id="product.benefit3">Se retire et se lave à la main en un geste</Editable></li>
            </ul>

            <div className="product-preorder" data-reveal>
              <span className="product-preorder-badge"><Editable id="product.preorderBadge">Précommande</Editable></span>
              <p className="product-preorder-title">
                <Editable id="product.preorderTitle">Sois parmi les 1000 premiers à porter Le Soyeux.</Editable>
              </p>
              <p className="product-preorder-sub">
                <Editable id="product.preorderStock">Premier lot fabriqué en quantité limitée — 700 noir, 300 blanc.</Editable>
              </p>
            </div>

            <div className="product-price">
              <span className="product-price-amount">{priceLabel}</span>
            </div>

            <a href="#avis" className="product-rating">
              <span className="product-rating-stars" aria-hidden="true">★★★★★</span>
              <span><Editable id="product.ratingLabel">5/5 · 3 avis vérifiés</Editable></span>
            </a>

            {variants.length > 0 &&
            <div className="product-variant">
                <span className="product-variant-label"><Editable id="product.variantLabel">Coloris</Editable></span>
                <div className="product-swatches">
                  {variants.map((v) => {
                    const color = variantColor(v);
                    const active = v.id === selectedVariantId;
                    const unavailable = !v.availableForSale;
                    return (
                      <button
                        type="button"
                        key={v.id}
                        className={'product-swatch' + (active ? ' is-active' : '') + (unavailable ? ' is-unavailable' : '')}
                        onClick={() => setSelectedVariantId(v.id)}
                        title={unavailable ? `${color} (épuisé)` : color}>
                        <span className="product-swatch-dot" style={{ background: colorSwatchHex(color) }} />
                        {color}
                      </button>
                    );
                  })}
                </div>
              </div>
            }

            {!loading && selectedVariant &&
            <span className={'product-stock' + (stockClass ? ' ' + stockClass : '')}>
                <span className="product-stock-dot" />
                {outOfStock ?
              <Editable id="product.stockOutLabel">Rupture de stock</Editable> :
              lowStock ?
              <>Plus que {selectedVariant.quantityAvailable} <Editable id="product.stockLowSuffix">en stock</Editable></> :

              <Editable id="product.stockInLabel">En stock</Editable>}
              </span>
            }

            {error &&
            <p className="product-status-msg is-error">
                Impossible de charger les données Shopify ({error}). Prix indicatif affiché.
              </p>
            }
            {cartError &&
            <p className="product-status-msg is-error">{cartError}</p>
            }

            {!outOfStock &&
            <div className="product-pack-picker">
              <button
                type="button"
                className={'product-pack-option' + (qty === 1 ? ' is-active' : '')}
                onClick={() => setQty(1)}>
                <span className="product-pack-radio" />
                <span className="product-pack-info">
                  <span className="product-pack-name"><Editable id="product.pack1Name">1 Soyeux</Editable></span>
                </span>
                <span className="product-pack-price">{priceLabel}</span>
              </button>

              {maxQty >= 2 && variants.length >= 2 &&
              <div className={'product-pack-option is-best' + (qty === 2 ? ' is-active' : '')}>
                <div className="product-pack-banner">
                  <Editable id="product.pack2Banner">2 Soyeux = livraison + filet offerts</Editable>
                </div>
                <button type="button" className="product-pack-main" onClick={() => setQty(2)}>
                  <span className="product-pack-radio" />
                  <span className="product-pack-info">
                    <span className="product-pack-name"><Editable id="product.pack2Name">2 Soyeux</Editable></span>
                    <span className="product-pack-sub"><Editable id="product.pack2Sub">Si tu mets des casquettes tous les jours, autant en avoir deux.</Editable></span>
                    <span className="product-pack-savings">
                      <Editable id="product.pack2SavingsPre">Tu économises</Editable> {packSavingsLabel}
                    </span>
                  </span>
                  <span className="product-pack-price">{pack2PriceLabel}</span>
                </button>
                {qty === 2 &&
                <div className="product-pack-colors">
                  {[
                    { label: 'Soyeux 1', value: packColor1, set: setPackColor1 },
                    { label: 'Soyeux 2', value: packColor2, set: setPackColor2 },
                  ].map((slot, i) => (
                    <div className="product-pack-color-row" key={i}>
                      <span className="product-pack-color-label">{slot.label}</span>
                      <div className="product-pack-color-toggle">
                        {variants.map((v) => {
                          const color = variantColor(v);
                          return (
                            <button
                              type="button"
                              key={v.id}
                              className={'product-pack-color-btn' + (slot.value === color ? ' is-active' : '')}
                              onClick={() => slot.set(color)}>
                              <span className="product-swatch-dot" style={{ background: colorSwatchHex(color) }} />
                              {color}
                            </button>
                          );
                        })}
                      </div>
                    </div>
                  ))}
                </div>
                }
                <div className="product-pack-perks">
                  <div className="product-pack-perk-row">
                    <TruckIcon />
                    <span className="product-pack-perk-text"><Editable id="product.pack2Perk1">Livraison offerte</Editable></span>
                    <span className="product-pack-perk-was">{shippingValueLabel}</span>
                    <span className="product-pack-perk-pill"><Editable id="product.pack2Perk1Pill">Offert</Editable></span>
                  </div>
                  <div className="product-pack-perk-row">
                    <GiftIcon />
                    <span className="product-pack-perk-text"><Editable id="product.pack2Perk2">Filet de lavage pour soie</Editable></span>
                    <span className="product-pack-perk-was">{washBagValueLabel}</span>
                    <span className="product-pack-perk-pill"><Editable id="product.pack2Perk2Pill">Offert</Editable></span>
                  </div>
                </div>
              </div>
              }
            </div>
            }

            <div className="product-cta" ref={ctaRef}>
              <button
                type="button"
                className="btn btn-primary"
                disabled={outOfStock || cartLoading || (loading && !product)}
                onClick={async () => {
                  const ok = await addToCart(qty === 2 && packLines ? packLines : qty);
                  if (ok) { setJustAdded(true); setTimeout(() => setJustAdded(false), 2500); }
                }}>
                {outOfStock ?
                <Editable id="product.outOfStockLabel">Épuisé</Editable> :
                cartLoading ?
                <Editable id="product.checkoutLoadingLabel">Un instant…</Editable> :
                justAdded ?
                <Editable id="product.addedLabel">Ajouté ✓</Editable> :

                <><Editable id="product.commanderLabel">Ajouter au panier</Editable> · {ctaPriceLabel}</>}
              </button>
              {cartCount > 0 &&
              <a
                href={cartUrl || '#'}
                className="btn btn-ghost product-view-cart"
                onClick={(e) => { e.preventDefault(); openCart(); }}>
                <Editable id="product.viewCartLabel">Voir le panier</Editable> ({cartCount})
              </a>
              }
            </div>

            <div className="product-preorder-notes">
              <p className="product-preorder-note">
                <Editable id="product.preorderShipping">Expédition prévue fin novembre 2026. Email de confirmation dès l'envoi.</Editable>
              </p>
              <p className="product-preorder-note">
                <Editable id="product.preorderRefund">Remboursement possible à tout moment avant l'expédition, sans condition.</Editable>
              </p>
            </div>

            <div className="product-quality-badges">
              <div className="product-quality-badge">
                <FranceMapIcon />
                <span><Editable id="product.qualityBadge1">Marque française</Editable></span>
              </div>
              <div className="product-quality-badge">
                <FeatherIcon />
                <span><Editable id="product.qualityBadge2">100% soie de mûrier, 19 momme</Editable></span>
              </div>
              <div className="product-quality-badge">
                <img src="v2/assets/oeko-tex-standard-100.svg" alt="Certifié Oeko-Tex Standard 100" className="product-quality-badge-img" />
                <span><Editable id="product.qualityBadge3">Certifié Oeko-Tex</Editable></span>
              </div>
            </div>

            <div className="product-mini-faq">
              {MINI_FAQ_INDICES.map((i) => (
                <div className={'product-faq-item' + (openFaq === i ? ' open' : '')} key={i}>
                  <button type="button" className="product-faq-q" onClick={() => setOpenFaq(openFaq === i ? -1 : i)}>
                    <span><Editable id={`faq.item${i}.q`}>{FAQS[i].q}</Editable></span>
                    <span className="product-faq-toggle">+</span>
                  </button>
                  <div className="product-faq-a"><p><Editable id={`faq.item${i}.a`}>{FAQS[i].a}</Editable></p></div>
                </div>
              ))}
            </div>
          </div>
        </div>
      </div>

      <div className="wrap">
        <div className="product-trust-strip">
          <div className="product-trust-item">
            <SecurePaymentIcon />
            <strong><Editable id="product.trustPaymentTitle">Paiement sécurisé</Editable></strong>
            <span><Editable id="product.trustPaymentSub">Visa, Mastercard, PayPal</Editable></span>
          </div>
          <div className="product-trust-item">
            <TruckIcon />
            <strong><Editable id="product.trustShippingTitle">Livraison rapide</Editable></strong>
            <span><Editable id="product.trustShippingSub">Expédié sous 24h, en France</Editable></span>
          </div>
          <div className="product-trust-item">
            <MailIcon />
            <strong><Editable id="product.trustSupportTitle">Service client</Editable></strong>
            <span><CopyEmailButton><Editable id="product.trustSupportSub">support@boutiquesoyeux.fr</Editable></CopyEmailButton></span>
          </div>
        </div>
      </div>

      {showStickyBar &&
      <div className="product-sticky-bar">
        <div className="product-sticky-bar-info">
          <span className="product-sticky-bar-thumb"><image-slot id={currentImages[0]} shape="rect" placeholder="Photo produit"></image-slot></span>
          <div className="product-sticky-bar-text">
            <strong><Editable id="product.stickyName">Le Soyeux</Editable></strong>
            <span>{ctaPriceLabel}</span>
          </div>
        </div>
        <button
          type="button"
          className="btn btn-primary btn-sm"
          disabled={outOfStock || cartLoading || (loading && !product)}
          onClick={async () => {
            const ok = await addToCart(qty === 2 && packLines ? packLines : qty);
            if (ok) { setJustAdded(true); setTimeout(() => setJustAdded(false), 2500); }
          }}>
          {outOfStock ?
          <Editable id="product.outOfStockLabel">Épuisé</Editable> :
          justAdded ?
          <Editable id="product.addedLabel">Ajouté ✓</Editable> :
          <Editable id="product.commanderLabel">Ajouter au panier</Editable>}
        </button>
      </div>
      }
    </section>);

}

/* ─── Bénéfices ─── */

const BENEFITS = [
{
  n: '01',
  title: 'Moins de frisottis',
  p: 'Surface de soie anti-friction. La fibre glisse au lieu de s\'accrocher.',
  icon: '1'
},
{
  n: '02',
  title: 'Moins de casse',
  p: 'Protège la fibre capillaire des micro-frottements répétés.',
  icon: '2'
},
{
  n: '03',
  title: 'Cheveux hydratés',
  p: 'La soie n\'absorbe pas l\'hydratation naturelle reste là où elle doit.',
  icon: '3'
},
{
  n: '04',
  title: 'Coiffure préservée',
  p: 'La soie glisse, ne plaque pas. Tu retires la casquette, ta coiffure reste.',
  icon: '4'
}];


function Benefits() {
  return (
    <section className="benefits" id="bienfaits">
      <span className="section-num">— 02</span>
      <div className="wrap">
        <div className="benefits-head">
          <div data-reveal>
            <span className="eyebrow eyebrow-gold sec-num-inline"><Editable id="benefits.eyebrow">— les bienfaits</Editable></span>
            <h2 className="h-1">
              <Editable id="benefits.headingPre">Quatre choses que</Editable> <span className="italic-accent"><Editable id="benefits.headingItalic">tes cheveux</Editable></span><br />
              <Editable id="benefits.headingPost">vont remarquer.</Editable>
            </h2>
          </div>
          <p className="lede" data-reveal data-reveal-delay="1">
            <Editable id="benefits.lede">La soie mulberry 6A a une particularité simple : elle ne tire pas, ne chauffe pas, n'absorbe pas. Tout l'inverse d'une doublure de casquette standard.</Editable>
          </p>
        </div>

        <div className="benefits-grid">
          {BENEFITS.map((b, i) =>
          <div className="benefit" key={b.n} data-reveal data-reveal-delay={String(i)}>
              <div className="benefit-icon benefit-icon-num">{b.icon}</div>
              <h3><Editable id={`benefits.item${i}.title`}>{b.title}</Editable></h3>
              <p><Editable id={`benefits.item${i}.p`}>{b.p}</Editable></p>
            </div>
          )}
        </div>
      </div>
    </section>);

}

/* ─── How it works ─── */

const STEPS = [
{
  n: '01',
  title: 'Prends ton Soyeux.',
  p: 'Souple, léger, déjà prêt. Une seule taille — elle s\'adapte à la plupart des casquettes.',
  tone: ''
},
{
  n: '02',
  title: 'Insère-le dans ta casquette.',
  p: 'Le bord glisse sous la sudette, en un geste — et se retire tout aussi simplement.',
  tone: 'dark'
},
{
  n: '03',
  title: 'Remets ta casquette.',
  p: 'Invisible de l\'extérieur, doux pour tes cheveux. Tu le retires, tu le laves, tu recommences.',
  tone: ''
}];


function HowItWorks() {
  return (
    <section id="methode">
      <span className="section-num">— 03</span>
      <div className="wrap">
        <div className="sec-hd" data-reveal>
          <div>
            <span className="sec-num-inline"><Editable id="howitworks.eyebrow">— méthode</Editable></span>
            <h2 className="h-1">
              <Editable id="howitworks.heading1">Quelques secondes.</Editable> <span className="italic-accent"><Editable id="howitworks.headingItalic">Vraiment.</Editable></span>
            </h2>
          </div>
          <p className="lede">
            <Editable id="howitworks.lede">Pas d'outils, pas de notice, pas de couture — zéro effort, zéro trace sur ta casquette.</Editable>
          </p>
        </div>

        <div className="how-grid">
          {STEPS.map((s, i) =>
          <article className="how-step" key={s.n} data-reveal data-reveal-delay={String(i)}>
              <div className={`how-visual ${s.tone}`}>
                <div className="how-num-tag">— {s.n}</div>
                {s.tone === 'dark' ?
              <div className="cap-render" style={{ padding: '20%' }}><CapSVG tone="dark" /></div> :
              <div className="cap-render" style={{ padding: '20%' }}><CapSVG /></div>}
              </div>
              <h3><Editable id={`howitworks.step${i}.title`}>{s.title}</Editable></h3>
              <p><Editable id={`howitworks.step${i}.p`}>{s.p}</Editable></p>
            </article>
          )}
        </div>
      </div>
    </section>);

}

window.useReveal = useReveal;
window.CapSVG = CapSVG;
window.Nav = Nav;
window.Hero = Hero;
window.Marquee = Marquee;
window.Choc = Choc;
window.Product = Product;
window.Benefits = Benefits;
window.HowItWorks = HowItWorks;
