Foundations of Practical Magic