/* ============================================================
   训练日志 · Design tokens
   palette: paper / ink / arXiv-crimson   type: Newsreader × Noto Serif SC × Plex Mono
   ============================================================ */
:root {
  color-scheme: light;
  --paper: #FAFBFC;
  --surface: #FFFFFF;
  --ink: #191A1E;
  --ink-2: #565B66;
  --line: #DFE3E8;
  --accent: #B31B1B;
  --accent-soft: rgba(179, 27, 27, .08);
  --code-bg: #F1F4F7;
  --code-border: #DFE3E8;
  --syntax-keyword: #9E1A1A;
  --syntax-string: #3D6B4F;
  --syntax-comment: #656B75;
  --syntax-number: #6B4FA0;
  --syntax-function: #1D5FA8;
  --syntax-builtin: #7A5C2E;

  --serif: "Newsreader", "Noto Serif SC", Georgia, "Songti SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;

  --wrap: 49rem;
  --wrap-wide: 60rem;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #141518;
  --surface: #1B1C21;
  --ink: #E8E7E2;
  --ink-2: #9AA0AB;
  --line: #2A2C33;
  --accent: #E4574F;
  --accent-soft: rgba(228, 87, 79, .12);
  --code-bg: #202127;
  --code-border: #2A2C33;
  --syntax-keyword: #E4837C;
  --syntax-string: #8FC49E;
  --syntax-comment: #9AA0AB;
  --syntax-number: #B39AE0;
  --syntax-function: #7FADE0;
  --syntax-builtin: #CBA36B;
}
/* Without JavaScript, keep following the system preference. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --paper: #141518;
    --surface: #1B1C21;
    --ink: #E8E7E2;
    --ink-2: #9AA0AB;
    --line: #2A2C33;
    --accent: #E4574F;
    --accent-soft: rgba(228, 87, 79, .12);
    --code-bg: #202127;
    --code-border: #2A2C33;
    --syntax-keyword: #E4837C;
    --syntax-string: #8FC49E;
    --syntax-comment: #9AA0AB;
    --syntax-number: #B39AE0;
    --syntax-function: #7FADE0;
    --syntax-builtin: #CBA36B;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.85;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--accent); color: #fff; }
a { color: inherit; }
img { max-width: 100%; height: auto; display: block; }
.wrap { max-width: var(--wrap); margin-inline: auto; padding-inline: 1.25rem; }
.mono { font-family: var(--mono); font-size: .82rem; letter-spacing: 0; }
.dim { color: var(--ink-2); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
.skip-link {
  position: absolute; left: 1rem; top: -3rem; z-index: 10;
  background: var(--accent); color: #fff; padding: .4rem .8rem;
  font-size: .85rem; border-radius: 4px; transition: top .15s ease;
}
.skip-link:focus { top: 1rem; }

/* ---------- topbar ---------- */
.topbar { border-bottom: 1px solid var(--line); background: var(--paper); }
.topbar-inner {
  max-width: var(--wrap-wide);
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .6rem 1rem;
  padding-block: 1.05rem;
}
.brand { text-decoration: none; display: inline-flex; align-items: baseline; gap: .45rem; }
.brand-mark { color: var(--accent); font-weight: 600; }
.brand-name { font-family: var(--mono); font-weight: 500; letter-spacing: 0; }
.brand-sub { color: var(--ink-2); font-family: var(--mono); font-size: .78rem; }
.nav { display: flex; flex-wrap: wrap; gap: .6rem 1.1rem; margin-left: auto; }
.theme-control { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; color: var(--ink-2); font-family: var(--mono); font-size: .78rem; }
.theme-control[hidden] { display: none; }
.theme-control select {
  min-height: 2.75rem; max-width: 100%; padding: .35rem .4rem;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
}
.theme-control select:hover { border-color: var(--accent); }
.nav a {
  font-family: var(--mono); font-size: .82rem; letter-spacing: 0;
  text-decoration: none; color: var(--ink-2); padding-bottom: 2px;
  border-bottom: 1px solid transparent;
}
.nav a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.nav a.active { color: var(--accent); border-bottom-color: var(--accent); }

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

/* ---------- hero ---------- */
.hero { padding: clamp(3.2rem, 9vh, 6rem) 0 1rem; }
.eyebrow {
  font-family: var(--mono); font-size: .78rem; letter-spacing: 0;
  text-transform: uppercase; color: var(--accent);
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin: 0 0 1.1rem;
}
.hero-title {
  font-family: var(--serif); font-weight: 600;
  font-size: 3rem;
  line-height: 1.32; letter-spacing: 0;
  margin: 0 0 1.15rem;
}
.lede { color: var(--ink-2); max-width: 34em; margin: 0 0 1.6rem; }

