/*
 * Think Twice. One stylesheet for the whole app: tokens, type, then the parts in the order the pages
 * use them. Fonts are self-hosted (SIL Open Font License, see assets/fonts).
 */

@font-face {
	font-family: 'Fredoka';
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url('/assets/fonts/fredoka/fredoka-latin-ext-400-normal.woff2') format('woff2');
	unicode-range:
		U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
		U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
		U+A720-A7FF;
}
@font-face {
	font-family: 'Fredoka';
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url('/assets/fonts/fredoka/fredoka-latin-400-normal.woff2') format('woff2');
	unicode-range:
		U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
		U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
	font-family: 'Fredoka';
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url('/assets/fonts/fredoka/fredoka-latin-ext-700-normal.woff2') format('woff2');
	unicode-range:
		U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
		U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
		U+A720-A7FF;
}
@font-face {
	font-family: 'Fredoka';
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url('/assets/fonts/fredoka/fredoka-latin-700-normal.woff2') format('woff2');
	unicode-range:
		U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
		U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
	font-family: 'Atkinson Hyperlegible';
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url('/assets/fonts/atkinson-hyperlegible/atkinson-hyperlegible-latin-ext-400-normal.woff2')
		format('woff2');
	unicode-range:
		U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
		U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
		U+A720-A7FF;
}
@font-face {
	font-family: 'Atkinson Hyperlegible';
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url('/assets/fonts/atkinson-hyperlegible/atkinson-hyperlegible-latin-400-normal.woff2')
		format('woff2');
	unicode-range:
		U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
		U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
	font-family: 'Atkinson Hyperlegible';
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url('/assets/fonts/atkinson-hyperlegible/atkinson-hyperlegible-latin-ext-700-normal.woff2')
		format('woff2');
	unicode-range:
		U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
		U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
		U+A720-A7FF;
}
@font-face {
	font-family: 'Atkinson Hyperlegible';
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url('/assets/fonts/atkinson-hyperlegible/atkinson-hyperlegible-latin-700-normal.woff2')
		format('woff2');
	unicode-range:
		U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
		U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
	font-family: 'Courier Prime';
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url('/assets/fonts/courier-prime/courier-prime-latin-ext-400-normal.woff2') format('woff2');
	unicode-range:
		U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
		U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
		U+A720-A7FF;
}
@font-face {
	font-family: 'Courier Prime';
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url('/assets/fonts/courier-prime/courier-prime-latin-400-normal.woff2') format('woff2');
	unicode-range:
		U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
		U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
	font-family: 'Courier Prime';
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url('/assets/fonts/courier-prime/courier-prime-latin-ext-700-normal.woff2') format('woff2');
	unicode-range:
		U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
		U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
		U+A720-A7FF;
}
@font-face {
	font-family: 'Courier Prime';
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url('/assets/fonts/courier-prime/courier-prime-latin-700-normal.woff2') format('woff2');
	unicode-range:
		U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
		U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
	color-scheme: light;

	/* The room around the board: cool and quiet, so the board is the warm thing in it. */
	--page: #eef2f5;
	--card: #ffffff;
	--ink: #17212b;
	--ink-soft: #4c5a69;
	--rule: #c9d3dc;
	--focus: #1b5fd0;

	/* The classic board: buff and steel blue. Another set brings its own (`applyTheme`). */
	--sq-light: #efe8d5;
	--sq-dark: #6a8fb0;
	--on-light: #6f6a58;
	--on-dark: #eef4f9;

	/* What the teacher's markers say: picked up, in danger (three grades), safe. */
	--pick: #ffcf33;
	--last: rgb(255 207 51 / 0.42);
	--hanging: #e5383d;
	--outgunned: #f08a24;
	--defended: #d9a400;
	--good: #1c7c53;
	--hanging-soft: #fde8e8;
	--outgunned-soft: #fdeedd;
	--defended-soft: #fbf3d0;

	--display: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
	--body: 'Atkinson Hyperlegible', system-ui, sans-serif;
	--mono: 'Courier Prime', ui-monospace, 'Courier New', monospace;

	--radius: 12px;
}

@media (prefers-color-scheme: dark) {
	:root {
		color-scheme: dark;
		--page: #10161d;
		--card: #1a232d;
		--ink: #e8eef3;
		--ink-soft: #a6b3c0;
		--rule: #33414f;
		--focus: #8ab8ff;
		--sq-light: #d8d1bd;
		--sq-dark: #57799b;
		--good: #63c79a;
		--hanging: #ff6b6f;
		--outgunned: #ffa24a;
		--defended: #e8bd2c;
		--hanging-soft: #3a1c20;
		--outgunned-soft: #3a2a17;
		--defended-soft: #35300f;
	}
}

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

html {
	background: var(--page);
	color: var(--ink);
	font: 400 1.0625rem/1.5 var(--body);
	-webkit-text-size-adjust: 100%;
}

body {
	margin: 0;
	min-height: 100dvh;
}

