/* ============================================
   SERVICE BOOKS — 3D Book Grid + Mobile Shelf
   Replaces Swiper carousel for service cards
   ============================================ */

/* --- Variables (scoped) --- */
.service-books {
  --book-width: 220px;
  --book-height: 320px;
  --book-depth: 25px;
  --book-anim: 0.7s;
  --book-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Section --- */
.service-books {
  padding: var(--space-section) 0;
}

/* --- Desktop: 2×3 Book Grid --- */
.book-library {
  display: flex;
  flex-wrap: wrap;
  gap: 48px;
  justify-content: center;
  max-width: 860px;
  margin: 0 auto;
}

/* --- Book Shelf (mobile only, hidden on desktop) --- */
.book-shelf {
  display: none;
}

/* =============================================
   3D BOOK STRUCTURE
   From: covers-animated-1.html
   ============================================= */

.book-wrapper {
  width: var(--book-width);
  height: var(--book-height);
  position: relative;
  transform-style: preserve-3d;
  perspective: 1500px;
  cursor: pointer;
  z-index: 10;
  transition: transform 0.4s ease, opacity 0.3s ease;
}

.book-wrapper:hover {
  transform: translateY(-12px);
}

.book-wrapper.dimmed {
  opacity: 0.35;
  pointer-events: none;
  z-index: 1;
  filter: blur(2px);
}

.book-wrapper.active {
  z-index: 200;
  transition: transform 0.6s var(--book-ease), opacity 0.3s ease;
}

.book-wrapper.closing {
  z-index: 200;
  transition: transform 0.6s var(--book-ease), opacity 0.3s ease;
}

.book-wrapper.active:hover {
  transform: none;
}

/* --- The Book (3D container) --- */
.book-wrapper .book {
  width: 100%;
  height: 100%;
  position: absolute;
  transform-style: preserve-3d;
  transition: transform var(--book-anim) var(--book-ease);
  transform: rotateY(-8deg) rotateX(2deg);
}

.book-wrapper:hover .book:not(.open) {
  transform: rotateY(-15deg) rotateX(4deg);
}

.book-wrapper .book.open {
  transform: rotateY(0deg) rotateX(0deg);
}

/* --- Faces (shared) --- */
.book-wrapper .face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
}

/* --- Front Cover (flips open) --- */
.book-wrapper .front-cover {
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform var(--book-anim) var(--book-ease);
  z-index: 50;
}

.book-wrapper .book.open .front-cover {
  transform: rotateY(-180deg);
}

/* Front face (outer) */
.book-wrapper .front-face {
  border-radius: 0 4px 4px 0;
  display: flex;
  flex-direction: column;
  padding: 28px 24px;
  box-shadow:
    inset 3px 0 15px rgba(0,0,0,0.3),
    inset -2px 0 8px rgba(255,255,255,0.05),
    inset 0 2px 8px rgba(255,255,255,0.03),
    inset 0 -2px 8px rgba(0,0,0,0.2),
    0 15px 40px rgba(0,0,0,0.4);
  overflow: hidden;
}

/* Leather/cloth texture */
.book-wrapper .front-face::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.08'/%3E%3C/svg%3E");
  pointer-events: none;
  border-radius: inherit;
}

/* Spine edge highlight */
.book-wrapper .front-face::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 12px;
  height: 100%;
  background: linear-gradient(90deg,
    rgba(255,255,255,0.08) 0%,
    rgba(255,255,255,0.02) 50%,
    transparent 100%
  );
  pointer-events: none;
}

/* --- Inside Cover (bookplate) --- */
.book-wrapper .inside-cover {
  background:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E"),
    linear-gradient(to left, #ebe7e0 0%, #f5f2ed 5%, #f5f2ed 100%);
  transform: rotateY(180deg);
  border-radius: 4px 0 0 4px;
  box-shadow: inset -5px 0 20px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
}

.bookplate {
  background: #faf8f5;
  border: 1px solid #e0dcd5;
  padding: 30px 25px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.book-wrapper .book.open .bookplate {
  opacity: 1;
  transition: opacity 0.4s ease 0.4s;
}

.bookplate-label {
  font-family: var(--font-palatino);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #8a7a6a;
  margin-bottom: 8px;
}

.bookplate-title {
  font-family: 'Playfair Display', var(--font-palatino);
  font-size: 1.1rem;
  font-style: italic;
  color: #4a4035;
  margin-bottom: 12px;
}

.bookplate-line {
  width: 50px;
  height: 1px;
  margin: 0 auto 12px;
}

.bookplate-ornament {
  font-size: 1rem;
  opacity: 0.7;
}

/* --- Spine --- */
.book-wrapper .spine {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--book-depth);
  height: 100%;
  transform: rotateY(-90deg) translateX(calc(var(--book-depth) * -1));
  transform-origin: left center;
  border-radius: 4px 0 0 4px;
  box-shadow:
    inset -3px 0 10px rgba(0,0,0,0.4),
    inset 3px 0 6px rgba(255,255,255,0.05);
}

.book-wrapper .spine::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.1'/%3E%3C/svg%3E");
  pointer-events: none;
  border-radius: inherit;
}

