/* general-css/general.css */
@import url('https://fonts.googleapis.com/css2?family=Noticia+Text:ital,wght@0,400;0,700;1,400;1,700&display=swap');

:root {
  --c-bg-outer: #ececec;
  --c-bg-paper: #ededed;
  --c-text-muted: #777777;
  --c-text-main: #4a4a4a;
  --c-accent-light: #db9780;
  --c-accent-dark: #bd1a1a;
  --c-text-strong: #212121;
  
  /* 
   * 跨平台字体栈 (Cross-platform font stacks)
   * 顺序原则：西文 -> 苹果系统 -> 微软系统 -> 安卓/Linux -> 兜底
   */
  --font-serif: "Noticia Text", "Georgia", "Times New Roman", "Times", /* 西文衬线 */
                "Songti SC", "STSong", "PingFang SC", "PingFang TC", /* macOS/iOS 中文衬线与兜底 */
                "Noto Serif CJK SC", "Noto Serif SC", "Source Han Serif SC", "Source Han Serif CN", /* Linux/Android 衬线 */
                "SimSun", "NSimSun", "FangSong", /* Windows 衬线 */
                serif;
                
  --font-sans: -apple-system, BlinkMacSystemFont, /* macOS/iOS 系统默认 */
               "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", /* 西文无衬线 */
               "PingFang SC", "Hiragino Sans GB", /* macOS/iOS 中文无衬线 */
               "Microsoft YaHei", "Microsoft YaHei UI", /* Windows 中文无衬线 */
               "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC", "Source Han Sans CN", /* Linux/Android 中文无衬线 */
               "Arial", sans-serif;
}

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

html, body {
  min-height: 100vh;
  margin: 0;
  padding: 0;
  background-color: var(--c-bg-paper); /* Whole page is paper */
}

body {
  color: var(--c-text-main);
  font-family: var(--font-serif);
  line-height: 1.8;
  transition: padding-right 0.3s ease;
  padding-right: 300px; /* Default open on desktop */
}

body.toc-closed {
  padding-right: 0;
}

#workskin {
  max-width: 800px;
  width: 100%;
  padding: 3rem 4rem;
  margin: 0 auto; /* Center horizontally, no vertical margin */
  position: relative;
  color: var(--c-text-main);
}

/* 报头风格 (Preface) */
#preface {
  border-bottom: none; /* Removed the extra straight line */
  padding-bottom: 0;
  margin-bottom: 1rem;
  text-align: center;
}

#preface h1 {
  font-size: 2.5rem;
  font-weight: 900;
  margin: 1rem 0 0.5rem;
  letter-spacing: 1px;
  line-height: 1.3;
  color: var(--c-text-strong);
}

#preface .byline {
  font-family: var(--font-sans);
  font-size: 1.1rem;
  color: var(--c-text-muted);
  margin-bottom: 2rem;
}

#preface .byline a {
  color: var(--c-accent-dark);
  text-decoration: none;
}
#preface .byline a:hover {
  color: var(--c-accent-light);
}

/* 标签信息网格 (Meta Tags) */
details.meta-details {
  margin: 0 auto 2rem;
  border-top: 4px double var(--c-text-strong);
  border-bottom: 1px solid var(--c-text-strong);
  background: var(--c-bg-paper);
}

details.meta-details summary {
  padding: 1rem 1.5rem;
  font-family: var(--font-sans);
  font-weight: bold;
  font-size: 1rem;
  color: var(--c-text-strong);
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  list-style: none;
  text-align: center;
  border-bottom: 1px solid transparent;
}

details.meta-details summary::-webkit-details-marker {
  display: none;
}

details.meta-details summary::before {
  content: "+ ";
}

details.meta-details[open] summary::before {
  content: "- ";
}

details.meta-details[open] summary {
  border-bottom: 1px solid var(--c-text-strong);
}

.meta dl.tags {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.8rem 1.5rem;
  text-align: left;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 1.5rem;
  /* Fallback if JS fails, otherwise details handles the border */
  margin: 0 auto 2rem;
  border-top: 4px double var(--c-text-strong);
  border-bottom: 1px solid var(--c-text-strong);
  background: var(--c-bg-paper);
}

/* When wrapped in details, remove the inner border/shadow/margin */
details.meta-details .meta dl.tags,
details.meta-details dl.tags {
  border: none;
  box-shadow: none;
  border-top: none;
  margin: 0;
  max-width: none;
}

.meta dt {
  font-weight: bold;
  color: var(--c-text-strong);
  text-align: right;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.85rem;
}

.meta dd {
  margin: 0;
  color: var(--c-text-main);
}

.meta dd a {
  color: var(--c-accent-dark);
  text-decoration: none;
  border-bottom: 1px dotted var(--c-accent-dark);
}

.meta dd a:hover {
  color: var(--c-accent-light);
  border-bottom-style: solid;
}

/* Summary / Quote styling */
.meta blockquote.userstuff {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: #7e7e7e;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 1.5rem 2rem;
  margin: 2rem auto 1rem auto; /* Reduced bottom margin */
  text-align: center;
  font-style: italic;
  transition: color 0.3s ease;
}

.meta blockquote.userstuff:hover {
  color: #434343;
}

.meta blockquote.userstuff p {
  margin: 0 0 1rem 0;
  text-indent: 0;
}
.meta blockquote.userstuff p:last-child {
  margin-bottom: 0;
}

