/* ============================================================
   VerityLoft — LAYER 2: Research Paper
   Loads site-wide, but every rule is scoped to .vl-paper, so it
   only takes effect on pages you explicitly tag as papers.

   To turn a page into a paper:
     Page editor -> Page (sidebar) -> Advanced
       -> Additional CSS class(es) -> add:  vl-paper

   Requires vl-base.css to be loaded first (palette variables).
   ============================================================ */

.vl-paper {
  font-family: var(--vl-serif);
  font-size: 1.0625rem;
  line-height: 1.68;
  color: var(--vl-graphite);
  max-width: var(--vl-measure);
  margin-inline: auto;
  hanging-punctuation: first last;
  text-rendering: optimizeLegibility;
}

.vl-paper p { margin: 0 0 .75em; }

/* ---------- Paragraph indentation (journal convention) ----------
   The first paragraph after a heading, table, figure, list or quote sits
   flush left. Every RUN-ON paragraph takes a first-line indent. This is the
   standard used by academic journals and is what makes a wall of prose
   scannable — Section 1.2, with its four consecutive "The first / The second /
   The third / Additionally" paragraphs, is the clearest case.

   To revert to block paragraphs (indent off, wider gaps), delete this block
   and set `.vl-paper p { margin: 0 0 1.15em; }` above. */
.vl-paper p + p { text-indent: 1.6em; }

/* Never indent these — they are labels and lists, not running prose. */
.vl-paper .vl-table-caption,
.vl-paper .vl-figcaption,
.vl-paper .vl-references p,
.vl-paper blockquote p,
.vl-paper .vl-abstract p,
.vl-paper p:first-child,
.vl-paper li p,
.vl-paper p.vl-meta,
.vl-paper p.vl-runin { text-indent: 0; }

/* Title-block metadata lines (author, affiliation, ORCID, manuscript type) */
.vl-paper p.vl-meta {
  font-family: var(--vl-sans);
  font-size: .93rem;
  color: var(--vl-muted);
  margin: 0 0 .3em;
  text-align: left !important;
}
.vl-paper p.vl-meta strong { color: var(--vl-blue); }
.vl-paper p.vl-meta:last-of-type { margin-bottom: 1.4rem; }

/* A paragraph that merely restates a bold run-in label ("**Purpose.** …",
   "**Stream 1 —** …") reads better flush. */
.vl-paper p > strong:first-child { margin-left: -0.02em; }

/* Justify on wide screens only — justified text on narrow screens
   creates rivers of whitespace. */
@media (min-width: 60rem) {
  .vl-paper p { text-align: justify; hyphens: auto; }
}

/* ---------- Headings ---------- */
.vl-paper h2,
.vl-paper h3,
.vl-paper h4 {
  font-family: var(--vl-sans);
  color: var(--vl-blue);
  line-height: 1.25;
  scroll-margin-top: 5rem;      /* so anchor jumps clear sticky headers */
  text-wrap: balance;
}

.vl-paper h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 3rem 0 1rem;
  padding-bottom: .45rem;
  border-bottom: 2px solid var(--vl-blue);
  letter-spacing: -0.01em;
}

/* Gold tick marking each major section */
.vl-paper h2::before {
  content: "";
  display: block;
  width: 2.5rem;
  height: 3px;
  background: var(--vl-gold);
  margin-bottom: .7rem;
}

.vl-paper h3 {
  font-size: 1.22rem;
  font-weight: 700;
  margin: 2.1rem 0 .6rem;
}

.vl-paper h4 {
  font-size: 1.03rem;
  font-weight: 700;
  margin: 1.5rem 0 .4rem;
  color: var(--vl-graphite);
}

/* ---------- Links ---------- */
.vl-paper a {
  color: var(--vl-blue);
  text-decoration: none;
  background-image: linear-gradient(var(--vl-gold), var(--vl-gold));
  background-size: 100% 2px;
  background-repeat: no-repeat;
  background-position: 0 100%;
  transition: background-size .18s ease;
}
.vl-paper a:hover,
.vl-paper a:focus-visible {
  background-size: 100% 100%;
  color: var(--vl-blue);
}
.vl-paper a:focus-visible {
  outline: 2px solid var(--vl-gold-ink);
  outline-offset: 2px;
}

/* ---------- Title block ---------- */
.vl-paper > p:first-of-type strong:only-child { font-size: 1.05em; }

.vl-titleblock {
  border-top: 3px solid var(--vl-blue);
  border-bottom: 1px solid var(--vl-rule);
  padding: 1.25rem 0;
  margin-bottom: 2rem;
  font-family: var(--vl-sans);
  font-size: .93rem;
  color: var(--vl-muted);
}

