/* ======================================= */
/* БАЗОВЫЕ ПЕРЕМЕННЫЕ И ФОН (Telegram WebApp) */
/* ======================================= */
:root {
    --tg-theme-bg-color: #121927;
    --tg-theme-secondary-bg: #1c2738;
    --tg-theme-text-color: #f0f8ff;
    --tg-theme-hint-color: #a0aec0;
    --tg-theme-button-color: #4a5568;
    --tg-theme-button-text-color: #ffffff;
    
    --color-accent-blue: #A9D9F8;
    --color-cta-start: #7868e6;
    --color-cta-end: #3f55d2;
}

body {
    background: linear-gradient(180deg, var(--tg-theme-bg-color) 0%, #0d121b 100%);
    color: var(--tg-theme-text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    /* ИДЕАЛЬНОЕ РАСПОЛОЖЕНИЕ */
    padding-top: 5vh; 
    padding-bottom: 70px; 
    position: relative;
    overflow-x: hidden;
}

/* ======================================= */
/* НОВОГОДНИЙ СНЕГОПАД */
/* ======================================= */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(2px 2px at 20px 30px, rgba(138, 181, 224, 0.3) 50%, transparent 50%),
        radial-gradient(2px 2px at 40px 70px, rgba(169, 217, 248, 0.2) 50%, transparent 50%),
        radial-gradient(1.5px 1.5px at 60px 20px, rgba(224, 255, 255, 0.25) 50%, transparent 50%),
        radial-gradient(2px 2px at 80px 50px, rgba(138, 181, 224, 0.3) 50%, transparent 50%),
        radial-gradient(2.5px 2.5px at 100px 90px, rgba(169, 217, 248, 0.2) 50%, transparent 50%);
    background-size: 120px 120px;
    z-index: -1;
    pointer-events: none;
    animation: snowfall 20s linear infinite;
}

@keyframes snowfall {
    0% { background-position: 0 0, 0 0, 0 0, 0 0, 0 0; }
    100% { background-position: 0 120px, 30px 120px, 60px 120px, 90px 120px, 120px 120px; }
}

/* ======================================= */
/* КОНТЕЙНЕР ПРОФИЛЯ (ЧУТЬ МЕНЬШЕ) */
/* ======================================= */
.profile-container {
    max-width: 390px; /* Уменьшили с 420px */
    margin: 10px auto;
    padding: 20px 18px; /* Уменьшили отступы */
    text-align: center;
    background-color: rgba(28, 39, 56, 0.85); 
    border-radius: 22px;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.6),
        0 0 50px rgba(169, 217, 248, 0.1);
    width: 88%; 
    margin-bottom: 15px;
    backdrop-filter: blur(5px); 
    border: 1px solid rgba(169, 217, 248, 0.15);
    position: relative;
    z-index: 1;
}

.profile-header {
    margin-bottom: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

/* МАЛЕНЬКАЯ АВАТАРКА (В шапке) */
#user-avatar-header {
    width: 32px !important;     /* Реально маленький размер */
    height: 32px !important;
    min-width: 32px !important;  /* Убрали 82px, которые всё ломали */
    min-height: 32px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    border: 1.5px solid var(--color-accent-blue);
    box-shadow: 0 0 8px rgba(169, 217, 248, 0.4);
    display: block;
}

/* БОЛЬШАЯ АВАТАРКА (В центре профиля) */
#user-avatar-profile-page, 
#user-avatar {
    width: 82px !important;
    height: 82px !important;
    min-width: 82px !important;
    min-height: 82px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    border: 3px solid var(--color-accent-blue);
    margin: 0 auto 10px auto;
    display: block;
}

/* Контейнер в шапке для выравнивания */
.profile-wrapper .profile {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
}

