/* ============================================================
 * Icon button — static adapter for the proposed core/icon-button.
 *
 * No such block exists. What this renders is the contract one would have to
 * emit, and this repository already ships two of them: the theme switcher's
 * cycle button and its segments. The cycle button is the interesting case -
 * it is an icon button that is deliberately NOT a toggle icon button, because
 * it advances through three schemes and aria-pressed holds two values.
 *
 * Close to Button and not the same. The differences that actually bite:
 *
 *   no label      the accessible name has to come from text nobody can see
 *   icon 24 at S  Button's Small icon is 20
 *   spring        0.6 / 800, against Button's 0.9 / 1400
 *   width         three of them, and only this component has the axis
 *
 * Width changes the space either side of the icon and never the icon. Default
 * width equals the container height at every size, which is what makes the
 * default round icon button a circle rather than a lozenge.
 * ============================================================ */

/* --- The control ---------------------------------------------- */

/* Height and icon are size; inline padding is width. Keeping them apart is
 * what lets one control be Small-narrow and another Small-wide without either
 * touching the glyph. */
.wp-block-axismundi-icon-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	block-size: var(--ax-icon-button-height, 40px);
	position: relative;
	padding-inline: var(--ax-icon-button-space, var(--md-sys-measurement-space100));
	border: 0;
	border-radius: var(--ax-icon-button-shape, 20px);
	background-color: var(--ax-icon-button-container, transparent);
	color: var(--ax-icon-button-content, var(--md-sys-color-on-surface-variant));
	cursor: pointer;
	-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);
}

@media (prefers-reduced-motion: reduce) {
	.wp-block-axismundi-icon-button {
		transition: none;
	}
}

.wp-block-axismundi-icon-button > .material-symbols-outlined {
	flex: 0 0 var(--ax-icon-button-icon, 24px);
	inline-size: var(--ax-icon-button-icon, 24px);
	block-size: var(--ax-icon-button-icon, 24px);
	font-size: var(--ax-icon-button-icon, 24px);
	line-height: 1;
}

/* The name lives here, out of sight and in the tree. An icon button has no
 * label in its anatomy, so this is the only place the name can be, and it is
 * not optional the way a Button's hidden label is. */
.wp-block-axismundi-icon-button .screen-reader-text {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.wp-block-axismundi-icon-button:active {
	border-radius: var(--ax-icon-button-pressed-shape, var(--md-sys-shape-corner-value-small));
}

.wp-block-axismundi-icon-button:focus-visible {
	outline: var(--md-focus-ring-width) solid var(--md-sys-color-secondary);
	outline-offset: var(--md-focus-ring-outward-offset);
}

.wp-block-axismundi-icon-button[aria-disabled="true"],
.wp-block-axismundi-icon-button:disabled {
	background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 10%, transparent);
	border-color: transparent;
	color: color-mix(in srgb, var(--md-sys-color-on-surface) calc(var(--md-sys-state-disabled-state-layer-opacity) * 100%), transparent);
	cursor: not-allowed;
	pointer-events: none;
}

/* --- The 48dp target ------------------------------------------- */

/* M3 asks for a target size, not a container size: "Extra small and small icon
 * buttons must have a target size of 48x48dp or larger." The container keeps
 * its published measurements and the hit area is what grows.
 *
 * Growing the box instead was wrong twice over. It contradicts the spec, which
 * draws XS at 32dp wide, and it erased the one axis this component has that no
 * other does - at XS a 48px floor swallowed narrow, default and wide alike,
 * 28, 32 and 40 all rendering 48, and at S it took two of the three.
 *
 * An absolutely positioned overlay takes no space, so nothing in the layout
 * moves, and it centres on the control it belongs to. max() means the rule can
 * apply to every size: from Medium up the container is already larger and the
 * overlay simply matches it. */
.wp-block-axismundi-icon-button::after {
	content: "";
	position: absolute;
	inset-inline-start: 50%;
	inset-block-start: 50%;
	inline-size: max(100%, 48px);
	block-size: max(100%, 48px);
	translate: -50% -50%;
}

