/* ============================================================
   Sound · toggle + popover (shared by the spatial site and /comic/)
   js/sound.js renders a speaker button into every [data-sound-slot]
   and one popover (Effects, Soundtrack, Volume) anchored to it.
   Glass by default (visionOS Control Center); .sfx--comic swaps to
   ink and paper for the comic site.
   Hooks: --sfx-size on the slot sets the button size (hit area
   stays ≥ 44px).
   ============================================================ */

[data-sound-slot] { display: inline-flex; align-items: center; justify-content: center; }

/* ---------- Speaker button ---------- */
.sfx-btn {
  --s: var(--sfx-size, 38px);
  --sfx-spring: var(--vx-spring, cubic-bezier(0.34, 1.56, 0.64, 1));
  position: relative; flex: none; width: var(--s); height: var(--s); padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  color: rgb(255 255 255 / 0.62);
  background: var(--sfx-btn-bg, transparent);
  -webkit-tap-highlight-color: transparent;
  transition: background-color .22s, color .22s, scale .45s var(--sfx-spring);
}
.sfx-btn::before { content: ""; position: absolute; inset: min(0px, calc((var(--s) - 44px) / 2)); border-radius: 50%; } /* ≥ 44px target */
.sfx-btn:hover { background: rgb(255 255 255 / 0.14); color: rgb(255 255 255 / 0.96); }
.sfx-btn:active { scale: 0.88; }
.sfx-btn.is-on { color: rgb(255 255 255 / 0.96); }
.sfx-btn[aria-expanded="true"] { background: rgb(255 255 255 / 0.9); color: rgb(20 20 24); }
.sfx-btn:focus-visible { outline: 3px solid rgb(255 255 255 / 0.9); outline-offset: 2px; }

.sfx-ico { width: 20px; height: 20px; overflow: visible; }
.sfx-ico__w1, .sfx-ico__w2 { transform-box: view-box; transform-origin: 11px 12px; transition: opacity .28s, transform .5s var(--sfx-spring); }
.sfx-ico__w2 { transition-delay: 0s, .05s; }
.sfx-ico__body { transition: transform .5s var(--sfx-spring); transform-box: view-box; transform-origin: 7px 12px; }
.sfx-ico__slash { stroke-dasharray: 22; stroke-dashoffset: 0; transition: stroke-dashoffset .38s cubic-bezier(0.22, 1, 0.36, 1); }
.sfx-btn:not(.is-on) .sfx-ico__w1, .sfx-btn:not(.is-on) .sfx-ico__w2 { opacity: 0; transform: scale(0.35); }
.sfx-btn:not(.is-on) .sfx-ico__body { transform: translateX(2px); }
.sfx-btn.is-on .sfx-ico__slash { stroke-dashoffset: 22; }

/* Soundtrack on: the waves breathe slowly and a tiny dot marks the music */
.sfx-btn__music { position: absolute; right: 3px; bottom: 3px; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0; scale: 0.2; transition: opacity .25s, scale .45s var(--sfx-spring); }
.sfx-btn.is-music .sfx-btn__music { opacity: 0.9; scale: 1; }
/* glass: the soundtrack is on by default, so no permanent dot (it read as a stray, off centre mark); the waves breathe instead */
.sfx-btn:not(.sfx--comic) .sfx-btn__music { display: none; }
.sfx-btn.is-music .sfx-ico__w2 { animation: sfx-breathe 3.2s ease-in-out infinite; }
@keyframes sfx-breathe { 50% { opacity: 0.45; } }

/* Safety net when no slot exists (spatial site only) */
.sfx-float {
  position: fixed; z-index: 60; top: max(16px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right));
  padding: 4px; border-radius: 999px;
  background: rgb(var(--vx-glass, 36 36 42) / var(--vx-glass-a, 0.58));
  -webkit-backdrop-filter: blur(30px) saturate(170%); backdrop-filter: blur(30px) saturate(170%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.38), inset 0 0 0 1px rgb(255 255 255 / 0.14), 0 14px 34px -14px rgb(0 0 0 / 0.5);
}
.sfx-float .sfx-btn, .vx-cc__slot .sfx-btn { --s: 40px; }

