/* Paper pages (papers/*.html): slim top bar, contents on the left, paper in the middle, details on the right */

:root {
  --navy: #001626;
  --accent: #425f73;
  --light: #fefefd;
  --bg: #eef1f4;
  --bar-height: 56px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Open Sans', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--navy);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.paper-bar :focus-visible {
  outline-color: var(--light);
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Top bar: logo, viewer controls, link back to the homepage */
.paper-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: var(--bar-height);
  padding: 0 16px;
  color: var(--light);
  background: var(--navy);
}

.paper-bar-start {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: start;
}

.paper-bar-end {
  justify-self: end;
}

.paper-bar-logo img {
  display: block;
  height: 30px;
  width: auto;
}

.paper-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-inline-size: 32px;
  min-block-size: 32px;
  color: var(--light);
  font-weight: 600;
  white-space: nowrap;
}

.pdf-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pdf-sep {
  inline-size: 1px;
  block-size: 20px;
  margin: 0 6px;
  background: #ffffff40;
}

.pdf-page-input {
  inline-size: 3.5em;
  min-block-size: 30px;
  padding: 2px 4px;
  font: inherit;
  text-align: center;
  color: var(--navy);
  background: #ffffff;
  border: 1px solid transparent;
  border-radius: 4px;
  appearance: textfield;
}

.pdf-page-input::-webkit-inner-spin-button,
.pdf-page-input::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.paper-bar button {
  display: inline-grid;
  place-items: center;
  min-inline-size: 32px;
  min-block-size: 32px;
  padding: 0 8px;
  font: inherit;
  color: var(--light);
  background: transparent;
  border: 1px solid #ffffff4d;
  border-radius: 4px;
  cursor: pointer;
}

.paper-bar button:hover:not(:disabled) {
  background: #ffffff1f;
}

.paper-bar :disabled {
  opacity: .5;
  cursor: default;
}

.pdf-zoom-level {
  min-inline-size: 3.5em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.toc-toggle {
  display: none !important; /* shown below 1200px when the paper has contents */
}

/* Three-column layout */
.paper-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 300px;
  grid-template-areas: "toc viewer info";
  align-items: start;
  gap: 20px;
  padding: 20px;
}

.no-toc .paper-layout {
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-areas: "viewer info";
}

.no-toc .paper-toc {
  display: none;
}

.paper-info,
.paper-toc {
  position: sticky;
  top: calc(var(--bar-height) + 20px);
  max-height: calc(100dvh - var(--bar-height) - 40px);
  overflow-y: auto; /* no overscroll containment: once a column is at its end, the wheel scrolls the paper */
}

/* Right: title, authors, status and BibTeX */
.paper-info {
  grid-area: info;
  padding: 18px;
  background: #ffffff;
  border-radius: 6px;
  box-shadow: 0 1px 3px #00162626;
}

.paper-info h1 {
  margin: 0 0 10px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 19px;
  font-weight: 500;
  line-height: 1.3;
  text-wrap: pretty;
}

.paper-authors {
  margin: 0 0 6px;
}

.paper-authors a {
  font-weight: 600;
}

.paper-status {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--accent);
}

.paper-info > :last-child {
  margin-bottom: 0;
}

.paper-info .cite {
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid #e3e8ec;
}

/* Copy button sits on the "BibTeX" line, so the entry can use the full width of the column */
.paper-info .cite-copy-wrap {
  inset-block-start: -36px;
  inset-inline-end: 0;
}

.paper-info .cite-body pre {
  padding: 10px 12px;
  font-size: 11px;
  overflow-wrap: break-word;
}

/* Left: contents from the PDF's bookmarks */
.paper-toc {
  grid-area: toc;
  padding: 4px 0;
}

.paper-toc h2 {
  margin: 4px 10px 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
}

.toc-list,
.toc-list ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-list ol {
  padding-inline-start: 12px;
}

.toc-list button,
.toc-list .toc-label {
  display: block;
  inline-size: 100%;
  padding: 5px 10px;
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  text-align: start;
  color: var(--navy);
  background: transparent;
  border: 0;
  border-inline-start: 2px solid transparent;
  border-radius: 0 4px 4px 0;
}

.toc-list button {
  cursor: pointer;
}

.toc-list ol button {
  font-size: 12.5px;
  color: #2c4352;
}

