/* ======================
   読書録（Reading Log）
   表紙を棚板の上に並べる。スマホ3冊・タブレット5冊・PC6冊で1段
   ====================== */

.library-section {
    max-width: 1080px;
    margin: 0 auto;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-bottom: 4rem;
}

/* 見出しのすぐ右に全体の冊数を添える */
.library-head {
    display: flex;
    align-items: baseline;
    gap: 1.1rem;
    margin-bottom: 1.75rem;
}

.library-title {
    font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
    font-weight: 600;
    font-size: clamp(1.9rem, 8vw, 2.75rem);
    letter-spacing: 0.08em;
    margin: 0;
}

/* カテゴリの目次。細いタイルを敷き詰めてヘッダーの下に固定し、押すとその棚まで移動する。
   横スクロールはさせず、PC は6列×2段、それより狭いと4列×3段で折り返す */
.library-cats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 0.5rem;
    /* layout.css の nav（固定ヘッダー用）のスタイルを打ち消してから、目次として固定する */
    position: sticky;
    /* --header-height は実際のヘッダーより少し高い。その隙間から本が透けないよう、
       固定位置を上げてその分を上の余白（背景つき）で埋める。差分はヘッダーの下に隠れる */
    top: calc(var(--header-height) - 28px);
    margin-top: -28px;
    width: auto;
    padding: calc(0.5rem + 28px) 0 0.5rem;
    /* 背景はヘッダーの下に張り付いている間だけ付ける（js/library.js が is-stuck を切り替える）。
       常に付けると、ページ先頭で見出しの下に暗い帯が見える */
    background: transparent;
    transition: background 0.2s;
    backdrop-filter: none;
    border: 0;
    border-bottom: 1px solid var(--border-color);
    z-index: 5;
}

.library-cats.is-stuck {
    background: var(--bg-primary);
}

@media (min-width: 960px) {
    .library-cats {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}

.library-cats a {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 0.4rem;
    min-width: 0;
    padding: 0.32rem 0.5rem;
    /* 枠線は使わず、うっすら青い面だけで区切る */
    border-radius: 3px;
    background: rgba(30, 58, 138, 0.28);
    color: var(--text-primary);
    font-size: 0.82rem;
    white-space: nowrap;
    text-decoration: none;
    transition: background 0.2s;
}

.library-cats a:hover {
    background: rgba(59, 130, 246, 0.35);
}

/* いま見ている棚 */
.library-cats a.is-active {
    background: rgba(59, 130, 246, 0.55);
    color: #fff;
}

.library-cats a.is-active sup {
    color: rgba(255, 255, 255, 0.8);
}

.library-cats a:focus-visible {
    outline: 2px solid var(--metallic-blue-bright);
    outline-offset: 2px;
}

/* 冊数は名前の右に小さく */
.library-cats sup {
    vertical-align: baseline;
    font-size: 0.68rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* スマホでは冊数まで1行に収まるよう3列にし、文字を少し小さくする */
@media (max-width: 639px) {
    .library-cats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .library-cats a {
        gap: 0.3rem;
        padding: 0.3rem 0.2rem;
        font-size: 0.74rem;
    }

    .library-cats sup {
        font-size: 0.62rem;
    }
}

.shelf-section {
    padding-top: 2.25rem;
    /* 固定ヘッダーと目次（2〜3段）の下に見出しが隠れないようにする */
    scroll-margin-top: calc(var(--header-height) + 5.5rem);
}

/* スマホは目次が4段になるぶん、見出しが隠れないよう止める位置を下げる */
@media (max-width: 639px) {
    .shelf-section {
        scroll-margin-top: calc(var(--header-height) + 7.5rem);
    }
}

.shelf-section h2 {
    font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
    font-weight: 500;
    font-size: 1.05rem;
    letter-spacing: 0.12em;
    margin: 0 0 0.25rem;
}

.shelf {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: 18px;
}

@media (min-width: 640px) {
    .shelf {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        column-gap: 26px;
    }
}

@media (min-width: 960px) {
    .shelf {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}

.book {
    padding-top: 22px;
    min-width: 0;
}

/* 表紙の下に棚板。行の隙間まで伸ばしてつながった1枚に見せる */
.book-cover {
    position: relative;
    aspect-ratio: 2 / 3;
}

.book-cover::after {
    content: "";
    position: absolute;
    left: -14px;
    right: -14px;
    bottom: -6px;
    height: 6px;
    background: linear-gradient(180deg, #1a2740, #0d1525);
    box-shadow: 0 1px 0 rgba(147, 187, 253, 0.18) inset, 0 10px 18px -6px rgba(0, 0, 0, 0.8);
}

.book-cover img {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: bottom center;
    border-radius: 2px 4px 4px 2px;
    filter: drop-shadow(6px 8px 10px rgba(0, 0, 0, 0.7));
    transition: transform 0.35s ease;
}

@media (hover: hover) {
    .book:hover .book-cover img {
        transform: translateY(-4px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .book-cover img {
        transition: none;
    }
}

.book-title {
    margin-top: 16px;
    font-size: 0.78rem;
    line-height: 1.45;
    text-align: center;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 総冊数。目次タイルの最後の空きマスに、タイルより一段控えめに置く。
   10棚なので 3列・4列・6列のどれでも最後の段は2マス以上空く */
.library-cats .library-count {
    grid-column: span 2;
    align-self: center;
    justify-self: end;
    padding: 0 0.2rem;
    font-size: 0.7rem;
    line-height: 1.4;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 639px) {
    .library-cats .library-count {
        font-size: 0.64rem;
        letter-spacing: 0.02em;
    }
}
