/* ============================================
   common.css — 古文岛共享样式
   包含：基础重置、字体、侧边栏、Hero区、
         内容区、卡片通用、返回顶部、移动端响应
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@300;400;600;700&display=swap');

/* ====== Reset ====== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Noto Serif SC', 'STSong', '宋体', serif;
  background: var(--bg);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  background-image: var(--bg-pattern);
}

/* ====== CSS Variables (book-specific, override in book style) ====== */
:root {
  --bg: #f5f0e6;
  --sidebar-bg: #1a1505;
  --sidebar-hover: #2a2010;
  --accent: #b8832a;
  --accent-light: #e8c06a;
  --accent-dark: #8a5e18;
  --text-primary: #2a1a08;
  --text-secondary: #6b4a20;
  --text-light: #a08050;
  --card-bg: #fffef5;
  --card-border: #e8d8b8;
  --shadow: rgba(80, 50, 10, 0.10);
  --sidebar-width: 230px;
  --bg-pattern: url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23b8832a' fill-opacity='0.03'%3E%3Ccircle cx='40' cy='40' r='20'/%3E%3Ccircle cx='0' cy='0' r='10'/%3E%3Ccircle cx='80' cy='80' r='10'/%3E%3C/g%3E%3C/svg%3E");
}

/* ====== SIDEBAR ====== */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  position: fixed;
  left: 0; top: 0;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

.sidebar-logo {
  padding: 28px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  text-align: center;
}

.sidebar-logo .book-icon {
  font-size: 34px;
  display: block;
  margin-bottom: 10px;
}

.sidebar-logo .book-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-light);
  letter-spacing: 8px;
  display: block;
}

.sidebar-logo .book-author {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  margin-top: 6px;
  letter-spacing: 3px;
}

/* Search */
.search-wrap {
  padding: 12px 14px 8px;
}

.search-input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 3px;
  color: var(--accent-light);
  font-size: 13px;
  padding: 7px 10px;
  font-family: inherit;
  outline: none;
}

.search-input::placeholder { color: rgba(255,255,255,0.2); }
.search-input:focus { border-color: var(--accent-light); }

/* Nav */
.nav-section-title,
.nav-cat-title {
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 5px;
  padding: 12px 16px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.nav-list, .nav-sublist { list-style: none; padding-bottom: 8px; }

.nav-link {
  display: block;
  padding: 6px 16px;
  font-size: 13px;
  color: rgba(255,255,255,0.5);
  text-decoration: none;
  letter-spacing: 2px;
  transition: all 0.18s;
  border-left: 2px solid transparent;
}

.nav-link:hover,
.nav-link.active {
  color: var(--accent-light);
  background: var(--sidebar-hover);
  border-left-color: var(--accent-light);
}

.nav-count {
  font-size: 10px;
  background: rgba(255,255,255,0.1);
  color: var(--accent-light);
  padding: 1px 6px;
  border-radius: 8px;
  min-width: 22px;
  text-align: center;
  margin-left: auto;
}

/* ====== MAIN AREA ====== */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
}

/* ====== HERO ====== */
.page-hero {
  background: linear-gradient(150deg, var(--sidebar-bg) 0%, var(--sidebar-hover) 50%, color-mix(in srgb, var(--sidebar-hover) 70%, white) 100%);
  padding: 60px 60px 50px;
  position: relative;
  overflow: hidden;
}

.page-hero::after {
  content: var(--hero-char, '书');
  position: absolute;
  right: 50px; top: 50%;
  transform: translateY(-50%);
  font-size: 180px;
  color: rgba(255,255,255,0.03);
  font-weight: 700;
  pointer-events: none;
}

.hero-label {
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 6px;
  margin-bottom: 14px;
}

.hero-title {
  font-size: 54px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 16px;
}

.hero-sub {
  font-size: 15px;
  color: rgba(255,255,255,0.35);
  margin-top: 12px;
  letter-spacing: 3px;
}

.hero-quote {
  margin-top: 22px;
  font-size: 15px;
  color: rgba(255,255,255,0.35);
  letter-spacing: 2px;
  line-height: 1.9;
  max-width: 480px;
}

.hero-meta {
  margin-top: 24px;
  display: flex;
  gap: 28px;
}

.hero-meta-item { text-align: center; }

.hero-meta-num {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent-light);
}

.hero-meta-label {
  font-size: 11px;
  color: rgba(255,255,255,0.25);
  letter-spacing: 2px;
  margin-top: 3px;
}

/* ====== CONTENT AREA ====== */
.content-area {
  padding: 40px 50px 80px;
  max-width: 960px;
}

/* ====== SECTION HEADER (道德经/三十六计用) ====== */
.section-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 44px 0 20px;
}

.section-header:first-child { margin-top: 0; }

