:root {
  --bg: #fbfaf7;
  --paper: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --rule: #e4e1da;
  --accent: #2f5fb3;
  --accent-soft: #e8eefa;
  --on-accent: #ffffff; /* text on a filled var(--accent) button */
  --thm-bg: #f6f8fc;
  --thm-border: #9db3dc;
  --def-border: #c9b37a;
  --def-bg: #fbf8ef;
  --warn: #b5541b;
  --missing: #c62828;
  --code-bg: #f2f1ed;
  --toolbar: #ffffffee;
  --flash: #fff3b0;
  --hl-cmd: #1f5fbf;
  --hl-env: #9a3b8c;
  --hl-math: #2e7d4f;
  --hl-math-bg: rgba(46, 125, 79, 0.07);
  --hl-label: #b5541b;
  --hl-comment: #8a8a8f;
  --hl-punct: #8a8a8f;
  --hl-align: #c0392b;
  /* reading progress (src/progress.js) */
  --rp-skimmed: #c98a12;
  --rp-skimmed-bg: #fbf0d6;
  --rp-read: #2f74c0;
  --rp-read-bg: #dce9f8;
  --rp-understood: #2e8b57;
  --rp-understood-bg: #d6f0df;
  --rp-q: #c0392b;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191a1d;
    --paper: #222327;
    --ink: #d8d3c8;
    --muted: #9b9994;
    --rule: #37383d;
    --accent: #8eaad8;
    --accent-soft: #283244;
    --on-accent: #13161f;
    --thm-bg: #262930;
    --thm-border: #4c5f84;
    --def-border: #7d6d47;
    --def-bg: #292721;
    --warn: #dda27a;
    --missing: #ec8c86;
    --code-bg: #2c2d32;
    --toolbar: #222327ee;
    --flash: #4a4426;
    --hl-cmd: #8eaad8;
    --hl-env: #d2a5cc;
    --hl-math: #92c9a5;
    --hl-math-bg: rgba(146, 201, 165, 0.07);
    --hl-label: #dda27a;
    --hl-comment: #7d7d85;
    --hl-punct: #8a8a92;
    --hl-align: #ec8c86;
    --rp-skimmed: #d3ab62;
    --rp-skimmed-bg: #3a3020;
    --rp-read: #85a9d8;
    --rp-read-bg: #1f3048;
    --rp-understood: #80bf98;
    --rp-understood-bg: #1d3a2a;
    --rp-q: #ec8c86;
    /* softer xcolor names for TikZ and \color in maths (src/tikz.js, below) */
    --tg-red: #e8837c; --tg-green: #86c18f; --tg-blue: #8aa9e0; --tg-cyan: #7cc4cf; --tg-magenta: #d68ac4;
    --tg-yellow: #d9c06a; --tg-orange: #e0a066; --tg-violet: #ad97dc; --tg-purple: #c08fd4; --tg-brown: #c09a7c;
    --tg-pink: #e59ab6; --tg-teal: #6fbcb3; --tg-olive: #b5b36c; --tg-lime: #a8cf7a;
    /* highlights: less glow on a dark page */
    --tg-hl-yellow: rgba(222, 186, 70, 0.3);
    --tg-hl-green: rgba(98, 180, 122, 0.28);
    --tg-hl-pink: rgba(222, 110, 165, 0.26);
    --tg-hl-blue: rgba(100, 145, 220, 0.3);
    /* white-backed figures dimmed to the page; full brightness on hover */
    --tg-img-filter: brightness(0.82);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #191a1d;
  --paper: #222327;
  --ink: #d8d3c8;
  --muted: #9b9994;
  --rule: #37383d;
  --accent: #8eaad8;
  --accent-soft: #283244;
  --on-accent: #13161f;
  --thm-bg: #262930;
  --thm-border: #4c5f84;
  --def-border: #7d6d47;
  --def-bg: #292721;
  --warn: #dda27a;
  --missing: #ec8c86;
  --code-bg: #2c2d32;
  --toolbar: #222327ee;
  --flash: #4a4426;
  --hl-cmd: #8eaad8;
  --hl-env: #d2a5cc;
  --hl-math: #92c9a5;
  --hl-math-bg: rgba(146, 201, 165, 0.07);
  --hl-label: #dda27a;
  --hl-comment: #7d7d85;
  --hl-punct: #8a8a92;
  --hl-align: #ec8c86;
  --rp-skimmed: #d3ab62;
  --rp-skimmed-bg: #3a3020;
  --rp-read: #85a9d8;
  --rp-read-bg: #1f3048;
  --rp-understood: #80bf98;
  --rp-understood-bg: #1d3a2a;
  --rp-q: #ec8c86;
  /* softer xcolor names for TikZ and \color in maths (src/tikz.js, below) */
  --tg-red: #e8837c; --tg-green: #86c18f; --tg-blue: #8aa9e0; --tg-cyan: #7cc4cf; --tg-magenta: #d68ac4;
  --tg-yellow: #d9c06a; --tg-orange: #e0a066; --tg-violet: #ad97dc; --tg-purple: #c08fd4; --tg-brown: #c09a7c;
  --tg-pink: #e59ab6; --tg-teal: #6fbcb3; --tg-olive: #b5b36c; --tg-lime: #a8cf7a;
  /* highlights: less glow on a dark page */
  --tg-hl-yellow: rgba(222, 186, 70, 0.3);
  --tg-hl-green: rgba(98, 180, 122, 0.28);
  --tg-hl-pink: rgba(222, 110, 165, 0.26);
  --tg-hl-blue: rgba(100, 145, 220, 0.3);
  /* white-backed figures dimmed to the page; full brightness on hover */
  --tg-img-filter: brightness(0.82);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color-scheme: dark;
}


/* The dark theme, made for long reading: an off-black page, warm off-white text a
   little below full contrast, and muted accents. Named colours from the paper
   (\color{red} in maths, TikZ's red, blue, …) take the softer --tg-<name> tints
   set above; with no tint set (the light theme) they keep their own colour. */
.katex :is([style^="color:red;"], [style*=";color:red;"]) { color: var(--tg-red, red) !important; }
.katex :is([style^="color:green;"], [style*=";color:green;"]) { color: var(--tg-green, green) !important; }
.katex :is([style^="color:blue;"], [style*=";color:blue;"]) { color: var(--tg-blue, blue) !important; }
.katex :is([style^="color:cyan;"], [style*=";color:cyan;"]) { color: var(--tg-cyan, cyan) !important; }
.katex :is([style^="color:magenta;"], [style*=";color:magenta;"]) { color: var(--tg-magenta, magenta) !important; }
.katex :is([style^="color:yellow;"], [style*=";color:yellow;"]) { color: var(--tg-yellow, yellow) !important; }
.katex :is([style^="color:orange;"], [style*=";color:orange;"]) { color: var(--tg-orange, orange) !important; }
.katex :is([style^="color:violet;"], [style*=";color:violet;"]) { color: var(--tg-violet, violet) !important; }
.katex :is([style^="color:purple;"], [style*=";color:purple;"]) { color: var(--tg-purple, purple) !important; }
.katex :is([style^="color:brown;"], [style*=";color:brown;"]) { color: var(--tg-brown, brown) !important; }
.katex :is([style^="color:pink;"], [style*=";color:pink;"]) { color: var(--tg-pink, pink) !important; }
.katex :is([style^="color:teal;"], [style*=";color:teal;"]) { color: var(--tg-teal, teal) !important; }
.katex :is([style^="color:olive;"], [style*=";color:olive;"]) { color: var(--tg-olive, olive) !important; }
.katex :is([style^="color:lime;"], [style*=";color:lime;"]) { color: var(--tg-lime, lime) !important; }
@media screen {
  img.graphic { filter: var(--tg-img-filter, none); transition: filter 0.2s; }
  img.graphic:hover { filter: none; }
}

* { box-sizing: border-box; }

/* Only the panes scroll; the page itself never does. */
html, body { height: 100%; margin: 0; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

/* --- toolbar ------------------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  --toolbar-pad-y: 8px;
  --toolbar-pad-x: 16px;
  padding: calc(var(--toolbar-pad-y) + env(safe-area-inset-top, 0px))
    calc(var(--toolbar-pad-x) + env(safe-area-inset-right, 0px))
    var(--toolbar-pad-y)
    calc(var(--toolbar-pad-x) + env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--rule);
  background: var(--toolbar);
  backdrop-filter: blur(6px);
  flex-wrap: wrap;
  position: relative;
  z-index: 25; /* above the panes, so that the "…" menu opens over the document */
}

/* Keep mobile controls on a solid surface instead of a blur layer next to
   the system bar. Include tablets and Home Screen apps at desktop widths. */
@media screen and (max-width: 760px), screen and (any-pointer: coarse), screen and (display-mode: standalone) {
  .toolbar {
    background: var(--paper);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

.brand {
  font-family: "Latin Modern Roman", "Computer Modern Serif", Georgia, serif;
  font-size: 20px;
  font-weight: 600;
  margin-right: 8px;
}
.brand sub { font-size: 0.8em; vertical-align: -0.25em; margin: 0 -0.08em; }
/* Support TeXglass (Buy Me a Coffee), beside the name; on a phone, where the name is hidden, it stays in the "…" menu */
.support-link { display: inline-flex; align-items: center; gap: 4px; margin: 0 4px 0 -4px; padding: 3px 9px; border: 1px solid var(--rule); border-radius: 999px; color: var(--muted); font-size: 12.5px; text-decoration: none; white-space: nowrap; }
.support-link:hover, .support-link:focus-visible { color: var(--ink); border-color: var(--accent); background: var(--accent-soft); outline: none; }
.toolbar .more-menu .more-support { display: none; }

.toolbar button {
  font: inherit;
  font-size: 14px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
@media (hover: hover) { .toolbar button:hover { border-color: var(--accent); } }
.toolbar button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }

/* The "…" menu: Save, Export, Print */
.more-group { position: relative; display: inline-flex; }
.toolbar .more-button { padding: 5px 10px; font-weight: 600; letter-spacing: 0.05em; line-height: 1.2; }
.toolbar .more-button[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); }
.more-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  min-width: 210px;
  max-height: var(--more-menu-height, calc(100dvh - 80px));
  overflow: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  padding: 4px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.more-menu[hidden], .toolbar .more-menu [hidden] { display: none; }
.more-menu > * { flex-shrink: 0; }
.more-menu .more-export-options { margin-inline-start: 10px; border-inline-start: 1px solid var(--rule); }
.more-menu .more-chevron { color: var(--muted); flex: none; }
.more-menu [aria-expanded="true"] .more-chevron { transform: rotate(90deg); }
.toolbar .more-menu button {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 5px;
  background: none;
  padding: 6px 10px;
  white-space: nowrap;
}
@media (hover: hover) { .toolbar .more-menu button:hover { background: var(--accent-soft); } }
.toolbar .more-menu .more-export-options button { white-space: normal; }
.toolbar .more-menu button:focus-visible { background: var(--accent-soft); outline: none; }
.more-menu kbd, .more-menu .more-hint { font: inherit; font-size: 12px; color: var(--muted); }
.more-menu .more-sep { height: 1px; margin: 4px 6px; background: var(--rule); }
.more-menu .more-head { padding: 6px 10px 2px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.toolbar .more-menu button[role="menuitemcheckbox"]::after { content: ''; width: 1em; text-align: right; color: var(--accent); }
.toolbar .more-menu button[role="menuitemcheckbox"][aria-checked="true"]::after { content: '✓'; }
.toolbar .more-menu button:disabled { opacity: 0.45; cursor: default; background: none; }
/* "Support TeXglass ☕": a quiet link at the end of the menu */
.toolbar .more-menu .more-support {
  display: block;
  padding: 6px 10px;
  border-radius: 5px;
  color: inherit;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
.toolbar .more-menu .more-support:hover, .toolbar .more-menu .more-support:focus-visible { background: var(--accent-soft); outline: none; }
#notes-sync-dialog .local-note { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
#notes-sync-dialog .notes-sync-decks { display: flex; align-items: center; gap: 6px; font-size: 14px; margin: 4px 0 2px; }
#notes-sync-dialog .notes-sync-decks-about { margin-left: 22px; }
#notes-sync-dialog .notes-sync-decks[hidden] { display: none; }
/* Signed in: a plain status line says syncing is automatic; Sync now is a quiet link. */
#notes-sync-dialog .notes-sync-state { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; padding: 8px 10px; border-radius: 6px; background: var(--accent-soft); font-size: 14px; }
#notes-sync-dialog .notes-sync-state::before { content: "\2713"; font-weight: 700; color: var(--accent); }
#notes-sync-dialog .notes-sync-state.failed::before { content: "!"; color: #c0392b; }
#notes-sync-dialog .arxiv-actions .link-button { border: 0; background: none; padding: 5px 4px; color: var(--accent); text-decoration: underline; font-size: 13px; }
#notes-sync-dialog .arxiv-actions #notes-sync-signout { margin-right: auto; }

/* Import from arXiv */
.arxiv-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 20px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.arxiv-dialog::backdrop { background: rgba(0, 0, 0, 0.3); }
.arxiv-dialog h2 { margin: 0 0 12px; font-size: 17px; }
.arxiv-dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.arxiv-dialog label code { font-size: 12px; padding: 0 3px; border-radius: 3px; background: var(--accent-soft); color: var(--ink); }
.arxiv-dialog input, #github-browser-dialog select {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
}
.arxiv-dialog input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.arxiv-message { min-height: 1.4em; margin: 8px 0 4px; font-size: 13px; color: var(--muted); }
.arxiv-message.warn { color: var(--warn); }
.arxiv-original-pdf:not([hidden]) { display: inline-block; margin-bottom: 12px; color: var(--accent); font-size: 14px; }
.bookmarklet-hint { margin: 4px 0 12px; font-size: 13px; color: var(--muted); }
.bookmarklet {
  display: inline-block;
  padding: 1px 8px;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  color: var(--accent);
  text-decoration: none;
  cursor: grab;
}
.gh-link { font-size: 13px; color: var(--accent); white-space: nowrap; }
/* Give Open one scrolling body, not competing flex items for results and
   recents. Keep the search box and actions outside that scrolling area. */
#arxiv-dialog[open] { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
#arxiv-dialog.has-results { width: min(760px, calc(100vw - 32px)); }
#arxiv-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#arxiv-form > :not(.arxiv-content) { flex: none; }
.arxiv-open-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.arxiv-open-head h2 { margin: 0; }
.arxiv-open-head .link-button { flex: none; font-size: 13px; }
.arxiv-content { min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; }
#arxiv-dialog .arxiv-results { padding: 0; margin: 4px 0 12px; overflow: visible; }
#arxiv-dialog .arxiv-actions { margin-top: 8px; }
.arxiv-filters { margin: 0 0 6px; border-bottom: 1px solid var(--rule); }
.arxiv-filters summary { cursor: pointer; padding: 8px 2px; font-size: 13px; }
#arxiv-filter-summary { color: var(--muted); overflow-wrap: anywhere; }
.arxiv-filter-fields { padding: 4px 2px 8px; }
.arxiv-filter-fields label { margin-bottom: 0; }
.arxiv-filter-fields :is(input, select) { margin-top: 3px; }
.arxiv-filter-fields p { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.arxiv-filter-row { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 8px; }
.arxiv-filter-row label { min-width: 0; }
.arxiv-filter-row select {
  width: 100%; min-width: 0; height: 35px;
  border: 1px solid var(--rule); border-radius: 5px; background: var(--paper);
  color: var(--ink); font: inherit; font-size: 16px; padding: 3px 4px;
}
.arxiv-filter-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 8px; }
.arxiv-filter-actions button { min-height: 34px; }
@media (max-width: 600px) {
  .arxiv-filters summary { min-height: 40px; display: list-item; padding-block: 10px; }
  .arxiv-filter-actions button { min-height: 40px; }
}

.arxiv-label-short { display: none; }
@media (max-width: 760px) {
  #arxiv-dialog[open] {
    inset: calc(var(--tg-open-top, 0px) + 12px) 0 auto;
    margin: 0 auto;
    padding: 12px 14px;
    max-height: calc(var(--tg-open-height, 100dvh) - 24px);
  }
  #arxiv-dialog input { font-size: 16px; } /* don't zoom the form when iOS focuses it */
  #arxiv-dialog.has-results :is(.arxiv-open-tools, .arxiv-label-full) { display: none; }
  #arxiv-dialog.has-results .arxiv-label-short { display: inline; }
  .arxiv-open-head { margin-bottom: 6px; }
  .arxiv-open-head .link-button, #arxiv-dialog .arxiv-actions button { min-height: 40px; }
}
.arxiv-results .preprint { margin: 0; border-top: 1px solid var(--rule); border-radius: 0; padding: 8px; }
.arxiv-results .preprint:first-child { border-top: 0; }
.arxiv-result-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.arxiv-results .preprints-more { margin: 10px auto 0; }
.arxiv-actions { display: flex; justify-content: flex-end; gap: 8px; }
.arxiv-actions button {
  font: inherit;
  font-size: 14px;
  padding: 5px 14px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.arxiv-actions button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.arxiv-actions button:disabled { opacity: 0.6; cursor: default; }
/* Native phone select pickers can be hard to browse with long repo lists.
   Keep the filter and actions visible, and scroll repo/file rows inside. */
#github-browser-dialog[open] {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
}
#github-browser-dialog > :is(h2, .arxiv-message, .arxiv-actions) { flex: none; }
#github-connect-form { overflow-y: auto; min-height: 0; }
#github-repo-browser:not([hidden]), .github-picker-view:not([hidden]) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.github-picker-view > :not(.preprints-list) { flex: none; }
#github-repo-list, #github-folder-files {
  padding: 0 3px;
  overscroll-behavior-y: contain;
}
#github-repo-list .preprint, #github-folder-files .preprint {
  margin: 0;
  border-bottom: 1px solid var(--rule);
  padding: 0 5px;
}
#github-repo-list button, #github-folder-files button {
  min-height: 44px;
  overflow-wrap: anywhere;
}
#github-repo-count, #github-repo-hint, #github-repo-public-only { font-size: 12px; color: var(--muted); margin: 6px 0; }
#github-repo-public-only { color: var(--warn); }
#github-repo-public-only[hidden] { display: none; }
.github-repo-current {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}
#github-browser-dialog select, #github-connect-form input:not([type=checkbox]) { margin-bottom: 10px; }
#github-connect-form .github-remember { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink); margin: 0 0 2px; }
#github-connect-form .github-remember input { margin: 0; }
.github-remember-about, #github-remembered { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
#github-remember-about { margin-left: 22px; }
#github-remembered[hidden] { display: none; }
@media (max-width: 760px) {
  #github-browser-dialog[open] {
    inset: calc(var(--tg-open-top, 0px) + 12px) 0 auto;
    margin: 0 auto;
    padding: 12px 14px;
    max-height: calc(var(--tg-open-height, 100dvh) - 24px);
  }
  #github-browser-dialog :is(input, select) { font-size: 16px; }
  #github-browser-dialog .arxiv-actions button, #github-repo-change { min-height: 40px; }
}
@media (max-width: 760px) and (max-height: 430px) {
  #github-repo-hint, #github-remembered { display: none; }
}
.github-folder-nav:not([hidden]) {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
}
#github-folder-up { flex: none; }
#github-folder-path, #github-folder-files button { overflow-wrap: anywhere; }
/* Settings: switching reading aids on or off (src/features.js) */
.features-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px); /* the visible height, under a phone's browser bars */
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.features-dialog[open] { display: flex; flex-direction: column; }
.features-dialog::backdrop { background: rgba(0, 0, 0, 0.3); }
.features-head { display: flex; align-items: center; padding: 16px 20px 0; }
.features-head h2 { margin: 0; font-size: 17px; flex: 1; }
.features-close { font: inherit; font-size: 20px; line-height: 1; padding: 2px 8px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.features-close:hover { background: var(--accent-soft); color: var(--ink); }
.features-back { display: none; }
.features-intro { margin: 6px 20px 8px; font-size: 13px; color: var(--muted); }
.features-list { overflow-y: auto; padding: 0 20px; min-height: 0; flex: 1; }
.features-list fieldset { border: 0; margin: 0 0 6px; padding: 0; }
.features-list legend { padding: 8px 0 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.feature { display: flex; gap: 10px; align-items: flex-start; padding: 6px 8px; margin: 0 -8px; border-radius: 6px; cursor: pointer; }
.feature:hover { background: var(--accent-soft); }
.feature input { margin: 3px 0 0; flex: none; width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.feature-text { display: flex; flex-direction: column; }
.feature-label { font-weight: 500; }
.feature-hint { font-size: 12.5px; color: var(--muted); }
.feature-blocked .feature-label, .feature-blocked .feature-hint { opacity: 0.55; }
.features-contrast .contrast-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding-top: 2px; }
.features-contrast .contrast-value { font-size: 13px; color: var(--muted); }
.features-contrast .contrast-control { display: flex; align-items: center; gap: 10px; margin: 4px 0 2px; font-size: 12.5px; color: var(--muted); }
.features-contrast input[type="range"] { flex: 1; min-width: 0; margin: 0; accent-color: var(--accent); cursor: pointer; }
.features-contrast .feature-hint { margin: 2px 0 6px; }
.features-contrast .contrast-reset { font: inherit; font-size: 12.5px; padding: 3px 10px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); color: var(--ink); cursor: pointer; }
.features-contrast .contrast-reset:hover { border-color: var(--muted); }
.features-contrast .contrast-reset[hidden] { display: none; }
.features-foot { display: flex; justify-content: space-between; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--rule); }
.features-foot button {
  font: inherit; font-size: 13.5px; padding: 5px 14px; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink); cursor: pointer;
}
.features-foot button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.features-extra { padding: 8px 20px 12px; font-size: 13px; color: var(--muted); }
/* Settings: About TeXglass, last in the list (app.js aboutSection) */
.features-about .about-intro { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.features-about .about-links { margin: 0 0 8px; padding: 0; list-style: none; display: flex; flex-direction: column; font-size: 13.5px; }
.features-about .about-links li { padding: 4px 0; }
.features-about a { color: var(--accent); }
/* On a phone Settings fills the screen: its title bar and Done stay in view
   (clear of the notch and the home bar), and the list scrolls between them. */
@media (max-width: 760px) {
  .features-dialog {
    width: 100%; max-width: none; height: 100%; height: 100dvh; max-height: none;
    margin: 0; inset: 0; border: 0; border-radius: 0; box-shadow: none;
  }
  .features-head { padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left)); }
  .features-close { display: none; }
  .features-back {
    display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px;
    margin: 0 4px 0 -12px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--accent); cursor: pointer;
  }
  .features-back svg { width: 26px; height: 26px; }
  .features-back:active { background: var(--accent-soft); }
  .features-foot { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .features-foot button { min-height: 44px; }
}
@media (pointer: coarse) { .features-about .about-links li { padding: 8px 0; } }
/* "What does this use?" buttons switched off */
.tg-no-uses .uses-btn { display: none !important; }
img.graphic { max-width: 100%; height: auto; }
/* Opening from this computer: the dialog, the line in the arXiv dialog, and the bar under the toolbar */
.local-body p { margin: 0 0 12px; font-size: 14px; }
.local-body .local-note { font-size: 13px; color: var(--muted); }
.local-hint { margin: 2px 0 12px; font-size: 13px; color: var(--muted); }
.link-button { font: inherit; padding: 0; border: 0; background: none; color: var(--accent); cursor: pointer; text-decoration: underline; }
.folder-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--accent-soft);
  font-size: 13px;
}
.folder-hint[hidden] { display: none; }
.folder-hint span { flex: 1; min-width: 0; }
.folder-hint button { font: inherit; padding: 3px 10px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); cursor: pointer; white-space: nowrap; }
.folder-hint button[hidden] { display: none; }
.folder-hint .folder-hint-close { background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 4px; }
@media print { .folder-hint { display: none !important; } }

