/**
 * Storypath base styles.
 *
 * Every value comes from theme.json presets (--wp--preset--*) or the theme's
 * custom properties (--wp--custom--storypath--*). Do not add brand colours, font
 * names or text here. Logical properties keep the file direction-neutral.
 */

/*
 * Visible focus indicator. It is enforced and cannot be switched off
 * from Global Styles.
 */
:where(
a,
button,
input,
select,
textarea,
summary,
[tabindex],
.wp-element-button,
.wp-block-button__link
):focus-visible {
	outline:
		var(--wp--custom--storypath--focus-width, 2px)
		solid
		var(
			--storypath-focus-ring,
			var(--wp--custom--storypath--focus-colour, currentcolor)
		) !important;
	outline-offset: 2px !important;
}

/* Skip link (core adds the link; this keeps it legible with brand colours). */
.skip-link.screen-reader-text:focus {
	background-color: var(--wp--preset--color--background);
	color: var(--wp--preset--color--text);
	font-family: var(--wp--preset--font-family--body);
	z-index: 100000;
}

/* Logos. */
.wp-block-site-logo img,
.storypath-logo img {
	block-size: auto;
	max-inline-size: var(--wp--custom--storypath--logo-max-width, 200px);
}

.storypath-logo--inverse img {
	max-inline-size: var(--wp--custom--storypath--logo-max-width, 200px);
}

/* Brand placeholder text when no logo is set. */
.storypath-logo-fallback {
	font-family: var(--wp--preset--font-family--heading);
	font-weight: 700;
}

/* Cards (Group block style "Card"). */
.is-style-storypath-card {
	border-radius: var(--wp--preset--border-radius--brand);
	box-shadow: var(--wp--preset--shadow--card);
}

/*
 * Form controls follow the brand radius and keep a 3:1 border contrast
 * via neutral dark.
 */
:where(
input:not([type="checkbox"], [type="radio"], [type="submit"]),
select,
textarea
) {
	border: 1px solid var(--wp--preset--color--text-muted);
	border-radius: var(--wp--preset--border-radius--brand);
	font: inherit;
	padding-block: 0.5em;
	padding-inline: 0.75em;
}

/* Third-party embeds (Jotform, Brevo) load only where their pattern is used. */
.storypath-embed {
	inline-size: 100%;
}

.storypath-embed iframe {
	border: 0;
	inline-size: 100%;
	min-block-size: 36rem;
}

.storypath-embed__notice {
	background-color: var(--wp--preset--color--surface);
	border-inline-start: 4px solid var(--wp--preset--color--warning);
	padding: var(--wp--preset--spacing--40);
}

/* Contact list. */
.storypath-contact-list {
	list-style: none;
	padding-inline-start: 0;
}

/* Reduced motion. */
@media (prefers-reduced-motion: reduce) {

	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		scroll-behavior: auto !important;
		transition-duration: 0.01ms !important;
	}
}

/*
 * Links on dark brand backgrounds take the contrast-checked "on-" text
 * colour of their section.
 */
:where(
.has-neutral-dark-background-color,
.has-primary-background-color,
.has-secondary-background-color
) a:where(:not(.wp-element-button)) {
	color: inherit;
}

/*
 * Hover and focus on dark brand backgrounds (accessibility review A11Y-01).
 * The global link hover colour is checked against the page background only,
 * so on a dark section it can almost vanish. Links keep the section's text
 * colour and show the state with a thicker underline instead.
 */
:is(
.has-neutral-dark-background-color,
.has-primary-background-color,
.has-secondary-background-color
) a:where(:not(.wp-element-button)):is(:hover, :focus) {
	color: inherit;
	text-decoration-line: underline;
	text-decoration-thickness: max(2px, 0.12em);
}

/*
 * Focus ring on dark brand backgrounds (A11Y-02). The ring sits outside the
 * focused element, so it must stand out against the section background.
 * Dark sections use their contrast-checked "on-" text colour for the ring.
 * Inside a light block within a dark section (a card, for example), the
 * brand focus colour comes back. A light block itself, such as a white
 * button on a dark hero, keeps the section ring, because its ring is drawn
 * on the dark background.
 */
.has-neutral-dark-background-color {
	--storypath-focus-ring: var(--wp--preset--color--on-neutral-dark, currentcolor);
}

.has-primary-background-color {
	--storypath-focus-ring: var(--wp--preset--color--on-primary, currentcolor);
}

.has-secondary-background-color {
	--storypath-focus-ring: var(--wp--preset--color--on-secondary, currentcolor);
}

:is(
.has-neutral-dark-background-color,
.has-primary-background-color,
.has-secondary-background-color
) .has-background:not(
.has-neutral-dark-background-color,
.has-primary-background-color,
.has-secondary-background-color
) > :not(
.has-neutral-dark-background-color,
.has-primary-background-color,
.has-secondary-background-color
) {
	--storypath-focus-ring: initial;
}

/*
 * Submenu arrow (accessibility review A11Y-04). Core draws the arrow button
 * at 0.6em, about 10 by 10 pixels, right next to the parent link. WCAG 2.2
 * asks for a 24 by 24 pixel target. The button grows to 24 pixels and the
 * icon stays the same size in the middle. The end margin takes back the
 * extra width, so menu spacing barely changes and the hit area never covers
 * the parent link. Only the arrow button is changed. With "Open on click",
 * core uses a span inside the full-width toggle instead, so it's not affected.
 */
.wp-block-navigation button.wp-block-navigation__submenu-icon {
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	margin-inline: 0 calc((24px - 0.6em) / -2);
}

.wp-block-navigation button.wp-block-navigation__submenu-icon svg {
	flex: none;
	width: 0.6em;
	height: 0.6em;
	margin-top: 0;
}

/*
 * Previous and next post links on single posts (A11Y-06). The links now show
 * the post title, so each gets half the row and wraps inside it. On narrow
 * screens they stack, and the next link stays on the right.
 */
.wp-block-post-navigation-link {
	flex: 1 1 16rem;
	min-width: 0;
}

/*
 * Long words and web addresses wrap instead of pushing the page sideways
 * (A11Y-09). This shows on phones with large text, for example the long
 * links in the WordPress privacy policy text or a big hero heading. Words
 * only break when they don't fit on a line by themselves.
 */
:where(.wp-block-post-content, .wp-block-post-title, .wp-block-heading, .wp-block-comment-content, .wp-block-table td) {
	overflow-wrap: break-word;
}

/* Sticky header (Setup > Header and footer). The body class comes from inc/Front/StickyHeader.php. */
.storypath-sticky-header .wp-site-blocks > header.wp-block-template-part {
	position: sticky;
	top: var(--wp-admin--admin-bar--height, 0px);
	z-index: 100;
	background-color: var(--wp--preset--color--background);
	border-block-end: 1px solid var(--wp--preset--color--neutral-light, rgba(0, 0, 0, 0.1));
}

/* WordPress lets the admin bar scroll away on small screens, so the header sits at the very top there. */
@media (max-width: 600px) {
	.admin-bar.storypath-sticky-header .wp-site-blocks > header.wp-block-template-part {
		top: 0;
	}
}

/*
 * Keep in-page links (like #website-plan) and keyboard focus from landing
 * under the header (A11Y-08). assets/js/sticky-header.js sets the real header
 * height. Without it, the fallback fits the default header: one row on
 * tablets and desktops, and two rows on phones, where the menu and button
 * wrap below the logo. The fallback is in rem, so it grows with text size.
 */
html:has(body.storypath-sticky-header) {
	--storypath-header-fallback: 6rem;
	scroll-padding-block-start: calc(var(--wp-admin--admin-bar--height, 0px) + var(--storypath-header-height, var(--storypath-header-fallback)) + 0.5rem);
}

@media (max-width: 781px) {
	html:has(body.storypath-sticky-header) {
		--storypath-header-fallback: 8.5rem;
	}
}

@media (prefers-reduced-motion: no-preference) {
	html:has(body.storypath-sticky-header) {
		scroll-behavior: smooth;
	}
}

/* Headings inside a section with its own text colour follow that colour, so they stay readable on dark backgrounds. */
.has-text-color :is(h1, h2, h3, h4, h5, h6):not(.has-text-color) {
	color: inherit;
}

/*
 * Customer login form ([storypath_login], inc/Content/LoginForm.php).
 * The fields use the form control rules above; the button uses the theme
 * button style.
 */
.storypath-login {
	font-family: var(--wp--preset--font-family--body);
}

.storypath-login form p {
	margin-block: 0 var(--wp--preset--spacing--30, 1rem);
}

.storypath-login label {
	display: block;
	font-weight: 600;
	margin-block-end: 0.25em;
}

.storypath-login :is(.login-username, .login-password) br {
	display: none;
}

.storypath-login .login-remember label {
	align-items: center;
	display: inline-flex;
	font-weight: 400;
	gap: 0.5em;
	min-block-size: 24px;
}

.storypath-login .login-remember input {
	block-size: 1.125em;
	inline-size: 1.125em;
	margin: 0;
}

.storypath-login :where(.input, input[type="text"], input[type="password"]) {
	background-color: var(--wp--preset--color--background);
	box-sizing: border-box;
	color: var(--wp--preset--color--text);
	inline-size: 100%;
	min-block-size: 44px;
}

.storypath-login .login-submit .wp-element-button {
	cursor: pointer;
	min-block-size: 44px;
}

.storypath-login [aria-invalid="true"] {
	border-color: var(--wp--preset--color--error);
	border-width: 2px;
}

.storypath-login__notice {
	background-color: var(--wp--preset--color--background);
	border: 1px solid var(--wp--preset--color--text-muted);
	border-inline-start: 4px solid var(--wp--preset--color--primary);
	border-radius: var(--wp--preset--border-radius--brand);
	color: var(--wp--preset--color--text);
	margin-block-end: var(--wp--preset--spacing--40, 1.5rem);
	padding-block: 0.75em;
	padding-inline: 1em;
}

.storypath-login__notice p {
	margin: 0;
}

.storypath-login__notice--error {
	border-inline-start-color: var(--wp--preset--color--error);
}

.storypath-login__links {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5em 1.5em;
	list-style: none;
	margin-block: var(--wp--preset--spacing--30, 1rem) 0;
	padding: 0;
}

.storypath-login__links a {
	display: inline-block;
	padding-block: 0.25em;
}

/*
 * Sections touch (1.5.0-rc.2). Full-width sections sit flush against each
 * other and the footer, with no white strip between them. The main group in
 * each template has no bottom padding; it gets bottom space back only when
 * its last block is not a full-width section, so plain text never touches
 * the footer.
 */
:is(.wp-site-blocks, .editor-styles-wrapper .is-root-container) > footer {
	margin-block-start: 0;
}

:is(.wp-site-blocks, .editor-styles-wrapper .is-root-container) > main :is(
	.alignfull + .alignfull,
	.wp-block-post-content:has(> .alignfull:last-child) + .alignfull,
	.alignfull + .wp-block-post-content:has(> .alignfull:first-child)
) {
	margin-block-start: 0;
}

:is(.wp-site-blocks, .editor-styles-wrapper .is-root-container) > main.wp-block-group:not(:has(> .alignfull:last-child, > .wp-block-post-content:last-child > .alignfull:last-child)) {
	padding-bottom: var(--wp--preset--spacing--70);
}