h1,
h2,
h3,
p,
ul,
ol {
	margin: 0;
	padding: 0;
}

ul,
ol {
	list-style: none;
}

h1,
h2,
h3 {
	font-family: var(--display);
	font-weight: 700;
	line-height: 1.15;
}

h2 {
	font-size: 1.5rem;
}

h3 {
	font-size: 1.1875rem;
}

button,
input {
	font: inherit;
	color: inherit;
}

:focus-visible {
	outline: 3px solid var(--focus);
	outline-offset: 2px;
}

.ch-visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

.ch-icon {
	width: 1.25em;
	height: 1.25em;
	flex: none;
}

.ch-hint {
	color: var(--ink-soft);
	font-size: 0.9375rem;
}

.ch-you {
	color: var(--ink-soft);
	font-weight: 400;
}

.ch-badge {
	display: inline-block;
	padding: 0.05rem 0.5rem;
	border: 1.5px solid currentColor;
	border-radius: 999px;
	font-size: 0.8125rem;
	font-weight: 700;
	white-space: nowrap;
}

.ch-count {
	color: var(--ink-soft);
	font-family: var(--body);
	font-size: 0.9375rem;
	font-weight: 400;
}

/* Buttons and fields */

.ch-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	min-height: 2.75rem;
	padding: 0.5rem 1.1rem;
	border: 2px solid var(--ink);
	border-radius: var(--radius);
	background: var(--card);
	color: var(--ink);
	font-weight: 700;
	line-height: 1.2;
	cursor: pointer;
}

.ch-button:hover:not(:disabled) {
	background: color-mix(in srgb, var(--ink) 8%, var(--card));
}

.ch-button:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.ch-button.ch-primary {
	background: var(--ink);
	color: var(--card);
}

.ch-button.ch-primary:hover:not(:disabled) {
	background: color-mix(in srgb, var(--ink) 85%, var(--card));
}

.ch-button.ch-quiet {
	border-color: var(--rule);
	background: transparent;
}

.ch-button.ch-large {
	min-height: 3.5rem;
	padding-inline: 1.75rem;
	font-size: 1.1875rem;
}

