/* =========================================================
   Nedtelling til julaften – del 1: scene, hovednedtelling,
   sekundære nedtellinger
   ========================================================= */

:root {
  --ink: #fff8e7;
  --gold: #ffd45e;
  --gold-2: #ffb02e;
  --red: #e8453c;
  --green: #2e8b57;
  --font-head: "Mountains of Christmas", "Segoe Print", "Comic Sans MS", cursive;
  --font-body: "Fredoka", ui-rounded, "Trebuchet MS", system-ui, sans-serif;
  --w: clamp(78px, min(17vw, 22vh), 250px);   /* bredde på hovedkortene */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100%; }
body {
  background: #070d24;
  color: var(--ink);
  font-family: var(--font-body);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Bakgrunn ---------- */
.sky {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(120% 55% at 50% 108%, rgba(255, 150, 90, .55), transparent 60%),
    linear-gradient(180deg, #040818 0%, #0b1438 34%, #232468 62%, #5b3a84 82%, #b55f7c 100%);
}

.aurora { position: fixed; inset: 0 0 35% 0; z-index: 1; overflow: hidden; pointer-events: none; }
.aurora i {
  position: absolute; width: 70vw; height: 34vh; top: 6vh;
  opacity: .36;
  background:
    radial-gradient(ellipse 36% 55% at 32% 50%, rgba(61, 245, 176, .85), transparent 72%),
    radial-gradient(ellipse 36% 55% at 68% 50%, rgba(79, 140, 255, .85), transparent 72%);
  transform: rotate(-10deg);
  animation: aurora 22s ease-in-out infinite alternate;
}
.aurora i:nth-child(1) { left: -10vw; }
.aurora i:nth-child(2) { left: 30vw; top: 14vh; opacity: .28; animation-duration: 29s; animation-delay: -9s;
  background:
    radial-gradient(ellipse 36% 55% at 32% 50%, rgba(180, 109, 255, .85), transparent 72%),
    radial-gradient(ellipse 36% 55% at 68% 50%, rgba(61, 245, 176, .85), transparent 72%); }
.aurora i:nth-child(3) { left: 55vw; top: 2vh; opacity: .24; animation-duration: 36s; animation-delay: -17s;
  background:
    radial-gradient(ellipse 36% 55% at 32% 50%, rgba(79, 140, 255, .85), transparent 72%),
    radial-gradient(ellipse 36% 55% at 68% 50%, rgba(255, 122, 217, .85), transparent 72%); }
@keyframes aurora {
  from { transform: translateX(-6vw) rotate(-12deg) scaleY(.8); }
  to   { transform: translateX(8vw)  rotate(-6deg)  scaleY(1.25); }
}

#stars, #snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#stars { z-index: 1; }
#snow  { z-index: 8; }

.moon {
  position: fixed; z-index: 2;
  width: clamp(110px, 12vw, 190px);
  right: calc(1vw + 24px); top: 4vh;
  animation: moonbob 14s ease-in-out infinite alternate;
}
@keyframes moonbob { to { transform: translateY(10px); } }

#landscape {
  position: fixed; z-index: 3; left: 0; right: 0; bottom: 0;
  width: 100%; height: clamp(210px, 40vh, 520px);
}

#garland { position: fixed; z-index: 4; left: 0; top: 0; width: 100%; height: 120px; pointer-events: none; }

.vignette {
  position: fixed; inset: 0; z-index: 7; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(2, 4, 16, .55) 100%);
}

/* ---------- Landskaps-animasjoner ---------- */
.window rect:first-child { animation: flicker 4.2s ease-in-out infinite alternate; }
.window.w2 rect:first-child { animation-duration: 5.3s; animation-delay: -2s; }
@keyframes flicker { 0% { opacity: .82; } 40% { opacity: 1; } 100% { opacity: .9; } }

