.reader {
  --reader-gap: clamp(28px, 4vw, 54px);
  --reader-side: clamp(180px, 19vw, 215px);
  margin-block: 24px 48px;
}

/* Shared by article bodies and the admin preview; KaTeX assets stay optional. */
.markdown .blog-math {
  display: inline-block;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  vertical-align: middle;
  padding-block: .15em;
}
.markdown .blog-math-display { display: block; margin-block: 1em; padding-block: .3em; }
.markdown .blog-math-display > .katex-display { min-width: max-content; margin: 0; }
.markdown .blog-math-display:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.reader .reader-header {
  max-width: 770px;
  padding-bottom: 38px;
}
.reader .reader-back {
  display: inline-flex;
  align-items: center;
  align-self: start;
  gap: 6px;
  min-height: 44px;
  padding: 3px 0;
  border-radius: 3px;
  color: var(--accent);
  font-size: 13px;
}
.reader .reader-back:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: .25em; }
.reader .reader-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin: 25px 0 12px;
  color: var(--muted);
  font-size: 13px;
}
.reader .reader-meta[data-category="技术"] .type-chip { background: var(--accent-soft); color: var(--accent-on-soft); }
.reader .reader-meta time { font: 12px var(--mono); }
.reader .article-title {
  font-size: clamp(30px, 3vw, 40px);
  line-height: 1.37;
  font-weight: 560;
  letter-spacing: -.025em;
  text-wrap: balance;
}
.reader .reader-intro {
  max-width: 37em;
  text-wrap: balance;
  margin-top: 13px;
  color: var(--reader-prose);
  font: 17px/1.85 var(--serif);
}

.reader .reader-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--reader-side);
  column-gap: var(--reader-gap);
  align-items: start;
}
.reader .reader-grid[data-toc="false"] { grid-template-columns: minmax(0, 1fr); max-width: 770px; }
.reader .reader-body { grid-area: 1 / 1; min-width: 0; padding-bottom: 62vh; }
.reader .reader-section + .reader-section { margin-top: 42px; }
.reader .reader-section h2 {
  display: flex;
  align-items: baseline;
  gap: 11px;
  margin: 0 0 16px;
  font-size: clamp(21px, 2vw, 25px);
  font-weight: 550;
  letter-spacing: -.018em;
  line-height: 1.55;
  scroll-margin-top: 28px;
  text-wrap: balance;
}
.reader .section-index {
  flex: none;
  color: var(--muted);
  font: 13px/1.5 var(--mono);
}
.reader .reader-section { scroll-margin-top: 28px; }
.reader .reader-section p {
  font-size: 17px;
  line-height: 1.92;
  color: var(--reader-prose);
  overflow-wrap: anywhere;
}
.reader .reader-section p + p { margin-top: 15px; }
.reader .reader-section h2:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
  border-radius: 5px;
}
.reader .reader-body > .reader-back,
.reader > .reader-back { margin-top: 38px; }

.reader-neighbors {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 42px 0 0;
}
.reader-neighbors a { padding: 17px; background: var(--surface); border-radius: 12px; }
.reader-neighbors a:only-child { grid-column: 1 / -1; }
.reader-neighbors a:hover { background: var(--surface-hover); }
.reader-neighbors span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.reader-neighbors strong { font-size: 14px; font-weight: 550; line-height: 1.8; color: var(--reader-prose); }
.reader-neighbors a:hover strong { color: var(--accent); }

