I don't know since when AMP started supporting amp-scripts or localStorage, but nowadays it is possible to use them, so you can save user settings (like dark/light mode preference) in the localStorage.
They have an example in their site: https://amp.dev/documentation/examples/components/amp-script/#local-storage
Your script has access to the Web Storage API. This lets you persist user information between browser sessions. Here, we use localStorage to track a username. If you set the username, then reload this page, the username will remain set.
<amp-script layout="fixed-height" script="local-storage-script" height="110" class="sample">
<div>
<span>Current username: </span>
<b id="username-display"></b>
</div>
<div>
<label>Enter new username:</label>
<input id="username-input" type="text" maxlength="20">
</div>
<button id="username-submit">Submit</button>
</amp-script>
<script id="local-storage-script" type="text/plain" target="amp-script">
const submit = document.getElementById('username-submit');
const input = document.getElementById('username-input');
const display = document.getElementById('username-display');
const oldUsername = localStorage.getItem('username');
display.textContent = oldUsername ? oldUsername : '(not set)';
function setUsername() {
const newUsername = input.value;
localStorage.setItem('username', newUsername);
display.textContent = newUsername;
}
submit.addEventListener('click', setUsername);
</script>