:root {
  --page-max: 920px;
  --page-pad-x: 24px;
  --page-pad-y: 24px;
  --page-gap: 24px;
  --text: #2a1f0e;
  --muted: #6b5a42;
  --line: #d9cdb8;
  /* 笔记纸底色与格线 */
  --paper-bg: #fdf8ec;
  --paper-rule: rgba(160, 140, 100, 0.18);
  --paper-grid: rgba(160, 140, 100, 0.10);
  --paper-rule-spacing: 28px;
  /**
   * 有网：Inter（拉丁）+ Noto Sans SC（补中文，外链见 render 中 Google Fonts）
   * 无网/外链失败：不加载 webfont 时，浏览器跳过未解析名称，用后续系统无衬线
   */
  --font-sans: "Inter", "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  /* 行内/块 <code> 等；无 Source Code Pro 时走系统等宽 */
  --font-mono: "Source Code Pro", Menlo, Monaco, Consolas, "Courier New", monospace;
}
html {
  margin: 0;
  padding: 0;
  background: var(--paper-bg);
  color: var(--text);
  font-family: var(--font-sans);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  padding: 0;
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.7;
  overflow-x: hidden;
  /* 笔记纸纹理：竖向 + 横向格线，横线更淡 */
  background-color: var(--paper-bg);
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent calc(var(--paper-rule-spacing) - 1px),
      var(--paper-grid) calc(var(--paper-rule-spacing) - 1px),
      var(--paper-grid) var(--paper-rule-spacing)
    ),
    repeating-linear-gradient(
      180deg,
      transparent,
      transparent calc(var(--paper-rule-spacing) - 1px),
      rgba(160, 140, 100, 0.07) calc(var(--paper-rule-spacing) - 1px),
      rgba(160, 140, 100, 0.07) var(--paper-rule-spacing)
    );
}
code,
kbd,
samp {
  font-family: var(--font-mono);
}
main {
  width: min(100%, var(--page-max));
  margin: 0 auto;
  padding: var(--page-pad-y) var(--page-pad-x) 32px;
  box-sizing: border-box;
}
.site-footer {
  width: min(100%, var(--page-max));
  margin: 0 auto;
  padding: 20px var(--page-pad-x) 28px;
  box-sizing: border-box;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
}
.site-footer p {
  margin: 0;
  line-height: 1.6;
}
.site-footer p.site-footer-geo {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--muted);
  word-break: break-word;
}
header.site-header {
  margin-bottom: var(--page-gap);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.site-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.site-titles {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}
.site-title-link {
  text-decoration: none;
  color: inherit;
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1.2;
}
.site-title-en {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.site-logo {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  object-fit: contain;
  cursor: pointer;
  /* 让 logo 白底融入纸张背景 */
  mix-blend-mode: multiply;
}
.admin-gate {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
  box-sizing: border-box;
}
.admin-gate[hidden] {
  display: none !important;
}
.admin-gate-panel {
  background: var(--paper-bg);
  padding: 16px 18px;
  border-radius: 6px;
  border: 1px solid #c8b99a;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: min(100%, 420px);
  box-sizing: border-box;
}
.admin-gate-panel input[type="password"] {
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
}
h1,
h2,
h3 {
  line-height: 1.3;
  margin: 0 0 12px;
  word-break: break-word;
}
article,
section {
  margin: 0 0 24px;
}
p {
  margin: 0 0 12px;
  word-break: break-word;
}
a {
  color: inherit;
}
input,
textarea,
button {
  font: inherit;
  max-width: 100%;
}
input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
}
textarea {
  min-height: 320px;
  resize: vertical;
}
pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}
img {
  max-width: 100%;
  height: auto;
}
hr {
  border: 0;
  border-top: 1px solid #d4c5a8;
  margin: 24px 0;
}
.post-card {
  padding-bottom: 16px;
  border-bottom: 1px solid #e4d9c4;
}
.post-card:last-of-type {
  padding-bottom: 0;
  border-bottom: 0;
}
.post-card .post-excerpt {
  margin: 0 0 10px;
}
.post-card .post-meta {
  font-size: 0.9em;
  color: #555;
  margin: 0 0 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}
.post-detail-meta {
  font-size: 0.95em;
  color: #555;
  margin: 0 0 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}
