/* ---- Marginalia · 页边批注 ---- */
/* Type-driven editorial style. Warm off-white paper, deep ink, brick-red accent. */

:root {
  --bg: #fbf8f1;
  --bg-tint: #f4ecd9;
  --paper-edge: #efe6cf;
  --ink: #1f1d1b;
  --ink-soft: #4a443e;
  --muted: #8a7f73;
  --rule: #e3d9c2;
  --rule-soft: #ece4d1;
  --accent: #8b2e2a;
  --accent-soft: #b8615c;
  --code-bg: #f0e8d3;

  --serif: 'Iowan Old Style', 'Apple Garamond', 'Source Serif 4', 'Source Serif Pro', ui-serif,
           Georgia, Cambria, 'Songti SC', 'Source Han Serif SC', 'Noto Serif CJK SC', 'STSong',
           'Times New Roman', serif;
  --sans:  -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui,
           'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, sans-serif;
  --mono:  ui-monospace, 'SF Mono', SFMono-Regular, 'JetBrains Mono', Menlo, Consolas,
           'Liberation Mono', monospace;

  --measure: 720px;   /* reading column — articles & prose pages */
  --wide:   1080px;   /* header + listing/landing pages (cards, grids, catalogs) */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern", "liga", "onum";
}

::selection { background: var(--accent); color: var(--bg); }

/* paper-edge subtle texture via a pseudo line at the very top */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent) 0, var(--accent) 28%, var(--paper-edge) 28%);
  z-index: 20;
}

/* ---- Layout wrappers ---- */
.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.5rem;
}
/* listing/landing pages (home, ai-hot, apps, videos, showcases) breathe wider */
.wrap--wide { max-width: var(--wide); }
.site-main { padding: 3.5rem 0 4rem; }

/* ---- Header ---- */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: rgba(251, 248, 241, 0.85);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  position: sticky;
  top: 0;
  z-index: 15;
}
.header-wrap {
  max-width: var(--wide);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2rem;
  padding-top: 1.4rem;
  padding-bottom: 1.4rem;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: .55rem;
  border-bottom: none;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  font-family: var(--serif);
  font-size: 1.85rem;
  line-height: 1;
  color: var(--accent);
  font-weight: 700;
  transform: translateY(2px);
}
.brand-text {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: .005em;
}
.brand-tag {
  font-family: var(--sans);
  font-size: .82rem;
  color: var(--muted);
  letter-spacing: .03em;
  margin-left: .4rem;
}
.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem 1.6rem;
  font-family: var(--sans);
  font-size: .92rem;
}
.site-nav a {
  color: var(--ink-soft);
  border-bottom: none;
  position: relative;
}
.site-nav a:hover { color: var(--accent); }
.site-nav a:hover::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -.25em;
  height: 1px; background: var(--accent);
}

/* ---- Typography ---- */
h1, h2, h3, h4, h5 {
  font-family: var(--serif);
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
  letter-spacing: -0.005em;
  margin: 0 0 .5em;
}
h1 { font-size: 2.6rem; }
h2 {
  font-size: 1.55rem;
  margin: 2.4em 0 .8em;
  padding-bottom: .3em;
  border-bottom: 1px solid var(--rule);
}
h3 { font-size: 1.22rem; margin: 2em 0 .5em; }
h4 { font-size: 1.05rem; margin: 1.6em 0 .4em; color: var(--ink-soft); }

p, ul, ol, blockquote, pre, table, figure { margin: 0 0 1.15em; }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(139, 46, 42, 0.28);
  transition: border-color .15s, background .15s;
}
a:hover { border-bottom-color: var(--accent); background: rgba(139, 46, 42, 0.06); }

strong, b { font-weight: 700; color: var(--ink); }
em, i { font-style: italic; }

blockquote {
  border-left: 3px solid var(--accent);
  background: var(--rule-soft);
  padding: .6em 1.1em;
  color: var(--ink-soft);
  margin-left: 0;
  margin-right: 0;
  font-style: italic;
  border-radius: 0 4px 4px 0;
}
blockquote p:last-child { margin-bottom: 0; }

hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2.8em 0;
  position: relative;
}
hr::after {
  content: "❦";
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg);
  padding: 0 .6em;
  color: var(--muted);
  font-size: .9em;
}

code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--code-bg);
  padding: .14em .4em;
  border-radius: 3px;
  color: var(--ink);
}
pre {
  background: var(--code-bg);
  padding: 1em 1.15em;
  border-radius: 4px;
  overflow-x: auto;
  font-size: .87em;
  line-height: 1.6;
  border-left: 3px solid var(--rule);
}
pre code { background: transparent; padding: 0; font-size: inherit; color: var(--ink); }

table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--sans);
  font-size: .94rem;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
th, td { padding: .6em .9em; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--ink-soft); background: var(--rule-soft); }
tr:last-child td { border-bottom: none; }

img, video { max-width: 100%; height: auto; }
figure { margin: 1.5em 0; }
figcaption { font-family: var(--sans); font-size: .85rem; color: var(--muted); text-align: center; margin-top: .4em; }

ul, ol { padding-left: 1.4em; }
li { margin-bottom: .35em; }
li > ul, li > ol { margin-top: .35em; margin-bottom: .35em; }

/* ---- Home: intro + post list ---- */
.intro {
  font-size: 1.15rem;
  line-height: 1.7;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 2.2rem;
  margin-bottom: 2.6rem;
  max-width: var(--measure);   /* keep the lede readable even inside a wide wrap */
}
.intro p { margin-bottom: 1em; }
.intro p:last-child { margin-bottom: 0; }
.intro strong { color: var(--ink); }
.intro a { font-weight: 600; }

.section-title {
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  border: none;
  padding: 0;
  margin: 0 0 1.5rem;
}

.empty-state {
  font-family: var(--sans);
  font-size: .95rem;
  color: var(--muted);
  background: var(--rule-soft);
  padding: 1.2em 1.4em;
  border-radius: 4px;
  border-left: 3px solid var(--accent);
}

.posts { list-style: none; padding: 0; margin: 0; }
.post-item {
  padding: 1.7em 0;
  border-bottom: 1px solid var(--rule);
  display: grid;
  grid-template-columns: 7.5em 1fr;
  gap: 2.2rem;
  align-items: start;
}
.post-item:last-child { border-bottom: none; }

.margin-note {
  font-family: var(--sans);
  font-size: .82rem;
  color: var(--muted);
  text-align: right;
  padding-top: .55em;
  position: relative;
}
.margin-note::after {
  content: "";
  position: absolute;
  right: -1.1rem; top: .8em;
  width: 1px; height: 1.6em;
  background: var(--rule);
}
.margin-note time { display: block; font-variant-numeric: tabular-nums; line-height: 1.3; }
.margin-note .m-y { display: block; font-weight: 600; color: var(--ink-soft); letter-spacing: .04em; }
.margin-note .m-md { display: block; letter-spacing: .06em; }
.margin-note .tags {
  list-style: none; padding: 0; margin: .8em 0 0;
  display: flex; flex-direction: column; gap: .25em;
}
.margin-note .tags li { font-size: .72rem; letter-spacing: .03em; }

.post-summary h3 {
  margin: 0 0 .4em;
  font-size: 1.35rem;
  line-height: 1.3;
  letter-spacing: 0;
}
.post-summary h3 a {
  color: var(--ink);
  border-bottom: none;
  background: none;
}
.post-summary h3 a:hover { color: var(--accent); background: none; }

.excerpt {
  color: var(--ink-soft);
  margin: 0;
  font-size: 1rem;
  line-height: 1.65;
}

/* ---- Post page ---- */
.post { padding-bottom: 2rem; }
.post-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.4rem;
  border-bottom: 1px solid var(--rule);
}
.kicker {
  font-family: var(--sans);
  font-size: .76rem;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 .9em;
}
.post-header h1 {
  font-size: 2.7rem;
  margin: 0 0 .55rem;
  line-height: 1.2;
}
.post-meta {
  font-family: var(--sans);
  font-size: .9rem;
  color: var(--muted);
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: baseline;
}
.post-meta .dot { color: var(--rule); }
.tags-inline span { color: var(--muted); }

