/* ---- New Launches shelf: centre-focused carousel ----
   Every cover is a slot on a ring. `data-offset` (set by js/modules/book-shelf.js)
   says how far a card sits from the centre, and the geometry below turns that into
   position + size, so books glide between slots instead of swapping in place.
   Desktop shows offsets -3..3 (7 covers), mobile only -1..1 (3 covers). */

.book-track {
    /* Phones sit a touch under the workshops deck (.ws-slide is min(75%, 240px)
       wide) so the covers don't crowd the stage; md+ overrides below. */
    --book-w: min(42vw, 13rem);
    --book-h: calc(var(--book-w) * 1.4);
    position: relative;
    width: 100%;
    height: var(--book-h);
}

/* Keep the visible spread inside the stage; allow vertical room for shadows. */
#new-launches-stage {
    overflow-x: clip;
    overflow-y: visible;

    /* This padding is what holds the covers' feet on the podium: everything below the
       stage (dots, wrappers, the section's own padding) pushes them up, and this makes
       up the rest of the gap. js/modules/book-shelf.js measures the backdrop and
       overwrites it on load and on resize — the values here are only so the first paint
       lands close enough that nothing visibly jumps. See seatShelf() for the geometry.
       Mobile controls already reserve the space below the shelf. */
    padding-bottom: 0;
}
@media (min-width: 768px) {
    #new-launches-stage { padding-bottom: 1.5rem; }
}
@media (min-width: 1024px) {
    #new-launches-stage { padding-bottom: 2.5rem; }
}

/* md+: the whole spread has to fit between the arrows, the way the design shows
   it. The stage is a size container and its side padding is the arrows' gutter, so
   --book-w is sized off the room actually left for the covers (cqw = 1% of the
   stage's content box). The outermost visible slot reaches ~2.07 --book-w from
   the centre (slot-x plus half its scaled cover, which runs ~1.1x --book-w wide),
   so ±3 needs ~4.15 --book-w across and ±2 ~3.35. Tablets drop to ±2 below. */
@media (min-width: 768px) {
    #new-launches-stage {
        container-type: inline-size;
        padding-left: 3.5rem;
        padding-right: 3.5rem;
    }
    .book-track { --book-w: min(33cqw, 15rem); }
}
@media (min-width: 1024px) {
    #new-launches-stage {
        padding-left: 3.5rem;
        padding-right: 3.5rem;
    }
    .book-track { --book-w: min(26.5cqw, 23rem); }
}

.book-card {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: var(--book-w);
    height: var(--book-h);
    margin-left: calc(var(--book-w) / -2);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transform-origin: bottom center;
    /* The slot geometry lives in these three: --slot-x / --slot-s come from the
       per-offset rules below, --slot-r is how far this slot has to climb to keep
       its feet on the podium's curve (js/modules/book-shelf.js sets --rise-1..3 on
       .book-track — the podium is an ellipse in perspective, so a slot further out
       sits further back and therefore higher up). Composing them here rather than
       writing three transforms per offset keeps the rise out of every rule, and the
       transition below still runs because substituting a var recomputes `transform`. */
    --slot-x: 0px;
    --slot-s: 1;
    --slot-r: 0px;
    transform: translateX(var(--slot-x)) translateY(calc(var(--slot-r) * -1)) scale(var(--slot-s));
    will-change: transform;
    cursor: pointer;
    filter: drop-shadow(0 14px 12px rgba(0, 0, 0, 0.22));
    transition: transform 420ms ease, opacity 420ms ease, filter 420ms ease;
}

/* ── Turning a flat cover scan into a book ──────────────────────────────────
   The covers are flat artwork, so the depth is drawn around them: .book-3d is
   a shell that shrink-wraps the image and carries the two pieces a printed
   book has and a scan does not —

     ::before  the fore edge (right): a real side face hinged on the cover's
               edge and stood up 90deg, ruled to read as a stack of pages
     ::after   the binding: a dark crease down the spine edge (left), the
               highlight that always sits just off it, and a touch of shade
               along the fore edge so the cover turns instead of ending flat

   The shell itself is turned a few degrees so that side face is in shot.
   Everything is sized in % of the cover, so it holds at every slot size, and
   the drop-shadow on .book-card falls around the whole assembly. */
