/*
 * 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.45;
	--prose-cap: 72ch;
	--section-padding: clamp(5rem, 12.5vw, 12.5rem);
}

/* Registered so `ch` resolves against body's font here, not per heading at the point of use. */
@property --prose-cap { syntax: "<length>"; inherits: true; initial-value: 0px; }

/* 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 {
	height: auto;
}

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

	body :is(h1, h2, h3, h4, h5, h6) { font-weight: 300; line-height: 1.4; margin-block: 2rem 0.625rem; }

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

	/* 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.5rem; padding-inline-start: 1.5em; }
	.wp-block-list:where(ul) { list-style: disc; }
	.wp-block-list:where(ol) { list-style: decimal; }
	.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);
	/* 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 > :is(.wp-block-group.has-background, .nomon-hero) {
	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(--section-padding);
}

/* Descendants inherit this; add a sibling rule per dark swatch as the palette grows. */
.wp-block-group.has-dark-background-color {
	color: #fff;
}

/* Sections sit flush; the selector outranks WP's block-gap margin on constrained children. */
.has-global-padding > :is(.wp-block-group, .nomon-hero) + .wp-block-group {
	margin-top: 0;
}

:is(.site-content, .is-root-container) > .wp-block-group:not(.has-background) {
	padding-block: clamp(2.5rem, 6vw, 5rem);
}

/* Legacy inner pages run a smaller heading scale than the front page sections. */
:is(.site-content, .is-root-container) > .wp-block-group:not(.has-background) h1 {
	font-size: var(--wp--preset--font-size--heading-2);
	font-weight: 300;
	line-height: 1.4;
}
:is(.site-content, .is-root-container) > .wp-block-group:not(.has-background) h2 {
	font-size: var(--wp--preset--font-size--heading-4);
}
:is(.site-content, .is-root-container) > .wp-block-group:not(.has-background) h3 {
	font-size: var(--wp--preset--font-size--regular);
	font-weight: 700;
}

.wp-block-group :is(p, li) a {
	text-decoration: underline;
	text-underline-offset: 0.15em;
}
.wp-block-group:not(.has-dark-background-color) :is(p, li) a:hover {
	color: var(--wp--custom--color--gold-dark);
}

.wp-block-table {
	max-width: var(--prose-cap);
	margin-inline-start: max(0px, calc((100% - var(--wp--style--global--content-size)) / 2)) !important;
	overflow-x: auto;
}
.wp-block-table table { width: 100%; }
.wp-block-table :is(th, td) {
	border: 1px solid #000;
	padding: 7px;
	text-align: start;
	vertical-align: top;
	overflow-wrap: anywhere;
	hyphens: auto;
}

.wp-block-heading.is-style-separator {
	max-width: none;
	margin-inline: auto !important;
	text-align: center;
}
.wp-block-heading.is-style-separator + p { margin-top: 1.25rem; }
.wp-block-heading.is-style-separator + .wp-block-columns { margin-top: clamp(2.5rem, 4.4vw, 4.375rem); }
.wp-block-columns + .wp-block-columns { margin-top: clamp(2.5rem, 3.2vw, 3.125rem); }
.wp-block-heading.is-style-separator::after {
	content: "";
	display: block;
	width: 80px;
	margin: 25px auto 0;
	border-top: 1px solid var(--wp--custom--color--line);
}

.wp-block-group.is-style-centered {
	--prose-cap: 890px;
	text-align: center;
}
.wp-block-group.is-style-centered :is(p, h1, h2, h3, h4, h5, h6, ul, ol) {
	margin-inline: auto !important;
}
.wp-block-group.is-style-centered .wp-block-image {
	margin-block: 3.125rem 0;
}
.wp-block-group.is-style-centered .wp-block-image img {
	margin-inline: auto;
}

.nomon-button {
	--button-fill: #000;
	--button-ink: #fff;
}
:is(.nomon-hero, .has-dark-background-color) .nomon-button {
	--button-fill: #fff;
	--button-ink: #000;
}

