/*
Theme Name: Trailhead Framework
Theme URI: https://oldoakcreative.co/trailhead
Author: Old Oak Creative
Author URI: https://oldoakcreative.co
Description: A premium multipurpose parent block theme by Old Oak Creative. Build fast, accessible, mobile-first WordPress sites with a child theme per client.
Requires at least: 6.7
Tested up to: 7.0
Requires PHP: 8.0
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: trailhead-framework
Tags: full-site-editing, block-patterns, custom-colors, custom-logo, wide-blocks, blog, business, portfolio, accessibility-ready
*/

/* ── Link refinement ──────────────────────────────────────────────────────── */
a {
	text-decoration-thickness: 1px !important;
	text-underline-offset: 0.15em;
}

/* ── Focus ring ───────────────────────────────────────────────────────────── */
:where(.wp-site-blocks *:focus) {
	outline-width: 2px;
	outline-style: solid;
	outline-color: var(--wp--preset--color--primary, currentColor);
	outline-offset: 2px;
}

/* ── Nav submenu focus fix ────────────────────────────────────────────────── */
.wp-block-navigation .wp-block-navigation-item .wp-block-navigation-item__content {
	outline-offset: 4px;
}

.wp-block-navigation .wp-block-navigation-item ul.wp-block-navigation__submenu-container .wp-block-navigation-item__content {
	outline-offset: 0;
}

/* ── Typography polish ────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6,
blockquote, caption, figcaption, p {
	text-wrap: pretty;
}

/* ── Skip to content ──────────────────────────────────────────────────────── */
.skip-to-content {
	position: absolute;
	top: -100%;
	left: 0;
	z-index: 9999;
	padding: 0.75rem 1.25rem;
	background-color: var(--wp--preset--color--primary, #000);
	color: var(--wp--preset--color--base, #fff);
	font-weight: 600;
	text-decoration: none;
}

.skip-to-content:focus {
	top: 0;
}

/* ── Pre / code overflow ──────────────────────────────────────────────────── */
:where(pre) {
	overflow-x: auto;
}

/* ── Sticky header z-index (position:sticky set via block attributes) ─────── */
.wp-block-group[style*="position:sticky"] {
	z-index: 100;
}

/* ── Read more ────────────────────────────────────────────────────────────── */
.more-link {
	display: block;
}

/* ── Responsive images ────────────────────────────────────────────────────── */
img {
	max-width: 100%;
	height: auto;
}

/* ── Touch target minimum ─────────────────────────────────────────────────── */
.wp-block-navigation-item__content,
.wp-block-button__link,
input[type="submit"],
button {
	min-height: 44px;
	min-width: 44px;
}

/* min-height only reserves the space. Navigation links have no padding of
   their own, so without centring the label sits at the top of the 44px box —
   which read as the menu being misaligned against the logo. Buttons and
   inputs already centre their text via padding. */
/* Core ships `.wp-block-navigation .wp-block-navigation-item__content
   { display: block }`, so this has to match that specificity to win. */
.wp-block-navigation .wp-block-navigation-item__content {
	display: flex;
	align-items: center;
}

/* ── Pattern image treatments ─────────────────────────────────────────────── */
/* core/image's save() output has changed shape across WP releases, so border,
   aspect-ratio and object-fit are applied here by class rather than as inline
   styles in the pattern. Inline styles on that block drift out of sync with
   what the editor regenerates and trip block validation. */
.trailhead-team-photo img {
	width: 100%;
	aspect-ratio: 1;
	object-fit: cover;
	border-radius: 0.5rem;
}

/* ── Transparent header ───────────────────────────────────────────────────── */
/*
 * Enabled per page via the Header panel in the editor sidebar, which sets the
 * .has-transparent-header body class. The header overlays the first section
 * and JS adds .is-scrolled once the page has scrolled by the header's height.
 *
 * Transparency requires .trailhead-header--managed, which header.js
 * adds at runtime — without JS the header stays solid and readable.
 *
 * Child themes restyle the transparent state through --trailhead-header-fg
 * rather than redeclaring these selectors.
 */
body.has-transparent-header .wp-site-blocks > header {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 50;
}

body.has-transparent-header.admin-bar .wp-site-blocks > header {
	top: var(--wp-admin--admin-bar--height, 32px);
}

/* Taking the header out of flow makes the next section the second child of
   .wp-site-blocks, so it picks up the root block-gap margin and leaves a strip
   of page background above the hero. Collapse it so the hero meets the top. */
body.has-transparent-header .wp-site-blocks > header + * {
	margin-block-start: 0;
}

/* Everything that changes between the two states fades rather than snapping.
   The colours live on the inner bars, not the <header>, so the transition has
   to be declared there too. */
body.has-transparent-header .wp-site-blocks > header,
body.has-transparent-header .wp-site-blocks > header .wp-block-group,
body.has-transparent-header .wp-site-blocks > header .wp-block-navigation,
body.has-transparent-header .wp-site-blocks > header .wp-block-site-title,
body.has-transparent-header .wp-site-blocks > header .wp-block-site-title a {
	transition:
		background-color var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1)),
		border-color var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1)),
		color var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1)),
		box-shadow var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1));
}

