/**
 * `tr-embedbadge` — the "Featured on TiorAI" embed block.
 *
 * One bordered panel, split into reading matter on the left and a control panel
 * on the right. Every value is a theme token; the only literals are the three
 * stage fills, which reproduce the badge artwork's own baked-in backgrounds and
 * therefore cannot follow the page theme.
 *
 * BUILT FOR HEIGHT. The first version stacked heading, deck, a 168px
 * checkerboard stage, three bordered variant cards, the snippet and a
 * disclosure, and ran close to 500px on a page that already asks for a lot of
 * scrolling before it. This one is roughly a third shorter: two columns, and the
 * variant choice is one pill row rather than three cards.
 *
 * @package TiorAI
 */

.tr-embedbadge {
	/* The panel is never a `[data-tiorai-section]` target — see the template. */
	--tiorai-embedbadge-gap: clamp(1.25rem, 3vw, var(--space-8, 2rem));

	display: grid;
	gap: var(--tiorai-embedbadge-gap);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-2xl, 1.25rem);
	background: var(--surface-card, var(--color-bg-primary));
	padding: clamp(1.25rem, 3vw, var(--space-8, 2rem));
}

/*
 * The panel takes the wider share. It holds a 260px badge, a pill row and a
 * code block that has to stay readable; the intro is two short paragraphs.
 */
@media (min-width: 901px) {
	.tr-embedbadge {
		grid-template-columns: minmax(0, 0.85fr) minmax(360px, 1.15fr);
		align-items: start;
	}
}

/* ==========================================================================
   Left — intro
   ========================================================================== */

/*
 * LEFT: what the badge IS — heading, deck, and the badge itself on its stage
 * with the one line that describes it.
 * RIGHT: everything you DO — the style pills, the format tabs, the copy button,
 * the snippet, and how to install it.
 *
 * The pills sit with the code rather than with the preview, and the split works
 * because the choice has a visible result on BOTH sides: pressing "Dark" repaints
 * the badge on the left and rewrites the `src` in the snippet on the right, so
 * the control is never acting on something the reader cannot see.
 *
 * `max-width` is off the column: it carries a 260px badge, not just two
 * paragraphs. The deck keeps its own measure instead.
 */
.tr-embedbadge__intro {
	min-width: 0;
	display: grid;
	gap: var(--space-3, 0.75rem);
	align-content: start;
	justify-items: start;
}

.tr-embedbadge__heading {
	margin: 0;
	font-size: clamp(1.35rem, 2.5vw, var(--font-size-2xl, 1.5rem));
	font-weight: var(--font-weight-bold, 700);
	line-height: var(--line-height-tight, 1.25);
	letter-spacing: -0.01em;
	color: var(--color-text-primary);
}

.tr-embedbadge__deck {
	margin: 0;
	max-width: 46ch;
	font-size: var(--font-size-sm, 0.875rem);
	line-height: var(--line-height-normal, 1.5);
	color: var(--color-text-secondary);
}

/* --- How to install ------------------------------------------------------ */

.tr-embedbadge__help {
	margin-block-start: var(--space-1, 0.25rem);
}

.tr-embedbadge__help-summary {
	cursor: pointer;
	display: inline-block;
	font-size: var(--font-size-sm, 0.875rem);
	font-weight: var(--font-weight-semibold, 600);
	color: var(--color-text-link);
}

.tr-embedbadge__help-summary:hover {
	text-decoration: underline;
}

.tr-embedbadge__help-summary:focus-visible {
	outline: var(--tiorai-focus-ring-width, 2px) solid var(--tiorai-focus-ring-color);
	outline-offset: var(--tiorai-focus-ring-offset, 2px);
	border-radius: var(--radius-sm, 0.25rem);
}

.tr-embedbadge__help-steps {
	margin: var(--space-3, 0.75rem) 0 0;
	padding-inline-start: var(--space-5, 1.25rem);
	display: grid;
	gap: var(--space-2, 0.5rem);
	font-size: var(--font-size-sm, 0.875rem);
	line-height: var(--line-height-normal, 1.5);
	color: var(--color-text-secondary);
}

