/**
 * Gravity Forms — Rating field
 *
 * Markup is rendered by inc/gf-rating-field.php.
 *
 * The whole interaction is CSS. Real radio inputs sit visually hidden next to
 * their labels; `:has()` lets a label know whether a *later* sibling input is
 * checked, which is what gives us the "fill everything up to here" behaviour
 * without any JavaScript.
 *
 * Every rule is scoped under `.orbit-rating` on purpose. LiteSpeed combines
 * this file near the top of a ~178KB bundle, so all of the theme's form and
 * SVG styles load *after* it; the extra class keeps a stray `.gform_wrapper
 * label` or ` svg` rule from winning on source order.
 *
 * Colours come from theme.json presets with literal fallbacks, so the field
 * still looks right inside the block editor and the GF form editor where the
 * preset custom properties aren't always present.
 */

.orbit-rating {
	/* Filled star / selected pill. */
	--orbit-rating-color: var(--wp--preset--color--quaternary, #fdc41f);
	/* Unfilled star / pill — dimmed against whatever it sits on. */
	--orbit-rating-empty: currentColor;
	--orbit-rating-empty-opacity: 0.3;
	/* Number text colour once a pill is filled. */
	--orbit-rating-on-color: var(--wp--preset--color--septenary, #382678);
	--orbit-rating-size: 2.5rem;
	--orbit-rating-gap: 0.375rem;

	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem 1rem;
}

/* ---------------------------------------------------------------------------
 * Scale
 * ------------------------------------------------------------------------ */

.orbit-rating .orbit-rating__scale {
	display: flex;
	flex-wrap: nowrap;
	align-items: center;
	gap: var(--orbit-rating-gap);
	/* Kill the whitespace gaps between inline-level labels. */
	line-height: 0;
	margin: 0;
	padding: 0;
}

/* Visually hidden, but still in the tab order and still announced — this is
   what gives us free arrow-key navigation between the options. */
.orbit-rating .orbit-rating__input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	white-space: nowrap;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	/* Some themes force radios to display:block at a set size. */
	min-width: 0;
	min-height: 0;
	appearance: none;
	-webkit-appearance: none;
}

.orbit-rating .orbit-rating__item {
	/* Every mark reads this to decide whether it's on or off. */
	--mark: var(--orbit-rating-empty);
	--mark-opacity: var(--orbit-rating-empty-opacity);

	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* Fixed size, never allowed to grow, shrink or wrap onto a new line. */
	flex: 0 0 auto;
	width: var(--orbit-rating-size, 2.5rem);
	height: var(--orbit-rating-size, 2.5rem);
	max-width: var(--orbit-rating-size, 2.5rem);
	max-height: var(--orbit-rating-size, 2.5rem);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
	line-height: 0;
	cursor: pointer;
	transition: transform 0.12s ease;
	-webkit-tap-highlight-color: transparent;
}

/* Screen-reader-only text inside each label ("3 out of 5 — Very satisfied"). */
.orbit-rating .orbit-rating__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	white-space: nowrap;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
}

/* ---------------------------------------------------------------------------
 * Marks
 * ------------------------------------------------------------------------ */

.orbit-rating .orbit-rating__star {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	fill: var(--mark);
	opacity: var(--mark-opacity);
	transition: fill 0.12s ease, opacity 0.12s ease;
}

.orbit-rating .orbit-rating__number {
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	border: 2px solid var(--mark);
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	line-height: 1;
	opacity: var(--mark-opacity);
	transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}

/* ---------------------------------------------------------------------------
 * Filled state — the selected mark and everything before it.
 *
 * Rule 1: the label immediately after the checked input (the selection itself).
 * Rule 2: any label that has a checked input somewhere after it (everything to
 *         its left, since `~` only looks forward).
 * ------------------------------------------------------------------------ */

.orbit-rating .orbit-rating__input:checked + .orbit-rating__item,
.orbit-rating .orbit-rating__item:has(~ .orbit-rating__input:checked) {
	--mark: var(--orbit-rating-color);
	--mark-opacity: 1;
}

.orbit-rating .orbit-rating__input:checked + .orbit-rating__item .orbit-rating__number,
.orbit-rating .orbit-rating__item:has(~ .orbit-rating__input:checked) .orbit-rating__number {
	background: var(--orbit-rating-color);
	color: var(--orbit-rating-on-color);
}

