/*
 * カードファイル（図鑑）の見た目。バインダーを調整するときは、基本的にこのファイルだけを触ればよい。
 *
 * 実物のカードバインダーにならう：
 *   - 1ページは 3×3 の9ポケット（透明なシートを溶着で区切ったもの。上から差し込む）
 *   - 広い画面は見開き2ページ（中央にリング）、スマホは1ページ（左にリング）
 *   - 表紙は濃い藍の革風に、縁にステッチ
 * ページ送りと拡大表示の動きは app.js（renderAlbum / openZoom）。
 */

/* ---- 1. 絞り込みの札 ---- */
.bp-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.bp-filter {
  min-height: 34px;
  padding: 4px 14px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 0 0 1px var(--bp-line);
  color: var(--bp-ink);
  font-size: 0.82rem;
  font-weight: 700;
}

.bp-filter.is-active {
  background: linear-gradient(180deg, var(--bp-gold-a), var(--bp-gold-b));
  box-shadow: none;
  color: #2a1c03;
}

/* どのボックスのファイルかを示す見出し。棚で選んだ箱と同じものを指す */
.bp-album-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--bp-gold-a, #f0c650);
  font-family: var(--font-mincho);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.bp-album-box-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid currentColor;
  font-size: 0.8rem;
}

/* ---- 2. バインダー ---- */
.bp-binder {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  margin-top: 14px;
  padding: 18px 16px 18px 12px;
  border-radius: 16px;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.015) 0 2px, transparent 2px 5px),
    radial-gradient(ellipse 80% 60% at 50% 30%, #222c4d, #141a30 70%, #0d1122);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* 表紙の縁のステッチ */
.bp-binder::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px dashed rgba(214, 219, 227, 0.18);
  border-radius: 11px;
  pointer-events: none;
}

/* 横に引いてめくれる。縦のスクロールはそのまま */
.bp-binder {
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.bp-binder.is-dragging {
  cursor: grabbing;
}

/* めくっている途中は、ポケットを押しても拡大しない */
.bp-binder.is-turning .bp-pocket {
  pointer-events: none;
}

.bp-binder.is-dragging .bp-tcard.is-flat {
  transition: none;
}

.bp-binder.is-spread {
  grid-template-columns: 1fr 34px 1fr;
  padding: 22px;
}

/* リング */
.bp-binder-rings {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  padding: 24px 0;
}

.bp-binder-rings > i {
  display: block;
  width: 22px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f6f7fa, #9aa3b3 55%, #e3e7ed);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6), inset 0 -1px 0 rgba(0, 0, 0, 0.3);
}

.bp-binder.is-spread .bp-binder-rings > i {
  width: 34px;
  height: 14px;
}

/* ページ（透明のシート） */
.bp-binder-page {
  position: relative;
  /* 端のページで引いたとき：app.js が --page-x（引いた量）と --page-r（端の持ち上がり）を入れる */
  transform: perspective(1200px) translateX(var(--page-x, 0px)) rotateY(var(--page-r, 0deg));
  transition: transform var(--page-ms, 0ms) ease-out;
  padding: 12px;
  border-radius: 6px;
  background: linear-gradient(170deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.025) 40%, rgba(255, 255, 255, 0.05));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 2px 6px rgba(0, 0, 0, 0.3);
}

.bp-binder-page.is-blank {
  opacity: 0.5;
}

.bp-album {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.bp-binder-folio {
  margin: 8px 0 0;
  font-size: 0.7rem;
  color: var(--bp-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ポケット（上から差し込む透明の袋）。上の口の線と、溶着の縁 */
.bp-pocket {
  position: relative;
  padding: 4px;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03));
  box-shadow: inset 0 0 0 1px rgba(214, 219, 227, 0.22);
  perspective: 800px;
}

.bp-pocket::before {
  content: "";
  position: absolute;
  left: 6%;
  right: 6%;
  top: 3px;
  height: 1px;
  background: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

/* 透明フィルムの映り込み（カードの上にかぶる） */
.bp-pocket::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: inherit;
  background: linear-gradient(120deg, transparent 35%, rgba(255, 255, 255, 0.1) 45%, transparent 55%);
  pointer-events: none;
}

.bp-pocket .bp-tcard {
  cursor: zoom-in;
  touch-action: pan-y;
}

/* 図鑑のカードは裏返さない。3D の裏返しをやめ、表の面をそのまま置く（30枚並ぶので軽くする） */
.bp-tcard.is-flat {
  perspective: none;
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform 0.15s ease-out;
}

.bp-tcard.is-flat .bp-tcard-front {
  transform: none;
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
}

/* 図鑑では、ホロとラメは止まったまま見せる（スマホにはカーソルが無いので、乗せたときだけだと見えない）。
   指の位置に追う全体のつやだけは、乗せたカードに限る */
.bp-tcard.is-flat .bp-tcard-foil {
  opacity: 0;
}

.bp-tcard.is-flat:hover .bp-tcard-foil {
  opacity: var(--glare);
}

/* 空のポケット */
.bp-pocket.is-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  aspect-ratio: 63 / 88;
  background: rgba(255, 255, 255, 0.025);
  box-shadow: inset 0 0 0 1px rgba(214, 219, 227, 0.14);
  color: rgba(243, 240, 232, 0.5);
  text-align: center;
}

