/* Type: Baloo 2, scale 1.25 | Color: accent orange, warm neutrals |
   Space: 4px base | Finish: 16px radius, thick ink outline + hard offset
   shadow (manga panel), signature: halftone dots and the grade stamp. */
:root {
	--font: 'Baloo 2', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
	--fs-1: 0.875rem;
	--fs-2: 1rem;
	--fs-3: 1.25rem;
	--fs-4: 1.563rem;
	--fs-5: 1.953rem;
	--fs-6: 3.052rem;
	--fs-7: 4.768rem;

	--paper: #fff5e3;
	--panel: #ffffff;
	--text: #1f1a2e;
	--muted: #6a6274;
	--line: #1f1a2e;
	--halftone: rgba(31, 26, 46, 0.07);
	--accent: #ff6b1a;
	--accent-soft: #ffe3cf;
	--on-accent: #1f1a2e;
	--gold: #ffc21a;
	--star-off: #e9e1d4;
	--good: #17a657;
	--good-soft: #d3f4df;
	--bad: #d6293f;
	--bad-soft: #fde1e5;
	--info: #2f6fea;
	--review: #2f6fea;
	--g-s: #ffb300;
	--g-ss: #19b7f0;
	--g-sss-a: #ff3d7f;
	--g-sss-b: #ffc21a;
	--g-sss-c: #19b7f0;

	--sp-1: 4px;
	--sp-2: 8px;
	--sp-3: 12px;
	--sp-4: 16px;
	--sp-5: 24px;
	--sp-6: 32px;
	--r-1: 10px;
	--r-2: 16px;
	--r-3: 24px;
	--r-full: 999px;
	--bw: 3px;
	--shadow: 4px 4px 0 var(--line);
	--shadow-sm: 2px 2px 0 var(--line);
	--shadow-lg: 6px 6px 0 var(--line);
	--ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
	--ease-back: cubic-bezier(0.34, 1.56, 0.64, 1);
	color-scheme: light;
}

/* Theme: data-theme on <html> is the player's choice (set before the first
   paint by the inline script of each page); without it, the phone setting. */
@media (prefers-color-scheme: dark) {
	:root:not([data-theme='light']) {
		--paper: #17141f;
		--panel: #26222f;
		--text: #f7f0e4;
		--muted: #b8afc2;
		--line: #050408;
		--halftone: rgba(255, 245, 227, 0.05);
		--accent-soft: #4a2611;
		--star-off: #3b3546;
		--good-soft: #113d25;
		--bad-soft: #4a1720;
		--review: #7fa8ff;
		color-scheme: dark;
	}
}

:root[data-theme='dark'] {
	--paper: #17141f;
	--panel: #26222f;
	--text: #f7f0e4;
	--muted: #b8afc2;
	--line: #050408;
	--halftone: rgba(255, 245, 227, 0.05);
	--accent-soft: #4a2611;
	--star-off: #3b3546;
	--good-soft: #113d25;
	--bad-soft: #4a1720;
	--review: #7fa8ff;
	color-scheme: dark;
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	min-height: 100%;
}

body {
	font-family: var(--font);
	font-size: var(--fs-2);
	line-height: 1.5;
	color: var(--text);
	background-color: var(--paper);
	background-image: radial-gradient(var(--halftone) 1.5px, transparent 1.6px);
	background-size: 14px 14px;
	-webkit-tap-highlight-color: transparent;
	overscroll-behavior: none;
}

h1,
h2,
p {
	margin: 0;
}

button {
	font: inherit;
	color: inherit;
}

svg {
	width: 1em;
	height: 1em;
	fill: none;
	stroke: currentColor;
	stroke-width: 2.4;
	stroke-linecap: round;
	stroke-linejoin: round;
}

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

.app {
	max-width: 480px;
	min-height: 100dvh;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	gap: var(--sp-4);
	padding: calc(var(--sp-4) + env(safe-area-inset-top)) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
}

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

.btn {
	min-height: 52px;
	padding: var(--sp-2) var(--sp-5);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	box-shadow: var(--shadow);
	font-weight: 800;
	font-size: var(--fs-3);
	cursor: pointer;
	transition: transform 120ms var(--ease-out), box-shadow 120ms var(--ease-out);
	touch-action: manipulation;
}

.btn:active,
.choice:active:not(:disabled),
.key:active:not(:disabled) {
	transform: translate(2px, 2px);
	box-shadow: var(--shadow-sm);
}

.btn-primary {
	background: var(--accent);
	color: var(--on-accent);
}

.btn-danger {
	color: var(--bad);
	border-color: var(--bad);
	box-shadow: 4px 4px 0 var(--bad);
}

.btn-xl {
	width: 100%;
	min-height: 68px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	line-height: 1.1;
	font-size: var(--fs-4);
}

.btn-xl small {
	font-size: var(--fs-1);
	font-weight: 700;
}

.icon-btn {
	width: 44px;
	height: 44px;
	display: grid;
	place-items: center;
	border: var(--bw) solid var(--line);
	border-radius: var(--r-full);
	background: var(--panel);
	font-size: 22px;
	cursor: pointer;
}

.dock {
	position: sticky;
	bottom: 0;
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
	padding-top: var(--sp-5);
	margin-top: auto;
	background: linear-gradient(transparent, var(--paper) var(--sp-5));
}

.dock-row {
	display: flex;
	gap: var(--sp-3);
}

.dock-row .btn {
	flex: 1;
	padding-inline: var(--sp-2);
	font-size: var(--fs-2);
}

/* ---------- Home ---------- */

.home-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.logo {
	font-size: var(--fs-5);
	font-weight: 800;
	line-height: 1.1;
	letter-spacing: -0.02em;
}

.logo span {
	margin-left: 0.15em;
	padding: 0 0.25em;
	background: var(--accent);
	color: var(--on-accent);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-1);
	box-shadow: var(--shadow-sm);
	display: inline-block;
	transform: rotate(-3deg);
}

.star-total {
	display: flex;
	align-items: center;
	gap: var(--sp-1);
	padding: var(--sp-1) var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-full);
	background: var(--panel);
	font-size: var(--fs-3);
	font-weight: 800;
}

.star-total svg {
	fill: var(--gold);
	stroke: var(--line);
	stroke-width: 1.6;
}

.tabs {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--sp-2);
}

.tab {
	min-height: 56px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	line-height: 1.1;
	padding: var(--sp-1);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	font-weight: 700;
	font-size: var(--fs-1);
	cursor: pointer;
}

