Continuous rotation around z-axis with mouse movement

I need mouse/touch drags to translate to rotation of an object around its z-axis. So, if the player drags around in circles, the object should continue rotating around the z-axis properly, following the mouse/touch movement. I’ve pieced together a little code from various posts, but it’s not quite right.

I think I also need to move things out of OnMouseDrag, since I want the player to use screen drags instead of clicking on the object itself.

void OnMouseDown()
{
    _isRotating = true;
    _mouseReference = Input.mousePosition;
}
void OnMouseDrag()
{
    if(_isRotating)
    {
        // offset
        _mouseOffset = (Input.mousePosition - _mouseReference);
        Debug.Log("ref: " + _mouseReference + "; offset: " + _mouseOffset);
        // apply rotation
        _rotation.z = (_mouseOffset.x + _mouseOffset.y) * Sensitivity;
        
        // rotate
        transform.Rotate(_rotation);
        
        // store mouse
        _mouseReference = Input.mousePosition;
    }
}
void OnMouseUp()
{
    _isRotating = false;
}

The only rotation that works right now is when on the right or bottom of the object. The rotation also doesn’t work once the angle moves into the top or left side of the object. I need it to be continuous.

This is mostly how I made it work:
https://forum.unity.com/threads/only-rotate-object-when-user-click-and-drag-on-the-gameobject.354438/

in Update():

// this fires only on the frame the button is clicked
if(Input.GetMouseButtonDown(0)) {
    // get screen position of object
    screenPos = Camera.main.WorldToScreenPoint(transform.position);
    // get difference from mouse
    Vector3 v3 = Input.mousePosition - screenPos;
    // calculate the offset, so we can spin from point of click
    angleOffset = (Mathf.Atan2(transform.right.y, transform.right.x) - Mathf.Atan2(v3.y, v3.x)) * Mathf.Rad2Deg;
}
// this fires while the button is pressed down
if(Input.GetMouseButton(0)) {
    // caculate difference from original screen position of object
    Vector3 v3 = Input.mousePosition - screenPos;
    // figure out how much to move
    float angle = Mathf.Atan2(v3.y, v3.x) * Mathf.Rad2Deg;
    // move by that much plus offset
    transform.eulerAngles = new Vector3(0, 0, angle+angleOffset);
}