/* Treasure chests (Treetops and City View): when the ghost reaches a chest, the lid pops open, warm light glows
   from inside, and a little burst rises out of the chest and fades, like the confetti when the sleeping elephant wakes.
   - Treetops (night sky): glowing stars and sparkles.
   - City View: fruit, as emoji: pineapple, apple, grapes, melon, lemon, cherries.
   The ghost floats up a little so it no longer hides behind the chest. The lid closes again when the ghost leaves.
   No markup changes: the six existing fireflies (.fly) become the burst. Classic and Forest are unchanged. */

.forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .discovery .treasure {
  overflow: visible;
}
.forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .discovery .treasure-lid {
  transform-box: view-box;
  transform-origin: 5px 14px;
  transition: transform .5s cubic-bezier(.3, 1.6, .5, 1);
}
.forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .discovery:is(.is-revealed, :has(.light-call:focus-visible)) .treasure-lid {
  transform: translate(-1px, -2px) rotate(-30deg);
}

/* Warm light from the open chest */
.forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .discovery .light-call::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 34px;
  margin: -21px 0 0 -23px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 240, 170, .95), rgba(255, 214, 110, .45) 55%, rgba(255, 214, 110, 0));
  opacity: 0;
  scale: .3;
  transition: opacity .4s ease, scale .5s cubic-bezier(.3, 1.5, .5, 1);
  pointer-events: none;
  z-index: -1;
}
.forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .discovery:is(.is-revealed, :has(.light-call:focus-visible)) .light-call::before {
  opacity: 1;
  scale: 1;
}

/* The ghost rises a little while a chest is open, so it floats above the chest instead of behind it */
.forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections .spirit-wrap {
  transition: translate .45s cubic-bezier(.3, 1.4, .5, 1);
}
.forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections:has(.discovery.is-revealed) .spirit-wrap {
  translate: 0 -26px;
}

