/* ---------- Christmas (December only, see theme.js and christmas.js) ----------
   Everything here is scoped to html.christmas (or to elements only christmas.js
   creates), so the regular site and the other seasons are untouched. The scene
   is a 390x760 design box scaled by --u, like the Halloween house and the
   Thanksgiving dining room. */

html.christmas { background: #091a2c; }
html.christmas body { background: transparent; }

html.christmas .sky {
  background:
    radial-gradient(60% 34% at 50% 100%, rgba(255, 190, 90, 0.2), transparent 70%),
    linear-gradient(180deg, #091a2c 0%, #0b2238 60%, #14405e 100%);
  -webkit-mask-image: none;
  mask-image: none;
}

/* Leaderboard page: darker, blurred backing for the panels. */
html.christmas .board-row,
html.christmas .tabs,
html.christmas .boost-panel,
html.christmas .arcade-panel,
html.christmas .signup {
  background: rgba(9, 26, 44, 0.8);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

html.christmas { --u: min(calc(100vw / 390), calc(100svh / 760), 1.3px); }

html.christmas body:has(> .stage) {
  padding: 0;
  justify-content: center;
  overflow: hidden;
}

/* No overflow clipping on the stage: the wall, floor and string lights are drawn
   far wider/taller than the scene so they fill any window; the body clips. */
html.christmas .stage {
  flex: none;
  position: relative;
  display: block;
  width: calc(390 * var(--u));
  max-width: none;
  height: calc(760 * var(--u));
  margin: 0 auto;
}

/* No wheel, ring or hub: the present replaces them. Only the head that landed
   (.is-active) is shown, on the body. */
html.christmas .controls,
html.christmas .hub,
html.christmas .orbit,
html.christmas .spotlight,
html.christmas .figure::after {
  display: none;
}

html.christmas .ring-head:not(.is-active) {
  display: none;
}

/* The boots stand on the rug at y ~640 of 760: the Christmas body's last opaque
   row is 1511/1536, so with the offset below they end at top + 319u. */
html.christmas .figure {
  position: absolute;
  left: calc(95 * var(--u));
  top: calc(321 * var(--u));
  margin: 0;
  z-index: 2;
}

/* christmas_body has its neck (flat cut edge, row ~36 of 1536) 30 rows (1.95%)
   HIGHER in the image than body.png's (row 66), so it gets the regular 6% plus
   that, ~8%. Its torso centreline is x~503.5 of 1024 (body.png: ~500), so the
   centring shift is 0.9% instead of 1.17%. The per-head --chin-dy nudges in
   style.css apply unchanged. */
html.christmas .body-img {
  translate: 0.9% 8%;
}

/* ---- the room ---- */

.xm-room {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.xm-room svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Lights fade gently up and down (slow, nothing like a flash). */
.xm-bulb { animation: xm-twinkle 3.2s ease-in-out infinite; }
.xm-bulb.b1 { animation-duration: 4.1s; animation-delay: -1.3s; }
.xm-bulb.b2 { animation-duration: 2.6s; animation-delay: -0.7s; }
.xm-bulb.b3 { animation-duration: 3.7s; animation-delay: -2.2s; }

@keyframes xm-twinkle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.42; }
}

.stage.is-waiting .xm-bulb { animation-duration: 0.9s; }

.xm-star-glow {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: xm-pulse 3.6s ease-in-out infinite;
}

@keyframes xm-pulse {
  0%, 100% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.12); opacity: 1; }
}

/* Warm light behind the figure; fades in while the present is open. */
.xm-glow {
  position: absolute;
  left: calc(5 * var(--u));
  top: calc(200 * var(--u));
  width: calc(380 * var(--u));
  height: calc(480 * var(--u));
  z-index: 1;
  opacity: 0;
  transition: opacity 1s ease;
  pointer-events: none;
  background: radial-gradient(50% 50% at 50% 55%, rgba(255, 236, 170, 0.62), rgba(255, 190, 80, 0.2) 55%, transparent 76%);
}

.stage.door-open .xm-glow { opacity: 1; }

/* ---- the big present: the wrapping lifts off, the bow pops away ---- */

.gift-frame {
  position: absolute;
  left: calc(75 * var(--u));
  top: calc(205 * var(--u));
  width: calc(240 * var(--u));
  height: calc(450 * var(--u));
  z-index: 3;
  pointer-events: none;
}

.gift-shell {
  position: absolute;
  inset: 0;
  transform-origin: 50% 100%;
  transition: transform 1.3s cubic-bezier(0.45, 0, 0.2, 1), opacity 0.35s ease;
  filter: drop-shadow(0 calc(8 * var(--u)) calc(14 * var(--u)) rgba(0, 0, 0, 0.5));
  will-change: transform;
}

.gift-shell svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.gift-bow {
  position: absolute;
  left: calc(55 * var(--u));
  top: calc(12 * var(--u));
  width: calc(130 * var(--u));
  height: calc(90 * var(--u));
  transform-origin: 50% 80%;
  transition: transform 0.9s cubic-bezier(0.3, 1.35, 0.5, 1), opacity 0.5s ease 0.35s;
  filter: drop-shadow(0 calc(3 * var(--u)) calc(5 * var(--u)) rgba(0, 0, 0, 0.45));
}

