/* book3d.css — 모듈 D: 손에 든 3D 책 (inspect 단계) 스타일.
 * 6면 preserve-3d 박스. 면의 크기/3D transform은 book3d.js가 인라인으로 넣고
 * (책마다 pageW/pageH/depth가 다르다), 여기서는 표면 질감·그림자·캡션만 정의한다.
 * 색/시간/이징은 tokens.css 변수만 사용, 애니메이션은 transform/opacity만. */

/* ---------- 장면 (오버레이 안, 화면 전체) ---------- */

.fb-b3d-scene {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1800px;
  pointer-events: none; /* 배경 클릭은 오버레이가 받는다 */
  transition: opacity 160ms ease;
}

.fb-b3d-scene.is-hidden {
  opacity: 0;
}

/* ---------- 책 박스 ---------- */

.fb-b3d {
  position: relative;
  transform-style: preserve-3d;
  pointer-events: auto;
  touch-action: none;
  will-change: transform;
}

.fb-b3d.is-grabbable {
  cursor: grab;
}

.fb-b3d.is-dragging {
  cursor: grabbing;
}

/* 그립 스쿼시 — 쥐면 무게에 눌리듯 살짝 잦아들고, 놓으면 쫀득하게 복원 */
.fb-b3d-core {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 200ms var(--ease-pop);
}

.fb-b3d.is-dragging .fb-b3d-core {
  transform: scale(0.982);
  transition-duration: 120ms;
  transition-timing-function: var(--ease-settle);
}

/* 모든 면: 박스 중앙 기준 (margin 음수 오프셋은 JS가 크기와 함께 지정) */
.fb-b3d-face {
  position: absolute;
  left: 50%;
  top: 50%;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* 면 콘텐츠(표지 이미지/폴백/보드)는 면을 꽉 채운다 */
.fb-b3d-face > * {
  width: 100%;
  height: 100%;
}

.fb-b3d-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--page-cream);
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

/* 표지 보드: 모서리 라운드 + 은은한 보드 림 */
.fb-b3d-face--front {
  border-radius: 2px 4px 4px 2px;
  box-shadow: inset 0 0 0 1px rgba(40, 30, 18, 0.08);
}

.fb-b3d-face--back {
  border-radius: 2px 4px 4px 2px; /* 뒤집힌 면이라 좌우가 front와 대칭이 된다 */
  box-shadow: inset 0 0 0 1px rgba(40, 30, 18, 0.08);
}

/* 표지 위 원기둥 라이팅 — 회전할 때 입체감을 살린다 */
.fb-b3d-face--front::after,
.fb-b3d-face--back::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    to right,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0) 24%,
    rgba(40, 30, 18, 0) 78%,
    rgba(40, 30, 18, 0.1)
  );
}

/* 뒤표지 폴백 보드 */
.fb-b3d-board {
  width: 100%;
  height: 100%;
  background-image: linear-gradient(
    to right,
    color-mix(in srgb, var(--paper) 20%, transparent),
    transparent 40%,
    color-mix(in srgb, var(--ink) 10%, transparent)
  );
}

/* ---------- 책등 (생성형: 세로쓰기 제목/저자) ---------- */

.fb-b3d-face--spine {
  box-shadow: inset 0 0 0 1px rgba(40, 30, 18, 0.1);
}

.fb-b3d-spine-gen {
  width: 100%;
  height: 100%;
  writing-mode: vertical-rl;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8% 0;
  overflow: hidden;
  background-image: linear-gradient(
    to right,
    color-mix(in srgb, var(--paper) 26%, transparent),
    transparent 38%,
    color-mix(in srgb, var(--ink) 12%, transparent)
  );
}

.fb-b3d-spine-title,
.fb-b3d-spine-author {
  display: block;
  min-height: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fb-b3d-spine-title {
  font-family: var(--font-title);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.fb-b3d-spine-author {
  font-size: 0.68em;
  letter-spacing: 0.02em;
  opacity: 0.78;
}

/* ---------- 종이 단면 (배면 · 천 · 지) ---------- */

/* 배면(fore-edge): 페이지 결이 세로로 선다 → 두께 방향(가로)으로 줄무늬 */
.fb-b3d-face--edge.is-fore {
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.32) 0 1px,
      rgba(255, 255, 255, 0) 1px 2.5px
    ),
    linear-gradient(90deg, #e9ddc9, #d9c9b1);
}

/* 천(top)/지(bottom): 페이지 결이 가로로 눕는다 → 두께 방향(세로)으로 줄무늬 */
.fb-b3d-face--edge.is-top {
  background:
    repeating-linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.32) 0 1px,
      rgba(255, 255, 255, 0) 1px 2.5px
    ),
    linear-gradient(180deg, #efe4d2, #ddceb6);
}

.fb-b3d-face--edge.is-bottom {
  background:
    repeating-linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.28) 0 1px,
      rgba(255, 255, 255, 0) 1px 2.5px
    ),
    linear-gradient(180deg, #d9c9b1, #cbbaa0);
}

/* ---------- 바닥 그림자 · 캡션 ---------- */

.fb-b3d-shadow {
  position: absolute;
  left: 50%;
  height: 26px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(40, 30, 18, 0.28), rgba(40, 30, 18, 0));
  filter: blur(6px);
  opacity: 1;
  transition: opacity 320ms ease;
}

.fb-b3d-caption {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  opacity: 1;
  transition: opacity 320ms ease;
}

.fb-b3d-caption-title {
  font-family: var(--font-title);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.fb-b3d-caption-meta {
  margin-top: 5px;
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* 진입/핸드오프 동안 그림자·캡션 숨김 */
.fb-b3d-shadow.is-quiet,
.fb-b3d-caption.is-quiet {
  opacity: 0;
}

/* ---------- 모션 최소화 환경 ---------- */

@media (prefers-reduced-motion: reduce) {
  .fb-b3d-scene,
  .fb-b3d,
  .fb-b3d-shadow,
  .fb-b3d-caption {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
  }
}
