/*
 * Student feedback on the front end: the rating block on a course page, and
 * the "report a problem" disclosure under a lesson.
 *
 * SAME RULES AS course-page.css AND step-chrome.css, deliberately. No font
 * family, no type scale, no brand colour - this markup lands inside somebody
 * else's theme, directly under content they wrote, and a plugin that declares
 * its own type is a plugin you can see the seams of.
 *
 * The one colour used anywhere here is the theme's OWN text colour, reduced:
 * color-mix(in srgb, currentColor N%, transparent). It stays legible on a dark
 * theme and a light one without this file detecting either, and it means a
 * course page with real brand character above the fold does not run into a
 * ratings block that belongs to no theme at all. Every use has an
 * @supports not() fallback at the end of the file, the same way both those
 * stylesheets already do.
 *
 * STARS ARE THE ONE EXCEPTION, AND ONLY IN ONE DIRECTION. A filled star at
 * currentColor and an empty one at 25% of it reads correctly on any ground;
 * naming a gold would be this file's first and only brand decision, made on
 * behalf of a theme that did not ask for it.
 */

/* ---------------------------------------------------------------
   Ratings
   --------------------------------------------------------------- */

.tg-rating {
	margin: 2.5rem 0 0;
	padding-top: 1.5rem;
	border-top: 1px solid color-mix(in srgb, currentColor 20%, transparent);
}

.tg-rating__heading {
	margin: 0 0 1rem;
}

.tg-rating__empty {
	margin: 0 0 1rem;
	opacity: 0.7;
}

/*
 * The average on the left, the spread on the right.
 *
 * Two columns where there is room and one where there is not - a breakdown
 * squeezed into 40% of a phone screen is five bars nobody can compare.
 */
.tg-rating__summary {
	display: grid;
	gap: 1.5rem;
	align-items: center;
	margin: 0 0 1.5rem;
	grid-template-columns: 1fr;
}

@media (min-width: 40em) {
	.tg-rating__summary {
		/* minmax(0, ...) on the second column, not 1fr: a grid item's
		   default min-width is auto, which stops the bars shrinking and
		   pushes the whole block wider than its container. */
		grid-template-columns: auto minmax(0, 1fr);
	}
}

.tg-rating__score {
	text-align: center;
}

.tg-rating__average {
	display: block;
	font-size: 2.75em;
	font-weight: 700;
	line-height: 1.1;

	/* Digits that line up between one course and the next. */
	font-variant-numeric: tabular-nums;
}

.tg-rating__outof,
.tg-rating__count {
	display: block;
	font-size: 0.85em;
	opacity: 0.7;
}

.tg-rating__count {
	margin: 0.35em 0 0;
}

/* ---------------------------------------------------------------
   Stars
   --------------------------------------------------------------- */

.tg-rating__stars {
	display: inline-flex;
	gap: 0.1em;
	margin: 0.35em 0 0;
	line-height: 1;
}

.tg-rating__star {
	width: 1em;
	height: 1em;
}

.tg-rating__star--empty {
	opacity: 0.25;
}

/*
 * A half star, without a second icon file.
 *
 * The same star clipped down the middle by a linear-gradient mask: solid on
 * the left half, transparent on the right. Where masks are unsupported it
 * falls through to a whole star at reduced opacity, which is a rounding error
 * on a five-point scale rather than a broken layout.
 */
.tg-rating__star--half {
	opacity: 0.55;
}

