Preheat the oven to 375°F (190°C) and butter or oil a 9x13-inch baking dish.
If using fresh spinach, wash, blanch 1 minute, drain and squeeze out excess water; chop roughly. If using frozen, thaw and squeeze dry.
Heat 2 tablespoons olive oil in a skillet over medium heat and sauté the chopped onion until translucent, about 5–7 minutes.
Add the minced garlic and cook 30 seconds until fragrant, then add the spinach and cook until wilted and excess liquid has evaporated; cool slightly.
In a large bowl combine the cooled spinach mixture with crumbled feta, ricotta if using, beaten eggs, dill, parsley, nutmeg, salt and pepper; mix until evenly combined.
Unroll phyllo and keep covered with a damp towel. Brush the bottom of the prepared dish with melted butter.
Layer 5–6 sheets of phyllo into the dish, brushing each sheet lightly with butter and allowing edges to overhang for folding later.
Spread the spinach-feta filling evenly over the phyllo base, pressing gently to level the mixture.
Fold remaining phyllo sheets over the filling, brushing each sheet with butter; tuck and trim edges for a neat crust.
Score the top layers into serving pieces with a sharp knife to make slicing easier after baking, then brush the top with remaining butter.
Bake 30–40 minutes until the phyllo is crisp and deeply golden. Let rest 10–15 minutes before slicing and serving.