:root {
    --bg-base: #0E0F12;
    --bg-surface: #17181D;
    --bg-surface-2: #1F2129;
    --border-subtle: #2A2C34;
    --text-primary: #F5F6F8;
    --text-secondary: #9AA0AC;
    --text-tertiary: #5C6270;
    --accent: #6C8CFF;
    --accent-muted: rgba(108, 140, 255, 0.14);
    --success: #3DDC84;
    --danger: #FF5C5C;
    --locked: #C7A94A;

    --r-sm: 8px;
    --r-md: 14px;
    --r-lg: 20px;
    --r-pill: 999px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    overscroll-behavior-y: contain;
}

#app-container {
    width: 100%;
    max-width: 420px;
    min-height: 100vh;
    background-color: var(--bg-base);
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Безопасные зоны для TMA */
.screen {
    display: none;
    flex-direction: column;
    width: 100%;
    min-height: 100vh;
    padding: calc(env(safe-area-inset-top, 20px) + 16px) 16px calc(env(safe-area-inset-bottom, 20px) + 24px) 16px;
}

.screen.active {
    display: flex;
}

/* Типографика и компоненты кнопок */
.section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 16px 0 8px 2px;
}

.btn {
    height: 48px;
    border-radius: var(--r-md);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    transition: transform 0.1s ease, opacity 0.15s ease, background-color 0.15s ease;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 14px var(--accent-muted);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-surface-2);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.app-input {
    width: 100%;
    height: 48px;
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-sm);
    color: var(--text-primary);
    padding: 0 14px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.app-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-muted);
}

/* Бейджи */
.badge {
    padding: 3px 10px;
    border-radius: var(--r-pill);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--bg-surface-2);
    color: var(--text-secondary);
}

.badge.vip {
    background: var(--accent-muted);
    color: var(--accent);
}

.badge.ultimate {
    background: rgba(199, 169, 74, 0.15);
    color: var(--locked);
}

.badge.creator {
    background: rgba(255, 92, 92, 0.15);
    color: var(--danger);
}

/* ЭКРАН 0: АВТОРИЗАЦИЯ */
.auth-content {
    margin: auto 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.lock-icon-wrapper {
    width: 72px;
    height: 72px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.lock-icon { font-size: 32px; }

.auth-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 28px; }

.input-group {
    position: relative;
    width: 100%;
    margin-bottom: 12px;
}

.toggle-password-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-secondary);
}

.error-banner {
    background: rgba(255, 92, 92, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--r-sm);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 12px;
}

#btn-login { width: 100%; margin-top: 6px; }
.auth-support-link {
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-tertiary);
    text-decoration: underline;
}

/* ЭКРАН 1: ГЛАВНЫЙ КАТАЛОГ */
.profile-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    padding: 14px 16px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.15s;
}

.profile-card:hover { background: var(--bg-surface-2); }

.profile-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-right: 20px;
}

.profile-user-group { display: flex; align-items: center; gap: 8px; }
.profile-username { font-weight: 600; font-size: 15px; }

.card-arrow {
    position: absolute;
    right: 16px;
    top: 14px;
    color: var(--text-tertiary);
    font-size: 18px;
}

.limit-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 6px;
}

.limit-caption { color: var(--text-secondary); }
.timer-caption { color: var(--text-tertiary); font-variant-numeric: tabular-nums; }

.progress-track {
    width: 100%;
    height: 6px;
    background: var(--bg-surface-2);
    border-radius: var(--r-pill);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: var(--r-pill);
    transition: width 0.3s ease;
}

.search-wrapper {
    position: relative;
    margin: 14px 0 10px 0;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-input { padding-left: 40px; padding-right: 36px; }

.clear-input-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
}

#btn-global-random { width: 100%; margin-bottom: 14px; }

/* Сегментный контрол фильтра */
.segmented-control {
    display: flex;
    background: var(--bg-surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-pill);
    padding: 3px;
    gap: 2px;
}

.seg-btn {
    flex: 1;
    height: 36px;
    border-radius: var(--r-pill);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: background 0.15s, color 0.15s;
}

.seg-btn.active {
    background: var(--accent-muted);
    color: var(--accent);
    font-weight: 600;
}

.lock-chip { font-size: 11px; }

.dynamic-inputs {
    margin-top: 10px;
    animation: fadeIn 0.2s ease-out;
}

.dynamic-inputs.dual {
    display: flex;
    gap: 8px;
}

/* Алфавитные табы */
.alphabet-tabs {
    display: flex;
    gap: 8px;
    margin: 18px 0 12px 0;
    overflow-x: auto;
}

.pill-tab {
    flex: 1;
    height: 34px;
    border-radius: var(--r-pill);
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.15s;
}

.pill-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Сетка подарков */
.gift-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.gift-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    gap: 8px;
    min-height: 84px;
    transition: transform 0.1s, border-color 0.15s;
}

.gift-card:active { transform: scale(0.97); }
.gift-card:hover { border-color: rgba(255, 255, 255, 0.2); }
.gift-emoji { font-size: 26px; }
.gift-name { font-size: 13px; font-weight: 500; color: var(--text-primary); }

