/**
 * Bookshelf 页面样式
 * 外层白框/紫框用主题的 Tailwind 类（见 _index.md）。
 * 组成：Recommended (.read)、Archive (.years)、书籍页面 (.books)、悬停书评气泡。
 * 列数在各区块的 @media (min-width: 640px) 处从「手机」切到「桌面」。
 */

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

/* 区块标题 .bs-heading 的样式已移至 _partials/section-toc.html（书架与 Playlist 共用） */

/* ===== Recommended（网格：桌面每行5个，手机每行2个） ===== */
.bookshelf .read {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem 1rem;
}
@media (min-width: 640px) {
  .bookshelf .read {
    grid-template-columns: repeat(5, 1fr);
  }
}
.bookshelf .read_item {
  width: 100%;
}
.bookshelf .read figure {
  margin: 0;
  width: 100%;
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.4;
}
.bookshelf .read figure a {
  display: block;
  text-decoration: none;
}
.bookshelf .read img {
  display: block;
  width: 100%;
  max-width: 130px;
  height: auto;
  margin: 0 auto 0.5rem;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}
/* ===== 卡片交互（Recommended .read 与书籍页面 .books 共用）=====
   逻辑：
   1) 任意卡片：hover / 点击（含触屏 tap 展开态 .tip-open）时放大
   2) 含链接（<img> 被 <a> 包裹）的卡片：额外显示紫色框（＝有链接的证明） */

/* 1) 全カード：hover / タップで拡大 */
.bookshelf .read figure img:hover,
.bookshelf .read figure img:active,
.bookshelf .read figure[data-tip].tip-open img,
.bookshelf .books figure img:hover,
.bookshelf .books figure img:active,
.bookshelf .books figure[data-tip].tip-open img {
  transform: scale(1.05);
}

/* 2) リンク付きカードのみ：紫枠を表示 */
.bookshelf .read figure a:hover img,
.bookshelf .read figure a:active img,
.bookshelf .books figure a:hover img,
.bookshelf .books figure a:active img {
  outline: 3px solid rgba(225, 190, 231, 0.8);
}

/* ===== Archive（网格：桌面每行3个，手机每行2个） ===== */
.bookshelf .years {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.75rem;
}
@media (min-width: 640px) {
  .bookshelf .years {
    grid-template-columns: repeat(3, 1fr);
  }
}
/* 整张卡片为链接（点击任意位置都可跳转） */
.bookshelf .years .years_item {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 2 / 1;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  text-decoration: none;
  transition:
    transform 0.3s ease,
    box-shadow 0.3s ease;
}
.bookshelf .years .years_item span {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 1;
  color: #fff;
  /* 与首页最近文章标题一致：text-xl = 1.25rem，bold */
  font-size: 1.25rem;
  font-weight: 700;
  text-shadow: 0 1px 4px rgb(0 0 0 / 0.4);
}
.bookshelf .years .years_item:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

/* 图片来源署名 */
.bookshelf .bs-credit {
  margin-top: 2.5rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--color-muted-foreground);
}
.bookshelf .bs-credit a {
  color: var(--color-primary);
  text-decoration: none;
}

/* ===== 书籍页面（网格：桌面每行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;
}
.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 figure img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 190px;
  margin: 2.1rem auto 0.5rem;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

/* ===== 悬停书评气泡（覆盖封面居中，0.5s 显示） ===== */
.bookshelf figure[data-tip] {
  position: relative;
}
/* タッチ端末（iOS Safari 等）では cursor:pointer が無いと figure のタップで
   click イベントが発火しないため、タッチ時のみクリック可能要素として扱う */
@media (hover: none) {
  .bookshelf figure[data-tip] {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
}
.bookshelf figure[data-tip]:hover {
  z-index: 30;
}
.bookshelf figure[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.97);
  z-index: 30;
  width: max-content;
  max-width: min(82vw, 320px);
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  background: var(--color-popover, #1f1f23);
  color: var(--color-popover-foreground, #ffffff);
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.1));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  font-size: 0.72rem;
  line-height: 1.5;
  text-align: left;
  white-space: normal;
  word-break: break-word;
  pointer-events: none;
  /* 非表示時は display:none で完全に領域を消す
     （visibility:hidden だと端のカードで画面外にはみ出し、横スクロールの原因になるため） */
  display: none;
}
/* ホバー可能な端末（PC等）: 従来どおりカーソルを乗せると表示 */
@media (hover: hover) {
  .bookshelf figure[data-tip]:hover::after {
    display: block;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* タップで開いた状態（全端末共通）:
   横方向にはみ出さないよう、カード基準ではなく画面中央に固定し、
   幅を画面幅の88%以内（最大340px）に制限する。 */
.bookshelf figure[data-tip].tip-open {
  z-index: 30;
}
.bookshelf figure[data-tip].tip-open::after {
  display: block;
  position: fixed;
  left: 50%;
  top: 50%;
  max-width: min(88vw, 340px);
  transform: translate(-50%, -50%) scale(1);
}

/* 狭い画面（ホバー可能でもウィンドウが狭い場合）:
   ホバー表示も画面中央固定にして、端のカードで横にはみ出さないようにする */
@media (max-width: 639px) {
  .bookshelf figure[data-tip]:hover::after {
    position: fixed;
    left: 50%;
    top: 50%;
    max-width: min(88vw, 340px);
    transform: translate(-50%, -50%) scale(1);
  }
}
