/**
 * Design tokens, reset and the basic elements.
 *
 * The palette is deliberately narrow: a neutral page, one configurable accent
 * that the administrator sets, and grey text at three weights. There are no
 * gradients, no glass, no glow. This is a tool people use for ten minutes at a
 * time before printing something, and it should get out of the way.
 *
 * @package ActivityMaker
 */

:root {
	/* Neutrals. */
	--am-bg: #ffffff;
	--am-bg-sunken: #f5f6f8;
	--am-bg-raised: #ffffff;
	--am-border: #dfe3e8;
	--am-border-strong: #c6ccd4;
	--am-text: #16181c;
	--am-text-muted: #59616b;
	--am-text-faint: #838b95;

	/* Accent - overridden inline from theme settings. */
	--am-accent: #2563a8;
	--am-accent-hover: #1f5490;
	--am-accent-active: #194171;
	--am-accent-soft: #eef3f9;
	--am-accent-line: #b9cde5;
	--am-accent-ink: #ffffff;

	/* Feedback. */
	--am-danger: #a8302f;
	--am-danger-soft: #fdf1f0;
	--am-warning: #8a5a08;
	--am-warning-soft: #fdf6e8;
	--am-success: #1f6b45;
	--am-success-soft: #eef7f1;

	/* Type. */
	--am-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
	--am-font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

	--am-text-xs: 0.75rem;
	--am-text-sm: 0.8125rem;
	--am-text-base: 0.9375rem;
	--am-text-md: 1rem;
	--am-text-lg: 1.125rem;
	--am-text-xl: 1.375rem;
	--am-text-2xl: 1.75rem;
	--am-text-3xl: 2.25rem;

	/* Space. */
	--am-1: 4px;
	--am-2: 8px;
	--am-3: 12px;
	--am-4: 16px;
	--am-5: 24px;
	--am-6: 32px;
	--am-7: 48px;
	--am-8: 64px;

	/* Shape. */
	--am-radius-sm: 4px;
	--am-radius: 6px;
	--am-radius-lg: 10px;

	/* Elevation - used sparingly, for things that genuinely float. */
	--am-shadow-1: 0 1px 2px rgba(16, 20, 26, 0.06);
	--am-shadow-2: 0 6px 20px rgba(16, 20, 26, 0.10), 0 1px 3px rgba(16, 20, 26, 0.06);
	--am-shadow-3: 0 18px 48px rgba(16, 20, 26, 0.18);

	--am-header-height: 60px;
	--am-max-width: 1240px;
	--am-prose-width: 42rem;
}

/* --------------------------------------------------------------- Reset. */

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

html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
	scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
	html {
		scroll-behavior: auto;
	}

	*,
	*::before,
	*::after {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
	}
}

body {
	margin: 0;
	background: var(--am-bg);
	color: var(--am-text);
	font-family: var(--am-font);
	font-size: var(--am-text-base);
	line-height: 1.6;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	/* A share URL, a long email address or a pasted German compound noun should
	   wrap rather than push the whole page sideways. This is the single most
	   common cause of a sideways-scrolling phone layout, and the guard costs
	   nothing on wider screens. */
	overflow-wrap: break-word;
}

h1, h2, h3, h4, h5, h6 {
	margin: 0 0 var(--am-3);
	font-weight: 650;
	line-height: 1.25;
	letter-spacing: -0.011em;
	color: var(--am-text);
	/* Headings are the other common culprit: they are large, so a single long
	   word overflows a narrow screen much sooner. */
	overflow-wrap: break-word;
}

h1 { font-size: var(--am-text-2xl); }
h2 { font-size: var(--am-text-xl); }
h3 { font-size: var(--am-text-lg); }
h4 { font-size: var(--am-text-md); }

p {
	margin: 0 0 var(--am-4);
}

p:last-child {
	margin-bottom: 0;
}

a {
	color: var(--am-accent);
	text-decoration: underline;
	text-underline-offset: 2px;
	text-decoration-thickness: 1px;
}

a:hover {
	color: var(--am-accent-hover);
}

img,
svg,
video,
canvas {
	max-width: 100%;
	height: auto;
}

ul, ol {
	margin: 0 0 var(--am-4);
	padding-left: 1.35em;
}

li + li {
	margin-top: var(--am-1);
}

hr {
	border: 0;
	border-top: 1px solid var(--am-border);
	margin: var(--am-6) 0;
}

code, pre, kbd {
	font-family: var(--am-font-mono);
	font-size: 0.9em;
}

code {
	background: var(--am-bg-sunken);
	padding: 0.1em 0.35em;
	border-radius: var(--am-radius-sm);
}

