/*
   Full-screen pages over the game (pages.js): the bar with Back, the scroll
   under it, and the slide in and out; then Player stats (player-stats.js).
   Loaded in order with the others (see index.html): a later rule wins. */

.page {
	position: absolute;
	inset: 0; /* the whole screen; its own padding keeps it clear of a notch and the home bar */
	z-index: 100; /* over the game; popups come later in the page, so over it */
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
	background: var(--page);
	background-color: var(--row);
	color: var(--text);
}

.page[hidden] {
	display: none;
}

.page-bar {
	flex: none;
	display: grid;
	grid-template-columns: 1fr auto 1fr; /* the title in the middle, whatever Back's width */
	align-items: center;
	gap: calc(2 * var(--m));
	padding: calc(1.5 * var(--m)) calc(2 * var(--m));
	border-bottom: 1px solid var(--text-muted);
}

.page-back {
	justify-self: start;
	display: grid;
	place-items: center;
	width: calc(7 * var(--m));
	height: calc(7 * var(--m));
	padding: 0;
	border: var(--border);
	border-radius: var(--radius);
	background: var(--button);
	color: var(--text);
	font-family: var(--font);
	font-size: calc(3 * var(--m));
	font-weight: 500;
	cursor: pointer;
}

.page-back:active {
	background: var(--button-pressed);
}

.page-back .icon {
	width: calc(4.5 * var(--m));
	height: calc(4.5 * var(--m));
	fill: none;
	stroke: currentColor;
	stroke-width: 2.5;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.page-title {
	margin: 0;
	font-size: calc(3.8 * var(--m));
	font-weight: 600;
}

.page-scroll {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain; /* its end doesn't drag the app (or Back) along */
	-webkit-overflow-scrolling: touch;
}

.page-body {
	box-sizing: border-box;
	max-width: calc(150 * var(--m));
	margin: 0 auto;
	padding: calc(2.5 * var(--m)) calc(3 * var(--m)) calc(3 * var(--m) + env(safe-area-inset-bottom));
}

/* Popups open as a page came, waiting under it once it's in (pages.js). */
.settings-background.under-page {
	display: none; /* not visibility: what's inside can make itself visible (the start screen does) */
}

/* Player stats */
.ps-empty {
	text-align: center;
}

.ps-player[hidden],
.ps-filled[hidden],
.ps-none[hidden],
.ps-kinds[hidden],
.ps-charts[hidden],
.ps-modes[hidden],
.ps-everyone[hidden],
.ps-doubles[hidden],
.ps-start-pick[hidden],
.ps-caret[hidden],
.ps-pick[hidden] {
	display: none;
}

/* The name, a dropdown of who else can be shown: this device's player in green. */
.ps-head {
	position: relative;
	display: flex;
	justify-content: center;
	margin-bottom: calc(1.5 * var(--m));
}

/* The name alone is centred; the arrow hangs off its right. */
.ps-name-btn {
	position: relative;
	display: flex;
	align-items: center;
	padding: calc(0.5 * var(--m)) calc(1.5 * var(--m));
	border: none;
	border-radius: var(--radius);
	background: none;
	color: var(--text);
	font-family: var(--font);
	font-size: calc(5 * var(--m));
	font-weight: 600;
	cursor: pointer;
}

.ps-name-btn:disabled {
	cursor: default;
}

.ps-name-btn:not(:disabled):active {
	background: var(--button-pressed);
}

.ps-name-btn.is-main,
.ps-pick-item.is-main {
	color: var(--checkout);
}

.ps-caret {
	position: absolute;
	left: 100%;
	top: 50%;
	width: calc(3 * var(--m));
	height: calc(3 * var(--m));
	margin-top: calc(-1.5 * var(--m));
	color: var(--text-muted);
	fill: none;
	stroke: currentColor;
	stroke-width: 2.5;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.ps-pick {
	position: absolute;
	top: 100%;
	left: 50%;
	z-index: 2;
	display: flex;
	flex-direction: column;
	min-width: calc(40 * var(--m));
	max-height: calc(60 * var(--m));
	overflow-y: auto;
	padding: calc(1 * var(--m));
	gap: calc(0.5 * var(--m));
	background: var(--panel);
	border: var(--border);
	border-radius: var(--radius);
	box-shadow: 0 calc(0.5 * var(--m)) calc(2 * var(--m)) rgba(0, 0, 0, 0.5);
	transform: translateX(-50%);
}

.ps-pick-item {
	padding: calc(1.2 * var(--m)) calc(2 * var(--m));
	border: none;
	border-radius: calc(var(--radius) * 0.6);
	background: none;
	color: var(--text);
	font-family: var(--font);
	font-size: calc(3.2 * var(--m));
	font-weight: 500;
	text-align: left;
	cursor: pointer;
}

.ps-pick-item[aria-checked="true"],
.ps-pick-item:active {
	background: var(--button-disabled);
}

/* X01, cricket, the party games, practice: under the name. */
.ps-kinds {
	display: flex;
	width: fit-content;
	max-width: 100%;
	margin: 0 auto calc(1.5 * var(--m));
	overflow-x: auto;
}

.ps-none {
	text-align: center;
}

/* Which games count, under the kinds: dates, who against, the start; as Game history's dates. */
.ps-filters {
	justify-content: center;
	margin-bottom: calc(2 * var(--m));
}

.ps-since:empty {
	display: none;
}

.ps-since {
	margin: 0 0 calc(2 * var(--m));
	text-align: center;
	font-family: var(--font-condensed);
	font-size: calc(2.8 * var(--m));
	color: var(--text-soft);
}

.ps-tiles {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); /* in a row; on a phone upright, two by two */
	gap: calc(1.5 * var(--m));
	margin-bottom: calc(3 * var(--m));
}

.ps-tile {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: calc(1.5 * var(--m)) calc(1 * var(--m));
	border: var(--border-muted);
	border-radius: var(--radius);
	background: var(--panel);
}

.ps-tile-value {
	font-size: calc(6 * var(--m));
	font-weight: 600;
	line-height: 1.1;
}

.ps-tile-label {
	font-size: calc(2.6 * var(--m));
	color: var(--text-soft);
}

.ps-tile-note {
	font-family: var(--font-condensed);
	font-size: calc(2.4 * var(--m));
	color: var(--text-muted);
}

/* The trends beside the board, side by side in landscape, one under the other upright. */
.ps-charts {
	display: flex;
	justify-content: center;
	align-items: flex-start;
	gap: calc(4 * var(--m));
	margin-bottom: calc(3 * var(--m));
}

.ps-charts .trend,
.ps-charts .heat {
	margin-bottom: 0;
}

/* A card per game played (the party games, practice), its own stats summed. */
.ps-modes {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(calc(44 * var(--m)), 1fr));
	gap: calc(1.5 * var(--m));
	margin-bottom: calc(3 * var(--m));
}

