/*
 * Thought & Meaning: foundations.
 * Colours, type and spacing come from theme.json (--wp--preset--*). This file adds the
 * motifs, focus, white reading panels, forms and buttons. Only the seven palette
 * colours are used, plus translucent white or black.
 */

/* ---------- Tokens ---------- */

:root {
	--tm-night: var(--wp--preset--color--night);
	--tm-evergreen: var(--wp--preset--color--evergreen);
	--tm-moss: var(--wp--preset--color--moss);
	--tm-gold: var(--wp--preset--color--gold);
	--tm-white: var(--wp--preset--color--white);
	--tm-ink: var(--wp--preset--color--ink);
	--tm-garnet: var(--wp--preset--color--garnet);

	--tm-font-display: var(--wp--preset--font-family--display);
	--tm-font-serif-display: var(--wp--preset--font-family--serif-display);
	--tm-font-body: var(--wp--preset--font-family--body);

	/* Multi-layer, subtle: a contact shadow, a near shadow and a long soft fall-off. */
	--tm-shadow: 0 1px 2px rgba(0, 0, 0, 0.16), 0 6px 16px rgba(0, 0, 0, 0.14), 0 24px 48px rgba(0, 0, 0, 0.12);

	--tm-gutter: var(--wp--style--root--padding-left, clamp(1rem, 4vw, 2.5rem));
	--tm-focus-ring: var(--tm-gold);
}

/*
 * The cartouche: the logo frame's rectangle with concave (scooped) corners.
 * Each corner is a quarter circle of radius --tm-cartouche-r cut into the box, drawn
 * as a polygon so it scales with any box and works in every browser. It is declared
 * again on the elements that use it so a local --tm-cartouche-r takes effect.
 */
:root,
.tm-cartouche,
.tm-piece__img--placeholder,
.tm-button,
.tm-contact-form button[type="submit"],
.single_add_to_cart_button {
	--tm-cartouche-r: 14px;
	--tm-cartouche: polygon(
		0 var(--tm-cartouche-r),
		calc(var(--tm-cartouche-r) * 0.259) calc(var(--tm-cartouche-r) * 0.966),
		calc(var(--tm-cartouche-r) * 0.5) calc(var(--tm-cartouche-r) * 0.866),
		calc(var(--tm-cartouche-r) * 0.707) calc(var(--tm-cartouche-r) * 0.707),
		calc(var(--tm-cartouche-r) * 0.866) calc(var(--tm-cartouche-r) * 0.5),
		calc(var(--tm-cartouche-r) * 0.966) calc(var(--tm-cartouche-r) * 0.259),
		var(--tm-cartouche-r) 0,
		calc(100% - var(--tm-cartouche-r)) 0,
		calc(100% - var(--tm-cartouche-r) * 0.966) calc(var(--tm-cartouche-r) * 0.259),
		calc(100% - var(--tm-cartouche-r) * 0.866) calc(var(--tm-cartouche-r) * 0.5),
		calc(100% - var(--tm-cartouche-r) * 0.707) calc(var(--tm-cartouche-r) * 0.707),
		calc(100% - var(--tm-cartouche-r) * 0.5) calc(var(--tm-cartouche-r) * 0.866),
		calc(100% - var(--tm-cartouche-r) * 0.259) calc(var(--tm-cartouche-r) * 0.966),
		100% var(--tm-cartouche-r),
		100% calc(100% - var(--tm-cartouche-r)),
		calc(100% - var(--tm-cartouche-r) * 0.259) calc(100% - var(--tm-cartouche-r) * 0.966),
		calc(100% - var(--tm-cartouche-r) * 0.5) calc(100% - var(--tm-cartouche-r) * 0.866),
		calc(100% - var(--tm-cartouche-r) * 0.707) calc(100% - var(--tm-cartouche-r) * 0.707),
		calc(100% - var(--tm-cartouche-r) * 0.866) calc(100% - var(--tm-cartouche-r) * 0.5),
		calc(100% - var(--tm-cartouche-r) * 0.966) calc(100% - var(--tm-cartouche-r) * 0.259),
		calc(100% - var(--tm-cartouche-r)) 100%,
		var(--tm-cartouche-r) 100%,
		calc(var(--tm-cartouche-r) * 0.966) calc(100% - var(--tm-cartouche-r) * 0.259),
		calc(var(--tm-cartouche-r) * 0.866) calc(100% - var(--tm-cartouche-r) * 0.5),
		calc(var(--tm-cartouche-r) * 0.707) calc(100% - var(--tm-cartouche-r) * 0.707),
		calc(var(--tm-cartouche-r) * 0.5) calc(100% - var(--tm-cartouche-r) * 0.866),
		calc(var(--tm-cartouche-r) * 0.259) calc(100% - var(--tm-cartouche-r) * 0.966),
		0 calc(100% - var(--tm-cartouche-r))
	);
}