/* ======================================= */
/* БЛОКИ ИНФОРМАЦИИ */
/* ======================================= */
.profile-info {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px; /* Уменьшили зазор */
    text-align: left;
}
.info-block {
    padding: 10px 14px; /* Уменьшили внутренние отступы */
    background-color: rgba(36, 49, 71, 0.85); 
    border-radius: 13px;
    border-left: 4px solid var(--color-accent-blue);
    box-shadow: inset 0 1px 5px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
    backdrop-filter: blur(5px);
}

.info-block strong {
    color: #B8C2D9; 
    display: block;
    font-size: 0.8em; 
    margin-bottom: 3px;
    opacity: 0.9;
}
.info-block span {
    color: var(--tg-theme-text-color);
    font-weight: 700;
    font-size: 0.95em; /* Уменьшили с 1.05em */
    display: block;
    word-break: break-all; 
}

/* ======================================= */
/* КНОПКА ИНВЕНТАРЯ */
/* ======================================= */
.btn-inventory {
    width: 88%; 
    padding: 11px 22px !important; 
    max-width: 300px; 
    background: linear-gradient(90deg, var(--color-cta-start) 0%, var(--color-cta-end) 100%);
    border: none;
    border-radius: 12px !important; 
    color: var(--tg-theme-button-text-color);
    font-size: 0.95em !important; 
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: block;
    margin: 15px auto 5px auto; 
    text-align: center;
    position: relative;
    z-index: 2;
    box-shadow: 0 5px 20px rgba(100, 100, 200, 0.5);
}

/* ======================================= */
/* ОБЕРТКА ДЛЯ ГИБКОГО ПОЗИЦИОНИРОВАНИЯ */
/* ======================================= */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

.profile-container {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
}

/* АДАПТИВНОСТЬ */
@media (max-width: 480px) {
    .profile-container {
        padding: 18px 14px;
    }
    #user-avatar {
        width: 75px;
        height: 75px;
    }
    .profile-header h1 {
        font-size: 1.3em;
    }
}

/* Дополнительный снег для мобильных */
@media (max-width: 768px) {
    body::before {
        background-image: 
            radial-gradient(2px 2px at 10px 20px, rgba(138, 181, 224, 0.3) 50%, transparent 50%),
            radial-gradient(1.5px 1.5px at 25px 50px, rgba(169, 217, 248, 0.25) 50%, transparent 50%),
            radial-gradient(1.5px 1.5px at 40px 10px, rgba(224, 255, 255, 0.3) 50%, transparent 50%),
            radial-gradient(2px 2px at 55px 35px, rgba(138, 181, 224, 0.3) 50%, transparent 50%),
            radial-gradient(2px 2px at 70px 60px, rgba(169, 217, 248, 0.25) 50%, transparent 50%);
        background-size: 80px 80px;
    }
}

.profile-header {
    position: relative; /* Чтобы подарки позиционировались относительно шапки */
}

.floating-items-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100px;
    pointer-events: none; /* Чтобы иконки не мешали кликать на аватар */
}

.floating-gift {
    position: absolute;
    width: 45px; /* Чуть увеличили для сочности */
    height: 45px;
    filter: drop-shadow(0 5px 15px rgba(0,0,0,0.3));
    transition: all 0.3s ease;
    z-index: 5; /* Чтобы были над фоном, но не перекрывали важные кнопки */
}

/* Первый подарок (слева, наклонен влево) */
.floating-gift:nth-child(1) { 
    left: 15%; 
    top: 10px; 
    transform: rotate(-15deg); 
    animation: float1 4s ease-in-out infinite; 
}

/* Второй подарок (центральный, чуть выше аватара, стоит прямо) */
.floating-gift:nth-child(2) { 
    left: 65%; 
    top: 0px; 
    transform: rotate(0deg); 
    animation: float2 3s ease-in-out infinite; 
}

/* Третий подарок (справа, наклонен вправо) */
.floating-gift:nth-child(3) { 
    right: 8%; 
    top: 50px; 
    transform: rotate(15deg); 
    animation: float3 4.5s ease-in-out infinite; 
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

/* Кнопка-карандаш в шапке */
.edit-profile-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    color: white;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: background 0.2s;
    z-index: 100;
}

