/* Load before classic.css. Attribute specificity protects these palettes from
   its :root defaults. The UI owns main's width, padding and safe-area inset. */
html[data-wallpaper] {
  --ink: 237, 231, 221;
  --glow: 255, 236, 208;
  --late: 212, 163, 134;
  --warm: 250, 226, 190;
  --page: #000000;
  background: var(--page);
  color-scheme: dark;
}

html[data-tone="light"] {
  --ink: 35, 46, 49;
  --glow: 55, 81, 85;
  --late: 76, 44, 24;
  --warm: 70, 46, 24;
  color-scheme: light;
}

html[data-wallpaper="dunes"] { --page: #f6f1e6; }
html[data-wallpaper="tide"] { --page: #eff4ef; }
html[data-wallpaper="mist"] { --page: #eff2e9; }
html[data-wallpaper="solid"] { --page: #020305; }
html[data-wallpaper="moonlight"] { --page: #05090c; }
html[data-wallpaper="clouds"] {
  --page: #edf0f2;
  --ink: 35, 46, 55;
  --glow: 55, 75, 90;
}
html[data-wallpaper="sunlight"] {
  --page: #eee8dc;
  --ink: 49, 43, 35;
  --glow: 86, 68, 48;
}

body[data-wallpaper] {
  position: relative;
  isolation: isolate;
  background: var(--page);
  color: rgb(var(--ink));
}

/* Scrolls with the document, like old mobile/index.html. svh never follows the
   software keyboard or the browser toolbar. No fixed or visualViewport sizing. */
#wallpaper {
  position: absolute;
  inset: 0 0 auto;
  height: min(72vh, 680px);
  height: min(72svh, 680px);
  z-index: -1;
  overflow: hidden;
  contain: layout paint;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-mask-image: linear-gradient(#000 24%, #000 31%, rgba(0,0,0,.8) 43%, rgba(0,0,0,.28) 55%, rgba(0,0,0,.04) 68%, transparent 80%);
  mask-image: linear-gradient(#000 24%, #000 31%, rgba(0,0,0,.8) 43%, rgba(0,0,0,.28) 55%, rgba(0,0,0,.04) 68%, transparent 80%);
}

/* Keep the lake reflection faintly visible; preserve the existing fade above
   the task area. The other eight heroes retain their original mask. */
#wallpaper[data-wallpaper="moonlight"] {
  -webkit-mask-image: linear-gradient(#000 24%, #000 31%, rgba(0,0,0,.8) 43%, rgba(0,0,0,.28) 55%, rgba(0,0,0,.14) 72%, rgba(0,0,0,.08) 86%, transparent 100%);
  mask-image: linear-gradient(#000 24%, #000 31%, rgba(0,0,0,.8) 43%, rgba(0,0,0,.28) 55%, rgba(0,0,0,.14) 72%, rgba(0,0,0,.08) 86%, transparent 100%);
}

#wallpaper .wallpaper-scene {
  position: absolute;
  left: 50%;
  top: min(23vh, 224px);
  top: min(23svh, 224px);
  width: min(100%, 760px);
  aspect-ratio: 4 / 3;
  transform: translate(-50%, -50%);
}

#wallpaper .wallpaper-picture {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: wallpaper-breathe 28s ease-in-out infinite alternate;
}

/* The original mobile Gargantua remains a still, perfectly centred lens. */
#wallpaper[data-wallpaper="gargantua"] .wallpaper-picture { animation: none; }
#wallpaper[data-wallpaper="nocturne"] .wallpaper-picture { animation-duration: 37s; }
#wallpaper[data-wallpaper="accretion"] .wallpaper-picture,
#wallpaper[data-wallpaper="nocturne"] .wallpaper-picture {
  -webkit-mask-image: linear-gradient(transparent, #000 18%, #000 75%, transparent);
  mask-image: linear-gradient(transparent, #000 18%, #000 75%, transparent);
}

/* A full-bleed sky/photo on a phone, bounded art with soft sides on a desktop. */
#wallpaper[data-wallpaper="solid"] .wallpaper-scene,
#wallpaper[data-wallpaper="moonlight"] .wallpaper-scene,
#wallpaper[data-tone="light"] .wallpaper-scene {
  top: 0;
  width: min(100%, 1100px);
  height: 100%;
  aspect-ratio: auto;
  transform: translateX(-50%);
}

#wallpaper[data-wallpaper="solid"] .wallpaper-picture,
#wallpaper[data-wallpaper="moonlight"] .wallpaper-picture,
#wallpaper[data-tone="light"] .wallpaper-picture { object-fit: cover; }
#wallpaper[data-wallpaper="solid"] .wallpaper-picture,
#wallpaper[data-wallpaper="moonlight"] .wallpaper-picture { animation: none; }
#wallpaper[data-wallpaper="moonlight"] .wallpaper-picture {
  object-position: 31% 50%;
  filter: brightness(1.25) contrast(1.2);
}

#wallpaper[data-tone="light"] .wallpaper-picture {
  animation: wallpaper-drift 48s ease-in-out infinite alternate;
  transform: scale(1.025);
}
#wallpaper[data-wallpaper="dunes"] .wallpaper-picture { object-position: 22% 50%; animation: none; transform: none; }
#wallpaper[data-wallpaper="tide"] .wallpaper-picture { object-position: 64% 50%; animation-duration: 38s; }
#wallpaper[data-wallpaper="mist"] .wallpaper-picture { object-position: 27% 50%; animation-duration: 56s; }
#wallpaper[data-wallpaper="clouds"] .wallpaper-picture { object-position: 28% 50%; animation-duration: 58s; }
#wallpaper[data-wallpaper="sunlight"] .wallpaper-scene {
  isolation: isolate;
  background: var(--page);
}
#wallpaper[data-wallpaper="sunlight"] .wallpaper-picture {
  object-position: 34% 50%;
  animation: none;
  transform: none;
}
#wallpaper[data-wallpaper="sunlight"] .wallpaper-picture[hidden] { visibility: hidden; }

/* Static plates plus two composited layers. The glow masks select actual stars
   in solid.webp and share its cover crop; the rest of the sky never pulses. */
#wallpaper .wallpaper-scene::before,
#wallpaper .wallpaper-scene::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#wallpaper[data-wallpaper="solid"] .wallpaper-scene::before,
#wallpaper[data-wallpaper="solid"] .wallpaper-scene::after {
  content: '';
  background: center / cover no-repeat;
  opacity: .3;
  animation: wallpaper-twinkle 7.1s ease-in-out -2s infinite;
}
#wallpaper[data-wallpaper="solid"] .wallpaper-scene::before { background-image: url('./wallpapers/solid-twinkle-a.webp'); }
#wallpaper[data-wallpaper="solid"] .wallpaper-scene::after {
  background-image: url('./wallpapers/solid-twinkle-b.webp');
  animation-duration: 10.7s;
  animation-delay: -6s;
}

