Atomic mechanism of polarization-controlled surface reconstruction in ferroelectric thin films