
:root {
  --ink: #111;
  --muted: #666;
  --paper: #fff;
  --paper2: #eee;
  --line: #111;
  --accent: #111;
  --measure: 720px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  line-height: 1.55;
  font-size: 17px;
}
body.dark {
  --ink: #e8e8e8;
  --muted: #888;
  --paper: #0a0a0a;
  --paper2: #141414;
  --line: #e8e8e8;
  --accent: #e8e8e8;
}
a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .12em;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: .45rem clamp(.75rem, 2vw, 1.25rem);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.brand { display: flex; flex-direction: column; gap: 0; }
.brand strong {
  font: 600 .72rem/1.2 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: .04em;
  text-transform: lowercase;
}
.brand span {
  color: var(--muted);
  font: 400 .62rem/1.2 ui-monospace, "SF Mono", Menlo, monospace;
}
.controls { display: flex; gap: 0; flex-wrap: wrap; justify-content: flex-end; }
button, .button {
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  padding: .22rem .45rem;
  margin-left: -1px;
  font: 500 .62rem/1 ui-monospace, "SF Mono", Menlo, monospace;
  text-transform: lowercase;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .button:hover { background: var(--ink); color: var(--paper); }
.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--ink);
  z-index: 30;
}
.layout {
  display: grid;
  grid-template-columns: minmax(140px, 200px) minmax(0, var(--measure)) minmax(0, 200px);
  gap: clamp(.75rem, 1.5vw, 1.25rem);
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(.75rem, 2vw, 1.25rem);
}
.toc {
  position: sticky;
  top: 3.5rem;
  align-self: start;
  max-height: calc(100vh - 4.5rem);
  overflow: auto;
  border-right: 1px solid var(--line);
  padding-right: .65rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.toc-title {
  margin: 0 0 .35rem;
  color: var(--muted);
  font-size: .58rem;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: lowercase;
}
.toc a {
  display: block;
  padding: .1rem 0;
  color: var(--muted);
  text-decoration: none;
  font-size: .62rem;
  line-height: 1.25;
}
.toc a:hover { color: var(--ink); text-decoration: underline; }
.toc-l2 { padding-left: .55rem !important; }
.toc-l3 { padding-left: 1rem !important; font-size: .58rem !important; }
.paper {
  max-width: var(--measure);
  min-width: 0;
  border: 1px solid var(--line);
  padding: clamp(.9rem, 2.5vw, 1.5rem);
}
.hero {
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.25rem;
  padding-bottom: .85rem;
}
.hero h1 {
  font-size: clamp(1.6rem, 6vw, 2.75rem);
  line-height: 1;
  margin: 0 0 .35rem;
  letter-spacing: -.03em;
  font-weight: 700;
}
.hero p { margin: .15rem 0; color: var(--muted); font-size: .9rem; }
.meta {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .68rem;
  letter-spacing: .02em;
}
.paper h1, .paper h2, .paper h3 {
  line-height: 1.15;
  scroll-margin-top: 3.5rem;
  letter-spacing: -.02em;
  font-weight: 700;
}
.paper h1 { margin: 1.75rem 0 .65rem; font-size: clamp(1.35rem, 4vw, 1.85rem); }
.paper h2 { margin: 1.4rem 0 .5rem; font-size: clamp(1.1rem, 3vw, 1.4rem); }
.paper h3 { margin: 1.1rem 0 .4rem; font-size: clamp(1rem, 2.5vw, 1.15rem); }
.copy-anchor {
  margin-left: .2rem;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0 .1rem;
  font: 500 .58rem ui-monospace, "SF Mono", Menlo, monospace;
  opacity: 0;
  text-decoration: none;
}
h1:hover .copy-anchor, h2:hover .copy-anchor, h3:hover .copy-anchor { opacity: 1; }
.copy-anchor:hover { color: var(--ink); }
p { margin: .75rem 0; }
.paper ol, .paper ul { margin: .65rem 0; padding-left: 1.2rem; }
.paper li { margin: .2rem 0; }
blockquote {
  border-left: 2px solid var(--line);
  margin: 1rem 0;
  padding: .35rem 0 .35rem .75rem;
  background: none;
}
pre {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: .55rem .65rem;
  background: var(--paper2);
  font: 400 .68rem/1.35 ui-monospace, "SF Mono", Menlo, monospace;
}
code {
  font: 400 .78em ui-monospace, "SF Mono", Menlo, monospace;
}
mjx-container[jax="CHTML"][display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  padding: .35rem 0;
}
.paper table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  margin: .85rem 0;
  font-size: .82rem;
}
.paper th, .paper td {
  border: 1px solid var(--line);
  padding: .35rem .45rem;
  vertical-align: top;
}
.paper th {
  text-align: left;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .68rem;
  font-weight: 500;
}
.paper-figure { margin: 1.1rem 0; }
.figure-shell {
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 0;
  overflow-x: auto;
}
.paper-figure img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
blockquote strong {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .03em;
  text-transform: lowercase;
}
.thebibliography {
  border-top: 1px solid var(--line);
  margin-top: 1.5rem;
  padding-top: .75rem;
  font-size: .78rem;
}
.thebibliography p { margin: .35rem 0; }
figcaption {
  margin-top: .4rem;
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.35;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.margin {
  position: sticky;
  top: 3.5rem;
  align-self: start;
  max-height: calc(100vh - 4.5rem);
  overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
  font-size: .58rem;
  line-height: 1.45;
  letter-spacing: .01em;
  border-left: 1px solid var(--line);
  padding-left: .65rem;
}
.margin-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .35rem;
  margin-bottom: .45rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--line);
}
.margin-title {
  color: var(--ink);
  font-size: .62rem;
  text-transform: lowercase;
}
.margin-count {
  color: var(--muted);
  font-size: .58rem;
}
.margin-hint {
  margin: 0 0 .55rem;
  font-size: .56rem;
  line-height: 1.35;
}
.margin-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  min-height: 4rem;
}
.margin-empty {
  margin: 0;
  padding: .75rem 0;
  color: var(--muted);
  font-size: .56rem;
  border: 1px dashed var(--line);
  text-align: center;
}
.margin-foot {
  margin: .65rem 0 0;
  padding-top: .45rem;
  border-top: 1px solid var(--line);
  font-size: .54rem;
  color: var(--muted);
}
.note-item {
  border: 1px solid var(--line);
  padding: .35rem;
  background: var(--paper);
}
.note-item.is-active {
  box-shadow: 2px 2px 0 var(--ink);
}
.note-quote {
  display: block;
  width: 100%;
  margin: 0 0 .3rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: .56rem;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: .1em;
}
.note-quote:hover { background: var(--paper2); }
.note-input {
  display: block;
  width: 100%;
  margin: 0 0 .25rem;
  padding: .22rem .28rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--paper2);
  color: var(--ink);
  font: inherit;
  font-size: .58rem;
  line-height: 1.35;
  resize: vertical;
  min-height: 2.4rem;
}
.note-input:focus {
  outline: none;
  background: var(--paper);
  box-shadow: inset 0 0 0 1px var(--ink);
}
.note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .25rem;
  font-size: .52rem;
}
.note-del {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 0 .28rem;
  font: inherit;
  font-size: .62rem;
  line-height: 1;
  cursor: pointer;
}
.note-del:hover { background: var(--ink); color: var(--paper); }
.highlighted {
  background: var(--paper2);
  box-shadow: inset 0 -2px 0 var(--ink);
  border-radius: 0;
  cursor: pointer;
}
.highlighted.is-active {
  background: var(--ink);
  color: var(--paper);
  box-shadow: none;
}
.popover {
  position: absolute;
  display: none;
  z-index: 40;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 2px 2px 0 var(--ink);
}
.popover button {
  display: block;
  width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
  border-bottom: 1px solid var(--line);
  padding: .18rem .35rem;
  font: 500 .58rem/1.2 ui-monospace, "SF Mono", Menlo, monospace;
  text-transform: lowercase;
  color: var(--ink);
  background: var(--paper);
}
.popover button:last-child { border-bottom: 0; }
.popover button:hover { background: var(--ink); color: var(--paper); }
.toast {
  position: fixed;
  bottom: .65rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: .25rem .45rem;
  font: 500 .58rem ui-monospace, "SF Mono", Menlo, monospace;
  text-transform: lowercase;
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms linear;
  z-index: 50;
}
.toast.show { opacity: 1; }
.mobile-toc-toggle { display: none; }
@media (max-width: 960px) {
  .layout { display: block; padding: .55rem; }
  .paper { padding: clamp(.75rem, 4vw, 1.1rem); }
  .toc, .margin { display: none; }
  .toc.open {
    display: block;
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    margin-bottom: .55rem;
    padding: .55rem 0;
    background: var(--paper);
  }
  .mobile-toc-toggle { display: inline-flex; }
}
