/* ベースレイアウト */
.diary.container {
  max-width: 860px;
  margin: 48px auto 80px;
  padding: 0 20px;
}

/* 戻るボタン */
.back-to-home {
  display: inline-block;
  margin-bottom: 20px;
  padding: 8px 16px;
  color: #5a4a3a;
  text-decoration: none;
  font-size: 14px;
  border: 1px solid #d4c4a8;
  border-radius: 4px;
  background: #faf6f0;
  transition: background 0.2s, color 0.2s;
}
.back-to-home:hover {
  background: #f0e8d8;
  color: #3a2a1a;
}

/* ヘッダー */
.diary-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
  margin-bottom: 20px;
}
.diary-header h1 {
  font-size: clamp(24px, 2.4vw, 36px);
  margin: 0;
}
.diary-filter {
  margin-left: auto;
  background: var(--dl-surface, rgba(127,127,255,0.06));
  border: 1px solid rgba(0,0,0,0.08);
  padding: 10px 12px;
  border-radius: 10px;
}
.diary-filter label {
  font-size: 13px;
  opacity: .8;
  margin-right: 8px;
}
.diary-filter select {
  font: inherit;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.15);
  background: var(--dl-bg, #fff);
}

/* リスト → カード化 */
.diary-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.diary-card {
  margin: 0;
}
.diary-link {
  display: block;
  padding: 16px 18px;
  border-radius: 14px;
  text-decoration: none;
  background: var(--dl-card, #fff);
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
  transition: transform .06s ease, box-shadow .12s ease, border-color .12s ease;
  color: inherit;
}
.diary-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.15);
}

/* メタ情報 */
.diary-card-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 12px;
  opacity: .8;
  margin-bottom: 6px;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 999px;
  background: rgba(100, 120, 255, 0.15);
  border: 1px solid rgba(100, 120, 255, 0.35);
}

/* タイトル・抜粋 */
.diary-card-title {
  font-size: clamp(16px, 1.7vw, 20px);
  line-height: 1.35;
  margin: 4px 0 8px;
}
.diary-card-excerpt {
  margin: 0;
  line-height: 1.7;
  color: rgba(0,0,0,0.74);
}

/* ダークモード（背景が暗いサイト想定） */
@media (prefers-color-scheme: dark) {
  .diary-filter {
    background: rgba(255,255,255,0.04);
    border-color: rgba(255,255,255,0.12);
  }
  .diary-filter select {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.2);
    color: #fff;
  }
  .diary-link {
    background: rgba(255,255,255,0.03);
    border-color: rgba(255,255,255,0.10);
    box-shadow: none;
  }
  .diary-link:hover {
    box-shadow: 0 6px 18px rgba(0,0,0,0.5);
    border-color: rgba(255,255,255,0.18);
  }
  .diary-card-excerpt {
    color: rgba(255,255,255,0.78);
  }
  .badge {
    background: rgba(120, 160, 255, 0.15);
    border-color: rgba(120, 160, 255, 0.45);
    color: #dbe6ff;
  }
}

/* モバイル微調整 */
@media (max-width: 640px) {
  .diary.container { margin-top: 36px; }
  .diary-link { padding: 14px 14px; }
}
/* ===== 3D Book Shelf（最終版：中央バランス＋モバイル最適） ===== */
.book-shelf {
  position: relative;
  max-width: none;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);

  /* 空気感とバランス */
  margin-top: 48px;
  margin-bottom: 64px;
  padding-block: 36px 48px;
  padding-inline: clamp(64px, 10vw, 120px);

  --book-h: 240px;
  --gap: 22px;

  perspective: 900px;
  -webkit-perspective: 900px;
  perspective-origin: 50% 30%;
  background: linear-gradient(180deg, #fbf8f4 0%, #f7f3ee 100%);
  border-radius: 12px;
  box-shadow: inset 0 -18px 32px rgba(0, 0, 0, 0.03);
}

/* 固定棚装飾は削除 */
.book-shelf::before,
.book-shelf::after {
  content: none;
}
.book-shelf .shelf-backdrop {
  display: none;
}

/* グリッド構成 */
.shelf-rail {
  position: relative;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  justify-content: center; /* 中央寄せ */
  align-items: end;
  gap: var(--gap);
  overflow: visible;
  padding: 6px 0 0;

  background: repeating-linear-gradient(
    to bottom,
    transparent 0 calc(var(--book-h) + var(--gap) - 10px),
    rgba(185, 146, 99, 0.25)
      calc(var(--book-h) + var(--gap) - 10px)
      calc(var(--book-h) + var(--gap) + 10px),
    transparent calc(var(--book-h) + var(--gap) + 10px)
      calc(var(--book-h) + var(--gap) + 11px)
  );
}