.smoke circle { transform-box: fill-box; transform-origin: center; opacity: 0; animation: smoke 6s linear infinite; }
.smoke circle:nth-child(2) { animation-delay: -2s; }
.smoke circle:nth-child(3) { animation-delay: -4s; }
@keyframes smoke {
  0%   { transform: translate(0, 0) scale(.6); opacity: 0; }
  15%  { opacity: .55; }
  100% { transform: translate(28px, -90px) scale(3); opacity: 0; }
}

.tl { transform-box: fill-box; transform-origin: center; animation: twinkle 2.2s ease-in-out infinite alternate; }
@keyframes twinkle { from { opacity: .35; } to { opacity: 1; } }
.star-halo { transform-box: fill-box; transform-origin: center; animation: halo 3s ease-in-out infinite alternate; }
@keyframes halo { from { transform: scale(.8); opacity: .6; } to { transform: scale(1.25); opacity: 1; } }

.bulb { animation: bulb 2.4s ease-in-out infinite alternate; }
@keyframes bulb { from { opacity: .45; } to { opacity: 1; } }

/* ---------- Scene / layout ---------- */
.stage {
  position: relative; z-index: 5;
  min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 7.5rem 1rem calc(clamp(210px, 40vh, 520px) * .55);
  text-align: center;
}

/* ---------- Tittel ---------- */
.eyebrow {
  display: inline-flex; align-items: center; gap: .7rem;
  font-weight: 600; text-transform: uppercase; letter-spacing: .38em;
  font-size: clamp(.8rem, 1.8vw, 1.25rem);
  color: var(--gold);
  text-shadow: 0 0 14px rgba(255, 190, 80, .55);
}
.eyebrow .sp { width: 1.4em; height: 1.4em; animation: spin 9s linear infinite; }
.eyebrow .sp:last-child { animation-direction: reverse; }
@keyframes spin { to { transform: rotate(360deg); } }

