/* ================================================================
   MTGPopup — Style Grimoire unifié
   ================================================================ */

#mtg-popup-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

.mtg-pop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 4, 10, 0.82);
  backdrop-filter: blur(16px) saturate(140%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  z-index: 9999;
  padding: 1rem;
  animation: mtgPopFadeIn 0.22s cubic-bezier(.2,.85,.3,1);
}
.mtg-pop-overlay.closing {
  animation: mtgPopFadeOut 0.18s ease-in forwards;
}
@keyframes mtgPopFadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes mtgPopFadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Carte principale ── */
.mtg-pop-card {
  background:
    linear-gradient(160deg, #1c1510 0%, #090508 100%);
  border: 1.5px solid rgba(201,168,76,0.6);
  border-radius: 10px;
  width: min(860px, 96vw);
  max-height: 90vh;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  position: relative;
  overflow: hidden;
  z-index: 10000;
  box-shadow:
    0 0 0 1px rgba(240,215,122,0.12) inset,
    0 0 60px rgba(201,168,76,0.25),
    0 30px 80px rgba(0,0,0,0.9);
  animation: mtgPopScaleIn 0.28s cubic-bezier(.2,.9,.3,1.05);
  font-family: 'Raleway', sans-serif;
}
@keyframes mtgPopScaleIn {
  from { opacity: 0; transform: scale(0.93) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.mtg-pop-overlay.closing .mtg-pop-card {
  animation: mtgPopScaleOut 0.18s ease-in forwards;
}
@keyframes mtgPopScaleOut {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.96); }
}

/* Coins dorés */
.mtg-pop-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(240,215,122,0.15) 0%, transparent 30%),
    linear-gradient(315deg, rgba(240,215,122,0.08) 0%, transparent 30%);
  pointer-events: none;
  z-index: 0;
}

/* Bouton fermer */
.mtg-pop-close {
  position: absolute;
  top: 10px; right: 12px;
  width: 34px; height: 34px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(201,168,76,0.4);
  border-radius: 50%;
  color: #c9a84c;
  font-size: 1rem;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center; justify-content: center;
  transition: all 0.2s;
}
.mtg-pop-close:hover {
  background: rgba(201,168,76,0.2);
  color: #fff;
  transform: rotate(90deg);
  box-shadow: 0 0 12px rgba(201,168,76,0.4);
}

/* ── Colonne gauche ── */
.mtg-pop-left {
  background: linear-gradient(180deg, rgba(0,0,0,0.3), rgba(0,0,0,0.15));
  border-right: 1px solid rgba(201,168,76,0.2);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(201,168,76,0.2) transparent;
  position: relative;
  z-index: 1;
}

/* Image */
.mtg-pop-img-wrap {
  perspective: 1200px;
  width: 100%;
  aspect-ratio: 5 / 7;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
}
.mtg-pop-img-wrap.has-back { cursor: pointer; }
.mtg-pop-img-wrap.has-back::after {
  content: "↺";
  position: absolute;
  bottom: 8px; right: 8px;
  background: rgba(10,6,12,0.85);
  border: 1px solid rgba(201,168,76,0.5);
  border-radius: 50%;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  color: #c9a84c;
  font-size: 1rem;
  z-index: 3;
}
.mtg-pop-img-flipper {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.75s cubic-bezier(.4,.05,.3,1);
}
.mtg-pop-img-flipper.flipped { transform: rotateY(180deg); }
.mtg-pop-img-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 10px;
  overflow: hidden;
}
.mtg-pop-img-face img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.mtg-pop-img-face.back { transform: rotateY(180deg); }
.mtg-pop-no-img {
  width: 100%; height: 100%;
  background: #1a1410;
  color: #c9a84c;
  display: flex;
  align-items: center; justify-content: center;
  text-align: center;
  padding: 1rem;
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
}
.mtg-pop-flip-hint {
  font-size: 0.7rem;
  color: rgba(201,168,76,0.5);
  text-align: center;
  font-style: italic;
  margin-top: -0.5rem;
}