pre {
	background: var(--am-bg-sunken);
	border: 1px solid var(--am-border);
	border-radius: var(--am-radius);
	padding: var(--am-4);
	overflow-x: auto;
}

table {
	border-collapse: collapse;
	width: 100%;
}

/* A table with more columns than a phone has room for has to scroll inside its
   own box. The wrapper is added by the front-end script, so the table keeps its
   markup - and therefore its meaning to a screen reader - rather than being
   turned into a block element. */
.am-tablewrap {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	max-width: 100%;
	margin-bottom: var(--am-4);
}

.am-tablewrap > table {
	margin-bottom: 0;
	/* Below this the columns become unreadable and scrolling is the better
	   answer than squeezing. */
	min-width: 30rem;
}

th, td {
	text-align: left;
	padding: var(--am-2) var(--am-3);
	border-bottom: 1px solid var(--am-border);
}

th {
	font-weight: 620;
	color: var(--am-text-muted);
	font-size: var(--am-text-sm);
}

/* --------------------------------------------------------------- Focus. */

:focus-visible {
	outline: 2px solid var(--am-accent);
	outline-offset: 2px;
	border-radius: 2px;
}

/* Only remove the default ring where we draw our own. */
.am-btn:focus:not(:focus-visible),
.am-input:focus:not(:focus-visible) {
	outline: none;
}

.screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal !important;
}

.am-skip-link {
	position: absolute;
	left: -9999px;
	top: 0;
	z-index: 100;
	background: var(--am-bg);
	color: var(--am-text);
	padding: var(--am-3) var(--am-4);
	border: 1px solid var(--am-border);
	border-radius: 0 0 var(--am-radius) 0;
	box-shadow: var(--am-shadow-2);
}

.am-skip-link:focus {
	left: 0;
}

/* --------------------------------------------------------------- Buttons. */

.am-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--am-2);
	padding: 0.55rem 0.95rem;
	min-height: 40px;
	border: 1px solid transparent;
	border-radius: var(--am-radius);
	background: transparent;
	color: var(--am-text);
	font-family: inherit;
	font-size: var(--am-text-base);
	font-weight: 550;
	line-height: 1.2;
	text-decoration: none;
	cursor: pointer;
	transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
	white-space: nowrap;
}

.am-btn:disabled,
.am-btn[disabled] {
	opacity: 0.45;
	cursor: not-allowed;
}

/*
 * On a touch screen every control grows to the 44px that a fingertip actually
 * needs, and the grey flash Safari paints over anything tapped is replaced by
 * the state we style ourselves. Keyed on the pointer rather than on the screen
 * width, because a small laptop with a mouse does not need bigger buttons and a
 * large tablet with a finger does.
 */
@media (pointer: coarse) {
	.am-btn,
	.am-input,
	.am-select,
	.am-segment__item {
		min-height: 44px;
	}

	a,
	button,
	.am-btn,
	summary,
	[role="button"] {
		-webkit-tap-highlight-color: transparent;
	}
}

.am-btn--primary {
	background: var(--am-accent);
	border-color: var(--am-accent);
	color: var(--am-accent-ink);
}

.am-btn--primary:hover:not(:disabled) {
	background: var(--am-accent-hover);
	border-color: var(--am-accent-hover);
	color: var(--am-accent-ink);
}

.am-btn--primary:active:not(:disabled) {
	background: var(--am-accent-active);
}

/* A bordered button - the workhorse for secondary actions. */
.am-btn--solidline {
	background: var(--am-bg-raised);
	border-color: var(--am-border-strong);
	color: var(--am-text);
}

.am-btn--solidline:hover:not(:disabled) {
	border-color: var(--am-accent);
	color: var(--am-accent);
}

.am-btn--ghost {
	background: transparent;
	border-color: var(--am-border);
	color: var(--am-text-muted);
}

.am-btn--ghost:hover:not(:disabled) {
	background: var(--am-bg-sunken);
	color: var(--am-text);
}

.am-btn--quiet {
	background: transparent;
	border-color: transparent;
	color: var(--am-text-muted);
	padding-inline: 0.5rem;
}

.am-btn--quiet:hover:not(:disabled) {
	background: var(--am-bg-sunken);
	color: var(--am-text);
}

.am-btn--danger {
	color: var(--am-danger);
}

.am-btn--danger:hover:not(:disabled) {
	background: var(--am-danger-soft);
	color: var(--am-danger);
}

.am-btn--sm {
	min-height: 32px;
	padding: 0.3rem 0.6rem;
	font-size: var(--am-text-sm);
}