/* 签名元素：checkpoint 日志条 */
.log {
  border: 1px solid var(--line); background: var(--surface);
  padding: .8rem 1rem; border-radius: 6px;
  min-height: 2.55em;
  overflow-wrap: anywhere;
}
.log-prompt { color: var(--accent); user-select: none; }
.log-caret {
  display: inline-block; width: .58em; height: 1.05em;
  background: var(--accent); vertical-align: text-bottom; margin-left: 2px;
  animation: blink 1.06s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- feed / post list ---------- */
.feed { padding: 2.8rem 0 3.5rem; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-bottom: .4rem;
}
.section-head h2 {
  font-family: var(--mono); font-size: .8rem; font-weight: 500;
  letter-spacing: 0; text-transform: uppercase; color: var(--ink-2);
  display: flex; align-items: center; gap: .9rem; margin: 0;
}
.section-head h2::after { content: ""; width: 4.5rem; height: 1px; background: var(--line); }
.more { color: var(--accent); text-decoration: none; }
.more:hover { text-decoration: underline; text-underline-offset: 4px; }

.post-list { list-style: none; margin: 0; padding: 0; }
.post-item { border-bottom: 1px solid var(--line); }
.post-item a {
  display: block; padding: 1.35rem 0 1.45rem; text-decoration: none;
}
.post-item .eyebrow { color: var(--ink-2); margin-bottom: .55rem; letter-spacing: 0; }
.post-item-title {
  font-family: var(--sans); font-weight: 650;
  font-size: 1.32rem; line-height: 1.55; margin: 0 0 .45rem;
  display: inline; background-image: linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat; background-position: 0 100%;
  background-size: 0% 1.5px; transition: background-size .28s cubic-bezier(.22,.61,.36,1);
}
.post-item a:hover .post-item-title,
.post-item a:focus-visible .post-item-title { background-size: 100% 1.5px; color: var(--accent); }
.excerpt { margin: 0; color: var(--ink-2); font-size: .93rem; line-height: 1.75; }
.empty { color: var(--ink-2); padding: 2.5rem 0; }

/* ---------- archive 页 ---------- */
.page-title {
  font-family: var(--serif); font-weight: 600;
  font-size: 2.3rem; margin: 2.6rem 0 1rem;
}
.tag-row { display: flex; flex-wrap: wrap; gap: .55rem; margin: 0 0 1.6rem; padding: 0; list-style: none; }
.tag-row a {
  text-decoration: none; color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 99px; padding: .18rem .75rem;
  scroll-margin-top: 4.5rem;
}
.tag-row a:hover { color: var(--accent); border-color: var(--accent); }
.year {
  font-size: .85rem; color: var(--ink-2); letter-spacing: 0;
  margin: 2.1rem 0 0; scroll-margin-top: 4.5rem;
}

/* ---------- 文章页 ---------- */
.reading-wrap { max-width: 72rem; }
.post { max-width: 48rem; margin-inline: auto; }
.post.has-toc {
  display: grid; max-width: none;
  grid-template-columns: minmax(0, 48rem) minmax(0, 13rem);
  column-gap: 3rem;
}
.post-header { padding: 3.2rem 0 1.8rem; border-bottom: 1px solid var(--line); margin-bottom: 1.8rem; }
.post-header .eyebrow { margin-bottom: 1rem; color: var(--ink-2); line-height: 1.7; gap: .25rem .6rem; }
.post.has-toc > .post-header { grid-column: 1; grid-row: 1; }
.post.has-toc > .prose { grid-column: 1; grid-row: 2; min-width: 0; }
.post.has-toc > .post-foot { grid-column: 1; grid-row: 3; }
.post-title {
  font-family: var(--serif); font-weight: 600;
  font-size: 2.25rem; line-height: 1.48; text-wrap: balance;
  margin: 0; overflow-wrap: anywhere;
}

/* 正文排版 */
.prose { padding-bottom: 1rem; font-size: 18px; overflow-wrap: break-word; }
.prose > p, .prose li { line-height: 1.95; }
.prose > p { margin: 1.15em 0; }
.prose > :first-child { margin-top: 0; }
.prose ul, .prose ol { padding-left: 1.5em; margin: 1.3em 0; }
.prose li + li { margin-top: .45em; }
.prose li::marker { color: var(--accent); }
.prose strong { font-weight: 650; color: var(--ink); }
.prose h2, .prose h3, .prose h4 {
  font-family: var(--sans); font-weight: 650; line-height: 1.55;
  margin: 2.1em 0 .85em; scroll-margin-top: 2rem;
  text-wrap: pretty;
}
.prose h2 {
  font-size: 1.55rem; border-top: 1px solid var(--line);
  padding-top: 1.5rem; margin-top: 3.2rem;
}
.prose h2::before { content: ""; display: block; width: 1.7rem; height: 3px; background: var(--accent); margin-bottom: .75rem; }
.prose h3 { font-size: 1.2rem; }
.prose h4 { font-size: 1.08rem; }
.prose a {
  color: var(--accent); text-decoration: underline;
  text-decoration-thickness: 1px; text-underline-offset: 3px;
}
.prose a:hover { text-decoration-thickness: 2px; }
.prose blockquote {
  margin: 1.7em 0; padding: .6em 1.15em; overflow-x: auto;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent); color: var(--ink);
  font-size: .97em; line-height: 1.85;
}
.prose blockquote p { margin: .35em 0; }
.prose blockquote.figure-note {
  margin-top: -.6rem; padding: .2rem 0 .2rem 1rem;
  background: transparent; border-left: 2px solid var(--line);
  color: var(--ink-2); font-size: .87em; line-height: 1.85;
}
.prose .figure-note strong { color: var(--ink-2); }
.prose code {
  font-family: var(--mono); font-size: .86em;
  background: var(--code-bg); border: 1px solid var(--code-border);
  padding: .08em .35em; border-radius: 4px;
}
.prose pre {
  background: var(--code-bg); border: 1px solid var(--code-border);
  border-radius: 6px; padding: 1rem 1.15rem; overflow-x: auto;
  font-size: .84rem; line-height: 1.7;
}
.prose pre code { background: none; border: none; padding: 0; font-size: inherit; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 3em auto; width: 40%; }
.prose table {
  width: 100%; border-collapse: collapse; font-size: .92rem; margin: 1.8em 0;
  line-height: 1.85; background: var(--surface);
}
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: .85em 1em; text-align: left; vertical-align: top; }
.prose th { font-family: var(--sans); font-size: .87rem; font-weight: 650; letter-spacing: 0; color: var(--ink); background: var(--code-bg); }
.prose tbody tr:nth-child(even) { background: var(--paper); }
.prose .table-scroll { overflow-x: auto; max-width: 100%; margin: 1.8em 0; overscroll-behavior-inline: contain; }
.prose .table-scroll table { margin: 0; min-width: 34rem; }
.prose .table-scroll td:first-child { min-width: 7rem; }
.prose .table-scroll.is-wide table { min-width: 44rem; }
.prose .table-scroll.is-compact table { min-width: 100%; }
.prose img {
  display: block; max-width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: 4px; margin: 2em auto 1.2em;
  background: #fff;
}
.prose figure { margin: 1.8em 0; }
.prose figcaption {
  font-family: var(--mono); font-size: .76rem; color: var(--ink-2);
  text-align: center; margin-top: .5rem;
}
.prose .katex {
  position: relative; white-space: nowrap; display: inline-block; max-width: 100%;
  overflow-x: auto; overflow-y: hidden; vertical-align: middle;
  padding-block: .15em;
}
.prose .katex-display > .katex {
  display: block; max-width: none; overflow: visible;
}
.prose .katex-display {
  overflow-x: auto; overflow-y: hidden; padding: 1rem .7rem;
  margin: 1.5em 0; background: var(--code-bg); border-radius: 4px;
  font-size: .95em;
}
.prose sup a { text-decoration: none; font-family: var(--mono); font-size: .72em; }
.prose .footnotes { font-size: .88rem; color: var(--ink-2); }
.prose .footnotes::before {
  content: ""; display: block; width: 40%;
  border-top: 1px solid var(--line); margin: 2.4em 0 1em;
}

