/* --- ПЕРЕМЕННЫЕ ТЕМ --- */
:root {
    --bg-color: #080b14;
    --bg-page: #0c1120;
    --card-bg: rgba(20, 29, 48, 0.88);
    --text-main: #ffffff;
    --text-secondary: #9caac2;
    --primary: #ffd166;
    --accent: #54d9ff;
    --border-color: rgba(255, 255, 255, 0.1);
    --neon-shadow: 0 0 24px rgba(84, 217, 255, 0.13);
    --gold-gradient: linear-gradient(135deg, #ffe49a, #ffb83d, #e78b24);
    --panel-gradient: linear-gradient(145deg, rgba(27, 38, 61, 0.96), rgba(10, 15, 29, 0.98));
    --nav-height: 82px;
}
body.theme-dark { --bg-color: #080b14; --bg-page: #0c1120; --card-bg: rgba(20, 29, 48, 0.88); --text-main: #ffffff; --text-secondary: #9caac2; --primary: #ffd166; --accent: #54d9ff; --border-color: rgba(255, 255, 255, 0.1); }
body.theme-light { --bg-color: #edf1f8; --bg-page: #f7f9fd; --card-bg: #ffffff; --text-main: #172033; --text-secondary: #68758a; --primary: #e9a52d; --accent: #168ec5; --border-color: rgba(20, 35, 60, 0.13); --neon-shadow: 0 5px 20px rgba(20, 35, 60, 0.08); }
body.theme-neon { --bg-color: #090515; --bg-page: #100923; --card-bg: rgba(35, 15, 57, 0.9); --text-main: #ffffff; --text-secondary: #c5a9df; --primary: #ffce57; --accent: #ed61ff; --border-color: rgba(237, 97, 255, 0.25); --neon-shadow: 0 0 25px rgba(237, 97, 255, 0.18); }

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
body {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    min-height: 0;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: radial-gradient(ellipse at 50% 30%, rgba(44, 86, 140, 0.13), transparent 60%), var(--bg-color);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    transition: background 0.3s, color 0.3s;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}
button, input { font: inherit; }
button {
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    border: 0;
    background: none;
    color: inherit;
}
img { max-width: 100%; display: block; }

#snow-container { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 1; }
.snowflake { position: absolute; top: -20px; color: #fff; pointer-events: none; animation: snowFall linear forwards; }
@keyframes snowFall { to { transform: translateY(110vh) rotate(360deg); opacity: 0; } }

#game-loader { position: fixed; inset: 0; background: var(--bg-color); display: flex; align-items: center; justify-content: center; flex-direction: column; z-index: 99998; transition: opacity 0.4s, visibility 0.4s; }
#game-loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.spinner { width: 48px; height: 48px; border: 4px solid rgba(255, 209, 102, 0.15); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

header {
    width: 100%;
    padding: 12px 14px 8px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    position: relative;
    z-index: 20;
    flex-shrink: 0;
}
.neon-box {
    width: 100%;
    max-width: 440px;
    margin: auto;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--panel-gradient);
    box-shadow: var(--neon-shadow);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    cursor: pointer;
}
.user-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar-wrapper { position: relative; width: 52px; height: 52px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.level-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--border-color); stroke-width: 5; }
.ring-progress { fill: none; stroke: var(--accent); stroke-width: 5; stroke-dasharray: 283; stroke-dashoffset: 283; stroke-linecap: round; transition: stroke-dashoffset 0.5s; }
.avatar { width: 40px; height: 40px; object-fit: cover; border-radius: 50%; border: 2px solid var(--primary); position: relative; z-index: 2; }
.level-badge { position: absolute; bottom: -3px; right: -4px; width: 21px; height: 21px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--gold-gradient); color: #251400; font-size: 10px; font-weight: 900; z-index: 3; }
.balance-box { display: flex; align-items: center; gap: 12px; font-weight: 900; white-space: nowrap; }

main { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; overflow: hidden; z-index: 2; }
.screen { position: absolute; inset: 0; width: 100%; min-height: 0; display: none; flex-direction: column; align-items: center; opacity: 0; overflow: hidden; }
.screen.active { display: flex; opacity: 1; animation: screenEnter 0.3s ease; }
@keyframes screenEnter { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }

#screen-tap {
    padding: 12px 18px calc(var(--nav-height) + 15px + env(safe-area-inset-bottom, 0px));
    justify-content: space-between;
    background: radial-gradient(circle at 50% 48%, rgba(255, 193, 77, 0.12), transparent 42%), var(--bg-color);
    background-position: center;
    background-size: cover;
    transition: background 0.4s;
}
#particles-container { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 5; }
#kolobok-container {
    width: min(70vw, 270px);
    height: min(70vw, 270px);
    min-width: 190px;
    min-height: 190px;
    max-width: 270px;
    max-height: 270px;
    margin: auto;
    flex-shrink: 0;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    border: 2px solid rgba(255, 209, 102, 0.35);
    background: radial-gradient(circle at 35% 25%, rgba(255, 209, 102, 0.25), rgba(84, 217, 255, 0.07) 60%, transparent 75%);
    box-shadow: 0 0 30px rgba(255, 193, 77, 0.16), inset 0 0 35px rgba(255, 209, 102, 0.12);
    cursor: pointer;
    touch-action: none;
    transition: transform 0.12s;
    animation: kolobokGlow 3s ease-in-out infinite alternate;
    -webkit-user-select: none;
    user-select: none;
}
#kolobok-container:active {
    transform: none;
}

