/* paper-viewer.css — modal PDF viewer (scroll + spread) for engineering papers
   Visual language: warm paper + sumi ink + seal red, matched to the rest of
   the site. ESC hint and core typography reuse tokens from styles.css. */

.pv-root {
  position: fixed; inset: 0; z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.32s ease;
}
.pv-root.is-open {
  pointer-events: auto;
  opacity: 1;
}
body.pv-locked { overflow: hidden; }

.pv-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 18, 14, 0.86);
  backdrop-filter: blur(14px) saturate(0.9);
  -webkit-backdrop-filter: blur(14px) saturate(0.9);
}

.pv-shell {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
}

/* ── Top bar ─────────────────────────────────────────── */
.pv-topbar {
  position: relative;
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 24px;
  flex: 0 0 auto;
}
.pv-topbar-left,
.pv-topbar-right {
  display: flex; align-items: center; gap: 14px;
}
.pv-badge {
  font-family: var(--mono);
  font-size: 10px; letter-spacing: 0.18em; font-weight: 600;
  color: #d9a39a;
  background: rgba(139, 26, 26, 0.22);
  border: 1px solid rgba(139, 26, 26, 0.32);
  padding: 4px 9px;
  border-radius: 2px;
}
.pv-doc-title {
  font-family: var(--serif-display, 'Cormorant Garamond', serif);
  font-style: italic;
  font-size: 15px;
  color: #c8bfb0;
  letter-spacing: 0.01em;
}
.pv-close {
  background: none; border: none;
  color: #c8bfb0; font-size: 30px; line-height: 1;
  font-family: var(--sans, 'Helvetica Neue', sans-serif);
  font-weight: 200;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.2s, transform 0.2s;
}
.pv-close:hover { color: #ffffff; transform: scale(1.08); }

/* Reader.css already styles .esc-hint; tone it for dark backdrop */
.pv-esc-hint { color: rgba(200, 191, 176, 0.7); }
.pv-esc-hint .esc-key {
  border-color: rgba(200, 191, 176, 0.32);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(200, 191, 176, 0.85);
}
.pv-esc-hint .esc-lbl { color: rgba(200, 191, 176, 0.6); }

/* ── Side nav arrows (only shown in spread mode) ─────── */
.pv-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: #c8bfb0;
  font-size: 22px; line-height: 1;
  cursor: pointer;
  transition: background 0.22s, color 0.22s, transform 0.22s, opacity 0.22s;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
}
.pv-root.is-spread .pv-nav { opacity: 1; pointer-events: auto; }
.pv-nav:hover {
  background: rgba(139, 26, 26, 0.34);
  border-color: rgba(139, 26, 26, 0.48);
  color: #ffffff;
}
.pv-nav-prev { left: 22px; }
.pv-nav-next { right: 22px; }

/* ── Stage (page area) ───────────────────────────────── */
.pv-stage {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden auto;
  scroll-behavior: smooth;
  padding: 0 24px 24px;
  /* Faint cream backdrop tint behind the dark backdrop where pages sit */
}
.pv-root.is-spread .pv-stage {
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  padding: 8px 24px 24px;
}

.pv-pages {
  display: flex; flex-direction: column;
  align-items: center;
  gap: 22px;
  padding-top: 12px;
  padding-bottom: 96px; /* leave room for the bottom bar */
  min-height: 100%;
}
.pv-root.is-spread .pv-pages {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  width: 100%;
}

