If we separate, is there a risk I will lose my residence permit?

As far as your residence permit and the conditions for its renewal are concerned, that depends on numerous factors, notably the number of years of marriage and the level of integration in Swiss society. It is indispensable that you take advice from a specialized legal service.