Two high-speed trains collided in Spain, killing at least 40 people and shaking a nation at the forefront of rail transport.