/*
 * Statistics page: key figures, one tab per competition, score distribution and card lists.
 * Loaded after base.css (colors, reset, site header).
 */

.stats-page {
	display: flex;
	flex-direction: column;
	min-height: 100dvh;
}

.stats {
	width: 100%;
	max-width: 1120px;
	margin: 0 auto;
	padding: 24px 16px calc(32px + env(safe-area-inset-bottom));
}

.stats__title {
	margin: 0;
	font-size: clamp(32px, 9vw, 56px);
	font-weight: 800;
	line-height: 1;
	letter-spacing: -0.02em;
}

.stats__intro {
	margin: 10px 0 0;
	color: var(--ink-soft);
	font-size: 16px;
	line-height: 1.4;
}

.stats__section {
	margin-top: 28px;
}

.stats__heading {
	margin: 0 0 12px;
	font-size: 20px;
	font-weight: 800;
}

.stats__subheading {
	margin: 0 0 12px;
	font-size: 17px;
	font-weight: 800;
}

.stats__note,
.stats__updated {
	margin: 10px 0 0;
	color: var(--ink-soft);
	font-size: 13px;
	line-height: 1.4;
}

.stats__updated {
	margin-top: 28px;
	text-align: center;
}

.stats__empty {
	margin: 0;
	padding: 18px;
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--ink-soft);
	text-align: center;
}

/* Message of a competition without games, under its tiles. */
.stats__competition > .stats__empty {
	margin-top: 16px;
}

/* Key figures: two per row on mobile, four (or three when there are six) on wide screens. */

.tiles {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 10px;
}

.tile {
	padding: 14px;
	border-radius: var(--radius);
	background: var(--surface);
	box-shadow: 0 1px 3px rgba(11, 31, 58, 0.08);
}

.tile p {
	margin: 0;
}

.tile__label {
	color: var(--ink-soft);
	font-size: 13px;
	font-weight: 700;
}

.tile__value {
	margin-top: 4px !important;
	font-size: 28px;
	font-weight: 800;
	line-height: 1.1;
	font-variant-numeric: tabular-nums;
}

.tile__note {
	margin-top: 4px !important;
	color: var(--ink-soft);
	font-size: 12px;
	line-height: 1.3;
}

/* The record of the player stands out in the site colors. */
.tile--you {
	background: var(--ink);
	color: #fff;
}

.tile--you .tile__label,
.tile--you .tile__note {
	color: rgba(255, 255, 255, 0.75);
}

.tile--you .tile__value {
	color: var(--accent);
}

/* Competition tabs: a segmented control that scrolls sideways if it must. */

.stats__tabs {
	display: flex;
	gap: 4px;
	margin-bottom: 18px;
	padding: 4px;
	overflow-x: auto;
	border-radius: var(--radius);
	background: var(--line);
}

/* Groups of tabs (national teams, international clubs, national clubs). On phones they are
   not laid out: every tab sits in the scrolling bar, a thin line between two groups. */
.stats__tab-group,
.stats__tab-row {
	display: contents;
}

.stats__tab-label {
	display: none;
}

.stats__tab-group + .stats__tab-group::before {
	content: "";
	flex: none;
	width: 1px;
	margin: 8px 4px;
	background: var(--muted);
}

.stats__tab {
	flex: 1 0 auto;
	min-height: 44px;
	padding: 0 10px;
	border: 0;
	border-radius: 9px;
	background: none;
	color: var(--ink-soft);
	font-size: 14px;
	font-weight: 800;
	white-space: nowrap;
	cursor: pointer;
}

.stats__tab:hover {
	color: var(--ink);
}

.stats__tab[aria-selected="true"] {
	background: var(--surface);
	color: var(--ink);
	box-shadow: 0 1px 4px rgba(11, 31, 58, 0.15);
}

.stats__tab:focus-visible,
.stats__play:focus-visible,
.stats__data summary:focus-visible {
	outline: 3px solid var(--accent);
	outline-offset: 2px;
}

.stats__competition-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 12px;
}

.stats__competition-head .stats__heading {
	margin: 0;
}

.stats__play {
	flex: none;
	padding: 10px 20px;
	border-radius: 999px;
	background: var(--accent);
	color: var(--ink);
	font-weight: 800;
	text-decoration: none;
}

.stats__play:hover {
	box-shadow: 0 4px 12px rgba(11, 31, 58, 0.2);
}

.stats__block {
	margin-top: 16px;
	padding: 16px;
	border-radius: var(--radius);
	background: var(--surface);
	box-shadow: 0 1px 3px rgba(11, 31, 58, 0.08);
}

/* Average score per period or level: name, games, bar, value. */