h1 {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(3.6rem, 12.5vw, 9rem);
  line-height: 1;
  margin: .05em 0 .1em;
  background: linear-gradient(180deg, #ffffff 15%, #ffe9a8 60%, #ffc24d 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px rgba(255, 170, 70, .5)) drop-shadow(0 4px 0 rgba(120, 30, 20, .55));
}

.when {
  font-weight: 500;
  font-size: clamp(.85rem, 1.7vw, 1.15rem);
  color: rgba(255, 248, 231, .78);
  letter-spacing: .04em;
  margin-bottom: clamp(1.2rem, 3.5vh, 2.4rem);
}
.when::first-letter { text-transform: uppercase; }

/* ---------- Hovednedtelling ---------- */
.clock { display: flex; gap: clamp(.5rem, 1.6vw, 1.5rem); justify-content: center; }

.unit {
  position: relative;
  width: var(--w);
  aspect-ratio: 5 / 6;
  border-radius: calc(var(--w) * .14);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background:
    linear-gradient(165deg, rgba(255, 255, 255, .14), transparent 38%),
    linear-gradient(160deg, rgba(44, 58, 132, .92), rgba(14, 20, 62, .94));
  border: 2px solid rgba(255, 212, 94, .55);
  box-shadow: 0 0 34px rgba(255, 170, 60, .22), 0 14px 30px rgba(0, 0, 8, .45), inset 0 0 34px rgba(255, 255, 255, .06);
  animation: bob 6s ease-in-out infinite alternate;
}
.unit:nth-child(2) { animation-delay: -1.5s; }
.unit:nth-child(3) { animation-delay: -3s; }
.unit:nth-child(4) { animation-delay: -4.5s; }
@keyframes bob { to { transform: translateY(-6px); } }

/* strikket sting-kant */
.unit::after {
  content: ""; position: absolute; inset: calc(var(--w) * .045);
  border: 1.5px dashed rgba(255, 255, 255, .2);
  border-radius: calc(var(--w) * .1);
  pointer-events: none;
}

.num {
  font-family: var(--font-body); font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: calc(var(--w) * .54);
  line-height: 1;
  background: linear-gradient(180deg, #fff 10%, #ffe28a 55%, #ffb02e 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 176, 46, .55));
  min-width: 2ch; text-align: center;
}
.num.d3 { font-size: calc(var(--w) * .42); }
.num.pop { animation: pop .45s ease-out; }
@keyframes pop {
  0%   { transform: scale(1.22); filter: drop-shadow(0 0 26px rgba(255, 230, 140, .95)) brightness(1.4); }
  100% { transform: scale(1);    filter: drop-shadow(0 0 14px rgba(255, 176, 46, .55)); }
}

.lbl {
  margin-top: calc(var(--w) * .04);
  font-family: var(--font-head); font-weight: 700;
  font-size: calc(var(--w) * .15);
  color: #ffd9d4;
  text-shadow: 0 0 10px rgba(232, 69, 60, .6);
}

.ring { position: absolute; inset: -2px; width: calc(100% + 4px); height: calc(100% + 4px); overflow: visible; pointer-events: none; }
.ring rect {
  fill: none; stroke: #ff6b5b; stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 0;
  filter: drop-shadow(0 0 5px rgba(255, 107, 91, .9));
}
.secs { border-color: rgba(255, 255, 255, .25); }

/* pynt på kortene */
.deco { position: absolute; pointer-events: none; z-index: 2; overflow: visible; }
.hat   { width: 66%; top: -27%; left: -15%; transform: rotate(-14deg); filter: drop-shadow(0 4px 6px rgba(0,0,0,.4)); }
.holly { width: 42%; filter: drop-shadow(0 3px 4px rgba(0,0,0,.4)); }
.holly.tr { top: -12%; right: -12%; transform: rotate(18deg); }
.holly.bl { bottom: -11%; left: -12%; transform: rotate(-12deg) scaleX(-1); }

/* ---------- Melding + feiring ---------- */
.message {
  margin-top: clamp(1.4rem, 4vh, 2.6rem);
  min-height: 1.6em;
  max-width: 32rem;
  /* Fast bredde og eget lag: ellers kan Safari la rester av en lengre, forrige tekst bli stående */
  width: min(32rem, 100%);
  will-change: opacity;
  isolation: isolate;
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 500;
  color: #fff3d6;
  text-shadow: 0 2px 10px rgba(0, 0, 20, .7);
  transition: opacity .8s ease;
}
.message.out { opacity: 0; }

.celebrate {
  font-family: var(--font-head); font-weight: 700;
  font-size: clamp(3rem, 11vw, 8rem); line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(255, 190, 80, .8);
}
.celebrate span { display: block; font-family: var(--font-body); font-weight: 500; font-size: .22em; color: var(--ink); margin-top: .6em; }
body.is-christmas .clock { display: none; }
body.is-christmas .celebrate { display: block; animation: pop .8s ease-out; }

/* ---------- Sekundære nedtellinger (hengende pynt) ---------- */
.ornaments {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 1.9rem .9rem;
  margin-top: 2.2rem;
}

.orn {
  --len: 80px;
  display: flex; flex-direction: column; align-items: center;
  width: max-content;
  transform-origin: 50% 0;
  animation: swing var(--dur, 6s) ease-in-out var(--delay, 0s) infinite alternate;
}
.orn::before {                       /* tråden */
  content: ""; width: 2px; height: 14px;
  background: linear-gradient(rgba(255, 224, 150, .35), rgba(255, 224, 150, .9));
}
@keyframes swing { from { transform: rotate(-3.2deg); } to { transform: rotate(3.2deg); } }

.chip {
  position: relative;
  padding: 1.35rem .75rem .55rem;
  min-width: 8.6rem;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(48, 60, 138, .93), rgba(18, 24, 70, .95));
  border: 1.5px solid rgba(255, 212, 94, .5);
  box-shadow: 0 0 20px rgba(255, 170, 60, .2), 0 8px 16px rgba(0, 0, 10, .4);
}
.chip .ic {                           /* ikon-knapp som stikker opp over kortet */
  position: absolute; left: 50%; top: -17px; transform: translateX(-50%);
  width: 36px; height: 36px; padding: 5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #5b6bd0, #1e2766);
  border: 1.5px solid rgba(255, 212, 94, .8);
  box-shadow: 0 0 12px rgba(255, 190, 80, .5);
}
.chip .ic svg { width: 100%; height: 100%; display: block; }
.chip .nm { display: block; font-size: .74rem; font-weight: 500; letter-spacing: .02em; color: rgba(255, 248, 231, .85); white-space: nowrap; }
.chip .tm { display: flex; justify-content: center; gap: .45rem; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.chip .seg { display: inline-flex; align-items: baseline; gap: 1px; }
.chip .seg b { font-size: 1.1rem; font-weight: 700; color: var(--gold); min-width: 2ch; text-align: right; }
.chip .seg i { font-style: normal; font-size: .68rem; font-weight: 500; color: #ffd9d4; }
.chip.done .tm { color: #9fe3b4; font-weight: 600; font-size: .9rem; }

/* På brede skjermer henger de rundt omkring på skjermen, festet i lysslyngen */
@media (min-width: 1180px) {
  .ornaments {
    position: fixed; inset: 0; z-index: 5; margin: 0; display: block; pointer-events: none;
  }
  .orn {
    position: absolute; top: -2px; pointer-events: auto;
    left: var(--l, auto); right: var(--r, auto);
  }
  .orn::before { height: var(--len); }
  .orn:hover .chip { box-shadow: 0 0 30px rgba(255, 200, 90, .55), 0 8px 16px rgba(0, 0, 10, .4); }
}

/* ---------- Små skjermer ---------- */
@media (max-width: 1179px) {
  .moon { right: 4vw; width: clamp(80px, 16vw, 150px); top: 3vh; }
}

@media (max-width: 600px) {
  .stage { padding-top: 6.5rem; }
  .eyebrow { letter-spacing: .22em; }
  .hat { top: -24%; }
  .clock { gap: 6px; }
  /* De små nedtellingene i to kolonner */
  .ornaments { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.7rem .6rem; width: 100%; max-width: 22rem; }
  .orn { width: auto; }
  .chip { min-width: 0; width: 100%; padding: 1.3rem .4rem .5rem; }
  .chip .nm { font-size: .68rem; overflow: hidden; text-overflow: ellipsis; }
  .chip .tm { gap: .3rem; }
  .chip .seg b { font-size: .95rem; }
  .chip .seg i { font-size: .6rem; }
}

@media (prefers-reduced-motion: reduce) {
  .aurora i, .moon, .unit, .orn, .eyebrow .sp, .smoke circle, .tl, .bulb, .star-halo { animation: none !important; }
  .num.pop { animation: none; }
}

/* =========================================================
   Del 2: reinsdyr, nisser og slede
   ========================================================= */

/* Reinsdyr */
.leg { transform-box: fill-box; transform-origin: 50% 0; }
.deer.run .leg { animation: run .42s ease-in-out infinite alternate; }
.deer.run .leg.b2, .deer.run .leg.f1 { animation-direction: alternate-reverse; }
@keyframes run { from { transform: rotate(-34deg); } to { transform: rotate(34deg); } }

.deer .head { transform-box: fill-box; transform-origin: 10% 95%; animation: nod 7s ease-in-out infinite; }
.deer.run .head { animation: none; }
@keyframes nod { 0%, 100% { transform: rotate(0); } 45%, 60% { transform: rotate(6deg); } }

.deer .eye { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.08); } }

.deer .glow { transform-box: fill-box; transform-origin: center; animation: nose 1.5s ease-in-out infinite alternate; }
@keyframes nose { from { opacity: .5; transform: scale(.8); } to { opacity: 1; transform: scale(1.35); } }

.hover { animation: hover 1.3s ease-in-out var(--dl, 0s) infinite alternate; }
@keyframes hover { from { transform: translateY(-3px); } to { transform: translateY(4px); } }

/* Nisser */
.arm.wave { transform-box: fill-box; transform-origin: 0% 100%; animation: wave 1.1s ease-in-out infinite alternate; }
@keyframes wave { from { transform: rotate(-14deg); } to { transform: rotate(22deg); } }

.patrol { transform-origin: 0 0; animation: patrol 56s linear infinite; }
@keyframes patrol {
  0%   { transform: translateX(0) scaleX(1); }
  46%  { transform: translateX(calc(var(--D) * 1px)) scaleX(1); }
  50%  { transform: translateX(calc(var(--D) * 1px)) scaleX(-1); }
  96%  { transform: translateX(0) scaleX(-1); }
  100% { transform: translateX(0) scaleX(1); }
}
.waddle { transform-origin: 0 0; animation: waddle .55s ease-in-out infinite alternate; }
@keyframes waddle { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }

/* Slede som flyr forbi (foran alt unntatt snøen) */
#flyer {
  position: fixed; left: 0; top: 0; z-index: 6;
  width: clamp(230px, 26vw, 440px);
  pointer-events: none; visibility: hidden; will-change: transform;
}
#flyer svg { display: block; width: 100%; height: auto; overflow: visible; filter: drop-shadow(0 0 10px rgba(255, 210, 120, .35)); }

@media (prefers-reduced-motion: reduce) {
  .deer .head, .deer .eye, .deer .glow, .hover, .arm.wave, .patrol, .waddle, .deer.run .leg, .googly .pupil { animation: none !important; }
  #flyer { display: none; }
}

/* =========================================================
   Del 4: lyd (start-skjerm og kontroller)
   ========================================================= */
.start {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: rgba(4, 8, 24, .62);
  backdrop-filter: blur(7px);
  transition: opacity .6s ease, visibility .6s;
}
.start[hidden] { display: none; }
.start.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.start-card {
  max-width: 24rem; text-align: center; padding: 2rem 1.6rem 1.5rem;
  border-radius: 26px;
  background: linear-gradient(160deg, rgba(48, 60, 138, .92), rgba(16, 22, 66, .95));
  border: 2px solid rgba(255, 212, 94, .6);
  box-shadow: 0 0 60px rgba(255, 170, 60, .3), 0 20px 50px rgba(0, 0, 10, .6);
}
.start-star { width: 3rem; height: 3rem; animation: spin 10s linear infinite; }
.start h2 { font-family: var(--font-head); font-size: 2.3rem; line-height: 1.1; margin: .3rem 0 .5rem; color: var(--gold); text-shadow: 0 0 20px rgba(255, 190, 80, .6); }
.start p { color: rgba(255, 248, 231, .85); margin-bottom: 1.3rem; line-height: 1.4; }
.go {
  display: block; width: 100%; padding: .85rem 1rem; cursor: pointer;
  font: 600 1.1rem var(--font-body); color: #3a1d00;
  border: 0; border-radius: 999px;
  background: linear-gradient(180deg, #ffe28a, #ffb02e);
  box-shadow: 0 0 24px rgba(255, 176, 46, .55), inset 0 -3px 0 rgba(160, 90, 0, .35);
  transition: transform .15s;
}
.go:hover { transform: scale(1.04); }
.skip { margin-top: .9rem; background: none; border: 0; cursor: pointer; font: 500 .9rem var(--font-body); color: rgba(255, 248, 231, .7); text-decoration: underline; }
.go:focus-visible, .skip:focus-visible, .sbtn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.sound { position: fixed; right: 14px; bottom: 14px; z-index: 9; display: flex; align-items: center; gap: 8px; }
.sbtn {
  width: 44px; height: 44px; padding: 10px; cursor: pointer; color: var(--gold);
  border-radius: 50%;
  background: linear-gradient(160deg, rgba(48, 60, 138, .88), rgba(16, 22, 66, .92));
  border: 1.5px solid rgba(255, 212, 94, .6);
  box-shadow: 0 0 16px rgba(255, 170, 60, .25), 0 4px 10px rgba(0, 0, 10, .4);
}
.sbtn svg { width: 100%; height: 100%; display: block; }
#soundBtn .off { display: none; }
#soundBtn.off .on { display: none; }
#soundBtn.off .off { display: block; }
#soundBtn.off { color: rgba(255, 248, 231, .6); border-color: rgba(255, 255, 255, .3); }

.sound-panel {
  position: absolute; right: 0; bottom: 56px; width: 14.5rem; padding: .8rem .9rem;
  display: none; flex-direction: column; gap: .5rem;
  font-size: .88rem; color: var(--ink);
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(48, 60, 138, .94), rgba(16, 22, 66, .96));
  border: 1.5px solid rgba(255, 212, 94, .5);
  box-shadow: 0 8px 24px rgba(0, 0, 10, .5);
}
.sound.open .sound-panel { display: flex; }
.sound-panel .row { display: flex; align-items: center; gap: .5rem; cursor: pointer; }
.sound-panel .vol { justify-content: space-between; }
.sound-panel input[type=range] { flex: 1; accent-color: var(--gold); }
.sound-panel input[type=checkbox] { accent-color: var(--gold); width: 1rem; height: 1rem; }

/* =========================================================
   Snøfolk-gjengen (kollegaer som snømenn)
   ========================================================= */
.stage { pointer-events: none; }                 /* så snøfolkene nederst kan klikkes */
.title, .clock, .message, .celebrate { pointer-events: auto; }
#landscape { pointer-events: none; }
.snowman { pointer-events: all; cursor: pointer; }
.sway { transform-origin: 0 0; animation: sway 4.6s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotate(-1.6deg); } to { transform: rotate(1.6deg); } }
.snowman:hover .sway { animation-duration: 1.6s; }
.boing { transform-origin: 0 0; }
.boing.go { animation: boing .8s ease-out; }
@keyframes boing {
  0%   { transform: scale(1, 1); }
  18%  { transform: scale(1.14, .84); }
  42%  { transform: translateY(-26px) scale(.92, 1.1); }
  66%  { transform: scale(1.08, .93); }
  100% { transform: scale(1, 1); }
}

