/* Shared catalog grid: one on phones, two on tablets, four on desktop. */
.col-book-grid, .col-xl-2-5 {
    width: 100%; flex: 0 0 100%; max-width: 100%;
    padding-inline: calc(var(--bs-gutter-x, 1rem) * .5);
}
@media (max-width: 575.98px) {
    :is(.col-book-grid, .col-xl-2-5) > .library-book-card { max-width: 320px; margin-inline: auto; }
}
@media (min-width: 576px) and (max-width: 991.98px) {
    .col-book-grid, .col-xl-2-5 { width: 50% !important; flex: 0 0 50% !important; max-width: 50% !important; }
}
@media (min-width: 992px) {
    .col-book-grid, .col-xl-2-5 { width: 25% !important; flex: 0 0 25% !important; max-width: 25% !important; }
}

.ref-item-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    padding: 10px 10px 12px 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 3px 14px -3px rgba(0, 36, 49, 0.05);
    position: relative;
    direction: rtl;
    text-align: right;
    overflow: hidden;
    height: 100%;
}
html[dir="ltr"] .ref-item-card {
    direction: ltr;
    text-align: left;
}
html[dir="ltr"] .ref-card-title {
    text-align: center !important;
    font-family: 'Plus Jakarta Sans', sans-serif !important;
}
html[dir="ltr"] .ref-action-btn {
    font-family: 'Plus Jakarta Sans', sans-serif !important;
}
html[dir="ltr"] .ref-fav-btn {
    left: auto;
    right: 8px;
}
.ref-item-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 12px 28px -4px rgba(0, 36, 49, 0.12);
    transform: translateY(-4px);
}

/* Showcase Stage */
.ref-cover-stage {
    position: relative;
    width: 100%;
    margin-bottom: 8px;
    border-radius: 12px;
    background: transparent;
    padding: 0;
    border: none;
}

/* Floating Favorite Heart */
.ref-fav-btn {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 5;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(226, 232, 240, 0.9);
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.ref-fav-btn:hover, .ref-fav-btn.active {
    color: #ef4444 !important;
    border-color: #fca5a5 !important;
    background: #fef2f2 !important;
    transform: scale(1.1);
}

.ref-cover-link {
    display: block;
    width: 100%;
    text-align: center;
    text-decoration: none;
}

.ref-book-spine-effect {
    position: relative;
    width: 100% !important;
    aspect-ratio: 1 / 1.38 !important;
    border-radius: 12px;
    overflow: hidden !important;
    background: #f8fafc;
    box-shadow: 0 4px 14px -2px rgba(0, 36, 49, 0.1);
    transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.ref-book-spine-effect::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 6px;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.12), transparent);
    pointer-events: none;
    z-index: 2;
}
html[dir="ltr"] .ref-book-spine-effect::after {
    right: auto;
    left: 0;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.12), transparent);
}
.ref-item-card:hover .ref-book-spine-effect {
    transform: translateY(-3px) scale(1.015);
    box-shadow: 0 10px 22px -3px rgba(0, 36, 49, 0.18);
}

.ref-cover-img {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    border-radius: 12px;
    transition: transform 0.4s ease;
    z-index: 1;
}
.ref-media-play {
    position: absolute;
    z-index: 3;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 24px;
    pointer-events: none;
    background: none;
}
.ref-media-play-disc {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    padding: 0;
    background: linear-gradient(145deg, rgba(9, 83, 98, .94), rgba(0, 42, 56, .96));
    border: 1px solid rgba(246, 215, 154, .9);
    box-shadow: 0 0 0 5px rgba(255, 255, 255, .2), 0 6px 18px rgba(0, 28, 39, .3);
    font-size: 21px;
    transition: transform .2s ease, box-shadow .2s ease;
}
.ref-media-play-disc svg { display: block; flex: none; }
.ref-cover-link:is(:hover, :focus-visible) .ref-media-play-disc {
    transform: scale(1.06);
    box-shadow: 0 0 0 6px rgba(255, 255, 255, .3), 0 8px 22px rgba(0, 28, 39, .35);
}
@media (prefers-reduced-motion: reduce) {
    .ref-cover-link .ref-media-play-disc { transition: none; transform: none; }
}

/* Card Body */
.ref-card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 6px 2px 0 2px;
}