.gift-bow svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* The wrapping lifts straight up and tilts away, fading near the top of its flight. */
.stage.door-open .gift-shell {
  transform: translate(calc(-26 * var(--u)), calc(-640 * var(--u))) rotate(-9deg);
  opacity: 0;
  transition: transform 1.3s cubic-bezier(0.45, 0, 0.2, 1), opacity 0.5s ease 0.85s;
}

.stage.door-open .gift-bow {
  transform: translate(calc(44 * var(--u)), calc(-170 * var(--u))) rotate(26deg) scale(1.12);
  opacity: 0;
}

/* While the present is shut and the new head is being chosen it shakes. */
.stage.is-waiting .gift-shell { animation: gift-rattle 0.42s ease-in-out infinite; }
.stage.is-waiting .gift-bow { animation: bow-jiggle 0.42s ease-in-out infinite; }

@keyframes gift-rattle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(calc(-4 * var(--u))) rotate(-1.3deg); }
  75% { transform: translateY(calc(-2 * var(--u))) rotate(1.2deg); }
}

@keyframes bow-jiggle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(calc(-5 * var(--u))) rotate(-4deg); }
  75% { transform: translateY(calc(-2 * var(--u))) rotate(3deg); }
}

/* Gold sparkles drifting up from the floor as the present opens. */
.xm-sparks {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.xm-sparks .spark {
  position: absolute;
  top: calc(600 * var(--u));
  width: calc(18 * var(--u));
  height: calc(18 * var(--u));
  opacity: 0;
  background: radial-gradient(circle, #fff7c2, #ffd23a 60%, rgba(255, 210, 58, 0));
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
  filter: drop-shadow(0 0 calc(4 * var(--u)) #ffe27a);
}

.xm-sparks .sp0 { left: calc(96 * var(--u)); --d: 0s; }
.xm-sparks .sp1 { left: calc(128 * var(--u)); --d: 0.12s; width: calc(12 * var(--u)); height: calc(12 * var(--u)); }
.xm-sparks .sp2 { left: calc(160 * var(--u)); --d: 0.05s; }
.xm-sparks .sp3 { left: calc(196 * var(--u)); --d: 0.2s; width: calc(24 * var(--u)); height: calc(24 * var(--u)); }
.xm-sparks .sp4 { left: calc(228 * var(--u)); --d: 0.1s; }
.xm-sparks .sp5 { left: calc(262 * var(--u)); --d: 0.25s; width: calc(12 * var(--u)); height: calc(12 * var(--u)); }
.xm-sparks .sp6 { left: calc(112 * var(--u)); --d: 0.32s; width: calc(10 * var(--u)); height: calc(10 * var(--u)); }
.xm-sparks .sp7 { left: calc(178 * var(--u)); --d: 0.38s; width: calc(14 * var(--u)); height: calc(14 * var(--u)); }
.xm-sparks .sp8 { left: calc(244 * var(--u)); --d: 0.3s; }
.xm-sparks .sp9 { left: calc(146 * var(--u)); --d: 0.42s; width: calc(10 * var(--u)); height: calc(10 * var(--u)); }

.stage.door-open .spark {
  animation: spark-rise 2.3s ease-out both;
  animation-delay: var(--d, 0s);
}

@keyframes spark-rise {
  0% { transform: translateY(0) scale(0.4) rotate(0deg); opacity: 0; }
  18% { opacity: 1; }
  100% { transform: translateY(calc(-300 * var(--u))) scale(1.2) rotate(120deg); opacity: 0; }
}

/* ---- sign and the ribbon button ---- */

.xm-sign {
  position: absolute;
  left: calc(103 * var(--u));
  top: calc(58 * var(--u));
  width: calc(184 * var(--u));
  z-index: 5;
  text-align: center;
  pointer-events: none;
}

.xm-eyebrow {
  margin: 0 0 calc(7 * var(--u));
  font-family: "DM Mono", "Space Grotesk", monospace;
  font-weight: 500;
  font-size: calc(8.5 * var(--u));
  line-height: 1.4;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #e6f4ff;
  text-shadow: 0 0 calc(6 * var(--u)) rgba(4, 12, 24, 0.95);
}

/* A candy-cane striped frame round a dark green board, hung from the garland bow. */
.xm-plate {
  position: relative;
  padding: calc(3.5 * var(--u));
  border-radius: calc(10 * var(--u));
  background: repeating-linear-gradient(135deg, #e11d2e 0 calc(7 * var(--u)), #fffaf0 calc(7 * var(--u)) calc(14 * var(--u)));
  box-shadow: 0 calc(4 * var(--u)) calc(14 * var(--u)) rgba(0, 0, 0, 0.5);
}

.xm-plate-in {
  padding: calc(8 * var(--u)) calc(4 * var(--u));
  border-radius: calc(7 * var(--u));
  background: linear-gradient(180deg, #14543a, #0a2f21);
  box-shadow: inset 0 0 0 calc(1.5 * var(--u)) rgba(255, 226, 122, 0.45);
}

.xm-plate::before,
.xm-plate::after {
  content: "";
  position: absolute;
  top: calc(-12 * var(--u));
  width: calc(2 * var(--u));
  height: calc(12 * var(--u));
  background: #ffd23a;
}

.xm-plate::before { left: calc(24 * var(--u)); }
.xm-plate::after { right: calc(24 * var(--u)); }

.xm-wordmark {
  display: block;
  font-family: "Bungee", "Space Grotesk", sans-serif;
  font-size: calc(23 * var(--u));
  line-height: 1.1;
  letter-spacing: 0.02em;
  white-space: nowrap;
  background: linear-gradient(180deg, var(--gold), var(--magenta) 60%, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 calc(6 * var(--u)) rgba(255, 46, 154, 0.45));
}

.ribbon-btn {
  position: absolute;
  left: calc(88 * var(--u));
  top: calc(702 * var(--u));
  width: calc(214 * var(--u));
  min-height: max(44px, calc(50 * var(--u)));
  z-index: 6;
  display: flex;
  align-items: center;
  gap: calc(8 * var(--u));
  padding: calc(5 * var(--u)) calc(12 * var(--u)) calc(5 * var(--u)) calc(9 * var(--u));
  border: calc(3 * var(--u)) solid #1b9a4e;
  border-radius: calc(14 * var(--u));
  background: linear-gradient(180deg, #fffaf0, #f0e4c8);
  color: #8f0e17;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 calc(3 * var(--u)) 0 #0d5a2c, 0 0 calc(16 * var(--u)) rgba(255, 210, 90, 0.5);
  animation: rb-pulse 1.8s ease-in-out infinite;
  transition: transform 0.12s ease;
}

@keyframes rb-pulse {
  0%, 100% { box-shadow: 0 calc(3 * var(--u)) 0 #0d5a2c, 0 0 calc(10 * var(--u)) rgba(255, 210, 90, 0.35); }
  50% { box-shadow: 0 calc(3 * var(--u)) 0 #0d5a2c, 0 0 calc(24 * var(--u)) rgba(255, 226, 130, 0.85); }
}

.ribbon-btn:hover { transform: scale(1.03); }
.ribbon-btn:active,
.ribbon-btn.is-pressed { transform: translateY(calc(2 * var(--u))) scale(0.97); }
.ribbon-btn:disabled { cursor: progress; animation: none; filter: saturate(0.5) brightness(0.8); }

.rb-icon {
  flex: none;
  width: calc(34 * var(--u));
  height: calc(34 * var(--u));
  overflow: visible;
}

.rb-icon g {
  transform-box: view-box;
  transform-origin: 50% 58%;
}

/* The bow tugs open: each loop kicks outward and settles back. */
.ribbon-btn.is-pressed .rb-l { animation: rb-tug-l 0.3s ease-out; }
.ribbon-btn.is-pressed .rb-r { animation: rb-tug-r 0.3s ease-out; }

@keyframes rb-tug-l { 40% { transform: rotate(-22deg) translateX(-3px); } }
@keyframes rb-tug-r { 40% { transform: rotate(22deg) translateX(3px); } }

.rb-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }

.rb-text strong {
  font-family: "Bungee", "Space Grotesk", sans-serif;
  font-weight: 400;
  font-size: calc(11 * var(--u));
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.rb-text span {
  margin-top: calc(2 * var(--u));
  font-family: "Space Grotesk", sans-serif;
  font-size: calc(8.5 * var(--u));
  font-weight: 500;
  letter-spacing: 0.03em;
  color: #0d5a2c;
  white-space: nowrap;
}

/* ---- snow: drifting ambient flakes, and the burst when a head lands ---- */

.xm-snow {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.xm-flake {
  position: absolute;
  top: 0;
  display: block;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 30%, rgba(255, 255, 255, 0.25) 70%, rgba(255, 255, 255, 0));
  animation: xm-fall linear infinite;
  will-change: transform;
}

@keyframes xm-fall {
  0% { transform: translate(0, -24px); }
  50% { transform: translate(var(--sway, 30px), 52vh); }
  100% { transform: translate(calc(var(--sway, 30px) * -0.5), 108vh); }
}

.xm-piece {
  position: absolute;
  display: block;
  pointer-events: none;
  will-change: transform, opacity;
  filter: drop-shadow(0 1px 3px rgba(0, 20, 40, 0.5));
}

.xm-piece svg { display: block; width: 100%; height: 100%; }

@media (prefers-reduced-motion: reduce) {
  .xm-bulb,
  .xm-star-glow,
  .xm-flake,
  .xm-glow,
  .gift-shell,
  .gift-bow,
  .stage.is-waiting .gift-shell,
  .stage.is-waiting .gift-bow,
  .stage.door-open .spark,
  .ribbon-btn,
  .ribbon-btn.is-pressed .rb-l,
  .ribbon-btn.is-pressed .rb-r {
    animation: none !important;
    transition: none !important;
  }

  .xm-snow { display: none; }
}
