why does the direction of light change during refraction if the speed changes?how are speed and direction related?
it's because light is a wave
in fact, it applies to any wave … for example, the direction of an earthquake wave will change when it goes through a boundary between rocks with a different speed of sound
the frequency stays the same (that's obvious, isn't it?), and frequency times wavelength = speed, so if speed decreases, then wavelength must decrease, so the waves must get closer together, and the only way of doing that is to bend away from the perpendicular
Notice that the distance between lines in incoming wave (wavelength) is longer than in the wave that passed into material (there is also a reflected wave going back up), but the lines still match at the boundary. That forces a change of the direction angle.