/*
 * Святкові дудли: the drawings over the header logo on a holiday.
 * Loaded by assets/js/layout/doodles.js only on a day with a doodle, and on
 * the doodles screen in wp-admin for the previews. The drawings themselves are
 * in includes/modules/doodles/library.php.
 *
 * Nothing here moves the logo: every layer is absolutely placed, and the room
 * the wordmark gets above and below its letters is taken back by a negative
 * margin. Motion is transform and opacity only, and the header's own shrink on
 * scroll is left alone (see the note header-logo-stutter).
 */

.logo-link--doodle {
  --dd-snow: #8db6e3;
  --dd-snow-edge: #b9d2ec;
  --dd-ice-a: #ffffff;
  --dd-ice-b: #cfe8fd;
  --dd-ice-edge: #9cc6ee;
  --dd-vane: #ffffff;
  --dd-ink: #2062af;
  /* The garland: a thin gold wire; a bead that is off goes pale, not dark,
     and the glow is faint on white paper, where a full one smudged. */
  --dd-wire: #d2a93a;
  --dd-dim: #ffffff;
  --dd-glow: 0.45;
  --dd-wood: #6b4423;
  --dd-stitch: #1a1a1a;
  --dd-blue: #0057b7;
}

html[data-theme="dark"] .logo-link--doodle,
.dd-dark .logo-link--doodle {
  --dd-snow: #ffffff;
  --dd-snow-edge: transparent;
  --dd-ice-a: #f4faff;
  --dd-ice-b: #b4daf7;
  --dd-ice-edge: #7fb2e6;
  --dd-vane: #e6ebf2;
  --dd-ink: #8fb8f0;
  --dd-wire: #b8933a;
  --dd-dim: #161b1f;
  --dd-glow: 0.9;
  --dd-wood: #b48a62;
  --dd-stitch: #e9e1d2;
  --dd-blue: #4a95ec;
}

.dd-layer {
  position: absolute;
  pointer-events: none;
}

/* What doodles.js lays out in pixels: garlands and the picture beside the wordmark. */
.logo-link--doodle {
  position: relative;
}

.dd-letters {
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 3;
}

/* Under the wordmark (z-index 1) and the shield (2): it peeks out from behind them. */
.dd-side {
  z-index: 0;
}

.dd-g {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
}

.dd-side svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}


/*
 * What hangs on the wordmark from outside its box leaves and comes back with
 * it on scroll in the very same motion: the wordmark's own transition from
 * logo.css (0.5s ease-in-out, fading while moving 15px left). (Drawn inside
 * the wordmark's clipped box instead, the garland was not painted by Chrome.)
 */
.dd-letters,
.dd-side {
  transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
}

.header._scrolled .dd-letters,
.header._scrolled .dd-side {
  opacity: 0;
  transform: translateX(-15px);
}

/*
 * The wordmark does not only fade: its box closes from the right and its left
 * margin goes. The garland follows both, or its lights hung on at full length
 * under half a word. Its layer is a twin of that box (doodles.js puts the
 * box's place, margin and max-width on it) and closes with the very same
 * properties and transition as logo.css gives the box. An exception to
 * «transform and opacity only», on purpose: a twin that slid and cut the
 * garland by transforms ran on the compositor while the box closed on the
 * main thread, and on a busy scroll the two drifted apart (2026-11-30).
 */
.dd-letters {
  overflow: hidden;
  margin-left: var(--dd-ml, 0px);
  max-width: var(--dd-mw, none);
  transition: 0.5s ease-in-out;
  transition-property: max-width, margin-left, opacity, transform;
}

.header._scrolled .dd-letters {
  max-width: 0;
  margin-left: 0;
}

/*
 * The lights: doodles.js sets the pattern on the garland about once a second,
 * and a bead eases between on and dimmed instead of flicking, so the strand
 * glows rather than flickers (the owner, 2026-11-30: «глаза не мусолили»).
 */
.dd-gb__dim {
  opacity: 0;
  transition: opacity 0.6s ease-in-out;
}

.dd-gb__glow {
  opacity: var(--dd-glow);
  transition: opacity 0.6s ease-in-out;
  /* A bulb under the pointer flares from its own centre (doodles.js). */
  transform-box: fill-box;
  transform-origin: center;
}

/* Flakes shaken off the pompom (doodles.js), over the shield's edge. */
.dd-puff {
  z-index: 4;
}

.dd-g[data-p="c0"] .dd-gb:not(.dd-gb--m0) .dd-gb__dim,
.dd-g[data-p="c1"] .dd-gb:not(.dd-gb--m1) .dd-gb__dim,
.dd-g[data-p="c2"] .dd-gb:not(.dd-gb--m2) .dd-gb__dim,
.dd-g[data-p="off"] .dd-gb__dim,
.dd-g[data-p="odd"] .dd-gb--even .dd-gb__dim,
.dd-g[data-p="even"] .dd-gb--odd .dd-gb__dim {
  opacity: 0.35;
}

