/* Exchange Center (exchange_center.html)
   - grid : la grille d'offres, les cartes à choisir dans les fenêtres
   - flex : les onglets, les filtres, l'intérieur d'une offre (donne ⇄ veut), les boutons des fenêtres */

.exchange-page {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 16px 48px;
}

.exchange-intro {
  text-align: center;
}

/* ---------- Compteur de la semaine ---------- */

.trade-status {
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
  margin: 8px 0 24px;
}

.exchange-page .trade-status p {
  margin: 0;
  padding: 8px 16px;
  background-color: #1a1d27;
  border: 1px solid #2a2e3a;
  border-radius: 999px;
}

.trade-status strong {
  color: #eab711;
}

.exchange-page .trade-lock {
  border-color: #ff6b6b;
}

/* ---------- Onglets → FLEX ---------- */

.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid #2a2e3a;
}

.tabs .tab {
  padding: 12px 20px;
  border-radius: 0;
  background: none;
  color: #9aa0ad;
  border-bottom: 3px solid transparent;
}

.tabs .tab:hover {
  background: none;
  color: #ffffff;
}

.tabs .tab.active {
  color: #eab711;
  border-bottom-color: #eab711;      /* onglet actif souligné en jaune, comme le menu */
}

/* ---------- Filtres ---------- */

.browse-filters {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

/* Menu déroulant et barre de recherche sur la même ligne */
.exchange-page .search {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.exchange-page .search select {
  padding: 8px 12px;
  border: 1px solid #2a2e3a;
  border-radius: 999px;
  background-color: #1a1d27;
  color: #e7eaf4;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.filter-row .licence-btn {
  padding: 6px 14px;
  font-size: 0.85rem;
}

.only-mine {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #e7eaf4;
  cursor: pointer;
}

.only-mine input {
  width: 18px;
  height: 18px;
  accent-color: #eab711;
}

/* ---------- Grille d'offres → GRID ---------- */

.offers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.offer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background-color: #1a1d27;
  border: 1px solid #2a2e3a;
  border-radius: 12px;
}

.exchange-page .offer-player {
  margin: 0;
  font-size: 0.85rem;
  color: #9aa0ad;
}

.offer-player strong {
  color: #e7eaf4;
}

/* Donne ⇄ veut → FLEX */
.offer-body {
  display: flex;
  align-items: flex-start;           /* "Gives" et "Wants one of" alignés en haut */
  gap: 8px;
}

.offer-body .offer-arrow {
  align-self: center;
}

.offer-give {
  flex: 0 0 88px;
  min-width: 0;                      /* sinon le texte long ("Surging Sparks · #009") élargit la colonne */
}

/* Cartes demandées plus petites : texte un peu réduit pour que les noms restent lisibles */
.offer-want-list .trade-card {
  padding: 4px;
}

.offer-want-list .trade-card .trade-card-name {
  font-size: 0.72rem;
}

.offer-want-list .trade-card .trade-card-info {
  font-size: 0.65rem;
}

.offer-want {
  flex: 1;
  min-width: 0;                      /* sans ça, un élément flex refuse de rétrécir sous la taille de son contenu */
}

/* Toujours 3 emplacements de même largeur : avec 3 cartes demandées, elles rétrécissent au lieu de déborder */
.offer-want-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.exchange-page .offer-label,
.offer-dialog .offer-label {
  margin: 0 0 6px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #9aa0ad;
}

.offer-arrow {
  font-size: 1.6rem;
  color: #eab711;
}

.offer-trade,
.offer-cancel {
  width: 100%;
  margin-top: auto;                  /* le bouton reste collé en bas de l'offre */
}

.offer-trade:disabled {
  background-color: #2a2e3a;
  color: #6b7080;
  cursor: not-allowed;
}

.offer-cancel {
  background-color: transparent;
  border: 1px solid #ff6b6b;
  color: #ff6b6b;
}

.offer-cancel:hover {
  background-color: #ff6b6b22;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.exchange-page .empty-message {
  text-align: center;
  color: #9aa0ad;
}

/* La carte (.trade-card) est dans css/cards.css, partagée avec la boutique TwinPoints */

/* ---------- Historique ---------- */

.history-list {
  max-width: 700px;
  margin: 0 auto;
  padding: 0;
  list-style: none;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid #2a2e3a;
  color: #e7eaf4;
}

.history-item time {
  flex: 0 0 100px;
  font-size: 0.85rem;
  color: #9aa0ad;
}

.exchange-page .history-item p {
  flex: 1;
  margin: 0;
}

/* ---------- Fenêtres (<dialog>) ---------- */

.trade-dialog,
.offer-dialog {
  width: min(640px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  margin: auto;                      /* centrée à l'écran (une règle globale remet les marges à 0) */
  padding: 24px;
  background-color: #1a1d27;
  border: 1px solid #2a2e3a;
  border-radius: 16px;
  color: #e7eaf4;
}

/* La fenêtre d'échange est plus large : c'est elle qui montre l'animation */
.trade-dialog {
  width: min(960px, calc(100% - 32px));
  padding: 32px;
}

.trade-dialog::backdrop,
/* Récapitulatif de la création d'offre : la fenêtre est large, les cartes demandées
   gardent la même taille que la carte donnée (88px) au lieu de s'étirer */
.offer-dialog .offer-want-list {
  grid-template-columns: repeat(3, 88px);
}

/* "The other player must give [1] of the cards you selected." → FLEX sur une ligne */
.want-number {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  color: #e7eaf4;
}

.want-number select {
  padding: 6px 12px;
  border: 1px solid #727272;
  border-radius: 8px;
  background-color: #0f1117;
  color: #ffffff;
  font-weight: bold;
}

.want-number select:disabled {
  opacity: 0.5;
}

.offer-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.75);   /* assombrit la page derrière */
}

