/*
 * Dark mode.
 *
 * This LIFTS the active palette rather than replacing it. A Mint site stays
 * green; only the grounds and the text invert. That is what lets one file
 * serve all eight palettes -- and it is why the rules redefine the preset
 * variables themselves rather than restyling components: everything in the
 * theme, patterns and user content alike, already reads from those variables.
 *
 * `--wp--preset--color--overlay` is deliberately NOT touched. It is near-white
 * in every palette because it sits on photographs and on the `dark` ground,
 * both of which stay dark here.
 */

.martine-dark {
	color-scheme: dark;

	/* The page turns over: what was the navy text becomes the ground, and
	   vice versa. The band, the footer and the photographs' shade are dark
	   already and stay as they are. */
	--wp--preset--color--base: #0f1621;
	--wp--preset--color--surface: #172131;
	--wp--preset--color--tint: #131c29;
	--wp--preset--color--contrast: #eef2f8;
	--wp--preset--color--muted: #aab4c3;
	--wp--preset--color--divider: #2a3546;
}

/*
 * The brand colours have to hold their own against a dark ground.
 *
 * Each palette's `primary` is chosen to clear AA against white; against
 * #0f1621 most of them do not. Mixing the palette's own `accent` toward white
 * lifts each one without flattening the differences between them; the hover
 * blue is lifted from the band's own navy.
 *
 * The slugs it mixes are load-bearing: a colour-mix on an undefined variable
 * makes the whole declaration invalid, `primary` stops resolving, and every
 * button on the site renders as bare text while every text-contrast check
 * still passes. build_theme.py refuses to build if this file names a slug the
 * palette does not define, and reads the percentages below to audit them.
 *
 * On a dark ground hover *brightens* rather than deepens, so primary-deep
 * carries more white, not less. `on-primary` turns over with the fill: a
 * lifted fill is a light one, and a white label on it is unreadable.
 */
.martine-dark {
	--wp--preset--color--primary: color-mix(in srgb, var(--wp--preset--color--accent) 72%, white);
	--wp--preset--color--primary-deep: color-mix(in srgb, var(--wp--preset--color--accent) 52%, white);
	/* Not a mix of `secondary` itself: a custom property that reads its own
	   value is a cycle, the declaration is thrown away, and the hero's button
	   had no fill at all in dark mode. The band's raised navy, lifted, is the
	   same family of blue in every palette. */
	--wp--preset--color--secondary: color-mix(in srgb, var(--wp--preset--color--band-raised) 35%, white);
	--wp--preset--color--on-primary: #0f1621;
}

/* The hero's button stands on a photograph, not on the page: a lifted light
   blue lost its edge against the bright water. The band's navy keeps it. */
.martine-dark .martine-hero__button > .wp-block-button__link {
	background-color: var(--wp--preset--color--band-raised) !important;
	color: var(--wp--preset--color--overlay) !important;
}

.martine-dark .martine-hero__button > .wp-block-button__link:hover,
.martine-dark .martine-hero__button > .wp-block-button__link:focus-visible {
	background-color: var(--wp--preset--color--primary) !important;
	color: var(--wp--preset--color--on-primary) !important;
}

/* Photographs are a touch bright against a dark page. */
@media (prefers-reduced-motion: no-preference) {
	.martine-dark img:not(.wp-block-cover__image-background):not([src$=".svg"]) {
		filter: brightness(0.94);
		transition: filter 0.2s ease;
	}
}

/*
 * The toggle itself.
 *
 * It is a core/button with a class, so it can be dropped anywhere in the
 * editor and inherits the theme's button styling.
 */
.wp-block-button.martine-scheme-toggle > .wp-block-button__link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* An icon, not a filled button: no border and no padding. */
	border: 0;
	padding: 0;
	/* 44px square: this is the one control on the page that is only an icon,
	   and a 16px tap target is not a tap target. */
	width: 44px;
	height: 44px;
	min-width: 0;
	border-radius: 4px;
}

.wp-block-button.martine-scheme-toggle > .wp-block-button__link:hover,
.wp-block-button.martine-scheme-toggle > .wp-block-button__link:focus-visible {
	background-color: color-mix(in srgb, currentColor 12%, transparent);
}

.wp-block-button.martine-scheme-toggle > .wp-block-button__link::before {
	width: 1.15em;
	height: 1.15em;
}

.wp-block-button.martine-scheme-toggle > .wp-block-button__link::before {
	content: "";
	width: 1em;
	height: 1em;
	flex: 0 0 auto;
	background-color: currentColor;
	/* A moon, and a sun in dark mode. Masked rather than an icon font or an
	   inline SVG, so it takes the button's colour automatically and costs no
	   extra request. */
	-webkit-mask: var(--martine-scheme-icon) center / contain no-repeat;
	mask: var(--martine-scheme-icon) center / contain no-repeat;
	--martine-scheme-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z'/%3E%3C/svg%3E");
}

.martine-dark .wp-block-button.martine-scheme-toggle > .wp-block-button__link::before {
	--martine-scheme-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M19.1 4.9 17 7M7 17l-2.1 2.1' stroke='black' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

/*
 * Form controls do not inherit the page's colours, so they have to be told.
 * Without this the ticket form stays a block of white in a dark page.
 */
.martine-dark .martine-field__control,
.martine-dark .wp-block-search__input,
.martine-dark .wp-block-post-comments-form input:not([type="submit"]),
.martine-dark .wp-block-post-comments-form textarea {
	background-color: var(--wp--preset--color--surface);
	color: var(--wp--preset--color--contrast);
}

/* A native select draws its list in the system's light theme otherwise. */
.martine-dark select.martine-field__control option {
	background-color: var(--wp--preset--color--surface);
	color: var(--wp--preset--color--contrast);
}

/* Cards lift with a deeper shadow: a soft grey one does not register on a
   dark page. */
.martine-dark .martine-finder__card,
.martine-dark .martine-enquiry__form,
.martine-dark .martine-post-card__body {
	box-shadow: 0 14px 34px rgb(0 0 0 / 0.5);
}
