/* Photobook-style flipbook viewer — layer only, no layout engine. */

.fb-root {
  position: fixed;
  inset: 0;
  z-index: 100200;
  display: flex;
  flex-direction: column;
  background: radial-gradient(120% 80% at 50% 0%, #1a1c24 0%, #0a0a0c 100%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #e8e4db;
  touch-action: none;
}

.fb-root[hidden] {
  display: none !important;
}

.fb-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(32, 34, 42, 0.95) 0%, rgba(20, 22, 28, 0.98) 100%);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.fb-title {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #b8b3a6;
}

.fb-meta {
  font-size: 13px;
  color: #8a8579;
  font-variant-numeric: tabular-nums;
}

.fb-close {
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: #f0ebe2;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.fb-close:hover {
  background: rgba(255, 255, 255, 0.12);
}

.fb-hint {
  font-size: 12px;
  color: #6d6860;
  padding: 0 16px 6px 16px;
}

.fb-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px 20px 12px;
  perspective: 3000px;
  perspective-origin: 50% 46%;
}

.fb-stage {
  position: relative;
  width: min(100%, 100vw - 32px, 1200px);
  height: min(100%, 85vh, 800px);
  max-height: 85vh;
  border-radius: 2px;
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.25),
    0 24px 64px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.07) inset;
  transform-style: preserve-3d;
}
.fb-stage::before {
  content: "";
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  margin-left: -0.5px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.2), rgba(200, 190, 170, 0.35) 20%, rgba(0, 0, 0, 0.45) 50%, rgba(200, 190, 170, 0.35) 80%, rgba(0, 0, 0, 0.2));
  pointer-events: none;
  opacity: 0.65;
  mix-blend-mode: multiply;
}

.fb-paper {
  position: absolute;
  inset: 0;
  border-radius: 2px;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
}

.fb-paper img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #111;
  pointer-events: none;
  user-select: none;
}

/* Underlying spread (peeks as top sheet lifts) */
.fb-paper--under {
  z-index: 1;
  transition: transform 0.12s ease;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.35) inset, 0 0 0 1px rgba(0, 0, 0, 0.25) inset;
}

/* Turning leaf — hinge on the spine (center) to mimic opening the next pair */
.fb-paper--turn {
  z-index: 2;
  transform-origin: 50% 50% 0;
  will-change: transform, box-shadow, filter;
  --fb-curl: 0;
  box-shadow:
    -4px 0 28px rgba(0, 0, 0, 0.5),
    -1px 0 0 rgba(255, 255, 255, 0.08) inset,
    0 12px 40px rgba(0, 0, 0, 0.4);
  filter: drop-shadow(-6px 4px 12px rgba(0, 0, 0, 0.35));
}

/* Paper curl / spine shadow — read by --fb-curl (0..1) from JS for page-turn feel */
.fb-paper--turn::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(
    100deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.1) 18%,
    rgba(0, 0, 0, 0.32) 50%,
    rgba(0, 0, 0, 0.1) 82%,
    rgba(255, 255, 255, 0) 100%
  );
  opacity: calc(0.12 + var(--fb-curl) * 0.82);
  mix-blend-mode: multiply;
  transition: opacity 0.05s ease;
}

/* Edge grab zones: drag to turn */
.fb-edge {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 4;
  width: 20%;
  cursor: ew-resize;
}

.fb-edge--next {
  right: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04));
}

.fb-edge--prev {
  left: 0;
  background: linear-gradient(270deg, transparent, rgba(255, 255, 255, 0.04));
}

/* Corners: grab / curl from spine-adjacent corners (sits above edges) */
.fb-corner {
  position: absolute;
  z-index: 6;
  width: 22%;
  height: 30%;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  border-radius: 2px;
}
.fb-corner--tr {
  right: 0;
  top: 0;
  background: radial-gradient(100% 100% at 100% 0%, rgba(255, 255, 255, 0.1), transparent 65%);
}
.fb-corner--bl {
  left: 0;
  bottom: 0;
  background: radial-gradient(100% 100% at 0% 100%, rgba(255, 255, 255, 0.1), transparent 65%);
}

.fb-edge::after {
  content: "";
  position: absolute;
  top: 16%;
  bottom: 16%;
  width: 2px;
  background: linear-gradient(180deg, rgba(200, 190, 170, 0.15), rgba(200, 190, 170, 0.4));
  border-radius: 1px;
  opacity: 0.45;
  pointer-events: none;
}

.fb-edge--next::after {
  right: 12px;
  left: auto;
}
.fb-edge--prev::after {
  left: 12px;
  right: auto;
}

/* Nav chips */
.fb-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 8px 0 4px 0;
}

.fb-nav button {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: #e8e4db;
  border-radius: 999px;
  min-width: 40px;
  min-height: 40px;
  font-size: 16px;
  cursor: pointer;
  font-weight: 700;
}

.fb-nav button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.fb-nav button:disabled {
  opacity: 0.25;
  cursor: default;
}

@media (max-width: 600px) {
  .fb-edge { width: 22%; }
}