/* WordPress emits its preset colour utilities as
   `.has-white-background-color { background-color: … !important }` — not
   wrapped in :where() — so these overrides must also be !important. Extra
   specificity alone is not enough. The border is an inline style, same deal.

   A bar opts out with the "Keep Background" block style (Styles panel) or the
   `trailhead-header-opaque` class — typically a slim utility bar above the
   main navigation, which reads better as a constant anchor. */
body.has-transparent-header .wp-site-blocks > header.trailhead-header--managed:not(.is-scrolled) .wp-block-group.has-background:not(.trailhead-header-opaque):not(.is-style-keep-background) {
	background-color: transparent !important;
	border-bottom-color: transparent !important;
}

body.has-transparent-header .wp-site-blocks > header.trailhead-header--managed:not(.is-scrolled) {
	--trailhead-header-fg: #fff;
	box-shadow: none;
}

/* Lift the navigation and site title onto the hero. Deliberately narrow:
   anything already styled for a dark background (utility bars, buttons) keeps
   its own colour, and child themes extend this via --trailhead-header-fg.
   !important for the same reason as above: `.has-primary-color` is emitted
   with !important, so the navigation would otherwise stay dark on the hero. */
/* The `:not(:has(.is-menu-open))` guard sits on the header, so the whole
   override switches off while the mobile overlay is open. It paints its own
   background and sets its own text colour via overlayTextColor, and the links
   would otherwise render white on white. Guarding the nav instead does not
   work: core copies the `wp-block-navigation` class onto the overlay's inner
   <ul>, which has no `.is-menu-open` descendant of its own. */
body.has-transparent-header .wp-site-blocks > header.trailhead-header--managed:not(.is-scrolled):not(:has(.is-menu-open)) .wp-block-navigation,
body.has-transparent-header .wp-site-blocks > header.trailhead-header--managed:not(.is-scrolled):not(:has(.is-menu-open)) .wp-block-navigation a,
body.has-transparent-header .wp-site-blocks > header.trailhead-header--managed:not(.is-scrolled):not(:has(.is-menu-open)) .wp-block-site-title,
body.has-transparent-header .wp-site-blocks > header.trailhead-header--managed:not(.is-scrolled):not(:has(.is-menu-open)) .wp-block-site-title a {
	color: var(--trailhead-header-fg) !important;
}

body.has-transparent-header .wp-site-blocks > header.is-scrolled {
	box-shadow: 0 1px 12px rgba(0, 0, 0, 0.08);
}

/* ── Transparent header: optional light logo ──────────────────────────────── */
/*
 * Add an Image block with the class `trailhead-logo-light` to the header
 * template part and the theme will cross-fade to it while the header is
 * transparent. It is edited in the Site Editor like any other image — core has
 * only one site_logo, and the Site Editor's Identity screen is not extensible,
 * so a second logo cannot live there.
 *
 * The light logo is taken out of flow and laid over the site logo, so the site
 * logo alone defines the header's height. Both logos stay in the layout and
 * only their opacity changes, which keeps the header exactly the same height in
 * both states — no jump on scroll. Give the two images the same width.
 *
 * Until an image is chosen, core renders nothing for that block, so :has()
 * finds no <img> and the site logo is lightened with a filter instead.
 */
.wp-site-blocks > header .trailhead-logo-light {
	display: none;
	margin: 0;
}

/* The anchor is inline by default, which adds a descender gap below the image
   and makes the figure taller than the logo. */
