By the end of the XVII was they already had been behind the “Western” level. The gap was not, yet, critical but it already did exist. Explanation of their defeats is not convincing: at the mid-/late XVIII they had been winning against the Austrians while fighting against the Russian-Austrian coalition and being, beyond any serious doubt, noticeably behind the “west”.
As far as the Russians are involved, in the war you are talking about the Ottoman involvement on that “front” was minuscule: not at all during Golitsin’s campaigns against the Crimea and few thousands during Peyer’s Azov campaigns.
Disclaimer: In regard to why the Ottomans lost the great Turkish war, we don't have a definitive answer. Nobody has written a modern detailed study of the war.
The traditional explanation would be that the Ottomans did not keep up with European developments in the realm of army drill and in the shift from cavalry to infantry, but current research is pushing back against this. Until recently we've been in the dark with regard to how seventeenth-century Ottoman armies fought, relying basically on European observers. Relying on foreign observations is fraught with danger because the observers often write more from their own biases than any real knowledge of what they're talking about - I could cite an Ottoman observer telling you that Austrian musketeers did not know how to aim. So lately we've tried to rely more on what the actual Ottoman sources have to tell us, and they've given us an image of the Ottoman army as being much more "modern" than we thought. For instance, we know that the Ottomans maintained an infantry/cavalry ratio roughly equivalent to that of the Habsburgs and that they also made use of their cavalry as dragoons. We also have very early proof that they were training their infantry in volley formations.
So the Ottoman army doesn't appear to have been all that "backwards," or at least we can't say that with certainty anymore. We can say that the Ottomans definitely had less experience with battle than the Habsburgs. Large-scale battles were far more common in central European wars than they were for the Ottomans if this is what you refer to. However even here this would only be true for the specific period were talking about and not reflective of the ottomans “falling behind” holistically in terms of military capabilities. Habsburg leadership probably knew how to conduct itself in battle better than that of the Ottomans, and this is part of the explanation for why the Ottomans lost most of the major field battles they fought during the war. Sieges were another matter - there the Ottomans were experts.
The context of the war is extremely important. The Ottomans weren't just fighting the Habsburgs and Imperials; they were also fighting Venice, Poland-Lithuania, and Russia. This meant that the war took place on a huge number of fronts. The Ottomans had to divide their forces to fight in Greece, in Dalmatia, in Hungary, in Podolia, and in Crimea. You mentioned that direct ottoman focus against the Russians was minuscule for most of the war. This is true, but you’re forgetting something important. The Crimean Khans were unable to support Ottoman operations in Hungary for pretty much the entire duration of the war because they were defending their territory against the Russian empire, robbing the main Ottoman field army there of its usual enormous light cavalry support (and consequently its ability to engage in effective reconnaissance and harrassment). For Rhoads Murphey, probably the foremost military historian of this era, the logistical strain of trying to fight on so many fronts is the primary reason for the Ottoman defeat.
To this we can add a few other features: one, the defensive structure of the Ottoman fortress network in Hungary was very hollow. Border fortresses were quite strong, but once the exterior fortress line was breached (the fall of Buda, 1686), the Habsburgs could pour through the gap and conquer basically all of central Hungary. If you look at the timeline of Habsburg conquest, you can clearly see this pattern: the Habsburgs reached the Danube very soon after the fall of Buda, but it took them a long time to actually consolidate that position by conquering all the Ottoman border forts they bypassed.
By the end of 1686 the Ottoman-Habsburg frontier basically looked like this. The Ottomans were really not prepared to suddenly have their network breached.
Secondly, the aftermath of the Siege of Vienna was a political nightmare. These critical Habsburg advances were occurring during a time of severe instability in Istanbul. The grand vizier Kara Mustafa Pasha was executed for his decision to attack Vienna without the consent of Mehmed IV*, and this led to an attempt to dismantle the whole Köprülü political apparatus that had dominated the empire's politics for the last thirty years. The empire really needed stable leadership but in this crucial moment, it didn't have it. By 1687 Mehmed IV was overthrown and replaced by Süleyman II, which eventually brought about a Köprülü restoration as well. This provided the stability the Ottomans needed to push the Habsburgs back across the Danube and reconquer Belgrade (helped by the outbreak of the Nine Years' War between France and the Habsburgs), but they couldn't get back into Hungary - all their fortresses there remained cut off and were gradually conquered. The fight shifted to Transylvania and ultimately ended with a stalemate on the Danube. The Ottomans couldn't push back north and the Habsburgs couldn't push south.
*Some historians think that Mehmed IV actually ordered the attack, and just shifted the blame to Kara Mustafa after the failure.
- Ágoston, Gábor. “Firearms and Military Adaptation: The Ottomans and the European Military Revolution, 1450-1800.” Journal of World History 25 (2014): 85-124.
- Börekçi, Günhan. “A Contribution to the Military Revolution Debate: The Janissaries Use of Volley Fire during the Long Ottoman-Habsburg War of 1593-1606 and the Problem of Origins.” Acta Orientalia Academiae Scientiarum Hungaricae 59 (2006): 407-438.
- Kolçak, Özgür. “The Composition, Tactics and Strategy of the Ottoman Field Army at Zrínyi-Újvár and St. Gotthard (1663–1664).” In A szentgotthárdi csata és a vasvári béke: Oszmán Terjeszkedés-Európai Összefogás, 73-92. Edited by Tóth Ference and Zágorhidi Czigány. Budapest: MTA Történettudományi Intézet, 2017
- Murphey, Rhoads. Ottoman Warfare, 1500-1700.London, UCL Press, 1999.