@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Playfair+Display:ital,wght@1,400;1,500&display=swap");

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fcfcfc;
  --text: #1a1a18;
  --text-sec: #9a9a98;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family:
    "Inter",
    system-ui,
    -apple-system,
    sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Canvas ─────────────────────────────────────────── */

#canvas {
  display: block;
  position: fixed;
  inset: 0;
  cursor: grab;
  touch-action: none;
}

#canvas.dragging {
  cursor: grabbing;
}

/* ── UI Overlay ─────────────────────────────────────── */

#ui {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 24px 28px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 10;
}

#ui h1 {
  font-size: 15px;
  font-weight: 400;
  color: #000;
}

#ui .sub {
  font-size: 12px;
  opacity: 0.38;
  margin-top: 4px;
}

#ui .hint {
  font-size: 11px;
  opacity: 0.28;
  font-family: monospace;
  text-align: right;
}

/* ── Loader ─────────────────────────────────────────── */

#loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 200;
  gap: 16px;
  transition: opacity 0.5s ease;
}

#loader.hidden {
  opacity: 0;
  pointer-events: none;
}

#loader .spinner {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(26, 26, 24, 0.08);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Modal ─────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 8, 0.38);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 100;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-panel {
  position: relative;
  background: #fcfcfc;
  border-radius: 32px;
  box-shadow:
    0 32px 80px rgba(0, 0, 0, 0.12),
    0 4px 16px rgba(0, 0, 0, 0.04);

  display: flex;
  flex-direction: column;

  padding: 32px;

  max-width: 420px;
  width: 100%;
  height: 640px;

  overflow: hidden;

  transform: translateY(20px) scale(0.97);
  opacity: 0;

  transition:
    transform 0.4s cubic-bezier(0.32, 0.72, 0, 1),
    opacity 0.35s cubic-bezier(0.32, 0.72, 0, 1);

  --scroll-progress: 0;
}

.modal-backdrop.open .modal-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ── Close button ───────────────────────────────────── */

.modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  color: #999;
  z-index: 2;
}

/* ── Sticky header ─────────────────────────────────── */

.modal-sticky {
  position: relative;
  flex-shrink: 0;

  /* Shrink more on scroll so the quotes sit closer to the book.
     At full scroll this now lands around the book height. */
  height: calc(282px - (146px * var(--scroll-progress)));

  display: flex;
  flex-direction: column;
  /* Center content horizontally by default; we translate the cover left via a
     computed CSS variable as the user scrolls. */
  align-items: center;

  overflow: hidden;
}

/* ── Cover ─────────────────────────────────────────── */

.modal-cover-wrap {
  width: calc(200px - (64px * var(--scroll-progress)));
  height: calc(200px - (64px * var(--scroll-progress)));

  /* X shift is computed in JS per panel width so the
     cover lands flush to the left padding on scroll end. */
  --cover-shift-x: -134px; /* 24px further left at scroll end */
  --cover-shift-y: -16px; /* slight nudge upwards on scroll */
  transform: translateX(calc(var(--cover-shift-x) * var(--scroll-progress)))
    translateY(calc(var(--cover-shift-y) * var(--scroll-progress)));

  transform-origin: center top;
}

.modal-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Title + author ────────────────────────────────── */

.modal-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;

  overflow: hidden;

  opacity: calc(1 - (var(--scroll-progress) * 1.6));

  transform: scale(calc(1 - (0.06 * var(--scroll-progress))))
    translateY(calc(-8px * var(--scroll-progress)));

  max-height: calc(120px * (1 - (var(--scroll-progress) * 1.4)));
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 22px;
  text-align: center;
  white-space: normal;
  word-break: break-word;
}

.modal-author {
  font-size: 13px;
  color: #9c9c9c;
  text-align: center;
}

/* ── Scroll area ───────────────────────────────────── */

.modal-scroll {
  flex: 1;
  overflow-y: auto;
  margin-top: 12px;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
}

.modal-scroll::-webkit-scrollbar {
  display: none;
}

/* ── Quotes ────────────────────────────────────────── */

.modal-quotes {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-quote {
  background: #ebebeb;
  border-radius: 14px;
  padding: 20px;

  font-family: "Playfair Display", serif;
  font-style: italic;

  font-size: 16px;
  line-height: 24px;
}

.modal-quote p {
  margin: 0;
}

.modal-quote p + p {
  margin-top: 12px;
}

.modal-quotes-empty {
  display: none;
  text-align: center;
  color: #9c9c9c;
  padding: 20px 24px;
  font-size: 12px;
  line-height: 1.5;
  margin-top: auto;
  margin-bottom: auto;
}

.modal-quotes:empty + .modal-quotes-empty {
  display: block;
}

/* ── Mobile ────────────────────────────────────────── */

@media (max-width: 640px) {
  .modal-panel {
    border-radius: 16px;
  }
}

@media (max-width: 540px) {
  .modal-panel {
    max-width: 340px;
    padding: 24px;
  }

  .modal-sticky {
    height: calc(262px - (130px * var(--scroll-progress)));
  }

  .modal-cover-wrap {
    /* On mobile, scale in place — no translate to avoid overflow/clipping */
    transform: none;
  }

  #ui {
    padding: 18px 20px;
  }

  #ui .hint {
    display: none;
  }
}

@media (hover: none) and (pointer: coarse) {
  #ui .hint::after {
    content: "swipe to explore";
  }
}

@media (hover: hover) {
  #ui .hint::after {
    content: "drag to explore";
  }
}
