Reducer function for state transitions.
Implements pure state reduction - no side effects, exhaustive pattern matching.