/* --- Back Cover --- */
.book-wrapper .back-cover {
  transform: translateZ(calc(var(--book-depth) * -1));
  border-radius: 4px;
  box-shadow: 10px 10px 40px rgba(0,0,0,0.5);
}

.book-wrapper .back-cover::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.08'/%3E%3C/svg%3E");
  pointer-events: none;
  border-radius: inherit;
}

/* --- Pages Block (revealed when cover opens) --- */
.book-wrapper .pages {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  background:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E"),
    linear-gradient(to right, #ebe7e0 0%, #f5f2ed 5%, #f5f2ed 100%);
  transform: translateZ(calc(var(--book-depth) * -0.5));
  border-radius: 0 4px 4px 0;
  z-index: 5;
  box-shadow: inset 8px 0 20px rgba(0,0,0,0.08);
  overflow: hidden;
}

.book-wrapper .pages > * {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.book-wrapper .book.open .pages > * {
  opacity: 1;
  transition: opacity 0.3s ease 0.3s;
}

/* --- Binding Shadow (center crease when open) --- */
.book-wrapper .binding-shadow {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 100%;
  transform: translateZ(calc(var(--book-depth) * -0.5 + 1px));
  background: linear-gradient(90deg,
    rgba(0,0,0,0.12) 0%,
    rgba(0,0,0,0.06) 40%,
    transparent 100%
  );
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.book-wrapper .book.open .binding-shadow {
  opacity: 1;
  transition: opacity 0.4s ease 0.4s;
}

/* --- Paper Edge (visible on right side) --- */
.book-wrapper .paper-edge {
  position: absolute;
  right: 0;
  top: 2%;
  height: 96%;
  width: calc(var(--book-depth) - 4px);
  background: repeating-linear-gradient(
    90deg,
    #f5f2ed,
    #f5f2ed 2px,
    #e8e4dd 2px,
    #e8e4dd 3px
  );
  transform: rotateY(90deg) translateX(50%);
  transform-origin: right center;
  border-radius: 0 2px 2px 0;
}

/* =============================================
   COVER DECORATIONS
   ============================================= */

.cover-frame {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  bottom: 16px;
  border: 1px solid currentColor;
  opacity: 0.2;
  pointer-events: none;
}

.cover-corners,
.cover-corners-bottom {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  bottom: 12px;
  pointer-events: none;
}

.cover-corners::before,
.cover-corners::after,
.cover-corners-bottom::before,
.cover-corners-bottom::after {
  content: '';
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: currentColor;
  border-style: solid;
  opacity: 0.35;
}

.cover-corners::before { top: 0; left: 0; border-width: 2px 0 0 2px; }
.cover-corners::after { top: 0; right: 0; border-width: 2px 2px 0 0; }
.cover-corners-bottom::before { bottom: 0; left: 0; border-width: 0 0 2px 2px; }
.cover-corners-bottom::after { bottom: 0; right: 0; border-width: 0 2px 2px 0; }

.cover-corners .corner-detail,
.cover-corners-bottom .corner-detail {
  position: absolute;
  width: 8px;
  height: 8px;
  border: 1px solid currentColor;
  opacity: 0.25;
  transform: rotate(45deg);
}

.cover-corners .corner-detail:nth-child(1) { top: 6px; left: 6px; }
.cover-corners .corner-detail:nth-child(2) { top: 6px; right: 6px; }
.cover-corners-bottom .corner-detail:nth-child(1) { bottom: 6px; left: 6px; }
.cover-corners-bottom .corner-detail:nth-child(2) { bottom: 6px; right: 6px; }

.cover-ornament {
  text-align: center;
  font-size: 1.2rem;
  margin-bottom: 8px;
  opacity: 0.8;
  text-shadow:
    0 1px 1px rgba(0,0,0,0.3),
    0 -1px 0 rgba(255,255,255,0.1);
}

.cover-title {
  font-family: 'Playfair Display', var(--font-palatino);
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.25;
  text-shadow:
    0 1px 2px rgba(0,0,0,0.4),
    0 -1px 0 rgba(255,255,255,0.08);
}

.cover-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.cover-divider .line { width: 25px; height: 1px; }
.cover-divider .dot { width: 4px; height: 4px; border-radius: 50%; opacity: 0.5; }

.cover-subtitle {
  font-size: 0.9rem;
  font-style: italic;
  opacity: 0.8;
}

.cover-year {
  font-family: var(--font-palatino);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0.6;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* =============================================
   PAGE CONTENT (inside opened book)
   Uses site typography vars
   ============================================= */

.book-wrapper .page-title {
  font-family: 'Playfair Display', var(--font-palatino);
  font-size: 1.15rem;
  font-weight: 600;
  color: #2a2520;
  margin-bottom: 4px;
  margin-top: 8px;
  line-height: 1.2;
}

.book-wrapper .page-subtitle {
  font-size: 0.75rem;
  color: #7a6a5a;
  font-style: italic;
  margin-bottom: 12px;
}

.book-wrapper .page-divider {
  width: 35px;
  height: 2px;
  margin-bottom: 12px;
}

.book-wrapper .page-description {
  font-family: var(--font-gentium);
  font-size: 0.85rem;
  color: #4a4035;
  line-height: 1.6;
  flex: 1;
  overflow-y: auto;
}

.book-wrapper .page-section-title {
  font-family: 'Playfair Display', var(--font-palatino);
  font-size: 0.95rem;
  font-weight: 600;
  color: #3a3025;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

/* CTA buttons inside pages */
.book-wrapper .page-cta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
}

.book-wrapper .page-button {
  padding: 10px 18px;
  border: 1px solid rgba(0,0,0,0.2);
  border-radius: 3px;
  font-family: var(--font-palatino);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  text-align: center;
}

.book-wrapper .page-button:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transform: translateY(-1px);
}

.book-wrapper .page-button-secondary {
  background: transparent;
  color: #4a4035;
  border: 1px solid #c4b9a8;
}

.book-wrapper .page-button-secondary:hover {
  background: rgba(0,0,0,0.04);
}

/* Close button */
.book-wrapper .close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: rgba(0,0,0,0.06);
  border: none;
  border-radius: 50%;
  font-size: 1.1rem;
  color: #9a8a7a;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease, color 0.2s ease, background 0.2s ease;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.book-wrapper .book.open .close-btn {
  opacity: 1;
  transition: opacity 0.3s ease 0.4s;
}

.book-wrapper .close-btn:hover {
  color: #4a4035;
  background: rgba(0,0,0,0.1);
}

/* --- StPageFlip container override --- */
/* StPageFlip creates .stf__parent as a sibling of .pages inside .book.
   Constrain it to the right half so it renders in portrait (single-page) mode
   while the inside-cover bookplate occupies the left half. */
.book-wrapper .book .stf__parent {
  position: absolute !important;
  top: 4px !important;
  left: 50% !important;
  width: 48% !important;
  height: calc(100% - 8px) !important;
  z-index: 10;
}

/* --- StPageFlip page styling --- */
.book-wrapper .flip-page {
  background: linear-gradient(to right, #ebe7e0 0%, #f5f2ed 5%, #f5f2ed 100%);
  padding: 18px 15px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Hide flip-page elements until StPageFlip initializes */
.book-wrapper .pages .flip-page {
  position: absolute;
  visibility: hidden;
}

.stf__parent .flip-page,
.book-wrapper .pages.pageflip-ready .flip-page {
  position: static;
  visibility: visible;
}

.flip-page .page-ornament {
  font-size: 1.5rem;
  margin-bottom: 12px;
  opacity: 0.7;
  text-align: center;
}

/* =============================================
   OVERLAY
   ============================================= */

.book-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 4, 0);
  pointer-events: none;
  transition: background 0.5s ease;
  z-index: 50;
}

.book-overlay.active {
  background: rgba(8, 6, 4, 0.55);
  pointer-events: auto;
}

/* =============================================
   MOBILE: BOOKSHELF WITH SPINES
   ============================================= */

@media (max-width: 767px) {
  .book-library { display: none; }
  .book-shelf { display: block; }

  .shelf-container {
    position: relative;
    padding: 24px 16px 0;
    max-width: 400px;
    margin: 0 auto;
  }

  .shelf-back {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 24px;
    background: linear-gradient(180deg, #4a3628 0%, #3d2d21 100%);
    border-radius: 8px 8px 0 0;
    box-shadow: inset 0 5px 30px rgba(0,0,0,0.5);
  }

  .shelf-books {
    display: flex;
    gap: 6px;
    position: relative;
    z-index: 1;
    padding: 16px 8px;
    justify-content: center;
  }

  .shelf-bottom {
    height: 24px;
    background: linear-gradient(180deg, #5c4636 0%, #3d2d21 100%);
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4), inset 0 2px 0 rgba(255,255,255,0.1);
    position: relative;
  }

  .shelf-shadow {
    position: absolute;
    bottom: -16px;
    left: 10%;
    right: 10%;
    height: 16px;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.3) 0%, transparent 70%);
  }

  /* Individual spine */
  .book-spine {
    width: 50px;
    height: 200px;
    border-radius: 3px 6px 6px 3px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 16px 6px;
    cursor: pointer;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    border: 1px solid rgba(255,255,255,0.1);
    border-left: 3px solid rgba(0,0,0,0.3);
    box-shadow: inset 0 0 30px rgba(0,0,0,0.3);
  }

  .book-spine:hover,
  .book-spine:active {
    transform: translateY(-8px);
  }

  .book-spine .spine-title {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    color: #e8dcc8;
    font-family: var(--font-palatino);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .book-spine .spine-ornament {
    font-size: 1rem;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
  }

  /* --- Mobile Overlay (card-style, no page flip) --- */
  .mobile-book-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 8, 6, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 24px;
    backdrop-filter: blur(4px);
  }

  .mobile-book-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-book-card {
    background: linear-gradient(135deg, #f5f2ed 0%, #ebe7e0 100%);
    border-radius: 8px;
    padding: 32px 28px;
    max-width: 360px;
    width: 100%;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  }

  .mobile-book-card .mobile-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0,0,0,0.06);
    border-radius: 50%;
    font-size: 1.2rem;
    color: #7a6a5a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-book-card .mobile-title {
    font-family: 'Playfair Display', var(--font-palatino);
    font-size: 1.4rem;
    font-weight: 600;
    color: #2a2520;
    margin-bottom: 4px;
  }

  .mobile-book-card .mobile-subtitle {
    font-size: 0.85rem;
    color: #7a6a5a;
    font-style: italic;
    margin-bottom: 16px;
  }

  .mobile-book-card .mobile-divider {
    width: 40px;
    height: 2px;
    margin-bottom: 16px;
  }

  .mobile-book-card .mobile-description {
    font-family: var(--font-gentium);
    font-size: 1rem;
    color: #4a4035;
    line-height: 1.7;
    margin-bottom: 24px;
  }

  .mobile-book-card .mobile-cta {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .mobile-book-card .mobile-btn {
    padding: 12px 20px;
    border-radius: 4px;
    font-family: var(--font-palatino);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: all 0.2s ease;
    border: none;
  }

  .mobile-book-card .mobile-btn-primary {
    color: #e8dcc8;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }

  .mobile-book-card .mobile-btn-secondary {
    background: transparent;
    color: #4a4035;
    border: 1px solid #c4b9a8;
  }
}

/* =============================================
   RESPONSIVE: Tablet adjustments
   ============================================= */

@media (min-width: 768px) and (max-width: 1023px) {
  .service-books {
    --book-width: 180px;
    --book-height: 260px;
    --book-depth: 20px;
  }

  .book-library {
    gap: 32px;
  }

  .book-wrapper .book.open {
    transform: rotateY(0deg) rotateX(0deg);
  }

  .cover-title { font-size: 1.1rem; }
  .cover-subtitle { font-size: 0.8rem; }
}

/* =============================================
   REDUCED MOTION
   ============================================= */

@media (prefers-reduced-motion: reduce) {
  .book-wrapper,
  .book-wrapper .book,
  .book-wrapper .front-cover,
  .book-overlay,
  .bookplate,
  .book-spine {
    transition-duration: 0.01ms;
  }

  .book-wrapper .book {
    transform: none;
  }

  .book-wrapper:hover {
    transform: none;
  }

  .book-wrapper .book.open {
    transform: none;
  }
}