/* Long-form navigation stays outside the reading column. */
.post-toc {
  grid-column: 2; grid-row: 2; align-self: start;
  position: sticky; top: 2rem; max-height: calc(100vh - 4rem);
  overflow-y: auto; font-size: .82rem; line-height: 1.65;
  border-left: 1px solid var(--line); padding-left: 1.2rem;
  scrollbar-width: thin;
}
.post-toc summary { cursor: pointer; font-size: .85rem; font-weight: 650; padding-bottom: .8rem; color: var(--ink); }
.post-toc ol { list-style: none; padding: 0; margin: 0; }
.post-toc li + li { margin-top: .4rem; }
.post-toc a { display: block; padding: .35rem .5rem; color: var(--ink-2); text-decoration: none; border-left: 2px solid transparent; }
.post-toc a:hover { color: var(--accent); }
.post-toc a[aria-current="location"] { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); }

/* 代码高亮（Rouge）：与正文使用同一主题，不受系统偏好覆盖。 */
.highlight .k, .highlight .kv, .highlight .kn, .highlight .kr { color: var(--syntax-keyword); }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sa { color: var(--syntax-string); }
.highlight .c1, .highlight .cm, .highlight .c { color: var(--syntax-comment); font-style: italic; }
.highlight .mi, .highlight .mf, .highlight .no { color: var(--syntax-number); }
.highlight .nf, .highlight .fm { color: var(--syntax-function); }
.highlight .nb { color: var(--syntax-builtin); }
.highlight .o, .highlight .p { color: var(--ink-2); }

