Arbitrary rotation around a point works except when up flips?

I’ve been working on the ability to rotate my camera around an arbitrary point based on mouse movement and have it working great except when it crosses the top/bottom of an axis. The code for moving the camera is:

					// Get mouse inputs
					float horizontalSpeed = 1.0f;
					float verticalSpeed = 1.0f;
			        float h = horizontalSpeed * Input.GetAxis("Mouse X");
			        float v = verticalSpeed * Input.GetAxis("Mouse Y");

					Vector3 upDirection = Camera.main.transform.up * h;
					Vector3 rightDirection = Camera.main.transform.right * v;
					Vector3 totalDirection = upDirection + rightDirection;
				

					// Set camera variables
					Camera.main.transform.position = MathHelp.Vector3Help.RotateAroundAPoint(Camera.main.transform.position, 

						Vector3.zero, 
					Quaternion.Euler(totalDirection));
					Camera.main.transform.LookAt(Vector3.zero);

Note I have to multiply the up direction by the horizontal axis, and vice versa. And the code for rotating around a point is:

		public static Vector3 RotateAroundAPoint(Vector3 point, Vector3 pivot, Quaternion angle)
		{
			// Center the point around the origin
			Vector3 finalPos = point - pivot;
			
			// Rotate the point
			finalPos = angle * finalPos;
			
			// Move back in place
			finalPos += pivot;
			return finalPos;
		}

Any thoughts?

My goal is to try and be able to rotate the camera in a sphere anywhere.

Here, delta is a Vector2 containing the mouse movement (like h and v above); center is the point you’re rotating around; RotationSpeed is a speed multiplier. You might want to switch magnitude for sqrMagnitude.

void SphericalPan(Vector2 delta, Vector3 center, float RotationSpeed)
{
    float Angle = delta.sqrMagnitude;
    if(Angle > 0.0f)
    {
        Vector3 Axis = Vector3.Cross(delta, Vector3.forward);
        Axis=Camera.main.transform.TransformDirection(-Axis);
        Camera.main.transform.RotateAround(center, Axis, Angle * RotationSpeed);
    }        
}