/* Shared paper typesetting. Template files override metrics and voice. */

@page {
  size: letter;
  margin: 1in;
}

html {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

body.paper {
  margin: 0;
  color: #000;
  background: #fff;
  font-size: 10pt;
  line-height: 1.2;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  text-rendering: optimizeLegibility;
  orphans: 2;
  widows: 2;
}

/* ---- title block -------------------------------------------------------- */
.title-block { text-align: center; hyphens: manual; }
.title-block .title { margin: 0; font-weight: bold; line-height: 1.2; }
/* Invisible copy of margin-box text so its font faces load before printing (see templates.ts). */
.mb-preload { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: hidden; visibility: hidden; white-space: nowrap; font-weight: normal; font-style: normal; }
.title-block sup { font-size: 0.7em; line-height: 0; }
.abstract h2 { margin: 0; }

/* ---- body flow ---------------------------------------------------------- */
.paper-main p { margin: 0; text-indent: 1.5em; }
.paper-main h2 + p,
.paper-main h3 + p,
.paper-main h4 + p,
.paper-main .equation + p,
.paper-main .appendix-start + h2 + p,
.paper-main p:first-child,
.paper-main .thm p:first-child,
.paper-main li p,
.paper-main blockquote p { text-indent: 0; }

.paper-main h2, .paper-main h3, .paper-main h4 {
  text-align: left;
  hyphens: manual;
  break-after: avoid;
  page-break-after: avoid;
  font-weight: bold;
  line-height: 1.2;
}
.paper-main h2 { font-size: 1.44em; margin: 1.1em 0 0.55em; }
.paper-main h3 { font-size: 1.2em; margin: 1em 0 0.45em; }
.paper-main h4 { font-size: 1em; margin: 0.9em 0 0.4em; }
.secnum { margin-right: 1em; }

.runin { font-weight: bold; }
.runin-p { text-indent: 0 !important; margin-top: 0.6em !important; }

.paper-main ul, .paper-main ol { margin: 0.4em 0; padding-left: 2em; }
.paper-main li { margin: 0.15em 0; }
.paper-main li > p { text-indent: 0; }
.paper-main blockquote { margin: 0.5em 2em; }

.paper-main a, .paper-head a { color: inherit; text-decoration: none; }
.sc { font-variant: small-caps; }
code, pre { font-family: "Inconsolata", "CMU Typewriter Text", monospace; font-size: 0.95em; }
pre.code {
  margin: 0.6em 0 0.6em 1.5em;
  white-space: pre-wrap;
  text-align: left;
  font-size: 0.85em;
  line-height: 1.25;
  break-inside: avoid;
}

/* ---- math --------------------------------------------------------------- */
.katex { font-size: 1.05em; text-indent: 0; }
/* Inline math must not open up the line: TeX only adds \lineskip when a formula's
   height + depth exceed the baselineskip. Zero the inline box's own leading and let
   the struts overhang by a quarter em above and below before the line grows. */
:not(.katex-display) > .katex { line-height: 0; }
/* A formula and the punctuation after it break as one word (markdown.ts wraps them). */
.nobr { white-space: nowrap; }
:not(.katex-display) > .katex .base,
:not(.katex-display) > .katex .katex-base { margin-top: -0.25em; margin-bottom: -0.25em; }
.equation { margin: 0.55em 0; break-inside: avoid; }
.equation .katex-display { margin: 0; }
.katex-display > .katex { text-align: center; }
/* An equation number that does not fit beside its equation goes on its own line below, flush
   right, as amsmath sets it (src/render/fit.ts adds the class). */
.equation.eq-tag-below .katex-display > .katex > .katex-html > .katex-tag,
.equation.eq-tag-below .katex-display > .katex > .katex-html > .tag { position: static; display: block; text-align: right; }
@media print {
  /* Anything that reaches past the right edge of the text block makes Chrome shrink every page to
     fit it. Clip the blocks that can overflow at their own edge instead; the layout lint reports
     them. (Equations are first set smaller to fit, by src/render/fit.ts.) */
  .paper-main .equation, .paper-main figure.table, .paper-main pre.code, .paper-main figure.algorithm { overflow-x: clip; }
}

/* ---- figures and tables ------------------------------------------------- */
figure { margin: 1em 0; break-inside: avoid; page-break-inside: avoid; text-indent: 0; }
.figure-body { text-align: center; }
.figure-body > svg, .figure-body > img {
  max-width: calc(100% * var(--fig-w, 1));
  height: auto;
  display: inline-block;
}
.figure-body > img { width: calc(100% * var(--fig-w, 1)); }
figcaption {
  display: table;
  margin: 0.5em auto 0;
  text-align: justify;
  hyphens: auto;
  font-size: 0.95em;
}
figure.table figcaption { margin: 0 auto 0.45em; }
.missing-figure { border: 1px solid #000; padding: 2em; font-family: monospace; }

figure.table { text-align: center; }
figure.table table {
  margin: 0 auto;
  border-collapse: collapse;
  border-top: 0.08em solid #000;
  border-bottom: 0.08em solid #000;
  font-size: 0.9em;
  line-height: 1.25;
  text-align: left;
  hyphens: manual;
}
figure.table thead th { border-bottom: 0.05em solid #000; font-weight: normal; }
figure.table th, figure.table td { padding: 0.18em 0.55em; vertical-align: baseline; }
figure.table tbody tr:first-child td { padding-top: 0.35em; }
figure.table tbody tr:last-child td { padding-bottom: 0.3em; }
figure.table thead tr:last-child th { padding-bottom: 0.3em; }
figure.table thead tr:first-child th { padding-top: 0.3em; }
figure.table td p, figure.table th p { text-indent: 0; }

.span-full { column-span: all; -webkit-column-span: all; }

/* ---- theorems ----------------------------------------------------------- */
.thm { margin: 0.7em 0; }
.thm p { text-indent: 0; }
.thm p + p { text-indent: 1.5em; }
.thm-italic p { font-style: italic; }
.thm-italic .thm-head, .thm-italic .thm-note { font-style: normal; }
.thm-proof p { font-style: normal; }
.qed { float: right; margin-left: 1em; }

/* ---- algorithms --------------------------------------------------------- */
figure.algorithm {
  border-top: 0.08em solid #000;
  border-bottom: 0.08em solid #000;
  padding: 0;
  text-align: left;
  hyphens: manual;
}
.alg-caption { border-bottom: 0.05em solid #000; padding: 0.2em 0 0.25em; }
.alg-body { padding: 0.25em 0 0.3em; font-size: 0.95em; line-height: 1.3; }
.alg-line { display: flex; align-items: baseline; }
.alg-no { flex: 0 0 1.8em; text-align: right; padding-right: 0.5em; font-size: 0.85em; }
.alg-code { flex: 1; }
.alg-comment { margin-left: auto; padding-left: 1em; white-space: nowrap; }

/* ---- back matter -------------------------------------------------------- */
.acknowledgments { margin-top: 1em; }
.endnotes ol, .references ol { list-style: none; padding: 0; margin: 0; }
.endnotes { font-size: 0.9em; }
.endnotes li { margin: 0.2em 0; }
.endnotes ol { counter-reset: fn; }
.endnotes li { counter-increment: fn; padding-left: 1.5em; text-indent: -1.5em; }
.endnotes li::before { content: counter(fn) ". "; }
.fnref a { color: inherit; }

.references { font-size: 0.9em; text-align: left; hyphens: manual; }
.references.numbered li { display: grid; grid-template-columns: max-content 1fr; column-gap: 0.6em; margin: 0 0 0.35em; break-inside: avoid; }
.references.numbered .ref-label { text-align: right; min-width: 1.6em; }
/* Several templates lay the list out as one grid (li { display: contents }); Chrome does not move
   the next row down when a grid item breaks across a page or column, so the two print over each
   other. Keep each entry whole instead. */
.references.numbered .ref-label, .references.numbered .ref-text { break-inside: avoid; }
.references.author-year li { padding-left: 1.5em; text-indent: -1.5em; margin: 0 0 0.4em; }
.references .url { font-family: "Inconsolata", monospace; font-size: 0.95em; word-break: break-all; }
.refs-rule { border: 0; border-top: 0.05em solid #000; width: 30%; margin: 1.2em auto 0.8em; }

.cite-missing, .xref-missing { font-weight: bold; }

/* ---- screen (HTML view) ------------------------------------------------- */
@media screen {
  body.paper { max-width: 46em; margin: 0 auto; padding: 3em 1.5em 5em; font-size: 12pt; }
  .paper-main { column-count: 1 !important; }
  figure.table, .equation, .katex-display, pre.code { max-width: 100%; overflow-x: auto; overflow-y: hidden; }
  .figure-body > svg { max-width: 100%; height: auto; }
}
@media screen and (max-width: 600px) {
  body.paper { padding: 1.5em 1em 3em; font-size: 11pt; }
  .t-mlconf .abstract, .t-article .abstract, .t-physrev .abstract { margin-left: 0; margin-right: 0; }
}
