“explain how the Soviets lost in Afghanistan”
The Soviets lost in Afghanistan for the same reasons the US military lost in Afghanistan and Vietnam.
The locals are willing to fight harder and more importantly longer than outsiders with no vested reason to stay.
For UKR to “win” in Ukraine means it will have to go back to the 4th Century and mud huts - like Afghanistan. Either that or be a part of a nuclear war Zelenskyy goads.
If the South Vietnamese fought as hard as We did for them...
It would have had a different outcome.