:root {
  color-scheme: light dark;
  --bg: #f7f6f2;
  --surface: #fffefa;
  --text: #23211d;
  --text-soft: #6d6960;
  --text-faint: #918c81;
  --line: #e5e1d8;
  --line-strong: #d2ccbf;
  --accent: #185fa5;
  --accent-soft: #eaf2fa;
  --code-bg: #f1efe9;
  --quote-bg: #f2efe7;
  --shadow: 0 1px 2px rgb(35 33 29 / 4%), 0 18px 50px rgb(35 33 29 / 5%);
  --radius: 18px;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --surface: #1d2024;
    --text: #e8e6e1;
    --text-soft: #a8a49b;
    --text-faint: #77736b;
    --line: #2e3237;
    --line-strong: #3c4148;
    --accent: #85b7eb;
    --accent-soft: #1e2c3c;
    --code-bg: #23262b;
    --quote-bg: #202328;
    --shadow: 0 1px 2px rgb(0 0 0 / 15%), 0 18px 50px rgb(0 0 0 / 18%);
  }
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 14% 0%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -80px;
  z-index: 10;
  padding: 9px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  text-decoration: none;
}
.skip-link:focus { top: 16px; }

.topbar {
  width: min(100% - 48px, 1160px);
  margin: 0 auto;
  padding: 24px 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .01em;
}

.brand-mark {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background:
    linear-gradient(90deg, transparent 32%, var(--surface) 32%, var(--surface) 46%, transparent 46%),
    linear-gradient(0deg, transparent 46%, var(--surface) 46%, var(--surface) 58%, transparent 58%),
    var(--accent);
}

.readonly-tag {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: .04em;
}

.reading-layout {
  width: min(100% - 48px, 1160px);
  margin: 16px auto 0;
  display: grid;
  grid-template-columns: 206px minmax(0, 1fr);
  column-gap: 32px;
  row-gap: 0;
  align-items: start;
}

.reading-layout--single {
  width: min(100% - 48px, 880px);
  display: block;
}

.page {
  width: 100%;
  min-width: 0;
  margin: 0;
}

.toc {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 14px 6px 14px 0;
  scrollbar-width: thin;
}

.toc-heading {
  margin: 0 0 13px 13px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .12em;
}

.toc-list {
  margin: 0;
  padding: 0 0 0 1px;
  border-left: 1px solid var(--line);
  list-style: none;
}

.toc-list li { margin: 0; }

.toc-link {
  display: block;
  margin-left: -1px;
  padding: 5px 8px 5px 13px;
  border-left: 2px solid transparent;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.5;
  text-decoration: none;
  overflow-wrap: anywhere;
  transition: color .15s ease, border-color .15s ease;
}

.toc-link:hover {
  border-left-color: var(--line-strong);
  color: var(--text);
  text-decoration: none;
}

.toc-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toc-level-1 {
  color: var(--text);
  font-weight: 500;
}

.toc-link.toc-document-title {
  padding-top: 2px;
  padding-bottom: 7px;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
}

.toc-level-2 { padding-left: 25px; }
.toc-level-3 {
  padding-left: 37px;
  color: var(--text-faint);
  font-size: 12.5px;
}

.document {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(28px, 6vw, 72px) clamp(22px, 7vw, 84px) clamp(38px, 8vw, 84px);
}

.document-header {
  padding-bottom: 30px;
  margin-bottom: 38px;
  border-bottom: 1px solid var(--line);
}

.document-title {
  margin: 0 0 14px;
  scroll-margin-top: 24px;
  color: var(--text);
  font-size: clamp(29px, 4.8vw, 44px);
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -.028em;
  overflow-wrap: anywhere;
}

.document-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--text-faint);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--line-strong);
}

.markdown-body {
  color: var(--text);
  font-size: 16.5px;
  line-height: 1.82;
  overflow-wrap: anywhere;
}

.markdown-body > :first-child { margin-top: 0 !important; }
.markdown-body > :last-child { margin-bottom: 0 !important; }

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 2em 0 .7em;
  color: var(--text);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -.015em;
  scroll-margin-top: 24px;
}

.markdown-body h1 { font-size: 1.8em; }
.markdown-body h2 {
  font-size: 1.42em;
  padding-bottom: .35em;
  border-bottom: 1px solid var(--line);
}
.markdown-body h3 { font-size: 1.18em; }
.markdown-body h4 { font-size: 1.03em; }
.markdown-body h5,
.markdown-body h6 { font-size: .95em; color: var(--text-soft); }

.markdown-body p { margin: 0 0 1.15em; }

.markdown-body a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-underline-offset: 3px;
  transition: text-decoration-color .15s ease;
}
.markdown-body a:hover { text-decoration-color: var(--accent); }

.markdown-body strong { font-weight: 650; }
.markdown-body em { font-style: italic; }
.markdown-body del { color: var(--text-soft); }

