.library {
    --max-book: 60;
    width: 100%;
    height: 100%;
    background-position: 50% 50%;
    background-size: cover;
    overflow: scroll;
    perspective: none;
    font-size: 1rem;
    background: black;
}

#switch-3d:checked+.library {
    perspective: 100rem;
}

.library * {
    transform-style: preserve-3d;
    backface-visibility: hidden;
}

.shelf {
    min-width: 100vw;
    width: calc(2em * var(--max-book));
    transform-origin: left top;
}

@media screen and (-webkit-min-device-pixel-ratio:0) {
    .shelf {
        animation-fill-mode: forwards;
    }
}

@keyframes shelf-rot {
    100% {
        transform: rotateY(-10deg);
    }
}

.tray {
    position: relative;
    height: 32em;
    box-sizing: border-box;
    border-color: transparent;
    border-style: solid;
    border-width: 4em;
    border-bottom-width: 0;
    transform-origin: left top;
}

.tray:nth-of-type(3) {
    transform: translateZ(2px);
}

.tray:nth-of-type(4) {
    transform: translateZ(3px);
}

.tray:nth-of-type(5) {
    transform: translateZ(4px);
}

.tray:nth-of-type(6) {
    transform: translateZ(5px);
}


.plate {
    position: absolute;
    box-sizing: border-box;
    background-image: url("../img/books/wood.jpg");
    background-repeat: repeat;
    background-size: 256px;
    backface-visibility: hidden;
}

/* 左 */
.shelf>.plate:nth-of-type(6) {
    top: 0;
    width: 4em;
    height: 100%;
    border-left: solid #685f56 1px;
    border-right: solid #685f56 1px;
}

/* 右 */
.shelf>.plate:nth-of-type(7) {
    top: 0;
    width: 4em;
    right: 0;
    height: 100%;
    border-left: solid #685f56 1px;
    border-right: solid #685f56 1px;
}

/* 下 */
.shelf>.plate:nth-of-type(8) {
    width: 100%;
    bottom: -4em;
    height: 4em;
    background-image: url("../img/books/wood_rot.jpg");
    border-top: solid #685f56 1px;
    border-bottom: solid #685f56 1px;
}

/* 上 */
.tray>.plate:nth-of-type(1) {
    width: 100%;
    height: 20em;
    transform-origin: center top;
    filter: brightness(50%);
    transform: rotateX(-90deg) rotateZ(180deg) translateY(-20em);
    background-image: url("../img/books/wood_fade_v.jpg");
    background-size: auto 100%;
}

/* 下 */
.tray>.plate:nth-of-type(2) {
    bottom: 0;
    width: 100%;
    height: 20em;
    transform-origin: left bottom;
    filter: brightness(80%);
    transform: rotateX(90deg);
    background-image: url("../img/books/wood_fade_v.jpg");
    background-size: auto 100%;
    /* z-index: -2; */
}

/* 左 */
.tray>.plate:nth-of-type(3) {
    width: 20em;
    height: 100%;
    transform-origin: left center;
    filter: brightness(60%);
    transform: rotateY(90deg) rotateZ(180deg) translateX(-20em);
    background-image: url("../img/books/wood_fade_h.jpg");
    background-size: auto 100%;
    backface-visibility: visible;
}

/* 右 */
.tray>.plate:nth-of-type(4) {
    right: 0;
    width: 20em;
    height: 100%;
    transform-origin: right top;
    filter: brightness(60%);
    transform: rotateY(-90deg);
    background-image: url("../img/books/wood_fade_h.jpg");
    background-size: auto 100%;
}

.tray>.plate:nth-of-type(5) {
    width: 100%;
    height: 100%;
    filter: brightness(40%);
    transform: translateZ(-20em);
}

.tray>.plate:nth-of-type(7) {
    width: 100%;
    top: -4em;
    height: 4em;
    border-top: solid #685f56 1px;
    border-bottom: solid #685f56 1px;
    background-size: 128px;
    background-image: url("../img/books/wood_rot.jpg");
}

.tray-label {
    position: absolute;
    background: url("../img/books/label.jpg");
    background-size: cover;
    padding: 0 0.8em;
    font-weight: bolder;
    font-size: 1.5em;
    color: rgb(126, 126, 126);
    text-shadow: -1px -1px 1px black, 1px 1px #ffffff;
    height: 2em;
    line-height: 2.2em;
    transform: translateX(2em) translateY(-120%) translateZ(0.1em);
    box-shadow: 0.1em 0.1em 0.1em black;
}

.books {
    display: inline-block;
    position: absolute;
    box-sizing: border-box;
    height: 21.5em;
    bottom: 0em;
}

#switch-3d:checked+.library .books {
    transform: translateZ(-4em);
}



.book {
    position: relative;
    min-height: 21.5em;
    max-height: 21.5em;
    float: left;
    width: 2em;
    writing-mode: vertical-rl;
    animation: book-height 0s steps(1) 0.5s forwards;
    color: black;
    background: white;
}

.book>a {
    overflow: hidden;
    display: none;
    position: absolute;
    z-index: 2;
    display: block;
    width: 100%;
    line-height: 2em;
    text-align: center;
    height: 0%;
    bottom: 0;
    left: 0;
    color: white;
    background: rgba(0, 0, 0, 0.9);
    transition: all 0.5s ease-in-out;
    border-top-left-radius: 1em;
    transform: translateZ(1px);

}

.books>div:hover>a {
    height: 50%;
}

@keyframes book-height {
    100% {
        height: 22rem;
    }
}

.book>img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book>span {
    display: block;
    width: 2rem;
    line-height: 2em;
    padding-top: 1em;
    overflow: hidden;
}

.book>span.double-line {
    display: block;
    width: 4em;
    line-height: inherit;
    margin: 0 auto;
    padding-top: 1em;
}

.books>div::before {
    position: absolute;
    display: block;
    content: "";
    /* z-index: 1; */
    width: 2em;
    height: 16em;
    transform-origin: center top;
    transform: rotateX(-90deg);
    background: url("../img/books/top.jpg");
    background-size: auto 100%;
}

.books>.book-last {
    overflow: initial;
    background: url("../img/books/last.jpg");
    background-size: 100% 100%;
}

.books>.book-last::after {
    display: block;
    content: "";
    position: absolute;
    right: 0;
    width: 16em;
    height: 100%;
    transform-origin: right center;
    transform: rotateY(90deg) translateX(16em);
    background: url("../img/books/urabyoshi.jpg");
    background-size: 100% 100%;
    backface-visibility: hidden;
}

@media screen and (min-width: 450px) {
    .library {
        font-size: 1.2rem;
    }
}

.syazi {
    width: 30rem;
    background: black;
    text-align: center;
    vertical-align: middle;
    padding: 2rem;
    transform-origin: left bottom;
    bottom: 0;
    border: double 3px white;
    margin: 2rem;
}