/* ============================================================
   述衣·服饰古籍全量通识 — 全局样式
   中国古典古籍国风，素雅庄重
   ============================================================ */

/* --- CSS Variables: 亮色模式 (default) --- */
:root {
  --bg-primary: #f5f0e8;
  --bg-secondary: #ece5d5;
  --bg-header: #3c2415;
  --bg-nav: #5a3a24;
  --bg-nav-active: #7a5030;
  --bg-footer: #3c2415;
  --bg-card: #faf7f0;
  --bg-hover: #e8dfc8;
  --bg-tab-active: #f5f0e8;
  --bg-tab-inactive: #ddd5c3;
  --bg-search-input: #fff;
  --bg-highlight: #fff3cd;

  --text-primary: #3c2415;
  --text-secondary: #6b5340;
  --text-header: #f5f0e8;
  --text-nav: #f0e6d2;
  --text-nav-hover: #ffd700;
  --text-footer: #d4c4a8;
  --text-muted: #9a8a70;
  --text-link: #8b4513;
  --text-link-hover: #a0522d;
  --text-highlight: #c0392b;
  --text-tab-active: #3c2415;
  --text-tab-inactive: #8a7a65;

  --border-primary: #b8a080;
  --border-secondary: #d4c4a8;
  --border-table: #c0a878;
  --border-header: #5a3a24;

  --shadow-light: rgba(60, 36, 21, 0.08);
  --shadow-medium: rgba(60, 36, 21, 0.15);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --font-song: "Songti SC", "Songti TC", "SimSun", "Noto Serif CJK SC", "Noto Serif SC", serif;
  --font-size-base: 16px;
  --line-height-base: 1.85;
  --max-width: 1200px;
}

/* --- CSS Variables: 暗色模式 --- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1a120a;
    --bg-secondary: #2a1f14;
    --bg-header: #0f0a05;
    --bg-nav: #2a1f14;
    --bg-nav-active: #4a3525;
    --bg-footer: #0f0a05;
    --bg-card: #241a10;
    --bg-hover: #3a2a1a;
    --bg-tab-active: #1a120a;
    --bg-tab-inactive: #2a1f14;
    --bg-search-input: #2a1f14;
    --bg-highlight: #4a3520;

    --text-primary: #e8dcc8;
    --text-secondary: #c4b498;
    --text-header: #f0e6d2;
    --text-nav: #d4c4a8;
    --text-nav-hover: #ffd700;
    --text-footer: #8a7a65;
    --text-muted: #7a6a55;
    --text-link: #d4a574;
    --text-link-hover: #e8c49a;
    --text-highlight: #ff6b6b;
    --text-tab-active: #e8dcc8;
    --text-tab-inactive: #7a6a55;

    --border-primary: #4a3a28;
    --border-secondary: #3a2a1a;
    --border-table: #5a4a35;
    --border-header: #2a1f14;

    --shadow-light: rgba(0, 0, 0, 0.2);
    --shadow-medium: rgba(0, 0, 0, 0.35);
  }
}

/* --- 强制暗色模式类 --- */
[data-theme="dark"] {
  --bg-primary: #1a120a;
  --bg-secondary: #2a1f14;
  --bg-header: #0f0a05;
  --bg-nav: #2a1f14;
  --bg-nav-active: #4a3525;
  --bg-footer: #0f0a05;
  --bg-card: #241a10;
  --bg-hover: #3a2a1a;
  --bg-tab-active: #1a120a;
  --bg-tab-inactive: #2a1f14;
  --bg-search-input: #2a1f14;
  --bg-highlight: #4a3520;
  --text-primary: #e8dcc8;
  --text-secondary: #c4b498;
  --text-header: #f0e6d2;
  --text-nav: #d4c4a8;
  --text-nav-hover: #ffd700;
  --text-footer: #8a7a65;
  --text-muted: #7a6a55;
  --text-link: #d4a574;
  --text-link-hover: #e8c49a;
  --text-highlight: #ff6b6b;
  --text-tab-active: #e8dcc8;
  --text-tab-inactive: #7a6a55;
  --border-primary: #4a3a28;
  --border-secondary: #3a2a1a;
  --border-table: #5a4a35;
  --border-header: #2a1f14;
  --shadow-light: rgba(0, 0, 0, 0.2);
  --shadow-medium: rgba(0, 0, 0, 0.35);
}

/* --- 基础重置 --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: var(--font-size-base);
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-song);
  line-height: var(--line-height-base);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color 0.2s ease;
}
a:hover {
  color: var(--text-link-hover);
  text-decoration: underline;
}

/* ============================================================
   页头 Header
   ============================================================ */
