Morphogenesis of maze-like magnetic domains