/* =====================================================================
   Skrzynki (MAI-212): karty skrzyń OneBlocka i Tycoona z renderami modeli 3D z packa
   (assets/crates/*.png: zamknięta i z uchylonym wiekiem w tym samym kadrze), zawartością
   z szansami i sklepem kluczy. Kolory skrzyni w --c1 i --c2 (jak w crates.yml), rzadkości
   w --r (te same co w grze: Rarity w shardzie crate-api).
   ===================================================================== */

.crates [hidden] { display: none !important; }

.r--zwykla { --r: #86a897; }
.r--rzadka { --r: #9cffc9; }
.r--epicka { --r: #b8f55a; }
.r--legendarna { --r: #ffc93c; }

/* Pasek nad kartami: tryb i legenda rzadkości */
.crates__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 24px;
}
.crates__bar .chips { margin: 0; }
.crates__modes .chip { display: inline-flex; align-items: center; gap: 8px; font-size: 22px; padding: 6px 14px; }
.crates__modes .chip img { width: 20px; height: 20px; }
.rarity-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 0;
  padding: 0;
  list-style: none;
  font: 400 19px/1 var(--font-pixel);
  letter-spacing: .04em;
}
.rarity-legend li { display: inline-flex; align-items: center; gap: 9px; color: var(--r); }
.rarity-legend li::before {
  content: "";
  width: 8px; height: 8px;
  background: var(--r);
  transform: rotate(45deg);
  box-shadow: 0 0 0 2px var(--shadow), 0 0 8px var(--r);
}

/* ---------- Karty skrzyń ---------- */
.crates__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 24px;
  align-items: stretch;
}
.crate {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .25s ease, filter .25s ease;
}
.crate:hover { transform: translateY(-4px); filter: drop-shadow(0 14px 22px rgba(0, 0, 0, .5)); }
/* Połysk przechodzi po kartach po kolei (jak w rangach) */
.crate::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(105deg, transparent 36%, color-mix(in srgb, var(--c1) 14%, transparent) 47%, rgba(255, 255, 255, .07) 50%, transparent 62%);
  transform: translateX(-100%);
  animation: sheen 8s ease-in-out 1.2s infinite;
  pointer-events: none;
}
.crate:nth-child(3n+2)::before { animation-delay: 1.8s; }
.crate:nth-child(3n)::before { animation-delay: 2.4s; }