.post-body > h2:first-child,
.post-body > h3:first-child {
  margin-top: 0;
}

.post-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

/* ---- Post page · Table of Contents ----
 * Default (mobile / narrow): TOC is a collapsed <details> above the article.
 * Wide screens (≥1100px): TOC becomes a sticky sidebar to the LEFT of the
 * article. Article keeps its 720px reading measure; .post-wrap widens to
 * accommodate the sidebar without re-flowing the body. */
.post-wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.5rem;
}
.post-toc {
  font-family: var(--sans);
  font-size: .86rem;
  line-height: 1.55;
  margin: 0 0 2rem;
  border-left: 2px solid var(--rule);
  padding-left: 1rem;
}
.post-toc[hidden] { display: none; }
.toc-details > .toc-title {
  cursor: pointer;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: .72rem;
  color: var(--accent);
  list-style: none;
  user-select: none;
}
.toc-details > .toc-title::-webkit-details-marker { display: none; }
.toc-details > .toc-title::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  margin-right: .15em;
  transition: transform .15s ease;
  color: var(--muted);
}
.toc-details[open] > .toc-title::before { transform: rotate(90deg); }
.toc-details[open] > .toc-title { margin-bottom: .9rem; }

#toc .toc-list,
#toc .toc-sub {
  list-style: none;
  padding: 0;
  margin: 0;
}
#toc .toc-sub {
  margin: .15rem 0 .35rem .9rem;
  padding-left: .6rem;
  border-left: 1px solid var(--rule-soft);
}
#toc li {
  margin: .25rem 0;
  position: relative;
  padding-left: 1.05rem;
}
#toc a {
  display: block;
  color: var(--ink-soft);
  text-decoration: none;
  padding: .12rem .35rem;
  border-radius: 2px;
  border-bottom: none;
  background: none;
  transition: color .12s, background-color .12s;
  word-break: break-word;
}
#toc .toc-h3 a { font-size: .84rem; color: var(--ink-soft); }
#toc a:hover {
  color: var(--accent);
  background: var(--rule-soft);
}
#toc a.active {
  color: var(--accent);
  font-weight: 600;
  background: linear-gradient(90deg, var(--rule-soft) 0%, transparent 90%);
}
#toc a.active::before {
  content: "";
  display: inline-block;
  width: .35em;
  height: .35em;
  border-radius: 50%;
  background: var(--accent);
  margin-right: .55em;
  vertical-align: middle;
}

/* Collapse / expand toggle on parent list items. */
#toc .toc-toggle {
  position: absolute;
  left: 0;
  top: .15rem;
  width: 1rem;
  height: 1rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: .75rem;
  line-height: 1;
  cursor: pointer;
  transition: transform .15s ease, color .12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#toc .toc-toggle:hover { color: var(--accent); }
#toc li.expanded > .toc-toggle { transform: rotate(90deg); }
#toc li.has-children > .toc-sub { display: none; }
#toc li.has-children.expanded > .toc-sub { display: block; }

@media (min-width: 1100px) {
  .post-wrap {
    max-width: 1080px;
    display: grid;
    grid-template-columns: 240px minmax(0, 720px);
    gap: 3rem;
    align-items: start;
  }
  .post-toc {
    position: sticky;
    top: 5rem;
    margin: 0;
    max-height: calc(100vh - 7rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    /* hide scrollbar by default; show on hover for power users */
    scrollbar-width: thin;
    scrollbar-color: var(--rule) transparent;
  }
  .post-toc::-webkit-scrollbar { width: 6px; }
  .post-toc::-webkit-scrollbar-thumb {
    background: var(--rule);
    border-radius: 3px;
  }
  .toc-details > .toc-title { cursor: default; }
  /* On wide screens always show; the disclosure triangle is decoration only. */
}
.back {
  font-family: var(--sans);
  font-size: .92rem;
  color: var(--ink-soft);
  border-bottom: none;
}
.back:hover { color: var(--accent); background: none; }

/* ---- Static page ---- */
.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}
.page-header h1 { font-size: 2.3rem; margin: 0; }

