:root {
  --bg-page: #f8f9fa;
  --bg-surface: #ffffff;
  --bg-subtle: #eff2f5;
  --text-primary: #14171a;
  --text-secondary: #52606d;
  --border-color: #dde3ea;
  --accent: #0d6e52;
  --accent-soft: rgba(13, 110, 82, 0.08);
  --header-bg: rgba(248, 249, 250, 0.88);

  --font-sans: "Inter", "PingFang SC", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Newsreader", "Noto Serif SC", "Songti SC", Georgia, serif;

  /* 严格 3 档正文字号 */
  --text-h2: 1.5rem;
  --text-body: 1.0625rem;
  --text-sm: 0.875rem;
}

html[data-theme="dark"] {
  --bg-page: #0f1419;
  --bg-surface: #161c24;
  --bg-subtle: #1d2530;
  --text-primary: #e7e9ea;
  --text-secondary: #9aa4b2;
  --border-color: #26303d;
  --accent: #34d399;
  --accent-soft: rgba(52, 211, 153, 0.12);
  --header-bg: rgba(15, 20, 25, 0.88);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  transition: background-color 200ms cubic-bezier(0.22, 1, 0.36, 1),
              color 200ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* 顶部阅读进度条 */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  z-index: 100;
  pointer-events: none;
}

.reading-progress-bar {
  width: 0%;
  height: 100%;
  background-color: var(--accent);
  transition: width 80ms linear;
}

/* 顶部单行导航 */
.site-header {
  position: sticky;
  top: 0;
  z-index: 90;
  background-color: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
              background-color 200ms cubic-bezier(0.22, 1, 0.36, 1);
}

