/*
 * Сетка листингов на shuffle.js: /blog/*, /fitness/praktisch/, /fitness/dialog/.
 *
 * Одна разметка карточки (.lm-card) на оба вида:
 *   сетка  — #cat-shuf.lm-grid, раскладка masonry (см. ниже);
 *   список — тот же DOM при .list-view и всегда на экранах уже 812px.
 * Скрипт карточки не перерисовывает, а только переставляет и показывает.
 *
 * Masonry без абсолютных координат: CSS Grid с рядами по 8px, каждая карточка
 * занимает столько рядов, сколько весит её высота (--lm-span ставит
 * lingoMasonry.layout). Авторазмещение grid кладёт следующую карточку в самую
 * короткую колонку, первые N стоят в верхнем ряду слева направо.
 * Число колонок задаётся ТОЛЬКО здесь (--lm-cols), в JS брейкпоинтов нет.
 */

#cat-shuf.lm-grid {
    --lm-cols: 4;
    --lm-gap: 24px;
    --lm-masonry: 1;            /* 0 — раскладка выключена (список) */
    display: grid;
    grid-template-columns: repeat(var(--lm-cols), minmax(0, 1fr));
    gap: var(--lm-gap);
    align-items: start;
    margin: 0;
    padding: var(--lm-gap);
    background: #eaf3fc;
}
#cat-shuf.lm-grid.lm-cols-3 { --lm-cols: 3; }

@media (max-width: 991px) {
    #cat-shuf.lm-grid,
    #cat-shuf.lm-grid.lm-cols-3 { --lm-cols: 3; }
}

/* Раскладка включена скриптом: ряды по 8px, зазор входит в высоту карточки
   (поэтому снизу у контейнера поля нет — его даёт последняя карточка). */
#cat-shuf.lm-grid.is-masonry {
    grid-auto-rows: 8px;
    row-gap: 0;
    padding-bottom: 0;
}
#cat-shuf.lm-grid.is-masonry > .lm-card {
    grid-row-end: span var(--lm-span, 40);
}

#cat-shuf .grid-sizer { display: none; }

/* Данные ещё не пришли: держим высоту, чтобы блоки ниже не прыгали. */
#cat-shuf.lm-loading { min-height: 100vh; }

/* Порции: пока скрипт не взял управление, видны первые 20 (grid-sizer — 1-й
   потомок, поэтому n+22). Без JS класса .lm-js нет и видны все карточки. */
.lm-js #cat-shuf:not(.lm-ready) > .lm-card:nth-child(n+22):not(.is-on) { display: none; }
#cat-shuf.lm-ready > .lm-card:not(.is-on) { display: none; }

/* ---- Карточка ---------------------------------------------------------- */
.lm-card { min-width: 0; }
/* В теме у ссылок и кнопок стоит transition: all. Размеры внутри карточки
   анимировать нельзя: раскладка мерит высоту сразу после смены вида. */
