/* Writing Studio — cinematic "enter the book" transition (shelf → book page).
   Self-contained. To remove: delete this file, js/book-anim.js, the matching
   <link> and <script> in index.html, and the bookAnim hooks in js/app.js.
   Animate transform and opacity only. Gated by JS (WS.motion() === 'full'). */

.ba {
  position: fixed;
  inset: 0;
  z-index: 280;
  pointer-events: none;
}
.ba.is-on { pointer-events: auto; }
.ba[hidden] { display: none !important; }

.ba-dim {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 16, .55);
  opacity: 0;
  will-change: opacity;
}
html[data-theme=dark] .ba-dim { background: rgba(4, 5, 8, .62); }
/* Light blur only when the device can afford it (JS adds .ba-blur). */
.ba.ba-blur.is-on .ba-dim {
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.ba-stage {
  position: absolute;
  inset: 0;
  perspective: 1400px;
  perspective-origin: 50% 46%;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

.ba-book {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  transform-style: preserve-3d;
  will-change: transform, opacity;
  pointer-events: none;
}

.ba-shadow {
  position: absolute;
  left: 6%;
  right: -18%;
  top: 22%;
  bottom: -18%;
  background: radial-gradient(ellipse at 50% 62%, rgba(0, 0, 0, .48), rgba(0, 0, 0, 0) 68%);
  opacity: .3;
  transform: translateZ(-60px) scale(.86);
  will-change: transform, opacity;
  pointer-events: none;
}

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

.ba-stage { z-index: 1; }
.ba-dim { z-index: 0; }
.ba-leaf {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #f3eadc;
  background-image:
    linear-gradient(90deg, rgba(0, 0, 0, .10) 0, rgba(0, 0, 0, 0) 10%),
    linear-gradient(180deg, #f8f3ea 0%, #efe6d4 100%);
  box-shadow: 0 10px 28px -12px rgba(0, 0, 0, .45);
}
.ba-left {
  left: -100%;
  z-index: 3;
  border-radius: 7px 0 0 7px;
  transform-origin: 100% 50%;
  transform: rotateY(90deg);
  background-color: #f3eadc;
  background-image:
    linear-gradient(270deg, rgba(0, 0, 0, .12) 0, rgba(0, 0, 0, 0) 11%),
    linear-gradient(180deg, #f8f3ea 0%, #efe6d4 100%);
  will-change: transform;
}
.ba-right {
  z-index: 1;
  border-radius: 0 7px 7px 0;
  transform-origin: 0 50%;
  box-shadow:
    inset 8px 0 14px -8px rgba(0, 0, 0, .18),
    0 10px 28px -12px rgba(0, 0, 0, .45);
}
.ba-left {
  box-shadow:
    inset -8px 0 14px -8px rgba(0, 0, 0, .18),
    0 10px 28px -12px rgba(0, 0, 0, .45);
}

.ba-page-inner {
  position: absolute;
  inset: 9% 10% 10%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: .4em;
  color: #3c3226;
  pointer-events: none;
}
.ba-kicker {
  font: 600 max(8px, 7cqw) / 1.3 var(--font-ui);
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: .62;
}
.ba-title {
  font: 600 max(16px, 16cqw) / 1.05 var(--font-head);
  letter-spacing: -.02em;
}
.ba-sub {
  font: 500 max(8px, 7.4cqw) / 1.3 var(--font-ui);
  opacity: .7;
}
.ba-left, .ba-right { container-type: inline-size; }

.ba-sheen {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 30%, rgba(255, 255, 255, .38) 48%, transparent 66%);
  transform: translateX(-120%);
  opacity: 0;
  will-change: transform, opacity;
}

.ba-cover {
  position: absolute;
  inset: 0;
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  will-change: transform;
  z-index: 2;
}
.ba-cover-front,
.ba-cover-back {
  position: absolute;
  inset: 0;
  border-radius: 3px 7px 7px 3px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.ba-cover-front {
  background: var(--book, #33506B);
  box-shadow:
    0 1px 1px rgba(0, 0, 0, .25),
    inset 0 0 0 1px rgba(255, 255, 255, .07);
}
.ba-cover-front img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ba-cover-front::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, .32) 0, rgba(0, 0, 0, .1) 4.5%, rgba(255, 255, 255, .12) 6.5%, rgba(255, 255, 255, 0) 11%);
}
.ba-cover-back {
  /* Hidden: once the cover swings past 90°, the left page is what you read. */
  display: none;
  transform: rotateY(180deg);
  background:
    linear-gradient(270deg, rgba(0, 0, 0, .16) 0, rgba(0, 0, 0, 0) 12%),
    linear-gradient(180deg, #f3eadc, #e7dcc8);
  box-shadow: inset 0 0 0 1px rgba(90, 70, 40, .12);
}

/* Kill hover/active motion so FLIP can measure the book's resting slot. */
.book.ba-rest,
html[data-motion=on] .book.ba-rest,
html[data-motion=on] .book.ba-rest:is(:hover, :focus-visible, :active) {
  transform: none !important;
  transition: none !important;
}

/* Hide the real cover as soon as the clone exists. Keep the layout box so the
   shelf leaves an empty gap, with only the faint plank contact shadow. */
.book.ba-ghost .book-cover,
.book.ba-ghost > * {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}
.book.ba-ghost::before { opacity: 0 !important; }
.book.ba-ghost::after { opacity: .45; }
.mini-book.ba-ghost { visibility: hidden; opacity: 0; }

/* No hover tooltips or a leftover exam "Open" banner during the flight. */
html.ba-playing .book { pointer-events: none; }
html.ba-playing .exam-banner {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .ba { display: none !important; }
}
html[data-motion=off] .ba { display: none !important; }
