/* ============================================================
   Teo's Research Notebook - minimal theme
   System fonts, generous whitespace, automatic dark mode.
   ============================================================ */

:root {
  --font: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --faint: #e6e8eb;
  --accent: #0f766e;
  --code-bg: #f5f6f7;
  --measure: 680px;
  color-scheme: light;
}

/* Dark palette is applied two ways:
   1. by OS preference, but only while the reader has not chosen a theme;
   2. explicitly, when the reader toggles to dark (data-theme overrides the OS). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #121417;
    --text: #d7dde3;
    --muted: #8b97a3;
    --faint: #262b31;
    --accent: #5eead4;
    --code-bg: #1a1e23;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121417;
  --text: #d7dde3;
  --muted: #8b97a3;
  --faint: #262b31;
  --accent: #5eead4;
  --code-bg: #1a1e23;
  color-scheme: dark;
}

/* ---------- Reset / base ---------- */

html {
  -webkit-text-size-adjust: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 19px;
  line-height: 1.7;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrapper {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s ease, color 0.15s ease;
}

a:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

hr {
  border: 0;
  border-top: 1px solid var(--faint);
  margin: 2.5rem 0;
}

strong {
  font-weight: 600;
}

/* ---------- Accessibility ---------- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 10;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  padding: 0.55rem 0.9rem;
  border-radius: 0 0 5px 0;
  text-decoration: none;
}

.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Header ---------- */

.site-header {
  background: none;
  border: 0;
  border-top: 0;
  min-height: 0;
  line-height: normal;
}

.site-header__inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  padding: 2rem 20px 0;
}

.site-title {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  float: none;
}

.site-title:hover {
  color: var(--accent);
}

.site-nav {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  float: none;
  position: static;
  background: none;
  border: 0;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--accent);
}

.site-nav a[aria-current="page"],
.site-title[aria-current="page"] {
  color: var(--text);
}

.site-nav a[aria-current="page"] {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 4px;
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  margin-left: -0.2rem;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--faint);
}

.theme-toggle svg {
  display: block;
}

/* Show the icon for the theme you'd switch TO. Scoped under .theme-toggle so
   these win over `.theme-toggle svg { display: block }` above (specificity). */
.theme-toggle .theme-toggle__sun { display: none; }
.theme-toggle .theme-toggle__moon { display: block; }

:root[data-theme="dark"] .theme-toggle__sun { display: block; }
:root[data-theme="dark"] .theme-toggle__moon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle__sun { display: block; }
  :root:not([data-theme]) .theme-toggle__moon { display: none; }
}

/* ---------- Reading progress ---------- */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  z-index: 20;
  background: transparent;
  pointer-events: none;
}

.reading-progress__bar {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}

/* ---------- Page scaffolding ---------- */

.page-content {
  padding: 3rem 0 4rem;
}

/* ---------- Home ---------- */

.home-intro {
  font-size: 1.05rem;
  color: var(--muted);
  margin: 0 0 1.75rem;
  max-width: 48ch;
}

.archive-tools {
  margin: 0 0 1.3rem;
}

.searchbar {
  position: relative;
  margin: 0 0 0.8rem;
}

.searchbar__icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}

.searchbar__input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--faint);
  border-radius: 8px;
  padding: 0.62rem 2.6rem 0.62rem 2.3rem;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s ease;
}

.searchbar__input::placeholder {
  color: var(--muted);
}

.searchbar__input:focus {
  outline: none;
  border-color: var(--accent);
}

.searchbar__kbd {
  position: absolute;
  right: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--faint);
  border-radius: 4px;
  padding: 0.04rem 0.36rem;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.searchbar__input:focus ~ .searchbar__kbd,
.searchbar.has-query .searchbar__kbd {
  opacity: 0;
}

@media (max-width: 540px) {
  .searchbar__kbd {
    display: none;
  }
  .searchbar__input {
    padding-right: 0.9rem;
  }
}

.viewbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
  font-family: var(--font-ui);
}

