.sunset-scene-page {
  background: linear-gradient(#d6a6b8, #f6d4a6 30%, #a8ad77 31%);
}

.scene-stage {
  display: grid;
  place-items: center;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.scene-view {
  position: relative;
  width: min(100%, calc(100vh * var(--scene-width) / var(--scene-height)));
  width: min(100%, calc(100dvh * var(--scene-width) / var(--scene-height)));
  aspect-ratio: var(--scene-width) / var(--scene-height);
}

/* Keep the animated composition centered inside the wider artwork. */
.scene-view--landscape {
  --scene-width: 450;
  --scene-height: 300;
  --art-width: 1080;
  --art-height: 450;
}

.scene-view--portrait {
  --scene-width: 244;
  --scene-height: 416;
  --art-width: 440;
  --art-height: 704;
  display: none;
}

.scene-view img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.scene-view > img {
  position: absolute;
  top: calc((var(--scene-height) - var(--art-height)) * 50% / var(--scene-height));
  left: calc((var(--scene-width) - var(--art-width)) * 50% / var(--scene-width));
  width: calc(var(--art-width) * 100% / var(--scene-width));
}

.scene-motion {
  position: absolute;
  inset: 0;
  container-type: size;
  pointer-events: none;
}

.lake-ripple,
.drifting-petal {
  position: absolute;
  left: calc(var(--x) * 100% / var(--scene-width));
  top: calc(var(--y) * 100% / var(--scene-height));
  opacity: 0;
}

.lake-ripple {
  width: calc(var(--span) * 100% / var(--scene-width));
  height: calc(100% / var(--scene-height));
  background: #c1cbb1;
  animation: lake-shimmer var(--duration) linear var(--delay) infinite;
}

.lake-ripple--sun {
  background: #ffe8bb;
}

.drifting-petal {
  width: calc(4 * 100% / var(--scene-width));
  height: calc(3 * 100% / var(--scene-height));
  clip-path: polygon(0 33%, 25% 33%, 25% 0, 75% 0, 75% 33%, 100% 33%, 100% 66%, 75% 66%, 75% 100%, 25% 100%, 25% 66%, 0 66%);
  background: linear-gradient(150deg, #f3b7a5 30%, #c77283 65%);
  animation: petal-drift var(--duration) linear var(--delay) infinite;
}

.drifting-petal--light {
  background: linear-gradient(150deg, #ffe0b2 30%, #e69a9a 65%);
}

.scene-cat {
  --padded-width: calc(var(--width) * var(--frame-scale, 1));
  position: absolute;
  left: calc((var(--x) - var(--padded-width) / 2) * 100% / var(--scene-width));
  bottom: calc((var(--scene-height) - var(--ground-y)) * 100% / var(--scene-height));
  width: calc(var(--padded-width) * 100% / var(--scene-width));
}

.scene-cat--tabby {
  --frames: 8;
  --frame-cycle: 1.76s;
}

.scene-cat--sleeping {
  --frames: 4;
  --frame-cycle: 1.6s;
}

.scene-cat--siamese {
  --frame-scale: calc(51 / 47);
  --frames: 4;
  --frame-cycle: .6s;
  --walk-cycle: calc(8 * var(--frame-cycle));
  --travel-x: calc(var(--walk-x) * 100cqw / var(--scene-width));
  --travel-y: calc(var(--walk-y) * 100cqh / var(--scene-height));
  animation: siamese-path var(--walk-cycle) linear infinite;
}

.cat-frame {
  display: block;
  overflow: hidden;
}

.scene-cat--siamese .cat-frame {
  animation: siamese-direction var(--walk-cycle) steps(1, end) infinite;
}

.scene-cat img {
  width: calc(var(--frames) * 100%);
  animation: cat-frames var(--frame-cycle) steps(var(--frames), end) infinite;
}

@keyframes cat-frames {
  to { transform: translateX(-100%); }
}

@keyframes siamese-path {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(var(--travel-x), var(--travel-y)); }
}

@keyframes siamese-direction {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(-1); }
}

@keyframes lake-shimmer {
  0% { opacity: 0; transform: translateX(-18%) scaleX(.62); }
  25% { opacity: .88; }
  58% { opacity: .59; transform: translateX(6%) scaleX(1.08); }
  100% { opacity: 0; transform: translateX(22%) scaleX(.72); }
}

@keyframes petal-drift {
  0% { opacity: 0; transform: translate(0, 0) rotate(-9deg); }
  17% { opacity: .96; }
  42% { transform: translate(132%, -120%) rotate(24deg); }
  75% { opacity: .86; transform: translate(306%, 16%) rotate(-16deg); }
  100% { opacity: 0; transform: translate(430%, 155%) rotate(18deg); }
}

@media (max-aspect-ratio: 1 / 1) {
  .scene-view--landscape { display: none; }
  .scene-view--portrait { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .lake-ripple,
  .drifting-petal,
  .scene-cat--siamese,
  .scene-cat--siamese .cat-frame,
  .scene-cat img { animation: none; }
}
