{
  pkgs,
  myConfig,
  inputs,
  ...
}: {
  wayland.windowManager.hyprland.settings = {
    exec-once = [
      "uwsm app -- pywalfox start"
    ];

    bindd = [
      "SUPER, W, Open Browser, exec, uwsm app -- firefox"
      "SUPER ALT, P, Open Browser, exec, uwsm app -- firefox -P VPN"
      "SUPER, Y, Toggle YouTube, togglespecialworkspace, youtube"
      "SUPER SHIFT, Y, Move to YouTube Special Workspace, movetoworkspace, special:youtube"
      "SUPER, I, Toggle Jellyfin, togglespecialworkspace, jellyfin"
      "SUPER SHIFT, I, Move to Jellyfin Special Workspace, movetoworkspace, special:jellyfin"
    ];

    workspace = [
      "special:youtube, on-created-empty:uwsm app -- firefox -P web-app --name youtube https://youtube.com"
      "special:jellyfin, on-created-empty:uwsm app -- firefox -P web-app --name jellyfin https://watch.sakamoto.dev"
    ];

    windowrule = [
      "match:class (?i)(firefox|youtube|jellyfin), opacity 1 1"
      "match:class ^(youtube)$, workspace special:youtube"
      "match:class ^(jellyfin)$, workspace special:jellyfin"
    ];
  };
  imports = [
    inputs.textfox.homeManagerModules.default
    ./textfox.nix
  ];
  home.packages = with pkgs; [
    pywalfox-native
    tridactyl-native
  ];

  home.file.".config/tridactyl/tridactylrc".text = ''
    set focusbypass true
    set smoothscroll true
    bind J tabnext
    bind K tabprev
    unbind <C-e>

    " Force Tridactyl to yield new tab control to Firefox/Extensions
    set newtab about:newtab
  '';

  xdg.mimeApps = {
    enable = true;
    defaultApplications = {
      "text/html" = "firefox.desktop";
      "x-scheme-handler/http" = "firefox.desktop";
      "x-scheme-handler/https" = "firefox.desktop";
      "x-scheme-handler/about" = "firefox.desktop";
      "x-scheme-handler/unknown" = "firefox.desktop";
    };
  };

  programs.firefox = {
    enable = true;
    languagePacks = ["en-US"];
    nativeMessagingHosts = [
      pkgs.pywalfox-native
      pkgs.tridactyl-native
    ];

    profiles = {
      youtube = import ./profiles/web-app.nix {
        inherit pkgs myConfig;
        id = 1;
        name = "YouTube";
        url = "https://youtube.com";
      };
      jellyfin = import ./profiles/web-app.nix {
        inherit pkgs myConfig;
        id = 2;
        name = "Jellyfin";
        url = "https://watch.sakamoto.dev";
      };
      web-app = import ./profiles/web-app.nix {
        inherit pkgs myConfig;
        id = 3;
        name = "web-app";
        url = "about:blank";
      };
      vpn-proxy = import ./profiles/vpn-proxy.nix {
        inherit pkgs myConfig;
        id = 4;
        name = "VPN";
        url = "https://browserleaks.com/ip";
      };

      hakase = {
        search.force = true;
        isDefault = true;
        search.default = "ddg";
        extensions.packages = with pkgs.nur.repos.rycee.firefox-addons; [
          pywalfox
          ublock-origin
          bitwarden
          tridactyl
          new-tab-override
        ];

        bookmarks = {
          force = true;
          settings = [
            {
              name = "Toolbar Bookmarks";
              toolbar = true;
              bookmarks = myConfig.firefox.bookmarks;
            }
          ];
        };

        settings = {
          # --- Privacy & Hardening ---
          "browser.contentblocking.category" = "strict";
          "geo.enabled" = true;
          "media.peerconnection.enabled" = false; # Prevents WebRTC IP leaks
          "network.dns.disablePrefetch" = true;
          "network.prefetch-next" = false;
          "privacy.resistFingerprinting" = false; # Note: Spoofs timezone and caps FPS to 60
          "privacy.trackingprotection.enabled" = true;

          # --- NixOS / Hyprland Integration ---
          "widget.use-xdg-desktop-portal.file-picker" = 1; # Use native file picker

          # --- UI & Behavior ---
          "accessibility.typeaheadfind" = false;
          "browser.compactmode.show" = true;
          "browser.formfill.enable" = false;
          "browser.newtabpage.activity-stream.feeds.section.topstories" = false;
          "browser.newtabpage.activity-stream.feeds.snippets" = false;
          "browser.newtabpage.activity-stream.section.highlights.includeBookmarks" = false;
          "browser.newtabpage.activity-stream.section.highlights.includeDownloads" = false;
          "browser.newtabpage.activity-stream.section.highlights.includePocket" = false;
          "browser.newtabpage.activity-stream.section.highlights.includeVisited" = false;
          "browser.newtabpage.activity-stream.showSponsored" = false;
          "browser.newtabpage.activity-stream.showSponsoredTopSites" = false;
          "browser.newtabpage.activity-stream.system.showSponsored" = false;
          "browser.search.suggest.enabled" = false;
          "browser.search.suggest.enabled.private" = false;
          "browser.tabs.closeWindowWithLastTab" = false;
          "browser.topsites.contile.enabled" = false;
          "browser.urlbar.showSearchSuggestionsFirst" = false;
          "browser.urlbar.suggest.searches" = false;
          "extensions.pocket.enabled" = false;
          "extensions.screenshots.disabled" = true;

          # --- Homepage & Navigation ---
          "browser.newtabpage.pinned" = myConfig.firefox.newtabpage;
          "browser.startup.homepage" = "https://dash.sakamoto.dev";

          # --- DNS over HTTPS (Quad9) ---
          "network.trr.mode" = 2; # Use DoH with system fallback
          "network.trr.uri" = "https://dns.quad9.net/dns-query";
        };
      };
    };

    policies = {
      DisableTelemetry = true;
      DisableFirefoxStudies = true;
      EnableTrackingProtection = {
        Value = true;
        Locked = false;
        Cryptomining = true;
        Fingerprinting = true;
      };
      DisablePocket = true;
      DisableFirefoxAccounts = true;
      DisableAccounts = true;
      DisableFirefoxScreenshots = true;
      OverrideFirstRunPage = "";
      OverridePostUpdatePage = "";
      DontCheckDefaultBrowser = true;
      DisplayBookmarksToolbar = "always";
      SearchBar = "unified";

      # Power User Messaging
      UserMessaging = {
        ExtensionRecommendations = false;
        SkipOnboarding = true;
        FeatureRecommendations = false;
        UrlbarInterventions = false;
        WhatsNew = false;
      };
    };
  };
}