.toc-list button:hover {
  background: #ffffffb3;
}

.toc-list button[aria-current] {
  font-weight: 600;
  color: var(--navy);
  background: #ffffff;
  border-inline-start-color: var(--accent);
}

/* Middle: the paper */
.pdf-viewer {
  grid-area: viewer;
  min-inline-size: 0;
}

.pdf-status {
  margin: 0;
  padding: 64px 16px;
  text-align: center;
  color: var(--accent);
}

/* Only scrolls sideways when a page is zoomed wider than the column */
.pdf-pages {
  overflow-x: auto;
  padding: 4px 8px 24px;
}

.pdf-pages-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  inline-size: max-content;
  min-inline-size: 100%;
}

.pdf-page {
  /* PDF.js text layer sizing, from pdfjs-dist 6.4.299 web/pdf_viewer.css (.pdfViewer .page) */
  --user-unit: 1;
  --total-scale-factor: calc(var(--scale-factor) * var(--user-unit));
  --scale-round-x: 1px;
  --scale-round-y: 1px;

  position: relative;
  flex: none;
  background: #ffffff;
  box-shadow: 0 1px 3px #00162630, 0 6px 18px #00162614;
  scroll-margin-top: calc(var(--bar-height) + 16px);
}

.pdf-page canvas {
  position: absolute;
  inset: 0;
  display: block;
  inline-size: 100%;
  block-size: 100%;
}

/* PDF.js text layer: invisible, selectable and searchable text on top of each page.
   Rules taken from pdfjs-dist 6.4.299 web/pdf_viewer.css (.textLayer), without the editor parts. */
.textLayer {
  color-scheme: only light;
  position: absolute;
  text-align: initial;
  inset: 0;
  overflow: clip;
  opacity: 1;
  line-height: 1;
  letter-spacing: normal;
  word-spacing: normal;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: CanvasText;
  z-index: 0;
  --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 :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  -webkit-user-select: text;
  user-select: text;
}

.textLayer > :not(.markedContent),
.textLayer .markedContent span:not(.markedContent) {
  z-index: 1;
  --font-height: 0;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  --scale-x: 1;
  --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}

.textLayer .markedContent {
  display: contents;
}

.textLayer span[role="img"] {
  -webkit-user-select: none;
  user-select: none;
  cursor: default;
}

.textLayer ::selection {
  background: rgba(0 0 255 / 0.25);
  background: color-mix(in srgb, AccentColor, transparent 50%);
  color: transparent;
}

.textLayer br::selection {
  background: transparent;
}

.textLayer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
}

.textLayer.selecting .endOfContent {
  top: 0;
}

/* Medium screens: contents become a drawer opened from the top bar */
@media (max-width: 1199px) {
  .paper-layout,
  .no-toc .paper-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-template-areas: "viewer info";
  }

  body:not(.no-toc) .toc-toggle {
    display: inline-grid !important;
  }

  .paper-toc {
    position: fixed;
    top: var(--bar-height);
    bottom: 0;
    left: 0;
    z-index: 25;
    inline-size: min(320px, 85vw);
    max-height: none;
    overscroll-behavior: contain; /* the open drawer keeps scrolling to itself */
    padding: 16px 8px;
    background: #ffffff;
    box-shadow: 4px 0 24px #00162633;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .2s ease, visibility .2s;
  }

  .paper-toc.is-open {
    transform: none;
    visibility: visible;
    /* visible at once when opening, so focus can move into the drawer right away */
    transition: transform .2s ease, visibility 0s;
  }

  .toc-list button:hover,
  .toc-list button[aria-current] {
    background: var(--bg);
  }
}

/* Small screens: details above the paper, compact top bar */
@media (max-width: 899px) {
  .paper-layout,
  .no-toc .paper-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "info" "viewer";
    gap: 16px;
    padding: 16px 12px;
  }

  .paper-info {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .paper-bar-logo {
    display: none;
  }

  .paper-back span {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .pdf-pages {
    padding: 0 0 24px;
  }
}

@media (max-width: 599px) {
  .paper-bar {
    gap: 8px;
    padding: 0 8px;
  }

  .pdf-controls {
    gap: 6px;
  }

  .pdf-page-label {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .pdf-sep,
  .pdf-zoom-level {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .paper-toc {
    transition: none;
  }
}
