How months of miscalculation led the U.S. and Iran to the brink of war