/* =========================================================
   مكتبة المفضلة — نافذة مستقلة منسجمة مع هوية واجهة عبقر
   ========================================================= */

body.favorites-open {
    overflow: hidden;
}

.favorites-modal {
    position: fixed;
    inset: 0;
    z-index: 160;
    align-items: center;
    justify-content: center;
    padding: clamp(12px, 3vw, 34px);
    background:
        radial-gradient(circle at 78% 12%, rgba(139, 92, 246, .18), transparent 34%),
        rgba(5, 3, 15, .76);
    -webkit-backdrop-filter: blur(15px) saturate(115%);
    backdrop-filter: blur(15px) saturate(115%);
    opacity: 0;
    transition: opacity .22s ease;
}

.favorites-modal.is-open {
    opacity: 1;
}

.favorites-dialog {
    --fav-panel: #151027;
    --fav-panel-soft: #1c1534;
    --fav-card: #20183a;
    --fav-card-hover: #251c43;
    --fav-line: rgba(196, 181, 253, .16);
    --fav-text: #f6f3ff;
    --fav-muted: #aaa2c7;
    --fav-violet: #a78bfa;
    --fav-gold: #fbbf24;
    width: min(100%, 980px);
    max-height: min(90dvh, 780px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--fav-text);
    background:
        linear-gradient(145deg, rgba(255, 255, 255, .035), transparent 35%),
        var(--fav-panel);
    border: 1px solid rgba(196, 181, 253, .2);
    border-radius: 28px;
    box-shadow: 0 34px 90px rgba(0, 0, 0, .58), 0 0 0 1px rgba(255, 255, 255, .025) inset;
    transform: translateY(16px) scale(.985);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}

.favorites-modal.is-open .favorites-dialog {
    transform: translateY(0) scale(1);
}

html:not(.dark) .favorites-dialog {
    --fav-panel: #fbfaff;
    --fav-panel-soft: #f4f0fd;
    --fav-card: #ffffff;
    --fav-card-hover: #fcfaff;
    --fav-line: rgba(91, 33, 182, .14);
    --fav-text: #241a4d;
    --fav-muted: #70678e;
    --fav-violet: #6d28d9;
    --fav-gold: #d97706;
    box-shadow: 0 30px 80px rgba(36, 26, 77, .24), 0 0 0 1px rgba(255, 255, 255, .5) inset;
}

.favorites-header {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: clamp(20px, 3vw, 30px) clamp(20px, 4vw, 38px) 22px;
    background:
        radial-gradient(circle at 18% -20%, rgba(251, 191, 36, .13), transparent 42%),
        linear-gradient(180deg, rgba(139, 92, 246, .09), transparent);
    border-bottom: 1px solid var(--fav-line);
}

.favorites-heading {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 15px;
}

