Gamma-ray bursts as probes of the distant Universe