/*
 * WH LMS — front-end styling.
 *
 * The rule this file lives by: the theme owns colour, typography, spacing,
 * containers and buttons. The LMS owns course-specific components and nothing
 * else. Where the theme already provides something, the plugin uses it rather
 * than drawing its own version next to it.
 *
 * Every selector is scoped under .wh-lms. This stylesheet never touches body,
 * h1-h6, p, a, button, input, table or any other bare element: it loads inside
 * somebody else's design and must not redecorate it.
 *
 * Colour strategy, in order of preference:
 *   1. a theme token, when the theme exposes one   var(--primary, …)
 *   2. currentColor, derived with color-mix        borders, surfaces, muted text
 *   3. a literal                                   never, for anything structural
 *
 * currentColor is what makes this work on an unknown theme. A hardcoded
 * near-black is invisible on a dark theme, and prefers-color-scheme does not
 * help — a theme with its own dark toggle can be dark while the OS is light.
 * Deriving from the inherited text colour needs no detection at all and is
 * correct in both, which is why there is no dark-mode block in this file.
 */

.wh-lms {
	/* Typography is inherited outright — the LMS introduces no font of its own. */
	--wh-lms-muted: color-mix(in srgb, currentColor 68%, transparent);
	--wh-lms-border: color-mix(in srgb, currentColor 18%, transparent);
	--wh-lms-surface: color-mix(in srgb, currentColor 4%, transparent);
	--wh-lms-subtle: color-mix(in srgb, currentColor 7%, transparent);

	/* Theme tokens where offered, with neutral fallbacks. */
	--wh-lms-accent: var(--primary, currentColor);
	--wh-lms-radius: var(--radius-lg, 0.75rem);
	--wh-lms-radius-lg: var(--radius-2xl, 1rem);

	/* Spacing scale, expressed in rem so it tracks the theme's root size. */
	--wh-lms-gap: 1.25rem;
	--wh-lms-block: 2.5rem;

	color: inherit;
	font-family: inherit;
}

/*
 * A browser without color-mix would resolve those tokens to nothing, taking the
 * borders and surfaces with them. Give it flat neutrals instead.
 */
@supports not (color: color-mix(in srgb, currentColor 50%, transparent)) {
	.wh-lms {
		--wh-lms-muted: inherit;
		--wh-lms-border: rgb(128 128 128 / 35%);
		--wh-lms-surface: transparent;
		--wh-lms-subtle: rgb(128 128 128 / 8%);
	}
}

/* =========================================================================
   Fallback layout primitives

   Only used when the theme has NOT declared wh-lms support. With support
   declared, the theme's own container/section/grid classes are emitted instead
   and none of these apply — which is why they are conservative.
   ====================================================================== */

.wh-lms-section {
	padding-block: var(--wh-lms-block);
}

.wh-lms-container {
	width: 100%;
	max-width: var(--container, 75rem);
	margin-inline: auto;
	padding-inline: clamp(1rem, 4vw, 1.5rem);
}

.wh-lms-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
	gap: var(--wh-lms-gap);
}

/*
 * Nothing inside the LMS may exceed its column. Grid and flex children default
 * to min-width:auto, refuse to shrink below their content, and push the page
 * into horizontal overflow on a narrow screen — the single most common way a
 * plugin breaks a theme on mobile.
 */
.wh-lms,
.wh-lms * {
	min-width: 0;
}

.wh-lms img,
.wh-lms video,
.wh-lms iframe {
	max-width: 100%;
	height: auto;
}

/* =========================================================================
   Page furniture
   ====================================================================== */

.wh-lms-page-header {
	margin-bottom: var(--wh-lms-block);
}

.wh-lms-page-title {
	margin: 0 0 0.5rem;
}

.wh-lms-page-lead,
.wh-lms-eyebrow {
	margin: 0;
	color: var(--wh-lms-muted);
}

.wh-lms-eyebrow {
	font-size: 0.8125rem;
	text-transform: uppercase;
	letter-spacing: 0.08em;
}

