:root {
  --bg-main: #101218;
  --bg-card: rgba(255, 255, 255, 0.08);
  --bg-card-strong: rgba(255, 255, 255, 0.14);
  --border-soft: rgba(255, 255, 255, 0.14);
  --text-main: #ffffff;
  --text-muted: rgba(255, 255, 255, 0.68);
  --accent: #d4af37;
  --accent-dark: #9b7b1f;
  --danger: #ff5b5b;
  --shadow-soft: 0 25px 80px rgba(0, 0, 0, 0.45);
  --book-shadow: 0 40px 120px rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Inter", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(212, 175, 55, 0.17), transparent 35%),
    radial-gradient(circle at bottom right, rgba(80, 100, 255, 0.15), transparent 35%),
    linear-gradient(135deg, #0d0f14 0%, #171922 45%, #090a0f 100%);
  color: var(--text-main);
  overflow-x: hidden;
}

body {
  min-height: 100vh;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  width: 100%;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(10, 12, 18, 0.84);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #fff1a6);
  color: #101010;
  box-shadow: 0 12px 30px rgba(212, 175, 55, 0.25);
  font-weight: 900;
  letter-spacing: -1px;
}

.brand-title {
  line-height: 1.1;
}

.brand-title strong {
  display: block;
  font-size: 16px;
  letter-spacing: 0.2px;
}

.brand-title span {
  font-size: 12px;
  color: var(--text-muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: end;
  align-items: center;
}

.glass-select,
.glass-input {
  background: rgba(255, 255, 255, 0.09) !important;
  border: 1px solid var(--border-soft) !important;
  color: #fff !important;
  border-radius: 14px !important;
  min-height: 42px;
}

.glass-select option {
  color: #111;
}

.btn-gold {
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #f7df8a);
  color: #111;
  font-weight: 800;
  min-height: 42px;
  box-shadow: 0 10px 30px rgba(212, 175, 55, 0.22);
}

.btn-gold:hover {
  color: #111;
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.btn-glass {
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  min-height: 42px;
}

.btn-glass:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 22px;
  gap: 18px;
}

.viewer-card {
  flex: 1;
  position: relative;
  border: 1px solid var(--border-soft);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03)),
    rgba(255,255,255,0.06);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  min-height: calc(100vh - 150px);
}

.viewer-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.045);
  position: relative;
  z-index: 40;
}

.doc-info {
  min-width: 0;
}

.doc-info h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-info p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(212, 175, 55, 0.28);
  background: rgba(212, 175, 55, 0.12);
  color: #f8dfa0;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.is-working i {
  animation: softPulse 1.4s ease-in-out infinite;
}

@keyframes softPulse {
  0%, 100% {
    opacity: 1;
  }

  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-pill.is-working i {
    animation: none;
  }
}

.book-stage {
  position: relative;
  width: 100%;
  height: calc(100% - 74px);
  min-height: 620px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 82px 90px;
  overflow: visible;
}

.book-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.11), transparent 35%),
    linear-gradient(90deg, rgba(255,255,255,0.04), transparent 20%, transparent 80%, rgba(255,255,255,0.04));
  pointer-events: none;
  z-index: 1;
}

.flipbook {
  position: relative;
  box-shadow: var(--book-shadow);
  border-radius: 10px;
  transform-origin: center center;
  opacity: 0;
  transition: opacity 0.35s ease;
  z-index: 10;
}

.flipbook.ready {
  opacity: 1;
}

/* Bloque de páginas asomando bajo el libro: da sensación real de grosor/papel */
.flipbook::before {
  content: "";
  position: absolute;
  inset: 4px -7px -9px 4px;
  z-index: -1;
  border-radius: 8px;
  background: linear-gradient(145deg, #f1ebdc, #ddd4ba);
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.05),
    0 16px 34px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* Sombra de lomo/cosido al centro del libro abierto (solo vista doble) */
.flipbook.is-double::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 90px;
  height: 100%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 5;
  mix-blend-mode: multiply;
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.14) 40%,
    rgba(0, 0, 0, 0.27) 50%,
    rgba(0, 0, 0, 0.14) 60%,
    rgba(0, 0, 0, 0) 100%
  );
}

