/* ==========================================================================
   Book 3D CSS — Pure CSS 3D book with opening animation
   ========================================================================== */

/* ----- Book Container ----- */
.book {
  position: relative;
  width: 160px;
  height: 220px;
  perspective: 1000px;
  transform-style: preserve-3d;
  flex-shrink: 0;
}

/* ----- Common styles for hardcover and spine ----- */
.hardcover-front,
.hardcover-back,
.book-spine,
.hardcover-front > li,
.hardcover-back > li,
.book-spine > li {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  list-style: none;
  margin: 0;
  padding: 0;
}

.hardcover-front,
.hardcover-back {
  transform-origin: 0% 100%;
}

/* ----- Hardcover Front ----- */
.hardcover-front {
  transform: rotateY(-34deg) translateZ(8px);
  z-index: 100;
  transition: all 0.8s ease, z-index 0.6s;
}

.hardcover-front > li:first-child {
  background-color: #eee;
  backface-visibility: hidden;
  transform: translateZ(2px);
  cursor: default;
  user-select: none;
  overflow: hidden;
  border-radius: 0 4px 4px 0;
}

.hardcover-front > li:last-child {
  background: #fffbec;
  transform: rotateY(180deg) translateZ(2px);
  border-radius: 0 4px 4px 0;
}

/* ----- Hardcover Back ----- */
.hardcover-back {
  transform: rotateY(-15deg) translateZ(-8px);
}

.hardcover-back > li:first-child {
  background: #fffbec;
  transform: translateZ(2px);
}

.hardcover-back > li:last-child {
  background: #fffbec;
  transform: translateZ(-2px);
}

/* ----- Book Spine ----- */
.book-spine {
  transform: rotateY(60deg) translateX(-5px) translateZ(-12px);
  width: 16px;
  z-index: 0;
}

.book-spine > li:first-child {
  background: #eee;
  transform: translateZ(2px);
}

.book-spine > li:last-child {
  background: #333;
  transform: translateZ(-2px);
}

/* ----- Pages ----- */
.page,
.page > li {
  position: absolute;
  top: 0;
  left: 0;
  transform-style: preserve-3d;
  list-style: none;
  margin: 0;
  padding: 0;
}

.page {
  width: 100%;
  height: 98%;
  top: 1%;
  left: 3%;
  z-index: 10;
}

.page > li {
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transition-property: transform;
  transition-timing-function: ease;
  background: linear-gradient(to right, #e1ddd8 0%, #fffbf6 100%);
  box-shadow: inset 0 -1px 2px rgba(50, 50, 50, 0.1),
    inset -1px 0 1px rgba(150, 150, 150, 0.2);
  border-radius: 0 5px 5px 0;
  overflow: hidden;
}

/* Page closed positions */
.page > li:nth-child(1) {
  transform: rotateY(-28deg);
  transition-duration: 0.6s;
}
.page > li:nth-child(2) {
  transform: rotateY(-30deg);
  transition-duration: 0.6s;
}
.page > li:nth-child(3) {
  transform: rotateY(-32deg);
  transition-duration: 0.4s;
}
.page > li:nth-child(4) {
  transform: rotateY(-34deg);
  transition-duration: 0.5s;
}
.page > li:nth-child(5) {
  transform: rotateY(-36deg);
  transition-duration: 0.6s;
}

/* ----- Thickness (pseudo-elements) ----- */
.hardcover-front > li::after,
.hardcover-front > li::before,
.hardcover-back > li::after,
.hardcover-back > li::before,
.book-spine > li::after,
.book-spine > li::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  background: #999;
}

/* Front cover thickness */
.hardcover-front > li:first-child::after,
.hardcover-front > li:first-child::before {
  width: 4px;
  height: 100%;
}

.hardcover-front > li:first-child::after {
  transform: rotateY(90deg) translateZ(-2px) translateX(2px);
}

.hardcover-front > li:first-child::before {
  transform: rotateY(90deg) translateZ(158px) translateX(2px);
}

.hardcover-front > li:last-child::after,
.hardcover-front > li:last-child::before {
  width: 4px;
  height: 160px;
}

