/**
 * Bookshelf 页面样式
 * 外层白框（.bs-panel）は主题の Tailwind 类（見 content/bookshelf/_index.md）。
 * 构成：
 *   - Recommended … 首页の推荐（.rec-grid / .rec-card。表紙＋書名のみ、クリックで詳細弹窗）
 *   - Archive     … 年カード（.years / .years_item）
 *   - 书籍页面     … 月ごとの封面墙（.books。状态徽章 .bk-pill＋星 .bk-stars）
 *   - 详情弹窗     … .bk-modal（Recommended と书籍页面で共用）
 * 列数は各区块の @media (min-width: 640px) で「手机」→「桌面」に切替。
 * 区块标题 .bs-heading の样式は _partials/section-toc.html 側（书架と Playlist 共用）。
 */

.bookshelf {
  color: var(--color-foreground);
}

/* ===== 白框（Recommended / Archive 共用） =====
   ※ playlist.css の .pl-panel と同一内容。両ページの余白を揃えるため、
     片方を変えたらもう片方も合わせること（意図的に共通化していない）。
   padding は Tailwind の p-8（2rem）と同値をここでも明示しておく。 */
.bookshelf .bs-panel {
  padding: 2rem;
}
@media (max-width: 480px) {
  /* 極端に狭い画面のみ詰める（playlist 側と同条件・同値） */
  .bookshelf .bs-panel {
    padding: 1.5rem;
  }
}

/* 共通：カードはクリックで詳情弹窗を開く（書籍页面・Recommended とも） */
.bookshelf .book-card {
  cursor: pointer;
  outline: none;
}
.bookshelf .book-card:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
  border-radius: 6px;
}

/* ===== Recommended（网格：桌面每行5个，手机每行2个。表紙＋書名のみ） ===== */
/* 手机（<640px）では 2 列のまま、グリッド全体に max-width を掛けてカード幅の上限を作る。
   上限 190px は書籍页面の表紙（.books .bk-cover の max-width）と同値。
   これが無いと断点直前（639px 前後）で 2 列が引き伸ばされてカードが約 258px になり、
   桌面表示（約 138px）との落差が大きく粗く見える。
   grid 自体を絞って margin-inline: auto で中央寄せする方式なので、
   外側 .bs-panel の padding は変えずに済む（Archive と余白を揃えたままにできる）。
   ※ 列数を増やす案は不可：3 列が 190px に届くには枠内 624px 必要で、
     その前に 640px の桌面断点（5 列）が来てしまうため。 */
.bookshelf .rec-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: calc(190px * 2 + 1.7rem); /* カード上限190px×2 + gap */
  margin-inline: auto;
  gap: 1.7rem 1.7rem;
  align-items: start;
}
@media (min-width: 640px) {
  .bookshelf .rec-grid {
    grid-template-columns: repeat(5, 1fr);
    max-width: none;
  }
}
.bookshelf .rec-card {
  margin: 0;
  width: 100%;
  text-align: center;
  font-size: 0.72rem;
  line-height: 1.35;
}
.bookshelf .rec-card img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 0 0.5rem;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}
.bookshelf .rec-card:hover img,
.bookshelf .rec-card:focus-visible img {
  transform: scale(1.05);
}
.bookshelf .rec-card strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.875rem;
  line-height: 1.5;
  font-weight: 700;
  color: var(--color-foreground);
}

/* ===== Archive（年カード：左に年份＋冊数、右に最新3冊の表紙。手机1列 / 桌面2列） ===== */

/* ※ playlist.css の .ln-scroll / .ln-hint が姉妹実装（同じ考え方・別の値）。
      ヒントの見た目を変えるときは両方を合わせること。
   表示は2行まで（1画面で収まる高さ）。3行目以降は縦スクロール。
   max-height は最終的に JS が実測して px で上書きする（列数・比例を変えても追従する）。
   下の calc() は JS 実行前のちらつき防止用の概算値。
   ※ cqw は「祖先」コンテナを参照するため、container-type は .years-wrap 側に置く。 */
.bookshelf .years-wrap {
  container-type: inline-size;
}
.bookshelf .years-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  /* hover の scale(1.03) が縁で切れないための余白。
     同じ幅の負 margin で打ち消し、中身の位置を Recommended（.rec-grid）と揃える。 */
  padding: 0.375rem;
  margin: -0.375rem;
  /* 手机1列: 卡片高 = 100cqw/2 → ×2 + gap(1.5rem) + 上下padding(0.75rem) */
  max-height: calc(100cqw + 2.25rem);
  /* スクロールバーは非表示（スクロール自体は可能。上のヒントで存在を伝える）。
     テーマの base.css が全体に scrollbar-width: thin / ::-webkit-scrollbar 5px を
     当てているので、確実に消える display: none で上書きする。 */
  scrollbar-width: none;
}
.bookshelf .years-scroll::-webkit-scrollbar {
  display: none;
}
@media (min-width: 640px) {
  .bookshelf .years-scroll {
    /* 桌面2列: 卡片高 = (100cqw - gap 1.5rem)/4 → ×2 + gap(1.5rem) + 上下padding(0.75rem) */
    max-height: calc(50cqw + 1.5rem);
  }
}

