Passionate about a PhD in math, but unsure how to explain my chaotic transcript due to mental illness I'm passionate about getting a PhD in Math for a career as a research mathematician and then as an educator working at a community college.

I got A's in community college. I transferred to our local University and for my 1st semester got a 3.67 taking science courses and 300 level math courses. The next semester I got a 4.00 taking more science and math courses. The next year I started exhibiting symptoms of bi-polar and my grades tanked pretty hard. After that I muddled through, graduated with a total GPA of 3.5 and started on a long journey of learning to live and thrive with bi-polar and depression. However, I did probably the dumbest thing ever. I convinced myself that getting a C.S. masters was a prudent idea and proceeded to re-enroll at our University and fail a bunch of CS classes. Now my overall GPA (despite already having graduated) is 3.19. Since then I went into the workforce, decided I really just want to get my PhD in math and teach a community college and have been pursuing that for a year now. In working toward that goal I took an independent study course with one of my professors to refresh my linear algebra and got an A. Then I took graduate level analysis (B+) and graduate level applications of linear algebra (A-). I'm currently in the 2nd semester of graduate level analysis and feel like I've gotten the hang of graduate level course work (I'm confident I'll get an A in this one). 

So despite having early success in math (A's in the Calc series and A's in several 300 and 400 level courses) I have what looks like a really really confusing transcript because I tried CS, actually hated it, and go F's in two of those classes. To add to my transcript/GPA concerns I have C's in the undergraduate analysis courses from when bi-polar threw my life off the rails and around the same time got a D in diff-eq (which I retook for an A) and a C in combinatorics. 

Now that I'm looking to apply for grad school in Fall 2020 (possibly out of my small state if the program is good) I don't really know how to communicate what probably seems like a very confusing academic record. For what it's worth I have 1 math professor that will write me a good letter of rec, a retired math professor that will write me a good letter of rec, and the P.I. from my internship at a big name research institute that might write me a letter. So at least I have that. But damn, my transcript looks like something that will hurt me without explanation. How do I explain it? Is it possible? Should I reconsider my path? I'm very dedicated to this path but I worry that despite my passion current and ability to pass graduate level courses it won't be enough. Any suggestions on how to explain my transcript would be so wonderful =)

TL;DR - I got good grades at my local Uni in nowhere USA. Then I got bi-polar disorder and so did my grades, then I graduated, then I tried CS and got even crappier grades still. But now I'm doing well and getting better grades in grad-level classes but have no idea how to explain all of this to grad programs I apply to =/
You need to focus. Why do you think you need a PhD in mathematics? If you plan to be a serious researcher, how do you plan to balance that with working in your under-performing school district? What specific area of math is your intended focus? Are you trying to get into a top 5 program or any program? That also makes a difference. If you can show that you are focused today and have doable plans with a PhD, telling your story won't be as difficult as explaining a low grade in an entry-level math course such as differential calculus. You will have a hard time living that one down. Figure out why you earned a D and how that changed your approach to understanding math. You might want to consider applying to a MS mathematics program and state your intention to seek the PhD at that institution.