html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

:root {
    --bg: #000;
    --card: #111;
    --border: #222;
    --green: #39FF14;
    --yellow: #ffcc00;
    --text-sec: #666;
}

/* --- ОСНОВНЫЕ СТИЛИ --- */

body { 
    background: var(--bg); 
    color: #fff; 
    font-family: 'Inter', sans-serif; 
    margin: 0; 
    min-height: 100vh;
}

/* Блокировка скролла фона (активируется через JS) */
body.modal-open {
    overflow: hidden !important;
    height: 100vh !important;
    position: fixed;
    width: 100%;
}

.app-container { 
    width: 100%; 
    max-width: 450px; 
    margin: 0 auto;   
    min-height: 100vh;
    padding: 20px 16px 120px; 
    background: var(--bg);
    box-sizing: border-box;
    display: block; 
}

#user-shelf {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 15px;
}

.profile-header { text-align: center; position: relative; margin-bottom: 24px; }
.settings-trigger { position: absolute; right: 0; top: 0; font-size: 24px; color: #555; cursor: pointer; padding: 5px; }
.avatar-ring { position: relative; width: 90px; height: 90px; margin: 0 auto 12px; }
.avatar-ring img { width: 100%; height: 100%; border-radius: 50%; border: 2px solid var(--green); object-fit: cover; }
.badge { position: absolute; bottom: 0; right: 0; background: var(--green); color: #000; font-size: 10px; font-weight: 900; padding: 2px 4px; border-radius: 4px; }

.rank-row { display: flex; gap: 10px; margin-top: 15px; }
.rank-card { flex: 1; background: var(--card); border: 1px solid var(--border); padding: 12px; border-radius: 12px; }
.rank-card strong { display: block; font-size: 18px; }
.rank-card span { font-size: 10px; color: var(--text-sec); }

.status-banner-mini {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0;
    cursor: pointer;
}
.status-txt { color: var(--yellow); font-weight: 800; font-size: 13px; }
.status-action-btn { background: var(--yellow); border: none; padding: 6px 12px; border-radius: 8px; font-size: 10px; font-weight: 900; cursor: pointer; color: #000; }

.stats-grid { display: flex; gap: 10px; margin-bottom: 20px; }
.stat-item { flex: 1; background: var(--card); border: 1px solid var(--border); padding: 15px 5px; border-radius: 16px; text-align: center; }
.stat-num { display: block; font-size: 20px; font-weight: 900; color: var(--green); }
.stat-label { font-size: 9px; color: var(--text-sec); text-transform: uppercase; }

.limit-section { margin-bottom: 20px; cursor: pointer; }
.limit-info { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-sec); margin-bottom: 8px; font-weight: 700; }
.progress-container { height: 8px; background: #222; border-radius: 10px; overflow: hidden; width: 100%; }
.progress-bar { height: 100%; background: var(--green); width: 0%; transition: width 0.4s ease; }

.add-btn-main { display: flex; justify-content: center; align-items: center; background: var(--green); color: #000; padding: 16px; border-radius: 14px; font-weight: 900; cursor: pointer; }
.extend-btn-main { background: var(--yellow); color: #000; border: none; width: 100%; padding: 16px; border-radius: 14px; font-weight: 900; cursor: pointer; }

/* --- МОДАЛЬНЫЕ ОКНА (ОСНОВНОЙ ФИКС) --- */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: none; /* Переключается через JS */
    z-index: 2000;
    
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 40px 0;
    touch-action: pan-y;
}

.modal-card {
    background: var(--card);
    width: 90%;
    max-width: 400px;
    padding: 24px;
    border-radius: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    margin-top: auto;
    margin-bottom: auto;
    flex-shrink: 0;
}

.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.close-btn { background: #222; border: none; color: #fff; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; cursor: pointer; }

/* --- НАСТРОЙКИ --- */

.setting-row { display: flex; align-items: center; margin-bottom: 18px; width: 100%; }
.setting-row span { flex: 1; text-align: left; }

.text-input { 
    background: #222; 
    border: 1px solid #333; 
    color: #fff; 
    padding: 8px; 
    border-radius: 8px; 
    width: 210px; 
    text-align: center; 
}

.switch { position: relative; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #333; transition: .3s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background: var(--green); }
input:checked + .slider:before { transform: translateX(18px); }

.buy-btn { background: var(--yellow); border: none; width: 100%; padding: 14px; border-radius: 14px; font-weight: 900; color: #000; cursor: pointer; }

/* --- ПОЛКА --- */

.shelf-container.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 15px; }
.shelf-item img { width: 100%; border-radius: 12px; }
.blur { filter: blur(15px); pointer-events: none; }

.bottom-nav { position: fixed; bottom: 0; left: 0; width: 100%; height: 70px; background: #000; border-top: 1px solid var(--border); display: flex; justify-content: space-around; align-items: center; padding-bottom: 10px; }
.nav-link { text-decoration: none; color: #444; font-size: 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.nav-link.active { color: var(--green); }

/* --- ЗАГРУЗКА --- */

.photo-upload-grid {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}
.photo-slot {
    width: 80px;
    height: 80px;
    background: #222;
    border: 2px dashed #444;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
}
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }

.input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 12px;
    text-align: left;
}
.input-group label { font-size: 10px; color: #555; font-weight: 900; text-transform: uppercase; padding-left: 4px; }
.input-group input {
    background: #111;
    border: 1px solid #222;
    padding: 10px;
    border-radius: 10px;
    color: #fff;
    outline: none;
    font-size: 13px;
}
.input-group input:focus { border-color: var(--green); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.shelf-item {
    background: var(--card);
    border-radius: 16px;
    padding: 8px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.item-info-mini { font-size: 10px; color: #888; display: flex; justify-content: space-between; }
.item-title-mini { font-size: 12px; font-weight: 900; color: var(--green); margin: 2px 0; }

/* --- ДОПОЛНИТЕЛЬНАЯ СИНХРОНИЗАЦИЯ --- */

.stat-item, 
.status-banner-mini, 
.photo-slot, 
.shelf-item, 
.modal-card, 
.rank-card {
    background: #111 !important; 
    border: 1px solid #222 !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7), 
                0 4px 10px rgba(0, 0, 0, 0.5) !important;
    border-radius: 16px !important;
}

.status-banner-mini:active, 
.stat-item:active, 
.photo-slot:hover {
    background: linear-gradient(180deg, #161616 0%, #111 100%) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.8) !important;
    border-color: #333 !important;
}

.status-action-btn-gold {
    background: linear-gradient(180deg, #ffca28 0%, #e6b800 100%) !important;
}

@media screen and (max-width: 480px) {
    .modal-card {
        width: 92% !important;
        padding: 20px 16px !important;
        margin-top: 20px !important;
    }
}

/* В КОНЕЦ ФАЙЛА, НИЧЕГО НЕ УДАЛЯЯ */

.btn-add-shelf {
    background: linear-gradient(135deg, #39FF14 0%, #2ecc71 100%);
    color: #000;
    border: none;
    padding: 14px;
    border-radius: 12px;
    width: 100%;
    font-weight: 900;
    font-size: 16px;
    text-transform: uppercase;
    cursor: pointer;
}

.btn-upgrade-shelf {
    background: linear-gradient(135deg, #ffcc00 0%, #f1c40f 100%);
    color: #000;
    border: none;
    padding: 12px;
    border-radius: 12px;
    width: 100%;
    font-weight: 900;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.btn-upgrade-shelf span {
    font-size: 10px;
    text-transform: uppercase;
    opacity: 0.8;
}

.btn-add-shelf:active, .btn-upgrade-shelf:active {
    transform: scale(0.98);
}

/* ФИКС ЦВЕТА КНОПКИ ПРИОРИТЕТНЫЙ */

/* Если кнопка "Добавить" и на ней НЕТ функции оплаты — она всегда зеленая */
.status-action-btn:not([onclick*="openStarsModal"]), 
.add-btn-main:not([onclick*="openStarsModal"]) {
    background: var(--green) !important;
    color: #000 !important;
}

/* Если кнопка перешла в режим "Расширить" — она всегда желтая */
.status-action-btn[onclick*="openStarsModal"], 
.add-btn-main[onclick*="openStarsModal"] {
    background: linear-gradient(135deg, #FFD700, #FFA500) !important;
    color: #000 !important;
}

/* КЛАССЫ СОСТОЯНИЯ КНОПКИ — ДОБАВЬ В КОНЕЦ style-profile.css */

/* Состояние: Добавить на полку (Зеленая) */
.state-add {
    background: var(--green) !important;
    color: #000 !important;
    box-shadow: 0 4px 15px rgba(57, 255, 20, 0.3) !important;
}

/* Состояние: Лимит превышен (Золотая) */
.state-limit {
    background: linear-gradient(135deg, #FFD700, #FFA500) !important;
    color: #000 !important;
    font-weight: 900 !important;
    box-shadow: 0 4px 15px rgba(255, 204, 0, 0.4) !important;
}

/* --- ПРИНУДИТЕЛЬНАЯ ФИКСАЦИЯ ДЛЯ МОБИЛЬНЫХ И ТЕЛЕГРАМ --- */

#dynamic-action-container {
    width: 100%;
    margin-top: 20px;
    padding: 0 5px;
    box-sizing: border-box;
}

.btn-add-shelf, .btn-upgrade-shelf {
    width: 100% !important;
    display: block !important;
    padding: 16px !important;
    font-weight: 900 !important;
    font-size: 14px !important;
    text-transform: uppercase !important;
    border: none !important;
    border-radius: 14px !important;
    cursor: pointer !important;
    text-align: center !important;
}

/* ФИКС ФЛАГА НА АВАТАРЕ (лежит справа сверху на круге) */
#country-tag {
    position: absolute !important;
    bottom: 0px !important;
    right: 0 !important;
    width: 35px !important;
    height: 35px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 22px !important;
    background: transparent !important;
    z-index: 10 !important;
    pointer-events: none !important;
}

/* Фикс сетки, если полка пустая */
#user-shelf:empty {
    display: block !important;
    text-align: center;
    padding: 20px;
    color: #444;
}

/* Гарантированный сброс отступов для мобильных */
.app-container {
    padding-bottom: 150px !important;
}

/* Улучшение визуального отклика кнопок */
.btn-add-shelf:active, .btn-upgrade-shelf:active {
    transform: scale(0.97) !important;
    transition: transform 0.1s !important;
}