Загрузка данных


<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>MusorCase v9.0 — лучший скам 2026</title>
<style>
*{margin:0;padding:0;box-sizing:border-box;font-family:Arial,sans-serif}
body{background:linear-gradient(135deg,#1a1a2e,#16213e);color:#fff;min-height:100vh;padding:20px}
.container{max-width:1200px;margin:0 auto}
header{display:flex;justify-content:space-between;align-items:center;background:rgba(0,0,0,.4);padding:15px 25px;border-radius:12px;margin-bottom:10px;border:1px solid #2a3a5e;flex-wrap:wrap;gap:10px}
h1{font-size:26px;color:#ffd700;text-shadow:0 0 10px rgba(255,215,0,.5)}
h1 .sub{font-size:12px;color:#aaa;display:block;font-weight:normal;font-style:italic}
.balance{background:linear-gradient(135deg,#2d5016,#1a3a0a);padding:10px 20px;border-radius:8px;font-size:20px;font-weight:bold;border:1px solid #4a8020}
.balance span{color:#7fff00}
.topup-btn{background:linear-gradient(135deg,#10b981,#059669);color:#fff;border:none;padding:10px 18px;border-radius:8px;font-weight:bold;cursor:pointer}
.sound-btn{background:linear-gradient(135deg,#6b7280,#374151);color:#fff;border:none;padding:10px 14px;border-radius:8px;cursor:pointer;font-size:16px}
.sound-btn.on{background:linear-gradient(135deg,#10b981,#059669)}
.meme-ticker{background:linear-gradient(90deg,#7c3aed,#ec4899,#f59e0b);padding:8px 0;margin-bottom:15px;border-radius:8px;overflow:hidden;white-space:nowrap;font-weight:bold;font-size:14px}
.meme-ticker-inner{display:inline-block;animation:ticker 40s linear infinite;padding-left:100%}
@keyframes ticker{0%{transform:translateX(0)}100%{transform:translateX(-100%)}}
.tabs{display:flex;gap:8px;margin-bottom:20px;flex-wrap:wrap;background:rgba(0,0,0,.4);padding:10px;border-radius:12px;border:1px solid #2a3a5e}
.tab{flex:1;min-width:100px;padding:12px 10px;background:rgba(255,255,255,.05);border:2px solid transparent;border-radius:8px;color:#fff;font-size:13px;font-weight:bold;cursor:pointer;text-align:center}
.tab.active{background:linear-gradient(135deg,rgba(255,215,0,.2),rgba(255,140,0,.2));border-color:#ffd700;color:#ffd700}
.section{display:none}.section.active{display:block}
.panel{background:rgba(0,0,0,.4);padding:25px;border-radius:12px;margin-bottom:20px;border:1px solid #2a3a5e}
h2.title{color:#ffd700;margin-bottom:15px;text-align:center}
.cases-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:15px}
.case-card{background:rgba(255,255,255,.05);border:2px solid;border-radius:12px;padding:15px;text-align:center;cursor:pointer;transition:.2s}
.case-card:hover{transform:translateY(-5px)}
.case-card.selected{box-shadow:0 0 20px currentColor;transform:scale(1.03)}
.case-card img{width:80px;height:80px;object-fit:contain}
.case-card .name{font-weight:bold;font-size:15px;margin:10px 0 5px}
.case-card .price{color:#7fff00;font-weight:bold;font-size:18px}
.case-card .chance{font-size:11px;color:#ffd700;margin-top:5px}
.case-basic{border-color:#718096;color:#a0aec0}
.case-standard{border-color:#3b82f6;color:#60a5fa}
.case-premium{border-color:#8b5cf6;color:#a78bfa}
.case-legendary{border-color:#ef4444;color:#f87171}
.case-elite{border-color:#fbbf24;color:#fcd34d}
.case-gloves{border-color:#14b8a6;color:#5eead4;background:linear-gradient(135deg,rgba(20,184,166,.15),rgba(15,118,110,.15))}
.case-knife{border-color:#f59e0b;color:#fcd34d;background:linear-gradient(135deg,rgba(245,158,11,.15),rgba(180,83,9,.15))}
.speed-switcher{display:flex;justify-content:center;gap:8px;margin:15px 0;flex-wrap:wrap}
.speed-btn{background:rgba(255,255,255,.05);border:2px solid #2a3a5e;color:#fff;padding:8px 18px;border-radius:8px;cursor:pointer;font-weight:bold}
.speed-btn.active{background:linear-gradient(135deg,#ffd700,#ff8c00);color:#000;border-color:#ffd700}
.open-controls{display:flex;justify-content:center;gap:10px;flex-wrap:wrap}
.open-btn{background:linear-gradient(135deg,#ffd700,#ff8c00);color:#000;border:none;padding:14px 30px;font-size:16px;font-weight:bold;border-radius:8px;cursor:pointer;min-width:110px}
.open-btn:disabled{opacity:.5;cursor:not-allowed}
.open-btn.x5{background:linear-gradient(135deg,#8b5cf6,#5b21b6);color:#fff}
.open-btn.x10{background:linear-gradient(135deg,#ef4444,#991b1b);color:#fff}
.open-btn .sub{display:block;font-size:11px;opacity:.8;margin-top:2px}
.roulette-container{position:relative;width:100%;height:150px;overflow:hidden;background:rgba(0,0,0,.5);border-radius:10px;margin:20px 0;border:2px solid #2a3a5e;display:none}
.roulette-pointer{position:absolute;top:0;left:50%;transform:translateX(-50%);width:4px;height:100%;background:#ff0000;z-index:10;box-shadow:0 0 10px #ff0000}
.roulette-track{display:flex;position:absolute;top:10px;left:0}
.roulette-item{width:130px;height:130px;margin:0 5px;border-radius:8px;display:flex;flex-direction:column;align-items:center;justify-content:center;flex-shrink:0;border:2px solid}
.roulette-item img{width:70px;height:70px;object-fit:contain}
.roulette-item .iname{font-size:11px;margin-top:5px;text-align:center;padding:0 5px}
.rarity-common{background:linear-gradient(135deg,#4a5568,#2d3748);border-color:#718096}
.rarity-rare{background:linear-gradient(135deg,#2563eb,#1e40af);border-color:#3b82f6}
.rarity-epic{background:linear-gradient(135deg,#7c3aed,#5b21b6);border-color:#8b5cf6}
.rarity-legendary{background:linear-gradient(135deg,#dc2626,#991b1b);border-color:#ef4444}
.rarity-knife{background:linear-gradient(135deg,#fbbf24,#b45309);border-color:#fcd34d;box-shadow:0 0 20px rgba(251,191,36,.6)}
.rarity-gloves{background:linear-gradient(135deg,#14b8a6,#0f766e);border-color:#5eead4;box-shadow:0 0 20px rgba(20,184,166,.6)}
.multi-results{display:none}
.multi-stats{display:flex;justify-content:space-around;margin-bottom:20px;flex-wrap:wrap;gap:10px}
.stat-box{background:rgba(255,255,255,.05);padding:12px 20px;border-radius:8px;text-align:center;min-width:140px}
.stat-box .label{font-size:12px;color:#aaa;margin-bottom:4px}
.stat-box .value{font-size:20px;font-weight:bold}
.stat-box .profit{color:#7fff00}.stat-box .loss{color:#ef4444}
.multi-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:12px}
.multi-item{background:rgba(255,255,255,.05);padding:12px;border-radius:8px;text-align:center;border:2px solid;opacity:0;transform:scale(.5);animation:popIn .4s forwards}
.multi-item img{width:70px;height:70px;object-fit:contain}
.multi-item .name{font-size:11px;margin:5px 0;font-weight:bold}
.multi-item .price{color:#7fff00;font-size:13px;font-weight:bold}
@keyframes popIn{to{opacity:1;transform:scale(1)}}
.inv-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:15px;flex-wrap:wrap;gap:10px}
.sell-all-btn{background:linear-gradient(135deg,#ef4444,#991b1b);color:#fff;border:none;padding:8px 16px;border-radius:6px;cursor:pointer;font-weight:bold}
.inventory-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:12px}
.inv-item{background:rgba(255,255,255,.05);padding:12px;border-radius:8px;text-align:center;border:2px solid;cursor:pointer;transition:.2s}
.inv-item:hover{transform:translateY(-3px)}
.inv-item img{width:70px;height:70px;object-fit:contain}
.inv-item .name{font-size:12px;margin:5px 0;font-weight:bold}
.inv-item .price{color:#7fff00;font-size:13px;font-weight:bold}
.empty{text-align:center;color:#888;padding:30px;font-style:italic;grid-column:1/-1}
.wheel-wrapper{display:flex;flex-direction:column;align-items:center;gap:20px}
.wheel-info{display:flex;gap:20px;flex-wrap:wrap;justify-content:center;margin-bottom:10px}
.wheel-info-box{background:rgba(255,255,255,.05);padding:10px 20px;border-radius:8px;text-align:center;border:1px solid;display:flex;align-items:center;gap:10px}
.wheel-info-box img{width:50px;height:50px;object-fit:contain}
.wheel-info-box.win{border-color:#ffd700;color:#ffd700}
.wheel-info-box.lose{border-color:#718096;color:#a0aec0}
.wheel-info-box .big{font-size:20px;font-weight:bold}
.wheel-container{position:relative;width:350px;height:350px;max-width:90vw;max-height:90vw}
.wheel-pointer{position:absolute;top:-15px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:18px solid transparent;border-right:18px solid transparent;border-top:30px solid #ff0000;z-index:10}
#wheelCanvas{width:100%;height:100%;border-radius:50%;transition:transform 5s cubic-bezier(.17,.67,.21,.99)}
.wheel-center{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:60px;height:60px;background:radial-gradient(circle,#ffd700,#b8860b);border-radius:50%;border:4px solid #fff;display:flex;align-items:center;justify-content:center;z-index:5}
.wheel-center img{width:35px;height:35px}
.wheel-btn{background:linear-gradient(135deg,#ffd700,#ff8c00);color:#000;border:none;padding:16px 50px;font-size:20px;font-weight:bold;border-radius:10px;cursor:pointer}
.wheel-btn:disabled{opacity:.5;cursor:not-allowed}
.wheel-result{font-size:24px;font-weight:bold;min-height:40px;text-align:center;margin-top:10px}
.wheel-result.win{color:#ffd700}
.wheel-result.lose{color:#a0aec0}
.upgrade-layout{display:grid;grid-template-columns:1fr auto 1fr;gap:20px;align-items:start}
@media(max-width:800px){.upgrade-layout{grid-template-columns:1fr}}
.upgrade-panel{background:rgba(255,255,255,.03);border:1px solid #2a3a5e;border-radius:10px;padding:15px}
.upgrade-panel h3{color:#ffd700;margin-bottom:10px;text-align:center}
.upgrade-panel .hint{color:#aaa;font-size:12px;text-align:center;margin-bottom:10px;font-style:italic}
.upgrade-items{display:grid;grid-template-columns:repeat(auto-fill,minmax(110px,1fr));gap:8px;max-height:400px;overflow-y:auto;padding:5px}
.upgrade-item{background:rgba(255,255,255,.05);padding:8px;border-radius:6px;text-align:center;border:2px solid;cursor:pointer;transition:.2s;font-size:11px}
.upgrade-item:hover{transform:translateY(-2px)}
.upgrade-item.selected{box-shadow:0 0 15px currentColor;transform:scale(1.05);background:rgba(255,215,0,.1)}
.upgrade-item img{width:55px;height:55px;object-fit:contain}
.upgrade-item .name{margin:3px 0;font-weight:bold;font-size:10px}
.upgrade-item .price{color:#7fff00;font-weight:bold}
.upgrade-center{display:flex;flex-direction:column;align-items:center;gap:15px;padding:15px}
.upgrade-circle{position:relative;width:220px;height:220px}
#upgradeCanvas{width:100%;height:100%;border-radius:50%;transition:transform 4s cubic-bezier(.17,.67,.21,.99)}
.upgrade-pointer{position:absolute;top:-8px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:12px solid transparent;border-right:12px solid transparent;border-top:20px solid #fff;z-index:10}
.upgrade-percent{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font-size:32px;font-weight:bold;color:#fff;text-shadow:0 0 10px rgba(0,0,0,.8);z-index:5}
.upgrade-btn{background:linear-gradient(135deg,#10b981,#059669);color:#fff;border:none;padding:14px 40px;font-size:18px;font-weight:bold;border-radius:10px;cursor:pointer;width:100%;max-width:250px}
.upgrade-btn:disabled{opacity:.5;cursor:not-allowed;background:#4b5563}
.upgrade-result{font-size:18px;font-weight:bold;min-height:30px;text-align:center}
.upgrade-result.win{color:#7fff00}
.upgrade-result.lose{color:#ef4444}

/* ПРОФИЛЬ */
.profile-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:15px}
.profile-box{background:rgba(255,255,255,.06);border:1px solid #2a3a5e;border-radius:12px;padding:18px;text-align:center}
.profile-box .label{color:#aaa;font-size:13px;margin-bottom:6px}
.profile-box .value{color:#ffd700;font-size:22px;font-weight:bold}
.rank-badge{font-size:24px;font-weight:bold;color:#ffd700;text-shadow:0 0 15px rgba(255,215,0,.5)}
.rank-progress{width:100%;height:18px;background:rgba(0,0,0,.5);border-radius:20px;overflow:hidden;border:1px solid #374151;margin-top:10px}
.rank-progress-fill{height:100%;background:linear-gradient(90deg,#10b981,#ffd700);width:0%;transition:.4s}
.profile-btn{margin-top:12px;background:linear-gradient(135deg,#3b82f6,#1d4ed8);color:#fff;border:none;padding:9px 16px;border-radius:8px;cursor:pointer;font-weight:bold}

/* ТРЕЙДЫ */
.trade-layout{display:grid;grid-template-columns:1fr 1fr;gap:20px}
@media(max-width:900px){.trade-layout{grid-template-columns:1fr}}
.trade-panel{background:rgba(255,255,255,.03);border:1px solid #2a3a5e;border-radius:12px;padding:15px}
.trade-panel h3{color:#ffd700;text-align:center;margin-bottom:12px}
.trade-selected{box-shadow:0 0 20px #ffd700 !important;transform:scale(1.04)}
.bot-offers{display:grid;gap:12px}
.bot-offer{background:rgba(255,255,255,.06);border:2px solid;border-radius:12px;padding:15px;display:grid;grid-template-columns:auto 1fr auto;gap:12px;align-items:center}
.bot-offer img{width:70px;height:70px;object-fit:contain}
.bot-name{color:#60a5fa;font-weight:bold;margin-bottom:4px}
.bot-comment{color:#aaa;font-size:12px;font-style:italic}
.bot-price{color:#7fff00;font-weight:bold}
.trade-accept{background:linear-gradient(135deg,#10b981,#059669);color:#fff;border:none;padding:10px 16px;border-radius:8px;cursor:pointer;font-weight:bold}
.trade-accept:hover{transform:translateY(-2px)}

.games-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:15px;margin-bottom:20px}
.game-card{background:linear-gradient(135deg,rgba(139,92,246,.2),rgba(91,33,182,.2));border:2px solid #8b5cf6;border-radius:12px;padding:20px;text-align:center;cursor:pointer;transition:.2s}
.game-card:hover{transform:translateY(-5px)}
.game-card .gicon{font-size:70px;margin-bottom:10px}
.game-card .gname{font-size:20px;font-weight:bold;color:#ffd700;margin-bottom:5px}
.game-card .gdesc{font-size:13px;color:#ccc}
.game-area{display:none;flex-direction:column;align-items:center;gap:15px}
.game-area.active{display:flex}
.game-hud{display:flex;gap:15px;flex-wrap:wrap;justify-content:center;width:100%}
.hud-box{background:rgba(255,255,255,.05);padding:8px 16px;border-radius:8px;border:1px solid #2a3a5e;font-size:14px}
.hud-box span{color:#ffd700;font-weight:bold}
#gdCanvas{background:linear-gradient(180deg,#1e3a8a 0%,#312e81 50%,#1e1b4b 100%);border:3px solid #8b5cf6;border-radius:10px;max-width:100%}
#pacmanCanvas{background:#000;border:3px solid #8b5cf6;border-radius:10px;max-width:100%}
.game-controls{display:flex;gap:10px;flex-wrap:wrap;justify-content:center}
.game-btn{background:linear-gradient(135deg,#8b5cf6,#5b21b6);color:#fff;border:none;padding:12px 25px;font-size:15px;font-weight:bold;border-radius:8px;cursor:pointer}
.game-btn.back{background:linear-gradient(135deg,#6b7280,#374151)}
.game-hint{color:#aaa;font-size:13px;text-align:center;font-style:italic}
.game-over-screen{position:absolute;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.85);display:none;align-items:center;justify-content:center;flex-direction:column;gap:15px;border-radius:10px;z-index:20}
.game-over-screen.active{display:flex}
.game-over-screen h2{color:#ef4444;font-size:32px}
.game-over-screen .reward{color:#ffd700;font-size:22px;font-weight:bold}
.game-over-screen .meme{color:#fbbf24;font-size:16px;font-style:italic;margin-top:5px}
.canvas-wrapper{position:relative}
.notification{position:fixed;top:20px;right:20px;padding:15px 25px;border-radius:8px;background:rgba(0,0,0,.95);border:2px solid #ffd700;color:#fff;font-weight:bold;z-index:1000;animation:slideIn .3s;max-width:380px;display:flex;align-items:center;gap:10px}
.notification img{width:40px;height:40px;object-fit:contain}
.notification .ntext{display:flex;flex-direction:column}
.notification .ntext .main{font-size:14px}
.notification .ntext .meme{font-size:11px;color:#fbbf24;font-style:italic;margin-top:3px}
@keyframes slideIn{from{transform:translateX(400px);opacity:0}to{transform:translateX(0);opacity:1}}
.big-meme{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.85);display:flex;align-items:center;justify-content:center;z-index:2000;animation:memeFlash 3s forwards;pointer-events:none}
.big-meme .content{text-align:center;animation:memeZoom 3s forwards}
.big-meme .emoji{font-size:150px;filter:drop-shadow(0 0 30px #ffd700)}
.big-meme .text{font-size:60px;font-weight:bold;color:#ffd700;text-shadow:0 0 30px #ffd700;margin-top:10px}
.big-meme .subtext{font-size:24px;color:#fff;margin-top:10px;font-style:italic}
@keyframes memeFlash{0%{opacity:0}10%{opacity:1}80%{opacity:1}100%{opacity:0}}
@keyframes memeZoom{0%{transform:scale(0) rotate(-180deg)}30%{transform:scale(1.2) rotate(10deg)}50%{transform:scale(1) rotate(0deg)}100%{transform:scale(1) rotate(0deg)}}
</style>
</head>
<body>
<div class="container">

<div class="meme-ticker">
<div class="meme-ticker-inner">
🗿 SKIBIDI MUSORCASE 🗿 • 💀 F В ЧАТ ЕСЛИ НЕ ВЫИГРАЛ 💀 • 🗡️ НОЖ 1% ШАНС (НА САМОМ ДЕЛЕ 0.001%) 🗡️ • 🤡 ТЫ КУПИЛ КЕЙС? ТЫ ЛОХ 🤡 • 📉 ПРОФИТ? НЕ СЛЫШАЛ 📉 • 💎 LEGENDARY? А, НЕТ, ЭТО ПРОСТО КРАСНЫЙ 💎 • 🚽 MUSORCASE — ЛУЧШИЙ СКАМ 2026 🚽 • 🧤 ПЕРЧАТКИ — НОВЫЙ ТРЕНД 🧤 • 🤖 БОТЫ ТРЕЙДЯТ ЛУЧШЕ ЛЮДЕЙ 🤖 • 🏆 СТАНЬ КОРОЛЁМ ПОМОЙКИ 👑 • 🗿 МОИ ДЕЙСТВИЯ? ИЗИ КАТКА 🗿 • 💸 ДЕНЬГИ НЕ ГЛАВНОЕ, ГЛАВНОЕ — НОЖ 💸 • 🎰 КРУТИ И МОЛИСЬ 🎰 • 🔥 СКИЛЛ 100% (РАНДОМ 100%) 🔥 • ⚠️ ПРЕДУПРЕЖДЕНИЕ: ВЫЗЫВАЕТ ЗАВИСИМОСТЬ ⚠️ • 🗿 + + + + + SKIBIDITOILET + + + + + 🗿
</div>
</div>

<header>
<h1>🗑️ MusorCase<span class="sub">"Лучший скам 2026 года по версии Роскомнадзора"</span></h1>
<div style="display:flex;gap:10px;align-items:center;flex-wrap:wrap">
<div class="balance">💰 Баланс: <span id="balance">1000</span> ₽</div>
<button class="sound-btn on" id="soundBtn" onclick="toggleSound()">🔊</button>
<button class="topup-btn" onclick="topup()">+500 ₽ (бесплатно, лошара)</button>
</div>
</header>

<div class="tabs">
<button class="tab active" onclick="switchTab('cases',this)">📦 Кейсы</button>
<button class="tab" onclick="switchTab('wheel',this)">🎡 Колесо</button>
<button class="tab" onclick="switchTab('upgrade',this)">⚡ Апгрейд</button>
<button class="tab" onclick="switchTab('trades',this)">🤖 Трейды</button>
<button class="tab" onclick="switchTab('profile',this)">👤 Профиль</button>
<button class="tab" onclick="switchTab('games',this)">🎮 Игры</button>
</div>

<div class="section active" id="section-cases">
<div class="panel"><h2 class="title">📦 Выбери кейс (или не выбирай)</h2><div class="cases-grid" id="casesGrid"></div></div>
<div class="panel">
<div id="currentCaseName" style="font-size:20px;color:#ffd700;margin-bottom:15px;text-align:center">Выбран: Базовый кейс</div>
<div class="speed-switcher">
<button class="speed-btn" data-speed="fast" onclick="setSpeed('fast',this)">⚡ Быстро</button>
<button class="speed-btn active" data-speed="normal" onclick="setSpeed('normal',this)">🎯 Нормально</button>
<button class="speed-btn" data-speed="slow" onclick="setSpeed('slow',this)">🐢 Медленно</button>
</div>
<div class="roulette-container" id="rouletteContainer"><div class="roulette-pointer"></div><div class="roulette-track" id="rouletteTrack"></div></div>
<div class="open-controls">
<button class="open-btn" id="openBtn1" onclick="openCase(1)">🔓 x1<span class="sub" id="price1">50 ₽</span></button>
<button class="open-btn x5" id="openBtn5" onclick="openCase(5)">🔓 x5<span class="sub" id="price5">250 ₽</span></button>
<button class="open-btn x10" id="openBtn10" onclick="openCase(10)">🔓 x10<span class="sub" id="price10">500 ₽</span></button>
</div>
</div>
<div class="panel multi-results" id="multiResults">
<h2 class="title">🎁 Результаты (плач разрешён)</h2>
<div class="multi-stats" id="multiStats"></div>
<div class="multi-grid" id="multiGrid"></div>
</div>
<div class="panel">
<div class="inv-header"><h2>🎒 Инвентарь (<span id="invCount">0</span>)</h2><button class="sell-all-btn" onclick="sellAll()">💸 Продать всё</button></div>
<div class="inventory-grid" id="inventoryGrid"><div class="empty">Инвентарь пуст. Как и твоя жизнь.</div></div>
</div>
</div>

<div class="section" id="section-wheel">
<div class="panel">
<h2 class="title">🎡 Колесо Фортуны 30/70 (как и твоя зарплата)</h2>
<div class="wheel-info">
<div class="wheel-info-box win"><img id="wheelKnifeImg"><div><div>🗡️ НОЖ</div><div class="big">+2500 ₽</div><div>30%</div></div></div>
<div class="wheel-info-box lose"><img id="wheelBulletImg"><div><div>🔩 ПАТРОН</div><div class="big">0 ₽</div><div>70%</div></div></div>
</div>
<div class="wheel-wrapper">
<div class="wheel-container"><div class="wheel-pointer"></div><canvas id="wheelCanvas" width="350" height="350"></canvas><div class="wheel-center"><img id="wheelCenterImg"></div></div>
<button class="wheel-btn" id="wheelBtn" onclick="spinWheel()">🎰 КРУТИТЬ — 500 ₽</button>
<div class="wheel-result" id="wheelResult"></div>
</div>
</div>
</div>

<div class="section" id="section-upgrade">
<div class="panel">
<h2 class="title">⚡ Апгрейдер (казино для бедных)</h2>
<div class="upgrade-layout">
<div class="upgrade-panel"><h3>📤 Твой скин</h3><div class="hint">Выбери из инвентаря</div><div class="upgrade-items" id="upgradeSource"></div></div>
<div class="upgrade-center">
<div class="upgrade-circle"><div class="upgrade-pointer"></div><canvas id="upgradeCanvas" width="220" height="220"></canvas><div class="upgrade-percent" id="upgradePercent">—%</div></div>
<button class="upgrade-btn" id="upgradeBtn" onclick="doUpgrade()" disabled>🚀 АПГРЕЙД</button>
<div class="upgrade-result" id="upgradeResult"></div>
</div>
<div class="upgrade-panel"><h3>📥 Целевой скин</h3><div class="hint">Выбери что хочешь</div><div class="upgrade-items" id="upgradeTarget"></div></div>
</div>
</div>
</div>

<div class="section" id="section-trades">
<div class="panel">
<h2 class="title">🤖 Трейды с ботами</h2>
<p style="text-align:center;color:#aaa;margin-bottom:15px;font-style:italic">
Выбери свой скин, а боты предложат обмен. Иногда они дают дороже, иногда скамят.
</p>
<div class="trade-layout">
<div class="trade-panel">
<h3>📤 Твой скин для трейда</h3>
<div class="inventory-grid" id="tradeSource"></div>
</div>
<div class="trade-panel">
<h3>📥 Предложения ботов</h3>
<div class="bot-offers" id="botOffers">
<div class="empty">Выбери скин слева</div>
</div>
</div>
</div>
</div>
</div>

<div class="section" id="section-profile">
<div class="panel">
<h2 class="title">👤 Профиль MusorCase</h2>
<div id="profileContent"></div>
</div>
</div>

<div class="section" id="section-games">
<div class="panel">
<h2 class="title">🎮 Мини-Игры (заработай на кейсы)</h2>
<div class="games-grid" id="gamesGrid">
<div class="game-card" onclick="startGame('gd')"><div class="gicon">🟥</div><div class="gname">Geometry Dash</div><div class="gdesc">Прыгай через шипы! 1₽ за 10 метров</div></div>
<div class="game-card" onclick="startGame('pacman')"><div class="gicon">🟡</div><div class="gname">Pac-Man</div><div class="gdesc">Съешь все точки! 1₽ за 10 очков</div></div>
</div>
<div class="game-area" id="gameArea-gd">
<div class="game-hud">
<div class="hud-box">📏 <span id="gdDistance">0</span> м</div>
<div class="hud-box">🏆 <span id="gdRecord">0</span> м</div>
<div class="hud-box">💰 <span id="gdReward">0</span> ₽</div>
</div>
<div class="canvas-wrapper">
<canvas id="gdCanvas" width="800" height="300"></canvas>
<div class="game-over-screen" id="gdGameOver"><h2>💀 GAME OVER</h2><div>Дистанция: <span id="gdFinalDist">0</span> м</div><div class="reward">+<span id="gdFinalReward">0</span> ₽</div><div class="meme" id="gdMeme"></div><button class="game-btn" onclick="restartGD()">🔄 Заново</button></div>
</div>
<div class="game-hint">⌨️ Пробел / Клик — прыжок</div>
<div class="game-controls"><button class="game-btn back" onclick="exitGame('gd')">← Выход</button></div>
</div>
<div class="game-area" id="gameArea-pacman">
<div class="game-hud">
<div class="hud-box">🟡 Очки: <span id="pmScore">0</span></div>
<div class="hud-box">💰 <span id="pmReward">0</span> ₽</div>
<div class="hud-box">❤️ Жизни: <span id="pmLives">3</span></div>
<div class="hud-box">🏆 Рекорд: <span id="pmRecord">0</span></div>
</div>
<div class="canvas-wrapper">
<canvas id="pacmanCanvas" width="448" height="496"></canvas>
<div class="game-over-screen" id="pmGameOver"><h2>💀 GAME OVER</h2><div>Очки: <span id="pmFinalScore">0</span></div><div class="reward">+<span id="pmFinalReward">0</span> ₽</div><div class="meme" id="pmMeme"></div><button class="game-btn" onclick="restartPacman()">🔄 Заново</button></div>
</div>
<div class="game-hint">⌨️ Стрелки / WASD — движение</div>
<div class="game-controls"><button class="game-btn back" onclick="exitGame('pacman')">← Выход</button></div>
</div>
</div>
</div>
</div>

<script>
// ============ ЗВУКОВАЯ СИСТЕМА ============
let audioCtx=null;
let soundEnabled=true;
function initAudio(){if(!audioCtx)audioCtx=new(window.AudioContext||window.webkitAudioContext)()}
function toggleSound(){
soundEnabled=!soundEnabled;
const b=document.getElementById('soundBtn');
b.textContent=soundEnabled?'🔊':'🔇';
b.classList.toggle('on',soundEnabled);
}
function playTone(freq,dur,type='sine',vol=.2){
if(!soundEnabled)return;
initAudio();
const o=audioCtx.createOscillator();
const g=audioCtx.createGain();
o.type=type;o.frequency.value=freq;
g.gain.setValueAtTime(vol,audioCtx.currentTime);
g.gain.exponentialRampToValueAtTime(.001,audioCtx.currentTime+dur);
o.connect(g);g.connect(audioCtx.destination);
o.start();o.stop(audioCtx.currentTime+dur);
}
function playNoise(dur,vol=.1){
if(!soundEnabled)return;
initAudio();
const buf=audioCtx.createBuffer(1,audioCtx.sampleRate*dur,audioCtx.sampleRate);
const d=buf.getChannelData(0);
for(let i=0;i<d.length;i++)d[i]=(Math.random()*2-1)*(1-i/d.length);
const s=audioCtx.createBufferSource();
const g=audioCtx.createGain();
s.buffer=buf;g.gain.value=vol;
s.connect(g);g.connect(audioCtx.destination);
s.start();
}
const SFX={
click:()=>playTone(800,.05,'square',.1),
open:()=>{playNoise(.3,.15);playTone(400,.2,'sawtooth',.1)},
tick:()=>playTone(1200,.02,'square',.05),
win:()=>{[523,659,784,1047].forEach((f,i)=>setTimeout(()=>playTone(f,.2,'triangle',.2),i*100))},
knife:()=>{[523,659,784,1047,1319].forEach((f,i)=>setTimeout(()=>playTone(f,.3,'triangle',.25),i*120));setTimeout(()=>playNoise(.5,.1),600)},
lose:()=>{[400,300,200,100].forEach((f,i)=>setTimeout(()=>playTone(f,.3,'sawtooth',.15),i*150))},
wheel:()=>playTone(200+Math.random()*100,.05,'square',.08),
upgrade:()=>{playTone(600,.1,'square',.15);setTimeout(()=>playTone(900,.2,'square',.15),100)},
jump:()=>{playTone(500,.1,'square',.1);setTimeout(()=>playTone(800,.1,'square',.08),50)},
coin:()=>{playTone(988,.05,'square',.1);setTimeout(()=>playTone(1319,.1,'square',.1),50)},
die:()=>{[400,300,200].forEach((f,i)=>setTimeout(()=>playTone(f,.2,'sawtooth',.2),i*100))},
powerup:()=>{[523,784,1047].forEach((f,i)=>setTimeout(()=>playTone(f,.15,'triangle',.2),i*80))}
};

// ============ МЕМНЫЕ ФРАЗЫ ============
const MEMES={
knifeWin:["ПОТРАЧЕНО 💀","ИЗИ КАТКА 🗿","СКАМ 100% (НО НОЖ!)","ЖИЗА БРАТАН","ТЫ ЛЕГЕНДА 🗡️","+1 К АУРЕ","РОДИТЕЛИ ОЦЕНЯТ","ЭТО БАЗА","НУ ТЫ И КРАСАВЧИК","F В ЧАТ У СОСЕДА"],
legendaryWin:["ЛЕГЕНДА ПОЯВИЛАСЬ 🔥","ЭТО БАЗА","КРАСАВЧИК","НЕ ХУЖЕ ЧЕМ У СТРИМЕРА","+100 К УВАЖЕНИЮ","АФК РЕЖИМ АКТИВИРОВАН"],
epicWin:["ЭПИК МУВ 🎯","КРАСАВА","ИЗИ","БАЗА","НЕ ПЛОХО"],
rareWin:["РЕДКИЙ ДРОП ✨","УДАЧА НА ПРОХОДЕ","НОРМАС","ПРИНЯТО"],
commonWin:["МУСОР КАК И ОБЫЧНО 🗑️","ОЧЕРЕДНОЙ БОЛТ","ЖИЗНЬ БОЛЬ","F В ЧАТ","НУ НИЧЕ СЕБЕ...","СКУФ-ДРОП","ОПЯТЬ МИМУМ?"],
lose:["F В ЧАТ 💀","СКУФ НЕ ПОВЕЗЛО","АФК БЫЛ?","БРАКАН ПОЙМАЛ","ЭТО БАЗА (НЕТ)","РОДИТЕЛИ БЫ НЕ ОДОБРИЛИ","ТЫ ПРОСТО ЛОХ","+1 К ДЕПРЕССИИ","ЗАЧЕМ ТЫ ЭТО КУПИЛ?","МУСОРCase — МУСОР и ЕСТЬ"],
upgradeWin:["ИЗИ АПГРЕЙД 🔥","СКАМ НЕ ПРОКАТИЛ","ТЫ ХИТРЕЦ","БАЗА","КРАСАВЧИК","+1 К СКИЛЛУ"],
upgradeLose:["АПГРЕЙД? НЕ СЛЫШАЛ 💀","F В ЧАТ","КАЗИНО ВСЕГДА В ПЛЮСЕ","ПРОЕБАЛ","НУ ТЫ И ЛОХ","ЭТО БАЗА (НЕТ)","СКУФ-МУВ","ЗАЧЕМ ТЫ ЭТО СДЕЛАЛ?"],
gdDeath:["ИЗИ ДЭТ 🗿","ТЫ ПРОСТО НУБ","F В ЧАТ","ГЕОМЕТРИЯ? НЕ СЛЫШАЛ","ПРЫГАЙ НОРМАЛЬНО","СКУФ-МУВ"],
pmDeath:["ПАКМЕН МЁРТВ 💀","ПРИЗРАКИ 1, ТЫ 0","F В ЧАТ","ЖРИ ТОЧКИ БЫСТРЕЕ","СКУФ-МУВ"],
topup:["ДЕРЖИ КАРМАН ШИРЕ 💸","БЕСПЛАТНЫЙ СЫР...","ЛОВИ ДЕНЕЖКУ","ЕЩЁ ПОЧКА ПРОДАЙ","МАМА БЫ НЕ ОДОБРИЛА","ЭТО БАЗА"],
tradeWin:["БОТ ПРОИГРАЛ 🤖","СКАМ НЕ ПРОКАТИЛ","ИЗИ ТРЕЙД","БАЗА","КРАСАВЧИК"],
tradeLose:["БОТ ТЕБЯ ОБЫГРАЛ 🤖","F В ЧАТ","СКАМ 100%","ЗАЧЕМ ТЫ СОГЛАСИЛСЯ?","НУ ТЫ И ЛОХ"]
};
function randMeme(arr){return arr[Math.floor(Math.random()*arr.length)]}

function showBigMeme(emoji,text,subtext){
const d=document.createElement('div');d.className='big-meme';
d.innerHTML=`<div class="content"><div class="emoji">${emoji}</div><div class="text">${text}</div><div class="subtext">${subtext}</div></div>`;
document.body.appendChild(d);
setTimeout(()=>d.remove(),3000);
}

// ============ SVG ИКОНКИ ============
const ICONS={
karambit:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><linearGradient id="kb" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#f9fafb"/><stop offset=".5" stop-color="#9ca3af"/><stop offset="1" stop-color="#374151"/></linearGradient></defs><path d="M20 75 Q15 50 30 35 Q50 20 75 25 L78 32 Q55 30 38 45 Q25 58 28 75 Z" fill="url(#kb)" stroke="#1f2937" stroke-width="1"/><path d="M22 70 Q20 55 32 42" fill="none" stroke="#fff" stroke-width=".5" opacity=".6"/><circle cx="25" cy="72" r="8" fill="none" stroke="#78350f" stroke-width="4"/><path d="M20 75 L15 85 L30 82 Z" fill="#78350f"/></svg>`,
butterfly:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M50 50 L20 20 L25 15 L55 45 Z" fill="#d1d5db" stroke="#1f2937"/><path d="M50 50 L80 80 L75 85 L45 55 Z" fill="#d1d5db" stroke="#1f2937"/><path d="M50 50 L80 20 L85 25 L55 55 Z" fill="#4b5563" stroke="#1f2937"/><path d="M50 50 L20 80 L15 75 L45 45 Z" fill="#4b5563" stroke="#1f2937"/><circle cx="50" cy="50" r="5" fill="#b45309"/><circle cx="50" cy="50" r="2" fill="#fbbf24"/></svg>`,
m9bayonet:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M15 55 L75 45 L85 50 L75 55 L15 60 Z" fill="#d1d5db" stroke="#1f2937"/><path d="M75 45 L85 50 L75 55 Z" fill="#6b7280"/><rect x="10" y="52" width="20" height="10" fill="#78350f" stroke="#1f2937"/><rect x="5" y="50" width="8" height="14" fill="#1f2937" rx="2"/></svg>`,
talon:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M25 75 Q20 55 35 40 Q55 25 78 30 L80 38 Q58 35 42 48 Q30 60 32 75 Z" fill="#d1d5db" stroke="#1f2937"/><path d="M25 75 L20 82 L32 80 Z" fill="#78350f"/></svg>`,
flip:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M20 55 L78 50 L82 55 L78 60 L20 58 Z" fill="#d1d5db" stroke="#1f2937"/><rect x="12" y="52" width="15" height="8" fill="#78350f"/><circle cx="17" cy="56" r="1.5" fill="#fbbf24"/></svg>`,
skeleton:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M20 55 L75 48 L82 53 L75 58 L20 60 Z" fill="#1f2937" stroke="#6b7280"/><rect x="12" y="50" width="18" height="12" fill="#374151"/><circle cx="17" cy="56" r="2" fill="#ef4444"/><circle cx="25" cy="56" r="2" fill="#ef4444"/></svg>`,
fang:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M25 75 Q20 55 38 40 Q55 28 78 32 L80 40 Q60 38 45 50 Q32 62 35 75 Z" fill="#fbbf24" stroke="#78350f"/><path d="M25 75 L20 82 L35 80 Z" fill="#78350f"/></svg>`,
hunter:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M20 55 L70 48 L85 55 L70 62 L20 60 Z" fill="#d1d5db" stroke="#1f2937"/><rect x="10" y="50" width="18" height="14" fill="#78350f"/><rect x="5" y="48" width="8" height="18" fill="#1f2937" rx="2"/></svg>`,
navaja:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M30 55 L75 52 L78 56 L75 60 L30 58 Z" fill="#d1d5db" stroke="#1f2937"/><rect x="15" y="52" width="20" height="8" fill="#78350f"/><circle cx="25" cy="56" r="1.5" fill="#fbbf24"/></svg>`,
bayonet:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M15 55 L72 48 L85 55 L72 62 L15 60 Z" fill="#d1d5db" stroke="#1f2937"/><rect x="8" y="52" width="15" height="10" fill="#78350f"/></svg>`,
awp_dragon:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="75" height="8" fill="#dc2626" stroke="#78350f"/><rect x="80" y="45" width="12" height="14" fill="#78350f" rx="2"/><circle cx="25" cy="52" r="6" fill="#1f2937" stroke="#fbbf24" stroke-width="1.5"/><circle cx="25" cy="52" r="3" fill="#60a5fa"/><path d="M40 48 Q50 40 60 48" fill="none" stroke="#fbbf24" stroke-width="1.5"/></svg>`,
ak_fire:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="70" height="8" fill="#ef4444" stroke="#78350f"/><path d="M75 48 L85 45 L85 59 L75 56 Z" fill="#78350f"/><path d="M40 48 L45 42 L50 48" fill="#fbbf24"/><rect x="25" y="56" width="15" height="10" fill="#78350f"/></svg>`,
m4a1_beast:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="75" height="8" fill="#7c3aed" stroke="#4c1d95"/><rect x="80" y="45" width="12" height="14" fill="#1f2937" rx="2"/><circle cx="25" cy="52" r="6" fill="#1f2937" stroke="#a78bfa" stroke-width="1.5"/><circle cx="25" cy="52" r="3" fill="#fbbf24"/></svg>`,
awp_asimov:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="75" height="8" fill="#f3f4f6" stroke="#374151"/><rect x="80" y="45" width="12" height="14" fill="#1f2937" rx="2"/><circle cx="25" cy="52" r="6" fill="#1f2937" stroke="#f3f4f6" stroke-width="1.5"/><circle cx="25" cy="52" r="3" fill="#ef4444"/></svg>`,
ak47:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="70" height="8" fill="#92400e" stroke="#451a03"/><path d="M75 48 L85 45 L85 59 L75 56 Z" fill="#78350f"/><rect x="25" y="56" width="15" height="10" fill="#92400e"/><circle cx="20" cy="52" r="4" fill="#1f2937"/></svg>`,
m4a4:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="75" height="8" fill="#374151" stroke="#1f2937"/><rect x="80" y="45" width="12" height="14" fill="#1f2937" rx="2"/><circle cx="25" cy="52" r="5" fill="#1f2937"/><rect x="30" y="56" width="18" height="8" fill="#374151"/></svg>`,
mp9:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="20" y="48" width="50" height="10" fill="#1f2937"/><rect x="65" y="45" width="10" height="16" fill="#374151" rx="2"/><rect x="35" y="58" width="12" height="12" fill="#1f2937"/><circle cx="25" cy="53" r="4" fill="#000"/></svg>`,
ump45:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="48" width="55" height="10" fill="#374151"/><rect x="65" y="45" width="12" height="16" fill="#1f2937" rx="2"/><rect x="30" y="58" width="15" height="14" fill="#374151"/><circle cx="22" cy="53" r="4" fill="#000"/></svg>`,
pm:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="25" y="45" width="40" height="12" fill="#374151"/><rect x="35" y="57" width="15" height="18" fill="#1f2937"/><rect x="60" y="43" width="10" height="6" fill="#4b5563"/><circle cx="30" cy="51" r="2" fill="#000"/></svg>`,
glock:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="25" y="45" width="42" height="12" fill="#1f2937"/><rect x="35" y="57" width="15" height="20" fill="#000"/><rect x="62" y="43" width="10" height="6" fill="#374151"/></svg>`,
usps:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="25" y="45" width="45" height="12" fill="#374151"/><rect x="35" y="57" width="15" height="18" fill="#1f2937"/><rect x="65" y="40" width="12" height="5" fill="#4b5563"/><rect x="30" y="42" width="20" height="3" fill="#1f2937"/></svg>`,
deagle:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="20" y="42" width="50" height="15" fill="#fbbf24" stroke="#78350f"/><rect x="35" y="57" width="18" height="22" fill="#78350f"/><rect x="65" y="40" width="15" height="7" fill="#b45309"/><circle cx="28" cy="50" r="3" fill="#1f2937"/></svg>`,
p250:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="25" y="45" width="42" height="12" fill="#4b5563"/><rect x="35" y="57" width="15" height="18" fill="#1f2937"/><rect x="62" y="43" width="10" height="6" fill="#6b7280"/></svg>`,
bullet:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M25 40 Q20 50 25 60 L60 60 L70 50 L60 40 Z" fill="#fbbf24" stroke="#78350f" stroke-width="1.5"/><rect x="60" y="40" width="15" height="20" fill="#b45309" stroke="#78350f" stroke-width="1.5"/></svg>`,
bolt:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="20" fill="#6b7280" stroke="#374151" stroke-width="2"/><circle cx="50" cy="50" r="10" fill="#374151"/><path d="M50 30 L50 25 M50 70 L50 75 M30 50 L25 50 M70 50 L75 50" stroke="#374151" stroke-width="2"/></svg>`,
casing:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="30" y="35" width="40" height="30" fill="#fbbf24" stroke="#78350f" stroke-width="1.5" rx="2"/><ellipse cx="50" cy="35" rx="20" ry="4" fill="#fde68a"/><ellipse cx="50" cy="65" rx="20" ry="4" fill="#92400e"/></svg>`,
cloth:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M20 30 Q30 25 40 30 Q50 35 60 30 Q70 25 80 30 L80 70 Q70 75 60 70 Q50 65 40 70 Q30 75 20 70 Z" fill="#7c3aed" stroke="#4c1d95" stroke-width="1.5"/></svg>`,
scope:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="20" y="45" width="60" height="12" fill="#1f2937" stroke="#000" stroke-width="1.5" rx="3"/><circle cx="30" cy="51" r="8" fill="#374151" stroke="#60a5fa" stroke-width="1.5"/><circle cx="30" cy="51" r="4" fill="#1e3a8a"/><circle cx="70" cy="51" r="8" fill="#374151" stroke="#60a5fa" stroke-width="1.5"/></svg>`,
mag:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M35 25 L65 25 L68 75 L32 75 Z" fill="#374151" stroke="#1f2937" stroke-width="1.5"/><rect x="38" y="30" width="24" height="4" fill="#1f2937"/><rect x="38" y="38" width="24" height="4" fill="#1f2937"/><rect x="38" y="46" width="24" height="4" fill="#1f2937"/></svg>`,
target:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="35" fill="#fff" stroke="#000" stroke-width="3"/><circle cx="50" cy="50" r="25" fill="#ef4444"/><circle cx="50" cy="50" r="15" fill="#fff"/><circle cx="50" cy="50" r="7" fill="#ef4444"/></svg>`,
case_basic:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#6b7280" stroke="#374151" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#4b5563"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/></svg>`,
case_standard:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#3b82f6" stroke="#1e40af" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#2563eb"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/></svg>`,
case_premium:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#8b5cf6" stroke="#5b21b6" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#7c3aed"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/></svg>`,
case_legendary:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#ef4444" stroke="#991b1b" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#dc2626"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/></svg>`,
case_elite:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#fbbf24" stroke="#b45309" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#f59e0b"/><rect x="45" y="40" width="10" height="15" fill="#fff"/></svg>`,
case_gloves:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#14b8a6" stroke="#0f766e" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#0f766e"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/><text x="50" y="68" text-anchor="middle" font-size="24" fill="#fff">🧤</text></svg>`,
case_knife:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#f59e0b" stroke="#78350f" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#b45309"/><rect x="45" y="40" width="10" height="15" fill="#fff"/><text x="50" y="68" text-anchor="middle" font-size="24" fill="#fff">🗡️</text></svg>`,
gloves_sport:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><linearGradient id="g1" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#5eead4"/><stop offset=".5" stop-color="#14b8a6"/><stop offset="1" stop-color="#134e4a"/></linearGradient></defs><path d="M25 65 L20 38 Q20 32 25 32 Q29 32 30 38 L32 50 L34 28 Q35 22 40 23 Q44 24 43 30 L42 50 L46 27 Q47 22 52 23 Q56 24 55 30 L52 51 L58 32 Q60 27 64 29 Q68 31 66 37 L60 58 Q72 50 77 55 Q82 61 70 72 Q58 84 40 82 Q28 80 25 65Z" fill="url(#g1)" stroke="#022c22" stroke-width="2"/><path d="M32 62 Q45 70 62 62" fill="none" stroke="#ccfbf1" stroke-width="2" opacity=".7"/></svg>`,
gloves_driver:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><linearGradient id="g2" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#fde68a"/><stop offset=".5" stop-color="#92400e"/><stop offset="1" stop-color="#451a03"/></linearGradient></defs><path d="M25 65 L20 38 Q20 32 25 32 Q29 32 30 38 L32 50 L34 28 Q35 22 40 23 Q44 24 43 30 L42 50 L46 27 Q47 22 52 23 Q56 24 55 30 L52 51 L58 32 Q60 27 64 29 Q68 31 66 37 L60 58 Q72 50 77 55 Q82 61 70 72 Q58 84 40 82 Q28 80 25 65Z" fill="url(#g2)" stroke="#1f2937" stroke-width="2"/><circle cx="45" cy="65" r="4" fill="#111827"/><circle cx="55" cy="66" r="4" fill="#111827"/></svg>`,
gloves_specialist:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><linearGradient id="g3" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#fca5a5"/><stop offset=".45" stop-color="#7f1d1d"/><stop offset="1" stop-color="#111827"/></linearGradient></defs><path d="M25 65 L20 38 Q20 32 25 32 Q29 32 30 38 L32 50 L34 28 Q35 22 40 23 Q44 24 43 30 L42 50 L46 27 Q47 22 52 23 Q56 24 55 30 L52 51 L58 32 Q60 27 64 29 Q68 31 66 37 L60 58 Q72 50 77 55 Q82 61 70 72 Q58 84 40 82 Q28 80 25 65Z" fill="url(#g3)" stroke="#000" stroke-width="2"/><path d="M30 58 L65 70" stroke="#fecaca" stroke-width="2" opacity=".6"/><path d="M34 48 L62 60" stroke="#fecaca" stroke-width="1" opacity=".5"/></svg>`
};
function iconUrl(k){return 'data:image/svg+xml;utf8,'+encodeURIComponent(ICONS[k])}

// ============ ПРЕДМЕТЫ ============
const allItems={
common:[
{name:'Пустой патрон',icon:'bullet',price:5},
{name:'Ржавый болт',icon:'bolt',price:10},
{name:'Старая гильза',icon:'casing',price:15},
{name:'Кусок ткани',icon:'cloth',price:8},
{name:'Сломанный прицел',icon:'scope',price:12},
{name:'Пустая обойма',icon:'mag',price:7}
],
rare:[
{name:'Пистолет ПМ',icon:'pm',price:80},
{name:'Glock-18',icon:'glock',price:120},
{name:'USP-S',icon:'usps',price:150},
{name:'Desert Eagle',icon:'deagle',price:200},
{name:'P250',icon:'p250',price:90}
],
epic:[
{name:'AK-47',icon:'ak47',price:350},
{name:'M4A4',icon:'m4a4',price:400},
{name:'MP9',icon:'mp9',price:280},
{name:'UMP-45',icon:'ump45',price:320}
],
legendary:[
{name:'AWP Дракон',icon:'awp_dragon',price:800},
{name:'AK Огненный',icon:'ak_fire',price:1000},
{name:'M4A1-S Зверь',icon:'m4a1_beast',price:900},
{name:'AWP Азимов',icon:'awp_asimov',price:1200}
],
knife:[
{name:'Керамбит',icon:'karambit',price:2500},
{name:'Бабочка',icon:'butterfly',price:3000},
{name:'M9 Штык-нож',icon:'m9bayonet',price:3500},
{name:'Тычковые ножи',icon:'talon',price:2800},
{name:'Флип-нож',icon:'flip',price:2200},
{name:'Скелетный нож',icon:'skeleton',price:3200},
{name:'Нож-клык',icon:'fang',price:3800},
{name:'Нож охотника',icon:'hunter',price:2600},
{name:'Наварский нож',icon:'navaja',price:2400},
{name:'Штык-нож',icon:'bayonet',price:2900}
],
gloves:[
{name:'Спортивные | Бирюза',icon:'gloves_sport',price:1800},
{name:'Спортивные | Мусорный люкс',icon:'gloves_sport',price:2400},
{name:'Водительские | Коричневый скам',icon:'gloves_driver',price:1600},
{name:'Водительские | Золотой скуф',icon:'gloves_driver',price:2800},
{name:'Перчатки специалиста | Красный фартук',icon:'gloves_specialist',price:3200},
{name:'Перчатки специалиста | Полевой мусор',icon:'gloves_specialist',price:4200}
]
};

const allUpgradeTargets=[
...allItems.rare.map(i=>({...i,rarity:'rare'})),
...allItems.epic.map(i=>({...i,rarity:'epic'})),
...allItems.legendary.map(i=>({...i,rarity:'legendary'})),
...allItems.gloves.map(i=>({...i,rarity:'gloves'})),
...allItems.knife.map(i=>({...i,rarity:'knife'}))
];

const cases=[
{id:'basic',name:'Базовый кейс',icon:'case_basic',price:50,class:'case-basic',chanceText:'🗡️ Шанс ножа: 2%',chances:{common:70,rare:22,epic:5,legendary:1,knife:2}},
{id:'standard',name:'Стандартный кейс',icon:'case_standard',price:100,class:'case-standard',chanceText:'🗡️ Шанс ножа: 4%',chances:{common:55,rare:28,epic:10,legendary:3,knife:4}},
{id:'premium',name:'Премиум кейс',icon:'case_premium',price:250,class:'case-premium',chanceText:'🗡️ Шанс ножа: 8%',chances:{common:35,rare:35,epic:15,legendary:7,knife:8}},
{id:'legendary',name:'Легендарный кейс',icon:'case_legendary',price:500,class:'case-legendary',chanceText:'🗡️ Шанс ножа: 15%',chances:{common:15,rare:30,epic:25,legendary:15,knife:15}},
{id:'elite',name:'Элитный кейс',icon:'case_elite',price:1000,class:'case-elite',chanceText:'🗡️ Шанс ножа: 30%',chances:{common:5,rare:20,epic:30,legendary:15,knife:30}},
{id:'glove',name:'Перчаточный кейс',icon:'case_gloves',price:750,class:'case-gloves',chanceText:'🧤 Перчатки: 25% | 🗡️ Нож: 5%',chances:{common:10,rare:20,epic:25,legendary:15,gloves:25,knife:5}},
{id:'knife',name:'Ножевой кейс',icon:'case_knife',price:1500,class:'case-knife',chanceText:'🗡️ Шанс ножа: 45% | 🧤 Перчатки: 10%',chances:{common:2,rare:8,epic:15,legendary:20,gloves:10,knife:45}}
];

let balance=1000,inventory=[],isOpening=false,selectedCase=cases[0],animationSpeed='normal';
const SPEEDS={fast:{roulette:1,multiDelay:30},normal:{roulette:3,multiDelay:80},slow:{roulette:7,multiDelay:180}};
const balanceEl=document.getElementById('balance');
function updateBalance(){balanceEl.textContent=balance}
function topup(){balance+=500;updateBalance();SFX.coin();notify('💰 +500 ₽','#10b981',null,randMeme(MEMES.topup))}
function switchTab(tab,btn){
SFX.click();
document.querySelectorAll('.tab').forEach(t=>t.classList.remove('active'));
document.querySelectorAll('.section').forEach(s=>s.classList.remove('active'));
btn.classList.add('active');
document.getElementById('section-'+tab).classList.add('active');
if(tab==='upgrade')renderUpgradePanels();
if(tab==='profile')renderProfile();
if(tab==='trades')renderTradePanel();
}
function setSpeed(s,btn){SFX.click();animationSpeed=s;document.querySelectorAll('.speed-btn').forEach(b=>b.classList.remove('active'));btn.classList.add('active')}

function notify(text,color,iconKey,meme){
const n=document.createElement('div');n.className='notification';
const iconHtml=iconKey?`<img src="${iconUrl(iconKey)}">`:'';
const memeHtml=meme?`<div class="meme">${meme}</div>`:'';
n.innerHTML=iconHtml+`<div class="ntext"><div class="main">${text}</div>${memeHtml}</div>`;
n.style.borderColor=color;document.body.appendChild(n);
setTimeout(()=>n.remove(),3500);
}

// ============ КЕЙСЫ ============
function renderCases(){
const g=document.getElementById('casesGrid');g.innerHTML='';
cases.forEach(c=>{
const d=document.createElement('div');
d.className=`case-card ${c.class} ${c.id===selectedCase.id?'selected':''}`;
d.innerHTML=`<img src="${iconUrl(c.icon)}"><div class="name">${c.name}</div><div class="price">${c.price} ₽</div><div class="chance">${c.chanceText}</div>`;
d.onclick=()=>{SFX.click();selectCase(c)};g.appendChild(d);
});
updatePrices();
}
function updatePrices(){
document.getElementById('price1').textContent=selectedCase.price+' ₽';
document.getElementById('price5').textContent=selectedCase.price*5+' ₽';
document.getElementById('price10').textContent=selectedCase.price*10+' ₽';
}
function selectCase(c){if(isOpening)return;selectedCase=c;document.getElementById('currentCaseName').textContent=`Выбран: ${c.name} — ${c.price} ₽`;renderCases()}
function getRandomItem(cd){
const r=Math.random()*100;let c=0,ch='common';
for(const[k,v]of Object.entries(cd.chances)){c+=v;if(r<=c){ch=k;break}}
const p=allItems[ch];return{...p[Math.floor(Math.random()*p.length)],rarity:ch};
}
function mkItemEl(it){
const d=document.createElement('div');d.className=`roulette-item rarity-${it.rarity}`;
d.innerHTML=`<img src="${iconUrl(it.icon)}"><div class="iname">${it.name}</div>`;return d;
}
function setBtns(d){['openBtn1','openBtn5','openBtn10'].forEach(id=>document.getElementById(id).disabled=d)}

let tickInterval=null;
function openCase(count){
if(isOpening)return;
const cost=selectedCase.price*count;
if(balance<cost){notify(`❌ Нужно ${cost} ₽`,'#ff4444',null,randMeme(MEMES.lose));SFX.lose();return}
isOpening=true;balance-=cost;updateBalance();setBtns(true);
SFX.open();
mcProfile.stats.casesOpened+=count;
mcProfile.stats.spent+=cost;
addMCXP(count*12);
saveMCProfile();
const wins=[];for(let i=0;i<count;i++)wins.push(getRandomItem(selectedCase));
const sp=SPEEDS[animationSpeed],dur=sp.roulette;
if(count===1){
const rc=document.getElementById('rouletteContainer'),rt=document.getElementById('rouletteTrack'),mr=document.getElementById('multiResults');
rc.style.display='block';mr.style.display='none';
rt.style.transition='none';rt.style.transform='translateX(0)';rt.innerHTML='';
const w=wins[0],total=70,pos=55;
for(let i=0;i<total;i++)rt.appendChild(mkItemEl(i===pos?w:getRandomItem(selectedCase)));
let tickCount=0;
tickInterval=setInterval(()=>{SFX.tick();tickCount++;if(tickCount>dur*20)clearInterval(tickInterval)},50);
setTimeout(()=>{
const iw=140,cc=rc.offsetWidth/2,to=pos*iw+iw/2,ro=(Math.random()-.5)*80,fo=to-cc+ro;
rt.style.transition=`transform ${dur}s cubic-bezier(.15,.85,.35,1)`;
rt.style.transform=`translateX(-${fo}px)`;
},50);
setTimeout(()=>{
clearInterval(tickInterval);
inventory.push({...w,id:Date.now()+Math.random()});renderInventory();
const cols={knife:'#ffd700',gloves:'#14b8a6',legendary:'#ef4444',epic:'#8b5cf6',rare:'#3b82f6',common:'#718096'};
let memePool=MEMES.commonWin;
if(w.rarity==='knife'){memePool=MEMES.knifeWin;SFX.knife();showBigMeme('🗡️','НОЖ!!!',randMeme(MEMES.knifeWin))}
else if(w.rarity==='gloves'){memePool=MEMES.legendaryWin;SFX.win();showBigMeme('🧤','ПЕРЧАТКИ!',randMeme(MEMES.legendaryWin))}
else if(w.rarity==='legendary'){memePool=MEMES.legendaryWin;SFX.win()}
else if(w.rarity==='epic'){memePool=MEMES.epicWin;SFX.win()}
else if(w.rarity==='rare'){memePool=MEMES.rareWin;SFX.coin()}
else{SFX.lose()}
notify(`${w.name} — ${w.price} ₽`,cols[w.rarity],w.icon,randMeme(memePool));
isOpening=false;setBtns(false);
},dur*1000+200);
}else{
document.getElementById('rouletteContainer').style.display='none';
const mr=document.getElementById('multiResults'),mg=document.getElementById('multiGrid'),ms=document.getElementById('multiStats');
mr.style.display='block';mg.innerHTML='';
ms.innerHTML='<div style="text-align:center;width:100%;padding:20px;color:#ffd700">🎲 Открываем...</div>';
let tw=0,kc=0,gc=0;
wins.forEach((it,idx)=>{
inventory.push({...it,id:Date.now()+Math.random()+idx});
tw+=it.price;
if(it.rarity==='knife')kc++;
if(it.rarity==='gloves')gc++;
setTimeout(()=>{
SFX.tick();
const d=document.createElement('div');
d.className=`multi-item rarity-${it.rarity} ${it.rarity==='knife'||it.rarity==='gloves'?'knife-pulse':''}`;
d.innerHTML=`<img src="${iconUrl(it.icon)}"><div class="name">${it.name}</div><div class="price">${it.price} ₽</div>`;
mg.appendChild(d);
},idx*sp.multiDelay);
});
setTimeout(()=>{
const p=tw-cost,pc=p>=0?'profit':'loss',ps=p>=0?'+':'';
ms.innerHTML=`<div class="stat-box"><div class="label">Потрачено</div><div class="value">${cost} ₽</div></div>
<div class="stat-box"><div class="label">Выиграно</div><div class="value profit">${tw} ₽</div></div>
<div class="stat-box"><div class="label">Профит</div><div class="value ${pc}">${ps}${p} ₽</div></div>
${kc>0?`<div class="stat-box"><div class="label">🗡️ Ножей</div><div class="value" style="color:#ffd700">${kc}</div></div>`:''}
${gc>0?`<div class="stat-box"><div class="label">🧤 Перчаток</div><div class="value" style="color:#14b8a6">${gc}</div></div>`:''}`;
renderInventory();
if(kc>0){SFX.knife();showBigMeme('🗡️',`${kc} НОЖ(А)!`,randMeme(MEMES.knifeWin));notify(`🗡️ ДЖЕКПОТ! ${kc} нож(а)!`,'#ffd700',null,randMeme(MEMES.knifeWin))}
else if(gc>0){SFX.win();showBigMeme('🧤',`${gc} ПЕРЧАТКИ!`,randMeme(MEMES.legendaryWin));notify(`🧤 ${gc} перчаток!`,'#14b8a6',null,randMeme(MEMES.legendaryWin))}
else if(p>=0){SFX.win();notify(`В плюсе на ${p} ₽`,'#7fff00',null,randMeme(MEMES.epicWin))}
else{SFX.lose();notify(`Убыток ${Math.abs(p)} ₽`,'#ef4444',null,randMeme(MEMES.lose))}
isOpening=false;setBtns(false);
},wins.length*sp.multiDelay+500);
}
}

function renderInventory(){
const ic=document.getElementById('invCount'),ig=document.getElementById('inventoryGrid');
ic.textContent=inventory.length;
if(inventory.length===0){ig.innerHTML='<div class="empty">Инвентарь пуст. Как и твоя жизнь.</div>';return}
ig.innerHTML='';
[...inventory].sort((a,b)=>{
const o={knife:0,gloves:1,legendary:2,epic:3,rare:4,common:5};
return o[a.rarity]!==o[b.rarity]?o[a.rarity]-o[b.rarity]:b.price-a.price;
}).forEach(it=>{
const d=document.createElement('div');d.className=`inv-item rarity-${it.rarity}`;
d.innerHTML=`<img src="${iconUrl(it.icon)}"><div class="name">${it.name}</div><div class="price">${it.price} ₽</div>`;
d.onclick=()=>{SFX.coin();sellItem(it.id)};ig.appendChild(d);
});
}
function sellItem(id){
const it=inventory.find(i=>i.id===id);if(!it)return;
balance+=it.price;inventory=inventory.filter(i=>i.id!==id);
updateBalance();renderInventory();notify(`💸 ${it.name} за ${it.price} ₽`,'#7fff00',it.icon);
renderUpgradePanels();
}
function sellAll(){
if(inventory.length===0)return;
const t=inventory.reduce((s,i)=>s+i.price,0);
balance+=t;inventory=[];updateBalance();renderInventory();
SFX.coin();notify(`💸 Продано всё за ${t} ₽`,'#7fff00',null,'БАЗА');renderUpgradePanels();
}

// ============ КОЛЕСО ============
const wheelCanvas=document.getElementById('wheelCanvas'),wheelCtx=wheelCanvas.getContext('2d');
let wheelRotation=0,isSpinning=false;
const WHEEL_SEGS=[{t:'knife'},{t:'bullet'},{t:'bullet'},{t:'knife'},{t:'bullet'},{t:'bullet'},{t:'bullet'},{t:'knife'},{t:'bullet'},{t:'bullet'}];
const wKI=new Image();wKI.src=iconUrl('karambit');
const wBI=new Image();wBI.src=iconUrl('bullet');
document.getElementById('wheelKnifeImg').src=iconUrl('karambit');
document.getElementById('wheelBulletImg').src=iconUrl('bullet');
document.getElementById('wheelCenterImg').src=iconUrl('target');

function drawWheel(){
const cx=wheelCanvas.width/2,cy=wheelCanvas.height/2,r=cx-5,n=WHEEL_SEGS.length,sa=Math.PI*2/n;
for(let i=0;i<n;i++){
const s=i*sa,e=s+sa,isK=WHEEL_SEGS[i].t==='knife';
const g=wheelCtx.createRadialGradient(cx,cy,20,cx,cy,r);
if(isK){g.addColorStop(0,'#fcd34d');g.addColorStop(1,'#b45309')}
else{g.addColorStop(0,'#6b7280');g.addColorStop(1,'#1f2937')}
wheelCtx.beginPath();wheelCtx.moveTo(cx,cy);wheelCtx.arc(cx,cy,r,s,e);wheelCtx.closePath();
wheelCtx.fillStyle=g;wheelCtx.fill();wheelCtx.strokeStyle='#fff';wheelCtx.lineWidth=2;wheelCtx.stroke();
wheelCtx.save();wheelCtx.translate(cx,cy);wheelCtx.rotate(s+sa/2);
wheelCtx.textAlign='center';wheelCtx.fillStyle='#fff';wheelCtx.font='bold 14px Arial';
wheelCtx.fillText(isK?'+2500₽':'0₽',r*.42,6);wheelCtx.restore();
const im=isK?wKI:wBI;
if(im.complete&&im.naturalWidth>0){
wheelCtx.save();wheelCtx.translate(cx,cy);wheelCtx.rotate(s+sa/2);
wheelCtx.drawImage(im,r*.65-18,-18,36,36);wheelCtx.restore();
}
}
wheelCtx.beginPath();wheelCtx.arc(cx,cy,r,0,Math.PI*2);
wheelCtx.strokeStyle='#ffd700';wheelCtx.lineWidth=5;wheelCtx.stroke();
}
let il=0;function onIL(){il++;if(il>=2)drawWheel()}
wKI.onload=onIL;wBI.onload=onIL;
setTimeout(()=>{if(il<2)drawWheel()},500);

function spinWheel(){
if(isSpinning)return;
if(balance<500){notify('❌ Нужно 500 ₽','#ff4444',null,randMeme(MEMES.lose));SFX.lose();return}
isSpinning=true;balance-=500;updateBalance();
document.getElementById('wheelBtn').disabled=true;
document.getElementById('wheelResult').textContent='';
SFX.open();
mcProfile.stats.wheelSpins++;
mcProfile.stats.spent+=500;
addMCXP(15);
saveMCProfile();
const isWin=Math.random()<.3;
const n=WHEEL_SEGS.length,sa=360/n;
const ki=WHEEL_SEGS.map((s,i)=>s.t==='knife'?i:-1).filter(i=>i>=0);
const bi=WHEEL_SEGS.map((s,i)=>s.t==='bullet'?i:-1).filter(i=>i>=0);
const ts=isWin?ki[Math.floor(Math.random()*ki.length)]:bi[Math.floor(Math.random()*bi.length)];
const sc=ts*sa+sa/2,fs=6+Math.floor(Math.random()*3);
const fr=wheelRotation+fs*360+(270-sc)+(Math.random()-.5)*sa*.6;
wheelCanvas.style.transition='transform 5s cubic-bezier(.17,.67,.21,.99)';
wheelCanvas.style.transform=`rotate(${fr}deg)`;wheelRotation=fr;
let wheelTicks=0;
const wheelTickInt=setInterval(()=>{SFX.wheel();wheelTicks++;if(wheelTicks>50)clearInterval(wheelTickInt)},100);
setTimeout(()=>{
clearInterval(wheelTickInt);
const wr=document.getElementById('wheelResult');
if(isWin){
balance+=2500;updateBalance();
wr.innerHTML=`<img src="${iconUrl('karambit')}" style="width:40px;height:40px;vertical-align:middle"> НОЖ! +2500 ₽`;
wr.className='wheel-result win';
SFX.knife();
showBigMeme('🗡️','+2500 ₽',randMeme(MEMES.knifeWin));
notify('🗡️ ДЖЕКПОТ! +2500 ₽','#ffd700','karambit',randMeme(MEMES.knifeWin));
}else{
wr.innerHTML=`<img src="${iconUrl('bullet')}" style="width:40px;height:40px;vertical-align:middle"> Патрон... 0 ₽`;
wr.className='wheel-result lose';
SFX.lose();
notify('🔩 Патрон... 0 ₽','#718096','bullet',randMeme(MEMES.lose));
}
isSpinning=false;document.getElementById('wheelBtn').disabled=false;
},5100);
}

// ============ АПГРЕЙДЕР ============
let selSrcId=null,selTgtKey=null,isUpgrading=false;

function renderUpgradePanels(){
const us=document.getElementById('upgradeSource'),ut=document.getElementById('upgradeTarget');
us.innerHTML='';
if(inventory.length===0)us.innerHTML='<div class="empty">Инвентарь пуст</div>';
else inventory.forEach(it=>{
const d=document.createElement('div');
d.className=`upgrade-item rarity-${it.rarity} ${selSrcId===it.id?'selected':''}`;
d.innerHTML=`<img src="${iconUrl(it.icon)}"><div class="name">${it.name}</div><div class="price">${it.price} ₽</div>`;
d.onclick=()=>{if(isUpgrading)return;SFX.click();selSrcId=it.id;renderUpgradePanels()};
us.appendChild(d);
});
ut.innerHTML='';
allUpgradeTargets.forEach(it=>{
const k=it.name+'_'+it.price;
const d=document.createElement('div');
d.className=`upgrade-item rarity-${it.rarity} ${selTgtKey===k?'selected':''}`;
d.innerHTML=`<img src="${iconUrl(it.icon)}"><div class="name">${it.name}</div><div class="price">${it.price} ₽</div>`;
d.onclick=()=>{if(isUpgrading)return;SFX.click();selTgtKey=k;renderUpgradePanels()};
ut.appendChild(d);
});
updateUpgradeCircle();updateUpgradeBtn();
}
function getSrc(){return inventory.find(i=>i.id===selSrcId)}
function getTgt(){if(!selTgtKey)return null;return allUpgradeTargets.find(i=>i.name+'_'+i.price===selTgtKey)}
function calcChance(){
const s=getSrc(),t=getTgt();
if(!s||!t||s.price>=t.price)return 0;
let c=(s.price/t.price)*90;
return Math.max(3,Math.min(85,Math.round(c*10)/10));
}
function updateUpgradeCircle(){
const cv=document.getElementById('upgradeCanvas'),cx=cv.getContext('2d');
const ch=calcChance(),c=cv.width/2,r=c-10;
cx.clearRect(0,0,cv.width,cv.height);
cx.beginPath();cx.arc(c,c,r,0,Math.PI*2);cx.fillStyle='#991b1b';cx.fill();
if(ch>0){
const a=(ch/100)*Math.PI*2;
cx.beginPath();cx.moveTo(c,c);cx.arc(c,c,r,-Math.PI/2,-Math.PI/2+a);cx.closePath();
const g=cx.createRadialGradient(c,c,20,c,c,r);
g.addColorStop(0,'#10b981');g.addColorStop(1,'#047857');cx.fillStyle=g;cx.fill();
}
cx.beginPath();cx.arc(c,c,r,0,Math.PI*2);cx.strokeStyle='#ffd700';cx.lineWidth=3;cx.stroke();
const pe=document.getElementById('upgradePercent');
if(ch>0){pe.textContent=ch+'%';pe.style.color=ch>50?'#7fff00':ch>20?'#fbbf24':'#ef4444'}
else{pe.textContent='—%';pe.style.color='#fff'}
}
function updateUpgradeBtn(){document.getElementById('upgradeBtn').disabled=calcChance()<=0}

function doUpgrade(){
if(isUpgrading)return;
const ch=calcChance();if(ch<=0)return;
const s=getSrc(),t=getTgt();if(!s||!t)return;
isUpgrading=true;
document.getElementById('upgradeBtn').disabled=true;
document.getElementById('upgradeResult').textContent='';
SFX.upgrade();
mcProfile.stats.upgradesTried++;
addMCXP(20);
saveMCProfile();
const cv=document.getElementById('upgradeCanvas');
const sp=5+Math.random()*3,fa=Math.random()*360;
cv.style.transform=`rotate(${sp*360+fa}deg)`;
let upTicks=0;
const upTickInt=setInterval(()=>{SFX.tick();upTicks++;if(upTicks>40)clearInterval(upTickInt)},100);
setTimeout(()=>{
clearInterval(upTickInt);
const win=Math.random()*100<ch;
inventory=inventory.filter(i=>i.id!==s.id);
const re=document.getElementById('upgradeResult');
if(win){
inventory.push({...t,id:Date.now()+Math.random(),rarity:t.rarity});
re.textContent=`🎉 УСПЕХ! ${t.name}`;re.className='upgrade-result win';
SFX.knife();
showBigMeme('⚡','УСПЕХ!',randMeme(MEMES.upgradeWin));
notify(`⚡ Апгрейд успешен!`,'#7fff00',t.icon,randMeme(MEMES.upgradeWin));
}else{
re.textContent=`💀 ПРОВАЛ! -${s.name}`;re.className='upgrade-result lose';
SFX.lose();
notify(`💔 Апгрейд провален`,'#ef4444',s.icon,randMeme(MEMES.upgradeLose));
}
cv.style.transition='none';cv.style.transform='rotate(0deg)';
setTimeout(()=>{cv.style.transition='transform 4s cubic-bezier(.17,.67,.21,.99)'},50);
selSrcId=null;selTgtKey=null;
renderInventory();renderUpgradePanels();isUpgrading=false;
},4100);
}

// ============ ПРОФИЛЬ И РАНГИ ============
const MC_RANKS=[
{xp:0,name:'Мусорный новичок',icon:'🗑️'},
{xp:100,name:'Пакетник',icon:'🛍️'},
{xp:300,name:'Скуф-трейдер',icon:'🧔'},
{xp:700,name:'Кейсоман',icon:'📦'},
{xp:1500,name:'Дропхантер',icon:'🎯'},
{xp:3000,name:'Легенда помойки',icon:'🗿'},
{xp:6000,name:'MusorCase King',icon:'👑'}
];

let mcProfile=JSON.parse(localStorage.getItem('mcProfile')||'null')||{
nick:'Мусорщик',
xp:0,
stats:{casesOpened:0,spent:0,wheelSpins:0,upgradesTried:0,tradesDone:0,tradeProfit:0,gamesPlayed:0}
};

function saveMCProfile(){localStorage.setItem('mcProfile',JSON.stringify(mcProfile))}

function getRankInfo(xp){
let current=MC_RANKS[0],next=null;
for(let i=0;i<MC_RANKS.length;i++){
if(xp>=MC_RANKS[i].xp){current=MC_RANKS[i];next=MC_RANKS[i+1]||null}
}
let progress=100;
if(next){progress=((xp-current.xp)/(next.xp-current.xp))*100;progress=Math.max(0,Math.min(100,progress))}
return{current,next,progress};
}

function addMCXP(amount){
const oldRank=getRankInfo(mcProfile.xp).current.name;
mcProfile.xp+=amount;
const newRank=getRankInfo(mcProfile.xp).current.name;
saveMCProfile();
if(oldRank!==newRank){
SFX.win();
showBigMeme('🏆','НОВЫЙ РАНГ!',newRank);
notify(`Новый ранг: ${newRank}`,'#ffd700',null,'ИЗИ КАТКА');
}
if(document.getElementById('section-profile').classList.contains('active'))renderProfile();
}

function getBestInventoryItem(){
if(!inventory.length)return null;
return[...inventory].sort((a,b)=>b.price-a.price)[0];
}

function renderProfile(){
const box=document.getElementById('profileContent');
if(!box)return;
const rank=getRankInfo(mcProfile.xp);
const best=getBestInventoryItem();
const invValue=inventory.reduce((s,i)=>s+i.price,0);
box.innerHTML=`
<div class="profile-grid">
<div class="profile-box">
<div class="label">Ник</div>
<div class="value" style="font-size:18px">${mcProfile.nick}</div>
<button class="profile-btn" onclick="editNickname()">Сменить ник</button>
</div>
<div class="profile-box">
<div class="label">Ранг</div>
<div class="rank-badge">${rank.current.icon} ${rank.current.name}</div>
<div style="margin-top:8px;color:#aaa">XP: ${mcProfile.xp}</div>
<div class="rank-progress"><div class="rank-progress-fill" style="width:${rank.progress}%"></div></div>
<div style="font-size:12px;color:#aaa;margin-top:6px">${rank.next?`До следующего: ${rank.next.xp-mcProfile.xp} XP`:'Максимальный ранг'}</div>
</div>
<div class="profile-box">
<div class="label">Баланс</div>
<div class="value">${balance} ₽</div>
</div>
<div class="profile-box">
<div class="label">Стоимость инвентаря</div>
<div class="value">${invValue} ₽</div>
</div>
<div class="profile-box">
<div class="label">Открыто кейсов</div>
<div class="value">${mcProfile.stats.casesOpened}</div>
</div>
<div class="profile-box">
<div class="label">Потрачено</div>
<div class="value">${mcProfile.stats.spent} ₽</div>
</div>
<div class="profile-box">
<div class="label">Круток колеса</div>
<div class="value">${mcProfile.stats.wheelSpins}</div>
</div>
<div class="profile-box">
<div class="label">Апгрейдов</div>
<div class="value">${mcProfile.stats.upgradesTried}</div>
</div>
<div class="profile-box">
<div class="label">Трейдов с ботами</div>
<div class="value">${mcProfile.stats.tradesDone}</div>
</div>
<div class="profile-box">
<div class="label">Профит трейдов</div>
<div class="value" style="color:${mcProfile.stats.tradeProfit>=0?'#7fff00':'#ef4444'}">${mcProfile.stats.tradeProfit>=0?'+':''}${mcProfile.stats.tradeProfit} ₽</div>
</div>
<div class="profile-box">
<div class="label">Игр запущено</div>
<div class="value">${mcProfile.stats.gamesPlayed}</div>
</div>
<div class="profile-box">
<div class="label">Лучший дроп</div>
${best?`<img src="${iconUrl(best.icon)}" style="width:80px;height:80px;object-fit:contain"><div class="value" style="font-size:16px">${best.name}</div><div style="color:#7fff00;font-weight:bold">${best.price} ₽</div>`:`<div class="value" style="font-size:16px;color:#aaa">Пока ничего</div>`}
</div>
</div>`;
}

function editNickname(){
const nick=prompt('Введи новый ник:',mcProfile.nick);
if(!nick)return;
mcProfile.nick=nick.slice(0,20);
saveMCProfile();
renderProfile();
SFX.click();
}

// ============ ТРЕЙДЫ С БОТАМИ ============
let tradeSourceId=null;
let tradeOffers=[];

const BOT_NAMES=['Bot_Musor228','СкуфTrader','КейсовыйДед','NoobKillerBot','Мамонт_Exchange','РандомныйБарыга','TradeBot_3000'];
const BOT_COMMENTS=['Брат, это выгодно, зуб даю.','Я почти не наживаюсь, честно.','Это не скам, это маркетинг.','Давай быстрее, а то передумаю.','У меня таких скинов склад.','Мне просто по кайфу обменяться.','Ну что ты как не родной, соглашайся.','Ты что, лох? Это же халява.','Я тебя не обманываю, клянусь мамой.','Скину ещё сверху если быстро согласен.'];

function getAllTradeSkins(){
return Object.entries(allItems).flatMap(([rarity,items])=>items.map(i=>({...i,rarity})));
}

function makeBotOffers(source){
const pool=getAllTradeSkins();
return Array.from({length:3},()=>{
const multiplier=0.65+Math.random()*0.95;
const targetPrice=source.price*multiplier;
const candidates=pool.filter(i=>i.price>=targetPrice*0.65&&i.price<=targetPrice*1.35).sort(()=>Math.random()-0.5);
const item=candidates[0]||pool[Math.floor(Math.random()*pool.length)];
return{bot:BOT_NAMES[Math.floor(Math.random()*BOT_NAMES.length)],comment:BOT_COMMENTS[Math.floor(Math.random()*BOT_COMMENTS.length)],item};
});
}

function renderTradePanel(){
const sourceBox=document.getElementById('tradeSource');
const offersBox=document.getElementById('botOffers');
if(!sourceBox||!offersBox)return;
sourceBox.innerHTML='';
if(!inventory.length){
sourceBox.innerHTML='<div class="empty">Инвентарь пуст. Нечего трейдить.</div>';
offersBox.innerHTML='<div class="empty">Сначала открой кейс</div>';
return;
}
[...inventory].sort((a,b)=>b.price-a.price).forEach(item=>{
const div=document.createElement('div');
div.className=`inv-item rarity-${item.rarity} ${tradeSourceId===item.id?'trade-selected':''}`;
div.innerHTML=`<img src="${iconUrl(item.icon)}"><div class="name">${item.name}</div><div class="price">${item.price} ₽</div>`;
div.onclick=()=>selectTradeSource(item.id);
sourceBox.appendChild(div);
});
const source=inventory.find(i=>i.id===tradeSourceId);
if(!source){offersBox.innerHTML='<div class="empty">Выбери скин слева</div>';return}
if(!tradeOffers.length||tradeOffers._srcId!==tradeSourceId){
tradeOffers=makeBotOffers(source);
tradeOffers._srcId=tradeSourceId;
}
offersBox.innerHTML='';
tradeOffers.forEach((offer,index)=>{
const diff=offer.item.price-source.price;
const div=document.createElement('div');
div.className=`bot-offer rarity-${offer.item.rarity}`;
div.innerHTML=`
<img src="${iconUrl(offer.item.icon)}">
<div>
<div class="bot-name">🤖 ${offer.bot}</div>
<div style="font-weight:bold">${offer.item.name}</div>
<div class="bot-price">${offer.item.price} ₽</div>
<div style="font-size:12px;color:${diff>=0?'#7fff00':'#ef4444'}">${diff>=0?'+':''}${diff} ₽ к твоему скину</div>
<div class="bot-comment">${offer.comment}</div>
</div>
<button class="trade-accept" onclick="acceptBotTrade(${index})">Принять</button>`;
offersBox.appendChild(div);
});
}

function selectTradeSource(id){
SFX.click();
tradeSourceId=id;
tradeOffers=[];
renderTradePanel();
}

function acceptBotTrade(index){
const source=inventory.find(i=>i.id===tradeSourceId);
const offer=tradeOffers[index];
if(!source||!offer){notify('Трэйд сломался. Бот убежал.','#ef4444');return}
const profit=offer.item.price-source.price;
inventory=inventory.filter(i=>i.id!==source.id);
inventory.push({...offer.item,id:Date.now()+Math.random()});
mcProfile.stats.tradesDone++;
mcProfile.stats.tradeProfit+=profit;
addMCXP(30);
saveMCProfile();
tradeSourceId=null;
tradeOffers=[];
SFX.coin();
if(profit>=0){
notify(`Трэйд принят: +${profit} ₽`,'#7fff00',offer.item.icon,randMeme(MEMES.tradeWin));
if(profit>=500)showBigMeme('🤖','БОТ ПРОИГРАЛ!',randMeme(MEMES.tradeWin));
}else{
notify(`Трэйд принят: ${profit} ₽`,'#ef4444',offer.item.icon,randMeme(MEMES.tradeLose));
}
renderInventory();
renderTradePanel();
renderUpgradePanels();
renderProfile();
}

// ============ GEOMETRY DASH ============
const gdCanvas=document.getElementById('gdCanvas'),gdCtx=gdCanvas.getContext('2d');
let gd={running:false,cube:{x:100,y:200,size:40,vy:0,rot:0,onG:true},
obstacles:[],particles:[],dist:0,speed:6,base:6,grav:.8,jp:-14,gY:260,
rec:parseInt(localStorage.getItem('gdRec')||'0'),aid:null,rew:0,lrd:0,bgo:0,gro:0};
document.getElementById('gdRecord').textContent=gd.rec;

function startGame(g){
SFX.click();
document.getElementById('gamesGrid').style.display='none';
document.getElementById('gameArea-'+g).classList.add('active');
mcProfile.stats.gamesPlayed++;
addMCXP(5);
saveMCProfile();
if(g==='gd')initGD();else if(g==='pacman')initPacman();
}
function exitGame(g){
SFX.click();
if(g==='gd'){gd.running=false;if(gd.aid)cancelAnimationFrame(gd.aid)}
else if(g==='pacman'){pm.running=false;if(pm.aid)cancelAnimationFrame(pm.aid)}
document.getElementById('gamesGrid').style.display='grid';
document.getElementById('gameArea-'+g).classList.remove('active');
document.getElementById(g==='gd'?'gdGameOver':'pmGameOver').classList.remove('active');
}
function initGD(){
gd.cube={x:100,y:200,size:40,vy:0,rot:0,onG:true};
gd.obstacles=[];gd.particles=[];gd.dist=0;gd.speed=6;
gd.rew=0;gd.lrd=0;gd.bgo=0;gd.gro=0;
document.getElementById('gdGameOver').classList.remove('active');
gd.running=true;gdLoop();
}
function restartGD(){initGD()}
function gdJump(){
if(!gd.running||!gd.cube.onG)return;
gd.cube.vy=gd.jp;gd.cube.onG=false;
SFX.jump();
for(let i=0;i<6;i++)gd.particles.push({x:gd.cube.x+gd.cube.size/2,y:gd.cube.y+gd.cube.size,vx:(Math.random()-.5)*4,vy:Math.random()*3,life:20,color:'#ffd700',size:3+Math.random()*3});
}
function spawnObs(){
const t=['spike','spike','spike','block','doubleSpike'][Math.floor(Math.random()*5)];
let w,h,y;
if(t==='spike'){w=30;h=40;y=gd.gY-h}
else if(t==='doubleSpike'){w=60;h=40;y=gd.gY-h}
else{w=40;h=40;y=Math.random()<.5?gd.gY-h:gd.gY-h-70}
gd.obstacles.push({t,x:850,y,w,h});
}
function chkCol(c,o){
if(o.t==='spike'||o.t==='doubleSpike'){
const cx=c.x+c.size/2,cy=c.y+c.size/2,r=c.size*.4;
return cx+r>o.x&&cx-r<o.x+o.w&&cy+r>o.y&&cy-r<o.y+o.h&&cy+r>o.y+o.h*.4;
}
return c.x<o.x+o.w&&c.x+c.size>o.x&&c.y<o.y+o.h&&c.y+c.size>o.y;
}
function gdLoop(){
if(!gd.running)return;
gd.cube.vy+=gd.grav;gd.cube.y+=gd.cube.vy;
if(gd.cube.y+gd.cube.size>=gd.gY){gd.cube.y=gd.gY-gd.cube.size;gd.cube.vy=0;gd.cube.onG=true}
if(!gd.cube.onG)gd.cube.rot+=.15;
else{const t=Math.round(gd.cube.rot/(Math.PI/2))*(Math.PI/2);gd.cube.rot+=(t-gd.cube.rot)*.3}
gd.dist+=gd.speed*.1;gd.speed=gd.base+gd.dist*.005;if(gd.speed>14)gd.speed=14;
const m=Math.floor(gd.dist),rt=Math.floor(m/10);
if(rt>gd.lrd){gd.rew+=rt-gd.lrd;gd.lrd=rt}
const mg=Math.max(180,300-gd.dist*.3);
if(gd.obstacles.length===0||(800-gd.obstacles[gd.obstacles.length-1].x)>mg+Math.random()*150)spawnObs();
gd.obstacles.forEach(o=>o.x-=gd.speed);
gd.obstacles=gd.obstacles.filter(o=>o.x+o.w>-50);
for(const o of gd.obstacles)if(chkCol(gd.cube,o)){gameOverGD();return}
gd.particles.forEach(p=>{p.x+=p.vx;p.y+=p.vy;p.vy+=.2;p.life--});
gd.particles=gd.particles.filter(p=>p.life>0);
gd.bgo=(gd.bgo+gd.speed*.3)%100;gd.gro=(gd.gro+gd.speed)%40;
drawGD();
document.getElementById('gdDistance').textContent=Math.floor(gd.dist);
document.getElementById('gdReward').textContent=gd.rew;
gd.aid=requestAnimationFrame(gdLoop);
}
function drawGD(){
gdCtx.clearRect(0,0,800,300);
const bg=gdCtx.createLinearGradient(0,0,0,300);
bg.addColorStop(0,'#1e3a8a');bg.addColorStop(.5,'#312e81');bg.addColorStop(1,'#1e1b4b');
gdCtx.fillStyle=bg;gdCtx.fillRect(0,0,800,300);
gdCtx.fillStyle='rgba(255,255,255,.3)';
for(let i=0;i<30;i++){const x=(i*73-gd.bgo)%800,y=(i*37)%200;gdCtx.fillRect(x<0?x+800:x,y,2,2)}
gdCtx.fillStyle='#1f2937';gdCtx.fillRect(0,gd.gY,800,40);
gdCtx.strokeStyle='#4b5563';gdCtx.lineWidth=2;
for(let x=-gd.gro;x<800;x+=40){gdCtx.beginPath();gdCtx.moveTo(x,gd.gY);gdCtx.lineTo(x+20,gd.gY+40);gdCtx.stroke()}
gdCtx.strokeStyle='#8b5cf6';gdCtx.lineWidth=3;
gdCtx.beginPath();gdCtx.moveTo(0,gd.gY);gdCtx.lineTo(800,gd.gY);gdCtx.stroke();
gd.obstacles.forEach(o=>{
if(o.t==='spike'){drawSpike(o.x,o.y,o.w,o.h)}
else if(o.t==='doubleSpike'){drawSpike(o.x,o.y,30,o.h);drawSpike(o.x+30,o.y,30,o.h)}
else{
const g=gdCtx.createLinearGradient(o.x,o.y,o.x,o.y+o.h);
g.addColorStop(0,'#ef4444');g.addColorStop(1,'#991b1b');
gdCtx.fillStyle=g;gdCtx.fillRect(o.x,o.y,o.w,o.h);
gdCtx.strokeStyle='#fca5a5';gdCtx.lineWidth=2;gdCtx.strokeRect(o.x,o.y,o.w,o.h);
gdCtx.strokeStyle='#fff';gdCtx.lineWidth=2;gdCtx.beginPath();
gdCtx.moveTo(o.x+8,o.y+8);gdCtx.lineTo(o.x+o.w-8,o.y+o.h-8);
gdCtx.moveTo(o.x+o.w-8,o.y+8);gdCtx.lineTo(o.x+8,o.y+o.h-8);gdCtx.stroke();
}
});
gd.particles.forEach(p=>{gdCtx.fillStyle=p.color;gdCtx.globalAlpha=p.life/20;gdCtx.fillRect(p.x,p.y,p.size,p.size)});
gdCtx.globalAlpha=1;
gdCtx.save();gdCtx.translate(gd.cube.x+gd.cube.size/2,gd.cube.y+gd.cube.size/2);gdCtx.rotate(gd.cube.rot);
const cg=gdCtx.createLinearGradient(-20,-20,20,20);cg.addColorStop(0,'#fbbf24');cg.addColorStop(1,'#b45309');
gdCtx.fillStyle=cg;gdCtx.fillRect(-gd.cube.size/2,-gd.cube.size/2,gd.cube.size,gd.cube.size);
gdCtx.strokeStyle='#fff';gdCtx.lineWidth=3;gdCtx.strokeRect(-gd.cube.size/2,-gd.cube.size/2,gd.cube.size,gd.cube.size);
gdCtx.fillStyle='#fff';gdCtx.fillRect(-5,-8,14,14);
gdCtx.fillStyle='#000';gdCtx.fillRect(2,-5,7,8);gdCtx.restore();
}
function drawSpike(x,y,w,h){
const g=gdCtx.createLinearGradient(x,y,x,y+h);g.addColorStop(0,'#fbbf24');g.addColorStop(1,'#92400e');
gdCtx.fillStyle=g;gdCtx.beginPath();gdCtx.moveTo(x+w/2,y);gdCtx.lineTo(x,y+h);gdCtx.lineTo(x+w,y+h);gdCtx.closePath();
gdCtx.fill();gdCtx.strokeStyle='#fde68a';gdCtx.lineWidth=2;gdCtx.stroke();
}
function gameOverGD(){
gd.running=false;if(gd.aid)cancelAnimationFrame(gd.aid);
SFX.die();
const fd=Math.floor(gd.dist);
if(fd>gd.rec){gd.rec=fd;localStorage.setItem('gdRec',gd.rec);document.getElementById('gdRecord').textContent=gd.rec;notify(`🏆 Новый рекорд: ${gd.rec} м!`,'#ffd700',null,'ИЗИ')}
balance+=gd.rew;updateBalance();
document.getElementById('gdFinalDist').textContent=fd;
document.getElementById('gdFinalReward').textContent=gd.rew;
document.getElementById('gdMeme').textContent=randMeme(MEMES.gdDeath);
document.getElementById('gdGameOver').classList.add('active');
if(gd.rew>0)notify(`💰 +${gd.rew} ₽`,'#7fff00',null,randMeme(MEMES.epicWin));
}
document.addEventListener('keydown',e=>{if(e.code==='Space'&&gd.running){e.preventDefault();gdJump()}});
gdCanvas.addEventListener('mousedown',gdJump);
gdCanvas.addEventListener('touchstart',e=>{e.preventDefault();gdJump()});

// ============ PAC-MAN ============
const pmCanvas=document.getElementById('pacmanCanvas'),pmCtx=pmCanvas.getContext('2d');
const PM_CELL=16;
const PM_MAP=[
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,2,2,2,2,2,2,1],
[1,2,1,1,1,1,2,1,1,1,1,1,2,1,1,2,1,1,1,1,1,2,1,1,1,1,2,1],
[1,3,1,1,1,1,2,1,1,1,1,1,2,1,1,2,1,1,1,1,1,2,1,1,1,1,3,1],
[1,2,1,1,1,1,2,1,1,1,1,1,2,1,1,2,1,1,1,1,1,2,1,1,1,1,2,1],
[1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1],
[1,2,1,1,1,1,2,1,1,2,1,1,1,1,1,1,1,1,2,1,1,2,1,1,1,1,2,1],
[1,2,1,1,1,1,2,1,1,2,1,1,1,1,1,1,1,1,2,1,1,2,1,1,1,1,2,1],
[1,2,2,2,2,2,2,1,1,2,2,2,2,1,1,2,2,2,2,1,1,2,2,2,2,2,2,1],
[1,1,1,1,1,1,2,1,1,1,1,1,0,1,1,0,1,1,1,1,1,2,1,1,1,1,1,1],
[0,0,0,0,0,1,2,1,1,1,1,1,0,1,1,0,1,1,1,1,1,2,1,0,0,0,0,0],
[0,0,0,0,0,1,2,1,1,0,0,0,0,0,0,0,0,0,0,1,1,2,1,0,0,0,0,0],
[0,0,0,0,0,1,2,1,1,0,1,1,1,0,0,1,1,1,0,1,1,2,1,0,0,0,0,0],
[1,1,1,1,1,1,2,1,1,0,1,0,0,0,0,0,0,1,0,1,1,2,1,1,1,1,1,1],
[0,0,0,0,0,0,2,0,0,0,1,0,0,0,0,0,0,1,0,0,0,2,0,0,0,0,0,0],
[1,1,1,1,1,1,2,1,1,0,1,0,0,0,0,0,0,1,0,1,1,2,1,1,1,1,1,1],
[0,0,0,0,0,1,2,1,1,0,1,1,1,1,1,1,1,1,0,1,1,2,1,0,0,0,0,0],
[0,0,0,0,0,1,2,1,1,0,0,0,0,0,0,0,0,0,0,1,1,2,1,0,0,0,0,0],
[0,0,0,0,0,1,2,1,1,0,1,1,1,1,1,1,1,1,0,1,1,2,1,0,0,0,0,0],
[1,1,1,1,1,1,2,1,1,0,1,1,1,1,1,1,1,1,0,1,1,2,1,1,1,1,1,1],
[1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,2,2,2,2,2,2,1],
[1,2,1,1,1,1,2,1,1,1,1,1,2,1,1,2,1,1,1,1,1,2,1,1,1,1,2,1],
[1,3,2,2,1,1,2,2,2,2,2,2,2,0,0,2,2,2,2,2,2,2,1,1,2,2,3,1],
[1,1,1,2,1,1,2,1,1,2,1,1,1,1,1,1,1,1,2,1,1,2,1,1,2,1,1,1],
[1,2,2,2,2,2,2,1,1,2,2,2,2,1,1,2,2,2,2,1,1,2,2,2,2,2,2,1],
[1,2,1,1,1,1,1,1,1,1,1,1,2,1,1,2,1,1,1,1,1,1,1,1,1,1,2,1],
[1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];
const PM_W=28,PM_H=28;
let pm={running:false,pac:{x:13.5,y:22.5,dir:0,nextDir:0,mouth:0},
ghosts:[],map:[],score:0,lives:3,rew:0,rec:parseInt(localStorage.getItem('pmRec')||'0'),
aid:null,pellets:0,powerTimer:0};
document.getElementById('pmRecord').textContent=pm.rec;

function initPacman(){
pm.map=PM_MAP.map(r=>[...r]);
pm.pac={x:13.5,y:22.5,dir:0,nextDir:0,mouth:0};
pm.ghosts=[
{x:13.5,y:13.5,dir:0,color:'#ef4444',mode:'chase',startX:13.5,startY:13.5},
{x:12.5,y:13.5,dir:0,color:'#3b82f6',mode:'chase',startX:12.5,startY:13.5},
{x:14.5,y:13.5,dir:2,color:'#ec4899',mode:'chase',startX:14.5,startY:13.5},
{x:13.5,y:12.5,dir:2,color:'#f97316',mode:'chase',startX:13.5,startY:12.5}
];
pm.score=0;pm.lives=3;pm.rew=0;pm.powerTimer=0;
pm.pellets=0;
for(let y=0;y<PM_H;y++)for(let x=0;x<PM_W;x++)if(pm.map[y][x]===2||pm.map[y][x]===3)pm.pellets++;
document.getElementById('pmGameOver').classList.remove('active');
pm.running=true;pmLoop();
}
function restartPacman(){initPacman()}

function pmCanMove(x,y,dir){
const dx=[1,0,-1,0][dir],dy=[0,1,0,-1][dir];
const nx=x+dx*.5,ny=y+dy*.5;
const cx=Math.floor(nx+dx*.4),cy=Math.floor(ny+dy*.4);
if(cx<0||cx>=PM_W||cy<0||cy>=PM_H){
if(cy===13&&(cx<0||cx>=PM_W))return true;
return false;
}
return pm.map[cy][cx]!==1;
}

function pmLoop(){
if(!pm.running)return;
const p=pm.pac;
const spd=.08;
const dx=[1,0,-1,0][p.dir],dy=[0,1,0,-1][p.dir];
let nx=p.x+dx*spd,ny=p.y+dy*spd;
const cx=Math.floor(nx+(dx>0?.4:dx<0?-.4:0));
const cy=Math.floor(ny+(dy>0?.4:dy<0?-.4:0));
if(cx<0||cx>=PM_W){nx=nx<0?PM_W-1:0}
else if(cy<0||cy>=PM_H||pm.map[cy][cx]===1){nx=p.x;ny=p.y}
p.x=nx;p.y=ny;
if(p.nextDir!==p.dir&&pmCanMove(p.x,p.y,p.nextDir))p.dir=p.nextDir;
p.mouth=(p.mouth+.15)%(Math.PI*.8);

const tx=Math.floor(p.x),ty=Math.floor(p.y);
if(tx>=0&&tx<PM_W&&ty>=0&&ty<PM_H){
if(pm.map[ty][tx]===2){pm.map[ty][tx]=0;pm.score+=10;pm.pellets--;SFX.coin()}
else if(pm.map[ty][tx]===3){pm.map[ty][tx]=0;pm.score+=50;pm.pellets--;pm.powerTimer=300;SFX.powerup()}
}
const newRew=Math.floor(pm.score/10);
if(newRew>pm.rew){pm.rew=newRew}

if(pm.powerTimer>0)pm.powerTimer--;

pm.ghosts.forEach(g=>{
const gspd=.06;
const gdx=[1,0,-1,0][g.dir],gdy=[0,1,0,-1][g.dir];
let gnx=g.x+gdx*gspd,gny=g.y+gdy*gspd;
const gcx=Math.floor(gnx+(gdx>0?.4:gdx<0?-.4:0));
const gcy=Math.floor(gny+(gdy>0?.4:gdy<0?-.4:0));
if(gcx<0||gcx>=PM_W){gnx=gnx<0?PM_W-1:0}
else if(gcy<0||gcy>=PM_H||pm.map[gcy][gcx]===1){
const possible=[];
for(let d=0;d<4;d++){
if(d===(g.dir+2)%4)continue;
const ddx=[1,0,-1,0][d],ddy=[0,1,0,-1][d];
const tcx=Math.floor(g.x+ddx),tcy=Math.floor(g.y+ddy);
if(tcx<0||tcx>=PM_W){if(tcy===13)possible.push(d)}
else if(tcy>=0&&tcy<PM_H&&pm.map[tcy][tcx]!==1)possible.push(d);
}
if(possible.length>0){
if(g.mode==='frightened')g.dir=possible[Math.floor(Math.random()*possible.length)];
else{
let best=possible[0],bestD=Infinity;
possible.forEach(d=>{
const ddx=[1,0,-1,0][d],ddy=[0,1,0,-1][d];
const dist=Math.abs(g.x+ddx-p.x)+Math.abs(g.y+ddy-p.y);
if(dist<bestD){bestD=dist;best=d}
});
g.dir=best;
}
gnx=g.x;gny=g.y;
}
}
g.x=gnx;g.y=gny;
if(Math.abs(g.x-p.x)<.7&&Math.abs(g.y-p.y)<.7){
if(g.mode==='frightened'){
g.x=g.startX;g.y=g.startY;g.mode='chase';pm.score+=200;
SFX.powerup();
}else{
pm.lives--;SFX.die();
if(pm.lives<=0){gameOverPM();return}
p.x=13.5;p.y=22.5;p.dir=0;p.nextDir=0;
pm.ghosts.forEach(gg=>{gg.x=gg.startX;gg.y=gg.startY;gg.mode='chase'});
}
}
if(pm.powerTimer>0&&g.mode!=='frightened')g.mode='frightened';
if(pm.powerTimer===0&&g.mode==='frightened')g.mode='chase';
});

drawPM();
document.getElementById('pmScore').textContent=pm.score;
document.getElementById('pmReward').textContent=pm.rew;
document.getElementById('pmLives').textContent=pm.lives;

if(pm.pellets===0){notify('🎉 Уровень пройден!','#ffd700',null,'ИЗИ КАТКА');pm.running=false;setTimeout(()=>{initPacman();pm.score+=1000},1500);return}
pm.aid=requestAnimationFrame(pmLoop);
}

function drawPM(){
pmCtx.fillStyle='#000';pmCtx.fillRect(0,0,448,496);
for(let y=0;y<PM_H;y++){
for(let x=0;x<PM_W;x++){
const c=pm.map[y][x];
if(c===1){
pmCtx.fillStyle='#1e3a8a';
pmCtx.fillRect(x*PM_CELL,y*PM_CELL,PM_CELL,PM_CELL);
pmCtx.strokeStyle='#3b82f6';pmCtx.lineWidth=1;
pmCtx.strokeRect(x*PM_CELL+.5,y*PM_CELL+.5,PM_CELL-1,PM_CELL-1);
}else if(c===2){
pmCtx.fillStyle='#fbbf24';
pmCtx.beginPath();pmCtx.arc(x*PM_CELL+PM_CELL/2,y*PM_CELL+PM_CELL/2,2,0,Math.PI*2);pmCtx.fill();
}else if(c===3){
pmCtx.fillStyle='#fbbf24';
pmCtx.beginPath();pmCtx.arc(x*PM_CELL+PM_CELL/2,y*PM_CELL+PM_CELL/2,5,0,Math.PI*2);pmCtx.fill();
}
}
}
const p=pm.pac,px=p.x*PM_CELL+PM_CELL/2,py=p.y*PM_CELL+PM_CELL/2;
const angles=[0,Math.PI/2,Math.PI,-Math.PI/2];
const a=angles[p.dir];
pmCtx.fillStyle='#fbbf24';
pmCtx.beginPath();
pmCtx.moveTo(px,py);
pmCtx.arc(px,py,PM_CELL*.7,a+p.mouth/2,a-p.mouth/2+Math.PI*2);
pmCtx.closePath();pmCtx.fill();
const ex=px+Math.cos(a-Math.PI/2)*3,ey=py+Math.sin(a-Math.PI/2)*3;
pmCtx.fillStyle='#000';pmCtx.beginPath();pmCtx.arc(ex,ey,1.5,0,Math.PI*2);pmCtx.fill();

pm.ghosts.forEach(g=>{
const gx=g.x*PM_CELL+PM_CELL/2,gy=g.y*PM_CELL+PM_CELL/2;
pmCtx.fillStyle=g.mode==='frightened'?(pm.powerTimer<100&&Math.floor(pm.powerTimer/10)%2===0?'#fff':'#1e40af'):g.color;
pmCtx.beginPath();
pmCtx.arc(gx,gy-2,PM_CELL*.6,Math.PI,0);
pmCtx.lineTo(gx+PM_CELL*.6,gy+PM_CELL*.5);
for(let i=0;i<3;i++){
pmCtx.lineTo(gx+PM_CELL*.6-i*PM_CELL*.4-PM_CELL*.1,gy+PM_CELL*.3);
pmCtx.lineTo(gx+PM_CELL*.6-i*PM_CELL*.4-PM_CELL*.2,gy+PM_CELL*.5);
}
pmCtx.lineTo(gx-PM_CELL*.6,gy+PM_CELL*.5);
pmCtx.closePath();pmCtx.fill();
pmCtx.fillStyle='#fff';
pmCtx.beginPath();pmCtx.arc(gx-3,gy-3,2.5,0,Math.PI*2);pmCtx.fill();
pmCtx.beginPath();pmCtx.arc(gx+3,gy-3,2.5,0,Math.PI*2);pmCtx.fill();
pmCtx.fillStyle=g.mode==='frightened'?'#fff':'#1e3a8a';
const edx=[1,0,-1,0][g.dir],edy=[0,1,0,-1][g.dir];
pmCtx.beginPath();pmCtx.arc(gx-3+edx,gy-3+edy,1.2,0,Math.PI*2);pmCtx.fill();
pmCtx.beginPath();pmCtx.arc(gx+3+edx,gy-3+edy,1.2,0,Math.PI*2);pmCtx.fill();
});
}

function gameOverPM(){
pm.running=false;if(pm.aid)cancelAnimationFrame(pm.aid);
SFX.die();
if(pm.score>pm.rec){pm.rec=pm.score;localStorage.setItem('pmRec',pm.rec);document.getElementById('pmRecord').textContent=pm.rec;notify(`🏆 Новый рекорд: ${pm.rec}`,'#ffd700',null,'ИЗИ')}
balance+=pm.rew;updateBalance();
document.getElementById('pmFinalScore').textContent=pm.score;
document.getElementById('pmFinalReward').textContent=pm.rew;
document.getElementById('pmMeme').textContent=randMeme(MEMES.pmDeath);
document.getElementById('pmGameOver').classList.add('active');
if(pm.rew>0)notify(`💰 +${pm.rew} ₽`,'#7fff00',null,randMeme(MEMES.epicWin));
}

document.addEventListener('keydown',e=>{
if(!pm.running)return;
const k=e.key.toLowerCase();
if(k==='arrowup'||k==='w'){pm.pac.nextDir=2;SFX.click()}
else if(k==='arrowdown'||k==='s'){pm.pac.nextDir=1;SFX.click()}
else if(k==='arrowleft'||k==='a'){pm.pac.nextDir=0;SFX.click()}
else if(k==='arrowright'||k==='d'){pm.pac.nextDir=3;SFX.click()}
});

// ============ ИНИЦИАЛИЗАЦИЯ ============
renderCases();
updateBalance();
renderInventory();
renderUpgradePanels();
renderProfile();
renderTradePanel();
document.addEventListener('click',()=>initAudio(),{once:true});
</script>
</body>
</html>