/*
   The keypad.
   Loaded in order with the others (see index.html): a later rule wins. */

/* CALCULATOR */

/* --keys-h: the panel's full height, the keys' too (they keep it as it folds away). */
.calc-section {
	--keys-h: calc(4 * var(--ctrl-size) + 15px); /* four rows each a board button tall (and the 5px gaps between), so the bottom row lines up with the buttons beside it */
	position: relative;
	height: var(--keys-h);
	margin-top: var(--side-pad);
	box-sizing: border-box;
	flex: none;
	overflow: hidden;
	transition: height var(--medium) var(--ease-out), margin var(--medium) var(--ease-out), visibility var(--medium), filter var(--medium) var(--ease-out), background var(--medium) var(--ease-out);
	font-family: var(--font);
	font-weight: 500;
}

/* Its full size whatever the panel's doing, held to the panel's moving edge, so
   the keypad slides out of sight as a whole (the keys don't change size). */
.calc-tbl {
	position: absolute;
	/* The table's outer 5px gaps hang outside, so the keys' edges line up with the players' panel. */
	top: -5px;
	left: -5px;
	table-layout: fixed;
	border-spacing: 5px;
	width: calc(100cqw + 10px);
	height: calc(var(--keys-h) + 10px);
	text-align: center;
	font-size: calc(6 * var(--u));
	text-shadow: 0 0 calc(0.5 * var(--u)) black;
	line-height: calc(1 * var(--u));
	color: white;
}

.calc-tbl td {
	border: var(--border);
	border-radius: var(--radius);
	/* Four rows, their gaps, borders and padding fit a short screen's keypad too. */
	height: min(calc(7.5 * var(--u)), calc((var(--keys-h) - 15px) / 4 - 2 * var(--line) - 2px));
	background: var(--button);
	cursor: pointer;
}

.calc-tbl td:not(.calc-score):active {
	background: var(--button-pressed);
	font-size: calc(5.5 * var(--u));
}

.calc-tbl td.back-score:active {
	font-size: calc(4.2 * var(--u));
}

.calc-tbl td.disabled {
	color: var(--text-muted);
	background: var(--panel);
	border: var(--border-muted);
	pointer-events: none;
}

/* The box itself is a "plate" behind the text (::before), so it can tip
   like a rocker switch while the number stays put. */
td.calc-score {
	position: relative;
	isolation: isolate;
	font-family: var(--font-condensed);
	font-weight: 500;
	line-height: calc(5.25 * var(--u));
	background: none;
	text-shadow: 0 0 calc(1 * var(--u)) black;
}

/* The cell draws no border of its own, so the plate (inset 0) is exactly the
   cell, edge for edge with the buttons around it. Reaching out by --line over
   a border instead left its edges between screen pixels (borders snap to whole
   pixels, --line doesn't), and Chrome drew them a pixel wider while tipping. */
.calc-tbl td.calc-score,
.calc-tbl td.calc-score.disabled {
	border: none;
}

td.calc-score::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	border: var(--border);
	border-radius: var(--radius);
	background: var(--key-display);
}

td.calc-score.disabled {
	background: none;
}

td.calc-score.disabled::before {
	border: var(--border-muted);
	background: var(--field);
}

td.calc-score.tip-up:not(.disabled)::before,
td.calc-score.tip-up:not(.disabled) .score-face {
	animation: tip-up 260ms var(--ease-out);
}

td.calc-score.tip-down:not(.disabled)::before,
td.calc-score.tip-down:not(.disabled) .score-face {
	animation: tip-down 260ms var(--ease-out);
}

/* Seen in perspective, a tipping box looks like it slides (both edges drift the
   same way). The 1.9% shift cancels that, so it rocks in place. It holds while the
   perspective depth is about 1.5x the box height (--tip-depth, set for portrait). */
@keyframes tip-up {
	30% { transform: perspective(var(--tip-depth, calc(30 * var(--u)))) translateY(-1.9%) rotateX(7deg); }
}

@keyframes tip-down {
	30% { transform: perspective(var(--tip-depth, calc(30 * var(--u)))) translateY(1.9%) rotateX(-7deg); }
}

/* Same box as the plate, so it tips exactly with it. The arrows sit one line
   above and below the middle, where the number is. */
/* Always on its own layer, as it is while tipping: text on a layer sits a
   fraction of a pixel differently, so the arrows would flinch as it ended. */
.score-face {
	position: absolute;
	inset: 0;
	will-change: transform;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: calc(5.25 * var(--u));
	pointer-events: none;
}

.score-face > * {
	display: block;
	height: calc(5.25 * var(--u));
}

/* Drawn, not characters: iOS gives the two arrow characters different sizes. */
.arrow-up,
.arrow-down {
	width: calc(2.8 * var(--u));
	background: currentColor;
}

.arrow-up {
	clip-path: polygon(50% 30%, 100% 70%, 0 70%);
}

.arrow-down {
	clip-path: polygon(0 30%, 100% 30%, 50% 70%);
}

td.calc-score b {
	font-weight: normal;
	color: var(--text-muted);
}

td.calc-score i {
	font-style: normal;
	font-weight: normal;
	text-shadow: none;
}

td.back-score {
	font-size: calc(4.6 * var(--u));
	line-height: 1;
}

/* Drawn, not characters, so they're the same on every device. Sized by the key's
   text, so they shrink with it when pressed. */
.key-icon {
	width: 1em;
	height: 1em;
	margin: -0.5em auto; /* no height of its own, so the rows stay even on the smallest screens */
	stroke-width: 2.6;
}

td.back-score .key-icon {
	width: 1.25em;
	height: 1.25em;
	margin: -0.625em auto;
	stroke-width: 2.2;
}