.post-foot { padding: 2.2rem 0 3.5rem; }
.back { color: var(--ink-2); text-decoration: none; }
.back:hover { color: var(--accent); }

/* ---------- 404 ---------- */
.breadcrumbs { display: flex; flex-wrap: wrap; gap: .35rem .65rem; color: var(--ink-2); margin: 1.5rem 0; line-height: 1.7; overflow-wrap: anywhere; }
.breadcrumbs a { color: var(--accent); text-underline-offset: 3px; }
.breadcrumbs [aria-current] { min-width: 0; }
.post-header .breadcrumbs { margin-top: 0; }
.post-foot { display: flex; flex-wrap: wrap; gap: 1rem 2rem; }
.topic-label { text-transform: none; }
.archive-topics { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin-bottom: 1.6rem; }
.archive-topics a { color: var(--ink-2); text-underline-offset: 4px; }
.archive-topics a:hover { color: var(--accent); }

.hero-404 { padding-block: 22vh; }
.btn {
  display: inline-block; color: var(--accent); text-decoration: none;
  border: 1px solid var(--accent); border-radius: 99px; padding: .45rem 1.2rem;
}
.btn:hover { background: var(--accent-soft); }

/* ---------- footer ---------- */
.colophon { border-top: 1px solid var(--line); }
.colophon-inner {
  max-width: var(--wrap-wide);
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding-block: 1.4rem; color: var(--ink-2);
}
.colophon-inner p { margin: 0; }
.colophon a { color: var(--accent); text-decoration: none; }
.colophon a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- 动效 ---------- */
.rise { animation: rise .7s cubic-bezier(.22,.61,.36,1) both; animation-delay: var(--d, 0s); }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
.reveal-on-scroll {
  opacity: 0; transform: translateY(14px);
  transition: opacity .6s ease, transform .6s cubic-bezier(.22,.61,.36,1);
}
.reveal-on-scroll.in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .rise, .log-caret { animation: none !important; }
  .reveal-on-scroll { opacity: 1; transform: none; transition: none; }
  .post-item-title { transition: none; }
}

/* ---------- 小屏 ---------- */
@media (max-width: 1050px) {
  .reading-wrap { max-width: var(--wrap); }
  .post.has-toc { display: flex; flex-direction: column; }
  .post-header { order: 0; }
  .post-toc {
    order: 1; position: static; width: 100%; max-height: none;
    margin: 0 0 2rem; border: 0; border-bottom: 1px solid var(--line);
    padding: 0 0 .7rem;
  }
  .post-toc details[open] ol { max-height: 18rem; overflow-y: auto; padding-bottom: .6rem; }
  .post.has-toc > .prose { order: 2; }
  .post-foot { order: 3; }
}
@media (max-width: 560px) {
  body { font-size: 16px; }
  .hero-title { font-size: 2rem; }
  .page-title { font-size: 1.8rem; }
  .topbar-inner { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .7rem .5rem; align-items: center; padding-block: .9rem 1rem; }
  .brand { flex-wrap: wrap; gap: .15rem .4rem; }
  .brand-sub { flex-basis: 100%; }
  .nav { grid-column: 1 / -1; grid-row: 2; margin-left: 0; gap: .5rem 1rem; }
  .theme-control { grid-column: 2; grid-row: 1; }
  .colophon-inner { flex-direction: column; }
  .eyebrow { flex-wrap: wrap; overflow-wrap: anywhere; }
  .post-header .eyebrow { row-gap: .25rem; }
  .post-header { padding-top: 2rem; }
  .post-title { font-size: 1.85rem; line-height: 1.5; }
  .prose { min-width: 0; font-size: 17px; }
  .prose h2 { font-size: 1.35rem; margin-top: 2.6rem; }
  .prose h3 { font-size: 1.13rem; }
  .prose table { display: block; overflow-x: auto; }
  .prose .table-scroll table { display: table; }
  .prose th, .prose td { overflow-wrap: break-word; }
  .prose code { overflow-wrap: anywhere; word-break: break-word; }
  .prose pre code { overflow-wrap: normal; word-break: normal; }
  .prose .katex-display { max-width: 100%; box-sizing: border-box; }
}
