I will come to Spain as a tourist and then apply for my visa later. Can I apply for the visa inside Spain, or do I need to leave Spain and apply from another country?
You may start the application process while abroad, travel to Spain, stay there a bit, and then pick up your visa when its ready in the place you originally applied. However, you may not apply for a visa while inside Spain, nor can you pick one up in the country.