Prep the phyllo: Thaw phyllo in the fridge overnight, then bring to room temperature for 30 minutes.
Keep sheets covered with a slightly damp towel while working so they don’t dry out.
Cook the aromatics: In a large skillet, heat 2 tbsp olive oil over medium heat. Sauté the onion with a pinch of salt until soft and translucent, about 5–7 minutes. Add garlic and cook 1 minute more.
Wilt the spinach: If using fresh spinach, add it to the skillet in batches until wilted.
Transfer to a colander and press out as much liquid as possible. If using frozen spinach, thaw completely and squeeze dry in a clean towel. Excess moisture is the enemy of crispness.
Mix the filling: In a large bowl, combine spinach, cooked onion and garlic, crumbled feta, ricotta (if using), eggs, dill, parsley, lemon zest, a pinch of nutmeg, black pepper, and salt to taste. Go easy on salt because feta is salty.
Heat the oven: Preheat to 375°F (190°C).
Grease a 9x13-inch baking dish with butter or oil.
Layer the base: Brush the dish with melted butter. Lay a sheet of phyllo in the dish, letting edges overhang slightly. Brush lightly with butter.
Repeat with 6–8 sheets, brushing each layer. Don’t worry if sheets tear; keep layering.
Add the filling: Spread the spinach mixture evenly over the base layers.
Top layers: Add 6–8 more sheets of phyllo on top, brushing each with butter. Tuck in edges or fold them over for a neat border. Brush the top generously with butter or oil.
Sprinkle with sesame or nigella seeds if using.
Score before baking: With a sharp knife, gently score the top into squares or diamonds. This helps steam escape and makes slicing cleaner.
Bake: Bake for 35–45 minutes, until deep golden and crisp. If the top browns too quickly, tent loosely with foil for the last 10 minutes.
Rest and serve: Let the spanakopita rest for 10–15 minutes before cutting.
This keeps the layers intact and the filling set. Serve warm or at room temperature with lemon wedges.