/*
 * 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-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--regular);
	line-height: 1.5;
	color: var(--wp--preset--color--black);
	background-color: var(--wp--preset--color--white);
	--prose-cap: 57.5rem;
}

/* 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;
}

/* 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;
}

/* Unlayered to beat the block library's own caption margins. */
.wp-block-image figcaption {
	margin: 0;
	padding: 1.25rem;
	background-color: var(--wp--preset--color--gray-light);
	font-size: 1.125rem;
	text-align: center;
}

/* Unlayered: WS Form sets these inline in `:where()`, which any layered rule loses to. */
[data-wsf-style-id] {
	--wsf-form-color-primary: var(--wp--preset--color--primary);
	--wsf-form-color-accent: var(--wp--preset--color--primary);
	--wsf-form-font-size: 1.125rem;
	--wsf-form-font-size-small: 1rem;
	--wsf-form-line-height: 1.5;
	--wsf-form-grid-gap: 1.875rem;
	--wsf-field-button-font-size: 1.3125rem;
	--wsf-field-checkbox-size: 1.25rem;
	--wsf-field-radio-size: 1.25rem;
	--wsf-field-checkbox-gap-vertical: 1.0625rem;
	--wsf-field-radio-gap-vertical: 1.0625rem;
}
.wsf-form :is([data-row-checkbox], [data-row-radio]) {
	--wsf-field-label-font-size: 1rem;
}

/* WS Form zeroes the outline at (0,4,1); its label link is 2.5:1 on the text (WCAG 1.4.1). */
.wsf-form :focus-visible {
	outline: 2px solid var(--wp--preset--color--black) !important;
	outline-offset: 2px;
}
.wsf-form .wsf-label a {
	text-decoration: underline;
}

@layer base {
	body p { margin-block: 1.875rem; }
	body figure { margin-block: 1.25rem 2.5rem; }

	body :is(h1, h2, h3, h4, h5, h6) { font-weight: 600; line-height: 1.4; margin-block: 1.25rem 0.625rem; overflow-wrap: break-word; }

	body h1 { font-size: var(--wp--preset--font-size--heading-1); margin-bottom: 1.875rem; }
	body h2 { font-size: var(--wp--preset--font-size--heading-2); margin-bottom: 1.875rem; }
	body h3 { font-size: var(--wp--preset--font-size--heading-3); }
	body h4 { font-size: var(--wp--preset--font-size--heading-4); }

	body :is(strong, b) { font-weight: 700; }

	:is(p, .wp-block-list, figcaption) a { color: var(--wp--preset--color--primary); text-decoration: underline; }

	:focus-visible {
		outline: 2px solid var(--wp--preset--color--black);
		outline-offset: 2px;
	}

	.wp-block-quote {
		margin-block: 1.875rem;
		padding: 0.625rem 1.25rem;
		border-inline-start: 5px solid var(--wp--preset--color--border);
	}

	/* Stacked headings: any heading directly following another collapses its top margin. */
	body :is(h1, h2, h3, h4, h5, h6) + :is(h1, h2, h3, h4, h5, h6) { margin-top: 0; }

	/* core/list block: restore bullets/numbers and indent that Tailwind preflight zeroes. */
	.wp-block-list { margin-block: 1.875rem; padding-inline-start: 2.5rem; }
	.wp-block-list:where(ul) { list-style: disc; }
	.wp-block-list:where(ol) { list-style: decimal; }
	.wp-block-list :where(li > *) { margin-block: 0; }

	/* First/last reset: heading at top of a section, paragraph at end, don't push the container. */
	body :is(h1, h2, h3, h4, h5, h6):first-child { margin-top: 0; }
	body p:last-child { margin-bottom: 0; }
}

/* Prose cap; descendant selector so prose inside a nested group is capped too. */
.wp-block-group :is(p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote),
.site-content > :is(p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote) {
	max-width: var(--prose-cap);
	/* Pins prose to the contentSize start edge however wide the parent is;
	 * `!important` beats WP's `.is-layout-constrained > * { margin-inline: auto !important }`. */
	margin-inline-start: max(
		0px,
		calc((100% - var(--wp--style--global--content-size)) / 2)
	) !important;
}

/* 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: clamp(2rem, 6vw, 4rem);
}

.nomon-media-text h2 { font-size: var(--wp--preset--font-size--heading-1); }

.wp-block-group.nomon-hero { padding-block: 2.5rem 5rem; }
.nomon-hero .wp-block-columns { gap: 2.5rem; }
.nomon-hero .wp-block-column:first-child { padding-bottom: 1.25rem; }
.nomon-hero h1 {
	font-family: var(--wp--preset--font-family--script);
	font-size: var(--wp--preset--font-size--display);
	font-weight: 400;
	line-height: 1;
	margin-bottom: 2.5rem;
}
.nomon-hero .wp-block-image { margin-block: 0; }
/* No width/height in the markup: without this box the row grows when the file lands. */
.nomon-hero .wp-block-image img { margin-inline: auto; width: 33.75rem; aspect-ratio: 1; }
/* 781px is where core/columns stacks. */
@media (max-width: 781px) {
	.nomon-hero .wp-block-column:last-child { display: none; }
}