.ref-card-title {
    font-size: 13px;
    font-weight: 800;
    color: #002838;
    line-height: 1.38;
    margin-bottom: 6px;
    font-family: 'Tajawal', sans-serif;
    min-height: 36px;
    text-align: center;
}
.ref-card-title a {
    color: inherit;
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 0.25s ease;
}
.ref-card-title a:hover {
    color: #0284c7;
}

.ref-meta-lines {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-bottom: 8px;
    font-size: 11px;
    color: #64748b;
    font-weight: 600;
}
.ref-meta-item {
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ref-meta-author {
    color: #003244;
}
.ref-meta-sub {
    color: #64748b;
    font-size: 10.5px;
}
.ref-meta-icon {
    font-size: 10.5px;
    color: #94a3b8;
    width: 14px;
    text-align: center;
    flex-shrink: 0;
}
.ref-meta-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Footer Action & Stats */
.ref-card-footer {
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}
.ref-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    color: #ffffff !important;
    padding: 5px 12px;
    border-radius: 50px;
    font-size: 11px;
    font-weight: 700;
    text-decoration: none !important;
    transition: all 0.25s ease;
    box-shadow: 0 2px 8px rgba(0, 35, 46, 0.15);
    white-space: nowrap;
    font-family: 'Tajawal', sans-serif;
}
.ref-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 35, 46, 0.25);
    opacity: 0.95;
    color: #ffffff !important;
}
.ref-stats-wrap {
    display: flex;
    align-items: center;
    gap: 7px;
    color: #64748b;
    font-size: 10.5px;
    font-weight: 700;
}
.ref-stat-item {
    display: flex;
    align-items: center;
    gap: 3px;
}
.ref-stat-item i {
    font-size: 10.5px;
    color: #94a3b8;
}

@media (max-width: 767.98px) {
    .ref-item-card {
        padding: 7px 7px 9px 7px !important;
        border-radius: 14px !important;
    }
    .ref-cover-stage {
        margin-bottom: 5px !important;
    }
    .ref-book-spine-effect {
        border-radius: 8px !important;
    }
    .ref-cover-img {
        border-radius: 8px !important;
    }
    .ref-fav-btn {
        top: 5px !important;
        left: 5px !important;
        width: 24px !important;
        height: 24px !important;
        font-size: 10px !important;
    }
    .ref-card-title {
        font-size: 11.5px !important;
        min-height: 32px !important;
        margin-bottom: 4px !important;
        line-height: 1.3 !important;
    }
    .ref-meta-lines {
        font-size: 10px !important;
        gap: 2px !important;
        margin-bottom: 6px !important;
    }
    .ref-meta-sub {
        font-size: 9.5px !important;
    }
    .ref-action-btn {
        padding: 4px 8px !important;
        font-size: 10px !important;
        gap: 3px !important;
    }
    .ref-stats-wrap {
        font-size: 9.5px !important;
        gap: 4px !important;
    }
    .ref-stat-item i {
        font-size: 9.5px !important;
    }
}

