:root {
  --bg-0: #0a0613;
  --bg-1: #110a1f;
  --bg-2: #170d2c;
  --surface: #1a1030;
  --surface-2: #221540;
  --border: #2a1c4d;
  --primary: #8b5cf6;
  --primary-2: #a78bfa;
  --primary-3: #c4b5fd;
  --accent: #d946ef;
  --text: #ece9f5;
  --text-dim: #9d92b8;
  --text-faint: #6b5e87;
  --success: #4ade80;
  --danger: #f43f5e;
  --gold: #fbbf24;

  --rar-common: #7c8db5;
  --rar-uncommon: #5eead4;
  --rar-rare: #60a5fa;
  --rar-epic: #c084fc;
  --rar-legend: #f472b6;
  --rar-myth: #fbbf24;

  --radius: 14px;
  --radius-lg: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Display", Roboto, system-ui, sans-serif;
  background: var(--bg-0);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
.hidden { display: none !important; }

.bg-glow {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60vw 60vh at 15% -10%, rgba(139,92,246,0.20), transparent 60%),
    radial-gradient(50vw 50vh at 110% 10%, rgba(217,70,239,0.13), transparent 60%),
    radial-gradient(40vw 40vh at 50% 110%, rgba(139,92,246,0.10), transparent 60%),
    var(--bg-0);
}

.container { max-width: 1240px; margin: 0 auto; padding: 0 24px; }

/* HEADER */
.header {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(18px);
  background: rgba(10,6,19,0.7);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 70px; gap: 24px;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  box-shadow: 0 0 20px rgba(139,92,246,0.5);
  position: relative;
}
.logo-mark::after {
  content: ""; position: absolute; inset: 6px;
  background: var(--bg-0); border-radius: 4px;
}
.logo-text { font-weight: 600; letter-spacing: 0.5px; font-size: 16px; }
.logo-text b { color: var(--primary-2); font-weight: 700; }

.nav { display: flex; gap: 6px; }
.nav-link {
  padding: 8px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  color: var(--text-dim); transition: all .2s ease;
}
.nav-link:hover { color: var(--text); background: var(--surface); }
.nav-link.active {
  color: var(--text);
  background: linear-gradient(135deg, rgba(139,92,246,0.20), rgba(217,70,239,0.10));
  box-shadow: inset 0 0 0 1px var(--border);
}

.balance {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 600; font-size: 14px;
}

.live-badge {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 10px;
  background: rgba(74, 222, 128, 0.08);
  border: 1px solid rgba(74, 222, 128, 0.25);
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
  color: var(--success);
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6);
  animation: livePulse 2s ease-in-out infinite;
}
.live-dot.flash { animation: liveFlash .6s ease-out, livePulse 2s ease-in-out infinite 0.6s; }
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
}
@keyframes liveFlash {
  0%   { transform: scale(1); background: var(--success); }
  40%  { transform: scale(1.6); background: #86efac; }
  100% { transform: scale(1); background: var(--success); }
}
@media (max-width: 560px) { .live-badge { display: none; } }
.balance-icon { color: var(--primary-2); font-size: 12px; }
.balance-cur { color: var(--text-dim); font-size: 12px; font-weight: 500; }

/* MAIN */
.main { padding: 40px 24px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 28px; gap: 24px; flex-wrap: wrap; }
.page-title { font-size: 32px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.5px; }
.page-sub { color: var(--text-dim); margin: 0; font-size: 14px; }
.section-title { font-size: 16px; font-weight: 600; color: var(--text-dim); margin: 32px 0 16px; }

/* CASES GRID */
.cases-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.case-card {
  position: relative; padding: 22px 18px 20px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-1) 100%);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  cursor: pointer; transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease;
  overflow: hidden;
}
.case-card::before {
  content: ""; position: absolute; inset: -1px; border-radius: inherit;
  background: linear-gradient(180deg, transparent 50%, rgba(139,92,246,0.0) 100%);
  pointer-events: none; transition: background .3s ease;
}
.case-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: 0 20px 40px -20px rgba(139,92,246,0.5);
}
.case-card:hover::before {
  background: linear-gradient(180deg, transparent 30%, rgba(139,92,246,0.10) 100%);
}
.case-img {
  width: 100%; aspect-ratio: 1/1; display: grid; place-items: center;
  border-radius: var(--radius); position: relative; overflow: hidden;
  margin-bottom: 14px;
}
.case-emoji {
  font-size: 80px; position: relative; z-index: 1;
  filter: drop-shadow(0 8px 24px rgba(139,92,246,0.5));
  animation: floatY 4s ease-in-out infinite;
  display: inline-block;
}
.case-card:hover .case-emoji { animation-duration: 1.6s; }
@keyframes floatY {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-8px) rotate(2deg); }
}
.case-img::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(139,92,246,0.30), transparent 70%);
}
.case-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.case-price {
  display: flex; align-items: center; justify-content: space-between;
}
.case-price b { font-size: 14px; color: var(--primary-2); font-weight: 600; }
.case-price small { color: var(--text-faint); font-size: 12px; }