.section-badge {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 3px;
  padding: 5px 14px;
  border-radius: 2px;
  flex-shrink: 0;
}

.section-title {
  font-size: 20px;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 6px;
  white-space: nowrap;
}

.section-count {
  font-size: 12px;
  color: var(--text-light);
  letter-spacing: 1px;
  white-space: nowrap;
}

.section-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--card-border), transparent);
}

/* ====== CHAPTER CARD (道德经/孙子兵法用) ====== */
.chapter-card, .ch-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 10px var(--shadow);
  margin-bottom: 12px;
  transition: box-shadow 0.2s;
}

.chapter-card:hover, .ch-card:hover {
  box-shadow: 0 4px 18px var(--shadow);
}

.chapter-title-bar, .ch-header {
  background: linear-gradient(135deg, var(--sidebar-bg) 0%, var(--sidebar-hover) 100%);
  padding: 14px 22px;
  display: flex;
  align-items: center;
}

.chapter-title-left, .ch-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chapter-order, .ch-badge, .ji-badge {
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 2px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 2px 8px;
  border-radius: 2px;
  white-space: nowrap;
}

.chapter-name, .ch-name, .ji-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-light);
  letter-spacing: 4px;
}

.chapter-char-count, .ch-count, .ji-num {
  font-size: 12px;
  color: rgba(255,255,255,0.25);
  letter-spacing: 1px;
  white-space: nowrap;
}

.chapter-body, .ch-body, .ji-card-body {
  padding: 20px 24px 22px;
  border-top: 1px solid var(--card-border);
}

.chapter-text, .ch-text, .ji-original-text {
  font-size: 16px;
  line-height: 2.1;
  color: var(--text-primary);
  letter-spacing: 0.8px;
}

.sentence, .snt, .ji-sentence {
  display: inline;
}

/* ====== CHAPTER SECTION (论语用) ====== */
.chapter-section {
  margin-bottom: 44px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 10px var(--shadow);
}

.chapter-section .chapter-title-bar {
  cursor: pointer;
  user-select: none;
}

.chapter-section .chapter-title-bar:hover {
  filter: brightness(1.15);
}

.chapter-entry-count {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 1px;
  background: rgba(255,255,255,0.08);
  padding: 3px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  white-space: nowrap;
  margin-left: auto;
}

.entries-list { padding: 8px 0; }
.entries-list.collapsed { display: none; }

.entry-item {
  display: flex;
  gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid #eef3e8;
  transition: background 0.15s;
}

.entry-item:last-child { border-bottom: none; }
.entry-item:hover { background: rgba(0,0,0,0.02); }

.entry-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  font-style: normal;
}

.entry-text {
  font-size: 15px;
  line-height: 1.95;
  color: var(--text-primary);
  letter-spacing: 0.5px;
  flex: 1;
}

.speaker {
  color: var(--accent);
  font-weight: 600;
}

/* ====== JI CARD (三十六计用) ====== */
.ji-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 10px var(--shadow);
  margin-bottom: 16px;
  transition: box-shadow 0.2s;
}

.ji-card:hover {
  box-shadow: 0 4px 20px var(--shadow);
}

.ji-card-header {
  background: linear-gradient(135deg, var(--sidebar-bg) 0%, var(--sidebar-hover) 100%);
  padding: 14px 24px;
}

.ji-card-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ji-original { margin-bottom: 16px; }

.ji-original-label {
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 3px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #ede4d0;
}

.ji-anya {
  background: rgba(0,0,0,0.02);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  padding: 14px 18px;
  margin-top: 4px;
}

.anya-label {
  font-size: 11px;
  color: var(--text-light);
  letter-spacing: 3px;
  margin-bottom: 8px;
}

.anya-text {
  font-size: 14px;
  line-height: 2;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

/* ====== SEARCH HIGHLIGHT ====== */
.highlight {
  background: rgba(200,168,48,0.25);
  border-radius: 2px;
  padding: 0 2px;
}

/* ====== BACK TO TOP ====== */
.back-top {
  position: fixed;
  right: 28px; bottom: 28px;
  width: 42px; height: 42px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0,0,0,0.2);
  transition: all 0.2s;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.back-top:hover { transform: scale(1.1); background: var(--accent-dark); }
.back-top.visible { display: flex; }

/* ====== MOBILE ====== */
.menu-toggle {
  display: none;
  position: fixed;
  top: 14px; left: 14px;
  z-index: 300;
  background: var(--sidebar-bg);
  color: var(--accent-light);
  border: none;
  width: 38px; height: 38px;
  border-radius: 4px;
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .content-area { padding: 20px; }
  .page-hero { padding: 50px 24px 36px; }
  .hero-title { font-size: 38px; }
  .chapter-char-count,
  .ch-count,
  .chapter-short { display: none; }
}
