/* ==========================================
   DND 规则书 - Wikimedia 风格
   ========================================== */

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #202122;
  --text-muted: #54595d;
  --link: #36c;
  --link-hover: #6b8db5;
  --border: #c8ccd1;
  --accent: #f0f6ff;
  --sidebar-w: 260px;
  --header-h: 56px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', 'Noto Sans CJK SC', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

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

/* ==========================================
   HEADER
   ========================================== */
#header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo h1 { font-size: 18px; font-weight: 700; }
.logo h1 a { color: var(--text); }
.logo h1 a:hover { text-decoration: none; }
.tagline { font-size: 12px; color: var(--text-muted); margin-left: 8px; }
#header.compact .tagline { display: none; }

/* Search */
.search-bar { flex: 1; max-width: 500px; position: relative; }
.search-bar input {
  width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  background: var(--bg);
}
.search-bar input:focus {
  outline: none;
  border-color: var(--link);
  background: var(--surface);
}

.search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 4px 4px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.search-results.active { display: block; }
.search-results .sr-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--bg);
  font-size: 13px;
}
.search-results .sr-item:hover { background: var(--accent); }
.search-results .sr-item .sr-path { font-size: 11px; color: var(--text-muted); }

/* ==========================================
   HOME
   ========================================== */
#content {
  max-width: 1000px;
  margin: 40px auto;
  padding: 0 24px;
}

.welcome {
  text-align: center;
  padding: 40px 0;
}
.welcome h2 { font-size: 28px; margin-bottom: 12px; }
.welcome p { font-size: 15px; color: var(--text-muted); max-width: 600px; margin: 0 auto 8px; }

.categories {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin: 32px 0;
}

.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.cat-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.cat-icon { font-size: 32px; margin-bottom: 8px; }
.cat-card h3 { font-size: 16px; margin-bottom: 6px; }
.cat-card p { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.cat-count { font-size: 11px; color: var(--link); }

.stats { text-align: center; padding: 20px; color: var(--text-muted); font-size: 13px; }

/* ==========================================
   READER (Sidebar + Content)
   ========================================== */
#reader {
  display: flex;
  min-height: calc(100vh - var(--header-h) - 60px);
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  height: calc(100vh - var(--header-h));
  position: sticky;
  top: var(--header-h);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: 14px; }

.close-btn, .locate-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 4px;
  border-radius: 3px;
}
.locate-btn:hover {
  background: var(--accent);
  color: var(--link);
}
.close-btn:hover {
  background: var(--accent);
  color: var(--text);
}

#toc { padding: 8px 0; }
#toc .toc-item {
  display: block;
  padding: 4px 16px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#toc .toc-item:hover { background: var(--accent); text-decoration: none; }
#toc .toc-item.active { background: var(--accent); color: var(--link); font-weight: 600; }
#toc .toc-item.l1 { padding-left: 16px; font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
#toc .toc-item.l2 { padding-left: 28px; }
#toc .toc-item.l3 { padding-left: 40px; font-size: 12px; }
#toc .toc-item.l4 { padding-left: 52px; font-size: 12px; color: var(--text-muted); }
#toc .toc-group { font-weight: 600; padding: 5px 12px; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--bg); }
#toc .toc-group .toc-icon { width: 12px; height: 12px; vertical-align: middle; margin-left: 4px; flex-shrink: 0; }
#toc .toc-book-icon { width: 16px; height: 16px; vertical-align: middle; margin-right: 2px; }
#toc .toc-group {
  font-weight: 600;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--bg);
}
#toc .toc-group:hover { background: var(--accent); }
#toc .toc-children { display: none; }
#toc .toc-children.open { display: block; }

.loading { padding: 20px; text-align: center; color: var(--text-muted); }

/* Content Area */
#content-area {
  flex: 1;
  padding: 24px 32px;
  min-width: 0;
}

#menuToggle {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 16px;
}

.page-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 32px 40px;
  min-height: 60vh;
  line-height: 1.8;
}

#pageContent a { color: var(--link) !important; cursor: pointer !important; word-break: break-all !important; overflow-wrap: break-word !important; }
#pageContent a:hover { text-decoration: underline !important; }
.page-content h1 { font-size: 24px; margin: 24px 0 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.page-content h2 { font-size: 20px; margin: 20px 0 10px; }
.page-content h3 { font-size: 17px; margin: 16px 0 8px; }
.page-content p { margin: 8px 0; }
.page-content ul, .page-content ol { margin: 8px 0; padding-left: 24px; }
.page-content table { border-collapse: collapse; width: 100%; margin: 16px 0; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.page-content td, .page-content th { white-space: nowrap; }
.page-content .wide-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 16px 0; }
.page-content .wide-table-wrap table { display: table; width: 100%; margin: 0; }
#pageContent table, #pageContent .inline-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 16px 0; max-width: 100% !important; width: auto !important; }
#pageContent table[style*="WIDTH"], #pageContent table[style*="width"] { max-width: 100% !important; width: auto !important; }
#pageContent { white-space: normal; word-break: break-word; overflow-wrap: break-word; }
#pageContent td { white-space: nowrap; }
#pageContent pre { white-space: pre-wrap; word-break: break-all; }
#pageContent img { max-width: 100%; height: auto; }
#pageContent a { color: var(--link) !important; cursor: pointer !important; word-break: break-all !important; overflow-wrap: break-word !important; }
#pageContent a:hover { text-decoration: underline !important; }
.page-content th, .page-content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; font-size: 13px; }
.page-content th { background: var(--accent); }
.page-content blockquote {
  border-left: 3px solid var(--link);
  padding: 8px 16px;
  margin: 12px 0;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
}
.page-content pre {
  background: #f5f5f5;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 13px;
}

.welcome-page { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.welcome-page h2 { border: none; font-size: 20px; margin-bottom: 12px; }

.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  gap: 12px;
}
.page-nav a {
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
}
.page-nav a:hover { background: var(--accent); text-decoration: none; color: var(--link); }
.page-nav a:only-child { margin-left: auto; }

/* ==========================================
   FOOTER
   ========================================== */
#footer {
  text-align: center;
  padding: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: -260px;
    top: var(--header-h);
    z-index: 50;
    transition: left 0.3s;
    height: calc(100vh - var(--header-h));
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
  }
  #sidebar.open { left: 0; }
  #menuToggle { display: inline-block; }
  #content-area { padding: 16px; }
  .page-content { padding: 20px; }
  .categories { grid-template-columns: 1fr; }
}
