/* Weather stays behind the cast and controls. Place cards use the same light.
   weather-shader.mjs paints the layer; the gradients below are its fallback. */
[data-weather] {
  --weather-light: brightness(1) saturate(1);
  --rain-angle: 105deg;
  --rain-opacity: 0.24;
}
[data-weather="cloud"] {
  --weather-light: brightness(0.82) saturate(0.75);
}
[data-weather="rain"] {
  --weather-light: brightness(0.68) saturate(0.65);
}
[data-weather="mist"] {
  --weather-light: brightness(0.86) saturate(0.7);
}
.stage[data-weather] > .backdrop,
.art[data-weather] > img {
  filter: var(--weather-light);
}
.weather-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  border-radius: inherit;
}
.stage > .weather-layer {
  z-index: -1;
}
.art > .weather-layer {
  z-index: 1;
}
.art[data-weather] {
  position: relative;
}
[data-weather="cloud"] > .weather-layer:not([data-shader]) {
  background: linear-gradient(#8895ad30, transparent 68%);
}
[data-weather="rain"] > .weather-layer:not([data-shader]) {
  background: linear-gradient(#61738d38, #c0ccd90a 65%, #aabccc26);
}
[data-weather="rain"] > .weather-layer:not([data-shader])::after {
  content: "";
  position: absolute;
  inset: -40px;
  opacity: var(--rain-opacity);
  background: repeating-linear-gradient(
    var(--rain-angle),
    transparent 0 22px,
    #dde9f3 23px,
    transparent 24px 47px
  );
  mask-image: repeating-linear-gradient(
    0deg,
    #000 0 11px,
    transparent 13px 39px
  );
  animation: scene-rain 700ms linear infinite;
}
[data-exposure="coast"] {
  --rain-angle: 115deg;
  --rain-opacity: 0.32;
}
[data-exposure="grove"] {
  --rain-opacity: 0.14;
}
[data-exposure="shelter"] > .weather-layer:not([data-shader])::after {
  display: none;
}
[data-exposure="shelter"][data-weather] {
  --weather-light: brightness(0.92) saturate(0.9);
}
[data-weather="mist"] > .weather-layer:not([data-shader]) {
  background: linear-gradient(transparent 25%, #b6c6d922 55%, #bfcedb77);
}
[data-weather="mist"][data-exposure="coast"]
  > .weather-layer:not([data-shader]) {
  background: linear-gradient(transparent 15%, #bfcedb55 60%, #bfcedb88);
}
[data-weather="mist"][data-exposure="grove"]
  > .weather-layer:not([data-shader]) {
  background: linear-gradient(transparent 45%, #a4b9ab44 75%, #b9cbb788);
}
[data-weather="mist"][data-exposure="shelter"]
  > .weather-layer:not([data-shader]) {
  background: linear-gradient(#b6c6d914, transparent 50%);
}
[data-exposure="underground"] > .weather-layer:not([data-shader]) {
  background: linear-gradient(transparent 60%, #708c9b44 85%, #708c9b77);
}
.art[data-weather="rain"] > .weather-layer:not([data-shader])::after {
  animation: none;
  background-size: 50% 50%;
}
[data-time-of-day="night"][data-weather] {
  --weather-light: brightness(1) saturate(1);
}
[data-time-of-day="night"][data-weather="rain"],
[data-time-of-day="night"][data-weather="cloud"] {
  --weather-light: brightness(0.9) saturate(0.85);
}
/* Time of day (stage-light.mjs): the hour's shade and edge vignette multiply
   the painting, its desaturation greys it, and the figures take the same
   light as a filter (style.css). The hand and dialogue are never graded. */
/* The layer itself makes no stacking context, so each blend reaches the
   painting below. */
.stage-grade {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}
.stage[data-graded="true"] > .stage-grade {
  display: block;
}
.stage-grade::before,
.stage-grade::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
}
/* With WebGL the stage shader draws the shade and vignette (hard-light), and
   this CSS multiply is its fallback. */
.stage[data-stage-shader] > .stage-grade::after {
  display: none;
}
.stage > .weather-layer[data-shader] {
  mix-blend-mode: hard-light;
}
.stage-grade::before {
  background: rgb(128 128 128 / var(--tod-desat, 0));
  mix-blend-mode: saturation;
}
.stage-grade::after {
  background:
    radial-gradient(
      circle at calc(var(--art-left) + var(--art-w) * var(--light-x, 0.5))
        calc(var(--art-top) + var(--art-h) * var(--light-y, 0.5)),
      rgb(255 226 178 / var(--light-on, 0)),
      transparent calc(var(--art-h) * var(--light-r, 0.3))
    ),
    radial-gradient(
      ellipse 80% 75% at 50% 45%,
      transparent 45%,
      rgb(10 12 34 / var(--tod-vignette, 0))
    ),
    var(--tod-shade, #fff);
  mix-blend-mode: multiply;
}
@keyframes scene-rain {
  to {
    transform: translate(-10px, 39px);
  }
}
@media (prefers-reduced-motion: reduce) {
  [data-weather="rain"] > .weather-layer:not([data-shader])::after {
    animation: none;
  }
}
.weather-layer[data-shader] {
  background-size: cover;
  background-position: center;
}
.weather-layer > canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* The stage clips the painting plane. Its first layer sits above the
   backdrop at -2, behind the shade, weather and cast. */
.stage[data-ambience]::before {
  position: absolute;
  content: "";
  z-index: -1;
  pointer-events: none;
  left: var(--art-left);
  top: var(--art-top);
  width: var(--art-w);
  height: var(--art-h);
  opacity: 0.42;
}
.stage[data-ambience="gold"]::before {
  --ambient-shift: 0.6% -0.5%;
  background:
    radial-gradient(ellipse 8% 3% at 66% 26%, #ffdca73d, transparent),
    radial-gradient(circle at 61% 29%, #ffe7b4 0.05%, transparent 0.25%),
    radial-gradient(circle at 55% 32%, #e7b977 0.06%, transparent 0.25%),
    radial-gradient(circle at 46% 28%, #f4cd96 0.05%, transparent 0.24%),
    radial-gradient(circle at 50% 20%, #f4cd9680 0.05%, transparent 0.21%);
}
.stage[data-ambience="amber"]::before {
  --ambient-shift: -0.35% -1.2%;
  --ambient-period: 8s;
  background:
    radial-gradient(ellipse 10% 8% at 49% 49%, #e89d5c38, transparent),
    radial-gradient(circle at 46% 45%, #ffe4a0 0.06%, transparent 0.23%),
    radial-gradient(circle at 52% 39%, #ffd083 0.05%, transparent 0.25%),
    radial-gradient(circle at 56% 46%, #edac6caa 0.05%, transparent 0.23%),
    radial-gradient(circle at 51% 54%, #ffdbad9c 0.05%, transparent 0.24%);
}
.stage[data-ambience="mirror"]::before {
  --ambient-shift: 0.5% -0.25%;
  --ambient-period: 12s;
  background:
    radial-gradient(ellipse 2% 8% at 35% 33%, #bbe8ff46, transparent),
    radial-gradient(ellipse 2% 9% at 65% 32%, #dcf3ff66, transparent),
    radial-gradient(ellipse 10% 1.8% at 61% 61%, #acf3ff4a, transparent),
    radial-gradient(ellipse 8% 1.5% at 40% 62%, #acf3ff35, transparent);
}
.stage[data-ambience="loom"]::before {
  --ambient-shift: 1.2% 0%;
  --ambient-period: 14s;
  background:
    radial-gradient(ellipse 17% 5% at 50% 40%, #dca86046, transparent),
    radial-gradient(ellipse 15% 8% at 54% 50%, #65d8cf30, transparent),
    radial-gradient(ellipse 20% 2% at 48% 62%, #7cded02b, transparent);
}
.stage[data-ambience="well"]::before {
  --ambient-shift: 0% -0.45%;
  --ambient-period: 10s;
  background:
    radial-gradient(ellipse 17% 5% at 50% 42%, transparent 75%, #9597ff67 89%, transparent),
    radial-gradient(ellipse 15% 4% at 50% 48%, #9f9bf446, transparent),
    radial-gradient(ellipse 1% 22% at 50% 31%, #a7a9f635, transparent);
}
.stage[data-ambience="jade"]::before {
  --ambient-shift: 1.6% -0.9%;
  --ambient-period: 16s;
  background:
    radial-gradient(ellipse 26% 6% at 51% 57%, #93c7ae42, transparent),
    radial-gradient(ellipse 21% 6% at 36% 61%, #80af9570, transparent),
    radial-gradient(ellipse 15% 4% at 63% 50%, #85bea04f, transparent);
}
@keyframes stage-ambient-drift {
  to {
    opacity: 0.78;
    translate: var(--ambient-shift);
  }
}
.stage[data-ambience="copper"]::before {
  background-image: var(--ambient-impact, none);
  background-size: 100% 100%;
  mask-image: linear-gradient(#000 52%, transparent 79%);
  opacity: 0;
}
@keyframes stage-copper-strike {
  0%, 48.7%, 58%, 100% { opacity: 0; }
  49.15%, 49.55% { opacity: 0.83; }
  50.6% { opacity: 0.27; }
  53.8% { opacity: 0.12; }
}
.stage[data-place-covered="true"][data-ambience]::before,
.stage[data-ambience]:has(.travel.travelling)::before {
  display: none;
}
@media (prefers-reduced-motion: no-preference) {
  .stage[data-ambient-motion="true"]:not([data-ambience="copper"])::before {
    animation: stage-ambient-drift var(--ambient-period, 11s) ease-in-out infinite alternate;
  }
  .stage[data-ambience="copper"][data-ambient-motion="true"][data-ambient-ready="true"]::before {
    animation: stage-copper-strike 16s linear infinite;
  }
}

/* Where the player stays, the light eases with night and weather; travel and
   reduced motion cut. transitions.mjs fades the painting itself. */
.stage[data-settled="true"] > .backdrop {
  transition:
    filter 4s ease-in-out,
    opacity var(--recede-ms, 0ms) ease-in-out;
}
/* A Halloween apparition is stacked on its resident and only shown for one
   brief cut. */
.apparition {
  visibility: hidden;
  pointer-events: none;
}
.apparition[data-showing="true"] {
  visibility: visible;
}
@media (prefers-reduced-motion: reduce) {
  .stage[data-settled="true"] > .backdrop {
    transition: none;
  }
  .apparition {
    display: none;
  }
}
