/* ============================================================
   FlippablePDF — front-end styles
   Scoped under .fp-container and .flippdf-embed
   ============================================================ */

.flippdf-embed {
  width: 100%;
  min-height: 480px;
  background:
    radial-gradient(ellipse at top, rgba(212, 168, 90, 0.04), transparent 60%),
    rgba(0, 0, 0, 0.85);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.flippdf-embed.alignwide,
.flippdf-embed.alignfull {
  border-radius: 0;
}

.fp-container {
  --fp-bg: #0e0c08;
  --fp-page-bg: #f7f1e3;
  --fp-page-edge: #d9cfb8;
  --fp-spine: rgba(0, 0, 0, 0.55);
  --fp-shadow: rgba(0, 0, 0, 0.45);
  --fp-accent: #d4a85a;
  --fp-accent-soft: rgba(212, 168, 90, 0.18);
  --fp-text: #f5efe1;
  --fp-text-dim: rgba(245, 239, 225, 0.55);
  --fp-control-bg: rgba(255, 255, 255, 0.03);
  --fp-control-bg-hover: rgba(212, 168, 90, 0.1);
  --fp-control-border: rgba(245, 239, 225, 0.08);
  --fp-flip-duration: 1100ms;
  --fp-flip-easing: cubic-bezier(0.45, 0.05, 0.55, 0.95);

  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--fp-text);
}

.fp-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1700px;
  perspective-origin: 50% 38%;
  overflow: hidden;
  padding: 24px;
}

.fp-book-wrapper { position: relative; transform-style: preserve-3d; }

.fp-book {
  position: relative;
  transform-style: preserve-3d;
  background: linear-gradient(135deg, #2a2418 0%, #1a160e 100%);
  border-radius: 2px;
  filter: drop-shadow(0 25px 50px rgba(0, 0, 0, 0.55))
          drop-shadow(0 8px 16px rgba(0, 0, 0, 0.35));
  cursor: pointer;
}

.fp-spine {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 28px;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 999;
  background: linear-gradient(to right,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.05) 30%,
    rgba(0, 0, 0, 0.55) 50%,
    rgba(0, 0, 0, 0.05) 70%,
    rgba(0, 0, 0, 0) 100%);
}
.fp-mode-single .fp-spine { display: none; }

.fp-leaves {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.fp-mode-double .fp-leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform var(--fp-flip-duration) var(--fp-flip-easing);
  will-change: transform;
}

.fp-mode-single .fp-leaf {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform var(--fp-flip-duration) var(--fp-flip-easing);
  will-change: transform;
}

.fp-leaf.fp-flipped { transform: rotateY(-180deg); }

.fp-leaf-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--fp-page-bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  /* GPU layer — prevents backface-visibility flicker in Chrome */
  transform: translateZ(0);
}

.fp-leaf-front {
  box-shadow: inset 14px 0 22px -16px rgba(0, 0, 0, 0.4);
}

.fp-leaf-back {
  /* +1px translateZ keeps the back face in front of the front face
     at the rotateY(-180) end state — no z-fighting flash */
  transform: rotateY(180deg) translateZ(1px);
  box-shadow: inset -14px 0 22px -16px rgba(0, 0, 0, 0.4);
}

.fp-mode-single .fp-leaf-front,
.fp-mode-single .fp-leaf-back {
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
}

.fp-leaf-blank {
  background: radial-gradient(ellipse at center, var(--fp-page-bg) 0%, var(--fp-page-edge) 130%);
}

.fp-leaf-face::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 25% 15%, rgba(120, 90, 40, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 75% 85%, rgba(120, 90, 40, 0.04) 0%, transparent 40%);
  pointer-events: none;
  z-index: 2;
}

/* per-face sweep shadow during flip — sells the 3D rotation */
.fp-leaf-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
}
.fp-leaf-front::after {
  background: linear-gradient(to right,
    rgba(0, 0, 0, 0)    0%,
    rgba(0, 0, 0, 0)   38%,
    rgba(0, 0, 0, 0.55) 100%);
}
.fp-leaf-back::after {
  background: linear-gradient(to left,
    rgba(0, 0, 0, 0)    0%,
    rgba(0, 0, 0, 0)   38%,
    rgba(0, 0, 0, 0.55) 100%);
}
.fp-leaf.fp-flipping .fp-leaf-face::after {
  animation: fp-edge-shade var(--fp-flip-duration) var(--fp-flip-easing) forwards;
}
@keyframes fp-edge-shade {
  0%   { opacity: 0; }
  45%  { opacity: 1; }
  55%  { opacity: 1; }
  100% { opacity: 0; }
}