.markdown-body ul,
.markdown-body ol {
  margin: .35em 0 1.2em;
  padding-left: 1.6em;
}
.markdown-body li { margin: .3em 0; }
.markdown-body li > p { margin-bottom: .4em; }
.markdown-body li::marker { color: var(--text-faint); }

.markdown-body .contains-task-list {
  list-style: none;
  padding-left: .2em;
}
.markdown-body .task-list-item { padding-left: 1.7em; position: relative; }
.markdown-body .task-list-item input[type="checkbox"] {
  position: absolute;
  left: 0;
  top: .48em;
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
}

.markdown-body blockquote {
  margin: 1.4em 0;
  padding: 12px 20px;
  border-left: 3px solid var(--line-strong);
  border-radius: 0 8px 8px 0;
  background: var(--quote-bg);
  color: var(--text-soft);
}
.markdown-body blockquote > :last-child { margin-bottom: 0; }

.markdown-body code {
  padding: .16em .38em;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: .86em;
  color: color-mix(in srgb, var(--text) 88%, var(--accent));
}

.markdown-body pre {
  margin: 1.5em 0;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--code-bg);
  overflow: auto;
  line-height: 1.65;
  tab-size: 2;
  -webkit-overflow-scrolling: touch;
}

.markdown-body pre code {
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 13px;
  color: var(--text);
  white-space: pre;
}

.markdown-body hr {
  height: 1px;
  margin: 2.4em 0;
  border: 0;
  background: var(--line);
}

.markdown-body img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.6em auto;
  border-radius: 10px;
  background: var(--bg);
}

