// Tobeads — shared arcade cabinet color theme (intro + homepage hero)
// Persists in sessionStorage so START keeps the chosen shell color.

(function () {
  const KEY = 'tobeads.cabTheme';
  const THEMES = new Set(['red', 'blue', 'yellow', 'white']);

  function read() {
    try {
      const v = sessionStorage.getItem(KEY);
      return THEMES.has(v) ? v : null;
    } catch (e) { return null; }
  }

  function write(theme) {
    try {
      if (theme && THEMES.has(theme)) sessionStorage.setItem(KEY, theme);
      else sessionStorage.removeItem(KEY);
    } catch (e) {}
  }

  function toggle(theme) {
    if (!THEMES.has(theme)) return read();
    const next = read() === theme ? null : theme;
    write(next);
    return next;
  }

  window.CabTheme = { read, write, toggle, THEMES: [...THEMES] };
})();
