{ ... }: {
  flake.homeManagerModules.wisdomDesktopGtkQtTheming =
    { config, lib, pkgs, osConfig ? { }, ... }:
    let
      root = config.chiasson.home;
      cfg = config.chiasson.home.desktop.theming;
      dmsShell = (lib.attrByPath [ "chiasson" "desktop" "shell" ] null osConfig) == "dms";
      qtPlatformTheme = if dmsShell then "qt6ct" else cfg.qt.platformTheme;
    in
    {
      options.chiasson.home.desktop.theming = {
        enable = lib.mkEnableOption ''
          WhiteSur GTK + icon themes, Phinger cursor, and Qt via qt6ct (DMS) or KDE platform theme.
          Matugen accent colors load via gtk3/gtk4 extraCss when matugenGtkColors is enabled.
        '' // {
          default = true;
        };

        matugenGtkColors = lib.mkOption {
          type = lib.types.bool;
          default = true;
          description = ''
            Add `@import url("dank-colors.css");` to gtk3/gtk4 extraCss (DMS matugen writes the file).
          '';
        };

        gtkTheme = {
          name = lib.mkOption {
            type = lib.types.str;
            default = "WhiteSur-Dark";
          };
          package = lib.mkOption {
            type = lib.types.package;
            default = pkgs.whitesur-gtk-theme;
          };
        };

        iconTheme = {
          name = lib.mkOption {
            type = lib.types.str;
            default = "WhiteSur-dark";
          };
          package = lib.mkOption {
            type = lib.types.package;
            default = pkgs.whitesur-icon-theme;
          };
        };

        cursor = {
          name = lib.mkOption {
            type = lib.types.str;
            default = "phinger-cursors-dark";
          };
          package = lib.mkOption {
            type = lib.types.package;
            default = pkgs.phinger-cursors;
          };
          size = lib.mkOption {
            type = lib.types.int;
            default = 32;
          };
        };

        qt = {
          platformTheme = lib.mkOption {
            type = lib.types.str;
            default = "kde";
            description = ''
              `QT_QPA_PLATFORMTHEME` when not using DMS shell. DMS hosts use qt6ct automatically.
            '';
          };
          extraPackages = lib.mkOption {
            type = lib.types.listOf lib.types.package;
            default = [ pkgs.kdePackages.qt6ct ];
            description = "Qt platform integration packages.";
          };
        };
      };

      config = lib.mkIf (root.enable && cfg.enable) (lib.mkMerge [
        {
          home.packages =
            if dmsShell then
              [ pkgs.kdePackages.qt6ct ]
            else
              cfg.qt.extraPackages;

          home.sessionVariables = {
            QT_QPA_PLATFORMTHEME = qtPlatformTheme;
          }
          // lib.optionalAttrs (qtPlatformTheme == "qt6ct") {
            QT_QPA_PLATFORMTHEME_QT6 = "qt6ct";
          };

          home.pointerCursor = {
            name = cfg.cursor.name;
            package = cfg.cursor.package;
            size = cfg.cursor.size;
            gtk.enable = true;
            x11.enable = true;
          };

          gtk = {
            enable = true;
            theme = {
              name = cfg.gtkTheme.name;
              package = cfg.gtkTheme.package;
            };
            iconTheme = {
              name = cfg.iconTheme.name;
              package = cfg.iconTheme.package;
            };
            cursorTheme = {
              name = cfg.cursor.name;
              package = cfg.cursor.package;
              size = cfg.cursor.size;
            };
            gtk3.extraConfig = {
              gtk-application-prefer-dark-theme = 1;
            };
            gtk4 = {
              theme = {
                name = cfg.gtkTheme.name;
                package = cfg.gtkTheme.package;
              };
              extraConfig = {
                gtk-application-prefer-dark-theme = 1;
              };
            };
          };
        }
        (lib.mkIf cfg.matugenGtkColors {
          gtk.gtk3.extraCss = ''
            @import url("dank-colors.css");
          '';
          gtk.gtk4.extraCss = ''
            @import url("dank-colors.css");
          '';
        })
      ]);
    };
}
