/* modal.css — МОДАЛКА ГОЛУБЯ (4.0.7, вариант «Витрина»)
   Разметку создаёт inventory.js (initializeModal), классы .pm-*.
   Сверху «сцена» в цвете редкости с живым голубем (дышит, моргает),
   ниже: имя, 3 плитки с цифрами, прогресс слияния, кнопки.
   Анимации идут только пока модалка открыта (.is-open).
*/

/* ===== Overlay ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay-bg);
  z-index: var(--z-modal-overlay, 20000);

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0s linear 0.22s;

  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);

  touch-action: none;
  overscroll-behavior: none;
}

.modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.22s ease;
}

/* ===== Контейнер ===== */
.pigeon-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--z-modal, 20001);

  width: min(350px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);

  opacity: 0;
  visibility: hidden;
  pointer-events: none;

  /* цвета по умолчанию, если редкость неизвестна */
  --pm-accent: var(--rarity-color, #b0b0c3);
  --pm-stage: var(--rarity-bg, linear-gradient(180deg, #3a3b55, #2b2c45));
  --pm-border: var(--rarity-border, rgba(255,255,255,.18));
  --pm-glow: var(--rarity-glow-1, rgba(255,255,255,.12));
}

.pigeon-modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  animation: pmPop 0.24s cubic-bezier(0.25, 1, 0.35, 1) both;
}

@keyframes pmPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) translateY(14px); }
  100% { opacity: 1; transform: translate(-50%, -50%) translateY(0); }
}

.pm-card {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 32px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;

  border-radius: 28px;
  background: var(--bg-card, #23243a);
  border: 2px solid var(--pm-border);
  box-shadow:
    0 24px 60px rgba(0,0,0,.55),
    0 0 36px var(--pm-glow);
  text-align: left;
}

/* ===== Сцена ===== */
.pm-stage {
  position: relative;
  flex: 0 0 auto;
  height: clamp(190px, 36dvh, 300px);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 60%, rgba(255,255,255,.38) 0%, rgba(255,255,255,0) 55%),
    linear-gradient(to bottom, rgba(0,0,0,0) 55%, rgba(0,0,0,.28)),
    var(--pm-stage);
}

.pm-glow {
  position: absolute;
  left: 50%;
  top: 54%;
  width: 78%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,245,210,.6) 0%, rgba(255,245,210,0) 68%);
  pointer-events: none;
}

.pm-shadow {
  position: absolute;
  left: 50%;
  bottom: 7%;
  width: 38%;
  height: 16px;
  margin-left: -19%;
  border-radius: 50%;
  background: rgba(0,0,0,.32);
  pointer-events: none;
}

.pm-pigeon {
  position: absolute;
  left: 50%;
  bottom: 8%;
  height: 76%;
  aspect-ratio: 1;
  transform: translateX(-50%);
}

/* дыхание: отдельный слой, чтобы не спорить с translateX выше */
.pm-breathe {
  position: absolute;
  inset: 0;
  transform-origin: 50% 95%;
}

.pm-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,.25));
  -webkit-user-drag: none;
  user-select: none;
}

/* веко: координаты глаза задаёт inventory.js (у каждого голубя свои) */
.pm-lid {
  position: absolute;
  border-radius: 50%;
  transform: scaleY(0);
  transform-origin: 50% 0;
  pointer-events: none;
}

.pm-rarity {
  position: absolute;
  left: 14px;
  top: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,.38);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .2px;
  line-height: 1.1;
}

