<?php
/**
 * Dynamic CSS for the frontend.
 *
 * @package Blocks
 */

defined( 'WPINC' ) || exit;

/**
 * Helper function.
 * Merge and combine the CSS elements.
 *
 * @param  string|array $elements An array of our elements.
 *                                If we use a string then it is directly returned.
 * @return string
 */
function blocks_implode( $elements = array() ) {

	if ( ! is_array( $elements ) ) {
		return $elements;
	}

	// Make sure our values are unique.
	$elements = array_unique( $elements );

	// Sort elements alphabetically.
	// This way all duplicate items will be merged in the final CSS array.
	sort( $elements );

	// Implode items and return the value.
	return implode( ',', $elements );

}

/**
 * Maps elements from dynamic css to the selector.
 *
 * @param  array  $elements The elements.
 * @param  string $selector The selector.
 * @return array
 */
function blocks_map_selector( $elements, $selector ) {
	$array = array();

	foreach ( $elements as $element ) {
		$array[] = $element . $selector;
	}

	return $array;
}

/**
 * Map CSS selectors from values.
 *
 * @param array $css    Array of dynamic CSS.
 * @param array $values Array of values.
 */
function blocks_map_css_selectors( &$css, $values ) {
	if ( isset( $values['css-selectors'] ) ) {
		$elements = $values['css-selectors'];
		unset( $values['css-selectors'] );

		$css[ $elements ] = $values;
	}
}

/**
 * Merge CSS values.
 *
 * @param array $css    Array of dynamic CSS.
 * @param array $values Array of values.
 */
function blocks_merge_value( &$css, $values ) {
	foreach ( $values as $id => $val ) {
		$css[ $id ] = $val;
	}
}

/**
 * Format of the $css array:
 * $css['media-query']['element']['property'] = value
 *
 * If no media query is required then set it to 'global'
 *
 * If we want to add multiple values for the same property then we have to make it an array like this:
 * $css[media-query][element]['property'][] = value1
 * $css[media-query][element]['property'][] = value2
 *
 * Multiple values defined as an array above will be parsed separately.
 */
function blocks_dynamic_css_array() {

	global $wp_version;

	$css       = array();
	$c_page_id = blocks()->get_page_id();

	// Site Background.
	$css['global']['html body'] = Blocks_Sanitize::background( blocks_get_settings( 'mts_background' ) );

	// Top bar Background.
	$css['global']['#primary-nav, #primary-nav .sub-menu, .header-layout2 .header-search .searchbox-open #s'] = Blocks_Sanitize::background( blocks_get_settings( 'mts_top_bar_background' ) );

	// Header Background.
	$css['global']['#header, .header-default .header-search .searchbox-open #s'] = Blocks_Sanitize::background( blocks_get_settings( 'mts_main_navigation_background' ) );

	// Content Font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'content_font' ) ) );
	// Logo Font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'blocks_logo' ) ) );
	// Primary Navigation font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'primary_navigation_font' ) ) );
	// Secondary Navigation font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'secondary_navigation_font' ) ) );

	// Homepage post title font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'home_title_font' ) ) );
	// Breadcrumbs font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'breadcrumb_font' ) ) );
	// Single post title font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_title_font' ) ) );
	// Single Page titles font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_page_titles_font' ) ) );
	// Related Posts Section title font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'related_post_title_font' ) ) );
	// Single subscribe box.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_subscribe_title_font' ) ) );
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_subscribe_text_font' ) ) );
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_subscribe_input_font' ) ) );
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_subscribe_submit_font' ) ) );
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_subscribe_small_text_font' ) ) );
	// Author Box.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_authorbox_author_name_font' ) ) );
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_authorbox_text_font' ) ) );
	// Sidebar widget title font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'sidebar_title_font' ) ) );
	// Sidebar widget font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'sidebar_url' ) ) );
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'sidebar_font' ) ) );
	// Footer widget title font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'top_footer_title_font' ) ) );
	// Footer link font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'top_footer_link_font' ) ) );
	// Footer widget font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'top_footer_font' ) ) );
	// Footer meta font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'top_footer_meta_font' ) ) );
	// Copyrights section font.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'copyrights_font' ) ) );
	// H1 title in the content.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'h1_headline' ) ) );
	// H2 title in the content.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'h2_headline' ) ) );
	// H3 title in the content.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'h3_headline' ) ) );
	// H4 title in the content.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'h4_headline' ) ) );
	// H5 title in the content.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'h5_headline' ) ) );
	// H6 title in the content.
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'h6_headline' ) ) );

	// Footer background.
	$css['global']['#site-footer'] = Blocks_Sanitize::background( blocks_get_settings( 'mts_footer_background' ) );
	// Copyrights background.
	$css['global']['.copyrights'] = Blocks_Sanitize::background( blocks_get_settings( 'mts_copyrights_background' ) );

	blocks_dynamic_css_skin( $css );
	blocks_sidebar_position( $css );
	blocks_header( $css );
	blocks_sidebar_styling( $css );
	blocks_post_layouts( $css );
	blocks_post_pagination( $css );
	blocks_footer( $css );
	blocks_copyrights( $css );
	blocks_single( $css );
	blocks_single_social_buttons( $css );
	blocks_misc_css( $css );

	return apply_filters( 'blocks_dynamic_css_array', $css );
}

