How much does a student's ranking in their cohort matter for PhD applications?
Your letters of recommendation will be much, much more important than your class ranking. Spend your time on getting the strongest letters you can (and learning how to do this, if necessary).

Source: I have served on grad admissions for a top math department.