Not enough pins, looking for a "demultiplexer" that keeps state
What you are looking for is a GPIO "expander" chip. There are many available, typically using I2C or SPI to connect to the microcontroller. The Microchip MCP23017(I2C)/MCP23S17(SPI) is just one example that I have used in the past. There are many others to choose from.