.reader-related { margin-top: 42px; }
.reader .reader-related h2 { font-size: 21px; }
.reader-related ul { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.reader-related a { display: block; padding: 17px; border-radius: 12px; background: var(--surface); overflow-wrap: anywhere; }
.reader-related a:hover { background: var(--surface-hover); }
.reader-related strong { color: var(--reader-prose); font-size: 14px; line-height: 1.8; font-weight: 550; }
.reader-related a:hover strong { color: var(--accent); }
.reader-related time { display: block; margin-top: 6px; color: var(--muted); font: 12px var(--mono); }
.reader .reader-related p { margin-top: 8px; color: var(--muted); font-size: 14px; line-height: 1.8; }

.reader-comments { margin-top: 42px; min-height: 160px; }
.reader-comments h2 { margin-bottom: 20px; font-size: 21px; font-weight: 550; }

html[data-reader-lightbox="open"], html[data-reader-lightbox="open"] body { overflow: hidden; }
.reader .markdown img { max-width: 100%; height: auto; }
.reader .markdown img[role="button"] { cursor: zoom-in; }
.reader .markdown img[role="button"]:focus-visible { outline-offset: -3px; }
.reader-lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: clamp(8px, 3vw, 24px);
  border: 0;
  background: var(--backdrop);
  color: var(--ink);
  overscroll-behavior: contain;
}
.reader-lightbox[open] { display: flex; align-items: center; justify-content: center; }
.reader-lightbox::backdrop { background: transparent; }
.reader-lightbox-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: max-content;
  min-width: 0;
  max-width: min(1200px, 100%);
  max-height: 100%;
  margin: 0;
  padding: 16px;
  border-radius: 12px;
  background: var(--page);
  box-shadow: var(--popover-shadow);
  overflow: auto;
}
.reader-lightbox-panel img { display: block; align-self: center; flex-shrink: 0; max-width: 100%; max-height: 70dvh; width: auto; height: auto; object-fit: contain; }
.reader-lightbox-panel figcaption { color: var(--reader-prose); font-size: 14px; overflow-wrap: anywhere; }
.reader-lightbox-close { align-self: end; flex-shrink: 0; padding: 6px 14px; border-radius: 7px; background: var(--surface); }
.reader-lightbox-close:hover { background: var(--surface-hover); }
@media (prefers-reduced-motion: no-preference) {
  .reader-lightbox[open] .reader-lightbox-panel { animation: reader-lightbox-in .12s ease-out; }
}
@keyframes reader-lightbox-in { from { opacity: 0; } to { opacity: 1; } }

.reader .reader-toc {
  grid-area: 1 / 2;
  position: sticky;
  top: 28px;
  min-width: 0;
}
.reader .toc-panel {
  max-height: calc(100dvh - 60px);
  overflow: auto;
  overscroll-behavior: contain;
}
.reader .toc-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 49px;
  padding: 10px 8px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.reader .toc-summary::-webkit-details-marker { display: none; }
.reader .toc-summary::after {
  content: "";
  width: 6px;
  height: 6px;
  flex: none;
  margin: -3px 2px 0 2px;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.reader .toc-panel[open] .toc-summary::after { margin-top: 3px; transform: rotate(225deg); }
.reader .toc-summary:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: 12px; }
.reader .toc-name { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 600; }
.reader .toc-name svg, .reader .code-name svg, .reader .code-copy svg { width: 15px; height: 15px; flex: none; }
.reader .toc-count { margin-left: auto; font-size: 11px; color: var(--muted); }
.reader .toc-list { margin: 0; padding: 0 0 3px; list-style: none; }
.reader .toc-list li + li { margin-top: 2px; }
.reader .toc-subheading .toc-link { padding-left: 20px; }
.reader .toc-link {
  display: grid;
  grid-template-columns: 17px minmax(0, 1fr);
  align-items: baseline;
  gap: 7px;
  padding: 8px;
  border-radius: 8px;
  color: var(--reader-prose);
  font-size: 13px;
  line-height: 1.65;
  min-height: 44px;
}
.reader .toc-index { font: 11px var(--mono); color: var(--muted); }
.reader .toc-link:hover { color: var(--accent-hover); background: var(--surface); }
.reader .toc-link[aria-current="location"] { background: var(--accent-soft); color: var(--accent-on-soft); font-weight: 600; }
.reader .toc-link[aria-current="location"] .toc-index { color: inherit; font-weight: 600; }
.reader .toc-link:focus-visible { outline-offset: -2px; }