.tab-symbol {
	font-size: var(--fs-4);
	font-weight: 800;
}

.tab[aria-selected='true'] {
	background: var(--accent);
	color: var(--on-accent);
	box-shadow: var(--shadow);
}

.path {
	list-style: none;
	margin: 0;
	padding: var(--sp-2) 0;
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
}

/* Zigzag path like a world map. */
.node:nth-child(4n + 2) {
	padding-left: 14%;
}
.node:nth-child(4n + 3) {
	padding-left: 28%;
}
.node:nth-child(4n + 4) {
	padding-left: 14%;
}

.node-btn {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	width: 100%;
	padding: 0;
	border: 0;
	background: none;
	text-align: left;
	cursor: pointer;
}

.node-num {
	flex: none;
	width: 64px;
	height: 64px;
	display: grid;
	place-items: center;
	border: var(--bw) solid var(--line);
	border-radius: var(--r-full);
	background: var(--panel);
	box-shadow: var(--shadow);
	font-size: var(--fs-4);
	font-weight: 800;
}

.node.is-done .node-num {
	background: var(--gold);
	color: var(--line);
}

.node.is-next .node-num {
	background: var(--accent);
	color: var(--on-accent);
	animation: pulse 1.6s ease-in-out infinite;
}

.node.is-locked .node-num {
	background: var(--star-off);
	color: var(--muted);
	box-shadow: none;
	border-style: dashed;
}

.node-info {
	display: flex;
	flex-direction: column;
	line-height: 1.2;
}

.node-title {
	font-weight: 800;
	font-size: var(--fs-3);
}

.node.is-locked .node-title,
.node-locked {
	color: var(--muted);
}

.node-meta {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	min-height: 24px;
	font-size: var(--fs-1);
}

.mini-stars {
	display: inline-flex;
	gap: 1px;
	font-size: 20px;
}

.mini-stars svg {
	fill: var(--star-off);
	stroke: var(--line);
	stroke-width: 1.4;
}

.mini-stars .on svg {
	fill: var(--gold);
}

.grade-chip {
	padding: 0 var(--sp-2);
	border: 2px solid var(--line);
	border-radius: var(--r-1);
	font-weight: 800;
	font-size: var(--fs-1);
	line-height: 1.4;
	color: var(--line);
	background: var(--g-s);
}

.grade-chip.g-SS {
	background: var(--g-ss);
}

.grade-chip.g-SSS {
	background: linear-gradient(90deg, var(--g-sss-a), var(--g-sss-b), var(--g-sss-c));
}

/* ---------- Sheet (dialog) ---------- */

.sheet {
	width: calc(100% - 2 * var(--sp-4));
	max-width: 440px;
	/* Never taller than the screen: long sheets scroll inside. */
	max-height: calc(100dvh - 2 * var(--sp-4) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
	overflow-y: auto;
	overscroll-behavior: contain;
	margin: auto auto calc(var(--sp-4) + env(safe-area-inset-bottom));
	padding: 0;
	border: var(--bw) solid var(--line);
	border-radius: var(--r-3);
	background: var(--panel);
	color: var(--text);
	box-shadow: var(--shadow-lg);
}

.sheet[open] {
	animation: sheet-in 220ms var(--ease-out);
}

.sheet::backdrop {
	background: rgba(20, 16, 30, 0.55);
}

.sheet-body {
	display: flex;
	flex-direction: column;
	gap: var(--sp-4);
	padding: var(--sp-5);
}

.sheet-kicker {
	color: var(--muted);
	font-weight: 700;
	font-size: var(--fs-1);
	margin-bottom: calc(-1 * var(--sp-3));
}

.sheet-title {
	font-size: var(--fs-5);
	line-height: 1.15;
}

.sheet-example {
	color: var(--muted);
}

.sheet-example b {
	color: var(--text);
}

.sheet-actions {
	display: flex;
	justify-content: space-between;
	gap: var(--sp-3);
	/* Stays reachable at the bottom when a long sheet scrolls. */
	position: sticky;
	bottom: 0;
	margin: 0 calc(-1 * var(--sp-5)) calc(-1 * var(--sp-5));
	padding: var(--sp-3) var(--sp-5) var(--sp-5);
	background: var(--panel);
}

.sheet-actions .btn {
	/* Equal halves whatever the label length (long words in some languages). */
	flex: 1 1 0;
	min-width: 0;
	padding-inline: var(--sp-3);
	font-size: var(--fs-2);
	line-height: 1.15;
	overflow-wrap: anywhere;
}

.modes {
	margin: 0;
	padding: 0;
	border: 0;
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--sp-3);
}

.modes legend {
	padding: 0;
	margin-bottom: var(--sp-2);
	font-weight: 700;
}

.mode {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: var(--sp-1);
	padding: var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	cursor: pointer;
	line-height: 1.25;
}

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

.mode:has(input:checked) {
	background: var(--accent-soft);
	box-shadow: var(--shadow);
}

.mode:has(input:focus-visible) {
	outline: 3px solid var(--info);
	outline-offset: 3px;
}

.mode.is-disabled {
	border-style: dashed;
	cursor: not-allowed;
}

.mode-title {
	display: flex;
	align-items: center;
	gap: var(--sp-1);
	font-weight: 800;
	font-size: var(--fs-3);
}

.mode-text {
	font-size: var(--fs-1);
	color: var(--muted);
}

.mode-best {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
}

.mastery p {
	font-size: var(--fs-1);
}

.meter {
	height: 12px;
	border: 2px solid var(--line);
	border-radius: var(--r-full);
	background: var(--star-off);
	overflow: hidden;
}

.meter i {
	display: block;
	height: 100%;
	background: var(--good);
}

.note {
	padding: var(--sp-3);
	border-radius: var(--r-1);
	background: var(--accent-soft);
	font-size: var(--fs-1);
	font-weight: 700;
}

.locked-msg {
	display: flex;
	gap: var(--sp-2);
	align-items: flex-start;
	font-weight: 700;
}

.locked-msg svg {
	flex: none;
	margin-top: 4px;
}

/* ---------- Play ---------- */

.play-top {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
}