/* ---- Footer ---- */
.site-footer {
  border-top: 1px solid var(--rule);
  padding: 2.6rem 0 3rem;
  margin-top: 4rem;
  font-family: var(--sans);
  font-size: .85rem;
  color: var(--muted);
  text-align: center;
  background: var(--rule-soft);
}
.site-footer p { margin: 0; line-height: 1.7; }
.site-footer a { color: var(--ink-soft); border-bottom: 1px solid var(--rule); }
.site-footer a:hover { color: var(--accent); border-bottom-color: var(--accent); background: none; }
.site-footer .muted { color: var(--muted); font-style: italic; }

/* ---- Accessibility ---- */
.skip {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px; height: 1px;
  overflow: hidden;
}
.skip:focus {
  position: fixed;
  top: 1em; left: 1em;
  width: auto; height: auto;
  background: var(--ink);
  color: var(--bg);
  padding: .55em 1em;
  z-index: 100;
  border-radius: 3px;
}

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

/* ---- AI Hot featured card (home page) ---- */
.ai-hot-feature {
  margin: 2rem 0 3rem;
  padding: 1.6rem 1.6rem 1.4rem;
  background: linear-gradient(180deg, var(--bg-tint) 0%, var(--bg) 100%);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  position: relative;
}
.ai-hot-feature::before {
  content: "";
  position: absolute;
  top: -1px; right: -1px;
  width: 40px; height: 40px;
  background: linear-gradient(135deg, transparent 50%, var(--accent-soft) 50%);
  opacity: 0.25;
  border-radius: 0 4px 0 0;
}
.ai-hot-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: .9rem;
  flex-wrap: wrap;
}
.ai-hot-pill {
  font-family: var(--sans);
  font-size: .78rem;
  letter-spacing: .04em;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
}
.ai-hot-time {
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--muted);
}
.ai-hot-title {
  font-family: var(--serif);
  font-size: 1.7rem;
  line-height: 1.3;
  margin: .2rem 0 .7rem;
  color: var(--ink);
  font-weight: 700;
}
.ai-hot-title a {
  color: inherit;
  border-bottom: none;
  text-decoration: none;
}
.ai-hot-title a:hover { color: var(--accent); }
.ai-hot-excerpt {
  margin: 0 0 1rem;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.65;
}
.ai-hot-cta {
  display: inline-block;
  font-family: var(--sans);
  font-size: .9rem;
  color: var(--accent);
  border-bottom: 1px solid var(--accent);
  padding-bottom: 1px;
}
.ai-hot-cta:hover {
  color: var(--ink);
  border-color: var(--ink);
}

/* AI 晨报正文：图片美化 + 板块分隔 */
.post-content img,
.ai-hot-body img {
  max-width: 100%;
  height: auto;
  border-radius: 3px;
  margin: 1.2rem auto;
  display: block;
  box-shadow: 0 1px 3px rgba(31, 29, 27, 0.08);
}

/* AI Hot 文章页：双栏布局（左侧粘性 TOC + 右侧正文） */
.ai-hot-wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 3rem;
  /* 不设 align-items: start — 让 grid item 默认 stretch，
     这样 .ai-hot-toc 占满整列高度，内部 .toc-inner 才有滚动余地能 sticky */
}
.ai-hot-post {
  grid-column: 2;
  min-width: 0;
}
.ai-hot-post .post-header {
  margin-top: 0;
}
.ai-hot-toc {
  grid-column: 1;
  grid-row: 1;
  /* 默认 stretch — 关键：必须撑满文章高度，sticky 才有滚动空间 */
}
.ai-hot-toc .toc-inner {
  position: sticky;
  top: 6rem;
  padding: 1.2rem 1rem 1rem;
  border-right: 2px solid var(--rule);
  font-family: var(--sans);
  max-height: calc(100vh - 7rem);
  overflow-y: auto;
}
.ai-hot-toc .toc-title {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 .9rem;
}
.ai-hot-toc ul {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}
.ai-hot-toc li {
  margin: 0;
}
.ai-hot-toc a {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .45rem .55rem;
  color: var(--ink-soft);
  font-size: .92rem;
  border-bottom: none;
  border-radius: 3px;
  transition: background .15s, color .15s;
}
.ai-hot-toc a:hover {
  background: var(--bg-tint);
  color: var(--ink);
}
.ai-hot-toc a.active {
  color: var(--accent);
  background: var(--bg-tint);
  font-weight: 600;
}
.ai-hot-toc .toc-emoji {
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}
.ai-hot-toc .toc-name {
  flex: 1;
}
.ai-hot-toc .toc-count {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--muted);
  flex-shrink: 0;
}
.ai-hot-toc .toc-top {
  display: inline-block;
  font-size: .78rem;
  color: var(--muted);
  border-bottom: none;
  padding-left: .55rem;
}
.ai-hot-toc .toc-top:hover { color: var(--accent); }