/* Browse OpenAI's math preprints */
.preprints-dialog {
  width: min(820px, calc(100vw - 32px));
  height: min(86vh, 900px);
  padding: 0;
  overflow: hidden;
}
.preprints-dialog[open] { display: flex; flex-direction: column; }
.preprints-head { display: flex; align-items: baseline; gap: 12px; padding: 16px 20px 8px; }
.preprints-head h2 { margin: 0; }
.preprints-close {
  margin-left: auto;
  font: inherit;
  font-size: 20px;
  line-height: 1;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.preprints-close:hover { border-color: var(--rule); color: var(--ink); }
.preprints-filters { display: flex; gap: 8px; padding: 0 20px; }
.preprints-filters input { flex: 1; min-width: 0; }
.preprints-filters select {
  font: inherit;
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  max-width: 45%;
}
.preprints-dialog .arxiv-message { padding: 0 20px; }
.preprints-list {
  position: relative; /* KaTeX's hidden MathML must not escape the scroll box */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0 20px 16px;
  list-style: none;
}
.preprint-family { padding: 12px 0; border-top: 1px solid var(--rule); }
.preprint-family:first-child { border-top: 0; }
.preprint-family-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.preprint-family-num { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.preprint-family-title { font-weight: 600; font-size: 15px; }
.preprint-discipline { font-size: 12px; color: var(--muted); border: 1px solid var(--rule); border-radius: 999px; padding: 0 8px; }
.preprint-family-desc { margin: 4px 0 6px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.preprint-manuscripts { list-style: none; margin: 0; padding: 0; }
.preprint {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: 6px;
}
.preprint:hover, .preprint:focus-within { background: var(--accent-soft); }
.preprint-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  font: inherit;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
}
.preprint-open:disabled { cursor: progress; opacity: 0.7; }
.preprint-title { display: block; color: var(--accent); font-size: 14px; }
.preprint-note { color: var(--muted); font-size: 12px; }
.preprint-abstract {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
  margin-top: 2px;
}
.preprint:hover .preprint-abstract, .preprint:focus-within .preprint-abstract { -webkit-line-clamp: unset; }
.preprint-pdf { font-size: 12px; color: var(--muted); white-space: nowrap; padding-top: 2px; }
.preprint-pdf:hover { color: var(--accent); }
/* Saved papers, for offline reading (app.js, src/library.js) */
.library-recent { margin: 2px 0 12px; }
.library-recent[hidden] { display: none; }
.library-recent-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.library-recent-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: 6px; }
.library-recent-list li + li { border-top: 1px solid var(--rule); }
.library-recent-open { display: block; width: 100%; text-align: left; font: inherit; padding: 6px 10px; border: 0; background: none; color: var(--ink); cursor: pointer; }
.library-recent-open:hover, .library-recent-open:focus-visible { background: var(--accent-soft); outline: none; }
.library-recent-open:disabled { opacity: 0.55; cursor: default; }
.library-recent-title { display: block; color: var(--accent); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-recent-open.library-elsewhere .library-recent-title { color: var(--muted); }
@media (max-width: 760px) { .library-recent-open { padding: 9px 10px; } }
.library-dialog { width: min(640px, calc(100vw - 32px)); height: auto; max-height: min(86vh, 900px); }
.library-intro { margin: 0 20px 8px; font-size: 13px; color: var(--muted); }
.library-dialog .preprints-filters[hidden] { display: none; }
.library-list { padding-bottom: 8px; }
.library-item { align-items: center; padding: 8px; border-top: 1px solid var(--rule); border-radius: 0; margin: 0; }
.library-item:first-child { border-top: 0; }
.library-elsewhere .preprint-title { color: var(--muted); }
.library-action { flex: none; font: inherit; font-size: 12.5px; padding: 3px 10px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); color: var(--muted); cursor: pointer; }
.library-action:hover { color: var(--ink); border-color: var(--muted); }
.library-download { color: var(--accent); border-color: var(--accent); }
.library-foot { margin: 0; padding: 8px 20px 14px; border-top: 1px solid var(--rule); font-size: 12.5px; color: var(--muted); }
.library-foot:empty { display: none; }
/* bookmarks: All / Bookmarked / Offline here, tags (app.js renderLibrary, renderTagEditor) */
.library-kinds { display: flex; gap: 0; margin: 0 20px 8px; }
.library-kinds[hidden], .library-tagbar[hidden] { display: none; }
.library-kinds button { font: inherit; font-size: 13px; padding: 4px 12px; border: 1px solid var(--rule); background: var(--paper); color: var(--muted); cursor: pointer; }
.library-kinds button + button { border-left: 0; }
.library-kinds button:first-child { border-radius: 6px 0 0 6px; }
.library-kinds button:last-child { border-radius: 0 6px 6px 0; }
.library-kinds button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); }
.library-tagbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 20px 8px; font-size: 13px; color: var(--muted); }
.tag-chip { display: inline-flex; align-items: center; gap: 2px; font: inherit; font-size: 12.5px; line-height: 1.5; padding: 0 8px; border: 1px solid var(--rule); border-radius: 999px; background: var(--paper); color: var(--ink); }
button.tag-chip { cursor: pointer; }
.tag-count { margin-left: 4px; font-size: 11px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.tag-filter:hover { border-color: var(--accent); }
.tag-filter[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.tag-chip-remove { font: inherit; padding: 0 2px; margin-right: -4px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.tag-chip-remove:hover { color: var(--ink); }
.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag-input { flex: 1; min-width: 9em; font: inherit; font-size: 13px; padding: 3px 6px; border: 1px solid var(--rule); border-radius: 6px; background: var(--bg); color: var(--ink); }
.library-item { flex-wrap: wrap; }
.library-actions { display: flex; gap: 6px; align-items: center; flex: none; }
.library-bookmark { display: inline-flex; align-items: center; padding: 3px 6px; }
.library-bookmark svg { width: 16px; height: 16px; }
.library-bookmark[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.library-bookmark[aria-pressed="true"] .bookmark-mark { fill: currentColor; }
.library-tags { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; }
.library-tags > .tag-editor { flex: 1; }
.library-tags .link-button { font-size: 12.5px; }
.bookmark-pop { position: fixed; z-index: 60; width: min(320px, calc(100vw - 16px)); box-sizing: border-box; padding: 12px 14px; background: var(--paper); color: var(--ink); border: 1px solid var(--rule); border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); font-size: 14px; }
.bookmark-pop[hidden] { display: none; }
.bookmark-pop-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.bookmark-pop-head .link-button { font-size: 13px; }
.bookmark-pop-title { margin: 4px 0 10px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-pop-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 12px; }
.bookmark-pop-foot .link-button { font-size: 13px; }
.bookmark-pop-foot button.primary { font: inherit; font-size: 13px; padding: 4px 14px; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent); color: var(--on-accent); cursor: pointer; }
.bookmark-pop-foot .link-button:disabled { color: var(--muted); text-decoration: none; cursor: default; }
@media (max-width: 760px) {
  .library-item { padding: 10px 4px; }
  .library-action { min-height: 40px; padding: 6px 12px; font-size: 14px; }
}
.preprints-more { display: block; margin: 12px auto 0; font: inherit; font-size: 13px; padding: 5px 14px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); color: var(--ink); cursor: pointer; }

.mode-switch { display: inline-flex; }
.mode-switch button { border-radius: 0; }
.mode-switch button:first-child { border-radius: 6px 0 0 6px; }
.mode-switch button:last-child { border-radius: 0 6px 6px 0; }
.mode-switch button + button { margin-left: -1px; }
.mode-switch button[aria-pressed="true"] { position: relative; }
.file-name.dirty::after { content: " •"; color: var(--accent); }
.file-name { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.status { margin-left: auto; font-size: 13px; color: var(--muted); cursor: default; }
.status.warn { color: var(--warn); }
.render-actions:not([hidden]) { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.toolbar .render-actions [hidden] { display: none; }
.render-actions a { color: var(--accent); font-size: 13px; }
.toolbar .render-actions button { color: var(--warn); font-size: 13px; }
.render-warnings-list { max-height: 55dvh; overflow: auto; margin: 0 0 14px; padding: 0; list-style: none; }
.render-warnings-list li { border-top: 1px solid var(--rule); padding: 8px 6px; font-size: 14px; overflow-wrap: anywhere; }
.render-warnings-list button { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-align: left; text-decoration: underline; cursor: pointer; }
.document .render-warning-target:focus { outline: 2px solid var(--warn); outline-offset: 3px; }

/* --- panes --------------------------------------------------------------- */

.panes { flex: 1; display: flex; min-height: 0; }
.pane { flex: 1; min-width: 0; overflow: auto; position: relative; }

/* Table of contents sidebar (Preview and Edit) */
/* 300px by default: room for the four tabs and the head's two buttons on one row */
.toc-pane {
  flex: 0 0 var(--side-width, 300px);
  position: relative;
  overflow: auto;
  padding: 20px 10px 32px 16px;
  border-right: 1px solid var(--rule);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.35;
  overscroll-behavior: contain;
}
.toc-pane[hidden] { display: none; }
/* The contents can sit on the right of the document instead. */
body.toc-right .toc-pane { order: 2; border-right: 0; border-left: 1px solid var(--rule); padding: 20px 16px 32px 10px; }
.toc-pane-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 0 0 8px 8px; }
/* The head row (the tabs) stays at the top while the panel scrolls, so another
   tab is always one click away. It bleeds over the panel's padding, so nothing
   peeks out beside or above it, and keeps 6px of that padding once it sticks
   (sticky offsets count from inside the panel's 20px top padding). */
.toc-pane > .toc-pane-head {
  position: sticky;
  top: -34px;
  z-index: 2;
  margin: -20px -10px 8px -16px;
  padding: 20px 10px 6px 24px;
  background: var(--bg);
}
body.toc-right .toc-pane > .toc-pane-head { margin: -20px -16px 8px -10px; padding: 20px 16px 6px 18px; }
/* The side panel's tabs: Contents, Map, Notation (src/insight.js sidePanel). */
.side-tabs { display: flex; flex: 1; gap: 1px; min-width: 0; overflow: hidden; }
/* When they do not fit on one row, the tabs stack, so none is cut off (sidePanel sets the class). */
.toc-pane-head:has(.side-tabs-stacked) { align-items: flex-start; }
.side-tabs.side-tabs-stacked { flex-direction: column; align-items: stretch; }
.side-tabs-stacked button { text-align: left; }
.side-tabs button {
  font: inherit; font-size: 12px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  padding: 3px 5px; white-space: nowrap; border: 1px solid transparent; border-radius: 5px; background: none; color: var(--muted); cursor: pointer;
}
/* four tabs (with Pins): a little tighter, so they still fit one row at the default width */
.side-tabs:has(> button:nth-child(4):not([hidden])) button { padding: 3px 3px; letter-spacing: 0.01em; font-size: 11.5px; }
.side-tabs button:hover { color: var(--ink); }
.side-tabs button[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); }
.toc-list[hidden], .side-insight[hidden], .side-pins[hidden] { display: none; }
.side-insight { padding: 0 2px 0 8px; font-size: 13px; }
/* The divider that resizes it: drag, arrow keys, double-click to reset. */
.side-resizer { flex: 0 0 7px; margin: 0 -4px 0 -3px; position: relative; z-index: 3; cursor: col-resize; touch-action: none; }
.side-resizer::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 1px; background: transparent; transition: background 0.15s; }
.side-resizer:hover::after, .side-resizer:focus-visible::after, body.side-resizing .side-resizer::after { background: var(--accent); width: 2px; }
.side-resizer:focus { outline: none; }
body.toc-right .side-resizer { order: 1; margin: 0 -3px 0 -4px; }
.toc-pane[hidden] + .side-resizer { display: none; }
body.side-resizing { cursor: col-resize; user-select: none; }
body.side-resizing iframe { pointer-events: none; }
.toc-pane-title { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.toc-pane-head .toc-pane-title { margin: 0; }
.toc-side, .toc-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.toc-side:hover, .toc-close:hover { color: var(--ink); border-color: var(--rule); background: var(--paper); }
.toc-side svg, .toc-close svg { width: 15px; height: 15px; }
/* the side panel's close button: the last thing in its head row */
.toc-close { margin-left: -6px; }
.toc-side, .toc-close { flex: none; width: 22px; }
body.toc-right .toc-side svg { transform: scaleX(-1); }

/* Zoom: − 100% + in the toolbar, and a small floating one in the VS Code preview. */
/* Keep native panning, but let the reader handle two fingers inside the paper. */
body:not(.mode-edit) .tg-paper-pinch { touch-action: pan-x pan-y; }
@media (pointer: coarse) {
  /* Safari does not need to wait for a possible double-tap on these controls. */
  .toolbar button, .toolbar .more-menu a { touch-action: manipulation; }
}
.zoom-group { display: inline-flex; align-items: center; }
.zoom-group[hidden] { display: none; }
.toolbar .zoom-group button { border-radius: 0; padding: 5px 9px; }
.toolbar .zoom-group button:first-child { border-radius: 6px 0 0 6px; }
.toolbar .zoom-group button:last-child { border-radius: 0 6px 6px 0; }
.toolbar .zoom-group button + button { margin-left: -1px; }
.toolbar .zoom-group .zoom-level { min-width: 4.2em; padding: 5px 4px; font-variant-numeric: tabular-nums; }
.zoom-float {
  position: fixed;
  left: 12px;
  bottom: 8px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  font: 12px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--muted);
  opacity: 0.92;
}
.zoom-float[hidden] { display: none; }
/* VS Code: once something is pinned, a pin at the top right lists it all (src/pins.js) */
.pins-float {
  position: fixed; top: 10px; right: 16px; z-index: 40; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 30px; padding: 0; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); cursor: pointer;
}
.pins-float:hover { border-color: var(--accent); }
.pins-float[hidden] { display: none; }
.pins-float .tb-icon { display: block; width: 18px; height: 18px; }
.zoom-float button { font: inherit; color: inherit; background: none; border: 0; padding: 1px 8px; cursor: pointer; }
.zoom-float button:hover { color: var(--ink); }
.zoom-float .zoom-level { min-width: 3.6em; font-variant-numeric: tabular-nums; border-left: 1px solid var(--rule); border-right: 1px solid var(--rule); }
/* Back (and Forward) over the top left of the preview, once a jump has happened (src/scroll.js). */
.tg-history {
  position: fixed;
  z-index: 8;
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  font: 12.5px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  opacity: 0.55;
  transition: opacity 0.2s;
}
.tg-history[hidden] { display: none; }
.tg-history:hover, .tg-history:focus-within, .tg-history.tg-history-fresh { opacity: 1; }
.tg-history button {
  display: inline-flex; align-items: center; gap: 3px;
  font: inherit; color: inherit; background: none; border: 0; padding: 5px 10px 5px 7px; cursor: pointer;
}
.tg-history button[hidden] { display: none; }
.tg-history button:hover:not(:disabled) { color: var(--ink); background: var(--accent-soft); }
.tg-history button:disabled { opacity: 0.45; cursor: default; }
.tg-history .tg-history-fwd { padding: 5px 7px; border-left: 1px solid var(--rule); }
.tg-history svg { width: 14px; height: 14px; flex: none; }
@media (pointer: coarse) { .tg-history button { padding: 9px 13px 9px 10px; } .tg-history .tg-history-fwd { padding: 9px 10px; } }
@media print { .tg-history { display: none !important; } }
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list a {
  display: flex;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 5px;
  border-left: 2px solid transparent;
  color: var(--ink);
  text-decoration: none;
}
.toc-list a:hover { background: var(--accent-soft); }
.toc-list a.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); font-weight: 500; }
.toc-list .toc-num { min-width: 0; flex: 0 0 auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-list a.active .toc-num { color: inherit; }
.toc-list .toc-title { min-width: 0; overflow-wrap: anywhere; }
.toc-list .toc-title .katex { font-size: 1em; }
/* how many things are pinned in a section (src/pins.js) */
.toc-list .tg-toc-pins { margin-left: auto; align-self: center; flex: none; min-width: 1.5em; padding: 0 5px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600; line-height: 1.6; text-align: center; font-variant-numeric: tabular-nums; }
.toc-list .toc-d1 a { padding-left: 20px; }
.toc-list .toc-d2 a { padding-left: 32px; font-size: 13px; }
.toc-list .toc-d3 a { padding-left: 44px; font-size: 13px; }
.toc-list .toc-d0 { margin-top: 4px; }
.toc-list .toc-d0 > a { font-weight: 500; }
@media (max-width: 760px) {
  .toc-pane {
    position: fixed;
    z-index: 20;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 85vw);
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.25);
  }
  body.toc-right .toc-pane { left: auto; right: 0; }
  .side-resizer { display: none; }
}
.icon-button { display: inline-flex; align-items: center; justify-content: center; padding: 5px 7px !important; }
.icon-button svg { width: 18px; height: 18px; }
.icon-button .icon-sun { display: none; }
.theme-dark .icon-button .icon-sun { display: block; }
.theme-dark .icon-button .icon-moon { display: none; }

/* --- syntax colouring and completion -------------------------------------- */

.hl-wrap { position: relative; }
.hl-layer {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  overflow: hidden;
  pointer-events: none;
  white-space: pre-wrap;
  box-sizing: border-box;
  border-style: solid;
  border-color: transparent;
  color: var(--ink);
  background: transparent;
}
.hl-input { position: relative; z-index: 1; background: transparent !important; color: transparent !important; caret-color: var(--ink); }
.hl-input::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); color: transparent; }
.tok-cmd { color: var(--hl-cmd); }
.tok-section { color: var(--hl-cmd); font-weight: 700; }
.tok-kw { color: var(--hl-cmd); }
.tok-env { color: var(--hl-env); font-weight: 600; }
.tok-math { color: var(--hl-math); background: var(--hl-math-bg); border-radius: 2px; }
.tok-math .tok-cmd { color: var(--hl-math); font-weight: 600; }
.tok-delim { font-weight: 700; }
.tok-label { color: var(--hl-label); }
.tok-comment { color: var(--hl-comment); font-style: italic; }
.tok-brace { color: var(--hl-punct); }
.tok-align { color: var(--hl-align); }

.completion {
  position: fixed;
  z-index: 30;
  margin: 0;
  padding: 4px;
  list-style: none;
  min-width: 240px;
  max-width: min(440px, calc(100vw - 16px));
  max-height: 264px;
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
  font: 13px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.completion[hidden] { display: none; }
.completion li { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 4px 8px; border-radius: 5px; cursor: pointer; }
.completion li.active { background: var(--accent-soft); }
.c-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-detail { flex: 0 0 auto; color: var(--muted); font: 12px/1.4 system-ui, sans-serif; white-space: nowrap; }

/* --- the document -------------------------------------------------------- */

.document {
  font-family: "Latin Modern Roman", "Computer Modern Serif", "CMU Serif", Charter, "Iowan Old Style", Georgia, serif;
  /* --zoom is the viewer's zoom level (src/zoom.js); everything inside is in em. */
  font-size: calc(18px * var(--zoom, 1));
  line-height: 1.6;
  hyphens: auto;
  overflow-wrap: break-word;
}

#preview {
  /* --tg-text-width is the reader's own width, from the grips on the text's edges (src/textwidth.js). */
  max-width: calc(var(--tg-text-width, 760px) * var(--zoom, 1));
  margin: 0 auto;
  padding: 40px 16px 24px;
}
/* Dragged to the pane's edge: the text fills the pane (the margin notes keep their column). */
.tg-text-full #preview, .tg-text-full #preview.tg-with-margin, .tg-text-full #preview.tg-with-margin.tg-margin-collapsed { max-width: none; }

/* The grips on the text's edges that change its width (src/textwidth.js). */
.text-resizer {
  position: fixed;
  width: 10px;
  z-index: 3;
  cursor: ew-resize;
  touch-action: none;
}
.text-resizer[hidden] { display: none; }
.text-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 2px;
  background: transparent;
  transition: background 0.15s;
}
.text-resizer:hover::after, .text-resizer:focus-visible::after, body.text-resizing .text-resizer::after { background: var(--accent); }
.text-resizer:focus { outline: none; }
body.text-resizing { cursor: ew-resize; user-select: none; }
body.text-resizing #preview { transition: none; }
/* Phones: the text takes the screen whatever width was set elsewhere; no grips. */
@media (max-width: 760px) and (pointer: coarse) {
  #preview { max-width: calc(760px * var(--zoom, 1)); }
  .text-resizer { display: none !important; }
}

/* Let the browser skip layout and painting for offscreen blocks. Use a
   remembered height once naturally drawn (src/blockheights.js), or 120px
   for a block whose height is not yet known. */
#preview > .src-block {
  content-visibility: auto;
  contain-intrinsic-size: auto 120px;
}
/* While its scrollbar is dragged, the document keeps its length (src/blockheights.js). */
#preview.tg-frozen {
  box-sizing: border-box; height: var(--tg-frozen-h); min-height: 0; max-height: none;
  /* Positioned descendants with a containing block outside the preview can
     otherwise make the pane grow even though the preview itself is clipped. */
  contain: paint; overflow-y: clip;
}
.tg-scrollbar-held { overflow-anchor: none; }

.document p { margin: 0 0 0.9em; }
.document a { color: var(--accent); text-decoration: none; }
.document a:hover { text-decoration: underline; }

.title-block { text-align: center; margin-bottom: 2.2em; }
.doc-title { font-size: 1.9em; line-height: 1.2; margin: 0.4em 0 0.5em; font-weight: 600; }
.authors { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.3em 2em; font-variant: small-caps; font-size: 1.05em; }
.doc-date { color: var(--muted); margin-top: 0.4em; }

.document h1, .document h2, .document h3, .document h4 { line-height: 1.3; font-weight: 600; }
.document h1.chapter { font-size: 1.8em; margin: 2em 0 0.8em; }
.document h1.part { font-size: 2em; text-align: center; margin: 2em 0 1em; }
.document h2 { font-size: 1.4em; margin: 1.8em 0 0.6em; }
.document h3 { font-size: 1.18em; margin: 1.5em 0 0.5em; }
.document h4 { font-size: 1.02em; margin: 1.3em 0 0.4em; }
.secnum { margin-right: 0.8em; }
.run-in { margin-right: 0.4em; }

.abstract { margin: 0 2.5em 2em; font-size: 0.93em; }
.abstract-title { text-align: center; font-weight: 600; font-variant: small-caps; margin-bottom: 0.4em; }
.keywords { margin: 0 2.5em 0.4em; font-size: 0.93em; }
.keywords-head { font-variant: small-caps; margin-right: 0.3em; }

.toc { margin: 0 0 2em; padding: 0.8em 1.2em; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); }
.toc h2 { font-size: 1.05em; margin: 0 0 0.4em; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0.15em 0; }
.toc .toc-l3 { padding-left: 1.5em; }
.toc .toc-l4 { padding-left: 3em; }
.toc-num { display: inline-block; min-width: 2.2em; }

/* Theorem-like environments */
.theorem {
  margin: 1.2em 0;
  padding: 0.7em 1em 0.1em;
  border-left: 3px solid var(--thm-border);
  background: var(--thm-bg);
  border-radius: 0 6px 6px 0;
}
.thm-plain p { font-style: italic; }
.thm-plain .item-label { font-style: normal; }
.thm-plain .thm-head, .thm-plain .math, .thm-plain .ref { font-style: normal; }
.thm-plain .thm-head .thm-note { font-style: normal; }
.thm-definition { border-left-color: var(--def-border); background: var(--def-bg); }
.thm-remark { background: transparent; border-left-color: var(--rule); }
.thm-head .thm-name { font-weight: 700; }
.thm-remark .thm-head .thm-name { font-weight: 400; font-style: italic; }
.thm-head-only { margin-bottom: 0.3em; }

.proof { margin: 0.6em 0 1.4em; }
.proof-head { font-style: italic; }
.qed { float: right; margin-left: 1em; }
.qed-line { overflow: hidden; margin: 0; }

/* Math */
.math-display { margin: 0.8em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.math-display .katex-display { margin: 0; }
/* A formula wider than the column scrolls sideways, but its scrollbar stays
   hidden until the pointer is over the formula (or it has keyboard focus; src/widemath.js
   lets Tab reach a formula that overflows):
   the bar keeps its space, only its colours fade, so nothing moves on hover.
   On touch screens there is no bar at all; a swipe still scrolls. */
.math-display { scrollbar-width: thin; scrollbar-color: transparent transparent; }
.math-display:hover, .math-display:focus-within { scrollbar-color: color-mix(in srgb, currentColor 35%, transparent) transparent; }
.math-display:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.math-display::-webkit-scrollbar { height: 8px; }
.math-display::-webkit-scrollbar-track { background: transparent; }
.math-display::-webkit-scrollbar-thumb { background: transparent; border-radius: 4px; }
.math-display:hover::-webkit-scrollbar-thumb, .math-display:focus-within::-webkit-scrollbar-thumb { background: color-mix(in srgb, currentColor 35%, transparent); }
@media (hover: none) {
  .math-display { scrollbar-width: none; }
  .math-display::-webkit-scrollbar { display: none; }
}
/* KaTeX puts an equation number at the right edge of the box (position:
   absolute), so in a box narrower than the formula, such as the hover popover
   or a narrow pane, it is drawn over the formula. Lay the number out beside the
   formula instead: centred while there is room, and scrolled with it when not. */
.math-display .katex-display > .katex > .katex-html:has(> .tag) { display: flex; align-items: baseline; }
.math-display .katex-display > .katex > .katex-html:has(> .tag)::before { content: ''; flex: 1 1 0; }
.math-display .katex-display > .katex > .katex-html:has(> .tag) > .base { flex: none; }
.math-display .katex-display > .katex > .katex-html > .tag {
  position: static; flex: 1 0 0; min-width: max-content; padding-left: 1em; text-align: right;
}
.math-display .katex-display.leqno > .katex > .katex-html > .tag { order: -1; padding: 0 1em 0 0; text-align: left; }
.math-error, .math-src { color: var(--missing); font-family: ui-monospace, monospace; font-size: 0.85em; }

/* References */
.ref-missing { color: var(--missing); font-weight: 700; cursor: help; }
.cite-key { font-family: ui-monospace, monospace; font-size: 0.85em; }
.flash { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: var(--flash); } }