.hardcover-front > li:last-child::after {
  transform: rotateX(90deg) rotateZ(90deg) translateZ(80px) translateX(-2px)
    translateY(-78px);
}

.hardcover-front > li:last-child::before {
  box-shadow: 0 0 30px 5px #333;
  transform: rotateX(90deg) rotateZ(90deg) translateZ(-140px) translateX(-2px)
    translateY(-78px);
}

/* Back cover thickness */
.hardcover-back > li:first-child::after,
.hardcover-back > li:first-child::before {
  width: 4px;
  height: 100%;
}

.hardcover-back > li:first-child::after {
  transform: rotateY(90deg) translateZ(-2px) translateX(2px);
}

.hardcover-back > li:first-child::before {
  transform: rotateY(90deg) translateZ(158px) translateX(2px);
}

.hardcover-back > li:last-child::after,
.hardcover-back > li:last-child::before {
  width: 4px;
  height: 160px;
}

.hardcover-back > li:last-child::after {
  transform: rotateX(90deg) rotateZ(90deg) translateZ(80px) translateX(2px)
    translateY(-78px);
}

.hardcover-back > li:last-child::before {
  box-shadow: 10px -1px 80px 20px #666;
  transform: rotateX(90deg) rotateZ(90deg) translateZ(-140px) translateX(2px)
    translateY(-78px);
}

/* Spine thickness */
.book-spine > li:first-child::after,
.book-spine > li:first-child::before {
  width: 4px;
  height: 100%;
}

.book-spine > li:first-child::after {
  transform: rotateY(90deg) translateZ(-2px) translateX(2px);
}

.book-spine > li:first-child::before {
  transform: rotateY(-90deg) translateZ(-12px);
}

.book-spine > li:last-child::after,
.book-spine > li:last-child::before {
  width: 4px;
  height: 16px;
}

.book-spine > li:last-child::after {
  transform: rotateX(90deg) rotateZ(90deg) translateZ(8px) translateX(2px)
    translateY(-6px);
}

.book-spine > li:last-child::before {
  box-shadow: 5px -1px 100px 40px rgba(0, 0, 0, 0.2);
  transform: rotateX(90deg) rotateZ(90deg) translateZ(-210px) translateX(2px)
    translateY(-6px);
}

/* ==========================================================================
   Open State — Triggered by .is-open class (controlled by JS)
   ========================================================================== */

.book.is-open > .hardcover-front {
  transform: rotateY(-145deg) translateZ(0);
  z-index: 0;
}

.book.is-open > .page > li:nth-child(1) {
  transform: rotateY(-30deg);
  transition-duration: 1.5s;
}
.book.is-open > .page > li:nth-child(2) {
  transform: rotateY(-35deg);
  transition-duration: 1.8s;
}
.book.is-open > .page > li:nth-child(3) {
  transform: rotateY(-118deg);
  transition-duration: 1.6s;
}
.book.is-open > .page > li:nth-child(4) {
  transform: rotateY(-130deg);
  transition-duration: 1.4s;
}
.book.is-open > .page > li:nth-child(5) {
  transform: rotateY(-140deg);
  transition-duration: 1.2s;
}

/* ==========================================================================
   Page Content Styles
   ========================================================================== */

.page-inner {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 10px;
  backface-visibility: visible;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 4.45px;
  line-height: 1.28;
  color: #2c2416;
  /* background: linear-gradient(105deg, #e8e2d8 0%, #faf6ee 18%, #fffef9 50%, #f5f0e6 100%); */
  /* box-shadow: inset 2px 0 4px rgba(0, 0, 0, 0.06); */
}

/* Paper grain texture */
.page-inner::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.015) 2px,
    rgba(0, 0, 0, 0.015) 3px
  );
}

.page-num {
  position: absolute;
  bottom: 6px;
  font-size: 5px;
  color: #8a7f6e;
  font-style: italic;
}

.page-num.left {
  left: 8px;
}

.page-num.right {
  right: 8px;
}

.page-inner h2 {
  font-size: 7px;
  font-weight: 700;
  margin: 0 0 3px;
  color: #1a1510;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.page-inner h3 {
  font-size: 5.6px;
  font-weight: 600;
  margin: 4px 0 2px;
  color: #3d3428;
}