.bp-pocket-no {
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.bp-pocket-mark {
  font-size: 1.15rem;
  font-weight: 700;
}

.bp-pocket-rarity {
  padding: 0 4px;
  font-size: 0.62rem;
  line-height: 1.3;
}

/* 何も無い枠（ページの余り） */
.bp-pocket.is-void {
  aspect-ratio: 63 / 88;
  background: none;
  box-shadow: inset 0 0 0 1px rgba(214, 219, 227, 0.07);
}

.bp-pocket.is-void::before,
.bp-pocket.is-void::after {
  content: none;
}

/* ---- 2.5 ページをめくる ----
 * めくっている1枚は、リングを軸に rotateY で立ち上がって反対側へ倒れる（app.js の beginTurn）。
 * 表と裏を持つので、見開きでは裏に次の見開きの左ページが見える。
 * --turn-shade（0〜1）は紙の立ち上がり具合。紙の面と下のページに落ちる影の濃さに使う。
 */
.bp-binder {
  perspective: 1800px;
}

.bp-turn-sheet {
  position: absolute;
  z-index: 3;
  transform-style: preserve-3d;
  will-change: transform;
  pointer-events: none;
}

.bp-turn-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.bp-turn-face.is-back {
  transform: rotateY(180deg);
}

/* めくる紙は下のページが透けないよう、地を塗る。浮いている分の影も付ける */
.bp-turn-face .bp-binder-page {
  height: 100%;
  box-sizing: border-box;
  transform: none;
  background:
    linear-gradient(170deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03) 40%, rgba(255, 255, 255, 0.06)),
    #19203a;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.16),
    0 calc(var(--turn-shade, 0) * 14px) calc(var(--turn-shade, 0) * 30px) rgba(0, 0, 0, 0.55);
}

.bp-turn-face .bp-binder-page.is-blank {
  opacity: 1;
}

/* 紙が立つほど、面が光から外れて暗くなる。軸に近い側ほど暗い */
.bp-turn-face::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.1) 60%, rgba(255, 255, 255, 0.06));
  opacity: calc(var(--turn-shade, 0) * 0.9);
  pointer-events: none;
}

.bp-turn-face.is-back::after {
  background: linear-gradient(270deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.1) 60%, rgba(255, 255, 255, 0.06));
}

/* 下のページには、立ち上がった紙の影が落ちる */
.bp-binder.is-turning > .bp-binder-page::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: radial-gradient(ellipse 70% 90% at 50% 50%, rgba(0, 0, 0, 0.5), transparent 75%);
  opacity: calc(var(--turn-shade, 0) * 0.7);
  pointer-events: none;
}

/* ---- 3. ページ送り ---- */
.bp-binder-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 14px;
}

.bp-page-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(214, 219, 227, 0.4);
  font-size: 1.1rem;
}

.bp-page-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.bp-page-label {
  min-width: 90px;
  font-size: 0.85rem;
  color: var(--bp-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---- 4. 拡大表示 ---- */
.bp-zoom {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 16px;
  background:
    radial-gradient(ellipse 60% 50% at 50% 45%, rgba(40, 52, 96, 0.55), transparent 70%),
    rgba(5, 7, 14, 0.92);
}

.bp-zoom-card {
  width: min(78vw, 330px);
  perspective: 1000px;
}

/* 拡大表示のカードは、つかんで回せる（app.js の onZoomPointerDown）。
   つかんでいる間は指にぴったりついてくるよう遅れなし、離したらばねのように正面へ戻る */
.bp-zoom-card .bp-tcard {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.bp-zoom-card .bp-tcard.is-grabbed {
  cursor: grabbing;
  transition: none;
}

.bp-zoom-card .bp-tcard.is-settling {
  transition: transform 0.6s cubic-bezier(0.2, 1.5, 0.4, 1);
}

.bp-zoom-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--bp-muted);
}

/* 閉じるボタンと「動くカードで読む」を横に並べる */
.bp-zoom-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

/* 図鑑：動くカード・4コマ漫画があるカードの印（ポケットの左上に並べる） */
.bp-pocket-marks {
  position: absolute;
  top: 1px;
  left: 1px;
  z-index: 4;
  display: flex;
  gap: 2px;
  pointer-events: none;
}

.bp-pocket-mark-x {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--bp-gold-a), var(--bp-gold-b) 60%, var(--bp-gold-c));
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  color: #3a2806;
  font-family: var(--font-mincho);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

/* PC：拡大表示は、左に大きなカード、右に物語を並べる */
@media (min-width: 900px) and (min-height: 640px) {
  .bp-zoom {
    display: grid;
    grid-template-columns: auto minmax(0, 30em);
    grid-template-rows: 1fr auto auto auto 1fr;
    grid-template-areas:
      "card ."
      "card story"
      "card hint"
      "card close"
      "card .";
    align-items: start;
    justify-content: center;
    column-gap: 56px;
    row-gap: 18px;
    padding: 32px;
  }

  .bp-zoom-card {
    grid-area: card;
    align-self: center;
    width: min(57vh, 460px, 40vw); /* カードの高さが画面の約8割に収まる幅 */
  }

  .bp-zoom .bp-story {
    grid-area: story;
    width: auto;
    max-height: 60vh;
    margin: 0;
    font-size: 1.05rem;
  }

  .bp-zoom-hint {
    grid-area: hint;
  }

  .bp-zoom-actions {
    grid-area: close;
    justify-content: flex-start;
  }
}