.markdown-body table {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 1.5em 0;
  border-collapse: collapse;
  border-spacing: 0;
  overflow-x: auto;
  font-size: .92em;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 13px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.markdown-body th {
  background: var(--bg);
  font-weight: 600;
  white-space: nowrap;
}
.markdown-body tr:nth-child(even) td { background: color-mix(in srgb, var(--bg) 55%, transparent); }

.markdown-body img {
  cursor: zoom-in;
}

.markdown-body img:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

body.lightbox-open {
  overflow: hidden;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f7f7f4;
}

.image-lightbox[hidden] {
  display: none;
}

.lightbox-scrim {
  position: absolute;
  inset: 0;
  background: rgb(10 12 15 / 90%);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.lightbox-shell {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.lightbox-topbar {
  position: absolute;
  z-index: 3;
  top: 18px;
  left: 22px;
  right: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: rgb(255 255 255 / 62%);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lightbox-zoom-controls {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 2px;
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 9px;
  background: rgb(255 255 255 / 6%);
}

.lightbox-zoom-button,
.lightbox-zoom-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgb(255 255 255 / 78%);
  font-family: var(--sans);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.lightbox-zoom-button {
  width: 28px;
  font-size: 18px;
  line-height: 1;
}

.lightbox-zoom-level {
  min-width: 46px;
  padding: 0 4px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.lightbox-zoom-button:hover,
.lightbox-zoom-level:hover {
  background: rgb(255 255 255 / 11%);
  color: #ffffff;
}

.lightbox-zoom-button:focus-visible,
.lightbox-zoom-level:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.lightbox-original,
.lightbox-close,
.lightbox-nav {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.lightbox-original {
  padding: 7px 11px;
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 8px;
  color: rgb(255 255 255 / 78%);
  font-size: 12.5px;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.lightbox-original:hover {
  border-color: rgb(255 255 255 / 38%);
  background: rgb(255 255 255 / 8%);
  color: #ffffff;
  text-decoration: none;
}

.lightbox-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 50%;
  background: rgb(255 255 255 / 7%);
  color: #ffffff;
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}

.lightbox-close:hover {
  border-color: rgb(255 255 255 / 42%);
  background: rgb(255 255 255 / 14%);
}

.lightbox-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 76px 78px 56px;
}

.lightbox-figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 1560px);
  max-height: calc(100dvh - 136px);
  margin: 0;
}

.lightbox-image {
  display: block;
  width: auto;
  height: auto;
  max-width: min(92vw, 1560px);
  max-height: calc(100dvh - 198px);
  border-radius: 7px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgb(0 0 0 / 55%);
  cursor: zoom-in;
  transform-origin: center center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  will-change: transform;
}

.image-lightbox.is-zoomed .lightbox-image {
  cursor: grab;
}

.image-lightbox.is-dragging .lightbox-image {
  cursor: grabbing;
}

.lightbox-caption {
  max-width: min(80ch, 90vw);
  color: rgb(255 255 255 / 68%);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
  overflow-wrap: anywhere;
}

.lightbox-caption[hidden] {
  display: none;
}

.lightbox-nav {
  position: absolute;
  z-index: 3;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0 0 2px;
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 50%;
  background: rgb(255 255 255 / 7%);
  color: #ffffff;
  font-family: var(--sans);
  font-size: 31px;
  line-height: 1;
  cursor: pointer;
  transform: translateY(-50%);
  transition: background .15s ease, border-color .15s ease;
}

.lightbox-prev { left: 18px; }
.lightbox-next { right: 18px; }

.lightbox-nav:hover {
  border-color: rgb(255 255 255 / 38%);
  background: rgb(255 255 255 / 13%);
}

.lightbox-nav[hidden] {
  display: none;
}

.lightbox-close:focus-visible,
.lightbox-original:focus-visible,
.lightbox-nav:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}

.image-lightbox.is-open .lightbox-shell {
  animation: lightbox-fade .18s ease-out both;
}

.image-lightbox.is-open .lightbox-figure {
  animation: lightbox-rise .23s cubic-bezier(.2, .7, .2, 1) both;
}

@keyframes lightbox-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes lightbox-rise {
  from { opacity: 0; transform: scale(.975) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.page-footer {
  width: min(100% - 48px, 1160px);
  margin: 0 auto;
  padding: 26px 4px 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
  color: var(--text-faint);
  font-size: 12px;
}

.reading-layout > .page-footer {
  grid-column: 2;
  width: 100%;
  margin: 0;
}

/* Footer inside the layout must not participate in column placement when stacked. */
.reading-layout--single > .page-footer {
  grid-column: auto;
}

.message-page {
  width: min(100% - 40px, 620px);
  margin: 14vh auto 0;
  padding: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.message-page h1 { margin: 6px 0 10px; font-size: 26px; }
.message-page p { margin: 0; color: var(--text-soft); }
.message-page .message-code {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
}

@media (max-width: 1100px) {
  .topbar,
  .page-footer {
    width: min(100% - 40px, 880px);
  }

  .reading-layout,
  .reading-layout--single {
    width: min(100% - 40px, 880px);
    display: block;
    margin-top: 10px;
  }

  .toc {
    position: static;
    max-height: none;
    margin: 0 0 12px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  .reading-layout > .page-footer {
    grid-column: auto;
    width: 100%;
  }

  .toc-heading { margin-left: 0; }

  .toc-list {
    max-height: 40vh;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
}

@media (max-width: 640px) {
  body { font-size: 15.5px; }
  .topbar { padding-top: 16px; width: min(100% - 28px, 960px); }
  .reading-layout,
  .reading-layout--single {
    width: min(100% - 20px, 880px);
    margin-top: 8px;
  }
  .toc {
    margin-bottom: 10px;
    padding: 12px 14px;
    border-radius: 12px;
  }
  .toc-list { max-height: 40vh; }
  .toc-link { padding-top: 6px; padding-bottom: 6px; }
  .lightbox-topbar { top: 10px; left: 12px; right: 12px; }
  .lightbox-actions { gap: 6px; }
  .lightbox-zoom-controls { gap: 0; padding: 1px; }
  .lightbox-zoom-button { width: 25px; height: 26px; font-size: 17px; }
  .lightbox-zoom-level { min-width: 40px; height: 26px; font-size: 11px; }
  .lightbox-original { padding: 6px 9px; font-size: 11.5px; }
  .lightbox-close { width: 34px; height: 34px; font-size: 23px; }
  .lightbox-stage { padding: 58px 10px 34px; }
  .lightbox-figure {
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 108px);
    gap: 9px;
  }
  .lightbox-image {
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 162px);
  }
  .lightbox-caption { padding: 0 8px; font-size: 12px; }
  .lightbox-nav { width: 38px; height: 38px; font-size: 26px; background: rgb(20 22 25 / 68%); }
  .lightbox-prev { left: 5px; }
  .lightbox-next { right: 5px; }
  .document {
    padding: 28px 20px 40px;
    border-radius: 14px;
  }
  .document-header { padding-bottom: 22px; margin-bottom: 28px; }
  .markdown-body { font-size: 16px; line-height: 1.78; }
  .markdown-body pre { margin-left: -8px; margin-right: -8px; border-radius: 8px; }
  .page-footer { width: min(100% - 28px, 880px); }
  .message-page { padding: 30px 24px; margin-top: 10vh; }
}

@media print {
  body { background: #fff; }
  .topbar, .page-footer, .skip-link, .readonly-tag, .toc, .image-lightbox { display: none !important; }
  .reading-layout,
  .reading-layout--single { display: block; width: 100%; margin: 0; }
  .page { width: 100%; margin: 0; }
  .document { padding: 0; border: 0; box-shadow: none; }
  .markdown-body a { color: inherit; }
  .markdown-body pre, .markdown-body blockquote { break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
  .image-lightbox.is-open .lightbox-shell,
  .image-lightbox.is-open .lightbox-figure { animation: none !important; }
}