.flipbook .page {
  background: #fdfbf5;
  overflow: hidden;
  position: relative;
}

/* Tono cálido de papel + viñeta de borde, mezclados sobre el render del PDF */
.flipbook .page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.03), transparent 8%, transparent 92%, rgba(0, 0, 0, 0.032)),
    linear-gradient(135deg, rgba(255, 239, 201, 0.16), rgba(255, 250, 237, 0.04) 45%, rgba(255, 233, 189, 0.14));
}

.flipbook canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #fff;
}

/* ====== Página pendiente de renderizar (carga progresiva) ====== */

.flipbook .page.page-pending {
  background: linear-gradient(135deg, #fbf8f1, #efe9db);
}

.page-skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 14px;
  overflow: hidden;
}

.page-skeleton::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    100deg,
    transparent 30%,
    rgba(255, 255, 255, 0.55) 48%,
    rgba(255, 255, 255, 0.55) 52%,
    transparent 70%
  );
  background-size: 220% 100%;
  animation: paperShimmer 1.8s ease-in-out infinite;
}

.page-skeleton-number {
  position: relative;
  z-index: 1;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 12px;
  letter-spacing: 1px;
  color: rgba(80, 70, 45, 0.4);
}

@keyframes paperShimmer {
  0% {
    background-position: -120% 0;
  }

  100% {
    background-position: 120% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .page-skeleton::before {
    animation: none;
  }
}

.hard-cover {
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.025) 0 2px, transparent 2px 4px),
    linear-gradient(135deg, #181818, #2a2a2a 45%, #111),
    radial-gradient(circle at top left, rgba(212,175,55,0.25), transparent 40%) !important;
  color: #fff;
  display: grid !important;
  place-items: center;
  text-align: center;
  padding: 32px;
  border: 1px solid rgba(212,175,55,0.35);
  position: relative;
}

/* Lomo del libro: marca de qué lado se "cose" la tapa al resto de páginas */
.hard-cover::before {
  content: "";
  position: absolute;
  top: 14px;
  bottom: 14px;
  width: 3px;
  background: linear-gradient(180deg, rgba(212,175,55,0.05), rgba(212,175,55,0.6), rgba(212,175,55,0.05));
  pointer-events: none;
}

.hard-cover.cover-front::before {
  right: 7px;
}

.hard-cover.cover-back::before {
  left: 7px;
}

.hard-cover .cover-inner {
  border: 1px solid rgba(212,175,55,0.45);
  width: 86%;
  height: 86%;
  display: grid;
  place-items: center;
  padding: 30px;
  background: rgba(0,0,0,0.18);
}

.hard-cover h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 28px;
  margin-bottom: 12px;
  letter-spacing: -0.3px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.5), 0 0 22px rgba(212,175,55,0.18);
}

.hard-cover p {
  color: rgba(255,255,255,0.72);
  margin: 0;
  font-size: 14px;
  font-family: Georgia, "Times New Roman", serif;
}

.cover-brand {
  margin-top: 12px !important;
  color: var(--accent) !important;
  font-weight: 800;
  letter-spacing: 1px;
}

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 99999 !important;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid var(--border-soft);
  background: rgba(0,0,0,0.42);
  color: #fff;
  display: grid;
  place-items: center;
  backdrop-filter: blur(12px);
  transition: 0.2s ease;
  pointer-events: auto !important;
}

.nav-btn:hover {
  background: rgba(212,175,55,0.95);
  color: #111;
  transform: translateY(-50%) scale(1.05);
}

.nav-prev {
  left: 22px;
}

.nav-next {
  right: 22px;
}

.bottom-controls {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 99999 !important;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(10, 12, 18, 0.78);
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 50px rgba(0,0,0,0.35);
  pointer-events: auto !important;
}

