Improved viewport detection.