/* ヒントは枠（外側の p-8 = 32px）の上部パディングの中央に置く。
   負の margin-top で上のパディング帯まで持ち上げ、カードとの間隔を空ける。
   非表示時(display:none)は margin も効かないのでレイアウトに影響しない。 */
.bookshelf .years-hint {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: -1.125rem 0 1rem;
  font-size: 0.72rem;
  line-height: 1;
  color: var(--color-muted-foreground);
  transition: opacity 0.3s ease;
}
.bookshelf .years-wrap.is-scrollable .years-hint {
  display: flex;
}
.bookshelf .years-wrap.is-end .years-hint {
  opacity: 0;
}
.bookshelf .years-hint svg {
  flex: none;
  animation: yr-bob 1.6s ease-in-out infinite;
}
@keyframes yr-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(2px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .bookshelf .years-hint svg {
    animation: none;
  }
}

.bookshelf .years {
  display: grid;
  grid-template-columns: 1fr;
  /* Liner Notes の .ln-grid（playlist.css）と同値。断点で変えず一律 1.5rem。
     カードは aspect-ratio 2/1 なので、間隔を広げた分だけカードは自動的に小さくなる */
  gap: 1.5rem;
}
@media (min-width: 640px) {
  .bookshelf .years {
    grid-template-columns: repeat(2, 1fr);
  }
}
/* 整张卡片为链接（点击任意位置都可跳转）。比例は従来通り 2:1 */
.bookshelf .years .years_item {
  display: flex;
  aspect-ratio: 2 / 1;
  border-radius: 12px;
  overflow: hidden;
  /* --color-muted は浅色モードでは card より少し暗く、深色モードでは少し明るい
     → 外側の白框（bg-card）から必ずカードが浮き上がる */
  background: var(--color-muted);
  border: 1px solid var(--color-border);
  text-decoration: none;
  transition:
    transform 0.3s ease,
    box-shadow 0.3s ease;
}
/* クリックできるカードなので Recommended と同じ「拡大」ホバー
   （liner notes の song-card は非クリックなので枠線＋影だけ、という区別） */
.bookshelf .years .years_item:hover,
.bookshelf .years .years_item:focus-visible {
  transform: scale(1.03);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}
.bookshelf .years .years_item:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

/* 左侧：年份＋冊数 */
.bookshelf .years .yr-meta {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  padding: 0.875rem;
}
.bookshelf .years .yr-year {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--color-foreground);
}
.bookshelf .years .yr-count {
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--color-muted-foreground);
}
/* 右侧：最新3冊の表紙（左＝最新を一番大きく前面に、右へ少しずつ重ねる） */
.bookshelf .years .yr-covers {
  position: relative;
  flex: none;
  align-self: stretch;
  width: 56%;
}
.bookshelf .years .yr-cover {
  position: absolute;
  width: auto;
  aspect-ratio: 2 / 3;
  box-sizing: border-box;
  /* 重なった表紙の境目を出すため、カード背景と同色の細い縁を付ける */
  border: 1.5px solid var(--color-muted);
  border-radius: 3px;
  object-fit: cover;
  background: var(--color-border);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.bookshelf .years .yr-cover--1 {
  height: 80%;
  top: 10%;
  left: 3%;
  z-index: 3;
}
.bookshelf .years .yr-cover--2 {
  height: 72%;
  top: 14%;
  left: 28%;
  z-index: 2;
}
.bookshelf .years .yr-cover--3 {
  height: 72%;
  top: 14%;
  left: 53%;
  z-index: 1;
}

/* ===== 书籍页面（网格：桌面每行3个，手机每行1个） ===== */
.bookshelf .books {
  display: grid;
  grid-template-columns: repeat(1, 1fr);
  gap: 1.9rem;
  justify-items: center;
  align-items: start;
  margin: 0.5rem;
}
@media (min-width: 640px) {
  .bookshelf .books {
    grid-template-columns: repeat(3, 1fr);
  }
}
.bookshelf .books figure {
  margin: 0;
  width: 100%;
  max-width: 240px;
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.4;
  background-size: 100% auto;
  background-position: top center;
  background-repeat: no-repeat;
}
/* 月ごとの装饰背景（figure の月クラスで切替） */
.books figure.jan {
  background-image: url("/images/bookshelf/style/jan.webp");
}
.books figure.feb {
  background-image: url("/images/bookshelf/style/feb.webp");
}
.books figure.mar {
  background-image: url("/images/bookshelf/style/mar.webp");
}
.books figure.apr {
  background-image: url("/images/bookshelf/style/apr.webp");
}
.books figure.may {
  background-image: url("/images/bookshelf/style/may.webp");
}
.books figure.jun {
  background-image: url("/images/bookshelf/style/jun.webp");
}
.books figure.jul {
  background-image: url("/images/bookshelf/style/jul.webp");
}
.books figure.aug {
  background-image: url("/images/bookshelf/style/aug.webp");
}
.books figure.sep {
  background-image: url("/images/bookshelf/style/sep.webp");
}
.books figure.oct {
  background-image: url("/images/bookshelf/style/oct.webp");
}
.books figure.nov {
  background-image: url("/images/bookshelf/style/nov.webp");
}
.books figure.dec {
  background-image: url("/images/bookshelf/style/dec.webp");
}
/* 表紙ラッパー（月の装饰背景を上に見せるための余白を保持） */
.bookshelf .books .bk-cover {
  display: block;
  width: 100%;
  max-width: 190px;
  margin: 2.1rem auto 0.6rem;
}
.bookshelf .books .bk-cover img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}
.bookshelf .books figure img:hover,
.bookshelf .books figure img:active {
  transform: scale(1.05);
}
/* 书名（post カードの summary と同じ text-sm） */
.bookshelf .books figure strong {
  font-size: 0.875rem;
  line-height: 1.5;
}
/* 状态徽章＋星の行（表紙の下・书名の上、中央寄せ・同一行） */
.bookshelf .books .bk-status {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

/* ===== 状态徽章 .bk-pill（首页 BASE と同じグレー角丸。文字は主题色、丸だけ色分け＋パルス） ===== */
.bk-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 8px;
  background: var(--color-muted);
  color: var(--color-foreground);
  font-size: 0.78rem;
  line-height: 1;
  white-space: nowrap;
}
/* 进度ドット（project の animate-ping を再現：核 + 広がって消える環） */
.bk-dot {
  position: relative;
  display: inline-flex;
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  --dot-color: var(--color-muted-foreground);
}
.bk-dot::before {
  content: "";
  position: relative;
  display: inline-flex;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-color);
}
.bk-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--dot-color);
  opacity: 0.75;
  animation: bk-ping 1.1s cubic-bezier(0, 0, 0.2, 1) infinite;
}
@keyframes bk-ping {
  75%,
  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}