/* lifted shadow on the flipping leaf
   NOTE: filter:drop-shadow breaks transform-style:preserve-3d in Chrome and
   causes backface-visibility to fail mid-flip (showing the wrong page for a
   frame). The depth feel comes from the gradient overlays and hinge shadow. */

/* hinge shadow at the spine during flip (double mode) */
.fp-mode-double .fp-leaves::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: calc(50% - 14px);
  width: 28px;
  pointer-events: none;
  z-index: 998;
  opacity: 0;
  background: radial-gradient(ellipse at center,
    rgba(0,0,0,0.55) 0%,
    rgba(0,0,0,0)    70%);
  transition: opacity 0.15s;
}
.fp-mode-double .fp-leaves.fp-is-flipping::before { opacity: 1; }

.fp-page-canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

.fp-page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.fp-spinner, .fp-spinner-sm {
  width: 44px;
  height: 44px;
  border: 2px solid rgba(212, 168, 90, 0.18);
  border-top-color: var(--fp-accent);
  border-radius: 50%;
  animation: fp-spin 0.85s linear infinite;
}
.fp-spinner-sm { width: 24px; height: 24px; border-width: 2px; }
@keyframes fp-spin { to { transform: rotate(360deg); } }

.fp-loading-overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(14, 12, 8, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
}
.fp-loading-text {
  font-style: italic;
  font-size: 14px;
  letter-spacing: 0.4px;
  color: var(--fp-text-dim);
}

.fp-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--fp-text-dim);
  pointer-events: none;
}
.fp-empty-icon { width: 56px; height: 56px; opacity: 0.4; }
.fp-empty-text { font-style: italic; font-size: 14px; letter-spacing: 0.5px; }

.fp-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 20px;
  background: rgba(14, 12, 8, 0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--fp-control-border);
}

.fp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--fp-control-border);
  background: var(--fp-control-bg);
  color: var(--fp-text);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}
.fp-btn:hover:not(:disabled) {
  background: var(--fp-control-bg-hover);
  border-color: var(--fp-accent);
  color: var(--fp-accent);
  transform: translateY(-1px);
}
.fp-btn:active:not(:disabled) { transform: translateY(0); }
.fp-btn:disabled { opacity: 0.25; cursor: not-allowed; }

.fp-page-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 42px;
  background: var(--fp-control-bg);
  border: 1px solid var(--fp-control-border);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--fp-text);
  font-variant-numeric: tabular-nums;
  min-width: 110px;
  justify-content: center;
}
.fp-page-input {
  width: 36px;
  background: transparent;
  border: none;
  color: var(--fp-accent);
  font-family: inherit;
  font-size: 13px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding: 0;
}
.fp-page-input:focus { outline: none; }
.fp-page-input::-webkit-inner-spin-button,
.fp-page-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.fp-page-input { -moz-appearance: textfield; }
.fp-page-divider { opacity: 0.3; }
.fp-page-total { opacity: 0.6; }

.fp-book::before, .fp-book::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 998;
}
.fp-book::before { left: 0;  background: linear-gradient(to right, rgba(212, 168, 90, 0.08), transparent); }
.fp-book::after  { right: 0; background: linear-gradient(to left,  rgba(212, 168, 90, 0.08), transparent); }
.fp-book:hover::before, .fp-book:hover::after { opacity: 1; }

.fp-fullscreen-active {
  background: var(--fp-bg);
  height: 100vh !important;
  border-radius: 0;
}

@media (max-width: 768px) {
  .fp-controls { padding: 12px; gap: 8px; }
  .fp-btn { width: 38px; height: 38px; }
  .fp-page-info { padding: 0 12px; height: 38px; min-width: 90px; font-size: 12px; }
}

.flippdf-error {
  background: rgba(195, 51, 51, 0.05);
}
