if you're walking they can stop you for no reason. but 20 minutes is ridiculous, that isn't reasonable. You have the right to walk away at a certain point, as long as you aren't doing anything illegal (that they know of). I don't know what this point is though. anybody know? i'd agree with this, I'm pretty sure this is what he meant. i'm from a small town and cops literally have nothing better to do but to fuck with young kids.
A stranger walking around aimlessly at 9pm (hence it's dark out) and you're carrying a bookbag. That looks sketchy, so yes he did have a reason.
You need to remember to ask "Am I being detained or am I free to go?" You could have left a lot earlier than 20 minutes bro, you consented to being detained by never asking.