Even to the extent that natural selection can be said to be care about anything, saying that survival is that thing is kind of misleading.
Well, I have gone into more details elsewhere.
It’s perfectly normal for populations to hill-climb themselves into a local optimum and then get wiped out when it’s invalidated by changing environmental conditions that a more basal but less specialized species would have been able to handle, for example.
Sure. Optimization involves going uphill—but you might be climbing a mountain that is sinking into the sea. However, that doesn’t mean that you weren’t really optimizing—or that you were optimizing something other than altitude.
Evolution is only as short-sighted as the creatures that compose its populations. If organisms can do better by predicting the future (and sometimes they can) then the whole process is a foresightful one. Evolution is often characterised as ‘blind to the future’ - but that’s just a mistake.