/* ЭКРАН 2: РЕЗУЛЬТАТЫ ВЫДАЧИ */
.nav-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.nav-back-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--r-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-back-btn:active { transform: scale(0.95); }
.nav-title { font-size: 17px; font-weight: 600; line-height: 1.2; }
.nav-subtitle { font-size: 12px; color: var(--text-secondary); }

.results-stats {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.holders-list { display: flex; flex-direction: column; gap: 8px; }

.holder-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.holder-info { display: flex; flex-direction: column; gap: 4px; }
.holder-user-row { display: flex; align-items: center; gap: 8px; }
.holder-username { font-size: 14px; font-weight: 600; }

.copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    position: relative;
    border-radius: var(--r-sm);
    color: var(--text-secondary);
}

.copy-btn:active { color: var(--accent); }

.copy-tooltip {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    animation: fadeIn 0.15s ease;
}

.holder-count { font-size: 12px; color: var(--text-secondary); }

.chat-btn {
    height: 32px;
    padding: 0 14px;
    background: var(--accent-muted);
    color: var(--accent);
    border-radius: var(--r-pill);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
}

.chat-btn:active { transform: scale(0.95); }

.pagination-btn { width: 100%; margin-top: 16px; }

/* Пустое состояние */
.empty-state {
    text-align: center;
    padding: 40px 16px;
}

.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-title { font-size: 16px; margin-bottom: 6px; }
.empty-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 18px; }

/* ЭКРАН 3: ПРОФИЛЬ */
.info-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    padding: 16px;
    margin-bottom: 14px;
}

.account-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.account-avatar { font-size: 32px; }
.account-username { font-size: 16px; font-weight: 700; display: block; }
.account-id { font-size: 12px; color: var(--text-secondary); }
.role-row { display: flex; justify-content: space-between; align-items: center; }
.role-label { font-size: 13px; color: var(--text-secondary); }

.tiers-list { padding: 4px 16px; }
.tier-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.tier-row:last-child { border-bottom: none; }
.tier-name { font-size: 14px; font-weight: 600; display: block; }
.tier-desc { font-size: 12px; color: var(--text-secondary); }
.tier-check { color: var(--success); font-weight: 700; display: none; }
.tier-row.active .tier-check { display: block; }

#btn-support-link { width: 100%; margin-top: 10px; }

/* BOTTOM SHEET: МОДАЛЬНОЕ ОКНО */
.bottom-sheet-scrim {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    animation: fadeIn 0.2s ease;
}

.bottom-sheet {
    background: var(--bg-surface);
    width: 100%;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 16px 20px calc(env(safe-area-inset-bottom, 16px) + 16px) 20px;
    border-top: 1px solid var(--border-subtle);
    animation: slideUp 0.25s ease-out;
}

.drag-handle {
    width: 36px;
    height: 4px;
    background: var(--border-subtle);
    border-radius: var(--r-pill);
    margin: 0 auto 16px auto;
}

.sheet-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; text-align: center; }
.feature-list { list-style: none; margin-bottom: 20px; }
.feature-list li {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.feat-icon { font-size: 16px; }
#btn-upgrade-cta { width: 100%; margin-bottom: 8px; }
#btn-close-upgrade { width: 100%; }

/* Анимации */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Скелетон */
.skeleton-container { display: flex; flex-direction: column; gap: 8px; }
.skeleton-card {
    height: 64px;
    background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-surface-2) 50%, var(--bg-surface) 75%);
    background-size: 200% 100%;
    border-radius: var(--r-md);
    animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Плавное переключение экранов со сдвигом */
.screen {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.screen.active {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Неоновое свечение и переливание полосы лимита */
.progress-track {
    background: rgba(255, 255, 255, 0.06);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}

.progress-bar {
    background: linear-gradient(90deg, #3b82f6, #60a5fa, #93c5fd);
    background-size: 200% 100%;
    box-shadow: 0 0 12px rgba(96, 165, 250, 0.5);
    animation: gradientShift 3s ease infinite;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Пружинящий отклик (Spring feedback) для всех кнопок и карточек */
.btn, .gift-card, .holder-card, .pill-tab, .seg-btn, .profile-card {
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.15s ease, box-shadow 0.15s ease !important;
}

.btn:active, .gift-card:active, .profile-card:active {
    transform: scale(0.95) !important;
}

/* Каскадное появление карточек подарков при открытии каталога */
.gift-card {
    animation: cardEntrance 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cardEntrance {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Стеклянное размытие (Glassmorphism) для Bottom Sheet и модалок */
.bottom-sheet-scrim {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 0.25s ease;
}

.bottom-sheet {
    animation: sheetSpring 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.1) forwards;
}

@keyframes sheetSpring {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* Анимация всплывающего тултипа «Скопировано!» */
.copy-tooltip {
    animation: popTooltip 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.2) forwards;
}

@keyframes popTooltip {
    0% { opacity: 0; transform: translate(-50%, 6px) scale(0.7); }
    100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
}