/* lobby.css - the two game lobbies (Forgetful Fish and PopuGame): the frame,
   the leaderboard, lobby and history rows, the host modal's options, the
   resume strip and the live-game previews. Only the lobbies load it. The
   markup is frozen (ui/checks.py FROZEN): these rules draw it as the site's
   other pages read - flat sections, sentence-case labels, 30 px rows, quiet
   status words. Buttons, fields, the modal and the muted line are the site's
   (body.ui). The PopuGame board, play page, replay and end-of-game dialog are
   area_games.css's. */

/* ── Frame ─────────────────────────────────────────────────────── */

/* The page frame, at .l-page's padding, rhythm and type (components.css). */
.popugame-landing {
	box-sizing: border-box;
	max-inline-size: 72rem;
	margin-inline: auto;
	padding: var(--sp-4) var(--page-gutter) var(--sp-6);
	display: flex;
	flex-direction: column;
	gap: var(--sp-4);
	font-size: var(--fs-sm);
	line-height: 1.6;
}

.popugame-landing__body {
	display: grid;
	grid-template-columns: 17rem minmax(0, 1fr);
	gap: var(--sp-5) var(--sp-6);
	align-items: start;
}

.popugame-landing__rail,
.popugame-landing__right {
	display: grid;
	gap: var(--sp-5);
	align-content: start;
	min-inline-size: 0;
}

/* Sections as the site draws them (ui Section): no frame, the head on a
   rule, then the body. */
.popugame-landing .section-card {
	padding: 0;
	background: none;
	border: 0;
	border-radius: 0;
}
.popugame-landing .section-card__head {
	min-block-size: var(--ctl-h-field);
	padding-block-end: var(--sp-1);
	border-block-end: 1px solid var(--border);
}

/* The resume strip sits under Play and above the public lobby, so its rows
   arriving never push the host buttons down. */
.popugame-landing__right > .ff-resume { order: 1; }
.popugame-landing__right > .section-card:has([data-ff-lobby-list], [data-pg-lobby-list]) { order: 2; }

/* ── Play panel ────────────────────────────────────────────────── */

/* The host buttons share a line; each labelled row takes a line of its own. */
.popugame-landing__play {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--sp-2);
}

/* min 0: a field's default width must not hold its row wider than the panel. */
.popugame-landing__play > :is(.eyebrow, .inline-form, .ff-utility) {
	flex: 1 1 100%;
	min-inline-size: 0;
}

/* A row's name, as a field label reads elsewhere: sentence case, the
   interface size, no tracking. */
.popugame-landing .eyebrow {
	padding-block-start: var(--sp-1);
	font-size: var(--fs-sm);
	font-weight: 500;
	letter-spacing: normal;
	text-transform: none;
}

/* The join row holds a 6-character code and Join; the opponent row its
   select and Start. */
.popugame-landing__play > .inline-form {
	max-inline-size: 22rem;
	justify-content: flex-start;
}

/* The join and opponent fields, as the site's field (body.ui .fld). */
.popugame-landing .inline-form :is(input, select) {
	box-sizing: border-box;
	block-size: var(--ctl-h-field);
	padding: 0 var(--sp-2);
	font-size: var(--ctl-fs-field);
	background: var(--bg);
	border-radius: var(--radius-md);
}

.ff-myrating {
	color: var(--text-muted);
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.ff-utility {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-4);
	padding-block-start: var(--sp-2);
	border-block-start: 1px solid var(--border);
}

.ff-utility__link {
	display: inline-flex;
	align-items: center;
	min-inline-size: var(--ctl-h-chip);
	min-block-size: var(--ctl-h-chip);
}
.ff-utility__link:hover { color: var(--accent-hover); }

/* Games the viewer can return to. */
.ff-resume {
	padding: var(--sp-1) var(--sp-3);
	border-radius: var(--radius-md);
	background: var(--accent-soft);
}
.ff-resume[hidden] { display: none; }
.ff-resume__row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0 var(--sp-2);
	min-block-size: var(--row-h);
}
.ff-resume__row + .ff-resume__row { border-block-start: 1px solid var(--border); }
.ff-resume__label {
	flex: 1 1 12rem;
	min-inline-size: 0;
	font-weight: 500;
}
/* The game's code, whether it is listed, and its mode and clock. */
.ff-resume__detail {
	padding-inline-start: var(--sp-2);
	color: var(--text-muted);
	font-weight: 400;
	font-size: var(--fs-xs);
}
.ff-resume__actions { display: flex; gap: var(--sp-2); flex: none; }