/* Individual page card */
.pv-page {
  position: relative;
  background: #ffffff;
  border-radius: 2px;
  box-shadow:
    0 22px 60px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  /* Fallback while canvas hasn't been rendered yet */
  min-height: 280px;
  width: min(820px, calc(100vw - 56px));
  aspect-ratio: 1 / 1.41; /* approx A4; replaced once rendered */
  display: flex; align-items: stretch; justify-content: center;
}
.pv-root.is-spread .pv-page {
  /* Width/height come from the canvas's explicit JS-set pixel sizes.
     Don't stretch in CSS — spread fits to stage via targetPageCssWidth. */
  width: auto;
  height: auto;
  flex: 0 0 auto;
}
.pv-canvas {
  display: block;
  width: 100%; height: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none; /* extra defence against drag-save */
}
.pv-root.is-spread .pv-canvas {
  /* JS sets explicit pixel width/height for spread fit; don't override. */
  width: auto;
  height: auto;
}
.pv-page-num {
  position: absolute;
  bottom: 10px; right: 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: rgba(60, 50, 40, 0.32);
  pointer-events: none;
}
.pv-page.is-rendered { background: #ffffff; }

/* Spread-specific page positioning: tiny visible gutter between two pages */
.pv-page.is-spread-left {
  border-radius: 3px 1px 1px 3px;
  box-shadow:
    -16px 22px 60px rgba(0, 0, 0, 0.55),
    inset -2px 0 6px rgba(0, 0, 0, 0.06);
}
.pv-page.is-spread-right {
  border-radius: 1px 3px 3px 1px;
  box-shadow:
    16px 22px 60px rgba(0, 0, 0, 0.55),
    inset 2px 0 6px rgba(0, 0, 0, 0.06);
}

/* ── Loading / error ─────────────────────────────────── */
.pv-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  pointer-events: none;
  z-index: 2;
}
.pv-loading-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent, #8b1a1a);
  opacity: 0.6;
  animation: pv-bounce 1.1s ease-in-out infinite;
}
.pv-loading-dot:nth-child(2) { animation-delay: 0.15s; }
.pv-loading-dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes pv-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1.0); opacity: 1; }
}
.pv-error {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #d9a39a;
  background: rgba(139, 26, 26, 0.18);
  border: 1px solid rgba(139, 26, 26, 0.34);
  padding: 10px 16px;
  border-radius: 3px;
}

/* ── Bottom bar ──────────────────────────────────────── */
.pv-bottombar {
  position: absolute; bottom: 22px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  z-index: 5;
  background: rgba(20, 18, 14, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 30px;
  padding: 6px 10px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.pv-counter {
  display: flex; align-items: center; gap: 5px;
  padding: 0 12px 0 6px;
  font-family: var(--mono, 'JetBrains Mono', monospace);
  font-size: 12px;
  border-right: 1px solid rgba(255, 255, 255, 0.10);
}
.pv-counter-cur { color: #ffffff; font-weight: 600; }
.pv-counter-sep, .pv-counter-tot { color: rgba(200, 191, 176, 0.55); }

/* Mode toggle — segmented control */
.pv-mode {
  display: flex; align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 22px;
  padding: 3px;
  gap: 2px;
}
.pv-mode-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent;
  border: none;
  border-radius: 18px;
  padding: 5px 11px 5px 9px;
  font-family: var(--mono, 'JetBrains Mono', monospace);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: rgba(200, 191, 176, 0.7);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.pv-mode-btn:hover { color: #ffffff; }
.pv-mode-btn.is-active {
  background: rgba(139, 26, 26, 0.42);
  color: #ffffff;
}
.pv-mode-glyph {
  display: inline-flex; flex-direction: column;
  width: 12px; height: 12px;
  gap: 1px;
}
.pv-mode-glyph > span {
  flex: 1;
  background: currentColor;
  opacity: 0.7;
  border-radius: 1px;
}
.pv-mode-glyph-spread {
  flex-direction: row;
  gap: 2px;
}
.pv-mode-glyph-spread > span {
  flex: 1;
  height: 100%;
}

/* Zoom controls */
.pv-zoom-group {
  display: flex; align-items: center; gap: 4px;
  padding-left: 6px;
  border-left: 1px solid rgba(255, 255, 255, 0.10);
}
.pv-zoom-btn {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 50%;
  color: #c8bfb0;
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.pv-zoom-btn:hover {
  background: rgba(139, 26, 26, 0.32);
  border-color: rgba(139, 26, 26, 0.48);
  color: #ffffff;
}
.pv-zoom-val {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: #c8bfb0;
  min-width: 38px;
  text-align: center;
}

/* ── Mobile ──────────────────────────────────────────── */
@media (max-width: 720px) {
  .pv-topbar { padding: 14px 14px; }
  .pv-doc-title { display: none; }
  .pv-stage { padding: 0 12px 24px; }
  .pv-page { width: calc(100vw - 28px); }
  .pv-bottombar {
    gap: 8px;
    padding: 5px 8px;
    bottom: 14px;
  }
  .pv-mode-btn { padding: 4px 8px; font-size: 10px; }
  .pv-mode-btn .pv-mode-glyph { width: 10px; height: 10px; }
  .pv-zoom-btn { width: 24px; height: 24px; font-size: 14px; }
  .pv-zoom-val { min-width: 34px; font-size: 10px; }
  .pv-counter { font-size: 11px; padding: 0 8px 0 4px; }
  .pv-nav-prev { left: 8px; }
  .pv-nav-next { right: 8px; }
  .pv-nav { width: 40px; height: 40px; font-size: 20px; }
  /* Spread on mobile is cramped; default to scroll. */
  .pv-root.is-spread .pv-page { max-height: calc(100vh - 200px); }
}
