/* Coffres mystère: one isolated scene, shared outcome/probabilities in app.js. */
#gameModal .game-dialog.treasure-game{
  display:flex;flex-direction:column;width:min(640px,calc(100vw - 24px));height:min(840px,calc(100dvh - 24px));
  min-height:0;max-height:calc(100dvh - 24px);padding:34px 22px 24px;border:0;border-radius:30px;overflow:hidden;
  color:var(--game-text);background:var(--game-background);font-family:Nunito,Manrope,sans-serif;
  box-shadow:0 28px 85px #29134a3d;
}
#gameModal .treasure-game:before{background:radial-gradient(ellipse at 50% 44%,color-mix(in srgb,var(--game-secondary) 24%,transparent),transparent 65%),radial-gradient(circle at 4% 5%,color-mix(in srgb,var(--game-primary) 13%,transparent),transparent 38%)}
#gameModal .treasure-game>.eyebrow{flex:none;margin:0 22px 9px;font:850 10px/1.4 Manrope,sans-serif;letter-spacing:.16em;color:var(--game-primary)}
#gameModal .treasure-game>h2{flex:none;max-width:95%;margin:0 auto 12px;font:700 clamp(27px,7vw,41px)/1.1 Fredoka,Nunito,sans-serif;letter-spacing:-.025em;color:var(--game-text);overflow-wrap:anywhere;text-wrap:balance}
#gameModal .treasure-game>.game-instruction{flex:none;max-width:36ch;margin:0 auto;font-size:13px;line-height:1.5;color:color-mix(in srgb,var(--game-text) 78%,transparent);overflow-wrap:anywhere}
#gameModal .treasure-game #gameStage{flex:1;display:flex;min-height:0!important;width:100%;margin:10px 0 14px}
.treasure-experience{display:flex;flex-direction:column;gap:13px;min-height:0;width:100%;height:100%}
.treasure-scene{position:relative;isolation:isolate;flex:1;min-height:190px;container-type:size}
.treasure-decor{position:absolute;inset:0;z-index:-1;overflow:hidden;pointer-events:none}
.treasure-orbit{position:absolute;width:94%;aspect-ratio:1;left:3%;top:50%;transform:translateY(-50%);border-radius:50%;border:1px solid color-mix(in srgb,var(--game-primary) 13%,transparent);background:radial-gradient(circle,#fff8,transparent 64%)}
.treasure-orbit.inner{width:70%;left:15%;border-style:dashed;border-color:color-mix(in srgb,var(--game-primary) 18%,transparent);background:none}
.treasure-cloud{position:absolute;top:25%;left:-3%;width:26%;height:8%;border-radius:50px;background:#fff9}.treasure-cloud:before{content:"";position:absolute;left:30%;bottom:30%;width:42%;height:160%;border-radius:50%;background:inherit}.treasure-cloud.second{top:45%;left:84%;width:24%;opacity:.55}
.treasure-mystery{position:absolute;left:14%;top:13%;font:700 38px Fredoka,sans-serif;color:var(--game-primary);opacity:.17;transform:rotate(-18deg)}.treasure-mystery.second{left:auto;right:10%;top:26%;font-size:29px;transform:rotate(18deg)}
.treasure-star{position:absolute;width:19px;color:var(--game-secondary);animation:treasureTwinkle 3.4s ease-in-out infinite}.treasure-star svg{display:block;width:100%;filter:drop-shadow(0 2px 0 #a35c1421)}
.treasure-star.s0{top:11%;left:43%;width:28px}.treasure-star.s1{top:29%;left:7%;width:14px;animation-delay:-1s}.treasure-star.s2{top:32%;right:18%;width:24px;animation-delay:-2s}.treasure-star.s3{top:75%;left:9%;width:17px;animation-delay:-.5s}.treasure-star.s4{top:88%;right:15%;width:14px;animation-delay:-1.5s}.treasure-star.s5{top:61%;left:41%;width:11px}.treasure-star.s6{top:17%;right:1%;width:12px;color:var(--game-primary)}.treasure-star.s7{top:88%;left:32%;width:11px;color:var(--game-primary)}.treasure-star.s8{top:53%;right:4%;width:12px}
.treasure-scene-label{position:absolute;top:3%;left:0;right:0;display:flex;align-items:center;justify-content:center;gap:8px;margin:0;font:800 8px/1.4 Manrope,sans-serif;letter-spacing:.1em;color:color-mix(in srgb,var(--game-text) 60%,transparent)}.treasure-scene-label span{width:19px;height:1px;background:currentColor;opacity:.3}
.treasure-chests{position:absolute;inset:0;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));grid-template-rows:max-content;align-items:stretch;align-content:center;gap:12px;padding-top:25px;transition:grid-template-columns .7s cubic-bezier(.2,.8,.2,1)}
.treasure-chest{--chest-tone:var(--game-primary);position:relative;z-index:1;display:flex;flex-direction:column;align-items:center;gap:5px;min-width:0;width:100%;padding:0;border:0;background:none;color:var(--game-text);font-family:inherit;text-align:center;cursor:pointer;-webkit-tap-highlight-color:transparent}
.treasure-chest:nth-child(2){--chest-tone:color-mix(in srgb,var(--game-primary) 55%,#F0669A)}.treasure-chest:nth-child(3){--chest-tone:color-mix(in srgb,var(--game-primary) 28%,#26AFAC)}
.treasure-chest:focus-visible{outline:3px solid var(--game-primary);outline-offset:7px;border-radius:18px}.treasure-chest:disabled{opacity:1;cursor:default}
.treasure-number{display:grid;place-items:center;width:26px;height:26px;border-radius:50%;border:1px solid color-mix(in srgb,var(--game-primary) 17%,transparent);background:#fffb;color:var(--game-primary);font:900 10px Manrope,sans-serif;transition:background .3s,color .3s}
.treasure-box{position:relative;isolation:isolate;display:block;flex:none;width:100%;height:min(35cqw,44cqh,173px);min-height:100px;perspective:700px;filter:drop-shadow(0 12px 6px #25133a29);transition:transform .3s}
.treasure-chest:not(:disabled):hover .treasure-box{transform:translateY(-7px)}.treasure-chest:not(:disabled):active .treasure-box{transform:translateY(2px) scale(.97)}
.treasure-body{position:absolute;z-index:4;bottom:9%;left:5%;right:5%;height:40%;border:2px solid color-mix(in srgb,var(--chest-tone) 60%,#271940);border-radius:5px 5px 15px 15px;background:linear-gradient(125deg,color-mix(in srgb,var(--chest-tone) 70%,white),var(--chest-tone) 50%,color-mix(in srgb,var(--chest-tone) 70%,#251340));box-shadow:inset 0 3px #ffffff80,inset -5px -5px 0 #0000000c}
.treasure-body:before,.treasure-body:after{content:"";position:absolute;top:0;bottom:0;width:9%;background:linear-gradient(90deg,color-mix(in srgb,var(--game-secondary) 90%,#965920),#fff1b3,var(--game-secondary));border-inline:1px solid #80420f38}.treasure-body:before{left:13%}.treasure-body:after{right:13%}
.treasure-body i{position:absolute;left:9%;right:9%;bottom:10%;height:1px;background:#ffffff3d}.treasure-body b{position:absolute;inset:17% 32%;border-radius:6px;border:1px solid #ffffff1f}
.treasure-cavity{position:absolute;z-index:1;left:6%;right:6%;top:31%;height:31%;border-radius:50%;background:radial-gradient(ellipse at 50% 75%,#573b6a,#281b3e);border:4px solid var(--game-secondary);transform:rotateX(18deg);box-shadow:inset 0 9px 8px #10081799}
.treasure-cavity i{position:absolute;bottom:13%;left:18%;right:18%;height:22%;border-radius:50%;background:#b599c726;box-shadow:0 -1px 0 #ffffff1f}
.treasure-lid{position:absolute;z-index:5;top:18%;left:3%;right:3%;height:35%;border:2px solid color-mix(in srgb,var(--chest-tone) 55%,#25143b);border-bottom:6px solid var(--game-secondary);border-radius:40% 40% 5px 5px;background:linear-gradient(160deg,color-mix(in srgb,var(--chest-tone) 55%,white),var(--chest-tone) 60%,color-mix(in srgb,var(--chest-tone) 65%,#291840));transform-origin:50% 100%;transition:transform .9s cubic-bezier(.22,.8,.2,1);box-shadow:inset 0 4px 1px #fff5;backface-visibility:visible}
.treasure-lid:before,.treasure-lid:after{content:"";position:absolute;top:0;bottom:0;width:10%;background:linear-gradient(90deg,var(--game-secondary),#fff0ac,var(--game-secondary));border-inline:1px solid #85521c35}.treasure-lid:before{left:14%}.treasure-lid:after{right:14%}
.treasure-lid b{position:absolute;inset:14% 30% 0;font:700 clamp(21px,7cqw,34px)/1 Fredoka,sans-serif;color:#fff6cc;text-shadow:0 2px 0 #74421466}
.treasure-lock{position:absolute;z-index:6;left:39%;top:45%;width:22%;height:23%;border:2px solid #94681f;border-radius:8px;background:linear-gradient(135deg,#fff5b8,var(--game-secondary) 60%,#d39632);box-shadow:0 3px 2px #24173144;transition:opacity .2s,transform .6s}
.treasure-lock i{position:absolute;left:34%;top:27%;width:32%;height:30%;border-radius:50%;background:#483421}.treasure-lock i:after{content:"";position:absolute;top:50%;left:30%;width:40%;height:130%;background:inherit}
.treasure-caption{display:flex;flex-direction:column;align-items:center;gap:4px;min-height:68px;max-width:100%;line-height:1.25;overflow-wrap:anywhere;text-wrap:balance}.treasure-caption strong{font-size:12px;font-weight:900;max-width:100%}.treasure-caption small{font-size:9px;max-width:100%;color:color-mix(in srgb,var(--game-text) 65%,transparent)}
.treasure-plinth{position:absolute;z-index:-1;left:1%;right:1%;top:64%;height:12%;border-radius:50%;background:radial-gradient(ellipse,color-mix(in srgb,var(--game-primary) 12%,transparent),transparent 72%)}
.treasure-chest.is-chosen .treasure-number{background:var(--game-primary);color:#fff;box-shadow:0 0 0 4px color-mix(in srgb,var(--game-primary) 12%,transparent)}
/* Give the chosen chest real layout space, not a scale that covers its neighbours.
   Height-aware sizing keeps its rising prize inside even a short phone viewport. */
.treasure-chests:has(>.is-chosen:nth-child(1)){grid-template-columns:minmax(0,1.6fr) minmax(0,.7fr) minmax(0,.7fr)}
.treasure-chests:has(>.is-chosen:nth-child(2)){grid-template-columns:minmax(0,.7fr) minmax(0,1.6fr) minmax(0,.7fr)}
.treasure-chests:has(>.is-chosen:nth-child(3)){grid-template-columns:minmax(0,.7fr) minmax(0,.7fr) minmax(0,1.6fr)}
.treasure-opening .treasure-chests{padding-top:20px;align-items:center}
.treasure-opening .treasure-scene-label{opacity:0;transition:opacity .25s}
.treasure-opening .treasure-number{display:none}
.treasure-opening .treasure-box{width:min(100%,calc((100cqh - 105px) * .9));height:auto;min-height:0;aspect-ratio:.9}
.treasure-opening .treasure-chest{transition:opacity .4s}
.treasure-opening .treasure-chest:not(.is-chosen){opacity:.72}
.treasure-opening .treasure-chest.has-prize{opacity:1}
.treasure-opening .treasure-chest.is-chosen{z-index:3}
.treasure-opening .is-chosen .treasure-box{filter:drop-shadow(0 17px 9px #25133a45)}
.treasure-opening .treasure-caption{min-height:55px;gap:4px}
.treasure-opening .treasure-caption strong{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;overflow:hidden;font-size:10px}
.treasure-opening .is-chosen .treasure-caption strong{font-size:13px;-webkit-line-clamp:2}
.treasure-opening .is-chosen .treasure-caption small{font-weight:850;color:var(--game-primary)}
.treasure-chest.is-open .treasure-number{opacity:0}
.treasure-chest.is-chosen:not(.is-open) .treasure-box{animation:treasureRattle .75s ease-in-out both}
.treasure-chest.is-open .treasure-lid{transform:translateY(-8%) rotateX(-108deg);z-index:0}.treasure-chest.is-open .treasure-lock{transform:translateY(15px) rotate(18deg);opacity:0}
.treasure-glow{position:absolute;z-index:0;inset:-30% -12% 0;border-radius:50%;opacity:0;background:radial-gradient(ellipse,#fff8da,var(--game-secondary) 10%,transparent 65%);transition:opacity .7s}
.treasure-loot{position:absolute;z-index:3;top:26%;left:10%;right:10%;height:53%;display:grid;place-items:center;opacity:0;transform:translateY(20%) scale(.3);transition:transform 1s cubic-bezier(.18,.86,.18,1.15),opacity .5s;color:var(--game-primary)}
.treasure-loot svg,.treasure-loot img{grid-area:1/1;width:100%;height:100%;object-fit:contain;filter:drop-shadow(0 5px 3px #2f163840)}.treasure-loot img{opacity:0}.treasure-loot.image-ready img{opacity:1}.treasure-loot.image-ready svg{visibility:hidden}
.treasure-chest.is-open.has-prize .treasure-loot{opacity:1;transform:translateY(-95%) scale(1)}.treasure-chest.is-open.has-prize .treasure-glow{opacity:.7}
.treasure-burst{position:absolute;z-index:7;inset:0;pointer-events:none}.treasure-burst>i{position:absolute;left:50%;top:45%;width:13px;height:13px;color:var(--game-secondary);opacity:0;--angle:calc(var(--n) * 30deg)}.treasure-burst svg{display:block;width:100%}.treasure-won .is-chosen.is-open .treasure-burst>i{animation:treasureBurst 1.7s .25s cubic-bezier(.1,.7,.35,1) both}.treasure-burst>i:nth-child(3n){color:var(--game-primary);width:8px}
.treasure-announcement{flex:none;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;min-height:111px;padding:15px 17px;border:1px solid color-mix(in srgb,var(--game-primary) 13%,transparent);border-radius:22px;background:color-mix(in srgb,var(--game-background) 32%,white);box-shadow:0 6px 0 #ffffff60;text-align:center;color:var(--game-text)}
.treasure-announcement>span{font:900 9px/1.4 Manrope,sans-serif;letter-spacing:.1em;color:var(--game-primary)}.treasure-announcement>strong{font:700 clamp(17px,4.5vw,23px)/1.15 Fredoka,Nunito,sans-serif;overflow-wrap:anywhere}.treasure-announcement>p{margin:0;max-width:43ch;font-size:11px;line-height:1.5;overflow-wrap:anywhere}
.treasure-rules{flex:none;margin:0 auto;max-width:42ch;text-align:center;font-size:9px;line-height:1.45;color:color-mix(in srgb,var(--game-text) 65%,transparent)}
#gameModal .treasure-game>.game-launch-button{flex:none;min-width:0;min-height:52px;width:min(100%,350px);margin:0 auto;padding:14px 18px;background:var(--game-primary);color:#fff;border:1px solid #ffffff50;border-radius:18px;font:900 11px/1.4 Manrope,sans-serif;letter-spacing:.06em;box-shadow:0 5px 0 color-mix(in srgb,var(--game-primary) 60%,#201234),0 9px 18px #2715371f;overflow-wrap:anywhere}
#gameModal .treasure-game>.game-launch-button[hidden]{display:none}
#gameModal .treasure-game .game-back{width:30px;height:30px;top:14px;left:12px;background:#fff9;color:var(--game-text)}
@keyframes treasureTwinkle{0%,100%{transform:translateY(0) rotate(-7deg);opacity:.6}50%{transform:translateY(-7px) rotate(9deg);opacity:1}}
@keyframes treasureRattle{0%,100%{transform:rotate(0)}22%{transform:translateY(-4px) rotate(-4deg)}45%{transform:translateY(-6px) rotate(4deg)}68%{transform:translateY(-3px) rotate(-2deg)}}
@keyframes treasureBurst{0%{opacity:0;transform:rotate(var(--angle)) translateY(0) scale(.4)}15%{opacity:1}80%{opacity:1}100%{opacity:0;transform:rotate(var(--angle)) translateY(-110px) rotate(140deg) scale(.5)}}
@media(max-width:700px){
  #gameModal:has(>.treasure-game){padding:0}
  #gameModal .game-dialog.treasure-game{width:100%;height:100dvh;min-height:100dvh;max-height:100dvh;border-radius:0;padding:calc(27px + env(safe-area-inset-top)) 16px calc(22px + env(safe-area-inset-bottom))}
  .treasure-chests{gap:9px}.treasure-caption strong{font-size:11px}
}
@media(max-height:700px){
  #gameModal .game-dialog.treasure-game{padding-top:20px;padding-bottom:15px}
  #gameModal .treasure-game>h2{font-size:26px;margin-bottom:8px}
  #gameModal .treasure-game>.game-instruction{font-size:11px;line-height:1.4}
  #gameModal .treasure-game #gameStage{margin:3px 0 9px}
  .treasure-experience{gap:9px}.treasure-scene{min-height:182px}
  .treasure-announcement{min-height:93px;padding:10px 12px;gap:5px}
  .treasure-announcement>strong{font-size:18px}.treasure-announcement>p{font-size:10px}
  .treasure-caption{min-height:55px;gap:3px}.treasure-caption small{font-size:8px}
  .treasure-chests{padding-top:4px}
  .treasure-number{width:21px;height:21px;font-size:9px}
  .treasure-scene-label{font-size:7px}.treasure-box{min-height:87px}
  #gameModal .treasure-game>.game-launch-button{min-height:46px;padding:11px}
}
@media(max-height:520px){
  #gameModal .game-dialog.treasure-game{overflow-y:auto}
  #gameModal .treasure-game #gameStage{flex:none;height:330px}
}
@media(prefers-reduced-motion:reduce){.treasure-game *{animation:none!important;transition-duration:.01ms!important}}

/* Only the entrance changes: keep the result theme, texts and buttons selected
   by the merchant. Higher specificity replaces, rather than stacks, old entrances. */
#resultModal.open[data-result-game="mystery-boxes"]>.result-card[data-result-style][data-outcome]{
  animation:treasureResultIn .65s cubic-bezier(.18,.75,.25,1) both!important;
  transform-origin:50% 55%;
}
#resultModal.open[data-result-game="mystery-boxes"]>.modal-backdrop{animation:treasureBackdropIn .4s ease-out both}
@keyframes treasureResultIn{
  0%{opacity:0;transform:translateY(28px) scale(.78)}
  68%{opacity:1;transform:translateY(-3px) scale(1.018)}
  100%{opacity:1;transform:translateY(0) scale(1)}
}
@keyframes treasureBackdropIn{from{opacity:0}to{opacity:1}}
@media(prefers-reduced-motion:reduce){
  #resultModal.open[data-result-game="mystery-boxes"]>.result-card[data-result-style][data-outcome]{animation:treasureBackdropIn .15s linear both!important}
  #resultModal.open[data-result-game="mystery-boxes"]>.modal-backdrop{animation:none}
}