.site-header {
  background: var(--bg-header);
  color: var(--text-header);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 8px var(--shadow-medium);
}

.site-title {
  text-align: center;
  padding: 18px 20px 10px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text-header);
}

.site-title a {
  color: inherit;
  text-decoration: none;
}
.site-title a:hover {
  text-decoration: none;
  opacity: 0.9;
}

/* ============================================================
   全局导航栏 Nav
   ============================================================ */
.site-nav {
  background: var(--bg-nav);
  border-top: 1px solid rgba(255,255,255,0.08);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.site-nav::-webkit-scrollbar {
  height: 3px;
}
.site-nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
}

.nav-list {
  display: flex;
  list-style: none;
  justify-content: center;
  flex-wrap: nowrap;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0;
}

.nav-item a {
  display: block;
  padding: 12px 20px;
  color: var(--text-nav);
  font-size: 0.95rem;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  letter-spacing: 0.08em;
}

.nav-item a:hover,
.nav-item a:active,
.nav-item a:focus {
  color: var(--text-nav);
  text-decoration: none;
}

.nav-item.active a {
  color: var(--text-nav-hover);
  border-bottom-color: var(--text-nav-hover);
  background: rgba(255,255,255,0.08);
}

/* ============================================================
   主内容区 Main
   ============================================================ */
.site-main {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 30px 24px;
}

/* ============================================================
   页脚 Footer
   ============================================================ */
.site-footer {
  background: var(--bg-footer);
  color: var(--text-footer);
  text-align: center;
  padding: 20px;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  margin-top: auto;
}

/* ============================================================
   索引页 Index
   ============================================================ */
.breadcrumb {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-secondary);
}
.breadcrumb a {
  color: var(--text-secondary);
}

.index-title {
  font-size: 1.5rem;
  color: var(--text-primary);
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border-primary);
  letter-spacing: 0.08em;
}

.index-section {
  margin-bottom: 32px;
}

.index-section-title {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
  padding-left: 12px;
  border-left: 4px solid var(--border-primary);
}

.index-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

.index-list li {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.index-list li:hover {
  background: var(--bg-hover);
  border-color: var(--border-primary);
  box-shadow: 0 2px 6px var(--shadow-light);
}

.index-list li a {
  display: block;
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.index-list li a:hover {
  text-decoration: none;
}

/* ============================================================
   书籍内容页 Tab 导航
   ============================================================ */
.book-tabs {
  display: flex;
  border-bottom: 2px solid var(--border-primary);
  margin-bottom: 24px;
  gap: 4px;
}

.book-tab {
  padding: 10px 24px;
  font-size: 0.95rem;
  color: var(--text-tab-inactive);
  background: var(--bg-tab-inactive);
  border: 1px solid var(--border-secondary);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  letter-spacing: 0.05em;
}

.book-tab:hover {
  color: var(--text-tab-active);
  background: var(--bg-hover);
  text-decoration: none;
}

.book-tab.active {
  color: var(--text-tab-active);
  background: var(--bg-tab-active);
  border-color: var(--border-primary);
  border-bottom: 2px solid var(--bg-tab-active);
  margin-bottom: -2px;
  font-weight: 600;
}

/* ============================================================
   MD 内容渲染
   ============================================================ */
.md-content {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  padding: 28px 32px;
  box-shadow: 0 1px 4px var(--shadow-light);
}

.md-content h1, .md-content h2, .md-content h3,
.md-content h4, .md-content h5, .md-content h6 {
  color: var(--text-primary);
  margin-top: 1.5em;
  margin-bottom: 0.6em;
  line-height: 1.4;
  letter-spacing: 0.05em;
}

.md-content h1 {
  font-size: 1.7rem;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border-primary);
}

.md-content h2 {
  font-size: 1.35rem;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-secondary);
}

.md-content h3 { font-size: 1.15rem; }
.md-content h4 { font-size: 1.05rem; }

.md-content p {
  margin-bottom: 1em;
  text-align: justify;
}

.md-content ul, .md-content ol {
  margin: 0.6em 0;
  padding-left: 2em;
}

.md-content li {
  margin-bottom: 0.3em;
}

.md-content blockquote {
  margin: 1em 0;
  padding: 12px 20px;
  border-left: 4px solid var(--border-primary);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.md-content pre {
  margin: 1em 0;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}

.md-content code {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.88em;
}

.md-content pre code {
  background: none;
  padding: 0;
}

.md-content hr {
  border: none;
  border-top: 1px solid var(--border-primary);
  margin: 2em 0;
}

.md-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

/* --- 表格：100% 无损还原 --- */
.md-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.92rem;
}

