/*
   The players' panel: each player's card (a grid: the name and score, the
   stats, the history line), and the focus the rest of the screen steps back for.
   The history line itself is history-line.css; the checkout, checkout.css.
   Loaded in order with the others (see index.html): a later rule wins. */

/* SCORES */

/* Sizes below are for four players; JS sets --s to grow or shrink them
   to the number of players (see layoutScores and SCORES_LAYOUT). */

.scores-section {
	flex: 1 1 0;
	min-height: 0;
	box-sizing: border-box;
	font-weight: 500;
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: none;
}

.scores-section::-webkit-scrollbar {
	display: none;
}

/* Cards scrolled out of view fade out at that edge; the bottom one is taller
   and fades harder, so more players below are plain to see. (The panel's
   border is its wrapper's, so it never fades.) */
.scores-section {
	mask-image: linear-gradient(transparent, black var(--fade-top), black calc(100% - var(--fade-bottom)), rgba(0, 0, 0, 0.3) calc(100% - var(--fade-bottom) * 0.4), transparent);
	mask-repeat: no-repeat;
	transition: --fade-top var(--medium), --fade-bottom var(--medium);
}

.scores-section.fade-top {
	--fade-top: 4vmin;
}

.scores-section.fade-bottom {
	--fade-bottom: 8vmin;
}

/* Above a phone's keypad: one card, framed exactly, with no faded edges. The
   list's line over the keypad is the card's bottom line: it doesn't draw its own. */
.scores-section.framed {
	--fade-top: 0px;
	--fade-bottom: 0px;
	mask-image: none;
}

/* The cards' scale (layoutScores), as a number so it can ease: the cards grow
   with the room as the keypad folds away. */
@property --s {
	syntax: "<number>";
	inherits: true;
	initial-value: 1;
}

.score-cards.growing {
	transition: --s var(--medium) var(--ease-out);
}

/* The cards, one under another, sharing out the list's height (a card's rows
   keep their shares of it: 10 to 5, see .card). Their backgrounds (z-index -1)
   sit in here, under every card's text, so no text shadow is cut off at a card's edge. */
.score-cards {
	--s: 1;
	--name-gap: calc(0.4vmin * var(--s)); /* a little room before a name (and the lines under it), past the starter's spike */
	--card-end: calc(1.4vmin * var(--s)); /* the room after the score, the stats and the leg dots */
	display: flex;
	flex-direction: column;
	height: 100%;
	isolation: isolate;
	color: #fafafa;
	line-height: 1;
}

/* A card's background is one layer behind its name (and stats), its two
   colours (three in the big layout) registered so the turn passing fades them
   (a gradient itself can't). */
@property --row-top {
	syntax: "<color>";
	inherits: true;
	initial-value: transparent;
}

@property --row-mid {
	syntax: "<color>";
	inherits: true;
	initial-value: transparent;
}

@property --row-bottom {
	syntax: "<color>";
	inherits: true;
	initial-value: transparent;
}

/* A player: the name and score over the history line (10 to 5); with room, the
   stats between them ("roomy"); with more, the score down beside the stats,
   big, and the name across the top ("big"). --top is how far down the
   background reaches (all but the history line), --name-mid the name's middle. */
.card {
	--row-top: var(--card-top);
	--row-mid: var(--card-middle);
	--row-bottom: var(--card-bottom);
	--top: calc(100% * 10 / 15);
	--name-mid: calc(100% * 5 / 15);
	position: relative;
	flex: 1 0 calc(15vmin * var(--s));
	display: grid;
	grid-template:
		"name score" minmax(0, 10fr)
		"history history" minmax(0, 5fr)
		/ minmax(0, 1fr) auto;
	cursor: pointer;
	transition: filter var(--medium) var(--ease-out), --row-top var(--slow) var(--ease-out), --row-mid var(--slow) var(--ease-out), --row-bottom var(--slow) var(--ease-out);
}

.score-cards.roomy .card {
	--top: 75%;
	--name-mid: 25%;
	flex-basis: calc(20vmin * var(--s));
	grid-template:
		"name score" minmax(0, 10fr)
		"stats stats" minmax(0, 5fr)
		"history history" minmax(0, 5fr)
		/ minmax(0, 1fr) auto;
}