/* ---------- Popover ---------- */
.sfx-pop {
  --sfx-spring: var(--vx-spring, cubic-bezier(0.34, 1.56, 0.64, 1));
  position: fixed; z-index: 2147483000; left: 0; top: 0;
  width: min(320px, calc(100vw - 24px)); padding: 12px;
  border-radius: 32px; color: #fff;
  font-family: var(--vx-font, 'Geist', -apple-system, BlinkMacSystemFont, system-ui, sans-serif);
  letter-spacing: -0.011em; -webkit-font-smoothing: antialiased;
  background: rgb(var(--vx-glass, 36 36 42) / 0.9); /* opaque enough to stay legible where backdrop blur is unavailable */
  -webkit-backdrop-filter: blur(44px) saturate(180%); backdrop-filter: blur(44px) saturate(180%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.36), inset 0 0 0 1px rgb(255 255 255 / 0.13), 0 34px 80px -24px rgb(0 0 0 / 0.6), 0 12px 28px -12px rgb(0 0 0 / 0.42);
  transform-origin: var(--sfx-ox, 50%) var(--sfx-oy, 0);
  opacity: 0; scale: 0.6; visibility: hidden; pointer-events: none;
  transition: opacity .18s ease, scale .3s cubic-bezier(0.4, 0, 1, 1), visibility 0s linear .3s;
}
.sfx-pop.is-open {
  opacity: 1; scale: 1; visibility: visible; pointer-events: auto;
  transition: opacity .2s ease, scale .62s var(--sfx-spring), visibility 0s;
}
.sfx-pop:focus { outline: none; }
.sfx-pop .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.sfx-pop__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 4px 16px 8px; }
.sfx-meter { flex: none; width: 96px; height: 32px; }
.sfx-pop__title { margin: 0; font-size: 17px; line-height: 1.25; font-weight: 700; letter-spacing: -0.02em; }
.sfx-pop__sub { margin: 2px 0 0; font-size: 13px; line-height: 1.35; color: rgb(255 255 255 / 0.62); }
.sfx-pop__foot { margin: 12px 8px 4px; font-size: 13px; line-height: 1.4; color: rgb(255 255 255 / 0.62); }

/* Control Center style tiles */
.sfx-pop__tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sfx-tile {
  position: relative; display: grid; grid-template-columns: auto; justify-items: start; gap: 2px;
  min-height: 112px; padding: 16px; border: 0; border-radius: 24px; text-align: left; cursor: pointer;
  font: inherit; color: #fff; background: rgb(255 255 255 / 0.08);
  -webkit-tap-highlight-color: transparent;
  transition: background-color .25s, scale .45s var(--sfx-spring);
}
.sfx-tile:hover { background: rgb(255 255 255 / 0.13); }
.sfx-tile:active { scale: 0.95; }
.sfx-tile:focus-visible { outline: 3px solid rgb(255 255 255 / 0.9); outline-offset: 2px; }
.sfx-tile__icon {
  position: relative; width: 40px; height: 40px; margin-bottom: 12px; border-radius: 50%;
  display: grid; place-items: center; color: rgb(255 255 255 / 0.9); background: rgb(255 255 255 / 0.14);
  transition: background-color .3s, color .3s, scale .5s var(--sfx-spring);
}
.sfx-tile__glyph { width: 20px; height: 20px; transition: opacity .2s, scale .4s var(--sfx-spring); }
.sfx-tile.is-on .sfx-tile__icon { background: rgb(255 255 255 / 0.95); color: rgb(18 18 22); }
.sfx-tile.is-on:active .sfx-tile__icon, .sfx-tile:active .sfx-tile__icon { scale: 0.9; }
.sfx-tile__label { font-size: 15px; line-height: 1.25; font-weight: 600; }
.sfx-tile__state { font-size: 13px; line-height: 1.3; color: rgb(255 255 255 / 0.62); font-variant-numeric: tabular-nums; }

/* Soundtrack playing: the note glyph gives way to a tiny equalizer */
.sfx-eq { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 2.5px; opacity: 0; transition: opacity .25s; }
.sfx-eq i { width: 3px; height: 14px; border-radius: 2px; background: currentColor; transform-origin: 50% 100%; transform: scaleY(0.35); }
.sfx-tile.is-on .sfx-eq { opacity: 1; }
.sfx-tile.is-on[data-k="music"] .sfx-tile__glyph { opacity: 0; scale: 0.5; }
.sfx-tile.is-on .sfx-eq i { animation: sfx-eq 1.3s ease-in-out infinite; }
.sfx-eq i:nth-child(2) { animation-delay: -.45s !important; animation-duration: 1.1s !important; }
.sfx-eq i:nth-child(3) { animation-delay: -.8s !important; animation-duration: 1.5s !important; }
.sfx-eq i:nth-child(4) { animation-delay: -.2s !important; animation-duration: 1.2s !important; }
@keyframes sfx-eq { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }

/* Volume: a thick Control Center slider with the speaker glyph riding inside */
.sfx-vol { position: relative; display: block; margin-top: 8px; height: 48px; }
.sfx-vol__range {
  -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 48px; margin: 0; border-radius: 24px; cursor: pointer;
  background: linear-gradient(90deg, rgb(255 255 255 / 0.92) 0 var(--sfx-v, 70%), rgb(255 255 255 / 0.12) var(--sfx-v, 70%) 100%);
  transition: opacity .25s, filter .25s;
  touch-action: pan-y;
}
.sfx-vol__range::-webkit-slider-runnable-track { height: 48px; background: transparent; border: 0; }
.sfx-vol__range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 2px; height: 48px; border: 0; background: transparent; }
.sfx-vol__range::-moz-range-track { height: 48px; background: transparent; border: 0; }
.sfx-vol__range::-moz-range-thumb { width: 2px; height: 48px; border: 0; background: transparent; }
.sfx-vol__range:focus-visible { outline: 3px solid rgb(255 255 255 / 0.9); outline-offset: 2px; }
.sfx-vol__ico { position: absolute; left: 14px; top: 50%; translate: 0 -50%; width: 22px; height: 22px; pointer-events: none; color: rgb(18 18 22); mix-blend-mode: normal; }
.sfx-vol__ico svg { width: 100%; height: 100%; display: block; }
.sfx-vol__ico--hi { left: auto; right: 14px; color: rgb(255 255 255 / 0.62); }
.sfx-pop.is-silent .sfx-vol__range { filter: saturate(0) brightness(0.8); opacity: 0.55; }

