// The service worker can't play audio; this hidden offscreen page does it instead.
chrome.runtime.onMessage.addListener((msg) => {
  if (!msg || msg.target !== "offscreen" || msg.type !== "play") return;
  const a = document.getElementById("audio");
  if (!a) return;
  a.volume = typeof msg.volume === "number" ? Math.max(0, Math.min(1, msg.volume)) : 1;
  try {
    a.currentTime = 0;
  } catch (e) {}
  a.play().catch(() => {});
});