.score-cards.big .card {
	--top: calc(100% * 25 / 30);
	--name-mid: calc(100% * 5 / 30);
	flex-basis: calc(30vmin * var(--s));
	grid-template:
		"name name" minmax(0, 10fr)
		"stats score" minmax(0, 15fr)
		"history history" minmax(0, 5fr)
		/ minmax(0, 1fr) auto;
}

.card.active {
	--row-top: var(--active-top);
	--row-mid: var(--active-big-middle);
	--row-bottom: var(--active-bottom);
	color: white;
}

/* The background, a pixel into the history line, so no hairline of the dark
   page shows between the two where the edge falls between screen pixels; and
   over it the menu tint, which fades in and out. */
.card::before,
.card::after {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: calc(var(--top) + 1px);
	z-index: -1;
	background: linear-gradient(var(--row-top), var(--row-bottom));
}

.score-cards.big .card::before {
	background: linear-gradient(var(--row-top), var(--row-mid) 40%, var(--row-bottom));
}

.card::after {
	background: var(--menu-row);
	opacity: 0;
	transition: opacity var(--medium) var(--ease-out);
}

/* The player whose menu is open is tinted amber, like the menu. */
.card.menu-open::after {
	opacity: 1;
}

/* The big layout: a thin line between the name and the big score, short of
   the sides so it separates the two without splitting the player's field. */
.card-rule {
	display: none;
}

.score-cards.big .card-rule {
	display: block;
	position: absolute;
	top: calc(100% * 10 / 30);
	left: calc(1.5vmin * var(--s));
	right: calc(1.5vmin * var(--s));
	height: 2px;
	background: rgba(255, 255, 255, 0.28);
}

/* Who threw first this leg: a little spike in from the card's left edge, by
   the name, taking no room from it. */
.throw-first {
	position: absolute;
	top: calc(var(--name-mid) - 1vmin * var(--s));
	left: 0;
	width: calc(0.9vmin * var(--s));
	height: calc(2vmin * var(--s));
	clip-path: polygon(0 0, 100% 50%, 0 100%);
	background: var(--text-soft);
	opacity: 0;
	transform: scaleX(0);
	transform-origin: left;
	transition: opacity var(--medium) var(--ease-out), transform var(--medium) var(--ease-out);
}

.starts .throw-first {
	opacity: 1;
	transform: none;
}

.active .throw-first {
	background: white;
}

/* A linked player's banner (banners.js): their picture or their country's flag
   over the card's own background, at its left, fading into it: a background,
   with no room of its own. What's over it is shaded to stay readable: the
   name and the stats a heavier glow round the letters (.has-banner below). It
   reaches as far down as the card's background does, never into the history
   line. Its width follows its height, so it keeps its shape on any card,
   within a quarter and a half of the card (a flag, wider: a half to two
   thirds); the image is zoomed to fill it, never stretched. */
.banner {
	position: absolute;
	top: 0;
	left: 0;
	z-index: -1; /* over the background (.card::before), under the menu tint (::after) */
	height: var(--top);
	aspect-ratio: 4 / 3;
	min-width: 25%;
	max-width: 50%;
	background: center / cover no-repeat;
	mask-image: linear-gradient(to right, black 35%, transparent);
	filter: brightness(0.7);
	pointer-events: none;
}

.banner.flag {
	aspect-ratio: 2;
	min-width: 50%;
	max-width: 67%;
	filter: brightness(0.5); /* many are mostly white (England, Japan): what's over them stays white on dark */
}

.banner[hidden] {
	display: none;
}

/* The name as shown; fitName in scoreboard.js narrows, wraps or shrinks it to
   fit. It starts where the stats and the history do. */
.name-text {
	grid-area: name;
	align-self: center;
	display: flex;
	align-items: center;
	height: calc(9vmin * var(--s));
	margin-right: 1px;
	padding: 0 calc(1vmin * var(--s)) 0 calc(var(--card-inset) + var(--name-gap));
	/* Cut off what doesn't fit, but leave room for the text shadow. */
	overflow: clip;
	overflow-clip-margin: calc(1vmin * var(--s));
	font-family: var(--font-condensed);
	font-weight: normal;
	font-size: calc(6.5vmin * var(--s) * var(--name-size, 1));
	line-height: 1;
	text-shadow: 0 0 calc(1vmin * var(--s)) black;
	white-space: nowrap;
}

.name-text span {
	flex: none;
}