/**
 * Skin CSS
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_dynamic_css_skin( &$css ) {

	// Theme Color.
	$blocks_color_scheme = Blocks_Sanitize::color( blocks_get_settings( 'mts_color_scheme' ) );
	$light_border_color  = blocks_luminance( blocks_get_settings( 'mts_color_scheme' ), 0.6 );

	// Text Color.
	$elements = array(
		'a',
		'cite',
		'body a:hover',
		'.breadcrumb a',
		'.reply a:hover',
		'.reply:hover i',
		'.latestPost .title a:hover',
		'.related-posts .title a:hover',
		'.layout-default .latestPost .title a:hover',
		'.layout-1 .latestPost .title a:hover',
		'.layout-2 .latestPost .title a:hover',
		'#secondary-navigation .navigation ul li a:hover',
		'#primary-navigation a:hover',
		'#secondary-navigation .navigation ul .current-menu-item a',
		'.woocommerce ul.products li.product .price',
		'.product_list_widget .amount',
		'.woocommerce div.product p.price, .woocommerce div.product span.price',
		'.shareit-circular.standard a:hover',
		'.postauthor h5',
		'.textwidget a',
		'#wp-calendar td#today',
		'.pnavigation2 a',
		'.sidebar.c-4-12 a:hover',
		'footer .widget li a:hover',
		'.sidebar.c-4-12 a:hover',
		'.title a:hover',
		'.post-info a:hover',
		'#tabber .inside li a:hover',
		'.related-posts .title a:hover',
		'.layout-subscribe .widget #wp-subscribe .title span',
		'.footer-nav li a:hover',
		'.f-widget .widget .wp-subscribe-wrap input.submit',
		'blockquote:after',
		'article ul li::before',
		'.post-info > span::before',
		'#site-header .header-search .searchbox-open .searchbox-icon',
		'#commentform input#submit',
		'#mtscontact_submit',
		'.widget .wpt_widget_content #tags-tab-content ul li a'
	);

	$css['global'][ blocks_implode( $elements ) ]['color'] = $blocks_color_scheme;
	$css['global']['.sidebar .widget a:hover']['color']    = $blocks_color_scheme;
	$css['global']['.tagcloud a']['color']                 = $blocks_color_scheme . ' !important ';

	// Border Color.
	$elements = array(
		'.shareit.shareit-circular.circular .social-icon',
		'.aboutme-widget .aboutme-social a:hover',
	);
	$css['global'][ blocks_implode( $elements ) ]['color'] = $blocks_color_scheme . '!important';

	// Background Color.
	$elements = array(
		'.error404 .sbutton',
		'.search .sbutton',
		'.pace .pace-progress',
		'#mobile-menu-wrapper ul li a:hover',
		'#commentform input#submit:hover',
		'#mtscontact_submit:hover',
		'.navigation #wpmm-megamenu .wpmm-pagination a',
		'.wpmm-megamenu-showing.wpmm-light-scheme',
		'.mts-subscribe input[type="submit"]',
		'.widget_product_search button[type="submit"]',
		'#move-to-top:hover',
		'#tabber ul.tabs li a.selected',
		'.tagcloud a:hover',
		'.navigation ul .sfHover a',
		'.widget-slider .slide-caption',
		'.owl-prev, .owl-next',
		'.owl-prev:hover, .owl-next:hover',
		'.widget .wp-subscribe-wrap h4.title span.decor:after',
		'.mobile-menu-active .navigation.mobile-menu-wrapper',
		'.readMore a:hover',
		'.woocommerce a.button',
		'.woocommerce-page a.button',
		'.woocommerce button.button',
		'.woocommerce-page button.button',
		'.woocommerce input.button',
		'.woocommerce-page input.button',
		'.woocommerce #respond input#submit',
		'.woocommerce-page #respond input#submit',
		'.woocommerce #content input.button',
		'.woocommerce-page #content input.button',
		'.woocommerce .bypostauthor:after',
		'.woocommerce nav.woocommerce-pagination ul li span.current',
		'.woocommerce-page nav.woocommerce-pagination ul li span.current',
		'.woocommerce #content nav.woocommerce-pagination ul li span.current',
		'.woocommerce-page #content nav.woocommerce-pagination ul li span.current',
		'.woocommerce nav.woocommerce-pagination ul li a:hover',
		'.woocommerce-page nav.woocommerce-pagination ul li a:hover',
		'.woocommerce #content nav.woocommerce-pagination ul li a:hover',
		'.woocommerce-page #content nav.woocommerce-pagination ul li a:hover',
		'.woocommerce nav.woocommerce-pagination ul li a:focus',
		'.woocommerce-page nav.woocommerce-pagination ul li a:focus',
		'.woocommerce #content nav.woocommerce-pagination ul li a:focus',
		'.woocommerce-page #content nav.woocommerce-pagination ul li a:focus',
		'.woocommerce a.button',
		'.woocommerce-page a.button',
		'.woocommerce button.button',
		'.woocommerce-page button.button',
		'.woocommerce input.button',
		'.woocommerce-page input.button',
		'.woocommerce #respond input#submit',
		'.woocommerce-page #respond input#submit',
		'.woocommerce #content input.button',
		'.woocommerce-page #content input.button',
		'.woocommerce #respond input#submit.alt.disabled',
		'.woocommerce #respond input#submit.alt.disabled:hover',
		'.woocommerce #respond input#submit.alt:disabled',
		'.woocommerce #respond input#submit.alt:disabled:hover',
		'.woocommerce #respond input#submit.alt:disabled[disabled]',
		'.woocommerce #respond input#submit.alt:disabled[disabled]:hover',
		'.woocommerce a.button.alt.disabled, .woocommerce a.button.alt.disabled:hover',
		'.woocommerce a.button.alt:disabled',
		'.woocommerce a.button.alt:disabled:hover',
		'.woocommerce a.button.alt:disabled[disabled]',
		'.woocommerce a.button.alt:disabled[disabled]:hover',
		'.woocommerce button.button.alt.disabled',
		'.woocommerce button.button.alt.disabled:hover',
		'.woocommerce button.button.alt:disabled',
		'.woocommerce button.button.alt:disabled:hover',
		'.woocommerce button.button.alt:disabled[disabled]',
		'.woocommerce button.button.alt:disabled[disabled]:hover',
		'.woocommerce input.button.alt.disabled',
		'.woocommerce input.button.alt.disabled:hover',
		'.woocommerce input.button.alt:disabled',
		'.woocommerce input.button.alt:disabled:hover',
		'.woocommerce input.button.alt:disabled[disabled]',
		'.woocommerce input.button.alt:disabled[disabled]:hover',
		'#wpmm-megamenu .review-total-only',
		'#searchsubmit',
		'.widget .wpt_widget_content #tags-tab-content ul li a:hover',
		'#add_payment_method .wc-proceed-to-checkout a.checkout-button',
		'.woocommerce-cart .wc-proceed-to-checkout a.checkout-button',
		'.woocommerce-checkout .wc-proceed-to-checkout a.checkout-button',
		'.woocommerce #respond input#submit.alt',
		'.woocommerce a.button.alt',
		'.woocommerce button.button.alt',
		'.woocommerce input.button.alt',
		'.woocommerce-account .woocommerce-MyAccount-navigation li.is-active',
		'.widget #wp-subscribe form::after',
		'.button',
		'.instagram-button a',
		'.woocommerce .woocommerce-widget-layered-nav-dropdown__submit',
		'.layout-subscribe form:after',
		'.f-widget .widget #wp-subscribe form:after',
		'.widget .sbutton',
		'.owl-prev:hover, .owl-next:hover',
		'.woocommerce .widget_price_filter .ui-slider .ui-slider-handle',
		'.woocommerce .widget_price_filter .ui-slider .ui-slider-range',
		'.latestPost-review-wrapper',
		'.latestPost .review-type-circle.latestPost-review-wrapper',
		'.woocommerce span.onsale',
		'.post-info > span::after',
		'.widget .widget_wp_review_tab .review-total-only.large-thumb',
		'.widget .review-total-only.large-thumb',
		'.widget #wp-subscribe .title:after',
		'.widget #wp-subscribe input.submit',
		'#sidebar .widget .wpt_widget_content .tab_title.selected a',
		'#sidebar .widget .wp_review_tab_widget_content .tab_title.selected a',
		'footer .wpt_widget_content .tab_title.selected a',
		'footer .wp_review_tab_widget_content .tab_title.selected a',
		'.tags a:hover',
		'#load-posts a:hover',
		'.viewMore a:hover',
	);

	$css['global'][ blocks_implode( $elements ) ]['background-color'] = $blocks_color_scheme;
	$css['global']['.readMore a:hover']['background-color']           = $blocks_color_scheme . ' !important ';

	// Border Color.
	$elements = array(
		'.flex-control-thumbs .flex-active',
		'.tags a:hover',
		'.tagcloud a:hover',
		'.widget .wpt_widget_content #tags-tab-content ul li a:hover',
	);

	$css['global'][ blocks_implode( $elements ) ]['border-color'] = $blocks_color_scheme;

	// Border Color.
	$light_elements = array(
		'.single-like-button a',
		'.shareit-circular.circular .social-icon',
	);

	$css['global'][ blocks_implode( $light_elements ) ]['border-color'] = $light_border_color . '!important';

}

/**
 * Sidebar Position
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_sidebar_position( &$css ) {

	// Sidebar position.
	$sidebar_position = blocks_get_settings( 'mts_layout' );

	$sidebar_metabox_location = '';
	if ( is_page() || is_single() ) {
		$sidebar_metabox_location = get_post_meta( get_the_ID(), '_mts_sidebar_location', true );
	}

	if ( 'right' !== $sidebar_metabox_location && ( 'sclayout' === $sidebar_position || 'left' === $sidebar_metabox_location ) ) {
		$css['global']['.article']['float']                = 'right';
		$css['global']['.sidebar.c-4-12']['float']         = 'left';
		$css['global']['.sidebar.c-4-12']['padding-right'] = 0;

		if ( null !== blocks_get_settings( 'mts_social_button_position' ) && 'floating' === blocks_get_settings( 'mts_social_button_position' ) ) {
			$css['global']['.shareit.floating']['margin']      = '0 760px 0';
			$css['global']['.shareit.floating']['border-left'] = '0';
		}
	}
}

/**
 * Header
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_header( &$css ) {

	// header class.
	$header_class = array(
		'#header',
	);
	blocks_merge_value( $css['global'][ blocks_implode( $header_class ) ], Blocks_Sanitize::margin( blocks_get_settings( 'mts_header_margin' ) ) );
	blocks_merge_value( $css['global'][ blocks_implode( $header_class ) ], Blocks_Sanitize::padding( blocks_get_settings( 'mts_header_padding' ) ) );
	// Header Border.
	$header_border = Blocks_Sanitize::border( blocks_get_settings( 'mts_header_border' ) );
	$css['global'][ blocks_implode( $header_class ) ][ $header_border ['direction'] ] = $header_border ['value'];

	$top_header_class = array(
		'div#primary-nav',
	);
	// Top Header Border.
	$header_border = Blocks_Sanitize::border( blocks_get_settings( 'mts_top_header_border' ) );
	$css['global'][ blocks_implode( $top_header_class ) ][ $header_border ['direction'] ] = $header_border ['value'];

	// Main Nav.
	$main_nav_classes = array(
		'#secondary-navigation .navigation ul ul a',
		'#secondary-navigation .navigation ul ul a:link',
		'#secondary-navigation .navigation ul ul a:visited',
	);
	$css['global'][ blocks_implode( $main_nav_classes ) ]['color']             = Blocks_Sanitize::color( blocks_get_settings( 'main_navigation_dropdown_color' ) );
	$css['global']['#secondary-navigation .navigation ul ul a:hover']['color'] = Blocks_Sanitize::color( blocks_get_settings( 'main_navigation_dropdown_hover_color' ) );

	// Social icons.
	$header_style = blocks_get_settings( 'mts_header_style' );
	if ( 'header-default' === $header_style ) {
		$prefix = 'mts';
	} else {
		$prefix = 'top';
	}
	if ( ! empty( blocks_get_settings( $prefix . '_header_social' ) ) && is_array( blocks_get_settings( $prefix . '_header_social' ) ) ) :
		$header_icons = blocks_get_settings( $prefix . '_header_social' );
		foreach ( $header_icons as $header_icon ) :
			// Header border.
			$header_border = Blocks_Sanitize::border( $header_icon[ $prefix . '_header_icon_border' ] );
			$css['global'][ '.header-social-icons a.header-' . $header_icon[ $prefix . '_header_icon' ] ][ $header_border ['direction'] ] = $header_border ['value'];

			$css['global'][ '.header-social-icons a.header-' . $header_icon[ $prefix . '_header_icon' ] ]['background-color']            = Blocks_Sanitize::color( $header_icon[ $prefix . '_header_icon_bgcolor' ] );
			$css['global'][ '.header-social-icons a.header-' . $header_icon[ $prefix . '_header_icon' ] . ':hover' ]['background-color'] = Blocks_Sanitize::color( $header_icon[ $prefix . '_header_icon_hover_bgcolor' ] );
			$css['global'][ '.header-social-icons a.header-' . $header_icon[ $prefix . '_header_icon' ] ]['color']                       = Blocks_Sanitize::color( $header_icon[ $prefix . '_header_icon_color' ] );
			$css['global'][ '.header-social-icons a.header-' . $header_icon[ $prefix . '_header_icon' ] . ':hover' ]['color']            = Blocks_Sanitize::color( $header_icon[ $prefix . '_header_icon_hover_color' ] );

			blocks_merge_value( $css['global'][ '.header-social-icons a.header-' . $header_icon[ $prefix . '_header_icon' ] ], Blocks_Sanitize::margin( $header_icon[ $prefix . '_header_icon_margin' ] ) );
			blocks_merge_value( $css['global'][ '.header-social-icons a.header-' . $header_icon[ $prefix . '_header_icon' ] ], Blocks_Sanitize::padding( $header_icon[ $prefix . '_header_icon_padding' ] ) );
			$css['global'][ '.header-social-icons a.header-' . $header_icon[ $prefix . '_header_icon' ] ]['border-radius'] = Blocks_Sanitize::size( $header_icon[ $prefix . '_header_icon_border_radius' ] . 'px' );
		endforeach;
	endif;

	// Header Ad.
	blocks_merge_value( $css['global']['.widget-header, .small-header .widget-header'], Blocks_Sanitize::margin( blocks_get_settings( 'mts_header_adcode_margin' ) ) );

	// Ad-Blocker.
	$css['global']['.navigation-banner']['background'] = Blocks_Sanitize::color( blocks_get_settings( 'navigation_ad_background' ) );
}

/**
 * Social Share Styling
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_single_social_buttons( &$css ) {

	$social_shadow = blocks_get_settings( 'social_styling_box_shadow' );

	// Social share.
	$css['global']['.shareit.floating'] = Blocks_Sanitize::background( blocks_get_settings( 'social_styling_background' ) );
	blocks_merge_value( $css['global']['.shareit.floating'], Blocks_Sanitize::margin( blocks_get_settings( 'social_styling_margin' ) ) );

	// Social share border.
	$social_border = Blocks_Sanitize::border( blocks_get_settings( 'social_styling_border' ) );
	$css['global']['.shareit.floating'][ $social_border ['direction'] ] = $social_border ['value'];

	if ( 0 === $social_shadow ) {
		$css['global']['.shareit.floating']['box-shadow'] = 'none';
	}
	$social_button_layout   = blocks_get_settings( 'social_button_layout' );
	$social_button_position = blocks_get_settings( 'social_floating_button_position' );
	if ( ! empty( $social_button_position ) && is_array( $social_button_position ) ) {
		foreach ( $social_button_position as $key => $position ) {
			$css['global'][ '.shareit.shareit-' . $social_button_layout . '.floating' ][ $key ] = $position;
		}
	}
}

/**
 * Sidebar styling
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_sidebar_styling( &$css ) {

	// Sidebar.
	blocks_merge_value( $css['global']['#sidebar .widget'], Blocks_Sanitize::background( blocks_get_settings( 'mts_sidebar_styling_background' ) ) );
	blocks_merge_value( $css['global']['#sidebar .widget'], Blocks_Sanitize::margin( blocks_get_settings( 'mts_sidebar_styling_margin' ) ) );
	blocks_merge_value( $css['global']['#sidebar .widget'], Blocks_Sanitize::padding( blocks_get_settings( 'mts_sidebar_styling_padding' ) ) );
	// Sidebar border.
	$sidebar_border = Blocks_Sanitize::border( blocks_get_settings( 'sidebar_styling_border' ) );
	$css['global']['#sidebar .widget'][ $sidebar_border['direction'] ] = $sidebar_border['value'];

	// Sidebar title.
	$css['global']['#sidebar .widget h3'] = Blocks_Sanitize::background( blocks_get_settings( 'mts_sidebar_title_styling_background' ) );
	blocks_merge_value( $css['global']['#sidebar .widget h3'], Blocks_Sanitize::padding( blocks_get_settings( 'mts_sidebar_title_styling_padding' ) ) );
	blocks_merge_value( $css['global']['#sidebar .widget h3'], Blocks_Sanitize::margin( blocks_get_settings( 'mts_sidebar_title_styling_margin' ) ) );
	// Sidebar Title border.
	$sidebar_title_border = Blocks_Sanitize::border( blocks_get_settings( 'widget_title_border' ) );
	$css['global']['#sidebar .widget h3'][ $sidebar_title_border['direction'] ] = $sidebar_title_border['value'];
}

/**
 * Layout CSS
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_post_layouts( &$css ) {

	$features = blocks_get_settings( 'mts_featured_categories' );
	foreach ( $features as $feature ) :

		if ( ! isset( $feature['unique_id'] ) ) {
			continue;
		}

		$category     = $feature['mts_featured_category'];
		$posts_layout = isset( $feature['mts_thumb_layout'] ) ? $feature['mts_thumb_layout'] : '';
		$unique_id    = $feature['unique_id'];

		if ( 'layout-default' === $posts_layout ) :
			$posts_layout = 'default';
		endif;

		// Container Class.
		if ( ! in_array( $posts_layout, array( 'default' ) ) ) :
			$container_class                                     = array(
				'.layout-' . $unique_id,
			);
			$css['global'][ blocks_implode( $container_class ) ] = array(
				'width'    => '100%',
				'float'    => 'none',
				'overflow' => 'visible',
				'position' => 'relative',
			);
		endif;

		// Post area.
		$cat_class = 'cat-latest';
		if ( 'latest' !== $category ) {
			$category  = get_term_by( 'slug', $category, 'category' );
			$cat_class = sanitize_key( $category->name );
		}

		$title_class = '.title-container.title-id-' . $unique_id . ' h3';

		$css['global'][ $title_class ] = Blocks_Sanitize::background( blocks_get_settings( 'mts_featured_category_title_background_' . $unique_id ) );
		blocks_merge_value( $css['global'][ $title_class ], Blocks_Sanitize::margin( blocks_get_settings( 'mts_featured_category_title_margin_' . $unique_id ) ) );
		blocks_merge_value( $css['global'][ $title_class ], Blocks_Sanitize::padding( blocks_get_settings( 'mts_featured_category_title_padding_' . $unique_id ) ) );
		// Section title border.
		$post_title_border = Blocks_Sanitize::border( blocks_get_settings( 'post_title_border_' . $unique_id ) );
		$css['global'][ $title_class ][ $post_title_border['direction'] ] = $post_title_border['value'];

		blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'mts_featured_category_title_font_' . $unique_id ) ) );

		if ( 'default' === $posts_layout ) {
			$post_class = '.layout-' . $unique_id;
		} else {
			$post_class = '.article.layout-' . $unique_id;
		}
		//$post_class = '.layout-' . $unique_id;

		if ( ! in_array( $posts_layout, array( 'layout-partners', 'layout-category', 'layout-subscribe', 'layout-ad' ) ) ) :
			// Post border.
			$post_border = Blocks_Sanitize::border( blocks_get_settings( 'post_border_' . $unique_id ) );
			$css['global'][ $post_class ][ $post_border['direction'] ] = $post_border['value'];
		endif;

		//blocks_merge_value( $css['global'][ $post_class ], Blocks_Sanitize::margin( blocks_get_settings( 'mts_featured_category_margin_' . $unique_id ) ) );
		//blocks_merge_value( $css['global'][ $post_class ], Blocks_Sanitize::padding( blocks_get_settings( 'mts_featured_category_padding_' . $unique_id ) ) );

		blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'readmore_font_' . $unique_id ) ) );
		blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'mts_featured_category_font_' . $unique_id ) ) );
		blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'mts_featured_category_excerpt_font_' . $unique_id ) ) );

		/**
		 * Meta info
		 */
		blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'mts_meta_info_font_' . $unique_id ) ) );
		blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'post_category_font_' . $unique_id ) ) );
		blocks_merge_value( $css['global'][ $post_class . ' .latestPost .post-info' ], Blocks_Sanitize::margin( blocks_get_settings( 'mts_meta_info_margin_' . $unique_id ) ) );

		//if ( 'layout-3' === $posts_layout ) :
		$css['global'][ $post_class ] = Blocks_Sanitize::background( blocks_get_settings( 'mts_featured_category_background_' . $unique_id ) );
		//endif;

		// Layout Partners, Layout Subscribe, Layout Category and Layout ad.
		if ( in_array( $posts_layout, array( 'default', 'layout-1', 'layout-2', 'layout-partners', 'layout-category', 'layout-subscribe', 'layout-ad' ) ) ) :
			if ( 'default' === $posts_layout ) {
				$class = array(
					'.layout-' . $unique_id,
				);
			} else {
				$class = array(
					'.article.layout-' . $unique_id,
				);
			}
			$css['global'][ blocks_implode( $class ) ] = Blocks_Sanitize::background( blocks_get_settings( 'mts_featured_category_background_' . $unique_id ) );
			blocks_merge_value( $css['global'][ blocks_implode( $class ) ], Blocks_Sanitize::margin( blocks_get_settings( 'mts_featured_category_margin_' . $unique_id ) ) );
			blocks_merge_value( $css['global'][ blocks_implode( $class ) ], Blocks_Sanitize::padding( blocks_get_settings( 'mts_featured_category_padding_' . $unique_id ) ) );

			// Post border.
			$post_border = Blocks_Sanitize::border( blocks_get_settings( 'post_border_' . $unique_id ) );
			$css['global'][ blocks_implode( $class ) ][ $post_border['direction'] ] = $post_border['value'];
		endif;

		if ( in_array( $posts_layout, array( 'default', 'layout-1', 'layout-2' ) ) ) :
			$css['global'][ '.layout-' . $unique_id . ' .readMore a'  ]['background-color'] = Blocks_Sanitize::color( blocks_get_settings( 'readmore_bg_' . $unique_id ) );
		endif;

		// Layout Category.
		if ( 'layout-category' === $posts_layout && ! empty( blocks_get_settings( 'cat_section_' . $unique_id ) ) && is_array( blocks_get_settings( 'cat_section_' . $unique_id ) ) ) :
			$categories = blocks_get_settings( 'cat_section_' . $unique_id );
			foreach ( $categories as $category ) :
				$css['global'][ '.article.layout-' . $unique_id . ' .layout-category .overlay' ]['background']       = Blocks_Sanitize::color( $category['cat_section_background'] );
				$css['global'][ '.article.layout-' . $unique_id . ' .layout-category .overlay:hover' ]['background'] = Blocks_Sanitize::color( $category['cat_section_hover_background'] );
			endforeach;
		endif;

		// Layout Partners.
		if ( 'layout-partners' === $posts_layout ) :
			blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'partners_title_font_' . $unique_id ) ) );
		endif;

		// Layout Subscribe.
		if ( 'layout-subscribe' === $posts_layout ) :
			$input_class                                 = '.article.layout-' . $unique_id . ' .layout-subscribe #wp-subscribe input.email-field, .article.layout-' . $unique_id . ' .layout-subscribe #wp-subscribe input.name-field';
			$css['global'][ $input_class ]['background'] = Blocks_Sanitize::color( blocks_get_settings( 'subscribe_input_background_' . $unique_id ) );
			blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'subscribe_title_font_' . $unique_id ) ) );
			blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'subscribe_input_font_' . $unique_id ) ) );
			blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'subscribe_text_font_' . $unique_id ) ) );
			blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'subscribe_small_text_font_' . $unique_id ) ) );

			// Alignment.
			$alignment   = blocks_get_settings( 'subscribe_alignment_' . $unique_id );
			$align_class = array(
				'.article.layout-' . $unique_id . ' .wp-subscribe-wrap',
				'.article.layout-' . $unique_id . ' #wp-subscribe p.text',
			);
			if ( 'left' === $alignment ) :
				$css['global'][ blocks_implode( $align_class ) ]['text-align'] = 'left';
			elseif ( 'right' === $alignment ) :
				$css['global'][ blocks_implode( $align_class ) ]['text-align'] = 'right';
			endif;

			// Input fields size.
			$input_size  = blocks_get_settings( 'subscribe_input_size_' . $unique_id );
			$input_class = array(
				'.layout-' . $unique_id . ' .layout-subscribe #wp-subscribe input.email-field',
				'.layout-' . $unique_id . ' .layout-subscribe #wp-subscribe input.name-field',
				'.layout-' . $unique_id . ' .layout-subscribe .widget #wp-subscribe input.submit',
			);
			if ( 'large' === $input_size ) :
				$css['global'][ blocks_implode( $input_class ) ]['width'] = '100%';
			endif;

			// Subscribe Social icons
			if ( 1 === blocks_get_settings( 'subscribe_social_icons_' . $unique_id ) && ! empty( blocks_get_settings( 'subscribe_social_' . $unique_id ) ) && is_array( blocks_get_settings( 'subscribe_social_' . $unique_id ) ) ) :
				$subscribe_icons = blocks_get_settings( 'subscribe_social_' . $unique_id );
				foreach ( $subscribe_icons as $subscribe_icon ) :
					// $footer_icons[] = $subscribe_icon['subscribe_social_icon'];
					$css['global'][ '.subscribe-social-icons a.subscribe-' . $subscribe_icon['subscribe_social_icon'] ]['color'] = Blocks_Sanitize::color( $subscribe_icon['subscribe_social_color'] );

					$css['global'][ '.subscribe-social-icons a.subscribe-' . $subscribe_icon['subscribe_social_icon'] . ':hover' ]['color'] = Blocks_Sanitize::color( $subscribe_icon['subscribe_social_hover_color'] );

					blocks_merge_value( $css['global'][ '.subscribe-social-icons a.subscribe-' . $subscribe_icon['subscribe_social_icon'] ], Blocks_Sanitize::margin( $subscribe_icon['subscribe_social_margin'] ) );

					blocks_merge_value( $css['global'][ '.subscribe-social-icons a.subscribe-' . $subscribe_icon['subscribe_social_icon'] ], Blocks_Sanitize::padding( $subscribe_icon['subscribe_social_padding'] ) );
				endforeach;
			endif;

		endif;

	endforeach;
}

