Locking rotation WORLD Z AXIS (Quaternions are shaving years off my lifespan)

Spent half a day trying to figure this out but am still stuck. I am positive this is shaving some years off my lifespan.
How do I lock the WORLD Z AXIS rotation of my object while allowing LOCAL X & Y & Z rotation of the object?

The euler rotation of my z axis will no longer be 0 once the y and x axis are moved, so it is not possible for me to lock the euler angle of my z axis to 0.

To lock the WORLD Z AXIS rotation of my object, do I have to learn quaternion mathematics and manually restrict the w,x,y,z values?

If you allow relative rotations it’s not possible since you can reach any rotation by just using two local rotations. Example:

90° on local X → you’re looking up
90° on local Y → you’re looking sideways
-90° on local X → you’re looking the same initial direction but you are rotated 90° around Z even you never rotated around Z

The only way to avoid rotation around one axis is to use absolute rotations. Actually there is nothing like a world-z-rotation axis since the rotation axis of euler angles always depend on each other since their rotations are executed one after another.

The order of the rotations matters. Unity’s euler angle order is:

Y degree around local Y
X degree around local X
Z degree around local Z

This is the same as doing the rotations around world axis but in reverse order:

Z degree around world Z
X degree around world X
Y degree around world Y

Using absolute X and Y rotations is common for most FPS camera controls since you always want the view up-right. For this you would simply use two float variables to specify the current X and Y rotation and simply use Quaternion.Euler with the two variables. You would use the mouse delta input to change those two variables. That way your camera rotation is always defined by an absolute rotation around X and Y.

edit
Unity’s MoustLook script can do this with the right gameobject setup. Usually the player object should only rotate around the Y axis (turn left and right). Then you would have the camera as child which will only rotate around the local X axis (up and down). So you have a kinematic chain. You would place one MouseLook script on the player object and only allow mouseX rotation. On the child camera you use another MouseLook script and only allow mouseY rotation.

In games like Space Engineers where you actually float in space you actually have / need an additional control axis (usually Q and E) to rotate around local Z. In space there is no concept of “up” or “down”. Everything is relative.