/*
 * 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);
	font-weight: 400;
	line-height: 1.7;
	-webkit-font-smoothing: antialiased;
	--prose-cap: 56.25rem;
}

/* Referenced by theme.json's root padding, which can't step at breakpoints itself. */
:root { --gutter: 2.5rem; }
@media (max-width: 991.98px) { :root { --gutter: 1.875rem; } }
@media (max-width: 767.98px) { :root { --gutter: 0.9375rem; } }

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

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

/* 10.5vw keeps the longest title, "Tietosuojaseloste", inside the gutter down to 320 (WCAG 1.4.10). */
.hero h1 { font-size: min(var(--wp--preset--font-size--heading-1), 10.5vw); }

/* Stops are the measured minimum for 3:1 on the brightest snow (PROJECT.md): lower one and re-measure. */
.hero--shade-front::after,
.hero--shade-page::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	pointer-events: none;
}
.hero--shade-front::after {
	background: linear-gradient(to top, rgb(0 0 0 / 0.46), rgb(0 0 0 / 0.43) 15%, rgb(0 0 0 / 0.385) 35%, rgb(0 0 0 / 0.27) 46%, rgb(0 0 0 / 0.1) 60%, transparent 75%);
}
.hero--shade-page::after {
	background: linear-gradient(to top, rgb(0 0 0 / 0.44), rgb(0 0 0 / 0.42) 43%, rgb(0 0 0 / 0.38) 52%, rgb(0 0 0 / 0.335) 60%, rgb(0 0 0 / 0.22) 68%, rgb(0 0 0 / 0.08) 80%, transparent 92%);
}

@layer base {
	body { overflow-wrap: break-word; }
	body p { margin-block: 1.875rem; }
	body figure { margin-block: 3rem; }

	body :is(h1, h2, h3, h4, h5, h6) { font-weight: 600; line-height: 1.6; margin-block: 3.125rem 1.875rem; }

	body h1 { font-size: var(--wp--preset--font-size--heading-1); font-weight: 700; line-height: 1.2; }
	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); }

	/* 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. */
	:is(.wp-block-list, :is(.content, :where(.post-type-prose .is-root-container)) :is(ul, ol)) { margin-block: 1.875rem; padding-inline-start: 1em; }
	:is(.wp-block-list, :is(.content, :where(.post-type-prose .is-root-container)) ul):where(ul) { list-style: disc; }
	:is(.wp-block-list, :is(.content, :where(.post-type-prose .is-root-container)) ol):where(ol) { list-style: decimal; }
	:is(.wp-block-list, :is(.content, :where(.post-type-prose .is-root-container)) :is(ul, ol)) > li { margin-top: 0.625rem; }
	:is(.content, :where(.post-type-prose .is-root-container)) a:not(.nomon-button) { text-decoration: underline; }

	:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
		outline: 3px solid currentColor;
		outline-offset: 2px;
	}
	.wp-block-list :where(li > *) { margin-block: 0.5rem; }
	.wp-block-list :where(li > :first-child) { margin-top: 0; }
	.wp-block-list :where(li > :last-child)  { margin-bottom: 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),
.site-content > :is(p, h1, h2, h3, h4, h5, h6, ul, ol) {
	max-width: var(--prose-cap);
	/* `!important` matches WP's own `.is-layout-constrained > *` margin rule. */
	margin-inline: auto !important;
}

/* Unlayered: WP's `:root :where(.is-layout-constrained) > *` block gap would beat a layered rule. */
:is(:is(.content, :where(.post-type-prose .is-root-container)), .wp-block-group, .wp-block-column) > :is(h2, h3, h4, h5, h6):not(:first-child) {
	margin-block: 3.125rem 1.875rem;
}

/* A location's H1 is 35, so its sub-headings stay below that. Fallbacks: the classic editor iframe has no presets. */
:is(.single-location .content, .post-type-location) h2 { font-size: var(--wp--preset--font-size--heading-5, 1.25rem); }
:is(.single-location .content, .post-type-location) h3 { font-size: var(--wp--preset--font-size--heading-6, 1.125rem); }

