<?php
/**
 * Dynamic style for theme
 *
 * Generates inline CSS that overrides CSS custom properties (design tokens)
 * with the user's chosen theme color from the Customizer.
 *
 * By updating --color-primary on :root we get all derived styles for free.
 *
 * @package Godhuli
 */
function godhuli_theme_dynamic_style() {

	$godhuli_style = '';

	/**********************/
	// Scheme Color
	/**********************/

	$godhuli_theme_color = sanitize_hex_color( get_theme_mod( 'godhuli_theme_color', '#79be49' ) );

	if ( ! $godhuli_theme_color ) {
		return $godhuli_style;
	}

	/*
	 * Strategy: update the CSS custom property on :root so that every
	 * rule already referencing var(--color-primary) picks up the new value
	 * automatically. The explicit per-property fallbacks below are kept for
	 * browsers that do not yet support CSS custom properties (< 1% as of 2025).
	 */

	$godhuli_style .= ":root {
	    --color-primary: {$godhuli_theme_color};
	    --color-primary-alpha: rgba(0,0,0,0.08); /* recalculated in JS if needed */
	}
	";

	// Explicit fallback overrides for older browsers that ignore :root variables.
	$godhuli_style .= "
	.entry-content a {
	    color: {$godhuli_theme_color};
	}
	.entry-content a:focus {
	    border: 1px dashed {$godhuli_theme_color};
	}
	a:hover,
	a:focus {
	    color: {$godhuli_theme_color};
	}
	.btn-outline-custom {
	    color: {$godhuli_theme_color};
	    border-color: {$godhuli_theme_color};
	}
	.btn-outline-custom.active,
	.btn-outline-custom:hover,
	.btn-outline-custom:active,
	.show>.btn-outline-custom.dropdown-toggle,
	.btn-outline-custom.focus,
	.btn-outline-custom:focus {
	    background-color: {$godhuli_theme_color};
	    border-color: {$godhuli_theme_color};
	}
	#topnav .has-submenu.active .submenu li.active > a {
	    color: {$godhuli_theme_color};
	}
	#topnav .has-submenu.active > a,
	#topnav .navigation-menu li.active > a {
	    color: {$godhuli_theme_color};
	}
	#topnav .has-submenu.active .menu-arrow {
	    border-color: {$godhuli_theme_color};
	}
	#topnav .navbar-toggle.open span:hover,
	#topnav .navbar-toggle.open span:focus {
	    background-color: {$godhuli_theme_color};
	}
	#topnav .navbar-toggle:hover,
	#topnav .navbar-toggle:focus,
	#topnav .navigation-menu > li > a:hover,
	#topnav .navigation-menu > li > a:focus {
	    color: {$godhuli_theme_color};
	}
	#topnav .navigation-menu > li > a:hover,
	#topnav .navigation-menu > li .submenu li a:hover,
	#topnav .navigation-menu > li.has-submenu.open > a,
	#topnav .navigation-menu > li > a:focus,
	#topnav .navigation-menu > li .submenu li a:focus {
	    color: {$godhuli_theme_color};
	}
	.badge-custom {
	    background-color: {$godhuli_theme_color};
	}
	.post-tags a:hover,
	.post-tags a:focus,
	.tagcloud > a:hover,
	.tagcloud > a:focus {
	    background: {$godhuli_theme_color};
	}
	.search-button:hover,
	.search-button:focus {
	    color: {$godhuli_theme_color};
	}
	.widget-title:after {
	    border-bottom: 1px solid {$godhuli_theme_color};
	}
	.widget {
	    border: 4px double {$godhuli_theme_color};
	}
	.widget ul li a:hover,
	.widget ol li a:hover,
	.widget ul li a:focus,
	.widget ol li a:focus {
	    color: {$godhuli_theme_color};
	}
	.widget select:focus {
	    border-color: {$godhuli_theme_color};
	}
	.tagcloud > a:hover,
	.tagcloud > a:focus {
	    background: {$godhuli_theme_color};
	}
	.searchform > .button:hover,
	.searchform > .button:focus {
	    background-color: {$godhuli_theme_color};
	}
	.media-heading a:hover,
	.media-heading a:focus {
	    color: {$godhuli_theme_color};
	}
	.blog_comments ul .trackback a,
	.blog_comments ul .pingback a {
	    color: {$godhuli_theme_color};
	}
	.comment-form input[type='submit']:hover,
	.comment-form input[type='submit']:focus {
	    background-color: {$godhuli_theme_color};
	    border-color: {$godhuli_theme_color};
	}
	.related-post .post-header a:hover,
	.related-post .post-header a:focus {
	    color: {$godhuli_theme_color};
	}
	.post-author-box .socials li a:hover,
	.post-author-box .socials li a:focus {
	    background-color: {$godhuli_theme_color};
	    border-color: {$godhuli_theme_color};
	}
	.quote-post .blockquote {
	    border: 2px solid {$godhuli_theme_color};
	}
	.quote-post .blockquote:before {
	    color: {$godhuli_theme_color};
	}
	.link-post {
	    background-color: {$godhuli_theme_color};
	}
	th {
	    background: {$godhuli_theme_color};
	}
	.page-numbers > .active > a,
	.page-numbers > .active > span,
	.page-numbers > li > a:hover,
	.page-numbers > li > a:focus,
	.page-numbers > li > span:hover,
	.page-numbers > li > span:focus,
	.pagination .nav-links .page-numbers:hover,
	.pagination .nav-links .page-numbers.current {
	    background-color: {$godhuli_theme_color};
	    border-color: {$godhuli_theme_color};
	}
	.socials li a:hover,
	.socials li a:focus {
	    background-color: {$godhuli_theme_color};
	}
	.flex-center a.reply-btn:hover,
	.flex-center a.reply-btn:focus {
	    color: {$godhuli_theme_color};
	}
	.wp-block-cover__video-background:focus,
	video:focus,
	iframe:focus,
	.wp-block-embed__wrapper:focus,
	.wp-block-audio audio:focus {
	    border: 2px solid {$godhuli_theme_color};
	}
	.blocks-gallery-item figure:focus,
	figure:focus {
	    border: 1px dashed {$godhuli_theme_color};
	}
	.screen-reader-text:focus {
	    background-color: {$godhuli_theme_color};
	}
	button:not(.toggle),
	.button,
	.faux-button,
	.wp-block-button__link,
	.wp-block-file .wp-block-file__button,
	input[type='button'],
	input[type='reset'],
	input[type='submit'],
	.bg-accent,
	.bg-accent-hover:hover,
	.bg-accent-hover:focus,
	:root .has-accent-background-color {
	    background-color: {$godhuli_theme_color};
	}
	.is-style-outline .wp-block-button__link {
	    border: 2px solid {$godhuli_theme_color};
	}
	.badge-custom:focus {
	    background-color: transparent;
	    color: #333 !important;
	    border: 1px dashed {$godhuli_theme_color};
	}
	.wp-block-button__link:focus,
	.wp-block-file .wp-block-file__button:focus {
	    border: 2px solid {$godhuli_theme_color} !important;
	}
	.is-style-outline .wp-block-button__link:focus {
	    background: {$godhuli_theme_color} !important;
	}
	.wp-block-gallery .blocks-gallery-item figure a:focus {
	    border: 2px solid {$godhuli_theme_color};
	}
	.mejs-container:focus {
	    border: 2px solid {$godhuli_theme_color};
	}
	.wp-block-search .wp-block-search__input:focus,
	input:focus,
	textarea:focus {
	    border: 1px dashed {$godhuli_theme_color};
	}
	.wp-block-search .wp-block-search__button:focus,
	[type='submit']:focus {
	    border: 1px dashed {$godhuli_theme_color} !important;
	}
	.js .nav-collapse .dropdown-toggle:hover,
	.js .nav-collapse .dropdown-toggle:focus,
	.js .nav-collapse .dropdown-toggle:active {
	    background-color: {$godhuli_theme_color};
	    border: 1px solid {$godhuli_theme_color};
	}
	.nav-collapse ul li.active > a {
	    color: {$godhuli_theme_color};
	}
	.wp-block-calendar table th {
	    background: {$godhuli_theme_color};
	}
	";

	return $godhuli_style;
}