/* Scena: poświata, promień z wnętrza, iskry, model unoszący się nad cieniem */
.crate__stage {
  position: relative;
  display: grid;
  place-items: center;
  height: 214px;
  cursor: pointer;
  background:
    radial-gradient(60% 70% at 50% 60%, color-mix(in srgb, var(--c1) 18%, transparent), transparent 72%),
    linear-gradient(180deg, transparent, rgba(5, 12, 8, .35));
  border-bottom: 2px solid color-mix(in srgb, var(--c1) 28%, transparent);
}
.crate__glow {
  position: absolute;
  left: 50%; top: 56%;
  width: 190px; height: 120px;
  margin: -60px 0 0 -95px;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--c1) 42%, transparent), transparent);
  filter: blur(6px);
  animation: glow 3.4s ease-in-out infinite;
}
.crate__beam {
  position: absolute;
  left: 50%; bottom: 47%;
  width: 84px; height: 0;
  margin-left: -42px;
  background: linear-gradient(0deg, color-mix(in srgb, var(--c1) 75%, #fff), transparent);
  clip-path: polygon(32% 100%, 68% 100%, 100% 0, 0 0);
  filter: blur(2px);
  opacity: 0;
  transition: height .5s cubic-bezier(.2, .8, .2, 1), opacity .3s ease;
}
.crate__art {
  position: relative;
  z-index: 1;
  width: 200px; height: 200px;
  animation: crate-float 4.4s ease-in-out infinite;
}
.crate:nth-child(3n+2) .crate__art { animation-delay: -1.5s; }
.crate:nth-child(3n) .crate__art { animation-delay: -3s; }
.crate__img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  image-rendering: auto;
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--c1) 35%, transparent));
  transition: opacity .16s ease, transform .35s cubic-bezier(.3, .7, .4, 1.6);
}
.crate__img--open { opacity: 0; transform: translateY(2px) scale(.97); }
/* Połysk tylko na pikselach skrzyni (maska = render, ustawiona w index.html) */
.crate__shine {
  position: absolute;
  inset: 0;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, .5) 47%, rgba(255, 255, 255, .12) 52%, transparent 60%) 0 0 / 300% 100% no-repeat;
  mix-blend-mode: screen;
  animation: crate-shine 6s ease-in-out infinite;
  pointer-events: none;
}
.crate:nth-child(3n+2) .crate__shine { animation-delay: 2s; }
.crate:nth-child(3n) .crate__shine { animation-delay: 4s; }
.crate__shadow {
  position: absolute;
  left: 50%; bottom: 22px;
  width: 130px; height: 18px;
  margin-left: -65px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .55), transparent);
  animation: shadow-bob 4.4s ease-in-out infinite;
}
.crate:nth-child(3n+2) .crate__shadow { animation-delay: -1.5s; }
.crate:nth-child(3n) .crate__shadow { animation-delay: -3s; }
.crate__sparks { position: absolute; left: 50%; top: 50%; width: 0; height: 0; z-index: 2; pointer-events: none; }
.crate__sparks i {
  position: absolute;
  width: 3px; height: 3px;
  background: var(--c2);
  box-shadow: 0 0 6px 2px color-mix(in srgb, var(--c1) 60%, transparent);
  opacity: 0;
  animation: spark 3s ease-in-out infinite;
}
.crate__sparks i:nth-child(1) { left: -84px; top: -40px; }
.crate__sparks i:nth-child(2) { left: 70px; top: -56px; animation-delay: .75s; }
.crate__sparks i:nth-child(3) { left: 78px; top: 26px; animation-delay: 1.5s; }
.crate__sparks i:nth-child(4) { left: -72px; top: 38px; animation-delay: 2.25s; }

/* Najechanie (na telefonie dotknięcie sceny): wieko się uchyla, z wnętrza bije światło */
.crate:hover .crate__img--open,
.crate.is-open .crate__img--open { opacity: 1; transform: translateY(-4px) scale(1.03); }
.crate:hover .crate__img:not(.crate__img--open),
.crate.is-open .crate__img:not(.crate__img--open) { opacity: 0; transform: translateY(-2px) scale(1.02); }
.crate:hover .crate__beam,
.crate.is-open .crate__beam { height: 138px; opacity: .8; }
.crate:hover .crate__shine,
.crate.is-open .crate__shine { opacity: 0; }

/* Treść karty */
.crate__body { display: flex; flex-direction: column; gap: 8px; flex: 1; padding: 16px 20px 20px; }
.crate__tier {
  color: var(--c1);
  font: 400 17px/1 var(--font-pixel);
  letter-spacing: .12em;
  text-transform: uppercase;
}
.crate__title {
  width: fit-content;
  font: 400 34px/1.05 var(--font-pixel);
  letter-spacing: .02em;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c1) 80%, #fff), var(--c2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 var(--shadow));
}
.crate__desc { color: var(--text-soft); font-size: 15px; line-height: 1.5; }
.crate__price { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.crate__price img { width: 32px; height: 32px; }
.crate__price strong {
  color: var(--gold);
  font: 400 30px/1 var(--font-pixel);
  letter-spacing: .02em;
  text-shadow: 0 2px 0 var(--shadow), 0 0 14px rgba(255, 201, 60, .25);
}
.crate__price small { color: var(--sage); font-size: 14px; }
.crate__deals { color: var(--sage); font-size: 13.5px; }

/* Premia przy każdym otwarciu i gwarancja (MAI-217): dwa paski nad listą nagród, złoty i limonkowy */
.crate__extras { display: grid; gap: 6px; margin: 4px 0 0; padding: 0; list-style: none; }
.crate__extras li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.35;
}
.crate__extras img { width: 24px; height: 24px; flex: none; }
.crate__extras b { font-weight: 600; }
.crate__bonus {
  background: linear-gradient(90deg, rgba(255, 201, 60, .16), rgba(255, 201, 60, .04));
  box-shadow: inset 0 0 0 2px rgba(255, 201, 60, .45);
}
.crate__bonus b { color: var(--gold); }
.crate__guarantee {
  background: linear-gradient(90deg, rgba(184, 245, 90, .13), rgba(184, 245, 90, .03));
  box-shadow: inset 0 0 0 2px rgba(184, 245, 90, .38);
}
.crate__guarantee b { color: var(--lime); }
/* Błysk przechodzi po pasku premii po najechaniu karty, ikona premii podskakuje */
.crate__bonus::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 240, 190, .22) 50%, transparent 65%);
  transform: translateX(-100%);
  pointer-events: none;
}
.crate:hover .crate__bonus::after { animation: sheen 1.4s ease-out; }
.crate:hover .crate__extras img { animation: hop .55s cubic-bezier(.3, .7, .4, 1.3) both; }
.crate__extras li + li img { animation-delay: .08s; }

