Science fiction is based in reality and usually just extrapolates what we know is scientifically possible, just not with current technology. They can usually explain how stuff works because it's based on real science to some degree.
Star Trek is science fiction.
Fantasy really just follows the rule of cool. If it's cool, throw it in. It's based on nothing but what the writer thinks is cool as shit.