/**
 * Pagination
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_post_pagination( &$css ) {

	// Pagination Active class.
	$pagination_class_active = array(
		'.pace .pace-progress',
		'.page-numbers.current',
		'.pagination a:hover',
		'#mobile-menu-wrapper ul li a:hover',
		'#load-posts a:hover',
	);
	$pagination_class        = array(
		'.pagination a',
		'.pagination a:hover',
		'#load-posts a',
		'.single .pagination > .current > .currenttext',
		'.pagination .page-numbers.dots',
		'.page-numbers.current',
	);
	if ( '2' !== blocks_get_settings( 'mts_pagenavigation_type' ) ) {
		$css['global'][ blocks_implode( $pagination_class ) ]['background-color']        = Blocks_Sanitize::color( blocks_get_settings( 'mts_pagenavigation_bgcolor' ) );
		$css['global'][ blocks_implode( $pagination_class_active ) ]['background-color'] = Blocks_Sanitize::color( blocks_get_settings( 'mts_pagenavigation_hover_bgcolor' ) );
		$css['global'][ blocks_implode( $pagination_class ) ]['color']                   = Blocks_Sanitize::color( blocks_get_settings( 'mts_pagenavigation_color' ) );
		$css['global'][ blocks_implode( $pagination_class_active ) ]['color']            = Blocks_Sanitize::color( blocks_get_settings( 'mts_pagenavigation_hover_color' ) );
		blocks_merge_value( $css['global'][ blocks_implode( array_merge( $pagination_class_active, $pagination_class ) ) ], Blocks_Sanitize::margin( blocks_get_settings( 'mts_pagenavigation_margin' ) ) );
		blocks_merge_value( $css['global'][ blocks_implode( array_merge( $pagination_class_active, $pagination_class ) ) ], Blocks_Sanitize::padding( blocks_get_settings( 'mts_pagenavigation_padding' ) ) );
		// Pagination border.
		$pagination_border = Blocks_Sanitize::border( blocks_get_settings( 'pagenavigation_border' ) );
		$css['global'][ blocks_implode( $pagination_class ) ][ $pagination_border ['direction'] ] = $pagination_border ['value'];
	} else {
		$css['global'][ blocks_implode( $pagination_class ) ]['background-color']        = Blocks_Sanitize::color( blocks_get_settings( 'load_more_bgcolor' ) );
		$css['global'][ blocks_implode( $pagination_class_active ) ]['background-color'] = Blocks_Sanitize::color( blocks_get_settings( 'load_more_hover_bgcolor' ) );
		$css['global'][ blocks_implode( $pagination_class ) ]['color']                   = Blocks_Sanitize::color( blocks_get_settings( 'load_more_color' ) );
		$css['global'][ blocks_implode( $pagination_class_active ) ]['color']            = Blocks_Sanitize::color( blocks_get_settings( 'load_more_hover_color' ) );
		blocks_merge_value( $css['global'][ blocks_implode( array_merge( $pagination_class_active, $pagination_class ) ) ], Blocks_Sanitize::padding( blocks_get_settings( 'load_more_padding' ) ) );
		blocks_merge_value( $css['global'][ blocks_implode( array_merge( $pagination_class_active, $pagination_class ) ) ], Blocks_Sanitize::margin( blocks_get_settings( 'load_more_margin' ) ) );
		$css['global'][ blocks_implode( $pagination_class ) ]['border-radius']        = Blocks_Sanitize::size( blocks_get_settings( 'mts_pagenavigation_border_radius' ) . 'px' );
		$css['global'][ blocks_implode( $pagination_class_active ) ]['border-radius'] = Blocks_Sanitize::size( blocks_get_settings( 'mts_pagenavigation_border_radius' ) . 'px' );
		// Load More border.
		$load_more_border = Blocks_Sanitize::border( blocks_get_settings( 'load_more_border' ) );
		$css['global'][ blocks_implode( $pagination_class ) ][ $load_more_border ['direction'] ] = $load_more_border ['value'];
	}

	// Load more Alignment.
	$load_more_align = blocks_get_settings( 'load_more_alignment' );
	if ( 'left' === $load_more_align ) :
		$css['global']['#load-posts']['text-align'] = 'left';
	elseif ( 'right' === $load_more_align ) :
		$css['global']['#load-posts']['text-align'] = 'right';
	elseif ( 'full' === $load_more_align ) :
		$css['global']['#load-posts a']['width'] = '100%';
	endif;
}

/**
 * Single
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_single( &$css ) {

	// Single, Page, Archive, Search, Category and 404 Page Background.
	$page_classes = array(
		'.single .article',
		'.page .article',
		'.error404 .article',
	);

	$css['global'][ blocks_implode( $page_classes ) ] = Blocks_Sanitize::background( blocks_get_settings( 'single_background' ) );

	// Margin, Padding, Border and Box Shadow.
	blocks_merge_value( $css['global'][ blocks_implode( $page_classes ) ], Blocks_Sanitize::margin( blocks_get_settings( 'mts_single_styling_margin' ) ) );
	blocks_merge_value( $css['global'][ blocks_implode( $page_classes ) ], Blocks_Sanitize::padding( blocks_get_settings( 'mts_single_styling_padding' ) ) );
	// Single border.
	$single_border = Blocks_Sanitize::border( blocks_get_settings( 'single_styling_border' ) );
	$css['global'][ blocks_implode( $page_classes ) ][ $single_border ['direction'] ] = $single_border ['value'];

	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'mts_single_meta_info_font' ) ) );
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'single_category_post_font' ) ) );

	// Related Posts.
	if ( 'default' !== blocks_get_settings( 'related_posts_layouts' ) ) :
		$css['global']['.related-posts'] = Blocks_Sanitize::background( blocks_get_settings( 'related_posts_background' ) );
	endif;
	// Default.
	if ( 'default' === blocks_get_settings( 'related_posts_layouts' ) ) :
		$css['global']['.related-posts:after'] = Blocks_Sanitize::background( blocks_get_settings( 'related_posts_background' ) );
	endif;
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'related_posts_font' ) ) );
	blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'related_posts_meta_font' ) ) );
	blocks_merge_value( $css['global']['.related-posts'], Blocks_Sanitize::margin( blocks_get_settings( 'related_posts_margin' ) ) );
	blocks_merge_value( $css['global']['.related-posts'], Blocks_Sanitize::padding( blocks_get_settings( 'related_posts_padding' ) ) );
	if ( 'default' === blocks_get_settings( 'related_posts_layouts' ) ) :
		blocks_map_css_selectors( $css['global'], Blocks_Sanitize::typography( blocks_get_settings( 'related_posts_excerpt_font' ) ) );
	endif;

	// Related Posts articles.
	$css['global']['.related-posts article'] = Blocks_Sanitize::background( blocks_get_settings( 'related_article_background' ) );
	blocks_merge_value( $css['global']['.related-posts article'], Blocks_Sanitize::padding( blocks_get_settings( 'related_article_padding' ) ) );
	blocks_merge_value( $css['global']['.related-posts article header'], Blocks_Sanitize::padding( blocks_get_settings( 'related_article_text_padding' ) ) );

	// Post FullHeader.
	blocks_merge_value( $css['global']['.single-full-header'], Blocks_Sanitize::margin( blocks_get_settings( 'featured_image_margin' ) ) );

	// Post FullHeader Alignment.
	$text_align = blocks_get_settings( 'featured_text_alignment' );
	if ( 'center' === $text_align ) :
		$css['global']['.single-full-header .content']['text-align'] = 'center';
		if ( 1 === blocks_get_settings( 'mts_show_featured' ) ) :
			$css['global']['.single-full-header .single-title']['padding']     = '0 12%';
			$css['global']['.single-full-header .single-title']['box-sizing']  = 'border-box';
			$css['global']['.single-full-header .post-info > span']['float']   = 'none';
			$css['global']['.single-full-header .post-info > span']['clear']   = 'both';
			$css['global']['.single-full-header .post-info > span']['display'] = 'inline-block';
			$css['global']['.single-full-header .post-info > span']['margin']  = '5px 5px 5px 0';
		endif;
	elseif ( 'right' === $text_align ) :
		$css['global']['.single-full-header .content']['text-align'] = 'right';
	endif;
	if ( 0 === blocks_get_settings( 'mts_show_featured' ) && 'full' === blocks_get_settings( 'featured_image_size' ) ) {
		$css['global']['.single-full-header .content']['position'] = 'static';
	}

	if ( 1 !== blocks_get_settings( 'mts_show_featured' ) && 'full' === blocks_get_settings( 'featured_image_size' ) ) {
		$css['global']['.single-full-header .content .full-header-wrapper']['width'] = '100%';
	}

	// Meta info Background.
	$css['global']['.full-header-wrapper .post-info']['background-color'] = Blocks_Sanitize::color( blocks_get_settings( 'single_meta_info_background' ) );
	$css['global']['body .thesinglecategory a']['background-color']            = Blocks_Sanitize::color( blocks_get_settings( 'single_category_post_background' ) );

	// Subscribe Box.
	$css['global']['.single-subscribe .widget #wp-subscribe'] = Blocks_Sanitize::background( blocks_get_settings( 'single_subscribe_background' ) );
	blocks_merge_value( $css['global']['.single-subscribe .widget #wp-subscribe'], Blocks_Sanitize::margin( blocks_get_settings( 'single_subscribe_margin' ) ) );
	blocks_merge_value( $css['global']['.single-subscribe .widget #wp-subscribe'], Blocks_Sanitize::padding( blocks_get_settings( 'single_subscribe_padding' ) ) );
	$css['global']['.single-subscribe .widget #wp-subscribe']['border-radius'] = Blocks_Sanitize::size( blocks_get_settings( 'single_subscribe_border_radius' ) . 'px' );

	// Subscribe border.
	$subscribe_box = Blocks_Sanitize::border( blocks_get_settings( 'single_subscribe_border' ) );
	$css['global']['.single-subscribe .widget #wp-subscribe'][ $subscribe_box ['direction'] ] = $subscribe_box ['value'];

	// Subscribe Box Input fields.
	$subscribe_input_class = array(
		'.single-subscribe #wp-subscribe input.email-field',
		'.single-subscribe #wp-subscribe input.name-field',
	);
	$css['global'][ blocks_implode( $subscribe_input_class ) ]['background-color']   = Blocks_Sanitize::color( blocks_get_settings( 'single_subscribe_input_background' ) );
	$css['global'][ blocks_implode( $subscribe_input_class ) ]['height']             = Blocks_Sanitize::size( blocks_get_settings( 'single_subscribe_input_height' ) . 'px' );
	$css['global']['.single-subscribe .widget #wp-subscribe input.submit']['height'] = Blocks_Sanitize::size( blocks_get_settings( 'single_subscribe_input_height' ) . 'px' );
	$css['global'][ blocks_implode( $subscribe_input_class ) ]['border-radius']      = Blocks_Sanitize::size( blocks_get_settings( 'single_subscribe_input_border_radius' ) . 'px' );
	// Subscribe Box Input border.
	$subscribe_box_input_border = Blocks_Sanitize::border( blocks_get_settings( 'single_subscribe_input_border' ) );
	$css['global'][ blocks_implode( $subscribe_input_class ) ][ $subscribe_box_input_border ['direction'] ] = $subscribe_box_input_border ['value'];

	// Subscribe Box Submit button.
	$css['global']['.single-subscribe .widget #wp-subscribe input.submit']['background']    = Blocks_Sanitize::color( blocks_get_settings( 'single_subscribe_submit_backgroud' ) );
	$css['global']['.single-subscribe .widget #wp-subscribe input.submit']['border-radius'] = Blocks_Sanitize::size( blocks_get_settings( 'single_subscribe_submit_border_radius' ) . 'px' );

	// Subscribe Box Submit border.
	$subscribe_box_submit_border = Blocks_Sanitize::border( blocks_get_settings( 'single_subscribe_submit_border' ) );
	$css['global']['.single-subscribe .widget #wp-subscribe input.submit'][ $subscribe_box_submit_border ['direction'] ] = $subscribe_box_submit_border ['value'];

	blocks_merge_value( $css['global']['.single-subscribe .widget #wp-subscribe input.submit'], Blocks_Sanitize::padding( blocks_get_settings( 'single_subscribe_submit_padding' ) ) );

	// Author Box.
	$css['global']['.postauthor'] = Blocks_Sanitize::background( blocks_get_settings( 'single_authorbox_background' ) );
	blocks_merge_value( $css['global']['.postauthor'], Blocks_Sanitize::margin( blocks_get_settings( 'single_authorbox_margin' ) ) );
	blocks_merge_value( $css['global']['.postauthor'], Blocks_Sanitize::padding( blocks_get_settings( 'single_authorbox_padding' ) ) );
	$single_authorbox_border = Blocks_Sanitize::border( blocks_get_settings( 'single_authorbox_border' ) );
	$css['global']['.postauthor'][ $single_authorbox_border ['direction'] ] = $single_authorbox_border ['value'];
	// Author image.
	blocks_merge_value( $css['global']['.postauthor img'], Blocks_Sanitize::margin( blocks_get_settings( 'single_author_image_margin' ) ) );
	$css['global']['.postauthor img']['border-radius'] = Blocks_Sanitize::size( blocks_get_settings( 'single_author_image_border_radius' ) . 'px' );
	// Author Social
	blocks_merge_value( $css['global']['.author-social a'], Blocks_Sanitize::margin( blocks_get_settings( 'author_social_margin' ) ) );
	blocks_merge_value( $css['global']['.author-social a'], Blocks_Sanitize::padding( blocks_get_settings( 'author_social_padding' ) ) );
	$css['global']['.author-social a'] ['background']       = Blocks_Sanitize::color( blocks_get_settings( 'author_social_background' ) );
	$css['global']['.author-social a:hover'] ['background'] = Blocks_Sanitize::color( blocks_get_settings( 'author_social_hover_background' ) );
	$css['global']['.author-social a']['color']             = Blocks_Sanitize::color( blocks_get_settings( 'author_social_color' ) );
	$css['global']['.author-social a:hover']['color']       = Blocks_Sanitize::color( blocks_get_settings( 'author_social_hover_color' ) );
	$css['global']['.author-social a']['border-radius']     = Blocks_Sanitize::size( blocks_get_settings( 'author_social_border_radius' ) . 'px' );

	// Single Page titles Styling.
	$titles_align_class                               = array(
		'.comment-title',
		'#respond',
		'.related-posts-title',
	);
	$titles_class                                     = array(
		'#respond h4',
		'.total-comments',
		'.related-posts h4',
	);
	$css['global'][ blocks_implode( $titles_class ) ] = Blocks_Sanitize::background( blocks_get_settings( 'single_title_background' ) );
	blocks_merge_value( $css['global'][ blocks_implode( $titles_class ) ], Blocks_Sanitize::padding( blocks_get_settings( 'single_title_padding' ) ) );
	// Single title border.
	$single_titles_border = Blocks_Sanitize::border( blocks_get_settings( 'single_title_border' ) );
	$css['global'][ blocks_implode( $titles_class ) ][ $single_titles_border ['direction'] ] = $single_titles_border ['value'];

}

/**
 * Copyrights
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_copyrights( &$css ) {

	// copyrights border.
	$copyrights_border = Blocks_Sanitize::border( blocks_get_settings( 'copyrights_border' ) );
	$css['global']['.copyrights'][ $copyrights_border ['direction'] ] = $copyrights_border ['value'];

}

/**
 * Footer
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_footer( &$css ) {

	// Footer.
	blocks_merge_value( $css['global']['#site-footer'], Blocks_Sanitize::margin( blocks_get_settings( 'mts_top_footer_margin' ) ) );
	blocks_merge_value( $css['global']['#site-footer'], Blocks_Sanitize::padding( blocks_get_settings( 'mts_top_footer_padding' ) ) );

	// Footer widgets.
	if ( 1 === blocks_get_settings( 'mts_top_footer' ) && 1 === blocks_get_settings( 'mts_top_footer_num' ) ) :
		$css['global']['.footer-widgets']['display']                = 'flex';
		$css['global']['.footer-widgets']['justify-content']        = 'center';
		$css['global']['.footer-widgets .f-widget']['width']        = 'auto';
		$css['global']['.footer-widgets .f-widget']['text-align']   = 'center';
		$css['global']['.footer-widgets .f-widget']['margin-right'] = '0px';
	endif;

	// footer Nav position.
	$footer_sections_position = blocks_get_settings( 'footer_sections_position' );
	if ( 1 === blocks_get_settings( 'footer_brands_section' ) ) :
		if ( 'left' === $footer_sections_position || 'right' === $footer_sections_position ) :
			$css['global']['#site-footer .container']['display']   = 'flex';
			$css['global']['#site-footer .container']['flex-flow'] = 'row wrap';
			$css['global']['.footer-sections']['flex-basis']       = 'calc(25% - 20px )';
			$css['global']['.footer-sections']['padding-right']    = '20px';
			$css['global']['.footer-widgets']['flex-basis']        = '75%';
			$css['global']['.brands-container']['display']         = 'block';
			$css['global']['.brands-items li']['max-width']        = '100%';
			$css['global']['.brands-items li']['flex-basis']       = '60%';
		endif;
		if ( 'right' === $footer_sections_position ) :
			$css['global']['#site-footer .container']['flex-direction'] = 'row-reverse';
			$css['global']['.footer-sections']['padding-right']         = '0';
			$css['global']['.footer-sections']['padding-left']          = '20px';
			$css['global']['.brands-container']['text-align']           = 'right';
			$css['global']['.brands-items']['justify-content']          = 'flex-end';
		endif;
	endif;

	// Footer Brands Sections.
	$brands_border = Blocks_Sanitize::border( blocks_get_settings( 'brands_border' ) );
	$css['global']['.brands-container'][ $brands_border ['direction'] ] = $brands_border ['value'];

	// footer brands alignment.
	$footer_brands_align = blocks_get_settings( 'footer_brands_alignment' );
	if ( 'center' === $footer_brands_align ) :
		$css['global']['.brands-container']['justify-content'] = 'center';
	elseif ( 'right' === $footer_brands_align ) :
		$css['global']['.brands-container']['justify-content'] = 'flex-end';
	endif;

	// brand container.
	blocks_merge_value( $css['global']['.brands-container'], Blocks_Sanitize::margin( blocks_get_settings( 'brands_margin' ) ) );
	blocks_merge_value( $css['global']['.brands-container'], Blocks_Sanitize::padding( blocks_get_settings( 'brands_padding' ) ) );

}

/**
 * Misc
 *
 * @param array $css Array of dynamic CSS.
 */