.post-detail-views {
  color: #666;
}
.post-comments {
  margin-top: 36px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.post-comments__title {
  font-size: 1.35rem;
  margin: 0 0 16px;
}
form {
  margin: 0;
}
@media (max-width: 1024px) {
  :root {
    --page-max: 840px;
    --page-pad-x: 20px;
    --page-pad-y: 20px;
    --page-gap: 20px;
  }
}
@media (max-width: 768px) {
  :root {
    --page-max: 100%;
    --page-pad-x: 16px;
    --page-pad-y: 16px;
    --page-gap: 18px;
  }
  .site-logo {
    width: 36px;
    height: 36px;
  }
  .site-title-link {
    font-size: 1.1rem;
  }
  .post-card .post-meta,
  .post-detail-meta {
    gap: 6px 12px;
  }
}
@media (max-width: 480px) {
  :root {
    --page-pad-x: 14px;
    --page-pad-y: 14px;
    --page-gap: 16px;
  }
  body {
    line-height: 1.68;
  }
  header.site-header {
    padding-bottom: 12px;
  }
  textarea {
    min-height: 240px;
  }
  .site-brand {
    gap: 10px;
    align-items: flex-start;
  }
  .site-logo {
    width: 32px;
    height: 32px;
  }
  .site-title-link {
    font-size: 1rem;
  }
  .post-card .post-meta,
  .post-detail-meta {
    font-size: 0.82em;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 10px;
    row-gap: 4px;
  }
  .post-card .post-meta span,
  .post-detail-meta span {
    white-space: nowrap;
  }
  .admin-gate-panel {
    padding: 14px 14px;
  }
}

/* ----- 文章页布局 ----- */
main:has(.post-with-toc),
body:has(.post-with-toc) .site-footer {
  width: min(100%, 920px);
  max-width: 920px;
}
.post-with-toc {
  display: block;
  width: 100%;
}
.post-with-toc__main {
  min-width: 0;
  width: min(100%, 720px);
  margin: 0 auto;
}
/* ═══ 桌面端目录（≥1181px）═══════════════════════════════════ */
.post-toc {
  position: fixed;
  top: 96px;
  right: max(14px, calc((100vw - 1400px) / 2));
  z-index: 20;
  width: 260px;
  max-width: min(30vw, 260px);
  transition: opacity 0.18s ease, visibility 0.18s ease;
}
.post-toc--hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}
.post-toc__inner {
  box-sizing: border-box;
  max-height: calc(100vh - 128px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.post-toc__title {
  margin: 0 0 10px;
  font-size: 0.75rem;
  font-weight: 500;
  color: #888;
}
.post-toc__nav {
  position: relative;
  margin: 0;
  border-left: 1px solid #d4c5a8;
  padding-left: 14px;
}

/* 桌面：≤1180px 完全隐藏 aside */
@media (max-width: 1180px) {
  .post-toc {
    display: none;
  }
  main:has(.post-with-toc),
  body:has(.post-with-toc) .site-footer {
    width: min(100%, var(--page-max));
    max-width: var(--page-max);
  }
}

/* ═══ 公共目录列表样式（桌面 & 移动端共用类名）══════════════ */
.toc-tree,
.toc-sub {
  list-style: none;
  margin: 0;
  padding: 0;
}
.toc-sub {
  margin-top: 2px;
  margin-bottom: 2px;
  padding-left: 10px;
}
.toc-item {
  margin: 0;
}
.toc-link {
  display: block;
  position: relative;
  padding: 5px 0 6px;
  font-size: 0.88rem;
  line-height: 1.5;
  text-decoration: none;
  color: #777;
}
.toc-sub .toc-link {
  color: #999;
  font-size: 0.82rem;
}
.toc-link:hover,
.toc-sub .toc-link:hover {
  color: #111;
}
.toc-link--active {
  color: #111;
  font-weight: 500;
}
/* 桌面目录：当前项左侧指示条 */
.post-toc__nav .toc-link--active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 0.15em;
  bottom: 0.15em;
  width: 2px;
  background: #111;
  border-radius: 0;
}

/* ═══ 移动端 FAB（JS append 到 body，≤1180px 显示）═════════ */
#toc-fab {
  display: none;
}
@media (max-width: 1180px) {
  #toc-fab {
    display: inline-flex;
    position: fixed;
    right: 20px;
    bottom: calc(22px + env(safe-area-inset-bottom));
    z-index: 50;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(160, 130, 80, 0.25);
    border-radius: 50%;
    background: rgba(253, 248, 236, 0.97);
    box-shadow: 0 6px 20px rgba(100, 80, 40, 0.16);
    color: #333;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.18s, visibility 0.18s, transform 0.18s;
  }
  #toc-fab.toc-fab--hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.85);
  }
  /* 汉堡线 */
  .toc-fab__icon {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 18px;
    transition: gap 0.18s;
  }
  .toc-fab__icon span {
    display: block;
    height: 2px;
    width: 18px;
    background: currentColor;
    border-radius: 2px;
    transition: transform 0.18s, opacity 0.18s, width 0.18s;
    transform-origin: center;
  }
  /* 打开状态 → X 形 */
  #toc-fab.toc-fab--open .toc-fab__icon {
    gap: 0;
  }
  #toc-fab.toc-fab--open .toc-fab__icon span:nth-child(1) {
    transform: translateY(2px) rotate(45deg);
  }
  #toc-fab.toc-fab--open .toc-fab__icon span:nth-child(2) {
    opacity: 0;
    width: 0;
  }
  #toc-fab.toc-fab--open .toc-fab__icon span:nth-child(3) {
    transform: translateY(-2px) rotate(-45deg);
  }
}