.bottom-controls button,
.bottom-controls input {
  position: relative;
  z-index: 99999 !important;
  pointer-events: auto !important;
}

.page-counter {
  min-width: 110px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

.range-wrap {
  width: min(360px, 34vw);
  display: flex;
  align-items: center;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.loader-overlay {
  position: absolute;
  inset: 0;
  z-index: 100000;
  background: rgba(7, 8, 12, 0.84);
  backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
}

.loader-box {
  max-width: 430px;
  padding: 30px;
  border-radius: 28px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
}

.spinner-border {
  color: var(--accent);
  width: 3rem;
  height: 3rem;
}

.loader-box h2 {
  margin-top: 18px;
  font-size: 21px;
  font-weight: 900;
}

.loader-box p {
  color: var(--text-muted);
  margin-bottom: 0;
  font-size: 14px;
}

.progress {
  height: 9px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  margin-top: 18px;
  overflow: hidden;
}

.progress-bar {
  background: linear-gradient(90deg, var(--accent-dark), var(--accent), #fff1a6);
}

.empty-state {
  text-align: center;
  padding: 50px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 54px;
  color: var(--accent);
  margin-bottom: 14px;
}

.mobile-hint {
  display: none;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 8px 12px 0;
}

/* PANTALLA COMPLETA */

.viewer-card:fullscreen .viewer-header {
  display: none !important;
}

.viewer-card:-webkit-full-screen .viewer-header {
  display: none !important;
}

.viewer-card:fullscreen {
  border-radius: 0;
  border: none;
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.08), transparent 35%),
    linear-gradient(135deg, #11131a, #050608);
}

.viewer-card:-webkit-full-screen {
  border-radius: 0;
  border: none;
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.08), transparent 35%),
    linear-gradient(135deg, #11131a, #050608);
}

.viewer-card:fullscreen .book-stage {
  height: 100vh;
  min-height: 100vh;
  padding-top: 28px;
  padding-bottom: 90px;
}

.viewer-card:-webkit-full-screen .book-stage {
  height: 100vh;
  min-height: 100vh;
  padding-top: 28px;
  padding-bottom: 90px;
}

/* RESPONSIVE */

@media (max-width: 991px) {
  .topbar {
    padding: 14px;
  }

  .toolbar {
    justify-content: stretch;
    margin-top: 12px;
  }

  .toolbar > * {
    flex: 1 1 auto;
  }

  .main-area {
    padding: 12px;
  }

  .viewer-card {
    border-radius: 22px;
    min-height: calc(100vh - 170px);
  }

  .viewer-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-pill {
    width: 100%;
    justify-content: center;
  }

  .book-stage {
    min-height: 560px;
    padding: 22px 14px 78px;
  }

  .nav-btn {
    width: 44px;
    height: 44px;
    top: auto;
    bottom: 20px;
    transform: none;
  }

  .nav-btn:hover {
    transform: scale(1.04);
  }

  .nav-prev {
    left: 14px;
  }

  .nav-next {
    right: 14px;
  }

  .bottom-controls {
    bottom: 18px;
    max-width: calc(100% - 112px);
    padding: 8px;
  }

  .range-wrap {
    display: none;
  }

  .page-counter {
    min-width: 95px;
  }

  .mobile-hint {
    display: block;
  }
}

@media (max-width: 575px) {
  .brand-title strong {
    font-size: 14px;
  }

  .brand-title span {
    font-size: 11px;
  }

  .brand-logo {
    width: 38px;
    height: 38px;
  }

  .doc-info h1 {
    font-size: 16px;
  }

  .book-stage {
    min-height: 500px;
  }

  .hard-cover h2 {
    font-size: 22px;
  }

  .hard-cover p {
    font-size: 12px;
  }
}

/* IMPRESIÓN */

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .viewer-header,
  .nav-btn,
  .bottom-controls,
  .mobile-hint {
    display: none !important;
  }

  .viewer-card {
    border: 0;
    box-shadow: none;
  }
}