.archive-view {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 0.36rem 0.48rem;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.archive-view:hover {
  color: var(--text);
  background: var(--code-bg);
}

.archive-view.is-active {
  color: var(--text);
  background: var(--code-bg);
}

.archive-view__count {
  font-size: 0.74rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chipbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.38rem;
  margin: 0;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  scrollbar-width: none;
}

.chipbar::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 1px solid var(--faint);
  border-radius: 999px;
  padding: 0.34rem 0.62rem;
  cursor: pointer;
  flex: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.chip:hover {
  color: var(--text);
  border-color: var(--muted);
}

.chip.is-active {
  color: var(--bg);
  background: var(--text);
  border-color: var(--text);
}

.chip__dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex: none;
}

.chip__count {
  font-variant-numeric: tabular-nums;
  font-size: 0.74rem;
  opacity: 0.65;
}

.chip.is-active .chip__count {
  opacity: 0.85;
}

.postlist__status {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 0.65rem;
  font-variant-numeric: tabular-nums;
}

.archive-panel {
  margin: 0;
}

.postlist {
  list-style: none;
  margin: 0 -0.7rem;
  padding: 0;
  border-top: 1px solid var(--faint);
}

.postlist__item {
  margin: 0;
  border-bottom: 1px solid var(--faint);
}

.postlist__item:first-child .postlist__link {
  padding-top: 0.95rem;
}

.postlist__link {
  display: block;
  padding: 0.95rem 0.7rem;
  text-decoration: none;
  border-radius: 6px;
}

.postlist__link:hover {
  background: var(--code-bg);
}

.postlist__meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  margin-bottom: 0.3rem;
}

.postlist__cat {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 0;
}

.postlist__badge {
  display: inline-flex;
  align-items: center;
  flex: none;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  line-height: 1;
  color: var(--muted);
  border: 1px solid var(--faint);
  border-radius: 999px;
  padding: 0.18rem 0.42rem;
}

.postlist__dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex: none;
}

.postlist__title {
  display: block;
  font-size: 1.12rem;
  line-height: 1.35;
  color: var(--text);
}

.postlist__link:hover .postlist__title {
  color: var(--accent);
}

.postlist__desc {
  display: block;
  margin-top: 0.28rem;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--muted);
}

.postlist__empty {
  font-family: var(--font-ui);
  color: var(--muted);
  padding: 1.4rem 0.7rem;
  margin: 0;
}

.archive-group {
  border-top: 1px solid var(--faint);
  padding: 1rem 0 1.05rem;
}

.archive-group:last-child {
  border-bottom: 1px solid var(--faint);
}

.archive-group__h {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
  margin: 0 0 0.35rem;
  color: var(--text);
}

.archive-group__h a {
  color: var(--text);
  text-decoration: none;
}

.archive-group__h a:hover {
  color: var(--accent);
}

.archive-group__count {
  font-size: 0.74rem;
  font-weight: 400;
  color: var(--muted);
  margin-left: 0.05rem;
  font-variant-numeric: tabular-nums;
}

.archive-group__desc {
  font-family: var(--font-ui);
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 0 0 0.55rem;
  max-width: 58ch;
}

.compact-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.08rem;
}

.compact-list--numbered {
  counter-reset: compact;
}

.compact-list--numbered .compact-list__item {
  counter-increment: compact;
  position: relative;
  padding-left: 1.55rem;
}

.compact-list--numbered .compact-list__item::before {
  content: counter(compact);
  position: absolute;
  left: 0;
  top: 0.34rem;
  width: 1rem;
  text-align: right;
  font-family: var(--font-ui);
  font-size: 0.74rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.compact-list__link {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  max-width: 100%;
  padding: 0.18rem 0;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--text);
  text-decoration: none;
}

.compact-list__link:hover {
  color: var(--accent);
}

/* ---------- Post ---------- */

.post-header {
  text-align: left;
  border-bottom: 0;
  padding-bottom: 0;
  margin-bottom: 2.5rem;
}

.post-cat {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 0.7rem;
}

.post-cat:hover {
  color: var(--accent);
}

.post-cat__dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex: none;
}

.post-title {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.015em;
  margin: 0 0 0.6rem;
  color: var(--text);
}

.post-meta {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.post-content {
  font-size: 1.125rem;
  line-height: 1.75;
}

.post-content > p,
.post-content > ul,
.post-content > ol {
  margin: 0 0 1.4rem;
}

.post-content h2,
.post-content h3,
.post-content h4 {
  line-height: 1.3;
  margin: 2.4rem 0 0.8rem;
  scroll-margin-top: 1.5rem;
}

.post-content h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

.post-content h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.post-content h4 {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--muted);
}

