.fb {
  --fb-page-ratio: 0.625;
  --fb-ease: cubic-bezier(.22, .61, .36, 1);
  margin: 0 auto;
  width: 100%;
  max-width: 940px;
}

.fb-stage {
  position: relative;
  perspective: 2200px;
  perspective-origin: 50% 46%;
  margin: 0 auto;
  touch-action: pan-y;
  cursor: grab;
}
.fb-stage.is-grabbing { cursor: grabbing; }
.fb-stage.is-grabbing * { cursor: grabbing; }

.fb-book {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 620ms var(--fb-ease);
}
.fb-book.is-live, .fb-stack.is-live, .fb-edges.is-live { transition: none; }

.fb-sheet {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 620ms var(--fb-ease);
  will-change: transform;
}

.fb-sheet.is-live { transition: none; }
.fb-sheet.is-flipped { transform: rotateY(-180deg); }

.fb-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background: var(--surface);
  border-radius: 2px 5px 5px 2px;
}
.fb-face--back { transform: rotateY(180deg); border-radius: 5px 2px 2px 5px; }

.fb-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.fb-gutter {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
}
.fb-face--front .fb-gutter {
  background: linear-gradient(to right,
    rgba(60,40,25,.22) 0%, rgba(60,40,25,.07) 4%, rgba(0,0,0,0) 11%);
}
.fb-face--back .fb-gutter {
  background: linear-gradient(to left,
    rgba(60,40,25,.22) 0%, rgba(60,40,25,.07) 4%, rgba(0,0,0,0) 11%);
}

.fb-curl {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  opacity: var(--fb-lift, 0);
}
.fb-face--front .fb-curl {
  background:
    linear-gradient(100deg,
      rgba(255,255,255,.34) 0%,
      rgba(255,255,255,.06) 16%,
      rgba(0,0,0,0) 34%,
      rgba(40,26,14,.20) 74%,
      rgba(40,26,14,.42) 100%);
}
.fb-face--back .fb-curl {
  background:
    linear-gradient(260deg,
      rgba(255,255,255,.30) 0%,
      rgba(255,255,255,.05) 18%,
      rgba(0,0,0,0) 36%,
      rgba(40,26,14,.22) 76%,
      rgba(40,26,14,.46) 100%);
}

.fb-strips {
  position: absolute;
  inset: 0;
  display: none;
  transform-style: preserve-3d;
}
.fb-face.is-curled > img { visibility: hidden; }
.fb-face.is-curled .fb-strips { display: block; }

.fb-strip {
  position: absolute;
  top: 0;
  height: 100%;
  transform-origin: left center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background-repeat: no-repeat;
  will-change: transform;
}

.fb-cast {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  pointer-events: none;
  z-index: 30;
  opacity: 0;
  border-radius: 5px;
}
.fb-cast--left { left: 0; background: linear-gradient(to left, rgba(35,22,12,.34), rgba(0,0,0,0) 62%); }
.fb-cast--right { left: 50%; background: linear-gradient(to right, rgba(35,22,12,.34), rgba(0,0,0,0) 62%); }

.fb-stack {
  transition: transform 620ms var(--fb-ease);
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  border-radius: 5px 2px 2px 5px;
}
.fb-stack img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.fb-stack::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to left,
    rgba(60,40,25,.22) 0%, rgba(60,40,25,.07) 4%, rgba(0,0,0,0) 11%);
  pointer-events: none;
}

.fb-edges {
  transition: transform 620ms var(--fb-ease);
  position: absolute;
  top: 1.5%;
  bottom: 1.5%;
  width: 7px;
  pointer-events: none;
  border-radius: 2px;
  background: repeating-linear-gradient(to right,
    rgba(0,0,0,.11) 0 1px, rgba(255,255,255,.55) 1px 2.5px);
}
.fb-edges--right { right: -6px; }
.fb-edges--left { left: -6px; }

.fb-shadow {
  position: absolute;
  left: 3%;
  right: 3%;
  bottom: -20px;
  height: 38px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.32), rgba(0,0,0,0) 70%);
  pointer-events: none;
}

.fb[data-mode="single"] .fb-sheet,
.fb[data-mode="single"] .fb-stack,
.fb[data-mode="single"] .fb-edges,
.fb[data-mode="single"] .fb-cast { display: none; }

.fb-single {
  display: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--r-sm);
}
.fb[data-mode="single"] .fb-single { display: block; }
.fb-single img {
  width: 100%; height: 100%; object-fit: contain; display: block;
  background: var(--surface);
  user-select: none; -webkit-user-drag: none; pointer-events: none;
  will-change: transform;
}

.fb-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  margin-top: var(--sp-8);
  flex-wrap: wrap;
}
.fb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-pill);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--fs-md);
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast), opacity var(--dur-fast);
}
.fb-btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--ink-faint); }
.fb-btn:disabled { opacity: .38; cursor: default; }
.fb-btn--primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--on-accent);
}
.fb-btn--primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }

.fb-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: var(--fs-md);
  color: var(--ink-soft);
  min-width: 9ch;
  text-align: center;
}

.fb-hint {
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  margin-top: var(--sp-3);
  font-weight: 600;
}

.fb:fullscreen,
.fb:-webkit-full-screen {
  max-width: none;
  width: 100%;
  height: 100%;
  background: var(--ink-panel);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--sp-6);
}
.fb:fullscreen .fb-count, .fb:fullscreen .fb-hint { color: var(--on-panel-soft); }
.fb:fullscreen .fb-btn {
  background: var(--ink-panel-2);
  border-color: var(--ink-panel-3);
  color: var(--on-panel);
}
.fb:fullscreen .fb-btn--primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--on-accent);
}

.fb-fallback { text-align: center; }
.fb-fallback img {
  max-width: 320px; width: 100%; height: auto;
  border-radius: var(--r-lg); border: 1px solid var(--border);
}
.fb[data-ready="1"] .fb-fallback { display: none; }
.fb:not([data-ready="1"]) .fb-stage,
.fb:not([data-ready="1"]) .fb-controls,
.fb:not([data-ready="1"]) .fb-hint { display: none; }

@media (prefers-reduced-motion: reduce) {
  .fb-book, .fb-sheet { transition-duration: 1ms; }
  .fb-curl, .fb-cast { display: none; }
}
