/*
   New game: the game tiles, the match and options, who plays; the ⓘ tips and
   their bubble; popup buttons.
   Loaded in order with the others (see index.html): a later rule wins. */

/* New game: what to play as tiles, grouped, then its options and who plays. */
.new-game-section {
	width: max(50%, calc(78 * var(--m)));
}

/* The categories: X01, More games, Practice, a row of buttons across the
   panel; under it the picked one's tiles. */
.segmented.game-groups {
	display: flex;
	margin: calc(1.6 * var(--m)) calc(1 * var(--m)) calc(1.6 * var(--m));
}

.game-groups button {
	padding: calc(1.2 * var(--m));
	font-size: calc(3 * var(--m));
}

.game-tiles {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: calc(1.4 * var(--m));
	padding: 0 calc(1 * var(--m));
}

/* Four games: two rows of two. */
.game-tiles.two-up {
	grid-template-columns: repeat(2, 1fr);
}

.game-tile {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: calc(0.3 * var(--m));
	min-height: calc(9 * var(--m));
	padding: calc(1 * var(--m));
	font-family: var(--font-condensed);
	color: var(--text);
	text-shadow: 0 0 8px black;
	border: var(--border);
	border-radius: var(--radius);
	background: var(--button);
	cursor: pointer;
}

.game-tile:active {
	transform: scale(0.96);
}

/* A game with a note: the name at the top, so names in a row line up when a
   note (or a name) takes two lines. */
.game-tile:has(small) {
	justify-content: flex-start;
}

/* A group that leaves one tile on its last row: that tile in the middle. */
.game-tiles:not(.scroll-row, .two-up) > .game-tile:last-child:nth-child(3n + 1) {
	grid-column: 2;
}

.game-tile b {
	font-size: calc(3 * var(--m));
	font-weight: 500;
}

/* X01's starts: one row of three in view, scrolling sideways to the rest
   (101 before, 901, 1001 and Custom after), the edges faded where there's more. */
.game-tiles.scroll-row {
	grid-template-columns: none;
	grid-auto-flow: column;
	/* Three in view, with a sliver of the next on either side to show there's more. */
	--peek: calc(5 * var(--m));
	grid-auto-columns: calc((100% - 4 * 1.4 * var(--m) - 2 * var(--peek)) / 3);
	scroll-padding-inline: calc(1 * var(--m));
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
	--fade-left: 0px;
	--fade-right: 0px;
	mask-image: linear-gradient(to right, transparent, black var(--fade-left), black calc(100% - var(--fade-right)), transparent);
}

.game-tiles.scroll-row::-webkit-scrollbar {
	display: none;
}

.scroll-row > .game-tile {
	scroll-snap-align: center;
}

/* The two at each end can't come to the middle: the row's ends are their stops
   instead (a stop past the end, Safari scrolls to, then snaps back). */
.scroll-row > .game-tile:nth-child(2),
.scroll-row > .game-tile:nth-last-child(2) {
	scroll-snap-align: none;
}

.scroll-row > .game-tile:first-child {
	scroll-snap-align: start;
}

.scroll-row > .game-tile:last-child {
	scroll-snap-align: end;
}

.scroll-row.more-left {
	--fade-left: calc(var(--peek) + 1.4 * var(--m));
}

.scroll-row.more-right {
	--fade-right: calc(var(--peek) + 1.4 * var(--m));
}

.game-tile.custom-tile b {
	font-size: calc(3.4 * var(--m));
}

/* X01's tiles are just the start score: bigger. */
.game-tile:not(:has(small)) b {
	font-size: calc(4.4 * var(--m));
}

.game-tile small {
	font-size: calc(2 * var(--m));
	color: var(--text-soft);
}

.game-tile[aria-checked="true"] {
	border-color: var(--checkout);
	background: linear-gradient(var(--go-top), var(--go-bottom));
}

/* Under the tiles, only what the picked game has: the match, with legs and
   sets as − n + steppers, then its options. */
.match-row {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	margin: calc(2 * var(--m)) calc(1 * var(--m)) 0;
	color: var(--text);
	font-size: calc(3 * var(--m));
}

/* Sliding between its two steps, the panel shows no scrollbar. */
.new-game-section.sliding {
	overflow: hidden;
}

/* First to: the legs and sets slide out beside the match picker; Endless
   (no winner) folds them away. It takes the rest of the row, so 0fr really is
   nothing: sized to its content, the column never folded and only the fade showed. */
.counts-reveal {
	flex: 1 1 0;
	min-width: 0;
	display: grid;
	grid-template-columns: 0fr;
	opacity: 0;
	transition: grid-template-columns var(--medium) var(--ease-out), opacity var(--medium) var(--ease-out);
}

.counts-reveal.open {
	grid-template-columns: 1fr;
	opacity: 1;
}

.counts-reveal.instant {
	transition: none;
}