/* ── Leaderboard: one 30 px row a player under a head row ──────── */

.popugame-leaderboard-row {
	box-sizing: border-box;
	display: grid;
	grid-template-columns: 1.75rem minmax(0, 1fr) auto 4.75rem;
	align-items: center;
	column-gap: var(--sp-2);
	min-block-size: var(--row-h);
	padding: 0 var(--sp-1);
	border-block-end: 1px solid var(--border);
}
.popugame-leaderboard-row:last-child { border-block-end: 0; }

/* The column names, muted, as a table head. */
.popugame-leaderboard-row--head {
	color: var(--text-muted);
	font-size: var(--fs-xs);
	font-weight: 500;
}

.popugame-leaderboard-row__rank {
	color: var(--text-muted);
	font-size: var(--fs-xs);
	font-variant-numeric: tabular-nums;
}

.popugame-leaderboard-row__name {
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.popugame-leaderboard-row__elo {
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	text-align: end;
	white-space: nowrap;
}

.popugame-leaderboard-row__record {
	color: var(--text-muted);
	font-size: var(--fs-xs);
	font-variant-numeric: tabular-nums;
	text-align: end;
	white-space: nowrap;
}
.popugame-leaderboard-row--head > * { font-weight: 500; }

/* The list holds two rows' height while it loads; the full ladder can
   outgrow the column and scrolls inside it. */
.popugame-leaderboard-list {
	min-block-size: calc(var(--row-h) * 2);
	max-block-size: 26rem;
	overflow-y: auto;
}

/* The viewer's own row: the whole row tinted, the name heavier. */
.popugame-leaderboard-row--me {
	border-radius: var(--radius-sm);
	background: var(--accent-soft);
}
.popugame-leaderboard-row--me .popugame-leaderboard-row__name { font-weight: 600; }

/* "..." between the top of the ladder and the viewer's rank window. */
.ff-lb-gap {
	text-align: center;
	color: var(--text-muted);
	font-size: var(--fs-xs);
	letter-spacing: 0.2em;
}

/* Phones start at the top 3 (the head row first), with a toggle under them. */
.popugame-leaderboard-list--collapsed .popugame-leaderboard-row:nth-child(n+5) { display: none; }
.popugame-leaderboard-list--collapsed .ff-lb-gap { display: none; }
.ff-lb-toggle { inline-size: 100%; }

/* ── Public lobby rows ─────────────────────────────────────────── */

.popugame-lobby-row {
	box-sizing: border-box;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0 var(--sp-2);
	min-block-size: var(--row-h);
	border-block-end: 1px solid var(--border);
}
.popugame-lobby-row:last-child { border-block-end: 0; }

.popugame-lobby-row__host {
	flex: 1 1 8rem;
	min-inline-size: 0;
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.popugame-lobby-row--mine .popugame-lobby-row__host { font-weight: 600; }

.ff-lobby-row__elo {
	padding-inline-start: var(--sp-2);
	color: var(--text-muted);
	font-weight: 400;
	font-variant-numeric: tabular-nums;
}

.popugame-lobby-row__age,
.ff-lobby-row__time {
	color: var(--text-muted);
	font-size: var(--fs-xs);
	white-space: nowrap;
}

/* A game's mode is a word, as the site's status words read: no box and no
   accent, so it is never taken for a link or a button beside Join or Cancel. */
.popugame-landing .badge {
	padding: 0;
	border: 0;
	background: none;
	font-weight: 500;
	letter-spacing: normal;
	color: var(--text-muted);
}

.popugame-lobby-row .btn { flex: none; }

.pg-lobby-own-actions {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	flex: none;
}

/* ── History rows (in the rail): players, then the result with its
   score and Replay, then the length and date. ───────────────────── */

.popugame-history-row {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: center;
	gap: 0 var(--sp-3);
	padding-block: var(--sp-1);
	border-block-end: 1px solid var(--border);
}
.popugame-history-row:last-child { border-block-end: 0; }

.popugame-history-row__players {
	grid-column: 1 / -1;
	grid-row: 1;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* One line: the winner's name clips before the score does. */
.popugame-history-row__result {
	grid-column: 1;
	grid-row: 2;
	min-inline-size: 0;
	font-weight: 600;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.popugame-history-row__result--p0 { color: var(--player-0-color); }
.popugame-history-row__result--p1 { color: var(--player-1-color); }
.popugame-history-row__result--draw { color: var(--text-muted); }

.popugame-history-row__watch {
	grid-column: 2;
	grid-row: 2;
}

.popugame-history-row__meta {
	grid-column: 1 / -1;
	grid-row: 3;
	color: var(--text-muted);
	font-size: var(--fs-xs);
	white-space: nowrap;
}

/* ── Games in progress: one preview a row in the rail ──────────── */

.ff-active-panel [data-ff-active-list] {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--sp-2);
}
.ff-active-panel [data-ff-active-list] > .w-empty { grid-column: 1 / -1; }

.ff-mini {
	display: flex;
	flex-direction: column;
	gap: var(--sp-1);
	min-inline-size: 0;
	padding: var(--sp-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
}
.ff-mini__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--sp-2);
}
.ff-mini__vs {
	flex: 1 1 0;
	min-inline-size: 0;
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.ff-mini__elo {
	flex: none;
	color: var(--text-muted);
	font-size: var(--fs-xs);
	font-variant-numeric: tabular-nums;
}
.ff-mini__foot { display: flex; justify-content: flex-end; }

/* ── Host modal: one bordered row per game mode ────────────────── */

/* Cancel and Escape close it, as the site's other dialogs: no glyph. */
.popugame-landing .modal__close { display: none; }

.pg-host-options {
	display: grid;
	gap: var(--sp-2);
}

.pg-host-option {
	display: flex;
	align-items: baseline;
	gap: var(--sp-3);
	padding: var(--sp-2) var(--sp-3);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	cursor: pointer;
}
.pg-host-option:hover { background: var(--surface-3); }
.pg-host-option:has(.pg-host-option__radio:checked) {
	border-color: var(--accent);
	background: var(--accent-soft);
}
.pg-host-option:has(.pg-host-option__radio:disabled) {
	cursor: default;
	background: none;
	border-style: dashed;
	color: var(--text-muted);
}

.pg-host-option__radio {
	flex: none;
	margin: 0;
	accent-color: var(--accent);
}

.pg-host-option__body { display: grid; }
.pg-host-option__label { font-weight: 500; }
.pg-host-option__desc { color: var(--text-muted); }

.pg-host-clock {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	min-block-size: var(--ctl-h-chip);
	color: var(--text-muted);
	cursor: pointer;
}
.pg-host-clock input { accent-color: var(--accent); }
.pg-host-clock:has(input:disabled) { cursor: default; }

/* ── One column under the tablet break: Play and the public lobby
   first, then the leaderboard, then the rail's second panel (the rail
   becomes its children so the order can run through it). ───────── */
@media (max-width: 900px) {
	.popugame-landing__body { grid-template-columns: minmax(0, 1fr); }
	.popugame-landing__rail { display: contents; }
	.popugame-landing__rail > .section-card:not(.popugame-landing__rail-panel) { order: 1; }
	.popugame-landing__rail-panel { order: 2; }
	.ff-active-panel [data-ff-active-list] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
	/* The host buttons split the line; the labelled rows take all of it. */
	.popugame-landing__play > .btn { flex: 1 1 0; }
	.popugame-landing__play > .inline-form { max-inline-size: none; }
	/* A lobby row gives the host a line; mode, age and action share the next. */
	.popugame-lobby-row__host { flex-basis: 100%; white-space: normal; }
	.popugame-lobby-row :is(.btn, .pg-lobby-own-actions) { margin-inline-start: auto; }
	.ff-active-panel [data-ff-active-list] { grid-template-columns: minmax(0, 1fr); }
}
