/* ==========================================
   ГеоПро — окно сундука (chest.css)
   Подключить ПОСЛЕ style.css и web.css:
   <link rel="stylesheet" href="css/chest.css?v=14">
   ========================================== */

/* ── Оверлей: по умолчанию скрыт и не блокирует приложение ── */
#chest-modal-overlay {
  --rc: #f5c04a;
  --rc-rgb: 245, 192, 74;
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at 50% 38%, rgba(var(--rc-rgb), .16), rgba(5, 8, 14, .94) 72%);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  overflow: hidden;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .3s ease, visibility 0s linear .3s, background .6s ease;
}
#chest-modal-overlay.show { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .3s ease, background .6s ease; }
#chest-modal-overlay.dim { background: radial-gradient(circle at 50% 38%, rgba(var(--rc-rgb), .32), #02040a 78%); }

#chest-modal-overlay[data-rarity="common"]    { --rc: #9aa4b2; --rc-rgb: 154, 164, 178; }
#chest-modal-overlay[data-rarity="rare"]      { --rc: #58a6ff; --rc-rgb: 88, 166, 255; }
#chest-modal-overlay[data-rarity="epic"]      { --rc: #b080ff; --rc-rgb: 176, 128, 255; }
#chest-modal-overlay[data-rarity="legendary"] { --rc: #ffb62e; --rc-rgb: 255, 182, 46; }

/* ── Карточка ── */
#chest-modal-overlay .chest-modal-card {
  position: relative;
  width: 100%; max-width: 380px; max-height: none; overflow: visible;
  padding: 26px 22px 22px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
  background: linear-gradient(180deg, #1f2b44 0%, #151e32 100%);
  border: 1px solid rgba(var(--rc-rgb), .38);
  border-radius: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 70px rgba(var(--rc-rgb), .16);
  animation: chestCardIn .45s cubic-bezier(.2, 1.2, .4, 1) both;
}
@keyframes chestCardIn { from { opacity: 0; transform: translateY(24px) scale(.94); } to { opacity: 1; transform: none; } }

.chest-queue-label {
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: rgba(255, 255, 255, .06); border-radius: 999px; padding: 5px 14px;
}
.chest-close {
  position: absolute; top: 12px; right: 12px; width: 34px; height: 34px;
  border-radius: 50%; border: none; background: rgba(255, 255, 255, .07);
  color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
}

/* ── Сцена ── */
.chest-stage { position: relative; width: 100%; height: 232px; display: flex; align-items: center; justify-content: center; }
.chest-aura {
  position: absolute; width: 270px; height: 270px; border-radius: 50%;
  background: radial-gradient(circle, rgba(var(--rc-rgb), .34), transparent 64%);
  animation: chestAura 2.6s ease-in-out infinite;
}
@keyframes chestAura { 0%, 100% { transform: scale(.9); opacity: .65; } 50% { transform: scale(1.08); opacity: 1; } }

.chest-rays {
  position: absolute; width: 360px; height: 360px; opacity: 0; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(var(--rc-rgb), .42) 0 7deg, transparent 7deg 22deg);
  -webkit-mask: radial-gradient(circle, #000 0, transparent 66%);
  mask: radial-gradient(circle, #000 0, transparent 66%);
  animation: chestSpin 9s linear infinite; transition: opacity .5s ease;
}
.chest-stage.opened .chest-rays { opacity: 1; }
@keyframes chestSpin { to { transform: rotate(360deg); } }

.chest-beam {
  position: absolute; left: 50%; bottom: 128px; width: 130px; height: 190px; margin-left: -65px; z-index: 1;
  background: linear-gradient(to top, rgba(255, 248, 220, .95), rgba(var(--rc-rgb), .35) 55%, transparent);
  clip-path: polygon(18% 100%, 82% 100%, 100% 0, 0 0);
  transform: scaleY(0); transform-origin: bottom center; opacity: 0;
  transition: transform .5s cubic-bezier(.2, .9, .3, 1), opacity .5s ease;
}
.chest-stage.opened .chest-beam { transform: scaleY(1); opacity: .9; }

.chest-svg {
  position: relative; z-index: 2; width: 230px; height: auto; overflow: visible;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, .5));
  animation: chestFloat 3.2s ease-in-out infinite;
}
@keyframes chestFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

/* Тряска: сцена дрожит, сундук копит энергию */
.chest-stage.shaking { animation: chestShake .14s linear infinite; }
.chest-stage.shaking .chest-svg { animation: chestCharge 1s ease-in forwards; }
@keyframes chestShake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  20% { transform: translate(-4px, 1px) rotate(-2.5deg); }
  40% { transform: translate(4px, -1px) rotate(2.5deg); }
  60% { transform: translate(-3px, 0) rotate(-1.5deg); }
  80% { transform: translate(3px, 1px) rotate(1.5deg); }
}
@keyframes chestCharge {
  from { transform: scale(1); filter: drop-shadow(0 12px 16px rgba(0,0,0,.5)) brightness(1); }
  to   { transform: scale(1.1); filter: drop-shadow(0 0 26px rgba(var(--rc-rgb), .9)) brightness(1.35); }
}
.chest-stage.opened .chest-svg { animation: chestPop .5s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes chestPop { 0% { transform: scale(1.1); } 100% { transform: scale(1); } }

/* Крышка: шарнир в левом заднем углу (SVG-координаты) */
.chest-lid-svg { transform-box: view-box; transform-origin: 22px 80px; transition: transform .55s cubic-bezier(.3, 1.5, .5, 1); }
.chest-lid-svg.lid-open { transform: translate(-6px, -12px) rotate(-34deg); }
.chest-inner-glow { opacity: 0; transition: opacity .4s ease; }
.chest-inner-glow.glow-active { opacity: 1; }
.chest-body-svg { transition: filter .4s ease; }
.chest-body-svg.chest-body-lit { filter: brightness(1.25); }

/* ── Вспышка, частицы, конфетти ── */
.chest-flash {
  position: absolute; inset: -40px; border-radius: 48px; z-index: 6; pointer-events: none;
  animation: chestFlash .6s ease-out forwards;
}
@keyframes chestFlash { 0% { opacity: 1; transform: scale(.7); } 100% { opacity: 0; transform: scale(1.35); } }

.chest-particle {
  position: absolute; left: 50%; top: 40%; z-index: 3; border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 8px rgba(255, 255, 255, .7);
  animation: chestBurst 1.1s cubic-bezier(.15, .8, .3, 1) forwards;
}
@keyframes chestBurst {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty) + 50px)) scale(.15); }
}