.dots {
	flex: 1;
	display: flex;
	gap: 4px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.dots li {
	flex: 1;
	height: 12px;
	border: 2px solid var(--line);
	border-radius: var(--r-full);
	background: var(--panel);
	transition: background-color 200ms var(--ease-out);
}

.dots .ok {
	background: var(--good);
}

.dots .ko {
	background: var(--bad);
}

.dots .now {
	background: var(--accent);
}

.points {
	min-width: 72px;
	text-align: right;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}

.points b {
	font-size: var(--fs-4);
	font-weight: 800;
}

.points span {
	margin-left: 2px;
	font-size: var(--fs-1);
	color: var(--muted);
}

.stage {
	flex: 1;
	position: relative;
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: var(--sp-4);
}

.combo {
	/* Sticker over the card's top left corner: above the card (it overlaps it
	   on short phone screens), away from the points flying up on the right. */
	position: absolute;
	z-index: 2;
	top: 0;
	left: 0;
	pointer-events: none;
	padding: 0 var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-1);
	background: var(--gold);
	color: var(--line);
	font-weight: 800;
	font-size: var(--fs-3);
	transform: rotate(-4deg);
	opacity: 0;
}

.combo.show {
	animation: combo 900ms var(--ease-out) forwards;
}

.qcard {
	position: relative;
	padding: var(--sp-6) var(--sp-4) var(--sp-5);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-3);
	background: var(--panel);
	box-shadow: var(--shadow-lg);
	text-align: center;
	transition: background-color 200ms var(--ease-out);
}

.qcard.is-right {
	background: var(--good-soft);
}

.qcard.is-wrong {
	background: var(--bad-soft);
}

.qcard.enter {
	animation: enter 260ms var(--ease-out);
}

.qcard.pop {
	animation: pop 320ms var(--ease-back);
}

.qcard.shake {
	animation: shake 420ms ease-in-out;
}

.qtag {
	position: absolute;
	top: calc(-1 * var(--sp-3));
	left: 50%;
	transform: translateX(-50%) rotate(-2deg);
	padding: 0 var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-full);
	font-weight: 800;
	font-size: var(--fs-1);
	white-space: nowrap;
}

.tag-revenge {
	background: var(--accent);
	color: var(--on-accent);
}

.tag-review {
	background: var(--panel);
	color: var(--review);
}

.qtext {
	display: flex;
	justify-content: center;
	align-items: baseline;
	flex-wrap: wrap;
	gap: 0 0.3em;
	font-size: clamp(2.4rem, 13vw, var(--fs-6));
	font-weight: 800;
	line-height: 1.1;
	font-variant-numeric: tabular-nums;
}

.qtext .op {
	color: var(--accent);
}

.qcard.is-right .qanswer {
	color: var(--good);
}

.qcard.is-wrong .qanswer {
	color: var(--bad);
}

.bonus {
	height: 8px;
	margin-top: var(--sp-4);
	border-radius: var(--r-full);
	background: var(--star-off);
	overflow: hidden;
}

.bonus i {
	display: block;
	height: 100%;
	background: var(--gold);
	transform-origin: left;
}

.bonus i.run {
	animation: drain linear forwards;
}

.float-points {
	position: absolute;
	right: var(--sp-4);
	top: var(--sp-3);
	font-weight: 800;
	font-size: var(--fs-4);
	color: var(--good);
	pointer-events: none;
	animation: float 900ms var(--ease-out) forwards;
}

.feedback {
	min-height: 3em;
	text-align: center;
	font-weight: 700;
	font-size: var(--fs-3);
	line-height: 1.25;
}

.feedback.is-right {
	color: var(--good);
}

.feedback.is-wrong {
	color: var(--bad);
	font-size: var(--fs-2);
}

.answers-qcm {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--sp-3);
}

.choice {
	min-height: 84px;
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	box-shadow: var(--shadow);
	font-size: var(--fs-5);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	cursor: pointer;
	touch-action: manipulation;
	transition: transform 120ms var(--ease-out), box-shadow 120ms var(--ease-out), background-color 150ms;
}

.choice:disabled {
	cursor: default;
}

.choice.is-right {
	background: var(--good);
	color: var(--line);
	animation: pop 320ms var(--ease-back);
}

.choice.is-wrong {
	background: var(--bad);
	color: #fff;
	animation: shake 420ms ease-in-out;
}

.choice:disabled:not(.is-right):not(.is-wrong) {
	opacity: 0.45;
}

.answers-pad {
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
}

.pad-display {
	display: block;
	min-height: 64px;
	padding: var(--sp-2);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	text-align: center;
	font-size: var(--fs-5);
	font-weight: 800;
	line-height: 1.4;
	font-variant-numeric: tabular-nums;
}

.pad-display.is-empty {
	color: var(--muted);
	font-size: var(--fs-3);
	line-height: 2.2;
}

.pad-display.is-right {
	background: var(--good-soft);
}

.pad-display.is-wrong {
	background: var(--bad-soft);
}

.keypad {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--sp-2);
}

.key {
	min-height: 60px;
	display: grid;
	place-items: center;
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	box-shadow: var(--shadow-sm);
	font-size: var(--fs-4);
	font-weight: 800;
	cursor: pointer;
	touch-action: manipulation;
}

.key-ok {
	background: var(--accent);
	color: var(--on-accent);
}

.key-ok:disabled {
	background: var(--star-off);
	color: var(--muted);
	cursor: not-allowed;
}

/* ---------- Results ---------- */

.results {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--sp-4);
	text-align: center;
	padding-top: var(--sp-4);
}

.res-title {
	font-size: var(--fs-5);
	line-height: 1.1;
}

.res-stars {
	display: flex;
	gap: var(--sp-2);
	font-size: 72px;
}

.rstar:nth-child(2) {
	transform: translateY(-14px);
	font-size: 1.15em;
}

.rstar svg {
	fill: var(--star-off);
	stroke: var(--line);
	stroke-width: 1.2;
}

.rstar.on svg {
	fill: var(--gold);
	animation: star-in 520ms var(--ease-back) backwards;
	animation-delay: var(--delay);
}

.stamp {
	position: relative;
	width: 132px;
	height: 132px;
	display: grid;
	place-items: center;
	animation: stamp 520ms var(--ease-back) 900ms backwards;
}

