Complex problem where 360 camera is not handling vertical rotation properly

Godot Version

4.6.1

Question

I’ve been working on a player camera where it can rotate freely without reaching a degree limit (most games have it that if you look down far enough, you can’t look down any further so you don’t invert, but I’ve removed this). This is intentional, but I’ve ran into a problem where when I go so far up or down that I now face backwards, my mouse moves the camera with opposite controls. If I move the mouse up, the camera goes down for example, even when at the start it did the opposite. I thought that this was just from the camera’s rotation, but even if I rotate the camera horizontally to no longer be upside down, the controls will still be inverted.

Or to put it simply:
Camera is rotated down until it reaches the ground
Camera can keep rotating (this is intended!!!)
If the player moves the camera backwards this way, instead of turning horizontally (like a normal first person game might have) the controls are reversed
Controls invert when the camera rotates behind the starting rotation horizontally (180 degrees)

Admittedly this is really hard to explain especially since I don’t know the full terminology, but I’ve tried my best.

The code for my rotation is this:

func _unhandled_input(event):
	if event is InputEventMouseMotion:
		# rotate camera by how much the mouse is moving * mouse sensitivity
		self.rotate_y(-event.relative.x * SENSITIVITY)
		self.rotate_x(-event.relative.y * SENSITIVITY)

maybe something like this?
if camera2D.rotation > 180:
is_flipped = true
if Input.is_action_pressed(“left”):
if is_flipped:
velocity.x = 1000
else:
velocity.x = -1000

This doesn’t work because (I assume) rotation can’t be over 180 since it would just go to -180 instead.