@supports (mask-image: linear-gradient(to right, #000 50%, transparent 50%)) {
	.tg-rating__star--half {
		opacity: 1;
		mask-image: linear-gradient(to right, #000 50%, transparent 50%);
		-webkit-mask-image: linear-gradient(to right, #000 50%, transparent 50%);
	}
}

/* ---------------------------------------------------------------
   The spread
   --------------------------------------------------------------- */

.tg-rating__breakdown {
	margin: 0;
	padding: 0;
	list-style: none;
}

.tg-rating__row {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: center;
	gap: 0.75em;
	margin: 0 0 0.4em;
	font-size: 0.9em;
}

.tg-rating__row-label {
	white-space: nowrap;
	opacity: 0.75;
}

.tg-rating__row-count {
	font-variant-numeric: tabular-nums;
	opacity: 0.75;
}

.tg-rating__bar {
	display: block;
	height: 0.5em;
	border-radius: 999px;
	background: color-mix(in srgb, currentColor 12%, transparent);
	overflow: hidden;
}

.tg-rating__bar-fill {
	display: block;
	height: 100%;
	border-radius: inherit;
	background: color-mix(in srgb, currentColor 55%, transparent);
}

/* ---------------------------------------------------------------
   Giving a rating
   --------------------------------------------------------------- */

.tg-rating__form {
	padding: 1.25rem;
	margin: 0 0 1.5rem;
	border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
	border-radius: 8px;
}

.tg-rating__field {
	margin: 0;
	padding: 0;
	border: 0;
}

.tg-rating__legend {
	padding: 0;
	font-weight: 700;
}

/*
 * The picker.
 *
 * The radios are in DESCENDING order in the markup, because CSS sibling
 * selectors only reach FORWARDS: `input:checked ~ label` can fill the chosen
 * star and every lower one only if the lower ones come after it. row-reverse
 * puts them back in the order a reader expects, so one star is on the left.
 *
 * The inputs themselves are the real control - they are moved off-screen, not
 * display:none, which would take them out of the tab order and out of a screen
 * reader's radio group along with them.
 */
.tg-rating__picker {
	display: flex;
	flex-direction: row-reverse;
	justify-content: flex-end;
	gap: 0.15em;
	margin: 0.5em 0 0;
}

.tg-rating__radio {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

.tg-rating__pick {
	cursor: pointer;
	line-height: 1;
	font-size: 1.75em;
	opacity: 0.25;
	transition: opacity 0.12s ease-in-out;
}

.tg-rating__pick .tg-rating__star {
	width: 1em;
	height: 1em;
	display: block;
}

/* Filled: the chosen star and every lower one. */
.tg-rating__radio:checked ~ .tg-rating__pick,
.tg-rating__pick:hover,
.tg-rating__pick:hover ~ .tg-rating__pick {
	opacity: 1;
}

/*
 * While the pointer is anywhere in the picker, the CURRENT choice stops
 * being drawn and the hovered one is drawn instead.
 *
 * Without this, hovering two stars on a rating already set to five leaves
 * all five filled - so the preview says five while the click would give
 * two, which is the one thing a star picker must never do.
 *
 * The order of these three rules is load-bearing. The dimming selector and
 * the first re-filling one have the SAME specificity (0,4,0), so the fill
 * wins only by coming later in the file - moving the dim rule below them
 * would silently empty every star on hover.
 */
.tg-rating__picker:hover .tg-rating__radio:checked ~ .tg-rating__pick {
	opacity: 0.25;
}

.tg-rating__picker:hover .tg-rating__pick:hover,
.tg-rating__picker:hover .tg-rating__pick:hover ~ .tg-rating__pick {
	opacity: 1;
}

/* Keyboard focus has to be visible on a control whose input is off-screen. */
.tg-rating__radio:focus-visible + .tg-rating__pick {
	outline: 2px solid currentColor;
	outline-offset: 2px;
	border-radius: 3px;
}

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

.tg-rating__comment {
	margin: 1rem 0 0;
}

.tg-rating__comment label,
.tg-report__field label {
	display: block;
	margin: 0 0 0.35em;
	font-weight: 600;
}

.tg-rating__comment textarea,
.tg-report__form textarea,
.tg-report__form select {
	width: 100%;
	max-width: 100%;
	box-sizing: border-box;
}

.tg-rating__actions,
.tg-report__actions {
	margin: 1rem 0 0;
}

/*
 * The submit buttons.
 *
 * A boundary, not a colour - the same conclusion step-chrome.css reached
 * after Mark Complete rendered as leftover text on the real site. A theme
 * that styles its own buttons will usually reach these anyway; this is what
 * they look like when it does not.
 */
.tg-rating__submit,
.tg-report__submit {
	padding: 0.6em 1.4em;
	border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
	border-radius: 6px;
	background: color-mix(in srgb, currentColor 8%, transparent);
	color: inherit;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

.tg-rating__submit:hover,
.tg-report__submit:hover {
	background: color-mix(in srgb, currentColor 16%, transparent);
}

/* ---------------------------------------------------------------
   What other students said
   --------------------------------------------------------------- */

.tg-rating__reviews {
	margin: 0;
	padding: 0;
	list-style: none;
}

.tg-rating__review {
	padding: 1rem 0;
	border-top: 1px solid color-mix(in srgb, currentColor 12%, transparent);
}

.tg-rating__review-head {
	display: flex;
	align-items: center;
	gap: 0.6em;
	margin: 0 0 0.4em;
}

.tg-rating__review-name {
	font-weight: 600;
	opacity: 0.8;
}

.tg-rating__review-body {
	margin: 0;
}

/* ---------------------------------------------------------------
   Report a problem
   --------------------------------------------------------------- */

.tg-report {
	margin: 1.5rem 0 0;
	font-size: 0.95em;
}

/*
 * Deliberately understated. This is a control for the small minority of page
 * views where something is actually wrong - drawn as loudly as Mark Complete
 * it would read as an instruction rather than an offer.
 */
.tg-report__summary {
	display: inline-block;
	cursor: pointer;
	opacity: 0.7;
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

.tg-report__summary:hover {
	opacity: 1;
}

.tg-report__form,
.tg-report__already {
	margin: 0.75rem 0 0;
	padding: 1rem 1.25rem;
	border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
	border-radius: 8px;
}

.tg-report__field {
	margin: 0 0 0.9rem;
}

.tg-report__field:last-of-type {
	margin-bottom: 0;
}

/* ---------------------------------------------------------------
   What just happened
   --------------------------------------------------------------- */

/*
 * A LEFT EDGE, NOT A GREEN OR RED FILL. Success and failure are carried by
 * the sentence itself; a coloured panel here would be this file's second
 * brand decision, and a red one lands under a lesson somebody is reading.
 * The weight difference is what separates them at a glance.
 */
.tg-rating__notice,
.tg-report__notice {
	margin: 0 0 1rem;
	padding: 0.6em 0 0.6em 0.9em;
	border-left: 3px solid color-mix(in srgb, currentColor 30%, transparent);
}

.tg-rating__notice--ok,
.tg-report__notice--ok {
	border-left-color: color-mix(in srgb, currentColor 60%, transparent);
	font-weight: 600;
}

.tg-rating__notice--failed,
.tg-report__notice--failed {
	font-weight: 600;
}

/* ---------------------------------------------------------------
   Older browsers
   --------------------------------------------------------------- */

/*
 * Everything above uses color-mix() on the theme's own currentColor. Where it
 * is unavailable a neutral grey stands in - the layout is identical and only
 * the tint stops following the theme. Listed together at the end for
 * readability; @supports not() is what applies them.
 */
@supports not (color: color-mix(in srgb, currentColor 20%, transparent)) {
	.tg-rating,
	.tg-rating__form,
	.tg-report__form,
	.tg-report__already {
		border-color: rgba(128, 128, 128, 0.35);
	}

	.tg-rating__review {
		border-top-color: rgba(128, 128, 128, 0.25);
	}

	.tg-rating__bar {
		background: rgba(128, 128, 128, 0.2);
	}

	.tg-rating__bar-fill {
		background: rgba(128, 128, 128, 0.7);
	}

	.tg-rating__submit,
	.tg-report__submit {
		border-color: rgba(128, 128, 128, 0.45);
		background: rgba(128, 128, 128, 0.12);
	}

	.tg-rating__submit:hover,
	.tg-report__submit:hover {
		background: rgba(128, 128, 128, 0.22);
	}

	.tg-rating__notice,
	.tg-report__notice {
		border-left-color: rgba(128, 128, 128, 0.5);
	}
}