.counts {
	display: flex;
	gap: calc(2.5 * var(--m));
	min-width: 0;
	overflow: hidden;
	padding-left: calc(3 * var(--m));
	white-space: nowrap;
}

.stepper,
.option-choice {
	display: flex;
	flex-direction: column;
	gap: calc(0.75 * var(--m));
}

.stepper-label {
	font-family: var(--font-condensed);
	color: var(--text-soft);
}

.stepper-row {
	display: flex;
	align-items: center;
}

.stepper-btn {
	width: calc(5.5 * var(--m));
	height: calc(5.5 * var(--m));
	padding: 0;
	font-family: var(--font);
	font-size: calc(3.4 * var(--m));
	line-height: 1;
	color: var(--text);
	border: var(--border);
	border-radius: var(--radius);
	background: var(--button);
	cursor: pointer;
}

.stepper-btn:active {
	transform: scale(0.92);
}

.stepper-btn:disabled {
	opacity: 0.35;
	cursor: default;
}

.stepper output {
	min-width: calc(6 * var(--m));
	font-family: var(--font-condensed);
	font-size: calc(3.6 * var(--m));
	font-weight: 500;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

/* Options: Double out, or the game's own choice (around the clock's beds)
   and checkboxes, labelled like Match. A game with none has no section. */
.game-options-group {
	display: flex;
	flex-direction: column;
	gap: calc(0.75 * var(--m));
	margin: calc(2 * var(--m)) calc(1 * var(--m)) 0;
	font-size: calc(3 * var(--m));
}

.game-options-group:not(:has(.check-line:not([hidden]), .segmented.mode-check, .more-rules)) {
	display: none;
}

.game-checks {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: calc(0.8 * var(--m)) calc(4 * var(--m));
	/* Always as tall as around the clock's bed buttons, so picking another
	   game never resizes the screen. */
	min-height: calc(7 * var(--m));
	color: var(--text);
	white-space: nowrap;
}


/* ⓘ: a small circled i beside something that may need explaining (app.js). */
.info-btn {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: calc(2.4 * var(--m));
	height: calc(2.4 * var(--m));
	padding: 0;
	margin-left: calc(0.8 * var(--m));
	font-family: var(--font);
	font-size: calc(1.6 * var(--m));
	font-weight: 600;
	line-height: 1;
	touch-action: manipulation;
	color: var(--text-soft);
	background: none;
	border: 1px solid var(--text-muted);
	border-radius: 50%;
	cursor: help;
	transition: color var(--fast), border-color var(--fast);
}

/* A finger-sized tap area round the small circle, so a tap just beside it
   still opens the tip rather than ticking the checkbox it sits in. */
.info-btn::before {
	content: '';
	position: absolute;
	inset: calc(-1.6 * var(--m));
	border-radius: 50%;
}

.info-btn:hover,
.info-btn[aria-describedby] {
	color: var(--text);
	border-color: var(--text);
}

/* Anything with an ⓘ lines it up the same way: centred on the text, the same
   gap after it. A checkbox's ⓘ sits beside its label rather than in it, so
   pressing the ⓘ doesn't flash the checkbox. */
.check-line,
.stepper-label,
.range-name {
	display: flex;
	align-items: center;
}

/* The bubble it opens, over everything. */
.info-tip {
	position: fixed;
	z-index: 200;
	max-width: min(calc(40 * var(--m)), 90vw);
	box-sizing: border-box;
	padding: calc(1.2 * var(--m)) calc(1.6 * var(--m));
	font-family: var(--font-condensed);
	font-size: calc(2.4 * var(--m));
	line-height: 1.35;
	color: var(--text);
	background: var(--field);
	border: 1px solid var(--text-muted);
	border-radius: var(--radius);
	box-shadow: 0 calc(1 * var(--m)) calc(3 * var(--m)) rgba(0, 0, 0, 0.6);
	pointer-events: none;
}

.info-tip.opening {
	animation: fade-in var(--medium) var(--ease-out);
}

.info-tip.closing {
	animation: fade-out var(--medium) var(--ease-out) forwards;
}

/* Cancel and the next step, edge to edge with the tiles above. */
.dialog-actions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: calc(1.4 * var(--m));
	margin: calc(2.4 * var(--m)) calc(1 * var(--m)) 0;
}

/* A row of buttons where one is picked (around the clock's beds, Solo or not). */
.segmented {
	display: inline-flex;
	border: var(--border);
	border-radius: var(--radius);
	overflow: hidden;
}

.segmented button {
	flex: 1;
	padding: calc(1 * var(--m)) calc(2.2 * var(--m));
	font-family: var(--font-condensed);
	font-size: calc(2.6 * var(--m));
	white-space: nowrap;
	color: var(--text);
	text-shadow: 0 0 8px black;
	border: none;
	background: var(--button-disabled);
	cursor: pointer;
}

