/* Games area bundle (FRAMEWORK.md 9): what the games pages outside the
   Forgetful Fish table need beyond the vocabulary, loaded as their area
   bundle (ui/areas.py AREA_CSS). One section per round 7 lane; a lane edits
   only inside its own. The lobbies have their own lobby.css. */

/* -- PopuGame (pages/games_popugame.py, games_popugame_load.py; popugame.js, popugame_replay.js; lane G) -- */
/* The play page is one Panel ([data-popugame], popugame.js's root): the score
   header (the game link and code in the score line's place while waiting),
   the board, the controls, and the rules and end-of-game modals. The replay
   page is one Panel ([data-pg-replay]) with the scorebox, the same board and
   the step toolbar. The area leaves render spans (inline roots); these
   rules give them their boxes. The scripts build the cells and the
   end-of-game lines. */

/* The side to move tints the frame and the status line. */
[data-popugame][data-active-player="0"] { border-color: color-mix(in srgb, var(--player-0-color) 55%, transparent); }
[data-popugame][data-active-player="1"] { border-color: color-mix(in srgb, var(--player-1-color) 55%, transparent); }

/* Score header: whose move and turns left, then names and score (or, while
   the host waits, the game link and code in the same cell). */
.popugame__header {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: center;
	gap: var(--sp-2) var(--sp-4);
	font-weight: 600;
	min-inline-size: 0;
}

/* One line whatever it says (long names, a failed join): the board below
   never moves. */
