What do I do if I get lost at night?

The short answer

Head toward light.

A brightly lit shop or a bakery that's still open is your best reference point — ask the shopkeeper for the nearest gate (*bab*) or the "big square" where you can re-orient yourself. Shopkeepers are stationary, known in their neighbourhood, and far more reliable than someone approaching you in a dark street. Every medina gate leads to a main road where you can find a taxi.