  We prove that invariant subbundles of the Kontsevich-Zorich cocycle respect
the Hodge structure. In particular, we establish a version of Deligne
semisimplicity in this context. This implies that invariant subbundles must
vary polynomially on affine manifolds. All results apply to tensor powers of
the cocycle and this implies that the measurable and real-analytic algebraic
hulls coincide.
  We also prove that affine manifolds parametrize Jacobians with non-trivial
endomorphisms. Typically a factor has real multiplication.
  The tools involve curvature properties of the Hodge bundles and estimates
from random walks. In the appendix, we explain how methods from ergodic theory
imply some of the global consequences of Schmid's work on variations of Hodge
structures. We also derive the Kontsevich-Forni formula using differential
geometry.
