/* ผิววัตถุมีด้านนอก ด้านใน และขอบความหนา แยกจากกรอบ UI */
.ritual-workspace[data-ritual="chest"],.ritual-workspace[data-ritual="envelope"] { filter: none; }
.solid-chest,.chest-shell,.solid-lid,.layered-envelope,.solid-flap { transform-style: preserve-3d; }
.ceremony[data-presentation="chest"] .scene-heading p,.ceremony[data-presentation="envelope"] .scene-heading p { max-width: 190px; }
.solid-chest { position: absolute; width: 300px; height: 210px; left: calc(50% - 150px); bottom: 56px; transform: rotateX(-19deg) rotateY(-18deg); pointer-events: none; }
.chest-shell { position: absolute; left: 0; top: 94px; width: 300px; height: 116px; }
.chest-wall { position: absolute; width: 300px; height: 116px; border: 2px solid #5a3f27; background: #352215 url('assets/rituals/chest.webp') center -172px / 330px 330px no-repeat; backface-visibility: hidden; box-shadow: inset 0 0 14px #0007; }
.wall-front { transform: translateZ(70px); }
.wall-back { transform: rotateY(180deg) translateZ(70px); }
.wall-left,.wall-right { width: 140px; left: 80px; background-size: 230px 330px; }
.wall-left { transform: rotateY(-90deg) translateZ(150px); }
.wall-right { transform: rotateY(90deg) translateZ(150px); }
.chest-shell::before { content: ''; position: absolute; inset: 0; background: linear-gradient(#21100b,#42291b); transform: translateZ(-68px); box-shadow: inset 0 7px 14px #000c; }
.chest-rim { position: absolute; width: 300px; height: 140px; top: -70px; border: 8px solid #63482e; border-top-color: #897047; border-left-color: #9d7e4c; border-radius: 5px; transform: rotateX(90deg); box-shadow: inset 0 0 0 2px #1b110d,0 0 0 1px #b08d5060; }
.chest-floor { position: absolute; width: 284px; height: 124px; left: 8px; top: -62px; background: radial-gradient(ellipse at 50% 55%,#402021,#1c0d10 78%); transform: rotateX(90deg) translateZ(-104px); border: 2px solid #180d0a; box-shadow: inset 0 0 22px 10px #000c; }
.well-shadow,.well-light { position: absolute; inset: 0; display: block; }
.well-shadow { background: linear-gradient(#000e 10%,#000a 70%,transparent); }
.chest-open .well-shadow { animation: well-shadow-open 1.55s ease both; }
.well-light { opacity: 0; background: radial-gradient(ellipse,var(--rarity-glow),transparent 68%); }
.rarity-awaken .well-light { animation: inside-reward-light 1.3s ease both; }
.solid-lid { position: absolute; left: 0; top: 94px; width: 300px; height: 140px; transform-origin: 50% 0; transform: translateZ(-70px) rotateX(90deg); }
.lid-outer,.lid-inner { position: absolute; inset: 0; border-radius: 8px; backface-visibility: hidden; }
.lid-outer { transform: translateZ(6px); background: #501d20 url('assets/rituals/chest.webp') center -95px / 330px 500px no-repeat; border: 3px solid #96743f; box-shadow: inset 0 0 0 2px #392317,inset 0 0 24px #0008; }
.lid-outer::before,.lid-outer::after { content: ''; position: absolute; inset: 0 18px; border-left: 7px solid #9f7d49; border-right: 7px solid #9f7d49; box-shadow: inset 1px 0 #d9b77455,1px 0 #2d1b0e; }
.lid-outer::after { inset: 0 auto 0 calc(50% - 4px); width: 8px; border: 0; background: linear-gradient(90deg,#52321d,#bd9857,#54341e); }
.lid-inner { transform: rotateY(180deg) translateZ(6px); background: linear-gradient(110deg,#402026,#6a3536 50%,#2b151a); border: 9px solid #4b3222; box-shadow: inset 0 0 0 1px #aa885454,inset 0 0 20px #0009; }
.lid-inner span { position: absolute; inset: 12px; border-radius: 7px; background: linear-gradient(#6f414033,#21101588),url('assets/rituals/envelope.webp') center -80px / 640px 425px; box-shadow: inset 0 2px 9px #0009,0 1px #bd916b33; border: 1px dashed #ad82714d; }
.lid-inner::after { content: ''; position: absolute; inset: 0; background: linear-gradient(0deg,#000b,transparent 80%); animation: lid-shade-open 1.55s ease both paused; }
.chest-open .lid-inner::after { animation-play-state: running; }
.lid-edge { position: absolute; background: linear-gradient(#9e7b48,#4b2c19 45%,#b28a51 75%,#50311c); box-shadow: inset 0 0 0 1px #d3ab6844; }
.edge-front,.edge-back { left: 0; width: 300px; height: 12px; top: 134px; transform: rotateX(90deg); }
.edge-back { top: -6px; }
.edge-left,.edge-right { width: 12px; height: 140px; top: 0; left: -6px; transform: rotateY(90deg); }
.edge-right { left: 294px; }
.chest-clasp { position: absolute; width: 22px; height: 41px; left: calc(50% - 11px); top: -6px; border-radius: 4px 4px 9px 9px; background: linear-gradient(90deg,#5c4124,#be9c60 38%,#856034 85%); border: 1px solid #4c301b; transform-origin: 50% 3px; box-shadow: 1px 3px 4px #0009; }
.chest-clasp::after { content: ''; position: absolute; width: 4px; height: 12px; border-radius: 50%; left: 8px; bottom: 7px; background: #38251a; }
.chest-unlatching .chest-clasp { animation: clasp-release .5s ease both; }
.hinge { position: absolute; top: 90px; left: 45px; width: 34px; height: 9px; border-radius: 4px; background: repeating-linear-gradient(90deg,#4d341f 0 3px,#b49364 4px 7px); transform: translateZ(-68px); }
.hinge-right { left: 221px; }
.object-ground-shadow { position: absolute; width: 330px; height: 36px; left: calc(50% - 165px); bottom: 2px; border-radius: 50%; background: radial-gradient(ellipse,#000c,transparent 70%); pointer-events: none; }
.chest-open .chest-ground-shadow { animation: cast-shadow-open 1.55s ease both; }

/* ฝาซองพับรอบรอยต่อเดิม มีผิวด้านหลังและชั้นกระดาษหนา 3 พิกเซล */
.layered-envelope { position: absolute; width: 330px; height: 230px; left: calc(50% - 165px); bottom: 22px; transform: rotate(-5deg) rotateY(-5deg); pointer-events: none; }
.envelope-lining { position: absolute; inset: 10% 5% 7%; transform: translateZ(0); border-radius: 5px; background: radial-gradient(ellipse at 50% 25%,#8a4140,#411b21 65%,#1e1014); border: 2px solid #b58a644d; box-shadow: inset 0 -15px 30px #000a; }
.pocket-front { position: absolute; inset: 0; transform: translateZ(9px); clip-path: polygon(0 0,3% 9%,50% 74%,97% 9%,100% 0,100% 100%,0 100%); }
.pocket-front img,.flap-outer img { width: 100%; height: 100%; object-fit: contain; }
.pocket-lip { position: absolute; inset: 0; transform: translateZ(8px); clip-path: polygon(3% 10%,50% 75%,97% 10%,97% 12%,50% 77%,3% 12%); background: #bd9271; opacity: .7; }
.pocket-shadow { position: absolute; inset: 10% 5% 7%; transform: translateZ(2px); background: linear-gradient(#000c,transparent 70%); }
.envelope-open .pocket-shadow { animation: envelope-shadow-open 1.2s ease both; }
.solid-flap { position: absolute; inset: 0; transform-origin: 50% 12%; transform: translateZ(12px); }
.flap-outer,.flap-inner,.flap-edge-paper { position: absolute; inset: 0; clip-path: polygon(3% 9%,97% 9%,95% 29%,50% 74%,5% 29%); }
.flap-outer { backface-visibility: hidden; transform: translateZ(1.5px); }
.flap-inner { backface-visibility: hidden; transform: rotateY(180deg) translateZ(1.5px); background: linear-gradient(#4a222433,#1d121455),#673134 url('assets/rituals/envelope.webp') center -30px / 660px 460px; box-shadow: inset 0 28px 18px #0005; }
.flap-inner::after { content: ''; position: absolute; inset: 0; background: linear-gradient(0deg,transparent,#0009); animation: envelope-shadow-open 1.2s ease both paused; }
.envelope-open .flap-inner::after { animation-play-state: running; }
.flap-edge-paper { background: #bd9271; }
.edge-paper-one { transform: translateZ(-.5px); }
.edge-paper-two { transform: translateZ(-1.5px); background: #704338; }
.layered-envelope .reward-letter { inset: 31px 34px 27px; transform: translateZ(5px); border: 2px solid #9c8460; background: linear-gradient(130deg,#bba783,#e0cc9f 45%,#c1a67b); box-shadow: 0 2px 2px #4f341b,inset 0 0 0 6px #5c382615; color: #493326; opacity: 0; }
.envelope-open .reward-letter { opacity: 1; transition: opacity .5s .5s; }
.layered-envelope .reward-letter small { font-size: 10px; }
.wax-seal { position: absolute; left: calc(50% - 28px); top: 115px; width: 56px; height: 54px; display: grid; place-items: center; border-radius: 46% 43% 45% 48%; transform: translateZ(18px); background: radial-gradient(at 30% 25%,#96332e,#5d151c 68%,#330d13); border: 2px solid #9c4d43; box-shadow: 1px 4px 3px #0008,inset 0 0 0 4px #4310149c; color: #c78d71; font-size: 26px; }
.wax-releasing .wax-seal { animation: wax-lift-away .65s ease both; }
.rarity-awaken .envelope-lining { box-shadow: inset 0 0 25px var(--rarity-glow); }
.rarity-awaken .layered-envelope .reward-letter { background: linear-gradient(130deg,#8f7659,color-mix(in srgb,var(--rarity) 55%,#cdb58c)); color: #35251f; }
.envelope-open .envelope-ground-shadow { animation: cast-shadow-open 1.2s ease both; }
@keyframes clasp-release { to { transform: rotateX(-65deg); } }
@keyframes well-shadow-open { from { opacity: .96; } to { opacity: .28; } }
@keyframes lid-shade-open { from { opacity: 1; } to { opacity: .3; } }
@keyframes inside-reward-light { 0% { opacity: 0; } 35% { opacity: .9; } 100% { opacity: .25; } }
@keyframes cast-shadow-open { from { transform: scaleX(.95); opacity: .7; } to { transform: translate(12px,-4px) scaleX(1.1); opacity: .9; } }
@keyframes envelope-shadow-open { from { opacity: 1; } to { opacity: .22; } }
@keyframes wax-lift-away { to { transform: translate(43px,25px) translateZ(18px) rotate(22deg); opacity: .18; } }
@media(max-height:800px) { .solid-chest { bottom: 58px; transform: rotateX(-19deg) rotateY(-18deg) scale(.86); transform-origin: 50% 100%; } .layered-envelope { bottom: 7px; transform: rotate(-5deg) rotateY(-5deg) scale(.88); transform-origin: 50% 100%; } }
@media(prefers-reduced-motion:reduce) { .well-shadow,.lid-inner::after,.well-light,.object-ground-shadow,.chest-clasp,.pocket-shadow,.flap-inner::after,.wax-seal { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }
