/*
 * Nomon Theme — base stylesheet, loaded on the frontend and inside the editor iframe.
 *
 * Tailwind handles reset and utilities; this file owns only what utilities can't express.
 * Responsibilities and the cascade smoke-test: docs/styling.md.
 */

/* Up front so layer order doesn't depend on when Blockstudio's inline style loads. Holds
 * only while Blockstudio emits layered utilities — smoke-test in docs/styling.md. */
@layer theme, base, components, utilities;

/* Unlayered on purpose: wrapping this ties with preflight's `body { line-height: inherit }`. */
body {
	font-size: var(--wp--preset--font-size--regular);
	line-height: 1.7;
	color: var(--wp--preset--color--text);
}

:root {
	--site-gutter: 60px;
	--prose-cap: 58.75rem;
}

@media (max-width: 991.98px) {
	html { scroll-padding-top: 90px; }
}

@media (max-width: 767.98px) {
	:root { --site-gutter: 40px; }

	/* `html:root` outranks the `:root` preset block WordPress prints. */
	html:root {
		--wp--preset--font-size--display: 2.1875rem;
		--wp--preset--font-size--heading-1: 2.1875rem;
		--wp--preset--font-size--heading-2: 1.875rem;
	}
}

@media (max-width: 478.98px) {
	:root { --site-gutter: 30px; }
}

/* WP's `size-full` marker collides with Tailwind's utility of that name; unlayered on
 * purpose so it beats the layered utility. See docs/styling.md. */
.wp-block-image.size-full {
	width: auto;
	height: auto;
}

/* Core's unlayered `.wp-block-image { margin: 0 0 1em }` outranks `@layer base`. */
.wp-block-image {
	margin-bottom: 30px;
}

/* Block, not inline-block: the line box under an inline anchor opens a gap above the caption. */
.wp-block-image > a {
	display: block;
	width: fit-content;
}

/* Text-align control is hidden; unlayered at (0,2,1) to beat core's unlayered `:root .has-text-align-*`. */
:root :is(p, h1, h2, h3, h4, h5, h6):is(
	.has-text-align-left,
	.has-text-align-center,
	.has-text-align-right
) {
	text-align: inherit;
}

/* Unlayered at (0,1,2) to beat core's `.wp-block-image :where(figcaption)` margins. */
figure > figcaption.wp-element-caption {
	margin: 0;
	padding: 10px 15px;
	background-color: var(--wp--preset--color--grey-light);
	color: var(--wp--preset--color--text);
	font-size: var(--wp--preset--font-size--small);
	text-align: center;
}

/* Unlayered to beat core's unlayered table styles. */
figure.wp-block-table :is(th, td) { padding: 10px; }
figure.wp-block-table.is-style-stripes tbody tr:nth-child(odd) { background-color: transparent; }
figure.wp-block-table.is-style-stripes tbody tr:nth-child(even) { background-color: var(--wp--preset--color--grey-light); }

@layer base {
	body :is(p, h1, figure, .wp-block-list) { margin-block: 0 30px; }
	body :is(h2, h3, h4, h5, h6) { margin-block: 50px 30px; }
	body :is(h1, h2, h3, h4, h5, h6):first-child { margin-top: 0; }
	body :is(p, h1, h2, h3, h4, h5, h6, figure, .wp-block-list):last-child { margin-bottom: 0; }

	body :is(h1, h2, h3, h4, h5, h6) {
		color: var(--wp--preset--color--black);
		font-weight: 700;
		line-height: 1.4;
		overflow-wrap: break-word;
	}
	body h1 { font-size: var(--wp--preset--font-size--heading-1); }
	body h2 { font-size: var(--wp--preset--font-size--heading-2); }
	body h3 { font-size: var(--wp--preset--font-size--heading-3); }
	body h4 { font-size: var(--wp--preset--font-size--heading-4); }
	body h5 { font-size: var(--wp--preset--font-size--heading-5); }
	body h6 { font-size: var(--wp--preset--font-size--heading-6); }

	.wp-block-list { padding-inline-start: 1em; }
	.wp-block-list:where(ul) { list-style-type: disc; }
	.wp-block-list:where(ol) { list-style-type: decimal; }
	.wp-block-list li + li { margin-top: 10px; }
	.wp-block-list .wp-block-list { margin: 10px 0 0; }

	/* Underlined, not colour-only: the link colour is the text colour (WCAG 1.4.1). */
	:is(.site-content, .is-root-container) :is(p, li, td) a { text-decoration: underline; }


	:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
}

/* Centred legacy content column; `!important` matches WP's constrained-layout margin rule.
 * `.is-root-container` is the editor's stand-in for `.site-content > article`. */
:is(.wp-block-group:not(.alignwide), .site-content, .site-content > article, .is-root-container) > :is(p, h2, h3, h4, h5, h6, ul, ol, figure, .nomon-buttons, .wsf-form) {
	max-width: var(--prose-cap);
	margin-inline: auto !important;
}

/* Repeats the base rhythm unlayered: WP's unlayered block-gap rule (24px top, 0 bottom) beats `@layer base`. */
:is(.wp-block-group, .site-content, .site-content > article, .is-root-container) > :is(p, h1, ul, ol, figure, .nomon-buttons, .wsf-form) {
	margin-block: 0 30px;
}
:is(.wp-block-group, .site-content, .site-content > article, .is-root-container) > :is(h2, h3, h4, h5, h6) {
	margin-block: 50px 30px;
}
:is(.wp-block-group, .site-content, .site-content > article, .is-root-container) > :first-child { margin-block-start: 0; }
:is(.wp-block-group, .site-content, .site-content > article, .is-root-container) > :last-child { margin-block-end: 0; }

/* Editor-only: the referenssi single sets its content in the 2fr column of a 1080px grid with a 50px gap. */
.post-type-referenssi .is-root-container { --prose-cap: calc((1080px - 50px) * 2 / 3); }

/* Auto-bleed, mirroring native `.alignfull`; `!important` matches WP's own margin rule. */
.has-global-padding > .wp-block-group.has-background {
	max-width: none;
	margin-left: calc(var(--wp--style--root--padding-left) * -1) !important;
	margin-right: calc(var(--wp--style--root--padding-right) * -1) !important;
	padding-left: var(--wp--style--root--padding-left);
	padding-right: var(--wp--style--root--padding-right);
}

/* Spacing controls are disabled in theme.json, so colored sections need a default. */
.wp-block-group.has-background {
	padding-block: var(--wp--preset--spacing--section);
}

.has-dark-background-color {
	color: var(--wp--preset--color--white);
}

/* Editor-only: a synced pattern's wrapper sits between the page and its full-width blocks. */
.has-global-padding > .wp-block-block:has(> .alignfull) {
	max-width: none;
}
.has-global-padding > .wp-block-block > .alignfull {
	max-width: none;
	margin-left: calc(var(--wp--style--root--padding-left) * -1) !important;
	margin-right: calc(var(--wp--style--root--padding-right) * -1) !important;
}

/* Owl selector leaves the first section flush with the page top. */
.has-global-padding > .wp-block-group + .wp-block-group {
	margin-top: var(--wp--preset--spacing--section);
}

/* Page content sits 75 px from the hero and the footer; full-bleed sections sit flush.
 * `!important` beats WP's block gap and the heading rhythm above. */
.site-content > .page-hero + * { margin-block-start: var(--wp--preset--spacing--section) !important; }
.site-content > .page-hero ~ :last-child { margin-block-end: var(--wp--preset--spacing--section) !important; }
.site-content > .page-hero + :is(.alignfull, .has-background) { margin-block-start: 0 !important; }
.site-content > .page-hero ~ :is(.alignfull, .has-background):last-child { margin-block-end: 0 !important; }

@layer components {
	.site-breadcrumbs__list { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
	.site-breadcrumbs__item { color: var(--wp--preset--color--red); }
	.site-breadcrumbs__item::after { content: "/" / ""; margin-inline-start: 10px; }
	.site-breadcrumbs__item a { color: inherit; text-decoration: none; }
	.site-breadcrumbs__item a:is(:hover, :focus-visible) { text-decoration: underline; }
	.site-breadcrumbs__item--current { color: var(--wp--preset--color--grey); }

	.site-pagination { margin-top: 50px; }
	.site-pagination .nav-links { display: flex; flex-wrap: wrap; gap: 10px; }
	.site-pagination .page-numbers { color: var(--wp--preset--color--dark); text-decoration: none; }
	.site-pagination a.page-numbers:is(:hover, :focus-visible) { text-decoration: underline; }
	.site-pagination .page-numbers.current { color: var(--wp--preset--color--red); }
}

@layer base {
	html {
		scroll-behavior: smooth;
	}

	/* Gutenberg can't hide these toolbar buttons, so cancel the effect instead. */
	:where(h1, h2, h3, h4, h5, h6) :is(strong, b, em, i) {
		font-weight: inherit;
		font-style: inherit;
	}

	.screen-reader-text {
		border: 0;
		clip-path: inset(50%);
		height: 1px;
		margin: -1px;
		overflow: hidden;
		padding: 0;
		position: absolute;
		width: 1px;
		word-wrap: normal !important;
	}

	.skip-link:focus {
		clip-path: none;
		height: auto;
		margin: 0;
		overflow: auto;
		padding: 1rem;
		position: absolute;
		inset-block-start: 0;
		inset-inline-start: 0;
		width: auto;
		z-index: 100000;
		background: #000;
		color: #fff;
		text-decoration: underline;
	}

	/* WCAG 2.4.4: per-site CSS may restyle or hide the glyph, never the screen-reader text. */
	a.is-external-link::after,
	a.is-new-window::after {
		content: " ↗";
		display: inline-block;
		font-size: 0.85em;
		vertical-align: super;
		line-height: 1;
	}
	a.is-new-window::after {
		content: " ⧉";
	}
	a.is-external-link.is-new-window::after {
		content: " ⧉";
	}

	/* Hides the glyph in the footer and credit bar only; the screen-reader text stays. */
	:is(.site-footer, .nomon_footer) a.is-external-link::after,
	:is(.site-footer, .nomon_footer) a.is-new-window::after,
	:is(.site-footer, .nomon_footer) a.is-external-link.is-new-window::after {
		content: none;
	}
}

/* Critical Swiper layout before the lazy vendor CSS lands. No pre-init `visibility: hidden`
 * — that hid the hero from FlyingPress's above-the-fold pass, costing the LCP preload. */
.swiper { overflow: hidden; }
.swiper-wrapper { display: flex; }
.swiper-slide { flex-shrink: 0; width: 100%; }
/* Overrides FlyingPress Lazy Render's inline style — see docs/runtimes.md. */
.swiper-slide,
.swiper-slide * { content-visibility: visible !important; }

/* Editor-only: flattens Gutenberg's InnerBlocks wrapper chain, which breaks parent flex/grid.
 * Unlayered to outrank editor styles; descendant combinators because `useBlockProps` shifts a level. */
[data-type^="nomon/"] .block-editor-inner-blocks,
[data-type^="nomon/"] .block-editor-block-list__layout:not([data-type]) {
	display: contents;
}

/* Editor-only: the block wrapper is the flex child of `nomon/buttons`; inline-flex keeps label and icon on one row. */
[data-type="nomon/button"] {
	display: inline-flex;
}
.nomon-buttons--equal.flex-row > [data-type="nomon/button"] {
	flex: 1 1 0%;
}
/* Core positions the appender absolutely at the row's end, over a full-width last button. */
.nomon-buttons--equal.flex-row > .block-list-appender {
	position: static;
	align-self: center;
}

/* Editor-only: Blockstudio's marker span takes `:first-child`, so the block after it gets a block gap. */
:is(.is-layout-flow, .is-layout-constrained) > [data-blockstudio-render-marker]:first-child + * {
	margin-block-start: 0;
}

/* Editor-only: the front end swaps the `+` glyph for `plus.svg` (inc/integrations/core-blocks.php). */
[data-type="core/accordion-heading"] .wp-block-accordion-heading__toggle-icon {
	position: relative;
	-webkit-text-fill-color: transparent;
}
[data-type="core/accordion-heading"] .wp-block-accordion-heading__toggle-icon::before {
	content: "";
	position: absolute;
	inset: 0;
	background-color: currentColor;
	mask: url("../icons/plus.svg") center / contain no-repeat;
}

/* Editor-only: a drag saves the box's computed `aspectRatio`, which the ratio dropdown
 * cannot display or clear (`docs/integrations.md`). Selector length beats the components
 * stylesheet's own `.has-show-handle` rule at (0,3,0). */
[data-type="core/image"] .components-resizable-box__container.has-show-handle .components-resizable-box__handle {
	display: none;
}

/* Editor-only: makes the post title read as page metadata, not the first H1. No negative
 * inline margin needed — `useRootPaddingAwareAlignments` leaves body itself unpadded. */
/* WP core's editor styles add a top padding to the iframe body; zero it. */
body {
	padding-top: 0;
}

.edit-post-visual-editor__post-title-wrapper {
	background-color: #f0f0f0;
	color: #1e1e1e;
	margin-block-start: 0 !important;
	margin-block-end: 3rem;
	padding-inline: var(--wp--style--root--padding-left, var(--site-gutter));
}

.edit-post-visual-editor__post-title-wrapper .editor-post-title {
	color: inherit;
	margin: 0 auto;
	max-width: var(--wp--style--global--content-size, 1400px);
	padding-block: 3rem;
}

.edit-post-visual-editor__post-title-wrapper .editor-post-title::before {
	content: "Sivun otsikko";
	display: block;
	color: #666;
	font-size: 0.875rem;
	font-weight: 500;
	margin-block-end: 0.75rem;
}

.post-type-post .edit-post-visual-editor__post-title-wrapper .editor-post-title::before {
	content: "Artikkelin otsikko";
}

.post-type-referenssi .edit-post-visual-editor__post-title-wrapper .editor-post-title::before {
	content: "Referenssin otsikko";
}

.edit-post-visual-editor__post-title-wrapper .editor-post-title [data-rich-text-placeholder]::after {
	color: #666;
	opacity: 1;
}

:root {
	/* Must stay numeric: JS reads it via getComputedStyle for matchMedia. */
	--breakpoint-nav: 991px;

	--hamburger-color: var(--wp--preset--color--white);
	--hamburger-width: 2rem;
	--hamburger-layer-height: 3px;
	--transition-nav-mobile: 0.3s cubic-bezier(0.77, 0, 0.175, 1);
}

.hamburger,
.hamburger::before,
.hamburger::after {
	display: block;
	width: var(--hamburger-width);
	height: var(--hamburger-layer-height);
	border-radius: 4px;
	background-color: var(--hamburger-color);
	transition: all 0.3s;
}
.hamburger { position: relative; flex-shrink: 0; }
.hamburger::before,
.hamburger::after { content: ""; position: absolute; left: 0; }
.hamburger::before { top: -10px; }
.hamburger::after  { top: 10px; }

.js-nav-active .hamburger { background-color: transparent; }
.js-nav-active .hamburger::before { top: 0; transform: rotate(-45deg); background-color: var(--hamburger-color); }
.js-nav-active .hamburger::after  { top: 0; transform: rotate(45deg); background-color: var(--hamburger-color); }

.nav-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 44px;
	margin: 0;
	padding: 10px;
	background: var(--wp--preset--color--dark);
	border: 0;
	border-radius: 0;
	cursor: pointer;
}

body.js-nav-active { overflow: hidden; }

:is(.nav-primary, .nav-top) .menu-items { margin: 0; padding: 0; list-style: none; }
:is(.nav-primary, .nav-top) .menu-item { margin: 0; }
:is(.nav-primary, .nav-top) .menu-item a { display: block; text-decoration: none; }
:is(.nav-primary, .nav-top) .menu-item a:is(:hover, :focus-visible) { text-decoration: underline; }

.nav-top .menu-item a {
	color: var(--wp--preset--color--text);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 500;
	line-height: 1.7;
}
.header-top .nav-top .menu-items { display: flex; }
.header-top .nav-top .menu-item a { padding: 10px 0 10px 25px; }

@media (min-width: 1181px) {
	.header-top .mobile-only { display: none; }
}

@media (max-width: 991.98px) {
	.site-header {
		position: sticky;
		top: var(--wp-admin--admin-bar--height, 0px);
		z-index: 100;
	}

	/* Backdrop; a click on it lands outside #nav, which closes the drawer. */
	.site-header::before {
		content: "";
		position: fixed;
		inset: 0;
		background-color: rgb(0 0 0 / 0.5);
		opacity: 0;
		visibility: hidden;
		transition: opacity var(--transition-nav-mobile), visibility 0s linear 0.3s;
		z-index: 1;
	}
	.js-nav-active .site-header::before {
		opacity: 1;
		visibility: visible;
		transition-delay: 0s;
	}

	.nav-primary .menu-items-wrapper {
		position: fixed;
		top: var(--wp-admin--admin-bar--height, 0px);
		left: 0;
		width: 300px;
		height: calc(100dvh - var(--wp-admin--admin-bar--height, 0px));
		padding: 30px;
		background-color: var(--wp--preset--color--white);
		transform: translate3d(-100%, 0, 0);
		transition: transform var(--transition-nav-mobile), visibility 0s linear 0.3s;
		visibility: hidden;
		overflow: auto;
		z-index: 2;
	}
	.js-nav-active .nav-primary .menu-items-wrapper {
		visibility: visible;
		transform: translate3d(0, 0, 0);
		transition-delay: 0s;
	}

	.nav-primary .menu-item a { padding: 10px 10px 10px 0; line-height: 1.7; }
	.nav-primary > .menu-items-wrapper > .menu-items a {
		color: var(--wp--preset--color--red);
		font-size: var(--wp--preset--font-size--regular);
	}
	.nav-primary .nav-top .menu-item a { font-weight: 400; }

	.nav-drawer-divider {
		height: 0;
		margin: 15px 0;
		border: 0;
		border-top: 1px solid var(--wp--preset--color--grey-light);
	}
}

@media (max-width: 767.98px) {
	.nav-drawer-divider { margin-top: 5px; }
	.nav-drawer-extra .nav-top { margin-top: 10px; }
}

@media (max-width: 600px) {
	.admin-bar .site-header { top: 0; }
}

@media (min-width: 992px) {
	.nav-toggle { display: none; }

	.nav-primary > .menu-items-wrapper > .menu-items { display: flex; column-gap: 25px; }
	.nav-primary > .menu-items-wrapper > .menu-items a {
		color: var(--wp--preset--color--black);
		font-size: var(--wp--preset--font-size--large);
		font-weight: 700;
		line-height: 34px;
		white-space: nowrap;
	}
}

@media (min-width: 992px) and (max-width: 1266.98px) {
	.nav-primary > .menu-items-wrapper > .menu-items { column-gap: 15px; }
	.nav-primary > .menu-items-wrapper > .menu-items a { font-size: var(--wp--preset--font-size--regular); }
}

.footer-menu { margin: 25px 0 0; padding: 0; list-style: none; }
/* Legacy icon is 14 × 13 overflowing a 10 px box + 15 px margin: text starts 25 px in. */
.footer-menu li { display: flex; align-items: center; gap: 11px; margin: 0; }
.footer-menu li::before {
	content: "";
	flex: none;
	width: 14px;
	height: 13px;
	background-color: var(--wp--preset--color--red);
	mask: url("../icons/chevrons-right.svg") center / contain no-repeat;
}
.footer-menu a { color: var(--wp--preset--color--footer-link); text-decoration: none; }
.footer-menu a:is(:hover, :focus-visible) { text-decoration: underline; }

/* WS Form. The Styler prints its variables on `:where([data-wsf-style-id])`, so these win
 * without `!important`; element rules only where WS Form has no variable. */
.wsf-form {
	--wsf-form-color-primary: var(--wp--preset--color--dark);
	--wsf-form-color-accent: var(--wp--preset--color--dark);
	--wsf-form-font-size: 1rem;
	--wsf-form-font-size-small: 0.875rem;
	--wsf-section-legend-font-size: var(--wp--preset--font-size--heading-4);
	--wsf-section-legend-font-weight: 700;
	--wsf-field-label-font-size: 1rem;
	--wsf-field-font-size: 1rem;
	--wsf-field-border-color: var(--wp--preset--color--black);
	--wsf-field-border-radius: 0;
	--wsf-field-box-shadow-color-focus: rgb(18 28 34 / 50%);
	--wsf-field-color-placeholder: var(--wp--preset--color--grey);
	--wsf-field-button-font-size: 1rem;
	--wsf-field-button-color: var(--wp--preset--color--dark);
	--wsf-field-button-color-hover: var(--wp--preset--color--white);
	--wsf-field-button-color-focus: var(--wp--preset--color--white);
	--wsf-field-button-color-background: var(--wp--preset--color--white);
	--wsf-field-button-color-background-hover: var(--wp--preset--color--dark);
	--wsf-field-button-color-background-focus: var(--wp--preset--color--dark);
	--wsf-field-button-border-color: var(--wp--preset--color--dark);
	--wsf-field-button-border-color-hover: var(--wp--preset--color--dark);
	--wsf-field-button-border-color-focus: var(--wp--preset--color--dark);
	--wsf-field-button-danger-color: var(--wp--preset--color--dark);
	--wsf-field-button-danger-color-hover: var(--wp--preset--color--white);
	--wsf-field-button-danger-color-focus: var(--wp--preset--color--white);
	--wsf-field-button-danger-color-background: var(--wp--preset--color--white);
	--wsf-field-button-danger-color-background-hover: var(--wp--preset--color--dark);
	--wsf-field-button-danger-color-background-focus: var(--wp--preset--color--dark);
	--wsf-field-button-danger-border-color: var(--wp--preset--color--dark);
	--wsf-field-button-danger-border-color-hover: var(--wp--preset--color--dark);
	--wsf-field-button-danger-border-color-focus: var(--wp--preset--color--dark);
	--wsf-field-button-primary-color-background: var(--wp--preset--color--dark);
	--wsf-field-button-primary-color-background-hover: var(--wp--preset--color--red);
	--wsf-field-button-primary-color-background-focus: var(--wp--preset--color--red);
	--wsf-field-button-primary-border-color: var(--wp--preset--color--dark);
	--wsf-field-button-primary-border-color-hover: var(--wp--preset--color--red);
	--wsf-field-button-primary-border-color-focus: var(--wp--preset--color--red);
}

.wsf-form .wsf-button.wsf-button-primary {
	font-size: var(--wp--preset--font-size--regular);
	font-weight: 700;
}

.wsf-form .wsf-label {
	overflow-wrap: break-word;
}

.wsf-form .wsf-label a {
	text-decoration: underline;
}

/* Doubled class outranks WS Form's `.wsf-form button.wsf-button:focus { outline: 0 }`. */
.wsf-form .wsf-button.wsf-button:focus-visible,
.wsf-form .dropzone:focus-visible {
	outline: 2px solid var(--wp--preset--color--dark);
	outline-offset: 2px;
}

.wsf-form .dz-message {
	color: var(--wp--preset--color--grey);
	font-size: 1rem;
}
