/* 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;
    max-height: 100%;
    writing-mode: vertical-rl;
    font-family: var(--font-display);
    font-size: var(--fs, 12px);
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-align: center;
}
.book-spine-author {
    flex: 0 0 auto;
    font-size: 0.52rem;
    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 {
    /* the board's front strip covers the bottom 10px of the row; lift the
       flat pile onto the shelf surface so the bottom title stays readable */
    margin-bottom: 10px;
    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: 24px;
    padding: 0 18px 0 10px;
    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.7rem;
    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: 46px 20px 0; }
    .shelf-row { min-height: 178px; gap: 1px; }
    .book-spine { gap: 4px; padding: 7px 0; }
    .book-spine-author { font-size: 0.4rem; letter-spacing: 0.04em; }
    .book-band { display: none; }
    .book-flat { height: 17px; padding: 0 12px 0 6px; }
    .book-flat-title { font-size: 0.55rem; }
    .book-flat-pages { width: 5px; }
    .bookend { display: none; }
    .shelf-gap { flex-basis: 6px; }
    .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: a library request slip and a card-catalog drawer
   (shelf-suggest.js). Paper, typewriter text, red date stamps. */
.suggest {
    --paper: #f3ecdc;
    --paper-2: #e9dfc8;
    --ink: #2b2a27;
    --rule: rgba(66, 103, 140, 0.28);
    --red: #b5382e;
    display: grid;
    grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

/* the quiet bar under the shelf */
.suggest-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 14px; }
.suggest-bar[hidden] { display: none; }
.suggest-open {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: rgba(133, 192, 207, 0.35);
    text-underline-offset: 3px;
}
.suggest-open:hover { color: var(--text); text-decoration-color: currentColor; }
.suggest-open--quiet { color: var(--muted); text-decoration-color: rgba(170, 179, 186, 0.3); }