.wh-lms-section-title {
	margin: 0 0 1rem;
	font-size: 1.25rem;
}

.wh-lms-breadcrumbs {
	margin-bottom: 1.25rem;
	font-size: 0.875rem;
	color: var(--wh-lms-muted);
}

.wh-lms-breadcrumbs ol {
	display: flex;
	flex-wrap: wrap;
	gap: 0.375rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.wh-lms-breadcrumbs li + li::before {
	content: "/";
	margin-right: 0.375rem;
	opacity: 0.5;
}

.wh-lms-breadcrumbs a {
	color: inherit;
}

/* =========================================================================
   Course card

   Sits on top of the theme's card class, so border, radius, shadow and hover
   come from the theme. Only the internals are the plugin's.
   ====================================================================== */

.wh-lms-course-card {
	overflow: hidden;
}

.wh-lms-course-card__media {
	display: block;
	aspect-ratio: 16 / 9;
	background: var(--wh-lms-subtle);
}

.wh-lms-course-card__media img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.wh-lms-course-card__body {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	flex: 1;
	padding: 1.25rem;
}

/*
 * The theme's card may already carry padding. Where it does, the card is asked
 * not to double it up on the body.
 */
.wh-card.wh-lms-course-card {
	padding: 0;
}

.wh-lms-course-card__cat {
	margin: 0;
	font-size: 0.75rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--wh-lms-muted);
}

.wh-lms-course-card__title {
	margin: 0;
	font-size: 1.125rem;
	line-height: 1.35;
}

.wh-lms-course-card__title a {
	color: inherit;
	text-decoration: none;
}

.wh-lms-course-card__title a:hover,
.wh-lms-course-card__title a:focus-visible {
	text-decoration: underline;
}

.wh-lms-course-card__excerpt {
	margin: 0;
	font-size: 0.9375rem;
	line-height: 1.6;
	color: var(--wh-lms-muted);
}

.wh-lms-course-card__footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	margin-top: auto;
	padding-top: 0.875rem;
}

.wh-lms-course-card__author {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	font-size: 0.875rem;
	color: var(--wh-lms-muted);
}

.wh-lms-avatar {
	border-radius: 50%;
	flex-shrink: 0;
}

.wh-lms-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem 0.875rem;
	margin: 0;
	padding: 0;
	list-style: none;
	font-size: 0.8125rem;
	color: var(--wh-lms-muted);
}

.wh-lms-meta li + li::before {
	content: "·";
	margin-right: 0.875rem;
	opacity: 0.6;
}

/* =========================================================================
   Single course
   ====================================================================== */

.wh-lms-course-layout {
	display: grid;
	gap: var(--wh-lms-block);
}

/*
 * One column until there is genuinely room for two. The aside comes first in
 * the single-column order because "what is this and what do I get" is the
 * question a phone visitor has before they start scrolling.
 */
@media (min-width: 62rem) {
	.wh-lms-course-layout {
		grid-template-columns: minmax(0, 1fr) 19rem;
		align-items: start;
	}

	.wh-lms-course-main {
		order: 1;
	}

	.wh-lms-course-aside {
		order: 2;
		position: sticky;
		top: var(--wh-lms-sticky-top, 2rem);
	}
}

.wh-lms-course-media {
	margin: 0 0 var(--wh-lms-gap);
	overflow: hidden;
	border-radius: var(--wh-lms-radius-lg);
}

.wh-lms-course-media img {
	display: block;
	width: 100%;
}

.wh-lms-prose > :first-child {
	margin-top: 0;
}

.wh-lms-prose > :last-child {
	margin-bottom: 0;
}

.wh-lms-curriculum-block {
	margin-top: var(--wh-lms-block);
}

/* Summary aside */

.wh-lms-summary__title {
	margin: 0 0 0.75rem;
	font-size: 1rem;
}

.wh-lms-summary__list {
	margin: 0 0 1.25rem;
	padding: 0;
	list-style: none;
	font-size: 0.9375rem;
}

