{
  pkgs,
  inputs,
  myConfig,
  ...
}: {
  home.packages = with pkgs; [
    inputs.matugen.packages.${pkgs.system}.default
    dconf
    psmisc # for killall
  ];
  home.file.".config/matugen/config.toml" = {
    source = ./config.toml;
  };

  # Copy static templates
  home.file.".config/matugen/templates/theme-switch".text = ''
    #!/bin/sh
    # Generated by Matugen

    # mode will be replaced by 'dark' or 'light'
    MODE="{{mode}}"

    if [ "$MODE" = "dark" ]; then
        ${pkgs.dconf}/bin/dconf write /org/gnome/desktop/interface/color-scheme "'prefer-dark'"
    else
        ${pkgs.dconf}/bin/dconf write /org/gnome/desktop/interface/color-scheme "'prefer-light'"
    fi
  '';
  home.file.".config/matugen/templates/cava".source = ./templates/cava;
  home.file.".config/matugen/templates/firefox".source = ./templates/firefox;
  home.file.".config/matugen/templates/ghostty".source = ./templates/ghostty;
  home.file.".config/matugen/templates/gtk3".source = ./templates/gtk3;
  home.file.".config/matugen/templates/gtk4".source = ./templates/gtk4;
  home.file.".config/matugen/templates/hyprland".source = ./templates/hyprland;
  home.file.".config/matugen/templates/hyprlock".source = ./templates/hyprlock;
  home.file.".config/matugen/templates/starship".source = ./templates/starship;
  home.file.".config/matugen/templates/waybar".source = ./templates/waybar;
  home.file.".config/matugen/templates/zathura".source = ./templates/zathura;

  home.file.".config/matugen/templates/vicinae".text = ''
    # Vicinae Matugen Theme Template

    [meta]
    name = "Matugen"
    description = "Material You theme generated by Matugen - {{mode}} variant"
    variant = "{{mode}}"

    # ============================================================================
    # Typography
    # ============================================================================

    [typography]
    font_family = "${myConfig.font.monospace}"

    # ============================================================================
    # Core Colors
    # ============================================================================

    [colors.core]
    accent = "{{colors.primary.default.hex}}"
    accent_foreground = "{{colors.on_primary.default.hex}}"
    background = "{{colors.surface.default.hex}}"
    foreground = "{{colors.on_surface.default.hex}}"
    secondary_background = "{{colors.surface_container.default.hex}}"
    border = "{{colors.outline_variant.default.hex}}"

    # ============================================================================
    # Window Borders
    # ============================================================================

    [colors.main_window]
    border = "{{colors.outline_variant.default.hex}}"

    [colors.settings_window]
    border = "{{colors.outline.default.hex}}"

    # ============================================================================
    # Accent Palette
    # ============================================================================

    [colors.accents]
    blue = "{{colors.primary.default.hex}}"
    green = "{{colors.tertiary.default.hex}}"
    magenta = "{{colors.secondary.default.hex}}"
    orange = { name = "{{colors.error.default.hex}}", lighter = 40 }
    red = "{{colors.error.default.hex}}"
    yellow = { name = "{{colors.tertiary.default.hex}}", lighter = 80 }
    cyan = { name = "{{colors.primary.default.hex}}", lighter = 50 }
    purple = "{{colors.secondary.default.hex}}"

    # ============================================================================
    # Text System
    # ============================================================================

    [colors.text]
    default = "{{colors.on_surface.default.hex}}"
    muted = "{{colors.on_surface_variant.default.hex}}"
    danger = "{{colors.error.default.hex}}"
    success = "{{colors.tertiary.default.hex}}"
    placeholder = { name = "{{colors.on_surface_variant.default.hex}}", opacity = 0.6 }

    [colors.text.selection]
    background = "{{colors.primary.default.hex}}"
    foreground = "{{colors.on_primary.default.hex}}"

    [colors.text.links]
    default = "{{colors.primary.default.hex}}"
    visited = { name = "{{colors.tertiary.default.hex}}", darker = 20 }

    # ============================================================================
    # Input Fields
    # ============================================================================

    [colors.input]
    border = "{{colors.outline.default.hex}}"
    border_focus = "{{colors.primary.default.hex}}"
    border_error = "{{colors.error.default.hex}}"

    # ============================================================================
    # Buttons
    # ============================================================================

    [colors.button.primary]
    background = "{{colors.surface_container_high.default.hex}}"
    foreground = "{{colors.on_surface.default.hex}}"

    [colors.button.primary.hover]
    background = "{{colors.surface_container_highest.default.hex}}"

    [colors.button.primary.focus]
    outline = "{{colors.primary.default.hex}}"

    # ============================================================================
    # Lists
    # ============================================================================

    [colors.list.item.hover]
    background = { name = "{{colors.primary_container.default.hex}}", opacity = 0.25 }
    foreground = "{{colors.on_surface.default.hex}}"

    [colors.list.item.selection]
    background = { name = "{{colors.primary_container.default.hex}}", opacity = 0.50 }
    foreground = "{{colors.on_primary_container.default.hex}}"
    secondary_background = "{{colors.primary_container.default.hex}}"
    secondary_foreground = "{{colors.on_primary_container.default.hex}}"

    # ============================================================================
    # Grid Items
    # ============================================================================

    [colors.grid.item]
    background = "{{colors.surface_container.default.hex}}"

    [colors.grid.item.hover]
    outline = { name = "{{colors.secondary.default.hex}}", opacity = 0.8 }

    [colors.grid.item.selection]
    outline = { name = "{{colors.primary.default.hex}}" }

    # ============================================================================
    # Scrollbars
    # ============================================================================

    [colors.scrollbars]
    background = { name = "{{colors.primary.default.hex}}", opacity = 0.2 }

    # ============================================================================
    # Loading States
    # ============================================================================

    [colors.loading]
    bar = "{{colors.primary.default.hex}}"
    spinner = "{{colors.primary.default.hex}}"
  '';

  # Generate templates with font interpolation
  home.file.".config/matugen/templates/walker".text = ''
    /* @import "../../../../../../../.config/omarchy/current/theme/walker.css"; */

    /* Define Matugen Colors */
    @define-color text {{colors.on_surface.default.hex}};
    @define-color base {{colors.surface_container.default.hex}};
    @define-color border {{colors.primary.default.hex}};
    @define-color selected_text {{colors.primary.default.hex}};
    @define-color background {{colors.surface.default.hex}};

    * {
      all: unset;
    }

    * {
      font-family: ${myConfig.font.monospace};
      font-size: 18px;
      color: @text;
    }

    scrollbar {
      opacity: 0;
    }

    .normal-icons {
      -gtk-icon-size: 16px;
    }

    .large-icons {
      -gtk-icon-size: 32px;
    }

    .box-wrapper {
      background: alpha(@base, 0.95);
      padding: 20px;
      border: 2px solid @border;
    }

    .preview-box {
    }

    .box {
    }

    .search-container {
      background: @base;
      padding: 10px;
    }

    .input placeholder {
      opacity: 0.5;
    }

    .input {
    }

    .input:focus,
    .input:active {
      box-shadow: none;
      outline: none;
    }

    .content-container {
    }

    .placeholder {
    }

    .scroll {
    }

    .list {
    }

    child,
    child > * {
    }

    child:hover .item-box {
    }

    child:selected .item-box {
    }

    child:selected .item-box * {
      color: @selected_text;
    }

    .item-box {
      padding-left: 14px;
    }

    .item-text-box {
      all: unset;
      padding: 14px 0;
    }

    .item-text {
    }

    .item-subtext {
      font-size: 0px;
      min-height: 0px;
      margin: 0px;
      padding: 0px;
    }

    .item-image {
      margin-right: 14px;
      -gtk-icon-transform: scale(0.9);
    }

    .current {
      font-style: italic;
    }

    .keybind-hints {
      background: @background;
      padding: 10px;
      margin-top: 10px;
    }

    .preview {
    }
  '';

  home.file.".config/matugen/templates/mako".text = ''
    # Mako notification daemon configuration
    # Generated by matugen

    # Appearance
    font=${myConfig.font.sans} 11
    width=350
    height=150
    margin=10
    padding=15
    border-size=2
    border-radius=8

    # Behavior
    default-timeout=5000
    ignore-timeout=false
    layer=overlay
    anchor=top-right

    # Interaction
    markup=true
    actions=true

    # Grouping
    group-by=app-name
    max-visible=5
    sort=-time

    # Theme colors from matugen
    background-color=#{{colors.surface_container_high.default.hex_stripped}}
    text-color=#{{colors.on_surface.default.hex_stripped}}
    border-color=#{{colors.primary.default.hex_stripped}}
    progress-color=over #{{colors.primary_container.default.hex_stripped}}

    [urgency=low]
    border-color=#{{colors.tertiary.default.hex_stripped}}

    [urgency=normal]
    border-color=#{{colors.primary.default.hex_stripped}}

    [urgency=high]
    border-color=#{{colors.error.default.hex_stripped}}
    default-timeout=0
  '';

  # Qt theming - follow GTK theme
  qt = {
    enable = true;
    platformTheme.name = "gtk";
  };

  dconf.settings = {
    "org/gnome/desktop/interface" = {
      color-scheme =
        if myConfig.theme.mode == "dark"
        then "prefer-dark"
        else "prefer-light";
    };
  };

  # GTK theming with adw-gtk3 and Matugen colors
  gtk = {
    enable = true;
    theme = {
      name = "adw-gtk3";
      package = pkgs.adw-gtk3;
    };
    iconTheme = {
      name = "Papirus-Dark";
      package = pkgs.papirus-icon-theme;
    };
    gtk3.extraCss = ''@import url("colors.css");'';
    gtk3.extraConfig = {
      gtk-application-prefer-dark-theme =
        if myConfig.theme.mode == "dark"
        then 1
        else 0;
    };
    gtk4.extraCss = ''@import url("colors.css");'';
    gtk4.extraConfig = {
      gtk-application-prefer-dark-theme =
        if myConfig.theme.mode == "dark"
        then 1
        else 0;
    };
  };

  programs.ghostty.settings.theme = "matugen";
  programs.starship.enable = true;
  wayland.windowManager.hyprland.settings.source = ["./matugen.conf"];
  programs.walker.config.theme = "nixos";
}