.book-3d {
    --book-turn: 7deg;
    --book-thickness: 5%;
    position: relative;
    display: block;
    max-width: 100%;
    max-height: 100%;
    /* Fore edge eased, spine edge only just off square — a bound spine has a
       corner, but not a knife-sharp one. */
    border-radius: 2px 5px 5px 2px;
    /* Turned a few degrees away from the viewer so the fore edge below is in
       shot. The perspective is on this element rather than on .book-track: the
       drop-shadow filter on .book-card flattens any 3D context handed down
       from above it. */
    transform: perspective(1400px) rotateY(var(--book-turn));
    transform-style: preserve-3d;
    transition: transform 300ms ease;
}

/* The fore edge — a real side face, stood up at 90deg off the cover's right
   edge, so it foreshortens with the turn instead of being a painted-on strip.
   The ruling is what reads as a stack of pages. */
.book-3d::before {
    content: '';
    position: absolute;
    top: 1.5%;
    bottom: 1.5%;
    /* hinged on the cover's right edge, not inset from it — anchoring with
       `right: 0` put the fold line 5% inside the artwork, which drew a seam
       down the front of every cover */
    left: 100%;
    width: var(--book-thickness);
    transform-origin: left center;
    transform: rotateY(90deg);
    border-radius: 0 3px 3px 0;
    background:
        linear-gradient(to bottom, rgba(0, 0, 0, 0.10), rgba(0, 0, 0, 0) 12%),
        repeating-linear-gradient(to right,
            #fdfbf6 0, #fdfbf6 1px,
            #cfc7b6 1px, #cfc7b6 2px);
    box-shadow: 0 2px 8px -3px rgba(18, 20, 45, 0.6);
}

/* Painted over the artwork, so it has to clear the image's own corners. */
.book-3d::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background:
        linear-gradient(to right,
            rgba(12, 16, 40, 0.34) 0%,
            rgba(12, 16, 40, 0.16) 1.4%,
            rgba(255, 255, 255, 0.30) 3%,
            rgba(255, 255, 255, 0.08) 5.5%,
            rgba(255, 255, 255, 0) 10%),
        linear-gradient(to left,
            rgba(12, 16, 40, 0.14) 0%,
            rgba(12, 16, 40, 0) 5%);
}

.book-cover {
    /* Auto width, fixed height: the element's box then *is* the cover, so the
       radius below lands on the artwork's own corners instead of on a box the
       letterboxed image only partly fills. */
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: bottom center;
    display: block;
    border-radius: 2px 5px 5px 2px;
    transition: transform 300ms ease;
}

@media (min-width: 768px) {

    .book-3d,
    .book-cover {
        border-radius: 3px 7px 7px 3px;
    }

    .book-3d::before {
        border-radius: 0 4px 4px 0;
    }
}

/* The spread. Keep the --book-w multipliers in step with SLOTS_X in
   js/modules/book-shelf.js — that's what turns them into each slot's rise. */

/* Only the centre slot is highlighted: full size, front of the stack, deepest shadow.
   It's also the podium's near point, so it never rises: --slot-r stays 0. */
.book-card[data-offset="0"] {
    --slot-x: 0px;
    --slot-s: 1;
    z-index: 40;
    filter: drop-shadow(0 26px 20px rgba(0, 0, 0, 0.3));
}

.book-card[data-offset="-1"] { --slot-x: calc(var(--book-w) * -0.72); --slot-s: 0.8; --slot-r: var(--rise-1, 0px); z-index: 30; }
.book-card[data-offset="1"]  { --slot-x: calc(var(--book-w) *  0.72); --slot-s: 0.8; --slot-r: var(--rise-1, 0px); z-index: 30; }

.book-card[data-offset="-2"] { --slot-x: calc(var(--book-w) * -1.3); --slot-s: 0.66; --slot-r: var(--rise-2, 0px); z-index: 20; }
.book-card[data-offset="2"]  { --slot-x: calc(var(--book-w) *  1.3); --slot-s: 0.66; --slot-r: var(--rise-2, 0px); z-index: 20; }

