/* Homepage bookshelf: a wooden case viewed from slightly above. Books are 3D
   boxes (spine, cover on the right side, page block on top) built by shelf.js. */
.shelf {
    --wood: #4a3729;
    --wood-hi: #6a4f3a;
    --wood-lo: #2b2019;
    position: relative;
    padding: 70px 34px 0;
    border-radius: 10px 10px 0 0;
    background:
        linear-gradient(180deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0) 38%),
        linear-gradient(90deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0) 12%, rgba(0, 0, 0, 0) 88%, rgba(0, 0, 0, 0.45)),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.018) 0 2px, transparent 2px 9px, rgba(0, 0, 0, 0.05) 9px 10px, transparent 10px 23px),
        linear-gradient(180deg, #2c221b, #221a15);
    box-shadow:
        inset 16px 0 0 var(--wood), inset -16px 0 0 var(--wood), inset 0 16px 0 var(--wood),
        inset 18px 0 0 var(--wood-lo), inset -18px 0 0 var(--wood-lo), inset 0 18px 0 var(--wood-lo),
        0 30px 60px -20px rgba(0, 0, 0, 0.6);
}
.shelf::before {
    /* warm light falling from the top left */
    content: "";
    position: absolute;
    inset: 18px 18px 0;
    background: radial-gradient(70% 90% at 22% 0%, rgba(255, 214, 160, 0.09), transparent 70%);
    pointer-events: none;
}
.shelf-row {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    min-height: 260px;
    perspective: 2600px;
    perspective-origin: 50% -60%;
    overflow-x: auto;
    overflow-y: visible;
    padding: 40px 6px 0;
    margin-top: -40px;
    scrollbar-width: none;
}
.shelf-row::-webkit-scrollbar { display: none; }
.shelf-board {
    position: relative;
    height: 20px;
    margin: 0 -34px;
    background: linear-gradient(180deg, var(--wood-hi) 0, var(--wood) 30%, var(--wood-lo) 100%);
    box-shadow: 0 14px 24px rgba(0, 0, 0, 0.5);
}
.shelf-board::before {
    /* top surface of the board, seen from above */
    content: "";
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 100%;
    height: 10px;
    background: linear-gradient(180deg, #3a2c21, #57412f);
}

.bookend {
    flex: 0 0 auto;
    width: 10px;
    height: 120px;
    margin-right: 4px;
    border-radius: 2px 2px 0 0;
    background: linear-gradient(90deg, #8b949c, #c9d1d6 40%, #6d757c);
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.45);
}
.book-slot {
    position: relative;
    flex: 0 0 auto;
    transform-style: preserve-3d;
}
.book-slot::after {
    /* contact shadow on the board */
    content: "";
    position: absolute;
    left: -4px;
    right: -10px;
    bottom: -4px;
    height: 10px;
    background: radial-gradient(closest-side, rgba(0, 0, 0, 0.55), transparent);
    pointer-events: none;
}
.book {
    --lift: 0px;
    position: relative;
    display: block;
    width: var(--w);
    height: var(--h);
    padding: 0;
    border: 0;
    background: none;
    cursor: grab;
    touch-action: pan-x;
    transform-style: preserve-3d;
    --nudge: 0px;
    --lean: 0deg;
    transform: translate(var(--nudge), var(--lift)) rotate(calc(var(--tilt) + var(--lean)));
    transform-origin: bottom center;
    transition: width 560ms cubic-bezier(0.22, 1, 0.36, 1), transform 380ms cubic-bezier(0.22, 1, 0.36, 1), filter 300ms ease;
}
.book:hover { --lift: -12px; }
.book:focus-visible { box-shadow: none; outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 3px; }
.book-body {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--w);
    transform-style: preserve-3d;
    transform-origin: 100% 50%;
    transition: transform 820ms cubic-bezier(0.3, 1.25, 0.45, 1);
}
.book-spine,
.book-cover,
.book-top { position: absolute; top: 0; left: 0; }
.book-spine {
    width: var(--w);
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    color: var(--ink, #f5efe4);
    border-radius: 2px;
    background:
        linear-gradient(90deg, rgba(0,0,0,0.38), rgba(255,255,255,0.14) 18%, rgba(255,255,255,0.02) 40%, rgba(0,0,0,0.08) 70%, rgba(0,0,0,0.42)),
        linear-gradient(180deg, rgba(255,255,255,0.08), transparent 20%, transparent 85%, rgba(0,0,0,0.25)),
        var(--c, #56606a);
    backface-visibility: hidden;
}
.book-band {
    width: 100%;
    height: 3px;
    flex: 0 0 auto;
    border-top: 1px solid color-mix(in srgb, var(--ink, #fff) 45%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--ink, #fff) 45%, transparent);
    opacity: 0.7;
}
.book-spine-title {
    flex: 1 1 auto;
    min-height: 0;
    writing-mode: vertical-rl;
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.05;
    overflow: hidden;
    text-align: left;
}
.book-spine-author {
    font-size: 0.56rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.75;
    writing-mode: vertical-rl;
}
.book-ribbon {
    position: absolute;
    bottom: -12px;
    right: 7px;
    width: 5px;
    height: 18px;
    background: #c4443a;
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 75%, 0 100%);
}
.book-cover {
    left: var(--w);
    width: var(--d);
    height: 100%;
    overflow: hidden;
    border-radius: 0 3px 3px 0;
    background: var(--c, #56606a);
    transform-origin: 0 50%;
    transform: rotateY(90deg);
    backface-visibility: hidden;
}
.book-cover img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}
.book-cover::after {
    /* hinge crease and a little sheen */
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(0,0,0,0.35) 0, rgba(0,0,0,0) 4%, rgba(255,255,255,0.12) 6%, rgba(0,0,0,0) 9%),
        linear-gradient(125deg, rgba(255,255,255,0.14), transparent 40%);
}
.book-cover-title {
    display: block;
    padding: 14px;
    color: var(--ink, #f5efe4);
    font-family: var(--font-display);
    font-weight: 600;
}
.book-top {
    width: var(--w);
    height: var(--d);
    transform-origin: 50% 0;
    transform: rotateX(-90deg);
    background:
        repeating-linear-gradient(90deg, #efe6d3 0 1px, #d9ceb6 1px 2px),
        #e8dfcc;
    box-shadow: inset 2px 0 0 var(--c, #56606a), inset -2px 0 0 var(--c, #56606a), inset 0 -3px 0 var(--c, #56606a);
    filter: brightness(0.62);
}

/* Pulled: the slot widens to the cover, the box slides forward off the
   shelf and swings round so the cover faces out. */
.book.is-pulled {
    width: var(--d);
    --lift: -26px;
    transform: translateY(var(--lift));
    cursor: pointer;
    z-index: 2;
}
.book.is-pulled .book-body {
    transform: translateZ(60px) translateX(calc(var(--w) * -1)) rotateY(-90deg);
}
.book.is-pulled .book-cover { box-shadow: 0 26px 40px rgba(0, 0, 0, 0.55); }
.shelf-row.has-pulled .book:not(.is-pulled),
.shelf-row.has-pulled .book-flat:not(.is-pulled) { filter: brightness(0.6); }

.shelf-gap { flex: 1 0 28px; }
.book-pile {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    padding-right: 6px;
}
.book-flat {
    position: relative;
    width: var(--len);
    height: 30px;
    padding: 0 18px 0 12px;
    border: 0;
    border-radius: 2px;
    color: var(--ink, #f5efe4);
    background:
        linear-gradient(180deg, rgba(255,255,255,0.16), rgba(0,0,0,0) 35%, rgba(0,0,0,0.32)),
        var(--c, #56606a);
    text-align: left;
    cursor: pointer;
    transform: translateX(var(--shift, 0));
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
    transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1), filter 300ms ease;
}
.book-flat-pages {
    position: absolute;
    top: 3px;
    bottom: 3px;
    right: 3px;
    width: 8px;
    background: repeating-linear-gradient(180deg, #efe6d3 0 1px, #cfc4ac 1px 2px);
    border-radius: 1px;
}
.book-flat:hover { transform: translateX(calc(var(--shift, 0px) - 14px)); }
.book-flat.is-pulled { transform: translateX(-40px) translateY(-4px); box-shadow: 0 14px 22px rgba(0,0,0,0.5); }
.book-flat-title {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-family: var(--font-display);
    font-size: 0.78rem;
    font-weight: 600;
}

.shelf-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 22px;
    align-items: center;
    min-height: 132px;
    padding: 22px 28px 24px;
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--tile);
    border: 1px solid var(--tile-line);
    border-top: 0;
}
.shelf-card:not(.has-book) { grid-template-columns: 1fr; }
.shelf-card-cover {
    width: 84px;
    border-radius: 3px;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
    animation: card-in 420ms cubic-bezier(0.22, 1, 0.36, 1);
}
.shelf-card-text { display: grid; gap: 6px; animation: card-in 420ms cubic-bezier(0.22, 1, 0.36, 1) 60ms both; }
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } }
.shelf-card-empty { color: var(--muted); font-size: 0.92rem; }
.shelf-card-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.shelf-card-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
}
.shelf-card-status[data-status="reading"]::before { background: var(--accent); }
.shelf-card-status[data-status="next"]::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
.shelf-card-title { font-size: 1.4rem; font-weight: 600; }
.shelf-card-author { color: var(--muted); font-size: 0.9rem; }
.shelf-card-note { max-width: 40rem; margin-top: 4px; color: #c9d1d6; font-size: 0.95rem; }

@media (max-width: 620px) {
    .shelf { padding: 60px 20px 0; }
    .shelf-board { margin: 0 -20px; }
    .shelf-card { padding: 18px 16px 20px; gap: 16px; }
    .shelf-card-cover { width: 64px; }
}

@media (prefers-reduced-motion: reduce) {
    .book, .book-body, .book-flat { transition: none; }
}

/* Thrown books (shelf.js): a copy of the spine moved by a small rigid-body
   simulation inside the case. The real book's slot collapses while it's out. */
.book-slot.is-out .book { width: 0; opacity: 0; pointer-events: none; }
.book-slot.is-out::after { opacity: 0; }
.book-flyer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 5;
    cursor: pointer;
    touch-action: none;
    will-change: transform;
    filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.45));
}
.book-flyer.is-held { cursor: grabbing; filter: drop-shadow(0 22px 22px rgba(0, 0, 0, 0.5)); }
.book-flyer.is-returning { transition: transform 500ms cubic-bezier(0.22, 1, 0.36, 1); }
.book-flyer .book-spine { position: absolute; inset: 0; width: 100%; backface-visibility: visible; }
.book-flyer:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
/* springy lift and lean (slight overshoot), smooth width for the gap */
.book { transition: width 620ms cubic-bezier(0.22, 1, 0.36, 1), transform 520ms cubic-bezier(0.34, 1.45, 0.5, 1), filter 300ms ease, opacity 300ms ease; }
.book-flyer.is-settling { transition: transform 240ms ease-out; }