.md-content thead {
  background: var(--bg-secondary);
}

.md-content th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  border: 1px solid var(--border-table);
  color: var(--text-primary);
  white-space: nowrap;
}

.md-content td {
  padding: 9px 14px;
  border: 1px solid var(--border-table);
  vertical-align: top;
}

.md-content tr:nth-child(even) {
  background: var(--bg-secondary);
}

.md-content tr:hover {
  background: var(--bg-hover);
}

/* ============================================================
   搜索页 Search
   ============================================================ */
.search-box {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 1px 4px var(--shadow-light);
}

.search-form {
  display: flex;
  gap: 12px;
  align-items: center;
}

.search-input {
  flex: 1;
  padding: 12px 18px;
  font-size: 1rem;
  font-family: var(--font-song);
  border: 2px solid var(--border-primary);
  border-radius: var(--radius-sm);
  background: var(--bg-search-input);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

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

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

.search-btn {
  padding: 12px 28px;
  font-size: 1rem;
  font-family: var(--font-song);
  background: var(--bg-nav);
  color: var(--text-nav);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  letter-spacing: 0.08em;
}

.search-btn:hover {
  background: var(--bg-nav-active);
}

.search-tips {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.search-tips code {
  background: var(--bg-secondary);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}

/* --- 搜索结果 --- */
.search-meta {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-secondary);
}

.search-result-item {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.search-result-item:hover {
  border-color: var(--border-primary);
}

.search-result-title {
  font-size: 1.05rem;
  margin-bottom: 6px;
}

.search-result-title a {
  color: var(--text-link);
  font-weight: 600;
}

.search-result-path {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.search-result-snippets {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.search-result-snippets .snippet-line {
  padding: 4px 0;
  border-bottom: 1px dashed var(--border-secondary);
}

.search-result-snippets .snippet-line:last-child {
  border-bottom: none;
}

.search-result-snippets mark,
.search-highlight {
  color: var(--text-highlight);
  background: var(--bg-highlight);
  padding: 1px 3px;
  border-radius: 2px;
  font-weight: 600;
}

/* --- 分页 --- */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border-secondary);
}

.pagination a, .pagination span {
  padding: 8px 14px;
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: all 0.2s;
}

.pagination a:hover {
  background: var(--bg-hover);
  border-color: var(--border-primary);
  text-decoration: none;
}

.pagination .current {
  background: var(--bg-nav);
  color: var(--text-nav);
  border-color: var(--bg-nav);
}

.pagination .disabled {
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}

/* ============================================================
   搜索历史
   ============================================================ */
.search-history {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-secondary);
}

.search-history-title {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.search-history-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.search-history-tag {
  display: inline-block;
  padding: 4px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.search-history-tag:hover {
  background: var(--bg-hover);
  border-color: var(--border-primary);
  color: var(--text-primary);
  text-decoration: none;
}

/* ============================================================
   主题切换按钮
   ============================================================ */
.theme-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-nav);
  color: var(--text-nav);
  border: 2px solid var(--border-primary);
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px var(--shadow-medium);
  transition: all 0.2s;
  z-index: 999;
}

.theme-toggle:hover {
  transform: scale(1.1);
  background: var(--bg-nav-active);
}

/* ============================================================
   面包屑导航 / 返回上级
   ============================================================ */
.back-link {
  display: inline-block;
  margin-bottom: 16px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}
.back-link:hover {
  color: var(--text-link);
}

/* ============================================================
   空状态
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 1rem;
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 768px) {
  .site-title {
    font-size: 1.2rem;
    padding: 14px 16px 8px;
  }

  .nav-list {
    justify-content: flex-start;
    padding: 0 8px;
  }

  .nav-item a {
    padding: 10px 14px;
    font-size: 0.88rem;
  }

  .site-main {
    padding: 20px 14px;
  }

  .md-content {
    padding: 18px 16px;
  }

  .index-list {
    grid-template-columns: 1fr;
  }

  .search-form {
    flex-direction: column;
  }

  .search-input {
    width: 100%;
  }

  .search-btn {
    width: 100%;
  }

  .book-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .book-tab {
    padding: 8px 16px;
    font-size: 0.88rem;
    white-space: nowrap;
  }

  .md-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .md-content thead,
  .md-content tbody,
  .md-content tr {
    display: table;
    width: 100%;
    table-layout: fixed;
  }

  .theme-toggle {
    bottom: 16px;
    right: 16px;
    width: 38px;
    height: 38px;
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .site-title {
    font-size: 1rem;
    letter-spacing: 0.08em;
  }

  .nav-item a {
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .index-list li a {
    padding: 10px 12px;
    font-size: 0.88rem;
  }
}