#kolobok-container.tap-anim {
    animation: kolobokTap 0.15s ease;
}

@keyframes kolobokTap {
    0%   { transform: scale(1); }
    35%  { transform: scale(0.94); }
    100% { transform: scale(1); }
}
@keyframes kolobokTap {
    0% { transform: scale(1); }
    50% { transform: scale(0.88); }
    100% { transform: scale(1); }
}
@keyframes kolobokGlow {
    from { box-shadow: 0 0 20px rgba(255, 193, 77, 0.12), inset 0 0 20px rgba(255, 209, 102, 0.08); }
    to { box-shadow: 0 0 42px rgba(255, 193, 77, 0.28), inset 0 0 35px rgba(255, 209, 102, 0.18); }
}
#kolobok-img { width: 84%; height: 84%; object-fit: contain; pointer-events: none; filter: drop-shadow(0 12px 20px rgba(0, 0, 0, 0.35)); position: relative; z-index: 2; }

.ad-btn {
    position: relative;
    z-index: 20;
    width: 85%;
    max-width: 310px;
    margin: 10px auto;
    padding: 13px 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 9px;
    color: #291900;
    background: var(--gold-gradient);
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 16px;
    font-size: 14px;
    font-weight: 900;
    box-shadow: 0 7px 25px rgba(255, 177, 48, 0.25);
    transition: transform 0.2s;
}
.ad-btn:active { transform: scale(0.96); }