.dd-g[data-p="c0"] .dd-gb:not(.dd-gb--m0) .dd-gb__glow,
.dd-g[data-p="c1"] .dd-gb:not(.dd-gb--m1) .dd-gb__glow,
.dd-g[data-p="c2"] .dd-gb:not(.dd-gb--m2) .dd-gb__glow,
.dd-g[data-p="off"] .dd-gb__glow,
.dd-g[data-p="odd"] .dd-gb--even .dd-gb__glow,
.dd-g[data-p="even"] .dd-gb--odd .dd-gb__glow {
  opacity: calc(var(--dd-glow) * 0.35);
}

/* The shield's layers span −16…70 × −16…69 in its 54 × 53 coordinates. */
.dd-shield {
  left: -29.63%;
  top: -30.19%;
  width: 159.26%;
  height: 160.38%;
}

.dd-shield svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dd-shield--back {
  z-index: -1;
}

.dd-shield--front {
  z-index: 1;
}

/* 8px of room above and below the letters, inside the box that hides the wordmark on scroll. */
.logo-link--doodle .logo-link__text {
  padding-block: 8px;
  margin-block: -8px;
}


.dd-text {
  inset: 0;
  z-index: 1;
}

.dd-text > svg {
  position: absolute;
  overflow: visible;
}

.dd-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------ shared motions */

@keyframes dd-in {
  from { opacity: 0; }
}

@keyframes dd-pop {
  from { opacity: 0; transform: scale(0.2); }
}

@keyframes dd-reveal {
  from { transform: scaleX(0); }
}

@keyframes dd-twinkle {
  50% { opacity: 0.35; }
}

@keyframes dd-swing {
  0%, 100% { transform: rotate(-7deg); }
  50% { transform: rotate(7deg); }
}