/* Shared illustrated card skin. */
.library-book-card.ref-item-card { padding: 0 !important; border: 1px solid #d5dfdb; border-radius: 18px; background: #fcfcfa; justify-content: flex-start; box-shadow: 0 12px 28px #001e291c; }
.library-book-card .ref-cover-stage { margin: 0; border-radius: 0; }
.library-book-card .ref-book-spine-effect { height: auto; aspect-ratio: 0.85 !important; border-radius: 23px 23px 0 0 !important; background: #e4e9e4; box-shadow: none; }
.library-book-card .ref-cover-img { padding: 0; border-radius: 0 !important; object-fit: cover !important; object-position: center top; }
.library-book-card.ref-item-card:hover .ref-book-spine-effect { transform: none; box-shadow: none; }
.library-book-card .ref-book-spine-effect::after { display: none; }
.home-cover-wave { position: absolute; bottom: -1px; left: 0; width: 100%; height: var(--cover-wave-height); color: var(--cover-accent); pointer-events: none; z-index: 2; }
.home-cover-ornament { position: absolute; bottom: -4px; left: 4px; width: 100px; height: 48px; background: url('/assets/img/home-card-ornament.svg') top left / 110px auto; opacity: .8; pointer-events: none; z-index: 3; }
.library-book-card .book-access-badges { bottom: calc(var(--cover-wave-height) * .65 + 8px) !important; inset-inline: 8px !important; justify-content: flex-start; z-index: 4 !important; }
html[dir="ltr"] .library-book-card .book-access-badges { justify-content: flex-end; }
.library-book-card .book-access-badges > span { border-radius: 30px !important; padding: 7px 12px !important; font-size: 12px !important; box-shadow: 0 3px 10px #00243130; }
.library-book-card .ref-fav-btn, .library-book-card .cover-preview-trigger { top: 10px !important; width: 34px !important; height: 34px !important; font-size: 14px !important; color: #06485a; }
.library-book-card .ref-fav-btn { left: 10px !important; }
.library-book-card .cover-preview-trigger { inset-inline-start: auto; right: 10px; }
.library-book-card .ref-card-body { display: flex; flex-direction: column; flex: 1; padding: 8px 14px 10px; }
.library-book-card .ref-card-title { font-size: 16px !important; line-height: 1.5 !important; min-height: 0 !important; margin: 0 0 6px !important; text-align: center !important; }
.library-book-card .ref-meta-lines { font-size: 12px !important; gap: 6px; margin-bottom: 10px; }
.library-book-card .ref-meta-sub { font-size: 12px !important; font-weight: 800; color: #526e7b; }
.library-book-card .ref-meta-icon { font-size: 14px; width: 18px; color: #526e7b; }
.library-book-card .ref-card-footer { margin-top: auto; gap: 10px; flex-wrap: wrap; padding-top: 8px; border-color: #e5ebe8; }
.library-book-card .ref-action-btn { min-height: 40px; padding: 8px 12px !important; font-size: 13px !important; border-radius: 11px; box-shadow: 0 4px 9px #00243120; }
.library-book-card .ref-stats-wrap { font-size: 12px !important; gap: 8px; color: #526e7b; }
.library-book-card .ref-stat-item i { font-size: 13px !important; }
.library-book-card.ref-item-card :is(a, button):focus-visible { outline: 3px solid #b77a16; outline-offset: 3px; }
html[dir="ltr"] .library-book-card .ref-fav-btn { right: auto !important; }
.library-book-card { --cover-accent: #348766; --cover-wave-height: 56px; }
.row > :nth-child(4n + 2) .library-book-card { --cover-accent: #4887b4; }
.row > :nth-child(4n + 3) .library-book-card { --cover-accent: #b59151; }
.row > :nth-child(4n) .library-book-card { --cover-accent: #b78b37; }
@media (max-width: 575.98px) {
 .library-book-card .ref-card-body { padding: 8px 10px 10px; }
 .library-book-card .ref-card-title { font-size: 14px !important; min-height: 0 !important; margin-bottom: 6px !important; }
 .library-book-card .ref-meta-lines { gap: 5px; margin-bottom: 8px !important; }
 .library-book-card .ref-meta-sub { font-size: 11px !important; }
 .library-book-card .ref-meta-icon { font-size: 11px; width: 12px; }
 .library-book-card .ref-card-footer { gap: 8px; padding-top: 8px; }
 .library-book-card .ref-action-btn { width: 100%; min-height: 36px; padding: 6px !important; font-size: 12px !important; }
 .library-book-card .ref-stats-wrap { width: 100%; justify-content: center; font-size: 11px !important; }
 .library-book-card .ref-fav-btn, .library-book-card .cover-preview-trigger { top: 7px !important; width: 30px !important; height: 30px !important; font-size: 12px !important; }
 .library-book-card .ref-fav-btn { left: 7px !important; }
 .library-book-card .cover-preview-trigger { right: 7px; }
 .library-book-card .book-access-badges { inset-inline: 8px !important; }
 .library-book-card .book-access-badges > span { padding: 4px 6px !important; font-size: 10px !important; }
 .library-book-card .home-cover-ornament { width: 65px; height: 28px; background-size: 75px auto; }
}
@media (prefers-reduced-motion: reduce) { .library-book-card, .library-book-card .ref-book-spine-effect { transition: none; transform: none; } }

/* Give every content type the same action area, including longer English labels. */
.library-book-card .ref-card-footer { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.library-book-card .ref-action-btn { width: 100%; min-height: 44px; white-space: normal; line-height: 1.4; text-align: center; }
.library-book-card .ref-action-btn i { flex-shrink: 0; }
.library-book-card .ref-stats-wrap { width: 100%; justify-content: center; min-height: 18px; }

.library-book-card .ref-card-body { padding-top: 4px; padding-bottom: 6px; }
.library-book-card .ref-card-title { margin-bottom: 4px !important; line-height: 1.4 !important; }
.library-book-card .ref-meta-lines { margin-bottom: 4px !important; gap: 2px; }
.library-book-card .ref-card-footer { padding-top: 4px; gap: 2px; }