/* OPEN PAGE */
.back-btn {
  background: transparent; color: var(--text-dim); padding: 8px 0;
  font-size: 14px; margin-bottom: 16px; transition: color .2s;
}
.back-btn:hover { color: var(--text); }

.open-stage {
  position: relative; margin: 36px 0 28px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-1) 100%);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 30px 0; overflow: hidden;
}
.open-pointer {
  position: absolute; left: 50%; top: 14px; bottom: 14px;
  width: 2px; transform: translateX(-50%); z-index: 3;
  background: linear-gradient(180deg, var(--accent), var(--primary));
  box-shadow: 0 0 18px rgba(217,70,239,0.8);
}
.open-pointer::before, .open-pointer::after {
  content: ""; position: absolute; left: 50%; transform: translateX(-50%);
  border-left: 8px solid transparent; border-right: 8px solid transparent;
}
.open-pointer::before { top: -2px; border-top: 10px solid var(--accent); }
.open-pointer::after { bottom: -2px; border-bottom: 10px solid var(--primary); }

.roulette {
  display: flex; gap: 12px; padding: 0 12px;
  transition: transform 7.2s cubic-bezier(0.06, 0.6, 0.18, 1);
  will-change: transform;
}
.roulette-item {
  flex: 0 0 160px; height: 160px;
  border-radius: var(--radius);
  position: relative; display: grid; place-items: center;
  background: var(--bg-2);
  border: 1px solid var(--border);
}
.roulette-item .ri-emoji { font-size: 60px; }
.roulette-item .ri-name { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--text-dim); padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roulette-item.rar-common  { box-shadow: inset 0 -3px 0 var(--rar-common); }
.roulette-item.rar-uncommon{ box-shadow: inset 0 -3px 0 var(--rar-uncommon); }
.roulette-item.rar-rare    { box-shadow: inset 0 -3px 0 var(--rar-rare); }
.roulette-item.rar-epic    { box-shadow: inset 0 -3px 0 var(--rar-epic); }
.roulette-item.rar-legend  { box-shadow: inset 0 -3px 0 var(--rar-legend); }
.roulette-item.rar-myth    { box-shadow: inset 0 -3px 0 var(--rar-myth); }

.open-actions { display: flex; gap: 12px; justify-content: center; margin-bottom: 40px; }

/* BUTTONS */
.btn {
  padding: 12px 24px; border-radius: 12px; font-size: 14px; font-weight: 600;
  transition: all .2s ease; display: inline-flex; align-items: center; gap: 8px;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: white; box-shadow: 0 8px 20px -8px rgba(139,92,246,0.7);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 24px -8px rgba(139,92,246,0.9); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--primary); }

/* ITEMS GRID */
.items-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.item-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  transition: all .2s ease; cursor: pointer;
  overflow: hidden;
}
.item-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.item-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(139,92,246,0.4), 0 0 30px -8px rgba(139,92,246,0.6);
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
}
/* Lottie / emoji контейнеры подарков */
.gift-anim, .gift-emoji {
  display: block; width: 80px; height: 80px;
  margin: 4px auto 10px; pointer-events: none;
  filter: drop-shadow(0 4px 12px rgba(139,92,246,0.4));
  transition: transform .3s ease, filter .3s ease;
}
.gift-emoji { font-size: 56px; line-height: 80px; text-align: center; }
.gift-anim svg { width: 100% !important; height: 100% !important; }
.item-card:hover .gift-anim, .item-card:hover .gift-emoji {
  transform: translateY(-4px) scale(1.08);
  filter: drop-shadow(0 8px 20px rgba(139,92,246,0.7));
}
.item-card.rar-epic   .gift-anim, .item-card.rar-epic   .gift-emoji,
.item-card.rar-legend .gift-anim, .item-card.rar-legend .gift-emoji,
.item-card.rar-myth   .gift-anim, .item-card.rar-myth   .gift-emoji {
  animation: glowPulse 2.6s ease-in-out infinite;
}
.item-card.rar-myth .gift-anim, .item-card.rar-myth .gift-emoji { animation-duration: 1.8s; }