/* Manga speed lines behind the grade. */
.stamp::before {
	content: '';
	position: absolute;
	inset: -40px;
	border-radius: 50%;
	background: repeating-conic-gradient(var(--grade-color) 0 6deg, transparent 6deg 18deg);
	mask: radial-gradient(circle, transparent 38%, #000 40%, transparent 72%);
	opacity: 0.6;
	animation: spin 12s linear infinite;
}

.stamp span {
	position: relative;
	padding: 0 var(--sp-3);
	border: 5px solid var(--line);
	border-radius: var(--r-2);
	background: var(--grade-color);
	color: var(--line);
	box-shadow: var(--shadow-lg);
	font-size: var(--fs-7);
	font-weight: 800;
	line-height: 1.15;
	letter-spacing: -0.04em;
	transform: rotate(-8deg);
}

.stamp.g-S {
	--grade-color: var(--g-s);
}

.stamp.g-SS {
	--grade-color: var(--g-ss);
}

.stamp.g-SSS {
	--grade-color: var(--g-sss-b);
}

.stamp.g-SSS span {
	font-size: var(--fs-6);
	padding: var(--sp-2) var(--sp-3);
	background: linear-gradient(110deg, var(--g-sss-a), var(--g-sss-b), var(--g-sss-c), var(--g-sss-a));
	background-size: 300% 100%;
	animation: shine 3s linear infinite;
}

.badge-new,
.res-unlock {
	padding: var(--sp-1) var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-full);
	background: var(--gold);
	color: var(--line);
	font-weight: 800;
}

.res-unlock {
	background: var(--good-soft);
	color: var(--text);
	font-weight: 700;
}

.res-stats {
	width: 100%;
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--sp-2);
	margin: 0;
}

.res-stats div {
	padding: var(--sp-2);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
}

.res-stats dt {
	font-size: var(--fs-1);
	color: var(--muted);
}

.res-stats dd {
	margin: 0;
	font-size: var(--fs-4);
	font-weight: 800;
	line-height: 1.2;
	font-variant-numeric: tabular-nums;
}

.res-hint {
	font-weight: 700;
}

.res-missed {
	width: 100%;
	padding: var(--sp-3) var(--sp-4);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	text-align: left;
}

.res-missed h2 {
	font-size: var(--fs-3);
}

.res-missed ul {
	margin: var(--sp-1) 0 0;
	padding: 0;
	list-style: none;
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-1) var(--sp-4);
	font-size: var(--fs-3);
	font-variant-numeric: tabular-nums;
}

.res-missed b {
	color: var(--good);
}

.noscript {
	padding: var(--sp-5);
	text-align: center;
}

/* ---------- Animations ---------- */

@keyframes pulse {
	50% {
		box-shadow: var(--shadow), 0 0 0 8px rgba(255, 107, 26, 0.3);
	}
}

@keyframes sheet-in {
	from {
		transform: translateY(24px);
		opacity: 0;
	}
}

@keyframes enter {
	from {
		transform: translateX(40px) rotate(2deg);
		opacity: 0;
	}
}

@keyframes pop {
	40% {
		transform: scale(1.06);
	}
}

@keyframes shake {
	20%,
	60% {
		transform: translateX(-8px);
	}
	40%,
	80% {
		transform: translateX(8px);
	}
}

@keyframes drain {
	from {
		transform: scaleX(1);
	}
	to {
		transform: scaleX(0);
	}
}

@keyframes float {
	from {
		transform: translateY(0);
		opacity: 1;
	}
	to {
		transform: translateY(-48px);
		opacity: 0;
	}
}

@keyframes combo {
	0% {
		opacity: 0;
		transform: scale(0.4) rotate(10deg);
	}
	25% {
		opacity: 1;
		transform: scale(1.15) rotate(-4deg);
	}
	75% {
		opacity: 1;
		transform: scale(1) rotate(-4deg);
	}
	100% {
		opacity: 0;
		transform: scale(1) rotate(-4deg);
	}
}

@keyframes star-in {
	from {
		transform: scale(0) rotate(-120deg);
	}
}

@keyframes stamp {
	from {
		transform: scale(3) rotate(-20deg);
		opacity: 0;
	}
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

@keyframes shine {
	to {
		background-position: 300% 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 1ms !important;
		animation-iteration-count: 1 !important;
		animation-delay: 0ms !important;
		transition-duration: 1ms !important;
	}
	.bonus i.run {
		animation: none;
	}
}

.head-actions {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
}

a.icon-btn {
	color: var(--text);
}

/* Screens with the keypad must fit the screen height: the submit key is on
   the last row and must always be visible. */
.app-play:has(.answers-pad) {
	height: 100vh;
	height: 100dvh;
	min-height: 0;
	overflow: hidden;
}

.app-play:has(.answers-pad) .stage {
	min-height: 0;
}

.answers-pad .keypad .key {
	min-height: 0;
	height: clamp(44px, 7.5dvh, 60px);
}

@media (max-height: 760px) {
	.app-play:has(.answers-pad) {
		gap: var(--sp-2);
		padding-top: calc(var(--sp-2) + env(safe-area-inset-top));
		padding-bottom: calc(var(--sp-2) + env(safe-area-inset-bottom));
	}
	.app-play:has(.answers-pad) .qcard {
		padding: var(--sp-4) var(--sp-3) var(--sp-3);
	}
	.app-play:has(.answers-pad) .qtext {
		font-size: clamp(2rem, 10vw, 2.6rem);
	}
	.answers-pad .pad-display {
		min-height: 48px;
		line-height: 1.3;
		font-size: var(--fs-4);
	}
	.answers-pad .pad-display.is-empty {
		line-height: 2;
		font-size: var(--fs-2);
	}
	.answers-pad .keypad {
		gap: 6px;
	}
}

.settings-group {
	margin: 0;
	padding: 0;
	border: 0;
	display: grid;
	gap: var(--sp-2);
}

.settings-group legend {
	padding: 0;
	margin-bottom: var(--sp-2);
	font-weight: 800;
}

.settings-options {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: var(--sp-2);
}

.settings-options.is-3 {
	grid-template-columns: repeat(3, 1fr);
}

.settings-options .btn {
	min-width: 0;
	padding-inline: var(--sp-2);
	font-size: var(--fs-2);
}

.settings-hint {
	font-size: var(--fs-1);
	color: var(--muted);
}

/* ---------- About page ---------- */

.head-spacer {
	width: 44px;
}

.about-card {
	display: flex;
	flex-direction: column;
	gap: var(--sp-2);
	padding: var(--sp-4);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	box-shadow: var(--shadow);
}

.about-card h2 {
	font-size: var(--fs-3);
	line-height: 1.2;
}

.about-story {
	background: var(--accent-soft);
}

.about-card a {
	color: inherit;
	font-weight: 700;
	text-underline-offset: 3px;
}

.about-list {
	margin: 0;
	padding-left: 1.2em;
	display: grid;
	gap: var(--sp-1);
}

.legal-list,
.legal-rows {
	margin: 0;
	display: grid;
	gap: var(--sp-3);
}

.legal-rows {
	gap: 0;
	margin-top: var(--sp-1);
	font-size: var(--fs-1);
}

.legal-list dt {
	font-size: var(--fs-1);
	font-weight: 800;
	color: var(--muted);
}

.legal-rows dt {
	display: inline;
	font-weight: 700;
}

.legal-rows dt::after {
	content: ' : ';
}

.legal-rows dd {
	display: inline;
}

.legal-list dd {
	margin: 0;
}

.legal-sub {
	display: block;
	font-size: var(--fs-1);
	color: var(--muted);
}

.legal-updated {
	font-size: var(--fs-1);
	color: var(--muted);
}

.site-footer {
	text-align: center;
	font-size: var(--fs-1);
}

.site-footer a {
	color: var(--muted);
	text-underline-offset: 3px;
}

.update-banner {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-2) var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--gold);
	color: var(--line);
	font-weight: 700;
	font-size: var(--fs-1);
	box-shadow: var(--shadow-sm);
}

