{
  lib,
  config,
  outputs,
  ...
}: let
  cfg = config.colorscheme;
  inherit (lib) types mkOption;

  hexColor = types.strMatching "#([0-9a-fA-F]{3}){1,2}";
in {
  options.colorscheme = {
    # Source color (hex). Defaults to the wallpaper's precomputed sourceColor
    # (matugen's extracted seed, committed in pkgs/wallpapers/list.json), so schemes
    # are generated purely with no image decoding / IFD.
    source = mkOption {
      type = hexColor;
      default =
        if config.wallpaper != null
        then config.wallpaper.sourceColor
        else "#2B3975";
    };
    mode = mkOption {
      type = types.enum ["dark" "light"];
      default = "dark";
    };

    # Extra named colors, harmonized toward the source (matugen custom_colors).
    customColors = mkOption {
      type = types.attrsOf hexColor;
      default = {
        red = "#dd0000";
        orange = "#dd5522";
        yellow = "#dddd00";
        green = "#22dd22";
        cyan = "#22dddd";
        blue = "#2222dd";
        magenta = "#dd22dd";
      };
    };

    # Full pure-Nix material-you scheme ({ colors = { dark; light; }; }),
    # generated by lib/material-you.nix (rainbow variant, standard contrast).
    rawColorscheme = mkOption {
      type = types.attrs;
      default = outputs.lib.material-you.generateColorscheme cfg.source cfg.customColors;
    };

    colors = mkOption {
      readOnly = true;
      type = types.attrsOf hexColor;
      default = cfg.rawColorscheme.colors.${cfg.mode};
    };

    # Gives access to other homes' colors
    hosts = mkOption {
      readOnly = true;
      type = types.attrs;
      default = lib.mapAttrs (_: v: v.colors.${cfg.mode}) outputs.colorschemes;
    };
  };
}