/* Roulette */
.roulette-item .ri-anim, .roulette-item .gift-emoji.ri-anim {
  width: 90px; height: 90px;
}
/* Upgrade slot */
.slot-filled .sl-anim .gift-anim,
.slot-filled .sl-anim .gift-emoji {
  width: 100px; height: 100px; margin: 0 auto;
  filter: drop-shadow(0 8px 24px rgba(139,92,246,0.5));
}
/* Contract slot */
.contract-slot .cs-anim {
  width: 50px !important; height: 50px !important;
  margin: 0; filter: none;
}
.contract-slot .gift-emoji { font-size: 36px; line-height: 50px; }
/* Drop modal */
.modal-item .mi-anim .gift-anim,
.modal-item .mi-anim .gift-emoji {
  width: 130px; height: 130px;
  filter: drop-shadow(0 8px 30px rgba(139,92,246,0.7));
}

.loading {
  grid-column: 1/-1; padding: 60px 0; text-align: center;
  color: var(--text-dim); font-size: 14px;
}

.item-card .ic-emoji {
  font-size: 56px; display: block; text-align: center; margin: 4px 0 10px;
  filter: drop-shadow(0 4px 12px rgba(139,92,246,0.4));
  transition: transform .3s ease, filter .3s ease;
}
.item-card:hover .ic-emoji {
  transform: translateY(-4px) scale(1.08);
  filter: drop-shadow(0 8px 20px rgba(139,92,246,0.7));
}
.item-card.rar-epic   .ic-emoji,
.item-card.rar-legend .ic-emoji,
.item-card.rar-myth   .ic-emoji {
  animation: glowPulse 2.6s ease-in-out infinite;
}
.item-card.rar-myth .ic-emoji { animation-duration: 1.8s; }
@keyframes glowPulse {
  0%, 100% { filter: drop-shadow(0 4px 12px rgba(139,92,246,0.4)); }
  50%      { filter: drop-shadow(0 6px 22px rgba(217,70,239,0.85)); }
}

/* Искры на легендарных и мифических предметах */
.item-card.rar-legend::before,
.item-card.rar-myth::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(244,114,182,0.6) 0, transparent 1.5px),
    radial-gradient(circle at 80% 25%, rgba(251,191,36,0.6) 0, transparent 1.5px),
    radial-gradient(circle at 75% 75%, rgba(192,132,252,0.5) 0, transparent 1.5px),
    radial-gradient(circle at 25% 80%, rgba(251,191,36,0.5) 0, transparent 1.5px);
  background-size: 100% 100%;
  animation: sparkle 3s ease-in-out infinite;
  opacity: 0.8;
}
.item-card.rar-myth::before { animation-duration: 2s; opacity: 1; }
@keyframes sparkle {
  0%, 100% { opacity: 0.3; transform: scale(0.95); }
  50%      { opacity: 1; transform: scale(1.05); }
}
.item-card .ic-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-card .ic-price { font-size: 13px; color: var(--primary-2); font-weight: 600; }
.item-card .ic-rar {
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.item-card.rar-common  .ic-rar { background: var(--rar-common); }
.item-card.rar-uncommon .ic-rar{ background: var(--rar-uncommon); }
.item-card.rar-rare    .ic-rar { background: var(--rar-rare); }
.item-card.rar-epic    .ic-rar { background: var(--rar-epic); }
.item-card.rar-legend  .ic-rar { background: var(--rar-legend); }
.item-card.rar-myth    .ic-rar { background: var(--rar-myth); }
.item-card .ic-count {
  position: absolute; top: 8px; right: 8px;
  background: rgba(139,92,246,0.2); color: var(--primary-2);
  padding: 2px 8px; border-radius: 8px; font-size: 11px; font-weight: 600;
}
.item-card .ic-chance {
  font-size: 11px; color: var(--text-faint); margin-top: 4px;
}

/* UPGRADE */
.upgrade-stage {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 24px; align-items: center;
  margin: 32px 0;
}
.upgrade-card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-1) 100%);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 24px; min-height: 240px;
  display: flex; flex-direction: column;
}
.upgrade-label { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; font-weight: 500; }
.upgrade-slot { flex: 1; display: grid; place-items: center; }
.slot-empty { color: var(--text-faint); font-size: 14px; text-align: center; }
.slot-filled { text-align: center; }
.slot-filled .sl-emoji { font-size: 90px; filter: drop-shadow(0 8px 24px rgba(139,92,246,0.5)); }
.slot-filled .sl-name { font-weight: 600; margin-top: 10px; }
.slot-filled .sl-price { color: var(--primary-2); font-weight: 600; margin-top: 4px; }

