/* All positions on the set use the same 1024 × 1536 artwork coordinates. */
.world {
  position: absolute;
  z-index: 0;
  inset: 0;
  overflow: hidden;
  overflow: clip;
  container-type: size;
}

.jungle-set {
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(100%, calc(100cqh * 2 / 3));
  aspect-ratio: 2 / 3;
  transform: translate(-50%, -50%);
}

.jungle, .scene-shade { position: absolute; inset: 0; width: 100%; height: 100%; }
.scene-shade {
  z-index: 5;
  pointer-events: none;
  background: linear-gradient(180deg, #021212ba, #02121230 26%, transparent 43%, transparent 70%, #03130faa 86%, #071c17);
}

.stone-door {
  --door-x: .338;
  --door-y: .244;
  --door-width: .328;
  --door-height: .2105;
  position: absolute;
  top: calc(100% * var(--door-y));
  left: calc(100% * var(--door-x));
  width: calc(100% * var(--door-width));
  height: calc(100% * var(--door-height));
  pointer-events: none;
}

.doorway {
  position: absolute;
  inset: 0;
  overflow: hidden;
  clip-path: ellipse(50% 50%);
  isolation: isolate;
  visibility: hidden;
}

[data-doors-open] .doorway { visibility: visible; }
.tunnel {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 12px 4px #090904, inset 0 5px 10px 5px #140d07;
  background:
    radial-gradient(ellipse at 50% 48%, #1a261c 9%, #201e13 41%, #594427 68%, #21170d 82%);
}
.tunnel::after {
  position: absolute;
  inset: 56% 5% 0;
  clip-path: polygon(39% 0, 61% 0, 100% 100%, 0 100%);
  background: repeating-linear-gradient(0deg, #553c25 0 3%, #170f08 4% 6%, #38291a 7% 19%);
  opacity: .78;
  content: "";
}
.stone-door::after {
  position: absolute;
  inset: 91% -15% -85%;
  background: radial-gradient(ellipse at 50% 8%, #ffc661b3, #e797353b 38%, transparent 67%);
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity .62s ease;
  content: "";
}

.door-leaf {
  position: absolute;
  inset: 0;
  background-image: url("./public/jungle-ruins.webp");
  background-repeat: no-repeat;
  background-size: calc(100% / var(--door-width)) calc(100% / var(--door-height));
  background-position:
    calc(100% * var(--door-x) / (1 - var(--door-width)))
    calc(100% * var(--door-y) / (1 - var(--door-height)));
  transition: transform var(--door-duration, 920ms) cubic-bezier(.68, .04, .2, 1);
}
.door-left { clip-path: inset(0 49.9% 0 0); }
.door-right { clip-path: inset(0 0 0 50%); }
[data-doors-open] .door-left { transform: translateX(-51%); }
[data-doors-open] .door-right { transform: translateX(51%); }

.guardian, .runner {
  position: absolute;
  z-index: 3;
  top: 76%;
  left: 52%;
  width: 51%;
  transform: translate(-50%, -100%);
  transform-origin: 50% 91%;
}
.guardian {
  left: 61%;
  width: 59%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .17s ease, transform .2s ease;
}
.guardian img { display: block; width: 100%; height: auto; filter: brightness(1.12) drop-shadow(0 9px 8px #0009); }
[data-state="ready"] .guardian img {
  filter:
    brightness(1.12)
    drop-shadow(1.4px 0 #ffd981)
    drop-shadow(-1.4px 0 #ffd981)
    drop-shadow(0 1.4px #ffd981)
    drop-shadow(0 -1.4px #ffd981)
    drop-shadow(0 0 8px #ffcc6b8c)
    drop-shadow(0 9px 8px #0009);
}
.guardian:active { transform: translate(-50%, -100%) scale(.97); }
.guardian:disabled { cursor: default; }
.guardian-cue {
  position: absolute;
  z-index: 1;
  top: 58%;
  left: 25%;
  translate: -50% 0;
  display: grid;
  justify-items: center;
  row-gap: 7px;
  pointer-events: none;
}
.guardian-cue-ring {
  position: relative;
  display: grid;
  width: clamp(36px, 9vw, 46px);
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid #fff1b1;
  border-radius: 50%;
  background: #0b231999;
  box-shadow: 0 0 16px #ffc96378, inset 0 0 12px #ffe4a73d;
}
.guardian-cue-ring::before {
  position: absolute;
  inset: -2px;
  border: 2px solid #ffde8d;
  border-radius: inherit;
  opacity: 0;
  content: "";
  animation: guardian-tap-ring 1.65s ease-out 3;
}
.guardian-cue-ring::after {
  width: 9px;
  aspect-ratio: 1;
  rotate: 45deg;
  border: 1px solid #fff7d3;
  border-radius: 1px;
  background: #f4d37d;
  box-shadow: 0 0 9px #ffe589b3;
  content: "";
}
.guardian-cue-hand {
  position: absolute;
  z-index: 1;
  top: 42%;
  left: 67%;
  width: clamp(25px, 6.6vw, 32px);
  aspect-ratio: 4 / 5;
  transform: rotate(-23deg);
  filter: drop-shadow(1px 2px 0 #241d12) drop-shadow(-1px 0 0 #241d12);
  animation: guardian-finger-tap 1.65s ease-in-out 3;
}
.guardian-cue-hand::before {
  position: absolute;
  inset: 0;
  background: linear-gradient(#fff8dd 24%, #ffe7a8 72%, #e4b965);
  clip-path: polygon(33% 0, 42% 0, 49% 6%, 51% 12%, 51% 40%, 58% 35%, 66% 35%, 72% 40%, 78% 38%, 85% 38%, 91% 45%, 96% 45%, 100% 51%, 100% 72%, 93% 85%, 85% 91%, 85% 100%, 40% 100%, 40% 91%, 28% 83%, 7% 62%, 3% 53%, 8% 47%, 16% 46%, 23% 50%, 31% 59%, 28% 12%, 29% 5%);
  content: "";
}
.guardian-cue-label {
  padding: 5px 10px;
  border: 1px solid #c8a35f;
  border-radius: 4px;
  background: #0b251cee;
  box-shadow: 0 2px 8px #000a;
  color: #fff2c8;
  font-family: "Barlow Condensed", Impact, sans-serif;
  font-size: clamp(12px, 3vw, 15px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: .09em;
  white-space: nowrap;
}
.guardian:is(:hover, :focus-visible):not(:disabled) .guardian-cue-ring {
  background: #2d624fbb;
  box-shadow: 0 0 22px #ffdf8cab, inset 0 0 12px #ffe4a753;
}
[data-state]:not([data-state="ready"]) .guardian-cue { display: none; }

@keyframes guardian-tap-ring {
  0% { opacity: .9; transform: scale(1); }
  68%, 100% { opacity: 0; transform: scale(1.64); }
}
@keyframes guardian-finger-tap {
  0%, 100% { transform: translate(4px, 4px) rotate(-23deg); }
  25%, 39% { transform: translate(-5px, -4px) rotate(-23deg) scale(.92); }
  60% { transform: rotate(-23deg); }
}

.eye-flare {
  position: absolute;
  inset: 0;
  opacity: 0;
  background:
    radial-gradient(ellipse 3.5% 3.5% at 18.1% 27.5%, #fff5af 8%, #ffd767bb 34%, transparent 83%),
    radial-gradient(ellipse 3.5% 3.5% at 30.6% 27.5%, #fff5af 8%, #ffd767bb 34%, transparent 83%);
  filter: drop-shadow(0 0 8px #e6ff98);
  transition: opacity .16s ease;
}
[data-state="awakening"] .eye-flare, [data-state="opening"] .eye-flare { opacity: 1; }
[data-state="awakening"] .jungle-set, [data-state="opening"] .jungle-set { animation: stone-tremor .34s ease-in-out 2; }
[data-state="awakening"] .guardian { transform: translate(-50%, -100%) scale(1.035); }
[data-state="running"] .guardian, [data-state="found"] .guardian { opacity: 0; pointer-events: none; }
[data-state="running"] .guardian { transform: translate(-50%, -100%) scale(.96) rotate(-4deg); }
.runner { width: 49%; opacity: 0; pointer-events: none; }
.runner::before {
  position: absolute;
  inset: auto 19% 1% 18%;
  height: 21%;
  border-radius: 50%;
  background: radial-gradient(ellipse, #030e0dcc, transparent 68%);
  content: "";
}
.run-pose {
  position: relative;
  aspect-ratio: 59 / 48;
  background: url("./public/jaguar-gallop.webp") 0 0 / 200% 200% no-repeat;
  filter: drop-shadow(0 4px 3px #0007);
}
[data-state="running"] .runner { animation: jaguar-sprint var(--run-duration, 1260ms) linear both; }
[data-state="running"] .run-pose { animation: jaguar-gallop .42s steps(1) infinite; }

.treasure {
  position: absolute;
  inset: 16% 8% 8%;
  opacity: 0;
  transition: opacity .17s ease;
}
.treasure-light {
  position: absolute;
  inset: 0 -16% -8%;
  background: radial-gradient(ellipse at 50% 61%, #fff0a9de 8%, #ffb83a70 39%, transparent 69%);
  opacity: .55;
}
.treasure-rays {
  position: absolute;
  inset: -12% -16% -4%;
  background: repeating-conic-gradient(from -15deg at 50% 62%, #ffe7a065 0deg 8deg, transparent 12deg 28deg, #fff0a69c 31deg 34deg, transparent 37deg 52deg);
  mask-image: radial-gradient(ellipse at 50% 61%, #000 11%, #000a 35%, transparent 67%);
  mix-blend-mode: screen;
  opacity: 0;
  transform-origin: 50% 62%;
}
.treasure-display {
  position: absolute;
  bottom: 7%;
  left: 50%;
  width: 69.5%;
  aspect-ratio: 1;
  translate: -50% 0;
}
.treasure-chest {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 5px 5px #100b04) drop-shadow(0 0 7px #e59f3d55);
}
.chest-shimmer {
  position: absolute;
  inset: 24% 12% 45%;
  background: linear-gradient(106deg, transparent 43%, #fff1a987 50%, transparent 57%) 100% 0 / 235% 100%;
  mask-image: radial-gradient(ellipse at 50% 64%, #000 25%, #000b 49%, transparent 73%);
  mix-blend-mode: screen;
  opacity: 0;
}
.chest-glint {
  position: absolute;
  z-index: 1;
  width: 13%;
  aspect-ratio: 1;
  translate: -50% -50%;
  filter: drop-shadow(0 0 4px #ffc653);
  opacity: 0;
}
.chest-glint::before {
  position: absolute;
  inset: 0;
  background: #fff5b7;
  clip-path: polygon(50% 0, 59% 41%, 100% 50%, 59% 59%, 50% 100%, 41% 59%, 0 50%, 41% 41%);
  content: "";
}
.glint-left { top: 39.5%; left: 24.5%; --delay: .26s; }
.glint-right { top: 38.4%; left: 78%; --delay: .72s; }
[data-state="found"] .treasure { opacity: 1; }
[data-state="found"] .stone-door::after {
  opacity: .72;
  animation: treasure-reflection 2.2s ease-in-out infinite;
}
[data-state="found"] .treasure-light { animation: treasure-glow 2.2s ease-in-out infinite; }
[data-state="found"] .treasure-rays { animation: treasure-rays 2.2s ease-in-out infinite; }
[data-state="found"] .treasure-display { animation: treasure-appear .62s cubic-bezier(.18,.72,.24,1) both; }
[data-state="found"] .chest-shimmer { animation: chest-shimmer 2.2s ease-out .22s infinite; }
[data-state="found"] .chest-glint { animation: chest-glint 2.2s ease-out var(--delay) infinite; }

@keyframes treasure-glow {
  0%, 100% { opacity: .36; transform: scale(.9); }
  34% { opacity: .94; transform: scale(1.12); }
}
@keyframes treasure-rays {
  0%, 100% { opacity: .16; transform: scale(.89) rotate(-10deg); }
  38% { opacity: .85; transform: scale(1.08) rotate(12deg); }
}
@keyframes treasure-reflection {
  0%, 100% { opacity: .32; transform: scaleX(.92); }
  40% { opacity: 1; transform: scaleX(1.1); }
}
@keyframes treasure-appear {
  from { opacity: 0; transform: translateY(11%) scale(.85); }
  to { opacity: 1; transform: none; }
}
@keyframes chest-shimmer {
  0% { opacity: 0; background-position: 100% 0; }
  15% { opacity: .92; }
  43%, 100% { opacity: 0; background-position: 0 0; }
}
@keyframes chest-glint {
  0% { opacity: 0; transform: scale(.12) rotate(-18deg); }
  17% { opacity: 1; transform: scale(1.08) rotate(0deg); }
  36%, 100% { opacity: 0; transform: scale(.35) rotate(18deg); }
}
@media (prefers-reduced-motion: reduce) {
  [data-state="found"] :is(.treasure-light, .treasure-rays, .chest-shimmer, .chest-glint),
  [data-state="found"] .stone-door::after { animation: none; }
  [data-state="found"] .treasure-rays { opacity: .2; }
}

@keyframes stone-tremor {
  0%, 100% { transform: translate(-50%, -50%); }
  22% { transform: translate(calc(-50% - 3px), calc(-50% + 1px)); }
  57% { transform: translate(calc(-50% + 3px), calc(-50% - 1px)); }
  78% { transform: translate(calc(-50% - 1px), -50%); }
}

@keyframes jaguar-sprint {
  0%   { top: 76%; left: 58%; opacity: 0; transform: translate(-50%, -100%) scale(.98); }
  12%  { top: 74%; left: 57.6%; opacity: 1; transform: translate(-50%, -100%) scale(.93); }
  34%  { top: 66%; left: 55.4%; transform: translate(-50%, -100%) scale(.77); }
  62%  { top: 54%; left: 51.9%; transform: translate(-50%, -100%) scale(.52); }
  84%  { top: 45%; left: 50.4%; transform: translate(-50%, -100%) scale(.33); }
  93%  { top: 42%; left: 50.2%; opacity: .95; transform: translate(-50%, -100%) scale(.25); }
  100% { top: 40%; left: 50.2%; opacity: 0; transform: translate(-50%, -100%) scale(.18); }
}

@keyframes jaguar-gallop {
  0% { background-position: 0 0; }
  25% { background-position: 100% 0; }
  50% { background-position: 0 100%; }
  75% { background-position: 100% 100%; }
}