.reader .code-block {
  margin: 22px 0;
  min-width: 0;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 14px;
}
.reader .code-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 14px 19px 4px;
  color: var(--code-text);
  font: 12px/1.5 var(--mono);
}
.reader .code-name { display: inline-flex; align-items: center; gap: 7px; overflow-wrap: anywhere; }
.reader .code-lang { color: var(--code-muted); font-size: 11px; }
.reader .code-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-left: auto;
  padding: 4px 9px;
  min-height: 44px;
  border-radius: 7px;
  background: var(--code-control);
  color: var(--code-text);
  font: 12px/1.5 var(--sans);
}
.reader .code-copy:hover { background: var(--code-control-hover); }
.reader .code-copy:disabled { cursor: wait; opacity: .7; }
.reader .code-status { flex-basis: 100%; color: var(--code-muted); font: 12px/1.6 var(--sans); }
.reader .code-status:empty { display: none; }
.code-copy-buffer { position: fixed; top: 0; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.reader .code-copy:focus-visible, .reader pre:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.reader .code-block pre {
  margin: 0;
  padding: 13px 20px 20px;
  max-width: 100%;
  border-radius: 0 0 14px 14px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-color: var(--code-muted) var(--code-bg);
  font: 14px/1.8 var(--mono);
  tab-size: 2;
}
.reader .code-block code { font: inherit; color: inherit; }
.reader .code-block ::selection { background: var(--accent-on-soft); color: var(--page); }
.reader .syn-key { color: var(--syntax-key); font-weight: 700; }
.reader .syn-string { color: var(--syntax-string); }
.reader .syn-number { color: var(--syntax-number); }
.reader .syn-comment { color: var(--syntax-comment); font-style: italic; }

@media (max-width: 800px) {
  .reader { margin-top: 18px; }
  .reader .reader-grid { display: block; }
  .reader .reader-toc { position: static; top: auto; z-index: auto; margin-bottom: 24px; padding-block: 6px; background: var(--page); }
  .reader .toc-panel { max-height: min(55dvh, 330px); border-radius: 11px; background: var(--elevated); }
  .reader .toc-panel[open] { box-shadow: var(--popover-shadow); }
  .reader .toc-summary { min-height: 44px; padding: 8px 12px; }
  .reader .toc-list { padding: 0 5px 5px; }
  .reader .toc-link { min-height: 44px; }
  .reader .reader-section, .reader .reader-section h2 { scroll-margin-top: 28px; }
  .reader .reader-header { padding-bottom: 19px; }
}
@media (max-width: 660px) {
  .reader-neighbors { grid-template-columns: minmax(0, 1fr); }
  .reader { margin-top: 12px; }
  .reader .reader-meta { margin: 21px 0 11px; gap: 6px 9px; font-size: 12px; }
  .reader .article-title { font-size: clamp(26px, 6.9vw, 34px); line-height: 1.4; }
  .reader .reader-intro { font-size: 16px; line-height: 1.85; }
  .reader .reader-section + .reader-section { margin-top: 33px; }
  .reader .reader-section h2 { gap: 8px; margin-bottom: 12px; }
  .reader .reader-section p { font-size: 16px; line-height: 1.9; }
  .reader .reader-section p + p { margin-top: 13px; }
  .reader .code-head { padding: 12px 13px 3px; gap: 6px 8px; }
  .reader .code-block pre { padding: 12px 14px 16px; font-size: 13px; }
}

.reader .markdown h2:not(:first-child), .reader .markdown h3:not(:first-child) { margin-top: 42px; }
.reader .markdown h3 { font-size: 20px; line-height: 1.6; scroll-margin-top: 28px; }

.reader .reader-series { display: block; margin: 0 0 28px; padding: 18px; border-radius: 12px; background: var(--surface); overflow-wrap: anywhere; }
.reader .reader-series a { white-space: normal; }
.reader .reader-series-name { display: inline-flex; min-height: 44px; align-items: center; font-weight: 600; color: var(--accent); }
.reader .series-position { margin: 4px 0 10px; color: var(--muted); font-size: 14px; }
.reader .series-directory { list-style: none; margin: 0; padding: 0; }
.reader .series-directory a { display: flex; align-items: center; min-height: 44px; padding: 7px 10px; border-radius: 8px; font-size: 14px; }
.reader .series-directory a:hover { background: var(--surface-hover); }
.reader .series-directory a[aria-current="page"] { color: var(--accent-on-soft); background: var(--accent-soft); font-weight: 600; }