.wp-block-accordion + .wp-block-accordion { margin-top: 1.25rem; }
.wp-block-accordion .wp-block-accordion-heading { max-width: none; margin: 0; font-size: var(--wp--preset--font-size--heading-4); }
.wp-block-accordion-heading__toggle {
	gap: 20px;
	padding: 15px;
	border: 2px solid currentColor;
}
.wp-block-accordion-heading__toggle:hover .wp-block-accordion-heading__toggle-title {
	text-decoration: none;
}
.wp-block-accordion-heading__toggle:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}
.wp-block-accordion-heading__toggle-icon {
	width: 16px;
	height: 16px;
}
.wp-block-accordion-heading__toggle-icon svg { stroke-width: 4; }
.wp-block-accordion-item.is-open > .wp-block-accordion-heading .wp-block-accordion-heading__toggle-icon {
	transform: none;
}
.wp-block-accordion-item.is-open > .wp-block-accordion-heading .wp-block-accordion-heading__toggle-icon path:last-child {
	display: none;
}
.wp-block-accordion-heading__toggle:hover,
.wp-block-accordion-item.is-open > .wp-block-accordion-heading .wp-block-accordion-heading__toggle {
	background: #000;
	border-color: #000;
	color: #fff;
}
.has-dark-background-color .wp-block-accordion-heading__toggle:hover,
.has-dark-background-color .wp-block-accordion-item.is-open > .wp-block-accordion-heading .wp-block-accordion-heading__toggle {
	background: #fff;
	border-color: #fff;
	color: var(--wp--preset--color--dark);
}
.wp-block-accordion-panel {
	--prose-cap: 100rem;
	margin-top: 0;
	padding: 20px;
	font-weight: 200;
}
.wp-block-accordion-panel p { margin-block: 0 10px; }

.nomon_footer { font-weight: 400; }

.site-footer .nomon-iframe-placeholder {
	position: absolute;
	inset: 0;
	border-radius: 0;
}

/* Set by main.js on section content below the fold; without JS nothing is hidden. */
@media screen {
	.will-reveal {
		opacity: 0;
		transform: translateY(2rem);
	}
	.will-reveal.is-revealed {
		opacity: 1;
		transform: none;
		transition: opacity 1s ease, transform 1s ease;
	}
}
}

@layer base {
	@media (prefers-reduced-motion: no-preference) {
		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;
	}

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

	/* Legacy shows no glyph, so it is hidden everywhere it could appear; 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;
	}
}

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

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

.edit-post-visual-editor__post-title-wrapper .editor-post-title {
	color: inherit;
	margin: 0 auto;
	max-width: var(--wp--style--global--content-size, 1160px);
	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. The menu is an overlay at every width. */
	--breakpoint-nav: 99999px;

	--hamburger-width: 20px;
	--hamburger-layer-height: 4px;
	--hamburger-layer-offset: 8px;
}

.hamburger {
	display: block;
	width: var(--hamburger-width);
	height: var(--hamburger-layer-height);
	background-color: currentColor;
	position: relative;
	flex-shrink: 0;
}
.hamburger::before,
.hamburger::after {
	content: "";
	display: block;
	width: var(--hamburger-width);
	height: var(--hamburger-layer-height);
	background-color: currentColor;
	position: absolute;
	left: 0;
}
.hamburger::before { top: calc(var(--hamburger-layer-offset) * -1); }
.hamburger::after  { bottom: calc(var(--hamburger-layer-offset) * -1); }

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

.nav-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 54px;
	height: 54px;
	margin: 0;
	padding: 0;
	background: transparent;
	border: 2px solid #fff;
	border-radius: 100%;
	color: #fff;
	cursor: pointer;
	position: relative;
	z-index: 99999;
	transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}
.nav-toggle:hover {
	background: #000;
	border-color: #000;
}
.nav-toggle:focus-visible,
.nav-primary .menu-item a:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 3px;
}

.js-nav-active .nav-toggle {
	--hamburger-width: 30px;
	--hamburger-layer-height: 2px;
	position: fixed;
	top: calc(28px + var(--wp-admin--admin-bar--height, 0px));
	right: 28px;
	background: transparent;
	border-color: transparent;
}

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

.nav-primary .menu-items-wrapper {
	position: fixed;
	inset: 0;
	z-index: 99998;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding-top: calc(20vh + 40px);
	overflow-y: auto;
	background: rgb(0 0 0 / 0.95);
	opacity: 0;
	visibility: hidden;
}
@media (prefers-reduced-motion: no-preference) {
	.nav-primary .menu-items-wrapper { transition: opacity 0.5s, visibility 0.5s; }
}
/* The front-page header is its own stacking context, so the cookie plugin's button would sit on top of the overlay. */
.js-nav-active #nomon-floating-btn { display: none; }
.js-nav-active .nav-primary .menu-items-wrapper {
	opacity: 1;
	visibility: visible;
}

.nav-primary .menu-items {
	width: 40%;
	margin: 0;
	padding: 0;
	list-style: none;
}
.nav-primary .menu-item { margin: 5px 0; }
.nav-primary .menu-item a {
	display: block;
	padding: 10px;
	color: #fff;
	font-size: var(--wp--preset--font-size--heading-2);
	font-weight: 200;
	line-height: 1;
	text-decoration: none;
}
.nav-primary .menu-item a:hover { color: var(--wp--custom--color--gold); }

@media (max-width: 768px) {
	.nav-primary .menu-items { width: 80%; }
	.js-nav-active .nav-toggle {
		top: calc(8px + var(--wp-admin--admin-bar--height, 0px));
		right: 8px;
	}
}