/* 各本カード */
.book {
  position: relative;
  display: block;
  width: 100%;
  max-width: 180px;
  height: 230px;
  box-sizing: border-box;
  cursor: pointer;

  transform-origin: center bottom;
  transform: translateZ(0) rotateY(-10deg);
  -webkit-transform: translateZ(0) rotateY(-10deg);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;

  transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.2, 1),
    filter 0.18s ease;
  will-change: transform;

  box-shadow: 4px 10px 20px rgba(0, 0, 0, 0.1),
    inset 0 2px 6px rgba(255, 255, 255, 0.02);
  z-index: 22;
  min-width: 0;
}

/* hover動作 */
.book:hover,
.book.active {
  transform: translateZ(60px) rotateX(-10deg) rotateY(0deg) scale(1.04);
  -webkit-transform: translateZ(60px) rotateX(-10deg) rotateY(0deg)
    scale(1.04);
  box-shadow: 10px 28px 44px rgba(0, 0, 0, 0.25),
    0 4px 14px rgba(0, 0, 0, 0.08);
  z-index: 80;
  filter: none;
}

/* 背表紙 */
.book-spine {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.05),
      rgba(0, 0, 0, 0.04)
    ),
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.02) 0 2px,
      transparent 2px 6px
    ),
    linear-gradient(180deg, #b88f63 0%, #d6b98f 40%, #b78f61 100%);
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: inset 0 6px 20px rgba(0, 0, 0, 0.12),
    0 6px 12px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  z-index: 24;
}
.book-spine .spine-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.03),
      rgba(255, 255, 255, 0)
    ),
    repeating-linear-gradient(
      135deg,
      rgba(0, 0, 0, 0.01) 0 2px,
      rgba(255, 255, 255, 0) 2px 6px
    );
  mix-blend-mode: overlay;
  opacity: 0.55;
  z-index: 26;
}
.book-spine::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 8%;
  bottom: 8%;
  width: 14px;
  border-radius: 6px;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.06),
    rgba(255, 255, 255, 0.03)
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  z-index: 28;
  opacity: 0.55;
  transform: skewY(-2deg);
}
.book-spine .spine-band {
  position: absolute;
  left: 12%;
  right: 12%;
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(90deg, #e0b14a 0%, #f7d884 40%, #e0b14a 100%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12),
    inset 0 1px rgba(255, 255, 255, 0.6);
  z-index: 30;
  opacity: 0.98;
  transform: translateZ(2px);
}
.book-spine .spine-band.top {
  top: 26%;
  width: 68%;
  margin: 0 auto;
}
.book-spine .spine-band.bottom {
  top: 62%;
  width: 56%;
  margin: 0 auto;
}

/* 小口 */
.book::after {
  content: "";
  position: absolute;
  left: 100%;
  top: 0;
  width: 14px;
  height: 100%;
  transform: rotateY(90deg) translateZ(1px);
  transform-origin: left;
  background: linear-gradient(180deg, #e6d8c2 0 3px, #d1bfa3 3px 6px);
  border-right: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 2px;
  z-index: 20;
  box-shadow: 2px 6px 18px rgba(0, 0, 0, 0.08);
}

/* === 縦書きタイトル（名前）＋ 文字数で自動縮小 === */
.book-title {
  position: absolute;
  inset: 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  color: #111;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: normal;
  line-height: 1.1;
  z-index: 40;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.book-title .label {
  display: inline-block;
  font-size: clamp(12px, 2vw, 18px);
  letter-spacing: 0.08em;
  max-height: 100%;
  max-width: 100%;
  word-break: break-all;
  transform-origin: center;
  transition: font-size 0.2s ease;
}
.book-title .label[data-length="6"],
.book-title .label[data-length="7"] {
  font-size: clamp(10px, 1.8vw, 16px);
}
.book-title .label[data-length="8"],
.book-title .label[data-length="9"] {
  font-size: clamp(9px, 1.6vw, 14px);
}
.book-title .label[data-length="10"],
.book-title .label[data-length="11"],
.book-title .label[data-length="12"] {
  font-size: clamp(8px, 1.4vw, 12px);
}
.book:hover .book-title .label {
  color: #000;
  filter: brightness(1.1);
}

/* ===== レスポンシブ最適化 ===== */
@media (max-width: 900px) {
  .book-shelf {
    --book-h: 210px;
    --gap: 18px;
    padding-inline: clamp(40px, 9vw, 80px);
  }
  .shelf-rail {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--gap);
  }
}

@media (max-width: 640px) {
  .book-shelf {
    --book-h: 190px;
    --gap: 16px;
    padding-inline: clamp(24px, 10vw, 72px);
  }
  .shelf-rail {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: var(--gap);
  }
  .book {
    height: var(--book-h);
    max-width: none;
  }
  .book-title .label {
    font-size: clamp(11px, 3.2vw, 16px);
  }
}

@media (max-width: 480px) {
  .book-shelf {
    --book-h: 178px;
    --gap: 16px;
    padding-inline: clamp(20px, 12vw, 56px);
  }
  .shelf-rail {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    justify-content: center;
  }
  .book-title .label {
    font-size: clamp(10px, 3.6vw, 15px);
  }
}
