/* Modal chrome — restrained, ink-on-bg, no boxy shadows. Reads --bg/--ink/etc from index.html. */

html.book-scroll-lock,
html.book-scroll-lock body {
  overflow: hidden;
}

.book-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}

/* UA rule: [hidden] { display: none } loses to `.book-modal { display: flex }`.
   Restore it explicitly so the modal actually hides when closed. */
.book-modal[hidden] {
  display: none;
}

.book-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.56);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

html.dark .book-backdrop {
  background: rgba(0, 0, 0, 0.76);
}

.book-modal[data-state="open"] .book-backdrop {
  opacity: 1;
}

.book-modal[data-state="closing"] .book-backdrop {
  opacity: 0;
  transition: opacity 180ms cubic-bezier(0.4, 0, 1, 1);
}

.book-panel {
  position: relative;
  background: var(--bg);
  color: var(--ink);
  max-width: 560px;
  width: 100%;
  margin: auto;
  padding: 2.5rem 2rem 2rem;
  border-radius: 6px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 280ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 1;
}

html.dark .book-panel {
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.book-modal[data-state="open"] .book-panel {
  opacity: 1;
  transform: translateY(0);
}

.book-modal[data-state="closing"] .book-panel {
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 180ms cubic-bezier(0.4, 0, 1, 1),
    transform 180ms cubic-bezier(0.4, 0, 1, 1);
}

.book-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 120ms ease-out, background 120ms ease-out;
}
.book-close:hover {
  color: var(--ink);
  background: var(--rule);
}
.book-close:focus-visible {
  outline: none;
  color: var(--ink);
  background: var(--rule);
  box-shadow: inset 0 -2px 0 var(--ink);
}

.book-close-x {
  display: block;
  font-size: 20px;
  font-weight: 400;
  margin-top: -2px;
}

/* ── Mobile: full-bleed panel ───────────────────────────── */
@media (max-width: 640px) {
  .book-modal {
    padding: 0;
    align-items: stretch;
  }
  .book-panel {
    max-width: none;
    border-radius: 0;
    min-height: 100dvh;
    padding: 3rem 1.5rem 2rem;
    box-shadow: none;
  }
  .book-close {
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    font-size: 22px;
  }
  .book-close-x {
    font-size: 24px;
  }
}

/* ── Full-page /book variant ────────────────────────────── */
.book-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
}
.book-page-inner {
  max-width: 520px;
  width: 100%;
}

@media (prefers-reduced-motion: reduce) {
  .book-backdrop,
  .book-panel {
    transition: opacity 120ms ease-out;
    transform: none !important;
  }
}
