// Logout broadcast for cross-domain teardown. Auth bumps the tick
// (with the outgoing user id) and downstream modules react via $effect
// on `sessionEnd.tick`. Keeps auth from importing player — the cycle
// stays inverted (player imports auth, never the reverse).

let _tick = $state(0);
let _userId = $state<string | null>(null);

export const sessionEnd = {
  get tick() { return _tick; },
  get userId() { return _userId; },
};

export function signalSessionEnd(userId: string | null): void {
  _userId = userId;
  _tick++;
}
