/* ==========================================================================
 * KARMA-HUB: MONOCHROME BRUTALISM (SYMMETRY UPDATE)
 * ========================================================================== */
:root {
    --bg-base: #000000;
    --bg-surface: #0a0a0a;
    --bg-elevated: #121212;

    --border-dim: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
    --border-strong: #ffffff;

    --text-main: #ffffff;
    --text-muted: #777777;
    --text-dim: #444444;

    /* Идеальные плавные кривые (Fluid Spring) */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; outline: none; }

html, body {
    height: 100dvh; width: 100vw; position: fixed; overflow: hidden; overscroll-behavior-y: none;
    background: var(--bg-base); color: var(--text-main);
    font-family: 'Inter', -apple-system, sans-serif;
    display: flex; flex-direction: column; -webkit-font-smoothing: antialiased;
}

/* --------------------------------------------------------------------------
 * 1. БАЗА И ФИКС ЧЕЛКИ (SAFE AREA)
 * -------------------------------------------------------------------------- */
.noise-layer { position: fixed; inset: 0; background: url('https://grainy-gradients.vercel.app/noise.svg'); opacity: 0.04; pointer-events: none; z-index: 0; }

.app-container { height: 100dvh; width: 100%; max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; overflow: hidden; position: relative; z-index: 1; }

.safe-area-top {
    width: 100%; flex-shrink: 0;
    height: var(--tg-content-safe-area-inset-top, env(safe-area-inset-top, 40px));
    background: var(--bg-surface);
}

/* --------------------------------------------------------------------------
 * 2. PRELOADER (ЭКРАН ЗАГРУЗКИ)
 * -------------------------------------------------------------------------- */
.preloader {
    position: fixed; inset: 0; background: var(--bg-base); z-index: 99999;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    transition: opacity 0.5s var(--ease-out-expo), visibility 0.5s;
}
.preloader:not(.active) { opacity: 0; visibility: hidden; pointer-events: none; }
.spinner { width: 44px; height: 44px; border: 2px solid var(--border-dim); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 24px; }
.preloader-text { font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: 3px; color: var(--text-muted); text-transform: uppercase; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
 * 3. ROUTING (ПЛАВНЫЕ ПЕРЕХОДЫ МЕЖДУ ЭКРАНАМИ)
 * -------------------------------------------------------------------------- */
#main-content { flex: 1; display: grid; grid-template-columns: 100%; position: relative; }

.screen {
    grid-area: 1/1; display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;
    padding-bottom: 120px; transition: 0.5s var(--ease-spring); will-change: transform, opacity;
}

#tasks-screen { transform: translateX(-100%); opacity: 0; }
#leaderboard-screen { transform: translateX(100%); opacity: 0; }
#shop-screen { transform: translateX(100%); opacity: 0; }

body.tab-tasks-active #tasks-screen { transform: translateX(0); opacity: 1; z-index: 2; pointer-events: auto; }
body.tab-tasks-active #leaderboard-screen, body.tab-tasks-active #shop-screen { pointer-events: none; transform: translateX(40%) scale(0.95); opacity: 0; }

body.tab-leaderboard-active #tasks-screen { pointer-events: none; transform: translateX(-40%) scale(0.95); opacity: 0; }
body.tab-leaderboard-active #leaderboard-screen { transform: translateX(0); opacity: 1; z-index: 2; pointer-events: auto; }
body.tab-leaderboard-active #shop-screen { pointer-events: none; transform: translateX(40%) scale(0.95); opacity: 0; }

body.tab-shop-active #tasks-screen, body.tab-shop-active #leaderboard-screen { pointer-events: none; transform: translateX(-40%) scale(0.95); opacity: 0; }
body.tab-shop-active #shop-screen { transform: translateX(0); opacity: 1; z-index: 2; pointer-events: auto; }

/* --------------------------------------------------------------------------
 * 4. HEADER & TYPOGRAPHY
 * -------------------------------------------------------------------------- */
.karma-header { padding: 25px 20px; display: flex; flex-direction: column; align-items: center; border-bottom: 1px solid var(--border-dim); background: var(--bg-surface); text-align: center; }
.pb-small { padding-bottom: 25px; } /* Уменьшил отступ для ТОПа и Магазина */

.user-badge { padding: 6px 16px; border: 1px solid var(--border-light); border-radius: 30px; margin-bottom: 25px; display: inline-flex; align-items: center; justify-content: center; }
.greeting-text { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-muted); }