/* 移动端：折叠 TOC */
.ai-hot-toc-mobile {
  display: none;
  margin: 1.2rem 0 1.5rem;
  padding: .6rem .9rem;
  background: var(--bg-tint);
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  font-family: var(--sans);
  font-size: .94rem;
}
.ai-hot-toc-mobile summary {
  cursor: pointer;
  color: var(--ink-soft);
  font-weight: 500;
}
.ai-hot-toc-mobile ul {
  list-style: none;
  padding: .8rem 0 .2rem;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem .9rem;
}
.ai-hot-toc-mobile a {
  color: var(--ink-soft);
  border-bottom: none;
  font-size: .88rem;
}

/* 板块锚点偏移：sticky header 高度补偿 */
.ai-hot-body [id] {
  scroll-margin-top: 5rem;
}

/* 板块分隔条：emoji + 名字，比 H2 弱一档 */
.ai-section-divider {
  text-align: center;
  margin: 3rem 0 1.6rem;
  padding: 0;
  color: var(--accent);
  font-family: var(--sans);
  letter-spacing: .12em;
  font-size: .9rem;
  font-weight: 600;
  border-bottom: none;
  position: relative;
}
.ai-section-divider::before,
.ai-section-divider::after {
  content: "";
  display: inline-block;
  width: 36px;
  height: 1px;
  background: var(--rule);
  vertical-align: middle;
  margin: 0 .8rem;
}

/* ---- Mobile ---- */
@media (max-width: 960px) {
  .ai-hot-wrap {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0 1.5rem;
    max-width: var(--measure);
  }
  .ai-hot-post { grid-column: 1; }
  .ai-hot-toc { display: none; }
  .ai-hot-toc-mobile { display: block; }
  .site-nav { gap: .5rem 1.2rem; font-size: .88rem; }
  .brand-tag { display: none; }
}
@media (max-width: 720px) {
  body { font-size: 17px; }
  .ai-hot-feature { padding: 1.2rem 1.1rem 1rem; }
  .ai-hot-title { font-size: 1.35rem; }
  .ai-hot-toc-mobile ul { grid-template-columns: 1fr; }
  .site-main { padding: 2.5rem 0 3rem; }
  .header-wrap { flex-direction: column; align-items: flex-start; gap: .8rem; padding: 1.1rem 1.5rem; }
  .site-nav {
    gap: .45rem 1.1rem;
    font-size: .88rem;
    width: 100%;
  }
  .brand-tag { display: none; }
  h1 { font-size: 2.1rem; }
  .post-header h1 { font-size: 2.05rem; }
  .post-item {
    grid-template-columns: 1fr;
    gap: .5rem;
    padding: 1.4em 0;
  }
  .margin-note { text-align: left; padding-top: 0; display: flex; align-items: center; gap: .9em; flex-wrap: wrap; }
  .margin-note::after { display: none; }
  .margin-note time { display: inline; }
  .margin-note .m-y, .margin-note .m-md { display: inline; }
  .margin-note .m-y::after { content: " · "; color: var(--rule); }
  .margin-note .tags { flex-direction: row; flex-wrap: wrap; margin: 0; gap: .7em; }
  .margin-note .tags li { font-size: .76rem; }
}

/* ---- Print ---- */
@media print {
  body { background: white; color: black; font-size: 12pt; }
  .site-header, .site-footer, .post-footer, .site-nav, body::before { display: none; }
  a { color: black; border-bottom: none; }
  pre, code { background: #f3f3f3; }
}