/* The outer box is transparent and padded, so the 8px gap between the link
   and the card is part of the popover: the pointer can cross it without the
   popover closing, then scroll inside the card. */
.ref-popover {
  position: fixed;
  z-index: 10;
  padding: 8px 0;
  font-size: calc(16px * var(--zoom, 1));
}
.ref-popover[hidden] { display: none; }
.ref-popover-body {
  position: relative; /* keeps KaTeX's MathML inside the scroll box */
  max-height: 75vh; /* and no taller than the room beside the link (src/popover.js) */
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0.6em 1em;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}
.ref-popover .theorem, .ref-popover .math-display { margin: 0; }
/* A footnote previewed from its mark: the note's text, at the footnotes' size. */
.ref-popover .fn-preview { font-size: 0.92em; }
.ref-popover .fn-preview > p:first-child { margin-top: 0; }
.ref-popover .fn-preview > p:last-child { margin-bottom: 0; }

/* The hypothesis checker (src/hypotheses.js): a result cited in a proof, split
   into its hypotheses (with boxes to tick) and its conclusion. */
.hyp-check { border-left: 3px solid var(--thm-border); background: var(--thm-bg); padding: 8px 12px 6px; border-radius: 0 4px 4px 0; }
.hyp-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 4px; margin-bottom: 4px; }
.hyp-note { font-style: italic; }
.hyp-count { color: var(--muted); font-size: 0.85em; }
.hyp-all-done .hyp-count { color: var(--hl-math); }
.hyp-switch { margin-left: auto; font: inherit; font-size: 0.8em; padding: 1px 8px; border: 1px solid var(--rule); border-radius: 4px; background: var(--paper); color: var(--accent); cursor: pointer; }
.hyp-switch:hover, .hyp-switch:focus-visible { border-color: var(--accent); outline: none; }
.hyp-switch-back { display: block; margin: 6px 0 0 auto; }
.hyp-switch[hidden] { display: none; }
.hyp-sec { margin: 6px 0 2px; font-size: 0.75em; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.hyp-list { list-style: none; margin: 0; padding: 0; }
.hyp-item { display: flex; align-items: flex-start; gap: 8px; padding: 2px 0; }
.hyp-box { flex: none; margin: 0.3em 0 0; width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.hyp-text { flex: 1; min-width: 0; }
.hyp-text p, .hyp-concl p, .hyp-from + * p { display: inline; margin: 0; }
.hyp-text .math-display, .hyp-concl .math-display { margin: 4px 0; }
.hyp-done .hyp-text { color: var(--muted); }
.hyp-label { font-weight: 600; }
.hyp-from { font-weight: 600; font-size: 0.92em; }
.hyp-from + .theorem, .hyp-from + .item-body { display: inline; margin: 0; padding: 0; border: 0; background: none; }
.hyp-hint { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 8px; font-size: 0.75em; font-style: normal; color: var(--warn); border: 1px solid currentColor; white-space: nowrap; cursor: help; }
.hyp-done .hyp-hint { display: none; }
.hyp-concl { padding-left: 23px; }
.hyp-concl-part + .hyp-concl-part { margin-top: 2px; }
.hyp-standing { margin-top: 6px; }
.hyp-standing > summary { cursor: pointer; font-size: 0.75em; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.hyp-standing > .hyp-list { margin-top: 2px; }
.hyp-written[hidden], .hyp-check[hidden] { display: none; }
@media print { .hyp-switch { display: none; } }

/* Notation on hover, the notation index and the dependency map (src/insight.js). */
.insight-pop-body { font-size: 0.9em; }
.insight-pop-title, .insight-usedby-k {
  font-size: 0.78em; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
}
.insight-pop-title { margin-bottom: 0.3em; }
.insight-note { padding: 0.35em 0; border-top: 1px solid var(--rule); }
.insight-note:first-of-type { border-top: 0; }
.insight-note-what { overflow-x: auto; }
.insight-note-what code, .insight-table code { font-size: 0.85em; background: var(--code-bg); padding: 0 0.3em; border-radius: 3px; overflow-wrap: anywhere; }
.insight-note-where, .insight-uses, .insight-muted { color: var(--muted); font-size: 0.9em; }
.insight-note .math-display { margin: 0.2em 0; }
.insight-sentence { line-height: 1.5; }
.insight-sentence p { display: inline; margin: 0; text-indent: 0; }
.insight-sentence p + p::before { content: " "; }
.insight-sentence .math-display { margin: 0.2em 0; }
.insight-defined { background: var(--flash); border-radius: 3px; box-shadow: 0 0 0 2px var(--flash); }
.insight-note-where .insight-sym { color: var(--ink); }
.insight-symbols .insight-sentence { font-size: 0.92em; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.insight-usedby { margin-top: 0.6em; padding-top: 0.5em; border-top: 1px solid var(--rule); font-size: 0.88em; line-height: 1.6; }
.insight-dialog {
  width: min(1100px, calc(100vw - 32px));
  height: min(760px, calc(100vh - 48px));
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}
.insight-dialog[open] { display: flex; flex-direction: column; }
/* The larger map takes nearly the whole window. */
.insight-dialog.insight-dialog-map { width: calc(100vw - 24px); height: calc(100vh - 24px); max-width: none; max-height: none; }
/* A result previewed from the map: the text's own font, at the popover's size. */
.dep-preview-text { font-size: inherit; line-height: 1.55; }
.dep-preview-text .theorem { margin: 0; }
.insight-dialog::backdrop { background: rgba(0, 0, 0, 0.3); }
.insight-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.insight-tabs { display: flex; gap: 4px; }
.insight-tabs button, .insight-close {
  font: inherit; border: 1px solid transparent; border-radius: 6px; padding: 4px 12px; background: none; color: var(--ink); cursor: pointer;
}
.insight-tabs button[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.insight-hover { margin-left: auto; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.insight-close { font-size: 20px; line-height: 1; padding: 2px 8px; }
.insight-body { flex: 1; overflow: auto; padding: 12px 16px 16px; }
.insight-body h3 { font-size: 15px; margin: 16px 0 6px; }
.insight-count { color: var(--muted); font-weight: normal; margin-left: 4px; }
.insight-filter { width: min(360px, 100%); font: inherit; padding: 6px 10px; border: 1px solid var(--rule); border-radius: 6px; background: var(--bg); color: var(--ink); }
/* The notation index: search, the order switch, and groups that fold. */
.insight-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.insight-tools .insight-filter { flex: 1 1 200px; }
.insight-order { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; flex: none; }
.insight-order button { font: inherit; font-size: 12.5px; padding: 4px 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; min-height: 28px; }
.insight-order button + button { border-left: 1px solid var(--rule); }
.insight-order button[aria-checked="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.insight-group { margin: 10px 0 0; }
.insight-group > summary { cursor: pointer; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; color: var(--muted); padding: 4px 0; list-style-position: outside; }
.insight-group > summary::marker { color: var(--muted); }
.insight-group > summary .insight-count { font-weight: 400; margin-left: 2px; }
.insight-group-used { background: var(--accent-soft); border-radius: 6px; padding: 2px 8px 4px; margin: 6px 0 4px; }
.insight-group-used > summary { color: var(--accent); }
/* Pins: a row (or "Used in …") pinned by the reader. In the side panel the
   pinned block stays in view under the tabs while the list scrolls (the head
   sticks at -34px from inside the panel's 20px padding). */
.insight-pin { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 22px; margin-left: 4px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--muted); opacity: 0.45; cursor: pointer; vertical-align: middle; }
.insight-pin svg { width: 14px; height: 14px; }
.insight-pin:hover, .insight-pin:focus-visible { opacity: 1; color: var(--accent); }
.insight-pin[aria-pressed="true"] { opacity: 1; color: var(--accent); }
.insight-pin[aria-pressed="true"] svg path { fill: var(--accent-soft); }
.insight-symbols li:hover .insight-pin, .insight-table tr:hover .insight-pin { opacity: 1; }
@media (pointer: coarse) { .insight-pin { width: 36px; height: 36px; opacity: 0.8; } .insight-pin svg { width: 17px; height: 17px; } }
/* the pin on a preview: a symbol to the Notation tab, a referenced result or equation to the map (both to Pinned) */
.insight-note { position: relative; }
.insight-note > .insight-pop-pin { position: absolute; top: 0; right: -4px; opacity: 0.7; }
.insight-note:has(> .insight-pop-pin) { padding-right: 26px; }
.tg-ref-pin { float: right; position: relative; z-index: 1; margin: -2px -4px 2px 8px; opacity: 0.7; }
.insight-row-end { display: inline-flex; align-items: center; gap: 2px; justify-content: space-between; }
.insight-group-used > summary .insight-pin { margin-left: 6px; }
.insight-group-pinned { background: var(--code-bg); border-radius: 6px; padding: 2px 8px 4px; margin: 6px 0 4px; }
.insight-group-pinned .insight-table tr:first-child, .insight-group-pinned .insight-symbols li:first-child { border-top-color: transparent; }
/* Pinned rows reorder by dragging their handle (pointer events: mouse, pen, touch). */
.insight-pin-item { display: flex; align-items: flex-start; gap: 2px; border-top: 1px solid var(--rule); background: var(--code-bg); }
.insight-pin-item:first-child { border-top-color: transparent; }
.insight-pin-body { flex: 1; min-width: 0; }
.insight-pin-body .insight-table tr, .insight-pin-body .insight-symbols li { border-top: 0; }
.insight-drag { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 18px; min-height: 30px; margin: 4px 0 0 -6px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: grab; touch-action: none; opacity: 0.6; }
.insight-drag svg { width: 8px; height: 14px; }
.insight-drag:hover, .insight-drag:focus-visible { opacity: 1; color: var(--accent); }
.insight-dragging { position: relative; z-index: 1; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); border-radius: 6px; background: var(--accent-soft); }
.insight-dragging .insight-drag { cursor: grabbing; }
@media (pointer: coarse) { .insight-drag { width: 30px; min-height: 40px; opacity: 0.8; } .insight-drag svg { width: 10px; height: 18px; } }
.side-insight .insight-stuck { position: sticky; top: calc(var(--side-head-h, 40px) - 34px); z-index: 1; background: var(--bg); max-height: 45vh; overflow-y: auto; overscroll-behavior: contain; }
.side-insight .insight-stuck:empty { display: none; }
.side-insight .insight-stuck .insight-group > summary { list-style-position: inside; }
.side-insight .insight-stuck .insight-group { margin-top: 0; margin-bottom: 4px; }
.side-insight .insight-stuck:not(:empty) + .insight-used .insight-group-used { margin-top: 6px; }
.side-insight .insight-symbols li, .side-insight .insight-table tr { scroll-margin-top: 30vh; }
.insight-chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 0 4px; }
.insight-chip { font: inherit; font-size: 15px; line-height: 1.2; min-width: 30px; min-height: 28px; padding: 2px 7px; border: 1px solid var(--rule); border-radius: 5px; background: var(--bg); color: var(--ink); cursor: pointer; }
.insight-chip:hover, .insight-chip:focus-visible { border-color: var(--accent); }
.insight-chip code { font-size: 12px; }
@media (pointer: coarse) { .insight-chip { min-height: 36px; min-width: 36px; } }
@keyframes insight-flash { from { background: var(--accent-soft); } to { background: transparent; } }
.insight-flash { animation: insight-flash 1.6s ease-out; }
.insight-group + .insight-group > .insight-table tr:first-child { border-top: 1px solid var(--rule); }
.insight-symbols li[hidden], .insight-group[hidden], .insight-table tr[hidden] { display: none; }
.insight-nomatch { color: var(--muted); font-size: 13px; }
@media (pointer: coarse) { .insight-order button { min-height: 36px; padding: 6px 12px; } }
.insight-table { border-collapse: collapse; width: 100%; }
.insight-table td { padding: 5px 8px; border-top: 1px solid var(--rule); vertical-align: middle; }
.insight-sym-cell { min-width: 3em; text-align: center; font-size: 17px; }
.insight-def { max-width: 420px; }
.insight-first a, .insight-symbols a { white-space: nowrap; }
.insight-uses { display: block; }
.insight-symbols { list-style: none; padding: 0; margin: 0; }
.insight-symbols li { display: grid; grid-template-columns: minmax(5em, auto) 1fr auto; gap: 14px; align-items: center; padding: 6px 4px; border-top: 1px solid var(--rule); }
.insight-symbols li > .insight-sym { font-size: 17px; }
.insight-sym-src { overflow-x: auto; font-size: 15px; }
.insight-sym-src .math-display { margin: 0; text-align: left; }
.insight-body [hidden] { display: none; }
.insight-empty, .insight-lead { color: var(--muted); max-width: 70ch; }
.dep-wrap { overflow: auto; border: 1px solid var(--rule); border-radius: 8px; background: var(--bg); max-height: 60%; }
.insight-body:has(.dep-wrap) { display: flex; flex-direction: column; }
.dep-wrap { flex: 1 1 auto; min-height: 160px; }
.dep-map { display: block; font-size: 12px; }
.insight-dialog .dep-wrap { max-height: none; cursor: grab; }
.insight-dialog .dep-wrap.dep-dragging, .dep-wrap.dep-dragging { cursor: grabbing; user-select: none; }
/* The text around the larger map keeps its full height; the map takes what is left. */
.insight-dialog .insight-body:has(.dep-wrap) > :not(.dep-wrap) { flex: 0 0 auto; }
.insight-dialog .dep-wrap { min-height: 120px; }
.insight-dialog .insight-lead { margin: 0 0 6px; max-width: none; }
.dep-zoom { display: inline-flex; align-items: center; margin-left: auto; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.dep-zoom button { font: inherit; font-size: 13px; min-width: 30px; padding: 2px 8px; border: 0; border-left: 1px solid var(--rule); background: var(--paper); color: var(--ink); cursor: pointer; }
.dep-zoom button:first-child { border-left: 0; }
.dep-zoom button:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.dep-zoom button:disabled { color: var(--muted); opacity: 0.5; cursor: default; }
.dep-zoom .dep-zoom-level { min-width: 52px; font-variant-numeric: tabular-nums; }
.dep-edge { fill: none; stroke: var(--muted); stroke-width: 1.1; opacity: 0.55; }
.dep-arrowhead { fill: var(--muted); }
.dep-node { cursor: pointer; outline: none; }
.dep-node rect { fill: var(--paper); stroke: var(--thm-border); stroke-width: 1.2; }
.dep-node text { fill: var(--ink); }
.dep-node.dep-main rect { stroke-width: 2; fill: var(--thm-bg); }
.dep-node.dep-definition rect { stroke: var(--def-border); fill: var(--def-bg); }
.dep-node.dep-remark rect { stroke: var(--rule); }
.dep-node:hover rect, .dep-node:focus-visible rect { stroke: var(--accent); stroke-width: 2; }
.dep-picked .dep-node:not(.dep-sel):not(.dep-up):not(.dep-down) { opacity: 0.3; }
.dep-picked .dep-edge { opacity: 0.12; }
.dep-picked .dep-edge.dep-lit { opacity: 0.9; stroke: var(--accent); stroke-width: 1.6; }
.dep-node.dep-sel rect { fill: var(--accent); stroke: var(--accent); }
.dep-node.dep-sel text { fill: var(--paper); font-weight: 600; }
.dep-node.dep-up rect { stroke: var(--accent); stroke-width: 2; }
.dep-node.dep-down rect { stroke: var(--warn); stroke-width: 2; }
.dep-detail { padding: 10px 2px 0; line-height: 1.6; }
/* Kinds of link: used in a proof (solid), named in a statement (dotted),
   guessed from the wording (dashed, lighter), to a cited work (thin). */
.dep-edge.dep-stmt { stroke-dasharray: 1.5 3; stroke-linecap: round; stroke-width: 1.5; }
.dep-edge.dep-guess { stroke-dasharray: 6 4; stroke-linecap: butt; stroke-width: 1.1; opacity: 0.45; }
.dep-edge.dep-cite-edge { stroke-width: 0.8; opacity: 0.4; }
.dep-picked .dep-edge.dep-lit.dep-guess { opacity: 0.7; }
.dep-node.dep-citenode rect { fill: var(--bg); stroke: var(--rule); stroke-dasharray: 3 2; }
.dep-node.dep-citenode text { fill: var(--muted); font-style: italic; font-size: 11px; }
.dep-node.dep-citenode.dep-sel text { fill: var(--paper); }
.dep-band rect { fill: var(--ink); opacity: 0.025; }
.dep-band.dep-band-odd rect { opacity: 0.055; }
.dep-band text { fill: var(--muted); font-size: 11px; letter-spacing: 0.02em; }
.dep-fold { cursor: pointer; outline: none; }
.dep-fold rect { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1; }
.dep-fold text { fill: var(--accent); font-size: 10.5px; font-weight: 600; }
.dep-fold:hover rect, .dep-fold:focus-visible rect { stroke-width: 2; }
.dep-node.dep-has-fold rect { stroke-width: 2; }
/* The reader's changes to the map: pins, hidden results, their own links, dragging. */
.dep-pin-mark circle { fill: var(--accent); stroke: var(--paper); stroke-width: 1.2; }
.dep-pin-mark path { fill: var(--paper); }
.dep-node.dep-pinned rect { stroke: var(--accent); stroke-width: 2.2; }
.dep-node.dep-pinned-sub rect { stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 4 2; }
.dep-node.dep-hidden, .dep-edge.dep-hidden { opacity: 0.3; }
.dep-node.dep-hidden rect { stroke-dasharray: 2 2; }
.dep-edge.dep-mine { stroke: var(--accent); stroke-width: 1.6; opacity: 0.8; stroke-dasharray: 8 3; }
.dep-edge.dep-eq-edge { stroke-width: 0.9; opacity: 0.45; stroke-dasharray: 1 2.5; stroke-linecap: round; }
.dep-node.dep-eqnode rect { fill: var(--bg); stroke: var(--accent); stroke-width: 1; }
.dep-node.dep-eqnode text { fill: var(--accent); font-size: 11.5px; }
.dep-node.dep-eqnode.dep-sel text { fill: var(--paper); }
.dep-node.dep-moving { cursor: grabbing; }
.dep-node.dep-moving rect { stroke: var(--accent); stroke-width: 2; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25)); }
.dep-wrap.dep-node-dragging { user-select: none; cursor: grabbing; }
.dep-map:not(.dep-linking) .dep-node { touch-action: pan-x pan-y; }
.dep-map.dep-linking .dep-node { cursor: crosshair; }
.dep-map.dep-linking .dep-node:hover rect { stroke: var(--accent); stroke-width: 2.5; }
.dep-opts button, .dep-pins button, .dep-edit button {
  font: inherit; font-size: 12px; padding: 1px 7px; border: 1px solid var(--rule); border-radius: 5px;
  background: var(--paper); color: var(--ink); cursor: pointer; line-height: 1.5;
}
.dep-opts button:hover, .dep-pins button:hover, .dep-edit button:hover { border-color: var(--accent); color: var(--accent); }
.dep-edit button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.dep-pins { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0 0 6px; font-size: 12.5px; color: var(--muted); }
.dep-pins-count { display: inline-flex; align-items: center; gap: 4px; color: var(--ink); }
.dep-views { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.dep-view { display: inline-flex; }
.dep-view button:first-child { border-radius: 5px 0 0 5px; }
.dep-view .dep-view-del { border-left: 0; border-radius: 0 5px 5px 0; padding: 1px 5px; color: var(--muted); }
.dep-view-new { display: inline-flex; gap: 4px; }
.dep-view-name { font: inherit; font-size: 12.5px; padding: 1px 6px; border: 1px solid var(--accent); border-radius: 5px; background: var(--paper); color: var(--ink); width: 11em; }
.dep-edit { margin: 8px 0 2px; padding-top: 6px; border-top: 1px solid var(--rule); line-height: 2; }
.dep-pin-btns { display: inline-flex; flex-wrap: wrap; gap: 3px; }
.dep-linking-hint { color: var(--accent); font-weight: 600; }
.dep-unlink, .dep-relink { font: inherit; font-size: 11px; line-height: 1.2; padding: 0 4px; border: 1px solid var(--rule); border-radius: 4px; background: var(--paper); color: var(--muted); cursor: pointer; }
.dep-unlink:hover { color: var(--warn); border-color: var(--warn); }
.dep-tag-mine { color: var(--accent); border-color: var(--accent); }
.dep-map:not(.dep-locked):not(.dep-linking) .dep-node { cursor: grab; }
.dep-history { display: inline-flex; }
.dep-opts .dep-history button { padding: 0 8px; font-size: 14px; line-height: 1.4; }
.dep-opts .dep-history button:first-child { border-radius: 5px 0 0 5px; }
.dep-opts .dep-history button:last-child { border-left: 0; border-radius: 0 5px 5px 0; }
.dep-opts button:disabled { opacity: 0.4; cursor: default; border-color: var(--rule); color: var(--muted); }
.dep-note { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 6px; padding: 2px 4px 2px 10px; border-radius: 6px; background: var(--accent-soft); color: var(--ink); font-size: 12.5px; }
.dep-note button { font: inherit; font-size: 12px; font-weight: 600; padding: 1px 8px; border: 0; border-radius: 4px; background: none; color: var(--accent); cursor: pointer; }
.dep-note button:hover { text-decoration: underline; }
.dep-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0 0 6px; padding: 6px 10px; border: 1px solid var(--warn); border-radius: 6px; font-size: 12.5px; }
.dep-confirm span { flex: 1 1 260px; }
.dep-confirm button { font: inherit; font-size: 12px; padding: 1px 9px; border: 1px solid var(--rule); border-radius: 5px; background: var(--paper); color: var(--ink); cursor: pointer; }
.dep-confirm .dep-confirm-yes { background: var(--warn); border-color: var(--warn); color: var(--paper); }
.dep-view-on button { border-color: var(--accent); }
.dep-view-on button:first-child { background: var(--accent); color: var(--paper); }
.dep-pins .dep-view-update { border-color: var(--accent); color: var(--accent); }
.dep-opts { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.dep-opts label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.dep-legend { display: flex; flex-wrap: wrap; gap: 2px 14px; margin: 6px 2px 0; font-size: 12px; color: var(--muted); }
.dep-legend > span { display: inline-flex; align-items: center; gap: 4px; }
.dep-legend svg { overflow: visible; }
.dep-legend .dep-edge { opacity: 0.9; }
.dep-key-cite { display: inline-block; width: 26px; height: 11px; border: 1px dashed var(--muted); border-radius: 6px; }
.dep-key-fold { display: inline-block; padding: 0 5px; border: 1px solid var(--accent); border-radius: 7px; color: var(--accent); background: var(--accent-soft); font-size: 10px; font-weight: 600; line-height: 13px; }
.dep-tag { font-size: 0.78em; color: var(--muted); border: 1px solid var(--rule); border-radius: 4px; padding: 0 4px; white-space: nowrap; }
.dep-tag-guess { border-style: dashed; }
.dep-detail a.dep-l-guess { text-decoration-style: dashed; }
.dep-preview-bib { list-style: none; margin: 0; padding: 0; }
.dep-preview-text .bibliography { margin: 0; border: 0; padding: 0; }
.dep-detail p { margin: 4px 0; }
.dep-detail-head { font-size: 15px; }
.dep-go { margin-left: 10px; font-size: 13px; }
.insight-dialog a, .insight-pop-body a, .insight-usedby a, .side-insight a { color: var(--accent); }
/* In the side panel the index stacks: symbol and command, then its definition and first use. */
.insight-side h3 { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 14px 0 4px; }
.insight-side .insight-filter { width: 100%; font-size: 13px; padding: 5px 8px; }
.insight-side .insight-tools { flex-direction: column; align-items: stretch; gap: 6px; }
.insight-side .insight-tools .insight-filter { flex: none; }
.insight-side .insight-order { display: flex; }
.insight-side .insight-order button { flex: 1; padding: 3px 6px; }
.insight-side .insight-table, .insight-side .insight-table tbody { display: block; }
.insight-side .insight-table tr { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; padding: 6px 0; border-top: 1px solid var(--rule); }
.insight-side .insight-table tr[hidden] { display: none; }
.insight-side .insight-table td { padding: 0; border: 0; }
.insight-side .insight-sym-cell { min-width: 1.6em; font-size: 15px; text-align: left; }
.insight-side .insight-def, .insight-side .insight-first { grid-column: 1 / -1; max-width: none; }
.insight-side .insight-first a { white-space: normal; }
.insight-side .insight-uses { display: inline; margin-left: 6px; }
.insight-side .insight-symbols li { grid-template-columns: 1fr; gap: 2px; }
.insight-side .insight-symbols li > .insight-sym { display: none; }
.insight-side .insight-hover { margin: 14px 0 0; font-size: 12px; }
.insight-side .insight-lead { font-size: 12px; margin: 0 0 8px; }
.insight-side .dep-wrap { max-height: 55vh; }
.insight-side .dep-detail { font-size: 13px; }
.insight-side .dep-opts, .insight-side .dep-legend { font-size: 11.5px; }
.insight-side .dep-detail-head { font-size: 14px; }

/* Picking a result on the map (select → understand → read): a ring around it,
   its own links lit and its neighbours outlined (solid: what it uses; dashed:
   where it is used), the rest dimmed but where it was; section bands stay. */
.dep-sel-ring { fill: none; stroke: var(--ink); stroke-width: 1.6; pointer-events: none; }
.dep-node.dep-down rect { stroke-dasharray: 5 2.5; }
.dep-node:focus-visible rect { stroke: var(--ink); stroke-width: 2.5; stroke-dasharray: 3 2; }
.dep-node.dep-sel:focus-visible rect { stroke: var(--ink); }
/* Its detail: name, section, Read result and Pin stay in view as the lists scroll. */
.dep-detail-head { position: sticky; top: 0; z-index: 1; background: var(--paper); padding: 6px 0 8px; margin-bottom: 4px; border-bottom: 1px solid var(--rule); }
.insight-side .dep-detail-head { background: var(--bg); top: calc(var(--side-head-h, 40px) - 20px); }
.dep-detail-title { outline: none; line-height: 1.35; }
.dep-detail-title:focus-visible { box-shadow: 0 0 0 2px var(--accent); border-radius: 3px; }
.dep-detail-note { color: var(--muted); }
.dep-detail-sec { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.dep-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.dep-actions button {
  display: inline-flex; align-items: center; gap: 5px; font: inherit; font-size: 13px; font-weight: 600; min-height: 32px; padding: 3px 12px;
  border: 1px solid var(--accent); border-radius: 6px; background: var(--paper); color: var(--accent); cursor: pointer;
}
.dep-actions .dep-read { background: var(--accent); color: var(--paper); }
.dep-actions button svg { width: 15px; height: 15px; }
.dep-actions button:hover { filter: brightness(1.08); }
.dep-actions button:focus-visible, .dep-li:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.dep-actions .dep-pin-one[aria-pressed="true"] { background: var(--accent-soft); }
.dep-actions .dep-pin-one[aria-pressed="true"] svg path { fill: currentColor; }
@media (pointer: coarse) { .dep-actions button { min-height: 40px; padding: 4px 14px; } }
.dep-list { margin: 4px 0; }
.dep-list > summary { cursor: pointer; padding: 3px 0; list-style-position: inside; }
.dep-list > summary .dep-count { color: var(--muted); }
.dep-list ul { list-style: none; margin: 2px 0 4px; padding: 0 0 0 14px; }
.dep-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; padding: 1px 0; }
.dep-li { font: inherit; text-align: left; padding: 2px 4px; margin-left: -4px; border: 0; border-radius: 4px; background: none; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.dep-li .insight-muted { text-decoration: none; display: inline-block; }
.dep-li.dep-l-guess { text-decoration-style: dashed; }
.dep-li:hover { background: var(--accent-soft); }
@media (pointer: coarse) { .dep-li { min-height: 36px; } }
.dep-list-empty .insight-muted { font-size: 12.5px; }
.dep-chain { font-size: 12.5px; }
.dep-tag-proof { border-style: solid; }
.dep-tag-stmt { border-style: dotted; }
/* The larger map: the detail is an inspector beside the map. */
.dep-stage { display: flex; gap: 14px; min-height: 0; }
.dep-map-col { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; min-height: 0; }
.insight-dialog .insight-body:has(.dep-stage) > .dep-stage { flex: 1 1 auto; }
.insight-dialog .dep-map-col > .dep-wrap { flex: 1 1 auto; }
.insight-dialog .dep-map-col > :not(.dep-wrap) { flex: 0 0 auto; }
.insight-dialog .dep-stage > .dep-detail { flex: 0 0 300px; overflow-y: auto; padding: 0 4px 0 0; overscroll-behavior: contain; }
/* A phone: the larger map on top, the detail a short sheet under it, with its
   lists folded; in the side panel the detail sticks to the bottom as a sheet. */
@media (max-width: 760px) {
  .insight-dialog-map .insight-lead, .insight-dialog-map .insight-hover, .insight-dialog-map .dep-pins > .insight-muted { display: none; }
  .insight-dialog-map .insight-body { padding: 8px 10px 10px; }
  .dep-stage { flex-direction: column; gap: 6px; }
  .insight-dialog .dep-map-col { flex: 1 1 auto; min-height: 180px; }
  .insight-dialog .dep-stage > .dep-detail { flex: 0 1 auto; max-height: 42%; padding: 0 2px; border-top: 1px solid var(--rule); }
  .insight-side .dep-detail.dep-detail-on {
    position: sticky; bottom: 0; z-index: 2; max-height: 44vh; overflow-y: auto; overscroll-behavior: contain;
    margin: 0 -10px 0 -16px; padding: 0 10px 8px 16px; background: var(--bg); border-top: 1px solid var(--rule); box-shadow: 0 -6px 14px rgba(0, 0, 0, 0.12);
  }
  .insight-side .dep-detail.dep-detail-on .dep-detail-head { top: 0; }
}

/* Click a formula to copy its LaTeX (src/copytex.js). */
.math-copyable .math[data-tex] { cursor: copy; border-radius: 4px; transition: background-color 0.15s; }
.math-copyable .math[data-tex]:hover { background: var(--accent-soft); }
.math-copyable .math[data-tex].copied { animation: flash 0.7s ease-out; }
/* …and, in VS Code and Overleaf, a theorem's name to copy its \label. */
.label-copyable .theorem[data-label] .thm-name, .label-copyable .hyp-view[data-label] .hyp-title { cursor: copy; border-radius: 4px; transition: background-color 0.15s; }
.label-copyable .theorem[data-label] .thm-name:hover, .label-copyable .hyp-view[data-label] .hyp-title:hover { background: var(--accent-soft); }
.label-copyable .thm-name.copied, .label-copyable .hyp-title.copied { animation: flash 0.7s ease-out; }
.copy-toast {
  position: fixed;
  z-index: 30;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--paper);
  font: 12px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.copy-toast.show { opacity: 1; }
.copy-toast.failed { background: var(--missing); color: #fff; }
.copy-toast[hidden] { display: none; }

/* Lists */
.list { list-style: none; padding: 0; margin: 0 0 0.9em; }
.list .item { display: flex; gap: 0.6em; margin: 0.25em 0; }
.item-label { flex: 0 0 auto; min-width: 1.6em; text-align: right; }
.description .item-label { font-weight: 700; min-width: 0; text-align: left; }
.item-body { flex: 1; min-width: 0; }
.item-body > p:last-child { margin-bottom: 0; }
.list .list { margin-top: 0.25em; }

/* Floats and tables */
.float { margin: 1.5em 0; text-align: center; }
.caption { font-size: 0.93em; margin-top: 0.5em; }
.caption-head { font-weight: 600; }
.table-wrap { overflow-x: auto; }
.tabular { border-collapse: collapse; margin: 0 auto; }
.tabular td { padding: 0.25em 0.8em; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.graphic { max-width: 100%; }
.graphic-placeholder {
  display: inline-block;
  padding: 1.5em 2em;
  border: 1px dashed var(--rule);
  color: var(--muted);
  font-size: 0.85em;
  font-family: ui-monospace, monospace;
}

/* Diagrams (tikzcd, xymatrix, tikzpicture): src/tikz.js + src/diagrams.js */
.tg-diagram { display: block; margin: 0.8em 0; text-align: center; overflow-x: auto; overflow-y: hidden; position: relative; }
.math-inline .tg-diagram, .diagram-display .tg-diagram, .float .tg-diagram { display: inline-block; margin: 0; vertical-align: middle; max-width: 100%; }
/* tree symbols (\<b0>) drawn inside formulas */
.tg-diagram.tg-tree { display: inline; margin: 0; overflow: visible; }
.cd-wrap { display: inline-block; position: relative; vertical-align: middle; text-align: left; }
.cd-grid { display: inline-grid; align-items: center; justify-items: center; vertical-align: middle; }
.cd-cell { display: block; }
.cd-node { display: inline-block; padding: 0.1em 0.32em; white-space: nowrap; }
.cd-node.cd-empty { padding: 0; width: 0; height: 0; }
.cd-svg { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.cd-label { position: absolute; left: 0; top: 0; visibility: hidden; white-space: nowrap; line-height: 1.1; padding: 0.04em 0.06em; }
.cd-label.cd-desc { padding: 0.08em 0.16em; }
.diagram-display { display: flex; align-items: center; justify-content: center; gap: 0.3em; position: relative; }
.diagram-row { display: inline-flex; align-items: center; gap: 0.25em; max-width: 100%; }
.diagram-display::before { content: ''; flex: 1 1 0; }
.diagram-row { flex: none; }
.diagram-fraction { display: inline-grid; text-align: center; vertical-align: middle; }
.diagram-fraction > span { padding: 0.2em 0.25em; }
.diagram-fraction > span + span { border-top: 1px solid currentColor; }
.diagram-tag { flex: 1 0 0; min-width: max-content; padding-left: 1em; text-align: right; }
.tikz-wrap { display: inline-block; position: relative; vertical-align: middle; text-align: left; isolation: isolate; transform-origin: 0 0; }
.tikz-svg { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.tikz-node { position: absolute; left: 0; top: 0; white-space: nowrap; line-height: 1.2; visibility: hidden; }
.tikz-node.tikz-multi { white-space: normal; text-align: center; }
.tikz-node.tikz-under { z-index: -1; line-height: 0; }
.tikz-node img.graphic { max-width: none; }
.tg-math-figure img.graphic { max-width: none; vertical-align: baseline; }
.tikz-note { display: block; font-size: 0.75em; color: var(--muted); margin-top: 0.3em; }
.tikz-fallback { text-align: left; display: inline-block; max-width: 100%; }
.tikz-fallback pre { font-size: 0.8em; max-height: 16em; overflow: auto; margin: 0.4em 0 0; }

.center { text-align: center; }
.flushright { text-align: right; }
.flushleft { text-align: left; }
blockquote { margin: 1em 2em; }

code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.82em; }
pre.verbatim { background: var(--code-bg); padding: 0.8em 1em; border-radius: 6px; overflow-x: auto; line-height: 1.45; }
.render-error { color: var(--missing); white-space: pre-wrap; }

.sc { font-variant: small-caps; }
.sf { font-family: system-ui, sans-serif; }
.fbox { border: 1px solid currentColor; padding: 0 0.2em; }
.latex-logo sup { font-size: 0.75em; vertical-align: 0.25em; margin-left: -0.3em; margin-right: -0.12em; }
.latex-logo sub { font-size: 1em; vertical-align: -0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase; }
.size-tiny { font-size: 0.5em; } .size-scriptsize { font-size: 0.7em; } .size-footnotesize { font-size: 0.8em; }
.size-small { font-size: 0.9em; } .size-large { font-size: 1.2em; } .size-Large { font-size: 1.44em; }
.size-LARGE { font-size: 1.73em; } .size-huge, .size-Huge { font-size: 2em; }

.bibliography ol { list-style: none; padding: 0; }
.bibliography li { display: flex; gap: 0.8em; margin: 0.4em 0; }
.bib-label { flex: 0 0 auto; }

.footnotes { margin-top: 3em; border-top: 1px solid var(--rule); padding-top: 0.6em; font-size: 0.88em; }
.footnotes ol { padding-left: 1.4em; }
.fn { line-height: 0; }
.fn-back { margin-left: 0.3em; }

/* Folding sections and proofs */
.fold-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  margin: 0 0.25em 0 -1.35em;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  vertical-align: -0.05em;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.fold-toggle svg { width: 0.75em; height: 0.75em; transition: transform 0.15s; }
.fold-toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }
.fold-toggle:hover, .fold-toggle:focus-visible, .fold-toggle[aria-expanded="false"] { opacity: 1; color: var(--accent); }
.fold-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.src-block > h1, .src-block > h2, .src-block > h3, .src-block > h4 { cursor: pointer; }
.mode-edit .src-block > h1, .mode-edit .src-block > h2, .mode-edit .src-block > h3, .mode-edit .src-block > h4 { cursor: text; }
.folded::after { content: " ⋯"; color: var(--muted); font-weight: 400; }
.fold-hidden { display: none; }

.proof .fold-toggle { font-size: 0.95em; margin-left: 0; }
.proof.folded > :not(:first-child):not(.tg-pin-btn) { display: none; }
.proof.folded > p:first-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  cursor: pointer;
}
.proof.folded > p:first-child .qed { display: none; }
.proof.folded::after { content: none; }
.mode-edit .proof.folded > p:first-child { cursor: text; }

@media (max-width: 760px) {
  .fold-toggle { margin-left: 0; }
}

/* Edit mode: click a block to edit its source in place */
.add-block-row { max-width: calc(var(--tg-text-width, 760px) * var(--zoom, 1)); margin: 0 auto; padding: 0 16px 120px; display: none; }
.mode-edit .add-block-row { display: block; }
.add-block {
  font: inherit;
  font-size: 14px;
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--rule);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.add-block:hover, .add-block:focus-visible { border-color: var(--accent); color: var(--accent); }

.mode-edit .src-block { border-radius: 4px; cursor: text; transition: box-shadow 0.12s; }
.mode-edit .src-block:hover { box-shadow: 0 0 0 6px var(--accent-soft); background: var(--accent-soft); }
.mode-edit .document a { cursor: text; }

.inline-editor {
  margin: 0.6em -10px;
  padding: 8px 10px 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
}
.inline-editor textarea {
  display: block;
  width: 100%;
  min-height: 2.6em;
  border: 0;
  resize: none;
  overflow: hidden;
  padding: 4px 2px;
  background: transparent;
  color: var(--ink);
  font: 14px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  outline: none;
  tab-size: 2;
}
.inline-hint {
  font: 12px/1.4 system-ui, sans-serif;
  color: var(--muted);
  padding: 4px 2px 0;
  border-top: 1px solid var(--rule);
  margin-top: 6px;
}
.inline-preview:not(:empty) { margin-top: 8px; padding-top: 4px; }
.inline-preview .src-block { cursor: default; }
.inline-preview .src-block:hover { box-shadow: none; background: transparent; }
.empty-doc { color: var(--muted); text-align: center; }

/* Drag and drop */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  border: 3px dashed var(--accent);
  font-size: 22px;
  color: var(--accent);
  pointer-events: none;
}
.drop-overlay[hidden] { display: none; }

/* Find bar: search the text, or go to a theorem, equation or section by number. */
.find-bar {
  position: fixed;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}
.find-bar[hidden] { display: none; }
.find-study { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 6px 6px; border-bottom: 1px solid var(--rule); }
.find-study[hidden] { display: none; }
.find-study button {
  background: var(--paper); color: var(--ink); border: 1px solid var(--rule); border-radius: 5px;
  padding: 4px 8px; font: inherit; font-size: 0.82em; cursor: pointer; min-height: 30px;
}
.find-study button:hover, .find-study button:focus-visible { background: var(--accent-soft); }
@media (pointer: coarse) { .find-study button { min-height: 44px; } }
.find-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px; }
.find-modes { display: flex; flex: none; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.find-modes button {
  font: inherit;
  font-size: 12px;
  padding: 3px 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.find-modes button[aria-selected="true"] { background: var(--accent-soft); color: var(--ink); }
.find-input {
  flex: 1 1 120px;
  min-width: 0;
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}
.find-input:focus { border-color: var(--accent); }
.find-bar.no-match .find-input { border-color: var(--missing); }
.find-count { flex: none; font-size: 12px; color: var(--muted); min-width: 0; white-space: nowrap; }
.find-count:empty { display: none; }
.find-icon {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 5px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.find-icon[hidden] { display: none; }
.find-icon svg { display: block; width: 16px; height: 16px; }
.find-icon:hover:not(:disabled) { background: var(--accent-soft); }
.find-icon:disabled { opacity: 0.35; cursor: default; }
.goto-list {
  list-style: none;
  margin: 0;
  padding: 4px;
  max-height: min(50vh, 360px);
  overflow-y: auto;
  border-top: 1px solid var(--rule);
}
.goto-list[hidden] { display: none; }
.goto-list li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.goto-list li[aria-selected="true"] { background: var(--accent-soft); }
.goto-name { flex: none; font-weight: 600; }
.goto-key { flex: none; font-size: 0.85em; color: var(--muted); }
.goto-title { overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.goto-rel { flex: none; margin-left: auto; padding-left: 8px; font-size: 0.9em; color: var(--muted); }
.goto-list li.goto-empty { color: var(--muted); cursor: default; white-space: normal; }
/* Uses tab: one result's two lists (Uses, Used by), or what a search by use found */
.goto-list li.uses-head { cursor: default; white-space: normal; align-items: center; color: var(--muted); border-bottom: 1px solid var(--rule); border-radius: 0; margin-bottom: 2px; }
.uses-sum { flex: 1; min-width: 0; }
.uses-sum strong { color: var(--ink); }
.uses-direct {
  flex: none;
  font: inherit;
  font-size: 12px;
  padding: 2px 8px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.uses-direct[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); border-color: var(--accent); }
.uses-pinset { flex: none; margin-right: 6px; font: inherit; font-size: 12px; padding: 2px 8px; border: 1px solid var(--accent); border-radius: 5px; background: transparent; color: var(--accent); cursor: pointer; }
.uses-pinset:disabled { cursor: default; opacity: 0.8; }
.uses-direct:disabled { cursor: default; }
.uses-help b { color: var(--ink); font-weight: 600; }
/* a sentence, not a row of name and count: the list's flex would set each bold name in a column */
.goto-list li.uses-help { display: block; line-height: 1.5; }
.goto-list li.uses-group { cursor: default; padding-top: 6px; font-size: 0.82em; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); }
.goto-list li.uses-none { padding-left: 16px; }
.goto-list li.uses-group ~ li[role="option"] { padding-left: 16px; }
::highlight(texglass-find) { background-color: rgba(255, 200, 0, 0.35); color: inherit; }
::highlight(texglass-find-current) { background-color: rgba(255, 150, 0, 0.75); color: inherit; }
@media (max-width: 520px) {
  .find-modes button { padding: 3px 6px; }
}

/* --- printing: Print / Save as PDF looks like a paper ----------------------------
   Used by the web viewer, the VS Code preview and exported pages alike. Only the
   document is printed, in black on white whatever the theme, with paper
   margins, every fold opened, and no page break inside a theorem or a display. */

@page { margin: 2.2cm 2.4cm 2.4cm; }

/* print / PDF of the deck: one slide to a page */
.tg-sb-print { display: none; }
@media print {
  body.tg-sb-printing > :not(.tg-sb-print) { display: none !important; }
  body.tg-sb-printing { display: block; height: auto; overflow: visible; background: #fff; }
  body.tg-sb-printing .tg-sb-print { display: block; }
  .tg-sb-page { width: 254mm; height: 142.875mm; aspect-ratio: auto; break-after: page; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

@media print {
  .pick-sheet-go { color: inherit; }
  .pick-sheet, .pick-memo { break-inside: avoid; }
  /* Print on the bar of Show only these prints the handout (src/pick.js), alone */
  .pick-printing > :not(.pick-handout) { display: none !important; }
  .pick-printing > .pick-handout { display: block !important; }
  .pick-context:not([open]) > .pick-ctx-body { display: none; }
  .tg-step-btn, .tg-step-bar, .tg-step-fold { display: none !important; }
  #preview .proof.tg-stepping .tg-step-hidden, .proof.tg-stepping .tg-step-hidden.tg-step-hidden { display: revert !important; }
  .uses-btn, .uses-bar, .rp-marks, .tg-pin-btn { display: none !important; }
  .tg-coach-veil, .tg-coach-spot, .tg-coach-card { display: none !important; } /* the first-run tour */
  .pick-view :is(.pick-sel, .pick-guess) { outline: none !important; }
  .pick-view .pick-ref { background: none !important; }
  /* Print what the view shows: in Show only these (src/pick.js), hidden blocks
     and folded proofs stay out. */
  .pick-box, .pick-bar { display: none !important; }
  .pick-mode .pick-able { outline: none !important; }
  .pick-view:not(.tg-print-paper) :is(.pick-hide, .pick-proof:not(.pick-open)) { display: none !important; }
  .tg-print-paper :is(.pick-sheet, .pick-memo, .pick-context, .pick-branch) { display: none !important; }
  /* a page printed from VS Code with a view applied (src/export.js) */
  .tg-view-hide { display: none !important; }
  :root {
    --bg: #fff !important;
    --paper: #fff !important;
    --ink: #000 !important;
    --muted: #444 !important;
    --rule: #bbb !important;
    --accent: #000 !important;
    --missing: #c62828 !important;
    --code-bg: transparent !important;
    /* the paper's own colours and undimmed figures, even from the dark theme */
    --tg-red: initial !important;
    --tg-green: initial !important;
    --tg-blue: initial !important;
    --tg-cyan: initial !important;
    --tg-magenta: initial !important;
    --tg-yellow: initial !important;
    --tg-orange: initial !important;
    --tg-violet: initial !important;
    --tg-purple: initial !important;
    --tg-brown: initial !important;
    --tg-pink: initial !important;
    --tg-teal: initial !important;
    --tg-olive: initial !important;
    --tg-lime: initial !important;
    --tg-img-filter: none !important;
    color-scheme: light !important;
  }

  /* Everything but the document. */
  .toolbar, .toc-pane, .ref-popover, .bib-open, .add-block-row, .zoom-float, .pins-float, .tg-pins-menu, .tg-pin-toast, .tg-ref-pin, .text-resizer,
  .fold-toggle, .tg-sliders, .find-bar, .diff-bar, .diff-tag, .drop-overlay, .completion, dialog, .status,
  .texglass-status, .copy-toast, .theme-toggle, .inline-hint, .fn-back, .no-print { display: none !important; }

  /* The margin column is laid out for the screen: notes float beside the text instead. */
  .tg-margin, .tg-hlbar, .tg-askai, .tg-note-pad, .tg-note-dock, .tg-drop-line { display: none !important; }
  #preview.tg-with-margin { max-width: none !important; padding: 0 !important; }
  .tg-with-margin .mnote > .mnote-body { display: block !important; }
  .tg-with-margin .mnote::before { content: none !important; }
  ::highlight(tg-hl-focus) { background-color: transparent; }

  /* One long page that the printer cuts, not a window with scrolling panes. */
  html, body { height: auto !important; overflow: visible !important; }
  body { display: block; background: #fff; color: #000; }
  .panes, .pane { display: block; overflow: visible !important; }
  #preview > .src-block { content-visibility: visible; contain-intrinsic-size: none; }

  /* Paper: a serif text block, justified, with no screen padding. */
  #preview {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  .document {
    font-size: 11pt;
    line-height: 1.42;
    text-align: justify;
    orphans: 3;
    widows: 3;
  }
  .document .center, .document .title-block, .document .float, .document .abstract-title { text-align: center; }
  .document .flushright { text-align: right; }
  .document .flushleft, .document pre { text-align: left; }
  .document h1.part { margin-top: 0; }
  .doc-title { font-size: 1.7em; }

  /* Open every folded section and proof. */
  .fold-hidden { display: revert !important; }
  .proof.folded > * { display: revert !important; }
  .proof.folded > p:first-child { white-space: normal; overflow: visible; color: inherit; }
  .proof.folded > p:first-child .qed { display: revert !important; }
  .folded::after { content: none !important; }

  /* Theorems as LaTeX sets them: no boxes, just the heading and the text. */
  .theorem, .thm-definition, .thm-remark {
    margin: 0.9em 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
  }
  .toc { border: 0; padding: 0; background: none; }

  /* Keep things whole across pages. */
  .theorem, .math-display, .float, .title-block, .abstract, .tabular, .graphic,
  .list .item, .bibliography li, pre.verbatim, .qed-line, .tg-diagram { break-inside: avoid; }
  h1, h2, h3, h4, .thm-head-only, .proof-head, .caption { break-after: avoid; }
  .document h1.chapter, .document h1.part { break-before: page; }
  #preview > .src-block:first-child h1.chapter, #preview > .src-block:first-child h1.part { break-before: auto; }

  /* Wide content wraps or shows in full: a scrollbar does not print. */
  .math-display, .table-wrap, pre.verbatim, .tg-diagram { overflow: visible !important; }
  pre.verbatim { white-space: pre-wrap; padding: 0; border-radius: 0; }

  /* Links read as text. A link whose words are not its address gets the address after it. */
  .document a { color: inherit; text-decoration: none; overflow-wrap: anywhere; }
  .document a.url { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.88em; }
  .document a.href[href^="http"]::after, .document a.href[href^="mailto:"]::after {
    content: " ⟨" attr(href) "⟩";
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.8em;
    overflow-wrap: anywhere;
  }

  /* Nothing left over from reading or editing on screen. */
  .flash { animation: none; }
  .mode-edit .src-block, .mode-edit .src-block:hover { box-shadow: none; background: none; }
  .inline-editor { margin: 0; padding: 0; border: 0; box-shadow: none; background: none; }
  .inline-editor textarea { display: none; }
  .inline-preview:not(:empty) { margin: 0; padding: 0; }
  ::highlight(texglass-find), ::highlight(texglass-find-current) { background-color: transparent; }
}

/* todonotes \todo{…}: an inline author's note */
.todo { font-size: 0.8em; background: #fff3b0; color: #5a4a00; border-radius: 3px; padding: 0 0.3em; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .todo { background: #3f3819; color: #e3d6a2; } }
:root[data-theme="dark"] .todo { background: #3f3819; color: #e3d6a2; }

/* ulem underlines and strike-outs */
u.uuline { text-decoration-style: double; }
u.uwave { text-decoration-style: wavy; text-decoration-skip-ink: none; }
u.dashuline { text-decoration-style: dashed; }
u.dotuline { text-decoration-style: dotted; }
s.xout { text-decoration-thickness: 0.15em; }

/* --- the margin: \marginpar, \todo and the reader's notes (src/margin.js) --- */

:root {
  --tg-hl-yellow: rgba(255, 210, 0, 0.4);
  --tg-hl-green: rgba(70, 200, 110, 0.34);
  --tg-hl-pink: rgba(255, 95, 170, 0.3);
  --tg-hl-blue: rgba(70, 150, 255, 0.3);
}
::highlight(tg-hl-yellow) { background-color: rgba(255, 210, 0, 0.4); }
::highlight(tg-hl-green) { background-color: rgba(70, 200, 110, 0.34); }
::highlight(tg-hl-pink) { background-color: rgba(255, 95, 170, 0.3); }
::highlight(tg-hl-blue) { background-color: rgba(70, 150, 255, 0.3); }
::highlight(tg-hl-focus) { background-color: rgba(255, 140, 0, 0.45); }
/* the dark theme: the same colours with less glow (as --tg-hl-* there) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) ::highlight(tg-hl-yellow) { background-color: rgba(222, 186, 70, 0.3); }
  :root:not([data-theme="light"]) ::highlight(tg-hl-green) { background-color: rgba(98, 180, 122, 0.28); }
  :root:not([data-theme="light"]) ::highlight(tg-hl-pink) { background-color: rgba(222, 110, 165, 0.26); }
  :root:not([data-theme="light"]) ::highlight(tg-hl-blue) { background-color: rgba(100, 145, 220, 0.3); }
  :root:not([data-theme="light"]) ::highlight(tg-hl-focus) { background-color: rgba(230, 140, 40, 0.34); }
}
:root[data-theme="dark"] ::highlight(tg-hl-yellow) { background-color: rgba(222, 186, 70, 0.3); }
:root[data-theme="dark"] ::highlight(tg-hl-green) { background-color: rgba(98, 180, 122, 0.28); }
:root[data-theme="dark"] ::highlight(tg-hl-pink) { background-color: rgba(222, 110, 165, 0.26); }
:root[data-theme="dark"] ::highlight(tg-hl-blue) { background-color: rgba(100, 145, 220, 0.3); }
:root[data-theme="dark"] ::highlight(tg-hl-focus) { background-color: rgba(230, 140, 40, 0.34); }

/* Without the viewer's script (exported HTML, print): notes float right of the text. */
.mnote-body {
  float: right;
  clear: right;
  width: 30%;
  margin: 0.15em 0 0.5em 1em;
  font-size: 0.78em;
  line-height: 1.4;
  text-align: left;
  font-style: normal;
  font-weight: normal;
  text-indent: 0;
}
.mnote-todo > .mnote-body {
  padding: 0.25em 0.45em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--note-c, var(--tg-orange, orange)) 28%, var(--paper));
  border-left: 3px solid var(--note-c, var(--tg-orange, orange));
}

/* With it, the text makes room for a margin column and the notes go there. */
#preview.tg-with-margin {
  max-width: calc(var(--tg-text-width, 760px) * var(--zoom, 1) + var(--tg-margin-w, 200px) + 28px);
  padding-right: calc(16px + var(--tg-margin-w, 200px) + 28px);
}
.tg-with-margin .mnote > .mnote-body { display: none; }
.tg-with-margin .mnote::before { content: "\200b"; }
.tg-with-margin .mnote-todo::before {
  content: "";
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  margin: 0 0.1em;
  border-radius: 50%;
  vertical-align: 0.4em;
  background: var(--note-c, var(--tg-orange, orange));
}

.tg-margin {
  position: absolute;
  top: 0;
  height: 0;
  z-index: 2;
}
.tg-margin[hidden] { display: none; }
/* The divider between the text and the margin (drag to resize it). */
.tg-margin-grip {
  position: absolute;
  top: 0;
  left: -18px;
  width: 11px;
  cursor: col-resize;
  touch-action: none;
  z-index: 1;
}
.tg-margin-grip::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 5px;
  width: 1px;
  background: transparent;
  transition: background 0.15s;
}
.tg-margin-grip:hover::after, .tg-margin-grip:focus-visible::after, body.tg-margin-resizing .tg-margin-grip::after { background: var(--accent); width: 2px; }
.tg-margin-grip:focus { outline: none; }
body.tg-margin-resizing { cursor: col-resize; user-select: none; }
/* The fold button and the note arrows ride a rail as tall as the text, in a sticky
   box, so they stand still on screen while the text scrolls (src/margin.js). */
.tg-margin-rail {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  pointer-events: none;
  z-index: 3;
}
.tg-margin-stick {
  position: sticky;
  top: 10px;
  height: 80px;
}
.tg-margin-stick > * { pointer-events: auto; }
.tg-note-modes,
.tg-notebook {
  position: absolute;
  inset-inline-start: 0;
  width: var(--tg-note-panel-w);
  box-sizing: border-box;
  font: 13px/1.4 system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
.tg-margin-drawer :is(.tg-note-modes, .tg-notebook) {
  inset-inline-start: 12px;
  width: calc(var(--tg-note-panel-w) - 24px);
}
.tg-note-modes {
  top: 0;
  z-index: 2;
  display: flex;
  align-items: stretch;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--rule);
  border-radius: 6px;
}
.tg-note-modes button {
  flex: 1 1 auto;
  padding: 4px 5px;
  min-height: 29px;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.tg-note-modes button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--rule); }
.tg-note-modes button:focus-visible, .tg-note-list-row button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tg-notebook {
  top: var(--tg-note-modes-h, 38px);
  max-height: var(--tg-note-panel-h, 70vh);
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 6px;
  border: 1px solid var(--rule);
  border-radius: 6px;
}
.tg-note-modes[hidden], .tg-notebook[hidden],
.tg-margin-notebook :is(.tg-mcard, .tg-margin-nav, .tg-mnav-menu) { display: none; }
.tg-notebook label { display: grid; gap: 3px; font-weight: 600; }
.tg-notebook input {
  min-width: 0; width: 100%; box-sizing: border-box;
  border: 1px solid var(--rule); border-radius: 5px; padding: 5px 6px; color: var(--ink); background: var(--paper); font: inherit; font-weight: 400;
}
.tg-note-search-status { margin: 0; color: var(--muted); }
.tg-note-list { list-style: none; margin: 0; padding: 0 2px; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.tg-note-list-row { position: relative; padding: 8px 6px; border-top: 1px solid var(--rule); overflow-wrap: anywhere; }
.tg-note-list-context { color: var(--muted); font-weight: 600; }
.tg-note-list-content { overflow-wrap: anywhere; }
.tg-note-list-content p { margin: 2px 0; }
.tg-note-list-quote { margin: 3px 0; color: var(--muted); }
.tg-note-list-jump {
  position: static; padding: 2px 0; color: var(--accent); border: 0; background: none;
  font: inherit; text-decoration: underline; cursor: pointer;
}
.tg-note-list-jump::after { content: ""; position: absolute; inset: 0; }
.tg-note-list-quote .katex-display { position: relative; z-index: 1; }
.tg-note-list-row:has(.tg-note-list-jump:hover) { background: var(--accent-soft); }
.tg-note-list-outline {
  position: relative; z-index: 1; margin: 3px 0 0 8px; padding: 3px 7px;
  border: 1px solid var(--rule); border-radius: 5px; color: var(--accent); background: var(--paper); font: inherit; cursor: pointer;
}
.tg-note-list-outline:first-of-type { margin-inline-start: 0; }
.tg-note-list-outline:hover { background: var(--accent-soft); }
@media (pointer: coarse) {
  .tg-note-modes button { min-height: 40px; }
  .tg-notebook input { font-size: 16px; }
  .tg-note-list-outline { min-height: 40px; }
}
/* The fold button, on the divider; folded, it waits beside the text with a count. */
.tg-margin-toggle {
  position: absolute;
  top: 0;
  left: -21px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 1px;
  height: 18px;
  min-width: 16px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--paper);
  color: var(--muted);
  font: 10px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
.tg-margin-toggle svg { width: 14px; height: 14px; flex: none; }
.tg-margin-toggle:hover, .tg-margin-toggle:focus-visible { opacity: 1; color: var(--ink); border-color: var(--accent); }
.tg-margin-folded .tg-margin-toggle { left: 0; padding: 0 5px 0 1px; opacity: 0.8; }
.tg-margin-folded .tg-mcard, body:not(.tg-margin-resizing) .tg-margin-folded .tg-margin-grip { display: none; }
/* Under it, arrows to the next and previous note, and which notes they visit. */
.tg-margin-nav {
  position: absolute;
  top: 24px;
  left: -21px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 18px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--paper);
  opacity: 0.55;
  transition: opacity 0.15s, border-color 0.15s;
}
.tg-margin-nav:hover, .tg-margin-nav:focus-within { opacity: 1; border-color: var(--accent); }
.tg-margin-folded .tg-margin-nav { left: 0; }
.tg-margin-nav button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 17px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.tg-margin-nav button[hidden] { display: none; }
.tg-margin-nav button:disabled { opacity: 0.35; cursor: default; }
.tg-margin-nav button:not(:disabled):hover, .tg-margin-nav button:focus-visible { color: var(--ink); }
.tg-margin-nav button:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }
.tg-margin-nav svg { width: 13px; height: 13px; }
.tg-margin-nav .tg-mnav-filter { border-top: 1px solid var(--rule); border-radius: 0 0 8px 8px; }
.tg-margin-nav .tg-mnav-filter.tg-mnav-on { color: var(--accent); }
.tg-mnav-menu {
  position: absolute;
  top: 24px;
  left: 2px;
  z-index: 4;
  min-width: 190px;
  padding: 4px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  font: 12px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.tg-margin-folded .tg-mnav-menu { left: auto; right: 4px; }
.tg-mnav-menu[hidden] { display: none; }
.tg-mnav-menu button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 4px 8px 4px 20px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.tg-mnav-menu button[aria-checked="true"] { position: relative; font-weight: 600; }
.tg-mnav-menu button[aria-checked="true"]::before { content: "\2713"; position: absolute; left: 6px; }
.tg-mnav-menu button:hover, .tg-mnav-menu button:focus-visible { background: color-mix(in srgb, var(--accent) 14%, transparent); outline: none; }
.tg-mnav-n { color: var(--muted); font-variant-numeric: tabular-nums; }
/* With one kind chosen, the other cards step back. */
.tg-margin[data-filter="par"] .tg-mcard:not(.tg-mcard-par),
.tg-margin[data-filter="todo"] .tg-mcard:not(.tg-mcard-todo),
.tg-margin[data-filter="mine"] .tg-mcard:not(.tg-mcard-user) { opacity: 0.35; }
/* The note just jumped to. */
.tg-mcard-pulse { animation: tg-mcard-pulse 1.5s ease-out; }
@keyframes tg-mcard-pulse {
  0%, 30% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent); }
  100% { box-shadow: 0 0 0 3px transparent; }
}
.tg-mnote-pulse::before { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 50%; }
/* Folded: the text takes the room back; the notes stay as dots in the text. */
#preview.tg-with-margin.tg-margin-collapsed { max-width: calc(var(--tg-text-width, 760px) * var(--zoom, 1) + 28px); padding-right: 44px; }
.tg-margin-collapsed .mnote { cursor: pointer; }
.tg-margin-collapsed .mnote:not(.mnote-todo)::before {
  content: "";
  display: inline-block;
  width: 0.35em;
  height: 0.35em;
  margin: 0 0.1em;
  border-radius: 50%;
  vertical-align: 0.4em;
  background: var(--muted);
  opacity: 0.6;
}
/* Folded: a dot at the right edge of the text beside each line with a note (click: the margin back). */
.tg-margin-dots { display: none; }
.tg-margin-folded .tg-margin-dots { display: block; }
.tg-mdot {
  position: absolute;
  left: -11px;
  z-index: 2;
  width: 14px;
  height: 1.2em;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: inherit;
}
.tg-mdot::before {
  content: "";
  position: absolute;
  left: 3px;
  top: calc(0.6em - 4px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.7;
  transition: opacity 0.15s, transform 0.15s;
}
.tg-mdot-todo::before { background: var(--note-c, var(--tg-orange, orange)); opacity: 0.9; }
.tg-mdot-mine::before { background: var(--note-c, var(--tg-hl-yellow)); opacity: 1; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18); }
.tg-mdot-more::before { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--muted); }
.tg-mdot:hover::before, .tg-mdot:focus-visible::before { opacity: 1; transform: scale(1.3); }
.tg-mdot:focus { outline: none; }
@media (pointer: coarse) {
  .tg-mdot { width: 24px; left: -14px; height: max(1.2em, 24px); }
  .tg-mdot::before { left: 8px; top: calc(50% - 4px); }
}
.tg-mcard {
  position: absolute;
  left: 0;
  right: 0;
  font-size: 0.74em;
  line-height: 1.4;
  color: var(--ink);
  overflow-wrap: break-word;
}
.tg-mcard[hidden] { display: none; }
.tg-mcard .katex { font-size: 1.05em; }
.tg-mcard-par { color: var(--muted); }
.tg-mcard-todo {
  padding: 0.3em 0.5em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--note-c, var(--tg-orange, orange)) 26%, var(--paper));
  border-left: 3px solid var(--note-c, var(--tg-orange, orange));
}
.tg-mcard-user {
  padding: 0.3em 0.5em;
  border-radius: 4px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-left: 3px solid color-mix(in srgb, var(--note-c) 100%, var(--ink) 25%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  cursor: grab;
  touch-action: none;
}
.tg-mcard-user.tg-mcard-editing { cursor: auto; }
.tg-mcard-dragging { opacity: 0.35; }
.tg-mcard-ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  opacity: 0.95;
}
.tg-mcard-tag { font: 10px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--warn); }
.tg-mcard-lost { border-style: dashed; }
.tg-mcard-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-bottom: 2px;
}
.tg-mcard-editing .tg-mcard-tools { display: none; }
.tg-mcard p { margin: 0 0 0.3em; }
.tg-mcard p:last-child { margin-bottom: 0; }
.tg-mcard-tools button, .tg-hlbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.tg-mcard-tools button { min-width: 22px; min-height: 24px; border-radius: 4px; }
.tg-mcard-tools .tg-mcard-edit { gap: 4px; padding: 0 4px; font: inherit; }
@media (pointer: coarse) { .tg-mcard-tools button { min-width: 40px; min-height: 40px; } }
.tg-mcard-tools button:hover, .tg-hlbar button:hover { color: var(--ink); background: var(--accent-soft); }
.tg-mcard-tools svg { width: 13px; height: 13px; }
.tg-mcard-empty { color: var(--muted); font-style: italic; }
.tg-mcard-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 2.6em;
  margin: 0;
  padding: 2px 4px;
  resize: none;
  overflow: hidden;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  outline: none;
}

