/* ─────────────────────────────────────────────────────────────────────────
   Coffre au trésor : récompense « Bravo ! » après une génération réussie quand le solde
   d'un compte gratuit devient faible → offre de bienvenue (pack « bienvenue »).
   Markup construit par assets/js/treasure.js ; aucune dépendance externe.
   ───────────────────────────────────────────────────────────────────────── */
/* Flex colonne + marges auto sur la pile : centrée quand elle tient, alignée en haut et défilable sinon
   (1280×800 : le haut du coffre était rogné par un centrage grid qui débordait des deux côtés). */
.treasure { position:fixed; inset:0; z-index:2500; display:flex; flex-direction:column; align-items:center; padding:16px; overflow:hidden auto; overscroll-behavior:contain; color:#fff7df;
  font-family:"DM Sans","DM Sans Fallback",system-ui,sans-serif; -webkit-tap-highlight-color:transparent; opacity:0; transition:opacity .35s ease; }
.treasure.is-in { opacity:1; }
.treasure.is-out { opacity:0; transition-duration:.28s; }
/* Calques plein écran en position:fixed (et non absolute) : ils ne défilent pas avec la pile. */
.treasure__backdrop { position:fixed; inset:0; background:radial-gradient(ellipse at 50% 40%, rgba(70,48,8,.55), rgba(6,8,12,.9) 70%), rgba(6,8,12,.86); backdrop-filter:blur(6px); -webkit-backdrop-filter:blur(6px); }
.treasure__canvas { position:fixed; inset:0; width:100%; height:100%; pointer-events:none; }
.treasure__flash { position:fixed; inset:0; pointer-events:none; background:radial-gradient(circle at 50% 55%, rgba(255,236,170,.95), rgba(255,200,60,.5) 30%, transparent 65%); opacity:0; }
.treasure.is-open .treasure__flash { animation:trFlash .9s ease-out both; }

