* { box-sizing: border-box; }
:root { color-scheme: dark; font-family: system-ui, sans-serif; }
body {
  margin: 0; min-height: 100svh; display: grid; grid-template-rows: 1fr auto;
  background: radial-gradient(ellipse at 50% 49%, #4b3424, #261b15 47%, #130e0b 86%);
  color: #f5ebd3;
}
main { min-width: 0; align-self: center; display: grid; justify-items: center; padding: 24px 12px 20px; }
.stage {
  --photograph: url("chest.jpg") center / 100% 100% no-repeat;
  width: min(100%, 960px); min-width: 0; aspect-ratio: 16 / 9; position: relative;
  container-type: inline-size; isolation: isolate;
  margin-top: clamp(28px, 7vw, 80px);
  background: radial-gradient(ellipse at 51% 0%, #72563c, #231914 51%, #0e0b0a 72%);
  box-shadow: 0 20px 65px #0b060780;
}
.scenery, .chest, .lid, .base, .velvet, .glow { position: absolute; inset: 0; }
.scenery {
  background: var(--photograph);
  clip-path: polygon(0 0, 12% 0, 8% 17%, 5% 39%, 5% 73%, 10.8% 73%, 10.8% 43%, 89.7% 43%, 89.7% 73%, 95% 73%, 95% 44%, 93% 24%, 86% 0, 100% 0, 100% 100%, 0 100%);
}
.base {
  background: var(--photograph);
  clip-path: polygon(10.75% 43%, 89.75% 43%, 89.75% 79%, 92% 87%, 8.3% 87%, 10.75% 78%);
  z-index: 5;
}
.lid { z-index: 2; }
.lid-shell {
  position: absolute; inset: 0;
  background: var(--photograph);
  clip-path: polygon(10.75% 43.5%,10.95% 33%,11.9% 24%,13.7% 17%,15.8% 12.5%,19.9% 12.2%,23% 14.7%,44% 14.7%,46% 13%,48% 11%,52% 11%,55% 14.6%,63% 14.6%,65% 12.6%,68% 12.4%,71% 14.8%,79% 14.7%,82% 12.3%,86% 13%,88% 19%,89.7% 34%,89.75% 43.5%);
}
#hinged-lid { display: none; position: absolute; width: 100%; height: 125%; top: -25%; }
.lid.moving #hinged-lid { display: block; }
.lid.moving .lid-shell { visibility: hidden; }
.velvet {
  inset: 25.5% 10.75% 56.3%;
  clip-path: polygon(6.8% 0,93.2% 0,100% 100%,0 100%);
  background: #260911;
}
.velvet::before, .velvet::after, .velvet i, .velvet b {
  content: ""; position: absolute; inset: 0;
}
.velvet::before {
  clip-path: polygon(6.8% 0,93.2% 0,83% 54%,17% 54%);
  background: linear-gradient(#853340,#470c20 20%,#20070f);
}
.velvet::after {
  clip-path: polygon(0 100%,17% 54%,83% 54%,100% 100%);
  background: linear-gradient(#1b060d,#69162c 65%,#351019 94%,#c68e53 97%);
}
.velvet i { clip-path: polygon(6.8% 0,17% 54%,0 100%); background: linear-gradient(105deg,#823447,#240711 24%); }
.velvet b { clip-path: polygon(93.2% 0,100% 100%,83% 54%); background: linear-gradient(255deg,#823447,#240711 24%); }
.glow {
  inset: 9% 16% 56%; opacity: 0; z-index: 2;
  background: radial-gradient(ellipse at 50% 97%,#ffd781b5, #f6bc5e3c 31%,transparent 65%);
  mix-blend-mode: screen; pointer-events: none;
}
/* The photo base above this layer occludes the parchment at the front rim. */
.scroll-opening {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  clip-path: inset(-22% 0 18% 0);
}
.scroll {
  position: absolute; left: 27%; top: -5%; width: 46%; height: 56%;
  transform: translateY(103%); pointer-events: none;
}
.paper {
  position: absolute; inset: 4% 2% 0; display: grid; place-items: center;
  text-align: center; padding: 6% 8% 19%;
  border-top: 1px solid #b27e47; border-radius: 5% 5% 0 0;
  background: radial-gradient(ellipse at center,#fff2ce 25%,#eacd95 73%,#af773e);
  clip-path: inset(0 0 100% 0);
}
.paper p { margin: 0; color: #302015; font: 600 clamp(16px,4.15cqw,33px)/1.12 Georgia,serif; }
.scroll-roll {
  position: absolute; left: 0; right: 0; top: 0; height: 9%;
  border-radius: 8% / 45%;
  background: linear-gradient(#9b6133,#ebca93 25%,#fff0c7 42%,#bc8950 75%,#73451e);
  box-shadow: 0 2px 5px #2b180d80;
}
.stage.opening .chest, .stage.opening .base { animation: shudder 380ms ease-in-out both; }
.stage.opening .glow { animation: glow 900ms 500ms ease-out both; }
.stage.opening .scroll { animation: rise 620ms 1530ms cubic-bezier(.32,.12,.28,1) both; }
.stage.opening .paper { animation: unroll 530ms 2080ms cubic-bezier(.22,.63,.24,1) both; }
.stage.opening .scroll-roll { animation: roll-down 530ms 2080ms cubic-bezier(.22,.63,.24,1) both; }
@keyframes shudder {
  23%, 68% { transform: rotate(-.65deg); }
  46% { transform: rotate(.65deg); }
}
@keyframes glow { 60% { opacity: .72; } to { opacity: .45; } }
@keyframes rise { to { transform: translateY(0); } }
@keyframes unroll { to { clip-path: inset(0); } }
@keyframes roll-down { to { top: 91%; } }
@media (max-width: 520px) {
  main { padding-inline: 0; }
  .stage { width: 100%; }
  .scroll { left: 19%; width: 62%; }
}
.controls { min-height: 56px; display: grid; place-items: center; margin-top: 22px; }
button {
  border: 1px solid #f1ce91; border-radius: 6px; min-height: 52px; padding: 12px 24px;
  background: linear-gradient(#f6dba4,#d2a366); color: #281b12;
  font: 650 1rem/1.25 system-ui, sans-serif; box-shadow: 0 4px 16px #0004; cursor: pointer;
}
button:hover { background: #f5d99f; }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid #fff3d4; outline-offset: 5px; }
button[hidden] { display: none; }
#retry { animation: appear 180ms ease-out both; }
@keyframes appear { from { opacity: 0; } }
footer { text-align: center; font-size: .75rem; color: #d8c3af; padding: 0 12px max(16px, env(safe-area-inset-bottom)); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; }
}