/* ==========================================================================
   Right — control panel
   ========================================================================== */

.tr-embedbadge__panel {
	min-width: 0;
	display: grid;
	gap: var(--space-2, 0.5rem);
	justify-items: stretch;
	align-content: start;
}

/* --- Variant pills ------------------------------------------------------- */

.tr-embedbadge__variants {
	margin: 0;
	padding: 0;
	border: 0;
	min-width: 0;
	max-width: 100%;
}

/*
 * The segmented track. The radios are visually hidden inside it and the labels
 * are the pills, which is what keeps the native group semantics — arrow keys,
 * "1 of 3", and a checked state the browser owns.
 */
.tr-embedbadge__pills {
	display: inline-flex;
	padding: 3px;
	border: 1px solid var(--border-default);
	border-radius: var(--radius-full, 9999px);
	background: var(--surface-sunken, var(--color-bg-tertiary));
}

.tr-embedbadge__radio {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	margin: 0;
	pointer-events: none;
}

.tr-embedbadge__pill {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* 34px tall in a 40px track: a real touch target without a tall row. */
	min-height: 2.125rem;
	padding-inline: var(--space-4, 1rem);
	border-radius: var(--radius-full, 9999px);
	cursor: pointer;
	font-size: var(--font-size-xs, 0.75rem);
	font-weight: var(--font-weight-semibold, 600);
	color: var(--color-text-secondary);
	transition: background-color 150ms ease-out, color 150ms ease-out;
}

.tr-embedbadge__pill:hover {
	color: var(--color-text-primary);
}

.tr-embedbadge__radio:checked + .tr-embedbadge__pill {
	background: var(--color-primary);
	color: var(--color-text-on-brand);
}

.tr-embedbadge__radio:focus-visible + .tr-embedbadge__pill {
	outline: var(--tiorai-focus-ring-width, 2px) solid var(--tiorai-focus-ring-color);
	outline-offset: var(--tiorai-focus-ring-offset, 2px);
}

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

/* --- Preview stage -------------------------------------------------------

   The stage reproduces the badge's own baked-in background so the visitor sees
   the fill they are choosing, and a hairline so a white badge on a white stage
   still has an edge. The three fills are literals because they belong to the
   SVG files, not to the page: a stage that followed the theme would show a dark
   badge on a dark ground and tell the visitor nothing.
   ------------------------------------------------------------------------- */

/*
 * Sized to the badge, not to the column. A 260px badge floating in the middle of
 * a 640px white box reads as an empty panel with something in it; hugging the
 * artwork makes the box read as the badge's own edge, which is what the visitor
 * is being shown. It sits on the reading edge, under the pill row that changes
 * it.
 */
.tr-embedbadge__stage {
	display: grid;
	place-items: center;
	max-width: 100%;
	padding: var(--space-3, 0.75rem);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-lg, 0.75rem);
	background-color: #ffffff;
	transition: background-color 180ms ease-out;
}

.tr-embedbadge__stage[data-variant="neutral"] {
	background-color: #e2e8f0;
}

.tr-embedbadge__stage[data-variant="dark"] {
	background-color: #1e293b;
}

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

.tr-embedbadge__preview {
	display: block;
	width: 260px;
	max-width: 100%;
	height: auto;
}

/*
 * `[hidden]` has to be restated, and this is not defensive style.
 *
 * The attribute's `display: none` comes from the UA stylesheet, where it has
 * effectively zero specificity — so the `display: block` one line above WINS and
 * all three previews render stacked. Measured: that is exactly what the block
 * shipped on the first build.
 *
 * The runtime toggles `hidden` rather than a class precisely because it also
 * removes the element from the accessibility tree, which a class cannot do. That
 * only holds if the attribute keeps its own meaning here.
 */
.tr-embedbadge__preview[hidden] {
	display: none;
}

/* One line, describing the badge on screen, on the same edge as the stage. */
.tr-embedbadge__note {
	margin: 0;
	font-size: var(--font-size-xs, 0.75rem);
	line-height: var(--line-height-snug, 1.375);
	color: var(--color-text-tertiary);
}

