Query for total time of a category, regardless of bucket

I would like to query the total time I spent today in a given category, e.g. Media>Games.

There is an example in the API docs (“Magic Variables”) that shows how to filter by category, but it queries from a single bucket only.

I have multiple buckets (window, browser, may become more later) so querying for certain buckets is not a sensible thing to do.

The total active time forum post shows how to get time without involving buckets, but I fail to find how to include categories there.
I tried the following, but it always returns 0 (I query the work category because my test instance has time tracked on it):

afk_events = query_bucket(find_bucket("aw-watcher-afk_"));
events = filter_keyvals(afk_events, "status", ["not-afk"]);
events = categorize(events, __CATEGORIES__);
events = filter_keyvals(events, "$category", [["Work"]]);
RETURN = sum_durations(events);

What am I doing wrong?