{pkgs, ...}: {
  services.jellyfin-mpv-shim = {
    enable = true;
    package = pkgs.jellyfin-mpv-shim;

    mpvConfig = {
      osc = false;
      osd-bar = false;
      load-scripts = true;
      input-vo-keyboard = true;
      input-default-bindings = true;

      # Automatic subtitle selection logic:
      # Prefer English subtitles
      slang = "eng,en";
      # Prefer Japanese/Non-English audio first (if that's what you usually watch)
      # or just ensure English subs are picked when audio isn't English.
      sub-auto = "fuzzy";
      sub-visibility = "yes";
    };

    mpvBindings = {
      "j" = "cycle sub";
      "S-j" = "cycle sub rev";
      "v" = "cycle sub-visibility";
    };

    settings = {
      use_mpv_config = false;
      enable_osc = false;
      menu_mouse = true;

      # Shim specific auto-sub logic
      # "subs-fallback" is a known good setting for the shim to handle this
      subtitle_color = "#FFFFFFFF";
      subtitle_size = 100;

      audio_output = "hdmi";
      auto_play = true;
      fullscreen = true;
      player_name = "hakase";
      remote_kbps = 100000;
      local_kbps = 1000000;
    };
  };

  # Modern OSC + Quality scripts
  home.file.".config/jellyfin-mpv-shim/scripts/uosc" = {
    source = "${pkgs.mpvScripts.uosc}/share/mpv/scripts/uosc";
  };
  home.file.".config/jellyfin-mpv-shim/scripts/thumbfast.lua" = {
    source = "${pkgs.mpvScripts.thumbfast}/share/mpv/scripts/thumbfast.lua";
  };
  home.file.".config/jellyfin-mpv-shim/scripts/autocrop.lua" = {
    source = "${pkgs.mpvScripts.autocrop}/share/mpv/scripts/autocrop.lua";
  };

  home.file.".config/jellyfin-mpv-shim/fonts" = {
    source = "${pkgs.mpvScripts.uosc}/share/fonts";
    recursive = true;
  };

  wayland.windowManager.hyprland.settings = {
    exec-once = ["systemctl --user start jellyfin-mpv-shim"];
    windowrule = [
      # --- JELLYFIN MPV SHIM ---
      "match:class ^(jellyfin-mpv-shim)$, float on"
      "match:class ^(jellyfin-mpv-shim)$, center on"
      "match:class ^(jellyfin-mpv-shim)$, size 70% 70%"
      "match:class ^(jellyfin-mpv-shim)$, opacity 1.0 override 1.0 override"
      "match:class ^(jellyfin-mpv-shim)$, idle_inhibit focus"
      "match:class ^(jellyfin-mpv-shim)$, no_blur on"
    ];
  };
}