.pm-top-right {
  position: absolute;
  right: 12px;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pm-tier {
  height: 32px;
  min-width: 32px;
  padding: 0 10px;
  box-sizing: border-box;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fff1c2, #ffb347);
  color: #3a1d00;
  font-size: 15px;
  font-weight: 900;
  box-shadow: 0 2px 8px rgba(80,40,0,.45);
}

.pm-close {
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.4);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Тело ===== */
.pm-body {
  padding: 16px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pm-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.pm-name {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  line-height: 1.15;
  color: var(--text-primary, #fff);
}

.pm-sub {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary, #b0b0c3);
}

.pm-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.pm-stat {
  padding: 10px 4px;
  border-radius: 14px;
  background: rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.pm-stat-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary, #b0b0c3);
}

.pm-stat-value {
  font-size: 15px;
  font-weight: 900;
  color: #fff;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Слияние ===== */
.pm-merge {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(165,105,189,.14);
  border: 1px solid rgba(165,105,189,.35);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pm-merge-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
  color: #e6d2f0;
}

.pm-merge-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.1);
  overflow: hidden;
}

.pm-merge-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #a569bd, #d59bf0);
  transition: width .3s ease;
}

.pm-merge.is-ready .pm-merge-fill { background: linear-gradient(90deg, #22a95a, #4ade80); }

.pm-merge-hint {
  font-size: 12px;
  font-weight: 600;
  color: #b9a8c4;
}

.pm-merge-btn {
  height: 44px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #8e44ad, #b565d9);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pm-merge-btn:active:not(:disabled) { transform: scale(.98); }
.pm-merge-btn:disabled { opacity: .55; cursor: default; }

/* ===== «Есть у тебя» (режим коллекции) ===== */
.pm-owned {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,.05);
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
}

/* ===== Кнопки ===== */
.pm-actions {
  display: flex;
  gap: 8px;
}

.pm-sell {
  flex: 1 1 auto;
  min-width: 0;
  height: 52px;
  border: none;
  border-radius: 16px;
  background: #22a95a;
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 12px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pm-sell:active:not(:disabled) { transform: scale(.98); }
.pm-sell:disabled {
  background: rgba(255,255,255,.08);
  color: var(--text-secondary, #b0b0c3);
  cursor: default;
}

.pm-fav {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color: #ffd35a;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pm-fav svg { fill: none; }
.pm-fav.is-on { background: rgba(255,211,90,.16); border-color: rgba(255,211,90,.5); }
.pm-fav.is-on svg { fill: currentColor; }

/* ===== Анимации (только открытая модалка) ===== */
.pigeon-modal.is-open .pm-breathe { animation: pmIdle 2.4s ease-in-out infinite; }
.pigeon-modal.is-open .pm-shadow  { animation: pmShadow 2.4s ease-in-out infinite; }
.pigeon-modal.is-open .pm-glow    { animation: pmPulse 3s ease-in-out infinite; }
.pigeon-modal.is-open .pm-lid     { animation: pmLid 3.6s infinite; }
.pigeon-modal.is-open .pm-merge.is-ready .pm-merge-btn { animation: pmReady 1.8s ease-in-out infinite; }

@keyframes pmIdle   { 0%,100% { transform: scale(1,1); } 50% { transform: scale(1.035,.965); } }
@keyframes pmShadow { 0%,100% { transform: scaleX(1); } 50% { transform: scaleX(1.07); } }
@keyframes pmPulse  { 0%,100% { opacity: .75; } 50% { opacity: 1; } }
@keyframes pmLid    { 0%,91%,100% { transform: scaleY(0); } 94% { transform: scaleY(1); } 97% { transform: scaleY(0); } }
@keyframes pmReady  { 0%,100% { box-shadow: 0 0 0 0 rgba(181,101,217,.6); } 50% { box-shadow: 0 0 0 6px rgba(181,101,217,0); } }

@media (hover: hover) and (pointer: fine) {
  .pm-close:hover { background: rgba(0,0,0,.55); }
  .pm-sell:hover:not(:disabled) { filter: brightness(1.08); }
  .pm-fav:hover { background: rgba(255,255,255,.1); }
  .pm-merge-btn:hover:not(:disabled) { filter: brightness(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  .pigeon-modal.is-open,
  .pigeon-modal.is-open * { animation: none !important; }
}

/* низкие экраны: плитки и отступы компактнее */
@media (max-height: 640px) {
  .pm-body { padding: 12px 14px 14px; gap: 10px; }
  .pm-name { font-size: 20px; }
  .pm-stat { padding: 8px 4px; }
  .pm-sell, .pm-fav { height: 46px; }
  .pm-fav { flex-basis: 46px; width: 46px; }
}

/* ===== Кнопка витрины в модалке (4.1) ===== */
.pm-showcase{
  height:46px;
  border-radius:14px;
  border:1px solid rgba(74,222,128,.45);
  background:rgba(74,222,128,.12);
  color:#8ff0b4;
  font-family:inherit;
  font-size:15px;
  font-weight:900;
  cursor:pointer;
  touch-action:manipulation;
  -webkit-tap-highlight-color:transparent;
}
.pm-showcase[hidden]{ display:none; }
.pm-showcase.is-on{
  border-color:rgba(255,255,255,.16);
  background:rgba(255,255,255,.06);
  color:#d7d9ea;
}
.pm-showcase:disabled{ opacity:.55; cursor:default; }
.pm-showcase:active:not(:disabled){ transform:scale(.98); }

/* ===== Кража с чужой витрины (4.1.1) ===== */
/* модалка открывается поверх профиля игрока — он сам на z-index ~2147483000 */
.modal-overlay.is-over{ z-index: 2147483100; }
.pigeon-modal.is-over { z-index: 2147483101; }

.pm-steal{
  height:52px;
  border-radius:14px;
  border:none;
  background:linear-gradient(180deg, #ff5a5a, #d42a2a);
  box-shadow:0 4px 0 #8f1717, 0 8px 18px rgba(212,42,42,.35);
  color:#fff;
  font-family:inherit;
  font-size:17px;
  font-weight:900;
  letter-spacing:.3px;
  cursor:pointer;
  touch-action:manipulation;
  -webkit-tap-highlight-color:transparent;
}
.pm-steal[hidden]{ display:none; }
.pm-steal:active:not(:disabled){ transform:translateY(2px); box-shadow:0 2px 0 #8f1717, 0 4px 10px rgba(212,42,42,.3); }
.pm-steal:disabled{ opacity:.7; cursor:default; }
.pm-steal.is-protected{
  background:rgba(63,209,192,.16);
  border:1px solid rgba(63,209,192,.5);
  box-shadow:none;
  color:#bff5ee;
  font-size:15px;
  opacity:1;
}
