/**
 * Language switcher.
 *
 * Styled only for layout and the flag itself. Colour, font and size are
 * inherited, because this sits inside whatever header the site already has and
 * should look like it belongs there rather than announce itself.
 */

.rtr-switcher {
	display: inline-block;
}

.rtr-switcher__list {
	display: flex;
	align-items: center;
	/* Keep languages on one line: headers are tight and a wrap reads as broken. */
	flex-wrap: nowrap;
	gap: 0.75em;
	margin: 0;
	padding: 0;
	list-style: none;
}

.rtr-switcher__item {
	margin: 0;
	padding: 0;
	line-height: 1;
}

.rtr-switcher a {
	display: inline-flex;
	align-items: center;
	gap: 0.35em;
	color: inherit;
	text-decoration: none;
	white-space: nowrap;
	/* Inactive languages recede; the active one is full strength. */
	opacity: 0.65;
	transition: opacity 0.12s ease;
}

.rtr-switcher a:hover,
.rtr-switcher a:focus-visible {
	opacity: 1;
}

.rtr-switcher__item.is-current a {
	opacity: 1;
	font-weight: 700;
	cursor: default;
}

/* Flag ------------------------------------------------------------------ */

.rtr-flag {
	display: block;
	width: 1.5em;
	height: 1em;
	/* A pale border keeps the white in a flag from vanishing on a light header. */
	box-shadow: 0 0 0 1px rgba( 0, 0, 0, 0.18 );
	border-radius: 1px;
	flex: none;
}

.rtr-switcher__code {
	font-size: 0.8em;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

/* Flag-only variant: the label still needs to reach a screen reader. */
.rtr-switcher .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect( 0, 0, 0, 0 );
	white-space: nowrap;
	border: 0;
}

/* Dropdown --------------------------------------------------------------- */

.rtr-switcher--dropdown {
	position: relative;
	display: inline-block;
}

/* The default disclosure triangle would sit beside our own caret. */
.rtr-switcher--dropdown > summary {
	list-style: none;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	gap: 0.3em;
	padding: 0.15em;
	color: inherit;
}
.rtr-switcher--dropdown > summary::-webkit-details-marker { display: none; }
.rtr-switcher--dropdown > summary::marker { content: ""; }

.rtr-switcher--dropdown > summary:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
	border-radius: 2px;
}

.rtr-switcher__caret {
	width: 0;
	height: 0;
	border-left: 0.28em solid transparent;
	border-right: 0.28em solid transparent;
	/* currentColor so the caret follows whatever the header's text colour is. */
	border-top: 0.3em solid currentColor;
	opacity: 0.7;
	transition: transform 0.12s ease;
}

.rtr-switcher--dropdown[open] .rtr-switcher__caret {
	transform: rotate( 180deg );
}

/*
 * The open panel is its own surface rather than inheriting the header's
 * colours. A switcher sits in whatever bar the theme gives it, which may be
 * dark, light, or an image, and text that inherits from it is legible in one of
 * those cases and invisible in the others. Owning the background is the only
 * way the menu reads correctly everywhere it might be placed.
 */
.rtr-switcher--dropdown .rtr-switcher__list {
	position: absolute;
	z-index: 999;
	top: calc( 100% + 0.4em );
	left: 0;
	display: block;
	min-width: max-content;
	margin: 0;
	padding: 0.3em;
	background: #fff;
	border: 1px solid rgba( 0, 0, 0, 0.12 );
	border-radius: 8px;
	box-shadow: 0 6px 24px rgba( 0, 0, 0, 0.16 );
}

/* Near a right edge the menu would otherwise run off screen. */
.rtr-switcher--dropdown.is-right .rtr-switcher__list {
	left: auto;
	right: 0;
}

.rtr-switcher--dropdown .rtr-switcher__link {
	display: flex;
	align-items: center;
	gap: 0.5em;
	padding: 0.45em 0.7em;
	border-radius: 5px;
	color: #1d2327;
	opacity: 1;
	font-weight: 500;
	white-space: nowrap;
}

.rtr-switcher--dropdown .rtr-switcher__link:hover,
.rtr-switcher--dropdown .rtr-switcher__link:focus-visible {
	background: #f2f4f3;
	color: #1d2327;
}

.rtr-switcher__name {
	font-size: 0.95em;
}

@media (prefers-reduced-motion: reduce) {
	.rtr-switcher a,
	.rtr-switcher__caret {
		transition: none;
	}
}