/* Minima hardcodes h1..h6 to #111, which disappears in dark mode.
   Re-anchor every heading to the theme's text colour (h4 and .topics__h
   keep their muted colour, set above/below). */
.post-content h1,
.post-content h2,
.post-content h3,
.post-content h5,
.post-content h6,
.page .post-title,
.post-list-heading,
.topics__group-title,
.notfound__code {
  color: var(--text);
}

.post-content a {
  text-decoration-color: var(--muted);
}

/* External links get a small outbound arrow. inline-block keeps the parent's
   underline from being drawn across the glyph. */
.post-content a.external-link::after {
  content: "\2197";
  display: inline-block;
  margin-left: 0.12em;
  font-size: 0.72em;
  line-height: 1;
  color: var(--muted);
  vertical-align: baseline;
}

.post-content a.external-link:hover::after {
  color: var(--accent);
}

.post-content li {
  margin-bottom: 0.35rem;
}

.post-content blockquote {
  margin: 1.8rem 0;
  padding-left: 1.1rem;
  border-left: 2px solid var(--faint);
  color: var(--muted);
  font-style: normal;
}

.post-content blockquote > :last-child {
  margin-bottom: 0;
}

.post-content img {
  max-width: 100%;
  height: auto;
}

.post-content table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  margin: 1.6rem 0;
}

.post-content th,
.post-content td {
  border-bottom: 1px solid var(--faint);
  padding: 0.5rem 0.6rem;
  text-align: left;
}

.post-content th {
  font-weight: 600;
}

/* ---------- Typography niceties ---------- */

.post-title,
.post-content h2,
.post-content h3,
.post-content h4,
.postlist__title {
  text-wrap: balance;
}

.post-content p,
.home-intro {
  text-wrap: pretty;
}

/* ---------- Code ---------- */

.post-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--text);
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.12em 0.34em;
}

.post-content pre,
.highlight,
.highlighter-rouge .highlight {
  background: var(--code-bg);
  border: 0;
  border-radius: 6px;
}

.post-content pre {
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
}

.post-content pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* Copy-to-clipboard button injected over each code block. */
.codeblock {
  position: relative;
}

.code-copy {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--faint);
  border-radius: 5px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.codeblock:hover .code-copy,
.code-copy:focus-visible {
  opacity: 1;
}

.code-copy:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.code-copy.is-copied {
  color: var(--accent);
  border-color: var(--accent);
}

/* Touch devices have no hover — keep the button discoverable. */
@media (hover: none) {
  .code-copy {
    opacity: 0.65;
  }
}

/* Language label, shown only for non-plaintext blocks (see notebook.js). */
.code-lang {
  position: absolute;
  top: 0.55rem;
  left: 0.7rem;
  z-index: 1;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
}

/* Make room for the label so it never sits on the first line of code. */
.codeblock.has-lang pre {
  padding-top: 2.2rem;
}

/* Minima's Rouge syntax palette is tuned for light backgrounds — several
   tokens (identifiers at #111, dark blues/reds) vanish on a dark surface.
   In dark mode fall back to a clean, always-legible rendering: text colour
   for code, muted comments, accent keywords. Light mode keeps minima's
   palette untouched. */