/*
 * How to use it: add class="tm-cartouche" to an image, figure or placeholder (set
 * --tm-cartouche-r on the same element for a different corner size). For a button,
 * use .tm-button, which clips a pseudo-element instead so its focus ring is not cut off
 * (WooCommerce's add to bag button gets the same styles by its own class).
 * Never put .tm-cartouche on a focusable element: clip-path would hide its outline.
 */
.tm-cartouche {
	clip-path: var(--tm-cartouche);
}

/* ---------- Page frame ---------- */

html {
	background-color: var(--tm-evergreen);
	color: var(--tm-white);
	-webkit-text-size-adjust: 100%;
}

body {
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;
	font-synthesis: none;
}

.wp-site-blocks {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	min-height: 100dvh;
}

/* Header, main and footer sit flush; spacing is set inside each. */
.wp-site-blocks > * {
	margin-block: 0;
}

.wp-site-blocks > main,
.wp-site-blocks > .tm-main {
	flex: 1 0 auto;
}

::selection {
	background-color: var(--tm-gold);
	color: var(--tm-night);
}

img {
	max-width: 100%;
	height: auto;
}

/* ---------- Focus: always visible, gold on dark, ink on white ---------- */

:focus {
	outline: none;
}

:focus-visible {
	outline: 3px solid var(--tm-focus-ring);
	outline-offset: 3px;
}

.tm-panel,
.tm-surface-white {
	--tm-focus-ring: var(--tm-ink);
}

.skip-link.screen-reader-text:focus {
	background-color: var(--tm-white);
	color: var(--tm-ink);
	font-family: var(--tm-font-body);
	font-size: 1.1875rem;
	outline: 3px solid var(--tm-gold);
}