.edit-profile-btn:active {
    background: rgba(255, 255, 255, 0.3);
}

/* Фон модального окна */

/* Контент модалки */
.modal-content {
    background: #1c1c1e !important;
    width: 90% !important;
    max-width: 340px !important;
    border-radius: 25px !important;
    padding: 25px !important;
    position: relative !important;
    margin: auto !important; 
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
    
    /* Убираем любые движения и масштабирование */
    animation: fadeIn 0.15s ease-out !important; 
    transform: none !important;
    transition: none !important;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #fff;
}

/* Слоты (куда залетают подарки) */
.featured-slots-admin {
    display: flex;
    flex-direction: row;
    justify-content: center; /* Центрирует слоты в ряд */
    align-items: center;
    gap: 10px;
    width: 100%;
    margin: 20px 0;
}

.slot {
    width: 85px; 
    height: 85px;
    border: 2px dashed #444;
    border-radius: 20px;
    background-color: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-sizing: border-box;
}

/* Мини-инвентарь в модалке */
.mini-inventory-grid {
    width: 100% !important;
    max-height: 200px !important; /* Ограничиваем высоту инвентаря внутри */
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 10px !important;
    overflow-y: auto !important;
    margin: 15px 0 !important;
    padding: 5px !important;
}

.mini-item {
    background: #2c2c2e !important;
    border-radius: 12px !important;
    aspect-ratio: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px !important;
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
}

.mini-item:active {
    transform: scale(0.9);
}

.mini-item img {
    width: 100%; height: 100%;
    object-fit: contain;
}

/* Кнопка сохранить */
.btn-save-featured {
    width: 100%;
    padding: 14px;
    background: #007aff; /* Классический синий цвет Apple/Telegram */
    border: none;
    border-radius: 15px;
    color: white;
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
}

.btn-save-featured:active {
    background: #0056b3;
}

/* Анимация появления */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Скроллбар для мини-инвентаря */
.mini-inventory-grid::-webkit-scrollbar {
    width: 4px;
}
.mini-inventory-grid::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 10px;
}

/* --- ФИНАЛЬНЫЕ ИСПРАВЛЕННЫЕ СТИЛИ МОДАЛКИ --- */

/* Крестик строго справа в углу */
.close-modal {
    position: absolute !important;
    top: 15px !important;
    right: 15px !important;
    width: 32px !important;
    height: 32px !important;
    background: rgba(255, 255, 255, 0.15) !important;
    border-radius: 50% !important;
    color: #fff !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    z-index: 11000 !important;
}

/* Слоты строго в горизонтальный ряд */
.featured-slots-admin, .slots-preview {
    display: flex !important;
    flex-direction: row !important;
    justify-content: center !important; /* Центрируем слоты внутри */
    gap: 12px !important;
    margin: 20px 0 !important;
    width: 100% !important;
}

/* Красивые слоты */
.slot {
    width: 80px !important;
    height: 80px !important;
    border: 2px dashed #444 !important;
    border-radius: 18px !important;
    background-color: rgba(255, 255, 255, 0.05) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
}

/* Кнопка сохранить (Telegram Style) */
.save-btn, .btn-save-featured {
    width: 100% !important;
    padding: 18px !important;
    background: #007aff !important;
    color: #fff !important;
    border: none !important;
    border-radius: 18px !important;
    font-size: 16px !important;
    font-weight: 800 !important;
    cursor: pointer !important;
    box-shadow: 0 4px 15px rgba(0, 122, 255, 0.3) !important;
    text-transform: uppercase !important;
}

.save-btn:active {
    background: #005ecb !important;
    transform: scale(0.98);
}

/* Анимация для 1-го подарка */
@keyframes float1 {
    0%, 100% { transform: translateY(0) rotate(-15deg); }
    50% { transform: translateY(-10px) rotate(-20deg); }
}