.tg-mnote-editor { font: 13px/1.4 system-ui, -apple-system, sans-serif; }
.tg-mnote-title { display: block; color: var(--ink); }
.tg-mnote-where { color: var(--muted); margin-block: 2px; overflow-wrap: anywhere; }
.tg-mnote-quote {
  margin: 5px 0; padding: 2px 8px; border-inline-start: 2px solid var(--rule);
  color: var(--muted); overflow-wrap: anywhere;
}
.tg-mnote-label { display: grid; gap: 4px; margin-block: 6px; min-height: 0; }
.tg-mnote-preview {
  min-height: 0; max-height: 6rem; margin-block: 0 6px; padding: 2px 6px; overflow: auto;
  border-inline-start: 2px solid var(--rule); overflow-wrap: anywhere;
}
.tg-mnote-preview p { margin: 0; }
:is(.tg-note-list-content, .tg-mcard-user, .tg-mnote-preview, .tg-note-list-quote, .tg-mnote-quote) .katex-display {
  margin-block: 0.35em;
  overflow-x: auto;
  overflow-y: hidden;
}
:is(.tg-note-list-content, .tg-mcard-user, .tg-mnote-preview, .tg-note-list-quote, .tg-mnote-quote) .katex-display > .katex {
  width: max-content;
  min-width: 100%;
}
.tg-mnote-editor .tg-mcard-input { min-height: 3.5em; overflow-y: auto; outline: revert; }
.tg-mnote-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 4px; }
.tg-mnote-actions button {
  min-height: 28px; padding: 3px 7px; font: inherit; border: 1px solid var(--rule);
  border-radius: 6px; color: var(--ink); background: var(--paper); cursor: pointer;
}
.tg-mnote-actions .tg-mnote-save { border-color: var(--accent); background: var(--accent-soft); }
.tg-mnote-sheet {
  position: fixed; inset: auto 0 var(--tg-keyboard-inset, 0px); width: auto;
  max-width: none; margin: 0; box-sizing: border-box;
  max-height: calc(var(--tg-visual-height, 100dvh) - 8px);
  padding: 14px 16px max(12px, env(safe-area-inset-bottom));
  border: 1px solid var(--rule); border-radius: 14px 14px 0 0;
  background: var(--paper); color: var(--ink); overscroll-behavior: contain;
}
.tg-mnote-sheet[open] { display: flex; flex-direction: column; }
.tg-mnote-sheet::backdrop { background: rgb(0 0 0 / .28); }
.tg-mnote-sheet .tg-mnote-quote { flex-shrink: 1; min-height: 0; overflow: auto; }
.tg-mnote-sheet .tg-mcard-input { font-size: 16px; }
.tg-mnote-sheet .tg-ink { max-height: 90px; }
.tg-mnote-sheet .tg-mnote-actions { flex: none; position: sticky; bottom: 0; background: var(--paper); }
.tg-mnote-sheet .tg-mnote-actions button { min-height: 40px; padding-inline: 14px; }