.trade-dialog h2,
.offer-dialog h2 {
  margin-top: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

.btn-ghost {
  background-color: transparent;
  border: 1px solid #727272;
  color: #e7eaf4;
}

.btn-ghost:hover {
  background-color: #23273a;
}

.dialog-actions button:disabled {
  background-color: #2a2e3a;
  color: #6b7080;
  cursor: not-allowed;
}

/* Cartes à choisir → GRID */
.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  max-height: 340px;
  overflow-y: auto;                  /* la liste défile si le joueur a beaucoup de cartes */
  padding: 4px;
}

.choice {
  padding: 0;
  border-radius: 10px;
  background: none;
  outline: 3px solid transparent;
  outline-offset: 2px;
}

.choice:hover {
  background: none;
  outline-color: #727272;
}

.choice[aria-pressed="true"] {
  outline-color: #eab711;            /* carte sélectionnée */
}

.trade-choice {
  margin: 0 0 16px;
  border: 1px solid #2a2e3a;
  border-radius: 12px;
}

/* Étapes 1 · 2 · 3 de la création d'offre */
.steps {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  counter-reset: etape;
}

.step {
  flex: 1;
  padding-top: 8px;
  border-top: 3px solid #2a2e3a;
  font-size: 0.8rem;
  color: #9aa0ad;
  counter-increment: etape;
}

.step::before {
  content: counter(etape) ". ";
}

.step.active,
.step.done {
  border-top-color: #eab711;
  color: #eab711;
}

/* ===================== ANIMATION D'ÉCHANGE ===================== */
/* Mise en page fixe : la distance de l'échange (--d) se calcule à partir des largeurs */

.trade-anim {
  /* clamp(min, idéal, max) : la taille suit la largeur de l'écran, entre un minimum et un maximum */
  --slot: clamp(105px, 22vw, 240px); /* largeur d'une carte */
  --mid: clamp(56px, 12vw, 170px);   /* largeur des flèches */
  --gap: clamp(10px, 3vw, 40px);
  --d: calc(var(--slot) + var(--mid) + 2 * var(--gap));   /* distance d'une carte à l'autre */
  display: grid;
  grid-template-columns: var(--slot) var(--mid) var(--slot);
  column-gap: var(--gap);
  justify-content: center;
  align-items: end;
  margin: 8px 0;
}

.exchange-page .trade-slot-label,
.trade-dialog .trade-slot-label {
  margin: 0 0 8px;
  text-align: center;
  font-weight: bold;
  color: #9aa0ad;
}

.trade-slot .trade-card {
  position: relative;
  z-index: 1;
  padding: 10px;
  border-width: 3px;
  border-radius: 12px;
}

/* Textes un peu plus grands dans la fenêtre d'échange que dans la grille d'offres */
.trade-slot .trade-card .trade-card-name {
  font-size: clamp(0.8rem, 1.6vw, 1.1rem);
}

.trade-slot .trade-card .trade-card-info {
  font-size: clamp(0.7rem, 1.2vw, 0.85rem);
}

.trade-dialog .trade-slot-label {
  font-size: 1.1rem;
}

.trade-arrows {
  align-self: center;
}

.trade-arrows svg {
  display: block;
  width: 100%;
}