.update-banner span {
	flex: 1;
}

/* Secondary button inside a line of text: still a 44 px target, but it
   leaves the room to the text on a phone. */
.btn-compact {
	min-height: 44px;
	padding-inline: var(--sp-3);
	font-size: var(--fs-2);
}

.update-banner .btn {
	/* The banner's dark ink is for the gold strip, not the button's panel
	   (dark in dark mode). */
	color: var(--text);
	min-height: 44px;
	padding-inline: var(--sp-3);
	font-size: var(--fs-1);
	flex: none;
}

/* ---------- Form fields ---------- */

.field {
	display: flex;
	flex-direction: column;
	gap: var(--sp-1);
	font-weight: 800;
}

.field input,
.field select {
	min-height: 52px;
	padding: 0 var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	color: var(--text);
	box-shadow: var(--shadow-sm);
	/* 16px minimum, or iOS zooms into the field. */
	font: inherit;
	font-size: max(16px, var(--fs-2));
	font-weight: 700;
}

.field small {
	font-weight: 500;
	font-size: var(--fs-1);
	color: var(--muted);
}

/* ---------- Duels ---------- */

.btn-duel {
	position: relative;
	gap: var(--sp-2);
}

/* Challenges received through the mailbox (home Duel button). */
.count-badge {
	position: absolute;
	top: -8px;
	right: -6px;
	min-width: 24px;
	height: 24px;
	padding: 0 6px;
	display: grid;
	place-items: center;
	font-size: var(--fs-1);
	font-weight: 800;
	line-height: 1;
	color: var(--on-accent);
	background: var(--accent);
	border: 2px solid var(--line);
	border-radius: var(--r-full);
}

.btn-duel svg,
.app-duel .btn svg {
	margin-right: var(--sp-1);
	vertical-align: -2px;
}

.app-duel .col-title {
	font-size: var(--fs-4);
	line-height: 1.15;
	text-align: center;
}

.duel-form,
.duel-share,
.duel-challenge {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: var(--sp-4);
}

.duel-share {
	align-items: stretch;
	text-align: center;
}

.duel-share .field {
	text-align: left;
}

/* What the shared link shows (nickname, avatar, score): said where it is shared. */
.duel-privacy {
	display: flex;
	align-items: flex-start;
	justify-content: center;
	gap: var(--sp-2);
	margin: 0;
	font-size: var(--fs-1);
	color: var(--muted);
	text-align: left;
}

.duel-privacy svg {
	flex: none;
	width: 1.25em;
	height: 1.25em;
	margin-top: 0.1em;
	stroke-width: 2;
}

.duel-scan {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-3);
	border: var(--bw) dashed var(--muted);
	border-radius: var(--r-2);
}

.duel-scan p {
	flex: 1 1 8em;
	margin: 0;
	font-weight: 700;
}

.duel-scan .btn {
	flex: none;
}

/* The scan sheet focuses its title, not the link field (no keyboard over
   the camera); a title is not a control, no focus ring. */
.sheet-title[tabindex='-1']:focus {
	outline: none;
}

.scan-box {
	position: relative;
	width: 100%;
	aspect-ratio: 1;
	max-height: 50dvh;
	overflow: hidden;
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: #000000;
}

.scan-box video {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.duel-here {
	align-self: center;
}

.duel-challenge .duel-player {
	justify-content: center;
}

.profile-guest {
	display: grid;
	place-items: center;
	background: var(--paper);
	color: var(--muted);
	font-weight: 800;
	font-size: var(--fs-4);
}

.qr-box {
	align-self: center;
	width: min(70vw, 260px);
	aspect-ratio: 1;
	padding: var(--sp-2);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	/* Always black on white: scanners need the contrast, even in dark mode. */
	background: #ffffff;
	box-shadow: var(--shadow);
}

.qr-box svg {
	display: block;
	width: 100%;
	height: 100%;
}

.duel-challenge {
	align-items: center;
	justify-content: center;
	text-align: center;
	font-size: var(--fs-3);
	font-weight: 700;
}

/* Duel result (reply link): the two players side by side. */
.duel-reply p {
	margin: 0;
}

.duel-versus {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--sp-3);
	width: 100%;
	max-width: 420px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.duel-side {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--sp-1);
	padding: var(--sp-5) var(--sp-2) var(--sp-3);
	background: var(--panel);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	box-shadow: var(--shadow-sm);
}

.duel-side.is-winner {
	background: var(--accent-soft);
	box-shadow: var(--shadow);
}

.duel-side .duel-face {
	width: 84px;
}

.duel-side-name {
	max-width: 100%;
	overflow-wrap: anywhere;
	font-size: var(--fs-3);
	line-height: 1.2;
}

.duel-side-score {
	font-size: var(--fs-5);
	font-weight: 800;
	line-height: 1.1;
}

.duel-side-time {
	font-size: var(--fs-2);
	color: var(--muted);
}

.duel-win {
	position: absolute;
	top: calc(-1 * var(--sp-3));
	display: inline-flex;
	align-items: center;
	gap: var(--sp-1);
	padding: 0 var(--sp-2);
	font-size: var(--fs-1);
	font-weight: 800;
	color: var(--on-accent);
	background: var(--gold);
	border: 2px solid var(--line);
	border-radius: var(--r-full);
}

.duel-win svg {
	fill: currentColor;
	stroke: none;
}