.name-text.narrow {
	font-family: var(--font);
}

.name-text.two-lines {
	font-size: calc(4.2vmin * var(--s) * var(--name-size, 1));
	line-height: 0.95;
	white-space: normal;
}

.name-text.two-lines span {
	flex: 1;
	min-width: 0;
}

.name-text.clipped span {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
}

.has-banner .name-text {
	text-shadow: 0 0 calc(0.4vmin * var(--s)) black, 0 0 calc(1vmin * var(--s)) black, 0 0 calc(2vmin * var(--s)) black;
}

/* Everyone else steps back while a score is being entered (the thrower stays
   lit) or a player's menu is open (that player stays lit). JS sets .inputting. */
.score-cards.inputting:not(:has(.menu-open)) .card:not(.active),
.score-cards:has(.menu-open) .card:not(.menu-open),
.score-cards:has(.review-focus) .card:not(.review-focus) {
	filter: var(--dim);
}

/* While a player's menu is open, or a past turn is on show, the rest of the
   screen steps back and stops reacting to the pointer (no hover lights or
   key presses); a tap anywhere just closes it. A past turn keeps the board
   and the darts card, which show its darts (each of the card's neighbours fades on its own). JS sets the body classes; the reviewed player's
   rows get .review-focus. */
.ctrl-section,
.dartboard-section,
.btn-section {
	transition: opacity var(--medium) var(--ease-out);
}

body.menu-focus :is(.ctrl-section, .dartboard-section, .btn-section),
body.review-focus .ctrl-section,
body.review-focus .btn-section > :not(.darts) {
	opacity: 0.4;
}

/* The keypad sits on the lighter side panel, where fading would wash it out:
   it darkens like the player rows above it instead (its transition is set
   with its fold-away one, under CALCULATOR). */
body:is(.menu-focus, .review-focus) .calc-section {
	filter: var(--dim);
}

/* Which way the score is going in, and the button that sends it, in the
   green of the New game screen's main button (Start). Typing: ✓ turns green,
   and the board's darts (still shown) turn grey with the darts column
   stepping back. Darts on the board: Done turns green. Nothing is cleared:
   using the other one switches. JS sets the body classes (renderInputting).
   The green is a gradient over each button's own fill, its two colours
   see-through until in use, so it fades in and out. */
@property --send-top {
	syntax: "<color>";
	inherits: false;
	initial-value: transparent;
}

@property --send-bottom {
	syntax: "<color>";
	inherits: false;
	initial-value: transparent;
}

.darts {
	transition: opacity var(--medium) var(--ease-out);
}

body.keypad-input:not(.visuals-open) .darts {
	opacity: 0.45;
}

/* Likewise the keypad's score rocker while the board is in use. (On its plate
   and what's on it: a table cell's own opacity didn't reach them.) */
td.calc-score::before,
td.calc-score > * {
	transition: opacity var(--medium) var(--ease-out);
}

body.board-input td.calc-score::before,
body.board-input td.calc-score > * {
	opacity: 0.45;
}

/* (Pressed, ✓ shows the keypad's pressed fill.) */
.calc-tbl td.check-score:not(.disabled, :active) {
	background: linear-gradient(var(--send-top), var(--send-bottom)), var(--button);
}

.done-btn:not(.disabled) {
	background: linear-gradient(var(--send-top), var(--send-bottom)), var(--button);
}

.calc-tbl td.check-score,
.side-btn.done-btn {
	transition: transform var(--fast) var(--ease-out), color var(--medium), border-color var(--medium), opacity var(--medium), box-shadow var(--hover-speed), --send-top var(--medium) var(--ease-out), --send-bottom var(--medium) var(--ease-out);
}

body.keypad-input .calc-tbl td.check-score:not(.disabled),
body.board-input .done-btn:not(.disabled) {
	--send-top: var(--go-top);
	--send-bottom: var(--go-bottom);
	border-color: var(--checkout);
}

/* The turn's darts, still on the board but not what is being entered. */
.light.hit {
	transition: fill var(--medium), stroke var(--medium), filter var(--medium);
}

body.keypad-input:not(.visuals-open) .light.hit {
	fill: color-mix(in srgb, white 12%, transparent); /* a mix, as the lit colours are: see light-from-hover */
	stroke: #969696;
	filter: none;
}

