When the energy of the heavy quark is comparable with its mass, it is natural to attribute this heavy quark to the hard part of the reaction. At large energies, this approach is impractical due to large logarithms from intensive QCD radiation affecting both inclusive and differential observables. We present a formalism for all-order summation of such logarithms and reliable description of heavy-quark distributions at all energies. As an illustration, we calculate angular distributions of B-mesons produced in neutral-current events at large momentum transfers at the ep collider HERA.