.bubble {
  position: fixed; z-index: 9; max-width: 15rem; padding: .55rem .85rem;
  transform: translate(-50%, -100%) scale(.8); transform-origin: 50% 100%;
  opacity: 0; pointer-events: none;
  background: #fffdf6; color: #2a2150; border-radius: 16px;
  font: 600 .95rem var(--font-body); text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 20, .45);
  transition: opacity .25s, transform .25s;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -8px; margin-left: -8px;
  border: 8px solid transparent; border-bottom: 0; border-top-color: #fffdf6;
}
.bubble.show { opacity: 1; transform: translate(-50%, -100%) scale(1); }

@media (prefers-reduced-motion: reduce) {
  .sway, .boing.go { animation: none !important; }
}

/* Googly eyes på nissene: pupillen slenger rundt inni øyet */
.googly .pupil { animation: googly 1.8s ease-in-out infinite; }
@keyframes googly {
  0%   { transform: translate(0, calc(var(--gr) * .9)); }
  10%  { transform: translate(calc(var(--gr) * .9), calc(var(--gr) * .5)); }
  18%  { transform: translate(calc(var(--gr) * -.8), calc(var(--gr) * .7)); }
  30%  { transform: translate(calc(var(--gr) * .3), calc(var(--gr) * -1)); }
  38%  { transform: translate(calc(var(--gr) * -1), calc(var(--gr) * -.2)); }
  52%  { transform: translate(calc(var(--gr) * .7), calc(var(--gr) * .8)); }
  60%  { transform: translate(calc(var(--gr) * -.4), calc(var(--gr) * 1)); }
  74%  { transform: translate(calc(var(--gr) * 1), calc(var(--gr) * -.4)); }
  86%  { transform: translate(calc(var(--gr) * -.7), calc(var(--gr) * -.8)); }
  100% { transform: translate(0, calc(var(--gr) * .9)); }
}