/* Windblown sand follows the surface while the terrain remains stationary. */
#wallpaper[data-wallpaper="dunes"] .wallpaper-scene::before,
#wallpaper[data-wallpaper="dunes"] .wallpaper-scene::after {
  content: '';
  inset: 0 -8%;
  opacity: .23;
  background:
    radial-gradient(ellipse 60% 2% at 32% 28%, rgba(255,244,219,.8), transparent 76%),
    radial-gradient(ellipse 85% 3% at 55% 39%, rgba(255,239,201,.6), transparent 74%),
    radial-gradient(ellipse 65% 2% at 31% 51%, rgba(255,242,211,.6), transparent 74%);
  animation: wallpaper-sand 14s ease-in-out -4s infinite alternate;
}
#wallpaper[data-wallpaper="dunes"] .wallpaper-scene::after {
  animation-duration: 21s;
  animation-delay: -12s;
  animation-direction: alternate-reverse;
  background:
    radial-gradient(ellipse 60% 1.5% at 60% 32%, rgba(255,249,228,.8), transparent 76%),
    radial-gradient(ellipse 80% 2% at 40% 46%, rgba(255,241,211,.7), transparent 74%);
}
/* Bounds are the projected 1200x675 photo, not the cropped hero. Identical
   masked clouds reflect across y=.525: the moon at .261 maps to .789.
   Only the clouds translate; the photo, water and horizon remain still. */