/* The editor canvas of a page.php page: same text column and prose rules as the front end's `.content`. */
.post-type-prose .is-root-container {
	max-width: calc(var(--prose-cap) + var(--wp--style--root--padding-left) + var(--wp--style--root--padding-right));
	margin-inline: auto;
}

:is(.content, :where(.post-type-prose .is-root-container)) > :first-child,
:is(.content, :where(.post-type-prose .is-root-container)) > .wp-block-group:first-child > :first-child {
	margin-top: 0;
}
:is(.content, :where(.post-type-prose .is-root-container)) > :last-child,
:is(.content, :where(.post-type-prose .is-root-container)) > .wp-block-group:last-child > :last-child {
	margin-bottom: 0;
}
:is(.content, :where(.post-type-prose .is-root-container)) > .wp-block-group + .wp-block-group {
	margin-top: 1.875rem;
}
/* Constrained Groups print `has-global-padding`, which would inset them inside the text column. */
:is(.content, :where(.post-type-prose .is-root-container)) .wp-block-group.has-global-padding {
	padding-inline: 0;
}
:is(.content, :where(.post-type-prose .is-root-container)) .wp-block-table {
	margin-block: 1.875rem;
	overflow-x: auto;
}
:is(.content, :where(.post-type-prose .is-root-container)) table {
	width: 100%;
	font-size: 1rem;
}
:is(.content, :where(.post-type-prose .is-root-container)) :is(th, td) {
	border: 1px solid var(--wp--preset--color--black);
	padding: 0.46875rem;
	overflow-wrap: break-word;
}
:is(.content, :where(.post-type-prose .is-root-container)) th {
	font-weight: 700;
	text-align: center;
}
/* 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);
}

/* The one button inverted where its own `blue` is the background; unlayered to beat the utilities. */
:is(.hero, .wp-block-group.has-blue-background-color) .nomon-button {
	background-color: var(--wp--preset--color--white);
	color: var(--wp--preset--color--blue);
	--icon-arrow: var(--wp--preset--color--white);
}
:is(.hero, .wp-block-group.has-blue-background-color) .nomon-button:hover {
	background-color: var(--wp--preset--color--blue-light);
}
:is(.hero, .wp-block-group.has-blue-background-color) .nomon-button:focus-visible {
	outline-color: var(--wp--preset--color--white);
	--tw-ring-color: var(--wp--preset--color--blue);
}

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

/* Descendants inherit this. */
.wp-block-group:is(.has-blue-background-color, .has-black-background-color) {
	color: var(--wp--preset--color--white);
}

/* 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: var(--wp--preset--spacing--section);
}

@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;
	}

	.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, credit bar and buttons (which carry their own arrow); 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,
	a.nomon-button:is(.is-external-link, .is-new-window)::after,
	a.nomon-contact-link:is(.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, not the link, is the flex child of `nomon/buttons`. */
[data-type="nomon/button"]:not(.nomon-button) {
	display: grid;
}
.nomon-buttons--equal.flex-row > [data-type="nomon/button"] {
	flex: 1 1 0%;
	min-width: 0;
}

/* 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: 0;
	padding-inline: var(--wp--style--root--padding-left, clamp(1rem, 5vw, 5rem));
}

/* Stands in for the hero: page.php puts the content a section below it, front page blocks bring their own margin. */
.post-type-prose .edit-post-visual-editor__post-title-wrapper {
	margin-block-end: var(--wp--preset--spacing--section);
}

.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;
}

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

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

/* --breakpoint-nav must stay numeric: navigation.js reads it for matchMedia. */
:root {
	--breakpoint-nav: 767px;

	--hamburger-color: var(--wp--preset--color--white);
	--hamburger-width: 32px;
	--hamburger-layer-height: 3.2px;
	--hamburger-layer-offset: 8px;

	--color-main-level: var(--wp--preset--color--blue);
	--typography-size-main-level: var(--wp--preset--font-size--regular);
	--typography-weight-main-level: 500;
	--typography-weight-main-level-mobile: 400;
	--gap-main-level-horizontal: 30px;

	--width-navigation: 300px;
	--color-background-menu-items: var(--wp--preset--color--white);
	--transition-navigation: 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);
}
.hamburger { position: relative; }
.hamburger::before,
.hamburger::after {
	content: "";
	position: absolute;
	transition: transform 0.3s;
}
.hamburger::before { top: calc(-1 * var(--hamburger-layer-offset)); }
.hamburger::after  { bottom: calc(-1 * var(--hamburger-layer-offset)); }

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

