/* ==========================================
КАТАЛОГ МАНГИ: герой, топбар, блоки continue/favorites в один ряд,
панель фильтров (классы fanfics), карточки с mgFade,
одинаковые обложки 2/3
========================================== */

/* ---------- Герой ---------- */
.mg-hero {
    position: relative;
    padding: 54px 40px 42px;
    height: 320px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    background:
        /* Бесшовный переход в фон страницы: конечный цвет = body (#0d0e12).
           Прежде было #111111 — отсюда светлая полоса под баннером. */
        linear-gradient(180deg, rgba(13, 14, 18, .10) 0%, rgba(13, 14, 18, .72) 62%, rgba(13, 14, 18, .96) 86%, #0d0e12 100%),
        url('/static/images/manga-hero.avif') center/cover no-repeat;
    overflow: hidden;
}
.mg-hero-inner {
    max-width: 1600px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 18px;
    position: relative;
    text-align: left;
    margin-left: 60px;
}
.mg-hero-icon {
    width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255, 77, 109, .14); border: 1px solid rgba(255, 77, 109, .5);
    color: #ff8fa3;
}
.mg-hero-icon svg { width: 18px; height: 18px; }
.mg-hero-text h1 { margin: 0; font-size: 26px; font-weight: 800; color: #fff; line-height: 1.1; }
.mg-hero-text p { margin: 4px 0 0; font-size: 13px; color: #b98a94; }

/* ---------- Контейнер страницы ---------- */
.mg-page { max-width: none; margin: 0; padding: 26px 90px 80px; }

/* ---------- Обёртка topbar + фильтры ---------- */
.mg-topbar-wrap { position: relative; z-index: 60; margin-bottom: 22px; }
.mg-topbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mg-search {
    gap: 10px;
    flex: 1.6; min-width: 380px; position: relative;
    display: flex; align-items: center;
    background: #1d1e24; border: 1px solid #2c2e36; border-radius: 14px;
    padding: 0 18px; height: 50px;
    transition: border-color .25s ease, box-shadow .25s ease, background .25s ease;
}
.mg-search:focus-within {
    border-color: rgba(255, 77, 109, .65);
    box-shadow: 0 0 0 4px rgba(255, 77, 109, .12);
    background: #20212a;
}
.mg-search svg { width: 18px; height: 18px; color: #7a7d87; flex-shrink: 0; transition: color .25s; }
.mg-search:focus-within svg { color: #ff4d6d; }
.mg-search input {
    flex: 1; background: transparent; border: none; outline: none;
    color: #fff; height: 100%; padding: 0; font-size: 15px; font-family: 'MyCustomFont';
}
.mg-search input::placeholder { color: #5d6068; }
.mg-search .search-clear { background: none; border: none; color: #7a7d87; cursor: pointer; font-size: 15px; padding: 4px 8px; transition: color .15s, transform .15s; }
.mg-search .search-clear:hover { color: #ff4d6d; transform: scale(1.15); }

.mg-topbar-btns { display: flex; gap: 10px; flex-shrink: 0; }

/* Переключатель вида */
.mg-view { display: flex; border: 1px solid #2c2e36; border-radius: 14px; overflow: hidden; height: 52px; }
.mg-view button {
    width: 52px; background: #1d1e24; border: none; color: #6f727c; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.mg-view button svg { width: 17px; height: 17px; }
.mg-view button.active { background: rgba(255, 77, 109, .15); color: #ff8fa3; }

/* ---------- Панель фильтров (классы fanfics) ---------- */
.manga-page .fp-columns { grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.manga-page .filters-panel { max-height: 74vh; overflow-y: auto; }
.manga-page .filters-panel::-webkit-scrollbar { width: 6px; }
.manga-page .filters-panel::-webkit-scrollbar-thumb { background: #3a3d46; border-radius: 3px; }

/* ========== Продолжить чтение + Избранное (в один ряд, как в аниме) ========== */
.mg-continue-fav-row {
    display: flex;
    gap: 40px;
    margin: 24px 0 8px;
    animation: mgFade .4s ease both;
}
.mg-continue-wrap, .mg-favorites-wrap {
    flex: 1;
    min-width: 0;
}
.mg-cf-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding: 0 4px;
}
.mg-cf-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 16px;
    font-weight: 800;
    color: #fff;
}
.mg-cf-title svg {
    width: 17px;
    height: 17px;
    color: #ff8fa3;
    flex-shrink: 0;
}
.mg-clear-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid #2c2e36;
    color: #8b8e98;
    font-family: 'MyCustomFont';
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: all .15s;
    flex-shrink: 0;
}
.mg-clear-btn svg { width: 13px; height: 13px; }
.mg-clear-btn:hover { color: #f87171; border-color: rgba(248,113,113,.5); }

/* Полосы со скрытым скроллбаром */
.mg-continue-scroll, .mg-favorites-scroll {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding: 4px 2px 10px;
    scrollbar-width: none;
}
.mg-continue-scroll::-webkit-scrollbar, .mg-favorites-scroll::-webkit-scrollbar {
    display: none;
}

/* Карточки — фиксированное соотношение 2/3, текст поверх с градиентом */
.mg-mini-card {
    position: relative;
    flex: 0 0 150px;
    width: 150px;
    aspect-ratio: 2/3;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid #2c2e36;
    background: #1d1e24;
    display: block;
    text-decoration: none;
    transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.mg-mini-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255,77,109,.55);
    box-shadow: 0 12px 28px rgba(0,0,0,.5), 0 0 18px rgba(255,77,109,.18);
}
.mg-mini-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Затемнение снизу (как в аниме) */
.mg-chevron {
    display: none;
    width: 16px;
    height: 16px;
    margin-left: 6px;
    transition: transform .2s ease;
    color: #8b8e98;
}

@keyframes mgSlideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.mg-mini-body,
.mg-mini-info {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 3 !important;
    padding: 28px 10px 9px !important;
    background: linear-gradient(0deg, rgba(8,9,12,.95) 0%, rgba(8,9,12,.65) 55%, transparent 100%) !important;
    pointer-events: none !important;
}
.mg-mini-body b,
.mg-mini-info b {
    display: block !important;
    color: #fff !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}
.mg-mini-body span,
.mg-mini-info span {
    display: block !important;
    color: #c9ccd4 !important;
    font-size: 10.5px !important;
    margin-top: 2px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Сердечко в углу для избранного */
.mg-mini-heart {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(13, 14, 17, 0.90);
    color: #ff4d6d;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}
.mg-mini-heart svg {
    width: 14px;
    height: 14px;
    display: block;
    fill: currentColor;
}

/* Фейды краёв полос (как в аниме) */
.mg-continue-scroll, .mg-favorites-scroll {
    -webkit-mask-image: none;
    mask-image: none;
}
.mg-continue-scroll.fade-right:not(.fade-left),
.mg-favorites-scroll.fade-right:not(.fade-left) {
    -webkit-mask-image: linear-gradient(90deg, #000 0%, #000 calc(100% - 70px), transparent 100%);
    mask-image: linear-gradient(90deg, #000 0%, #000 calc(100% - 70px), transparent 100%);
}
.mg-continue-scroll.fade-left:not(.fade-right),
.mg-favorites-scroll.fade-left:not(.fade-right) {
    -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 70px, #000 100%);
    mask-image: linear-gradient(90deg, transparent 0%, #000 70px, #000 100%);
}
.mg-continue-scroll.fade-left.fade-right,
.mg-favorites-scroll.fade-left.fade-right {
    -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 70px, #000 calc(100% - 70px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0%, #000 70px, #000 calc(100% - 70px), transparent 100%);
}

/* Адаптив */
@media (max-width: 900px) {
    .mg-continue-fav-row { flex-direction: column; gap: 18px; }
    .mg-mini-card { flex: 0 0 140px; width: 140px; }
    .mg-cf-title { font-size: 16px; }
}

/* ---------- Популярные жанры ---------- */
.mg-hot { display: flex; align-items: center; gap: 12px; margin: 18px 0 22px; flex-wrap: wrap; }
.mg-hot-label { font-size: 13px; font-weight: 700; color: #8b8e98; }
.mg-hot-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.mg-hot-pills button {
    background: #1d1e24; border: 1px solid #2c2e36; border-radius: 999px;
    color: #c9ccd4; font-family: 'MyCustomFont'; font-size: 12px; font-weight: 700;
    padding: 7px 14px; cursor: pointer; transition: all .15s;
}
.mg-hot-pills button:hover { border-color: rgba(255, 77, 109, .5); color: #fff; }
.mg-hot-pills button.active {
    background: linear-gradient(135deg, #ff4d6d, #d63a6a); border-color: transparent; color: #fff;
    box-shadow: 0 4px 14px rgba(255, 77, 109, .35);
}

/* ---------- Плавное появление карточек ---------- */
@keyframes mgFade {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.mg-card { animation: mgFade .35s ease backwards; animation-delay: var(--d, 0s); }

/* ---------- Сетка карточек + одинаковые обложки ---------- */
.mg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 22px; }
.mg-card {
    display: flex; flex-direction: column;
    background: #1d1e24; border: 1px solid #2c2e36; border-radius: 16px;
    overflow: hidden;
    transition: transform .3s ease, box-shadow .3s ease, border-color .3s ease;
}
.mg-card:hover {
    transform: translateY(-6px);
    border-color: rgba(255, 77, 109, .5);
    box-shadow: 0 16px 40px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 77, 109, .25);
}
.mg-media { position: relative; aspect-ratio: 2 / 3; background: #17181c; overflow: hidden; flex-shrink: 0; }
.mg-media img {
    width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block;
    filter: brightness(.92) saturate(.97); transition: transform .45s ease, filter .45s ease;
}
.mg-card:hover .mg-media img { transform: scale(1.05); filter: brightness(1) saturate(1); }
.mg-score {
    position: absolute; top: 10px; left: 10px; z-index: 2;
    display: inline-flex; align-items: center; gap: 5px;
    background: rgba(13, 14, 17, 0.90);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 8px; padding: 4px 9px;
    font-size: 11px; font-weight: 800;
}
.mg-score svg { width: 12px; height: 12px; }
.mg-score.high { color: #4ade80; }
.mg-score.mid { color: #facc15; }
.mg-score.low { color: #f87171; }
.mg-score.none { color: #8b8e98; }
.mg-likes {
    position: absolute; top: 10px; right: 10px; z-index: 2;
    display: inline-flex; align-items: center; gap: 5px;
    background: rgba(13, 14, 17, 0.90);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 8px; padding: 4px 9px;
    font-size: 11px; font-weight: 800; color: #ff8fa3;
}
.mg-likes svg {
    width: 12px;
    height: 12px;
    color: #ff4d6d;
    fill: currentColor;
    display: block;
    flex-shrink: 0;
}
.mg-type {
    position: absolute; left: 10px; bottom: 10px; z-index: 2;
    font-size: 10px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
    color: #ffd3db; background: rgba(13, 14, 17, 0.90);
    border: 1px solid rgba(255, 77, 109, .5);
    padding: 3px 9px; border-radius: 999px;
}
.mg-body { display: flex; flex-direction: column; gap: 8px; padding: 14px 14px 12px; flex: 1; }
.mg-body h3 {
    margin: 0; font-size: 15px; font-weight: 700; color: #fff;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    transition: color .2s;
}
.mg-card:hover .mg-body h3 { color: #ff8fa3; }
.mg-sub { font-size: 12.5px; color: #8b8e98; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.mg-tag {
    background: #262831; border: 1px solid #33363f; border-radius: 8px;
    color: #aeb2bc; font-size: 10.5px; font-weight: 600; padding: 3px 9px;
}
.mg-tag.more { color: #ff8fa3; background: rgba(255, 77, 109, .10); border-color: rgba(255, 77, 109, .35); }
.mg-meta {
    margin-top: auto; padding-top: 10px; border-top: 1px solid #262831;
    display: flex; align-items: center; gap: 12px;
    color: #8b8e98; font-size: 11.5px; font-weight: 600;
}
.mg-meta span { display: inline-flex; align-items: center; gap: 5px; }
.mg-meta svg { width: 13px; height: 13px; opacity: .8; }
.mg-status {
    display: inline-flex !important;
}

/* ---------- Режим списка ---------- */
.mg-grid.list { grid-template-columns: 1fr; gap: 14px; }
.mg-grid.list .mg-card { flex-direction: row; }
.mg-grid.list .mg-media { width: 180px; aspect-ratio: 2 / 3; }
.mg-grid.list .mg-body { padding: 16px 20px; }
.mg-grid.list .mg-body h3 { font-size: 16px; white-space: normal; }
.mg-grid.list .mg-meta { margin-top: 8px; }

/* ---------- Пагинация ---------- */
.mg-pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 44px; padding-bottom: 40px; }
.mg-pagination .page-dots { color: #5d6068; padding: 0 4px; }

/* ---------- Адаптив ---------- */
@media (max-width: 900px) {
    .mg-hero { height: 240px; padding: 34px 20px 30px; }
    .mg-hero-inner { margin-left: 16px; gap: 12px; }
    .mg-hero-icon { width: 32px; height: 32px; border-radius: 8px; }
    .mg-hero-icon svg { width: 16px; height: 16px; }
    .mg-hero-text h1 { font-size: 20px; }
    .mg-hero-text p { font-size: 12px; }
    .mg-page { padding: 16px 16px 60px; }
    .mg-grid:not(.view-compact):not(.view-list):not(.list), .mg-grid.view-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
    .mg-grid.view-compact { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 8px !important; }
    .mg-grid.list .mg-media { width: 130px; }
    .manga-page .fp-columns { grid-template-columns: 1fr; }
    .mg-continue-fav-row { flex-direction: column; gap: 24px; }
    .mg-mini-card { flex: 0 0 130px; }
    .mg-cf-title { font-size: 17px; }
}

@media (max-width: 768px) {
    .mg-hero {
        height: auto !important;
        min-height: 180px !important;
        padding: 20px 14px 18px !important;
    }
    .mg-hero-inner {
        margin-left: 0 !important;
        gap: 12px !important;
        width: 100% !important;
    }
    .mg-hero-icon {
        width: 32px !important;
        height: 32px !important;
        border-radius: 8px !important;
    }
    .mg-hero-icon svg {
        width: 16px !important;
        height: 16px !important;
    }
    .mg-hero-text h1 {
        font-size: 20px !important;
    }
    .mg-hero-text p {
        font-size: 12px !important;
        margin-top: 4px !important;
    }
    .mg-page {
        padding: 14px 12px 24px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    .mg-topbar-wrap {
        margin-bottom: 12px !important;
    }
    .mg-topbar {
        gap: 8px !important;
        width: 100% !important;
    }
    .mg-search {
        min-width: 0 !important;
        width: 100% !important;
        flex: 1 1 100% !important;
        height: 46px !important;
        padding: 0 14px !important;
    }
    .mg-topbar-btns {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        overflow-x: auto !important;
        padding-bottom: 4px !important;
        scrollbar-width: none !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .mg-topbar-btns::-webkit-scrollbar {
        display: none !important;
    }
    .topbar-btn {
        height: 38px !important;
        padding: 0 12px !important;
        font-size: 12px !important;
        flex-shrink: 0 !important;
    }
    .mg-view {
        height: 38px !important;
        flex-shrink: 0 !important;
    }
    .mg-view button {
        width: 38px !important;
    }
    .mg-hot {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 6px !important;
        margin: 8px 0 14px !important;
    }
    .mg-hot-label {
        font-size: 11.5px !important;
    }
    .mg-hot-pills {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        width: 100% !important;
        padding-bottom: 4px !important;
        scrollbar-width: none !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .mg-hot-pills::-webkit-scrollbar { display: none; }
    .mg-hot-pills button {
        padding: 5px 12px !important;
        font-size: 11px !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }

    .mg-grid:not(.view-compact):not(.view-list):not(.list),
    .mg-grid.view-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 8px !important;
        width: 100% !important;
    }
    .mg-grid.view-compact {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
        gap: 5px !important;
        width: 100% !important;
    }
    .mg-card {
        border-radius: 12px !important;
        content-visibility: auto !important;
        contain-intrinsic-size: auto 240px !important;
    }
    .mg-media {
        aspect-ratio: 2 / 2.85 !important;
        max-height: 200px !important;
    }
    .mg-body {
        padding: 6px 8px 8px !important;
        gap: 2px !important;
    }
    .mg-body h3 {
        font-size: 12px !important;
        line-height: 1.2 !important;
    }
    .mg-sub {
        font-size: 10px !important;
    }
    .mg-tags {
        display: none !important;
    }
    .mg-meta {
        padding-top: 3px !important;
        font-size: 9.5px !important;
    }
    .mg-action-btn {
        font-size: 10px !important;
        height: 26px !important;
        padding: 2px 8px !important;
    }

    /* Мобильный аккордеон для Продолжить чтение и Избранное */
    .mg-continue-fav-row {
        flex-direction: column !important;
        gap: 8px !important;
        margin: 10px 0 12px !important;
    }
    .mg-cf-head {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 9px 12px !important;
        background: #17181f !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
        border-radius: 12px !important;
        margin-bottom: 6px !important;
        cursor: pointer !important;
        user-select: none !important;
    }
    .mg-cf-title {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        margin: 0 !important;
        font-size: 13.5px !important;
        font-weight: 700 !important;
    }
    .mg-chevron {
        display: inline-block !important;
    }
    .mg-continue-wrap:not(.open) .mg-continue-scroll,
    .mg-favorites-wrap:not(.open) .mg-favorites-scroll {
        display: none !important;
    }
    .mg-continue-wrap.open .mg-continue-scroll,
    .mg-favorites-wrap.open .mg-favorites-scroll {
        display: flex !important;
        animation: mgSlideDown .25s ease both !important;
    }
    .mg-continue-wrap.open .mg-chevron,
    .mg-favorites-wrap.open .mg-chevron {
        transform: rotate(180deg) !important;
    }
    .mg-clear-btn {
        font-size: 11px !important;
        padding: 4px 10px !important;
    }
    .mg-mini-card {
        flex-basis: 115px !important;
        width: 115px !important;
        border-radius: 11px !important;
        position: relative !important;
    }
    .mg-mini-body,
    .mg-mini-info {
        padding: 20px 8px 6px !important;
    }
    .mg-mini-body b,
    .mg-mini-info b {
        font-size: 11.5px !important;
    }
    .mg-mini-body span,
    .mg-mini-info span {
        font-size: 9.5px !important;
    }
}


/* Recommendations badge, reason and button */
#btn-mg-recs.active {
    background: rgba(255, 183, 3, 0.15) !important;
    border-color: #ffb703 !important;
    color: #ffb703 !important;
}
.mg-match {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(255, 183, 3, 0.92);
    color: #121316;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    z-index: 2;
    letter-spacing: 0.3px;
}
.mg-reason {
    color: #ffb703;
    font-size: 11px;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Подвал карточки манги: мета + кнопка «Читать» ---------- */
.mg-list-foot {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid #262831;
}

.mg-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 11.5px;
    color: #8b8e98;
}

.mg-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 14px;
    border-radius: 10px;
    background: rgba(255, 183, 3, .08);
    border: 1px solid rgba(255, 183, 3, .35);
    color: #ffb703;
    font-size: 12.5px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: background .2s, border-color .2s, color .2s, box-shadow .2s;
}

.mg-action-btn:hover,
.mg-card:hover .mg-action-btn {
    background: rgba(255, 183, 3, .2);
    border-color: rgba(255, 183, 3, .7);
    color: #fff;
    box-shadow: 0 0 14px rgba(255, 183, 3, .3);
}