:root[data-theme="dark"] .highlight,
:root[data-theme="dark"] .highlight :not(.c):not(.c1):not(.cm):not(.cs):not(.cp):not(.cd):not(.k):not(.kc):not(.kd):not(.kn):not(.kp):not(.kr):not(.kt):not(.s):not(.s1):not(.s2):not(.sb):not(.sc):not(.sd):not(.se):not(.sh):not(.si):not(.sx):not(.sr):not(.ss):not(.dl) {
  color: var(--text);
  background: none;
}
:root[data-theme="dark"] .highlight .c,
:root[data-theme="dark"] .highlight .c1,
:root[data-theme="dark"] .highlight .cm,
:root[data-theme="dark"] .highlight .cs,
:root[data-theme="dark"] .highlight .cp,
:root[data-theme="dark"] .highlight .cd {
  color: var(--muted);
  font-style: italic;
}
:root[data-theme="dark"] .highlight .k,
:root[data-theme="dark"] .highlight .kc,
:root[data-theme="dark"] .highlight .kd,
:root[data-theme="dark"] .highlight .kn,
:root[data-theme="dark"] .highlight .kp,
:root[data-theme="dark"] .highlight .kr,
:root[data-theme="dark"] .highlight .kt {
  color: var(--accent);
}
:root[data-theme="dark"] .highlight .s,
:root[data-theme="dark"] .highlight .s1,
:root[data-theme="dark"] .highlight .s2,
:root[data-theme="dark"] .highlight .sb,
:root[data-theme="dark"] .highlight .sc,
:root[data-theme="dark"] .highlight .sd,
:root[data-theme="dark"] .highlight .se,
:root[data-theme="dark"] .highlight .sh,
:root[data-theme="dark"] .highlight .si,
:root[data-theme="dark"] .highlight .sx,
:root[data-theme="dark"] .highlight .sr,
:root[data-theme="dark"] .highlight .ss,
:root[data-theme="dark"] .highlight .dl {
  color: #9ecb8a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .highlight,
  :root:not([data-theme]) .highlight :not(.c):not(.c1):not(.cm):not(.cs):not(.cp):not(.cd):not(.k):not(.kc):not(.kd):not(.kn):not(.kp):not(.kr):not(.kt):not(.s):not(.s1):not(.s2):not(.sb):not(.sc):not(.sd):not(.se):not(.sh):not(.si):not(.sx):not(.sr):not(.ss):not(.dl) {
    color: var(--text);
    background: none;
  }
  :root:not([data-theme]) .highlight .c,
  :root:not([data-theme]) .highlight .c1,
  :root:not([data-theme]) .highlight .cm,
  :root:not([data-theme]) .highlight .cs,
  :root:not([data-theme]) .highlight .cp,
  :root:not([data-theme]) .highlight .cd {
    color: var(--muted);
    font-style: italic;
  }
  :root:not([data-theme]) .highlight .k,
  :root:not([data-theme]) .highlight .kc,
  :root:not([data-theme]) .highlight .kd,
  :root:not([data-theme]) .highlight .kn,
  :root:not([data-theme]) .highlight .kp,
  :root:not([data-theme]) .highlight .kr,
  :root:not([data-theme]) .highlight .kt {
    color: var(--accent);
  }
  :root:not([data-theme]) .highlight .s,
  :root:not([data-theme]) .highlight .s1,
  :root:not([data-theme]) .highlight .s2,
  :root:not([data-theme]) .highlight .sb,
  :root:not([data-theme]) .highlight .sc,
  :root:not([data-theme]) .highlight .sd,
  :root:not([data-theme]) .highlight .se,
  :root:not([data-theme]) .highlight .sh,
  :root:not([data-theme]) .highlight .si,
  :root:not([data-theme]) .highlight .sx,
  :root:not([data-theme]) .highlight .sr,
  :root:not([data-theme]) .highlight .ss,
  :root:not([data-theme]) .highlight .dl {
    color: #9ecba8;
  }
}

/* ---------- Table of contents ---------- */

.post-toc {
  font-family: var(--font-ui);
  margin: 0 0 2.2rem;
  border: 1px solid var(--faint);
  border-radius: 8px;
  padding: 0.2rem 0.9rem;
}