.wh-lms-summary__list li {
	padding: 0.375rem 0;
	border-bottom: 1px solid var(--wh-lms-border);
}

.wh-lms-summary__list li:last-child {
	border-bottom: 0;
}

.wh-lms-summary__cta {
	display: block;
	width: 100%;
	text-align: center;
}

.wh-card.wh-lms-summary,
.wh-lms-card.wh-lms-summary {
	padding: 1.25rem;
}

.wh-lms-instructor {
	display: flex;
	align-items: center;
	gap: 0.625rem;
	margin-top: 1.25rem;
	padding-top: 1.25rem;
	border-top: 1px solid var(--wh-lms-border);
}

.wh-lms-instructor__label {
	display: block;
	font-size: 0.75rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--wh-lms-muted);
}

.wh-lms-instructor__name {
	display: block;
	font-weight: 600;
}

/* =========================================================================
   Curriculum accordion

   Native <details>/<summary>: keyboard operable, announced correctly, and
   works with JavaScript disabled. A div with a click handler is none of those.
   ====================================================================== */

.wh-lms-curriculum {
	border: 1px solid var(--wh-lms-border);
	border-radius: var(--wh-lms-radius-lg);
	overflow: hidden;
}

.wh-lms-accordion + .wh-lms-accordion {
	border-top: 1px solid var(--wh-lms-border);
}

.wh-lms-accordion__summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.875rem 1.125rem;
	background: var(--wh-lms-subtle);
	cursor: pointer;
	font-weight: 600;
	list-style: none;
}

/* Replace the default marker with one that reflects open state. */
.wh-lms-accordion__summary::-webkit-details-marker {
	display: none;
}

.wh-lms-accordion__title {
	flex: 1;
}

.wh-lms-accordion__title::before {
	content: "▸";
	display: inline-block;
	width: 1em;
	margin-right: 0.25rem;
	transition: transform 0.15s ease;
}

.wh-lms-accordion[open] .wh-lms-accordion__title::before {
	transform: rotate(90deg);
}

.wh-lms-accordion__count {
	flex-shrink: 0;
	font-size: 0.8125rem;
	font-weight: 400;
	color: var(--wh-lms-muted);
}

.wh-lms-accordion__summary:focus-visible {
	outline: 2px solid var(--wh-lms-accent);
	outline-offset: -2px;
}

.wh-lms-curriculum__items {
	margin: 0;
	padding: 0;
	list-style: none;
}

.wh-lms-curriculum__item + .wh-lms-curriculum__item {
	border-top: 1px solid var(--wh-lms-border);
}

.wh-lms-curriculum__row {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem 1.125rem;
	color: inherit;
	text-decoration: none;
	font-size: 0.9375rem;
}

a.wh-lms-curriculum__row:hover {
	background: var(--wh-lms-subtle);
}

a.wh-lms-curriculum__row:focus-visible {
	outline: 2px solid var(--wh-lms-accent);
	outline-offset: -2px;
}

.wh-lms-curriculum__item.is-locked .wh-lms-curriculum__row {
	cursor: default;
	color: var(--wh-lms-muted);
}

/* A word, not an icon font and not a colour swatch. */
.wh-lms-curriculum__type {
	flex-shrink: 0;
	min-width: 4.5rem;
	font-size: 0.6875rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--wh-lms-muted);
}

.wh-lms-curriculum__name {
	flex: 1;
}

.wh-lms-curriculum__time {
	flex-shrink: 0;
	font-size: 0.8125rem;
	color: var(--wh-lms-muted);
	font-variant-numeric: tabular-nums;
}

.wh-lms-curriculum__empty {
	margin: 0;
	padding: 0.875rem 1.125rem;
	font-size: 0.875rem;
	color: var(--wh-lms-muted);
}

/* =========================================================================
   Badges and states
   ====================================================================== */