.ch-button-row {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.ch-link-button {
	padding: 0.25rem;
	border: 0;
	background: none;
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 0.15em;
	cursor: pointer;
}

.ch-copy-done,
[data-copied='true'] > .ch-copy-label {
	display: none;
}

[data-copied='true'] > .ch-copy-done,
.ch-copy-label {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
}

input:not([type='checkbox']) {
	width: 100%;
	min-height: 2.75rem;
	padding: 0.5rem 0.75rem;
	border: 2px solid var(--ink);
	border-radius: var(--radius);
	background: var(--card);
}

input::placeholder {
	color: var(--ink-soft);
	opacity: 1;
}

label {
	display: block;
	font-weight: 700;
}

label > input:not([type='checkbox']) {
	margin-top: 0.35rem;
	font-weight: 400;
}

.ch-input-row {
	display: flex;
	gap: 0.5rem;
}

.ch-input-row > input {
	flex: 1;
	min-width: 0;
}

/*
 * The pieces: turned figures. `ui/pieces.ts` puts the set in use into the document, painted, and a
 * piece on the page refers to its figure there.
 */

.ch-piece-defs {
	position: absolute;
	width: 0;
	height: 0;
}

.ch-piece {
	display: block;
	pointer-events: none;
}

/* Why a move was weak, after its grade; and a game summed up by the engine. */

.ch-reason {
	display: block;
}

.ch-report {
	display: grid;
	gap: 0.6rem;
	padding: 1rem;
	border: 2px solid var(--rule);
	border-radius: var(--radius);
	background: var(--card);
}

.ch-report-counts {
	width: 100%;
	border-collapse: collapse;
	font-variant-numeric: tabular-nums;
}

.ch-report-counts th,
.ch-report-counts td {
	padding: 0.3rem 0.4rem;
	border-bottom: 1px solid var(--rule);
	text-align: right;
}

.ch-report-counts thead th {
	color: var(--ink-soft);
	font-size: 0.875rem;
	font-weight: 400;
}

.ch-report-counts tbody th {
	text-align: left;
}

.ch-report-counts td {
	font-weight: 700;
}

.ch-report-counts td[data-count='0'] {
	color: var(--ink-soft);
	font-weight: 400;
}

.ch-report-moments {
	display: grid;
	gap: 0.35rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ch-report-moment {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 0 0.6rem;
	width: 100%;
	min-height: 2.75rem;
	padding: 0.45rem 0.7rem;
	border: 1px solid var(--rule);
	border-left: 5px solid var(--defended);
	border-radius: 6px;
	background: none;
	color: var(--ink);
	font: inherit;
	text-align: left;
	cursor: pointer;
}

.ch-report-moment[data-grade='mistake'] {
	border-left-color: var(--outgunned);
}

.ch-report-moment[data-grade='blunder'] {
	border-left-color: var(--hanging);
}

.ch-report-moment:hover {
	border-color: var(--ink);
}

.ch-report-why {
	grid-column: 1 / -1;
	color: var(--ink-soft);
	font-size: 0.875rem;
}

/* Openings: named in a game, searched and browsed on a page of their own. */

.ch-opening {
	color: var(--ink-soft);
}

.ch-opening strong {
	color: var(--ink);
}

.ch-opening-eco {
	color: var(--ink-soft);
	font: 400 0.875em/1 var(--mono);
}

.ch-openings-choose,
.ch-opening-one {
	display: grid;
	gap: 0.75rem;
	min-width: 0;
}

.ch-openings-choose {
	max-width: 44rem;
	padding-block: clamp(1rem, 4vw, 2rem);
}

.ch-openings-choose h1,
.ch-opening-one h1 {
	font-size: clamp(1.75rem, 6vw, 2.5rem);
	line-height: 1.1;
}

.ch-openings-back {
	justify-self: start;
}

.ch-openings-choose input {
	width: 100%;
	min-height: 3rem;
	padding: 0 0.8rem;
	border: 2px solid var(--ink);
	border-radius: var(--radius);
	background: var(--card);
	color: var(--ink);
	font: inherit;
}

.ch-opening-families {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
	gap: 0.35rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ch-opening-family,
.ch-opening-entry {
	width: 100%;
	min-height: 2.75rem;
	padding: 0.5rem 0.7rem;
	border: 1px solid var(--rule);
	border-radius: 8px;
	background: var(--card);
	color: var(--ink);
	font: inherit;
	text-align: left;
	cursor: pointer;
}

.ch-opening-family {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.5rem;
}

.ch-opening-family:hover,
.ch-opening-entry:hover {
	border-color: var(--ink);
}

.ch-opening-count {
	color: var(--ink-soft);
	font-size: 0.875rem;
}

.ch-opening-list {
	display: grid;
	gap: 0.35rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ch-opening-entry {
	display: grid;
	grid-template-columns: 2.75rem minmax(0, 1fr);
	gap: 0.1rem 0.5rem;
	align-items: baseline;
}

.ch-opening-name {
	font-weight: 700;
}

.ch-opening-moves {
	grid-column: 2;
	overflow: hidden;
	color: var(--ink-soft);
	font: 400 0.875rem/1.4 var(--mono);
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ch-opening-article {
	display: grid;
	gap: 0.15rem;
}

.ch-opening-article a {
	color: var(--ink);
	font-weight: 700;
}

.ch-opening-links {
	display: grid;
	gap: 0.5rem;
	min-width: 0;
}

/* Going through a game: a file or text in, then the board with the moves to step through. */

.ch-review-offer {
	display: grid;
	gap: 1rem;
	justify-items: start;
	max-width: 40rem;
	padding-block: clamp(1rem, 5vw, 3rem);
}

.ch-review-offer h1 {
	font-size: clamp(2.25rem, 9vw, 3.5rem);
	line-height: 1;
}

/* The file field is the button: the native control is there for the keyboard, unseen. */
.ch-review-file {
	position: relative;
	cursor: pointer;
}

.ch-review-file input {
	position: absolute;
	inset: 0;
	opacity: 0;
	cursor: pointer;
}

.ch-review-file:has(input:focus-visible) {
	outline: 3px solid var(--focus);
	outline-offset: 2px;
}

.ch-review-paste {
	display: grid;
	gap: 0.4rem;
	justify-items: start;
	width: 100%;
}

.ch-review-paste textarea {
	width: 100%;
	padding: 0.6rem 0.75rem;
	border: 2px solid var(--ink);
	border-radius: var(--radius);
	background: var(--card);
	color: var(--ink);
	font: 400 1rem/1.5 var(--mono);
	resize: vertical;
}

.ch-review-player {
	font-weight: 700;
}

.ch-review-steps {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 0.5rem;
}

.ch-review-steps .ch-button {
	min-height: 3rem;
	font-size: 1.125rem;
}

.ch-review-standing {
	color: var(--ink-soft);
}

.ch-review-move {
	justify-self: start;
	padding: 0 0.25rem;
	white-space: nowrap;
	border: 0;
	border-radius: 4px;
	background: none;
	color: inherit;
	font: inherit;
	font-weight: 700;
	text-align: left;
	cursor: pointer;
}

.ch-review-move[aria-current='true'] {
	background: var(--pick);
	color: #17212b;
}

.ch-review .ch-moves {
	max-height: 18rem;
}

/* Puzzles: the offer to fetch them, then one after the other. */

.ch-start-puzzles {
	color: var(--ink);
	font-weight: 700;
}

.ch-puzzle-offer {
	display: grid;
	gap: 1rem;
	justify-items: start;
	max-width: 40rem;
	padding-block: clamp(1rem, 5vw, 3rem);
}

.ch-puzzle-offer h1 {
	font-size: clamp(2.25rem, 9vw, 3.5rem);
	line-height: 1;
}

.ch-puzzle-feedback {
	padding: 0.6rem 0.8rem;
	border-left: 5px solid var(--rule);
	border-radius: 4px;
	background: color-mix(in srgb, var(--ink) 5%, var(--card));
}

.ch-puzzle-feedback[data-feedback='right'],
.ch-puzzle-feedback[data-feedback='solved'] {
	border-left-color: var(--good);
}

.ch-puzzle-feedback[data-feedback='wrong'] {
	border-left-color: var(--hanging);
	background: var(--hanging-soft);
}

.ch-puzzle-facts {
	display: grid;
	gap: 0.5rem;
	margin: 0;
}

.ch-puzzle-facts > div {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem 0.75rem;
	align-items: baseline;
}

.ch-puzzle-facts dt {
	color: var(--ink-soft);
}

.ch-puzzle-facts dd {
	margin: 0;
	font-weight: 700;
}

.ch-puzzle-themes {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
}

.ch-puzzle-levels {
	min-width: 0;
	margin: 0;
	padding: 0;
	border: 0;
}

.ch-puzzle-levels legend {
	margin-bottom: 0.5rem;
	padding: 0;
	font-weight: 700;
}

.ch-puzzle-level-list {
	display: grid;
	gap: 0.4rem;
}

.ch-puzzle-level {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.75rem;
	min-height: 2.75rem;
	padding: 0.55rem 0.8rem;
	border: 2px solid var(--rule);
	border-radius: var(--radius);
	font-weight: 400;
	cursor: pointer;
}

.ch-puzzle-level input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.ch-puzzle-level:has(input:checked) {
	border-color: var(--ink);
}

.ch-puzzle-level:has(input:checked) .ch-puzzle-level-name {
	font-weight: 700;
}

.ch-puzzle-level:has(input:focus-visible) {
	outline: 3px solid var(--focus);
	outline-offset: 2px;
}

.ch-puzzle-level-count {
	color: var(--ink-soft);
	font-size: 0.9375rem;
}

/* The start page */

.ch-start {
	max-width: 44rem;
	margin-inline: auto;
	padding: clamp(1.5rem, 6vw, 4rem) 1.25rem 2.5rem;
	display: grid;
	gap: 2.5rem;
}

.ch-start-hero {
	display: grid;
	gap: 1.25rem;
	justify-items: start;
}

/* Six pieces on a strip of board: what the app is, before any word. */
.ch-start-pieces {
	display: grid;
	grid-template-columns: repeat(6, minmax(0, 1fr));
	width: min(100%, 27rem);
	border: 3px solid var(--ink);
	border-radius: 8px;
	overflow: hidden;
}

.ch-start-pieces .ch-piece {
	padding: 7%;
	background: var(--sq-light);
}

.ch-start-pieces .ch-piece:nth-child(odd) {
	background: var(--sq-dark);
}

.ch-start-hero h1 {
	font-size: clamp(3rem, 12vw, 5rem);
	line-height: 0.95;
	letter-spacing: -0.01em;
}

.ch-start-lead {
	max-width: 34rem;
	font-size: 1.1875rem;
}

.ch-start-pick {
	display: grid;
	gap: 0.5rem;
	max-width: 30rem;
}

@media (max-width: 40rem) {
	.ch-start-create {
		justify-self: stretch;
	}
}

.ch-kept-rooms {
	display: grid;
	gap: 0.75rem;
}

.ch-kept-rooms h2,
.ch-kept-room {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem 0.75rem;
	padding-block: 0.75rem;
	border-top: 1px solid var(--rule);
}

.ch-kept-room-text {
	flex: 1 1 14rem;
	display: grid;
	min-width: 0;
}

.ch-kept-room-name {
	font-weight: 700;
	overflow-wrap: anywhere;
}

.ch-kept-room-meta {
	color: var(--ink-soft);
	font-size: 0.9375rem;
}

/*
 * What the app is and how it teaches: written into the page itself (index.html), so it is there
 * without JavaScript. It belongs to the start page and is hidden on a game and on the puzzles.
 */
html[data-page]:not([data-page='start']) .ch-about {
	display: none;
}

.ch-about {
	max-width: 44rem;
	margin-inline: auto;
	padding: 0 1.25rem 4rem;
	display: grid;
	gap: 1rem;
}

.ch-about-head {
	padding-top: clamp(1.5rem, 6vw, 4rem);
	padding-bottom: 2.5rem;
}

.ch-about-head h1 {
	font-size: clamp(3rem, 12vw, 5rem);
	line-height: 0.95;
}

.ch-about h2 {
	padding-top: 2rem;
	border-top: 3px solid var(--ink);
	font-size: clamp(1.625rem, 5vw, 2.125rem);
	line-height: 1.15;
}

.ch-about h3 {
	margin-top: 1.25rem;
	font-size: 1.3125rem;
}

.ch-about p,
.ch-about li,
.ch-about dd {
	max-width: 65ch;
	color: var(--ink-soft);
}

.ch-about strong,
.ch-about dt {
	color: var(--ink);
}

.ch-about ul {
	display: grid;
	gap: 0.6rem;
	margin: 0;
	padding-left: 1.25rem;
}

.ch-about-questions {
	display: grid;
	gap: 0.25rem;
	margin: 0;
}

.ch-about-questions dt {
	margin-top: 0.6rem;
	font-weight: 700;
}

.ch-about-questions dd {
	margin: 0;
}

/* How a game goes, as numbered steps. */
.ch-start-steps {
	counter-reset: step;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
	gap: 1.25rem 2rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ch-start-steps li {
	counter-increment: step;
	display: grid;
	grid-template-columns: 2.25rem 1fr;
	column-gap: 0.75rem;
	align-items: start;
}

.ch-start-steps li::before {
	content: counter(step);
	grid-row: span 2;
	display: grid;
	place-items: center;
	width: 2.25rem;
	height: 2.25rem;
	border-radius: 50%;
	background: var(--ink);
	color: var(--card);
	font: 700 1.125rem/1 var(--display);
}

.ch-start-steps strong {
	font: 700 1.1875rem/1.3 var(--display);
}

.ch-start-steps span {
	color: var(--ink-soft);
}

/* The room */

.ch-room {
	max-width: 68rem;
	margin-inline: auto;
	padding: 0.75rem 1rem 4rem;
	display: grid;
	gap: 1.25rem;
}

.ch-room-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	padding-bottom: 0.625rem;
	border-bottom: 3px solid var(--ink);
}

.ch-room-title {
	display: grid;
	min-width: 0;
}

.ch-home {
	color: var(--ink);
	font: 700 1.375rem/1.1 var(--display);
	text-decoration: none;
}

.ch-home:hover {
	text-decoration: underline;
}

.ch-room-name {
	overflow: hidden;
	color: var(--ink-soft);
	font-size: 0.875rem;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ch-room-actions {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	flex: none;
}

@media (max-width: 34rem) {
	.ch-copy-text {
		display: none;
	}

	.ch-copy-link {
		padding-inline: 0.7rem;
	}
}

.ch-profile-button {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	max-width: 11rem;
	min-height: 2.75rem;
	padding: 0.25rem 0.75rem;
	border: 2px solid var(--rule);
	border-radius: var(--radius);
	background: transparent;
	font-weight: 700;
	cursor: pointer;
}

.ch-profile-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ch-caret {
	width: 0.625rem;
	flex: none;
}

.ch-menu {
	position: fixed;
	inset: 4rem 1rem auto auto;
	width: min(18rem, calc(100vw - 2rem));
	margin: 0;
	padding: 1rem;
	border: 2px solid var(--ink);
	border-radius: var(--radius);
	background: var(--card);
	color: var(--ink);
}

.ch-menu:popover-open {
	display: grid;
	gap: 1rem;
}

.ch-room-status {
	padding-block: 2rem;
	font-size: 1.1875rem;
}

.ch-stranded {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem;
}

.ch-stranded p {
	flex-basis: 100%;
}

.ch-notices {
	display: grid;
	gap: 0.5rem;
}

.ch-notice {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.5rem 1rem;
	padding: 0.625rem 0.875rem;
	border-left: 4px solid var(--ink);
	border-radius: 4px;
	background: var(--card);
}

.ch-notice.ch-error {
	border-left-color: var(--hanging);
}

/* The game: the table (two seats and the board between them), and what goes with it. */

.ch-game {
	display: grid;
	gap: 1.5rem;
	align-items: start;
}

@media (min-width: 56rem) {
	.ch-game {
		grid-template-columns: minmax(0, 1fr) 22rem;
		gap: 2.5rem;
	}
}

.ch-table {
	display: grid;
	gap: 0.5rem;
	/* As large as the screen allows with both seats in view. */
	width: min(100%, calc(100dvh - 13.5rem));
	min-width: min(100%, 18rem);
	margin-inline: auto;
}

.ch-seat {
	display: flex;
	align-items: center;
	gap: 0.625rem;
	min-height: 3rem;
}

.ch-seat-piece {
	flex: none;
	width: 2.5rem;
	height: 2.5rem;
	padding: 0.2rem;
	border-radius: 8px;
	background: var(--sq-dark);
}

.ch-seat[data-color='b'] .ch-seat-piece {
	background: var(--sq-light);
}

.ch-seat-who {
	display: grid;
	min-width: 0;
	line-height: 1.25;
}

.ch-seat-color {
	color: var(--ink-soft);
	font-size: 0.875rem;
}

.ch-seat-name {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.3rem 0.5rem;
	font-weight: 700;
	overflow-wrap: anywhere;
}

.ch-seat[data-free='true'] .ch-seat-name {
	color: var(--ink-soft);
	font-weight: 400;
}

/* Whose move it is: the one loud thing beside the board. */
.ch-turn {
	flex: none;
	padding: 0.15rem 0.7rem;
	border-radius: 999px;
	background: var(--pick);
	color: #17212b;
	font-size: 0.875rem;
	font-weight: 700;
}

.ch-seat-actions {
	display: flex;
	gap: 0.5rem;
	margin-left: auto;
}

.ch-seat-actions .ch-button {
	min-height: 2.5rem;
	padding-inline: 0.8rem;
	font-size: 0.9375rem;
}

/* The board */

ch-board-view {
	display: block;
	min-width: 0;
}

.ch-board {
	position: relative;
	display: grid;
	grid-template-columns: repeat(8, minmax(0, 1fr));
	aspect-ratio: 1;
	border: 3px solid var(--board-frame, var(--ink));
	border-radius: 8px;
	box-shadow: var(--board-glow, none);
	overflow: hidden;
	user-select: none;
	-webkit-user-select: none;
}

.ch-square {
	position: relative;
	display: grid;
	place-items: center;
	aspect-ratio: 1;
	min-width: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: var(--sq-light);
	color: var(--on-light);
	/* Where a board has them: the joints between its squares. */
	box-shadow: inset 0 0 0 0.5px var(--sq-edge, transparent);
	cursor: default;
}

.ch-square[data-shade='dark'] {
	background: var(--sq-dark);
	color: var(--on-dark);
}

.ch-board[data-active='true'] .ch-square {
	cursor: pointer;
}

/* A piece that can be dragged doesn't scroll the page with the finger on it. */
.ch-board[data-active='true'][data-turn='w'] .ch-square:has(.ch-piece[data-color='w']),
.ch-board[data-active='true'][data-turn='b'] .ch-square:has(.ch-piece[data-color='b']) {
	touch-action: none;
}

.ch-square:focus-visible {
	z-index: 2;
	outline-offset: -3px;
}

.ch-square .ch-piece {
	position: relative;
	z-index: 1;
	width: 96%;
	height: 96%;
}

.ch-rank,
.ch-file {
	position: absolute;
	font: 700 clamp(0.5625rem, 1.6vw, 0.75rem) / 1 var(--display);
}

.ch-rank {
	top: 4%;
	left: 6%;
}

.ch-file {
	right: 7%;
	bottom: 3%;
}

/* The move just made, and the piece picked up. */
.ch-square[data-last='true'] {
	background-image: linear-gradient(var(--last), var(--last));
}

.ch-square[data-selected='true'] {
	background: var(--pick);
}

.ch-square[data-dragging='true'] {
	z-index: 3;
}

.ch-square[data-dragging='true'] .ch-piece {
	scale: 1.2;
	filter: drop-shadow(0 4px 4px rgb(0 0 0 / 0.35));
}

/* Learner's mode: where the picked-up piece can go. A dot for a free square, a ring around a piece
   it would take. Dark with a light edge, so it shows on both kinds of square. */
.ch-square[data-target]::after {
	content: '';
	position: absolute;
	z-index: 2;
	border-radius: 50%;
}

.ch-square[data-target='move']::after {
	width: 30%;
	height: 30%;
	background: rgb(23 33 43 / 0.62);
	box-shadow: 0 0 0 2px rgb(255 255 255 / 0.75);
}

.ch-square[data-target='capture']::after {
	inset: 5%;
	border: 5px solid rgb(23 33 43 / 0.7);
	box-shadow:
		0 0 0 2px rgb(255 255 255 / 0.7),
		inset 0 0 0 2px rgb(255 255 255 / 0.7);
}

/* The king in check. */
.ch-square[data-check='true'] {
	background-image: radial-gradient(circle, var(--hanging) 10%, transparent 72%);
}

/* A move being looked at: what it leaves in danger. Red for free, orange for a bad trade, a dashed
   yellow for a fair one. */
.ch-square[data-danger]::before {
	content: '';
	position: absolute;
	inset: 3%;
	border: 5px solid var(--risk);
	border-radius: 50%;
	background: color-mix(in srgb, var(--risk) 22%, transparent);
	box-shadow: 0 0 0 2px rgb(255 255 255 / 0.6);
}

[data-danger='hanging'],
[data-risk='hanging'] {
	--risk: var(--hanging);
	--risk-soft: var(--hanging-soft);
}

[data-danger='outgunned'],
[data-risk='outgunned'] {
	--risk: var(--outgunned);
	--risk-soft: var(--outgunned-soft);
}

[data-danger='defended'],
[data-risk='defended'] {
	--risk: var(--defended);
	--risk-soft: var(--defended-soft);
}

.ch-square[data-danger='defended']::before {
	border-style: dashed;
}

.ch-arrows {
	position: absolute;
	inset: 0;
	z-index: 4;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

.ch-arrow line {
	stroke: var(--risk);
	stroke-width: 0.11;
	stroke-linecap: round;
}

.ch-arrow polygon {
	fill: var(--risk);
}

.ch-arrow {
	filter: drop-shadow(0 0 0.03px rgb(255 255 255 / 0.9));
}

/* Beside the board */

.ch-side {
	display: grid;
	gap: 1.25rem;
	min-width: 0;
}

.ch-status {
	font: 400 1.25rem/1.3 var(--display);
}

.ch-status strong {
	font-weight: 700;
}

.ch-status[data-check='true'] {
	color: var(--hanging);
}

.ch-setup,
.ch-preview,
.ch-options,
.ch-draw-offer {
	display: grid;
	gap: 0.875rem;
	padding: 1rem;
	border: 2px solid var(--ink);
	border-radius: var(--radius);
	background: var(--card);
}

.ch-setup-choice {
	display: grid;
	gap: 0.4rem;
	justify-items: start;
}

.ch-setup-choice + .ch-setup-choice {
	padding-top: 0.875rem;
	border-top: 1px solid var(--rule);
}

.ch-setup .ch-play-both {
	justify-self: stretch;
}

.ch-options {
	border-color: var(--rule);
}

/* The chess engine: how far it is, under its switch. */
.ch-engine-status {
	display: block;
	margin-top: 0.25rem;
	font-size: 0.9375rem;
	font-weight: 700;
}

.ch-engine-status[data-status='ready'] {
	color: var(--good);
}

.ch-engine-status[data-status='failed'] {
	color: var(--hanging);
}

/* The computer as an opponent: how strong, then which side. */
.ch-bot-level {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	font-weight: 700;
}

.ch-bot-level select {
	min-height: 2.75rem;
	padding: 0 0.6rem;
	border: 2px solid var(--ink);
	border-radius: var(--radius);
	background: var(--card);
	color: var(--ink);
	font: inherit;
	font-weight: 400;
}

/* The engine's grade of a move: the same colors as the dangers, from good to bad. */
.ch-rating {
	padding: 0.6rem 0.8rem;
	border-left: 5px solid var(--rule);
	border-radius: 4px;
	background: color-mix(in srgb, var(--ink) 5%, var(--card));
}

.ch-rating[data-grade='pending'] {
	color: var(--ink-soft);
}

.ch-rating[data-grade='best'],
.ch-rating[data-grade='good'] {
	border-left-color: var(--good);
}

.ch-rating[data-grade='inaccuracy'] {
	border-left-color: var(--defended);
	background: var(--defended-soft);
}

.ch-rating[data-grade='mistake'] {
	border-left-color: var(--outgunned);
	background: var(--outgunned-soft);
}

.ch-rating[data-grade='blunder'] {
	border-left-color: var(--hanging);
	background: var(--hanging-soft);
}

.ch-move[data-mark]::after {
	content: attr(data-mark);
	margin-left: 0.15em;
	font-weight: 700;
}

.ch-move[data-grade='best']::after {
	color: var(--good);
}

.ch-move[data-grade='inaccuracy']::after {
	color: var(--defended);
}

.ch-move[data-grade='mistake']::after {
	color: var(--outgunned);
}

.ch-move[data-grade='blunder']::after {
	color: var(--hanging);
}

/* The sets of pieces to choose from: each shows its board. */
.ch-themes {
	margin: 0;
	padding: 0;
	border: 0;
	min-width: 0;
}

.ch-themes legend {
	padding: 0;
	margin-bottom: 0.5rem;
	font-weight: 700;
}

.ch-theme-list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(8.75rem, 1fr));
	gap: 0.5rem;
}

.ch-theme {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	min-height: 2.75rem;
	padding: 0.4rem 0.6rem 0.4rem 0.4rem;
	border: 2px solid var(--rule);
	border-radius: var(--radius);
	font-weight: 400;
	cursor: pointer;
}

.ch-theme input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.ch-theme:has(input:checked) {
	border-color: var(--ink);
	font-weight: 700;
}

.ch-theme:has(input:focus-visible) {
	outline: 3px solid var(--focus);
	outline-offset: 2px;
}

/* A set's knight on one of its dark squares. */
.ch-theme-swatch {
	flex: none;
	width: 2.5rem;
	height: 2.5rem;
	border: 2px solid;
	border-radius: 5px;
}

/* A switch: a checkbox drawn as one. */
.ch-switch {
	display: flex;
	align-items: flex-start;
	gap: 0.75rem;
	font-weight: 400;
	cursor: pointer;
}

.ch-switch input {
	appearance: none;
	position: relative;
	flex: none;
	width: 2.875rem;
	height: 1.625rem;
	margin: 0.15rem 0 0;
	border: 2px solid var(--ink);
	border-radius: 999px;
	background: var(--card);
	cursor: pointer;
}

.ch-switch input::after {
	content: '';
	position: absolute;
	top: 2px;
	left: 2px;
	width: 1.125rem;
	height: 1.125rem;
	border-radius: 50%;
	background: var(--ink);
}

.ch-switch input:checked {
	background: var(--ink);
}

.ch-switch input:checked::after {
	left: calc(100% - 1.125rem - 2px);
	background: var(--pick);
}

.ch-switch-text {
	display: grid;
	gap: 0.1rem;
}

/* A move looked at before it counts. */
.ch-preview {
	border-width: 3px;
}

.ch-preview:focus-visible {
	outline-offset: 3px;
}

.ch-preview-move {
	display: flex;
	align-items: center;
	gap: 0.625rem;
	font-weight: 700;
}

.ch-preview-move .ch-piece,
.ch-danger .ch-piece {
	flex: none;
	width: 2.25rem;
	height: 2.25rem;
	padding: 0.15rem;
	border-radius: 6px;
	background: var(--sq-dark);
}

.ch-san {
	margin-left: 0.4rem;
	color: var(--ink-soft);
	font: 700 1rem var(--mono);
}

.ch-preview-safe,
.ch-preview-good {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	color: var(--good);
	font-weight: 700;
}

.ch-preview-warn {
	font-weight: 700;
}

.ch-preview-mate {
	padding: 0.625rem 0.75rem;
	border-radius: 8px;
	background: var(--hanging);
	color: #fff;
	font-weight: 700;
}

.ch-preview-lead {
	font-weight: 700;
}

.ch-dangers {
	display: grid;
	gap: 0.5rem;
}

.ch-danger {
	display: flex;
	align-items: flex-start;
	gap: 0.625rem;
	padding: 0.5rem 0.625rem;
	border-left: 6px solid var(--risk);
	border-radius: 6px;
	background: var(--risk-soft);
}

.ch-preview-actions {
	padding-top: 0.25rem;
}

.ch-preview-actions .ch-button {
	flex: 1 1 9rem;
}

/* On a phone the decision stays in reach, as a bar at the card's foot, while the list above scrolls. */
@media (max-width: 55.99rem) {
	.ch-preview-actions {
		position: sticky;
		bottom: 0;
		margin: 0 -1rem -1rem;
		padding: 0.75rem 1rem;
		border-top: 1px solid var(--rule);
		border-radius: 0 0 calc(var(--radius) - 3px) calc(var(--radius) - 3px);
		background: var(--card);
	}
}

.ch-moves-section {
	display: grid;
	gap: 0.5rem;
}

.ch-moves {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
	gap: 0.15rem 1rem;
	max-height: 13rem;
	overflow: auto;
	padding: 0.625rem 0.75rem;
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	background: var(--card);
	font: 400 1rem/1.5 var(--mono);
}

.ch-moves li {
	display: grid;
	grid-template-columns: 2.25rem 1fr 1fr;
	gap: 0.25rem;
}

.ch-move-number {
	color: var(--ink-soft);
}

.ch-move {
	font-weight: 700;
}

.ch-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

/* Everyone in the room */

.ch-people {
	display: grid;
	gap: 0.5rem;
	padding-top: 1rem;
	border-top: 1px solid var(--rule);
}

.ch-people h2 {
	font-size: 1.1875rem;
}

.ch-people ul {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 2rem;
}

.ch-person {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.ch-person[data-connected='false'] .ch-person-name {
	color: var(--ink-soft);
}

.ch-person-name {
	font-weight: 700;
	overflow-wrap: anywhere;
}

.ch-person-seats {
	display: flex;
	align-items: center;
	gap: 0.25rem;
}

.ch-person-seats .ch-piece {
	width: 1.75rem;
	height: 1.75rem;
	padding: 0.1rem;
	border-radius: 5px;
	background: var(--sq-dark);
}

.ch-person-watching {
	color: var(--ink-soft);
	font-size: 0.875rem;
}

/* Dialogs and sheets */

.ch-dialog,
.ch-sheet {
	padding: 0;
	border: 2px solid var(--ink);
	border-radius: var(--radius);
	background: var(--card);
	color: var(--ink);
}

.ch-dialog {
	width: min(26rem, calc(100vw - 2rem));
	padding: 1.5rem;
}

.ch-dialog::backdrop,
.ch-sheet::backdrop {
	background: rgb(12 21 34 / 0.6);
}

.ch-dialog[open],
.ch-name-prompt {
	display: grid;
	gap: 1.1rem;
}

.ch-dialog-actions {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 0.5rem;
}

.ch-sheet {
	width: min(24rem, calc(100vw - 2rem));
}

.ch-sheet-body {
	display: grid;
	gap: 1rem;
	padding: 1.25rem;
}

.ch-promotion-pieces {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 0.5rem;
}

.ch-promote {
	display: grid;
	justify-items: center;
	gap: 0.25rem;
	padding: 0.5rem 0.25rem;
	border: 2px solid var(--ink);
	border-radius: var(--radius);
	background: var(--sq-dark);
	color: #fff;
	font-weight: 700;
	cursor: pointer;
}

.ch-promote:hover {
	background: color-mix(in srgb, var(--sq-dark) 80%, #000);
}