.favorites-heading-icon {
    width: 54px;
    height: 54px;
    flex: 0 0 54px;
    display: grid;
    place-items: center;
    color: #362300;
    background: linear-gradient(145deg, #fde68a, #f59e0b);
    border: 1px solid rgba(255, 255, 255, .5);
    border-radius: 17px;
    box-shadow: 0 10px 28px rgba(245, 158, 11, .23), 0 1px 0 rgba(255, 255, 255, .7) inset;
    transform: rotate(4deg);
}

.favorites-heading-icon svg {
    width: 27px;
    height: 27px;
}

.favorites-eyebrow {
    display: block;
    margin-bottom: 2px;
    color: var(--fav-gold);
    font-size: .72rem;
    font-weight: 900;
    letter-spacing: .04em;
}

.favorites-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.favorites-title-row h2 {
    margin: 0;
    color: var(--fav-text);
    font-size: clamp(1.55rem, 3vw, 2rem);
    font-weight: 900;
    line-height: 1.18;
}

.favorites-count {
    min-width: 29px;
    height: 29px;
    display: inline-grid;
    place-items: center;
    padding: 0 8px;
    color: var(--fav-gold);
    background: rgba(251, 191, 36, .11);
    border: 1px solid rgba(251, 191, 36, .24);
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 900;
}

.favorites-heading p {
    margin: 5px 0 0;
    color: var(--fav-muted);
    font-size: .88rem;
    line-height: 1.55;
}

.favorites-close {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: grid;
    place-items: center;
    color: var(--fav-muted);
    background: rgba(255, 255, 255, .045);
    border: 1px solid var(--fav-line);
    border-radius: 13px;
    cursor: pointer;
    transition: color .18s ease, background .18s ease, transform .18s ease;
}

.favorites-close svg {
    width: 21px;
    height: 21px;
}

.favorites-close:hover,
.favorites-close:focus-visible {
    color: var(--fav-text);
    background: rgba(167, 139, 250, .13);
    transform: rotate(4deg);
}

.favorites-close:focus-visible,
.favorites-filter:focus-visible,
.favorite-open:focus-visible,
.favorite-remove:focus-visible,
.favorites-explore:focus-visible {
    outline: 3px solid rgba(251, 191, 36, .68);
    outline-offset: 2px;
}

.favorites-body {
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 18px clamp(16px, 4vw, 38px) clamp(20px, 4vw, 34px);
}

.favorites-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.favorites-filters {
    display: flex;
    align-items: center;
    gap: 7px;
    overflow-x: auto;
    padding: 2px;
    scrollbar-width: none;
}

.favorites-filters::-webkit-scrollbar {
    display: none;
}

.favorites-filter {
    flex: 0 0 auto;
    padding: 9px 15px;
    color: var(--fav-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 800;
    cursor: pointer;
    transition: color .18s ease, background .18s ease, border-color .18s ease;
}

.favorites-filter:hover {
    color: var(--fav-text);
    background: rgba(167, 139, 250, .07);
}

.favorites-filter.is-active {
    color: var(--fav-text);
    background: rgba(139, 92, 246, .15);
    border-color: rgba(167, 139, 250, .25);
}

html:not(.dark) .favorites-filter.is-active {
    color: #5b21b6;
    background: #eee8ff;
}

.favorites-visible-count {
    flex: 0 0 auto;
    color: var(--fav-muted);
    font-size: .78rem;
    font-weight: 700;
}

.favorites-feedback {
    margin: -4px 0 14px;
    padding: 10px 13px;
    color: #d1fae5;
    background: rgba(16, 185, 129, .11);
    border: 1px solid rgba(16, 185, 129, .25);
    border-radius: 12px;
    font-size: .82rem;
    font-weight: 700;
}

.favorites-feedback.is-error {
    color: #fecaca;
    background: rgba(239, 68, 68, .11);
    border-color: rgba(239, 68, 68, .25);
}

html:not(.dark) .favorites-feedback {
    color: #047857;
}

html:not(.dark) .favorites-feedback.is-error {
    color: #b91c1c;
}

.favorites-grid {
    min-height: 150px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1px 3px 4px;
    scrollbar-color: rgba(167, 139, 250, .35) transparent;
    scrollbar-width: thin;
}

.favorite-card {
    min-width: 0;
    min-height: 184px;
    display: grid;
    grid-template-columns: minmax(118px, 37%) 1fr;
    overflow: hidden;
    background: var(--fav-card);
    border: 1px solid var(--fav-line);
    border-radius: 19px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .13);
    transition: transform .2s ease, border-color .2s ease, background .2s ease, box-shadow .2s ease;
}

.favorite-card:hover {
    background: var(--fav-card-hover);
    border-color: rgba(167, 139, 250, .32);
    box-shadow: 0 14px 30px rgba(0, 0, 0, .2);
    transform: translateY(-2px);
}

.favorite-cover {
    position: relative;
    min-height: 184px;
    overflow: hidden;
    background: #0b0717;
}

.favorite-cover::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(21, 16, 39, .2), transparent 55%);
    pointer-events: none;
}