.wh-lms-badge {
	flex-shrink: 0;
	padding: 0.0625rem 0.4375rem;
	border: 1px solid var(--wh-lms-border);
	border-radius: 999px;
	font-size: 0.6875rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	white-space: nowrap;
	color: var(--wh-lms-muted);
}

.wh-lms-badge--preview {
	border-color: currentcolor;
	color: inherit;
}

.wh-lms-empty {
	padding: 2.5rem 1.5rem;
	border: 1px dashed var(--wh-lms-border);
	border-radius: var(--wh-lms-radius-lg);
	text-align: center;
	color: var(--wh-lms-muted);
}

.wh-lms-empty__title {
	margin: 0 0 0.375rem;
	font-size: 1.0625rem;
	font-weight: 600;
	color: inherit;
}

.wh-lms-empty__actions {
	margin-bottom: 0;
}

/* =========================================================================
   Lesson and topic
   ====================================================================== */

.wh-lms-lesson__meta,
.wh-lms-topic__meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.625rem;
	margin: 0 0 1.25rem;
	font-size: 0.875rem;
	color: var(--wh-lms-muted);
}

.wh-lms-lesson__nav,
.wh-lms-topic__nav {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.625rem;
	margin-top: var(--wh-lms-block);
	padding-top: 1.25rem;
	border-top: 1px solid var(--wh-lms-border);
}

/*
 * Previous sits left, next is pushed right, and "back to course" stays between
 * them — the spatial arrangement carries the meaning, so the direction is
 * readable before the labels are. On a phone the row wraps and each control
 * takes a full line rather than shrinking into an unreadable stack.
 */

.wh-lms-nav__next {
	margin-inline-start: auto;
}

.wh-lms-nav__prev,
.wh-lms-nav__next {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	text-align: start;
}

.wh-lms-nav__label {
	display: flex;
	flex-direction: column;
	line-height: 1.25;
}

.wh-lms-nav__hint {
	font-size: 0.6875rem;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	opacity: 0.7;
}

/* The lesson title is the useful part, but it must not stretch the button. */
.wh-lms-nav__title {
	display: block;
	max-width: 16ch;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.wh-lms-nav__end {
	margin-inline-start: auto;
	font-size: 0.875rem;
	color: var(--wh-lms-muted, #6b7280);
}

.wh-lms-nav__progress {
	flex-basis: 100%;
	margin: 0.25rem 0 0;
	font-size: 0.8125rem;
	font-variant-numeric: tabular-nums;
	color: var(--wh-lms-muted, #6b7280);
}

@media (max-width: 640px) {
	.wh-lms-nav__prev,
	.wh-lms-nav__next,
	.wh-lms-nav__up {
		flex: 1 1 100%;
		justify-content: center;
	}

	.wh-lms-nav__next {
		margin-inline-start: 0;
		order: -1;
	}

	.wh-lms-nav__title {
		max-width: 22ch;
	}
}

.wh-lms-pagination {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-top: var(--wh-lms-block);
}

.wh-lms-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* =========================================================================
   Fallback button

   Only reached when the theme declares no button class. Intentionally plain:
   it should read as "unstyled but tidy", never as a competing design.
   ====================================================================== */

.wh-lms-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.375rem;
	padding: 0.5rem 1rem;
	border: 1px solid transparent;
	border-radius: var(--wh-lms-radius);
	background: var(--wh-lms-accent);
	color: var(--wh-lms-on-accent, #fff);
	font: inherit;
	font-size: 0.9375rem;
	font-weight: 500;
	line-height: 1.4;
	text-decoration: none;
	cursor: pointer;
}

.wh-lms-button--ghost {
	background: transparent;
	border-color: var(--wh-lms-border);
	color: inherit;
}

.wh-lms-button:focus-visible {
	outline: 2px solid var(--wh-lms-accent);
	outline-offset: 2px;
}

/* =========================================================================
   Motion
   ====================================================================== */

@media (prefers-reduced-motion: reduce) {
	.wh-lms *,
	.wh-lms *::before {
		transition: none !important;
		animation: none !important;
	}
}