/* the pop-up */
.suggest-dialog {
    width: min(900px, calc(100% - 32px));
    max-height: calc(100dvh - 48px);
    padding: 26px 22px 22px;
    border: 0;
    border-radius: 16px;
    background: #141a1f;
    color: var(--text);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px #262f37;
    overflow-y: auto;
}
.suggest-dialog::backdrop { background: rgba(8, 11, 14, 0.62); backdrop-filter: blur(3px); }
.suggest-dialog[open] { animation: dialog-in 260ms cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
.suggest-close {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}
.suggest-close:hover { background: #1f272e; color: var(--text); }

/* request slip */
.slip {
    position: relative;
    padding: 18px 20px 16px;
    border-radius: 3px;
    color: var(--ink);
    font-family: "Courier Prime", "Courier New", monospace;
    background:
        linear-gradient(90deg, transparent 54px, rgba(181, 56, 46, 0.35) 54px, rgba(181, 56, 46, 0.35) 55px, transparent 55px),
        linear-gradient(180deg, var(--paper), var(--paper-2));
    box-shadow: 0 1px 0 rgba(255,255,255,0.4) inset, 0 18px 30px rgba(0, 0, 0, 0.45);
    transform: rotate(-0.8deg);
    overflow: hidden;
}
.slip-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--red); padding-bottom: 6px; }
.slip-head h3 { font-family: inherit; font-size: 1.05rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink); }
.slip-no { font-size: 0.82rem; color: var(--red); }
.slip-lede { margin: 10px 0 6px; font-size: 0.8rem; line-height: 1.4; color: #5a554b; }
.slip-line {
    display: grid;
    grid-template-columns: 96px 1fr;
    align-items: end;
    gap: 6px;
    padding: 6px 0 2px;
    border-bottom: 1px solid var(--rule);
}
.slip-line > span { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #6d675b; padding-bottom: 3px; }
.slip-line input,
.slip-line textarea {
    width: 100%;
    border: 0;
    padding: 2px 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 0.95rem;
    resize: none;
}
.slip-line input::placeholder { color: #a39b89; }
.slip-line input:focus,
.slip-line textarea:focus { outline: none; background: rgba(66, 103, 140, 0.08); }
.slip-line--tall textarea {
    line-height: 1.55rem;
    background: repeating-linear-gradient(180deg, transparent 0 calc(1.55rem - 1px), var(--rule) calc(1.55rem - 1px) 1.55rem);
}
.slip-foot { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.slip-stamp-btn {
    padding: 7px 14px;
    border: 2px solid var(--red);
    border-radius: 4px;
    background: transparent;
    color: var(--red);
    font: inherit;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background-color 150ms ease, color 150ms ease;
}
.slip-stamp-btn:hover { background: var(--red); color: var(--paper); }
.slip-stamp-btn:disabled { opacity: 0.55; cursor: default; }
.suggest-status { font-size: 0.8rem; color: #6d675b; }
.slip-stamp {
    position: absolute;
    right: 18px;
    top: 52px;
    padding: 4px 10px;
    border: 3px double var(--red);
    border-radius: 6px;
    color: var(--red);
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    opacity: 0;
    transform: rotate(-12deg) scale(1.6);
    pointer-events: none;
    mix-blend-mode: multiply;
}
.slip-stamp.is-down { animation: stamp-down 1.6s ease-out forwards; }
@keyframes stamp-down {
    0% { opacity: 0; transform: rotate(-12deg) scale(1.6); }
    12% { opacity: 0.85; transform: rotate(-12deg) scale(1); }
    75% { opacity: 0.85; }
    100% { opacity: 0; transform: rotate(-12deg) scale(1); }
}

/* card catalog drawer */
.drawer {
    position: relative;
    border-radius: 6px;
    background: linear-gradient(180deg, #3b2c21, #2a1f18);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05), 0 20px 36px rgba(0, 0, 0, 0.5);
    padding: 0 14px 14px;
}
.drawer-front {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 4px 10px;
}
.drawer-label {
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
    padding: 5px 12px;
    border-radius: 3px;
    background: linear-gradient(180deg, #d9b56a, #a9843e);
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25), 0 1px 0 rgba(255,255,255,0.2);
    color: #2a1f18;
    font-family: "Courier Prime", "Courier New", monospace;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-size: 0.78rem;
}
.drawer-label small { font-size: 0.68rem; letter-spacing: 0.06em; text-transform: none; font-weight: 400; }
.drawer-pull {
    width: 64px;
    height: 16px;
    border-radius: 0 0 14px 14px;
    background: linear-gradient(180deg, #c7a35d, #8d6c30);
    box-shadow: 0 2px 3px rgba(0,0,0,0.45);
}
.drawer-cards {
    list-style: none;
    margin: 0;
    padding: 10px 8px 4px;
    display: grid;
    gap: 10px;
    max-height: 380px;
    overflow-y: auto;
    border-radius: 3px;
    background: #1d1611;
    box-shadow: inset 0 8px 14px rgba(0, 0, 0, 0.55);
    scrollbar-width: thin;
    scrollbar-color: #5a4636 transparent;
}
.cat-card {
    --tilt: 0deg;
    padding: 10px 14px 10px;
    border-radius: 2px;
    color: var(--ink);
    font-family: "Courier Prime", "Courier New", monospace;
    background:
        linear-gradient(180deg, transparent 30px, var(--red) 30px, var(--red) 31px, transparent 31px),
        repeating-linear-gradient(180deg, transparent 0 21px, var(--rule) 21px 22px) 0 38px / 100% calc(100% - 38px) no-repeat,
        linear-gradient(180deg, var(--paper), var(--paper-2));
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
    transform: rotate(var(--tilt));
    transition: transform 220ms ease;
}
.cat-card:hover { transform: rotate(0deg) translateY(-2px); }
.cat-card.is-fresh { animation: card-file 700ms cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes card-file { from { opacity: 0; transform: translateY(-26px) rotate(-4deg); } }
.cat-top { display: flex; justify-content: space-between; align-items: center; height: 22px; margin-bottom: 8px; font-size: 0.72rem; }
.cat-call { font-weight: 700; letter-spacing: 0.08em; color: #6d675b; }
.cat-date {
    padding: 1px 6px;
    border: 1.5px solid var(--red);
    border-radius: 3px;
    color: var(--red);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    transform: rotate(-3deg);
    mix-blend-mode: multiply;
}
.cat-title { font-size: 1rem; font-weight: 700; line-height: 22px; }
.cat-author { font-size: 0.88rem; line-height: 22px; }
.cat-note { font-size: 0.84rem; line-height: 22px; color: #3d3a35; }
.cat-by { font-size: 0.72rem; line-height: 22px; color: #7a7366; }
.cat-empty { padding: 26px 10px; color: #b9a98c; font-family: "Courier Prime", monospace; font-size: 0.88rem; text-align: center; }

@media (max-width: 720px) {
    .suggest { grid-template-columns: 1fr; gap: 22px; }
    .suggest-dialog { padding: 40px 12px 14px; }
    .suggest-dialog.is-browsing .drawer { order: -1; }
    .slip { transform: none; padding: 16px 14px 14px; background:
        linear-gradient(180deg, var(--paper), var(--paper-2)); }
    .slip-line { grid-template-columns: 84px 1fr; }
    .drawer-cards { max-height: 320px; }
}