/* The sections themselves let taps through; their buttons and the board opt back in. */
body:is(.menu-focus, .review-focus) :is(.ctrl-section, .dartboard-section, .btn-section, .calc-section) *,
body:is(.menu-focus, .review-focus) #dartboard {
	pointer-events: none;
}

/* The tap that closed it stays asleep until it lifts (see 'dismissing' in app.js). */
body.dismissing * {
	pointer-events: none !important;
}


/* The score: beside the name, or in the big layout beside the stats, big. */
.player-score {
	grid-area: score;
	position: relative;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	width: calc(12vmin * var(--s));
	padding: 0 var(--card-end) 0 1px;
	font-size: calc(7.5vmin * var(--s));
	text-shadow: 0 0 calc(1vmin * var(--s)) black;
	white-space: nowrap;
}

.score-cards.big .player-score {
	display: block;
	align-self: center;
	width: auto;
	padding: 0 var(--card-end) 0 0;
	font-size: calc(11vmin * var(--s));
	line-height: 0.95;
	text-align: right;
}

/* A note small and grey under the score (scoreNote in the mode: X01's darts
   this leg, 121's target): without the stats line, in the score's room, the
   score lifted over it; with the stats line, at its end; in the big layout,
   under the big score. A note the stats line shows too (NOTE_IN_STATS) is
   only there without it. */
.player-score[data-note]::after {
	content: attr(data-note);
	position: absolute;
	right: var(--card-end);
	font-size: calc(1.9vmin * var(--s));
	font-weight: normal;
	line-height: 1;
	color: var(--text-soft);
	text-shadow: 0 0 calc(0.5vmin * var(--s)) black;
}

.score-cards:not(.roomy) .player-score[data-note] {
	padding-bottom: calc(1.6vmin * var(--s));
	font-size: calc(6.8vmin * var(--s));
}

.score-cards:not(.roomy) .player-score[data-note]::after {
	bottom: calc(0.9vmin * var(--s));
}

.score-cards.roomy .player-score[data-note]::after {
	top: 100%;
}

.score-cards.big .player-score[data-note]::after {
	display: block;
	position: static;
	margin-top: calc(0.4vmin * var(--s));
	font-size: calc(2.4vmin * var(--s));
}

.score-cards.roomy .player-score.note-in-stats::after {
	content: none;
}

/* Only when there is room: a line of match stats between the name and the
   history; in the big layout, stacked beside the big score. */
.stats {
	grid-area: stats;
	justify-self: start;
	align-self: center;
	display: flex;
	gap: calc(2.5vmin * var(--s));
	margin: -0.25em var(--card-end) -0.25em calc(var(--card-inset) + var(--name-gap));
	/* Room for the g of Avg and the text shadow inside what's cut, not moving the line (Safari has no overflow-clip-margin). */
	padding-block: 0.25em;
	font-family: var(--font-condensed);
	font-size: calc(2.5vmin * var(--s));
	font-weight: normal;
	color: var(--text-muted);
	white-space: nowrap;
	overflow: clip;
	overflow-clip-margin: calc(1vmin * var(--s)); /* room for the text shadow */
}

.score-cards:not(.roomy) .stats {
	display: none;
}

.score-cards.big .stats {
	flex-direction: column;
	gap: calc(0.6vmin * var(--s));
	margin-right: 0;
	font-size: calc(2.8vmin * var(--s));
	color: var(--text-soft);
	text-shadow: 0 0 calc(0.5vmin * var(--s)) black;
}

/* On the thrower's bright field the labels need the lighter grey, as in .big. */
.score-cards.roomy .card.active .stats {
	color: var(--text-soft);
	text-shadow: 0 0 calc(0.5vmin * var(--s)) black;
}

/* Over a banner, the stats a heavier glow round the letters, like the name. */
.score-cards .card.has-banner .stats {
	text-shadow: 0 0 calc(0.4vmin * var(--s)) black, 0 0 calc(1vmin * var(--s)) black, 0 0 calc(2vmin * var(--s)) black;
}

.stats b {
	color: var(--value);
	font-weight: 500;
	transition: color var(--slow) var(--ease-out);
}

.card:not(.active) {
	--value: var(--value-idle);
}

/* The labels' short forms, unless stacked on a card wide enough for them in full. */
.stat-full,
.full-labels .stat-short {
	display: none;
}

.full-labels .stat-full {
	display: inline;
}
