/* --- 1. ГЛОБАЛЬНЫЕ СТИЛИ --- */
* {
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
    outline: none;
}

body {
    margin: 0;
    padding: 0;
    background-color: #7195ba;
    background-image: url('../img/bg.png');
    background-blend-mode: soft-light;
    background-attachment: fixed;
    background-repeat: repeat;
    background-size: 400px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: scroll;
}

body.modal-open {
    overflow: hidden;
    top: 0;
}

/* --- 2. ШАПКА И НАВИГАЦИЯ --- */
#main-header {
    position: sticky;
    top: 0;
    width: 100%;
    background: rgba(84, 126, 168, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 100;
    box-shadow: 0 1px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
}

.header-content {
    max-width: 520px;
    width: 100%;
    height: 60px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-logo-text {
    font-size: 17px;
    font-weight: 500;
    color: #ffffff;
    letter-spacing: -0.4px;
    white-space: nowrap;
    cursor: default;
    user-select: none;
}

.header-logo-text span {
    font-weight: 800;
    color: #ffda44;
    margin-left: 3px;
    text-shadow: 0 0 10px rgba(255, 218, 68, 0.3);
}

.nav-toggle {
    display: flex;
    background: rgba(0, 0, 0, 0.15);
    padding: 3px;
    border-radius: 20px;
    height: 36px;
    align-items: center;
}

.nav-toggle button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.9);
    padding: 0 16px;
    border-radius: 17px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    height: 30px;
    display: flex;
    align-items: center;
}

.nav-toggle button.active {
    background: white;
    color: #547ea8;
}

.tg-link {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    width: 30px;
    background: #fff;
    border-radius: 50%;
    flex-shrink: 0;
}

.tg-link img {
    width: 70%;
    height: 70%;
    object-fit: contain;
}

/* --- 3. КОНТЕНТ И ПОСТЫ --- */
#feed,
#comics-grid {
    max-width: 520px;
    width: 100%;
    padding: 0 10px;
}
/* Контейнер комикса должен быть relative, чтобы бейдж прилип к углу */
#comics-grid .comic-item {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
}

.comic-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6); /* Темный фон */
    backdrop-filter: blur(8px); /* Твой любимый блюр */
    -webkit-backdrop-filter: blur(8px);
    color: white;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 5px;
    z-index: 2;
    border: 1px solid rgba(255, 255, 255, 0.1);
    pointer-events: none; /* Чтобы бейдж не мешал клику по посту */
}
#feed {
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    will-change: opacity, transform;
    display: flex;
    flex-direction: column;
    align-items: start;
}
#comics-grid {
    display: flex;
    flex-direction: column;
    text-align: center;
}

#comics-grid .comic-card {
    /*width: 250px; /* Узкие карточки для сетки */
}

#comics-grid .comic-card:nth-of-type(1) {
    margin-top: 0;
}
#tags-filter-container {
    display: none; /* Прячем изначально */
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: 15px 10px;
    justify-content: center;
}

/* Этот класс мы будем добавлять через JS */
#tags-filter-container.active {
    display: flex; 
}

#tags-wrapper {
    display: flex;
    flex-wrap: wrap;    /* Разрешает перенос на новую строку */
    justify-content: center; /* Центрирует теги внутри обертки */
    gap: 8px;           /* Расстояние между кнопками по горизонтали и вертикали */
    padding: 0 5px;
}

.tag-item {
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    /* Убираем white-space: nowrap если хотим, чтобы длинные теги тоже могли ломаться, 
       но лучше оставить, чтобы кнопка была цельной */
    white-space: nowrap; 
    
    background: rgba(84, 126, 168, 0.2); 
    color: rgba(255, 255, 255, 0.9);
    
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.tag-item.active {
    background: #ffffff;
    color: #547ea8;
    opacity: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-color: #ffffff;
}
.feed-loading {
    opacity: 0;
    transform: translateY(10px);
}

.hidden-section {
    display: none !important;
}

.post-node {
    background: #ffffff;
    border-radius: 15px;
    margin-top: 30px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    position: relative;
    padding: 2px;
    /* ИЗМЕНЕНО: padding 2px для всех */
    cursor: pointer;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.post-node.is-vertical {
    max-width: 250px;
}

.post-node.show {
    opacity: 1;
    transform: translateY(0);
}

.post-node .text {
    font-size: 15px;
    line-height: 1.5;
    color: #000;
    margin: 8px 5px 12px 5px;
    /* Немного подправлен отступ для padding 3px */
    word-wrap: break-word;
}

.post-node img {
    display: block;
    width: 100%;
    height: auto;
    min-height: 100px;
    background: #f0f0f0;
    border-radius: 13px;
    /* Чуть больше радиус, чтобы внутри 15px смотрелось ок */
}

/* ИЗМЕНЕНО: если капш не пустой, нижние радиусы в 2 раза меньше */
.post-node.has-caption img {
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
}


.post-share {
    position: absolute;
    top: 0;
    right: -35px;
    width: 30px;
    height: 30px;
    opacity: 0.7;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

.post-share svg {
    fill: #7195ba;
    width: 20px;
    height: 20px;
}

/* --- 4. РАЗДЕЛИТЕЛИ И ИНДИКАТОРЫ --- */
.unread-separator {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 35px 0 15px 0;
    position: relative;
    pointer-events: none;
}

.unread-separator::before {
    content: "";
    position: absolute;
    left: 4%;
    right: 4%;
    height: 1px;
    background: #333;
    z-index: 1;
}

.unread-separator span {
    background: #333;
    color: #ffffff;
    padding: 5px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* --- 5. КНОПКА СКРОЛЛА --- */
#tg-scroll-btn {
    position: fixed;
    bottom: 25px;
    right: 20px;
    width: 52px;
    height: 52px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    cursor: pointer;
    transition: opacity 0.3s, visibility 0.3s, transform 0.2s;
}

#tg-scroll-btn.hidden-btn {
    opacity: 0;
    visibility: hidden;
}

#tg-scroll-btn svg {
    fill: #547ea8;
    width: 28px;
    height: 28px;
}

#new-posts-badge {
    position: absolute;
    top: -2px;
    left: -2px;
    background: #ff4b4b;
    color: white;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: bold;
    display: none;
    border: 2px solid white;
}