.tm-visually-hidden {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* ---------- Text ---------- */

a {
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}

a:hover {
	text-decoration-color: var(--tm-gold);
}

p {
	text-wrap: pretty;
}

h1,
h2,
h3 {
	text-wrap: balance;
}

.tm-display-line {
	font-family: var(--tm-font-serif-display);
	font-style: italic;
	font-weight: 500;
	font-size: var(--wp--preset--font-size--display);
	line-height: 1.1;
	letter-spacing: 0;
}

/* ---------- Main areas ---------- */

.tm-main {
	padding-block: clamp(3rem, 7vw, 5.5rem) clamp(4rem, 9vw, 7rem);
}

.tm-page__title {
	margin-block: 0 clamp(2rem, 4vw, 3rem);
}

/* A single gold hairline under the page title, like the rule beside the logo's ampersand. */
.tm-page__title::after {
	content: "";
	display: block;
	width: 4.5rem;
	height: 0;
	margin: 1.25rem auto 0;
	border-top: 1px solid var(--tm-gold);
}

/* White reading panel: the card on its stand against the dark box. */
.tm-panel {
	box-sizing: border-box;
	max-width: 48rem;
	margin-inline: auto;
	padding: clamp(1.75rem, 5vw, 4rem) clamp(1.5rem, 5vw, 4.5rem);
	background-color: var(--tm-white);
	color: var(--tm-ink);
	box-shadow: var(--tm-shadow);
}

.tm-panel a {
	color: var(--tm-ink);
}

.tm-panel a:hover {
	text-decoration-color: var(--tm-moss);
	text-decoration-thickness: 2px;
}

.tm-panel > .wp-block-post-content > :first-child {
	margin-block-start: 0;
}

.tm-panel > .wp-block-post-content > :last-child {
	margin-block-end: 0;
}

.tm-front {
	display: grid;
	align-content: center;
	min-height: 55vh;
}

/* ---------- Search results and archive lists ---------- */

.tm-results {
	gap: clamp(1.5rem, 3vw, 2.5rem);
}

.tm-results__image {
	--tm-cartouche-r: 12px;
	margin: 0 0 0.75rem;
	background-color: var(--tm-moss);
}

.tm-results__title,
.tm-list .wp-block-post-title {
	font-size: var(--wp--preset--font-size--large);
}

.tm-results__title a,
.tm-list .wp-block-post-title a {
	color: var(--tm-white);
	text-decoration: none;
}

.tm-results__title a:hover,
.tm-list .wp-block-post-title a:hover {
	text-decoration: underline;
	text-decoration-color: var(--tm-gold);
}

/* ---------- Fixed backgrounds ---------- */

/*
 * A background that stays put while the page scrolls past it. background-attachment: fixed
 * does not work on iPhone and iPad, so the picture is a position: fixed layer inside a
 * container that clips it (clip-path clips fixed descendants; overflow does not).
 *   <div class="tm-fixed-bg" aria-hidden="true"><div class="tm-fixed-bg__layer"></div></div>
 * Put it first inside a position: relative section, and set --tm-bg-image (a url()) on the
 * section or the .tm-fixed-bg. Without one, the layer is flat --tm-bg-colour (evergreen).
 */
.tm-fixed-bg {
	position: absolute;
	inset: 0;
	z-index: -1;
	clip-path: inset(0);
	pointer-events: none;
}

.tm-fixed-bg__layer {
	position: fixed;
	inset: 0;
	/* The large viewport, so the layer still fills the screen while Safari's toolbars hide and show. */
	height: 100lvh;
	background-color: var(--tm-bg-colour, var(--tm-evergreen));
	background-image: var(--tm-bg-image, none);
	background-position: var(--tm-bg-position, center);
	background-size: var(--tm-bg-size, cover);
	background-repeat: var(--tm-bg-repeat, no-repeat);
}

/*
 * Optional, set where the layer is used:
 * --tm-bg-size / --tm-bg-repeat / --tm-bg-position: for a tiled texture (for example
 *   "36rem auto" and "repeat").
 * --tm-bg-dim: a night veil over the picture (0 to 1), so white type on top keeps its contrast.
 */
.tm-fixed-bg__layer::after {
	content: "";
	position: absolute;
	inset: 0;
	background-color: var(--tm-night);
	opacity: var(--tm-bg-dim, 0);
}

/*
 * The textures (scripts/images/textures.mjs): the Christmas background, a generated picture of
 * fir and fairy lights, and the others from her own photography. Phone-sized files by default;
 * larger ones where the screen is larger. Used on the home page; the Christmas background is
 * also behind the Christmas collection title (set on .tm-collection-hero--christmas, the
 * collection page's hook).
 */
.tm-fixed-bg--christmas,
.tm-collection-hero--christmas {
	--tm-bg-image: url("../img/texture-christmas-portrait.webp");
	--tm-bg-dim: 0.42;
}

@media (orientation: landscape), (min-width: 48em) {
	.tm-fixed-bg--christmas,
	.tm-collection-hero--christmas {
		--tm-bg-image: url("../img/texture-christmas-1280.webp");
	}
}

@media (min-width: 80em) {
	.tm-fixed-bg--christmas,
	.tm-collection-hero--christmas {
		--tm-bg-image: url("../img/texture-christmas.webp");
	}
}

.tm-fixed-bg--damask {
	--tm-bg-image: url("../img/texture-damask-1020.webp");
	--tm-bg-size: 40rem auto;
	--tm-bg-repeat: repeat;
	--tm-bg-dim: 0.4;
}

@media (min-width: 64em) {
	.tm-fixed-bg--damask {
		--tm-bg-image: url("../img/texture-damask.webp");
		--tm-bg-size: 64rem auto;
	}
}

/* ---------- Buttons ---------- */

/*
 * The fill is drawn on a pseudo-element clipped to the cartouche, so the focus
 * outline on the button itself is never clipped away.
 */
.tm-button,
.tm-contact-form button[type="submit"],
.single_add_to_cart_button {
	--tm-button-fill: var(--tm-moss);
	--tm-button-text: var(--tm-white);
	position: relative;
	isolation: isolate;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 3.25rem;
	padding: 0.75rem 2rem;
	border: 0;
	background-color: transparent;
	color: var(--tm-button-text);
	font-family: var(--tm-font-display);
	font-size: 1.0625rem;
	font-weight: 400;
	letter-spacing: 0.08em;
	line-height: 1.2;
	text-decoration: none;
	cursor: pointer;
	--tm-cartouche-r: 9px;
}

.tm-button::before,
.tm-contact-form button[type="submit"]::before,
.single_add_to_cart_button::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	background-color: var(--tm-button-fill);
	clip-path: var(--tm-cartouche);
	transition: background-color 160ms ease;
}

