& {
	//Give the tabs/Incognito/pfp the appropriate offset
	#private-browsing-indicator-with-label,
	.private-browsing-indicator-with-label /* Fix for Firefox 133+ */,
    #gkavatar-container {
		order: -1 !important; // Force to left
	}
	.titlebar-spacer {
		&[type="pre-tabs"] {
			order: -2 !important; // Force to left of Incognito
		}
	}
	&:not([privatebrowsingmode="temporary"]) {
		#TabsToolbar-customization-target {
			margin-inline-start: var(--tab-distance-from-toolbar-edge);
		}
	}
	// Incognito can't use this^ spacing, so we need to set it separately for Incognito
	&[privatebrowsingmode="temporary"] {
		#private-browsing-indicator-with-label,
		.private-browsing-indicator-with-label /* Fix for Firefox 133+ */ {
			margin-inline-start: var(--tab-distance-from-toolbar-edge);
		}
	}
	#gkavatar-container > #gk-firefox-account-button,
	.private-browsing-indicator-icon {
		margin-inline-start: 1px !important;
		margin-inline-end: var(--tab-distance-from-pfp) !important;
	}
	//Ensure left-sided titlebuttons go before Incognito in native titlebars
	&[gktitnative="true"] {
		@media (-moz-platform: macos) or ((-moz-platform: linux) and (-moz-gtk-csd-reversed-placement)) {
			.titlebar-buttonbox-container {
				order: -3 !important;
			}
		}
	}

	// Tweaks for Profile Titlebutton
	#gkpeople-button-container {
		margin-inline-end: 0 !important;
	}

	//Restore Firefox's Win10 menubar styling
	&[gktitnative="true"] {
		.titlebar-spacer[type="post-tabs"] {
			margin-inline-end: 4px !important; // Add spacing between caption buttons and tabs.
		}
		
		#main-menubar > menu {
			text-shadow: 0 1px 4px rgba(255, 255, 255, 0.8) !important;
			&[_moz-menuactive] {
				background-color: hsla(0,0%,0%,.12) !important;

				@media (prefers-color-scheme: dark) {
					background-color: hsla(0,0%,100%,.22) !important;
				}
			}
			@media (-moz-platform: linux) { // Temporary
				border-color: transparent !important;
			}
		}
	}

	&[gktitnative="false"] {
		&[type="post-tabs"] {
			margin-inline-end: 16px !important; // Add spacing between caption buttons and tabs.
		}
		
		//Always use the white Google logo in non-native titlebars
		&[gkbranding="chrome"]:not([geckium-chrflag-linux-pre-alpha-titlebar="true"]) {
			&[privatebrowsingmode="temporary"],
			&:not([gkpeoplestyle="titlebutton"]) {
				.titlebar-buttonbox-container::before {
					content: url("chrome://userchrome/content/assets/img/chrome-1/titlebar/windows/google-alternate.png");
					margin-block-start: 3px;
					margin-inline-end: 7px;
				}
				&[sizemode="maximized"],
				&[sizemode="fullscreen"] {
					.titlebar-buttonbox-container::before {
						content: unset !important;
					}
				}
			}
			&:not([privatebrowsingmode="temporary"]),
			&[gkpeoplestyle="titlebutton"] {
				#gkpeople-button-container::before {
					content: url("chrome://userchrome/content/assets/img/chrome-1/titlebar/windows/google-alternate.png");
					margin-block-start: 3px;
					margin-inline-end: 7px;
				}
				&[sizemode="maximized"],
				&[sizemode="fullscreen"] {
					#gkpeople-button-container::before {
						content: unset !important;
					}
				}
			}
		}

		//Shared non-native titlebar variables
		& {
			--titlebutton-border-outer: 1px solid rgb(0, 0, 0, 0.35);
			--titlebutton-corner: 5px;
			--titlebutton-background-hover: rgba(255, 255, 255, 0.3);
			--titlebutton-background-active: rgba(255, 255, 255, 0.2);
		}

		//Titlebar button box (force onto right side)
		.titlebar-buttonbox-container {
			order: 1000 !important;
			align-items: unset !important;
		}
		//Linux quirk: Counteract exclusive menubar padding
		@media (-moz-platform: linux) {
			#toolbar-menubar .titlebar-buttonbox-container {
				margin-block-start: -1px; // top margin
			}
		}

		.titlebar-buttonbox {
			align-items: unset !important;
			gap: 1px;
		}
		
		//Shared titlebar button code
		.titlebar-button {
			background: transparent !important;
			border-radius: 0 !important;
			transition: background-color 100ms linear; //hover-fade animation
			display: flex !important;
			height: 30px;
			width: 45px;
			color: var(--titlebar-button-foreground, inherit) !important;
			&:-moz-window-inactive {
				color: var(--titlebar-button-foreground-inactive, inherit) !important;
			}
			
			// Hover and pressed states
			&:not([disabled]):hover {
				background: color-mix(in srgb, currentColor 12%, transparent) !important;

				&:active {
					background: color-mix(in srgb, currentColor 22%, transparent) !important;
					transition: none;
				}
			}

			//Make the stroke actually visible
			-moz-context-properties: stroke !important;
			.toolbarbutton-icon {
				stroke: currentColor !important;
			}
		}

		&[sizemode="maximized"],
		&[sizemode="fullscreen"] {
			// Decrease button height before MD1
			&:not([geckium-sixtyeight]) .titlebar-button {
				height: 24px;
			}

			// Decrease button height during MD1
			&[geckium-sixtyeight] .titlebar-button {
				height: 29px;
			}
		}

		// Halve opacity if window's inactive
		&:-moz-window-inactive[gkthemed],
		&:-moz-window-inactive:not([gksystheme="gtk"], [gkthemed]) { // can cause readability issues on GTK+
			.titlebar-button:not(:hover, :active) {
				opacity: 0.5;
			}
		}

		//Close button
		.titlebar-close {
			list-style-image: url(chrome://userchrome/content/assets/img/chrome-68/titlebar/windows/close.svg) !important;
			border-top-right-radius: var(--titlebar-border-radius) !important; // Ensure it doesn't overlay the border in macOS
			order: 2 !important;

			&:not([disabled]):hover {
				background: hsl(355,86%,49%) !important;
				color: white !important;
			}

			&:not([disabled]):hover:active {
				background: hsl(355,82%,69%) !important;
				color: white !important;
			}
		}
		&:-moz-locale-dir(rtl) { // Swap corners in RTL
			.titlebar-close {
				border-top-right-radius: 0 !important;
				border-top-left-radius: min(var(--titlebar-border-radius), 0px) !important;
			}
		}

		//Maximise and Restore buttons
		.titlebar-max {
			list-style-image: url(chrome://userchrome/content/assets/img/chrome-68/titlebar/windows/maximise.svg) !important;
		}
		&[sizemode="maximized"],
		&[sizemode="fullscreen"] {
			.titlebar-max {
				display: none !important;
			}
		}
		.titlebar-restore {
			list-style-image: url(chrome://userchrome/content/assets/img/chrome-68/titlebar/windows/restore.svg) !important;
		}
		&:not([sizemode="maximized"]):not([sizemode="fullscreen"]) {
			.titlebar-restore {
				display: none !important;
			}
		}
		.titlebar-max,
		.titlebar-restore {
			order: 1 !important;
		}

		//Minimise button
		.titlebar-min {
			list-style-image: url(chrome://userchrome/content/assets/img/chrome-68/titlebar/windows/minimise.svg) !important;
			order: 0 !important;
		}
	}

	// Add spacing between caption buttons and tabs.
	&[sizemode="maximized"] .titlebar-spacer[type="post-tabs"] {
		margin-inline-end: 16px !important;
	}
	&:not([sizemode="maximized"]) .titlebar-spacer[type="post-tabs"] {
		margin-inline-end: 5px !important;
	}
}