/* ---------- Abstract ---------- */
.vl-abstract {
  background: var(--vl-blue);
  color: var(--vl-linen);
  padding: 1.6rem 1.8rem;
  border-radius: 3px;
  margin: 2rem 0 2.5rem;
  font-size: .99rem;
}
.vl-abstract strong { color: var(--vl-gold); }   /* 7.68:1 — passes */
.vl-abstract a { color: var(--vl-gold); background-image: none; text-decoration: underline; }

/* ---------- Blockquote (research questions) ---------- */
.vl-paper blockquote {
  margin: 1.6rem 0;
  padding: 1rem 1.3rem;
  background: var(--vl-gold-wash);
  border-left: 4px solid var(--vl-gold);
  font-size: .98rem;
  color: var(--vl-graphite);
}
.vl-paper blockquote p { text-align: left; margin-bottom: .6em; }
.vl-paper blockquote p:last-child { margin-bottom: 0; }

/* ---------- Tables ---------- */
/* JS wraps every table in .vl-table-scroll for horizontal overflow on mobile.
   45 tables at up to 6 columns will otherwise break the layout. */
.vl-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.2rem 0 1.6rem;
  border: 1px solid var(--vl-rule);
  border-radius: 3px;
  position: relative;
}
.vl-table-scroll[data-overflowing="true"]::after {
  content: "";
  position: absolute; inset: 0 0 0 auto;
  width: 2.5rem; pointer-events: none;
  background: linear-gradient(to right, rgba(250,248,244,0), rgba(250,248,244,.96));
}
.vl-table-scroll table { margin: 0; border: 0; }

.vl-paper table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--vl-sans);
  font-size: .82rem;
  line-height: 1.45;
  background: #fff;
}
.vl-paper thead th {
  background: var(--vl-blue);
  color: var(--vl-porcelain);
  font-weight: 600;
  text-align: left;
  vertical-align: bottom;
  padding: .6rem .75rem;
  border: 0;
  border-bottom: 2px solid var(--vl-gold);
  position: sticky; top: 0; z-index: 1;
}
.vl-paper tbody td {
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--vl-rule);
  vertical-align: top;
}
.vl-paper tbody tr:nth-child(even) td { background: rgba(230,226,218,.34); }
.vl-paper tbody tr:hover td { background: var(--vl-gold-wash); }
.vl-paper tbody tr:last-child td { border-bottom: 0; }

/* Table captions ("Table 1." ...) sit as a paragraph before the table */
.vl-table-caption {
  font-family: var(--vl-sans);
  font-size: .86rem;
  color: var(--vl-blue);
  margin: 1.8rem 0 .4rem;
  padding-left: .7rem;
  border-left: 3px solid var(--vl-gold);
  text-align: left !important;
}

/* ---------- Figures ---------- */
.vl-paper figure,
.vl-paper .wp-block-image { margin: 2rem 0; }
.vl-paper img {
  max-width: 100%; height: auto;
  border: 1px solid var(--vl-rule);
  border-radius: 3px;
  background: #fff;
}
.vl-zoomable { cursor: zoom-in; transition: box-shadow .18s ease; }
.vl-zoomable:hover { box-shadow: 0 0 0 3px var(--vl-gold); }

.vl-figcaption {
  font-family: var(--vl-sans);
  font-size: .84rem;
  color: var(--vl-muted);
  line-height: 1.5;
  margin-top: .6rem;
  text-align: left !important;
}

/* ---------- Reference list ---------- */
.vl-references p {
  padding-left: 2em;
  text-indent: -2em;          /* hanging indent, APA style */
  font-size: .95rem;
  text-align: left !important;
  margin-bottom: .75em;
}

/* ---------- In-text citation popovers ---------- */
.vl-cite {
  border-bottom: 1px dotted var(--vl-gold-ink);
  cursor: help;
}
.vl-cite[aria-expanded="true"] { background: var(--vl-gold-wash); }

.vl-popover {
  position: absolute;
  z-index: 60;
  max-width: min(30rem, 88vw);
  background: var(--vl-blue);
  color: var(--vl-linen);
  font-family: var(--vl-sans);
  font-size: .82rem;
  line-height: 1.5;
  padding: .7rem .85rem;
  border-radius: 4px;
  border-top: 3px solid var(--vl-gold);
  box-shadow: 0 8px 28px rgba(30,41,59,.28);
}

/* ---------- Table of contents ---------- */
.vl-toc {
  font-family: var(--vl-sans);
  font-size: .84rem;
  line-height: 1.4;
}
.vl-toc ol { list-style: none; margin: 0; padding: 0; }
.vl-toc li { margin: 0; }
.vl-toc a {
  display: block;
  padding: .3rem .6rem .3rem .8rem;
  color: var(--vl-muted);
  border-left: 2px solid var(--vl-rule);
  background-image: none;
  text-decoration: none;
}
.vl-toc a:hover { color: var(--vl-blue); border-left-color: var(--vl-gold); background: none; }
.vl-toc .is-sub a { padding-left: 1.6rem; font-size: .95em; }
.vl-toc a[aria-current="true"] {
  color: var(--vl-blue);
  font-weight: 600;
  border-left-color: var(--vl-gold);
  border-left-width: 3px;
  background: var(--vl-gold-wash);
}