.site-header.is-scrolled {
  border-bottom-color: var(--border-color);
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-brand-group {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  min-width: 0;
}

.brand-title {
  font-family: var(--font-serif);
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
}

.header-back-link {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  transition: color 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

.header-back-link:hover {
  color: var(--accent);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.segmented-control {
  display: inline-flex;
  padding: 2px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms cubic-bezier(0.22, 1, 0.36, 1),
              color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.seg-btn:hover {
  color: var(--text-primary);
}

.seg-btn.is-active {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* =========================================
   首页布局：编辑室刊头 + 筛选栏 + 摘录列表
   ========================================= */
.home-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

.masthead {
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
}

.masthead-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4.5vw, 3rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.masthead-desc {
  margin: 0.85rem 0 0;
  max-width: 60ch;
  font-size: var(--text-body);
  line-height: 1.7;
  color: var(--text-secondary);
}

.filter-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.875rem 1.25rem;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border-color);
}

.filter-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.search-input {
  width: 240px;
  max-width: 100%;
  padding: 0.45rem 0.75rem;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  outline: none;
  transition: border-color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.search-input::placeholder {
  color: var(--text-secondary);
}

.search-input:focus {
  border-color: var(--accent);
}

.article-count {
  margin: 0;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.entry-list {
  display: flex;
  flex-direction: column;
}

.entry-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 2rem;
  align-items: start;
  padding: 2rem 0;
  border-bottom: 1px solid var(--border-color);
}

.entry-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.55rem;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.entry-title {
  margin: 0.5rem 0 0;
  font-family: var(--font-serif);
  font-size: var(--text-h2);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.015em;
}

.entry-title a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

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

.entry-subtitle {
  margin: 0.25rem 0 0;
  font-family: var(--font-serif);
  font-size: var(--text-sm);
  font-style: italic;
  color: var(--text-secondary);
}

.entry-summary {
  margin: 0.875rem 0 0;
  max-width: 65ch;
  font-size: var(--text-body);
  line-height: 1.75;
  color: var(--text-primary);
}

.entry-highlights {
  margin: 0.875rem 0 0;
  padding-left: 1.125rem;
  max-width: 65ch;
  font-size: var(--text-body);
  line-height: 1.7;
  color: var(--text-secondary);
}

.entry-highlights li + li {
  margin-top: 0.3rem;
}

.entry-actions {
  margin-top: 1.125rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: var(--text-sm);
}

.entry-read-link {
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.entry-read-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.entry-source-link {
  color: var(--text-secondary);
  text-decoration: none;
}

.entry-source-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.entry-thumb {
  display: block;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.entry-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.entry-item:hover .entry-thumb img {
  transform: scale(1.02);
}

.empty-state,
.load-error {
  padding: 3rem 0;
  font-size: var(--text-body);
  color: var(--text-secondary);
}

.site-footer {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* =========================================
   文章阅读页布局：左侧目录 + 居中阅读栏 + 右侧旁注
   ========================================= */
.page-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
  display: grid;
  grid-template-columns: 170px minmax(0, 62ch) 235px;
  gap: 2rem;
  align-items: start;
}

.toc-rail {
  position: relative;
}

.toc-sticky {
  position: sticky;
  top: 5.25rem;
}

.toc-heading {
  margin: 0 0 0.75rem;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border-color);
}

.toc-link {
  display: block;
  padding: 0.35rem 0 0.35rem 0.875rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 160ms cubic-bezier(0.22, 1, 0.36, 1),
              border-color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.toc-link:hover {
  color: var(--text-primary);
}

.toc-link.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

.article-container {
  grid-column: 2;
  min-width: 0;
}

.article-header {
  margin-bottom: 2.25rem;
}

.article-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 2.75rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

.article-subtitle {
  margin: 0.625rem 0 0;
  font-family: var(--font-serif);
  font-size: var(--text-h2);
  font-style: italic;
  line-height: 1.35;
  color: var(--text-secondary);
}

.article-meta {
  margin-top: 1.25rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.625rem;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.article-meta strong {
  color: var(--text-primary);
  font-weight: 600;
}

.article-meta a {
  color: var(--accent);
  text-decoration: none;
}

.article-meta a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.meta-sep {
  color: var(--border-color);
}

.cover-figure {
  margin: 1.75rem 0 0;
}

.cover-figure img,
.diagram-figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.article-body h2 {
  margin: 3rem 0 0.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  font-family: var(--font-serif);
  font-size: var(--text-h2);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

.section-en {
  margin: -0.35rem 0 1.25rem;
  font-size: var(--text-sm);
  font-style: italic;
  color: var(--text-secondary);
}

.para-group {
  position: relative;
  margin: 0 0 1.35rem;
}

/* 正文术语高亮与旁注（Margin Notes） */
.term-ref {
  border-bottom: 1.5px dotted var(--accent);
  cursor: help;
  transition: background-color 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

.term-ref:hover,
.term-ref.is-highlighted {
  background-color: var(--accent-soft);
  border-radius: 3px;
}

.margin-note {
  position: absolute;
  left: calc(100% + 2rem);
  top: 0.15rem;
  width: 235px;
  padding: 0.2rem 0 0.2rem 0.75rem;
  border-left: 2px solid var(--border-color);
  font-size: var(--text-sm);
  line-height: 1.55;
  color: var(--text-secondary);
  transition: border-color 180ms cubic-bezier(0.22, 1, 0.36, 1),
              color 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.margin-note.is-highlighted {
  border-left-color: var(--accent);
  color: var(--text-primary);
}

.margin-note-toggle {
  display: none;
}

.margin-note-title {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.margin-note-body {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.6;
}

.note-pill {
  display: none;
}

/* 移动端旁注弹窗（Bottom Sheet） */
.note-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background-color: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.note-modal-backdrop[hidden] {
  display: none;
}

.note-modal-backdrop.is-open {
  opacity: 1;
}

.note-modal-sheet {
  width: 100%;
  max-width: 540px;
  max-height: 75vh;
  overflow-y: auto;
  background-color: var(--bg-page);
  color: var(--text-primary);
  border-top: 1px solid var(--border-color);
  border-radius: 16px 16px 0 0;
  padding: 1.15rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.14);
  transform: translateY(18px);
  transition: transform 200ms cubic-bezier(0.22, 1, 0.36, 1);
}

.note-modal-backdrop.is-open .note-modal-sheet {
  transform: translateY(0);
}

.note-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.note-modal-title {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--text-primary);
}

.note-modal-close {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 1.15rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.note-modal-body {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.75;
  color: var(--text-secondary);
}

.note-modal-body strong {
  color: var(--text-primary);
  font-weight: 600;
}

.para-group p {
  margin: 0;
  font-size: var(--text-body);
  line-height: 1.8;
}

.para-group strong {
  font-weight: 600;
  color: var(--text-primary);
}

.article-body a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: opacity 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

.article-body a:hover {
  opacity: 0.78;
}

.en {
  display: none;
}

html[data-lang-mode="bilingual"] .en {
  display: block;
}

html[data-lang-mode="bilingual"] .para-group .en {
  margin-top: 0.55rem;
  padding-left: 0.875rem;
  border-left: 2px solid var(--border-color);
  color: var(--text-secondary);
  line-height: 1.7;
}

.checklist {
  list-style: none;
  margin: 1.25rem 0 1.75rem;
  padding: 0;
  border-top: 1px solid var(--border-color);
}

.checklist-item {
  border-bottom: 1px solid var(--border-color);
}

.checklist-label {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 0.9rem 0.25rem;
  cursor: pointer;
}

.checklist-input {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.35rem;
  border: 1.5px solid var(--text-secondary);
  border-radius: 4px;
  background-color: transparent;
  cursor: pointer;
  position: relative;
  transition: background-color 150ms cubic-bezier(0.22, 1, 0.36, 1),
              border-color 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

.checklist-input:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}

.checklist-input:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

html[data-theme="dark"] .checklist-input:checked::after {
  border-color: #0f1419;
}

.checklist-text {
  display: block;
  font-size: var(--text-body);
  line-height: 1.75;
}

.checklist-text .zh,
.checklist-text .en {
  display: block;
}

html[data-lang-mode="zh"] .checklist-text .en {
  display: none;
}

html[data-lang-mode="bilingual"] .checklist-text .en {
  margin-top: 0.35rem;
  color: var(--text-secondary);
  font-size: var(--text-body);
}

.checklist-input:checked + .checklist-text .zh {
  color: var(--text-secondary);
  text-decoration: line-through;
  text-decoration-color: var(--border-color);
}

.diagram-figure {
  margin: 2rem 0 0;
  background-color: #ffffff;
  padding: 1rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.diagram-figure img {
  border: none;
  border-radius: 4px;
}

.article-footer {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem 1.5rem;
}

.footer-note {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.footer-note a,
.footer-home-link {
  color: var(--accent);
  text-decoration: none;
  font-size: var(--text-sm);
}

.footer-note a:hover,
.footer-home-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 响应式适配：宽度 >= 980px 时旁注始终显示在右侧空白栏；仅在窄屏/手机端收拢 */
@media (max-width: 1120px) {
  .page-shell {
    grid-template-columns: minmax(0, 62ch) 230px;
    justify-content: center;
  }

  .toc-rail {
    display: none;
  }

  .article-container {
    grid-column: 1;
  }
}

@media (max-width: 900px) {
  .page-shell {
    grid-template-columns: minmax(0, 65ch);
    justify-content: center;
    gap: 0;
  }

  .margin-note {
    display: none;
  }

  .term-ref {
    cursor: pointer;
  }

  .note-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: super;
    margin-left: 0.18rem;
    padding: 0 0.32rem;
    height: 1.15rem;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background-color: var(--accent-soft);
    color: var(--accent);
    font-family: var(--font-sans);
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
}

@media (max-width: 720px) {
  .entry-item {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
  }

  .entry-thumb {
    order: -1;
  }
}

@media (max-width: 640px) {
  .header-inner {
    flex-wrap: wrap;
    padding: 0.65rem 1rem;
    gap: 0.55rem 0.75rem;
  }

  .header-brand-group {
    width: 100%;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .brand-title {
    font-size: 1rem;
  }

  .header-controls {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* 首页顶栏只有一组主题按钮时，保持单行对齐 */
  .header-inner > .brand-title {
    flex: 1 1 auto;
  }

  .header-inner > .brand-title + .header-controls {
    width: auto;
    justify-content: flex-end;
  }

  .seg-btn {
    padding: 0.4rem 0.6rem;
  }

  .home-shell,
  .page-shell {
    padding: 1.75rem 1rem 4rem;
  }

  .search-input {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