.bk-pill--read .bk-dot {
  --dot-color: var(--color-tip);
}
.bk-pill--reading .bk-dot {
  --dot-color: var(--color-warning);
}
.bk-pill--to-read .bk-dot {
  --dot-color: var(--color-muted-foreground);
}

/* ===== 星评价 .bk-stars（rating が空なら非表示。小数対応） ===== */
.bk-stars:empty {
  display: none;
}
.stars-wrap {
  position: relative;
  display: inline-block;
  font-size: 0.85rem;
  line-height: 1;
  white-space: nowrap;
}
.stars-wrap .stars-empty {
  color: var(--color-muted-foreground);
  opacity: 0.3;
}
.stars-wrap .stars-fill {
  position: absolute;
  left: 0;
  top: 0;
  overflow: hidden;
  color: #e6a817;
}

/* ===== 书籍详情弹窗 .bk-modal（点击封面打开） ===== */
html.bk-modal-open {
  overflow: hidden;
}
.bk-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
}
.bk-modal.is-open {
  display: block;
}
.bk-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}
.bk-modal__panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 620px);
  max-height: 88vh;
  overflow: auto;
  padding: 1.75rem;
  background: var(--color-card);
  color: var(--color-foreground);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.bk-modal__close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  padding: 0;
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--color-muted-foreground);
  cursor: pointer;
}
.bk-modal__body {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
}
.bk-modal__cover {
  flex-shrink: 0;
  align-self: flex-start;
  width: 160px;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
@media (max-width: 520px) {
  .bk-modal__body {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  /* 縦並びのときは表紙を中央寄せ */
  .bk-modal__cover {
    align-self: center;
  }
}
.bk-modal__info {
  flex: 1;
  min-width: 0;
}
.bk-modal__title {
  margin: 0 0 2px;
  font-size: 1.15rem;
  font-weight: 700;
}
.bk-modal__sub,
.bk-modal__author {
  font-size: 0.85rem;
  color: var(--color-foreground);
}
.bk-modal__author {
  margin-top: 2px;
}
.bk-modal__flabel {
  color: var(--color-muted-foreground);
}
.bk-modal__flabel::after {
  content: ":";
  margin-right: 4px;
}
.bk-modal__badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}
@media (max-width: 520px) {
  .bk-modal__badges {
    justify-content: center;
  }
}
.bk-modal__review {
  margin: 0 0 1rem;
  padding: 0.9rem 1rem;
  background: var(--color-muted);
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--color-foreground);
  white-space: pre-wrap;
}
.bk-modal__review.is-empty {
  color: var(--color-muted-foreground);
  font-style: italic;
}
.bk-modal__links {
  display: flex;
  gap: 14px;
}
.bk-modal__links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--color-primary);
  text-decoration: none;
}
.bk-modal__links a:hover {
  opacity: 0.7;
}
.bk-modal__links .bk-ico {
  flex-shrink: 0;
}