.am-btn--lg {
	min-height: 48px;
	padding: 0.75rem 1.4rem;
	font-size: var(--am-text-md);
}

.am-btn--block {
	width: 100%;
}

.am-iconbtn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 1px solid var(--am-border);
	border-radius: var(--am-radius);
	background: var(--am-bg-raised);
	color: var(--am-text-muted);
	cursor: pointer;
	font-size: var(--am-text-md);
	line-height: 1;
}

.am-iconbtn:hover:not(:disabled) {
	border-color: var(--am-accent);
	color: var(--am-accent);
}

.am-iconbtn:disabled {
	opacity: 0.35;
	cursor: not-allowed;
}

.am-iconbtn--danger:hover:not(:disabled) {
	border-color: var(--am-danger);
	color: var(--am-danger);
}

.am-icon-wrap {
	display: inline-flex;
	flex: none;
}

.am-flip svg {
	transform: scaleX(-1);
}

/* --------------------------------------------------------------- Forms. */

.am-label {
	display: block;
	margin-bottom: var(--am-1);
	font-size: var(--am-text-sm);
	font-weight: 600;
	color: var(--am-text);
}

.am-help {
	margin: var(--am-1) 0 0;
	font-size: var(--am-text-sm);
	color: var(--am-text-muted);
	line-height: 1.5;
}

.am-field {
	margin-bottom: var(--am-4);
}

.am-field:last-child {
	margin-bottom: 0;
}

.am-input {
	display: block;
	width: 100%;
	padding: 0.5rem 0.7rem;
	min-height: 40px;
	border: 1px solid var(--am-border-strong);
	border-radius: var(--am-radius);
	background: var(--am-bg-raised);
	color: var(--am-text);
	font-family: inherit;
	font-size: var(--am-text-base);
	line-height: 1.45;
	transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.am-input:hover:not(:disabled) {
	border-color: var(--am-text-faint);
}

.am-input:focus {
	border-color: var(--am-accent);
	box-shadow: 0 0 0 3px var(--am-accent-soft);
	outline: none;
}

.am-input::placeholder {
	color: var(--am-text-faint);
}

.am-input[readonly] {
	background: var(--am-bg-sunken);
}

.am-textarea {
	min-height: 9rem;
	resize: vertical;
	font-family: var(--am-font);
	line-height: 1.65;
}

.am-select {
	appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2359616b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.6rem center;
	padding-right: 2rem;
}

.am-select--sm {
	min-height: 32px;
	padding-block: 0.2rem;
	font-size: var(--am-text-sm);
	width: auto;
}

.am-input--number {
	width: 8rem;
}

.am-checkbox {
	width: 17px;
	height: 17px;
	margin: 0;
	accent-color: var(--am-accent);
	flex: none;
	cursor: pointer;
}

.am-toggle {
	display: flex;
	align-items: flex-start;
	gap: var(--am-2);
	cursor: pointer;
	font-size: var(--am-text-base);
	line-height: 1.45;
	padding-block: 2px;
}

.am-field--toggle {
	margin-bottom: var(--am-2);
}

.am-checkgroup {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
	gap: var(--am-1) var(--am-3);
}

.am-checkgroup__item {
	display: flex;
	align-items: center;
	gap: var(--am-2);
	font-size: var(--am-text-sm);
	cursor: pointer;
}

/* Segmented control - used wherever there are two to four exclusive choices. */
.am-segment {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 2px;
	padding: 2px;
	background: var(--am-bg-sunken);
	border: 1px solid var(--am-border);
	border-radius: var(--am-radius);
}

.am-segment__item {
	appearance: none;
	border: 0;
	background: transparent;
	color: var(--am-text-muted);
	font-family: inherit;
	font-size: var(--am-text-sm);
	font-weight: 550;
	padding: 0.35rem 0.7rem;
	min-height: 30px;
	border-radius: var(--am-radius-sm);
	cursor: pointer;
	transition: background-color 0.12s ease, color 0.12s ease;
}

.am-segment__item:hover {
	color: var(--am-text);
}

.am-segment__item[aria-checked="true"] {
	background: var(--am-bg-raised);
	color: var(--am-text);
	box-shadow: var(--am-shadow-1);
}

.am-range__row {
	display: flex;
	align-items: center;
	gap: var(--am-3);
}

.am-range {
	flex: 1;
	accent-color: var(--am-accent);
	min-height: 24px;
}

.am-range__value {
	min-width: 3.5rem;
	font-size: var(--am-text-sm);
	color: var(--am-text-muted);
	font-variant-numeric: tabular-nums;
}

.am-spacer {
	flex: 1 1 auto;
}