/* The burst: the six fireflies pop out of the chest, rise and fade */
@media (prefers-reduced-motion: no-preference) {
  body.motion-enabled .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections:not(.still) .discovery.is-revealed .fireflies {
    opacity: 1;
  }
  body.motion-enabled .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections:not(.still) .discovery.is-revealed .fly {
    left: 50%;
    top: 57%;
    width: var(--piece, 11px);
    height: var(--piece, 11px);
    margin: calc(var(--piece, 11px) / -2) 0 0 calc(var(--piece, 11px) / -2);
    border-radius: 0;
    background: var(--shape, none) center / contain no-repeat;
    box-shadow: none;
    transform: none;
    transition: none;
    animation: chest-burst 1.5s var(--delay, 0s) cubic-bezier(.2, .8, .3, 1) both;
  }
  body.motion-enabled .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections:not(.still) .discovery.is-revealed .fly-1 { --dx: 0px; --dy: -46px; --r: -8deg; --delay: 0s; }
  body.motion-enabled .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections:not(.still) .discovery.is-revealed .fly-2 { --dx: -28px; --dy: -31px; --r: -22deg; --delay: .05s; }
  body.motion-enabled .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections:not(.still) .discovery.is-revealed .fly-3 { --dx: 28px; --dy: -35px; --r: 16deg; --delay: .08s; }
  body.motion-enabled .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections:not(.still) .discovery.is-revealed .fly-4 { --dx: -15px; --dy: -57px; --r: -6deg; --delay: .12s; }
  body.motion-enabled .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections:not(.still) .discovery.is-revealed .fly-5 { --dx: 17px; --dy: -58px; --r: 18deg; --delay: .15s; }
  body.motion-enabled .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections:not(.still) .discovery.is-revealed .fly-6 { --dx: 37px; --dy: -15px; --r: 12deg; --delay: .1s; }

  /* Treetops: stars and sparkles that glow against the night sky */
  body.motion-enabled .forest-stage[data-scene="treetop"] .connections:not(.still) .discovery.is-revealed .fly {
    filter: drop-shadow(0 0 3px rgba(255, 242, 190, .85));
  }
  body.motion-enabled .forest-stage[data-scene="treetop"] .connections:not(.still) .discovery.is-revealed .fly-1 { --shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 1.8l2.9 6.4 6.9.7-5.2 4.7 1.5 6.8L12 16.9l-6.1 3.5 1.5-6.8L2.2 8.9l6.9-.7z' fill='%23ffe066'/%3E%3C/svg%3E"); --piece: 12px; }
  body.motion-enabled .forest-stage[data-scene="treetop"] .connections:not(.still) .discovery.is-revealed .fly-2 { --shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 .8c.9 5.8 5.4 10.3 11.2 11.2-5.8.9-10.3 5.4-11.2 11.2C11.1 17.4 6.6 12.9.8 12 6.6 11.1 11.1 6.6 12 .8z' fill='%23fff8e1'/%3E%3C/svg%3E"); --piece: 10px; }
  body.motion-enabled .forest-stage[data-scene="treetop"] .connections:not(.still) .discovery.is-revealed .fly-3 { --shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 1.8l2.9 6.4 6.9.7-5.2 4.7 1.5 6.8L12 16.9l-6.1 3.5 1.5-6.8L2.2 8.9l6.9-.7z' fill='%23ffd27a'/%3E%3C/svg%3E"); --piece: 11px; }
  body.motion-enabled .forest-stage[data-scene="treetop"] .connections:not(.still) .discovery.is-revealed .fly-4 { --shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 .8c.9 5.8 5.4 10.3 11.2 11.2-5.8.9-10.3 5.4-11.2 11.2C11.1 17.4 6.6 12.9.8 12 6.6 11.1 11.1 6.6 12 .8z' fill='%23fff3b0'/%3E%3C/svg%3E"); --piece: 9px; }
  body.motion-enabled .forest-stage[data-scene="treetop"] .connections:not(.still) .discovery.is-revealed .fly-5 { --shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 1.8l2.9 6.4 6.9.7-5.2 4.7 1.5 6.8L12 16.9l-6.1 3.5 1.5-6.8L2.2 8.9l6.9-.7z' fill='%23fff8e1'/%3E%3C/svg%3E"); --piece: 9px; }
  body.motion-enabled .forest-stage[data-scene="treetop"] .connections:not(.still) .discovery.is-revealed .fly-6 { --shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 .8c.9 5.8 5.4 10.3 11.2 11.2-5.8.9-10.3 5.4-11.2 11.2C11.1 17.4 6.6 12.9.8 12 6.6 11.1 11.1 6.6 12 .8z' fill='%23ffe066'/%3E%3C/svg%3E"); --piece: 8px; }

  /* City View: fruit emoji */
  body.motion-enabled .forest-stage[data-scene="nyc"] .connections:not(.still) .discovery.is-revealed .fly {
    --piece: 14px;
    background: none;
    filter: drop-shadow(0 1px 1px rgba(40, 20, 40, .35));
  }
  body.motion-enabled .forest-stage[data-scene="nyc"] .connections:not(.still) .discovery.is-revealed .fly::before {
    content: var(--fruit);
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font: 400 var(--piece)/1 "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  }
  body.motion-enabled .forest-stage[data-scene="nyc"] .connections:not(.still) .discovery.is-revealed .fly-1 { --fruit: "\1F34D"; }
  body.motion-enabled .forest-stage[data-scene="nyc"] .connections:not(.still) .discovery.is-revealed .fly-2 { --fruit: "\1F34E"; }
  body.motion-enabled .forest-stage[data-scene="nyc"] .connections:not(.still) .discovery.is-revealed .fly-3 { --fruit: "\1F347"; }
  body.motion-enabled .forest-stage[data-scene="nyc"] .connections:not(.still) .discovery.is-revealed .fly-4 { --fruit: "\1F348"; }
  body.motion-enabled .forest-stage[data-scene="nyc"] .connections:not(.still) .discovery.is-revealed .fly-5 { --fruit: "\1F34B"; }
  body.motion-enabled .forest-stage[data-scene="nyc"] .connections:not(.still) .discovery.is-revealed .fly-6 { --fruit: "\1F352"; }
}

@keyframes chest-burst {
  0% { translate: 0 0; scale: .2; rotate: 0deg; opacity: 0; }
  14% { opacity: 1; }
  58% { translate: var(--dx) var(--dy); scale: 1; rotate: var(--r); opacity: 1; }
  100% { translate: calc(var(--dx) * 1.15) calc(var(--dy) - 12px); scale: .85; rotate: var(--r); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .discovery .treasure-lid,
  .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .discovery .light-call::before,
  .forest-stage:is([data-scene="treetop"], [data-scene="nyc"]) .connections .spirit-wrap {
    transition: none;
  }
}
