/* Keep the old palette below the new one and reveal only the new snapshot. */
html.theme-transitioning::view-transition-group(root) {
  animation: none;
}

html.theme-transitioning::view-transition-old(root) {
  z-index: 1;
  animation: none;
  mix-blend-mode: normal;
}

html.theme-transitioning::view-transition-new(root) {
  z-index: 2;
  mix-blend-mode: normal;
  animation: theme-reveal-clip var(--theme-transition-duration, 1.6s) cubic-bezier(.35, 0, .25, 1) both;
  transform-origin: var(--theme-transition-x) var(--theme-transition-y);
}

@keyframes theme-reveal-clip {
  from { clip-path: circle(0 at var(--theme-transition-x) var(--theme-transition-y)); }
  to { clip-path: circle(var(--theme-transition-radius) at var(--theme-transition-x) var(--theme-transition-y)); }
}

html.theme-transitioning.theme-transition-soft::view-transition-new(root) {
  animation-name: theme-reveal-mask;
  /* Render only a viewport-sized mask. Animate the typed radius, keeping the
     centre and texture bounds fixed. 70/64 preserves the existing feather. */
  mask-image: radial-gradient(circle at var(--theme-transition-x) var(--theme-transition-y), black var(--theme-reveal-radius), transparent calc(var(--theme-reveal-radius) * 1.09375));
  mask-position: 0 0;
  mask-repeat: no-repeat;
  mask-size: 100% 100%;
  -webkit-mask-image: radial-gradient(circle at var(--theme-transition-x) var(--theme-transition-y), black var(--theme-reveal-radius), transparent calc(var(--theme-reveal-radius) * 1.09375));
  -webkit-mask-position: 0 0;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
}

@keyframes theme-reveal-mask {
  from { --theme-reveal-radius: 0px; }
  to { --theme-reveal-radius: var(--theme-transition-radius); }
}

.theme-toggle-transitioning > * {
  animation: theme-toggle-icon var(--theme-transition-duration, 1.6s) cubic-bezier(.35, 0, .25, 1) both;
  transform-origin: center;
}

@keyframes theme-toggle-icon {
  0% { transform: rotate(-35deg) scale(.75); }
  45% { transform: rotate(12deg) scale(1.12); }
  100% { transform: rotate(0) scale(1); }
}

/* Theme switching explicitly keeps its animation independent of the system
   preference, including the home page's general reduced-motion duration rule. */
html.theme-transitioning::view-transition-new(root),
.theme-toggle-transitioning > * {
  animation-duration: var(--theme-transition-duration, 1.6s) !important;
}