/* --- Size: height, icon, corners ------------------------------- */

/* Small is the fallback above and needs no block. XS and S also carry the 48dp
 * minimum: at default width they measure 32 and 40, so the target rule is not
 * a rounding note - it is the only thing making those two reachable. */
.wp-block-axismundi-icon-button[data-size="xsmall"] {
	--ax-icon-button-height: 32px;
	--ax-icon-button-icon: 20px;
	--ax-icon-button-shape: 16px;
	--ax-icon-button-square-shape: var(--md-sys-shape-corner-value-medium);
	--ax-icon-button-pressed-shape: var(--md-sys-shape-corner-value-small);
	--ax-icon-button-selected-shape: var(--md-sys-shape-corner-value-medium);
	--ax-icon-button-outline-width: 1px;
}

.wp-block-axismundi-icon-button[data-size="medium"] {
	--ax-icon-button-height: 56px;
	--ax-icon-button-icon: 24px;
	--ax-icon-button-shape: 28px;
	--ax-icon-button-square-shape: var(--md-sys-shape-corner-value-large);
	--ax-icon-button-pressed-shape: var(--md-sys-shape-corner-value-medium);
	--ax-icon-button-selected-shape: var(--md-sys-shape-corner-value-large);
	--ax-icon-button-outline-width: 1px;
}

.wp-block-axismundi-icon-button[data-size="large"] {
	--ax-icon-button-height: 96px;
	--ax-icon-button-icon: 32px;
	--ax-icon-button-shape: 48px;
	--ax-icon-button-square-shape: var(--md-sys-shape-corner-value-extra-large);
	--ax-icon-button-pressed-shape: var(--md-sys-shape-corner-value-large);
	--ax-icon-button-selected-shape: var(--md-sys-shape-corner-value-extra-large);
	--ax-icon-button-outline-width: 2px;
}

.wp-block-axismundi-icon-button[data-size="xlarge"] {
	--ax-icon-button-height: 136px;
	--ax-icon-button-icon: 40px;
	--ax-icon-button-shape: 68px;
	--ax-icon-button-square-shape: var(--md-sys-shape-corner-value-extra-large);
	--ax-icon-button-pressed-shape: var(--md-sys-shape-corner-value-large);
	--ax-icon-button-selected-shape: var(--md-sys-shape-corner-value-extra-large);
	--ax-icon-button-outline-width: 3px;
}

/* --- Width: the space either side of the icon ------------------ */

/* Default is the fallback and equals half the difference between height and
 * icon at every size, which is why it always comes out circular. */
.wp-block-axismundi-icon-button[data-width="narrow"] { --ax-icon-button-space: var(--md-sys-measurement-space50); }
.wp-block-axismundi-icon-button[data-width="wide"] { --ax-icon-button-space: 14px; }

.wp-block-axismundi-icon-button[data-size="xsmall"] { --ax-icon-button-space: var(--md-sys-measurement-space75); }
.wp-block-axismundi-icon-button[data-size="xsmall"][data-width="narrow"] { --ax-icon-button-space: var(--md-sys-measurement-space50); }
.wp-block-axismundi-icon-button[data-size="xsmall"][data-width="wide"] { --ax-icon-button-space: var(--md-sys-measurement-space125); }

.wp-block-axismundi-icon-button[data-size="medium"] { --ax-icon-button-space: var(--md-sys-measurement-space200); }
.wp-block-axismundi-icon-button[data-size="medium"][data-width="narrow"] { --ax-icon-button-space: var(--md-sys-measurement-space150); }
.wp-block-axismundi-icon-button[data-size="medium"][data-width="wide"] { --ax-icon-button-space: var(--md-sys-measurement-space300); }