/* Rayons de lumière tournants derrière le coffre */
.treasure__rays { position:fixed; left:50%; top:50%; width:min(160vmax, 1400px); height:min(160vmax, 1400px); margin:calc(min(160vmax,1400px) / -2) 0 0 calc(min(160vmax,1400px) / -2); pointer-events:none; opacity:0;
  background:repeating-conic-gradient(from 0deg, rgba(255,214,102,.28) 0deg 9deg, rgba(255,214,102,0) 9deg 24deg);
  -webkit-mask:radial-gradient(circle, #000 0%, rgba(0,0,0,.6) 28%, transparent 62%); mask:radial-gradient(circle, #000 0%, rgba(0,0,0,.6) 28%, transparent 62%);
  transition:opacity .6s ease; }
.treasure.is-open .treasure__rays { opacity:1; animation:trSpin 26s linear infinite; }
.treasure__rays--2 { background:repeating-conic-gradient(from 12deg, rgba(255,255,255,.12) 0deg 4deg, transparent 4deg 30deg); }
.treasure.is-open .treasure__rays--2 { animation-direction:reverse; animation-duration:40s; }

/* Pile centrale : coffre + textes + carte */
.treasure__stage { position:relative; z-index:2; display:grid; justify-items:center; gap:0; width:min(560px, 100%); margin:auto; flex:none; overflow:visible; }

/* Coffre : deux calques SVG (corps + couvercle) dans une scène en perspective */
.treasure__chest { --w:min(250px, 54vw); position:relative; width:var(--w); height:calc(var(--w) * .86); perspective:900px; transform:translateY(-120vh) scale(.6); filter:drop-shadow(0 18px 24px rgba(0,0,0,.55)); }
.treasure.is-in .treasure__chest { animation:trDrop .75s cubic-bezier(.22,1.4,.36,1) .1s both; }
.treasure.is-shake .treasure__chest { animation:trShake .7s cubic-bezier(.36,.07,.19,.97) both; }
.treasure.is-open .treasure__chest { transform:none; animation:trHop .5s cubic-bezier(.22,1.4,.36,1) both; }
.treasure__chest svg { position:absolute; left:0; width:100%; height:auto; overflow:visible; }
.treasure__chest-body { bottom:0; }
/* Charnière = ligne à 78 % du couvercle (bord arrière du coffre) ; en s'ouvrant, le dôme bascule
   vers l'arrière (raccourci par la perspective) et la bordure avant se soulève vers le spectateur. */
.treasure__chest-lid { top:0; transform-origin:50% 72.7%; transform:rotateX(0deg); transition:transform .32s cubic-bezier(.5,0,.8,.4), opacity .1s linear .24s; }
.treasure.is-open .treasure__chest-lid { transform:rotateX(88deg); opacity:0; }
/* Couvercle ouvert (intérieur visible) : se déplie depuis la charnière juste après la bascule du couvercle fermé. */
.treasure__chest-lid-open { bottom:calc(var(--w) * .512); transform-origin:50% 100%; transform:rotateX(-88deg); opacity:0; transition:transform .55s cubic-bezier(.3,1.5,.5,1) .2s, opacity .12s linear .2s; }
.treasure.is-open .treasure__chest-lid-open { transform:rotateX(14deg); opacity:1; }
.treasure__chest-glow { position:absolute; left:50%; top:22%; width:90%; height:40%; transform:translateX(-50%) scale(0); border-radius:50%; pointer-events:none;
  background:radial-gradient(ellipse, rgba(255,247,210,.95), rgba(255,205,70,.7) 35%, rgba(255,180,30,0) 72%); filter:blur(5px); opacity:0; }
.treasure.is-open .treasure__chest-glow { animation:trGlow 1.2s ease-out .05s both; }
/* Faisceau de lumière qui jaillit du coffre ouvert */
.treasure__beam { position:absolute; left:50%; bottom:56%; width:70%; height:150%; transform:translateX(-50%) scaleY(0); transform-origin:50% 100%; pointer-events:none; opacity:0;
  clip-path:polygon(0 0, 100% 0, 64% 100%, 36% 100%);
  background:linear-gradient(180deg, rgba(255,236,170,0) 0%, rgba(255,226,130,.4) 45%, rgba(255,243,200,.95) 100%); filter:blur(1.5px); }
.treasure.is-open .treasure__beam { animation:trBeam 1s cubic-bezier(.2,.8,.3,1) .08s both, trFlicker 2.2s ease-in-out 1.1s infinite; }
.treasure__glint { position:absolute; width:14px; height:14px; pointer-events:none; opacity:0; background:conic-gradient(from 0deg, transparent 0 40%, #fff 50%, transparent 60% 90%, #fff 100%); border-radius:50%; mix-blend-mode:screen;
  -webkit-mask:radial-gradient(circle, #000 0 30%, transparent 70%); mask:radial-gradient(circle, #000 0 30%, transparent 70%); }
.treasure.is-shake .treasure__glint { animation:trGlint .5s ease-out both; }
.treasure__glint--a { left:18%; top:30%; animation-delay:.05s !important; }
.treasure__glint--b { left:72%; top:22%; animation-delay:.22s !important; }
.treasure__glint--c { left:56%; top:60%; animation-delay:.4s !important; }

/* Textes */
.treasure__title { margin:14px 0 0; font-size:clamp(44px, 11vw, 78px); line-height:1; font-weight:900; letter-spacing:-.03em; color:#ffe27a; text-align:center;
  background:linear-gradient(180deg, #fff6c8 0%, #ffd34d 38%, #f0a500 60%, #ffe28a 100%); -webkit-background-clip:text; background-clip:text; -webkit-text-fill-color:transparent;
  filter:drop-shadow(0 3px 0 #8a5a00) drop-shadow(0 8px 22px rgba(255,190,40,.45)); opacity:0; transform:scale(.3); }
.treasure.is-open .treasure__title { animation:trPop .55s cubic-bezier(.2,1.6,.4,1) .25s both; }
.treasure__sub { margin:6px 0 0; font-size:clamp(15px, 2.6vw, 18px); font-weight:600; letter-spacing:.01em; text-align:center; color:#f3e7c6; text-shadow:0 2px 10px rgba(0,0,0,.6); opacity:0; }
.treasure.is-open .treasure__sub { animation:trRise .5s ease-out .55s both; }

/* Carte d'offre */
.treasure__card { position:relative; margin-top:16px; width:min(480px, 100%); padding:18px 18px 16px; border-radius:18px; text-align:center; opacity:0; transform:translateY(28px);
  background:linear-gradient(180deg, rgba(48,34,10,.92), rgba(14,18,25,.96)); border:1px solid rgba(255,205,80,.55); box-shadow:0 0 0 4px rgba(255,205,80,.08), 0 0 50px rgba(255,190,40,.25), 0 30px 70px rgba(0,0,0,.6); }
.treasure.is-open .treasure__card { animation:trRise .55s cubic-bezier(.2,1.2,.4,1) .9s both; }
.treasure__card::before { content:""; position:absolute; inset:-1px; border-radius:inherit; padding:1px; pointer-events:none;
  background:linear-gradient(120deg, rgba(255,230,150,.9), rgba(255,180,40,.2) 40%, rgba(255,230,150,.9)); -webkit-mask:linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite:xor; mask-composite:exclude; opacity:.7; }
.treasure__eyebrow { display:inline-flex; align-items:center; gap:8px; font-size:11px; letter-spacing:.14em; text-transform:uppercase; font-weight:800; color:#ffd34d; }
/* Pictogrammes en traits (SVG inline, couleur héritée) */
.treasure__ico { width:18px; height:18px; flex:none; display:inline-block; vertical-align:-4px; }
.treasure__ico--coin { width:20px; height:20px; color:#ffd34d; filter:drop-shadow(0 0 6px rgba(255,205,80,.45)); }
.treasure__ico--arrow { width:20px; height:20px; stroke-width:2.25; transition:transform .2s; }
.treasure__cta:hover .treasure__ico--arrow { transform:translateX(4px); }
.treasure__offer { margin:8px 0 0; font-size:clamp(20px, 4.4vw, 26px); line-height:1.15; font-weight:900; color:#fff; letter-spacing:-.01em; }
.treasure__offer b { color:#ffd34d; }
.treasure__price { display:flex; align-items:baseline; justify-content:center; gap:10px; margin-top:10px; }
.treasure__price-now { font-size:clamp(40px, 9vw, 54px); line-height:1; font-weight:900; color:#ffd34d; text-shadow:0 2px 0 #7a4e00, 0 6px 24px rgba(255,190,40,.4); font-variant-numeric:tabular-nums; }
.treasure__price-old { font-size:clamp(18px, 3.6vw, 22px); font-weight:700; color:#b7a98a; text-decoration:line-through; }
.treasure__badge { display:inline-block; padding:4px 10px; border-radius:999px; font-size:13px; font-weight:900; color:#1a1200; background:linear-gradient(180deg, #ffe58a, #f5b301); box-shadow:0 4px 12px rgba(245,179,1,.4); transform:rotate(-4deg); }
.treasure__timer { display:inline-flex; align-items:center; gap:6px; margin:10px 0 0; padding:5px 12px; border-radius:999px; font-size:13px; font-weight:700; color:#ffd9a0; background:rgba(255,120,40,.14); border:1px solid rgba(255,160,60,.35); }
.treasure__timer b { color:#fff; font-variant-numeric:tabular-nums; letter-spacing:.03em; }
.treasure__detail { margin:10px 0 0; font-size:13.5px; color:#e9dfc7; line-height:1.45; }
.treasure__detail b { color:#fff; }
.treasure__balance { display:inline-flex; align-items:center; gap:8px; margin-top:12px; padding:7px 14px; border-radius:999px; font-size:13px; font-weight:700; color:#ffe9b0; background:rgba(255,255,255,.07); border:1px solid rgba(255,205,80,.25); }
.treasure__balance b { font-size:16px; color:#fff; font-variant-numeric:tabular-nums; }
.treasure__cta { position:relative; display:flex; align-items:center; justify-content:center; gap:10px; width:100%; margin-top:14px; padding:15px 18px; border:0; border-radius:14px; cursor:pointer; overflow:hidden;
  font:inherit; font-size:clamp(15px, 3.6vw, 18px); font-weight:900; color:#1a1200; letter-spacing:-.01em;
  background:linear-gradient(180deg, #ffe58a 0%, #f7bd1a 55%, #e39a00 100%); box-shadow:0 10px 30px rgba(245,179,1,.45), inset 0 1px 0 rgba(255,255,255,.7), inset 0 -2px 0 rgba(120,70,0,.35);
  transition:transform .15s, box-shadow .2s; animation:trBreath 2.4s ease-in-out infinite; }
.treasure__cta:hover { transform:translateY(-2px) scale(1.02); box-shadow:0 14px 36px rgba(245,179,1,.6), inset 0 1px 0 rgba(255,255,255,.7); }
.treasure__cta:active { transform:translateY(1px) scale(.99); }
.treasure__cta::after { content:""; position:absolute; top:-40%; bottom:-40%; width:40px; left:-60px; transform:skewX(-20deg); background:linear-gradient(90deg, transparent, rgba(255,255,255,.75), transparent); animation:trShine 2.6s ease-in-out 1.6s infinite; }
.treasure__cta:focus-visible, .treasure__later:focus-visible, .treasure__close:focus-visible { outline:3px solid #fff; outline-offset:3px; }
.treasure__later { display:inline-block; margin-top:12px; padding:6px 10px; border:0; background:none; color:#c8bda3; font:inherit; font-size:13px; font-weight:600; cursor:pointer; text-decoration:underline; text-underline-offset:3px; }
.treasure__later:hover { color:#fff; }
.treasure__close { position:fixed; top:12px; right:12px; z-index:3; width:40px; height:40px; border-radius:50%; border:1px solid rgba(255,255,255,.18); background:rgba(0,0,0,.4); color:#fff; font-size:22px; line-height:1; cursor:pointer; display:grid; place-items:center; backdrop-filter:blur(4px); }
.treasure__close:hover { background:rgba(255,255,255,.14); }
.treasure__sr { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); clip-path:inset(50%); white-space:nowrap; }

/* Téléphone : moins de hauteur, carte collée en bas, coffre plus petit */
@media (max-width: 560px) {
  .treasure { padding:12px 12px max(12px, env(safe-area-inset-bottom)); align-items:center; }
  .treasure__chest { --w:min(190px, 48vw); }
  .treasure__stage { gap:0; }
  .treasure__card { padding:14px 14px 12px; margin-top:12px; }
  .treasure__detail { font-size:12.5px; }
  .treasure__cta { padding:14px 14px; }
}
@media (max-height: 700px) {
  .treasure { overflow-y:auto; }
  .treasure__stage { padding-top:10px; }
  .treasure__chest { --w:150px; }
  .treasure__title { font-size:38px; margin-top:2px; }
  .treasure__sub { font-size:14px; }
  .treasure__card { margin-top:8px; padding:12px; }
  .treasure__detail { margin-top:6px; }
  .treasure__price-now { font-size:36px; }
}

@keyframes trDrop { from { transform:translateY(-120vh) scale(.6); } 60% { transform:translateY(12px) scale(1.04, .94); } 80% { transform:translateY(-6px) scale(.98, 1.03); } to { transform:none; } }
@keyframes trShake { 0%, 100% { transform:translateX(0) rotate(0); } 10% { transform:translateX(-3px) rotate(-1.5deg); } 20% { transform:translateX(4px) rotate(1.5deg); } 30% { transform:translateX(-5px) rotate(-2deg); } 40% { transform:translateX(6px) rotate(2.5deg); } 50% { transform:translateX(-7px) rotate(-3deg) scale(1.02); } 60% { transform:translateX(7px) rotate(3deg) scale(1.03); } 70% { transform:translateX(-8px) rotate(-3.5deg) scale(1.04); } 80% { transform:translateX(8px) rotate(3.5deg) scale(1.05); } 90% { transform:translateX(-5px) rotate(-2deg) scale(1.06); } }
@keyframes trHop { 0% { transform:translateY(0) scale(1.06); } 35% { transform:translateY(-22px) scale(1.1, 1.14); } 70% { transform:translateY(4px) scale(1.04, .97); } 100% { transform:none; } }
@keyframes trGlow { 0% { opacity:0; transform:translateX(-50%) scale(0); } 30% { opacity:1; transform:translateX(-50%) scale(1.6); } 100% { opacity:.75; transform:translateX(-50%) scale(1.15); } }
@keyframes trFlash { 0% { opacity:0; } 12% { opacity:1; } 100% { opacity:0; } }
@keyframes trBeam { 0% { opacity:0; transform:translateX(-50%) scaleY(0); } 40% { opacity:1; } 100% { opacity:.85; transform:translateX(-50%) scaleY(1); } }
@keyframes trFlicker { 0%, 100% { opacity:.85; } 50% { opacity:.6; } }
@keyframes trSpin { to { transform:rotate(360deg); } }
@keyframes trGlint { 0% { opacity:0; transform:scale(.2) rotate(0); } 40% { opacity:1; transform:scale(2.2) rotate(60deg); } 100% { opacity:0; transform:scale(.4) rotate(120deg); } }
@keyframes trPop { 0% { opacity:0; transform:scale(.3); } 55% { opacity:1; transform:scale(1.18) rotate(-2deg); } 75% { transform:scale(.96) rotate(1deg); } 100% { opacity:1; transform:scale(1); } }
@keyframes trRise { from { opacity:0; transform:translateY(28px); } to { opacity:1; transform:none; } }
@keyframes trBreath { 0%, 100% { box-shadow:0 10px 30px rgba(245,179,1,.45), inset 0 1px 0 rgba(255,255,255,.7), inset 0 -2px 0 rgba(120,70,0,.35); } 50% { box-shadow:0 14px 44px rgba(245,179,1,.7), inset 0 1px 0 rgba(255,255,255,.7), inset 0 -2px 0 rgba(120,70,0,.35); } }
@keyframes trShine { 0% { left:-60px; } 35%, 100% { left:120%; } }

/* Mouvement réduit : tout est affiché d'emblée, coffre ouvert, sans pièces ni rayons tournants */
@media (prefers-reduced-motion: reduce) {
  .treasure, .treasure__chest, .treasure__chest-lid, .treasure__chest-lid-open, .treasure__card, .treasure__title, .treasure__sub, .treasure__cta, .treasure__cta::after, .treasure__glint, .treasure__chest-glow, .treasure__beam, .treasure__flash, .treasure__rays { animation:none !important; transition:none !important; }
  .treasure { opacity:1; }
  .treasure__chest { transform:none; }
  .treasure__chest-lid { transform:rotateX(88deg); opacity:0; }
  .treasure__chest-lid-open { transform:rotateX(14deg); opacity:1; }
  .treasure__chest-glow { opacity:.7; transform:translateX(-50%) scale(1.15); }
  .treasure__beam { opacity:.6; transform:translateX(-50%) scaleY(1); }
  .treasure__title, .treasure__sub, .treasure__card { opacity:1; transform:none; }
  .treasure__rays { opacity:.5; }
  .treasure__canvas { display:none; }
}
