/* Seasonal effects (src/platform/seasons.ts, season-ui.ts, public/seasons.js; art built by scripts/build-season-art.ts).
   Rules: decorative only (aria-hidden, pointer-events: none), never on top of text or ads: the picture columns sit in
   the page margins outside the content column (only on screens wide enough to have margins, ≥ 1280px), the header
   accent is a 2px background hairline inside the header (no positioned box, so it can never land on content — also
   on phones where the header is not sticky), and the first-visit moment is a short (≤ 2.5 s), skippable animation.
   Off with prefers-reduced-motion (static pictures, no moment), with prefers-contrast: more / forced colors (nothing),
   and in print. Nothing here changes the layout (no CLS); animations use opacity and rotate/translate only. */

/* z-index 0 as the first child of <body>: painted above section backgrounds (hero bands) but below every positioned
   element (sticky header, dialogs, ads); the pictures only occupy the margins outside the 1160px content column. */
.uw-season { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; contain: strict; container-type: inline-size; }
.uw-season-side { display: none; }
@media (min-width: 1280px) {
  /* --free: margin outside the 1160px column plus its 28px padding (100cqw = the layer's width, i.e. the viewport
     without its scrollbar, resolved on the columns); --w: picture width, ≥ 20px clear of the text on both sides. */
  .uw-season { --free: calc((100cqw - 1160px) / 2 + 28px); --w: min(180px, calc(var(--free) - 40px)); }
  .uw-season-side { display: block; position: absolute; top: 76px; bottom: 0; width: var(--w); }
  .uw-season-start { inset-inline-start: calc((var(--free) - var(--w)) / 2); }
  .uw-season-end { inset-inline-end: calc((var(--free) - var(--w)) / 2); scale: -1 1; }
  .uw-season-hang, .uw-season-ground { position: absolute; inset-inline: 0; background: no-repeat center top / 100% auto; }
  /* Hanging part: up to 600/180 of the width tall, shortened (soft fade at the end) when the window is low. */
  .uw-season-hang {
    top: 0; height: min(calc(var(--w) * 10 / 3), calc(100% - var(--w) * 4 / 3 - 8px));
    -webkit-mask-image: linear-gradient(#000 calc(100% - 56px), transparent); mask-image: linear-gradient(#000 calc(100% - 56px), transparent);
    transform-origin: 50% 0; animation: uw-season-in .6s cubic-bezier(.16, 1, .3, 1) .3s both;
  }
  .uw-season-ground { bottom: 0; height: calc(var(--w) * 4 / 3); background-position: center bottom; animation: uw-season-rise .7s cubic-bezier(.16, 1, .3, 1) .45s both; }
  /* The end column hangs a little lower, so the two sides do not mirror each other line for line. */
  .uw-season-end .uw-season-hang { top: 56px; height: min(calc(var(--w) * 10 / 3), calc(100% - 56px - var(--w) * 4 / 3 - 8px)); }
  /* Things that hang on a thread settle with a short damped swing (once, ≈ 4 s; never loops). */
  .uw-season:is([data-uw-season="christmas"], [data-uw-season="advent"], [data-uw-season="easter"], [data-uw-season="orthodox-easter"], [data-uw-season="lunar-new-year"], [data-uw-season="diwali"], [data-uw-season="new-year"], [data-uw-season="halloween"]) .uw-season-hang {
    animation: uw-season-in .6s cubic-bezier(.16, 1, .3, 1) .3s both, uw-season-swing 4.2s cubic-bezier(.37, 0, .63, 1) .3s both;
  }
  .uw-season .uw-season-end .uw-season-hang { animation-delay: .5s; }
}
@media (min-width: 1280px) and (max-height: 640px) { .uw-season-ground { display: none; } .uw-season-hang { height: min(calc(var(--w) * 10 / 3), calc(100% - 8px)); } }
@keyframes uw-season-in { from { opacity: 0; translate: 0 -10px; } }
@keyframes uw-season-rise { from { opacity: 0; translate: 0 14px; } }
@keyframes uw-season-swing { 0% { rotate: 0deg; } 16% { rotate: 1.4deg; } 36% { rotate: -1deg; } 56% { rotate: .55deg; } 76% { rotate: -.22deg; } 100% { rotate: 0deg; } }
/* Dark canvas: slightly quieter so the art never competes with text. */
:root[data-theme="dark"] .uw-season-side { opacity: .8; }
:root[data-theme="dark"] .uw-season-ground { opacity: .85; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .uw-season-side { opacity: .8; }
  :root:not([data-theme="light"]) .uw-season-ground { opacity: .85; }
}

.uw-season[data-uw-season="winter"] .uw-season-hang { background-image: url("/static/seasons/winter.svg"); }
.uw-season[data-uw-season="winter"] .uw-season-ground { background-image: url("/static/seasons/winter-ground.svg"); }
.uw-season[data-uw-season="advent"] .uw-season-hang { background-image: url("/static/seasons/advent.svg"); }
.uw-season[data-uw-season="advent"] .uw-season-ground { background-image: url("/static/seasons/advent-ground-1.svg"); }
.uw-season[data-uw-season="advent"][data-week="2"] .uw-season-ground { background-image: url("/static/seasons/advent-ground-2.svg"); }
.uw-season[data-uw-season="advent"][data-week="3"] .uw-season-ground { background-image: url("/static/seasons/advent-ground-3.svg"); }
.uw-season[data-uw-season="advent"][data-week="4"] .uw-season-ground { background-image: url("/static/seasons/advent-ground-4.svg"); }
.uw-season[data-uw-season="christmas"] .uw-season-hang { background-image: url("/static/seasons/christmas.svg"); }
.uw-season[data-uw-season="christmas"] .uw-season-ground { background-image: url("/static/seasons/christmas-ground.svg"); }
.uw-season[data-uw-season="new-year"] .uw-season-hang { background-image: url("/static/seasons/new-year.svg"); }
.uw-season[data-uw-season="new-year"] .uw-season-ground { background-image: url("/static/seasons/new-year-ground.svg"); }
.uw-season[data-uw-season="halloween"] .uw-season-hang { background-image: url("/static/seasons/halloween.svg"); }
.uw-season[data-uw-season="halloween"] .uw-season-ground { background-image: url("/static/seasons/halloween-ground.svg"); }
.uw-season[data-uw-season="easter"] .uw-season-hang { background-image: url("/static/seasons/easter.svg"); }
.uw-season[data-uw-season="easter"] .uw-season-ground { background-image: url("/static/seasons/easter-ground.svg"); }
.uw-season[data-uw-season="orthodox-easter"] .uw-season-hang { background-image: url("/static/seasons/orthodox-easter.svg"); }
.uw-season[data-uw-season="orthodox-easter"] .uw-season-ground { background-image: url("/static/seasons/orthodox-easter-ground.svg"); }
.uw-season[data-uw-season="lunar-new-year"] .uw-season-hang { background-image: url("/static/seasons/lunar-new-year.svg"); }
.uw-season[data-uw-season="lunar-new-year"] .uw-season-ground { background-image: url("/static/seasons/lunar-new-year-ground.svg"); }
.uw-season[data-uw-season="diwali"] .uw-season-hang { background-image: url("/static/seasons/diwali.svg"); }
.uw-season[data-uw-season="diwali"] .uw-season-ground { background-image: url("/static/seasons/diwali-ground.svg"); }
.uw-season[data-uw-season="spring"] .uw-season-hang { background-image: url("/static/seasons/spring.svg"); }
.uw-season[data-uw-season="spring"] .uw-season-ground { background-image: url("/static/seasons/spring-ground.svg"); }
.uw-season[data-uw-season="summer"] .uw-season-hang { background-image: url("/static/seasons/summer.svg"); }
.uw-season[data-uw-season="summer"] .uw-season-ground { background-image: url("/static/seasons/summer-ground.svg"); }
.uw-season[data-uw-season="autumn"] .uw-season-hang { background-image: url("/static/seasons/autumn.svg"); }
.uw-season[data-uw-season="autumn"] .uw-season-ground { background-image: url("/static/seasons/autumn-ground.svg"); }

/* Header accent: a 2px hairline in the season's colours that fades out towards both ends, drawn as a background layer
   on the header's lower edge (inside the header box; the header's own background colour stays underneath). */
.uw-season ~ .site-header { background-image: var(--uw-band, none); background-repeat: no-repeat; background-position: 0 100%; background-size: 100% 2px; }
.uw-season[data-uw-season="winter"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #9cc6ee 14%, #6aa6dd 50%, #9cc6ee 86%, transparent); }
.uw-season[data-uw-season="advent"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #3f7d55 14%, #c8323a 42%, #e2a92a 50%, #c8323a 58%, #3f7d55 86%, transparent); }
.uw-season[data-uw-season="christmas"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #2f6b48 12%, #c8323a 38%, #d9a92e 50%, #c8323a 62%, #2f6b48 88%, transparent); }
.uw-season[data-uw-season="new-year"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #7a5cc7 12%, #c9962a 38%, #d64f8a 62%, #2f9aa8 88%, transparent); }
.uw-season[data-uw-season="halloween"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #6b5a84 14%, #e07a1f 40%, #efc35a 50%, #e07a1f 60%, #6b5a84 86%, transparent); }
.uw-season[data-uw-season="easter"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #f2c94c 12%, #7fb5e0 37%, #e88fb4 62%, #93c97a 88%, transparent); }
.uw-season[data-uw-season="orthodox-easter"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #b3262b 16%, #e2ad38 50%, #b3262b 84%, transparent); }
.uw-season[data-uw-season="lunar-new-year"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #d63a2f 16%, #e2ad38 50%, #d63a2f 84%, transparent); }
.uw-season[data-uw-season="diwali"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #e0457b 14%, #f2a01c 40%, #f7c33a 50%, #f2a01c 60%, #2f9aa8 86%, transparent); }
.uw-season[data-uw-season="spring"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #f2a7bd 16%, #7dbb5c 50%, #f2a7bd 84%, transparent); }
.uw-season[data-uw-season="summer"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #f2b632 16%, #d93b30 46%, #4f7fd8 70%, #8db552 86%, transparent); }
.uw-season[data-uw-season="autumn"] ~ .site-header { --uw-band: linear-gradient(90deg, transparent, #c4512c 16%, #d9822b 40%, #e3b23c 60%, #8a9a3a 86%, transparent); }

/* Visitor switched effects off (public/seasons.js sets the attribute from localStorage). */
:root[data-season-fx="off"] .uw-season, :root[data-season-fx="off"] .uw-season-moment { display: none; }
:root[data-season-fx="off"] .uw-season ~ .site-header { background-image: none; }
/* Tab in the background: hold every seasonal animation where it is (public/seasons.js toggles the attribute). */
:root[data-season-hidden] .uw-season *, :root[data-season-hidden] .uw-season-moment * { animation-play-state: paused; }

/* ---- the short first-visit moment (≤ 2.5 s, skippable; public/seasons.js builds and removes it) ---- */
.uw-season-moment { position: fixed; inset: 0; z-index: 60; pointer-events: none; overflow: hidden; contain: strict; transition: opacity .18s ease-out; }
.uw-season-moment.uw-out { opacity: 0; }
.uw-p {
  position: absolute; top: -56px; width: var(--s, 28px); height: var(--s, 28px);
  background: center / contain no-repeat; opacity: 0; will-change: transform, opacity;
  animation: uw-fall var(--d, 2s) cubic-bezier(.35, .1, .6, 1) var(--delay, 0s) forwards;
}
/* Falling with a gentle side-to-side drift (--sx) and a depth-dependent peak opacity (--o). */
@keyframes uw-fall {
  0% { opacity: 0; transform: translate3d(0, 0, 0) rotate(0deg); }
  12% { opacity: var(--o, .95); }
  35% { transform: translate3d(var(--sx, 0px), calc(var(--fy, 70vh) * .33), 0) rotate(calc(var(--r, 180deg) * .33)); }
  68% { transform: translate3d(calc(var(--sx, 0px) * -.7), calc(var(--fy, 70vh) * .66), 0) rotate(calc(var(--r, 180deg) * .66)); }
  80% { opacity: var(--o, .9); }
  100% { opacity: 0; transform: translate3d(var(--dx, 0px), var(--fy, 70vh), 0) rotate(var(--r, 180deg)); }
}
/* Leaves and petals tumble: the flat shape turns edge-on and back while it falls. */
.uw-p.uw-tumble { animation-name: uw-fall, uw-tumble; animation-duration: var(--d, 2s), .9s; animation-timing-function: cubic-bezier(.35, .1, .6, 1), ease-in-out; animation-delay: var(--delay, 0s), var(--delay, 0s); animation-iteration-count: 1, 3; animation-direction: normal, alternate; animation-fill-mode: forwards, none; }
@keyframes uw-tumble { 0% { scale: 1 1; } 50% { scale: .25 1; } 100% { scale: 1 1; } }
.uw-p.uw-rise { top: auto; bottom: -56px; animation-name: uw-rise; }
@keyframes uw-rise {
  0% { opacity: 0; transform: translate3d(0, 0, 0); }
  15% { opacity: var(--o, .95); }
  50% { transform: translate3d(var(--sx, 0px), calc(-.5 * var(--fy, 60vh)), 0) rotate(calc(var(--r, 0deg) * -.5)); }
  85% { opacity: var(--o, .9); }
  100% { opacity: 0; transform: translate3d(var(--dx, 0px), calc(-1 * var(--fy, 60vh)), 0) rotate(var(--r, 0deg)); }
}
.uw-p[data-p="snow"] { background-image: url("/static/seasons/p-snow.svg"); }
.uw-p[data-p="leaf"] { background-image: url("/static/seasons/p-leaf.svg"); }
.uw-p[data-p="leaf2"] { background-image: url("/static/seasons/p-leaf2.svg"); }
.uw-p[data-p="petal"] { background-image: url("/static/seasons/p-petal.svg"); }
.uw-p[data-p="star"] { background-image: url("/static/seasons/p-star.svg"); }
.uw-p[data-p="egg"] { background-image: url("/static/seasons/p-egg.svg"); }
.uw-p[data-p="egg2"] { background-image: url("/static/seasons/p-egg2.svg"); }
.uw-p[data-p="lantern"] { background-image: url("/static/seasons/p-lantern.svg"); }
.uw-p[data-p="diya"] { background-image: url("/static/seasons/p-diya.svg"); }
.uw-p[data-p="sun"] { background-image: url("/static/seasons/p-sun.svg"); }
.uw-p[data-p="bat"] { background-image: url("/static/seasons/p-bat.svg"); }

/* Fireworks: a rocket climbs, flashes and opens into sparks that droop under gravity. */
.uw-rocket {
  position: absolute; bottom: 0; width: 3px; height: 26px; margin-left: -1.5px; border-radius: 2px;
  background: linear-gradient(to top, transparent, var(--c, #e0a526)); opacity: 0;
  animation: uw-climb .5s cubic-bezier(.2, .6, .35, 1) var(--delay, 0s) forwards;
}
@keyframes uw-climb { 0% { opacity: 0; transform: translateY(0); } 15% { opacity: 1; } 90% { opacity: 1; } 100% { opacity: 0; transform: translateY(var(--ty, -60vh)); } }
.uw-flash {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  background: radial-gradient(circle, var(--c, #e0a526), transparent 65%); opacity: 0;
  animation: uw-flash .6s ease-out var(--delay, 0s) forwards;
}
@keyframes uw-flash { 0% { opacity: 0; transform: scale(.2); } 15% { opacity: .55; } 100% { opacity: 0; transform: scale(1.2); } }
.uw-spark {
  position: absolute; width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px; border-radius: 50%;
  background: var(--c, #e0a526); box-shadow: 0 0 6px 1px var(--c, #e0a526); opacity: 0;
  animation: uw-burst 1.15s cubic-bezier(.15, .7, .4, 1) var(--delay, 0s) forwards;
}
@keyframes uw-burst {
  0% { opacity: 0; transform: translate(0, 0) scale(.6); }
  8% { opacity: 1; }
  55% { opacity: .95; transform: translate(calc(var(--dx, 0px) * .86), calc(var(--dy, 0px) * .86)) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx, 0px), calc(var(--dy, 0px) + 34px)) scale(.35); }
}

/* Summer: a few soft glints near the top. */
.uw-glint {
  position: absolute; width: var(--s, 60px); height: var(--s, 60px); margin: calc(var(--s, 60px) / -2) 0 0 calc(var(--s, 60px) / -2);
  border-radius: 50%; background: radial-gradient(circle, rgba(255, 214, 102, .55), rgba(255, 214, 102, 0) 70%);
  opacity: 0; animation: uw-glint 1.8s ease-in-out var(--delay, 0s) forwards;
}
@keyframes uw-glint { 0%, 100% { opacity: 0; transform: scale(.6); } 45% { opacity: 1; transform: scale(1); } }

/* Halloween: a carved pumpkin peeks in at the bottom corner and winks while bats flit across the top. */
.uw-pumpkin {
  position: absolute; bottom: 10px; inset-inline-end: 18px; width: 104px; height: 104px;
  animation: uw-peek 2.4s cubic-bezier(.16, 1, .3, 1) forwards; transform: translateY(130px);
}
.uw-pumpkin .uw-lid { transform-box: fill-box; transform-origin: 50% 0; transform: scaleY(0); animation: uw-wink 2.4s linear forwards; }
@keyframes uw-peek { 0% { transform: translateY(130px); } 24%, 76% { transform: translateY(0); } 100% { transform: translateY(130px); } }
@keyframes uw-wink { 0%, 44% { transform: scaleY(0); } 50%, 58% { transform: scaleY(1); } 64%, 100% { transform: scaleY(0); } }
.uw-p.uw-fly { top: var(--y0, 80px); left: -60px; animation-name: uw-fly; animation-timing-function: cubic-bezier(.45, .05, .55, .95); }
:root[dir="rtl"] .uw-p.uw-fly { left: auto; right: -60px; scale: -1 1; }
@keyframes uw-fly {
  0% { opacity: 0; transform: translate3d(0, 0, 0); }
  10%, 85% { opacity: var(--o, .9); }
  30% { transform: translate3d(calc(var(--fx, 100vw) * .3), -18px, 0); }
  60% { transform: translate3d(calc(var(--fx, 100vw) * .6), 14px, 0); }
  100% { opacity: 0; transform: translate3d(var(--fx, 100vw), -10px, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .uw-season-hang, .uw-season-ground { animation: none !important; }
  .uw-season-moment { display: none; }
}
/* High contrast and forced colours: no decoration at all (it would only add noise to a deliberately plain page). */
@media (prefers-contrast: more), (forced-colors: active) {
  .uw-season, .uw-season-moment { display: none !important; }
  .uw-season ~ .site-header { background-image: none; }
}

/* ---- footer control ---- */
.season-ctl { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 0; padding: 0; border: 0; min-width: 0; color: var(--ink-2); }
.season-ctl[hidden] { display: none; }
.season-ctl legend { float: inline-start; margin-inline-end: 6px; padding: 0; font-weight: 600; color: var(--ink); }
.season-opt { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; cursor: pointer; }
.season-opt input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent-solid, #1d5bd8); }
.season-hint { flex-basis: 100%; margin: 0; font-size: var(--fs-sm, .875rem); color: var(--muted); }

@media print {
  .uw-season, .uw-season-moment, .season-ctl { display: none !important; }
  .uw-season ~ .site-header { background-image: none; }
}