/* Duplo gap; the owl selector leaves the first section flush with the page top. Scoped to
 * `core/group` as the only duplo — add block names when composite blocks join. */
.has-global-padding > .wp-block-group + .wp-block-group {
	margin-top: clamp(2rem, 5vw, 75px);
}

/* A Group nested in a Group (one per year or award) is not a duplo; it keeps the paragraph gap. */
.wp-block-group > .wp-block-group + .wp-block-group {
	margin-top: 1.875rem;
}

/* The first section heading after a page's intro text stands further off than the rest. */
.wp-block-group > p + h2:first-of-type { margin-top: 4.375rem; }
:is(.nomon-people, [data-type="nomon/people"]) + p + .wp-block-image { margin-top: 5rem; }

/* A file narrower than the column would leave the caption box wider than the image. */
.wp-block-image.size-full:has(> figcaption) :is(a, img) {
	width: 100%;
}

/* `medium` keeps WordPress's 300px box; the file BIS serves for it is larger. */
.wp-block-image.size-medium :is(img, figcaption) {
	max-width: min(100%, 18.75rem);
}
.wp-block-image.size-medium img {
	width: auto;
	max-height: 18.75rem;
}

@layer base {
	html {
		scroll-behavior: smooth;
		scroll-padding-top: var(--scroll-offset, 2rem);
	}

	/* 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;
	}

	/* Same reason as above; the editor iframe loads this file too, so preview matches. */
	:is(p, h1, h2, h3, h4, h5, h6):is(
		.has-text-align-left,
		.has-text-align-center,
		.has-text-align-right
	) {
		text-align: 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 content, footer and credit bar; the screen-reader text stays. */
	:is(.site-content, .site-footer, .nomon_footer) a.is-external-link::after,
	:is(.site-content, .site-footer, .nomon_footer) a.is-new-window::after,
	:is(.site-content, .site-footer, .nomon_footer) a.is-external-link.is-new-window::after {
		content: none;
	}
}

@layer components {
	.nomon-button {
		display: inline-block;
		padding: 0 5px 5px;
		border-bottom: 2px solid;
		color: var(--wp--preset--color--primary);
		font-family: var(--wp--preset--font-family--ui);
		font-size: var(--wp--preset--font-size--small);
		line-height: 1.2;
		text-align: center;
		text-decoration: none;
	}
	.nomon-button:is(:hover, :focus-visible) { color: var(--wp--preset--color--black); }

	.nomon-button:is(.nomon-button--filled, .nomon-button--outline) {
		padding: 1.25rem 3.125rem;
		border-width: 2px;
	}

	.nomon-button--filled {
		border-color: var(--wp--preset--color--primary);
		background-color: var(--wp--preset--color--primary);
		color: var(--wp--preset--color--white);
	}
	.nomon-button--filled:is(:hover, :focus-visible) {
		background-color: var(--wp--preset--color--white);
		color: var(--wp--preset--color--primary);
	}

	.nomon-button--outline { color: var(--wp--preset--color--black); }
	.nomon-button--outline:is(:hover, :focus-visible) {
		background-color: var(--wp--preset--color--black);
		color: var(--wp--preset--color--white);
		text-decoration: underline;
	}
	.nomon-button--outline[aria-current] {
		border-color: var(--wp--preset--color--primary);
		background-color: var(--wp--preset--color--primary);
		color: var(--wp--preset--color--white);
	}
}

/* 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 {
	display: contents;
}
[data-type="nomon/media-text"] > .block-editor-block-list__layout {
	display: block;
}
[data-type="nomon/media-text"] [data-type="nomon/buttons"]:not(.grid) {
	display: flex;
}

/* Editor-only: the block wrapper, not the link, is the flex child of `nomon/buttons`. */
[data-type="nomon/button"] {
	display: grid;
}
.nomon-buttons--equal.flex-row > [data-type="nomon/button"] {
	flex: 1 1 0%;
	min-width: 0;
}

:is(.is-layout-flow, .is-layout-constrained) > [data-blockstudio-render-marker]:first-child + * {
	margin-block-start: 0;
}

/* Editor-only: the reading column `page.php` and `single.php` set on the front end. */
.is-root-container.block-editor-block-list__layout > :not(.nomon-hero) {
	--wp--style--global--content-size: var(--prose-cap);
}
.is-root-container.block-editor-block-list__layout > :not(.alignfull, .has-background) {
	max-width: var(--prose-cap);
	margin-inline: auto !important;
}

/* 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, clamp(1rem, 5vw, 5rem));
}

.edit-post-visual-editor__post-title-wrapper .editor-post-title {
	color: inherit;
	margin: 0 auto;
	max-width: var(--wp--style--global--content-size, 1440px);
	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;
}

.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: 992px;
}

.nav-primary {
	font-family: var(--wp--preset--font-family--ui);
	font-size: 1.125rem;
	line-height: 1;
	margin-bottom: 5px;
}

.nav-primary :is(.menu-items, .sub-menu) { margin: 0; padding: 0; list-style: none; }
.nav-primary .sub-menu { font-size: 1rem; }
.nav-primary .sub-menu .sub-menu { line-height: 1.3; text-wrap: balance; }
.nav-primary .menu-item { position: relative; display: flex; flex-wrap: wrap; align-items: center; }

.nav-primary .menu-item :is(a, .dropdown-toggle) {
	display: flex;
	align-items: center;
	padding-block: 1.25rem;
	color: var(--wp--preset--color--black);
	cursor: pointer;
}
.nav-primary .menu-item :is(a, .nav-link):hover { text-decoration: underline; }
.nav-primary .menu-item [aria-current="page"] { color: var(--wp--preset--color--primary); }
.nav-primary a + .dropdown-toggle { min-width: 1.5rem; justify-content: flex-end; }

/* Negative margins trim the icon's built-in whitespace so it sits tight to the label. */
.nav-primary .dropdown-toggle svg {
	flex-shrink: 0;
	width: 1.25rem;
	height: 1.25rem;
	margin: -1px -0.3125rem -1px 0.25rem;
	stroke-width: 2.4;
}

.nav-toggle,
.nav-close { cursor: pointer; }

@media (max-width: 992px) {
	.nav-toggle {
		display: block;
		padding: 1.25rem 0 1.25rem 1.875rem;
		color: var(--wp--preset--color--primary);
	}
	.nav-toggle:is(:hover, [aria-expanded="true"]) { color: var(--wp--preset--color--black); }

	/* Bars are borders, not backgrounds, so they survive forced-colors mode. */
	.hamburger {
		position: relative;
		display: block;
		width: 1.375rem;
		height: 1.375rem;
		border-block: 4px solid;
	}
	.hamburger::before {
		content: "";
		position: absolute;
		inset: 5px 0 auto;
		border-top: 4px solid;
	}

	.nav-primary .menu-items-wrapper {
		position: fixed;
		top: var(--wp-admin--admin-bar--height, 0px);
		bottom: 0;
		left: 0;
		z-index: 99998;
		width: 15.625rem;
		padding-inline: 5px;
		overflow-y: auto;
		background-color: var(--wp--preset--color--white);
		box-shadow: 0 0 4px #4e3c3c;
		transform: translateX(-110%);
		visibility: hidden;
		transition: transform 0.2s, visibility 0s 0.2s;
	}
	/* Visibility flips at once on open, or focus() on the close button is refused. */
	.js-nav-active .nav-primary .menu-items-wrapper {
		transform: none;
		visibility: visible;
		transition: transform 0.2s;
	}

	.nav-close {
		display: block;
		margin-inline-start: auto;
		padding: 10px 6px 10px 14px;
	}
	.nav-close svg { width: 1.125rem; height: 1.125rem; stroke-width: 4; }

	.nav-primary .menu-item { justify-content: flex-end; text-align: right; }
	.nav-primary .sub-menu { display: none; flex-basis: 100%; }
	.nav-primary .dropdown-toggle[aria-expanded="true"] ~ .sub-menu { display: block; }
	.nav-primary .dropdown-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
	.nav-primary .sub-menu a { border-top: 1px solid transparent; }
}

@media (max-width: 992px) and (prefers-reduced-motion: reduce) {
	.nav-primary .menu-items-wrapper,
	.js-nav-active .nav-primary .menu-items-wrapper { transition: none; }
}

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

	.nav-primary .menu-items {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-end;
		column-gap: 1.875rem;
	}
	.nav-primary .menu-item { flex-wrap: nowrap; }
	.nav-primary .menu-items > .menu-item-has-children { margin-right: -0.3125rem; }
	.nav-primary .nav-link { white-space: nowrap; }

	.nav-primary .sub-menu {
		position: absolute;
		top: 100%;
		left: -1.875rem;
		z-index: 10;
		width: 13.75rem;
		background-color: var(--wp--preset--color--white);
		box-shadow: 0 1px 20px rgb(0 0 0 / 0.1);
		visibility: hidden;
	}
	.nav-primary .sub-menu .sub-menu { top: 0; left: 100%; }
	.nav-primary .sub-menu.is-out-of-viewport { left: auto; right: 0; }
	.nav-primary .sub-menu .sub-menu.is-out-of-viewport { left: auto; right: 100%; }

	.nav-primary .menu-item-has-children:hover > .sub-menu,
	.nav-primary .dropdown-toggle[aria-expanded="true"] ~ .sub-menu { visibility: visible; }

	.nav-primary .sub-menu a {
		flex: 1;
		padding-inline: 1.875rem 0.625rem;
		border-top: 1px solid transparent;
	}
	.nav-primary .sub-menu .dropdown-toggle { padding-inline: 0 0.5625rem; }
	.nav-primary .sub-menu .dropdown-toggle svg { transform: rotate(-90deg); }
}
