/* ============================================
   STORYAMIGOS — REAL BOOK COVERS
   ============================================
   Used by:
     - home.php     (Explore grid + Book of the Week)
     - books.php    (catalog)
     - book-detail.php
   Shared between all pages that show book
   covers. Link this file AFTER style.css.
   ============================================ */

/* ----------------------------------------------------------
   EXPLORE GRID — 5 small books per row
   ---------------------------------------------------------- */
.book-grid-wrap {
    position: relative;
    margin: 24px auto 0;
    column-count: 5;
    column-gap: 16px;
    padding: 4px;
    max-width: 1000px;
}

.book-grid-item {
    position: relative;
    cursor: default;
    padding: 10px;
    margin: 0 0 8px 0;
    display: grid;
    break-inside: avoid;
    page-break-inside: avoid;
}

.main-book-wrap {
    position: relative;
}

/* ----------------------------------------------------------
   HOMEPAGE EXPLORE GRID — 5 books per row on desktop
   ----------------------------------------------------------
   Uses CSS Grid (not columns) so exactly 5 books sit
   side by side on wide screens, no wrapping quirks.
   Only targets #preview-grid, so books.php is unaffected.
   ---------------------------------------------------------- */
#preview-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 100%;
    column-count: initial;
}

#preview-grid .book-grid-item {
    display: block;
    padding: 10px;
    margin: 0;
}

@media (min-width: 640px) {
    #preview-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    #preview-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1024px) {
    #preview-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 16px;
    }
}

/* ----------------------------------------------------------
   BOOK STRUCTURE (shared by grid + Book of the Week)
   ---------------------------------------------------------- */
.book-cover {
    position: relative;
}

/* Page block behind the cover */
.book-cover .book-inside {
    position: absolute;
    width: 90%;
    height: 96%;
    top: 1%;
    left: 16px;
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 2px 6px 6px 2px;
    background: #fdfbf6;
    box-shadow:
        10px 40px 40px -10px rgba(31,58,95,0.20),
        inset -2px 0 0 rgba(0,0,0,0.15),
        inset -3px 0 0 #dbdbdb,
        inset -4px 0 0 #ffffff,
        inset -5px 0 0 #dbdbdb,
        inset -6px 0 0 #ffffff,
        inset -7px 0 0 #dbdbdb,
        inset -8px 0 0 #ffffff,
        inset -9px 0 0 #dbdbdb;
}

/* The cover itself — fixed 3:4 */
.book-cover .book-image {
    line-height: 0;
    position: relative;
    border-radius: 2px 6px 6px 2px;
    box-shadow:
        6px 6px 18px -2px rgba(0,0,0,0.20),
        24px 28px 40px -6px rgba(0,0,0,0.10);
    transition: all 0.3s ease-in-out;
    transform: perspective(2000px) rotateY(-15deg) translateX(-10px) scaleX(0.94);
    cursor: pointer;
    display: block;
    aspect-ratio: 3 / 4;
    min-height: 120px;                 /* fallback for old browsers */

    /* NEW — keep the hover zoom inside the frame and give the
       cover a warm backdrop while the image is loading. */
    overflow: hidden;
    background: linear-gradient(160deg, #fff4e3 0%, #ffe7c7 100%);
}

.book-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;                 /* crop to fill, no stretching */
    object-position: center top;       /* keeps titles at the top */
    display: block;
    border-radius: 2px 6px 6px 2px;
    background: transparent;           /* container already paints the warm bg */
    transition: transform .35s ease;
}

.book-image:hover img {
    transform: scale(1.03);
}

.book-image:hover {
    transform: perspective(2000px) rotateY(0deg) translateX(0px) scaleX(1);
    transform-style: preserve-3d;
    box-shadow:
        6px 6px 12px -1px rgba(0,0,0,0.10),
        20px 14px 16px -6px rgba(0,0,0,0.10);
}

/* Cover shadow on the page block */
.effect {
    position: absolute;
    width: 20px;
    height: 100%;
    margin-left: 16px;
    top: 0;
    border-left: 2px solid rgba(0,0,0,0.06);
    background-image: linear-gradient(
        90deg,
        rgba(255,255,255,0.2) 0%,
        rgba(255,255,255,0) 100%
    );
    transition: all 0.5s ease;
    z-index: 5;
    pointer-events: none;
}