.popugame__status {
	font-size: var(--fs-base);
	min-inline-size: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

[data-popugame][data-active-player="0"] .popugame__status { color: var(--player-0-color); }
[data-popugame][data-active-player="1"] .popugame__status { color: var(--player-1-color); }
/* The wait and the result are nobody's turn. */
[data-popugame][data-waiting] .popugame__status { color: var(--text); }
/* A refused join's line: error text is the bad tone, never a seat colour. */
[data-popugame] .popugame__status[data-tone="bad"] { color: var(--danger); }

.popugame__turnlabel {
	font-size: var(--fs-sm);
	color: var(--text-muted);
	white-space: nowrap;
}

/* The score line and the share chips share the header's second row; the
   root's data-waiting picks the one that shows, and the row keeps the
   taller one's height, so the swap moves nothing. */
.popugame__seats,
.popugame__share {
	grid-column: 1 / -1;
	grid-row: 2;
	display: grid;
	gap: var(--sp-1);
	min-inline-size: 0;
}
[data-popugame]:not([data-waiting]) .popugame__share,
[data-popugame][data-waiting] .popugame__seats { visibility: hidden; }

.popugame__share {
	grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
	align-items: center;
	font-weight: 400;
}
.popugame__share-item {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	min-inline-size: 0;
}
.popugame__share-label {
	flex: none;
	color: var(--text-muted);
}
.popugame__share-item .minecraft-host-chip { flex: 1 1 auto; min-inline-size: 0; }

/* One line too: a long name clips. */
.popugame__scoreline {
	display: flex;
	flex-wrap: nowrap;
	min-inline-size: 0;
	justify-content: center;
	align-items: baseline;
	gap: var(--sp-1) var(--sp-2);
	font-size: var(--fs-base);
}

.popugame__name {
	font-weight: 600;
	min-inline-size: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.popugame__name--p0,
.popugame__score--p0 { color: var(--player-0-color); }
.popugame__name--p1,
.popugame__score--p1 { color: var(--player-1-color); }

/* A seat's name leads with its token's shape, as the board draws it: the
   status shapes' box (.st), 8 px of shape and 4 px before the name. */
.popugame__name--p0::before,
.popugame__name--p1::before {
	content: "";
	display: inline-block;
	inline-size: 0.75rem;
	block-size: 0.5rem;
	background: currentColor;
}
.popugame__name--p0::before { clip-path: circle(0.25rem at 0.25rem 50%); }
.popugame__name--p1::before { clip-path: inset(0 0.25rem 0 0 round 1px); }

.popugame__score-sep {
	color: var(--text-muted);
	font-weight: 600;
}

.popugame__score-label {
	display: block;
	text-align: center;
	font-size: var(--fs-xs);
	font-weight: 400;
	color: var(--text-muted);
}

/* The replay's scorebox: names, then the score. */
.popugame__scorebox {
	display: grid;
	justify-items: center;
	gap: var(--sp-1);
	font-weight: 600;
}

.popugame__nameline {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: baseline;
	gap: var(--sp-2);
}

.popugame__name-sep {
	color: var(--text-muted);
	font-size: var(--fs-xs);
	font-weight: 400;
}

/* The board is square from the first paint: its grid comes from data-size
   (the engine serves 9), so the cells the script adds fill a box that is
   already there. */
.popugame__board {
	display: grid;
	gap: var(--sp-1);
	aspect-ratio: 1;
	inline-size: 100%;
	box-sizing: border-box;
	padding: var(--sp-1);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	background: var(--bg);
}

.popugame__board[data-size="9"] {
	grid-template-columns: repeat(9, minmax(0, 1fr));
	grid-template-rows: repeat(9, minmax(0, 1fr));
}

.popugame__cell {
	display: grid;
	place-items: center;
	inline-size: 100%;
	block-size: 100%;
	min-inline-size: 0;
	padding: 0;
	box-sizing: border-box;
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	background: var(--surface-2);
	cursor: pointer;
}

/* A cell that cannot be played: only an empty one dims; tokens and claims
   keep full strength on the opponent's turn and on the final board. */
.popugame__cell[aria-disabled="true"],
.popugame__cell:disabled { cursor: default; }
.popugame__cell[aria-disabled="true"]:not(.is-token-p0, .is-token-p1, .is-claim-p0, .is-claim-p1) { opacity: 0.45; }

.popugame__cell:not(:disabled, [aria-disabled="true"]):hover {
	border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
	background: color-mix(in srgb, var(--accent) 6%, var(--surface-2));
}

/* A seat reads without its hue: seat 0 is a disc on filled claims, seat 1 a
   square on hatched ones. --pg-tint is a claim's strength: 28% at rest, the
   mover's own 30%, the other seat's and a hovered one 34%. */
.popugame__cell.is-claim-p0 {
	--pg-tint: 28%;
	--pg-claim: color-mix(in srgb, var(--player-0-color) var(--pg-tint), transparent);
	background: var(--pg-claim);
}
.popugame__cell.is-claim-p1 {
	--pg-tint: 28%;
	--pg-claim: repeating-linear-gradient(
		45deg,
		color-mix(in srgb, var(--player-1-color) 70%, transparent) 0 1.5px,
		color-mix(in srgb, var(--player-1-color) var(--pg-tint), transparent) 1.5px 6px
	);
	background: var(--pg-claim);
}
[data-popugame][data-active-player="0"] .popugame__cell.is-claim-p0,
[data-popugame][data-active-player="1"] .popugame__cell.is-claim-p1 { --pg-tint: 30%; }
[data-popugame][data-active-player="0"] .popugame__cell.is-claim-p1,
[data-popugame][data-active-player="1"] .popugame__cell.is-claim-p0 { --pg-tint: 34%; }
.popugame__cell.is-claim-p0:not(:disabled, [aria-disabled="true"]):hover,
.popugame__cell.is-claim-p1:not(:disabled, [aria-disabled="true"]):hover {
	--pg-tint: 34%;
	background: var(--pg-claim);
}

/* Legal moves for the side to move. */
[data-popugame][data-active-player] .popugame__cell.is-legal { border-color: color-mix(in srgb, var(--accent) 20%, var(--border)); }

.popugame__cell.is-legal:not(:disabled, [aria-disabled="true"]):hover {
	background: color-mix(in srgb, var(--accent) 10%, var(--surface-2));
	border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.popugame__cell.is-token-p0::before {
	content: "";
	inline-size: 56%;
	block-size: 56%;
	border-radius: 50%;
	background: var(--player-0-color);
}
.popugame__cell.is-token-p1::before {
	content: "";
	inline-size: 50%;
	block-size: 50%;
	border-radius: var(--radius-sm);
	background: var(--player-1-color);
}

/* The replay marks the cell just played until the next step. */
.popugame-replay__last-move {
	outline: 2px solid var(--accent);
	outline-offset: -2px;
}

/* End of game: the result line (the score and reason are a KV), and the
   rating change. */
.popugame__endgame-result {
	display: block;
	font-size: var(--fs-title);
	font-weight: 600;
	line-height: 1.2;
}

.popugame__endgame-result.is-p0 { color: var(--player-0-color); }
.popugame__endgame-result.is-p1 { color: var(--player-1-color); }

.popugame__endgame-elo:not([hidden]) {
	display: grid;
	gap: var(--sp-1);
	padding: var(--sp-2) var(--sp-3);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	background: var(--bg);
	font-size: var(--fs-sm);
}

.popugame__elo-value { font-weight: 600; }

/* A rating change in the site's good and bad tones, never a seat colour. */
.popugame__delta--positive {
	color: var(--ok);
	font-weight: 600;
}

.popugame__delta--negative {
	color: var(--danger);
	font-weight: 600;
}

/* On a phone the board takes the full width with no gaps between cells
   (nine 41 px cells at 400): the frame and its inset go. */
@media (max-width: 600px) {
	[data-popugame],
	[data-pg-replay] {
		padding: 0;
		border: 0;
		background: transparent;
	}
	.popugame__board {
		padding: 0;
		gap: 0;
	}
	.popugame__cell { border-radius: 0; }
}

/* The board is no taller than the screen leaves under the page's head and
   the score header (20rem with the frame's foot), so all nine rows show at
   once on a short window; the 400 px floor keeps cells tappable. */
.popugame__board { max-inline-size: max(400px, calc(100dvh - 20rem)); margin-inline: auto; }
/* -- end PopuGame -- */

/* -- Training view (pages/games_training.py, games_training_load.py; fishrl_training.js; lane T) -- */
/* The live line holds one line whatever the run's detail, so a long time
   stamp clips rather than wrapping the body down at 400 px. */
[data-page="fishrl-metrics"] [data-fishrl-status] {
	min-inline-size: 0;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}
/* On a phone the line is its own row from the first paint: the run's
   detail would not fit beside the h1 and would wrap the head down. */
@media (max-width: 600px) {
	[data-page="fishrl-metrics"] .l-page__meta { flex-basis: 100%; }
}
/* The opponent picker keeps one width, so Play does not move when the
   options land. */
#fr-opponent { inline-size: 16rem; max-inline-size: 100%; }

/* The chart wall: one WPlot.section per plot section. */
[data-async="fishrl-grid"] { display: flex; flex-direction: column; gap: var(--sp-5); }
/* Held at the screen from the first paint, before reserve.js runs: the
   sections run past it, so nothing under the wall moves into view. */
[data-async="fishrl-grid"]:empty { min-block-size: 100vh; }
/* Turn x iteration heatmaps (renderHeatmap): a plain canvas in the plot's
   box; the title and readout read as uPlot's (components.css .uplot). */
.fr-heat__title { font-size: var(--fs-sm); font-weight: 600; text-align: center; }
.fr-heat__canvas { display: block; inline-size: 100%; }
.fr-heat__readout {
	padding: var(--sp-1) 0 0;
	overflow: hidden;
	font-size: var(--fs-xs);
	white-space: nowrap;
	text-overflow: ellipsis;
}
/* A phone's folded legend (fishrl_training.js foldLegend): its pager sits
   centred under the centred legend rows it unfolds. */
[data-async="fishrl-grid"] .metric-plot > .c-pager { justify-content: center; }
/* -- end Training view -- */