.lm-card, .lm-card * {
    transition-property: color, background-color, border-color, opacity, box-shadow, transform !important;
}
.lm-card__box {
    position: relative;
    overflow: hidden;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(31, 41, 51, .14);
}
.lm-card__link {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    color: inherit;
    text-decoration: none;
}
.lm-card__link:hover .lm-card__title { color: #b3001b; }
.lm-card__link:focus-visible { outline: 3px solid #1a4fd6; outline-offset: -3px; }
.lm-card__media { position: relative; line-height: 0; background: #eef0f3; }
/* карточка без обложки: место под значок уровня и звезду */
.lm-card__media:empty { min-height: 44px; }
.lm-card__img {
    display: block;
    width: 100%;
    height: auto;
    /* --lm-ratio (ширина/высота) приходит уже ограниченным снизу 0.75:
       картинки выше 3:4 обрезаются до 3:4, видна верхняя треть */
    aspect-ratio: var(--lm-ratio, 1.3333);
    object-fit: cover;
    object-position: 50% 33%;
}
.lm-card__text { padding: 12px 14px 14px; }
.lm-card__level {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    padding: 3px 8px;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(31, 41, 51, .3);
    font-size: 17px;
    line-height: 1.2;
    font-weight: 700;
    color: #b3001b;
}
.lm-card__title {
    margin: 0;
    padding: 0;
    font-size: 20px;
    line-height: 1.3;
    font-weight: 700;
    color: #45566b;
}
.lm-card__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 8px;
    margin-top: 6px;
    font-size: 14px;
    line-height: 1.35;
    color: #5c6773;
}
.lm-card__theme + .lm-card__views::before { content: "·"; margin-right: 8px; }
.lm-card__views { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.lm-ico { flex: none; width: 14px; height: 14px; }

/* Звезда: область нажатия 44x44, сам значок — на белом круге поверх картинки */
.lm-card__fav {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: none;
    border: 0;
    cursor: pointer;
}
.lm-card__fav.isfav { color: #b85c00 !important; }
.lm-card__fav.notfav { color: #5c6773 !important; }
.lm-card__fav-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(31, 41, 51, .3);
}
.lm-ico--star { width: 16px; height: 16px; fill: none; }
.lm-card__fav.isfav .lm-ico--star { fill: currentColor; }
.lm-card__fav:focus-visible { outline: 3px solid #1a4fd6; outline-offset: -4px; }

/* «Новое»: в сетке — плашка на картинке под уровнем, в списке — метка во второй строке */
.lm-new { background: #1d7a4a; color: #fff; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.lm-new--pic { position: absolute; top: 42px; left: 8px; z-index: 2; padding: 3px 8px; border-radius: 6px; box-shadow: 0 1px 2px rgba(31, 41, 51, .3); font-size: 13px; }
.lm-new--tag { display: none; padding: 1px 8px; border-radius: 4px; font-size: 13px; }
.lm-card__media:empty ~ .lm-new--pic { display: none; }
.lm-card__media:empty ~ .lm-card__text .lm-new--tag { display: inline-flex; }

/* ---- Статус ------------------------------------------------------------- */
.lm-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    line-height: 1.3;
    font-weight: 700;
}
.lm-status--strip { padding: 6px 14px; }
.lm-status--strip .lm-status__num { margin-left: auto; padding-left: 8px; }
.lm-status--tag { display: none; padding: 1px 8px; border-radius: 4px; font-size: 13px; gap: 5px; }
.lm-status--tag .lm-ico { width: 12px; height: 12px; }
.lm-status__num { font-weight: 400; white-space: nowrap; }
.lm-status--tag .lm-status__label { white-space: nowrap; }
.lm-status--in_progress { background: #ffe7ad; color: #4f3600; }
.lm-status--needs_review { background: #9a4a00; color: #fff; }
.lm-status--completed { background: #3b4654; color: #fff; }

/* Пройдено: картинка обесцвечена и под серым слоем, заголовок серый.
   Уровень и звезда остаются поверх слоя. */
.lm-card--done .lm-card__img { filter: grayscale(1); }
.lm-card--done .lm-card__media::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(238, 240, 243, .72);
}
.lm-card--done .lm-card__title { color: #5c6773; }

/* Рекламная карточка: в сетке — вертикальный баннер, в списке — широкий. */
.lm-card--ad .lm-card__box { line-height: 0; }
.lm-card--ad .lm-ad__wide { display: none; }
.lm-card--ad img { display: block; width: 100%; height: auto; }

.shuffle-empty {
    grid-column: 1 / -1;
    padding: 32px 12px;
    text-align: center;
    color: #555;
}
#shuffle-more { height: 1px; }

/* ---- Список: по кнопке и всегда до 812px -------------------------------- */
#cat-shuf.lm-grid.list-view {
    --lm-masonry: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 24px;
}
/* на /fitness/ сбоку колонка с описанием: два столбца строк не помещаются */
#cat-shuf.lm-grid.lm-cols-3.list-view { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 811px) {
    #cat-shuf.lm-grid {
        --lm-masonry: 0;
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
        padding: 12px;
    }
}

/* Правила списка написаны дважды — под класс и под media: объединить селектор
   с условием ширины нельзя, а вложенные @media поддерживают не все браузеры. */
#cat-shuf.list-view .lm-card__box { height: 100%; }
#cat-shuf.list-view .lm-card__link { flex-direction: row; align-items: stretch; min-height: 84px; padding-right: 44px; }
#cat-shuf.list-view .lm-card__media { flex: none; width: 112px; }
#cat-shuf.list-view .lm-card__img { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; }
#cat-shuf.list-view .lm-card__text { flex: 1; min-width: 0; align-self: center; padding: 10px 14px; }
#cat-shuf.list-view .lm-card__level { position: static; display: inline; margin-right: 8px; padding: 0; background: none; box-shadow: none; font-size: 18px; line-height: 1.3; }
#cat-shuf.list-view .lm-card__title { display: inline; font-size: 18px; }
#cat-shuf.list-view .lm-card__meta { gap: 3px 8px; margin-top: 4px; }
#cat-shuf.list-view .lm-status--strip, #cat-shuf.list-view .lm-new--pic { display: none; }
#cat-shuf.list-view .lm-new--tag { display: inline-flex; }
#cat-shuf.list-view .lm-status--tag { display: inline-flex; }
#cat-shuf.list-view .lm-card__fav { top: 50%; transform: translateY(-50%); }
#cat-shuf.list-view .lm-card__fav-dot { background: none; box-shadow: none; }
#cat-shuf.list-view .lm-ico--star { width: 18px; height: 18px; }
#cat-shuf.list-view .lm-card--ad { grid-column: 1 / -1; }
#cat-shuf.list-view .lm-card--ad .lm-ad__tall { display: none; }
#cat-shuf.list-view .lm-card--ad .lm-ad__wide { display: block; }

@media (max-width: 811px) {
    #cat-shuf .lm-card__box { height: 100%; }
    #cat-shuf .lm-card__link { flex-direction: row; align-items: stretch; min-height: 80px; padding-right: 44px; }
    #cat-shuf .lm-card__media { flex: none; width: 76px; }
    #cat-shuf .lm-card__img { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; }
    #cat-shuf .lm-card__text { flex: 1; min-width: 0; align-self: center; padding: 9px 10px; }
    #cat-shuf .lm-card__level { position: static; display: inline; margin-right: 8px; padding: 0; background: none; box-shadow: none; font-size: 16px; line-height: 1.3; }
    #cat-shuf .lm-card__title { display: inline; font-size: 16px; }
    #cat-shuf .lm-card__meta { gap: 3px 8px; margin-top: 4px; font-size: 13px; }
    #cat-shuf .lm-card__views { display: none; }          /* на мобилке просмотры не выводятся */
    #cat-shuf .lm-status--strip, #cat-shuf .lm-new--pic { display: none; }
    #cat-shuf .lm-new--tag { display: inline-flex; }
    #cat-shuf .lm-status--tag { display: inline-flex; }
    #cat-shuf .lm-card__fav { top: 50%; transform: translateY(-50%); }
    #cat-shuf .lm-card__fav-dot { background: none; box-shadow: none; }
    #cat-shuf .lm-ico--star { width: 18px; height: 18px; }
    #cat-shuf .lm-card--ad { grid-column: 1 / -1; }
    #cat-shuf .lm-card--ad .lm-ad__tall { display: none; }
    #cat-shuf .lm-card--ad .lm-ad__wide { display: block; }
}

/* ==== Панель: вкладки, фильтры, сортировка, вид, поиск ==================== */
.lm-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin: 0 0 14px;
    font-size: 15px;
    color: #1f2933;
}
.lm-sheet { display: contents; }
.lm-sheet__head, .lm-sheet__foot, .lm-sheet__label, .lm-chosen { display: none; }
/* с .lm-panel впереди — чтобы перебить display у .lm-btn ниже */
.lm-panel .lm-panel__open, .lm-panel .lm-panel__search-btn { display: none; }

.lm-btn, .lm-select, .lm-tab {
    min-height: 44px;
    padding: 0 16px;
    font: inherit;
    font-size: 15px;
    line-height: 1.2;
    color: #1f2933;
    background: #fff;
    border: 1px solid #8a94a0;
    border-radius: 6px;
    cursor: pointer;
}
.lm-btn { display: inline-flex; align-items: center; gap: 8px; }
.lm-btn--main { color: #fff; background: #b3001b; border-color: #b3001b; font-weight: 700; }
.lm-btn:focus-visible, .lm-select:focus-visible, .lm-tab:focus-visible, .lm-view:focus-visible, .lm-check input:focus-visible {
    outline: 3px solid #1a4fd6;
    outline-offset: 2px;
}

.lm-tabs { display: flex; order: 1; }
.lm-tab { border-radius: 0; border-left-width: 0; white-space: nowrap; }
.lm-tab:first-of-type { border-left-width: 1px; border-radius: 6px 0 0 6px; }
.lm-tab:last-of-type { border-radius: 0 6px 6px 0; }
.lm-tab[aria-pressed="true"] { color: #fff; background: #b3001b; border-color: #b3001b; font-weight: 700; }
.lm-tab__n { font-size: 13px; color: #5c6773; }
.lm-tab[aria-pressed="true"] .lm-tab__n { color: #fff; }

.lm-panel__tools { display: flex; align-items: center; gap: 2px; order: 2; margin-left: auto; }
.lm-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; order: 3; flex-basis: 100%; }

.lm-select {
    width: 230px;                /* ширина не зависит от списка — панель не прыгает при загрузке */
    max-width: 100%;
    padding-right: 34px;
    text-overflow: ellipsis;
    -webkit-appearance: none;
    appearance: none;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f2933' stroke-width='3'%3E%3Cpath d='m5 9 7 7 7-7'/%3E%3C/svg%3E") no-repeat right 12px center / 12px 12px;
}
.lm-select--plain { width: 236px; border-color: transparent; color: #45566b; }
.lm-check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; margin: 0; cursor: pointer; }
.lm-check input { width: 18px; height: 18px; margin: 0; accent-color: #b3001b; }
.lm-check[hidden] { display: none; }
/* Сложность и темы: выбрать можно несколько. На широком экране список добавляет
   значение, выбранные стоят рядом мини-тегами с крестиком (нажатие убирает);
   в окне «Фильтры» все уровни показаны кнопками, у тем — список и выбранные под ним. */
.lm-levels, .lm-themes { display: contents; }
.lm-lv {
    display: none; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px;
    font-size: 14px; font-weight: 700; line-height: 1; color: #b3001b; white-space: nowrap;
    background: #fff; border: 1px solid #b3001b; border-radius: 16px; cursor: pointer;
}
.lm-lv[aria-pressed="true"]:not([data-level="all"]) { display: inline-flex; }
.lm-lv:hover { background: #fbeaec; }
.lm-lv:focus-visible { outline: 2px solid #1f2933; outline-offset: 2px; }
.lm-lv__x { font-size: 12px; font-weight: 400; }

.lm-view {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: none;
    border: 0;
    color: #7b8794;
    cursor: pointer;
}
.lm-view[aria-pressed="true"] { color: #1f2933; }
.lm-view .lm-ico, .lm-panel__search-btn .lm-ico { width: 18px; height: 18px; }
.lm-panel .shuffle-search { width: 220px; height: 44px; margin-left: 10px; font-size: 15px; border-color: #8a94a0; border-radius: 6px; }

.shuffle-empty .lm-btn { margin-top: 12px; }

/* До 812px сетки нет — нет и переключателя вида. */
@media (max-width: 811px) {
    .lm-view { display: none; }
}

/* Свёрнутый вид: одна строка «Фильтры · сортировка · поиск», остальное в окне.
   Порог 1200px: в контейнере 960px (992–1199) полная панель в строку не входит. */
@media (max-width: 1199px) {
    .lm-panel { gap: 8px; flex-wrap: wrap; }
    .lm-panel .lm-panel__open { display: inline-flex; flex: none; order: 1; padding: 0 12px; }
    .lm-panel__count:not(:empty)::before { content: "· "; }
    .lm-panel__tools { flex: 1; min-width: 0; margin-left: 0; gap: 4px; flex-wrap: wrap; }
    .lm-select--plain { flex: 1; width: auto; min-width: 0; text-align: center; text-align-last: center; }
    .lm-panel .lm-panel__search-btn { display: inline-flex; flex: none; justify-content: center; width: 44px; padding: 0; }
    .lm-panel .shuffle-search { display: none; flex-basis: 100%; width: 100%; margin: 8px 0 0; font-size: 16px; }
    .lm-panel.is-search .shuffle-search { display: block; }

    .lm-chosen:not(:empty) { display: flex; flex-wrap: wrap; gap: 6px; order: 4; flex-basis: 100%; }
    .lm-chip {
        display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px;
        font: inherit; font-size: 14px; color: #1f2933; background: #eaf3fc; border: 0; border-radius: 6px; cursor: pointer;
    }
    .lm-chip--reset { background: none; color: #45566b; text-decoration: underline; }

    .lm-sheet { display: none; }
    .lm-sheet.is-open {
        display: flex;
        flex-direction: column;
        gap: 16px;
        position: fixed;
        inset: 0;
        z-index: 2000;
        padding: 0 16px;
        overflow-y: auto;
        background: #fff;
    }
    .lm-sheet__head {
        display: flex; align-items: center; justify-content: space-between;
        position: sticky; top: 0; z-index: 1; margin: 0 -16px; padding: 4px 4px 4px 16px;
        background: #fff; border-bottom: 1px solid #dfe4ea;
    }
    .lm-sheet__title { font-size: 18px; font-weight: 700; }
    .lm-sheet__close { width: 44px; height: 44px; padding: 0; background: none; border: 0; color: #1f2933; cursor: pointer; }
    .lm-sheet__close .lm-ico { width: 18px; height: 18px; }
    .lm-sheet__label { display: block; margin-bottom: 4px; font-size: 13px; color: #5c6773; }
    .lm-tabs { flex-direction: column; order: 0; }
    .lm-tab, .lm-tab:first-of-type, .lm-tab:last-of-type { text-align: left; border-width: 1px 1px 0; border-radius: 0; }
    .lm-tab:first-of-type { border-radius: 6px 6px 0 0; }
    .lm-tab:last-of-type { border-width: 1px; border-radius: 0 0 6px 6px; }
    .lm-filters { flex-direction: column; align-items: stretch; order: 0; flex-basis: auto; }
    .lm-filters .lm-select { width: 100%; }
    .lm-filters #lm-level { display: none; }
    .lm-levels { display: flex; flex-wrap: wrap; gap: 8px; }
    .lm-levels .lm-sheet__label { flex-basis: 100%; margin: 0; }
    .lm-themes { display: flex; flex-wrap: wrap; gap: 8px; }
    .lm-themes:empty { display: none; }
    .lm-themes .lm-lv { white-space: normal; text-align: left; line-height: 1.2; }
    .lm-lv, .lm-lv[aria-pressed="true"]:not([data-level="all"]) {
        display: inline-flex; min-height: 44px; padding: 0 14px; font-size: 15px; font-weight: 400;
        color: #1f2933; border-color: #8a94a0; border-radius: 6px;
    }
    .lm-lv[aria-pressed="true"], .lm-lv[aria-pressed="true"]:not([data-level="all"]) {
        color: #fff; background: #b3001b; border-color: #b3001b; font-weight: 700;
    }
    .lm-lv[aria-pressed="false"] .lm-lv__x { display: none; }
    .lm-sheet__foot {
        display: flex; gap: 8px; position: sticky; bottom: 0; margin: auto -16px 0; padding: 12px 16px;
        background: #fff; border-top: 1px solid #dfe4ea;
    }
    .lm-sheet__foot .lm-btn { flex: 1; justify-content: center; }
    .lm-sheet__foot .lm-btn--main { flex: 2; }
    html.lm-sheet-open { overflow: hidden; }
}

/* /blog/: крошки на мобилке — одна ссылка назад. Разметка не меняется. */
@media (max-width: 811px) {
    .linguo-title .page-breadcrumb li:first-child,
    .linguo-title .page-breadcrumb li:last-child { display: none; }
    .linguo-title .page-breadcrumb li:nth-child(2) a::before { content: "‹ "; }
}

/* ==== Широкий экран (от 1440px) ============================================
   Сайт свёрстан «коробкой» 1220px. На листингах (body.lm-wide-page) коробка
   расширяется, а контейнер листинга становится 1380px. Шапка, меню и подвал
   остаются в своих контейнерах прежней ширины; .container глобально не меняется. */
@media (min-width: 1440px) {
    body.boxed-layout.lm-wide-page .wrapper { width: 1430px; }
    body.lm-wide-page .masonry-page > .container,
    body.lm-wide-page .linguo-title > .container {
        width: 1380px;
        max-width: 1380px;
    }
    #cat-shuf.lm-grid:not(.lm-cols-3):not(.list-view) { --lm-cols: 5; }
    #cat-shuf.lm-grid:not(.lm-cols-3):not(.list-view) .lm-card__title { font-size: 18px; }
}


/* Длинные названия в сетке: класс ставит lingoMasonry (shuffle_grid_boot.html),
   когда название занимает больше двух строк (lm-fit-s) и больше трёх (lm-fit-xs).
   В списке и на мобилке размер обычный. Стоит после правила пяти колонок. */
@media (min-width: 812px) {
    #cat-shuf.lm-grid:not(.list-view) .lm-card__title.lm-fit-s { font-size: 17px; }
    #cat-shuf.lm-grid:not(.list-view) .lm-card__title.lm-fit-xs { font-size: 15px; }
}
@media (min-width: 1440px) {
    #cat-shuf.lm-grid:not(.lm-cols-3):not(.list-view) .lm-card__title.lm-fit-s { font-size: 16px; }
}