.post-toc__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  background: none;
  border: 0;
  padding: 0.55rem 0;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.post-toc__chevron {
  width: 0.5rem;
  height: 0.5rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.post-toc[data-collapsed="true"] .post-toc__chevron {
  transform: rotate(-45deg);
}

.post-toc[data-collapsed="true"] .post-toc__list {
  display: none;
}

.post-toc__list {
  list-style: none;
  margin: 0.2rem 0 0.6rem;
  padding: 0;
  display: grid;
  gap: 0.1rem;
}

.post-toc__list a {
  display: block;
  font-size: 0.86rem;
  line-height: 1.4;
  color: var(--muted);
  text-decoration: none;
  padding: 0.2rem 0;
}

.post-toc__list a:hover {
  color: var(--accent);
}

.post-toc__list a[aria-current="true"] {
  color: var(--text);
}

@media (min-width: 1200px) {
  .post-toc {
    position: fixed;
    top: 7rem;
    left: calc(50% - 552px);
    width: 188px;
    max-height: calc(100vh - 10rem);
    overflow-y: auto;
    margin: 0;
    padding: 0 0 0 1rem;
    border: 0;
    border-left: 1px solid var(--faint);
  }

  .post-toc__toggle {
    cursor: default;
    pointer-events: none;
    padding: 0 0 0.4rem;
  }

  .post-toc__chevron {
    display: none;
  }

  .post-toc[data-collapsed="true"] .post-toc__list {
    display: grid;
  }

  .post-toc__list a[aria-current="true"] {
    color: var(--text);
    font-weight: 600;
  }
}

/* ---------- Series box ---------- */

.series {
  font-family: var(--font-ui);
  margin: 0 0 2.2rem;
  border: 1px solid var(--faint);
  border-radius: 8px;
  padding: 0.9rem 1.1rem 1rem;
}

.series__head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.2rem 0.6rem;
  margin-bottom: 0.75rem;
}

.series__eyebrow {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.series__title {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.series__title:hover {
  color: var(--accent);
}

.series__part {
  margin-left: auto;
  flex: none;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.series__list {
  counter-reset: series;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.28rem;
}

.series__item {
  counter-increment: series;
  position: relative;
  padding-left: 1.7rem;
  line-height: 1.4;
}

.series__item::before {
  content: counter(series);
  position: absolute;
  left: 0;
  top: 0.02em;
  width: 1.15rem;
  text-align: right;
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.series__item a {
  font-size: 0.9rem;
  color: var(--muted);
  text-decoration: none;
}

.series__item a:hover {
  color: var(--accent);
}

.series__item.is-current span {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.series__item.is-current::before {
  color: var(--accent);
  font-weight: 600;
}

.series-next {
  margin: 2.5rem 0 0;
  padding-top: 1.4rem;
  border-top: 1px solid var(--faint);
}

.series-next__links {
  display: grid;
  gap: 0.7rem;
}

.series-next__link {
  display: grid;
  gap: 0.12rem;
  font-family: var(--font-ui);
  text-decoration: none;
}

.series-next__dir {
  font-size: 0.74rem;
  color: var(--muted);
}

.series-next__title {
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--text);
}

.series-next__link:hover .series-next__title {
  color: var(--accent);
}

/* ---------- Post tags ---------- */

.post-tags {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 2.6rem 0 0;
  padding: 0;
}

.post-tag {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--faint);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.post-tag::before {
  content: "#";
  opacity: 0.5;
  margin-right: 0.08rem;
}

.post-tag:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---------- Post nav ---------- */

.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: 3rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--faint);
  font-family: var(--font-ui);
}

.post-nav__link {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 47%;
  text-decoration: none;
}

.post-nav__next {
  margin-left: auto;
  text-align: right;
}

.post-nav__dir {
  font-size: 0.78rem;
  color: var(--muted);
}

.post-nav__name {
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--text);
}

.post-nav__link:hover .post-nav__name {
  color: var(--accent);
}

.post-nav__home {
  margin: 1.1rem 0 0;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

.post-nav__home a {
  color: var(--muted);
  text-decoration: none;
}

.post-nav__home a:hover {
  color: var(--accent);
}

/* ---------- Footnotes ---------- */

.footnotes {
  font-family: var(--font-ui);
  font-size: 0.88rem;
  color: var(--muted);
  border-top: 1px solid var(--faint);
  margin-top: 3rem;
  padding-top: 1.2rem;
  line-height: 1.6;
}

.footnotes ol {
  padding-left: 1.2rem;
}

.footnotes li {
  margin-bottom: 0.4rem;
}

a.footnote,
a[role="doc-noteref"] {
  text-decoration: none;
  font-size: 0.8em;
  padding: 0 0.12em;
}

/* ---------- Heading anchors ---------- */

.post-content h2,
.post-content h3 {
  position: relative;
}

.heading-anchor {
  position: absolute;
  top: 0;
  right: 100%;
  width: 1.4rem;
  margin-right: 0.1rem;
  font-family: var(--font-ui);
  font-weight: 400;
  color: var(--muted);
  text-decoration: none;
  text-align: center;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.heading-anchor:hover {
  color: var(--accent);
}

.post-content h2:hover .heading-anchor,
.post-content h3:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}

/* On narrow screens there is no room in the left margin, so the anchor
   drops inline after the heading text at low emphasis (no hover to reveal it). */
@media (max-width: 820px) {
  .heading-anchor {
    position: static;
    width: auto;
    margin: 0 0 0 0.35em;
    opacity: 0.4;
    font-size: 0.78em;
    vertical-align: middle;
  }
}

/* ---------- Math ---------- */

mjx-container[display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 0.3rem 0;
}

mjx-container {
  color: var(--text);
}

/* ---------- Callout + figures + interactive labs ---------- */

.callout {
  border-left: 2px solid var(--accent);
  padding: 0.2rem 0 0.2rem 1.1rem;
  margin: 1.9rem 0;
  font-family: var(--font-ui);
  font-size: 0.96rem;
  line-height: 1.6;
  color: var(--muted);
}

.callout strong {
  color: var(--text);
}

.callout > :last-child {
  margin-bottom: 0;
}

.research-figure,
[class$="-lab"] {
  border: 1px solid var(--faint);
  border-radius: 6px;
  margin: 2rem 0;
  padding: 1.2rem;
}

/* Eyebrow that signals a lab is meant to be touched, not just read. Generated
   on the container itself so it is immune to whatever a lab script does to its
   own children (some rebuild innerHTML on init). */
[class$="-lab"]::before {
  content: "Interactive";
  display: block;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.95rem;
}

.research-figure svg,
.research-figure canvas,
[class$="-lab"] canvas {
  display: block;
  max-width: 100%;
}

[class$="-lab"] canvas {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--faint);
  border-radius: 4px;
}

.research-figure figcaption,
[class$="-lab__note"] {
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  line-height: 1.55;
  margin-top: 0.85rem;
}

[class$="-lab__controls"] {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 1.1rem;
}

[class$="-lab"] label {
  display: grid;
  gap: 0.35rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--muted);
}