/* Sheen on the cover */
.light {
    width: 90%;
    height: 100%;
    position: absolute;
    border-radius: 3px;
    background-image: linear-gradient(
        90deg,
        rgba(255,255,255,0) 0%,
        rgba(255,255,255,0.2) 100%
    );
    top: 0;
    right: 0;
    opacity: 0.1;
    transition: all 0.5s ease;
    z-index: 4;
    pointer-events: none;
}

.book-image:hover .effect {
    margin-left: 14px;
}

/* ----------------------------------------------------------
   COVER FIT OVERRIDES
   ----------------------------------------------------------
   Books whose cover art must not be cropped can opt out of
   `object-fit: cover` via a per-book flag. In books.json:

     {
       "slug": "some-book",
       "cover_fit": "contain"
     }

   The rendering template then emits:

     <div class="book-image" data-cover-fit="contain">

   Everything else defaults to `cover`.
   ---------------------------------------------------------- */
.book-image[data-cover-fit="contain"] {
    background: linear-gradient(160deg, #fff7ec 0%, #ffe9d6 100%);
}

.book-image[data-cover-fit="contain"] img {
    object-fit: contain;
    object-position: center center;
    padding: 4%;
    transform: none;                   /* no zoom on padded covers */
}

.book-image[data-cover-fit="contain"]:hover img {
    transform: none;
}

/* Placeholder / fallback cover styling — looks intentional
   rather than broken when the real cover is missing. */
.book-image img.is-fallback {
    object-fit: contain;
    padding: 14%;
    opacity: .65;
}

/* ----------------------------------------------------------
   META TEXT UNDER EACH GRID BOOK
   ---------------------------------------------------------- */
.book-grid-meta {
    margin-top: 14px;
    text-align: center;
}
.book-grid-meta .book-grid-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.95rem;
    color: #1f3a5f;
    line-height: 1.25;
}
.book-grid-meta .book-grid-sub {
    font-size: 0.7rem;
    font-weight: 700;
    color: rgba(45,74,107,0.55);
    margin-top: 4px;
    display: flex;
    justify-content: center;
    gap: 6px;
}

/* Slightly smaller meta at 5-per-row so cards don't feel cramped */
@media (min-width: 1024px) {
    #preview-grid .book-grid-meta {
        margin-top: 10px;
    }
    #preview-grid .book-grid-meta .book-grid-title {
        font-size: 0.85rem;
    }
    #preview-grid .book-grid-meta .book-grid-sub {
        font-size: 0.65rem;
    }
}

/* ----------------------------------------------------------
   BOOK OF THE WEEK — larger offset for the spine
   ---------------------------------------------------------- */
.bow-book {
    position: relative;
    display: block;
}
.bow-book .book-cover .book-inside {
    left: 22px;
    width: 92%;
}
.bow-book .book-image .effect {
    margin-left: 22px;
}
.bow-book .book-image:hover .effect {
    margin-left: 20px;
}

/* ----------------------------------------------------------
   RESPONSIVE — grid only (Book of the Week sizes via Tailwind)
   ---------------------------------------------------------- */
@media (max-width: 1024px) {
    .book-grid-wrap { column-count: 4; max-width: 800px; }
}
@media (max-width: 768px) {
    .book-grid-wrap { column-count: 3; max-width: 640px; }
}
@media (max-width: 560px) {
    .book-grid-wrap { column-count: 2; max-width: 420px; }
    .book-grid-item { padding: 8px; margin-bottom: 6px; }
}
@media (max-width: 400px) {
    .book-grid-wrap { column-count: 1; max-width: 240px; }
    .book-grid-item { padding: 10px; margin-bottom: 8px; }
    /* Smaller resting tilt on phones */
    .book-cover .book-image {
        transform: perspective(2000px) rotateY(-8deg) translateX(-6px) scaleX(0.96);
    }
}

/* ----------------------------------------------------------
   GRID ACTIONS — small icon buttons under each catalog book
   ---------------------------------------------------------- */
.book-grid-actions {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}

.book-grid-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    border: 2px solid rgba(45,74,107,0.15);
    background: transparent;
    color: #1f3a5f;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
    padding: 0;
}

.book-grid-action-btn:hover {
    border-color: rgba(45,74,107,0.4);
    background: rgba(45,74,107,0.05);
}

.book-grid-action-btn.primary {
    background: var(--coral);
    color: #ffffff;
    border-color: var(--coral);
}

.book-grid-action-btn.primary:hover {
    background: var(--coral-dark);
    border-color: var(--coral-dark);
}

.book-grid-action-btn.active {
    background: var(--coral);
    color: #ffffff;
    border-color: var(--coral);
}