Democrats harnessed worries about the cost of living, with polls showing that Republicans’ longtime advantage on the economy has evaporated.