[class$="-lab"] input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
}

[class$="-lab"] select,
[class$="-lab"] input[type="number"] {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--faint);
  border-radius: 4px;
  padding: 0.3rem 0.45rem;
}

[class$="-lab__metrics"] {
  display: grid;
  gap: 0.6rem 1.4rem;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  margin: 1.1rem 0;
}

[class$="-lab__metric"] span {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

[class$="-lab__metric"] strong {
  display: block;
  font-family: var(--font-ui);
  font-size: 1.3rem;
  font-weight: 700;
  margin-top: 0.15rem;
}

[class$="-lab__legend"] {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-top: 0.85rem;
}

[class$="-lab__legend"] span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-ui);
  font-size: 0.83rem;
  color: var(--muted);
}

[class$="-lab__legend"] i {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 999px;
}

[class$="-lab"] button {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--bg);
  background: var(--accent);
  border: 0;
  border-radius: 5px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--faint);
  margin-top: 4rem;
  padding: 2.2rem 0 2.6rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--muted);
}

.site-footer__inner {
  display: grid;
  grid-template-columns: 1.7fr 1fr 1fr;
  gap: 1.4rem 2rem;
}

.site-footer__title {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.site-footer__tagline {
  margin: 0.5rem 0 0;
  max-width: 34ch;
  line-height: 1.5;
}

.site-footer__col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
}

.site-footer__h {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 0.15rem;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover,
.site-footer__title:hover {
  color: var(--accent);
}

.site-footer__base {
  margin-top: 1.9rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--faint);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 600px) {
  .site-footer__inner {
    grid-template-columns: 1fr 1fr;
  }

  .site-footer__brand {
    grid-column: 1 / -1;
  }
}

/* ---------- Page (About etc.) ---------- */

.page .post-title,
.post-list-heading {
  font-size: 1.7rem;
}

/* ---------- Topics index ---------- */

.topics__intro {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.topics__nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin: 0 0 2rem;
  font-family: var(--font-ui);
  font-size: 0.86rem;
}

.topics__nav a {
  color: var(--muted);
  text-decoration: none;
}

.topics__nav a:hover {
  color: var(--accent);
}

