:root {
  --bg: #0b0e17;
  --bg2: #121726;
  --card: #171d2f;
  --card2: #1e2540;
  --line: rgba(255, 255, 255, .07);
  --text: #eef1f8;
  --muted: #8a93ab;
  --gold: #f4b942;
  --green: #3ddc97;
  --red: #ff5c77;
  --common: #8d99ae;
  --rare: #4cc9f0;
  --epic: #b66cff;
  --legendary: #ffb703;
  --mythic: #ff4d6d;
  --radius: 16px;
  --item-w: 124px;
  --item-gap: 8px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; min-height: 100dvh; overflow-x: hidden;
}
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; background: radial-gradient(700px 360px at 50% -140px, #232b52 0%, transparent 70%), var(--bg); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
.hidden { display: none !important; }
#app { max-width: 520px; margin: 0 auto; padding: 14px 14px calc(28px + env(safe-area-inset-bottom)); }
.boot { display: grid; place-items: center; height: 60vh; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--gold); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Профиль */
.profile { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 19px; background: linear-gradient(135deg, #f4b942, #ef476f); color: #1a1205; flex: none; }
.who { min-width: 0; }
.who b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { color: var(--muted); font-size: 13px; }
.balances { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.bal { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.bal small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.bal b { font-size: 20px; letter-spacing: .2px; }
.bal.rub b { color: var(--gold); }
.game-bal { color: var(--muted); font-size: 13px; margin: 0 2px 14px; }
.game-bal b { color: var(--text); font-weight: 600; }

/* Вкладки */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--bg2); padding: 4px; border-radius: 14px; margin-bottom: 14px; border: 1px solid var(--line); }
.tabs button { padding: 10px 0; border-radius: 11px; color: var(--muted); font-weight: 600; transition: background .2s, color .2s; }
.tabs button.active { background: var(--card2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.06) inset; }

/* Сетка кейсов */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.case-card { position: relative; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; display: flex; flex-direction: column; transition: transform .15s; }
.case-card:active { transform: scale(.97); }
.case-art { height: 118px; display: grid; place-items: center; position: relative; background: radial-gradient(ellipse 70% 60% at 50% 55%, color-mix(in srgb, var(--c) 42%, transparent), transparent 100%), linear-gradient(180deg, #1b2240, var(--card)); }
.case-art img { max-width: 86%; max-height: 92%; object-fit: contain; filter: drop-shadow(0 8px 14px rgba(0,0,0,.45)); }
.case-art .emoji { font-size: 54px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
.case-body { padding: 10px 12px 12px; }
.case-body b { display: block; font-size: 15px; margin-bottom: 2px; }
.case-body small { color: var(--muted); font-size: 12px; }
.price-pill { margin-top: 9px; display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px; background: color-mix(in srgb, var(--c) 22%, transparent); color: var(--c); font-weight: 700; border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); }
.soon { text-align: center; padding: 38px 18px; background: var(--card); border: 1px dashed rgba(255,255,255,.15); border-radius: 18px; color: var(--muted); }
.soon .emoji { font-size: 40px; display: block; margin-bottom: 8px; }
.soon b { color: var(--text); display: block; margin-bottom: 4px; font-size: 16px; }
.banner { background: rgba(255, 92, 119, .12); border: 1px solid rgba(255, 92, 119, .4); color: #ffb3c0; border-radius: 14px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.banner.admin { background: rgba(244, 185, 66, .1); border-color: rgba(244, 185, 66, .4); color: #ffd98a; }

/* Страница кейса */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.back { width: 38px; height: 38px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 18px; }
.topbar h1 { font-size: 19px; margin: 0; flex: 1; }
.topbar .mini { color: var(--gold); font-weight: 700; font-size: 14px; }

.roulette { position: relative; margin: 6px -14px 14px; padding: 14px 0; background: linear-gradient(180deg, #0f1424, #121830); border-block: 1px solid var(--line); overflow: hidden; }
.marker { position: absolute; left: 50%; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: var(--gold); z-index: 4; box-shadow: 0 0 14px var(--gold); }
.marker::before, .marker::after { content: ""; position: absolute; left: -6px; border: 7px solid transparent; }
.marker::before { top: 0; border-top-color: var(--gold); }
.marker::after { bottom: 0; border-bottom-color: var(--gold); }
.viewport { overflow: hidden; padding: 10px 0; margin: -10px 0; }
.reel { display: flex; gap: var(--item-gap); padding: 0 calc(50% - var(--item-w) / 2); }
.r-item { flex: none; width: var(--item-w); height: 118px; border-radius: 14px; padding: 8px 6px 7px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center; background: linear-gradient(180deg, color-mix(in srgb, var(--rc) 24%, #171d2f), #171d2f 78%); border: 1px solid color-mix(in srgb, var(--rc) 55%, transparent); border-bottom: 3px solid var(--rc); }
.r-item .pic { flex: 1; width: 100%; display: grid; place-items: center; min-height: 0; }
.r-item img { max-width: 100%; max-height: 64px; object-fit: contain; }
.r-item .nm { font-size: 11.5px; line-height: 1.15; color: #dfe4f2; height: 27px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.r-item.win { animation: winpulse 1s ease-in-out 2; }
@keyframes winpulse { 50% { transform: scale(1.05); box-shadow: 0 0 12px var(--rc); } }

.money-tile { width: 100%; height: 100%; min-height: 48px; border-radius: 10px; display: grid; place-items: center; background: rgba(61, 220, 151, .08); }
.money-tile b { color: var(--green); font-size: 20px; line-height: 1; text-align: center; }
.money-tile i { font-style: normal; font-size: 11px; color: #9be9c6; display: block; margin-top: 3px; }

.open-btn { width: 100%; padding: 15px; border-radius: 16px; font-weight: 800; font-size: 17px; color: #1a1205; background: linear-gradient(180deg, #ffd36b, #f4a62a); box-shadow: 0 6px 24px rgba(244, 166, 42, .3); transition: transform .12s, opacity .2s, filter .2s; }
.open-btn:active { transform: scale(.98); }
.open-btn:disabled { background: var(--card2); color: var(--muted); box-shadow: none; border: 1px solid var(--line); }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 8px 0 18px; }
.hint b { color: var(--text); }

h2 { font-size: 16px; margin: 22px 2px 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -14px; padding: 2px 14px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--card); border: 1px solid color-mix(in srgb, var(--rc) 50%, transparent); font-size: 12.5px; white-space: nowrap; }
.chip .th { width: 34px; height: 34px; border-radius: 50%; background: var(--bg2); display: grid; place-items: center; overflow: hidden; font-size: 15px; }
.chip .th img { width: 100%; height: 100%; object-fit: contain; }
.chip .th.mn { color: var(--green); font-weight: 800; font-size: 11px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; background: var(--card); border-radius: 12px; border-left: 3px solid var(--rc); }
.row .th { width: 66px; height: 44px; display: grid; place-items: center; flex: none; }
.row .th img { max-width: 100%; max-height: 100%; object-fit: contain; }
.row .th .mn { color: var(--green); font-weight: 800; font-size: 12px; text-align: center; line-height: 1.1; }
.row .nm { flex: 1; min-width: 0; font-size: 14px; }
.row .nm small { display: block; color: var(--muted); font-size: 11.5px; }
.row .ch { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* Инвентарь */
.inv { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--rc); border-radius: 14px; padding: 10px; margin-bottom: 10px; }
.inv-head { display: flex; gap: 12px; align-items: center; }
.inv-head .th { width: 84px; height: 54px; display: grid; place-items: center; flex: none; }
.inv-head .th img { max-width: 100%; max-height: 100%; object-fit: contain; }
.inv-head b { display: block; font-size: 15px; }
.inv-head small { color: var(--muted); font-size: 12px; }
.inv-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn { flex: 1; min-width: 120px; padding: 10px 12px; border-radius: 12px; font-weight: 700; font-size: 14px; background: var(--card2); border: 1px solid var(--line); }
.btn.primary { background: linear-gradient(180deg, #ffd36b, #f4a62a); color: #1a1205; border: 0; }
.btn.green { background: rgba(61, 220, 151, .16); color: var(--green); border: 1px solid rgba(61, 220, 151, .4); }
.btn:disabled { opacity: .5; }
.badge { display: inline-block; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--bg2); color: var(--muted); margin-top: 8px; }
.badge.wait { background: rgba(244, 185, 66, .14); color: var(--gold); }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .emoji { font-size: 44px; display: block; margin-bottom: 10px; }
.inv.done { opacity: .6; }

/* Навигация */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: 1fr 1fr; max-width: 520px; margin: 0 auto; padding: 8px 14px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); gap: 8px; }
.nav button { padding: 11px 0; border-radius: 14px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; }
.nav button span { font-size: 17px; }
.nav button.active { color: var(--text); background: var(--card2); border-color: rgba(244, 185, 66, .45); }

/* Окно результата */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: rgba(5, 7, 12, .88); animation: fade .25s ease-out; }
@keyframes fade { from { background-color: rgba(5, 7, 12, 0); } }
.win-card { width: min(100%, 380px); text-align: center; padding: 22px 18px 18px; border-radius: 24px; background: linear-gradient(180deg, color-mix(in srgb, var(--rc) 22%, #171d2f), #12172a 60%); border: 1px solid color-mix(in srgb, var(--rc) 60%, transparent); box-shadow: 0 8px 40px rgba(0, 0, 0, .5); animation: pop .35s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
.win-card .lbl { text-transform: uppercase; letter-spacing: 2px; font-size: 12px; color: var(--rc); font-weight: 700; }
.win-card .big { height: 130px; margin: 14px 0 8px; display: grid; place-items: center; }
.win-card .big img { max-width: 92%; max-height: 130px; object-fit: contain; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .5)); }
.win-card .big .money-tile b { font-size: 34px; }
.win-card h3 { margin: 0 0 4px; font-size: 20px; }
.win-card p { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; }
.win-card .actions { display: flex; flex-direction: column; gap: 8px; }
.win-card .btn { width: 100%; padding: 13px; font-size: 15px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); max-width: 88%; background: #2a3150; color: var(--text); padding: 11px 16px; border-radius: 14px; font-size: 14px; text-align: center; opacity: 0; pointer-events: none; transition: .25s; z-index: 80; border: 1px solid var(--line); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #4a1f2b; border-color: rgba(255, 92, 119, .5); }

.win-card { position: relative; }
.win-x { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, .08); color: var(--muted); font-size: 22px; line-height: 1; }
.btn.big { padding: 15px; font-size: 16px; }

.pend { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--rc); border-radius: 14px; padding: 10px; margin-bottom: 10px; }
.pend-head { display: flex; gap: 12px; align-items: center; }
.pend-head .th { width: 84px; height: 54px; display: grid; place-items: center; flex: none; }
.pend-head .th img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pend-head b { display: block; font-size: 15px; }
.pend-head small { color: var(--gold); font-size: 12px; }
.inv-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* Подложка цвета редкости за фото */
.row .th, .inv-head .th { border-radius: 10px; }
.row .th:has(img) { background: radial-gradient(ellipse 75% 70% at 50% 65%, color-mix(in srgb, var(--rc) 50%, transparent), transparent 78%), color-mix(in srgb, var(--rc) 9%, #12172a); }
.row .th img { padding: 2px; }
.chip .th:has(img) { background: radial-gradient(circle at 50% 60%, color-mix(in srgb, var(--rc) 55%, transparent), transparent 80%), var(--bg2); }
.r-item .pic:has(img) { background: radial-gradient(ellipse 80% 65% at 50% 62%, color-mix(in srgb, var(--rc) 45%, transparent), transparent 78%); border-radius: 10px; }
.win-card .big:has(img) { background: radial-gradient(ellipse 60% 55% at 50% 60%, color-mix(in srgb, var(--rc) 50%, transparent), transparent 80%); }
.pend-head .th { border-radius: 10px; background: radial-gradient(ellipse 75% 70% at 50% 65%, color-mix(in srgb, var(--rc) 50%, transparent), transparent 78%), color-mix(in srgb, var(--rc) 9%, #12172a); }

/* Картинки всегда вписываются в свою рамку (SVG без размеров иначе вылезают за неё) */
.row .th img, .pend-head .th img, .inv-head .th img { width: 100%; height: 100%; object-fit: contain; }
.r-item img { width: 100%; height: 64px; object-fit: contain; }
.win-card .big img { width: 100%; height: 130px; object-fit: contain; }
.chip .th img { width: 100%; height: 100%; object-fit: contain; }
.row .th, .pend-head .th, .inv-head .th, .chip .th { grid-template: minmax(0, 1fr) / minmax(0, 1fr); overflow: hidden; }
.win-card .big { grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
.r-item .pic { grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
