sh-code-example {
	--sh-code-example-border-color: var(--sh-color-neutral-0);
	--sh-code-example-background-color: var(--sh-color-neutral-100);

	background-color: var(--sh-code-example-background-color);
	border: 2px solid var(--sh-code-example-border-color);
	box-shadow: 4px 4px 0 0 var(--sh-code-example-border-color);

	/* Preview */

	&::part(preview) {
		padding: var(--sh-space-lg);
	}

	/* Header and copy button — mirror `code-block.css` (the global `sh-code-block` selector cannot
	   pierce this component's shadow DOM, so they are restated through the forwarded parts). */

	&::part(code-toolbar) {
		padding: var(--sh-space-xs);
		background-color: var(--sh-color-neutral-100);
		border-block-end: 2px solid var(--sh-code-example-border-color);
	}

	&::part(copy-button) {
		min-inline-size: 2rem;
		min-block-size: 2rem;
		padding: var(--sh-space-xs);
		color: var(--sh-color-neutral-0);
		background-color: transparent;
	}

	&::part(copy-button):hover {
		background-color: var(--sh-color-neutral-80);
	}

	&::part(copy-button):focus-visible {
		outline: var(--sh-focus-outline);
		outline-offset: calc(var(--sh-focus-outline-offset) * -1);
	}

	&::part(copy-icon) {
		--icon-size: 1.125rem;
	}

	/* Code — collapsible source region; the nested sh-code-block is themed via its forwarded parts and
	   custom properties (custom properties inherit through the shadow boundary). */

	&::part(code) {
		border-block-start: 2px solid var(--sh-code-example-border-color);
	}

	&::part(code-block) {
		/* Monospace stack consumed by the code block's [part="code"]. */
		--font-family: monospace;

		/* Token palette — mirrors `code-block.css` (the global `sh-code-block` selector cannot pierce
		   this component's shadow DOM, so the palette is restated on the nested instance). */
		--token-comment: var(--sh-color-neutral-40);
		--token-string: var(--sh-color-success-20);
		--token-keyword: var(--sh-color-info-50);
		--token-number: var(--sh-color-warning-20);
		--token-boolean: var(--sh-color-warning-20);
		--token-function: var(--sh-color-info-20);
		--token-operator: var(--sh-color-neutral-30);
		--token-punctuation: var(--sh-color-neutral-30);
		--token-tag: var(--sh-color-danger-20);
		--token-attr-name: var(--sh-color-warning-20);
		--token-attr-value: var(--sh-color-success-20);
		--token-property: var(--sh-color-info-50);
		--token-selector: var(--sh-color-danger-20);
		--token-at-rule: var(--sh-color-info-50);
		/* No hue is left for types, and the darkest tones read as plain text: mix two hues into a violet. */
		--token-type: color-mix(in oklch, var(--sh-color-info-50) 55%, var(--sh-color-danger-50));
		--token-regexp: var(--sh-color-danger-20);
		--token-variable: var(--sh-color-warning-20);
		--token-inserted: var(--sh-color-success-20);
		--token-deleted: var(--sh-color-danger-20);

		color: var(--sh-color-neutral-0);
		background-color: var(--sh-color-neutral-90);
	}

	&::part(code-pre) {
		padding: 1rem;
		line-height: 1.5;
	}

	&::part(code-pre):focus-visible {
		outline: var(--sh-focus-outline);
		outline-offset: calc(var(--sh-focus-outline-offset) * -1);
	}

	/* Toggle */

	&::part(toggle) {
		padding-block: var(--sh-space-xs);
		padding-inline: var(--sh-space-md);
		font-weight: 700;
		color: var(--sh-color-neutral-0);
		background-color: var(--sh-color-neutral-100);
		border-block-start: 2px solid var(--sh-code-example-border-color);
	}

	&::part(toggle):hover {
		background-color: var(--sh-color-neutral-90);
	}

	&::part(toggle-icon) {
		--icon-size: 1.125rem;
	}
}

/* Motion */

@media (prefers-reduced-motion: no-preference) {
	sh-code-example::part(copy-button),
	sh-code-example::part(toggle) {
		transition: background-color 100ms ease;
	}
}