/* The bar over a selection: highlight in a colour, add a note, remove. */
.tg-hlbar {
  position: absolute;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.16);
}
.tg-hlbar[hidden] { display: none; }
.tg-hlbar .tg-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.tg-hlbar .tg-swatch:hover { background: var(--sw); transform: scale(1.15); }
.tg-hlbar-pin, .tg-hlbar-del { width: 24px; height: 24px; border-radius: 4px; }
.tg-hlbar button.tg-hlbar-note { height: 24px; gap: 3px; padding: 0 4px; border-radius: 4px; font-size: 12px; white-space: nowrap; }
.tg-hlbar-pin[aria-pressed="true"] { color: var(--accent); }
.tg-hlbar-pin[aria-pressed="true"] svg path { fill: var(--accent-soft); }
.tg-hlbar svg { width: 16px; height: 16px; }
.tg-hlbar-del { display: none !important; }
.tg-hlbar-existing .tg-hlbar-del { display: inline-flex !important; }
/* askAI on the bar, and its panel (src/askai.js) */
.tg-hlbar .tg-hlbar-ask {
  height: 24px;
  padding: 0 7px;
  margin-left: 2px;
  border-left: 1px solid var(--rule);
  border-radius: 0 4px 4px 0;
  font: 600 12px/1 system-ui, sans-serif;
  color: var(--accent);
  white-space: nowrap;
}
.tg-askai {
  position: fixed;
  z-index: 60;
  box-sizing: border-box;
  width: min(380px, calc(100vw - 16px));
  padding: 10px 12px 12px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  font: 13px/1.4 system-ui, sans-serif;
}
.tg-askai[hidden] { display: none; }
.tg-askai-sheet {
  left: 0 !important;
  right: 0;
  bottom: 0;
  top: auto !important;
  width: 100%;
  border-radius: 14px 14px 0 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}
.tg-askai-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.tg-askai-status { flex: 1; color: var(--accent); font-size: 12px; }
.tg-askai-close { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.tg-askai-close:hover { color: var(--ink); background: var(--accent-soft); }
.tg-askai-quote { margin-bottom: 8px; color: var(--muted); font-style: italic; overflow-wrap: anywhere; }
.tg-askai-qs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tg-askai button:not(.tg-askai-close) {
  padding: 5px 9px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.tg-askai button:not(.tg-askai-close):hover { background: var(--accent-soft); }
.tg-askai-qs button[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.tg-askai-own {
  display: block;
  box-sizing: border-box;
  width: 100%;
  margin-bottom: 8px;
  padding: 5px 7px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  resize: vertical;
}
.tg-askai-own:focus { outline: none; border-color: var(--accent); }
.tg-askai-full {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-height: 40vh;
  margin-top: 8px;
  padding: 5px 7px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: 12px/1.4 ui-monospace, monospace;
  resize: vertical;
}
.tg-askai-full[hidden] { display: none; }
.tg-askai-go { display: flex; flex-wrap: wrap; gap: 6px; }
.tg-askai-go .tg-askai-open { font-weight: 600; }
.tg-askai-hint { margin-top: 8px; color: var(--muted); font-size: 11.5px; }
@media (pointer: coarse) {
  .tg-hlbar .tg-hlbar-ask { height: 32px; }
  .tg-askai button:not(.tg-askai-close) { padding: 8px 11px; }
}

/* The note pad: drag it onto a line to write a note there. Its handle on top moves it. */
.tg-note-dock {
  position: fixed;
  right: 14px;
  bottom: 40px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tg-note-dock[hidden] { display: none; }
.tg-note-dock-grip {
  width: 22px;
  height: 10px;
  margin-bottom: 1px;
  border-radius: 4px;
  cursor: move;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.15s;
  background: radial-gradient(circle, var(--muted) 1px, transparent 1.4px) 0 0 / 5px 5px;
  background-position: center;
}
.tg-note-dock:hover .tg-note-dock-grip, .tg-note-dock-grip:focus-visible, .tg-note-dock-moving .tg-note-dock-grip { opacity: 0.8; }
.tg-note-dock-grip:focus { outline: none; }
.tg-note-dock-grip:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.tg-note-pad {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: color-mix(in srgb, var(--tg-hl-yellow) 60%, var(--paper));
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  cursor: grab;
  touch-action: none;
  opacity: 0.85;
}
.tg-note-pad:hover { opacity: 1; }
.tg-note-pad[hidden] { display: none; }
.tg-note-pad svg { width: 18px; height: 18px; }
.tg-drop-line {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 2px 0 0 var(--accent);
}
.tg-drop-line[hidden] { display: none; }

/* Citation previews (src/cite.js): the cited paper's title and abstract under its entry. */
.cite-note { margin-top: 0.6em; padding-top: 0.5em; border-top: 1px solid var(--rule); font-size: 0.88em; line-height: 1.5; }
.cite-title { font-weight: 600; margin-bottom: 0.3em; }
.cite-abstract { color: var(--ink); }
.cite-abstract .insight-usedby-k { margin-right: 0.3em; }
.cite-wait::after { content: ""; display: inline-block; width: 0.8em; height: 0.8em; margin-left: 0.4em; vertical-align: -0.1em;
  border: 2px solid var(--rule); border-top-color: var(--accent); border-radius: 50%; animation: cite-spin 0.8s linear infinite; }
@keyframes cite-spin { to { transform: rotate(360deg); } }
.cite-actions { margin-top: 0.5em; display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em 0.8em; }
.cite-open {
  font: inherit; font-size: 0.95em; padding: 0.15em 0.7em; border-radius: 5px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent);
}
.cite-open:hover { filter: brightness(1.08); }
.cite-out { font-size: 0.92em; color: var(--muted); }
.cite-out:hover { color: var(--accent); }
/* A cited result ("[12, Theorem 4.1]", src/cited.js): the statement itself, from the cited paper. */
.cited-result { margin: 0.1em 0 0.6em; }
.cited-head { color: var(--muted); margin-bottom: 0.25em; }
.cited-head .insight-usedby-k { margin-right: 0.2em; }
.cite-open.cited-open {
  background: none; border: none; padding: 0; color: var(--accent); font-size: 1em; text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 2px;
}
.cited-body {
  font-size: calc(1em / 0.88); line-height: 1.55; padding: 0.35em 0.7em; border-left: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 5%, transparent); border-radius: 0 5px 5px 0; overflow-x: auto;
}
.cited-body > :first-child { margin-top: 0; }
.cited-body > :last-child { margin-bottom: 0; }
.cited-body > .theorem { margin: -0.35em -0.7em; padding: 0.45em 0.7em 0.1em; border-left: none; background: none; border-radius: 0; }
.cited-missing { margin: 0.2em 0 0.4em; }
.cite-more { margin-top: 0.4em; }
.cite-more > summary { cursor: pointer; color: var(--muted); font-size: 0.95em; }
.cite-more[open] > summary { margin-bottom: 0.25em; }
/* An entry of the bibliography that is on arXiv: a button that opens it in TeXglass. */
.bib-open {
  font: inherit; font-size: 0.8em; line-height: 1.3; margin-left: 0.5em; padding: 0.05em 0.55em; vertical-align: 0.05em;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); border-radius: 999px;
  background: none; color: var(--accent); cursor: pointer; white-space: nowrap; user-select: none;
}
.bib-open::after { content: "Open in TeXglass"; }
.bib-open:hover, .bib-open:focus-visible { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.ref-popover .bib-open { display: none; }

/* "What does this use?" (src/insight.js): a result's dependencies lit up, the rest faded. */
.uses-btn {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: -0.12em;
  width: 1.25em; height: 1.25em; margin: 0 0.15em 0 0.25em; padding: 0; border: 0; border-radius: 4px;
  background: none; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity 0.15s;
  font-style: normal;
}
.uses-btn svg { width: 0.9em; height: 0.9em; }
.theorem:hover .uses-btn, .uses-btn:focus-visible, .uses-btn[aria-pressed="true"] { opacity: 1; }
.uses-btn:hover, .uses-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
@media (hover: none) { .uses-btn { opacity: 0.6; } }
/* Pins (src/insight.js): a pin by each result's heading and each numbered equation's number. */
.tg-pin-btn {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: -0.12em;
  width: 1.25em; height: 1.25em; margin: 0 0.15em; padding: 0; border: 0; border-radius: 4px;
  background: none; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity 0.15s; font-style: normal;
}
.tg-pin-btn svg { width: 0.95em; height: 0.95em; }
.theorem:hover > * > .tg-pin-btn, .theorem:hover > .tg-pin-btn, .theorem:hover .thm-head ~ .tg-pin-btn, .math-display:hover > .tg-pin-btn,
.tg-pin-btn:focus-visible, .tg-pinned > .tg-pin-btn, .tg-pinned > * > .tg-pin-btn, .tg-pin-btn[aria-pressed="true"] { opacity: 1; }
.tg-pin-btn:hover, .tg-pin-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.math-display.tg-pinned, .math-display:has(> .tg-pin-btn) { position: relative; }
.tg-pin-btn.tg-pin-eq { position: absolute; left: 0; top: 50%; transform: translateY(-50%); font-size: 15px; }
figure.float.tg-pinned, figure.float:has(> .tg-pin-btn) { position: relative; }
.tg-pin-btn.tg-pin-fig { position: absolute; right: 0; top: 0; font-size: 15px; }
figure.float:hover > .tg-pin-btn { opacity: 1; }
.proof.tg-pinned, .proof:has(> .tg-pin-btn) { position: relative; }
/* by the proof's title, like a result's pin by its heading (absolute only when a proof has no title) */
.proof > .tg-pin-btn.tg-pin-proof { position: absolute; right: 0; top: 0; font-size: 15px; }
.proof:hover > .tg-pin-btn, .proof:hover > * > .tg-pin-btn.tg-pin-proof { opacity: 1; }
/* a preview is a copy of the text: the copied in-text pin would do nothing there (the preview has its own) */
.ref-popover .tg-pin-btn, .insight-popover .tg-pin-btn, .insight-dialog .dep-preview .tg-pin-btn { display: none !important; }
@media (hover: none) { .tg-pin-btn { opacity: 0.7; width: 1.7em; height: 1.7em; margin: 0 0.05em; } .tg-pin-btn svg { width: 1.05em; height: 1.05em; } }

/* Show only these (src/pick.js): the proofs of the results shown stay, folded
   to their first line until clicked */
@media screen {
  .pick-view .pick-proof:not(.pick-open) > :not(:first-child) { display: none; }
  .pick-view .pick-proof:not(.pick-open) > p:first-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--muted);
    cursor: pointer;
  }
  .pick-view .pick-proof:not(.pick-open) > p:first-child .qed { display: none; }
  .pick-view .pick-proof:not(.pick-open) .fold-toggle { opacity: 1; color: var(--accent); }
  .pick-view .pick-proof:not(.pick-open) .fold-toggle svg { transform: rotate(-90deg); }
}
/* "What does this use?" in Show only these: the result asked about, what it
   refers to, and (dashed) what was reached through a link guessed from the wording */