/* Nagrody z szansami: romb i procent w kolorze rzadkości */
.loot {
  display: grid;
  gap: 5px;
  margin: 4px 0 2px;
  padding: 10px 12px;
  list-style: none;
  background: rgba(5, 12, 8, .45);
  box-shadow: inset 0 0 0 2px var(--frame);
}
.loot li { display: flex; align-items: baseline; gap: 10px; color: var(--text-soft); font-size: 14.5px; line-height: 1.35; }
.loot li::before {
  content: "";
  flex: none;
  width: 7px; height: 7px;
  background: var(--r);
  transform: translateY(-1px) rotate(45deg);
  box-shadow: 0 0 6px var(--r);
}
.loot li span { flex: 1; }
.loot li small { display: block; color: var(--sage); font-size: 12.5px; line-height: 1.3; }
.crate__note { color: var(--sage); font-size: 13px; line-height: 1.45; }
.loot li b { color: var(--r); font: 400 19px/1 var(--font-pixel); letter-spacing: .03em; }
.loot .r--legendarna span { color: #ffe8a8; }
.loot .r--epicka span { color: #e6ffc2; }
.crate__free { display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 6px; color: var(--mint); font-size: 14px; }
.crate__free img { width: 16px; height: 16px; }
.crate__pick { align-self: flex-start; }

/* Opis nagród Tycoona i sklep kluczy */
.crates__note { max-width: 860px; margin: 18px auto 0; text-align: center; }
.crates__info {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  margin-top: 24px;
  padding: 20px 22px;
}
@media (min-width: 860px) {
  .crates__info { grid-template-columns: 1fr auto; align-items: center; gap: 40px; }
}
.crates__how li { font-size: 15px; }
.crates__how b { color: var(--text); font-weight: 600; }
.crates__shop { display: grid; gap: 10px; justify-items: start; max-width: 390px; }
@media (min-width: 860px) { .crates__shop { justify-items: center; text-align: center; } }
.crates__shop .shop__sum small { color: var(--mint); font-size: 15px; letter-spacing: 0; }
.crates__shop .shop__sum.is-bump strong { display: inline-block; animation: price-bump .35s cubic-bezier(.3, .7, .4, 1.4); }

@keyframes crate-float {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-9px) rotate(1deg); }
}
/* Kafel połysku ma 300% szerokości: od 100% do 0% pas przechodzi przez skrzynię z lewej do prawej, potem przerwa */
@keyframes crate-shine {
  0% { background-position: 100% 0; }
  30%, 100% { background-position: 0% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .crate__sparks { display: none; }
}

@media (max-width: 559px) {
  .crate__stage { height: 186px; }
  .crate__art { width: 172px; height: 172px; }
  .crate__body { padding: 14px 16px 18px; }
  .crate__title { font-size: 30px; }
  .loot li { font-size: 14px; }
  .rarity-legend { font-size: 17px; gap: 6px 14px; }
}
