Keeping the lights on nationwide is a feat of engineering that depends on millions of miles of power lines and thousands of power-generation plants.