#no-energy-screen { width: 100%; }
.battery-container-v2 {
    width: 100%;
    max-width: 370px;
    margin: 10px auto 0;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--panel-gradient);
    border: 1px solid var(--border-color);
    border-radius: 19px;
    box-shadow: var(--neon-shadow);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
}
.battery-header { width: 100%; display: flex; justify-content: space-between; margin-bottom: 9px; color: var(--text-secondary); font-size: 12px; font-weight: 800; }
.battery-segments { width: 100%; height: 22px; padding: 3px; display: flex; gap: 5px; border-radius: 8px; border: 1px solid var(--border-color); background: rgba(0, 0, 0, 0.2); }
.segment { flex: 1; border-radius: 4px; background: rgba(255, 255, 255, 0.07); transition: background 0.25s, box-shadow 0.25s; }
.segment.green { background: #27e68a; box-shadow: 0 0 10px rgba(39, 230, 138, 0.5); }
.segment.yellow { background: #ffd166; box-shadow: 0 0 10px rgba(255, 209, 102, 0.5); }
.segment.red { background: #ff526a; box-shadow: 0 0 10px rgba(255, 82, 106, 0.5); }
.battery-timer { margin-top: 9px; color: var(--accent); font-size: 12px; font-weight: 800; }

.floating-text { position: fixed; z-index: 9999; pointer-events: none; transform: translate(-50%, -50%); color: var(--primary); font-size: 30px; font-weight: 1000; text-shadow: 0 3px 15px rgba(0, 0, 0, 0.8), 0 0 15px rgba(255, 209, 102, 0.6); animation: floatUp 0.85s ease-out forwards; }
@keyframes floatUp { 0% { opacity: 1; transform: translate(-50%, -50%) scale(0.65); } 100% { opacity: 0; transform: translate(-50%, -150%) scale(1.25); } }

.page-bg {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom, 0px));
    background: radial-gradient(ellipse at 50% 0%, rgba(84, 217, 255, 0.055), transparent 55%), var(--bg-page);
    scrollbar-width: none;
}
.page-bg::-webkit-scrollbar { display: none; }
.page-content { width: 100%; min-height: 100%; padding: 20px 16px; display: flex; flex-direction: column; align-items: center; }
.page-title { margin: 5px 0 22px; color: var(--primary); font-size: 25px; font-weight: 950; letter-spacing: 0.5px; text-align: center; text-shadow: 0 0 20px rgba(255, 209, 102, 0.2); }

.card { display: flex; align-items: center; justify-content: center; gap: 12px; border-radius: 22px; border: 1px solid var(--border-color); background: var(--panel-gradient); box-shadow: var(--neon-shadow); }
.card-icon { margin-bottom: 8px; }
.card-title { font-weight: 900; text-align: center; }
.action-btn {
    min-height: 46px;
    padding: 12px 20px;
    color: #251600;
    background: var(--gold-gradient);
    border: 0;
    border-radius: 14px;
    font-weight: 900;
    box-shadow: 0 6px 20px rgba(255, 177, 48, 0.2);
    transition: transform 0.2s, filter 0.2s;
    -webkit-appearance: none;
    appearance: none;
}
.action-btn:active { transform: scale(0.97); filter: brightness(0.94); }

.shop-tabs { display: flex; gap: 7px; width: 100%; max-width: 420px; margin-bottom: 18px; padding: 5px; border: 1px solid var(--border-color); border-radius: 15px; background: rgba(0, 0, 0, 0.18); }
.shop-tab { flex: 1; padding: 11px 5px; color: var(--text-secondary); background: transparent; border: 0; border-radius: 11px; font-size: 12px; font-weight: 850; -webkit-appearance: none; appearance: none; }
.shop-tab.active { color: #241600; background: var(--gold-gradient); box-shadow: 0 3px 15px rgba(255, 177, 48, 0.2); }
.shop-content { width: 100%; display: none; flex-direction: column; align-items: center; }
.shop-content.active { display: flex; animation: screenEnter 0.25s ease; }
.shop-grid { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 11px; }

.upgrade-card { width: 100%; padding: 15px; display: flex; align-items: center; gap: 13px; position: relative; overflow: hidden; cursor: pointer; background: var(--panel-gradient); border: 1px solid var(--border-color); border-radius: 17px; box-shadow: var(--neon-shadow); transition: transform 0.2s, border-color 0.2s; }
.upgrade-card:active { transform: scale(0.98); border-color: var(--primary); }
.upgrade-icon { width: 48px; height: 48px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, 0.06); border-radius: 14px; font-size: 26px; }
.upgrade-info { flex: 1; min-width: 0; }
.upgrade-title { color: var(--text-main); font-weight: 900; font-size: 14px; }
.upgrade-level { color: var(--accent); font-size: 12px; margin-top: 4px; font-weight: 800; }
.upgrade-price { padding: 8px 10px; border-radius: 10px; background: rgba(255, 209, 102, 0.1); color: var(--primary); font-size: 12px; font-weight: 900; white-space: nowrap; }

.market-filters { width: 100%; max-width: 420px; display: flex; gap: 7px; overflow-x: auto; margin-bottom: 16px; padding-bottom: 5px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.market-filters::-webkit-scrollbar { display: none; }
.filter-btn { flex-shrink: 0; padding: 8px 13px; border: 1px solid var(--border-color); border-radius: 30px; color: var(--text-secondary); background: var(--card-bg); font-size: 11px; font-weight: 850; -webkit-appearance: none; appearance: none; }
.filter-btn.active { color: #251600; background: var(--gold-gradient); border-color: var(--primary); }
.filter-btn.rare.active { background: #1878ff; color: white; }
.filter-btn.epic.active { background: #a33dff; color: white; }
.filter-btn.mythic.active { background: #ed49c4; color: white; }
.filter-btn.legendary.active { background: var(--gold-gradient); color: #251600; }

.market-grid { width: 100%; max-width: 420px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.market-card { min-width: 0; min-height: 160px; padding: 14px 9px; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; overflow: hidden; cursor: pointer; border: 1px solid var(--border-color); border-radius: 18px; background: var(--panel-gradient); transition: transform 0.2s; -webkit-appearance: none; appearance: none; }
.market-card:active { transform: scale(0.96); }
.market-card.rare { border-color: rgba(24, 120, 255, 0.6); }
.market-card.epic { border-color: rgba(163, 61, 255, 0.65); }
.market-card.mythic { border-color: rgba(237, 73, 196, 0.65); }
.market-card.legendary { border-color: rgba(255, 209, 102, 0.75); }
.market-rarity-badge { position: absolute; top: 8px; right: 8px; padding: 4px 7px; border-radius: 7px; background: rgba(0, 0, 0, 0.45); font-size: 9px; font-weight: 900; text-transform: uppercase; }
.rare .market-rarity-badge { color: #58a2ff; }
.epic .market-rarity-badge { color: #c18aff; }
.mythic .market-rarity-badge { color: #ff78df; }
.legendary .market-rarity-badge { color: var(--primary); }
.market-item-preview { width: 78px; height: 78px; margin: 10px 0; background-position: center; background-size: cover; background-repeat: no-repeat; }
.market-item-preview.round { border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.2); }
.market-item-name { color: var(--text-main); font-size: 13px; font-weight: 850; text-align: center; }
.market-item-price { margin-top: 6px; color: var(--primary); font-weight: 900; font-size: 13px; }

.items-grid { width: 100%; display: flex; justify-content: center; flex-wrap: wrap; gap: 11px; }
.item { width: 92px; min-height: 105px; padding: 10px 6px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px; color: var(--text-main); background: var(--panel-gradient); border: 1px solid var(--border-color); border-radius: 15px; font-size: 11px; font-weight: 800; text-align: center; cursor: pointer; transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s; -webkit-appearance: none; appearance: none; }
.item:active { transform: scale(0.95); }
.item.active { border-color: var(--primary); box-shadow: 0 0 12px rgba(255, 209, 102, 0.35); }
.item img { object-fit: cover; max-width: 65px; max-height: 65px; }

.leaderboard { width: 100%; max-width: 420px; padding: 7px 12px; border: 1px solid var(--border-color); border-radius: 20px; background: var(--panel-gradient); box-shadow: var(--neon-shadow); }
.leader-row { min-height: 68px; padding: 10px 5px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--border-color); }
.leader-row:last-child { border-bottom: 0; }

.raffle-card { width: 100%; max-width: 370px; padding: 26px 20px; position: relative; overflow: hidden; text-align: center; border: 1px solid rgba(255, 209, 102, 0.55); border-radius: 25px; background: radial-gradient(circle at 50% 0%, rgba(255, 209, 102, 0.22), transparent 55%), var(--panel-gradient); box-shadow: 0 10px 35px rgba(255, 177, 48, 0.12); }
.raffle-card::before { content: ""; position: absolute; inset: -100%; pointer-events: none; background: conic-gradient(transparent, rgba(255, 209, 102, 0.07), transparent 30%); animation: raffleGlow 12s linear infinite; }
@keyframes raffleGlow { to { transform: rotate(360deg); } }
.raffle-title { position: relative; color: var(--primary); font-size: 25px; font-weight: 950; margin-bottom: 12px; }
.raffle-prize { position: relative; color: white; font-size: 19px; font-weight: 900; margin-bottom: 18px; }
.raffle-timer { position: relative; color: var(--accent); font-size: 32px; font-weight: 950; margin-bottom: 18px; }

nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    min-height: var(--nav-height);
    padding: 8px 5px max(10px, env(safe-area-inset-bottom, 0px));
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: 2px;
    background: rgba(9, 13, 24, 0.94);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    transition: transform 0.3s;
}
nav.nav-hidden { transform: translateY(110%); }
.nav-btn {
    flex: 1;
    min-width: 0;
    min-height: 58px;
    padding: 6px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    color: #8c98ae;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 13px;
    font-size: 9px;
    font-weight: 850;
    transition: color 0.2s, background 0.2s;
    -webkit-appearance: none;
    appearance: none;
}
.nav-btn i { font-size: 19px; }
.nav-btn.active { color: var(--primary); background: rgba(255, 209, 102, 0.08); border-color: rgba(255, 209, 102, 0.16); }
.nav-btn.active i { filter: drop-shadow(0 0 7px var(--primary)); transform: translateY(-2px); }

.modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    padding-top: calc(15px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    background: rgba(0, 0, 0, 0.78);
    -webkit-backdrop-filter: blur(9px);
    backdrop-filter: blur(9px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s, visibility 0.25s;
}
.modal.active { opacity: 1; visibility: visible; }
.modal-content {
    width: 100%;
    max-width: 420px;
    max-height: calc(var(--app-height, 100dvh) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 30px);
    max-height: min(90vh, calc(var(--app-height, 100dvh) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 30px));
    padding: 22px 17px;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 25px;
    box-shadow: 0 20px 70px rgba(0, 0, 0, 0.5);
    transform: translateY(20px) scale(0.97);
    transition: transform 0.3s;
}
.modal.active .modal-content { transform: translateY(0) scale(1); }
.close-btn { position: absolute; top: 12px; right: 17px; z-index: 5; color: var(--text-secondary); font-size: 30px; cursor: pointer; background: transparent; border: 0; -webkit-appearance: none; appearance: none; }
.profile-header { display: flex; flex-direction: column; align-items: center; margin: 15px 0 18px; }
.profile-avatar-wrapper { width: 105px; height: 105px; margin-bottom: 13px; position: relative; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 3px solid var(--primary); background: rgba(255, 255, 255, 0.04); box-shadow: 0 0 28px rgba(255, 209, 102, 0.2); }
.profile-avatar { width: 92px; height: 92px; border-radius: 50%; object-fit: cover; }
.nick-edit-container { display: flex; flex-direction: column; align-items: center; margin-bottom: 12px; width: 100%; }
#nick-input-container { display: none; gap: 8px; margin-top: 10px; align-items: center; justify-content: center; width: 100%; }
#input-new-nick {
    min-width: 0;
    width: 150px;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-main);
    font-size: 16px; /* iOS: 16px чтобы не было зума при фокусе */
}
.invite-btn {
    width: 100%;
    padding: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #071522;
    background: linear-gradient(100deg, var(--accent), #399bff);
    border: 0;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 900;
    box-shadow: 0 5px 18px rgba(84, 217, 255, 0.16);
    -webkit-appearance: none;
    appearance: none;
}

.profile-tabs { width: 100%; display: flex; gap: 5px; padding: 5px; margin-bottom: 12px; background: rgba(0, 0, 0, 0.2); border: 1px solid var(--border-color); border-radius: 14px; }
.p-tab { flex: 1; padding: 10px 5px; color: var(--text-secondary); background: transparent; border: 0; border-radius: 10px; font-size: 12px; font-weight: 850; -webkit-appearance: none; appearance: none; }
.p-tab.active { color: var(--primary); background: var(--card-bg); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); }
.profile-content { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 5px 2px; }
.p-content { display: none; }
.p-content.active { display: block; }
.reset-btn { padding: 6px 12px; color: var(--text-main); background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 9px; font-size: 11px; -webkit-appearance: none; appearance: none; }

.themes-grid { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }
.theme-btn { width: 82px; height: 78px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; color: white; border: 2px solid transparent; border-radius: 15px; font-size: 11px; font-weight: 850; cursor: pointer; transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s; -webkit-appearance: none; appearance: none; }
.theme-btn.active { border-color: var(--primary); box-shadow: 0 0 15px rgba(255, 209, 102, 0.3); transform: scale(1.04); }
.theme-btn.dark { background: #101827; }
.theme-btn.light { color: #172033; background: #f2f4f8; }
.theme-btn.neon { color: #ff77ed; background: #180b2a; border-color: #7e28b7; }

.popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    background: rgba(0, 0, 0, 0.78);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s, visibility 0.25s;
}
.popup-overlay.active { opacity: 1; visibility: visible; }
.popup-content { width: 100%; max-width: 350px; padding: 27px 20px; text-align: center; background: var(--panel-gradient); border: 1px solid var(--accent); border-radius: 23px; box-shadow: 0 15px 50px rgba(0, 0, 0, 0.45), 0 0 25px rgba(84, 217, 255, 0.12); transform: scale(0.92); transition: transform 0.25s; }
.popup-overlay.active .popup-content { transform: scale(1); }

#video-overlay { z-index: 99999; }

/* Дописанные классы */
.header-inner { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; border: 0; -webkit-appearance: none; appearance: none; }
.nick-container { display: flex; flex-direction: column; min-width: 0; }
.nick-container #header-nick { font-weight: 900; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.nick-sub { font-size: 10px; color: var(--text-secondary); font-weight: 700; }
.currency { display: flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 900; }
.currency.blue { color: var(--accent); }
.currency.gold { color: var(--primary); }

.exchange-card, .donate-card { flex-direction: column; padding: 22px 18px; width: 100%; max-width: 380px; margin-bottom: 14px; text-align: center; }
.wallet-address { font-family: monospace; font-size: 11px; word-break: break-all; color: var(--text-secondary); background: rgba(0, 0, 0, 0.25); padding: 10px; border-radius: 10px; width: 100%; }
.btn-pink { background: linear-gradient(100deg, #ff6ec4, #7873f5); color: #fff; }

.inventory-heading { color: var(--text-secondary); font-size: 13px; font-weight: 800; margin: 14px 0 8px; text-align: center; }
.bg-section-header { display: flex; justify-content: space-between; align-items: center; width: 100%; margin: 14px 0 8px; }
.bg-section-header h3 { color: var(--text-secondary); font-size: 13px; font-weight: 800; }
.empty-state { grid-column: 1 / -1; text-align: center; color: var(--text-secondary); padding: 24px; }

.leader-tabs { display: flex; gap: 6px; width: 100%; max-width: 420px; margin-bottom: 14px; padding: 5px; background: rgba(0, 0, 0, 0.2); border: 1px solid var(--border-color); border-radius: 14px; }
.leader-tab { flex: 1; padding: 10px 6px; color: var(--text-secondary); background: transparent; border: 0; border-radius: 10px; font-size: 12px; font-weight: 850; -webkit-appearance: none; appearance: none; }
.leader-tab.active { color: #251600; background: var(--gold-gradient); }
.leader-header { text-align: center; margin-bottom: 18px; }
.leader-header .trophy-icon { font-size: 56px; filter: drop-shadow(0 0 18px rgba(255, 209, 102, 0.6)); margin-bottom: 6px; }
.leader-header h2 { color: var(--primary); font-size: 24px; font-weight: 950; letter-spacing: 1px; }
.leader-header p { color: var(--text-secondary); font-size: 12px; font-weight: 700; margin-top: 4px; }
.top-players-list { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.top-player-card { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--panel-gradient); border: 1px solid var(--border-color); border-radius: 14px; box-shadow: var(--neon-shadow); }
.top-player-card.rank-1 { border-color: var(--primary); box-shadow: 0 0 20px rgba(255, 209, 102, 0.25); }
.top-player-card.rank-2 { border-color: rgba(198, 211, 232, 0.5); }
.top-player-card.rank-3 { border-color: rgba(217, 155, 108, 0.6); }
.tp-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.tp-rank { width: 26px; text-align: center; font-weight: 900; color: var(--primary); font-size: 15px; flex-shrink: 0; }
.tp-avatar-wrapper { flex-shrink: 0; }
.tp-avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border-color); }
.tp-info { min-width: 0; }
.tp-name { font-weight: 800; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-level { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.tp-right { display: flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 900; font-size: 14px; flex-shrink: 0; }
.tp-stars-icon { font-size: 14px; }
.player-rank-box { width: 100%; max-width: 420px; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--panel-gradient); border: 1px solid var(--primary); border-radius: 16px; box-shadow: 0 0 20px rgba(255, 209, 102, 0.18); }
.rank-label { font-size: 10px; color: var(--text-secondary); font-weight: 800; letter-spacing: 0.5px; }
.rank-value { font-size: 22px; font-weight: 950; color: var(--primary); }
.rank-score { display: flex; align-items: center; gap: 6px; font-size: 18px; font-weight: 900; color: var(--accent); }
.star-icon { font-size: 18px; }

/* Fallback only for older iOS versions without dynamic viewport units. */
@supports (-webkit-touch-callout: none) and (not (height: 100dvh)) {
    html { height: -webkit-fill-available; }
    body { height: -webkit-fill-available; }
}
@supports (-webkit-touch-callout: none) {
    input, textarea, select { font-size: 16px; }
}

/* Fallback для старых iOS без gap в flex */
@supports not (gap: 10px) {
    .user-info > * + * { margin-left: 10px; }
    .balance-box > * + * { margin-left: 12px; }
    .nav-btn > * + * { margin-top: 5px; }
}

@media (max-width: 360px) {
    header { padding: 8px 9px 5px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
    .neon-box { padding: 8px 10px; }
    .balance-box { gap: 7px; font-size: 12px; }
    .page-content { padding: 15px 11px; }
    .nav-btn { font-size: 8px; }
    .nav-btn i { font-size: 17px; }
    #kolobok-container { width: 215px; height: 215px; }
}
@media (min-width: 600px) {
    .page-content { padding-top: 25px; }
    .market-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}

/* Desktop and landscape safety */
@media (min-width: 768px) {
    .page-content {
        max-width: 760px;
        margin-inline: auto;
    }
    nav {
        left: 50%;
        right: auto;
        width: min(100%, 760px);
        transform: translateX(-50%);
        border-left: 1px solid rgba(255, 255, 255, 0.08);
        border-right: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 16px 16px 0 0;
    }
    nav.nav-hidden {
        transform: translate(-50%, 110%);
    }
}
@media (max-height: 560px) and (orientation: landscape) {
    header { padding-top: max(5px, env(safe-area-inset-top, 0px)); }
    .neon-box { padding-block: 5px; }
    .avatar-wrapper { width: 42px; height: 42px; }
    .avatar { width: 32px; height: 32px; }
    #screen-tap { padding-top: 5px; }
    #kolobok-container { width: min(45vh, 190px); height: min(45vh, 190px); min-width: 150px; min-height: 150px; }
    nav { min-height: 62px; }
    .nav-btn { min-height: 50px; }
}
/* Отключаем двойной тап для увеличения страницы на iPhone */
html,
body {
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

/* Не даём Safari увеличивать страницу при фокусе на полях */
input,
textarea,
select {
    font-size: 16px !important;
}

/* Игровая область */
#screen-tap,
#kolobok-container,
button,
.nav-btn {
    touch-action: manipulation;
}

html {
    touch-action: pan-x pan-y;
}

body {
    touch-action: pan-x pan-y;
    -webkit-text-size-adjust: 100%;
}

#screen-tap,
#kolobok-container,
#kolobok-img,
button,
.nav-btn,
.page-content,
.screen {
    touch-action: manipulation;
}