/* Duel mailbox: challenges received, friends, sending (duel screens). */
.duel-inbox ul,
.duel-friends ul {
	display: flex;
	flex-direction: column;
	gap: var(--sp-2);
	margin: 0;
	padding: 0;
	list-style: none;
}

.duel-received {
	width: 100%;
	min-height: 64px;
	display: grid;
	grid-template-columns: auto 1fr auto;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-2) var(--sp-3);
	text-align: left;
	font: inherit;
	color: var(--text);
	background: var(--accent-soft);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	box-shadow: var(--shadow-sm);
	cursor: pointer;
}

.duel-received small,
.duel-friends li small {
	display: block;
	font-size: var(--fs-1);
	font-weight: 600;
	color: var(--muted);
}

.duel-received .profile-face,
.duel-friends .profile-face,
.send-friend .profile-face {
	width: 44px;
	height: 44px;
}

.duel-friends-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--sp-3);
}

.duel-friends li {
	display: grid;
	grid-template-columns: auto 1fr auto;
	align-items: center;
	gap: var(--sp-3);
}

.duel-friends li.is-gone .profile-face {
	opacity: 0.45;
}

.icon-btn-sm {
	font-size: 18px;
}

.friend-actions {
	display: flex;
	gap: var(--sp-2);
}

.friend-name-field {
	width: 100%;
	max-width: 420px;
	font-size: var(--fs-2);
	text-align: left;
}

/* Sending to a friend: state line under the results, or on the sent screen. */
.send-box {
	display: flex;
	flex-direction: column;
	gap: var(--sp-2);
	width: 100%;
}

.send-state {
	display: flex;
	align-items: flex-start;
	justify-content: center;
	gap: var(--sp-2);
	margin: 0;
	font-weight: 700;
	text-align: center;
}

.send-state span {
	text-align: left;
}

.send-state small {
	display: block;
	font-size: var(--fs-1);
	font-weight: 600;
	color: var(--muted);
}

.send-state.is-done {
	color: var(--good);
}

.send-state.is-done svg {
	flex: none;
	width: 1.3em;
	height: 1.3em;
	margin-top: 0.1em;
	stroke-width: 3;
}

.send-state.is-error {
	color: var(--bad);
}

/* "Who?" before a new challenge: friends first, then someone else (QR). */
.duel-target {
	display: flex;
	flex-direction: column;
	gap: var(--sp-2);
	margin: 0;
	padding: 0;
	border: 0;
}

.duel-target legend {
	margin-bottom: var(--sp-2);
	padding: 0;
	font-weight: 700;
}

.target {
	position: relative;
	display: grid;
	grid-template-columns: auto 1fr;
	align-items: center;
	gap: var(--sp-3);
	min-height: 56px;
	padding: var(--sp-2) var(--sp-3);
	background: var(--panel);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	cursor: pointer;
}

.target:has(input:checked) {
	background: var(--accent-soft);
	box-shadow: var(--shadow-sm);
}

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

.target.is-off {
	cursor: default;
	opacity: 0.6;
}

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

.target small {
	display: block;
	font-size: var(--fs-1);
	font-weight: 600;
	color: var(--muted);
}

.target .profile-face,
.target-qr {
	width: 40px;
	height: 40px;
}

.target-qr {
	display: grid;
	place-items: center;
	font-size: 22px;
	border: 2px dashed var(--muted);
	border-radius: 50%;
}

.send-friend small {
	display: block;
	font-size: var(--fs-1);
	font-weight: 600;
	color: var(--muted);
}

.link-btn {
	align-self: flex-start;
	min-height: 44px;
	padding: 0;
	font: inherit;
	font-size: var(--fs-1);
	color: var(--muted);
	text-decoration: underline;
	background: none;
	border: 0;
	cursor: pointer;
}

.duel-friends {
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
}

.send-list {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--sp-2);
}

.send-friend .profile-face {
	width: 32px;
	height: 32px;
	margin-right: var(--sp-2);
	border-width: 2px;
}

.send-friend:disabled {
	opacity: 0.6;
}

/* Duel history (duel screen), one line per friend. */
.duel-history ul {
	display: flex;
	flex-direction: column;
	gap: var(--sp-2);
	margin: 0;
	padding: 0;
	list-style: none;
}

.duel-history li {
	display: grid;
	grid-template-columns: auto 1fr;
	grid-template-rows: auto auto;
	column-gap: var(--sp-3);
	align-items: center;
}

.duel-history .profile-face {
	grid-row: span 2;
	width: 44px;
	height: 44px;
}

.duel-history li span:last-child {
	font-size: var(--fs-1);
	color: var(--muted);
}

/* ---------- Avatar ---------- */

svg.avatar {
	display: block;
	width: 100%;
	height: 100%;
}

.profile-pill {
	gap: var(--sp-2);
	padding-left: 3px;
	text-decoration: none;
	color: var(--text);
}

.pill-avatar {
	width: 34px;
	height: 34px;
	overflow: hidden;
	border: 2px solid var(--line);
	border-radius: 50%;
	flex: none;
}

.avatar-stage {
	position: sticky;
	top: 0;
	z-index: 2;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-2) 0 var(--sp-3);
	background: linear-gradient(var(--paper) 85%, transparent);
}

.avatar-preview {
	width: min(44vw, 170px);
	aspect-ratio: 1;
	overflow: hidden;
	border: var(--bw) solid var(--line);
	border-radius: 50%;
	box-shadow: var(--shadow-lg);
}

.avatar-stage .btn {
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	gap: var(--sp-2);
	font-size: var(--fs-2);
}

.avatar-stage .btn svg {
	fill: var(--gold);
	stroke: var(--line);
	stroke-width: 1.6;
}

.avatar-groups {
	display: flex;
	flex-direction: column;
	gap: var(--sp-4);
	padding-bottom: var(--sp-6);
}

.avatar-group {
	margin: 0;
	padding: 0;
	border: 0;
}

.avatar-group legend {
	padding: 0;
	margin-bottom: var(--sp-2);
	font-weight: 800;
}

.avatar-options {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
	gap: var(--sp-2);
}

.avatar-option {
	position: relative;
	aspect-ratio: 1;
	padding: 0;
	overflow: hidden;
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	cursor: pointer;
}

.avatar-option[aria-pressed='true'],
.avatar-swatch[aria-pressed='true'] {
	outline: 4px solid var(--accent);
	outline-offset: 2px;
}

.avatar-option.is-locked svg.avatar {
	filter: grayscale(1) brightness(0.6);
}