/* --- 6. VIEWER (ОБНОВЛЕННЫЙ) --- */
#viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.98);
    backdrop-filter: blur(10px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    touch-action: none;
    overflow: hidden; /* Важно: отсекаем всё лишнее */
}

#viewer.active {
    display: flex;
}

#viewer-body {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

#viewer-body img {
    will-change: transform;
    max-width: 100%;
    max-height: 100vh;
    object-fit: contain;
    transition: none; /* Никаких анимаций при таче! */
    transform-origin: center center;
    /* Убираем любые дефолтные смещения */
    position: relative;
    display: block;
}

/* Убираем все старые стили .viewer-bubble img, которые могли мешать */
.viewer-bubble, .viewer-bubble img {
    display: contents; /* Это заставит браузер игнорировать этот контейнер в верстке */
}
.viewer-counter {
    position: fixed;
    display:none;
    bottom: 25px; /* Отступ снизу */
    top: auto;    /* Сбрасываем верхнее позиционирование */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #000;
    padding: 6px 16px; /* Чуть увеличил для удобства */
    border-radius: 20px; /* Более округлый вид в стиле кнопок Telegram */
    font-size: 14px;
    font-weight: 500;
    z-index: 1100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none; 
    transition: opacity 0.2s ease;
}

/* Показываем только когда активен вьюер и это комикс */
.viewer-counter.visible {
    display: block;
}
/* УБИРАЕМ ЛИШНЕЕ В МОДАЛКЕ */
.viewer-bubble .text,
.viewer-close,
.viewer-bubble .post-share {
    display: none !important;
}

.viewer-nav {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    /* Скрыто по дефолту (мобилки) */
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    pointer-events: none;
    z-index: 1010;
}

/* Показываем стрелки только на ПК */
@media (hover: hover) and (pointer: fine) {
    .viewer-nav {
        display: flex;
    }

    .viewer-nav button {
        pointer-events: auto;
        background: rgba(255, 255, 255, 0.15);
        border: none;
        color: white;
        font-size: 30px;
        width: 60px;
        height: 80px;
        border-radius: 12px;
        cursor: pointer;
        backdrop-filter: blur(5px);
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* --- 7. АНИМАЦИИ И ХОВЕРЫ (НЕ ТРОГАЕМ) --- */
.tg-link,
.post-share,
#tg-scroll-btn,
.viewer-nav button,
.viewer-close {
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    will-change: transform;
}

@media (hover: hover) {

    .tg-link:hover,
    .post-share:hover,
    #tg-scroll-btn:hover,
    .viewer-nav button:hover {
        transform: scale(1.1);
        opacity: 1;
    }
}

.tg-link:active,
.post-share:active,
#tg-scroll-btn:active,
.viewer-nav button:active {
    transform: scale(0.95);
}

.btn-loading {
    animation: scrollPulse 0.8s infinite;
    pointer-events: none;
}
/* Если пост находится внутри экрана авторизации — он виден всегда */
#auth-screen .post-node {
    opacity: 1 !important;
    transform: none !important;
    display: block !important;
    width: 100%!important;
    margin-top: 0px; /* Немного опустим от верха */
}

/* Общий контейнер */
#auth-screen {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Убираем фон у формы ввода, оставляем только в инпуте */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 15px 20px;
}

#key-input {
    /* Делаем фон чуть темнее или контрастнее относительно белого фона поста */
    background: rgba(0, 0, 0, 0.03); 
    /* Четкая, но мягкая рамка */
    border: 1px solid rgba(84, 126, 168, 0.3); 
    border-radius: 12px;
    padding: 13px;
    /* Цвет текста — темный или твой акцентный, чтобы было видно на белом */
    color: #333; 
    text-align: center;
    font-size: 16px;
    outline: none;
    transition: all 0.3s ease;
    width: 100%;
    box-sizing: border-box;
}

/* Эффект при клике (фокусе) */
#key-input:focus {
    background: #fff;
    border-color: #547ea8;
    box-shadow: 0 0 10px rgba(84, 126, 168, 0.1);
}

/* Стиль плейсхолдера (текста внутри, когда пусто) */
#key-input::placeholder {
    color: #999;
    opacity: 0.8;
}
#btn-auth {
    background: #547ea8;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 15px;
    font-weight: bold;
    cursor: pointer;
}

/* Внешние кнопки (под постом) */
.auth-external-buttons {
    width: 100%;
    max-width:400px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 5px; /* Небольшой отступ от краев экрана */
}

.btn-ext-wide, .btn-ext-row a {
    background: rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    text-decoration: none;
    padding: 14px;
    border-radius: 12px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    transition: 0.2s;
}

.btn-ext-row {
    display: flex;
    gap: 10px;
}

.btn-ext-row a {
    flex: 1;
}

/* Эффект нажатия */
.btn-ext-wide:active, .btn-ext-row a:active {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0.98);
}

#main-content {
    width: 100%;
    max-width: 520px;
}
@keyframes scrollPulse {
    50% {
        opacity: 0.5;
        transform: scale(0.9);
    }
}

/* --- 8. АДАПТИВНОСТЬ --- */
@media (max-width: 600px) {
    .post-node {
        margin-top: 20px;
        width: calc(100% - 40px);
    }
}