/* Подзаголовок (для ТОПа) - сделан меньше и аккуратнее */
.sub-text { font-size: 10px; color: var(--text-dim); margin-top: 8px; font-family: 'JetBrains Mono', monospace; letter-spacing: 0.5px; }

.karma-display { display: flex; align-items: baseline; gap: 8px; margin-bottom: 30px; justify-content: center; width: 100%; }
.karma-number { font-size: clamp(60px, 18vw, 85px); font-weight: 900; letter-spacing: -3px; line-height: 1; color: #fff; text-shadow: 0 0 30px rgba(255,255,255,0.15); }
.karma-currency { font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 800; color: var(--text-muted); }

.section-title { font-size: 11px; font-weight: 800; color: var(--text-muted); letter-spacing: 2px; padding: 25px 20px 10px; text-transform: uppercase; }

/* --------------------------------------------------------------------------
 * 5. БРУТАЛЬНЫЕ КНОПКИ
 * -------------------------------------------------------------------------- */
.btn-primary {
    display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 16px;
    background: #fff; color: #000; font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px;
    border: none; border-radius: 12px; cursor: pointer; transition: transform 0.2s var(--ease-spring), background 0.2s;
}
.btn-primary:active { transform: scale(0.96); background: #d0d0d0; }
.btn-icon { width: 18px; height: 18px; fill: none; stroke: #000; flex-shrink: 0; }

/* --------------------------------------------------------------------------
 * 6. СПИСКИ (ЗАДАЧИ И ТОП)
 * -------------------------------------------------------------------------- */
.list-container { padding: 0 20px; display: flex; flex-direction: column; gap: 12px; }

.task-card, .leaderboard-card {
    display: flex; align-items: center; justify-content: space-between; padding: 18px 20px;
    background: var(--bg-elevated); border: 1px solid var(--border-light); border-radius: 14px; transition: 0.3s;
}
.task-card.achieved { border-color: #fff; background: rgba(255,255,255,0.03); }
.task-card.failed { opacity: 0.4; border-style: dashed; }

.task-info { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.task-title { font-size: 15px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Фиксированный размер для иконок, чтобы верстка не прыгала */
.task-status-icon { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; flex-shrink: 0; margin-left: 12px; }
.task-status-icon svg { width: 100%; height: 100%; stroke: var(--text-muted); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.task-card.achieved .task-status-icon svg { stroke: #fff; stroke-width: 2; }

/* Карточка "МОЕ МЕСТО" в топе */
.my-rank-card { margin: 20px; padding: 18px 24px; background: #fff; color: #000; border-radius: 14px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 10px 30px rgba(255,255,255,0.1); }
.rank-label { font-size: 11px; font-weight: 800; letter-spacing: 1px; }
.rank-value { font-family: 'JetBrains Mono', monospace; font-size: 24px; font-weight: 900; letter-spacing: -1px; }

/* --------------------------------------------------------------------------
 * 7. МАГАЗИН (ИДЕАЛЬНАЯ СИММЕТРИЯ)
 * -------------------------------------------------------------------------- */
.bento-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 20px; }
.bento-card {
    background: var(--bg-elevated); border: 1px solid var(--border-light); border-radius: 16px;
    padding: 20px 16px; display: flex; flex-direction: column; align-items: center; text-align: center;
    /* Добавлен flex-grow и justify-content для выравнивания */
    justify-content: space-between; min-height: 180px;
}
/* Обертка для верхней части карточки (иконка + текст), чтобы кнопка всегда была внизу */
.shop-card-content { display: flex; flex-direction: column; align-items: center; flex: 1; width: 100%; justify-content: flex-start; }

.shop-icon { margin-bottom: 12px; display: flex; align-items: center; justify-content: center; height: 32px; }
.shop-icon svg { width: 32px; height: 32px; stroke: #fff; stroke-width: 1.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.shop-title { font-size: 13px; font-weight: 700; color: #fff; margin-bottom: 6px; line-height: 1.3; }
.shop-price { font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 16px; }

.btn-buy {
    width: 100%; padding: 12px; background: transparent; border: 1px solid var(--border-strong);
    color: #fff; font-size: 11px; font-weight: 800; border-radius: 8px;
    transition: 0.2s var(--ease-spring); letter-spacing: 1px; text-transform: uppercase;
    /* Убеждаемся, что кнопка не сжимается */
    flex-shrink: 0; margin-top: auto; cursor: pointer;
}
.btn-buy:active { background: #fff; color: #000; transform: scale(0.95); }

/* --------------------------------------------------------------------------
 * 8. НИЖНЯЯ НАВИГАЦИЯ
 * -------------------------------------------------------------------------- */
.bottom-nav {
    position: fixed; bottom: 0; width: 100%; display: flex;
    background: rgba(0,0,0,0.85); backdrop-filter: blur(25px); -webkit-backdrop-filter: blur(25px);
    border-top: 1px solid var(--border-light); padding-bottom: env(safe-area-inset-bottom); z-index: 1000;
}
.nav-tab { flex: 1; padding: 14px 0; display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; border: none; color: var(--text-muted); cursor: pointer; transition: 0.3s; }
.nav-tab.active { color: #fff; }
.nav-icon { display: flex; align-items: center; justify-content: center; height: 24px; }
.nav-icon svg { width: 24px; height: 24px; transition: 0.4s var(--ease-spring); }
.nav-tab.active .nav-icon svg { transform: translateY(-4px); filter: drop-shadow(0 4px 8px rgba(255,255,255,0.3)); }
.nav-tab span { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; line-height: 1; }

/* --------------------------------------------------------------------------
 * 9. МОДАЛЬНОЕ ОКНО (АБСОЛЮТНЫЙ ЦЕНТР И ОКАНТОВКА КНОПОК)
 * -------------------------------------------------------------------------- */
.center-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 50000; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: 0.4s var(--ease-out-expo); padding: 20px; }
.center-modal.active { opacity: 1; pointer-events: auto; }

.modal-dialog { width: 100%; max-width: 340px; background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: 24px; padding: 25px 20px; transform: scale(0.95) translateY(20px); transition: 0.4s var(--ease-spring); display: flex; flex-direction: column; align-items: center; margin: auto; }
.center-modal.active .modal-dialog { transform: scale(1) translateY(0); }

.modal-drag-handle { width: 40px; height: 4px; background: var(--border-light); border-radius: 2px; margin-bottom: 25px; }
.modal-title { font-size: 16px; font-weight: 800; letter-spacing: 1.5px; margin-bottom: 24px; color: #fff; text-align: center; }

.input-wrapper { width: 100%; margin-bottom: 24px; }
.input-base { width: 100%; padding: 16px; background: var(--bg-elevated); border: 1px solid var(--border-light); border-radius: 12px; color: #fff; font-size: 15px; font-weight: 500; text-align: center; transition: 0.3s; outline: none; box-sizing: border-box; }
.input-base:focus { border-color: var(--border-strong); background: #000; box-shadow: 0 0 20px rgba(255,255,255,0.05); }

.modal-actions { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.btn-submit { width: 100%; padding: 16px; background: #fff; color: #000; font-weight: 800; font-size: 13px; border-radius: 12px; border: none; text-transform: uppercase; letter-spacing: 1px; cursor: pointer; transition: 0.2s; display: flex; justify-content: center; align-items: center;}
.btn-submit:active { transform: scale(0.96); background: #ccc; }

/* Кнопка "ОТМЕНА" теперь с четкой рамкой */
.btn-cancel {
    width: 100%; padding: 14px; background: transparent;
    border: 1px solid var(--border-light); /* Окантовка */
    border-radius: 12px; /* Такое же скругление */
    color: var(--text-muted); font-weight: 700; font-size: 12px;
    text-transform: uppercase; letter-spacing: 1px; cursor: pointer;
    transition: 0.2s; display: flex; justify-content: center; align-items: center;
}
.btn-cancel:active { background: rgba(255,255,255,0.05); color: #fff; border-color: rgba(255,255,255,0.3); }