.tm-button:hover,
.tm-contact-form button[type="submit"]:hover,
.single_add_to_cart_button:hover {
	--tm-button-fill: var(--tm-night);
}

/* On dark surfaces. */
.tm-button--light {
	--tm-button-fill: var(--tm-white);
	--tm-button-text: var(--tm-ink);
}

/* Gold is never a fill behind text; the light button inverts to night instead. */
.tm-button--light:hover {
	--tm-button-fill: var(--tm-night);
	--tm-button-text: var(--tm-white);
}

/* ---------- Forms (always on white) ---------- */

.tm-panel label,
.tm-contact-form label {
	display: block;
	margin-block-end: 0.4rem;
	font-weight: 700;
}

.tm-panel input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
.tm-panel textarea,
.tm-panel select,
.tm-search__field {
	box-sizing: border-box;
	width: 100%;
	min-height: 3.25rem;
	padding: 0.7rem 0.9rem;
	border: 1px solid var(--tm-moss);
	border-radius: 0;
	background-color: var(--tm-white);
	color: var(--tm-ink);
	font: inherit;
	font-size: 1.1875rem;
	line-height: 1.4;
	appearance: none;
}

::placeholder {
	color: var(--tm-moss);
	opacity: 1;
}

.tm-panel input:focus-visible,
.tm-panel textarea:focus-visible,
.tm-panel select:focus-visible {
	outline: 3px solid var(--tm-ink);
	outline-offset: 2px;
}

.tm-contact-form p {
	margin-block: 0 1.5rem;
}

.tm-contact-form__error {
	color: var(--tm-garnet);
	font-weight: 700;
}

.tm-contact-form [aria-invalid="true"] {
	border-color: var(--tm-garnet) !important;
	border-width: 2px !important;
}

/* ---------- Pattern backgrounds ---------- */

/*
 * A gold trellis from pagepatterns.com behind the home page's Christmas cards and the footer:
 * an inline, aria-hidden SVG, first child of its section, quieter in the middle where the
 * copy sits. The section sets position and isolation; the SVG fills it behind the content
 * and clips itself. --pattern-tint recolours the lines; --pattern-strength (0 to 1) fades them.
 */
.pattern-bg {
	position: absolute;
	inset: 0;
	z-index: -1;
	width: 100%;
	height: 100%;
	color: var(--pattern-tint, var(--tm-gold));
	/* The lines are strokes; this keeps the browser's default black fill off the SVG. */
	fill: none;
	opacity: var(--pattern-strength, 1);
	pointer-events: none;
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}

/*
 * A landscape photo in a portrait tile (the markup adds .tm-fit): shown whole and centred, not cut to a
 * slice of the card. The space above and below it is the photo's own top and bottom edge, averaged to a grey
 * (--tm-fit-bg is a tiny one-by-two picture the plugin makes from it, scaled up smoothly), so the wall
 * and the table carry on past the photo.
 */
img.tm-fit {
	object-fit: contain;
	background-color: #8b8a86;
	background-image: var(--tm-fit-bg, none);
	background-size: 100% 100%;
	background-repeat: no-repeat;
}
