Castelnuovo bounds for higher-dimensional varieties