/* ============================================================
   LootLink — Catalog page styles
   Performance notes:
   - НЕ используем backdrop-filter на .cat-game (770 элементов = GPU kill).
   - content-visibility: auto на .cat-section — браузер не рендерит
     невидимые секции до scroll (огромный win при 39 секциях).
   - Иконка-плейсхолдер игры — inline SVG в background-image (без JS).
   ============================================================ */

/* Локальные solid-tokens для каталога (без blur).
   Совпадают с дизайн-системой по цветам, но opaque. */
:root {
    --cat-card-bg: #ffffff;
    --cat-card-bg-hover: #f8fafc;
    --cat-tag-bg: #f1f5f9;
    --cat-tag-bg-hover: rgba(74, 144, 226, 0.10);
}
[data-theme="dark"] {
    --cat-card-bg: #1e293b;
    --cat-card-bg-hover: #243245;
    --cat-tag-bg: #243245;
    --cat-tag-bg-hover: rgba(129, 140, 248, 0.18);
}

/* ── Catalog: Header ─────────────────────────────────── */
.catalog-page { contain: layout style; }
.cat-header { margin-bottom: var(--space-5); }
.cat-header__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}
.cat-header__title {
    font-size: var(--text-3xl);
    font-weight: var(--weight-extrabold);
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.02em;
    line-height: 1.15;
}
.cat-header__sub {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    margin-top: 6px;
}

/* ── Catalog: Search ─────────────────────────────────── */
.cat-search {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-xl);
    transition: border-color 0.2s var(--ease-out);
}
.cat-search:focus-within { border-color: var(--accent-primary); }
.cat-search__ico {
    width: 18px;
    height: 18px;
    color: var(--text-tertiary);
    flex-shrink: 0;
    transition: color 0.2s;
}
.cat-search:focus-within .cat-search__ico { color: var(--accent-primary); }
.cat-search__input {
    flex: 1;
    border: none !important;
    background: none !important;
    font-size: var(--text-sm);
    color: var(--text-primary);
    outline: none !important;
    box-shadow: none !important;
    min-width: 0;
    padding: 0;
}
.cat-search__input:focus,
.cat-search__input:focus-visible {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}
.cat-search__input::placeholder { color: var(--text-tertiary); }

/* ── Catalog: Alphabet nav (1 элемент с blur — это OK) ─ */
.cat-abc {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    padding: var(--space-3) 0;
    margin-bottom: var(--space-2);
    transition: background 0.3s var(--ease-out), border-color 0.3s var(--ease-out);
}
.cat-abc.stuck {
    background: var(--card-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--card-border);
    box-shadow: var(--shadow-sm);
    margin-left: -40px;
    margin-right: -40px;
    padding-left: 40px;
    padding-right: 40px;
}
.cat-abc__track {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
}
.cat-abc__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 6px;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    color: var(--text-secondary);
    background: var(--btn-secondary-bg);
    border: 1px solid var(--btn-secondary-border);
    text-decoration: none;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.cat-abc__btn::after { display: none !important; }
.cat-abc__btn:hover {
    color: var(--accent-primary);
    background: var(--color-primary-light);
    border-color: var(--accent-primary);
}
.cat-abc__btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* ── Catalog: Sections (lazy render через content-visibility) */
.cat-dir { padding-bottom: var(--space-8); }
.cat-section {
    padding-top: var(--space-5);
    /* Браузер не рендерит секцию пока она вне viewport.
       Огромный win: на 39 секций по ~20 карточек DOM-cost
       пересчитывается только для видимых. */
    content-visibility: auto;
    contain-intrinsic-size: auto 800px;
}
.cat-section.s-hidden { display: none; }
.cat-section__head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}
.cat-section__letter {
    font-size: var(--text-2xl);
    font-weight: var(--weight-extrabold);
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
    min-width: 32px;
}
.cat-section__line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--card-border) 0%, transparent 100%);
}
.cat-section__count {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-tertiary);
    background: var(--btn-secondary-bg);
    border: 1px solid var(--btn-secondary-border);
    padding: 3px 10px;
    border-radius: var(--radius-full);
}

/* ── Catalog: Game Grid ──────────────────────────────── */
.cat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
}

/* ── Catalog: Game Card (БЕЗ backdrop-filter) ────────── */
.cat-game {
    background: var(--cat-card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
    contain: layout style;
}
.cat-game:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-md);
    background: var(--cat-card-bg-hover);
}
.cat-game.s-hidden { display: none; }
.cat-game__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
    margin-bottom: var(--space-2);
}

/* Иконка-плейсхолдер: inline SVG (gamepad-2) через background-image.
   Без JavaScript, без 770 проходов lucide.createIcons(). */
.cat-game__icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-primary-light);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 20px 20px;
    color: var(--accent-primary);
}
/* Дефолт-иконка (gamepad-2 от Lucide) inline через data: URI.
   Цвет через CSS color + filter не работает на background → используем
   currentColor через mask вместо background-image. */