.favorite-cover img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    transition: transform .35s ease;
}

.favorite-card:hover .favorite-cover img {
    transform: scale(1.035);
}

.favorite-status {
    position: absolute;
    z-index: 1;
    top: 10px;
    right: 10px;
    padding: 5px 8px;
    color: #fff7ed;
    background: rgba(154, 52, 18, .88);
    border: 1px solid rgba(253, 186, 116, .35);
    border-radius: 999px;
    -webkit-backdrop-filter: blur(7px);
    backdrop-filter: blur(7px);
    font-size: .67rem;
    font-weight: 900;
}

.favorite-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 15px 15px 13px;
}

.favorite-category {
    align-self: flex-start;
    margin-bottom: 7px;
    color: var(--category-color, var(--fav-violet));
    font-size: .7rem;
    font-weight: 900;
}

.favorite-category::before {
    content: "";
    width: 6px;
    height: 6px;
    display: inline-block;
    margin-inline-end: 6px;
    vertical-align: 1px;
    background: currentColor;
    border-radius: 50%;
    box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 13%, transparent);
}

.favorite-card[data-section="competitions"] { --category-color: #34d399; }
.favorite-card[data-section="games"] { --category-color: #fb7185; }
.favorite-card[data-section="tools"] { --category-color: #60a5fa; }

html:not(.dark) .favorite-card[data-section="competitions"] { --category-color: #047857; }
html:not(.dark) .favorite-card[data-section="games"] { --category-color: #be123c; }
html:not(.dark) .favorite-card[data-section="tools"] { --category-color: #1d4ed8; }

.favorite-content h3 {
    margin: 0;
    overflow: hidden;
    color: var(--fav-text);
    font-size: 1rem;
    font-weight: 900;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.favorite-description {
    display: -webkit-box;
    margin: 6px 0 12px;
    overflow: hidden;
    color: var(--fav-muted);
    font-size: .76rem;
    line-height: 1.65;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.favorite-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
}

.favorite-open,
.favorite-remove,
.favorites-explore {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 0;
    cursor: pointer;
    font-weight: 900;
    transition: transform .18s ease, filter .18s ease, background .18s ease, color .18s ease;
}

.favorite-open {
    min-height: 37px;
    flex: 1 1 auto;
    padding: 8px 12px;
    color: #211400;
    background: linear-gradient(135deg, #fde68a, #f59e0b);
    border-radius: 11px;
    font-size: .76rem;
    box-shadow: 0 7px 18px rgba(245, 158, 11, .16);
}

.favorite-open svg,
.favorite-remove svg {
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
}

.favorite-open:hover:not(:disabled) {
    filter: brightness(1.05);
    transform: translateY(-1px);
}

.favorite-open:disabled {
    color: var(--fav-muted);
    background: rgba(255, 255, 255, .06);
    box-shadow: none;
    cursor: not-allowed;
}

.favorite-remove {
    width: 37px;
    height: 37px;
    flex: 0 0 37px;
    color: #fda4af;
    background: rgba(244, 63, 94, .09);
    border: 1px solid rgba(244, 63, 94, .18);
    border-radius: 11px;
}

.favorite-remove:hover:not(:disabled) {
    color: #fff;
    background: rgba(244, 63, 94, .24);
    transform: translateY(-1px);
}

.favorite-remove:disabled {
    opacity: .6;
    cursor: wait;
}

.favorite-remove.is-pending svg {
    animation: favorites-spin .8s linear infinite;
}

.favorites-empty,
.favorites-loading {
    grid-column: 1 / -1;
    min-height: 260px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px 18px;
    text-align: center;
    background:
        radial-gradient(circle at 50% 38%, rgba(139, 92, 246, .1), transparent 38%),
        var(--fav-panel-soft);
    border: 1px dashed rgba(167, 139, 250, .22);
    border-radius: 20px;
}

.favorites-empty-visual {
    position: relative;
    width: 74px;
    height: 74px;
    display: grid;
    place-items: center;
    margin-bottom: 14px;
    color: var(--fav-gold);
    background: rgba(251, 191, 36, .09);
    border: 1px solid rgba(251, 191, 36, .2);
    border-radius: 24px;
    transform: rotate(4deg);
}

.favorites-empty-visual svg {
    width: 34px;
    height: 34px;
}

.favorites-empty h3 {
    margin: 0 0 6px;
    color: var(--fav-text);
    font-size: 1.08rem;
    font-weight: 900;
}

.favorites-empty p {
    max-width: 430px;
    margin: 0;
    color: var(--fav-muted);
    font-size: .84rem;
    line-height: 1.7;
}

.favorites-explore {
    min-height: 42px;
    margin-top: 17px;
    padding: 10px 18px;
    color: #fff;
    background: linear-gradient(135deg, #7c3aed, #5b21b6);
    border-radius: 13px;
    font-size: .82rem;
    box-shadow: 0 9px 22px rgba(109, 40, 217, .22);
}

.favorites-explore:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.favorites-loading {
    gap: 10px;
    color: var(--fav-muted);
    font-size: .86rem;
    font-weight: 700;
}

.favorites-loading-star {
    color: var(--fav-gold);
    font-size: 2rem;
    animation: favorites-pulse 1.1s ease-in-out infinite;
}

@keyframes favorites-spin {
    to { transform: rotate(360deg); }
}

@keyframes favorites-pulse {
    50% { opacity: .45; transform: scale(.86) rotate(-8deg); }
}

@media (max-width: 760px) {
    .favorites-modal {
        align-items: flex-end;
        padding: 10px;
    }

    .favorites-dialog {
        max-height: calc(100dvh - 20px);
        border-radius: 24px;
    }

    .favorites-header {
        padding: 18px 18px 16px;
    }

    .favorites-heading-icon {
        width: 47px;
        height: 47px;
        flex-basis: 47px;
        border-radius: 15px;
    }

    .favorites-heading-icon svg {
        width: 23px;
        height: 23px;
    }

    .favorites-heading p {
        max-width: 34ch;
        font-size: .78rem;
    }

    .favorites-body {
        padding: 14px 14px 18px;
    }

    .favorites-toolbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        margin-bottom: 12px;
    }

    .favorites-filters {
        width: 100%;
    }

    .favorites-visible-count {
        padding-inline: 4px;
    }

    .favorites-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .favorite-card,
    .favorite-cover {
        min-height: 158px;
    }

    .favorite-card {
        grid-template-columns: minmax(108px, 35%) 1fr;
        border-radius: 17px;
    }

    .favorite-content {
        padding: 12px;
    }

    .favorite-description {
        margin-bottom: 9px;
    }
}

@media (max-width: 430px) {
    .favorites-modal {
        padding: 0;
    }

    .favorites-dialog {
        width: 100%;
        max-height: 100dvh;
        min-height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    .favorites-header {
        gap: 10px;
    }

    .favorites-heading {
        gap: 11px;
    }

    .favorites-heading p {
        max-width: 26ch;
    }

    .favorites-close {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }

    .favorite-card,
    .favorite-cover {
        min-height: 150px;
    }

    .favorite-card {
        grid-template-columns: 104px 1fr;
    }

    .favorite-content h3 {
        font-size: .92rem;
    }

    .favorite-description {
        font-size: .71rem;
    }

    .favorite-open {
        padding-inline: 9px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .favorites-modal,
    .favorites-dialog,
    .favorite-card,
    .favorite-cover img,
    .favorites-close,
    .favorite-open,
    .favorite-remove,
    .favorites-explore {
        transition: none !important;
    }

    .favorites-loading-star,
    .favorite-remove.is-pending svg {
        animation: none !important;
    }
}