/* Prix */
.mtg-pop-prices {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
}
.mtg-pop-price-chip {
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(201,168,76,0.25);
  padding: 3px 9px;
  border-radius: 4px;
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}
.mtg-pop-price-chip.eur  { color: #f0d77a; }
.mtg-pop-price-chip.usd  { color: #6cd46c; }
.mtg-pop-price-chip.foil { color: #c9a4f0; }

/* Salt */
.mtg-pop-salt, .mtg-pop-edhrec {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  padding: 4px 8px;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(201,168,76,0.15);
  border-radius: 4px;
}
.mtg-pop-salt-label, .mtg-pop-edhrec-label {
  color: rgba(201,168,76,0.6);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.mtg-pop-salt-value { font-weight: 700; }
.mtg-pop-edhrec-value { color: #c9a84c; }

/* Divider */
.mtg-pop-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(201,168,76,0.3), transparent);
  margin: 0.25rem 0;
}

/* Sections contextuelles */
.mtg-pop-section { display: flex; flex-direction: column; gap: 0.4rem; }
.mtg-pop-section-title {
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  letter-spacing: 2px;
  color: rgba(201,168,76,0.6);
  text-transform: uppercase;
}

/* Quantité */
.mtg-pop-qty-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.mtg-pop-qty-btn {
  width: 28px; height: 28px;
  background: rgba(201,168,76,0.1);
  border: 1px solid rgba(201,168,76,0.35);
  border-radius: 4px;
  color: #c9a84c;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.mtg-pop-qty-btn:hover { background: rgba(201,168,76,0.25); }
.mtg-pop-qty-val {
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  color: #f0d77a;
  min-width: 24px;
  text-align: center;
}

/* Catégories */
.mtg-pop-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  min-height: 28px;
}
.mtg-pop-cat-tag {
  background: rgba(201,168,76,0.12);
  border: 1px solid rgba(201,168,76,0.35);
  color: #f0d77a;
  padding: 2px 8px;
  border-radius: 3px;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.mtg-pop-cat-rm {
  background: none;
  border: none;
  color: rgba(240,215,122,0.5);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0;
  line-height: 1;
}
.mtg-pop-cat-rm:hover { color: #ff8080; }
.mtg-pop-cat-add-row {
  display: flex;
  gap: 0.3rem;
}

/* Inputs et selects */
.mtg-pop-select, .mtg-pop-input {
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(201,168,76,0.3);
  color: #e8e0d0;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  font-family: 'Raleway', sans-serif;
  font-size: 0.8rem;
  flex: 1;
  outline: none;
}
.mtg-pop-select:focus, .mtg-pop-input:focus {
  border-color: rgba(201,168,76,0.6);
}

/* Boutons */
.mtg-pop-btn {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 4px;
  font-family: 'Cinzel', serif;
  font-size: 0.78rem;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-align: center;
}
.mtg-pop-btn-primary {
  background: linear-gradient(180deg, #c9a84c, #8a6f2c);
  color: #1a1410;
  font-weight: 600;
}
.mtg-pop-btn-primary:hover {
  background: linear-gradient(180deg, #f0d77a, #c9a84c);
  box-shadow: 0 0 14px rgba(201,168,76,0.5);
}
.mtg-pop-btn-secondary {
  background: rgba(201,168,76,0.1);
  border: 1px solid rgba(201,168,76,0.35) !important;
  color: #c9a84c;
}
.mtg-pop-btn-secondary:hover {
  background: rgba(201,168,76,0.2);
  color: #f0d77a;
}
.mtg-pop-btn-danger {
  background: rgba(220,80,80,0.1);
  border: 1px solid rgba(220,80,80,0.4) !important;
  color: #ff9090;
}
.mtg-pop-btn-danger:hover {
  background: rgba(220,80,80,0.2);
}
.mtg-pop-btn-col {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: auto;
}
.mtg-pop-btn-sm {
  background: rgba(201,168,76,0.15);
  border: 1px solid rgba(201,168,76,0.35);
  color: #c9a84c;
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
  font-family: 'Cinzel', serif;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.mtg-pop-btn-sm:hover { background: rgba(201,168,76,0.25); color: #f0d77a; }

/* Row */
.mtg-pop-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

/* Status */
.mtg-pop-status {
  font-size: 0.78rem;
  text-align: center;
  min-height: 18px;
  font-family: 'Cinzel', serif;
}

/* Actions custom */
.mtg-pop-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* ── Colonne droite ── */
.mtg-pop-right {
  padding: 1.5rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow-y: auto;
  max-height: 90vh;
  scrollbar-width: thin;
  scrollbar-color: rgba(201,168,76,0.2) transparent;
  position: relative;
  z-index: 1;
  overflow-y: auto;
}

/* Nom + mana */
.mtg-pop-name-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-right: 40px;
  border-bottom: 1px solid rgba(201,168,76,0.2);
  padding-bottom: 0.6rem;
}
.mtg-pop-name {
  font-family: 'Cinzel', serif;
  font-size: 1.35rem;
  font-weight: 600;
  color: #f0d77a;
  letter-spacing: 1px;
  margin: 0;
  text-shadow: 0 0 10px rgba(201,168,76,0.2);
}
.mtg-pop-mana { display: inline-flex; align-items: center; gap: 2px; }
.mtg-pop-mana .ms { font-size: 1.15rem; }

/* Type */
.mtg-pop-type {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  color: #c8b896;
  font-size: 1rem;
  margin: 0;
}

/* Stats */
.mtg-pop-stats-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.mtg-pop-stat {
  background: linear-gradient(180deg, rgba(201,168,76,0.15), rgba(0,0,0,0.35));
  border: 1px solid rgba(201,168,76,0.4);
  color: #f0d77a;
  padding: 3px 10px;
  border-radius: 4px;
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Oracle */
.mtg-pop-oracle {
  background: rgba(255,245,220,0.04);
  border-left: 3px solid rgba(201,168,76,0.5);
  padding: 0.75rem 0.9rem;
  border-radius: 4px;
  color: #e8e0d0;
  font-size: 0.88rem;
  line-height: 1.6;
  white-space: pre-line;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(201,168,76,0.2) transparent;
  flex-shrink: 0;
}

/* Flavor */
.mtg-pop-flavor {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  color: #b09870;
  font-size: 0.88rem;
  border-top: 1px dashed rgba(201,168,76,0.25);
  padding-top: 0.5rem;
}

/* Meta pills */
.mtg-pop-meta { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.mtg-pop-pill {
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(201,168,76,0.18);
  padding: 3px 8px;
  border-radius: 3px;
  font-family: 'Raleway', sans-serif;
  font-size: 0.75rem;
  color: #8a7a5a;
}
.mtg-pop-rarity { text-transform: capitalize; letter-spacing: 1px; }
.mtg-pop-rarity.mythic   { color: #f0884a; border-color: rgba(240,136,74,0.4); }
.mtg-pop-rarity.rare     { color: #f0d77a; border-color: rgba(240,215,122,0.4); }
.mtg-pop-rarity.uncommon { color: #c0c8d0; border-color: rgba(192,200,208,0.3); }
.mtg-pop-rarity.common   { color: #8a8a8a; }

/* Thèmes */
.mtg-pop-themes { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.mtg-pop-theme-chip {
  background: linear-gradient(180deg, rgba(123,47,190,0.2), rgba(0,0,0,0.3));
  border: 1px solid rgba(123,47,190,0.4);
  color: #c9a4f0;
  padding: 2px 8px;
  border-radius: 10px;
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Rulings */
.mtg-pop-rulings-title {
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  letter-spacing: 2px;
  color: rgba(201,168,76,0.6);
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}
.mtg-pop-rulings {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(201,168,76,0.2) transparent;
  flex-shrink: 0;
}
.mtg-pop-ruling {
  background: rgba(201,168,76,0.04);
  border-left: 2px solid rgba(201,168,76,0.35);
  padding: 0.4rem 0.6rem;
  border-radius: 0 3px 3px 0;
}
.mtg-pop-ruling-date {
  font-family: 'Cinzel', serif;
  font-size: 0.65rem;
  color: rgba(201,168,76,0.5);
  display: block;
  margin-bottom: 0.2rem;
}
.mtg-pop-ruling p {
  margin: 0;
  font-size: 0.8rem;
  color: #c8b896;
  line-height: 1.5;
}
.mtg-pop-rulings-empty {
  font-size: 0.8rem;
  color: rgba(201,168,76,0.4);
  font-style: italic;
}

/* Mobile */
@media (max-width: 700px) {
  .mtg-pop-card {
    grid-template-columns: 1fr;
    max-height: 95vh;
  }
  .mtg-pop-left {
    border-right: none;
    border-bottom: 1px solid rgba(201,168,76,0.2);
  }
  .mtg-pop-img-wrap { max-width: 200px; margin: 0 auto; }
  .mtg-pop-name { font-size: 1.1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .mtg-pop-overlay, .mtg-pop-card, .mtg-pop-img-flipper {
    animation: none !important;
    transition: none !important;
  }
}