improve css transition logic