/** Preloaded at module load — swap file in `public/sounds/` without changing call sites. */
export const SFX_BUTTON_DEFAULT = new Audio('/sounds/button-default.mp3')

/** Preloaded at module load — swap file in `public/sounds/` without changing call sites. */
export const SFX_BUTTON_START = new Audio('/sounds/button-start.mp3')

SFX_BUTTON_DEFAULT.preload = 'auto'
SFX_BUTTON_START.preload = 'auto'

/**
 * Fire-and-forget: rewind, play, do not await (navigation/state may follow immediately).
 */
export function playSound(sound: HTMLAudioElement): void {
  try {
    sound.currentTime = 0
    void sound.play().catch(() => {
      // Autoplay policy, missing asset, etc.
    })
  } catch {
    // Audio unavailable
  }
}
