Burnley cut the gap to the Championship’s top two back to two points with a nervy win against lowly Cardiff City.