.wp-block-axismundi-icon-button[data-size="large"] { --ax-icon-button-space: var(--md-sys-measurement-space400); }
.wp-block-axismundi-icon-button[data-size="large"][data-width="narrow"] { --ax-icon-button-space: var(--md-sys-measurement-space200); }
.wp-block-axismundi-icon-button[data-size="large"][data-width="wide"] { --ax-icon-button-space: var(--md-sys-measurement-space600); }

.wp-block-axismundi-icon-button[data-size="xlarge"] { --ax-icon-button-space: var(--md-sys-measurement-space600); }
.wp-block-axismundi-icon-button[data-size="xlarge"][data-width="narrow"] { --ax-icon-button-space: var(--md-sys-measurement-space400); }
.wp-block-axismundi-icon-button[data-size="xlarge"][data-width="wide"] { --ax-icon-button-space: 72px; }

/* --- Shape ----------------------------------------------------- */

.wp-block-axismundi-icon-button[data-shape="square"] {
	border-radius: var(--ax-icon-button-square-shape, var(--md-sys-shape-corner-value-medium));
}

/* Selected changes the resting shape, and M3 gives the rule as a contrast
 * rather than a direction: round becomes square, and a square resting shape
 * becomes round. */
.wp-block-axismundi-icon-button[aria-pressed="true"] {
	border-radius: var(--ax-icon-button-selected-shape, var(--md-sys-shape-corner-value-medium));
}

.wp-block-axismundi-icon-button[data-shape="square"][aria-pressed="true"] {
	border-radius: var(--ax-icon-button-shape, 20px);
}

/* --- Colour: four styles, and one of them has no container ----- */

/* Written as a fallback, not a value, because a standard button group hands a
 * Color down to the children that have not chosen one. A value declared on the
 * element would outrank the group's inherited variable - the same cascade trap
 * that pinned every button's icon at 20px. `is-style-*` below is the child
 * choosing, and it wins on specificity, which is Figma's worked example: a
 * group set to Filled holding a tonal icon button. */
.wp-block-axismundi-icon-button {
	--ax-icon-button-container: var(--ax-group-color-container, var(--md-sys-color-primary));
	--ax-icon-button-content: var(--ax-group-color-content, var(--md-sys-color-on-primary));
	--ax-icon-button-state-role: var(--ax-group-color-content, var(--md-sys-color-on-primary));
}

.wp-block-axismundi-icon-button.is-style-tonal {
	--ax-icon-button-container: var(--md-sys-color-secondary-container);
	--ax-icon-button-content: var(--md-sys-color-on-secondary-container);
	--ax-icon-button-state-role: var(--md-sys-color-on-secondary-container);
}

.wp-block-axismundi-icon-button.is-style-outline {
	--ax-icon-button-container: transparent;
	--ax-icon-button-content: var(--md-sys-color-on-surface-variant);
	--ax-icon-button-state-role: var(--md-sys-color-on-surface-variant);
	border: var(--ax-icon-button-outline-width, 1px) solid var(--md-sys-color-outline-variant);
}

/* Standard has no container at rest; the state layer is the only thing that
 * ever paints one. That is why M3 tells you to keep it out of a button group,
 * where a segment needs a box for its seam and its selection. */
.wp-block-axismundi-icon-button.is-style-standard {
	--ax-icon-button-container: transparent;
	--ax-icon-button-content: var(--md-sys-color-on-surface-variant);
	--ax-icon-button-state-role: var(--md-sys-color-on-surface-variant);
}

/* --- Toggle ---------------------------------------------------- */

/* The published toggle table, which differs from the default one for every
 * style: unselected is quieter and selected is louder. */
.wp-block-axismundi-icon-button[aria-pressed] {
	--ax-icon-button-container: var(--ax-button-toggle-unselected-container, var(--md-sys-color-surface-container));
	--ax-icon-button-content: var(--ax-button-toggle-unselected-content, var(--md-sys-color-on-surface-variant));
	--ax-icon-button-state-role: var(--ax-button-toggle-unselected-content, var(--md-sys-color-on-surface-variant));
}

