:root {
  --ink: #1a1814;
  --ink-light: #4a453d;
  --ink-muted: #8a847a;
  --paper: #f8f6f2;
  --paper-warm: #f2ede5;
  --rule: #ddd9d2;
  --rule-light: #eae6df;
  --amber: #d4830a;
  --amber-soft: rgba(212, 131, 10, 0.18);
  --amber-glow: rgba(212, 131, 10, 0.32);
  --danger: #b03030;
  --danger-soft: rgba(176, 48, 48, 0.08);
  --font-serif: 'Libre Baskerville', Georgia, serif;
  --font-sans: 'DM Sans', system-ui, sans-serif;
}

/* ── PDF viewer column ────────────────────────────────────────── */
.viewer-column {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  background: #6b6660;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: #4a4540 #3a3530;
}
.viewer-column::-webkit-scrollbar { width: 8px; }
.viewer-column::-webkit-scrollbar-track { background: #3a3530; }
.viewer-column::-webkit-scrollbar-thumb { background: #5a5550; border-radius: 4px; }

.pdf-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 24px 60px;
  gap: 12px;
  min-height: 100%;
}
/* `.pdf-viewer`/`.reader-viewer` set `display` unconditionally above, which
   otherwise beats the UA [hidden] default (author CSS wins over UA CSS
   regardless of specificity) — toggling the `hidden` property alone would
   silently do nothing. */
.pdf-viewer[hidden], .reader-viewer[hidden] { display: none; }

.viewer-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #c0bab4;
  padding: 80px 0;
  font-size: 14px;
}
.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── PDF page wrapper ─────────────────────────────────────────── */
.pdf-page-wrapper {
  position: relative;
  background: white;
  box-shadow: 0 2px 12px rgba(0,0,0,0.35), 0 0 0 1px rgba(0,0,0,0.12);
  line-height: 0; /* prevent gap under canvas */
  transition: box-shadow 0.2s;
}
.pdf-page-wrapper.flash-page {
  box-shadow: 0 2px 20px rgba(212,131,10,0.5), 0 0 0 2px var(--amber);
}

/* ── PDF.js canvas ────────────────────────────────────────────── */
.pdf-page-wrapper canvas {
  display: block;
}

/* ── Text layer (PDF.js) ──────────────────────────────────────── */
/* pdf.js ≥4 sizes the layer and every span through CSS custom properties
   (--total-scale-factor, --font-height, --scale-x, …); these variable
   definitions are load-bearing — without them spans collapse to 0px and
   text selection silently stops working. viewer.js sets --scale-factor per
   page render; pdf.js sets --min-font-size and the per-span variables. */
.textLayer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  line-height: 1;
  text-align: initial;
  transform-origin: 0 0;
  z-index: 0;
  --user-unit: 1;
  --total-scale-factor: calc(var(--scale-factor) * var(--user-unit));
  --scale-round-x: 1px;
  --scale-round-y: 1px;
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
}
.textLayer span,
.textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  /* Allow text selection */
  user-select: text;
  -webkit-user-select: text;
}
.textLayer > span:not(.markedContent),
.textLayer .markedContent span:not(.markedContent) {
  z-index: 1;
  --font-height: 0;
  --scale-x: 1;
  --rotate: 0deg;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.textLayer .markedContent {
  display: contents;
}
.textLayer ::selection {
  background: rgba(70, 130, 200, 0.3);
  color: transparent;
}

/* ── Reader mode ──────────────────────────────────────────────── */
.reader-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px 90px;
  min-height: 100%;
  background: var(--paper);
}
.reader-page-wrapper {
  width: 100%;
  max-width: 640px;
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
}
.reader-page-marker {
  display: block;
  font-family: var(--font-sans);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  text-align: center;
  margin: 28px 0 14px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  user-select: none;
  -webkit-user-select: none;
}
.reader-page-wrapper:first-child .reader-page-marker { margin-top: 0; border-top: none; padding-top: 0; }
.reader-page-wrapper.flash-page { animation: readerPageFlash 0.8s ease-out; }
@keyframes readerPageFlash {
  0%   { background: var(--amber-soft); }
  100% { background: transparent; }
}

.reader-block {
  display: block;
  margin: 0 0 14px;
  user-select: text;
  -webkit-user-select: text;
}
.reader-block-heading {
  font-weight: 700;
  font-size: 1.05em;
  margin-top: 22px;
}
.reader-block-list-item {
  margin-left: 1.4em;
}
.reader-block-empty {
  display: block;
  color: var(--ink-muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-style: italic;
  user-select: none;
  -webkit-user-select: none;
}

.reader-table-scroll {
  display: block;
  overflow-x: auto;
  margin: 14px 0 20px;
  -webkit-overflow-scrolling: touch;
}
.reader-table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.85em;
}
.reader-table td {
  border: 1px solid var(--rule);
  padding: 6px 9px;
  vertical-align: middle;
  text-align: center;
  white-space: nowrap;
}
.reader-table td:first-child {
  text-align: left;
  white-space: normal;
}
.reader-cell-bold { font-weight: 700; }
.reader-cell-italic { font-style: italic; }

/* ── Annotation highlights ────────────────────────────────────── */
.annotation-highlight {
  position: absolute;
  background: var(--amber-soft);
  border-bottom: 2px solid var(--amber);
  pointer-events: all;
  cursor: pointer;
  transition: background 0.15s;
  z-index: 5;
}
.annotation-highlight:hover {
  background: var(--amber-glow);
}
.annotation-highlight.flash-highlight {
  animation: highlightFlash 0.6s ease-out 2;
}
/* Reader mode highlights are real inline <mark> elements, not absolutely
   positioned overlays — reset the PDF-mode box model, keep the same colors. */
.annotation-highlight.is-inline {
  position: static;
  display: inline;
  border-bottom-width: 2px;
  font: inherit;
  color: inherit;
}
.deeplink-highlight {
  position: absolute;
  background: rgba(70, 130, 200, 0.28);
  border-bottom: 2px solid rgba(45, 100, 170, 0.9);
  pointer-events: none;
  z-index: 6;
  animation: deeplinkPulse 0.8s ease-in-out infinite alternate;
}
.deeplink-highlight.is-inline {
  position: static;
  display: inline;
  font: inherit;
  color: inherit;
}
@keyframes deeplinkPulse {
  from { background: rgba(70, 130, 200, 0.18); }
  to   { background: rgba(70, 130, 200, 0.42); }
}
@keyframes highlightFlash {
  0%   { background: var(--amber-glow); }
  50%  { background: rgba(212,131,10,0.5); }
  100% { background: var(--amber-soft); }
}


@media (max-width: 900px) {
  .pdf-viewer { padding: 10px 8px 90px; gap: 8px; }
  .reader-viewer { padding: 20px 18px 90px; }
}
/* Private/pending highlights are visually distinct from published ones */
.annotation-highlight.hl-private { border-bottom-style: dashed; background: rgba(138,132,122,0.16); border-bottom-color: var(--ink-muted); }
.annotation-highlight.hl-pending { border-bottom-style: dotted; }
.annotation-highlight.hl-rejected{ background: var(--danger-soft); border-bottom-color: var(--danger); }

@media (max-width: 900px) {
  .annotation-highlight,
  .annotation-highlight.is-inline {
    background: rgba(212, 131, 10, 0.28);
    border-bottom-width: 3px;
  }
  .annotation-highlight.hl-private {
    background: rgba(212, 131, 10, 0.22);
    border-bottom-color: var(--amber);
  }
}
