/*
   A phone: the board edge to edge, buttons in its corners, one player card at a
   time with the keypad.
   Loaded in order with the others (see index.html): a later rule wins. */

/* PHONE */

/* A portrait screen narrower than a tablet's (3:5, so a 9:16 phone still counts
   with its browser's bars taking some of the height). Stacked: the board on top,
   the players under it across the whole width, and under them the keypad, hidden
   to begin with. Along the top a strip of buttons; the board's corners and its
   right side keep the rest. */
@media (orientation: portrait) and (max-aspect-ratio: 3/5) {
	:root {
		--m: 1.3vmin;
		--top-drop: min(env(safe-area-inset-top), 3vmin); /* clear of iOS's blur under the status bar, into the room beside the round board */
		--side-pad: 2vmin;
		--ctrl-size: 11vmin;
		--board-top: 11vmin; /* clear of undo and redo, even with the status bar's drop */
		--board-d: 92vmin; /* short of the full width: the corners then hold their buttons clear of it */
		--row-one: calc(var(--board-top) + var(--board-d) + var(--side-pad));
		--slit: calc(14.5vmin + 2 * var(--side-pad)); /* the darts' column, beside the players */
		--card-inset: 2.4vmin;
	}

	.ctrl-top,
	.btn-section .settings-btn {
		position: relative;
		top: var(--top-drop);
	}

	/* The legs and sets fit beside the match picker at the menus' bigger size. */
	.counts {
		gap: calc(1.2 * var(--m));
		padding-left: calc(1.5 * var(--m));
	}

	main {
		--band: 50vw; /* the keypad's height */
		--u: 1.15vmin;
		--card-w: 14.5vmin;
		grid-template-columns: minmax(0, 1fr) var(--slit);
		grid-template-rows: var(--row-one) minmax(0, 1fr);
	}

	/* The board in the middle, its buttons in the corners it leaves. */
	.ctrl-section,
	.dartboard-section {
		grid-column: 1 / -1;
	}

	.dartboard-section {
		justify-content: center;
		align-items: flex-start;
		box-sizing: border-box;
		padding: var(--board-top) 0 0;
	}

	.board-frame {
		width: var(--board-d);
	}

	.ctrl-btn .icon {
		width: 6vmin;
		height: 6vmin;
	}

	.ctrl-btn .keypad-icon {
		width: 5vmin;
		height: 5vmin;
	}

	.ctrl-btn .keypad-arrow {
		width: 3.4vmin;
		height: 3.4vmin;
	}

	/* Done in the board's bottom right corner, and the darts under it, in the middle
	   of the column beside the players. The menu stays in the board's top corner. */
	.btn-section {
		--card-w: 14.5vmin;
		--done-w: var(--card-w);
		--done-h: var(--ctrl-size);
		grid-row: 1 / -1;
		grid-column: 2;
		justify-self: stretch;
		justify-content: flex-start;
		align-items: center;
		width: 100%;
		padding-top: calc(var(--row-one) - var(--side-pad) - var(--done-h));
	}

	.side-btn.done-btn {
		order: 1;
		margin-top: 0;
	}

	/* Its top level with the player cards' (Done ends a gap above them). */
	.darts {
		order: 2;
		position: relative;
		margin: var(--side-pad) 0 0;
	}

	/* Under the darts, the rest of the column, down to the players' panel's
	   bottom: two of the thrower's numbers for this leg. Its text is sized
	   by its height too (cqh), so a short screen shrinks it rather than cut it. */
	.side-info {
		container-type: size;
		order: 3;
		flex: 1 1 0;
		min-height: 0;
		margin: var(--side-pad) 0 0;
	}

	.side-title {
		font-size: min(calc(2.6 * var(--u)), 9cqh);
		color: var(--text-muted);
	}

	/* The numbers spread down whatever height there is. */
	.side-leg {
		flex: 1;
		justify-content: space-evenly;
		gap: 0;
		margin: 0;
	}

	.side-leg dt {
		font-size: min(calc(2.6 * var(--u)), 9cqh);
		color: var(--text-muted);
	}

	.side-leg dd {
		margin: 0;
		font-size: min(calc(4.6 * var(--u)), 16cqh);
		font-weight: 600;
	}

	/* Too short to read (a short screen, the darts card taking the room): an empty panel. */
	@container (max-height: 60px) {
		.side-info > * {
			display: none;
		}
	}

	.btn-section .settings-btn {
		position: fixed;
		top: calc(env(safe-area-inset-top) + var(--side-pad) + var(--top-drop));
		right: calc(env(safe-area-inset-right) + var(--side-pad));
		z-index: 2;
	}

	.btn-section .profile-btn {
		position: fixed;
		top: calc(env(safe-area-inset-top) + var(--side-pad) + var(--top-drop));
		right: calc(env(safe-area-inset-right) + 2 * var(--side-pad) + var(--ctrl-size));
		z-index: 2;
	}

	.done-btn:not(.disabled) .done-score {
		margin-right: 0.6vmin;
	}

	.done-total:not(:empty) {
		font-size: 4.4vmin;
	}

	/* No room beside the number: the word goes under it. */
	.done-unit {
		display: block;
		margin: -0.2em 0 0;
		line-height: 1;
	}

	body.visuals-open aside {
		grid-column: 1 / -1;
	}


	/* Board layout: its controls stacked, in all the room there is, Reset and Done at the bottom.
	   On a short screen the controls scroll, so the buttons never cover them. */
	.visuals-panel {
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows: auto minmax(0, 1fr) auto;
		row-gap: calc(1.2 * var(--m));
		overflow: hidden;
	}

	/* One control a row: each slider the panel's width, the colours under them. */
	.visuals-controls {
		grid-template-columns: minmax(0, 1fr);
		row-gap: calc(1.5 * var(--m));
		overflow-x: hidden;
		overflow-y: auto;
		scrollbar-width: none;
		padding-bottom: calc(0.6 * var(--m));
	}

	.visuals-panel .swatch {
		width: calc(5.5 * var(--m));
		height: calc(5.5 * var(--m));
	}

	.visuals-actions {
		grid-template-columns: 1fr 1fr;
		grid-row: 3;
		align-content: end;
	}

	/* The two panels stacked, the players over the keypad. */
	aside {
		grid-column: 1;
		flex-direction: column;
		padding: 0 0 var(--side-pad) var(--side-pad);
	}

	body.visuals-open aside {
		padding-right: var(--side-pad);
	}

	/* Never so tall that there's no room left for the thrower's card above it.
	   The keys keep their size, held to the panel's top edge: they slide down
	   out of it as it folds away, and back up. */
	.calc-section {
		--keys-h: min(var(--band), 60cqh);
		order: 0;
		width: auto;
		height: var(--keys-h);
		margin: var(--side-pad) 0 0;
		transition: height var(--medium) var(--ease-out), margin var(--medium) var(--ease-out), visibility var(--medium), filter var(--medium) var(--ease-out);
	}

	.calc-tbl {
		left: -5px;
		right: auto;
		width: calc(100cqw + 10px);
	}

	aside.keypad-hidden .calc-section {
		width: auto;
		height: 0;
		margin: 0;
	}

	/* The keypad folds away downward here, as in landscape. */
	.keypad-btn .keypad-arrow {
		transform: none;
	}

	.keypad-btn[aria-expanded="false"] .keypad-arrow {
		transform: rotate(180deg);
	}

	/* The stats as tall as the room clear of the status bar and home bar, less
	   the gap the popups have at their sides (90% wide). */
	.stats-section {
		max-height: calc(100% - 10vw);
	}
}

/* A phone held sideways (a screen no taller than a phone's width): the menus
   and popups at the size they have upright, to read and tap as easily. */
@media (orientation: landscape) and (max-height: 540px) {
	:root {
		--m: 1.3vmin;
		--ctrl-size: 10.5vmin; /* the board's buttons and the keypad's keys, about 40px: the board's corners have the room */
		--card-inset: 2.4vmin;
	}

	/* Their icons grown with them. */
	.ctrl-btn .icon {
		width: 5.8vmin;
		height: 5.8vmin;
	}

	.ctrl-btn .keypad-icon {
		width: 4.7vmin;
		height: 4.7vmin;
	}

	.ctrl-btn .keypad-arrow {
		width: 3.4vmin;
		height: 3.4vmin;
	}

	/* New game: Back and Next always in view, the step above them scrolling. */
	.new-game-section {
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}

	.new-game-section > .ng-step {
		flex: 0 1 auto;
		min-height: 0;
		overflow-y: auto;
	}

	.new-game-section > .dialog-actions {
		flex: none;
	}
}

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