/*
 * SuperQuest Competitions portal. Inherits the theme's fonts; the custom
 * properties below are the knobs a theme can override on .sqm-portal.
 *
 * The cards, fields and the signed-in panel bring their own light surfaces
 * and text colour, so the portal reads on light and dark sites alike.
 */
.sqm-portal {
	--sqm-accent: #1d5fd1;
	--sqm-accent-text: #fff;
	--sqm-danger: #b42318;
	--sqm-success: #116b3a;
	--sqm-text: #1d2433;
	--sqm-background: #eef1f6; /* the signed-in panel */
	--sqm-card: #fff;
	--sqm-field: #fff;
	--sqm-border: #d5dbe5;
	--sqm-surface: #f3f5f9; /* insets on a card */
	--sqm-shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 2px 8px rgb(16 24 40 / 6%);
	--sqm-radius: 8px;
	--sqm-gap: 1rem;

	max-width: 56rem;
	margin-inline: auto;
	line-height: 1.5;
}

.sqm-portal--signed-in {
	padding: clamp(1rem, 4vw, 2rem);
	border-radius: var(--sqm-radius);
	color: var(--sqm-text);
	background: var(--sqm-background);
}

.sqm-portal *,
.sqm-portal *::before,
.sqm-portal *::after {
	box-sizing: border-box;
}

.sqm-portal h2,
.sqm-portal h3 {
	margin: 0 0 0.75rem;
	line-height: 1.25;
	color: inherit; /* not the site's heading colour, which may not suit the card */
}

.sqm-card {
	max-width: 28rem;
	margin: 0 auto var(--sqm-gap);
	padding: 1.5rem;
	border: 1px solid var(--sqm-border);
	border-radius: var(--sqm-radius);
	color: var(--sqm-text);
	background: var(--sqm-card);
	box-shadow: var(--sqm-shadow);
}

.sqm-portal--signed-in .sqm-card {
	max-width: none;
}

/* One size for the Profile, Password and New group card headings. */
.sqm-portal--signed-in .sqm-card h2,
.sqm-portal--signed-in .sqm-card h3 {
	font-size: 1.4em;
}

.sqm-card--inset {
	background: var(--sqm-surface);
}

/* The rules page's content: longer reading, so the portal's full width. */
.sqm-card--rules {
	max-width: none;
}

.sqm-rules {
	margin-bottom: 1.5rem;
}

.sqm-rules > :first-child {
	margin-top: 0;
}

/* Weighted to outrank the h2/h3 rule above: these are a step below the card's title. */
.sqm-portal .sqm-rules h2,
.sqm-portal .sqm-rules h3 {
	margin: 1.5rem 0 0.5rem;
	font-size: 1.2em;
}

.sqm-rules ol,
.sqm-rules ul {
	padding-left: 1.5rem;
}

.sqm-rules li + li {
	margin-top: 0.4rem;
}

.sqm-rules a {
	color: inherit;
}

.sqm-rules img {
	max-width: 100%;
	height: auto;
}

.sqm-form {
	display: grid;
	gap: 0.75rem;
}

/* A grid would stretch them across the form. */
.sqm-form .sqm-button {
	justify-self: start;
}

.sqm-field {
	display: grid;
	gap: 0.25rem;
	margin: 0;
}

.sqm-field label {
	font-weight: 600;
}

.sqm-field small,
.sqm-muted {
	opacity: 0.75;
}

.sqm-field input,
.sqm-field select {
	width: 100%;
	padding: 0.6rem 0.75rem;
	border: 1px solid var(--sqm-border);
	border-radius: calc(var(--sqm-radius) / 2);
	font: inherit;
	color: inherit;
	background: var(--sqm-field);
}

.sqm-field input:focus-visible,
.sqm-field select:focus-visible,
.sqm-button:focus-visible,
.sqm-link:focus-visible,
.sqm-tab:focus-visible {
	outline: 2px solid var(--sqm-accent);
	outline-offset: 2px;
}

.sqm-check {
	margin: 0;
}

.sqm-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0.6rem 1.1rem;
	border: 1px solid var(--sqm-border);
	border-radius: calc(var(--sqm-radius) / 2);
	font: inherit;
	font-weight: 600;
	color: inherit;
	background: var(--sqm-card);
	cursor: pointer;
}

.sqm-button--primary {
	border-color: var(--sqm-accent);
	color: var(--sqm-accent-text);
	background: var(--sqm-accent);
}

.sqm-button--small {
	padding: 0.3rem 0.7rem;
	font-size: 0.875em;
}

.sqm-button:disabled {
	opacity: 0.6;
	cursor: progress;
}

.sqm-link {
	padding: 0;
	border: 0;
	font: inherit;
	color: inherit; /* the accent can be unreadable on the site's background */
	text-decoration: underline;
	background: none;
	cursor: pointer;
}

.sqm-link--danger {
	color: var(--sqm-danger);
}

.sqm-links {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 0.5rem 1rem;
	margin: 1rem 0 0;
}

.sqm-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem;
	margin: 0;
}

/* Notices bring their own light surface so they read on any theme background. */
.sqm-notice {
	margin: 0 0 1rem;
	padding: 0.6rem 0.9rem;
	border-radius: calc(var(--sqm-radius) / 2);
	border-left: 4px solid currentColor;
	background: #fff;
}