.ps-mode {
	padding: calc(1.5 * var(--m)) calc(2 * var(--m));
	border: var(--border-muted);
	border-radius: var(--radius);
	background: var(--panel);
}

.ps-mode-head {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: calc(1 * var(--m));
	margin: 0 0 calc(1 * var(--m));
}

.ps-mode-name {
	font-size: calc(3.2 * var(--m));
	font-weight: 600;
}

.ps-mode-games,
.ps-mode-note {
	font-family: var(--font-condensed);
	font-size: calc(2.4 * var(--m));
	color: var(--text-muted);
}

.ps-mode-rows {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: calc(0.6 * var(--m)) calc(2 * var(--m));
	margin: 0;
	font-family: var(--font-condensed);
	font-size: calc(2.8 * var(--m));
}

.ps-mode-rows dt {
	color: var(--text-soft);
}

.ps-mode-rows dd {
	margin: 0;
	text-align: right;
	font-weight: 500;
}

/* The game's number per game, under its stats. */
.ps-mode-trend {
	margin-top: calc(2 * var(--m));
}

/* Game history: the kept games, newest first. */
.kept-body {
	max-width: calc(110 * var(--m));
}

.kept-row-line {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-family: var(--font-condensed);
	font-size: calc(2.6 * var(--m));
	font-weight: normal;
	color: var(--text);
}

.ps-doubles,
.ps-everyone {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-top: calc(2 * var(--m));
	border-top: 1px solid var(--text-muted);
}

.ps-heading {
	margin: 0 0 calc(1.5 * var(--m));
	font-size: calc(3.4 * var(--m));
	font-weight: 600;
}

.ps-doubles .stats-scroll,
.ps-everyone .stats-scroll {
	max-width: 100%;
}

.ps-doubles {
	margin-bottom: calc(3 * var(--m));
}

.ps-doubles-note {
	margin: calc(1 * var(--m)) 0 0;
	font-size: calc(2.4 * var(--m));
}

@media (orientation: portrait) {
	.ps-charts {
		flex-direction: column;
		align-items: center;
	}

}

@media (orientation: portrait) and (max-aspect-ratio: 3/5) {
	.ps-tiles {
		grid-template-columns: repeat(2, 1fr);
	}

	/* Three fit in a row; two by two would leave a gap. */
	.ps-tiles:has(> :nth-child(3):last-child) {
		grid-template-columns: repeat(3, 1fr);
	}
}