.topics__h {
  font-family: var(--font-ui);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2.6rem 0 1.2rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--faint);
  scroll-margin-top: 1.5rem;
}

.topics__group {
  margin: 0 0 1.7rem;
  scroll-margin-top: 1.5rem;
}

.topics__group-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 0.5rem;
}

.topics__count {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
  margin-left: 0.15rem;
}

.topics__blurb {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0 0 0.6rem;
  max-width: 60ch;
}

.topics__serieslist {
  counter-reset: tseries;
  list-style: none;
  margin: 0;
  padding: 0;
}

.topics__serieslist li {
  counter-increment: tseries;
  position: relative;
  padding-left: 1.7rem;
}

.topics__serieslist li::before {
  content: counter(tseries);
  position: absolute;
  left: 0;
  top: 0.22rem;
  width: 1.15rem;
  text-align: right;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.topics__serieslist a {
  display: inline-block;
  padding: 0.22rem 0;
  text-decoration: none;
  text-decoration-color: var(--faint);
}

.topics__serieslist a:hover {
  color: var(--accent);
}

.topics__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.topics__list li {
  margin: 0;
}

.topics__list a {
  display: inline-block;
  padding: 0.22rem 0;
  text-decoration: none;
  text-decoration-color: var(--faint);
}

.topics__list a:hover {
  color: var(--accent);
}

.topics__taglist {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 2.2rem;
}

.topics__tagchip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--faint);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.topics__tagchip:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.topics__tagchip .topics__count {
  margin-left: 0;
}

/* ---------- 404 ---------- */

.notfound {
  text-align: center;
  padding: 3rem 0 4rem;
}

.notfound__code {
  font-size: 4rem;
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 0 0 0.6rem;
}

.notfound__msg {
  color: var(--muted);
  margin: 0 0 1.4rem;
}

.notfound a {
  font-family: var(--font-ui);
  text-decoration: none;
  color: var(--accent);
}

/* ---------- Related posts ---------- */

.related {
  margin: 3rem 0 0;
  padding-top: 1.4rem;
  border-top: 1px solid var(--faint);
}

.related__h {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.85rem;
}

.related__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.related__link {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--text);
  text-decoration: none;
}

.related__link:hover {
  color: var(--accent);
}

.related__dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex: none;
  position: relative;
  top: 0.05em;
}

/* ---------- Back to top ---------- */

.to-top {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--faint);
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(0.5rem);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease,
    color 0.15s ease, border-color 0.15s ease;
}

.to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.to-top:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.to-top svg {
  display: block;
}

/* ---------- Cross-document view transitions ---------- */

@view-transition {
  navigation: auto;
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

/* ---------- Print ---------- */

@media print {
  .reading-progress,
  .site-nav,
  .theme-toggle,
  .post-toc,
  .to-top,
  .searchbar,
  .viewbar,
  .chipbar,
  .code-copy,
  .skip-link,
  .post-nav,
  .series-next,
  .related,
  [class$="-lab__controls"] {
    display: none !important;
  }

  :root {
    --bg: #ffffff;
    --text: #000000;
    --muted: #444444;
    --faint: #cccccc;
    --accent: #000000;
    color-scheme: light;
  }

  body {
    font-size: 11pt;
    line-height: 1.5;
  }

  .wrapper {
    max-width: none;
    padding: 0;
  }

  .page-content {
    padding: 0;
  }

  a {
    color: #000;
  }

  /* Surface the destination of content links when on paper. */
  .post-content a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.82em;
    color: #555;
    word-break: break-all;
  }

  pre,
  blockquote,
  table,
  .research-figure,
  [class$="-lab"] {
    page-break-inside: avoid;
  }

  .site-footer {
    border: 0;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 540px) {
  body {
    font-size: 18px;
  }

  .chipbar {
    margin: 0 -20px;
    padding: 0 20px 0.15rem;
  }

  .compact-list__link {
    align-items: flex-start;
  }

  .post-title {
    font-size: 1.65rem;
  }

  .post-nav {
    flex-direction: column;
    gap: 1.2rem;
  }

  .post-nav__link,
  .post-nav__next {
    max-width: 100%;
    margin-left: 0;
    text-align: left;
  }
}
