The right peer group makes all the difference.
I currently live in a rural environment with tiny schools and wonder how I would’ve turned out if that’s where I did high school. I think you need a critical mass of other gifted kids to really set the bar and drive some aspirational goals. If your class has a single gifted kid, they’ll just see that they exceed their peers and coast; if there’s a whole group they’ll push each other once they know more about where the ceiling is.
The reality is that, even in a rural shithole like I went to, if you WANTED to learn, their was near infinite opportunity, especially in the 2000s as the internet grew. I didn't have much in terms of AP classes, but we had a vocational wing and that was essential to ensuring everyone could find a passion to really pursue. So many kids that would be seen as slackers or dumb found something they were passionate about in the vocational wing that set them up for a future and gave them a real opportunity.
But if you or your friends decide that learning or striving for education isn't a good thing, you're fucked. You only get one chance to live through public school and so many kids waste it.
All we gotta do is build a society where education for it's own sake is seen as a desirable thing to have. 99% of education is motivation. You cannot learn if you don't want to.
99% of the people I see saying "Why didn't school teach me <X>" were busy sniffing glue in the back of class and not paying attention to the school system explicitly teaching them <X>. We had one kid in honors chemistry who literally snorted garlic powder one day and was not considered smart but his desire to learn meant he was willing to try the harder class, and he did well.
So many kids are raised by parents who fill them with anti-intellectualism and hostility to learning. "When am I ever going to use this" say kids who can't even compare the unit price of competing brands because they didn't want to pay attention in math class. "Why don't the democrats stop <Bad Thing>" they say despite reading aloud in 6th grade how you need enough votes in the senate to do anything at all. "Nobody needs math" they say when they agree to a predatory 72 month loan on a shitty car.