/* Suggest-a-book board (shelf-suggest.js) */
.suggest {
    display: grid;
    grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
    gap: 18px 32px;
    margin-top: 18px;
    padding: 24px 28px;
    border-radius: var(--radius);
    background: var(--tile);
    border: 1px solid var(--tile-line);
}
.suggest[hidden] { display: none; }
.suggest-head { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.suggest-head h3 { font-size: 1.25rem; font-weight: 600; }
.suggest-head p { color: var(--muted); font-size: 0.9rem; }
.suggest-form { display: grid; gap: 8px; align-content: start; }
.suggest-form input,
.suggest-form textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--tile-line);
    border-radius: 10px;
    background: #11161a;
    color: var(--text);
    font-size: 0.92rem;
    resize: vertical;
}
.suggest-form input:focus,
.suggest-form textarea:focus { outline: none; border-color: var(--accent); }
.suggest-form button {
    justify-self: start;
    padding: 8px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: #0d1215;
    font-weight: 600;
    cursor: pointer;
}
.suggest-form button:disabled { opacity: 0.6; cursor: default; }
.suggest-status { min-height: 1.2em; color: var(--muted); font-size: 0.84rem; }
.suggest-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 10px;
    max-height: 340px;
    overflow-y: auto;
    padding-right: 6px;
    align-content: start;
}
.suggest-item { padding: 12px 14px; border-radius: 12px; background: #11161a; border: 1px solid var(--tile-line); }
.suggest-item.is-fresh { animation: suggest-in 500ms cubic-bezier(0.22, 1, 0.36, 1); border-color: var(--accent); }
@keyframes suggest-in { from { opacity: 0; transform: translateY(-8px); } }
.suggest-book { font-size: 0.95rem; }
.suggest-author { color: var(--muted); }
.suggest-note { margin-top: 4px; color: #c9d1d6; font-size: 0.9rem; }
.suggest-by { margin-top: 6px; color: var(--muted); font-size: 0.78rem; }
.suggest-empty { color: var(--muted); font-size: 0.9rem; }
@media (max-width: 720px) {
    .suggest { grid-template-columns: 1fr; padding: 20px 16px; }
}