.nav-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 44px;
	padding: 10px;
	border: 0;
	border-radius: 5px;
	background-color: var(--wp--preset--color--blue);
	color: var(--wp--preset--color--blue);
	cursor: pointer;
	position: relative;
	z-index: 1002;
}

.nav-primary :is(.menu-items, .lang-switcher) {
	margin: 0;
	padding: 0;
	list-style: none;
}
.nav-primary :is(.menu-items, .lang-switcher) a {
	color: var(--color-main-level);
	font-size: var(--typography-size-main-level);
	line-height: 1.7;
	text-decoration: none;
}
.nav-primary .lang-switcher {
	display: inline-flex;
	width: fit-content;
	border: 2px solid var(--wp--preset--color--blue);
	border-radius: 5px;
	overflow: hidden;
}
.nav-primary .lang-switcher li { display: flex; }
.nav-primary .lang-switcher a {
	display: block;
	width: 2.75rem;
	padding: 3px 0;
	text-align: center;
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.5;
	transition: background-color 0.2s ease, color 0.2s ease;
}
.nav-primary .lang-switcher a:hover { background-color: var(--wp--preset--color--blue-light); }
.nav-primary .lang-switcher a[aria-current] {
	background-color: var(--wp--preset--color--blue);
	color: var(--wp--preset--color--white);
}
.nav-primary .lang-switcher a:focus-visible {
	outline: 2px solid var(--wp--preset--color--blue);
	outline-offset: 2px;
}

@media (max-width: 767.98px) {
	body.js-nav-active { overflow: hidden; }

	.nav-backdrop {
		position: fixed;
		inset: 0;
		z-index: 1000;
		background-color: rgba(0, 0, 0, 0.5);
		opacity: 0;
		visibility: hidden;
		transition: opacity var(--transition-navigation), visibility var(--transition-navigation);
	}
	.js-nav-active .nav-backdrop { opacity: 1; visibility: visible; }

	.nav-primary .menu-items-wrapper {
		position: fixed;
		top: var(--wp-admin--admin-bar--height, 0px);
		bottom: 0;
		left: 0;
		z-index: 1001;
		width: var(--width-navigation);
		max-width: 100%;
		padding: 30px;
		overflow: hidden auto;
		background-color: var(--color-background-menu-items);
		transform: translateX(-100%);
		visibility: hidden;
		transition: transform var(--transition-navigation), visibility var(--transition-navigation);
	}
	.js-nav-active .nav-primary .menu-items-wrapper { transform: none; visibility: visible; }

	.nav-primary .menu-items a {
		display: block;
		padding: 10px 10px 10px 0;
		font-weight: var(--typography-weight-main-level-mobile);
	}
	.nav-primary .menu-items {
		margin-bottom: 25px;
		padding-bottom: 15px;
		border-bottom: 1px solid var(--wp--preset--color--grey);
	}
}

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

	.nav-primary .menu-items-wrapper,
	.nav-primary .menu-items {
		display: flex;
		align-items: center;
		gap: var(--gap-main-level-horizontal);
	}

	.nav-primary .menu-items a {
		display: inline-block;
		position: relative;
		font-weight: var(--typography-weight-main-level);
		transition: transform 0.3s ease;
	}
	.nav-primary .menu-items a::after {
		content: "";
		position: absolute;
		left: 0;
		bottom: -2px;
		width: 100%;
		height: 2px;
		background-color: currentColor;
		transform: scaleX(0);
		transform-origin: left;
		transition: transform 0.3s ease;
	}
	.nav-primary .menu-items a:hover { transform: translateY(-1px); }
	.nav-primary .menu-items a:hover::after { transform: scaleX(1); }
}

@media (prefers-reduced-motion: reduce) {
	.nav-primary *,
	.nav-primary *::before,
	.nav-primary *::after { transition: none !important; }
}
