/* The site's look: simple and academic.  A white page, a contents column on every page, and a
   lightly tinted panel behind the text of a note, so the writing reads as a sheet on the page. */

:root {
  --bg: #ffffff;           /* the page */
  --paper: #f8f6f0;        /* behind the text of a note */
  --paper-edge: #ebe7dc;
  --fg: #1a1a1a;
  --muted: #666a70;
  --rule: #e1e1dc;
  --accent: #1a4f8b;
  --soft: #f1efe8;
  --measure: 43rem;
  --toc: 13.5rem;
  --serif: Charter, "Bitstream Charter", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }
/* No smooth scrolling: a jump to a section must land on it, and a smooth scroll aims at where the
   section was before the images and demos on the way had loaded. */
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--serif); font-size: 1.0625rem; line-height: 1.65; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

/* ---------------------------------------------------------------- frame */

.site-header, .site-footer, main { max-width: calc(var(--toc) + var(--measure) + 9rem); margin: 0 auto; padding: 0 1.5rem; }
.site-header { display: flex; justify-content: space-between; align-items: baseline; padding-top: 1.4rem; padding-bottom: 1rem; border-bottom: 1px solid var(--rule); font-family: var(--sans); }
.site-name { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; color: var(--fg); text-decoration: none; }
.site-header nav a { color: var(--muted); text-decoration: none; margin-left: 1.4rem; font-size: .95rem; }
.site-header nav a:hover, .site-header nav a[aria-current] { color: var(--fg); }
.site-header nav a[aria-current] { border-bottom: 2px solid var(--accent); padding-bottom: 2px; }
.site-footer { margin-top: 4rem; padding-top: 1rem; padding-bottom: 3rem; border-top: 1px solid var(--rule); color: var(--muted); font-family: var(--sans); font-size: .85rem; }

/* every page: a contents column beside the text */
.with-toc { display: grid; grid-template-columns: var(--toc) minmax(0, 1fr); gap: 2.5rem; align-items: start; padding-top: 2rem; }
.note-main { min-width: 0; max-width: calc(var(--measure) + 5rem); }
.toc-col { position: sticky; top: 1.25rem; max-height: calc(100vh - 2.5rem); overflow-y: auto; }
.toc { font-family: var(--sans); font-size: .875rem; line-height: 1.4; }
.toc-title { font-size: .72rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-bottom: .6rem; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--rule); }
.toc li a { display: block; padding: .22rem 0 .22rem .8rem; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; }
.toc li a:hover { color: var(--fg); }
.toc li a.here { color: var(--fg); border-left-color: var(--accent); }
.toc .toc-d1 a { font-weight: 600; color: var(--fg); }
.toc .toc-d3 a { padding-left: 1.6rem; font-size: .84rem; }
.toc .toc-d4 a { padding-left: 2.4rem; font-size: .84rem; }

@media (max-width: 62rem) {
  .with-toc { display: block; }
  .toc-col { position: static; max-height: none; margin-bottom: 1.5rem; padding: .8rem 1rem; border: 1px solid var(--rule); border-radius: 4px; }
}

