Executive order 9066 was put into action 2 months after Pearl Harbor. The nukes also happened after that initial bombing.
The Pearl bombing resulted from US embargoes. The Imperial Japs were being far too successful after the Meiji shift, winning the Rus-Jap war, taking strategically beneficial swaths of China, etc, and it freaked the Western powers, so they put a strangle on Jap oil to hobble the Jap military. That put the Japs in a position of fight right now or can't fight at all. Would you sit still and let your military be made helpless by unfriendly nations with established histories of exploiting weaker nations?
Yamamoto's attack surprised America by how effective it was, but an attack of some kind was totally foreseeable. It wasn't out of the blue at all, like your school teacher told you. We'd been fucking with them for quite awhile. And imo Roosevelt wanted an attack of some kind in order to overcome majority public resistance to entering the war. The Great War was still fresh in everyone's memories and they didn't want to get involved in another one. They don't tell you that in school either.
When you hear that we're the good guys and they're the bad guys, you're hearing propaganda. There are no good guys. Just necessary decisions.