<?php
/**
 * Dynamic CSS
 */
function handmade_craft_dynamic_css() {
	$handmade_craft_primary_color = get_theme_mod( 'handmade_craft_primary_color', '#6B7050' );
	$handmade_craft_secondary_color = get_theme_mod( 'handmade_craft_secondary_color', '#657150' );

	$handmade_craft_site_title_font       = get_theme_mod( 'handmade_craft_site_title_font', 'Marcellus' );
	$handmade_craft_site_description_font = get_theme_mod( 'handmade_craft_site_description_font', 'Jost' );
	$handmade_craft_header_font           = get_theme_mod( 'handmade_craft_header_font', 'Marcellus' );
	$handmade_craft_content_font          = get_theme_mod( 'handmade_craft_content_font', 'Jost' );

	// Enqueue Google Fonts
	$handmade_craft_fonts_url = handmade_craft_get_fonts_url();
	if ( ! empty( $handmade_craft_fonts_url ) ) {
		wp_enqueue_style( 'handmade-craft-google-fonts', esc_url( $handmade_craft_fonts_url ), array(), null );
	}

	$handmade_craft_custom_css  = '';
	$handmade_craft_custom_css .= '
    /* Color */
    :root {
        --primary-color: ' . esc_attr( $handmade_craft_primary_color ) . ';
		--secondary-color: ' . esc_attr( $handmade_craft_secondary_color ) . ';
        --header-text-color: ' . esc_attr( '#' . get_header_textcolor() ) . ';
    }
    ';

	$handmade_craft_custom_css .= '
    /* Typography */
    :root {
        --font-heading: "' . esc_attr( $handmade_craft_header_font ) . '", serif;
        --font-main: -apple-system, BlinkMacSystemFont, "' . esc_attr( $handmade_craft_content_font ) . '", "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    }

    body,
	button, input, select, optgroup, textarea, p {
        font-family: "' . esc_attr( $handmade_craft_content_font ) . '", sans-serif;
	}

	.site-identity p.site-title, h1.site-title a, h1.site-title, p.site-title a, .site-branding h1.site-title a, header.site-header .header-main-wrapper:not(.transparent-header) .bottom-header-outer-wrapper .bottom-header-part .bottom-header-part-wrapper .site-branding .site-identity .site-title .banner-text {
        font-family: "' . esc_attr( $handmade_craft_site_title_font ) . '", serif;
	}
    
	p.site-description {
        font-family: "' . esc_attr( $handmade_craft_site_description_font ) . '", sans-serif !important;
	}
    ';

	wp_add_inline_style( 'handmade-craft-style', $handmade_craft_custom_css );
}
add_action( 'wp_enqueue_scripts', 'handmade_craft_dynamic_css', 99 );