/* ---------- Comic theme (ink + paper) ---------- */
.sfx-btn.sfx--comic { color: rgb(var(--dd-ink, 28 28 28)); background: rgb(var(--dd-paper, 255 255 255)); box-shadow: 0 0 0 2.5px rgb(var(--dd-ink, 28 28 28)), 3px 3px 0 2.5px rgb(var(--dd-ink, 28 28 28)); }
.sfx-btn.sfx--comic:hover { background: rgb(var(--dd-paper, 255 255 255)); color: rgb(var(--dd-ink, 28 28 28)); translate: -1px -1px; }
.sfx-btn.sfx--comic[aria-expanded="true"] { background: rgb(var(--dd-bg, 46 91 255)); color: #fff; }
.sfx-pop.sfx--comic {
  color: rgb(var(--dd-ink, 28 28 28)); background: rgb(var(--dd-paper, 255 255 255));
  -webkit-backdrop-filter: none; backdrop-filter: none; border-radius: 22px;
  box-shadow: 0 0 0 3px rgb(var(--dd-ink, 28 28 28)), 6px 6px 0 3px rgb(var(--dd-ink, 28 28 28));
  font-family: var(--dd-ff, 'Patrick Hand SC', cursive);
}
.sfx--comic .sfx-pop__sub, .sfx--comic .sfx-pop__foot, .sfx--comic .sfx-tile__state { color: rgb(var(--dd-ink, 28 28 28) / 0.7); }
.sfx--comic .sfx-pop__title { font-family: var(--dd-ff-display, 'Gochi Hand', cursive); font-size: 24px; font-weight: 400; }
.sfx--comic .sfx-pop__sub, .sfx--comic .sfx-tile__state { font-size: 16px; }
.sfx--comic .sfx-tile__label { font-size: 19px; font-weight: 400; }
.sfx--comic .sfx-pop__foot { font-size: 15px; }
.sfx--comic .sfx-tile { color: rgb(var(--dd-ink, 28 28 28)); background: rgb(var(--dd-paper, 255 255 255)); box-shadow: inset 0 0 0 2.5px rgb(var(--dd-ink, 28 28 28)); border-radius: 16px; }
.sfx--comic .sfx-tile__icon { color: rgb(var(--dd-ink, 28 28 28)); background: rgb(var(--dd-ink, 28 28 28) / 0.08); }
.sfx--comic .sfx-tile.is-on .sfx-tile__icon { background: rgb(var(--dd-bg, 46 91 255)); color: #fff; }
.sfx--comic .sfx-vol__range { border-radius: 14px; box-shadow: inset 0 0 0 2.5px rgb(var(--dd-ink, 28 28 28)); background: linear-gradient(90deg, rgb(var(--dd-bg, 46 91 255)) 0 var(--sfx-v, 70%), rgb(var(--dd-paper, 255 255 255)) var(--sfx-v, 70%) 100%); }
.sfx--comic .sfx-vol__ico { color: #fff; }
.sfx--comic .sfx-vol__ico--hi { color: rgb(var(--dd-ink, 28 28 28) / 0.7); }
.sfx--comic .sfx-tile:focus-visible, .sfx--comic .sfx-vol__range:focus-visible, .sfx-btn.sfx--comic:focus-visible { outline-color: rgb(var(--dd-ink, 28 28 28)); }

/* ---------- Reduced motion / transparency ---------- */
@media (prefers-reduced-motion: reduce) {
  .sfx-btn, .sfx-tile, .sfx-tile__icon, .sfx-ico__w1, .sfx-ico__w2, .sfx-ico__body, .sfx-btn__music { transition-duration: 0.01ms !important; }
  .sfx-pop, .sfx-pop.is-open { scale: 1; transition: opacity .15s ease, visibility 0s linear .15s; }
  .sfx-pop.is-open { transition: opacity .15s ease, visibility 0s; }
  .sfx-btn.is-music .sfx-ico__w2, .sfx-tile.is-on .sfx-eq i { animation: none; }
  .sfx-tile.is-on .sfx-eq i:nth-child(odd) { transform: scaleY(0.8); }
  .sfx-tile.is-on .sfx-eq i:nth-child(even) { transform: scaleY(0.5); }
}
@media (prefers-reduced-transparency: reduce) {
  .sfx-pop { background: rgb(30 30 36 / 0.97); }
}
