/*
 * 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 (docs/styling.md). */
@layer theme, base, components, utilities;

body {
	--prose-cap: 72ch;
}

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

/* Unlayered so WP's `size-full` marker beats Tailwind's utility of that name (docs/styling.md). */
.wp-block-image.size-full {
	height: auto;
}

@layer base {
	body p { margin-block: 0 1.2em; }
	body figure[class^="wp-block-"] { margin-block: 1em; }

	body :is(h1, h2, h3, h4, h5, h6) { font-weight: 500; line-height: 1.4; margin-block: 0; }
	body p:last-of-type + :is(h1, h2, h3, h4, h5, h6) { margin-top: 1.2em; }

	body h1 { font-size: 2.4em; }
	body h2 { font-size: var(--wp--preset--font-size--display-3); }
	body h3 { font-size: 1.25rem; font-weight: 500; line-height: 1.7; text-transform: uppercase; color: var(--wp--preset--color--black); margin-bottom: 1.25rem; }
	body h4 { font-size: 1.6em; }
	body h5 { font-size: 1.3em; }
	body h6 { font-size: 1.1em; }

	.entry-content a { text-decoration: underline; }
	.entry-content p strong { font-weight: 500; }

	/* `body` prefix outranks preflight's form-control reset, which loads later in the same layer. */
	body input:not([type="submit"], [type="button"], [type="reset"], [type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="image"], [type="color"]),
	body select,
	body textarea {
		width: 100%;
		padding: 0 12px;
		line-height: 40px;
		border: 1px solid var(--wp--preset--color--mid-grey);
		background-color: var(--wp--preset--color--white);
	}
	body textarea { min-height: 90px; padding: 10px 12px; line-height: inherit; }
	body select { background-color: transparent; }

	/* core/list block: restore bullets/numbers and indent that Tailwind preflight zeroes. */
	.wp-block-list { margin-block: 1em; padding-inline-start: 40px; }
	.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; }
}

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

.wp-block-group.has-black-background-color {
	color: var(--wp--preset--color--white);
}

/* Duplo gap; the owl selector leaves the first section flush with the page top. */
.has-global-padding > .wp-block-group + .wp-block-group {
	margin-top: clamp(2rem, 5vw, 75px);
}

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

	* {
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	/* Gutenberg can't hide these toolbar buttons, so cancel the effect instead; `body` outranks preflight's `strong`. */
	body :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 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;
	}

	.site-footer a {
		transition: color 0.2s;
	}

	.site-footer a:hover {
		color: var(--wp--preset--color--black);
		text-decoration: underline;
	}
}

/* Critical Swiper layout; no pre-init `visibility: hidden`, it costs 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; }

/* Klarna's badge list indents each logo by an 8px margin; pull the row back flush with the heading. */
.site-footer klarna-placement {
	display: block;
	margin-inline-start: -8px;
}

.site-footer klarna-placement::part(osm-logo) {
	padding: 6px 10px;
	background: rgb(255 255 255 / 0.5);
}

/* Editor-only: flattens Gutenberg's InnerBlocks wrapper chain, which breaks parent flex/grid. */
[data-type^="nomon/"] .block-editor-inner-blocks,
[data-type^="nomon/"] .block-editor-block-list__layout {
	display: contents;
}

/* Editor-only: the ratio dropdown can't clear a drag-saved `aspectRatio` (docs/integrations.md). */
[data-type="core/image"] .components-resizable-box__container.has-show-handle .components-resizable-box__handle {
	display: none;
}

/* Editor-only: the post title reads as page metadata, not the first H1. */
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;
}
