Phase shifts and the role of herbivory in the resilience of coral reefs