.wp-site-blocks > header .trailhead-logo-light a {
	display: block;
	line-height: 0;
}

.wp-site-blocks > header .trailhead-logo-light img {
	display: block;
	width: var(--trailhead-logo-light-width, 140px);
	height: auto;
}

body.has-transparent-header .wp-site-blocks > header .wp-block-group:has(> .trailhead-logo-light) {
	position: relative;
}

body.has-transparent-header .wp-site-blocks > header .trailhead-logo-light {
	display: block;
	position: absolute;
	left: 0;
	top: 50%;
	transform: translateY(-50%);
	opacity: 0;
	visibility: hidden;
	transition:
		opacity var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1)),
		visibility 0s linear var(--trailhead-header-duration, 320ms);
}

body.has-transparent-header .wp-site-blocks > header.trailhead-header--managed:not(.is-scrolled) .trailhead-logo-light {
	opacity: 1;
	visibility: visible;
	transition:
		opacity var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1)),
		visibility 0s;
}

/* A real light logo exists, so fade the default one out rather than filtering
   it. It keeps its space in the layout, which is what holds the height steady. */
body.has-transparent-header .wp-site-blocks > header .wp-block-site-logo {
	transition:
		opacity var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1)),
		visibility 0s;
}

body.has-transparent-header .wp-site-blocks > header.trailhead-header--managed:not(.is-scrolled):has(.trailhead-logo-light img) .wp-block-site-logo {
	opacity: 0;
	visibility: hidden;
	transition:
		opacity var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1)),
		visibility 0s linear var(--trailhead-header-duration, 320ms);
}

/* No light logo yet — lighten the default one so it stays visible. */
body.has-transparent-header .wp-site-blocks > header.trailhead-header--managed:not(.is-scrolled):not(:has(.trailhead-logo-light img)) .wp-block-site-logo img {
	filter: brightness(0) invert(1);
	transition: filter var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1));
}

@media (prefers-reduced-motion: reduce) {
	body.has-transparent-header .wp-site-blocks > header,
	body.has-transparent-header .wp-site-blocks > header * {
		transition-duration: 1ms !important;
	}
}

/* ── Condensed sticky header ──────────────────────────────────────────────── */
/*
 * Once the page has scrolled past the header, the bar carrying the logo
 * tightens up: smaller logo, less vertical padding. Applies on every page, not
 * just transparent-header ones, so an ordinary sticky header condenses too.
 *
 * Only the background-painted bar containing the site logo is touched, so a
 * slim utility bar above it keeps its own proportions. `.has-background` also
 * excludes the inner layout row, which contains the logo too and would
 * otherwise gain padding it never had. The block's padding is an inline style,
 * hence !important.
 *
 * Child themes tune this with --trailhead-logo-width-condensed and
 * --trailhead-header-padding-condensed; setting them equal to the expanded
 * values effectively disables the condensing.
 */
.wp-site-blocks > header .wp-block-group.has-background:has(.wp-block-site-logo),
.wp-site-blocks > header .wp-block-site-logo img,
.wp-site-blocks > header .trailhead-logo-light img {
	transition:
		padding var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1)),
		width var(--trailhead-header-duration, 320ms) var(--trailhead-header-ease, cubic-bezier(0.4, 0, 0.2, 1));
}

.wp-site-blocks > header.is-scrolled .wp-block-group.has-background:has(.wp-block-site-logo) {
	padding-top: var(--trailhead-header-padding-condensed, 0.5rem) !important;
	padding-bottom: var(--trailhead-header-padding-condensed, 0.5rem) !important;
}

/* The site logo carries width/height as HTML attributes (no specificity), but
   the light logo is an Image block with an inline `style="width:…"`, so this
   needs !important to reach it. height:auto keeps both aspect ratios, since
   the attribute height would otherwise squash the scaled image. */
.wp-site-blocks > header.is-scrolled .wp-block-site-logo img,
.wp-site-blocks > header.is-scrolled .trailhead-logo-light img {
	width: var(--trailhead-logo-width-condensed, 94px) !important;
	height: auto !important;
}

@media (prefers-reduced-motion: reduce) {
	.wp-site-blocks > header .wp-block-group.has-background:has(.wp-block-site-logo),
	.wp-site-blocks > header .wp-block-site-logo img,
	.wp-site-blocks > header .trailhead-logo-light img {
		transition-duration: 1ms;
	}
}
