You’re trying t build a railway up the side of a mountain. Have you ever taken a train through the mountains or hills – they tend yo wind around a lot to gain altitude or go through tunnels.
Turn on the contours. The use the slope feature to set a slope (for steam use the lowest slope option), then build your track up the hill crossing the contours. If the contour lines are too close together, you’ll have to go at an angle and you might even have to plan turns. It takes a lot of time and practice to engineer a line over the mountains.