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


<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>MusorCase v11.0</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:24px;color:#ffd700;text-shadow:0 0 10px rgba(255,215,0,.5)}
h1 .sub{font-size:11px;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:18px;font-weight:bold;border:1px solid #4a8020}
.balance span{color:#7fff00}
.topup-btn,.sound-btn{border:none;padding:10px 15px;border-radius:8px;font-weight:bold;cursor:pointer;color:#fff}
.topup-btn{background:linear-gradient(135deg,#10b981,#059669)}
.sound-btn{background:linear-gradient(135deg,#6b7280,#374151)}
.sound-btn.on{background:linear-gradient(135deg,#10b981,#059669)}
.tabs{display:flex;gap:6px;margin-bottom:15px;flex-wrap:wrap;background:rgba(0,0,0,.4);padding:8px;border-radius:12px;border:1px solid #2a3a5e}
.tab{flex:1;min-width:85px;padding:10px 6px;background:rgba(255,255,255,.05);border:2px solid transparent;border-radius:8px;color:#fff;font-size:11px;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:20px;border-radius:12px;margin-bottom:15px;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(150px,1fr));gap:12px}
.case-card{background:rgba(255,255,255,.05);border:2px solid;border-radius:12px;padding:12px;text-align:center;cursor:pointer;transition:.2s;position:relative}
.case-card:hover{transform:translateY(-5px)}
.case-card.selected{box-shadow:0 0 20px currentColor;transform:scale(1.03)}
.case-card img{width:65px;height:65px;object-fit:contain}
.case-card .name{font-weight:bold;font-size:13px;margin:8px 0 4px}
.case-card .price{color:#7fff00;font-weight:bold;font-size:15px}
.case-card .chance{font-size:10px;color:#ffd700;margin-top:4px}
.case-card .view-btn{position:absolute;top:5px;right:5px;background:rgba(0,0,0,.6);border:1px solid #ffd700;color:#ffd700;padding:3px 6px;border-radius:4px;font-size:10px;cursor:pointer}
.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}
.case-knife{border-color:#f59e0b;color:#fcd34d}
.case-midnight{border-color:#6366f1;color:#818cf8}
.case-neon{border-color:#ec4899;color:#f472b6}
.case-lunar{border-color:#a78bfa;color:#c4b5fd}
.case-fire{border-color:#f97316;color:#fb923c}
.case-cosmic{border-color:#06b6d4;color:#22d3ee}
.speed-switcher{display:flex;justify-content:center;gap:6px;margin:12px 0;flex-wrap:wrap}
.speed-btn{background:rgba(255,255,255,.05);border:2px solid #2a3a5e;color:#fff;padding:7px 14px;border-radius:8px;cursor:pointer;font-weight:bold;font-size:12px}
.speed-btn.active{background:linear-gradient(135deg,#ffd700,#ff8c00);color:#000;border-color:#ffd700}
.open-controls{display:flex;justify-content:center;gap:8px;flex-wrap:wrap}
.open-btn{background:linear-gradient(135deg,#ffd700,#ff8c00);color:#000;border:none;padding:12px 25px;font-size:15px;font-weight:bold;border-radius:8px;cursor:pointer;min-width:100px}
.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:10px;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:15px 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:15px;flex-wrap:wrap;gap:8px}
.stat-box{background:rgba(255,255,255,.05);padding:10px 15px;border-radius:8px;text-align:center;min-width:120px}
.stat-box .label{font-size:11px;color:#aaa;margin-bottom:3px}
.stat-box .value{font-size:18px;font-weight:bold}
.stat-box .profit{color:#7fff00}.stat-box .loss{color:#ef4444}
.multi-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:10px}
.multi-item{background:rgba(255,255,255,.05);padding:10px;border-radius:8px;text-align:center;border:2px solid;opacity:0;transform:scale(.5);animation:popIn .4s forwards}
.multi-item img{width:60px;height:60px;object-fit:contain}
.multi-item .name{font-size:10px;margin:4px 0;font-weight:bold}
.multi-item .price{color:#7fff00;font-size:12px;font-weight:bold}
@keyframes popIn{to{opacity:1;transform:scale(1)}}
.inv-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;flex-wrap:wrap;gap:8px}
.sell-all-btn{background:linear-gradient(135deg,#ef4444,#991b1b);color:#fff;border:none;padding:7px 14px;border-radius:6px;cursor:pointer;font-weight:bold;font-size:12px}
.inventory-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:10px}
.inv-item{background:rgba(255,255,255,.05);padding:10px;border-radius:8px;text-align:center;border:2px solid;cursor:pointer;transition:.2s}
.inv-item:hover{transform:translateY(-3px)}
.inv-item img{width:60px;height:60px;object-fit:contain}
.inv-item .name{font-size:11px;margin:4px 0;font-weight:bold}
.inv-item .price{color:#7fff00;font-size:12px;font-weight:bold}
.empty{text-align:center;color:#888;padding:25px;font-style:italic;grid-column:1/-1}
.wheel-wrapper,.upgrade-center{display:flex;flex-direction:column;align-items:center;gap:15px}
.wheel-info{display:flex;gap:15px;flex-wrap:wrap;justify-content:center;margin-bottom:10px}
.wheel-info-box{background:rgba(255,255,255,.05);padding:10px 15px;border-radius:8px;text-align:center;border:1px solid;display:flex;align-items:center;gap:10px}
.wheel-info-box img{width:45px;height:45px;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:18px;font-weight:bold}
.wheel-container{position:relative;width:300px;height:300px;max-width:90vw;max-height:90vw}
.wheel-pointer{position:absolute;top:-15px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:15px solid transparent;border-right:15px solid transparent;border-top:25px solid #ff0000;z-index:10}
#wheelCanvas,#upgradeCanvas{width:100%;height:100%;border-radius:50%}
#wheelCanvas{transition:transform 5s cubic-bezier(.17,.67,.21,.99)}
.wheel-center{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:50px;height:50px;background:radial-gradient(circle,#ffd700,#b8860b);border-radius:50%;border:3px solid #fff;display:flex;align-items:center;justify-content:center;z-index:5}
.wheel-center img{width:30px;height:30px}
.wheel-btn{background:linear-gradient(135deg,#ffd700,#ff8c00);color:#000;border:none;padding:14px 40px;font-size:18px;font-weight:bold;border-radius:10px;cursor:pointer}
.wheel-btn:disabled{opacity:.5;cursor:not-allowed}
.wheel-result{font-size:22px;font-weight:bold;min-height:35px;text-align:center;margin-top:8px}
.wheel-result.win{color:#ffd700}
.wheel-result.lose{color:#a0aec0}
.upgrade-layout{display:grid;grid-template-columns:1fr auto 1fr;gap:15px;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:12px}
.upgrade-panel h3{color:#ffd700;margin-bottom:8px;text-align:center;font-size:14px}
.upgrade-panel .hint{color:#aaa;font-size:11px;text-align:center;margin-bottom:8px;font-style:italic}
.upgrade-items{display:grid;grid-template-columns:repeat(auto-fill,minmax(100px,1fr));gap:6px;max-height:350px;overflow-y:auto;padding:4px}
.upgrade-item{background:rgba(255,255,255,.05);padding:6px;border-radius:6px;text-align:center;border:2px solid;cursor:pointer;transition:.2s;font-size:10px}
.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:50px;height:50px;object-fit:contain}
.upgrade-item .name{margin:2px 0;font-weight:bold;font-size:9px}
.upgrade-item .price{color:#7fff00;font-weight:bold}
.upgrade-circle{position:relative;width:200px;height:200px}
#upgradeCanvas{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:10px solid transparent;border-right:10px solid transparent;border-top:18px solid #fff;z-index:10}
.upgrade-percent{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font-size:28px;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:12px 35px;font-size:16px;font-weight:bold;border-radius:10px;cursor:pointer;width:100%;max-width:220px}
.upgrade-btn:disabled{opacity:.5;cursor:not-allowed;background:#4b5563}
.upgrade-result{font-size:16px;font-weight:bold;min-height:25px;text-align:center}
.upgrade-result.win{color:#7fff00}
.upgrade-result.lose{color:#ef4444}
.profile-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:12px}
.profile-box{background:rgba(255,255,255,.06);border:1px solid #2a3a5e;border-radius:12px;padding:15px;text-align:center}
.profile-box .label{color:#aaa;font-size:12px;margin-bottom:5px}
.profile-box .value{color:#ffd700;font-size:20px;font-weight:bold}
.rank-badge{font-size:22px;font-weight:bold;color:#ffd700;text-shadow:0 0 15px rgba(255,215,0,.5)}
.rank-progress{width:100%;height:16px;background:rgba(0,0,0,.5);border-radius:20px;overflow:hidden;border:1px solid #374151;margin-top:8px}
.rank-progress-fill{height:100%;background:linear-gradient(90deg,#10b981,#ffd700);width:0%;transition:.4s}
.profile-btn{margin-top:10px;background:linear-gradient(135deg,#3b82f6,#1d4ed8);color:#fff;border:none;padding:8px 14px;border-radius:8px;cursor:pointer;font-weight:bold;font-size:12px}
.avatar-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(80px,1fr));gap:10px;margin-top:10px}
.avatar-item{width:80px;height:80px;border:3px solid #374151;border-radius:50%;cursor:pointer;transition:.2s;overflow:hidden;background:rgba(0,0,0,.3)}
.avatar-item:hover{transform:scale(1.1)}
.avatar-item.selected{border-color:#ffd700;box-shadow:0 0 20px #ffd700}
.avatar-item img{width:100%;height:100%;object-fit:contain}
.trade-layout{display:grid;grid-template-columns:1fr 1fr;gap:15px}
@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:12px}
.trade-panel h3{color:#ffd700;text-align:center;margin-bottom:10px;font-size:14px}
.trade-selected{box-shadow:0 0 20px #ffd700 !important;transform:scale(1.04)}
.bot-offers{display:grid;gap:10px}
.bot-offer{background:rgba(255,255,255,.06);border:2px solid;border-radius:12px;padding:12px;display:grid;grid-template-columns:auto 1fr auto;gap:10px;align-items:center}
.bot-offer img{width:60px;height:60px;object-fit:contain}
.bot-name{color:#60a5fa;font-weight:bold;margin-bottom:3px;font-size:13px}
.bot-comment{color:#aaa;font-size:11px;font-style:italic}
.bot-price{color:#7fff00;font-weight:bold;font-size:13px}
.trade-accept{background:linear-gradient(135deg,#10b981,#059669);color:#fff;border:none;padding:8px 14px;border-radius:8px;cursor:pointer;font-weight:bold;font-size:12px}
.daily-grid{display:grid;grid-template-columns:repeat(7,1fr);gap:8px;margin-bottom:15px}
.daily-day{background:rgba(255,255,255,.05);border:2px solid #374151;border-radius:10px;padding:12px 6px;text-align:center;transition:.2s}
.daily-day.claimed{background:rgba(16,185,129,.2);border-color:#10b981}
.daily-day.today{background:rgba(251,191,36,.2);border-color:#ffd700;animation:pulse 2s infinite}
.daily-day.locked{opacity:.4}
@keyframes pulse{0%,100%{box-shadow:0 0 0 0 rgba(251,191,36,.4)}50%{box-shadow:0 0 0 8px rgba(251,191,36,0)}}
.daily-day .day-num{font-size:11px;color:#aaa;margin-bottom:4px}
.daily-day .day-reward{font-size:18px;font-weight:bold;color:#ffd700}
.daily-day .day-label{font-size:10px;color:#aaa;margin-top:3px}
.bp-container{display:grid;grid-template-columns:1fr 1fr;gap:15px}
@media(max-width:800px){.bp-container{grid-template-columns:1fr}}
.bp-track{background:rgba(255,255,255,.03);border:2px solid #374151;border-radius:12px;padding:12px}
.bp-track.premium{border-color:#ffd700;background:linear-gradient(135deg,rgba(251,191,36,.1),rgba(180,83,9,.1))}
.bp-track h3{text-align:center;margin-bottom:10px;font-size:14px}
.bp-levels{display:flex;flex-direction:column;gap:6px;max-height:400px;overflow-y:auto}
.bp-level{background:rgba(255,255,255,.05);border:1px solid #374151;border-radius:8px;padding:8px;display:flex;align-items:center;gap:10px;font-size:12px}
.bp-level.unlocked{border-color:#10b981;background:rgba(16,185,129,.1)}
.bp-level.claimed{opacity:.5}
.bp-level .lvl-num{font-weight:bold;color:#ffd700;width:30px;font-size:14px}
.bp-level .lvl-reward{flex:1}
.bp-level .claim-btn{background:linear-gradient(135deg,#10b981,#059669);color:#fff;border:none;padding:5px 10px;border-radius:6px;cursor:pointer;font-weight:bold;font-size:11px}
.bp-level .claim-btn:disabled{opacity:.5;cursor:not-allowed}
.bp-quests{background:rgba(255,255,255,.03);border:1px solid #2a3a5e;border-radius:12px;padding:12px;margin-top:15px}
.bp-quests h3{color:#ffd700;text-align:center;margin-bottom:10px;font-size:14px}
.quest{background:rgba(255,255,255,.05);border:1px solid #374151;border-radius:8px;padding:10px;margin-bottom:8px}
.quest .q-name{font-weight:bold;font-size:13px;margin-bottom:4px}
.quest .q-progress{height:8px;background:rgba(0,0,0,.5);border-radius:4px;overflow:hidden;margin:5px 0}
.quest .q-progress-fill{height:100%;background:linear-gradient(90deg,#10b981,#ffd700);transition:.3s}
.quest .q-info{display:flex;justify-content:space-between;font-size:11px;color:#aaa}
.quest .q-reward{color:#ffd700;font-weight:bold}
.quest.completed{border-color:#10b981;background:rgba(16,185,129,.1)}
.games-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px;margin-bottom:15px}
.game-card{background:linear-gradient(135deg,rgba(139,92,246,.2),rgba(91,33,182,.2));border:2px solid #8b5cf6;border-radius:12px;padding:15px;text-align:center;cursor:pointer;transition:.2s}
.game-card:hover{transform:translateY(-5px)}
.game-card .gicon{font-size:60px;margin-bottom:8px}
.game-card .gname{font-size:18px;font-weight:bold;color:#ffd700;margin-bottom:4px}
.game-card .gdesc{font-size:12px;color:#ccc}
.game-area{display:none;flex-direction:column;align-items:center;gap:12px}
.game-area.active{display:flex}
.game-hud{display:flex;gap:12px;flex-wrap:wrap;justify-content:center;width:100%}
.hud-box{background:rgba(255,255,255,.05);padding:6px 12px;border-radius:8px;border:1px solid #2a3a5e;font-size:13px}
.hud-box span{color:#ffd700;font-weight:bold}
#gdCanvas,#pacmanCanvas{border:3px solid #8b5cf6;border-radius:10px;max-width:100%}
#gdCanvas{background:linear-gradient(180deg,#1e3a8a 0%,#312e81 50%,#1e1b4b 100%)}
#pacmanCanvas{background:#000;image-rendering:pixelated}
#crashCanvas{background:linear-gradient(180deg,#0f172a,#1e293b);border:3px solid #8b5cf6;border-radius:10px;max-width:100%}
.game-controls{display:flex;gap:8px;flex-wrap:wrap;justify-content:center}
.game-btn{background:linear-gradient(135deg,#8b5cf6,#5b21b6);color:#fff;border:none;padding:10px 20px;font-size:14px;font-weight:bold;border-radius:8px;cursor:pointer}
.game-btn.back{background:linear-gradient(135deg,#6b7280,#374151)}
.game-btn.cashout{background:linear-gradient(135deg,#10b981,#059669)}
.game-hint{color:#aaa;font-size:12px;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:12px;border-radius:10px;z-index:20}
.game-over-screen.active{display:flex}
.game-over-screen h2{color:#ef4444;font-size:28px}
.game-over-screen .reward{color:#ffd700;font-size:20px;font-weight:bold}
.game-over-screen .meme{color:#fbbf24;font-size:14px;font-style:italic}
.canvas-wrapper{position:relative}
.modal{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.85);display:none;align-items:center;justify-content:center;z-index:1500;padding:20px}
.modal.active{display:flex}
.modal-content{background:linear-gradient(135deg,#1a1a2e,#16213e);border:2px solid #ffd700;border-radius:15px;padding:25px;max-width:600px;width:100%;max-height:85vh;overflow-y:auto}
.modal-content h2{color:#ffd700;margin-bottom:15px;text-align:center}
.modal-close{background:#ef4444;color:#fff;border:none;padding:8px 16px;border-radius:6px;cursor:pointer;font-weight:bold;float:right}
.drop-list{display:grid;gap:8px}
.drop-item{background:rgba(255,255,255,.05);border:2px solid;border-radius:8px;padding:8px;display:flex;align-items:center;gap:10px}
.drop-item img{width:50px;height:50px;object-fit:contain}
.drop-item .drop-info{flex:1}
.drop-item .drop-name{font-weight:bold;font-size:13px}
.drop-item .drop-price{color:#7fff00;font-size:12px}
.drop-item .drop-chance{color:#ffd700;font-size:11px;font-weight:bold}
.notification{position:fixed;top:20px;right:20px;padding:12px 20px;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:350px;display:flex;align-items:center;gap:8px}
.notification img{width:35px;height:35px;object-fit:contain}
.notification .ntext{display:flex;flex-direction:column}
.notification .ntext .main{font-size:13px}
.notification .ntext .meme{font-size:10px;color:#fbbf24;font-style:italic;margin-top:2px}
@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:130px;filter:drop-shadow(0 0 30px #ffd700)}
.big-meme .text{font-size:50px;font-weight:bold;color:#ffd700;text-shadow:0 0 30px #ffd700;margin-top:8px}
.big-meme .subtext{font-size:20px;color:#fff;margin-top:8px;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">

<header>
<h1>🗑️ MusorCase<span class="sub">"Лучший скам 2026 года"</span></h1>
<div style="display:flex;gap:8px;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('battlepass',this)">🎫 БП</button>
<button class="tab" onclick="switchTab('daily',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:18px;color:#ffd700;margin-bottom:12px;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="300" height="300"></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 style="position:relative;width:200px;height:200px"><div style="position:absolute;top:-8px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:10px solid transparent;border-right:10px solid transparent;border-top:18px solid #fff;z-index:10"></div><canvas id="upgradeCanvas" width="200" height="200"></canvas><div id="upgradePercent" style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font-size:28px;font-weight:bold;color:#fff;text-shadow:0 0 10px rgba(0,0,0,.8);z-index:5">—%</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>
<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-battlepass">
<div class="panel">
<h2 class="title">🎫 Батл-пасс MusorCase</h2>
<div style="text-align:center;margin-bottom:15px">
<div style="font-size:18px;color:#ffd700;font-weight:bold">Уровень: <span id="bpLevel">1</span> / 30</div>
<div style="color:#aaa;font-size:13px">Опыт БП: <span id="bpXP">0</span> / <span id="bpNextXP">100</span></div>
<div class="rank-progress" style="margin-top:8px"><div class="rank-progress-fill" id="bpProgressFill" style="width:0%"></div></div>
</div>
<div class="bp-container">
<div class="bp-track"><h3>🆓 Бесплатный трек</h3><div class="bp-levels" id="bpFreeTrack"></div></div>
<div class="bp-track premium"><h3>💎 Премиум трек</h3><div class="bp-levels" id="bpPremiumTrack"></div></div>
</div>
<div class="bp-quests">
<h3>📋 Задания</h3>
<div id="bpQuests"></div>
</div>
</div>
</div>

<!-- ЕЖЕДНЕВНЫЕ НАГРАДЫ -->
<div class="section" id="section-daily">
<div class="panel">
<h2 class="title">🎁 Ежедневные награды</h2>
<p style="text-align:center;color:#aaa;margin-bottom:15px;font-style:italic;font-size:13px">Заходи каждый день! Награды растут.</p>
<div class="daily-grid" id="dailyGrid"></div>
<div style="text-align:center;margin-top:15px">
<button class="profile-btn" onclick="claimDailyReward()" id="claimDailyBtn">🎁 Забрать награду</button>
</div>
</div>
</div>

<!-- ПРОФИЛЬ -->
<div class="section" id="section-profile">
<div class="panel">
<h2 class="title">👤 Профиль</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 class="game-card" onclick="startGame('crash')"><div class="gicon">📈</div><div class="gname">Crash</div><div class="gdesc">Забери до краха!</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="gdReward">0</span> ₽</div>
<div class="hud-box">🏆 <span id="gdRecord">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>
<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 class="game-area" id="gameArea-crash">
<div class="game-hud">
<div class="hud-box">💵 Ставка: <input type="number" id="crashBet" value="100" min="10" style="width:70px;background:#1f2937;border:1px solid #374151;color:#fff;padding:4px;border-radius:4px"> ₽</div>
<div class="hud-box">📈 Множитель: <span id="crashMult">1.00</span>x</div>
<div class="hud-box">💰 Выигрыш: <span id="crashWin">0</span> ₽</div>
</div>
<canvas id="crashCanvas" width="600" height="300"></canvas>
<div class="game-controls">
<button class="game-btn" id="crashStartBtn" onclick="startCrash()">🚀 СТАРТ</button>
<button class="game-btn cashout" id="crashCashoutBtn" onclick="cashoutCrash()" disabled>💰 ЗАБРАТЬ</button>
<button class="game-btn back" onclick="exitGame('crash')">← Выход</button>
</div>
<div class="game-hint" id="crashStatus">Сделай ставку и нажми СТАРТ</div>
</div>
</div>
</div>

<!-- МОДАЛКА СОДЕРЖИМОГО КЕЙСА -->
<div class="modal" id="dropModal">
<div class="modal-content">
<button class="modal-close" onclick="closeDropModal()">✕ Закрыть</button>
<h2 id="dropModalTitle">Содержимое кейса</h2>
<div class="drop-list" id="dropList"></div>
</div>
</div>

</div>

<script>
// ============ ЗВУКИ ============
let audioCtx=null,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(f,d,t='sine',v=.2){if(!soundEnabled)return;initAudio();const o=audioCtx.createOscillator(),g=audioCtx.createGain();o.type=t;o.frequency.value=f;g.gain.setValueAtTime(v,audioCtx.currentTime);g.gain.exponentialRampToValueAtTime(.001,audioCtx.currentTime+d);o.connect(g);g.connect(audioCtx.destination);o.start();o.stop(audioCtx.currentTime+d)}
function playNoise(d,v=.1){if(!soundEnabled)return;initAudio();const b=audioCtx.createBuffer(1,audioCtx.sampleRate*d,audioCtx.sampleRate),dt=b.getChannelData(0);for(let i=0;i<dt.length;i++)dt[i]=(Math.random()*2-1)*(1-i/dt.length);const s=audioCtx.createBufferSource(),g=audioCtx.createGain();s.buffer=b;g.gain.value=v;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))},
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))},
crash:()=>playNoise(.5,.3),
crashTick:()=>playTone(400+Math.random()*200,.05,'square',.08)
};

const MEMES={
knifeWin:["ПОТРАЧЕНО 💀","ИЗИ КАТКА 🗿","ТЫ ЛЕГЕНДА 🗡️","+1 К АУРЕ","ЭТО БАЗА"],
legendaryWin:["ЛЕГЕНДА 🔥","ЭТО БАЗА","КРАСАВЧИК"],
epicWin:["ЭПИК МУВ 🎯","КРАСАВА","ИЗИ"],
rareWin:["РЕДКИЙ ДРОП ✨","НОРМАС","ПРИНЯТО"],
commonWin:["МУСОР 🗑️","ОЧЕРЕДНОЙ БОЛТ","F В ЧАТ","СКУФ-ДРОП"],
lose:["F В ЧАТ 💀","СКАМ 100%","ТЫ ПРОСТО ЛОХ","ЗАЧЕМ ТЫ ЭТО КУПИЛ?"],
upgradeWin:["ИЗИ АПГРЕЙД 🔥","БАЗА","КРАСАВЧИК"],
upgradeLose:["АПГРЕЙД? НЕ СЛЫШАЛ 💀","КАЗИНО В ПЛЮСЕ","НУ ТЫ И ЛОХ"],
gdDeath:["ИЗИ ДЭТ 🗿","ТЫ НУБ","F В ЧАТ"],
pmDeath:["ПАКМЕН МЁРТВ 💀","F В ЧАТ"],
topup:["ДЕРЖИ КАРМАН 💸","БЕСПЛАТНЫЙ СЫР...","ЕЩЁ ПОЧКА ПРОДАЙ"]
};
function randMeme(a){return a[Math.floor(Math.random()*a.length)]}
function showBigMeme(e,t,s){const d=document.createElement('div');d.className='big-meme';d.innerHTML=`<div class="content"><div class="emoji">${e}</div><div class="text">${t}</div><div class="subtext">${s}</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"/><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"/></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"/><rect x="10" y="52" width="20" height="10" fill="#78350f"/><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>`,
stiletto:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M25 75 L45 25 L50 25 L55 75 Z" fill="#e5e7eb" stroke="#1f2937"/><rect x="30" y="70" width="20" height="15" fill="#78350f" rx="2"/></svg>`,
ursus:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M20 55 L75 48 L82 55 L75 62 L20 60 Z" fill="#9ca3af" stroke="#1f2937"/><rect x="10" y="50" width="20" height="15" fill="#78350f" rx="2"/></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>`,
awp_gungnir:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="75" height="8" fill="#10b981" stroke="#065f46"/><rect x="80" y="45" width="12" height="14" fill="#78350f" rx="2"/><circle cx="25" cy="52" r="6" fill="#1f2937" stroke="#10b981" stroke-width="1.5"/><circle cx="25" cy="52" r="3" fill="#fbbf24"/></svg>`,
ak_neon:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="70" height="8" fill="#ec4899" stroke="#831843"/><path d="M75 48 L85 45 L85 59 L75 56 Z" fill="#831843"/><rect x="25" y="56" width="15" height="10" fill="#831843"/></svg>`,
m4a4_emperor:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="75" height="8" fill="#fbbf24" 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"/></svg>`,
scar20:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="48" width="75" height="8" fill="#78350f" stroke="#451a03"/><rect x="80" y="45" width="12" height="14" fill="#451a03" rx="2"/><circle cx="25" cy="52" r="5" fill="#1f2937"/></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>`,
famas:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="48" width="60" height="10" fill="#4b5563"/><rect x="70" y="45" width="10" height="16" fill="#374151" rx="2"/><rect x="30" y="58" width="15" height="10" fill="#4b5563"/></svg>`,
galil:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="48" width="60" height="10" fill="#78350f"/><rect x="70" y="45" width="10" height="16" fill="#451a03" rx="2"/><rect x="30" y="58" width="15" height="10" fill="#78350f"/></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"/></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>`,
tec9:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="25" y="45" width="40" height="12" fill="#6b7280"/><rect x="35" y="57" width="15" height="18" fill="#374151"/><rect x="60" y="43" width="10" height="6" fill="#9ca3af"/></svg>`,
fiveseven:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="25" y="45" width="42" height="12" fill="#1e40af"/><rect x="35" y="57" width="15" height="18" fill="#1e3a8a"/><rect x="62" y="43" width="10" height="6" fill="#3b82f6"/></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="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"/></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"/></svg>`,
case_midnight:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#6366f1" stroke="#4338ca" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#4f46e5"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/></svg>`,
case_neon:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#ec4899" stroke="#db2777" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#db2777"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/></svg>`,
case_lunar:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#a78bfa" stroke="#6d28d9" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#8b5cf6"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/><circle cx="50" cy="65" r="6" fill="#fbbf24"/></svg>`,
case_fire:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#f97316" stroke="#c2410c" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#ea580c"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/><path d="M45 65 Q50 55 55 65" fill="#fbbf24"/></svg>`,
case_cosmic:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="15" y="30" width="70" height="50" fill="#06b6d4" stroke="#0e7490" stroke-width="2" rx="3"/><rect x="15" y="30" width="70" height="15" fill="#0891b2"/><rect x="45" y="40" width="10" height="15" fill="#fbbf24"/><circle cx="40" cy="65" r="2" fill="#fff"/><circle cx="55" cy="60" r="1.5" fill="#fff"/><circle cx="60" cy="70" r="1" fill="#fff"/></svg>`,
gloves_sport:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><linearGradient id="gsb" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#5eead4"/><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(#gsb)" stroke="#022c22" stroke-width="2"/></svg>`,
gloves_driver:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><linearGradient id="gdb" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#fde68a"/><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(#gdb)" 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="gsb2" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#fca5a5"/><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(#gsb2)" stroke="#000" stroke-width="2"/></svg>`,
gloves_moto:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><linearGradient id="gmb" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#1f2937"/><stop offset="1" stop-color="#000"/></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(#gmb)" stroke="#ef4444" stroke-width="2"/><path d="M35 55 L60 60" stroke="#ef4444" stroke-width="2"/></svg>`,
gloves_war:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><linearGradient id="gwb" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#4b5563"/><stop offset="1" stop-color="#1f2937"/></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(#gwb)" stroke="#fbbf24" stroke-width="2"/><path d="M40 45 L55 50 L45 60" stroke="#fbbf24" stroke-width="1.5" fill="none"/></svg>`,
avatar_skuf:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="#fbbf24"/><circle cx="35" cy="40" r="5" fill="#000"/><circle cx="65" cy="40" r="5" fill="#000"/><path d="M30 65 Q50 80 70 65" stroke="#000" stroke-width="3" fill="none"/><path d="M20 25 Q50 10 80 25" stroke="#78350f" stroke-width="8" fill="none"/></svg>`,
avatar_knife:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="#1f2937"/><path d="M30 70 L50 20 L70 70 Z" fill="#d1d5db" stroke="#fbbf24" stroke-width="2"/></svg>`,
avatar_case:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="#8b5cf6"/><rect x="25" y="35" width="50" height="35" fill="#6d28d9" stroke="#fbbf24" stroke-width="2" rx="3"/><rect x="45" y="45" width="10" height="15" fill="#fbbf24"/></svg>`,
avatar_pacman:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="#fbbf24"/><path d="M50 50 L95 30 L95 70 Z" fill="#1a1a2e"/><circle cx="50" cy="35" r="4" fill="#000"/></svg>`,
avatar_crown:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="#dc2626"/><path d="M20 60 L30 35 L40 55 L50 30 L60 55 L70 35 L80 60 Z" fill="#fbbf24" stroke="#78350f" stroke-width="2"/></svg>`,
avatar_skull:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="#1f2937"/><circle cx="50" cy="45" r="25" fill="#f3f4f6"/><circle cx="40" cy="42" r="5" fill="#000"/><circle cx="60" cy="42" r="5" fill="#000"/><path d="M40 60 L45 55 L50 60 L55 55 L60 60" stroke="#000" stroke-width="2" fill="none"/></svg>`,
avatar_fire:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="#7c2d12"/><path d="M50 20 Q30 40 40 60 Q50 50 50 70 Q60 50 70 60 Q80 40 50 20" fill="#fbbf24" stroke="#ef4444" stroke-width="2"/></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},
{name:'Погнутый гвоздь',icon:'bolt',price:6},
{name:'Обрывок верёвки',icon:'cloth',price:4}
],
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},
{name:'Tec-9',icon:'tec9',price:110},
{name:'Five-SeveN',icon:'fiveseven',price:130}
],
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},
{name:'FAMAS',icon:'famas',price:300},
{name:'Galil AR',icon:'galil',price:290},
{name:'SCAR-20',icon:'scar20',price:380}
],
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},
{name:'AK Неон',icon:'ak_neon',price:1100},
{name:'M4A4 Император',icon:'m4a4_emperor',price:950},
{name:'AWP Gungnir',icon:'awp_gungnir',price:1500}
],
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},
{name:'Стилет',icon:'stiletto',price:2700},
{name:'Ursus нож',icon:'ursus',price:3100}
],
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},
{name:'Мото | Кожаные',icon:'gloves_moto',price:2200},
{name:'Боевые | Тактические',icon:'gloves_war',price:3500}
]
};

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:'🗡️ 0.5% | 🧤 0.3%',chances:{common:75,rare:20,epic:3.5,legendary:0.7,knife:0.5,gloves:0.3}},
{id:'standard',name:'Стандартный кейс',icon:'case_standard',price:100,class:'case-standard',chanceText:'🗡️ 1% | 🧤 0.5%',chances:{common:60,rare:28,epic:8,legendary:2,knife:1,gloves:0.5}},
{id:'premium',name:'Премиум кейс',icon:'case_premium',price:250,class:'case-premium',chanceText:'🗡️ 2% | 🧤 1%',chances:{common:40,rare:35,epic:15,legendary:5,knife:2,gloves:1}},
{id:'legendary',name:'Легендарный кейс',icon:'case_legendary',price:500,class:'case-legendary',chanceText:'🗡️ 3% | 🧤 1.5%',chances:{common:20,rare:35,epic:25,legendary:10,knife:3,gloves:1.5}},
{id:'elite',name:'Элитный кейс',icon:'case_elite',price:1000,class:'case-elite',chanceText:'🗡️ 5% | 🧤 2.5%',chances:{common:10,rare:25,epic:35,legendary:20,knife:5,gloves:2.5}},
{id:'glove',name:'Перчаточный кейс',icon:'case_gloves',price:750,class:'case-gloves',chanceText:'🧤 100% перчатки',chances:{rare:30,epic:40,legendary:20,gloves:10}},
{id:'knife',name:'Ножевой кейс',icon:'case_knife',price:1500,class:'case-knife',chanceText:'🗡️ 100% ножи',chances:{rare:25,epic:40,legendary:20,knife:15}},
{id:'midnight',name:'Полуночный кейс',icon:'case_midnight',price:2000,class:'case-midnight',chanceText:'🗡️ 8% | 🧤 4%',chances:{common:5,rare:15,epic:35,legendary:30,knife:8,gloves:4}},
{id:'neon',name:'Неоновый кейс',icon:'case_neon',price:3000,class:'case-neon',chanceText:'🗡️ 12% | 🧤 6%',chances:{rare:10,epic:30,legendary:35,knife:12,gloves:6}},
{id:'lunar',name:'Лунный кейс',icon:'case_lunar',price:1200,class:'case-lunar',chanceText:'🗡️ 4% | 🧤 2%',chances:{common:15,rare:30,epic:30,legendary:15,knife:4,gloves:2}},
{id:'fire',name:'Огненный кейс',icon:'case_fire',price:1800,class:'case-fire',chanceText:'🗡️ 6% | 🧤 3%',chances:{common:10,rare:25,epic:35,legendary:18,knife:6,gloves:3}},
{id:'cosmic',name:'Космический кейс',icon:'case_cosmic',price:2500,class:'case-cosmic',chanceText:'🗡️ 10% | 🧤 5%',chances:{rare:15,epic:35,legendary:30,knife:10,gloves:5}}
];

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));addBPXP(5)}
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();
if(tab==='daily')renderDailyRewards();
if(tab==='battlepass')renderBattlePass();
}
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=`<button class="view-btn" onclick="event.stopPropagation();showDropModal('${c.id}')">👁️</button><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 showDropModal(caseId){
SFX.click();
const c=cases.find(x=>x.id===caseId);
const modal=document.getElementById('dropModal');
document.getElementById('dropModalTitle').textContent=`📦 ${c.name} — ${c.price} ₽`;
const list=document.getElementById('dropList');
list.innerHTML='';
Object.entries(c.chances).forEach(([rarity,chance])=>{
if(chance<=0)return;
const items=allItems[rarity];
if(!items)return;
items.forEach(item=>{
const perItemChance=(chance/items.length).toFixed(2);
const d=document.createElement('div');
d.className=`drop-item rarity-${rarity}`;
d.innerHTML=`<img src="${iconUrl(item.icon)}"><div class="drop-info"><div class="drop-name">${item.name}</div><div class="drop-price">${item.price} ₽</div></div><div class="drop-chance">${perItemChance}%</div>`;
list.appendChild(d);
});
});
modal.classList.add('active');
}
function closeDropModal(){document.getElementById('dropModal').classList.remove('active')}

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];if(!p||!p.length)return{...allItems.common[0],rarity:'common'};
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);
addBPXP(count*10);
completeQuest('openCases',count);
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));completeQuest('getKnife',1)}
else if(w.rarity==='gloves'){memePool=MEMES.legendaryWin;SFX.win();showBigMeme('🧤','ПЕРЧАТКИ!',randMeme(MEMES.legendaryWin));completeQuest('getGloves',1)}
else if(w.rarity==='legendary'){memePool=MEMES.legendaryWin;SFX.win();completeQuest('getLegendary',1)}
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++;completeQuest('getKnife',1)}
if(it.rarity==='gloves'){gc++;completeQuest('getGloves',1)}
if(it.rarity==='legendary')completeQuest('getLegendary',1);
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 13px Arial';
wheelCtx.fillText(isK?'+2500₽':'0₽',r*.42,5);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-15,-15,30,30);wheelCtx.restore();
}
}
wheelCtx.beginPath();wheelCtx.arc(cx,cy,r,0,Math.PI*2);
wheelCtx.strokeStyle='#ffd700';wheelCtx.lineWidth=4;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);addBPXP(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:35px;height:35px;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:35px;height:35px;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);addBPXP(20);
completeQuest('doUpgrade',1);
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);
}

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

function getAllTradeSkins(){return Object.entries(allItems).flatMap(([r,items])=>items.map(i=>({...i,rarity:r})))}
function makeBotOffers(source){
const pool=getAllTradeSkins();
return Array.from({length:3},()=>{
const m=0.65+Math.random()*0.95;
const tp=source.price*m;
const c=pool.filter(i=>i.price>=tp*0.65&&i.price<=tp*1.35).sort(()=>Math.random()-0.5);
const item=c[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 sb=document.getElementById('tradeSource'),ob=document.getElementById('botOffers');
if(!sb||!ob)return;
sb.innerHTML='';
if(!inventory.length){sb.innerHTML='<div class="empty">Инвентарь пуст</div>';ob.innerHTML='<div class="empty">Открой кейс</div>';return}
[...inventory].sort((a,b)=>b.price-a.price).forEach(item=>{
const d=document.createElement('div');
d.className=`inv-item rarity-${item.rarity} ${tradeSourceId===item.id?'trade-selected':''}`;
d.innerHTML=`<img src="${iconUrl(item.icon)}"><div class="name">${item.name}</div><div class="price">${item.price} ₽</div>`;
d.onclick=()=>selectTradeSource(item.id);sb.appendChild(d);
});
const source=inventory.find(i=>i.id===tradeSourceId);
if(!source){ob.innerHTML='<div class="empty">Выбери скин слева</div>';return}
if(!tradeOffers.length||tradeOffers._srcId!==tradeSourceId){tradeOffers=makeBotOffers(source);tradeOffers._srcId=tradeSourceId}
ob.innerHTML='';
tradeOffers.forEach((offer,index)=>{
const diff=offer.item.price-source.price;
const d=document.createElement('div');
d.className=`bot-offer rarity-${offer.item.rarity}`;
d.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:11px;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>`;
ob.appendChild(d);
});
}
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);addBPXP(25);
completeQuest('doTrade',1);
saveMCProfile();
tradeSourceId=null;tradeOffers=[];
SFX.coin();
if(profit>=0){notify(`Трэйд: +${profit} ₽`,'#7fff00',offer.item.icon,randMeme(MEMES.knifeWin));if(profit>=500)showBigMeme('🤖','БОТ ПРОИГРАЛ!',randMeme(MEMES.knifeWin))}
else{notify(`Трэйд: ${profit} ₽`,'#ef4444',offer.item.icon,randMeme(MEMES.lose))}
renderInventory();renderTradePanel();renderUpgradePanels();renderProfile();
}

// ============ ПРОФИЛЬ ============
const AVATARS=['avatar_skuf','avatar_knife','avatar_case','avatar_pacman','avatar_crown','avatar_skull','avatar_fire'];
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,avatar:'avatar_skuf',
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')}
if(document.getElementById('section-profile').classList.contains('active'))renderProfile();
}

function renderProfile(){
const box=document.getElementById('profileContent');if(!box)return;
const rank=getRankInfo(mcProfile.xp);
const best=inventory.length?[...inventory].sort((a,b)=>b.price-a.price)[0]:null;
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="avatar-grid">
${AVATARS.map(a=>`<div class="avatar-item ${mcProfile.avatar===a?'selected':''}" onclick="selectAvatar('${a}')"><img src="${iconUrl(a)}"></div>`).join('')}
</div>
</div>
<div class="profile-box">
<div class="label">Ник</div>
<div class="value" style="font-size:16px">${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:6px;color:#aaa;font-size:12px">XP: ${mcProfile.xp}</div>
<div class="rank-progress"><div class="rank-progress-fill" style="width:${rank.progress}%"></div></div>
<div style="font-size:11px;color:#aaa;margin-top:4px">${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:70px;height:70px;object-fit:contain"><div class="value" style="font-size:14px">${best.name}</div><div style="color:#7fff00;font-weight:bold">${best.price} ₽</div>`:`<div class="value" style="font-size:14px;color:#aaa">Пока ничего</div>`}
</div>
</div>`;
}
function selectAvatar(a){mcProfile.avatar=a;saveMCProfile();renderProfile();SFX.click()}
function editNickname(){
const nick=prompt('Введи новый ник:',mcProfile.nick);
if(!nick)return;
mcProfile.nick=nick.slice(0,20);
saveMCProfile();renderProfile();SFX.click();
}

// ============ ЕЖЕДНЕВНЫЕ НАГРАДЫ ============
const DAILY_REWARDS=[
{day:1,reward:100,label:'100 ₽'},
{day:2,reward:200,label:'200 ₽'},
{day:3,reward:350,label:'350 ₽'},
{day:4,reward:500,label:'500 ₽'},
{day:5,reward:750,label:'750 ₽'},
{day:6,reward:1000,label:'1000 ₽'},
{day:7,reward:2500,label:'2500 ₽ + 🗡️'}
];
let dailyData=JSON.parse(localStorage.getItem('mcDaily')||'null')||{lastClaim:0,streak:0};
function saveDaily(){localStorage.setItem('mcDaily',JSON.stringify(dailyData))}

function renderDailyRewards(){
const grid=document.getElementById('dailyGrid');
grid.innerHTML='';
const today=new Date().toDateString();
const lastDay=dailyData.lastClaim?new Date(dailyData.lastClaim).toDateString():'';
const canClaim=lastDay!==today;
DAILY_REWARDS.forEach((dr,i)=>{
const d=document.createElement('div');
let cls='daily-day';
if(i<dailyData.streak)cls+=' claimed';
else if(i===dailyData.streak&&canClaim)cls+=' today';
else if(i>dailyData.streak)cls+=' locked';
d.className=cls;
d.innerHTML=`<div class="day-num">День ${dr.day}</div><div class="day-reward">${dr.label}</div>`;
grid.appendChild(d);
});
const btn=document.getElementById('claimDailyBtn');
btn.disabled=!canClaim||dailyData.streak>=7;
btn.textContent=canClaim?(dailyData.streak>=7?'🎉 Все награды получены':'🎁 Забрать награду'):'✅ Получено сегодня';
}
function claimDailyReward(){
const today=new Date().toDateString();
const lastDay=dailyData.lastClaim?new Date(dailyData.lastClaim).toDateString():'';
if(lastDay===today||dailyData.streak>=7)return;
const reward=DAILY_REWARDS[dailyData.streak];
balance+=reward.reward;
updateBalance();
dailyData.lastClaim=Date.now();
dailyData.streak++;
if(dailyData.streak>=7)dailyData.streak=0;
saveDaily();
addBPXP(50);
SFX.knife();
showBigMeme('🎁',`+${reward.reward} ₽`,'Ежедневная награда!');
notify(`🎁 День ${reward.day}: +${reward.reward} ₽`,'#ffd700',null,'ИЗИ');
renderDailyRewards();
}

// ============ БАТЛ-ПАСС ============
let bpData=JSON.parse(localStorage.getItem('mcBP')||'null')||{xp:0,level:1,freeClaimed:[],premiumClaimed:[],premium:false,quests:{}};
function saveBP(){localStorage.setItem('mcBP',JSON.stringify(bpData))}

const BP_QUESTS=[
{id:'openCases',name:'Открыть кейсы',target:20,reward:100,xp:50},
{id:'getKnife',name:'Получить нож',target:1,reward:500,xp:200},
{id:'getGloves',name:'Получить перчатки',target:1,reward:300,xp:150},
{id:'getLegendary',name:'Получить легендарку',target:3,reward:200,xp:100},
{id:'doUpgrade',name:'Сделать апгрейд',target:5,reward:150,xp:80},
{id:'doTrade',name:'Сделать трейд',target:3,reward:150,xp:80},
{id:'playGames',name:'Поиграть в игры',target:10,reward:200,xp:100}
];

const BP_REWARDS_FREE=[50,100,150,200,250,300,400,500,600,750,900,1000,1200,1500,1800,2000,2500,3000,3500,4000,5000,6000,7500,9000,10000,12500,15000,20000,25000,50000];
const BP_REWARDS_PREMIUM=[150,300,450,600,750,900,1200,1500,1800,2250,2700,3000,3600,4500,5400,6000,7500,9000,10500,12000,15000,18000,22500,27000,30000,37500,45000,60000,75000,150000];

function addBPXP(amount){
bpData.xp+=amount;
const newLevel=Math.floor(bpData.xp/100)+1;
if(newLevel>bpData.level){
bpData.level=newLevel;
SFX.win();
notify(`🎫 Уровень БП: ${bpData.level}`,'#ffd700');
}
saveBP();
if(document.getElementById('section-battlepass').classList.contains('active'))renderBattlePass();
}

function completeQuest(id,amount){
if(!bpData.quests[id])bpData.quests[id]={progress:0,claimed:false};
const q=BP_QUESTS.find(x=>x.id===id);
if(!q||bpData.quests[id].claimed)return;
bpData.quests[id].progress=Math.min(q.target,bpData.quests[id].progress+amount);
if(bpData.quests[id].progress>=q.target&&!bpData.quests[id].claimed){
bpData.quests[id].claimed=true;
balance+=q.reward;
updateBalance();
addBPXP(q.xp);
notify(`📋 Задание выполнено: +${q.reward} ₽`,'#10b981');
}
saveBP();
}

function renderBattlePass(){
document.getElementById('bpLevel').textContent=bpData.level;
document.getElementById('bpXP').textContent=bpData.xp;
document.getElementById('bpNextXP').textContent=bpData.level*100;
const progress=(bpData.xp%100);
document.getElementById('bpProgressFill').style.width=progress+'%';

const freeTrack=document.getElementById('bpFreeTrack');
const premTrack=document.getElementById('bpPremiumTrack');
freeTrack.innerHTML='';premTrack.innerHTML='';

for(let i=1;i<=30;i++){
const unlocked=bpData.level>=i;
const freeClaimed=bpData.freeClaimed.includes(i);
const premClaimed=bpData.premiumClaimed.includes(i);

const freeDiv=document.createElement('div');
freeDiv.className='bp-level'+(unlocked?' unlocked':'')+(freeClaimed?' claimed':'');
freeDiv.innerHTML=`<div class="lvl-num">${i}</div><div class="lvl-reward">💰 ${BP_REWARDS_FREE[i-1]} ₽</div>${unlocked&&!freeClaimed?`<button class="claim-btn" onclick="claimBP('free',${i})">Забрать</button>`:freeClaimed?'<span style="color:#10b981">✓</span>':'<span style="color:#666">🔒</span>'}`;
freeTrack.appendChild(freeDiv);

const premDiv=document.createElement('div');
premDiv.className='bp-level'+(unlocked?' unlocked':'')+(premClaimed?' claimed':'');
premDiv.innerHTML=`<div class="lvl-num">${i}</div><div class="lvl-reward">💎 ${BP_REWARDS_PREMIUM[i-1]} ₽</div>${unlocked&&!premClaimed?`<button class="claim-btn" onclick="claimBP('premium',${i})">Забрать</button>`:premClaimed?'<span style="color:#10b981">✓</span>':'<span style="color:#666">🔒</span>'}`;
premTrack.appendChild(premDiv);
}

const questsDiv=document.getElementById('bpQuests');
questsDiv.innerHTML='';
BP_QUESTS.forEach(q=>{
const prog=bpData.quests[q.id]||{progress:0,claimed:false};
const pct=Math.min(100,(prog.progress/q.target)*100);
const d=document.createElement('div');
d.className='quest'+(prog.claimed?' completed':'');
d.innerHTML=`<div class="q-name">${q.name}</div><div class="q-progress"><div class="q-progress-fill" style="width:${pct}%"></div></div><div class="q-info"><span>${prog.progress} / ${q.target}</span><span class="q-reward">+${q.reward} ₽ | +${q.xp} XP</span></div>`;
questsDiv.appendChild(d);
});
}
function claimBP(type,level){
if(bpData.level<level)return;
if(type==='free'){
if(bpData.freeClaimed.includes(level))return;
bpData.freeClaimed.push(level);
balance+=BP_REWARDS_FREE[level-1];
}else{
if(bpData.premiumClaimed.includes(level))return;
bpData.premiumClaimed.push(level);
balance+=BP_REWARDS_PREMIUM[level-1];
}
updateBalance();saveBP();
SFX.coin();
notify(`🎫 Награда БП получена!`,'#ffd700');
renderBattlePass();
}

// ============ 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);addBPXP(5);
completeQuest('playGames',1);
saveMCProfile();
if(g==='gd')initGD();else if(g==='pacman')initPacman();else if(g==='crash')initCrash();
}
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)}
else if(g==='crash'){crash.running=false;if(crash.aid)cancelAnimationFrame(crash.aid)}
document.getElementById('gamesGrid').style.display='grid';
document.getElementById('gameArea-'+g).classList.remove('active');
const goId=g==='gd'?'gdGameOver':g==='pacman'?'pmGameOver':null;
if(goId)document.getElementById(goId).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')}
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,mouthOpen:true},ghosts:[],map:[],score:0,lives:3,rew:0,rec:parseInt(localStorage.getItem('pmRec')||'0'),aid:null,pellets:0,powerTimer:0};

function initPacman(){
pm.map=PM_MAP.map(r=>[...r]);
pm.pac={x:13.5,y:22.5,dir:0,nextDir:0,mouth:0,mouthOpen:true};
pm.ghosts=[
{x:13.5,y:11.5,dir:2,color:'#ef4444',mode:'chase',startX:13.5,startY:11.5,name:'Blinky'},
{x:12.5,y:13.5,dir:2,color:'#ec4899',mode:'chase',startX:12.5,startY:13.5,name:'Pinky'},
{x:14.5,y:13.5,dir:2,color:'#06b6d4',mode:'chase',startX:14.5,startY:13.5,name:'Inky'},
{x:13.5,y:13.5,dir:2,color:'#f97316',mode:'chase',startX:13.5,startY:13.5,name:'Clyde'}
];
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=Math.floor(x+dx*0.6),ny=Math.floor(y+dy*0.6);
if(ny===13&&(nx<0||nx>=PM_W))return true;
if(nx<0||nx>=PM_W||ny<0||ny>=PM_H)return false;
return pm.map[ny][nx]!==1;
}

function pmLoop(){
if(!pm.running)return;
const p=pm.pac,spd=0.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;
if(pmCanMove(nx,ny,p.dir)){p.x=nx;p.y=ny}
else{p.x=Math.round(p.x-0.5)+0.5;p.y=Math.round(p.y-0.5)+0.5}
const cx=Math.round(p.x-0.5)+0.5,cy=Math.round(p.y-0.5)+0.5;
if(Math.abs(p.x-cx)+Math.abs(p.y-cy)<0.05&&p.nextDir!==p.dir&&p.nextDir!==4&&pmCanMove(cx,cy,p.nextDir)){p.dir=p.nextDir;p.x=cx;p.y=cy}
if(p.mouthOpen){p.mouth+=0.15;if(p.mouth>=0.8)p.mouthOpen=false}else{p.mouth-=0.15;if(p.mouth<=0)p.mouthOpen=true}
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=400;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=0.06,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)),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)<0.7&&Math.abs(g.y-p.y)<0.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.5,0,Math.PI*2);pmCtx.fill()}
else if(c===3){pmCtx.fillStyle='#fbbf24';pmCtx.shadowColor='#fbbf24';pmCtx.shadowBlur=8;pmCtx.beginPath();pmCtx.arc(x*PM_CELL+PM_CELL/2,y*PM_CELL+PM_CELL/2,6,0,Math.PI*2);pmCtx.fill();pmCtx.shadowBlur=0}
}
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],a=angles[p.dir];
pmCtx.save();pmCtx.translate(px,py);pmCtx.rotate(a);
pmCtx.shadowColor='#fbbf24';pmCtx.shadowBlur=12;pmCtx.fillStyle='#fbbf24';
pmCtx.beginPath();pmCtx.arc(0,0,PM_CELL*0.75,p.mouth,Math.PI*2-p.mouth);pmCtx.lineTo(0,0);pmCtx.fill();
pmCtx.shadowBlur=0;pmCtx.fillStyle='#111827';pmCtx.beginPath();pmCtx.arc(2,-6,3,0,Math.PI*2);pmCtx.fill();
pmCtx.fillStyle='#fff';pmCtx.beginPath();pmCtx.arc(3,-7,1,0,Math.PI*2);pmCtx.fill();
pmCtx.restore();
pm.ghosts.forEach(g=>{
const gx=g.x*PM_CELL+PM_CELL/2,gy=g.y*PM_CELL+PM_CELL/2;
const isFrightened=g.mode==='frightened';
const color=isFrightened?(pm.powerTimer<100&&Math.floor(pm.powerTimer/10)%2===0?'#fff':'#1e40af'):g.color;
pmCtx.save();pmCtx.translate(gx,gy);
pmCtx.fillStyle=color;pmCtx.beginPath();pmCtx.arc(0,-2,PM_CELL*0.7,Math.PI,0);pmCtx.lineTo(PM_CELL*0.7,PM_CELL*0.6);
for(let i=0;i<3;i++){pmCtx.lineTo(PM_CELL*0.7-i*PM_CELL*0.47-PM_CELL*0.12,PM_CELL*0.3);pmCtx.lineTo(PM_CELL*0.7-i*PM_CELL*0.47-PM_CELL*0.24,PM_CELL*0.6)}
pmCtx.lineTo(-PM_CELL*0.7,PM_CELL*0.6);pmCtx.closePath();pmCtx.fill();
if(isFrightened){
pmCtx.fillStyle='#fff';pmCtx.beginPath();pmCtx.arc(-4,-3,2.5,0,Math.PI*2);pmCtx.fill();pmCtx.beginPath();pmCtx.arc(4,-3,2.5,0,Math.PI*2);pmCtx.fill();
pmCtx.fillStyle='#1e40af';pmCtx.beginPath();pmCtx.arc(-4,-3,1,0,Math.PI*2);pmCtx.fill();pmCtx.beginPath();pmCtx.arc(4,-3,1,0,Math.PI*2);pmCtx.fill();
pmCtx.strokeStyle='#fff';pmCtx.lineWidth=1.5;pmCtx.beginPath();pmCtx.moveTo(-6,4);
for(let i=0;i<4;i++){pmCtx.lineTo(-6+i*4+2,i%2===0?2:6)}pmCtx.stroke();
}else{
pmCtx.fillStyle='#fff';pmCtx.beginPath();pmCtx.arc(-4,-3,3.5,0,Math.PI*2);pmCtx.fill();pmCtx.beginPath();pmCtx.arc(4,-3,3.5,0,Math.PI*2);pmCtx.fill();
pmCtx.fillStyle='#1e3a8a';
if(g.name==='Blinky'){pmCtx.beginPath();pmCtx.arc(-3,-3,1.5,0,Math.PI*2);pmCtx.fill();pmCtx.beginPath();pmCtx.arc(5,-3,1.5,0,Math.PI*2);pmCtx.fill()}
else if(g.name==='Pinky'){pmCtx.beginPath();pmCtx.arc(-4,-3,1.5,0,Math.PI*2);pmCtx.fill();pmCtx.beginPath();pmCtx.arc(4,-3,1.5,0,Math.PI*2);pmCtx.fill()}
else if(g.name==='Inky'){pmCtx.beginPath();pmCtx.arc(-5,-3,1.5,0,Math.PI*2);pmCtx.fill();pmCtx.beginPath();pmCtx.arc(5,-3,1.5,0,Math.PI*2);pmCtx.fill()}
else{pmCtx.beginPath();pmCtx.arc(-4,-2,1.5,0,Math.PI*2);pmCtx.fill();pmCtx.beginPath();pmCtx.arc(4,-2,1.5,0,Math.PI*2);pmCtx.fill()}
}
pmCtx.restore();
});
}
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);notify(`🏆 Рекорд: ${pm.rec}`,'#ffd700')}
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(['ArrowUp','ArrowDown','ArrowLeft','ArrowRight',' '].includes(e.key))e.preventDefault();
if(!pm.running)return;
const k=e.key.toLowerCase();
if(k==='arrowup'||k==='w'||k==='ц'){pm.pac.nextDir=3;SFX.click()}
else if(k==='arrowdown'||k==='s'||k==='ы'){pm.pac.nextDir=1;SFX.click()}
else if(k==='arrowleft'||k==='a'||k==='ф'){pm.pac.nextDir=2;SFX.click()}
else if(k==='arrowright'||k==='d'||k==='в'){pm.pac.nextDir=0;SFX.click()}
});

// ============ CRASH ============
const crashCanvas=document.getElementById('crashCanvas'),crashCtx=crashCanvas.getContext('2d');
let crash={running:false,bet:0,mult:1,crashAt:0,startTime:0,aid:null,history:[],cashedOut:false};

function initCrash(){
crash.running=false;crash.mult=1;crash.cashedOut=false;
document.getElementById('crashMult').textContent='1.00';
document.getElementById('crashWin').textContent='0';
document.getElementById('crashStartBtn').disabled=false;
document.getElementById('crashCashoutBtn').disabled=true;
document.getElementById('crashStatus').textContent='Сделай ставку и нажми СТАРТ';
drawCrash();
}
function startCrash(){
const bet=parseInt(document.getElementById('crashBet').value)||0;
if(bet<10){notify('❌ Минимум 10 ₽','#ff4444');return}
if(balance<bet){notify('❌ Недостаточно средств','#ff4444');return}
balance-=bet;updateBalance();
crash.bet=bet;crash.mult=1;crash.cashedOut=false;
// Случайный крах — среднее ~2x, но часто падает рано
const r=Math.random();
if(r<0.33)crash.crashAt=1+Math.random()*0.5; // 33% шанс крашнуться рано (1.0-1.5x)
else if(r<0.66)crash.crashAt=1.5+Math.random()*1.5; // 33% (1.5-3x)
else if(r<0.9)crash.crashAt=3+Math.random()*4; // 24% (3-7x)
else crash.crashAt=7+Math.random()*13; // 10% (7-20x)
crash.startTime=Date.now();
crash.running=true;
document.getElementById('crashStartBtn').disabled=true;
document.getElementById('crashCashoutBtn').disabled=false;
document.getElementById('crashStatus').textContent='📈 РАСТЁТ! Успей забрать!';
crashLoop();
}
function cashoutCrash(){
if(!crash.running||crash.cashedOut)return;
crash.cashedOut=true;
const win=Math.floor(crash.bet*crash.mult);
balance+=win;updateBalance();
SFX.win();
crash.history.unshift(crash.mult.toFixed(2)+'x ✓');
if(crash.history.length>10)crash.history.pop();
notify(`💰 Забрал ${win} ₽ (${crash.mult.toFixed(2)}x)`,'#7fff00');
document.getElementById('crashStatus').textContent=`✅ Забрано на ${crash.mult.toFixed(2)}x`;
document.getElementById('crashCashoutBtn').disabled=true;
}
function crashLoop(){
if(!crash.running)return;
const elapsed=(Date.now()-crash.startTime)/1000;
crash.mult=1+elapsed*0.3+Math.pow(elapsed/5,2);
if(crash.mult>=crash.crashAt&&!crash.cashedOut){
// КРАХ!
crash.running=false;SFX.crash();
crash.history.unshift(crash.crashAt.toFixed(2)+'x 💥');
if(crash.history.length>10)crash.history.pop();
document.getElementById('crashStatus').textContent=`💥 КРАХ на ${crash.crashAt.toFixed(2)}x! Ты потерял ${crash.bet} ₽`;
document.getElementById('crashStartBtn').disabled=false;
document.getElementById('crashCashoutBtn').disabled=true;
notify(`💥 Крах на ${crash.crashAt.toFixed(2)}x!`,'#ef4444',null,randMeme(MEMES.lose));
drawCrash(true);
return;
}
if(crash.cashedOut&&crash.mult>=crash.crashAt){
crash.running=false;
document.getElementById('crashStartBtn').disabled=false;
drawCrash();
return;
}
document.getElementById('crashMult').textContent=crash.mult.toFixed(2);
document.getElementById('crashWin').textContent=Math.floor(crash.bet*crash.mult);
if(Math.floor(elapsed*10)%3===0)SFX.crashTick();
drawCrash();
crash.aid=requestAnimationFrame(crashLoop);
}
function drawCrash(crashed=false){
const w=crashCanvas.width,h=crashCanvas.height;
crashCtx.clearRect(0,0,w,h);
const bg=crashCtx.createLinearGradient(0,0,0,h);
bg.addColorStop(0,'#0f172a');bg.addColorStop(1,'#1e293b');
crashCtx.fillStyle=bg;crashCtx.fillRect(0,0,w,h);
// Сетка
crashCtx.strokeStyle='rgba(255,255,255,0.05)';crashCtx.lineWidth=1;
for(let i=0;i<10;i++){crashCtx.beginPath();crashCtx.moveTo(0,i*h/10);crashCtx.lineTo(w,i*h/10);crashCtx.stroke()}
for(let i=0;i<10;i++){crashCtx.beginPath();crashCtx.moveTo(i*w/10,0);crashCtx.lineTo(i*w/10,h);crashCtx.stroke()}
// Кривая
if(crash.mult>1){
crashCtx.strokeStyle=crashed?'#ef4444':'#10b981';
crashCtx.lineWidth=4;crashCtx.beginPath();
const steps=100;
for(let i=0;i<=steps;i++){
const t=i/steps;
const m=1+t*0.3*(crash.mult-1)+Math.pow(t,2)*(crash.mult-1);
const x=t*w*0.9+w*0.05;
const y=h-(m-1)/(crash.mult-1)*h*0.8-h*0.1;
if(i===0)crashCtx.moveTo(x,y);else cr