/* ---------------------------------------------------------------------------
 * Hover preview — mirrors Microsoft Forms: hovering shows what you'd get,
 * temporarily overriding the current selection.
 *
 * These rules must come *after* the checked rules; the "clear" rule carries
 * the same specificity and wins on source order alone.
 *
 * Gated behind `hover: hover` so the preview never sticks on touch screens.
 * ------------------------------------------------------------------------ */

@media (hover: hover) {
	/* While hovering anywhere on the scale, clear the committed selection... */
	.orbit-rating .orbit-rating__scale:hover .orbit-rating__item {
		--mark: var(--orbit-rating-empty);
		--mark-opacity: var(--orbit-rating-empty-opacity);
	}

	.orbit-rating .orbit-rating__scale:hover .orbit-rating__item .orbit-rating__number {
		background: transparent;
		color: inherit;
	}

	/* ...then light up the hovered mark and everything before it. */
	.orbit-rating .orbit-rating__scale:hover .orbit-rating__item:hover,
	.orbit-rating .orbit-rating__scale:hover .orbit-rating__item:has(~ .orbit-rating__item:hover) {
		--mark: var(--orbit-rating-color);
		--mark-opacity: 1;
	}

	.orbit-rating .orbit-rating__scale:hover .orbit-rating__item:hover .orbit-rating__number,
	.orbit-rating .orbit-rating__scale:hover .orbit-rating__item:has(~ .orbit-rating__item:hover) .orbit-rating__number {
		background: var(--orbit-rating-color);
		color: var(--orbit-rating-on-color);
	}

	.orbit-rating .orbit-rating__item:hover {
		transform: scale(1.12);
	}
}

/* ---------------------------------------------------------------------------
 * Keyboard focus
 * ------------------------------------------------------------------------ */

.orbit-rating .orbit-rating__input:focus-visible + .orbit-rating__item {
	outline: 2px solid var(--orbit-rating-color);
	outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
 * End labels
 * ------------------------------------------------------------------------ */

.orbit-rating .orbit-rating__end {
	flex: 0 1 auto;
	font-size: 0.875rem;
	line-height: 1.3;
	opacity: 0.75;
}

/* ---------------------------------------------------------------------------
 * Validation
 * ------------------------------------------------------------------------ */

.gfield_error .orbit-rating {
	--orbit-rating-empty-opacity: 0.55;
}

/* ---------------------------------------------------------------------------
 * Responsive — longer scales need smaller marks, and on narrow screens the end
 * labels drop below the row and split to opposite edges.
 * ------------------------------------------------------------------------ */

.orbit-rating--levels-7,
.orbit-rating--levels-8,
.orbit-rating--levels-9,
.orbit-rating--levels-10 {
	--orbit-rating-size: 2rem;
	--orbit-rating-gap: 0.25rem;
}

@media (max-width: 600px) {
	.orbit-rating {
		--orbit-rating-size: 2.125rem;
		--orbit-rating-gap: 0.25rem;
	}

	.orbit-rating--has-ends {
		display: grid;
		grid-template-columns: 1fr auto;
		gap: 0.5rem;
	}

	.orbit-rating--has-ends .orbit-rating__scale {
		grid-column: 1 / -1;
		order: -1;
		justify-content: space-between;
	}

	.orbit-rating .orbit-rating__end--low {
		justify-self: start;
	}

	.orbit-rating .orbit-rating__end--high {
		grid-column: 2;
		justify-self: end;
		text-align: right;
	}

	.orbit-rating--levels-9,
	.orbit-rating--levels-10 {
		--orbit-rating-size: 1.75rem;
	}
}

/* ---------------------------------------------------------------------------
 * Admin — the GF form editor and entry detail sit on a light background, so
 * the empty marks need a real colour rather than an alpha of white.
 * ------------------------------------------------------------------------ */

.wp-admin .orbit-rating {
	--orbit-rating-empty: #6b7280;
	--orbit-rating-empty-opacity: 0.45;
	color: #1e1e1e;
}

@media (prefers-reduced-motion: reduce) {
	.orbit-rating .orbit-rating__item,
	.orbit-rating .orbit-rating__star,
	.orbit-rating .orbit-rating__number {
		transition: none;
	}

	.orbit-rating .orbit-rating__item:hover {
		transform: none;
	}
}
