How can I make the camera follow the player's rotation only on the z axis?

I am making a game, something like Ketchapp’s Twist. How can I make the camera rotate along with the player only on the Z axis? I did this to make the camera follow the player’s position -

public GameObject player;
private Vector3 offset;

void Start()
{
    offset = transform.position - player.transform.position;
}

void Update()
{
	Vector3 pos = player.transform.position + offset;
	transform.position = new Vector3(pos.x,transform.position.y,pos.z);
}

But an error pops up when I try the samre thing with the rotation. Anyone have suggestions?

P.S. If you can make the platforms on which the player moves rotate instead of the camera, it’s fine too.

if this code is working correctly for position, there is no reason it wouldnt work for rotation.

every where is says “transform.position” change it to:

transform.eulerAngles