/* --- Snippet ------------------------------------------------------------- */

.tr-embedbadge__snippet {
	display: grid;
	gap: var(--space-2, 0.5rem);
	min-width: 0;
}

.tr-embedbadge__snippet-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-3, 0.75rem);
}

.tr-embedbadge__formats {
	display: inline-flex;
	padding: 3px;
	border: 1px solid var(--border-default);
	border-radius: var(--radius-full, 9999px);
	background: var(--surface-sunken, var(--color-bg-tertiary));
}

.tr-embedbadge__format {
	appearance: none;
	border: 0;
	background: transparent;
	cursor: pointer;
	padding: 0.3rem var(--space-4, 1rem);
	border-radius: var(--radius-full, 9999px);
	font-family: inherit;
	font-size: var(--font-size-xs, 0.75rem);
	font-weight: var(--font-weight-semibold, 600);
	color: var(--color-text-secondary);
	transition: background-color 150ms ease-out, color 150ms ease-out;
}

.tr-embedbadge__format:hover {
	color: var(--color-text-primary);
}

.tr-embedbadge__format.is-active {
	background: var(--surface-card, var(--color-bg-primary));
	color: var(--color-text-primary);
	box-shadow: var(--shadow-sm);
}

.tr-embedbadge__format:focus-visible {
	outline: var(--tiorai-focus-ring-width, 2px) solid var(--tiorai-focus-ring-color);
	outline-offset: var(--tiorai-focus-ring-offset, 2px);
}

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

.tr-embedbadge__copy {
	flex: 0 0 auto;
	gap: var(--space-2, 0.5rem);
}

.tr-embedbadge__copy.is-done {
	background: var(--color-success);
	border-color: var(--color-success);
	color: var(--color-text-on-success);
}

.tr-embedbadge__copy.is-fail {
	background: var(--color-danger);
	border-color: var(--color-danger);
	color: var(--color-text-on-danger);
}

.tr-embedbadge__copy-icon {
	flex: 0 0 auto;
}

/*
 * `pre-wrap` + `break-word`, so a long permalink wraps inside the panel instead
 * of opening a horizontal scrollbar. A code block that scrolls sideways on a
 * phone is a snippet a visitor cannot read before they copy it.
 *
 * The type is a step smaller than the first build and the line-height a step
 * tighter: this is a block to be copied, not read, and the four lines it used to
 * take were four lines of section height.
 */
.tr-embedbadge__code {
	margin: 0;
	padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-md, 0.625rem);
	background: var(--surface-sunken, var(--color-bg-tertiary));
	font-family: var(--font-family-mono);
	font-size: 0.6875rem;
	line-height: 1.6;
	color: var(--color-text-secondary);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	max-width: 100%;
}

.tr-embedbadge__code code {
	font: inherit;
	color: inherit;
	background: none;
	padding: 0;
}

/*
 * The live region reserves no height. It is empty until a copy happens, and a
 * permanently blank 1.25em line under the code block was 20px of nothing on
 * every page view.
 */
.tr-embedbadge__status {
	margin: 0;
	font-size: var(--font-size-xs, 0.75rem);
	color: var(--color-success);
}

.tr-embedbadge__status:empty {
	display: none;
}

/* ==========================================================================
   Narrow
   ========================================================================== */

@media (max-width: 480px) {
	/*
	 * The pill row is the first thing that runs out of width: three labels plus
	 * padding need about 240px, and at 320px the track would overflow the panel.
	 * Stretching it to the full width keeps the three pills equal and on one row.
	 */
	.tr-embedbadge__variants {
		justify-self: stretch;
	}

	.tr-embedbadge__pills {
		display: flex;
	}

	.tr-embedbadge__pill {
		flex: 1 1 0;
		padding-inline: var(--space-2, 0.5rem);
	}

	.tr-embedbadge__snippet-head {
		align-items: stretch;
		flex-direction: column;
	}

	.tr-embedbadge__formats {
		align-self: start;
	}

	.tr-embedbadge__copy {
		justify-content: center;
	}
}