.avatar-lock {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	color: #fff;
	font-size: 26px;
}

.avatar-swatches {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-2);
}

.avatar-swatch {
	width: 44px;
	height: 44px;
	border: var(--bw) solid var(--line);
	border-radius: 50%;
	cursor: pointer;
}

.avatar-lock-msg {
	min-height: 1.2em;
	margin-top: var(--sp-1);
	font-size: var(--fs-1);
	font-weight: 700;
	color: var(--muted);
}

.duel-face {
	width: 120px;
	aspect-ratio: 1;
	overflow: hidden;
	border: var(--bw) solid var(--line);
	border-radius: 50%;
	box-shadow: var(--shadow);
}

/* omokage drawings bring their own strokes: drop the icon defaults that the
   global svg rule above would make them inherit (thicker outlines). */
svg.avatar {
	fill: initial;
	stroke: initial;
	stroke-width: initial;
	stroke-linecap: initial;
	stroke-linejoin: initial;
}

.avatar-colors {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-2);
	margin-top: var(--sp-2);
}

.avatar-swatch.is-auto {
	background: repeating-linear-gradient(45deg, #d8d2dc 0 6px, #ffffff 6px 12px);
}

.avatar-option svg.avatar {
	background: #ffffff;
}

/* ---------- Profiles ---------- */

button.profile-pill {
	font: inherit;
	cursor: pointer;
}

.profile-list {
	margin: 0;
	padding: 0;
	list-style: none;
	display: grid;
	gap: var(--sp-2);
}

.profile-row {
	width: 100%;
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-2) var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	color: var(--text);
	box-shadow: var(--shadow-sm);
	text-align: left;
	cursor: pointer;
}

.profile-row.is-current {
	background: var(--accent-soft);
	box-shadow: var(--shadow);
}

.profile-face {
	flex: none;
	width: 52px;
	height: 52px;
	overflow: hidden;
	border: 2px solid var(--line);
	border-radius: 50%;
}

.profile-name {
	display: flex;
	flex-direction: column;
	font-weight: 800;
	font-size: var(--fs-3);
	line-height: 1.15;
}

.profile-name small {
	font-size: var(--fs-1);
	font-weight: 700;
	color: var(--muted);
}

.profile-name small svg {
	fill: var(--gold);
	stroke: var(--line);
	stroke-width: 1.6;
	vertical-align: -2px;
}

.profile-actions {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-2);
}

.profile-actions .btn {
	flex: 1 1 auto;
	min-height: 44px;
	padding-inline: var(--sp-3);
	font-size: var(--fs-1);
}

/* Duel: who challenges (the current profile) */
.duel-player {
	display: flex;
	align-items: center;
	gap: 12px;
}

.duel-player-name {
	flex: 1;
	line-height: 1.2;
	min-width: 0;
	font-weight: 800;
	overflow-wrap: anywhere;
}

/* Loading screen (index.html + js/splash.js) */
.splash {
	position: fixed;
	inset: 0;
	z-index: 100;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: var(--sp-5);
	padding: calc(var(--sp-4) + env(safe-area-inset-top)) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
	background-color: var(--paper);
	background-image: radial-gradient(var(--halftone) 1.5px, transparent 1.6px);
	background-size: 14px 14px;
	transition: opacity 0.3s ease;
}

.splash .logo {
	margin: 0;
	font-size: calc(var(--fs-5) * 1.6);
}

.splash-bar {
	width: min(240px, 70vw);
	height: 12px;
	overflow: hidden;
	border: var(--bw) solid var(--line);
	border-radius: 999px;
	background: var(--panel);
}

.splash-bar span {
	display: block;
	width: 10%;
	height: 100%;
	background: var(--accent);
	transition: width 0.4s ease;
}

.splash-actions {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: var(--sp-3);
	width: min(320px, 100%);
}

.splash-actions:empty {
	display: none;
}

.splash.is-ready .splash-bar {
	display: none;
}

.splash-mute {
	position: absolute;
	top: calc(var(--sp-4) + env(safe-area-inset-top));
	/* Top right corner of the game column (480px), not of a wide screen. */
	right: max(var(--sp-4), calc(50% - 240px + var(--sp-4)));
}

.splash.is-leaving {
	opacity: 0;
	pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
	.splash,
	.splash-bar span {
		transition: none;
	}
}

/* Home: play, and quit (back to the loading screen, music off) */
.dock-play {
	display: flex;
	gap: var(--sp-3);
}

.dock-play .btn-xl {
	flex: 1;
	width: auto;
}

.btn-quit {
	flex: none;
	width: 76px;
	padding: var(--sp-1);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 2px;
	font-size: var(--fs-1);
}

.btn-quit svg {
	width: 24px;
	height: 24px;
}

/* ---------- Training and daily bonus ---------- */

.btn-training {
	position: relative;
}

.todo-dot {
	position: absolute;
	top: 6px;
	right: 6px;
	width: 12px;
	height: 12px;
	border: 2px solid var(--line);
	border-radius: 50%;
	background: var(--accent);
}

.train-option {
	display: grid;
	gap: var(--sp-2);
	padding: var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
}

.train-option p {
	margin: 0;
}

.train-name {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	font-weight: 800;
	font-size: var(--fs-3);
}

.train-name svg,
.boss-bonus svg,
.bonus-won svg,
.stats-empty svg {
	flex: none;
	width: 22px;
	height: 22px;
}

.train-meta {
	color: var(--muted);
	font-size: var(--fs-1);
	font-weight: 700;
}

.boss-bonus {
	display: flex;
	align-items: center;
	gap: var(--sp-1);
	margin: 0;
	color: var(--text);
	font-size: var(--fs-1);
	font-weight: 800;
}

.boss-bonus svg {
	fill: var(--gold);
	stroke: var(--line);
}

.bonus-won {
	width: 100%;
	padding: var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--gold);
	color: var(--line);
	text-align: center;
	box-shadow: var(--shadow);
}

.bonus-won svg {
	fill: var(--panel);
	stroke: var(--line);
}

.bonus-won p {
	margin: 0;
	display: flex;
	justify-content: center;
	align-items: center;
	gap: var(--sp-2);
}

/* ---------- Progress page (#stats) ---------- */

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

.view-switch {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--sp-2);
}

.view-switch .btn {
	min-height: 44px;
	font-size: var(--fs-2);
}

.stats-block {
	display: grid;
	gap: var(--sp-3);
	padding: var(--sp-4);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: var(--panel);
	box-shadow: var(--shadow);
}