.upgrade-wheel-wrap {
  position: relative; width: 240px; height: 240px;
}
.upgrade-wheel { width: 100%; height: 100%; transform: rotate(0deg); transition: none; }
.wheel-bg { fill: none; stroke: var(--surface); stroke-width: 16; }
.wheel-arc {
  fill: none; stroke: url(#wheel-grad); stroke-width: 16; stroke-linecap: round;
  transition: stroke-dasharray .4s ease;
  stroke: var(--primary);
  filter: drop-shadow(0 0 6px rgba(139,92,246,0.6));
}
.wheel-inner { fill: var(--bg-1); }
.upgrade-wheel-text {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  pointer-events: none;
}
.wheel-pct { font-size: 36px; font-weight: 700; }
.wheel-mult { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.wheel-needle {
  position: absolute; left: 50%; top: 4px; width: 4px; height: 22px;
  background: linear-gradient(180deg, var(--accent), var(--primary));
  border-radius: 2px; transform-origin: 50% 116px;
  transform: translateX(-50%) rotate(0deg);
  box-shadow: 0 0 10px rgba(217,70,239,0.7);
  z-index: 5;
}
.wheel-needle.spin {
  transition: transform 4s cubic-bezier(0.18, 0.6, 0.16, 1);
}

.upgrade-actions { text-align: center; margin-bottom: 32px; }
.upgrade-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }

/* CONTRACT */
.contract-stage {
  display: grid; grid-template-columns: 1fr 280px; gap: 24px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-1) 100%);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 24px; margin-bottom: 32px;
}
.contract-slots {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
}
.contract-slot {
  aspect-ratio: 1/1; border-radius: var(--radius);
  border: 1.5px dashed var(--border); background: rgba(255,255,255,0.02);
  display: grid; place-items: center; transition: all .2s;
  position: relative; cursor: pointer; overflow: hidden;
}
.contract-slot.filled {
  border-style: solid; border-color: var(--primary);
  background: var(--surface-2);
}
.contract-slot .cs-emoji { font-size: 40px; }
.contract-slot .cs-price { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--primary-2); font-weight: 600; }
.contract-slot.empty-text { color: var(--text-faint); font-size: 22px; font-weight: 300; }

.contract-info {
  display: flex; flex-direction: column; gap: 14px;
  padding: 20px; background: var(--bg-2); border-radius: var(--radius);
}
.info-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--text-dim); }
.info-row b { color: var(--text); }

/* INVENTORY */
.inv-stats { display: flex; gap: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 18px; display: flex; flex-direction: column; gap: 2px;
}
.stat span { color: var(--text-dim); font-size: 12px; }
.stat b { font-size: 18px; font-weight: 700; color: var(--primary-2); }

/* MODAL */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10,6,19,0.85); backdrop-filter: blur(8px);
  display: grid; place-items: center; padding: 24px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-1) 100%);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 36px; min-width: 340px; text-align: center;
  position: relative; overflow: hidden;
  animation: pop .4s cubic-bezier(0.18, 0.9, 0.34, 1.2);
}
@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-card::before {
  content: ""; position: absolute; top: -60%; left: -50%; right: -50%; height: 200%;
  background: conic-gradient(from 0deg, transparent, rgba(139,92,246,0.3), transparent 30%);
  animation: spin 4s linear infinite; pointer-events: none;
}
.modal-card > * { position: relative; z-index: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-title { font-size: 18px; font-weight: 600; color: var(--text-dim); margin-bottom: 20px; }
.modal-item .mi-emoji { font-size: 100px; filter: drop-shadow(0 8px 30px rgba(139,92,246,0.7)); }
.modal-item .mi-name { font-size: 22px; font-weight: 700; margin: 14px 0 6px; }
.modal-item .mi-price { color: var(--primary-2); font-weight: 600; font-size: 16px; }
.modal-actions { margin-top: 26px; }

/* TOAST */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 20px; font-size: 14px; z-index: 200;
  transition: transform .3s ease; pointer-events: none;
  box-shadow: 0 12px 30px -8px rgba(0,0,0,0.5);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* RESPONSIVE */
@media (max-width: 900px) {
  .upgrade-stage { grid-template-columns: 1fr; gap: 16px; }
  .upgrade-wheel-wrap { margin: 0 auto; }
  .upgrade-columns { grid-template-columns: 1fr; }
  .contract-stage { grid-template-columns: 1fr; }
  .contract-slots { grid-template-columns: repeat(5, 1fr); }
  .nav { display: none; }
  .page-title { font-size: 24px; }
}
@media (max-width: 560px) {
  .contract-slots { grid-template-columns: repeat(5, 1fr); }
  .contract-slot .cs-emoji { font-size: 28px; }
  .header-inner { gap: 8px; }
  .balance { padding: 7px 10px; font-size: 13px; }
}
