/* Page layout. A single text column by default; from 1380px, a three-column grid
   (contents | text | margin notes) with the sticky table of contents on the left and the
   reading-progress bar under it (driven by js/post.js). */

.paper {
  max-width: calc(var(--measure) + 32px);
  margin: 0 auto;
  padding-block: 0 4rem;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.paper p {
  margin: 0;
  text-align: justify;
  /* text-wrap: pretty; */
  hyphens: auto;
  -webkit-hyphens: auto;
  overflow-wrap: break-word;
}

@media (max-width: 899px) {
  .paper p { text-align: left; }
  /* a formula that still cannot fit scrolls inside its paragraph, not the page */
  .paper p { overflow-x: auto; overflow-y: hidden; }
}

/* paragraphs are separated by an indent, as in LaTeX, not by a gap; LaTeX also indents
   the paragraph that follows a theorem or a proof */
.paper p + p, .thm + p, .proof + p, .fig + p { text-indent: 1.1em; }
.paper p.noindent { text-indent: 0; }
.paper .title-block p { text-indent: 0; }

/* ---------------------------------------------------------------- contents */
.toc { font-size: 0.95rem; line-height: 1.27; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0.35rem 0; }
.toc a { color: var(--fg); display: block; padding-left: 1.4em; text-indent: -1.4em; }
.toc a:hover { color: var(--ref); text-decoration: none; }
.toc-num { display: inline-block; min-width: 1.4em; color: var(--muted); text-indent: 0; }

/* wide screens: contents | text | margin notes.
   14.5 + 2.5 + 34 + 3 + 13 = 67rem = 1340px, plus the 16px gutters */
@media (min-width: 1380px) {
  .paper {
    max-width: none;
    display: grid;
    grid-template-columns: var(--toc) var(--toc-gap) minmax(0, var(--measure)) var(--margin-gap) var(--margin);
    justify-content: center;
  }
  .paper > * { grid-column: 3; }
  .paper > .title-block { grid-column: 1 / -1; }
  .toc {
    grid-column: 1;
    grid-row: 2 / span 100;
    align-self: start;
    position: sticky;
    top: 1.5rem;
    margin-top: 2.5rem;  /* = .sec margin-top, so it lines up with the first heading */
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    padding-bottom: 0.25rem;
  }
}
@media (max-width: 1379px) {
  .toc {
    border-top: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
    padding: 0.9rem 0;
    margin: 0 0 2.5rem;
  }
  .toc ol { columns: 2 14rem; column-gap: 2rem; }
  .toc li { break-inside: avoid; }
}

/* reading progress, below the contents in the sidebar */
.reading-progress { display: none; }
@media (min-width: 1380px) {
  .reading-progress {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 1.4rem;
    margin-top: 1.1rem;
  }
}
.progress-eye {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.3rem;
  height: 1.3rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.progress-eye:hover { color: var(--fg); }
.progress-eye:focus-visible { outline: 2px solid var(--ref); outline-offset: 2px; }
.progress-eye svg { width: 1.05rem; height: 1.05rem; }
.progress-eye .icon-eye-off,
.reading-progress.is-hidden .progress-eye .icon-eye { display: none; }
.reading-progress.is-hidden .progress-eye .icon-eye-off { display: block; }
.progress-bar {
  position: relative;
  flex: 1;
  height: 0.45rem;
  border: 1px solid var(--fg);
  background: var(--bg);
  transition: height 0.15s;
}
.reading-progress.is-hidden .progress-bar { visibility: hidden; }
.progress-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--fg); }
.progress-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  line-height: 1;
  color: #fff;
  mix-blend-mode: difference;
  opacity: 0;
  transition: opacity 0.15s;
}
.progress-bar:hover { height: 1.1rem; }
.progress-bar:hover .progress-label { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .progress-bar, .progress-label { transition: none; }
}

/* ---------------------------------------------------------------- theme switch */
.theme-toggle {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top, 0px));
  right: calc(0.75rem + env(safe-area-inset-right, 0px));
  z-index: 10;
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  opacity: 0.55;
  cursor: pointer;
  transition: opacity 0.15s, border-color 0.15s;
}
.theme-toggle:hover, .theme-toggle:focus-visible { opacity: 1; border-color: var(--rule); }
.theme-toggle:focus-visible { outline: 2px solid var(--ref); outline-offset: 2px; }
.theme-toggle svg { width: 1.05rem; height: 1.05rem; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
