/*
 * Styles for the "Log a play" space tab and its feed scoreboard.
 * Built entirely on BuddyNext's --bn-* design tokens (see buddynext-dev's
 * 45-design-system-tokens.md) so it re-themes and follows dark mode/RTL
 * automatically instead of hardcoding colors or pixel values.
 *
 * Motion follows the emil-design-eng skill's decision framework: only
 * transform/opacity/color, custom (non-default) easing curves, UI
 * durations under 300ms, and every animation named to a real purpose
 * (state indication / preventing a jarring change / feedback) -- see the
 * "Motion" section below for the audit this was built from.
 */

.wpbnbgg-space-plays,
.wpbnbgg-scoreboard {
	--wpbnbgg-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

@keyframes wpbnbgg-reveal {
	from {
		opacity: 0;
		transform: translateY(-4px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@media (prefers-reduced-motion: reduce) {
	@keyframes wpbnbgg-reveal {
		from {
			opacity: 0;
		}
		to {
			opacity: 1;
		}
	}
}

.wpbnbgg-log-play h3,
.wpbnbgg-play-history h3 {
	margin: 0 0 var(--bn-s4);
	font: var(--bn-fw-bold) var(--bn-text-lg) / var(--bn-leading-tight) var(--bn-font-display);
	color: var(--bn-ink);
}

/*
 * The form is collapsed until it is wanted, and its control is a square button
 * in the panel's top corner -- the place a "new thing" button lives, and small
 * enough that it never competes with the plays underneath it.
 *
 * The card chrome belongs to the open form, not to the button, so it is only
 * drawn while the form is open. Everything about the button's colour comes
 * from BuddyNext's own .bn-btn[data-variant="primary"].
 */
.wpbnbgg-log-play {
	display: flex;
	flex-direction: column;
}

.wpbnbgg-log-play:not([open]) {
	padding: 0;
	border: 0;
	background: none;
	box-shadow: none;
}

/* .bn-btn sets its own height, and it wins on specificity, so this has to
   match it to keep the button square. */
.wpbnbgg-log-play > summary.bn-btn {
	align-self: flex-end;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: 2.5rem;
	block-size: 2.5rem;
	min-block-size: 2.5rem;
	padding: 0;
	cursor: pointer;
	list-style: none;
}

/*
 * The button's label, for anyone who is not reading its shape. WordPress's
 * .screen-reader-text is an admin style and is not loaded on the front end
 * here, so the class is ours.
 */
.wpbnbgg-visually-hidden {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.wpbnbgg-log-play > summary::-webkit-details-marker {
	display: none;
}

/* The plus turns into a cross while the form is open: same control, and the
   rotation says which way it goes. */
.wpbnbgg-log-play__glyph {
	font-size: var(--bn-text-lg);
	line-height: 1;
	transition: transform 160ms var(--wpbnbgg-ease-out);
}

.wpbnbgg-log-play[open] .wpbnbgg-log-play__glyph {
	transform: rotate(45deg);
}

.wpbnbgg-log-play[open] > summary {
	margin-block-end: var(--bn-s3);
}

@media (prefers-reduced-motion: reduce) {
	.wpbnbgg-log-play__glyph {
		transition: none;
	}
}

.wpbnbgg-log-play h4 {
	margin: 0 0 var(--bn-s2);
	font: var(--bn-fw-semibold) var(--bn-text-base) / var(--bn-leading-tight) var(--bn-font-ui);
	color: var(--bn-ink-2);
}

.wpbnbgg-field {
	display: flex;
	flex-direction: column;
	gap: var(--bn-s1);
	margin-block-end: var(--bn-s4);
}

.wpbnbgg-field label {
	font: var(--bn-fw-medium) var(--bn-text-2xs) / var(--bn-leading-tight) var(--bn-font-ui);
	color: var(--bn-ink-3);
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.wpbnbgg-row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--bn-s4);
}

@media (max-width: 480px) {
	.wpbnbgg-row {
		grid-template-columns: 1fr;
	}
}

/* Game picker -- and the space picker, which is the same control */

.wpbnbgg-game-picker,
.wpbnbgg-space-picker {
	position: relative;
}

.wpbnbgg-space-selected {
	display: flex;
	align-items: center;
	gap: var(--bn-s2);
}

.wpbnbgg-dropdown {
	position: absolute;
	inset-inline: 0;
	top: calc(100% + var(--bn-s1));
	z-index: 20;
	margin: 0;
	padding: var(--bn-s1);
	list-style: none;
	background: var(--bn-raised);
	border: 1px solid var(--bn-line);
	border-radius: var(--bn-r-md);
	box-shadow: var(--bn-shadow-md);
	max-height: 16rem;
	overflow-y: auto;
	transform-origin: top;
}

/* Fires when the Interactivity API removes the `hidden` attribute --
   occasional/tens-of-day frequency (search results, member picker), so a
   fast 180ms reveal is within the dropdown budget. Doesn't retrigger on
   every keystroke: `hidden` only toggles between "no results"/"has
   results", not on every character typed while results stay non-empty. */
.wpbnbgg-dropdown:not([hidden]) {
	animation: wpbnbgg-reveal 180ms var(--wpbnbgg-ease-out);
}

.wpbnbgg-dropdown-item {
	display: flex;
	align-items: center;
	gap: var(--bn-s2);
	padding: var(--bn-s2) var(--bn-s3);
	border-radius: var(--bn-r-sm);
	cursor: pointer;
	color: var(--bn-ink);
	transition: background-color 120ms ease;
}

.wpbnbgg-dropdown-item:hover,
.wpbnbgg-dropdown-item:focus-visible {
	background: var(--bn-accent-50);
}

.wpbnbgg-dropdown-text {
	display: flex;
	flex-direction: column;
	line-height: var(--bn-leading-tight);
}

.wpbnbgg-dropdown-name {
	font: var(--bn-fw-medium) var(--bn-text-base) / var(--bn-leading-tight) var(--bn-font-ui);
}

.wpbnbgg-dropdown-year {
	font-size: var(--bn-text-2xs);
	color: var(--bn-ink-3);
}

.wpbnbgg-dropdown-avatar {
	inline-size: 1.75rem;
	block-size: 1.75rem;
	border-radius: var(--bn-r-full);
	object-fit: cover;
	flex: none;
}

.wpbnbgg-icon--dice {
	inline-size: 1.5rem;
	block-size: 1.5rem;
	color: var(--bn-ink-3);
	flex: none;
}

.wpbnbgg-icon--dice svg {
	inline-size: 100%;
	block-size: 100%;
}

/* Selected-game card */

.wpbnbgg-game-selected {
	display: flex;
	align-items: center;
	gap: var(--bn-s3);
	padding: var(--bn-s3);
	border: 1px solid var(--bn-line);
	border-radius: var(--bn-r-md);
	background: var(--bn-sunken);
}

/* Replaces the picker instantly today (a "teleporting state") -- occasional
   frequency (once per game picked), so a standard 200ms reveal applies. */
.wpbnbgg-game-selected:not([hidden]) {
	animation: wpbnbgg-reveal 200ms var(--wpbnbgg-ease-out);
}

.wpbnbgg-thumb {
	inline-size: 3rem;
	block-size: 3rem;
	border-radius: var(--bn-r-sm);
	flex: none;
	overflow: hidden;
}

.wpbnbgg-thumb img {
	inline-size: 100%;
	block-size: 100%;
	object-fit: cover;
}

.wpbnbgg-thumb--placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--bn-raised);
	color: var(--bn-ink-3);
}

.wpbnbgg-thumb--placeholder svg {
	inline-size: 60%;
	block-size: 60%;
}

.wpbnbgg-game-meta {
	display: flex;
	flex-direction: column;
	gap: 2px;
	flex: 1;
	min-inline-size: 0;
}

.wpbnbgg-game-meta strong {
	font: var(--bn-fw-semibold) var(--bn-text-base) / var(--bn-leading-tight) var(--bn-font-ui);
	color: var(--bn-ink);
}

.wpbnbgg-game-sub {
	font-size: var(--bn-text-2xs);
	color: var(--bn-ink-3);
}

/* Player list */

.wpbnbgg-player-list {
	display: flex;
	flex-direction: column;
	gap: var(--bn-s2);
	margin: 0 0 var(--bn-s3);
	padding: 0;
	list-style: none;
}

.wpbnbgg-player-row {
	display: flex;
	align-items: center;
	gap: var(--bn-s2);
	padding: var(--bn-s2);
	border: 1px solid var(--bn-line-faint);
	border-radius: var(--bn-r-md);
	background: var(--bn-surface);
	/* Each row is a genuinely new DOM node when added (data-wp-each keys by
	   player), so this plays once on insert -- it doesn't retrigger for
	   existing rows on unrelated state changes like typing a score. */
	animation: wpbnbgg-reveal 200ms var(--wpbnbgg-ease-out);
}

.wpbnbgg-player-avatar {
	inline-size: 2rem;
	block-size: 2rem;
	border-radius: var(--bn-r-full);
	flex: none;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
}

.wpbnbgg-player-avatar img {
	inline-size: 100%;
	block-size: 100%;
	object-fit: cover;
}

.wpbnbgg-player-avatar--icon {
	background: var(--bn-sunken);
	color: var(--bn-ink-3);
}

.wpbnbgg-player-avatar--icon svg {
	inline-size: 60%;
	block-size: 60%;
}

.wpbnbgg-player-name {
	flex: 1;
	min-inline-size: 0;
	display: flex;
	align-items: center;
	gap: var(--bn-s1);
}

.wpbnbgg-player-name--static {
	font: var(--bn-fw-medium) var(--bn-text-base) / var(--bn-leading-tight) var(--bn-font-ui);
	color: var(--bn-ink);
}

.wpbnbgg-player-name input {
	width: 100%;
}

.wpbnbgg-score-input {
	inline-size: 5rem;
	flex: none;
	text-align: center;
}

.wpbnbgg-win-toggle {
	display: inline-flex;
	align-items: center;
	gap: var(--bn-s1);
	padding: var(--bn-s1) var(--bn-s3);
	border: 1px solid var(--bn-line);
	border-radius: var(--bn-r-full);
	font-size: var(--bn-text-2xs);
	font-weight: var(--bn-fw-medium);
	color: var(--bn-ink-3);
	cursor: pointer;
	flex: none;
	white-space: nowrap;
	/* Color/background change, not entering/exiting -- plain `ease`, not
	   ease-out (emil-design-eng's easing decision tree). */
	transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.wpbnbgg-win-toggle input {
	position: absolute;
	opacity: 0;
	inline-size: 1px;
	block-size: 1px;
}

.wpbnbgg-win-toggle.is-active {
	background: var(--bn-success-bg);
	border-color: transparent;
	color: var(--bn-success);
}

.wpbnbgg-remove-btn {
	inline-size: 1.75rem;
	block-size: 1.75rem;
	flex: none;
	border: none;
	background: transparent;
	border-radius: var(--bn-r-full);
	color: var(--bn-ink-3);
	font-size: var(--bn-text-lg);
	line-height: 1;
	cursor: pointer;
	transition: background-color 120ms ease, color 120ms ease, transform 160ms var(--wpbnbgg-ease-out);
}

.wpbnbgg-remove-btn:hover,
.wpbnbgg-remove-btn:focus-visible {
	background: var(--bn-danger-bg);
	color: var(--bn-danger);
}

.wpbnbgg-remove-btn:active {
	transform: scale(0.95);
}

.wpbnbgg-add-player-row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--bn-s2);
}

.wpbnbgg-member-picker {
	position: relative;
	flex: 1;
	min-inline-size: 12rem;
}

.wpbnbgg-form-error {
	margin: var(--bn-s3) 0 0;
	font-size: var(--bn-text-2xs);
	color: var(--bn-danger);
}

.wpbnbgg-log-play > .bn-btn[data-variant="primary"] {
	margin-block-start: var(--bn-s4);
}

/* Scoreboard (feed post) */

.wpbnbgg-scoreboard-title {
	margin: 0 0 var(--bn-s3);
	font: var(--bn-fw-bold) var(--bn-text-lg) / var(--bn-leading-tight) var(--bn-font-display);
	color: var(--bn-ink);
}

.wpbnbgg-scoreboard-main {
	display: flex;
	align-items: flex-start;
	gap: var(--bn-s4);
	margin-block-end: var(--bn-s3);
}

.wpbnbgg-thumb--lg {
	inline-size: 6rem;
	block-size: 6rem;
	border-radius: var(--bn-r-md);
}

@media (max-width: 480px) {
	.wpbnbgg-scoreboard-main {
		flex-direction: column;
	}

	.wpbnbgg-thumb--lg {
		inline-size: 100%;
		block-size: auto;
		aspect-ratio: 1;
		max-inline-size: 10rem;
	}
}

.wpbnbgg-stats-table {
	flex: 1;
	min-inline-size: 0;
	border-collapse: collapse;
	font-size: var(--bn-text-2xs);
}

.wpbnbgg-stats-table td {
	padding: calc(var(--bn-s1) / 2) 0;
	line-height: var(--bn-leading-tight);
	vertical-align: middle;
}

.wpbnbgg-stat-icon {
	inline-size: 1.1rem;
	block-size: 1.1rem;
	color: var(--bn-ink-3);
	padding-inline-end: var(--bn-s2);
}

.wpbnbgg-stat-icon svg {
	inline-size: 100%;
	block-size: 100%;
	display: block;
}

.wpbnbgg-stat-label {
	color: var(--bn-ink-3);
	padding-inline-end: var(--bn-s3);
	white-space: nowrap;
}

.wpbnbgg-stat-value {
	color: var(--bn-ink);
	font-weight: var(--bn-fw-medium);
}

.wpbnbgg-stat-value--muted {
	color: var(--bn-ink-3);
	font-weight: var(--bn-fw-normal);
	font-style: italic;
}

.wpbnbgg-players-details summary {
	cursor: pointer;
	font: var(--bn-fw-semibold) var(--bn-text-2xs) / var(--bn-leading-tight) var(--bn-font-ui);
	color: var(--bn-ink-3);
	list-style: none;
}

.wpbnbgg-players-details summary::-webkit-details-marker {
	display: none;
}

.wpbnbgg-players-details summary::before {
	content: "▸";
	display: inline-block;
	margin-inline-end: var(--bn-s1);
	transition: transform 160ms var(--wpbnbgg-ease-out);
}

.wpbnbgg-players-details[open] summary::before {
	transform: rotate(90deg);
}

.wpbnbgg-scoreboard-players {
	display: flex;
	flex-direction: column;
	gap: var(--bn-s1);
	margin: var(--bn-s2) 0 0;
	padding: 0;
	list-style: none;
}

/* The native <details> disclosure snaps open with no transition -- state
   indication, occasional frequency, so a 200ms reveal on the content
   applies (the open/close mechanics themselves stay native/instant;
   animating <details>'s height directly needs JS or bleeding-edge CSS
   that isn't worth the added complexity here). */
.wpbnbgg-players-details[open] > .wpbnbgg-scoreboard-players {
	animation: wpbnbgg-reveal 200ms var(--wpbnbgg-ease-out);
}

.wpbnbgg-scoreboard-players li {
	display: flex;
	align-items: center;
	gap: var(--bn-s2);
	font-size: var(--bn-text-base);
	color: var(--bn-ink-2);
}

.wpbnbgg-score {
	color: var(--bn-ink-3);
}

/*
 * The play under a feed post: the card's content, without the card.
 *
 * The post it hangs under is already a card -- BuddyNext drew that frame -- so
 * a second border and background inside it reads as a box in a box. What is
 * worth keeping is everything above the frame: the cover, the stat row, the
 * result bar, in the same shapes the profile uses.
 */
.wpbnbgg-feed-play {
	margin-block-start: var(--bn-s3);
}

.wpbnbgg-feed-play[data-view='grid'] {
	grid-template-columns: minmax(0, 1fr);
}

.wpbnbgg-feed-play .wpbnbgg-collection__item {
	padding: 0;
	background: none;
	border: 0;
	border-radius: 0;
}

/*
 * One statistic per line, as the tiles show them.
 *
 * The card sizes its stats from the width of its body, and a post is wide --
 * so left alone it spread them into a row, which is the layout a wide card
 * uses and not the one the tiles have. The tiles are the reference here: a
 * label on the left, its value on the right, read down the side of the cover.
 */
.wpbnbgg-feed-play .wpbnbgg-collection__stats {
	grid-template-columns: minmax(0, 1fr);
}

.wpbnbgg-feed-play .wpbnbgg-stat {
	grid-column: auto;
}

/*
 * The result keeps the tiles' bare table. BuddyNext rules tables inside a post
 * body -- a sensible default for a table somebody pasted into a post, and
 * wrong for one that is part of a card: on a dark feed those rules draw a pale
 * grid over every score.
 */
.wpbnbgg-feed-play .wpbnbgg-play-result table,
.wpbnbgg-feed-play .wpbnbgg-play-result th,
.wpbnbgg-feed-play .wpbnbgg-play-result td {
	border: 0;
	background: none;
}

/* The result bar keeps its own frame: it is a control, not decoration. */
.wpbnbgg-feed-play .wpbnbgg-play-result {
	margin-block-start: var(--bn-s3);
}

/* The "load more" step under every 99-entry list. */

.wpbnbgg-load-more {
	display: flex;
	justify-content: center;
	margin: var(--bn-s4) 0 0;
}

/* One tap for cooperative endings: everyone won, or the game did. */

.wpbnbgg-all-win-row {
	display: flex;
	gap: var(--bn-s2);
	margin-block-start: var(--bn-s2);
}