.dd-pop {
  transform-box: fill-box;
  transform-origin: center;
  animation: dd-pop 0.6s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

.dd-pop--2 { animation-delay: 0.15s; }
.dd-pop--3 { animation-delay: 0.3s; }

.dd-fade {
  animation: dd-in 1.6s ease-out both;
}

/* A shine across the shield now and then (Конституція, Захисники). */
.dd-shine {
  animation: dd-shine 6s ease-in-out 1s infinite;
}

@keyframes dd-shine {
  0% { transform: translateX(0); }
  30%, 100% { transform: translateX(110px); }
}

/* ------------------------------------------------ Новий рік */

/*
 * The scene, shown once (see «entrance shown once» below): the hand brings the hat, sets it down with a
 * little bounce and goes (1.1s – 3.3s); then the strand of lights under the
 * wordmark comes on. Hat and hand move together until the hat lands; both use
 * the layer's own origin, so their paths match. At rest the hat is on and
 * the hand is gone, which is also what visitors who ask for less motion see.
 */

.dd-hat {
  animation: dd-hat-in 2.2s cubic-bezier(0.35, 0.6, 0.3, 1) 1.1s both;
}

@keyframes dd-hat-in {
  0% { transform: translate(-44px, -40px) rotate(-10deg); opacity: 0; }
  8% { opacity: 1; }
  48% { transform: translate(0, -8px) rotate(-2deg); }
  60% { transform: translate(0, 0); }
  67% { transform: translate(0, -1.6px); }
  74%, 100% { transform: translate(0, 0); }
}

.dd-hand {
  opacity: 0;
  animation: dd-hand-in 2.2s cubic-bezier(0.35, 0.6, 0.3, 1) 1.1s both;
}

@keyframes dd-hand-in {
  0% { transform: translate(-44px, -40px) rotate(-10deg); opacity: 0; }
  8% { opacity: 1; }
  48% { transform: translate(0, -8px) rotate(-2deg); opacity: 1; }
  60% { transform: translate(0, 0); opacity: 1; }
  66% { transform: translate(0, 0); opacity: 1; }
  92%, 100% { transform: translate(-38px, -36px); opacity: 0; }
}

/*
 * Phones: the shield stands alone in a 56px bar and the hat rises about a
 * fifth of the shield above it, so it touched the top of the screen while
 * 8px stayed under the shield. A size smaller and set a little lower, the
 * shield with its hat has the same room above and below, about 6px (the
 * owner, 2026-11-30). Sizes and spacing only; `top`, not a transform, so the
 * header's own scale on scroll is left alone.
 */
@media (max-width: 480px) {
  .logo-link--doodle.dd--new-year .logo-link__label {
    top: 3.6px;
    width: 36px;
    height: 36px;
  }
}

/* The hat's shadow on the shield comes as the hat lands. */
.dd-hat-shadow {
  animation: dd-in 0.4s ease-out 2.4s both;
}

.dd-pompom {
  transform-box: fill-box;
  transform-origin: 0 30%;
  animation: dd-pompom 2.8s ease-in-out 3.3s infinite;
}

@keyframes dd-pompom {
  0%, 100% { transform: rotate(0); }
  35% { transform: rotate(9deg); }
  70% { transform: rotate(-5deg); }
}

/*
 * The boxes the snow falls in: in front of the wordmark, and behind the
 * wordmark (z-index 1) and the shield (2), where a flake shows between the
 * letters and at the shield's edges.
 */
.dd-snowfall {
  z-index: 4;
  overflow: hidden;
  transition: opacity 0.3s ease;
  /* A layer of its own: fading out with the header must not repaint it. The
     flakes keep their size, so the layer stays sharp. */
  will-change: opacity;
}

.header._scrolled .dd-snowfall {
  opacity: 0;
}

/*
 * Small snowflakes falling through the boxes, never past them. doodles.js
 * wraps each flake: the wrapper falls the whole height of its box at an even
 * pace (--dd-fall: from just above the box to its bottom edge) and fades only
 * on that edge; the flake inside sways from side to side as it turns
 * (--dd-sway, --dd-turn), on a beat of its own. Pace, sway, beat, size and
 * start differ for every flake and every page, so no two fall alike (the
 * owner, 2026-11-30: they fell alike and faded halfway).
 */
.dd-flake {
  position: absolute;
  top: 0;
  width: 10px;
  height: 10px;
  animation: dd-fall 6s linear infinite;
}

.dd-snow {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  animation: dd-sway 2.4s ease-in-out infinite alternate;
}

@keyframes dd-fall {
  0% { transform: translateY(-12px); opacity: 0; }
  8%, 88% { opacity: 1; }
  100% { transform: translateY(var(--dd-fall, 60px)); opacity: 0; }
}

@keyframes dd-sway {
  0% { transform: translateX(calc(-1 * var(--dd-sway, 3px))) rotate(calc(-1 * var(--dd-turn, 40deg))); }
  100% { transform: translateX(var(--dd-sway, 3px)) rotate(var(--dd-turn, 40deg)); }
}

.dd-snowfall--back {
  z-index: 0;
}

/* Beside the shield a flake falls seldom: in a third of its cycle, then it waits unseen. */
.dd-flake--rare {
  animation-name: dd-fall-rare;
}

@keyframes dd-fall-rare {
  0% { transform: translateY(-12px); opacity: 0; }
  3%, 29% { opacity: 1; }
  33%, 100% { transform: translateY(var(--dd-fall, 60px)); opacity: 0; }
}

/*
 * Frost on the letters (library.php draws it to the wordmark's measured
 * letters, doodles.js lays it over the wordmark picture): a thin glassy rim
 * on each top face and a few small icicles.
 */
.dd-ice {
  z-index: 1;
  animation: dd-in 1.2s ease-out 0.4s both;
}

.dd-ice svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* ------------------------------------------------ entrance shown once */

/*
 * A doodle comes in with a motion (the hand brings the hat, the lights come
 * on, the ornaments pop up) once; after that it opens already in place
 * (doodles.js adds the class; localStorage remembers for 12 hours). Stronger
 * than any drawing's own entrance rule, which may be more specific.
 */
.logo-link--dd-seen :is(.dd-g, .dd-ice, .dd-hat, .dd-hat-shadow, .dd-hand, .dd-pop, .dd-grow, .dd-chain, .dd-band, .dd-swash, .dd-fade, .dd-link) {
  animation: none !important;
}

/* ------------------------------------------------ less motion */

/*
 * variables.css shortens every animation to 1ms for these visitors; a 1ms
 * animation would leave a firework or a snowflake at its last frame, gone.
 * Without animation each drawing stands at rest, whole.
 */
@media (prefers-reduced-motion: reduce) {
  .logo-link--doodle .dd-layer,
  .logo-link--doodle .dd-layer * {
    animation: none !important;
  }

  .dd-fill,
  .dd-snowfall {
    display: none;
  }
}

/*
 * The same for «Без анімацій» of the accessibility panel (ms-accessibility),
 * which stops every animation on the page with a class on <html>. Snow that
 * stood still in the air would only look like specks, so it goes; the
 * garland's lights stay on without blinking (doodles.js).
 */
html.accessibility-no-anim .dd-fill,
html.accessibility-no-anim .dd-snowfall {
  display: none;
}