/* 章节标题 */
.meta.group .heading {
  font-size: 1.8rem;
  text-align: center;
  color: var(--c-text-strong);
  border-top: 4px double var(--c-text-strong); /* Changed to double line like INDEX */
  border-bottom: 1px solid var(--c-text-strong);
  padding: 1rem 0;
  margin: 1rem 0 2rem; /* Reduced top margin from 4rem to 1rem */
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* 正文排版 */
.userstuff {
  font-size: 1.1rem;
  color: var(--c-text-main);
}

.userstuff p {
  text-align: justify;
  margin-bottom: 1.2em;
  text-indent: 2em;
}

/* 重置特殊元素的缩进 */
.userstuff blockquote p,
.userstuff .tw p {
  text-indent: 0;
}

/* 右侧悬浮目录 (Floating TOC) */
#toc-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 300px;
  height: 100vh;
  background: var(--c-bg-paper);
  border-left: 2px solid var(--c-text-strong);
  box-shadow: -4px 0 0px rgba(0,0,0,0.05);
  font-family: var(--font-serif);
  z-index: 1000;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

body.toc-closed #toc-sidebar {
  transform: translateX(100%);
}

/* Newspaper style toggle button */
#toc-toggle-btn {
  position: absolute;
  left: -42px; /* Width + border */
  top: 2rem;
  width: 40px;
  height: 80px;
  background: var(--c-bg-paper);
  color: var(--c-text-strong);
  border: 2px solid var(--c-text-strong);
  border-right: none;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-family: var(--font-serif);
  font-weight: bold;
  box-shadow: -4px 4px 0px rgba(0,0,0,0.05);
  transition: background 0.2s, color 0.2s;
}

#toc-toggle-btn .toc-btn-icon {
  display: none;
}

#toc-toggle-btn:hover {
  background: var(--c-text-strong);
  color: var(--c-bg-paper);
}

#toc-sidebar .toc-content {
  padding: 2.5rem 0; /* Remove horizontal padding from container */
  overflow-y: auto;
  flex: 1;
}

#toc-sidebar h3 {
  margin-top: 0;
  font-size: 1.8rem; /* 增大两号 (原本是 1.4rem) */
  color: var(--c-text-strong);
  border-bottom: 4px double var(--c-text-strong);
  padding-bottom: 0.8rem;
  margin: 0 2.5rem 2rem 2.5rem; /* Add horizontal margin to match list items */
  text-align: center; /* Keep centered to avoid close button overlap */
  text-transform: uppercase;
  letter-spacing: 2px;
  display: block; /* Use block so border naturally spans 100% */
}

#toc-sidebar ul {
  list-style: none;
  padding: 0 2.5rem; /* Add horizontal padding to the list instead */
  margin: 0;
  counter-reset: chapter;
}

#toc-sidebar li {
  margin-bottom: 1.2rem;
  position: relative;
}

#toc-sidebar a {
  text-decoration: none;
  color: var(--c-text-main);
  transition: all 0.2s;
  display: block;
  padding: 0.5rem 0;
  border-bottom: 1px dotted var(--c-text-muted);
  font-size: 1.05rem;
}

#toc-sidebar a::before {
  counter-increment: chapter;
  content: "CH. " counter(chapter) " \2014 "; /* Changed Vol to CH, used em-dash */
  font-size: 0.85em;
  color: var(--c-text-muted);
  font-family: var(--font-sans);
  text-transform: uppercase;
  margin-right: 0.5rem; /* Ensure consistent spacing after the dash */
}

#toc-sidebar a:hover, #toc-sidebar a.active {
  color: var(--c-accent-dark);
  border-bottom: 1px solid var(--c-accent-dark);
  font-weight: bold;
}

#toc-sidebar a.active::before {
  color: var(--c-accent-dark);
}

/* 响应式设计 */
@media (max-width: 1024px) {
  body {
    padding-right: 0 !important;
  }
  
  #toc-sidebar {
    width: 100vw;
    border-left: none;
  }
  
  /* 当菜单展开时，按钮在左上角，变成关闭按钮 */
  body:not(.toc-closed) #toc-toggle-btn {
    position: absolute;
    left: 1rem;
    top: 1rem;
    width: 40px;
    height: 40px;
    border: 2px solid var(--c-text-strong);
    box-shadow: 4px 4px 0px rgba(0,0,0,0.05);
    z-index: 1001; /* 确保在最上层 */
  }
  
  /* 当菜单收起时，按钮固定在侧边栏左侧边缘外 */
  body.toc-closed #toc-toggle-btn {
    position: absolute;
    left: -28px;
    right: auto;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 60px;
    font-size: 1rem;
    border: 2px solid var(--c-text-strong);
    border-right: none;
    box-shadow: -3px 3px 0px rgba(0,0,0,0.05);
    z-index: 1001; /* 确保在最上层 */
  }
}

@media (max-width: 768px) {
  #workskin {
    padding: 2rem 2.5rem; /* 左右对称的 padding，增加到 2.5rem 约 40px，确保不被 26px 的按钮遮挡 */
    margin: 0 auto;
  }
  .userstuff p {
    text-indent: 0;
  }
  
  /* Mobile Meta Tags Layout */
  .meta dl.tags {
    display: block;
    padding: 1rem;
  }
  .meta dt {
    text-align: left;
    margin-top: 1.2rem;
    border-bottom: 1px dotted var(--c-text-muted);
    padding-bottom: 0.2rem;
  }
  .meta dt:first-child {
    margin-top: 0;
  }
  .meta dd {
    text-align: right;
    margin-top: 0.5rem;
    margin-left: 0;
  }
}