/* ---------------------------------------------------------------- text */

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.9rem; margin: 0 0 .4rem; }
h2 { font-size: 1.4rem; margin: 2.4rem 0 .6rem; }
h3 { font-size: 1.13rem; margin: 1.8rem 0 .4rem; }
.note-header { margin-bottom: 1.5rem; }
.note-meta, .note-item-meta { color: var(--muted); font-family: var(--sans); font-size: .88rem; margin: 0; }
.tag { background: var(--soft); border-radius: 3px; padding: .05rem .4rem; }
.badge { font-family: var(--sans); font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; vertical-align: middle; border-radius: 3px; padding: .15rem .4rem; background: var(--soft); color: var(--muted); }
.badge-restricted { background: #f6e3c1; color: #7a4b00; }

/* the part where a note is written: a sheet of slightly different colour on the white page */
.layout-note .note-body { background: var(--paper); border: 1px solid var(--paper-edge); border-radius: 3px; padding: 1.6rem 2.4rem 2.2rem; }
.layout-note .note-body > :first-child { margin-top: .4rem; }
.layout-page .note-body > :first-child { margin-top: 0; }
@media (max-width: 40rem) { .layout-note .note-body { padding: 1rem 1.1rem 1.4rem; margin: 0 -.6rem; } }

.note-body > p { margin: 1rem 0; }
.note-body blockquote { margin: 1.2rem 0; padding: .1rem 1.1rem; border-left: 3px solid var(--rule); color: var(--muted); }
.note-body code { font-family: var(--mono); font-size: .88em; background: var(--soft); padding: .08em .3em; border-radius: 3px; }
.note-body pre { background: var(--soft); padding: .9rem 1rem; border-radius: 4px; overflow-x: auto; }
.note-body pre code { background: none; padding: 0; }
.layout-note .note-body code, .layout-note .note-body pre { background: #efece3; }

.math-display { margin: 1.3rem 0; overflow-x: auto; overflow-y: hidden; padding: .2rem 0; }
.math-error { color: #b3261e; font-family: var(--mono); font-size: .9em; }

.note-body table { display: block; width: max-content; max-width: 100%; overflow-x: auto; margin: 1.4rem auto; border-collapse: collapse; font-family: var(--sans); font-size: .88rem; font-variant-numeric: tabular-nums; }
.note-body th, .note-body td { padding: .3rem .8rem; border-bottom: 1px solid var(--rule); }
.note-body thead th { border-top: 1.5px solid var(--fg); border-bottom: 1px solid var(--fg); font-weight: 600; }
.note-body tbody tr:last-child td { border-bottom: 1.5px solid var(--fg); }

.note-body figure { margin: 1.8rem 0; text-align: center; }
.note-body figure img, .note-body figure video, .note-body > video { max-width: 100%; height: auto; border-radius: 3px; }
.note-body figcaption { margin-top: .5rem; color: var(--muted); font-family: var(--sans); font-size: .86rem; }
.cap-label { font-weight: 600; color: var(--fg); }
.table-caption { margin: -.6rem 0 1.6rem; text-align: center; color: var(--muted); font-family: var(--sans); font-size: .86rem; }

.thm { margin: 1.4rem 0; padding: .2rem 1.1rem; border-left: 3px solid var(--accent); background: rgba(26, 79, 139, .045); }
.thm-head { margin-bottom: 0; }
.thm-proof { border-left-color: var(--rule); background: none; }
.thm-proof > p:last-child::after { content: " ∎"; }

.demo { margin: 1.8rem 0; background: var(--bg); border: 1px solid var(--rule); border-radius: 4px; padding: 1rem; font-family: var(--sans); font-size: .92rem; overflow: hidden; text-align: left; }
.demo-figure > .demo { margin: 0; }
.demo-fallback { color: var(--muted); }
.demo-error { color: #b3261e; white-space: pre-wrap; font-family: var(--mono); font-size: .8rem; margin: 0; }

.sec-no { color: var(--muted); font-weight: 500; margin-right: .1em; }
a.ref, a.cite { text-decoration: none; }
a.ref:hover, a.cite:hover { text-decoration: underline; }
.ref-missing { color: #b3261e; font-weight: 600; }
:target { scroll-margin-top: 1.5rem; }
.note-body :target { animation: target-flash 1.8s ease-out; }
@keyframes target-flash { 0% { background-color: rgba(26, 79, 139, .16); } 100% { background-color: transparent; } }

.references, .pubs { padding-left: 1.5rem; font-size: .95rem; }
.references li, .pubs li { margin: .5rem 0; }
.pubs { list-style: square; }
.ref-title { font-style: italic; }
.footnotes { margin-top: 2.5rem; padding-top: .5rem; border-top: 1px solid var(--rule); font-size: .92rem; }
.footnotes h2 { font-size: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* a preview of what a reference points at */
.ref-pop {
  position: absolute; z-index: 1200; display: none; box-sizing: border-box; width: max-content; min-width: min(20rem, 92vw);
  max-width: min(34rem, 92vw); max-height: 60vh; overflow: auto;
  padding: .7rem .9rem; background: var(--bg); border: 1px solid var(--rule); border-radius: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .14); font-size: .95rem;
}
.ref-pop > :first-child { margin-top: 0; }
.ref-pop > :last-child { margin-bottom: 0; }
.ref-pop img { max-width: 100%; height: auto; }

/* ---------------------------------------------------------------- search */

.site-header nav { display: flex; align-items: center; }
.site-search { position: relative; margin-left: 1.4rem; }
.site-search input { width: 9.5rem; font: inherit; font-size: .88rem; padding: .22rem .55rem; border: 1px solid var(--rule); border-radius: 3px; background: var(--bg); color: var(--fg); }
.site-search input:focus { outline: none; border-color: var(--accent); width: 13rem; }
.site-search-results { display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 1100; width: min(26rem, 90vw); max-height: 70vh; overflow: auto; background: var(--bg); border: 1px solid var(--rule); border-radius: 4px; box-shadow: 0 10px 30px rgba(0, 0, 0, .14); }
.site-search-results a { display: block; margin: 0 !important; padding: .55rem .8rem; border-bottom: 1px solid var(--rule); color: var(--fg) !important; text-decoration: none; }
.site-search-results a:last-child { border-bottom: 0; }
.site-search-results a:hover { background: var(--soft); }
.site-search-results strong { display: block; font-size: .88rem; }
.site-search-results span { display: block; font-size: .8rem; color: var(--muted); }
.site-search-results .empty { padding: .6rem .8rem; font-size: .88rem; }

/* ---------------------------------------------------------------- comments */

.comments { margin-top: 3rem; padding-top: .5rem; border-top: 1px solid var(--rule); font-family: var(--sans); font-size: .95rem; }
.comments h2, .comments h3 { font-family: var(--serif); }
.comment { padding: .9rem 0; border-top: 1px solid var(--rule); }
.comment-list > .comment:first-child { border-top: 0; }
.comment-reply { margin-left: 2rem; }
.comment-waiting { background: #fff8e6; padding-left: .8rem; padding-right: .8rem; border-left: 3px solid #d9a400; }
.comment header { display: flex; flex-wrap: wrap; align-items: baseline; gap: .6rem; font-size: .88rem; }
.comment-when { color: var(--muted); text-decoration: none; }
.comment-author { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: var(--accent); color: #fff; border-radius: 3px; padding: .08rem .35rem; }
.comment-via, .comment-status { font-size: .8rem; color: var(--muted); }
.comment-status { color: #8a6500; }
.comment-body { font-family: var(--serif); font-size: 1rem; }
.comment-body p { margin: .5rem 0; }
.comment footer { display: flex; gap: .9rem; }
.comment-link { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; font-size: .84rem; cursor: pointer; }
.comment-link:hover { text-decoration: underline; }
.comment-danger { color: #b3261e; }
.comment-form { margin-top: 1.5rem; }
.comment-policy { color: var(--muted); font-size: .88rem; margin: 0 0 .8rem; }
.comment-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; margin-bottom: .5rem; }
@media (max-width: 40rem) { .comment-fields { grid-template-columns: 1fr; } .comment-reply { margin-left: 1rem; } }
.comment-form input, .comment-form textarea, .me-signin input, .me-link-form input, .me-link-form select {
  width: 100%; font: inherit; padding: .45rem .6rem; border: 1px solid var(--rule); border-radius: 3px; background: var(--bg); color: var(--fg);
}
.comment-form textarea { font-family: var(--mono); font-size: .9rem; resize: vertical; }
.comment-form input:focus, .comment-form textarea:focus { outline: none; border-color: var(--accent); }
.comment-trap { position: absolute !important; left: -9999px; width: 1px !important; height: 1px; opacity: 0; }
.comment-preview { margin: .6rem 0; padding: 0 .8rem; border-left: 3px solid var(--rule); }
.comment-preview:empty { display: none; }
.comment-preview-label { font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.comment-actions { display: flex; align-items: center; gap: .9rem; margin-top: .5rem; }
.comment-form button[type=submit], .me-signin button, .me-link-form button { font: inherit; padding: .4rem 1rem; border: 1px solid var(--accent); border-radius: 3px; background: var(--accent); color: #fff; cursor: pointer; }
.comment-note, .comment-replying { font-size: .88rem; color: var(--muted); }
.owner-numbers { margin-top: .3rem; }

/* ---------------------------------------------------------------- the owner's page */

#me { font-family: var(--sans); font-size: .93rem; }
#me h2, #me h3 { font-family: var(--serif); }
.me-signin { display: grid; gap: .6rem; max-width: 20rem; }
.me-table { border-collapse: collapse; margin: .6rem 0 1.2rem; font-variant-numeric: tabular-nums; }
.me-table th, .me-table td { text-align: left; padding: .28rem 1.1rem .28rem 0; border-bottom: 1px solid var(--rule); }
.me-bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; margin: .8rem 0; border-bottom: 1px solid var(--rule); }
.me-bar { flex: 1; max-width: 22px; background: var(--accent); opacity: .75; border-radius: 2px 2px 0 0; }
.me-link-form { display: grid; grid-template-columns: 1.2fr 1.4fr 1.2fr auto; gap: .5rem; margin: .6rem 0; }
.me-made { margin: .6rem 0; }
.me-link { user-select: all; background: var(--soft); padding: .2rem .4rem; border-radius: 3px; overflow-wrap: anywhere; }

/* lists of notes */
.note-list { list-style: none; padding: 0; margin: 0; }
.note-item { padding: .9rem 0; border-top: 1px solid var(--rule); }
.note-item:first-child { border-top: 0; }
.note-item > a { font-size: 1.12rem; font-weight: 600; text-decoration: none; }
.note-item > a:hover { text-decoration: underline; }
.note-item p { margin: .35rem 0 0; color: var(--muted); font-size: .96rem; }
.note-item-meta { margin: .1rem 0 0; }
.empty { color: var(--muted); }
