:root {
  --bg: #fdf6ee;
  --card-bg: #fffaf3;
  --text: #3e3232;
  --text-secondary: #8b7e74;
  --accent: #c7925a;
  --accent-light: #e8d5c0;
  --border: #e3d4c0;
  --sidebar-bg: #faf3ea;
  --hover: #f5e8d8;
  --active: #edddc8;
  --shadow: 0 2px 12px rgba(139, 126, 116, 0.1);
  --font-main: 'PingFang SC', 'Hiragino Sans GB', 'Noto Serif SC', 'Source Han Serif SC', 'Microsoft YaHei', serif;
  --font-size-body: 17px;
  --line-height-body: 2;
}

[data-theme="dark"] {
  --bg: #1e1b18;
  --card-bg: #282420;
  --text: #d4c8bc;
  --text-secondary: #8b8076;
  --accent: #d4a06a;
  --accent-light: #4a3e32;
  --border: #3a322a;
  --sidebar-bg: #24211c;
  --hover: #322c24;
  --active: #4a3e32;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ====== Sidebar ====== */
.sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
  letter-spacing: 0.05em;
}

.sidebar-header .subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.search-box {
  margin-top: 14px;
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-main);
  outline: none;
  transition: border-color 0.2s;
}

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

.search-box .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 13px;
  pointer-events: none;
}

.article-count {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.article-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0;
}

.article-list::-webkit-scrollbar { width: 5px; }
.article-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.article-item {
  padding: 13px 20px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.article-item:hover { background: var(--hover); }
.article-item.active {
  background: var(--active);
  border-left-color: var(--accent);
}

.article-item .item-index {
  font-size: 12px;
  color: var(--text-secondary);
  margin-right: 8px;
}

.article-item .item-title {
  font-size: 14px;
  line-height: 1.55;
}

/* ====== Theme toggle ====== */
.theme-toggle {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle a {
  text-decoration: none;
  display: inline-flex;
}

.theme-toggle button {
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-main);
  transition: background 0.2s;
}

.theme-toggle button:hover { background: var(--active); }

/* ====== Main content ====== */
.main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 48px 64px 80px;
}

.main::-webkit-scrollbar { width: 6px; }
.main::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ====== Welcome screen ====== */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-secondary);
  user-select: none;
}

.welcome .icon {
  font-size: 72px;
  margin-bottom: 20px;
  opacity: 0.45;
}

.welcome h2 {
  font-size: 24px;
  color: var(--text);
  margin-bottom: 10px;
  font-weight: 600;
}

.welcome p {
  font-size: 15px;
  line-height: 1.7;
  max-width: 380px;
}

/* ====== Article content ====== */
.article-content {
  max-width: 740px;
  margin: 0 auto;
}

.article-content h1 {
  font-size: 28px;
  line-height: 1.55;
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--accent-light);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.03em;
}

.article-content .meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 36px;
}

.article-content .body {
  font-size: var(--font-size-body);
  line-height: var(--line-height-body);
  letter-spacing: 0.015em;
}

.article-content .body p {
  margin-bottom: 1.3em;
  text-indent: 2em;
}

.article-content .body p:first-of-type { text-indent: 0; }

.article-content .body strong {
  color: var(--accent);
  font-weight: 600;
}

.article-content .body em {
  color: var(--text-secondary);
  font-style: italic;
}

.article-content .body blockquote {
  border-left: 3px solid var(--accent-light);
  padding: 10px 18px;
  margin: 18px 0;
  background: var(--card-bg);
  border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.article-content .body hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 28px 0;
}

.article-content .body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-light);
  transition: border-color 0.2s;
}
.article-content .body a:hover { border-bottom-color: var(--accent); }

.article-content .body ul,
.article-content .body ol {
  margin: 14px 0 14px 1.8em;
}

.article-content .body li {
  margin-bottom: 8px;
}

.article-content .body img {
  max-width: 100%;
  border-radius: 8px;
  margin: 20px 0;
  box-shadow: var(--shadow);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 240px;
  color: var(--text-secondary);
  font-size: 15px;
  letter-spacing: 0.05em;
}

/* Spinner */
.loading::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin-right: 12px;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.no-results {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ====== Mobile menu button ====== */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 20;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  font-size: 16px;
  box-shadow: var(--shadow);
  font-family: var(--font-main);
}

/* ====== Back to top ====== */
.back-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 20px;
  box-shadow: var(--shadow);
  transition: background 0.2s, color 0.2s;
  z-index: 5;
}
.back-top:hover { background: var(--hover); color: var(--accent); }
.back-top.visible { display: flex; }

/* ====== Responsive ====== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    z-index: 15;
    width: 100%;
    min-width: 100%;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .main {
    padding: 72px 20px 60px;
  }

  .mobile-menu-btn { display: flex; }

  .article-content { max-width: 100%; }
  .article-content h1 { font-size: 22px; }
  .article-content .body { font-size: 16px; line-height: 1.9; }

  .back-top {
    bottom: 20px;
    right: 16px;
    width: 38px;
    height: 38px;
  }
}

/* Print styles */
@media print {
  .sidebar, .mobile-menu-btn, .back-top, .theme-toggle { display: none !important; }
  .main { padding: 0; overflow: visible; }
  body { display: block; background: white; color: black; }
}