.stats-block h2 {
	margin: 0;
	font-size: var(--fs-4);
	line-height: 1.1;
}

.stats-sub {
	margin: var(--sp-2) 0 0;
	font-size: var(--fs-2);
}

.stats-hint {
	margin: 0;
	color: var(--muted);
	font-size: var(--fs-1);
}

.stats-first {
	text-align: center;
}

.stats-hero {
	display: grid;
	grid-template-columns: auto 1fr;
	align-items: center;
	gap: var(--sp-3);
}

.stats-hero .note {
	grid-column: 1 / -1;
	margin: 0;
}

.stats-face {
	width: 88px;
	height: 88px;
	overflow: hidden;
	border: var(--bw) solid var(--line);
	border-radius: 50%;
	background: var(--panel);
}

.hero-numbers {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--sp-2);
	margin: 0;
	padding: 0;
	list-style: none;
}

.hero-numbers li {
	display: grid;
	text-align: center;
	font-size: var(--fs-1);
	font-weight: 700;
	color: var(--muted);
	line-height: 1.2;
}

.hero-numbers b {
	font-size: var(--fs-5);
	color: var(--text);
	font-variant-numeric: tabular-nums;
}

.trophies {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: var(--sp-2);
	margin: 0;
	padding: 0;
	list-style: none;
}

.trophy {
	display: grid;
	justify-items: center;
	gap: 2px;
	padding: var(--sp-3) var(--sp-2);
	border: 2px solid var(--line);
	border-radius: var(--r-1);
	background: var(--accent-soft);
	text-align: center;
	font-size: var(--fs-1);
	font-weight: 700;
	line-height: 1.2;
}

.trophy-wide {
	grid-column: 1 / -1;
}

.trophy svg {
	width: 26px;
	height: 26px;
}

.trophy b {
	font-size: var(--fs-4);
	font-variant-numeric: tabular-nums;
}

.trophy-sss {
	font-weight: 800;
	color: var(--g-sss-a);
}

.weak-list {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-2);
	margin: 0;
	padding: 0;
	list-style: none;
}

.weak-list li {
	padding: var(--sp-1) var(--sp-3);
	border: 2px solid var(--line);
	border-radius: var(--r-full);
	background: var(--bad-soft);
	font-weight: 800;
}

.stats-empty {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	margin: 0;
	font-weight: 800;
	color: var(--good);
}

/* Times tables grid: one hue, light to dark = better known; a heart on the
   facts known by heart, so the meaning never rests on the colour alone. */
.heatmap-wrap {
	overflow-x: auto;
}

.heatmap {
	width: 100%;
	border-collapse: separate;
	border-spacing: 2px;
	font-size: var(--fs-1);
	font-variant-numeric: tabular-nums;
}

.heatmap th {
	color: var(--muted);
	font-weight: 800;
	text-align: center;
}

.heat {
	height: 26px;
	min-width: 22px;
	padding: 0;
	border-radius: 4px;
	text-align: center;
	vertical-align: middle;
}

.heat svg {
	width: 14px;
	height: 14px;
	fill: var(--panel);
	stroke: none;
}

.heat-legend .heat {
	display: inline-grid;
	place-items: center;
}

.heat-legend .heat svg {
	width: 10px;
	height: 10px;
}

.heat.b0 {
	background: transparent;
	box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--muted) 45%, transparent);
}

.heat.b1 {
	background: color-mix(in srgb, var(--good) 35%, var(--panel));
}

.heat.b2 {
	background: color-mix(in srgb, var(--good) 60%, var(--panel));
}

.heat.b3 {
	background: color-mix(in srgb, var(--good) 82%, var(--panel));
}

.heat.b4 {
	background: color-mix(in srgb, var(--good) 93%, var(--panel));
}

.heat.b5 {
	background: var(--good);
}

.heat-legend {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-1) var(--sp-3);
	margin: 0;
	padding: 0;
	list-style: none;
	font-size: var(--fs-1);
	color: var(--muted);
}

.heat-legend li {
	display: flex;
	align-items: center;
	gap: var(--sp-1);
}

.heat-legend i {
	display: inline-block;
	width: 14px;
	height: 14px;
	min-width: 0;
}

.mastery-list {
	display: grid;
	gap: var(--sp-2);
	margin: 0;
	padding: 0;
	list-style: none;
}

.mastery-list li {
	display: grid;
	grid-template-columns: minmax(0, 1.4fr) 1fr auto;
	align-items: center;
	gap: var(--sp-2);
	font-size: var(--fs-1);
	font-weight: 700;
}

.mastery-list b {
	font-variant-numeric: tabular-nums;
}

/* Activity: one bar per day, 14 days, the count on hover and for screen readers. */
.stats-activity {
	margin: 0;
}

.activity-bars {
	display: grid;
	grid-template-columns: repeat(14, 1fr);
	align-items: end;
	gap: 2px;
	height: 96px;
	margin: 0;
	padding: 0;
	list-style: none;
	border-bottom: 2px solid var(--star-off);
}

.activity-bars li {
	height: 100%;
	display: flex;
	align-items: flex-end;
}

.activity-bars i {
	display: block;
	width: 100%;
	border-radius: 4px 4px 0 0;
	background: var(--accent);
}

.stats-activity figcaption {
	display: flex;
	justify-content: space-between;
	margin-top: var(--sp-1);
	font-size: var(--fs-1);
	color: var(--muted);
}

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

.stats-table {
	width: 100%;
	border-collapse: collapse;
	font-size: var(--fs-1);
	font-variant-numeric: tabular-nums;
}

.stats-table th,
.stats-table td {
	padding: var(--sp-1) var(--sp-2);
	border-bottom: 1px solid var(--star-off);
	text-align: left;
	white-space: nowrap;
}

.stats-table thead th {
	color: var(--muted);
}

.stats-table tbody th {
	font-weight: 800;
	white-space: normal;
}

.stats-table .mini-stars svg {
	width: 14px;
	height: 14px;
}

/* Small phones (360px): the logo stacks "Math" over "Powa" so that the
   four header buttons keep their 44px. */
@media (max-width: 400px) {
	.app-home .logo {
		font-size: var(--fs-4);
		line-height: 1;
	}

	.app-home .logo span {
		margin: 2px 0 0;
	}

	.app-home .head-actions {
		gap: var(--sp-1);
	}

	.app-home .profile-pill {
		padding-inline: var(--sp-2);
	}
}