.choices {
	display: grid;
	gap: 12px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.choice {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: center;
	gap: 4px 12px;
}

.choice__name {
	font-weight: 700;
}

.choice__coefficient {
	color: var(--ink-soft);
	font-size: 13px;
	font-variant-numeric: tabular-nums;
}

.choice__games {
	color: var(--ink-soft);
	font-size: 13px;
	text-align: right;
}

.choice__track {
	height: 10px;
	overflow: hidden;
	border-radius: 5px;
	background: var(--bg);
}

.choice__bar {
	display: block;
	height: 100%;
	border-radius: 0 5px 5px 0;
	background: var(--ink);
}

.choice__value {
	min-width: 3ch;
	font-size: 17px;
	font-weight: 800;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

/* Score distribution (inline SVG, app/js/stats.js). */

.scores {
	display: block;
	width: 100%;
	height: auto;
	margin-top: 8px;
	overflow: visible;
}

.scores__grid {
	stroke: var(--line);
	stroke-width: 1;
}

.scores__axis {
	fill: var(--ink-soft);
	font-size: 12px;
	font-variant-numeric: tabular-nums;
}

.scores__bar {
	fill: var(--ink-soft);
}

.scores__bar--you {
	fill: var(--ink);
}

.scores__you-mark {
	fill: var(--accent);
	stroke: var(--ink);
	stroke-width: 1;
}

.scores__you {
	fill: var(--ink);
	font-size: 13px;
	font-weight: 800;
}

.scores__hit {
	fill: transparent;
}

.scores__hit:hover {
	fill: rgba(11, 31, 58, 0.06);
}

.stats__data {
	margin-top: 10px;
	font-size: 14px;
}

.stats__data summary {
	color: var(--ink-soft);
	font-weight: 700;
	cursor: pointer;
}

.stats__data table {
	width: 100%;
	max-width: 360px;
	margin-top: 8px;
	border-collapse: collapse;
}

.stats__data th,
.stats__data td {
	padding: 6px 8px;
	border-bottom: 1px solid var(--line);
	text-align: left;
}

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

.stats__data .is-you td {
	font-weight: 800;
}

/* Hardest and easiest cards. */

.cards-columns {
	display: grid;
	gap: 20px;
}

.cards__heading {
	margin: 0 0 10px;
	font-size: 16px;
	font-weight: 800;
}

.cards__list {
	display: grid;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.cards__item {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr);
	gap: 2px 10px;
	padding: 10px 12px;
	border-radius: 10px;
	background: var(--bg);
}

.cards__year {
	grid-row: span 2;
	align-self: start;
	padding: 2px 8px;
	border-radius: 6px;
	background: var(--ink);
	color: #fff;
	font-size: 13px;
	font-weight: 800;
	font-variant-numeric: tabular-nums;
}

.cards__text {
	font-size: 14px;
	line-height: 1.35;
}

.cards__rate {
	color: var(--ink-soft);
	font-size: 13px;
	font-weight: 700;
}

/* Pages of the statistics, under the title: General, Players. Links styled as the tabs. */

.stats__pages {
	display: inline-flex;
	gap: 4px;
	margin-top: 16px;
	padding: 4px;
	border-radius: var(--radius);
	background: var(--line);
}

.stats__page {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	padding: 0 20px;
	border-radius: 9px;
	color: var(--ink-soft);
	font-size: 15px;
	font-weight: 800;
	text-decoration: none;
}

.stats__page:hover {
	color: var(--ink);
}

.stats__page[aria-current="page"] {
	background: var(--surface);
	color: var(--ink);
	box-shadow: 0 1px 4px rgba(11, 31, 58, 0.15);
}

.stats__page:focus-visible,
.players__join-link:focus-visible,
.ranking__filter select:focus-visible {
	outline: 3px solid var(--accent);
	outline-offset: 2px;
}

/* Players page: invitation to create an account. */

.players__join {
	margin: 14px 0 0;
	padding: 12px 16px;
	border-left: 4px solid var(--accent);
	border-radius: 10px;
	background: var(--surface);
	font-size: 15px;
	font-weight: 700;
}

.players__join[hidden] {
	display: none;
}

.players__join-link {
	color: var(--ink);
	font-weight: 800;
}

/* Rankings: rank, player, figures. The signed-in player stands out in the site colors. */

.ranking__filter {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 12px;
	margin-bottom: 14px;
	font-size: 14px;
	font-weight: 700;
}

/* 16px at least: iOS zooms on smaller fields. */
.ranking__filter select {
	min-height: 44px;
	padding: 0 12px;
	border: 2px solid var(--line);
	border-radius: 10px;
	background: var(--surface);
	color: var(--ink);
	font: inherit;
	font-size: 16px;
}

.ranking {
	width: 100%;
	border-collapse: collapse;
	font-size: 15px;
}

.ranking th,
.ranking td {
	padding: 9px 8px;
	border-bottom: 1px solid var(--line);
	text-align: left;
}

.ranking th {
	color: var(--ink-soft);
	font-size: 13px;
	font-weight: 700;
}

.ranking .num {
	text-align: right;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.ranking__rank {
	width: 1%;
	text-align: center !important;
	font-variant-numeric: tabular-nums;
}

td.ranking__rank {
	font-weight: 800;
}

.ranking__player {
	font-weight: 800;
	overflow-wrap: anywhere;
}

.ranking__competition {
	color: var(--ink-soft);
	font-size: 14px;
}

.ranking__you {
	display: inline-block;
	padding: 1px 8px;
	border-radius: 999px;
	background: var(--accent);
	color: var(--ink);
	font-size: 12px;
	font-weight: 800;
}

.ranking tr.is-you td {
	background: rgba(11, 31, 58, 0.06);
}

/* Phones: three key figures, the last one alone on its row takes the whole width. */
@media (max-width: 719px) {
	.tiles > .tile:nth-child(3):last-child {
		grid-column: 1 / -1;
	}
}

/* Phones: the competition of the best score is left out of the overall ranking. */
@media (max-width: 559px) {
	.ranking th:nth-child(4):not(:last-child),
	.ranking .ranking__competition {
		display: none;
	}
}

/* Links to the page of a player in the rankings. */

.ranking__link {
	color: var(--ink);
	text-decoration: underline;
	text-decoration-color: var(--muted);
	text-underline-offset: 3px;
}

.ranking__link:hover {
	text-decoration-color: var(--ink);
}

.ranking__link:focus-visible,
.players__back:focus-visible {
	outline: 3px solid var(--accent);
	outline-offset: 2px;
}

/* Page of a player: name, figures, a card per competition, latest games. */

.players__back {
	display: inline-block;
	margin-bottom: 14px;
	color: var(--ink-soft);
	font-size: 15px;
	font-weight: 800;
	text-decoration: none;
}

.players__back:hover {
	color: var(--ink);
}

.player__name {
	margin: 0;
	font-size: clamp(26px, 7vw, 36px);
	font-weight: 800;
	line-height: 1.1;
	overflow-wrap: anywhere;
}

.player__since {
	margin: 6px 0 16px;
	color: var(--ink-soft);
	font-size: 15px;
}

.player__heading {
	margin-top: 28px;
}

.player-cards {
	display: grid;
	gap: 12px;
}

.player-card {
	display: flex;
	flex-direction: column;
	gap: 12px;
	padding: 16px;
	border-radius: var(--radius);
	background: var(--surface);
	box-shadow: 0 1px 3px rgba(11, 31, 58, 0.08);
}

.player-card__head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 6px 12px;
}

.player-card__name {
	margin: 0;
	font-size: 18px;
	font-weight: 800;
}

.player-card__rank {
	padding: 2px 10px;
	border-radius: 999px;
	background: var(--ink);
	color: #fff;
	font-size: 13px;
	font-weight: 800;
	font-variant-numeric: tabular-nums;
}

.player-card__figures {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	gap: 0;
	margin: 0;
	font-size: 14px;
}

.player-card__figures dt,
.player-card__figures dd {
	margin: 0;
	padding: 6px 0;
	border-bottom: 1px solid var(--line);
}

.player-card__figures dt {
	color: var(--ink-soft);
	font-weight: 700;
}

.player-card__figures dd {
	font-weight: 800;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.player-card__play {
	align-self: flex-start;
	margin-top: auto;
}

@media (min-width: 720px) {
	/* Wide enough to show every tab: one row per group, its label on the left. */
	.stats__tabs {
		flex-direction: column;
		gap: 2px;
		padding: 6px;
		overflow-x: visible;
	}

	.stats__tab-group {
		display: grid;
		grid-template-columns: 184px minmax(0, 1fr);
		align-items: start;
		gap: 8px;
	}

	.stats__tab-group + .stats__tab-group {
		padding-top: 2px;
		border-top: 1px solid rgba(11, 31, 58, 0.08);
	}

	.stats__tab-group + .stats__tab-group::before {
		content: none;
	}

	.stats__tab-label {
		display: block;
		padding: 12px 0 0 8px;
		color: var(--ink-soft);
		font-size: 11px;
		font-weight: 800;
		letter-spacing: 0.08em;
		text-transform: uppercase;
		white-space: nowrap;
	}

	.stats__tab-row {
		display: flex;
		flex-wrap: wrap;
		gap: 2px;
	}

	.stats__tab {
		flex: 0 0 auto;
		min-height: 38px;
		padding: 0 12px;
		font-size: 14px;
	}

	.tiles {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}

	/* Six key figures (every competition, challenges included): two rows of three; three on the Players page: one row. */
	.tiles:has(> .tile:nth-child(6):last-child),
	.tiles:has(> .tile:nth-child(3):last-child) {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

	.cards-columns {
		grid-template-columns: 1fr 1fr;
	}

	.player-cards {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.choice {
		grid-template-columns: minmax(180px, 1fr) 90px minmax(0, 2fr) 48px;
	}
}

@media (min-width: 960px) {
	/* Same alignment as the splash screen and the game header (1120px column, 32px gutters). */
	.masthead {
		padding: 14px max(32px, calc((100% - 1120px) / 2 + 32px));
	}

	.stats {
		padding: 36px 32px 48px;
	}

	.stats__block {
		padding: 20px 24px;
	}
}
