/*
 * Échanges de cartes (app/features/trades.js) : écran de proposition en plein écran
 * (.trade-layer) et bloc « Échanges » de la Collection (.trades).
 */

/* Écran de proposition */

.trade-layer[open] {
	display: flex;
}

.trade-layer {
	position: fixed;
	inset: 0;
	flex-direction: column;
	width: 100%;
	max-width: none;
	height: 100%;
	max-height: none;
	margin: 0;
	padding: 0;
	border: none;
	box-sizing: border-box;
	background: var(--ColorBackground, #161616);
	color: var(--ColorText, #fff);
	outline: none;
	opacity: 0;
	transition: opacity 0.25s ease;
}

.trade-layer::backdrop {
	background: rgba(0, 0, 0, 0.6);
}

.trade-layer.open {
	opacity: 1;
}

.trade-header {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 4.75rem;
	padding: 0 1rem;
}

.trade-step {
	width: auto;
	font-weight: 700;
	opacity: 0.7;
}

.trade-header .trade-close {
	top: 1rem;
	right: 1rem;
}

.trade-body {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 0 1rem 1rem;
	text-align: center;
}

.trade-title,
.trade-subtitle {
	text-align: center;
}

.trade-title {
	margin: 0 0 0.25rem;
	font-size: 1.5rem;
}

.trade-subtitle {
	margin: 0 0 1.25rem;
	opacity: 0.75;
}

.trade-footer {
	display: flex;
	justify-content: center;
	gap: 0.75rem;
	padding: 1rem;
	border-top: 1px solid var(--ColorRow, rgba(255, 255, 255, 0.08));
}

.trade-footer .btn {
	flex: 1 1 0;
	max-width: 16rem;
	width: auto;
	justify-content: center;
}

/* css/main.css masque le texte des boutons sous 650px : ici il reste visible */
.trade-footer .btn span {
	display: inline;
	width: auto;
}

.trade-empty,
.trade-nothing {
	margin: 0;
	opacity: 0.6;
}

/* Grille de cartes à cocher */

.trade-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
	gap: 0.9rem;
	max-width: 48rem;
	/* Place sous les dernières cartes pour le bouton de tri flottant */
	margin: 0 auto 4.5rem;
}

.trade-pick {
	position: relative;
	padding: 0;
	border: none;
	border-radius: 0.6rem;
	background: none;
	cursor: pointer;
	/* Le contour de sélection suit l'arrondi de la carte (4.5cqw, css/trading-card.css) */
	container-type: inline-size;
	/* Pas d'attente du double-tap sur iOS : la sélection réagit dès le toucher */
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
	transition: opacity 0.12s ease, transform 0.12s ease;
}

.trade-pick:active {
	transform: scale(0.95);
}

/* Effets de carte figés dans les grilles et rangées d'échange : des dizaines de reflets animés
   repeints en continu ralentissent la réponse au toucher sur téléphone */
.trade-grid .tcard-shine,
.trade-grid .tcard-face::before,
.trade-strip .tcard-shine,
.trade-strip .tcard-face::before {
	animation: none;
}

.trade-pick.selected {
	transform: translateY(-0.25rem);
}

/* Une carte choisie : les autres s'estompent */
.trade-grid.has-pick .trade-pick:not(.selected, .reserved) {
	opacity: 0.55;
}

.trade-pick.selected::after {
	content: '';
	position: absolute;
	inset: -0.25rem;
	border: 0.2rem solid var(--ColorPrimary);
	border-radius: calc(4.5cqw + 0.25rem);
	pointer-events: none;
}

.trade-check {
	position: absolute;
	top: -0.45rem;
	right: -0.45rem;
	z-index: 3;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 1.6rem;
	height: 1.6rem;
	border-radius: 50%;
	background: var(--ColorPrimary);
	color: var(--ColorPrimaryText, #1b1b1b);
	font-size: 0.8rem;
	opacity: 0;
	transform: scale(0.5);
	transition: opacity 0.12s ease, transform 0.12s ease;
}

.trade-pick.selected .trade-check {
	opacity: 1;
	transform: none;
}

.trade-pick.reserved {
	cursor: not-allowed;
	opacity: 0.35;
}

.trade-reserved {
	position: absolute;
	left: 50%;
	bottom: 0.5rem;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	width: auto;
	padding: 0.15rem 0.5rem;
	border-radius: 99px;
	background: #111;
	color: #fff;
	font-size: 0.7rem;
	font-weight: 700;
	white-space: nowrap;
	transform: translateX(-50%);
}

.trade-count {
	position: absolute;
	right: -0.3rem;
	bottom: -0.3rem;
	z-index: 2;
	width: auto;
	padding: 0.1rem 0.4rem;
	border-radius: 99px;
	background: var(--ColorRow, #333);
	color: var(--ColorText, #fff);
	font-size: 0.7rem;
	font-weight: 700;
}

/* Récapitulatif et bloc Échanges : rangées de petites cartes */

.trade-summary {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.6rem;
	max-width: 36rem;
	margin: 1rem auto 0;
	text-align: center;
}

/* Pleine largeur : sinon la rangée prend la taille de son contenu et les cartes en % tombent à 0 */
.trade-summary .trade-strip {
	width: 100%;
	justify-content: center;
	gap: 0.75rem;
}

/* Récapitulatif : une carte par côté, affichée en grand */
.trade-summary .trade-mini {
	width: min(14rem, 60vw);
}

/* Contre-offre : les deux cartes côte à côte */
.trade-duo {
	flex-direction: row;
	align-items: flex-start;
	justify-content: center;
	gap: 1rem;
}

.trade-duo > div {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.6rem;
	flex: 1 1 0;
	min-width: 0;
	max-width: 14rem;
}

.trade-duo .trade-strip,
.trade-duo .trade-mini-item,
.trade-duo .trade-mini {
	width: 100%;
}

/* Rappel de la carte proposée au-dessus de la grille de contre-offre : plus petit */
.trade-offer-get .trade-mini {
	width: 8rem;
}

/* Contre-offre : rappel des cartes proposées au-dessus de la grille */
.trade-offer-get {
	margin: 0 auto 1.25rem;
}

.trade-note {
	max-width: 30rem;
	margin: 1.25rem auto 0;
	font-size: 0.9rem;
}

.trade-summary h3,
.trade-item-sides h3 {
	margin: 0.5rem 0 0;
	font-size: 0.95rem;
}

.trade-strip {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.trade-mini {
	width: 4.25rem;
	touch-action: manipulation;
	padding: 0;
	border: none;
	background: none;
	cursor: pointer;
}

/* Bloc « Échanges » de la Collection */

.trades {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	width: 100%;
}

.trade-item {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	padding: 1rem;
	border-radius: var(--BorderRadius, 1rem);
	background: var(--ColorContainer);
	box-shadow: var(--Shadow);
}

/* Échange qui attend une réponse du joueur : liseré à la couleur principale */
.trade-item.my-turn {
	box-shadow: var(--Shadow), inset 0 0 0 0.15rem var(--ColorPrimary);
}

/* Échange ouvert depuis une notification push : liseré qui pulse deux fois */
.trade-item.highlight {
    animation: trade-highlight 1.2s ease-in-out 2;
}

@keyframes trade-highlight {
    0%, 100% {
        box-shadow: var(--Shadow), inset 0 0 0 0.15rem var(--ColorPrimary);
    }

    50% {
        box-shadow: var(--Shadow), inset 0 0 0 0.4rem var(--ColorPrimary);
    }
}

.trade-item:not(.pending) {
	opacity: 0.7;
}

.trade-item-head {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

/* Avatar de l'autre joueur : ouvre son profil */
.trade-avatar-button {
	display: flex;
	flex-shrink: 0;
	width: auto;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: none;
	cursor: pointer;
}

.trade-avatar {
	flex-shrink: 0;
	width: 2.75rem;
	height: 2.75rem;
	border-radius: 50%;
	object-fit: cover;
}

.trade-item-title {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
	flex: 1;
	min-width: 0;
}

.trade-item-title p {
	margin: 0;
}

.trade-item-title small {
	width: auto;
	font-size: 0.75rem;
	opacity: 0.6;
}

.trade-item-head .badges {
	flex-shrink: 0;
	width: auto;
}

/* Les deux côtés, séparés par l'icône d'échange */
.trade-item-sides {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	align-items: stretch;
	gap: 0.75rem;
}

.trade-side {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem;
	border-radius: calc(var(--BorderRadius, 1rem) * 0.75);
	background: var(--ColorRow, rgba(255, 255, 255, 0.05));
	box-shadow: var(--Shadow);
}

.trade-item-sides h3 {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	width: auto;
	margin: 0;
	font-size: 0.95rem;
	white-space: nowrap;
}

.trade-item-sides h3 i {
	width: auto;
}

.trade-side.get h3 i,
.trade-heading.get i {
	color: #4caf50;
}

.trade-side.give h3 i,
.trade-heading.give i {
	color: #ef5350;
}

/* Titres des récapitulatifs (choix de carte, contre-offre) : flèche et libellé */
.trade-heading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
}

.trade-heading i {
	width: auto;
}

.trade-side .trade-strip {
	width: 100%;
	justify-content: center;
	gap: 0.6rem;
}

.trade-side .trade-mini {
	width: 5.5rem;
}

.trade-side .trade-nothing {
	margin: auto 0;
}

.trade-item-swap {
	display: flex;
	align-items: center;
	justify-content: center;
	align-self: center;
	width: 2.25rem;
	height: 2.25rem;
	border-radius: 50%;
	background: var(--ColorRow, rgba(255, 255, 255, 0.05));
	opacity: 0.8;
}

.trade-item-actions {
	display: flex;
	justify-content: flex-end;
	gap: 0.6rem;
}

.trade-item-actions .btn {
	width: auto;
}

.trade-item-actions .btn span {
	display: inline;
	width: auto;
}

@media (max-width: 650px) {
	.trade-item-sides {
		grid-template-columns: 1fr;
	}

	.trade-item-swap {
		justify-self: center;
		transform: rotate(90deg);
	}

	.trade-side .trade-mini {
		width: 6rem;
	}

	.trade-item-actions .btn {
		flex: 1 1 0;
		justify-content: center;
	}
}

@media (prefers-reduced-motion: reduce) {
	.trade-pick,
	.trade-check {
		transition: none;
	}
}

/* Onglet « Échanges » : pastille des propositions reçues, état vide */
.tab-count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 1.25rem;
	height: 1.25rem;
	padding: 0 0.35rem;
	border-radius: 99px;
	box-sizing: border-box;
	background: var(--ColorPrimary);
	color: var(--ColorPrimaryText, #1b1b1b);
	font-size: 0.75rem;
	font-weight: 700;
}

/* Page suivante en cours de chargement : un échange fantôme */
.trades-more {
	display: flex;
	flex-direction: column;
}

/* Historique (échanges terminés) masqué par défaut, sous les échanges en attente */
.trades-history-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	align-self: center;
	width: auto;
}

.trades-history-toggle .fa-chevron-up,
.trades-history-toggle .fa-chevron-down {
	font-size: 0.75rem;
	opacity: 0.7;
}

.trades-none {
	width: 100%;
	margin: 0;
	padding: 1.5rem 1rem 0.5rem;
	text-align: center;
}

/* Pleine largeur : sinon la colonne parente la réduit à son texte, calée à gauche */
.trades-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.4rem;
	width: 100%;
	box-sizing: border-box;
	padding: 2rem 1rem;
	text-align: center;
}

.trades-empty i {
	font-size: 2rem;
	opacity: 0.5;
}

.trades-empty p {
	margin: 0;
}

/* Choix du joueur pour une proposition (onglet Échanges, bouton « Proposer un échange ») */
/* Chaque enfant direct de .content reçoit les marges latérales de la modal (css/modal.css) :
   le champ est donc enveloppé, et seule la liste défile, sous la recherche qui reste visible */
#modal-trade-partner .content {
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.75rem;
    overflow: hidden;
}

.trade-partner-search {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

.trade-partner-search input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.75rem 1rem;
}

.trade-partners {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.trade-partner {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: var(--BorderRadius);
    background-color: var(--ColorContainer);
    color: var(--ColorText);
    font-size: var(--FontSize);
    text-align: left;
    cursor: pointer;
}

.trade-partner:hover {
    background-color: var(--ColorRowHover);
}

.trade-partner .logo {
    width: 2.5rem;
    height: 2.5rem;
    flex-shrink: 0;
}

/* Pseudo et titre : prend la place libre, les compteurs restent à droite */
.trade-partner-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

/* Nom du joueur : police des titres (choix du joueur, échanges) */
.trade-item-title .trade-who,
.trade-partner-name {
    font-family: var(--FontFocus);
    font-weight: 600;
}

.trade-partner-title {
    color: var(--ColorTextAlt);
    font-size: 0.8rem;
    font-weight: 400;
}

/* Cartes à récupérer (↓) et à donner (↑), ou « En attente » */
.trade-partner-stats {
    display: flex;
    flex-direction: row;
    gap: 0.35rem;
    flex-shrink: 0;
    width: auto;
}

/* width: auto contre la règle globale span { width: 100% } */
.trade-partner-stat {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    width: auto;
    min-width: 2.75rem;
    box-sizing: border-box;
    justify-content: center;
    padding: 0.25rem 0.5rem;
    border-radius: 99px;
    background-color: var(--ColorRow);
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.trade-partner-stat.get i,
.trade-partner-legend .fa-arrow-down {
    color: #4caf50;
}

.trade-partner-stat.give i,
.trade-partner-legend .fa-arrow-up {
    color: #ef5350;
}

.trade-partner-stat.none {
    opacity: 0.45;
}

.trade-partner-stat.pending i {
    color: var(--ColorTextAlt);
}

/* Légende des flèches, sous la recherche */
.trade-partner-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
}

.trade-partner-legend span {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    width: auto;
    font-size: inherit;
}

/* Rien à s'échanger, ou proposition déjà en attente : en retrait, en bas de la liste */
.trade-partner.idle {
    opacity: 0.55;
}

/* L'autre joueur n'a pas cette carte (choix de la carte à donner) */
.trade-missing {
    position: absolute;
    top: -0.3rem;
    left: -0.3rem;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    width: auto;
    padding: 0.1rem 0.45rem;
    border-radius: 99px;
    background: var(--ColorPrimary);
    color: var(--ColorPrimaryText, #1b1b1b);
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
}

/* Carte d'un échange et, dessous, pour qui elle est nouvelle */
.trade-mini-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.trade-new {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    width: auto;
    padding: 0.15rem 0.55rem;
    border-radius: 99px;
    background: var(--ColorPrimary);
    color: var(--ColorPrimaryText, #1b1b1b);
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}

/* Squelettes : ligne de joueur inerte, en-tête du choix des cartes */
.trade-partner.idle {
    cursor: default;
}

.trade-partner.idle:hover {
    background-color: var(--ColorContainer);
}

.trade-picker-skeleton {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0;
}

.trade-picker-skeleton .skeleton-text {
    flex: none;
    width: min(100%, 30rem);
}