/* ═══ 移动端弹出面板（JS append 到 body，≤1180px 显示）══════ */
#toc-panel {
  display: none;
}
@media (max-width: 1180px) {
  #toc-panel {
    display: block;
    position: fixed;
    right: 16px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    z-index: 49;
    width: min(300px, calc(100vw - 32px));
    max-height: min(60vh, 440px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    padding: 14px 16px 16px;
    background: rgba(253, 248, 236, 0.98);
    border: 1px solid rgba(160, 130, 80, 0.2);
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(100, 80, 40, 0.18);
    /* 默认隐藏 */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(10px) scale(0.97);
    transform-origin: bottom right;
    transition: opacity 0.16s ease, visibility 0.16s ease, transform 0.16s ease;
  }
  #toc-panel.toc-panel--open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
  }
  .toc-panel__title {
    margin: 0 0 8px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #888;
  }
  /* 移动端面板：当前项左侧指示条 */
  #toc-panel .toc-link--active::before {
    content: "";
    position: absolute;
    left: -14px;
    top: 0.15em;
    bottom: 0.15em;
    width: 2px;
    background: #111;
    border-radius: 0;
  }
  #toc-panel .toc-tree {
    border-left: 1px solid #d4c5a8;
    padding-left: 14px;
  }
  #toc-panel .toc-link {
    font-size: 0.9rem;
    padding: 6px 0 7px;
  }
  #toc-panel .toc-sub .toc-link {
    font-size: 0.84rem;
  }
}

/* React：可点击 Logo 用于后台入口 */
.admin-gate-logo-btn {
  all: unset;
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ═══ cwd-widget 评论区覆盖：融入纸张主题 ═══════════════════ */
#comments > div,
#comments .cwd-widget,
#comments [class*="card"],
#comments [class*="form-wrap"],
#comments [class*="comment-form"],
#comments [class*="CommentForm"],
#comments form {
  background: var(--paper-bg) !important;
  border-color: var(--line) !important;
  box-shadow: 0 2px 12px rgba(100, 80, 40, 0.1) !important;
}
#comments input[type="text"],
#comments input[type="email"],
#comments input[type="url"],
#comments textarea {
  background: rgba(255, 252, 240, 0.8) !important;
  border-color: #c8b99a !important;
  color: var(--text) !important;
}
#comments input[type="text"]:focus,
#comments input[type="email"]:focus,
#comments input[type="url"]:focus,
#comments textarea:focus {
  border-color: #a08060 !important;
  outline: none !important;
  box-shadow: 0 0 0 2px rgba(160, 128, 96, 0.2) !important;
}
#comments [class*="comment-item"],
#comments [class*="CommentItem"],
#comments [class*="comment-card"] {
  background: rgba(255, 252, 240, 0.6) !important;
  border-color: var(--line) !important;
}
/* 兜底：widget 内所有白色背景块 */
#comments > div[style*="background"],
#comments > div > div[style*="background:#fff"],
#comments > div > div[style*="background: #fff"],
#comments > div > div[style*="background:white"],
#comments > div > div[style*="background: white"] {
  background: var(--paper-bg) !important;
}
