/*
   The darts card beside the board (this visit's darts, the darts left, a past
   visit on show) and the side info under it (the game, what it's played to).
   Loaded in order with the others (see index.html): a later rule wins. */

/* The darts card: always as tall as Clear and three slots, whatever's down, so
   nothing moves. The player's three darts until the first one lands; then Clear
   across the top, a slot for each dart thrown, and small darts for those left. */
/* Under the darts card, in every layout: two of the thrower's numbers for this
   leg (legLine in the mode). The two together in the middle of the room
   between the menu and Done (the margins that are auto); on a phone the
   numbers fill the column under the card instead (phone.css). */
.side-info {
	display: flex;
	flex-direction: column;
	align-items: center;
	width: var(--card-w);
	margin: var(--side-pad) 0 auto;
	padding: calc(1.2 * var(--u)) 0;
	box-sizing: border-box;
	overflow: hidden;
	line-height: 1.1;
	text-align: center;
	color: var(--text);
	background: var(--panel-soft);
	border: var(--border-muted);
	border-radius: var(--radius);
}

.side-info p {
	max-width: 100%;
	margin: 0;
	padding: 0 calc(0.6 * var(--u));
	box-sizing: border-box;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

/* Sized by the card's width too: it's narrower on a 4:3 screen. */
.side-title {
	font-size: min(calc(2.6 * var(--u)), calc(var(--card-w) * 0.2));
	color: var(--text-muted);
}

/* A match: the game's name over what it's played to, in white. */
.side-info.side-match .side-title {
	color: white;
}

.side-leg {
	display: flex;
	flex-direction: column;
	gap: calc(0.8 * var(--u));
	width: 100%;
	margin: calc(0.8 * var(--u)) 0 0;
}

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

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

.darts {
	--clear-h: calc(7.6 * var(--u)); /* Clear, and Tap again to remove in its place (here, where --u is the layout's) */
	display: grid;
	grid-template-columns: 100%;
	justify-items: center;
	width: var(--card-w);
	padding: calc(0.6 * var(--u)) 0 calc(0.8 * var(--u));
	box-sizing: border-box;
	font-size: calc(3 * var(--u));
	text-align: center;
	line-height: 1.05;
	color: white;
	background: var(--panel-soft);
	border: var(--border-muted);
	border-radius: var(--radius);
	margin-top: auto; /* with the numbers under it, in the middle of the room (see .side-info) */
}

/* The two faces share one place, and the slots' room gives the card its height. */
.darts-reveal {
	grid-area: 1 / 1;
	align-self: center;
	width: 100%;
	opacity: 0;
	transition: opacity var(--medium) var(--ease-out);
}

.darts-reveal > div {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.darts:not(.has-darts) .darts-idle,
.darts.has-darts .darts-turn {
	opacity: 1;
}

/* While the darts left move, the picture is on top: its front dart stays in front of them. */
.darts:is(.dealing, .undealing) .darts-idle {
	z-index: 1;
}

/* The first dart (dealDarts): the darts left are there at once, in the picture's
   place, so only its front dart fades. */
.darts.dealing .darts-turn {
	transition: none;
}

.darts.dealing .darts-clear {
	animation: fade-in var(--medium) var(--ease-out);
}

/* And back (undealDarts): the turn's side stays until its darts have gone home. */
.darts.undealing .darts-turn {
	opacity: 1;
	transition: none;
}

.darts.undealing :is(.darts-left, .left-dart) {
	transition: none;
}

.darts.undealing .darts-clear {
	animation: fade-out var(--medium) var(--ease-out) forwards;
}

/* A copy of a slot as the turn's darts go, in the place it had. */
.darts span.slot-leaving {
	position: absolute;
	margin: 0;
	box-sizing: content-box;
	pointer-events: none;
}

/* With a dart picked up, Tap again to remove in Clear's place (nothing else
   moves, so the slots stay under the finger for the second tap), at once. */
.darts-hint {
	position: absolute;
	top: calc(-0.6 * var(--u)); /* where Clear is, its text centred as Clear's */
	left: 0;
	right: 0;
	display: grid;
	place-items: center;
	height: var(--clear-h);
	padding-top: calc(0.6 * var(--u));
	box-sizing: border-box;
	opacity: 0;
	font-family: var(--font-condensed);
	font-size: min(calc(2.3 * var(--u)), calc(var(--card-w) * 0.21)); /* two lines, even on the narrower 4:3 card */
	line-height: 1.1;
	color: color-mix(in srgb, var(--bust) 40%, white);
	pointer-events: none;
}

.darts.moving .darts-hint {
	opacity: 1;
}

/* A past visit on show: its darts in the slots, and which leg and visit it was
   in Clear's place (there's nothing to clear or move). */
.darts-visit {
	position: absolute;
	top: calc(-0.6 * var(--u));
	left: 0;
	right: 0;
	display: grid;
	place-items: center;
	height: var(--clear-h);
	padding-top: calc(0.6 * var(--u));
	box-sizing: border-box;
	opacity: 0;
	font-family: var(--font-condensed);
	font-size: min(calc(2.3 * var(--u)), calc(var(--card-w) * 0.21));
	line-height: 1.1;
	text-align: center;
	color: var(--text-soft);
	pointer-events: none;
}

.darts.reviewing .darts-visit {
	opacity: 1;
}

.darts.reviewing .darts-clear {
	opacity: 0;
	pointer-events: none;
}

.darts.moving .darts-clear {
	opacity: 0;
	pointer-events: none;
}

.dart-behind {
	filter: brightness(0.6);
	opacity: 0.5;
}

/* The darts left: side by side, one fewer with each dart thrown, over the slots
   still empty. */
.darts-left {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	justify-content: center;
	align-items: center;
	height: calc(12.4 * var(--u));
	pointer-events: none;
	transition: height var(--medium) var(--ease-out), opacity var(--medium) var(--ease-out);
}

.darts[data-left="2"] .darts-left,
.darts[data-left="3"] .darts-left {
	height: calc(24.8 * var(--u));
}

.darts[data-left="0"] .darts-left {
	opacity: 0;
}

.left-dart {
	flex: none;
	width: calc(3.2 * var(--u));
	height: calc(12 * var(--u));
	margin: 0 calc(0.4 * var(--u));
	filter: drop-shadow(0 0 calc(0.3 * var(--u)) black);
	transition: width var(--medium) var(--ease-out), margin var(--medium) var(--ease-out), opacity var(--medium) var(--ease-out);
}

.darts[data-left="1"] .left-dart:nth-child(2),
.darts[data-left="0"] .left-dart:nth-child(2) {
	width: 0;
	margin: 0;
	opacity: 0;
}

.idle-dart {
	display: block;
	flex: none;
	height: min(calc(30 * var(--u)), calc(var(--card-w) * 2.6)); /* the fan fits the narrower 4:3 card */
	margin: calc(1.2 * var(--u)) 0 calc(0.8 * var(--u));
	filter: drop-shadow(0 0 calc(0.5 * var(--u)) black);
}

.darts-clear {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: calc(0.4 * var(--u));
	width: 100%;
	height: var(--clear-h);
	margin-top: calc(-0.6 * var(--u)); /* up to the card's edge: all of it is there to tap */
	padding: calc(0.6 * var(--u)) 0 0;
	box-sizing: border-box;
	font-family: var(--font-condensed);
	font-size: calc(2.8 * var(--u));
	line-height: 1;
	color: var(--text);
	background: none;
	border: none;
	border-radius: calc(var(--radius) * 0.7);
	cursor: pointer;
	pointer-events: auto;
	transition: background var(--hover-speed), color var(--medium), transform var(--fast) var(--ease-out); /* opacity at once, Tap again to remove in its place */
}

.darts-clear:disabled {
	color: var(--text-muted);
	cursor: default;
}

.darts-clear:not(:disabled):active {
	transform: scale(0.9);
}

.darts-clear .icon {
	flex: none;
	width: calc(2.4 * var(--u));
	height: calc(2.4 * var(--u));
}

/* Each dart's value centred in its slot, with room round it. */
.darts span {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 86%;
	height: calc(10.4 * var(--u));
	margin: calc(1 * var(--u)) 0;
	border: var(--line) solid transparent;
	border-radius: var(--radius);
	text-shadow: 0 0 calc(0.5 * var(--u)) black;
	pointer-events: auto;
}

/* A double, treble or bull: the letter over its value, evenly spaced (the
   column stacks them; a <br> would add an empty line). */
.darts span br {
	display: none;
}

.darts span:has(br),
.darts span:has(br) u {
	line-height: 1;
}

.darts span:has(br) {
	gap: calc(0.8 * var(--u));
}

.darts u {
	font-size: calc(5 * var(--u));
	text-decoration-thickness: calc(0.25 * var(--u));
	text-underline-offset: calc(0.5 * var(--u));
}

.darts :is(.black, .white, .red, .green, .zero) {
	border-color: white;
	cursor: pointer;
}

.darts :is(.black, .white, .zero) {
	line-height: calc(8 * var(--u));
}

.darts .black {
	background: var(--slot-black);
}

.darts .white {
	color: var(--slot-white-text);
	background: var(--slot-white);
}

.darts .red {
	background: var(--slot-red);
}

.darts .green {
	background: var(--slot-green);
}

.darts .zero {
	background: black;
}

/* A dart still to throw: its slot keeps its room, unseen until it lands. */
.darts span.empty {
	opacity: 0;
	pointer-events: none;
}