#wallpaper .wallpaper-moonlight {
  position: absolute;
  overflow: hidden;
  pointer-events: none;
}
#wallpaper .wallpaper-moon-plane {
  position: absolute;
  inset: 0;
  clip-path: inset(0 0 47.5% 0);
}
#wallpaper .wallpaper-moon-reflection {
  transform-origin: 50% 0;
  transform: translateY(105%) scaleY(-1);
  opacity: .72;
}
#wallpaper .wallpaper-moon-plane::before,
#wallpaper .wallpaper-moon-plane::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #9aa3aa 13%, #4c545b 23%, #151c23 34%, #080d12 44%);
  opacity: .8;
  animation: wallpaper-moon-cloud 32s linear infinite alternate;
  -webkit-mask-image:
    radial-gradient(ellipse 13% 3.6% at 16% 25%, #000 12%, transparent 100%),
    radial-gradient(ellipse 10% 4.4% at 28% 26.1%, #000 12%, transparent 100%),
    radial-gradient(ellipse 12% 3% at 37% 28.5%, #000 12%, transparent 100%);
  mask-image:
    radial-gradient(ellipse 13% 3.6% at 16% 25%, #000 12%, transparent 100%),
    radial-gradient(ellipse 10% 4.4% at 28% 26.1%, #000 12%, transparent 100%),
    radial-gradient(ellipse 12% 3% at 37% 28.5%, #000 12%, transparent 100%);
}
#wallpaper .wallpaper-moon-plane::after {
  opacity: .5;
  animation: wallpaper-moon-cloud-high 46s linear -11s infinite alternate;
  -webkit-mask-image:
    radial-gradient(ellipse 18% 2.6% at 52% 17%, #000 12%, transparent 100%),
    radial-gradient(ellipse 12% 3.4% at 37% 19.5%, #000 12%, transparent 100%),
    radial-gradient(ellipse 17% 2% at 64% 21%, #000 12%, transparent 100%);
  mask-image:
    radial-gradient(ellipse 18% 2.6% at 52% 17%, #000 12%, transparent 100%),
    radial-gradient(ellipse 12% 3.4% at 37% 19.5%, #000 12%, transparent 100%),
    radial-gradient(ellipse 17% 2% at 64% 21%, #000 12%, transparent 100%);
}

/* A single whole shadow pivots around the branch root in photo coordinates.
   Fixed 1.06 overscan is centred in layout; only rigid rotation and translation
   animate. The projected wall clips contain margins and never moves itself. */
#wallpaper .wallpaper-sunlight {
  position: absolute;
  overflow: hidden;
  pointer-events: none;
}
#wallpaper .wallpaper-sun-shadow {
  position: absolute;
  inset: -3%;
  width: 106%;
  height: 106%;
  object-fit: fill;
  mix-blend-mode: multiply;
  opacity: .65;
  transform-origin: 6% 28%;
  transform: none;
  -webkit-mask-image: linear-gradient(90deg, #000 59%, rgba(0,0,0,.844) 63.75%, rgba(0,0,0,.5) 68.5%, rgba(0,0,0,.156) 73.25%, transparent 78%);
  mask-image: linear-gradient(90deg, #000 59%, rgba(0,0,0,.844) 63.75%, rgba(0,0,0,.5) 68.5%, rgba(0,0,0,.156) 73.25%, transparent 78%);
  animation: wallpaper-sun-sway var(--sunlight-sway-duration, 48s) ease-in-out infinite;
}
#wallpaper[data-wallpaper="sunlight"] .wallpaper-scene::after {
  content: '';
  background: #f5f3ed;
  opacity: var(--sunlight-dim, .15);
}

@keyframes wallpaper-breathe {
  from { opacity: .91; }
  to { opacity: 1; }
}
@keyframes wallpaper-drift {
  from { transform: scale(1.025) translate3d(-.25%, -.2%, 0); }
  to { transform: scale(1.035) translate3d(.25%, .2%, 0); }
}
@keyframes wallpaper-twinkle {
  0%, 100% { opacity: .12; }
  37% { opacity: .9; }
  72% { opacity: .32; }
}
@keyframes wallpaper-sand {
  from { transform: translate3d(-4%, -.4%, 0); opacity: .14; }
  to { transform: translate3d(4%, .4%, 0); opacity: .38; }
}
@keyframes wallpaper-moon-cloud {
  from { transform: translate3d(-12%, 0, 0); }
  to { transform: translate3d(12%, 0, 0); }
}
@keyframes wallpaper-moon-cloud-high {
  from { transform: translate3d(-8%, 0, 0); }
  to { transform: translate3d(8%, 0, 0); }
}
@keyframes wallpaper-sun-sway {
  0%, 100% { transform: translate3d(-.35%, -.12%, 0) rotate(-.36deg); }
  22% { transform: translate3d(.25%, .16%, 0) rotate(.28deg); }
  49% { transform: translate3d(-.28%, .08%, 0) rotate(-.24deg); }
  73% { transform: translate3d(.4%, -.1%, 0) rotate(.42deg); }
}

#wallpaper[data-paused="true"] .wallpaper-picture,
#wallpaper[data-paused="true"] .wallpaper-scene::before,
#wallpaper[data-paused="true"] .wallpaper-scene::after,
#wallpaper[data-paused="true"] .wallpaper-moon-plane::before,
#wallpaper[data-paused="true"] .wallpaper-moon-plane::after,
#wallpaper[data-paused="true"] .wallpaper-sun-shadow { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  #wallpaper[data-wallpaper] .wallpaper-picture,
  #wallpaper[data-wallpaper] .wallpaper-scene::before,
  #wallpaper[data-wallpaper] .wallpaper-scene::after,
  #wallpaper[data-wallpaper] .wallpaper-moon-plane::before,
  #wallpaper[data-wallpaper] .wallpaper-moon-plane::after,
  #wallpaper[data-wallpaper] .wallpaper-sun-shadow { animation: none; }
}

@media (min-width: 761px) {
  #wallpaper .wallpaper-scene {
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 13%, #000 87%, transparent);
    mask-image: linear-gradient(90deg, transparent, #000 13%, #000 87%, transparent);
  }
}
