Ontogenetic habitat shifts reduce costly male-male interactions