added a condition to check the width of the viewport

Good idea.