/* Maren faller sammen: toppen (hode, armer, skjerf) ramler av, ligger litt i snøen og spretter på plass igjen */
.tumble .sf-top { transform-origin: -14px -62px; animation: tumble-top 5.2s ease-in-out both; }
.tumble .sf-base { transform-origin: 0 0; animation: tumble-base 5.2s ease-in-out both; }
@keyframes tumble-top {
  0%   { transform: none; }
  5%   { transform: rotate(-7deg); }
  9%   { transform: rotate(6deg); }
  13%  { transform: rotate(-9deg); }
  27%  { transform: translate(-58px, 28px) rotate(-96deg); animation-timing-function: ease-out; }
  31%  { transform: translate(-64px, 18px) rotate(-90deg); animation-timing-function: ease-in; }
  35%  { transform: translate(-66px, 28px) rotate(-96deg); }
  50%  { transform: translate(-66px, 28px) rotate(-96deg); }
  53%  { transform: translate(-66px, 24px) rotate(-90deg); }
  56%  { transform: translate(-66px, 28px) rotate(-96deg); }
  68%  { transform: translate(-66px, 28px) rotate(-96deg); animation-timing-function: ease-out; }
  78%  { transform: translate(-22px, -46px) rotate(-30deg); animation-timing-function: ease-in; }
  86%  { transform: translate(0, 4px) rotate(5deg); }
  92%  { transform: translate(0, -6px) rotate(-3deg); }
  100% { transform: none; }
}
@keyframes tumble-base {
  0%, 13% { transform: none; }
  5%   { transform: rotate(-3deg); }
  9%   { transform: rotate(3deg); }
  27%  { transform: scale(1.08, .9); }
  33%, 84% { transform: none; }
  87%  { transform: scale(1.1, .86); }
  93%  { transform: scale(.96, 1.05); }
  100% { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tumble .sf-top, .tumble .sf-base { animation: none !important; }
}

/* Beaglen: bena går, halen logrer */
.beagle .bleg { transform-box: fill-box; transform-origin: 50% 0; }
.beagle.walk .bleg { animation: bwalk .34s ease-in-out infinite alternate; }
.beagle.walk .bleg.b2, .beagle.walk .bleg.f1 { animation-direction: alternate-reverse; }
.beagle.trot .bleg { animation-duration: .22s; }
@keyframes bwalk { from { transform: rotate(-22deg); } to { transform: rotate(22deg); } }
.beagle .btail { transform-box: fill-box; transform-origin: 100% 100%; animation: wag .28s ease-in-out infinite alternate; }
@keyframes wag { from { transform: rotate(-14deg); } to { transform: rotate(16deg); } }
@media (prefers-reduced-motion: reduce) {
  .beagle .bleg, .beagle .btail { animation: none !important; }
}

/* ---------- Hendelser (morgenmøte, gløgg, dupp, snøballkrig) ---------- */
.ev-pop { transform-box: fill-box; transform-origin: 50% 100%; animation: evpop .6s ease-out both; }
@keyframes evpop { from { opacity: 0; transform: translateY(10px) scale(.6); } }
.sign-t { font: 700 9px var(--font-body); fill: #fff3d6; letter-spacing: .04em; }
.sign-s { font: 600 7.5px var(--font-body); fill: #ffe0a0; }
.steam path { fill: none; stroke: rgba(255, 255, 255, .75); stroke-width: 1.6; stroke-linecap: round; opacity: 0;
  transform-box: fill-box; animation: steam 2.4s ease-out infinite; }
.steam path:nth-child(2) { animation-delay: -.8s; }
.steam path:nth-child(3) { animation-delay: -1.6s; }
@keyframes steam { 0% { opacity: 0; transform: translateY(4px); } 30% { opacity: .75; } 100% { opacity: 0; transform: translateY(-10px); } }

.ginger .gleg { transform-box: fill-box; transform-origin: 50% 0; animation: bwalk .2s ease-in-out infinite alternate; }
.ginger .gleg.r { animation-direction: alternate-reverse; }

.snowman.sleepy .sf-top { transform-origin: 0 -64px; animation: doze 3.6s ease-in-out infinite; }
@keyframes doze { 0%, 100% { transform: none; } 45%, 60% { transform: translateY(3px) rotate(8deg); } }
.zzz text { font-family: var(--font-body); font-weight: 700; fill: #e6eeff; opacity: 0;
  transform-box: fill-box; transform-origin: 50% 50%; animation: zfloat 3s linear infinite; }
.zzz text:nth-child(2) { animation-delay: -1s; }
.zzz text:nth-child(3) { animation-delay: -2s; }
@keyframes zfloat { 0% { opacity: 0; transform: translate(0, 0) scale(.5); } 15% { opacity: .95; } 100% { opacity: 0; transform: translate(14px, -44px) scale(1.15); } }
.ev-nap .roof-nisse .arm.wave { animation: none; }

.boing.throw { animation: throwk .45s ease-out; }
@keyframes throwk { 0% { transform: none; } 35% { transform: scale(1.07, .9); } 65% { transform: translateY(-4px) scale(.95, 1.07); } 100% { transform: none; } }
.boing.duck { animation: duck .7s ease-in-out; }
@keyframes duck { 0%, 100% { transform: none; } 25%, 65% { transform: scale(1.14, .7); } }
.splat-in { transform-box: fill-box; transform-origin: 50% 50%; animation: splat 5s ease-in forwards; }
@keyframes splat { 0% { transform: scale(.3); } 8% { transform: scale(1.12); } 14% { transform: none; } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(6px); } }

/* ---------- Rags: snøkanon og slalåm ---------- */
.cannon.on .cshake { animation: cshake .07s linear infinite alternate; }
@keyframes cshake { from { transform: translate(-.5px, .3px); } to { transform: translate(.5px, -.3px); } }
.gate { transform-box: fill-box; transform-origin: 50% 100%; }
.gate.knock { animation: knock .7s ease-out; }
@keyframes knock { 0%, 100% { transform: none; } 25% { transform: rotate(-16deg); } 55% { transform: rotate(8deg); } 80% { transform: rotate(-3deg); } }
.gate.down { animation: gdown .5s ease-in forwards; }
@keyframes gdown { to { transform: rotate(-80deg); } }

/* ---------- Tilfeldige overraskelser ---------- */
.dizzy .googly .pupil { animation-duration: .3s !important; }
.deer.flicker .glow, .deer.flicker .rnose { animation: flick 1s steps(1, end) infinite; }
@keyframes flick { 0% { opacity: 1; } 12% { opacity: .15; } 25% { opacity: 1; } 40% { opacity: 0; } 55% { opacity: .8; } 70% { opacity: 0; } 85% { opacity: .6; } }
.deer.dark .glow { animation: none; opacity: 0; }
.deer.dark .rnose { fill: #4a2424; }
.deer.bright .glow { animation: none; transform: scale(1.9); }
.deer.sneeze .head { animation: sneeze .6s ease-out; }
@keyframes sneeze { 0% { transform: none; } 30% { transform: rotate(-12deg); } 45% { transform: rotate(14deg); } 100% { transform: none; } }
.flash { position: fixed; inset: 0; z-index: 50; background: #fff; pointer-events: none; animation: flash .7s ease-out forwards; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }
.windy .snowman .sway { animation: windlean .5s ease-in-out infinite alternate; }
@keyframes windlean { from { transform: rotate(2deg); } to { transform: rotate(7deg); } }
.fox .fleg { transform-box: fill-box; transform-origin: 50% 0; animation: bwalk .4s ease-in-out infinite alternate; }
.fox .fleg.b { animation-direction: alternate-reverse; }
.fox.run .fleg { animation-duration: .14s; }
.runner .waddle { animation-duration: .22s; }
