For a tiny handful of the highest ranked schools (Harvard, Princeton, MIT, Stanford level) great grades in rigorous classes are necessary, but still are not sufficient for admissions. For a very long list of other very good universities, you should take the classes that make sense for you, do as well as you can, and try not to worry about it.
It is normal to be uncertain at this point regarding your likely major. I was a math major, liked it, and did well with it. Since you are leaning that way I will focus on math for now.
There are a LOT of universities that are very good for mathematics. Also, if you look at highly ranked graduate programs in math, the students in those programs come from a wide range of undergraduate universities.
Also, history is not all that closely related to mathematics.
I would be more concerned about this. You might want to take one more year of the same “foreign” language. I put “foreign” in quotes because it sounds like it is not actually foreign for you. However, I was in the same situation (my “foreign” language was French, but I did high school in Montreal so it wasn’t actually foreign for us either) and top schools in the US did not seem bothered by the fact that my foreign language was not really foreign.
A secret about life: You can’t compete with everyone. Just be yourself. Take the classes that make sense for you. Do as well as you can. Participate in the ECs that make sense for you. Treat people well. Be the best version of you that you can be, and do not worry about it. It will work out just fine one way or another.
Also, when the time comes do not just focus on famous universities. Instead look for colleges and universities that are a good fit for you, pay attention to your budget, and make sure that you apply to safeties. There really are a very large number of colleges and universities in the US where you can get a very good education.
And you can get accepted to very good universities with a B in AP US History, or an A or a B in some other class.
I also might be inclined to ask both your current AP World History teacher and your guidance counselor what they think. Mostly however I would forget about university admissions, and just take the classes that are the right classes for you.