.cat-game__icon:not(:has(img))::before {
    content: "";
    width: 22px;
    height: 22px;
    background-color: var(--accent-primary);
    -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><line x1='6' x2='10' y1='11' y2='11'/><line x1='8' x2='8' y1='9' y2='13'/><line x1='15' x2='15.01' y1='12' y2='12'/><line x1='18' x2='18.01' y1='10' y2='10'/><path d='M17.32 5H6.68a4 4 0 0 0-3.978 3.59c-.006.052-.01.101-.017.152C2.604 9.416 2 14.456 2 16a3 3 0 0 0 3 3c1 0 1.5-.5 2-1l1.414-1.414A2 2 0 0 1 9.828 16h4.344a2 2 0 0 1 1.414.586L17 18c.5.5 1 1 2 1a3 3 0 0 0 3-3c0-1.545-.604-6.584-.685-7.258A4 4 0 0 0 17.32 5z'/></svg>");
            mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><line x1='6' x2='10' y1='11' y2='11'/><line x1='8' x2='8' y1='9' y2='13'/><line x1='15' x2='15.01' y1='12' y2='12'/><line x1='18' x2='18.01' y1='10' y2='10'/><path d='M17.32 5H6.68a4 4 0 0 0-3.978 3.59c-.006.052-.01.101-.017.152C2.604 9.416 2 14.456 2 16a3 3 0 0 0 3 3c1 0 1.5-.5 2-1l1.414-1.414A2 2 0 0 1 9.828 16h4.344a2 2 0 0 1 1.414.586L17 18c.5.5 1 1 2 1a3 3 0 0 0 3-3c0-1.545-.604-6.584-.685-7.258A4 4 0 0 0 17.32 5z'/></svg>");
    -webkit-mask-repeat: no-repeat;
            mask-repeat: no-repeat;
    -webkit-mask-position: center;
            mask-position: center;
    -webkit-mask-size: contain;
            mask-size: contain;
}
.cat-game__icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.cat-game__info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cat-game__name {
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.2s;
}
.cat-game:hover .cat-game__name { color: var(--accent-primary); }
.cat-game__count {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}
.cat-game__count--empty {
    font-style: italic;
    opacity: 0.6;
}
.cat-game__badge {
    font-size: 11px;
    font-weight: var(--weight-bold);
    color: white;
    background: var(--accent-gradient);
    padding: 3px 9px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    line-height: 1.3;
}

/* ── Catalog: Categories Accordion (lazy AJAX) ──────── */
.cat-game__cats-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: var(--space-2);
    padding: 6px 12px;
    font-size: 11px;
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    background: var(--cat-tag-bg);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.cat-game__cats-toggle:hover {
    color: var(--accent-primary);
    background: var(--cat-tag-bg-hover);
    border-color: var(--accent-primary);
}
.cat-game__cats-toggle::after {
    content: "▾";
    font-size: 9px;
    transition: transform 0.2s var(--ease-out);
}
.cat-game__cats-toggle[aria-expanded="true"]::after { transform: rotate(180deg); }

.cat-game__cats {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding-top: var(--space-2);
    border-top: 1px solid var(--card-border);
    margin-top: var(--space-2);
}
.cat-game__cats[hidden] { display: none; }
.cat-game__cats--loading {
    color: var(--text-tertiary);
    font-size: 11px;
    font-style: italic;
    padding: var(--space-2) 0;
}
.cat-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--cat-tag-bg);
    border: 1px solid transparent;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
    line-height: 1.4;
}
.cat-tag:hover {
    color: var(--accent-primary);
    background: var(--cat-tag-bg-hover);
    border-color: var(--accent-primary);
}
.cat-tag__n {
    font-size: 10px;
    font-weight: var(--weight-bold);
    color: var(--accent-primary);
    opacity: 0.7;
}

/* ── Catalog: No Result ──────────────────────────────── */
.cat-noresult { display: none; }
.cat-noresult.visible { display: block; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1024px) {
    .cat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .cat-header__top {
        flex-direction: column;
        gap: var(--space-3);
    }
    .cat-header__title { font-size: var(--text-2xl); }
    .cat-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-2);
    }
    .cat-game { padding: var(--space-3); }
    .cat-abc.stuck {
        margin-left: -20px;
        margin-right: -20px;
        padding-left: 20px;
        padding-right: 20px;
    }
    .cat-abc__track {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }
    .cat-abc__track::-webkit-scrollbar { display: none; }
}
@media (max-width: 480px) {
    .cat-grid { grid-template-columns: 1fr; }
    .cat-abc__btn {
        min-width: 30px;
        height: 30px;
        font-size: 11px;
    }
}

/* ── Reduced motion ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .cat-game,
    .cat-tag,
    .cat-abc__btn,
    .cat-game__cats-toggle,
    .cat-game__cats-toggle::after,
    .cat-search { transition: none; }
}