.chest-confetti {
  position: absolute; top: -18px; width: 9px; height: 15px; border-radius: 2px; z-index: 10; pointer-events: none;
  animation: chestConfetti linear forwards;
}
@keyframes chestConfetti {
  0%   { transform: translate3d(0, 0, 0) rotate(0); opacity: 1; }
  100% { transform: translate3d(var(--dx, 0px), 112vh, 0) rotate(720deg); opacity: .85; }
}

/* ── Кнопки ── */
#chest-modal-overlay .chest-open-btn,
#chest-modal-overlay .chest-claim-btn { width: 100%; min-height: 54px; font-size: 16px; border-radius: 16px; }
#chest-modal-overlay .chest-open-btn { animation: chestBtnPulse 1.8s ease-in-out infinite; }
@keyframes chestBtnPulse {
  0%, 100% { box-shadow: 0 4px 18px rgba(76, 141, 255, .3); }
  50% { box-shadow: 0 4px 30px rgba(176, 107, 255, .65); }
}
#chest-modal-overlay .chest-claim-btn { box-shadow: 0 6px 26px rgba(var(--rc-rgb), .45); }
#chest-modal-overlay .chest-open-btn:disabled { opacity: .5; animation: none; }
.chest-all-btn {
  width: 100%; min-height: 46px; border-radius: 14px; cursor: pointer;
  background: transparent; border: 1px solid rgba(255, 255, 255, .14);
  color: var(--text); font-family: var(--fb); font-size: 14px; font-weight: 600;
}

/* ── Награда ── */
.chest-reveal-card > * { animation: chestRise .5s cubic-bezier(.2, 1.1, .4, 1) both; }
.chest-reveal-card > :nth-child(2) { animation-delay: .08s; }
.chest-reveal-card > :nth-child(3) { animation-delay: .16s; }
.chest-reveal-card > :nth-child(4) { animation-delay: .24s; }
.chest-reveal-card > :nth-child(5) { animation-delay: .32s; }
.chest-reveal-card > :nth-child(6) { animation-delay: .4s; }
@keyframes chestRise { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }

.chest-reveal-badge {
  padding: 6px 18px; border: 1px solid; border-radius: 999px;
  font-family: var(--fh); font-size: 12px; font-weight: 800; letter-spacing: .12em;
}
.chest-reveal-iconwrap { position: relative; width: 150px; height: 150px; display: flex; align-items: center; justify-content: center; }
.chest-reveal-iconwrap::before {
  content: ''; position: absolute; inset: -30px; opacity: .8;
  background: repeating-conic-gradient(from 0deg, rgba(var(--rc-rgb), .4) 0 7deg, transparent 7deg 22deg);
  -webkit-mask: radial-gradient(circle, #000 0, transparent 68%);
  mask: radial-gradient(circle, #000 0, transparent 68%);
  animation: chestSpin 10s linear infinite;
}
.chest-reveal-iconwrap::after {
  content: ''; position: absolute; inset: 14px; border-radius: 50%;
  background: radial-gradient(circle, rgba(var(--rc-rgb), .32), rgba(var(--rc-rgb), .06) 70%);
  border: 1px solid rgba(var(--rc-rgb), .4);
}
.chest-reveal-icon { position: relative; z-index: 2; font-size: 68px; line-height: 1; animation: chestIcon 2.4s ease-in-out infinite; }
@keyframes chestIcon { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-6px) scale(1.06); } }
.chest-reveal-title { font-family: var(--fh); font-size: 18px; font-weight: 700; }
.chest-reveal-amount { font-family: var(--fh); font-size: 32px; font-weight: 800; line-height: 1.15; }
.chest-reveal-howto { font-size: 13px; color: var(--muted); line-height: 1.45; max-width: 290px; }

/* ── Итоги «Открыть все» ── */
.chest-summary-title { font-family: var(--fh); font-size: 20px; font-weight: 800; }
.chest-summary-sub { font-size: 13px; color: var(--muted); margin-top: -6px; }
.chest-summary-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chest-summary-chip { padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; background: rgba(255, 255, 255, .07); }
.chest-summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; }
.chest-summary-item {
  background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 16px; padding: 12px 8px; animation: chestRise .45s both;
}
.chest-summary-item i { display: block; font-style: normal; font-size: 24px; margin-bottom: 2px; }
.chest-summary-item b { display: block; font-family: var(--fh); font-size: 20px; }
.chest-summary-item span { font-size: 11px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .chest-aura, .chest-svg, .chest-rays, .chest-reveal-icon, .chest-open-btn { animation: none !important; }
  .chest-confetti { display: none; }
}