.page-inner p {
  margin: 0 0 2px;
  text-align: justify;
  hyphens: auto;
}

.page-inner .lead {
  font-size: 4.85px;
  font-style: italic;
  color: #5c5345;
  margin-bottom: 3px;
}

.page-inner .small-caps {
  font-variant: small-caps;
  letter-spacing: 0.04em;
}

.page-inner .journal {
  margin-top: 3px;
  padding: 3px 4px;
  border-left: 2px solid #8b7355;
  background: rgba(255, 255, 255, 0.45);
  font-size: 4.2px;
  line-height: 1.3;
}

/* Title page */
.page-inner.title-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(180deg, #f8f4eb 0%, #efe8dc 100%);
  padding-bottom: 40px;
}

.page-inner.title-page h2 {
  font-size: 9px;
  margin-bottom: 6px;
}

.page-inner.title-page .subtitle {
  font-size: 6px;
  color: #6b5f4f;
  margin-bottom: 12px;
}

.page-inner.title-page .author {
  font-size: 5.5px;
  border-top: 1px solid #c4b8a4;
  padding-top: 6px;
  width: 70%;
}

.page-inner.title-page .imprint {
  position: absolute;
  bottom: 20px;
  left: 8px;
  right: 8px;
  font-size: 3.5px;
  line-height: 1.22;
  color: #7a6f5f;
  text-align: justify;
}

/* Table of contents */
.page-inner.toc ul {
  margin: 4px 0 0;
  padding: 0;
}

.page-inner.toc li {
  list-style: none;
  display: flex;
  justify-content: space-between;
  font-size: 4.35px;
  margin-bottom: 1.5px;
  padding: 0;
}

.page-inner.toc li::after {
  content: none;
}

.page-inner.toc .dots {
  flex: 1;
  border-bottom: 1px dotted #bbb;
  margin: 0 3px 1px;
  min-width: 8px;
}

/* Chapter opener */
.page-inner.chapter-opener {
  background: linear-gradient(135deg, #f5efe4 0%, #fffef9 60%);
}

.page-inner.chapter-opener .chapter-num {
  font-size: 14px;
  font-weight: 300;
  color: #c4a882;
  line-height: 1;
  margin-bottom: 2px;
}

/* Figure placeholder */
.mini-figure {
  margin: 3px 0;
  padding: 3px;
  border: 1px solid #d4cdc0;
  background: #fff;
  font-size: 4px;
  text-align: center;
  color: #7a7060;
}

.mini-figure .bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  height: 14px;
  margin-top: 2px;
}

.mini-figure .bar {
  width: 6px;
  border-radius: 1px 1px 0 0;
}

.mini-figure .bar:nth-child(1) {
  height: 40%;
  background: #3498db;
}
.mini-figure .bar:nth-child(2) {
  height: 70%;
  background: #2ecc71;
}
.mini-figure .bar:nth-child(3) {
  height: 55%;
  background: #e74c3c;
}
.mini-figure .bar:nth-child(4) {
  height: 85%;
  background: #9b59b6;
}

/* Variations per page */
.page > li:nth-child(1) .page-inner {
  background: linear-gradient(105deg, #ebe5db 0%, #fffef9 100%);
}
.page > li:nth-child(3) .page-inner {
  background: linear-gradient(105deg, #e6e0d6 0%, #fdf9f2 100%);
}
.page > li:nth-child(4) .page-inner {
  background: linear-gradient(105deg, #e4ddd2 0%, #fcf8f0 100%);
}
.page > li:nth-child(5) .page-inner {
  background: linear-gradient(105deg, #e2dbd0 0%, #faf6ee 100%);
}

/* ==========================================================================
   Book Hover Zone (for controlled interactions)
   ========================================================================== */

.book-hover-zone {
  display: inline-block;
  vertical-align: top;
  margin: 0;
  box-sizing: border-box;
}

@media (hover: none) {
  .book-hover-zone {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .hardcover-front,
  .page > li {
    transition-duration: 0.01ms !important;
  }
}