/* Анимация для 2-го (центрального) */
@keyframes float2 {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-15px) rotate(0deg); }
}

/* Анимация для 3-го подарка */
@keyframes float3 {
    0%, 100% { transform: translateY(0) rotate(15deg); }
    50% { transform: translateY(-8px) rotate(20deg); }
}

/* Стили для системы уровней */
.level-card {
    background: rgba(169, 217, 248, 0.1);
    border: 1px solid rgba(169, 217, 248, 0.2);
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 20px;
}

.level-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.level-badge {
    background: #A9D9F8;
    color: #000;
    padding: 4px 10px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 13px;
    text-transform: uppercase;
}

.xp-counter {
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    font-family: monospace;
}

.progress-container {
    background: rgba(255, 255, 255, 0.1);
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    width: 0%; /* Будет меняться через JS */
    background: linear-gradient(90deg, #A9D9F8 0%, #667eea 100%);
    box-shadow: 0 0 10px rgba(169, 217, 248, 0.5);
    transition: width 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Кнопка-вопрос */
.info-help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: sans-serif;
}

.info-help-btn:hover {
    background: rgba(169, 217, 248, 0.3);
    border-color: #A9D9F8;
}

/* Окно (Модалка) */
.modal-overlay {
    display: none; /* Включай через flex в JS */
    position: fixed !important; /* Фиксируем ОТНОСИТЕЛЬНО ОКНА БРАУЗЕРА */
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.6) !important; /* Уменьшил затемнение, чтобы было приятнее */
    backdrop-filter: blur(5px) !important;
    z-index: 10000 !important;
    
    /* Центрируем содержимое оверлея */
    justify-content: center !important;
    align-items: center !important;
    margin: 0 !important;
    padding: 0 !important;
}

.modal-content {
    background: #1c1c1e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 85%;           /* Окно не на весь экран, а аккуратное */
    max-width: 340px;     /* Ограничение ширины */
    height: auto;         /* ВЫСОТА ТЕПЕРЬ ПО КОНТЕНТУ, а не на весь экран */
    padding: 25px 20px;
    border-radius: 25px;
    position: relative;
    box-shadow: 0 15px 40px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.2s ease-out !important;
}

/* ======================================= */
/* СТИЛЬ МОДАЛЬНОГО ОКНА (СИСТЕМА ОПЫТА)  */
/* ======================================= */

/* 1. Фон-затемнение (Overlay) */
.modal-overlay, .modal {
    display: none; /* Скрыто по умолчанию */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.8) !important;
    backdrop-filter: blur(8px);
    z-index: 99999 !important; /* Самый верхний слой */
    
    /* Центрирование контента внутри */
    justify-content: center !important;
    align-items: center !important;
}

/* 2. Контентное окно */
.modal-content {
    background: #1c1c1e !important;
    width: 90% !important;
    max-width: 340px !important;
    border-radius: 25px !important;
    padding: 25px !important;
    position: relative !important;
    margin: auto !important; 
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
    
    /* Убираем любые движения и масштабирование */
    animation: fadeIn 0.15s ease-out !important; 
    transform: none !important;
    transition: none !important;
}
/* 3. Заголовок и текст */
.modal-content-level h3 {
    margin: 0 0 10px 0;
    font-size: 22px;
    color: var(--color-accent-blue);
    text-shadow: 0 0 15px rgba(169, 217, 248, 0.3);
}

.modal-content-level p {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 20px;
}

/* 4. Карточка с инфо по XP */
.xp-info-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    padding: 16px;
    margin-bottom: 25px;
}

.xp-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.xp-row:last-child {
    margin-bottom: 0;
}

.xp-label {
    font-size: 14px;
    color: #f0f8ff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.xp-value {
    font-weight: 800;
    color: var(--color-accent-blue);
    font-family: 'Courier New', monospace;
}

@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: scale(1); /* Убираем изменение размера, оставляем только прозрачность */
    }
    to { 
        opacity: 1; 
        transform: scale(1); 
    }
}