.segmented button + button {
	border-left: 1px solid var(--text-muted);
}

.segmented button[aria-checked="true"] {
	background: linear-gradient(var(--go-top), var(--go-bottom));
}

/* As tall as the legs and sets steppers beside it, so their labels line up too. */
.match-format {
	box-sizing: border-box;
	height: calc(5.5 * var(--m));
}

/* No room for padding above and below: iOS would push the text down. */
.match-format button {
	padding-block: 0;
	line-height: 1;
}

/* Who's playing: Solo is one name; otherwise a list to add to and reorder. */
.segmented.who {
	display: flex;
	margin: calc(2 * var(--m)) calc(1 * var(--m)) 0;
}

.segmented.who button {
	padding: calc(1.4 * var(--m));
	font-size: calc(3 * var(--m));
}

.who-solo,
.who-group {
	margin: calc(2 * var(--m)) calc(1 * var(--m)) 0;
}

.solo-name {
	width: 100%;
	height: calc(6.5 * var(--m));
	box-sizing: border-box;
	padding: 0 calc(1.5 * var(--m));
	font-family: var(--font);
	font-size: calc(3.2 * var(--m));
	color: var(--text);
	background: var(--field);
	border: 1px solid var(--text-muted);
	border-radius: var(--radius);
	outline: none;
}

/* The Custom tile's box, where its start is typed. */
.game-tile .custom-start {
	width: 80%;
	height: calc(5.5 * var(--m));
	box-sizing: border-box;
	padding: 0 calc(1 * var(--m));
	font-family: var(--font);
	font-size: calc(2.8 * var(--m));
	text-align: center;
	color: var(--text);
	background: var(--field);
	border: 1px solid var(--text-muted);
	border-radius: var(--radius);
	outline: none;
}

.custom-start:focus,
.solo-name:focus {
	border-color: var(--text);
}

.custom-start[aria-invalid="true"] {
	border-color: var(--bust);
}

/* Under the starts while Custom's is out of range. */
.start-hint {
	margin: calc(0.8 * var(--m)) calc(1 * var(--m)) 0;
	font-size: calc(2.4 * var(--m));
	text-align: center;
	color: var(--bust);
}

/* vs Computer: its level under your name. Who throws first: the same, under the players. */
.who-cpu,
.who-starts {
	display: flex;
	flex-direction: column;
	gap: calc(0.8 * var(--m));
	margin: calc(2 * var(--m)) calc(1 * var(--m)) 0;
	color: var(--text);
	font-size: calc(3 * var(--m));
}

.who-cpu .stepper-label,
.who-starts .stepper-label {
	font-size: calc(2.8 * var(--m));
}

.bot-levels button,
.starts button {
	flex: 1;
	padding: calc(1.2 * var(--m)) calc(1 * var(--m));
	font-size: calc(2.8 * var(--m));
}

/* Two or more: add a player, or a computer. */
.draft-adds {
	display: flex;
	gap: calc(1 * var(--m));
}

.draft-add-bot {
	flex: 0 0 30%;
	font-size: calc(2.6 * var(--m)) !important;
}

/* A computer in the list: its name is its level, tapped to change it. */
.draft-list .bot-player input {
	cursor: pointer;
	color: var(--text-soft);
}

/* During a game it keeps its level: the field only says it. */
.players-list .bot-player input {
	color: var(--text-soft);
}

.draft-list {
	max-height: calc(42 * var(--m));
	margin: 0;
	padding: 0;
	list-style: none;
}

.draft-list .player-field input {
	padding-left: calc(1.5 * var(--m));
}

.settings-btn-action {
	width: 100%;
	padding: calc(1 * var(--m));
	font-family: var(--font-condensed);
	font-size: calc(4 * var(--m));
	font-weight: 500;
	color: var(--text);
	text-shadow: 0 0 8px black;
	border: var(--border);
	border-radius: var(--radius);
	background: var(--button);
	cursor: pointer;
}

.settings-btn-action:active {
	background: var(--button-pressed);
}

/* The action that settings changes are waiting on (Start new game). */
.settings-btn-action.primary {
	border-color: var(--checkout);
	background: linear-gradient(var(--go-top), var(--go-bottom));
	animation: fade-in var(--medium) var(--ease-out);
}

/* Smaller link-style button that opens a sub-page of Settings. */
.settings-btn-action.settings-link {
	font-size: calc(3 * var(--m));
	font-weight: normal;
	background: var(--button-disabled);
}

/* In a popup, a quiet button (Close) is as tall as the full one beside it
   (Lifetime stats, Board layout): its smaller text gets the difference as padding.
   The start screen's links stay smaller, under its two big buttons. */
.settings-background:not(.start-screen) .settings-btn-action.settings-link {
	padding-block: calc(1.55 * var(--m));
}
