/* ============================================================
 * Theme switcher — static adapter for the axismundi-theme-switcher block.
 *
 * Every value here is a token from the layers this site syncs from the theme.
 * The literals that remain are M3 component measurements the token layers do
 * not publish - a standard icon button is 40x40 with a 24px glyph, a group
 * segment carries a 20px glyph with 16px of side space - and they are the
 * plugin's own numbers rather than ones chosen here.
 *
 * Two surfaces, one behaviour. The cycle button is an M3 standard icon button;
 * the group is an M3 connected button group. Both wear the same state layers
 * and the same focus ring, because in Material those belong to interaction
 * rather than to either component.
 * ============================================================ */

.ax-ts {
	--ax-ts-height: 40px;
	--ax-ts-pill: calc(var(--ax-ts-height) / 2);

	--ax-ts-icon-size: 24px;
	--ax-ts-segment-icon-size: 20px;
	--ax-ts-segment-space: 16px;
	--ax-ts-segment-gap: 8px;
	--ax-ts-group-space: 2px;

	/* Pressed morphs and the connected group's inner corners come from the
	 * shape scale's unitless values, which is what they are for. */
	--ax-ts-pressed-morph: var(--md-sys-shape-corner-value-small, 8px);
	--ax-ts-inner-corner: var(--md-sys-shape-corner-value-small, 8px);
	--ax-ts-pressed-inner-corner: var(--md-sys-shape-corner-value-extra-small, 4px);

	/* Filled: the plugin's default style. */
	--ax-ts-unselected-bg: var(--md-sys-color-surface-container);
	--ax-ts-unselected-fg: var(--md-sys-color-on-surface-variant);
	--ax-ts-selected-bg: var(--md-sys-color-primary);
	--ax-ts-selected-fg: var(--md-sys-color-on-primary);

	display: inline-flex;
	align-items: center;
}

.ax-ts__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--ax-ts-segment-gap);
	block-size: var(--ax-ts-height);
	border: 0;
	cursor: pointer;
	font-family: var(--md-sys-typescale-label-large-font);
	font-size: var(--md-sys-typescale-label-large-size);
	font-weight: var(--md-sys-typescale-label-large-weight);
	letter-spacing: var(--md-sys-typescale-label-large-tracking);
	line-height: var(--md-sys-typescale-label-large-line-height);
	/* No blue flash on tap: it is the wrong shape and the wrong colour for a
	 * pill, and nothing is lost - the pressed state layer answers the touch and
	 * :focus-visible still rings for the keyboard. */
	-webkit-tap-highlight-color: transparent;
	transition:
		border-radius var(--md-sys-motion-curve-fast-spatial-duration) var(--md-sys-motion-curve-fast-spatial),
		background-color var(--md-sys-motion-curve-fast-effects-duration) var(--md-sys-motion-curve-fast-effects);
}

/* Keyboard only. A pointer press should not leave a ring behind it. */
.ax-ts__button:focus-visible {
	outline: var(--md-focus-ring-width) solid var(--md-sys-color-secondary);
	outline-offset: var(--md-focus-ring-outward-offset);
}

.ax-ts__button:focus:not(:focus-visible) {
	outline: none;
}