.pick-view .pick-sel { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 2px; }
.pick-view .pick-guess { outline: 1.5px dashed var(--thm-border); outline-offset: 4px; border-radius: 2px; }
.pick-view .pick-ref { background: var(--accent-soft); border-radius: 4px; }
.uses-guessed { color: var(--muted); font-size: 0.9em; cursor: help; }
.uses-bar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 12;
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; max-width: calc(100vw - 32px);
  padding: 7px 10px 7px 14px; border: 1px solid var(--rule); border-radius: 10px;
  background: var(--paper); color: var(--ink); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 13px;
}
.uses-bar[hidden] { display: none; }
.uses-bar button {
  font: inherit; padding: 2px 8px; border: 1px solid var(--rule); border-radius: 6px; background: none; color: inherit; cursor: pointer;
}
.uses-bar button:hover { border-color: var(--accent); }
.uses-dir { display: inline-flex; }
.uses-dir button:first-child { border-radius: 6px 0 0 6px; }
.uses-dir button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.uses-bar button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.uses-step { color: var(--muted); font-variant-numeric: tabular-nums; }
.pick-step { display: inline-flex; align-items: center; gap: 4px; }
/* Print or share: one button on the Show only these bar, its menu opening upwards */
.pick-out { position: relative; display: inline-flex; }
.pick-out-menu {
  position: absolute; bottom: calc(100% + 6px); right: 0; z-index: 13;
  display: flex; flex-direction: column; gap: 2px; min-width: 180px; padding: 4px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
.pick-out-menu[hidden] { display: none; }
.uses-bar .pick-out-menu button { border: none; text-align: left; padding: 6px 10px; white-space: nowrap; }
.uses-bar .pick-out-menu button:hover, .uses-bar .pick-out-menu button:focus-visible { background: var(--accent-soft); }
.uses-done { font-weight: 600; }
.pick-saved { color: var(--muted); }
.pick-branch {
  margin: 4px 0; padding: 3px 8px; border: 1px solid var(--rule); border-radius: 6px;
  background: var(--paper); color: var(--accent); font: 13px system-ui, sans-serif; cursor: pointer;
}
.pick-branch:hover { border-color: var(--accent); }
/* a phone: the bar spans the width, and its menus open across it (not off the screen) */
@media (max-width: 600px) {
  .uses-bar { left: 8px; right: 8px; bottom: 8px; transform: none; max-width: none; }
  .uses-bar .pick-out { position: static; }
  .uses-bar .pick-out-menu { left: 8px; right: 8px; min-width: 0; }
}

/* --- comparing versions (src/diff.js) -------------------------------------------
   Changed blocks get an amber bar and their new words underlined in green; the
   old version (its removed words struck through in red) opens under them. New
   blocks get a green bar, removed ones a folded red box where they were. */
:root {
  --diff-changed: #c58a12; --diff-added: #2e8b57; --diff-removed: #c0392b; --diff-moved: #6b5bd2;
  --diff-ins-bg: rgba(46, 139, 87, 0.16); --diff-del-bg: rgba(192, 57, 43, 0.14);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --diff-changed: #e0a83a; --diff-added: #5cc28a; --diff-removed: #ef7a6c; --diff-moved: #a99cf5; --diff-ins-bg: rgba(92, 194, 138, 0.2); --diff-del-bg: rgba(239, 122, 108, 0.18); }
}
:root[data-theme="dark"] { --diff-changed: #e0a83a; --diff-added: #5cc28a; --diff-removed: #ef7a6c; --diff-moved: #a99cf5; --diff-ins-bg: rgba(92, 194, 138, 0.2); --diff-del-bg: rgba(239, 122, 108, 0.18); }
.diff-changed, .diff-added, .diff-moved, .diff-old { position: relative; box-shadow: -10px 0 0 -7px var(--diff-changed); }
.diff-added { box-shadow: -10px 0 0 -7px var(--diff-added); }
.diff-moved { box-shadow: -10px 0 0 -7px var(--diff-moved); }
.diff-old { box-shadow: -10px 0 0 -7px var(--diff-removed); margin: 0.4em 0 0.8em; padding: 0.3em 0.7em; border: 1px dashed var(--diff-removed); border-radius: 6px; }
.diff-old-changed { border-color: var(--diff-changed); box-shadow: -10px 0 0 -7px var(--diff-changed); }
.diff-old-body { opacity: 0.78; }
.diff-old-removed .diff-old-body { display: none; }
.diff-old-removed.diff-open .diff-old-body { display: block; }
.diff-old[hidden] { display: none; }
.diff-tag {
  display: inline-block; margin: 0 0 0.3em; padding: 1px 7px; border: 1px solid currentColor; border-radius: 999px;
  font: 12px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: none; color: var(--diff-changed);
}
button.diff-tag { cursor: pointer; }
button.diff-tag:hover { background: var(--accent-soft); }
.diff-added > .diff-tag { color: var(--diff-added); }
.diff-moved > .diff-tag { color: var(--diff-moved); }
.diff-old-removed > .diff-tag { color: var(--diff-removed); margin: 0; }
.diff-old-removed.diff-open > .diff-tag { margin-bottom: 0.3em; }
ins.diff-ins { text-decoration: none; background: var(--diff-ins-bg); border-bottom: 2px solid var(--diff-added); }
del.diff-del { background: var(--diff-del-bg); text-decoration: line-through; text-decoration-color: var(--diff-removed); }
.diff-math-ins { background: var(--diff-ins-bg); box-shadow: 0 2px 0 var(--diff-added); border-radius: 2px; }
.diff-math-del { background: var(--diff-del-bg); box-shadow: 0 2px 0 var(--diff-removed); border-radius: 2px; }
.diff-current { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
/* "Only changes": what changed, and the section headings around it */
.diff-only-changes > .src-block:not(.diff-changed):not(.diff-added):not(.diff-moved):not(:has(h1, h2, h3, h4, h5, h6)) { display: none; }
.diff-bar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 12;
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; max-width: calc(100vw - 32px);
  padding: 7px 10px 7px 14px; border: 1px solid var(--rule); border-radius: 10px;
  background: var(--paper); color: var(--ink); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 13px;
}
.diff-bar button, .diff-bar select {
  font: inherit; padding: 2px 8px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); color: inherit; cursor: pointer;
}
.diff-bar select { max-width: 16em; }
.diff-bar button:hover:not(:disabled) { border-color: var(--accent); }
.diff-bar button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.diff-step-group { display: inline-flex; align-items: center; gap: 4px; }
.diff-step { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: center; }
.diff-n-changed { color: var(--diff-changed); }
.diff-n-added { color: var(--diff-added); }
.diff-n-removed { color: var(--diff-removed); }
.diff-n-moved { color: var(--diff-moved); }
.compare-pick { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0.6em 0; }
.compare-pick select { font: inherit; margin-left: 6px; }

/* --- phones and tablets ---------------------------------------------------------
   Narrow windows (a phone, or a tablet in a split view) get a compact toolbar of a
   few large buttons (the rest move into the "…" menu, app.js), the side panel and
   the margin notes as drawers that swipe in from the edges (src/touch.js,
   src/margin.js setOverlay), and display formulas that break onto more lines
   instead of running off the screen. On any touch screen a preview opens on a
   tap, as a sheet at the bottom (src/popover.js). */

.tb-icon { display: none; width: 20px; height: 20px; flex: none; }
/* Save for offline: a bookmark, filled once the paper is saved */
#save-offline, #bookmark { display: inline-flex; align-items: center; gap: 5px; }
#save-offline .tb-icon, #bookmark .tb-icon { display: block; width: 18px; height: 18px; }
#bookmark[aria-pressed="true"] .bookmark-mark { fill: currentColor; }
#save-offline .save-offline-check, #save-offline[aria-pressed="true"] .save-offline-arrow { display: none; }
#save-offline[aria-pressed="true"] .save-offline-check { display: inline; }
#save-offline[aria-pressed="true"], #bookmark[aria-pressed="true"] { color: var(--accent); }
#save-offline[hidden], #bookmark[hidden] { display: none; }
#share { display: inline-flex; align-items: center; gap: 5px; }
#share .tb-icon { display: block; width: 18px; height: 18px; }
#share[hidden] { display: none; }
#settings .tb-label, #hand-toggle .tb-label { display: none; }
/* Open, Contents, Pinned and Hide proofs: icons, their names in the tooltip (and in
   the "…" menu on a phone, where Hide proofs and Pinned move) */
.toolbar .tb-iconic { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 4px 9px; position: relative; }
.toolbar .tb-iconic .tb-icon { display: block; width: 18px; height: 18px; }
.toolbar .tb-iconic .tb-label { display: none; }
.toolbar .tb-iconic[hidden] { display: none; }
.toolbar .more-compact .tb-iconic { padding: 6px 12px; }
.toolbar .more-compact .tb-iconic .tb-label { display: inline; }
.toolbar .tb-iconic:disabled { opacity: 0.45; cursor: default; }
#fold-proofs .fold-mark-show { display: none; }
#fold-proofs[aria-pressed="true"] .fold-mark-show { display: inline; }
#fold-proofs[aria-pressed="true"] .fold-mark-hide { display: none; }

/* Pinned: a pin with a count; a click lists everything pinned (src/pins.js) */
.tg-pins-some .tg-pin-icon path { fill: var(--accent-soft); }
.tg-pins-some { color: var(--accent); }
.tg-pins-badge {
  position: absolute; top: -6px; right: -6px; min-width: 16px; height: 16px; padding: 0 4px; box-sizing: border-box;
  border-radius: 8px; background: var(--accent); color: var(--paper); font-size: 10.5px; font-weight: 600; line-height: 16px; text-align: center;
  font-variant-numeric: tabular-nums; pointer-events: none;
}
.tg-pins-badge[hidden] { display: none; }
.more-compact .tg-pins-badge { position: static; margin-left: 2px; }
.tg-pins-menu .tg-pins-clear-ask, .tg-pins-panel .tg-pins-clear-ask { margin-right: auto; align-self: center; color: var(--ink); font-size: 13px; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-actions .tg-pins-clear { color: var(--muted); margin-right: auto; order: -1; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-actions .tg-pins-clear-yes { border-color: #c0392b; color: #c0392b; }
/* The side panel's Pins tab (src/pins.js panel): My pins and Pin sets at the top,
   the list under them (as the toolbar's pin shows it). */
.side-pins { font-size: 13px; }
.tg-sets-title { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); margin: 2px 0 4px; }
.tg-sets-list { display: flex; flex-direction: column; gap: 1px; }
.tg-sets-set {
  display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; text-align: left; font: inherit; color: var(--ink);
  padding: 4px 8px; border: 0; border-left: 2px solid transparent; border-radius: 5px; background: none; cursor: pointer;
}
.tg-sets-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tg-sets-size { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.tg-sets-now { font-size: 11px; color: var(--accent); border: 1px solid currentColor; border-radius: 999px; padding: 0 6px; font-weight: 500; }
.tg-sets-del { flex: none; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 5px; background: none; color: var(--muted); font: inherit; font-size: 15px; cursor: pointer; opacity: 0; }
@media (hover: none) { .tg-sets-del { opacity: 0.7; } }
.tg-sets-del:hover { color: var(--ink); }
.tg-sets-empty { color: var(--muted); margin: 0 6px 2px 0; line-height: 1.45; }
.tg-sets-starter { margin: 4px 0 0; font: inherit; font-size: 12px; padding: 3px 8px; border: 1px dashed var(--accent); border-radius: 6px; background: none; color: var(--accent); cursor: pointer; }
.tg-sets-starter:hover { background: var(--accent-soft); }
.tg-coll-part { padding: 8px 2px 10px 8px; border-top: 1px solid var(--rule); margin-top: 8px; }
.tg-coll-list { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.tg-coll > summary { display: flex; align-items: center; gap: 6px; padding: 3px 0 3px 6px; border-radius: 5px; cursor: pointer; }
.tg-coll > summary:hover { background: var(--accent-soft); }
.tg-coll > summary:hover .tg-sets-del, .tg-coll-row:hover .tg-sets-del { opacity: 1; }
.tg-coll-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tg-coll-paper { font-size: 12px; color: var(--muted); margin: 6px 0 1px 18px; overflow-wrap: anywhere; }
.tg-coll-paper.tg-coll-here { color: var(--ink); }
.tg-coll-row { display: flex; align-items: center; margin-left: 18px; border-radius: 5px; }
.tg-coll-row:hover { background: var(--accent-soft); }
.tg-coll-go { flex: 1; min-width: 0; text-align: left; font: inherit; font-size: 13px; padding: 3px 6px; border: 0; background: none; color: inherit; cursor: pointer; overflow-wrap: anywhere; }
.tg-coll-go:disabled { cursor: default; color: var(--muted); }
.tg-coll-add { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 6px 4px 0; }
.tg-coll-name { flex: 1 1 140px; min-width: 0; font: inherit; font-size: 13px; padding: 3px 6px; border: 1px solid var(--rule); border-radius: 5px; background: var(--bg); color: var(--ink); }
.tg-coll-add button { font: inherit; font-size: 12px; padding: 3px 8px; border: 1px solid var(--rule); border-radius: 5px; background: none; color: inherit; cursor: pointer; }
.tg-coll-add button[type="submit"] { border-color: var(--accent); color: var(--accent); }
.tg-pins-panel { padding: 6px 0 0 2px; }
.tg-pins-panel .tg-pins-head { padding-left: 6px; }
.tg-pins-menu {
  position: fixed; z-index: 60; width: min(340px, calc(100vw - 16px)); max-height: min(70vh, 520px); overflow: auto; overscroll-behavior: contain;
  box-sizing: border-box; padding: 6px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18); font-size: 14px;
}
.tg-pins-menu[hidden] { display: none; }
.tg-pins-menu.tg-pins-sheet {
  left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: 70dvh; border-radius: 14px 14px 0 0;
  padding: 10px 10px max(12px, env(safe-area-inset-bottom));
}
.tg-pins-head { display: flex; align-items: baseline; gap: 8px; padding: 4px 8px 6px; }
.tg-pins-count { color: var(--muted); font-variant-numeric: tabular-nums; }
/* the pin set the pins are (or the view on screen): in the header, next to the count */
.tg-pins-setname { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); font-size: 13px; }
.tg-pins-viewnote { margin: 0 8px 6px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.tg-pins-head-view { border-left: 3px solid var(--accent); padding-left: 8px; }
.tg-pins-empty { margin: 0 8px 8px; color: var(--muted); line-height: 1.45; }
.tg-pins-row { display: flex; align-items: stretch; border-radius: 6px; }
.tg-pins-row[hidden], .tg-pins-group[hidden] { display: none; }
.tg-pins-row:hover { background: var(--accent-soft); }
.tg-pins-tools { display: grid; gap: 5px; padding: 0 8px 6px; }
.tg-pins-tools input[type="search"], .tg-set-create input {
  min-width: 0; padding: 4px 7px; border: 1px solid var(--rule); border-radius: 5px;
  background: var(--paper); color: var(--ink); font: inherit;
}
.tg-set-choice { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; max-width: 100%; font: 12.5px system-ui, sans-serif; }
.tg-set-select { position: relative; display: inline-flex; align-items: center; max-width: 100%; }
.tg-set-select select {
  max-width: 100%; padding: 3px 4px; border: 1px solid var(--rule); border-radius: 5px;
  background: var(--paper); color: var(--ink); font: inherit; cursor: pointer;
}
.tg-set-select > span, .tg-set-create[hidden] { display: none; }
.tg-set-choice-compact .tg-set-select { width: 24px; height: 28px; justify-content: center; border-radius: 5px; }
.tg-set-choice-compact .tg-set-select > span { display: inline; color: var(--accent); font-size: 16px; }
.tg-set-choice-compact select { position: absolute; inset: 0; width: 100%; opacity: 0; }
.tg-set-choice-compact .tg-set-select:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
.tg-set-create { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 3px; }
.tg-set-create input { width: 8em; }
.tg-set-create button { font: inherit; color: var(--ink); cursor: pointer; }
.tg-set-feedback { color: var(--muted); }
.tg-set-feedback:empty { display: none; }
.ref-popover-body > .tg-set-choice { margin: 0 8px 6px 0; vertical-align: middle; }
.insight-note .tg-set-choice { margin-top: 5px; }
:is(.tg-pins-menu, .tg-pins-panel) button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; border-radius: 6px; }
.tg-pins-go { flex: 1; min-width: 0; text-align: left; padding: 6px 8px; overflow: hidden; text-overflow: ellipsis; }
.tg-pins-go:disabled { opacity: 0.5; cursor: default; }
.tg-pins-go:focus-visible, .tg-pins-x:focus-visible, .tg-pins-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tg-pins-x { flex: none; width: 32px; color: var(--muted); font-size: 17px; line-height: 1; }
.tg-pins-x:hover { color: var(--ink); }
.tg-pins-note, .tg-pins-along, .tg-pins-code { color: var(--muted); }
.tg-pins-along { font-size: 12.5px; }
.tg-pins-sym .katex { font-size: 1.05em; }
.tg-pins-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 8px 4px 2px; margin-top: 4px; border-top: 1px solid var(--rule); }
.tg-pins-actions:has([data-pins-destination-bulk]) { flex-wrap: wrap; align-items: center; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-actions button { border: 1px solid var(--rule); padding: 5px 12px; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-actions button:hover { border-color: var(--accent); }
/* list by kind or in the reading order */
/* pin sets */
.tg-pins-memo-in { font: inherit; font-size: 13px; padding: 2px 6px; border: 1px solid var(--accent); border-radius: 5px; background: var(--paper); color: var(--ink); }
@media (max-width: 760px) {
  .tg-pins-go, .tg-pins-x { min-height: 44px; }
  .tg-pins-x { width: 44px; }
  .tg-set-choice-compact .tg-set-select { width: 36px; min-height: 44px; }
}
/* Pins tab and pin list (src/pins.js): My pins | Pin sets on top; a row is the item · where it is, the note
   under it, and a … menu; a set's page names the set with a way back. */
.tg-pins-top { position: sticky; top: 0; z-index: 1; display: flex; gap: 4px; padding: 2px 6px 8px; background: var(--bg); }
.tg-pins-menu .tg-pins-top { background: var(--paper); }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-top button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 8px; border: 1px solid var(--rule); font-weight: 500; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-top button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.tg-pins-top .tg-pins-count { font-weight: 400; font-size: 12px; }
.tg-pins-sethead { display: flex; align-items: center; gap: 6px; margin: 0 6px 6px; padding: 4px 6px 4px 2px; border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; background: var(--accent-soft); }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-back { flex: none; width: 30px; height: 30px; font-size: 20px; line-height: 1; color: var(--accent); }
.tg-pins-setlabel { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.tg-pins-settitle { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tg-pins-list { display: flex; flex-direction: column; gap: 1px; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-go { display: flex; flex-direction: column; align-items: stretch; gap: 1px; white-space: normal; }
.tg-pins-line { overflow-wrap: anywhere; }
.tg-pins-where { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tg-pins-memo { font-size: 12.5px; color: var(--accent); font-style: italic; overflow-wrap: anywhere; }
.tg-pins-memo::before { content: "“"; } .tg-pins-memo::after { content: "”"; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-more { flex: none; width: 32px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.tg-pins-more svg { width: 15px; height: 15px; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-more:hover, :is(.tg-pins-menu, .tg-pins-panel) .tg-pins-more[aria-expanded="true"] { color: var(--ink); background: var(--accent-soft); }
.tg-pins-row-open { background: var(--accent-soft); }
.tg-pins-rowmenu { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 2px 6px 6px 12px; padding: 6px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); }
.tg-pins-rowmenu[hidden], .tg-pins-noteedit[hidden] { display: none; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-rowmenu > button { padding: 4px 10px; border: 1px solid var(--rule); font-size: 12.5px; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-rowmenu > button:hover { border-color: var(--accent); }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-rowmenu .tg-pins-danger { color: #c0392b; }
.tg-pins-rowmenu .tg-set-choice-compact .tg-set-select { width: auto; height: auto; padding: 4px 10px; border: 1px solid var(--rule); border-radius: 6px; }
.tg-pins-rowmenu .tg-set-choice-compact .tg-set-select > span { display: none; }
.tg-pins-rowmenu .tg-set-choice-compact .tg-set-select::after { content: "Add to set…"; color: var(--accent); font-size: 12.5px; }
.tg-pins-in, .tg-pins-flash { flex-basis: 100%; margin: 2px 2px 0; font-size: 12px; color: var(--muted); }
.tg-pins-flash { color: var(--accent); }
.tg-pins-noteedit { display: flex; gap: 4px; margin: 0 6px 6px 8px; }
.tg-pins-noteedit .tg-pins-memo-in { flex: 1; min-width: 0; margin: 0; padding: 4px 8px; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-noteedit button { padding: 4px 10px; border: 1px solid var(--accent); color: var(--accent); }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-actions > button { white-space: nowrap; }
:is(.tg-pins-menu, .tg-pins-panel) .tg-pins-read { border-color: var(--accent) !important; background: var(--accent) !important; color: var(--paper) !important; }
.tg-sets-page { padding: 0 6px 6px; }
.tg-sets-page .tg-sets-list { margin-bottom: 6px; }
.tg-sets-go { color: var(--muted); font-size: 16px; }
.tg-sets-page .tg-sets-set { padding: 8px; border: 1px solid var(--rule); border-left-width: 1px; border-radius: 6px; margin-bottom: 4px; }
.tg-sets-page .tg-sets-set:hover { border-color: var(--accent); background: var(--accent-soft); }
.tg-sets-new { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tg-sets-new input { flex: 1 1 140px; min-width: 0; font: inherit; padding: 4px 8px; border: 1px solid var(--accent); border-radius: 6px; background: var(--paper); color: var(--ink); }
:is(.tg-pins-menu, .tg-pins-panel) .tg-sets-new button { padding: 4px 10px; border: 1px solid var(--rule); }
:is(.tg-pins-menu, .tg-pins-panel) .tg-sets-new button[type="submit"] { border-color: var(--accent); color: var(--accent); }
.tg-sets-page .tg-sets-starter { margin-right: 6px; }
.tg-pins-empty kbd { font: 11px ui-monospace, monospace; padding: 0 4px; border: 1px solid var(--rule); border-radius: 3px; }
/* Pinned · Add note · Add to set… · Undo, at the bottom of the window as soon as something is pinned */
.tg-pin-toast {
  position: fixed; z-index: 80; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; max-width: min(560px, calc(100vw - 16px)); box-sizing: border-box;
  padding: 8px 8px 8px 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--paper); color: var(--ink);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); font: 13.5px system-ui, sans-serif;
}
.tg-pin-toast[hidden] { display: none; }
.tg-pin-toast-msg { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.tg-pin-toast-msg b { font-weight: 600; overflow-wrap: anywhere; }
.tg-pin-toast-msg .tg-pin-icon { flex: none; width: 16px; height: 16px; color: var(--accent); }
.tg-pin-toast-msg .tg-pin-icon path { fill: var(--accent-soft); }
.tg-pin-toast-acts { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-left: auto; }
.tg-pin-toast button { font: inherit; font-size: 13px; padding: 5px 10px; border: 1px solid var(--rule); border-radius: 6px; background: none; color: var(--accent); cursor: pointer; }
.tg-pin-toast button:hover { border-color: var(--accent); }
.tg-pin-toast .tg-pin-toast-x { border: 0; color: var(--muted); padding: 5px 8px; font-size: 16px; line-height: 1; }
.tg-pin-toast .tg-set-choice-compact .tg-set-select { width: auto; height: auto; padding: 5px 10px; border: 1px solid var(--rule); border-radius: 6px; }
.tg-pin-toast .tg-set-choice-compact .tg-set-select > span { display: none; }
.tg-pin-toast .tg-set-choice-compact .tg-set-select::after { content: "Add to set…"; color: var(--accent); font-size: 13px; }
.tg-pin-toast .tg-set-create input { width: 9em; }
.tg-pin-toast-note { display: flex; gap: 6px; width: 100%; }
.tg-pin-toast-note input { flex: 1; min-width: 0; font: inherit; padding: 5px 8px; border: 1px solid var(--accent); border-radius: 6px; background: var(--paper); color: var(--ink); }
@media (max-width: 760px) {
  .tg-pin-toast { left: 8px; right: 8px; transform: none; max-width: none; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .tg-pin-toast button, .tg-pin-toast .tg-set-choice-compact .tg-set-select { min-height: 40px; }
  :is(.tg-pins-menu, .tg-pins-panel) .tg-pins-more { width: 44px; }
  :is(.tg-pins-menu, .tg-pins-panel) .tg-pins-rowmenu > button, .tg-pins-rowmenu .tg-set-choice-compact .tg-set-select { min-height: 40px; }
  :is(.tg-pins-menu, .tg-pins-panel) .tg-pins-top button { min-height: 40px; }
}
/* the selection bar's pin says Pin on a touch screen, where there is no tooltip */
.tg-hlbar-pin-t { display: none; }
@media (hover: none) {
  .tg-hlbar .tg-hlbar-pin { width: auto; padding: 0 8px 0 6px; gap: 3px; display: inline-flex; align-items: center; font: 13px system-ui, sans-serif; color: var(--accent); }
  .tg-hlbar-pin-t { display: inline; }
}
/* Read pinned items: the study sheet at the top, each pin's number and note above it */
.pick-sheet { margin: 0 0 1.4em; padding: 10px 14px; border: 1px solid var(--rule); border-left: 3px solid var(--accent); border-radius: 6px; background: var(--paper); font-size: 0.92em; }
.pick-sheet-head { margin-bottom: 4px; }
.pick-sheet ol { margin: 0; padding-left: 1.6em; }
.pick-sheet li { margin: 2px 0; }
.pick-sheet-go { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.pick-sheet-go:hover { text-decoration: underline; }
.pick-sheet-note, .pick-memo-t { font-style: italic; color: var(--muted); }
.pick-memo { display: flex; align-items: baseline; gap: 8px; margin: 1em 0 -0.4em; font-size: 0.9em; }
.pick-memo-n { flex: none; min-width: 1.5em; height: 1.5em; line-height: 1.5em; border-radius: 0.75em; text-align: center; background: var(--accent); color: var(--paper); font-size: 0.85em; font-weight: 600; font-variant-numeric: tabular-nums; }
@media screen {
  .pick-reading { display: flex; flex-direction: column; reading-flow: flex-visual; }
  .pick-reading .pick-reading-shell:not(.pick-hide) { display: contents; }
  .pick-reading .pick-head:not(.title-block) { display: none; }
  .pick-reading :is(.pick-on, .pick-proof, .pick-head, .pick-sheet, .pick-memo, .pick-context) {
    order: var(--pick-order, 0);
  }
}
.toolbar .more-compact :is(#settings, #theme-toggle, #hand-toggle) { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; }
.more-compact :is(#settings, #theme-toggle, #hand-toggle) .tb-label { display: inline; }
.toolbar .more-compact :is(#settings, #theme-toggle, #hand-toggle) svg { width: 18px; height: 18px; }
.tb-phone-label { display: none; }
#theme-toggle .tb-label { display: none; }
.more-compact #theme-toggle .tb-label { display: inline; }
.more-compact[hidden] { display: none; }
.more-compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--rule);
}
.toolbar .more-compact > button,
.toolbar .more-compact .mode-switch button,
.toolbar .more-compact .zoom-group button {
  width: auto;
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: 6px;
  justify-content: center;
  align-items: center;
}
.toolbar .more-compact .mode-switch button,
.toolbar .more-compact .zoom-group button { border-radius: 0; }
.toolbar .more-compact .mode-switch button:first-child,
.toolbar .more-compact .zoom-group button:first-child { border-radius: 6px 0 0 6px; }
.toolbar .more-compact .mode-switch button:last-child,
.toolbar .more-compact .zoom-group button:last-child { border-radius: 0 6px 6px 0; }
.toolbar .more-compact button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.more-compact .mode-switch, .more-compact .zoom-group { flex: 1 0 100%; display: flex; }
.more-compact .mode-switch button, .more-compact .zoom-group button { flex: 1; }
.more-compact .gh-link { padding: 8px 4px; }
.more-compact .render-actions { flex: 1 0 100%; gap: 8px; }
.toolbar .more-compact .render-actions button { width: auto; border: 1px solid var(--rule); }
.more-compact .render-actions a:not([hidden]) { display: inline-flex; align-items: center; min-height: 44px; }

/* Only the vertical reader should move on a phone. Keep the horizontal
   scrollers inside individual equations, code, diagrams and tables. */
@media screen and (max-width: 760px), screen and (pointer: coarse) {
  html.tg-viewer { overscroll-behavior-x: none; }
  .tg-viewer #preview-pane {
    overflow-x: hidden;
    overscroll-behavior-x: none;
  }
  .tg-viewer #preview :is(.math-display, .table-wrap, .tg-diagram, pre) {
    overscroll-behavior-x: contain;
  }
}

@media (max-width: 760px) {
  .toolbar {
    flex-wrap: nowrap;
    gap: 6px;
    --toolbar-pad-y: 6px;
    --toolbar-pad-x: 10px;
  }
  .brand { display: none; }
  .support-link { display: none; }
  .toolbar .more-menu .more-support { display: flex; }
  .toolbar button { min-height: 44px; min-width: 44px; font-size: 15px; padding: 6px 12px; }
  .toolbar .icon-button svg, .tb-icon { width: 22px; height: 22px; }
  .tb-icon { display: block; }
  #toc-toggle .tb-label, #find .tb-label, #save-offline .tb-label, #bookmark .tb-label, #share .tb-label { display: none; }
  .more-compact :is(#share, #save-offline, #bookmark) .tb-label { display: inline; }
  .toolbar .tb-iconic .tb-icon { width: 22px; height: 22px; }
  .toolbar .more-compact .tb-iconic .tb-icon { width: 18px; height: 18px; }
  #save-offline .tb-icon, #bookmark .tb-icon, #share .tb-icon { width: 22px; height: 22px; }
  .toolbar .more-compact #save-offline .tb-icon, .toolbar .more-compact #bookmark .tb-icon { width: 18px; height: 18px; }
  #toc-toggle, #find, #save-offline, #bookmark, #share { display: inline-flex; align-items: center; justify-content: center; padding: 6px 10px; }
  .toolbar .more-button { padding: 6px 12px; font-size: 18px; line-height: 1; }
  .toolbar .more-button[data-render-warnings]::after {
    content: attr(data-render-warnings);
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 16px;
    padding: 2px 3px;
    border-radius: 12px;
    background: var(--warn);
    color: var(--paper);
    font-size: 10px;
  }
  .toolbar > :is(#open, #toc-toggle, #find, #pins, .more-group) { flex: 1 1 0; min-width: 44px; }
  .toolbar > .more-group > #more { width: 100%; }
  .toolbar > :is(#open, #toc-toggle, #find, #pins):not([hidden]),
  .toolbar > .more-group > #more {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    padding: 3px;
    min-height: 44px;
  }
  .toolbar > :is(#open, #toc-toggle) .tb-label, .toolbar .tb-phone-label {
    display: block;
    font-size: 10px;
    line-height: 1.15;
  }
  .toolbar .more-glyph { height: 22px; line-height: 18px; }
  .toolbar > #pins .tg-pins-badge { top: 1px; right: 3px; }
  .more-compact .file-name { order: -1; flex: 0 0 100%; font-size: 13px; }
  .status { position: absolute; right: 12px; top: 100%; margin-top: 4px; padding: 2px 8px; border-radius: 10px; background: var(--toolbar); font-size: 12px; pointer-events: none; }
  .status:empty { display: none; }
  .more-menu {
    left: auto;
    right: 0;
    width: min(320px, calc(100vw - 16px));
  }
  .toolbar .more-menu button { min-height: 44px; align-items: center; font-size: 15px; }
  .toolbar .more-menu .more-support { display: flex; min-height: 44px; align-items: center; font-size: 14px; }

  /* the side panel: a drawer over the page (opened by its button or a swipe from its edge) */
  .toc-pane {
    width: min(320px, 86vw);
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(32px, env(safe-area-inset-bottom));
    z-index: 30; /* over the toolbar too */
    touch-action: pan-y;
    animation: tg-drawer-left 0.18s ease-out;
  }
  body.toc-right .toc-pane { animation-name: tg-drawer-right; }
  body.toc-open .panes::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 29;
    background: rgba(0, 0, 0, 0.25);
  }
  .toc-list a { padding-top: 8px; padding-bottom: 8px; }

  /* the text takes the whole width: a little room left for the margin's button */
  #preview { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  #preview.tg-with-margin.tg-margin-overlay { max-width: calc(760px * var(--zoom, 1)); padding-right: max(30px, env(safe-area-inset-right)); }
  html.tg-viewer #preview, html.tg-viewer #preview.tg-with-margin:is(.tg-margin-overlay, .tg-margin-collapsed) { max-width: none; }
  :root[data-look="notes"] #preview.document.tg-with-margin.tg-margin-overlay { padding-right: 34px; }
  .tg-margin-toggle { min-width: 24px; height: 26px; border-radius: 13px; }
  .tg-margin-folded .tg-margin-toggle { left: -8px; }
  .tg-margin-nav button { min-width: 26px; min-height: 26px; }
  .tg-margin-nav, .tg-mnav-menu { top: 30px; }
  .tg-margin-stick { height: 112px; }


  .tg-note-dock { bottom: max(16px, env(safe-area-inset-bottom)); }
}
/* A display formula too wide for the screen breaks after its relations and operators
   (app.js marks the ones too wide, on a phone or a touch screen). */
.math-display.tg-reflow .katex-display > .katex { white-space: normal; text-align: left; padding-left: 1.2em; text-indent: -1.2em; }
.math-display.tg-reflow .katex-display > .katex > .katex-html { display: block !important; }
.math-display.tg-reflow .katex-display > .katex > .katex-html::before { content: none !important; }
.math-display.tg-reflow .katex-display > .katex > .katex-html > .base { margin: 0.25em 0; text-indent: 0; }
.math-display.tg-reflow .katex-display > .katex > .katex-html > .tag { position: static; display: block; text-align: right; padding: 0; text-indent: 0; }
@keyframes tg-drawer-left { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes tg-drawer-right { from { transform: translateX(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .toc-pane, .tg-margin-drawer { animation: none !important; } }

/* the margin as a drawer over the text, on a phone (src/margin.js setOverlay) */
.tg-margin.tg-margin-drawer {
  z-index: 18;
  background: var(--paper);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18);
  border-left: 1px solid var(--rule);
  touch-action: pan-y;
  animation: tg-drawer-right 0.18s ease-out;
}
:root[data-look="notes"] .tg-margin.tg-margin-drawer { background: var(--sheet, var(--paper)); }
.tg-margin-drawer .tg-mcard { left: 14px; right: 12px; }
.tg-margin-drawer .tg-margin-grip { display: none; }
.tg-margin-drawer .tg-margin-toggle { left: -13px; opacity: 1; }
.tg-margin-drawer .tg-margin-nav { left: -13px; }

/* handwritten notes (a pen in the margin, src/margin.js) */
.tg-ink { display: block; width: 100%; height: auto; overflow: visible; color: var(--ink); }
.tg-ink-text { margin-top: 0.2em; }
.tg-ink-live { position: absolute; left: 0; top: 0; width: 100%; overflow: visible; pointer-events: none; color: var(--ink); z-index: 4; }
.tg-mcard-editing .tg-ink { margin-bottom: 0.3em; }

/* previews as a sheet at the bottom, on a touch screen (src/popover.js) */
.ref-popover.tg-sheet {
  left: 0 !important;
  right: 0;
  top: auto !important;
  bottom: 0;
  width: auto !important;
  padding: 0;
  z-index: 40;
  animation: tg-sheet-up 0.18s ease-out;
  transition: transform 0.12s;
}
.tg-sheet > .ref-popover-body {
  max-height: min(70vh, 70dvh) !important;
  max-width: 820px;
  margin: 0 auto;
  padding: 26px max(18px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.22);
}
.tg-sheet-grip {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 24px;
  touch-action: none;
  cursor: grab;
}
.tg-sheet-grip::after {
  content: "";
  position: absolute;
  top: 9px;
  left: 42px;
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--rule);
}
.tg-sheet-head { display: flex; justify-content: flex-end; margin: -4px 0 6px; }
.tg-sheet-go {
  font: 14px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
}
@keyframes tg-sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .ref-popover.tg-sheet { animation: none; } }

/* Reading progress (src/progress.js): a status marker by each result's heading,
   progress in the Contents tab, and the map coloured by status. */
.rp-marks { display: inline-flex; align-items: center; gap: 0.15em; margin: 0 0.1em 0 0.3em; vertical-align: -0.1em; font-style: normal; }
.rp-off .rp-marks, .ref-popover .rp-marks, .insight-popover .rp-marks, .insight-dialog .rp-marks, .tg-margin .rp-marks { display: none; }
.rp-mark, .rp-q {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 1em; height: 1em; padding: 0; border-radius: 50%; cursor: pointer; font: inherit; line-height: 1;
}
.rp-mark { border: 1.5px solid var(--muted); background: none; opacity: 0.35; transition: opacity 0.15s; }
.theorem:hover > * > .rp-marks .rp-mark, .theorem:hover > .rp-marks .rp-mark, .proof:hover .rp-mark, .rp-mark:focus-visible { opacity: 0.9; }
.rp-mark[data-s="skimmed"] { opacity: 1; border-color: var(--rp-skimmed); background: conic-gradient(var(--rp-skimmed) 0 33%, transparent 0); }
.rp-mark[data-s="read"] { opacity: 1; border-color: var(--rp-read); background: conic-gradient(var(--rp-read) 0 67%, transparent 0); }
.rp-mark[data-s="understood"] { opacity: 1; border-color: var(--rp-understood); background: var(--rp-understood); }
.rp-mark[data-s="understood"]::after { content: "\2713"; color: var(--paper); font-size: 0.7em; font-weight: 700; }
.rp-q { border: 0; background: none; color: var(--muted); opacity: 0; transition: opacity 0.15s; }
.rp-q::before { content: "?"; font-weight: 700; font-size: 0.85em; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.theorem:hover .rp-q, .proof:hover .rp-q, .rp-q:focus-visible { opacity: 0.6; }
.rp-q:hover { opacity: 1; color: var(--rp-q); }
.rp-q[aria-pressed="true"] { opacity: 1; color: var(--on-accent); background: var(--rp-q); }
@media (hover: none) { .rp-mark { opacity: 0.6; } .rp-q { opacity: 0.5; } }

/* the Contents tab: the paper's progress at the top, and a bar by each section */
.rp-summary { margin: 0 0 8px; padding: 6px 8px 8px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); font-size: 13px; }
.rp-summary[hidden], .toc-pane:not([data-tab="toc"]) .rp-summary, .toc-pane.rp-only-q:not([data-tab="notation"]):not([data-tab="deps"]) .toc-list { display: none; }
.rp-sum-line { display: flex; align-items: center; gap: 8px; }
.rp-sum-line .rp-bar { flex: 1 1 auto; width: auto; height: 6px; }
.rp-sum-text { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rp-sum-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.rp-summary button { font: inherit; font-size: 12px; padding: 2px 8px; border: 1px solid var(--rule); border-radius: 6px; background: none; color: var(--ink); cursor: pointer; }
.rp-summary button:hover { border-color: var(--accent); color: var(--accent); }
.rp-summary button[data-rp="questions"] { color: var(--rp-q); font-weight: 600; }
.rp-summary button[aria-pressed="true"] { background: var(--rp-q); border-color: var(--rp-q); color: var(--on-accent); }
.rp-next p { margin: 6px 0 0; line-height: 1.4; }
.rp-next button { margin-left: 4px; }
.rp-qhead { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.rp-qlist { margin: 4px 0 0; padding-left: 1.4em; }
.rp-qlist li { margin: 2px 0; }
.rp-summary a { color: var(--accent); text-decoration: none; }
.rp-summary a:hover { text-decoration: underline; }
.rp-muted { color: var(--muted); }
.rp-bar { display: inline-flex; overflow: hidden; width: 34px; height: 5px; border-radius: 3px; background: var(--rule); flex: 0 0 auto; }
.rp-bar i { display: block; height: 100%; }
.rp-bar-understood { background: var(--rp-understood); }
.rp-bar-read { background: var(--rp-read); }
.rp-bar-skimmed { background: var(--rp-skimmed); }
.toc-list .rp-toc { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; padding-left: 4px; align-self: center; color: var(--muted); font-size: 11px; font-weight: 400; font-variant-numeric: tabular-nums; white-space: nowrap; }
.toc-list .rp-toc-done .rp-toc-n { color: var(--rp-understood); }

/* the map: results coloured by status, "?" flagged */
.dep-node.rp-st-skimmed rect { fill: var(--rp-skimmed-bg); }
.dep-node.rp-st-read rect { fill: var(--rp-read-bg); }
.dep-node.rp-st-understood rect { fill: var(--rp-understood-bg); stroke: var(--rp-understood); }
.dep-node.rp-st-understood.dep-sel rect, .dep-node.rp-st-read.dep-sel rect, .dep-node.rp-st-skimmed.dep-sel rect { fill: var(--accent); }
.dep-node .rp-qmark circle { fill: var(--rp-q); stroke: var(--paper); stroke-width: 1.5; }
.dep-node .rp-qmark text { fill: var(--on-accent); font-size: 10px; font-weight: 700; }
.dep-picked .dep-node .rp-qmark { opacity: 1; }
.rp-key { display: inline-block; width: 14px; height: 10px; border: 1px solid var(--thm-border); border-radius: 3px; vertical-align: -1px; background: var(--paper); }
.rp-key-skimmed { background: var(--rp-skimmed-bg); }
.rp-key-read { background: var(--rp-read-bg); }
.rp-key-understood { background: var(--rp-understood-bg); border-color: var(--rp-understood); }
.rp-key-q { border: 0; background: none; width: auto; color: var(--rp-q); font-weight: 700; }
.rp-detail { color: var(--ink); }

/* --- Show selected results (src/pick.js) -----------------------------------------
   Picking: every result and numbered equation gets a tick box; a click ticks it.
   Showing: only the ticked ones, their section headings and their proofs (folded). */
.pick-mode .pick-able { position: relative; cursor: pointer; }
.pick-mode .pick-able:hover { outline: 1.5px dashed var(--thm-border); outline-offset: 4px; border-radius: 2px; }
.pick-mode .pick-able.pick-on { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 2px; }
.pick-box {
  /* inside the block, top right of a result and left of an equation: results
     and displays may scroll sideways, which would clip anything outside them */
  position: absolute; right: 0.5em; top: 0.55em; z-index: 1;
  width: 1.05em; height: 1.05em; box-sizing: border-box;
  border: 1.6px solid var(--muted); border-radius: 3px; background: var(--paper);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem; font-style: normal; line-height: 1; color: #fff;
}
.pick-box[aria-checked="true"] { border-color: var(--accent); background: var(--accent); }
.pick-box[aria-checked="true"]::after { content: "✓"; font-size: 0.8em; font-weight: 700; }
.math-display > .pick-box { right: auto; left: 0.3em; top: 50%; transform: translateY(-50%); }
@media screen { .pick-view .pick-hide { display: none !important; } }
/* What a pinned result rests on (Show only these): definitions and notation, folded */
.pick-context { margin: -0.2em 0 1em; padding: 4px 10px; border-left: 3px solid var(--rule); font-size: 0.9em; color: var(--muted); }
.pick-context > summary { cursor: pointer; line-height: 1.6; }
.pick-context > summary:hover { color: var(--ink); }
.pick-context[open] { color: inherit; border-left-color: var(--accent); }
.pick-ctx-k { font-weight: 600; font-variant: small-caps; letter-spacing: 0.02em; margin-right: 0.25em; }
.pick-ctx-k2 { font-style: italic; }
.pick-ctx-sym code { font-size: 0.85em; }
.pick-ctx-body { padding: 4px 0 2px; }
.pick-ctx-def { margin: 0.4em 0 0.8em; }
.pick-ctx-src { font-size: 0.92em; margin-bottom: 2px; }
.pick-ctx-src a, .pick-ctx-where { color: var(--accent); }
.pick-ctx-def > .theorem { margin: 0; }
.pick-ctx-syms { margin: 0.3em 0; padding-left: 1.2em; }
.pick-ctx-syms li { margin: 0.35em 0; }
.pick-ctx-what { display: inline-block; min-width: 2em; margin-right: 0.3em; }
.pick-ctx-shown > * { display: inline; }
.pick-ctx-where { font-size: 0.9em; white-space: nowrap; }
/* The handout (Print on the bar of Show only these): only on paper */
.pick-handout { display: none; }
.pick-handout-order { margin: 0 0 1.4em; }
.pick-handout-order ol { padding-left: 1.6em; }
.pick-handout-item { margin: 0 0 1.2em; }
.pick-handout-from { margin: 0.8em 0 0.2em; font-size: 0.85em; color: var(--muted); font-variant: small-caps; }
.pick-handout-rests { margin: 0.3em 0 0; font-size: 0.88em; color: var(--muted); }
.pick-handout-context { margin-top: 2em; }
/* room to scroll the last item above the bar */
@media screen { .pick-mode, .pick-view { padding-bottom: 6rem !important; } }
.pick-names { color: var(--muted); font-size: 0.9em; }
.pick-bar button:disabled { opacity: 0.5; cursor: default; }


/* Stepping through a proof (src/steps.js) */
.tg-step-btn {
  display: inline-flex; align-items: center; gap: 4px;
  margin: 0 0.35em; padding: 1px 8px 1px 6px;
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--paper); color: var(--muted);
  font: 500 12px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  font-style: normal; vertical-align: 0.1em; cursor: pointer;
  opacity: 0.55; transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
.tg-step-btn svg { width: 9px; height: 9px; }
.proof:hover .tg-step-btn, .tg-step-btn:focus-visible { opacity: 1; }
.tg-step-btn:hover { color: var(--accent); border-color: var(--accent); }
.tg-step-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.proof.folded .tg-step-btn { display: none; }
.tg-stepping .tg-step-btn { opacity: 1; color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.tg-stepping .tg-step-btn span { display: none; }
.tg-stepping .tg-step-btn::after { content: "Stop"; }
.tg-stepping .tg-step-btn svg { display: none; }
@media (hover: none) { .tg-step-btn { opacity: 0.85; padding: 3px 10px 3px 8px; font-size: 13px; } }

.tg-stepping { cursor: pointer; }
.tg-stepping .tg-step-hidden { display: none !important; }
.tg-stepping .tg-step-now { background: var(--flash); border-radius: 3px; box-shadow: 0 0 0 2px var(--flash); scroll-margin: 90px 0; }
.tg-stepping .tg-step-now:not(.tg-step-text) { box-shadow: -8px 0 0 0 var(--flash), 0 0 0 2px var(--flash); }
.tg-stepping .tg-step-text { transition: background-color 0.25s; }
.tg-stepping .tg-step-folded:not(.tg-step-now) { color: var(--muted); }
.tg-stepping .tg-stepmark[data-tg-step]:not([data-tg-step=""])::before { content: attr(data-tg-step) ". "; font-weight: 600; }
.tg-step-fold {
  margin: 0 0.25em; padding: 0 6px;
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--paper); color: var(--accent);
  font: 500 11px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
  font-style: normal; vertical-align: 0.12em; cursor: pointer; white-space: nowrap;
}
.tg-step-fold:hover { color: var(--accent); border-color: var(--accent); }
.tg-step-fold[hidden] { display: none; }
.tg-step-bar {
  position: sticky; bottom: 10px; z-index: 6;
  display: flex; align-items: center; gap: 6px; width: max-content; max-width: 100%;
  margin: 10px auto 0; padding: 5px 6px;
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--toolbar); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; font-style: normal;
  cursor: default; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.tg-step-bar button {
  padding: 4px 12px; border: 1px solid var(--rule); border-radius: 999px;
  background: var(--paper); color: var(--ink); font: inherit; cursor: pointer;
}
.tg-step-bar button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.tg-step-bar button:disabled { opacity: 0.4; cursor: default; }
.tg-step-bar .tg-step-next { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tg-step-bar .tg-step-next:hover { color: var(--on-accent) !important; filter: brightness(1.08); }
.tg-step-count { min-width: 4.2em; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (pointer: coarse) {
  .tg-step-bar { bottom: max(12px, env(safe-area-inset-bottom)); gap: 8px; }
  .tg-step-bar button { min-height: 40px; padding: 6px 16px; }
  .tg-step-fold { padding: 2px 9px; font-size: 12px; }
}

/* Live parameters (src/params.js): sliders for texglass.sty's \tgparam */
.tg-sliders {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
  margin: 0.4em 0 0.6em; padding: 4px 10px;
  border: 1px solid var(--rule); border-radius: 8px;
  background: var(--paper); color: var(--muted);
  font: 13px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  font-style: normal; text-indent: 0; text-align: left;
  -webkit-user-select: none; user-select: none;
}
p > .tg-sliders, li > .tg-sliders, td > .tg-sliders, dd > .tg-sliders { margin-bottom: 0.2em; }
.tg-slider { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.tg-slider-name { color: var(--ink); }
.tg-slider input[type="range"] { width: 9em; accent-color: var(--accent); margin: 0; }
.tg-slider output { min-width: 2.5em; font-variant-numeric: tabular-nums; color: var(--ink); }
.tg-value { font-variant-numeric: tabular-nums; }
.tg-sliders-reset {
  margin-left: auto; padding: 0 8px; border: 1px solid var(--rule); border-radius: 999px;
  background: transparent; color: var(--muted); font: inherit; cursor: pointer;
}
.tg-sliders-reset:hover { color: var(--accent); border-color: var(--accent); }
.tg-sliders-reset[hidden] { display: none; }
@media (pointer: coarse) { .tg-slider input[type="range"] { width: 12em; height: 28px; } }
/* Settings: clearing the reader's notes (src/features.js) */
.features-clear .clear-intro { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); }
.features-clear .clear-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.features-clear [hidden] { display: none !important; }
.features-clear button {
  font: inherit; font-size: 13.5px; padding: 5px 12px; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink); cursor: pointer;
}
.features-clear button:disabled { opacity: 0.55; cursor: default; }
.features-clear .clear-confirm { border: 1px solid var(--warn); border-radius: 8px; padding: 10px 12px; }
.features-clear .clear-title { margin: 0; font-weight: 600; }
.features-clear .clear-summary { margin: 2px 0 6px; font-size: 13px; color: var(--muted); }
.features-clear .clear-summary:empty { display: none; }
.features-clear .clear-confirm .feature { margin: 0 -4px; padding: 4px; }
.features-clear .clear-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.features-clear button.danger { background: var(--warn); border-color: var(--warn); color: var(--paper); font-weight: 600; }
.features-clear .clear-done { margin: 6px 0 0; font-size: 13px; }
.features-clear .clear-done:empty { display: none; }

/* The first-run tour (src/coach.js): the page dimmed around one control, a card beside it */
.tg-coach-veil { position: fixed; inset: 0; z-index: 2147483000; background: transparent; }
.tg-coach-veil.tg-coach-dim { background: rgba(0, 0, 0, 0.45); }
.tg-coach-spot {
  position: fixed; z-index: 2147483001; pointer-events: none; border-radius: 10px;
  box-shadow: 0 0 0 3px var(--accent), 0 0 0 9999px rgba(0, 0, 0, 0.45);
  transition: left 0.2s ease, top 0.2s ease, width 0.2s ease, height 0.2s ease;
}
.tg-coach-card {
  position: fixed; z-index: 2147483002; box-sizing: border-box; width: min(360px, calc(100vw - 20px));
  padding: 14px 16px 12px; border: 1px solid var(--rule); border-radius: 12px;
  background: var(--paper); color: var(--ink); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.tg-coach-card.tg-coach-sheet {
  left: 0 !important; right: 0; width: auto; border-radius: 0; border-width: 1px 0 0;
  padding: 14px 16px calc(12px + env(safe-area-inset-bottom));
}
.tg-coach-card.tg-coach-sheet[data-sheet="bottom"] { bottom: 0; top: auto !important; border-radius: 14px 14px 0 0; }
.tg-coach-card.tg-coach-sheet[data-sheet="top"] { top: 0 !important; bottom: auto; border-width: 0 0 1px; border-radius: 0 0 14px 14px; padding-top: calc(14px + env(safe-area-inset-top)); padding-bottom: 12px; }
.tg-coach-count { display: flex; gap: 5px; margin-bottom: 8px; }
.tg-coach-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--rule); }
.tg-coach-dot.on { background: var(--accent); }
.tg-coach-title { margin: 0 0 4px; font-size: 15.5px; font-weight: 600; }
.tg-coach-body { color: var(--ink); }
.tg-coach-body p { margin: 0 0 6px; }
.tg-coach-body kbd { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 1px 4px; border: 1px solid var(--rule); border-radius: 4px; background: var(--code-bg); }
.tg-coach-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.tg-coach-grow { flex: 1; }
.tg-coach-actions button:not(.link-button) {
  font: inherit; font-size: 13.5px; padding: 6px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
}
.tg-coach-actions button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tg-coach-skip { font-size: 13px; color: var(--muted); }
@media (pointer: coarse) { .tg-coach-actions button:not(.link-button) { min-height: 40px; padding: 8px 16px; } .tg-coach-skip { min-height: 40px; } }
/* the pointed-at result shows its own buttons (pin, What does this use?, Step through) */
.tg-coach-hot .uses-btn, .tg-coach-hot .tg-pin-btn, .tg-coach-hot .tg-step-btn { opacity: 1 !important; }
@media (prefers-reduced-motion: reduce) { .tg-coach-spot { transition: none; } }

/* Formulas and pictures drawn by the reader's own LaTeX (src/texfallback.js),
   where TeXglass could not draw them: black ink on no paper, so dark themes
   turn it light. */
.tg-texfallback-img { max-width: 100%; height: auto; }
.math-display.tg-texfallback, div.tg-texfallback-picture { text-align: center; }
div.tg-texfallback-picture { margin: 0.8em 0; }
@media screen and (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tg-texfallback-img { filter: invert(1) hue-rotate(180deg); } }
@media screen { :root[data-theme="dark"] .tg-texfallback-img { filter: invert(1) hue-rotate(180deg); } }

/* A formula of a long paper on a phone, away from the screen: its drawing is put
   away (app.js stripMath); its text and equation number stay for the reading tools. */
.katex-html.tg-lazy { visibility: hidden; }

/* \author{Name\\ Affiliation}: the lines after the name, in the text's own font */
.author .affil { display: block; font-variant: normal; font-size: 0.85em; line-height: 1.5; }
.author .affil:first-of-type { margin-top: 0.3em; }
/* a \thanks note in the title: its mark is a symbol (∗, †, …), not a number */
.footnotes li.fn-symbol { list-style: none; }
.footnotes li.fn-symbol::before { content: attr(data-mark); display: inline-block; width: 1.4em; margin-left: -1.4em; }

/* Slide outlines: slide list and editor, with a separate audience view. */
.tg-outline {
  box-sizing: border-box; width: min(920px, calc(100% - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--rule); border-radius: 12px; color: var(--ink); background: var(--paper);
  font: 14px/1.45 system-ui, sans-serif;
}
.tg-outline::backdrop { background: rgb(0 0 0 / .42); }
.tg-outline header, .tg-outline footer { padding: 12px 16px; background: var(--paper); z-index: 1; }
.tg-outline header { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0; border-bottom: 1px solid var(--rule); }
.tg-outline header h2 { font-size: 1.25rem; margin: 0; }
.tg-outline footer { border-top: 1px solid var(--rule); }
.tg-outline-work { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(0, 3fr); }
.tg-outline nav, .tg-outline-editor { min-width: 0; padding: 12px 16px; }
.tg-outline nav { background: var(--bg); border-right: 1px solid var(--rule); }
.tg-outline label { display: grid; gap: 3px; margin: 9px 0; font-weight: 600; }
.tg-outline small { color: var(--muted); font-weight: 400; }
.tg-outline :is(input:not([type=checkbox]), select, textarea) {
  box-sizing: border-box; width: 100%; min-width: 0; font: inherit; font-weight: 400; color: var(--ink);
  background: var(--paper); border: 1px solid var(--rule); border-radius: 5px; padding: 6px 8px;
}
.tg-outline textarea { resize: vertical; }
.tg-outline button {
  color: var(--ink); background: var(--paper); border: 1px solid var(--rule); border-radius: 5px;
  padding: 5px 9px; min-height: 32px; font: inherit; text-align: left; cursor: pointer; overflow-wrap: anywhere;
}
.tg-outline button:disabled { opacity: .5; cursor: default; }
.tg-outline :is(button, input, select, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tg-outline button[aria-current], .tg-outline [data-outline-act=download], .tg-outline [data-outline-act=present] { background: var(--accent-soft); border-color: var(--accent); }
.tg-outline-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tg-outline-slides, .tg-outline-sources { list-style: none; padding: 0; margin: 8px 0; }
.tg-outline-slides li + li { margin-top: 4px; }
.tg-outline-slides button { width: 100%; }
.tg-outline-sources li { padding: 8px 0; border-bottom: 1px solid var(--rule); overflow-wrap: anywhere; }
.tg-outline-copy { white-space: pre-wrap; overflow: auto; overflow-wrap: anywhere; margin: 5px 0; }
.tg-outline-copy, .tg-presentation-slide { font-family: var(--tg-outline-paper-font, inherit); }
.tg-outline-preview:not(:empty) { border-left: 2px solid var(--rule); padding: 4px 8px; }
.tg-outline-link { width: min(510px, calc(100% - 24px)); }
.tg-outline-linked-note {
  max-height: 24vh; padding: 8px 10px; border-inline-start: 2px solid var(--accent); background: var(--bg);
}
.tg-outline-link [data-outline-act=link-slide] { background: var(--accent-soft); border-color: var(--accent); }
.tg-outline-link small { display: block; margin-top: 6px; }
.tg-outline-placement { margin-inline-start: 7px; color: var(--muted); font-size: 12px; }
.tg-outline fieldset { min-width: 0; margin: 12px 0; border: 1px solid var(--rule); border-radius: 6px; }
.tg-outline label.tg-outline-check { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; font-weight: 400; }
@media (max-width: 620px) {
  .tg-outline { width: calc(100% - 12px); max-height: calc(100dvh - 12px); }
  .tg-outline-link { width: min(510px, calc(100% - 12px)); }
  .tg-outline-work { grid-template-columns: minmax(0, 1fr); }
  .tg-outline nav { border-right: 0; border-bottom: 1px solid var(--rule); }
  .tg-outline-slides { max-height: 25vh; overflow: auto; }
  .tg-outline button { min-height: 40px; }
  .tg-outline :is(input:not([type=checkbox]), select, textarea) { font-size: 16px; }
}

/* Fill the viewer without asking for browser fullscreen permission. */
.tg-presentation[open] {
  position: fixed; inset: 0; margin: 0; width: 100%; max-width: none; height: 100dvh; max-height: none;
  border: 0; border-radius: 0; overflow: hidden;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
}
.tg-presentation header h2 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-presentation header, .tg-presentation footer { padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right)); }
.tg-presentation header { padding-top: max(12px, env(safe-area-inset-top)); }
.tg-presentation footer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.tg-presentation footer nav { display: flex; justify-content: center; align-items: center; gap: clamp(10px, 3vw, 32px); padding: 0; }
.tg-presentation button { min-height: 44px; min-width: 44px; text-align: center; }
.tg-presentation-stage { min-width: 0; overflow: auto; overscroll-behavior: contain; }
.tg-presentation-stage:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tg-presentation-slide {
  box-sizing: border-box; max-width: 72rem; margin-inline: auto; padding: clamp(16px, 4vw, 64px);
  font-size: clamp(1.125rem, 2.4vw, 2rem); line-height: 1.45; overflow-wrap: anywhere;
}
.tg-presentation-slide h3 { margin: 0 0 .65em; font-size: 1.6em; line-height: 1.2; }
.tg-presentation-slide h4 { margin: 0 0 .35em; font-size: 1em; }
.tg-presentation-slide :is(h3, h4, .tg-presentation-copy) { overflow-x: auto; }
.tg-presentation-copy { white-space: pre-wrap; }
.tg-presentation-source { margin-top: 1em; padding-top: .55em; border-top: 1px solid var(--rule); }

/* --- slide builder (src/slidebuilder.js) ------------------------------------
 * A panel beside the paper. A slide is a 16:9 stage whose boxes sit at
 * percentages of its size; text is sized from the stage's width (cqw), so a
 * slide looks the same in the strip, the editor, the presentation and print. */
.tg-sb-resizer { flex: 0 0 6px; cursor: col-resize; background: var(--rule); opacity: .5; touch-action: none; }
.tg-sb-resizer:hover, .tg-sb-resizer:focus-visible { opacity: 1; background: var(--accent); outline: none; }
.tg-sb-resizer[hidden] { display: none; }
.tg-sb {
  flex: 0 0 var(--tg-sb-width, 46%); min-width: 0; display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--rule); overflow: hidden; font-size: 13.5px; order: 3;
}
.tg-sb-resizer { order: 3; }
.tg-sb[hidden] { display: none; }
.tg-sb button { font: inherit; font-size: 13px; padding: 4px 9px; border-radius: 6px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink); cursor: pointer; }
.tg-sb button:hover:not(:disabled) { border-color: var(--accent); }
.tg-sb button:disabled { opacity: .45; cursor: default; }
.tg-sb button.tg-sb-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent, #fff); }
.tg-sb-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--rule); background: var(--paper); }
.tg-sb-top select { max-width: 12em; font: inherit; }
.tg-sb-top input { flex: 1 1 8em; min-width: 6em; font: inherit; padding: 3px 6px; border: 1px solid var(--rule); border-radius: 6px; background: var(--bg); color: var(--ink); }
.tg-sb-close { margin-left: auto; font-size: 16px !important; line-height: 1; }
.tg-sb details { position: relative; }
.tg-sb summary { cursor: pointer; list-style: none; padding: 4px 9px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); }
.tg-sb summary::-webkit-details-marker { display: none; }
.tg-sb details > div { position: absolute; z-index: 5; top: calc(100% + 4px); left: 0; display: flex; flex-direction: column; gap: 6px; padding: 8px; min-width: 14em;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; box-shadow: 0 6px 24px rgb(0 0 0 / .14); }
.tg-sb-more > div { left: auto; right: 0; }
.tg-sb-sources { max-height: 50vh; overflow: auto; width: min(26em, 70vw); }
.tg-sb-sources button { text-align: left; cursor: grab; }
.tg-sb-work { flex: 1; min-height: 0; display: flex; }
.tg-sb-strip { flex: 0 0 116px; margin: 0; padding: 8px; list-style: none; overflow: auto; border-right: 1px solid var(--rule); display: flex; flex-direction: column; gap: 8px; }
.tg-sb-strip li[data-slide] > button { display: flex; gap: 4px; align-items: flex-start; width: 100%; padding: 3px; background: transparent; border-color: transparent; }
.tg-sb-strip li[aria-current="true"] > button { border-color: var(--accent); background: var(--accent-soft); }
.tg-sb-num { font-size: 11px; color: var(--muted); min-width: 1.2em; }
.tg-sb-thumb { flex: 1; min-width: 0; display: block; pointer-events: none; }
.tg-sb-thumb .tg-sb-stage { display: block; }
.tg-sb-thumb .tg-sb-stage { box-shadow: 0 0 0 1px var(--rule); }
.tg-sb-main { flex: 1; min-width: 0; overflow: auto; padding: 8px 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.tg-sb-tools { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.tg-sb-sep { flex: 1; }
.tg-sb-boxtools { padding: 5px 6px; border-radius: 8px; background: var(--accent-soft); }
.tg-sb-boxname { font-weight: 600; margin-right: 4px; max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-sb-canvas { padding: 2px; }
.tg-sb-speaker { display: flex; flex-direction: column; gap: 3px; color: var(--muted); }
.tg-sb-speaker textarea { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; padding: 5px 7px; resize: vertical; }
.tg-sb-status { color: var(--muted); min-height: 1.2em; }
.tg-sb-unsaved { margin: .4em 0; padding: .4em .6em; border-left: 3px solid #c0392b; background: color-mix(in srgb, #c0392b 10%, transparent); }

/* the slide itself: white paper in every theme, as on a projector */
.tg-sb-stage {
  position: relative; aspect-ratio: 16 / 9; width: 100%; container-type: inline-size; overflow: hidden;
  background: #fff; color: #1b1d21; font-family: var(--tg-sb-font, "Latin Modern Roman", Georgia, serif); line-height: 1.3;
}
.tg-sb-edit { box-shadow: 0 1px 4px rgb(0 0 0 / .18), 0 0 0 1px var(--rule); border-radius: 3px; overflow: visible; }
.tg-sb-dropping .tg-sb-edit, .tg-sb-incoming .tg-sb-edit { box-shadow: 0 0 0 3px var(--accent); }
.tg-sb-box { position: absolute; box-sizing: border-box; font-size: calc(2.7cqw * var(--tg-sb-size, 1)); padding: .25em .4em; border-radius: .2em; }
.tg-sb-inner { width: 100%; height: 100%; overflow: hidden; }
.tg-sb-inner p { margin: 0 0 .45em; }
.tg-sb-inner p:last-child { margin-bottom: 0; }
.tg-sb-inner ul { margin: 0 0 .45em; padding-left: 1.2em; }
.tg-sb-inner .katex-display { margin: .3em 0; overflow: hidden; }
.tg-sb-title { margin: 0; font-size: 1.5em; font-weight: 600; line-height: 1.15; color: #23407a; }
.tg-sb-head { font-weight: 700; margin-bottom: .2em; }
.tg-sb-block { background: #eef2fa; border-top: .35em solid #3a5ba0; }
.tg-sb-block .tg-sb-head { color: #23407a; }
.tg-sb-cite { display: block; margin-top: .3em; font-size: .6em; color: #6b7280; }
.tg-sb-placeholder, .tg-sb-missing { color: #9aa0a8; font-style: italic; }
.tg-sb-empty { position: absolute; inset: 30% 10% auto; text-align: center; color: #8a9099; font: 13px/1.4 system-ui, sans-serif; margin: 0; }
.tg-sb-edit .tg-sb-box { cursor: move; touch-action: none; outline: 1px dashed transparent; }
.tg-sb-edit .tg-sb-box:hover { outline-color: #b9c3d6; }
.tg-sb-edit .tg-sb-box.tg-sb-picked, .tg-sb-edit .tg-sb-box:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 2; }
.tg-sb-edit .tg-sb-overflow { box-shadow: inset 0 -.5em .5em -.4em #d4483b; }
.tg-sb-handle { position: absolute; width: 10px; height: 10px; background: var(--accent); border: 1px solid #fff; border-radius: 2px; display: none; touch-action: none; }
.tg-sb-picked .tg-sb-handle { display: block; }
.tg-sb-handle[data-resize="se"] { right: -6px; bottom: -6px; cursor: nwse-resize; }
.tg-sb-handle[data-resize="e"] { right: -6px; top: calc(50% - 5px); cursor: ew-resize; }
.tg-sb-handle[data-resize="s"] { bottom: -6px; left: calc(50% - 5px); cursor: ns-resize; }
@media (pointer: coarse) { .tg-sb-handle { width: 18px; height: 18px; } .tg-sb-handle[data-resize="se"] { right: -10px; bottom: -10px; } }
.tg-sb-guide { position: absolute; pointer-events: none; z-index: 3; }
.tg-sb-guide-x { top: 0; bottom: 0; width: 0; border-left: 1px solid #e0457b; }
.tg-sb-guide-y { left: 0; right: 0; height: 0; border-top: 1px solid #e0457b; }
.tg-sb-guide[hidden] { display: none; }
.tg-sb-typing { cursor: auto !important; z-index: 4; background: #fff; overflow: visible; height: auto !important; min-height: var(--h); }
.tg-sb-typing .tg-sb-inner { overflow: visible; display: flex; flex-direction: column; gap: 4px; }
.tg-sb-typing textarea, .tg-sb-typing input { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; width: 100%; box-sizing: border-box; border: 1px solid #b9c3d6; border-radius: 4px; padding: 4px 6px; color: #1b1d21; background: #fff; }
.tg-sb-typing textarea { min-height: 7em; resize: vertical; }
.tg-sb-typing-bar { display: flex; gap: 6px; justify-content: flex-end; font-size: 12px; }

/* the handle by a paper block while the builder is open */
.tg-sb-grab { position: fixed; z-index: 30; font: 12px/1 system-ui, sans-serif; padding: 4px 7px; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--paper); color: var(--ink); cursor: grab; box-shadow: 0 2px 8px rgb(0 0 0 / .15); white-space: nowrap; }
.tg-sb-grab[hidden] { display: none; }

/* presenting */
.tg-sb-show { position: fixed; inset: 0; z-index: 1000; background: #111; display: flex; flex-direction: column; outline: none; }
.tg-sb-show[hidden] { display: none; }
.tg-sb-show-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.tg-sb-big { width: 100%; flex: none; }
.tg-sb-show-notes-panel { max-height: 30vh; overflow: auto; padding: 10px 18px; background: #1d1f24; color: #e8e8e8; font: 16px/1.45 system-ui, sans-serif; }
.tg-sb-show-notes-panel[hidden] { display: none; }
.tg-sb-show-bar { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 6px; color: #ccc; font: 13px system-ui, sans-serif; opacity: .35; transition: opacity .2s; }
.tg-sb-show-bar:hover, .tg-sb-show-bar:focus-within { opacity: 1; }
.tg-sb-show-bar button { font: inherit; background: #2a2d33; color: #eee; border: 1px solid #444; border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.tg-sb-show-bar button:disabled { opacity: .4; }

/* a phone: the builder is a sheet over the lower part of the screen */
@media (max-width: 760px) {
  .tg-sb { position: fixed; left: 0; right: 0; bottom: 0; height: 62vh; z-index: 26; border-left: 0; border-top: 1px solid var(--rule); box-shadow: 0 -6px 24px rgb(0 0 0 / .16); }
  .tg-sb-resizer { display: none; }
  .tg-sb-work { flex-direction: column; }
  .tg-sb-strip { flex: 0 0 auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--rule); overflow-x: auto; padding: 6px 8px; }
  .tg-sb-strip li { flex: 0 0 96px; }
  body.tg-sb-open .preview-pane { padding-bottom: 62vh; }
}

.tg-sb-strip li.tg-sb-target > button { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.tg-sb-speaker-refs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tg-sb-speaker-refs li { display: flex; gap: 6px; align-items: flex-start; padding: 6px 8px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); }
.tg-sb-speaker-copy { flex: 1; min-width: 0; font-family: var(--tg-sb-font, inherit); }
.tg-sb-speaker-copy p { display: inline; margin: 0; }