/* Desktop: dock the TOC beside the article */
@media (min-width: 82rem) {
  .vl-toc-dock {
    position: fixed;
    top: 6rem; left: max(1rem, calc(50vw - 46rem));
    width: 17rem; max-height: 74vh; overflow-y: auto;
    padding-right: .5rem;
  }
  .vl-toc-dock::-webkit-scrollbar { width: 6px; }
  .vl-toc-dock::-webkit-scrollbar-thumb { background: var(--vl-rule); border-radius: 3px; }
}
@media (max-width: 81.99rem) {
  .vl-toc-dock {
    margin: 0 0 2rem; padding: 1rem 1.1rem;
    background: #fff; border: 1px solid var(--vl-rule); border-top: 3px solid var(--vl-gold);
    border-radius: 3px;
  }
  .vl-toc-dock summary {
    font-family: var(--vl-sans); font-weight: 600; color: var(--vl-blue);
    cursor: pointer; font-size: .9rem;
  }
}

/* ---------- Reading progress ---------- */
.vl-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--vl-gold); z-index: 90;
  transition: width .1s linear;
}

/* ---------- Heading anchor links ---------- */
.vl-anchor {
  margin-left: .4rem;
  font-size: .72em;
  color: var(--vl-rule);
  opacity: 0;
  background-image: none !important;
  transition: opacity .15s ease;
}
h2:hover .vl-anchor, h3:hover .vl-anchor,
.vl-anchor:focus-visible { opacity: 1; color: var(--vl-gold-ink); }

/* ---------- Utility bar (cite / top) ---------- */
.vl-actions {
  display: flex; flex-wrap: wrap; gap: .5rem;
  margin: 1.5rem 0 2rem;
  font-family: var(--vl-sans);
}
.vl-btn {
  font: inherit; font-size: .82rem; font-weight: 600;
  padding: .5rem .9rem;
  border: 1px solid var(--vl-blue);
  background: transparent; color: var(--vl-blue);
  border-radius: 3px; cursor: pointer;
  background-image: none !important;
  transition: background-color .15s ease, color .15s ease;
}
.vl-btn:hover { background: var(--vl-blue); color: var(--vl-porcelain); }
.vl-btn[data-state="done"] { background: var(--vl-gold); border-color: var(--vl-gold); color: var(--vl-blue); }

.vl-top {
  position: fixed; right: 1.25rem; bottom: 1.25rem;
  width: 2.75rem; height: 2.75rem; border-radius: 50%;
  background: var(--vl-blue); color: var(--vl-gold);
  border: 0; cursor: pointer; z-index: 80;
  display: grid; place-items: center; font-size: 1.1rem;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
  box-shadow: 0 4px 16px rgba(30,41,59,.25);
}
.vl-top[data-visible="true"] { opacity: 1; pointer-events: auto; }

/* ---------- Lightbox ---------- */
.vl-lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(30,41,59,.93);
  display: grid; place-items: center; padding: 2rem;
  cursor: zoom-out;
}
.vl-lightbox img {
  max-width: 100%; max-height: 92vh;
  border: 0; border-radius: 3px; background: #fff;
}
.vl-lightbox button {
  position: absolute; top: 1rem; right: 1rem;
  background: none; border: 1px solid var(--vl-gold); color: var(--vl-gold);
  width: 2.4rem; height: 2.4rem; border-radius: 50%; cursor: pointer; font-size: 1.1rem;
}

/* ---------- Motion & print ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media print {
  .vl-toc-dock, .vl-progress, .vl-top, .vl-actions, .vl-anchor,
  .vl-popover, nav, header, footer, .site-header, .site-footer { display: none !important; }
  .vl-paper { max-width: none; font-size: 10.5pt; color: #000; }
  .vl-paper h2 { border-bottom-color: #000; page-break-after: avoid; }
  .vl-paper h2::before { background: #000; }
  .vl-paper h3, .vl-paper h4 { page-break-after: avoid; }
  .vl-paper thead th { background: #eee !important; color: #000 !important; -webkit-print-color-adjust: exact; }
  .vl-table-scroll, .vl-paper table, .vl-paper figure { page-break-inside: avoid; }
  .vl-abstract { background: #f4f4f4 !important; color: #000 !important; border: 1px solid #999; }
  .vl-abstract strong { color: #000; }
  .vl-paper a { background-image: none; text-decoration: underline; }
  .vl-paper a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 8pt; color: #555; }
}