.ax-ts__sr {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* --- Cycle: M3 standard icon button --------------------------- */

.ax-ts__cycle {
	inline-size: var(--ax-ts-height);
	padding: 0;
	border-radius: var(--ax-ts-pill);
	background-color: transparent;
	color: var(--ax-ts-unselected-fg);
}

.ax-ts__cycle .material-symbols-outlined {
	font-size: var(--ax-ts-icon-size);
}

/* Hover is gated: on a touch screen it sticks after the finger leaves, and the
 * pressed layer has already answered the tap. */
@media (hover: hover) {
	.ax-ts__cycle:hover {
		background-color: color-mix(in srgb, currentColor calc(var(--md-sys-state-hover-state-layer-opacity) * 100%), transparent);
	}
}

.ax-ts__cycle:focus-visible {
	background-color: color-mix(in srgb, currentColor calc(var(--md-sys-state-focus-state-layer-opacity) * 100%), transparent);
}

.ax-ts__cycle:active {
	background-color: color-mix(in srgb, currentColor calc(var(--md-sys-state-pressed-state-layer-opacity) * 100%), transparent);
	border-radius: var(--ax-ts-pressed-morph);
}

/* Once a scheme has been chosen the symbol carries it, rather than the button
 * growing a container. Material's Standard icon-button treatment. */
.ax-ts__cycle[data-theme-scheme="light"],
.ax-ts__cycle[data-theme-scheme="dark"] {
	color: var(--md-sys-color-primary);
}

/* FILL is the other half of that, and on this surface it is the whole of the
 * selected state: a cycle button stands alone with nothing to compare against,
 * so filling on hover as well would spend the only signal it has. That is why
 * there is no hover rule here and there is one on the segments below.
 *
 * The axis interpolates rather than snapping, because icons.css registers
 * --md-icon-fill with @property and transitions it. */
.ax-ts__cycle[data-theme-scheme="light"] .material-symbols-outlined,
.ax-ts__cycle[data-theme-scheme="dark"] .material-symbols-outlined {
	--md-icon-fill: 1;
}

/* --- Group: M3 connected button group ------------------------- */

.ax-ts__group {
	display: inline-flex;
	gap: var(--ax-ts-group-space);
}

.ax-ts__segment {
	padding-inline: var(--ax-ts-segment-space);
	border-radius: var(--ax-ts-inner-corner);
	background-color: var(--ax-ts-unselected-bg);
	color: var(--ax-ts-unselected-fg);
}

.ax-ts__segment .material-symbols-outlined {
	font-size: var(--ax-ts-segment-icon-size);
}

/* Only the outer edges of the group are pill-shaped; the seams between
 * segments stay on the shape scale. */
.ax-ts__segment:first-child {
	border-start-start-radius: var(--ax-ts-pill);
	border-end-start-radius: var(--ax-ts-pill);
}

.ax-ts__segment:last-child {
	border-start-end-radius: var(--ax-ts-pill);
	border-end-end-radius: var(--ax-ts-pill);
}

.ax-ts__segment[aria-pressed="true"] {
	background-color: var(--ax-ts-selected-bg);
	color: var(--ax-ts-selected-fg);
}

/* Unconditional, unlike the hover rule below. Gating this one behind a pointer
 * would leave the chosen segment unfilled on a touchscreen, which is the one
 * place the fill is doing real work. */
.ax-ts__segment[aria-pressed="true"] .material-symbols-outlined {
	--md-icon-fill: 1;
}

/* A segment can afford to fill under the cursor where the cycle button cannot:
 * selection here is already carried by the container - the selected one is the
 * only accent among three - so a filling symbol reads as the invitation it is,
 * with the answer to "which is selected" sitting right beside it. */
@media (hover: hover) {
	.ax-ts__segment:hover .material-symbols-outlined {
		--md-icon-fill: 1;
	}
}

@media (hover: hover) {
	.ax-ts__segment:hover {
		background-color: color-mix(in srgb, var(--ax-ts-unselected-fg) calc(var(--md-sys-state-hover-state-layer-opacity) * 100%), var(--ax-ts-unselected-bg));
	}

	.ax-ts__segment[aria-pressed="true"]:hover {
		background-color: color-mix(in srgb, var(--ax-ts-selected-fg) calc(var(--md-sys-state-hover-state-layer-opacity) * 100%), var(--ax-ts-selected-bg));
	}
}

.ax-ts__segment:focus-visible {
	background-color: color-mix(in srgb, var(--ax-ts-unselected-fg) calc(var(--md-sys-state-focus-state-layer-opacity) * 100%), var(--ax-ts-unselected-bg));
}

.ax-ts__segment[aria-pressed="true"]:focus-visible {
	background-color: color-mix(in srgb, var(--ax-ts-selected-fg) calc(var(--md-sys-state-focus-state-layer-opacity) * 100%), var(--ax-ts-selected-bg));
}

/* Pressed pulls every corner in, except the two that hold the group's outer
 * edge - those stay pill so the group keeps its silhouette while a segment
 * squeezes inside it. */
.ax-ts__segment:active {
	background-color: color-mix(in srgb, var(--ax-ts-unselected-fg) calc(var(--md-sys-state-pressed-state-layer-opacity) * 100%), var(--ax-ts-unselected-bg));
	border-radius: var(--ax-ts-pressed-inner-corner);
}

.ax-ts__segment[aria-pressed="true"]:active {
	background-color: color-mix(in srgb, var(--ax-ts-selected-fg) calc(var(--md-sys-state-pressed-state-layer-opacity) * 100%), var(--ax-ts-selected-bg));
	border-radius: var(--ax-ts-pressed-inner-corner);
}

.ax-ts__segment:first-child:active {
	border-start-start-radius: var(--ax-ts-pill);
	border-end-start-radius: var(--ax-ts-pill);
}

.ax-ts__segment:last-child:active {
	border-start-end-radius: var(--ax-ts-pill);
	border-end-end-radius: var(--ax-ts-pill);
}

@media (prefers-reduced-motion: reduce) {
	.ax-ts__button {
		transition: none;
	}
}
