/*
 * KKaio template - Christmas decorations
 * Copyright (C) 2026 KKaio.com - GNU General Public License version 2 or later
 *
 * Loaded only when the template style switches them on; data-xmas on the root element lists the ones
 * that are on. They lie over the page and ignore the pointer, so the layout stays as it is, except for
 * the room the snowy landscape needs at the bottom of the page.
 */

:root {
  --xmas-wire: #2f4a35;
  --xmas-red: #e0342f;
  --xmas-gold: #f5b70a;
  --xmas-green: #2f9e44;
  --xmas-blue: #2f7fe0;
  --xmas-glow: 2.5px;
}
:root[data-theme="dark"] {
  --xmas-wire: #5d7464;
  --xmas-red: #ff5a4f;
  --xmas-gold: #ffd23f;
  --xmas-green: #4fd46a;
  --xmas-blue: #5aa8ff;
  --xmas-glow: 4px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --xmas-wire: #5d7464;
    --xmas-red: #ff5a4f;
    --xmas-gold: #ffd23f;
    --xmas-green: #4fd46a;
    --xmas-blue: #5aa8ff;
    --xmas-glow: 4px;
  }
}

/* ---------- String of lights under the menu bar ---------- */

.xmas-lights {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 26px;
  overflow: hidden;
  pointer-events: none;
}
.xmas-lights svg { display: block; overflow: visible; }
.xmas-wire { fill: none; stroke: var(--xmas-wire); stroke-width: 1.4; stroke-linecap: round; }
.xmas-socket { fill: var(--xmas-wire); }
.xmas-shine { fill: #fff; opacity: .55; }
.xmas-red   { --bulb: var(--xmas-red); }
.xmas-gold  { --bulb: var(--xmas-gold); }
.xmas-green { --bulb: var(--xmas-green); }
.xmas-blue  { --bulb: var(--xmas-blue); }
.xmas-glass { fill: var(--bulb); }
.xmas-bulb {
  filter: drop-shadow(0 0 var(--xmas-glow) var(--bulb));
  animation: xmas-twinkle 2.6s ease-in-out infinite;
}
/* Out for a moment under the mouse: a dark bulb with no glow */
.xmas-bulb.is-off {
  animation: none;
  opacity: 1;
  filter: none;
}
.xmas-bulb.is-off .xmas-glass { fill: color-mix(in srgb, var(--bulb) 30%, #3a3f47); }
.xmas-bulb.is-off .xmas-shine { opacity: .25; }
@keyframes xmas-twinkle {
  0%, 100% { opacity: 1; }
  45%      { opacity: .55; }
  55%      { opacity: .6; }
}

/* ---------- Santa hat on the large logo ---------- */

.brand { position: relative; }
.xmas-hat {
  position: absolute;
  left: -17px;
  top: -25px;
  width: 52px;
  height: auto;
  transform: rotate(-16deg);
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .25));
}
.xmas-hat-body { fill: #d62828; }
.xmas-hat-shade { fill: #a51d1d; }
.xmas-hat-fur { fill: #f8f8f8; }
@media (max-width: 40em) {
  .xmas-hat { left: -12px; top: -18px; width: 38px; }
}

/* ---------- Comet crossing the header, behind the logo ---------- */

.band > .xmas-sky {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.xmas-comet {
  position: absolute;
  left: 0;
  top: 0;
  width: 110px;
  height: 2px;
  margin-left: -110px;
  border-radius: 2px;
  /* The head is the right end; the tail fades out behind it */
  background: linear-gradient(to right, transparent, var(--xmas-comet-tail) 70%, var(--xmas-comet-head));
  transform-origin: 100% 50%;
  animation: xmas-comet 1.5s cubic-bezier(.4, 0, .6, 1) forwards;
}
.xmas-comet::after {
  content: "";
  position: absolute;
  right: -3px;
  top: -2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--xmas-comet-head);
  box-shadow: 0 0 6px 2px var(--xmas-comet-glow), 0 0 14px 4px var(--xmas-comet-glow);
}
@keyframes xmas-comet {
  0%   { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--angle)); }
  15%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(var(--x) + var(--dx)), calc(var(--y) + var(--dy))) rotate(var(--angle)); }
}
:root {
  --xmas-comet-head: #fff;
  --xmas-comet-tail: rgba(34, 87, 214, .55);
  --xmas-comet-glow: rgba(245, 183, 10, .8);
}
:root[data-theme="dark"] {
  --xmas-comet-tail: rgba(255, 255, 255, .7);
  --xmas-comet-glow: rgba(255, 214, 102, .75);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --xmas-comet-tail: rgba(255, 255, 255, .7);
    --xmas-comet-glow: rgba(255, 214, 102, .75);
  }
}

/* ---------- Back-to-top button as a Christmas ornament ---------- */