.wp-block-axismundi-icon-button[aria-pressed="true"] {
	--ax-icon-button-container: var(--ax-button-toggle-selected-container, var(--md-sys-color-primary));
	--ax-icon-button-content: var(--ax-button-toggle-selected-content, var(--md-sys-color-on-primary));
	--ax-icon-button-state-role: var(--ax-button-toggle-selected-content, var(--md-sys-color-on-primary));
}

.wp-block-axismundi-icon-button.is-style-tonal[aria-pressed="false"] {
	--ax-icon-button-container: var(--md-sys-color-secondary-container);
	--ax-icon-button-content: var(--md-sys-color-on-secondary-container);
}

.wp-block-axismundi-icon-button.is-style-tonal[aria-pressed="true"] {
	--ax-icon-button-container: var(--md-sys-color-secondary);
	--ax-icon-button-content: var(--md-sys-color-on-secondary);
}

.wp-block-axismundi-icon-button.is-style-outline[aria-pressed="false"] {
	--ax-icon-button-container: transparent;
	--ax-icon-button-content: var(--md-sys-color-on-surface-variant);
}

.wp-block-axismundi-icon-button.is-style-outline[aria-pressed="true"] {
	--ax-icon-button-container: var(--md-sys-color-inverse-surface);
	--ax-icon-button-content: var(--md-sys-color-inverse-on-surface);
	border-color: transparent;
}

.wp-block-axismundi-icon-button.is-style-standard[aria-pressed="false"] {
	--ax-icon-button-container: transparent;
	--ax-icon-button-content: var(--md-sys-color-on-surface-variant);
}

.wp-block-axismundi-icon-button.is-style-standard[aria-pressed="true"] {
	--ax-icon-button-container: transparent;
	--ax-icon-button-content: var(--md-sys-color-primary);
	--ax-icon-button-state-role: var(--md-sys-color-primary);
}

/* The playground stage is a grid, and a grid stretches its items, so the
 * specimen was rendering 438px wide however the width control was set - the
 * one axis the demo exists to show. Icon buttons size themselves; they must
 * not be stretched to a track. */
.sg-button-group-playground__stage > .wp-block-axismundi-icon-button {
	justify-self: start;
}

/* --- Forced focus ring, for looking at ------------------------- */

/* Figma has a Show focus indicator property because a static file has to draw
 * the ring to show it. The browser owns the real one and :focus-visible only
 * fires for keyboard focus, which a reader inspecting a page is not doing, so
 * the demo forces the same ring rather than describing it. It stores nothing:
 * this is the one control on that panel with no attribute behind it. */
.wp-block-axismundi-icon-button.is-forced-focus {
	outline: var(--md-focus-ring-width) solid var(--md-sys-color-secondary);
	outline-offset: var(--md-focus-ring-outward-offset);
	background-color: color-mix(in srgb, var(--ax-icon-button-state-role) calc(var(--md-sys-state-focus-state-layer-opacity) * 100%), var(--ax-icon-button-container));
}

/* --- State layers and the FILL axis ---------------------------- */

.wp-block-axismundi-icon-button:hover {
	background-color: color-mix(in srgb, var(--ax-icon-button-state-role) calc(var(--md-sys-state-hover-state-layer-opacity) * 100%), var(--ax-icon-button-container));
}

.wp-block-axismundi-icon-button:focus-visible {
	background-color: color-mix(in srgb, var(--ax-icon-button-state-role) calc(var(--md-sys-state-focus-state-layer-opacity) * 100%), var(--ax-icon-button-container));
}

.wp-block-axismundi-icon-button:active {
	background-color: color-mix(in srgb, var(--ax-icon-button-state-role) calc(var(--md-sys-state-pressed-state-layer-opacity) * 100%), var(--ax-icon-button-container));
}

/* "In toggle buttons, use the outlined style of an icon for the unselected
 * state, and the filled style for the selected state." One glyph, one axis. */
.wp-block-axismundi-icon-button[aria-pressed="true"] .material-symbols-outlined {
	--md-icon-fill: 1;
}