.trade-arrows path {
  fill: none;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.arrow-track {
  stroke: #2a2e3a;
}

.arrow-fill {
  stroke: #eab711;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;            /* la flèche n'est pas encore "dessinée" */
  opacity: 0;                        /* cache le petit point laissé par les bouts arrondis */
}

/* 1. Chargement : les flèches se dessinent en boucle (classe is-loading) */
.trade-anim.is-loading .arrow-fill {
  animation: arrow-draw 0.9s ease-in-out infinite;
}

.trade-anim.is-loading .arrow-fill-back {
  animation-delay: 0.45s;            /* la flèche du retour part un peu après */
}

@keyframes arrow-draw {
  0%   { stroke-dashoffset: 100; opacity: 1; }
  70%  { stroke-dashoffset: 0;   opacity: 1; }
  100% { stroke-dashoffset: 0;   opacity: 0; }
}

/* 2. Échange : effet holo puis les cartes changent de place (classe is-done) */
.trade-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg,
      transparent 20%,
      rgba(255, 0, 170, 0.45) 35%,
      rgba(0, 255, 255, 0.45) 45%,
      rgba(255, 255, 0, 0.45) 55%,
      transparent 70%);
  background-size: 300% 300%;
  mix-blend-mode: color-dodge;       /* reflet brillant, comme une carte holographique */
  opacity: 0;
  pointer-events: none;
}

.trade-anim.is-done .trade-card::after {
  animation: holo 1.4s ease-in-out forwards;
}

@keyframes holo {
  0%   { opacity: 0; background-position: 100% 100%; }
  25%  { opacity: 1; }
  75%  { opacity: 1; }
  100% { opacity: 0; background-position: 0% 0%; }
}

.trade-anim.is-done .arrow-fill {
  stroke-dashoffset: 0;              /* flèches pleines une fois l'échange fait */
  opacity: 1;
}

.trade-anim.is-done #trade-give .trade-card {
  animation: swap-right 0.9s ease-in-out 0.5s forwards;
}

.trade-anim.is-done #trade-get .trade-card {
  animation: swap-left 0.9s ease-in-out 0.5s forwards;
}

/* Les deux cartes se croisent : l'une passe par-dessus, l'autre par-dessous */
@keyframes swap-right {
  0%   { transform: translate(0, 0); }
  50%  { transform: translate(calc(var(--d) / 2), -40px) rotate(6deg) scale(1.05); }
  100% { transform: translate(var(--d), 0); }
}

@keyframes swap-left {
  0%   { transform: translate(0, 0); }
  50%  { transform: translate(calc(var(--d) / -2), 40px) rotate(-6deg) scale(0.95); }
  100% { transform: translate(calc(var(--d) * -1), 0); }
}

.trade-dialog .trade-done-msg {
  margin: 16px 0 0;
  text-align: center;
  font-size: 1.2rem;
  font-weight: bold;
  color: #eab711;
}

/* ---------- Mobile ---------- */

@media (max-width: 600px) {
  .offers-grid {
    grid-template-columns: 1fr;
  }

  .offer-give {
    flex-basis: 80px;
  }

  .trade-anim {
    --slot: 105px;
    --mid: 56px;
    --gap: 10px;
  }

  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Animations réduites : pas de mouvement, l'échange se voit quand même (holo seul) */
@media (prefers-reduced-motion: reduce) {
  .trade-anim.is-loading .arrow-fill,
  .trade-anim.is-done #trade-give .trade-card,
  .trade-anim.is-done #trade-get .trade-card {
    animation: none;
  }
}

/* ===== Coming soon : échanges pas encore ouverts ===== */
.exchange-page.locked {
  position: relative;
}

/* Toute la page en flou derrière la pancarte, impossible à cliquer */
.exchange-page.locked > :not(.coming-soon) {
  filter: blur(6px);
  opacity: .5;
  pointer-events: none;
  user-select: none;
}

.coming-soon {
  position: absolute;
  top: 80px;
  left: 50%;
  translate: -50% 0;
  z-index: 10;
  width: min(480px, calc(100% - 32px));
  padding: 32px 28px;
  border: 1px solid #eab711;
  border-radius: 16px;
  background-color: #151821;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  text-align: center;
}

.coming-soon-tag {
  display: inline-block;
  margin: 0 0 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background-color: #eab711;
  color: #151821;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.coming-soon h2 {
  margin: 0 0 10px;
  color: #fff;
}

.coming-soon p:not(.coming-soon-tag) {
  margin: 0 0 22px;
  color: #b9bfcc;
  line-height: 1.5;
}
