The stability and collapse of marine ecosystems during the Permian-Triassic mass extinction