function blocks_misc_css( &$css ) {

	// Show Logo.
	$show_logo = blocks_get_settings( 'mts_header_section2' );

	if ( 0 === $show_logo ) {
		$css['global']['.logo-wrap']['display'] = 'none';
	}

	// Back to top.
	// Border.
	$top_button_border = Blocks_Sanitize::border( blocks_get_settings( 'top_button_border' ) );
	$css['global']['#move-to-top'][ $top_button_border ['direction'] ] = $top_button_border ['value'];
	// Font-size, Padding and Position.
	$css['global']['#move-to-top .fa']['font-size'] = Blocks_Sanitize::size( blocks_get_settings( 'top_button_font_size' ) . 'px' );
	blocks_merge_value( $css['global']['#move-to-top'], Blocks_Sanitize::padding( blocks_get_settings( 'top_button_padding' ) ) );
	$top_button_position = blocks_get_settings( 'top_button_position' );
	foreach ( $top_button_position as $key => $position ) {
		$css['global']['#move-to-top'][ $key ] = $position;
	}
	// Border-radius.
	$css['global']['#move-to-top']['border-radius'] = Blocks_Sanitize::size( blocks_get_settings( 'top_button_border_radius' ) . 'px' );
	// Colors.
	$css['global']['#move-to-top']['color']            = Blocks_Sanitize::color( blocks_get_settings( 'top_button_color' ) );
	$css['global']['#move-to-top:hover']['color']      = Blocks_Sanitize::color( blocks_get_settings( 'top_button_color_hover' ) );
	$css['global']['#move-to-top']['background']       = Blocks_Sanitize::color( blocks_get_settings( 'top_button_background' ) );
	$css['global']['#move-to-top:hover']['background'] = Blocks_Sanitize::color( blocks_get_settings( 'top_button_background_hover' ) );
}