.book-card[data-offset="-3"] { --slot-x: calc(var(--book-w) * -1.76); --slot-s: 0.55; --slot-r: var(--rise-3, 0px); z-index: 10; }
.book-card[data-offset="3"]  { --slot-x: calc(var(--book-w) *  1.76); --slot-s: 0.55; --slot-r: var(--rise-3, 0px); z-index: 10; }

/* Staging slots: parked off-stage so a card can wrap around the ring unseen. They
   carry the ±3 rise so a card wrapping in doesn't drop onto the curve mid-slide. */
.book-card[data-offset="-4"] { --slot-x: calc(var(--book-w) * -2.15); --slot-s: 0.5; --slot-r: var(--rise-3, 0px); }
.book-card[data-offset="4"]  { --slot-x: calc(var(--book-w) *  2.15); --slot-s: 0.5; --slot-r: var(--rise-3, 0px); }
.book-card[data-offset="-4"],
.book-card[data-offset="4"] {
    opacity: 0;
    z-index: 0;
    pointer-events: none;
}

/* Mobile: three covers only — the centre one plus a sliver of its neighbours.
   Only --slot-x / --slot-s change; the rise still comes from --rise-1..3, which
   book-shelf.js recomputes from the mobile podium's own arc. */
@media (max-width: 767px) {
    .book-card[data-offset="-1"] { --slot-x: calc(var(--book-w) * -0.66); --slot-s: 0.72; }
    .book-card[data-offset="1"]  { --slot-x: calc(var(--book-w) *  0.66); --slot-s: 0.72; }

    .book-card[data-offset="-2"],
    .book-card[data-offset="-3"] { --slot-x: calc(var(--book-w) * -0.95); --slot-s: 0.62; --slot-r: var(--rise-2, 0px); }
    .book-card[data-offset="2"],
    .book-card[data-offset="3"]  { --slot-x: calc(var(--book-w) *  0.95); --slot-s: 0.62; --slot-r: var(--rise-2, 0px); }

    .book-card[data-offset="-2"],
    .book-card[data-offset="-3"],
    .book-card[data-offset="2"],
    .book-card[data-offset="3"] {
        opacity: 0;
        pointer-events: none;
    }
}

/* Tablets: five covers — ±3 would have to shrink every cover to fit, so they
   park off-stage with ±4 instead. */
@media (min-width: 768px) and (max-width: 1023px) {
    .book-card[data-offset="-3"],
    .book-card[data-offset="3"] {
        opacity: 0;
        pointer-events: none;
    }
}

/* Gentle lift on hover — on the shell, so the card's slot transform stays intact */
@media (hover: hover) {
    .book-card:hover .book-3d {
        transform: perspective(1400px) rotateY(var(--book-turn)) translateY(-6px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .book-card,
    .book-3d,
    .book-cover { transition: none; }
}

/* md+: the shelf sits a touch lower than the seat line — the covers only, the
   backdrop and podium stay put. A plain translate on the track, so the per-slot
   transforms and seatShelf()'s padding are untouched. */
@media (min-width: 768px) {
    .book-track { transform: translateY(0.75rem); }
}

/* Red starburst "NEW" badge on a launch cover (NewLaunch.is_new) */
.book-new-star {
    position: absolute;
    top: -14px;
    right: -14px;
    z-index: 5;
    width: clamp(40px, 22%, 62px);
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #E11D2E;
    color: #fff;
    font-weight: 800;
    font-size: clamp(9px, 1.4vw, 13px);
    letter-spacing: .04em;
    line-height: 1;
    text-transform: uppercase;
    transform: rotate(12deg);
    pointer-events: none;
    clip-path: polygon(50% 0%, 61% 17%, 79% 9%, 79% 29%, 98% 35%, 85% 50%, 98% 65%, 79% 71%, 79% 91%, 61% 83%, 50% 100%, 39% 83%, 21% 91%, 21% 71%, 2% 65%, 15% 50%, 2% 35%, 21% 29%, 21% 9%, 39% 17%);
    filter: none;
}
.book-new-star[hidden] { display: none; }