:root[data-xmas~="ball"] .back-to-top {
  overflow: visible;
  background: radial-gradient(circle at 34% 30%, #ff9a8f 0, #e3342f 32%, #a31616 78%, #7d0f0f 100%);
  color: #fff;
  box-shadow: 0 6px 14px rgba(125, 15, 15, .35);
}
:root[data-xmas~="ball"] .back-to-top:hover {
  background: radial-gradient(circle at 34% 30%, #ffb3aa 0, #f04a43 32%, #b51d1d 78%, #8a1212 100%);
}
/* The metal cap and the loop it hangs from */
:root[data-xmas~="ball"] .back-to-top::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  width: 14px;
  height: 8px;
  transform: translateX(-50%);
  border-radius: 3px 3px 2px 2px;
  background: linear-gradient(90deg, #9c7412, #f3d27a 45%, #b8860b);
}
:root[data-xmas~="ball"] .back-to-top::after {
  content: "";
  position: absolute;
  top: -14px;
  left: 50%;
  width: 8px;
  height: 9px;
  transform: translateX(-50%);
  border: 2px solid #c9a227;
  border-bottom-color: transparent;
  border-radius: 50% 50% 40% 40%;
}

/* ---------- Frost in the corners of the window ---------- */

.xmas-frost {
  position: fixed;
  inset: 0;
  /* Above the sticky bar, as frost is on the glass in front of everything; it takes no clicks */
  z-index: 55;
  pointer-events: none;
  --frost-haze: rgba(150, 182, 232, .3);
  --frost: rgba(120, 158, 222, .85);
  --frost-size: 320px 230px;
}
/* Two layers: a soft haze where the glass is coldest, and patchy crystals over it */
.xmas-frost::before,
.xmas-frost::after {
  content: "";
  position: absolute;
  inset: 0;
}
.xmas-frost::before {
  background:
    radial-gradient(ellipse var(--frost-size) at 0 0, var(--frost-haze), transparent 65%),
    radial-gradient(ellipse var(--frost-size) at 100% 0, var(--frost-haze), transparent 65%),
    radial-gradient(ellipse var(--frost-size) at 0 100%, var(--frost-haze), transparent 65%),
    radial-gradient(ellipse var(--frost-size) at 100% 100%, var(--frost-haze), transparent 65%);
}
.xmas-frost::after {
  background:
    radial-gradient(ellipse var(--frost-size) at 0 0, var(--frost), transparent 60%),
    radial-gradient(ellipse var(--frost-size) at 100% 0, var(--frost), transparent 60%),
    radial-gradient(ellipse var(--frost-size) at 0 100%, var(--frost), transparent 60%),
    radial-gradient(ellipse var(--frost-size) at 100% 100%, var(--frost), transparent 60%);
  /* Noise drawn by the browser and cut sharp, so the crystals form patches and veins rather than grain */
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.09 .12' numOctaves='4' seed='11'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 -2.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.09 .12' numOctaves='4' seed='11'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 -2.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
}
:root[data-theme="dark"] .xmas-frost { --frost-haze: rgba(255, 255, 255, .1); --frost: rgba(235, 243, 255, .55); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .xmas-frost { --frost-haze: rgba(255, 255, 255, .1); --frost: rgba(235, 243, 255, .55); }
}
@media (max-width: 40em) {
  .xmas-frost { --frost-size: 170px 130px; }
}

/* ---------- Snowy landscape on the top edge of the footer ---------- */

.band > .xmas-landscape {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 64px;
  overflow: hidden;
  pointer-events: none;
  line-height: 0;
}
.xmas-landscape svg { display: block; }
/* Room for the landscape, which would otherwise reach whatever the page ends with (a pager, a counter) */
:root[data-xmas~="landscape"] .site-main { padding-bottom: 96px; }
.xmas-hill-far  { fill: #e6eef9; }
.xmas-hill-near { fill: #fff; }
.xmas-fir       { fill: #1f5c3a; }
.xmas-fir-snow  { fill: #fff; }
.xmas-trunk     { fill: #6b4a2b; }
:root[data-theme="dark"] .xmas-hill-far { fill: #c9d6ea; }
:root[data-theme="dark"] .xmas-fir { fill: #2c7a4d; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .xmas-hill-far { fill: #c9d6ea; }
  :root:not([data-theme]) .xmas-fir { fill: #2c7a4d; }
}

/* ---------- Falling snow ---------- */

.xmas-snow {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Under the sticky menu bar (50), so the flakes fall from behind it */
  z-index: 45;
  pointer-events: none;
}

/* ---------- Fireworks launched by a click on the background ---------- */

.xmas-fireworks {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Behind the snow, which falls in front of everything far away, and under the menu bar */
  z-index: 44;
  pointer-events: none;
}

/* Above the snow settled at the bottom of the window, so it stays in sight and in reach */
.back-to-top { z-index: 46; }

/* The button that stops and restarts the snow, shown by the script that makes it work */
.snow-toggle[hidden] { display: none; }
.snow-toggle.is-stopped svg { opacity: .45; }

@media (prefers-reduced-motion: reduce) {
  .xmas-bulb { animation: none; }
  .xmas-comet { display: none; }
}

@media print {
  .xmas-lights, .xmas-hat, .xmas-snow, .snow-toggle, .xmas-sky, .xmas-frost, .xmas-landscape, .xmas-fireworks { display: none !important; }
}