.sqm-notice--error {
	color: var(--sqm-danger);
	background: #fef3f2;
}

.sqm-notice--success {
	color: var(--sqm-success);
	background: #ecfdf3;
}

.sqm-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem 1rem;
	margin-bottom: 1.25rem;
	padding-bottom: 0.75rem;
	border-bottom: 1px solid var(--sqm-border);
}

.sqm-tabs {
	display: flex;
	gap: 0.25rem;
}

.sqm-tab {
	padding: 0.4rem 0.8rem;
	border: 0;
	border-radius: calc(var(--sqm-radius) / 2);
	font: inherit;
	color: inherit;
	background: none;
	cursor: pointer;
}

.sqm-tab[aria-current="page"] {
	font-weight: 700;
	background: var(--sqm-card);
	box-shadow: var(--sqm-shadow);
}

.sqm-groups {
	display: grid;
	gap: var(--sqm-gap);
	margin: var(--sqm-gap) 0 0;
	padding: 0;
	list-style: none;
	/* Cards lay out by their own width, not the screen's: the portal sits in
	   whatever column the page gives it. */
	container-type: inline-size;
}

/* Narrow: one column — name and details, code, stats and actions, results. */
.sqm-group {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 1rem;
	padding: 1.25rem;
	border: 1px solid var(--sqm-border);
	border-radius: var(--sqm-radius);
	background: var(--sqm-card);
	box-shadow: var(--sqm-shadow);
}

/* While editing, the form's own card stands in for the group's. Weighted to
   outrank a theme's .sqm-theme-x .sqm-group. */
.sqm-groups > .sqm-group.sqm-group--editing {
	display: block;
	padding: 0;
	border: 0;
	background: none;
	box-shadow: none;
}

.sqm-group__name {
	margin: 0;
}

.sqm-group__info .sqm-muted {
	margin: 0.25rem 0 0;
}

.sqm-group .sqm-stats {
	margin: 0;
}

/* Stats, then the actions; side by side when they fit. */
.sqm-group__foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 1rem 1.5rem;
}

.sqm-group__results .sqm-results {
	margin: 0;
}

/* Narrow: the results button on its own row, Edit and Delete together below it. */
@container (max-width: 34rem) {
	.sqm-group__actions {
		display: grid;
		grid-template-columns: auto auto;
		justify-content: start;
		gap: 0.75rem 1.25rem;
	}

	.sqm-group__actions > .sqm-button {
		grid-column: 1 / -1;
		justify-self: start;
	}
}

/* Wide: the code beside the name; stats and actions share the row below. */
@container (min-width: 34rem) {
	.sqm-group {
		grid-template-columns: minmax(0, 1fr) auto;
		grid-template-areas:
			"info    code"
			"foot    foot"
			"results results";
		column-gap: 1.5rem;
	}

	.sqm-group__info {
		grid-area: info;
		align-self: start;
	}

	.sqm-group .sqm-code {
		grid-area: code;
		align-self: start;
	}

	.sqm-group__foot {
		grid-area: foot;
	}

	.sqm-group__results {
		grid-area: results;
	}
}

/* Whether the group's quest counts right now (campaign window). */
.sqm-state {
	margin: 0.5rem 0 0;
	font-size: 0.875em;
}

.sqm-form .sqm-state {
	justify-self: start;
	margin: 0;
}

.sqm-state--stopped {
	font-weight: 600;
	color: var(--sqm-danger);
}

.sqm-code {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.sqm-code__label {
	font-size: 0.875em;
	opacity: 0.75;
}

.sqm-code__value {
	padding: 0.1rem 0.5rem;
	border-radius: calc(var(--sqm-radius) / 2);
	background: var(--sqm-surface);
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 1.35em;
	letter-spacing: 0.08em;
}

.sqm-stats {
	display: grid;
	grid-auto-flow: column;
	grid-template-rows: auto auto;
	justify-content: start;
	gap: 0 2rem;
	margin: 1rem 0;
}

/* Labels share a row and numbers share the next, so a label that wraps on a
   phone doesn't knock its number out of line. */
.sqm-stats div {
	display: grid;
	grid-row: span 2;
	grid-template-rows: subgrid;
	margin: 0;
}

.sqm-stats dt {
	align-self: end;
	font-size: 0.875em;
	opacity: 0.75;
}

.sqm-stats dd {
	margin: 0;
	font-size: 1.25em;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.sqm-results {
	margin-top: 1rem;
}

.sqm-table-wrap {
	overflow-x: auto;
}

.sqm-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.925em;
}

.sqm-table th,
.sqm-table td {
	padding: 0.45rem 0.6rem;
	border-bottom: 1px solid var(--sqm-border);
	text-align: left;
	white-space: nowrap;
}

.sqm-table .sqm-num {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.sqm-parts {
	font-variant-numeric: tabular-nums;
	opacity: 0.8;
}

@media (max-width: 600px) {
	.sqm-card,
	.sqm-group {
		padding: 1rem;
	}

	.sqm-stats {
		column-gap: 1.25rem;
	}
}
