/* ==========================================================================
   Библиотека текстов
   ========================================================================== */

.texts-page {
    padding-bottom: 26px;
}

.texts-page .page-hero {
    align-items: flex-end;
}

/* ---------- Панель фильтров ---------- */

.library-toolbar {
    position: sticky;
    top: calc(var(--header-height) + 10px);
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 26px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(9, 15, 27, 0.86);
    backdrop-filter: blur(16px);
    box-shadow: 0 16px 38px rgba(0, 0, 0, 0.3);
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.filter-chip {
    min-height: 36px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    cursor: pointer;
    transition: color 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.filter-chip:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
}

.filter-chip.is-active {
    color: #1b1105;
    border-color: transparent;
    background: linear-gradient(135deg, #ffd15c, #ffa134 58%, #ff7240);
    box-shadow: 0 8px 18px rgba(255, 128, 45, 0.2);
}

.search-box {
    position: relative;
    flex: 0 1 320px;
    display: flex;
    align-items: center;
}

.search-box__icon {
    position: absolute;
    left: 13px;
    width: 17px;
    height: 17px;
    color: var(--muted-2);
    pointer-events: none;
}

.search-box input {
    width: 100%;
    min-height: 40px;
    padding: 9px 14px 9px 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #0a1220;
    color: var(--text);
    font-size: 0.84rem;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.search-box input::placeholder {
    color: #5a6884;
}

.search-box input:focus {
    outline: none;
    border-color: rgba(255, 176, 32, 0.55);
    box-shadow: 0 0 0 4px rgba(255, 176, 32, 0.08);
}

.search-box input::-webkit-search-cancel-button {
    filter: invert(0.7);
}

/* ---------- Сетка трасс ---------- */

.text-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
}

.text-card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 22px 22px 20px;
    overflow: hidden;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.text-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 22px;
    right: 22px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 176, 32, 0.45), transparent);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.text-card:hover {
    transform: translateY(-3px);
    border-color: rgba(255, 176, 32, 0.24);
    box-shadow: 0 26px 54px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.text-card:hover::before {
    opacity: 1;
}

.text-card__top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.text-card__chars {
    margin-left: auto;
    color: var(--muted-2);
    font-size: 0.68rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.text-card__title {
    margin-bottom: 10px;
    font-size: 1.22rem;
    letter-spacing: -0.03em;
}

.text-card__title a {
    color: var(--text);
}

.text-card__title a:hover {
    color: var(--accent);
}

.text-card__preview {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    min-height: 4.5em;
    margin-bottom: 16px;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.5;
}

.text-card__meta {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted-2);
    font-size: 0.71rem;
    font-weight: 700;
}

.text-card__dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--muted-2);
}

.text-card__leader {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 46px;
    margin: 16px 0;
    padding: 8px 12px;
    border: 1px solid var(--line-soft);
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.02);
}

.text-card__leader-name {
    min-width: 0;
    overflow: hidden;
    color: #e3ebfa;
    font-size: 0.76rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-card__leader-score {
    margin-left: auto;
    flex: none;
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.text-card__leader-empty {
    color: var(--muted-2);
    font-size: 0.71rem;
    line-height: 1.4;
}

.text-card__actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

.text-card__actions .btn {
    flex: 1;
}

/* ---------- Блок «свой текст» ---------- */

.custom-cta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 26px;
    margin-top: 34px;
    padding: 28px 30px;
    border-color: rgba(255, 176, 32, 0.16);
    background:
        radial-gradient(520px 200px at 8% 0%, rgba(255, 176, 32, 0.1), transparent 68%),
        linear-gradient(160deg, rgba(24, 34, 58, 0.9), rgba(9, 15, 27, 0.95));
}

.custom-cta h2 {
    margin: 10px 0 8px;
    font-size: 1.35rem;
}

.custom-cta p {
    max-width: 640px;
    color: var(--muted);
    font-size: 0.85rem;
}

.custom-cta .btn {
    flex: none;
}

.texts-page .empty-state {
    margin-top: 8px;
}

/* ---------- Адаптивность ---------- */

@media (max-width: 1080px) {
    .text-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 860px) {
    .texts-page .page-hero {
        flex-direction: column;
        align-items: flex-start;
        gap: 22px;
    }

    .page-hero__stats {
        width: 100%;
        flex-wrap: wrap;
    }

    .hero-stat {
        flex: 1 1 0;
        min-width: 0;
    }

    .library-toolbar {
        position: static;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .search-box {
        flex: none;
    }

    .custom-cta {
        flex-direction: column;
        align-items: flex-start;
        gap: 20px;
    }
}

@media (max-width: 680px) {
    .text-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
    }

    .text-card {
        padding: 20px;
    }

    .text-card__preview {
        min-height: 0;
        -webkit-line-clamp: 2;
    }

    .custom-cta {
        padding: 22px;
    }

    .custom-cta .btn {
        width: 100%;
    }
}

@media (max-width: 420px) {
    .filter-chips {
        width: 100%;
    }

    .filter-chip {
        flex: 1;
    }
}
