/* ============================================
   道德经 Tao Te Ching — yiqidao.com
   Design System (matches /sage/ aesthetic)
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
  --bg-primary: #f6f5fa;
  --bg-secondary: #eeeef4;
  --bg-card: #ffffff;
  --bg-card-hover: #f8f7fc;
  --bg-accent: #f0eff5;
  --text-primary: #2a2a35;
  --text-secondary: #5a5a6a;
  --text-muted: #8a8a9a;
  --text-gold: #8b6914;
  --text-gold-bright: #a07a1a;
  --accent-gold: #9a7b2e;
  --accent-gold-dim: rgba(154, 123, 46, 0.10);
  --accent-jade: #4a8a7a;
  --accent-jade-dim: rgba(74, 138, 122, 0.08);
  --accent-red: #b85c5c;
  --accent-purple: #7a6aaa;
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-gold: rgba(154, 123, 46, 0.20);
  --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.06);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', serif;
  --font-sans: 'Noto Sans SC', 'Source Han Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Noto Serif SC', serif;
  --transition: 0.3s ease;
  --max-width: 1200px;
  --max-width-narrow: 900px;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.8;
  min-height: 100vh;
}

a { color: var(--accent-gold); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--text-gold-bright); }

img { max-width: 100%; height: auto; }

::selection { background: rgba(154, 123, 46, 0.15); color: var(--text-primary); }

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--text-primary);
  line-height: 1.3;
  font-weight: 600;
}
h1 { font-size: 2.5rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.4rem; }
h4 { font-size: 1.15rem; }

/* --- Layout --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}
.container-narrow {
  max-width: var(--max-width-narrow);
  margin: 0 auto;
  padding: 0 24px;
}

/* ============================================
   Header / Navigation
   ============================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(246, 245, 250, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 24px;
}
.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--text-primary);
  font-weight: 600;
}
.site-logo .logo-icon {
  font-size: 1.6rem;
  color: var(--accent-gold);
}
.site-logo span.sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}

.nav-main { display: flex; align-items: center; gap: 28px; }
.nav-main a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  transition: color var(--transition);
  position: relative;
}
.nav-main a:hover,
.nav-main a.active {
  color: var(--accent-gold);
}
.nav-main a.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent-gold);
  border-radius: 1px;
}

.lang-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.lang-switch a {
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.lang-switch a:hover { color: var(--text-primary); background: var(--bg-card); }
.lang-switch a.active { color: var(--accent-gold); background: var(--accent-gold-dim); }

.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
}

/* ============================================
   Hero Section
   ============================================ */
.hero {
  text-align: center;
  padding: 80px 24px 60px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(154, 123, 46, 0.08) 0%, transparent 70%);
  pointer-events: none;
}
.hero-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  display: block;
  opacity: 0.8;
}
.hero h1 {
  font-size: 3rem;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text-gold) 0%, var(--text-gold-bright) 50%, var(--accent-jade) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero .subtitle-en {
  font-family: 'Georgia', serif;
  font-size: 1.1rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  margin-bottom: 20px;
}
.hero .hero-desc {
  max-width: 680px;
  margin: 0 auto;
  color: var(--text-secondary);
  font-size: 1.05rem;
  line-height: 1.9;
}
.hero .hero-meta {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 28px;
  flex-wrap: wrap;
}
.hero .meta-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.hero .meta-item .meta-value {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--accent-gold);
  font-weight: 700;
}
.hero .meta-item .meta-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ============================================
   Section Headers
   ============================================ */
.section-header {
  text-align: center;
  margin-bottom: 48px;
}
.section-header .section-num {
  font-family: 'Georgia', serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.section-header h2 {
  margin-bottom: 8px;
}
.section-header .section-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 600px;
  margin: 0 auto;
}

/* ============================================
   Chapter Cards (Index Page)
   ============================================ */
.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
  margin-bottom: 60px;
}
.chapter-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 24px;
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  display: flex;
  gap: 18px;
  text-decoration: none;
  color: inherit;
}
.chapter-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-gold);
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}
.chapter-card:hover .card-icon { color: var(--accent-gold); }
.chapter-card .card-icon {
  font-size: 2.2rem;
  color: var(--text-muted);
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-accent);
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  font-family: var(--font-serif);
}
.chapter-card .card-body { flex: 1; min-width: 0; }
.chapter-card .card-num {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  margin-bottom: 2px;
}
.chapter-card .card-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--text-primary);
  margin-bottom: 8px;
  font-weight: 600;
}
.chapter-card .card-excerpt {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chapter-card .card-tags {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.chapter-card .tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--accent-gold-dim);
  color: var(--accent-gold);
}
.chapter-card .tag.tag-theme {
  background: var(--accent-jade-dim);
  color: var(--accent-jade);
}

/* ============================================
   Chapter Detail Page
   ============================================ */

/* Breadcrumb */
.breadcrumb {
  padding: 16px 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent-gold); }
.breadcrumb .sep { margin: 0 8px; opacity: 0.5; }

/* Chapter Header */
.chapter-hero {
  text-align: center;
  padding: 48px 0 36px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 36px;
}
.chapter-hero .ch-number {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.chapter-hero h1 {
  font-size: 2.4rem;
  margin-bottom: 12px;
}
.chapter-hero .ch-keyword {
  display: inline-block;
  font-size: 3rem;
  width: 72px;
  height: 72px;
  line-height: 72px;
  text-align: center;
  background: var(--accent-gold-dim);
  color: var(--accent-gold);
  border-radius: 50%;
  margin-bottom: 16px;
  font-family: var(--font-serif);
}
.chapter-hero .ch-summary {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.8;
}

/* Content Tabs */
.content-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 32px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.content-tabs .tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: var(--font-sans);
}
.content-tabs .tab-btn:hover { color: var(--text-secondary); }
.content-tabs .tab-btn.active {
  color: var(--accent-gold);
  border-bottom-color: var(--accent-gold);
}

.tab-panel { display: none; animation: fadeIn 0.3s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Original Text */
.original-text {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  line-height: 2.2;
  text-align: center;
  padding: 32px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin-bottom: 32px;
  letter-spacing: 0.08em;
}
.original-text .verse {
  margin-bottom: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.original-text .verse:hover {
  background: var(--accent-gold-dim);
}

/* Translation */
.translation-block {
  font-size: 1.05rem;
  line-height: 2;
  color: var(--text-secondary);
  padding: 24px;
  background: var(--bg-accent);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--accent-gold);
  margin-bottom: 32px;
}

/* Annotation Table */
.annotation-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 32px;
  font-size: 0.9rem;
}
.annotation-table th {
  background: var(--bg-card);
  color: var(--accent-gold);
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border-gold);
}
.annotation-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.annotation-table tr:hover td { background: var(--bg-card); }
.annotation-table .char-cell {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--text-primary);
}

/* Verse Interpretation */
.verse-block {
  margin-bottom: 28px;
  padding: 24px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}
.verse-block .verse-title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  color: var(--accent-gold);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}
.verse-block .verse-body {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.9;
}

/* Misconception Cards */
.misconception-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.misconception-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}
.misconception-card .mc-wrong {
  padding: 14px 18px;
  background: rgba(184, 92, 92, 0.08);
  border-bottom: 1px solid var(--border-subtle);
}
.misconception-card .mc-wrong::before {
  content: '✗ ';
  color: var(--accent-red);
  font-weight: 700;
}
.misconception-card .mc-right {
  padding: 14px 18px;
  background: rgba(122, 184, 168, 0.06);
}
.misconception-card .mc-right::before {
  content: '✓ ';
  color: var(--accent-jade);
  font-weight: 700;
}

/* Application Scenarios */
.scenario-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 20px;
}
.scenario-card .scenario-title {
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.scenario-card .scenario-title .icon { font-size: 1.3rem; }
.scenario-card .scenario-body {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.85;
}

/* Scholar Commentary */
.scholar-card {
  background: var(--bg-accent);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin-bottom: 16px;
  border-left: 3px solid var(--accent-purple);
}
.scholar-card .scholar-name {
  font-weight: 600;
  color: var(--accent-purple);
  font-size: 0.9rem;
  margin-bottom: 6px;
}
.scholar-card .scholar-quote {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 8px;
}
.scholar-card .scholar-analysis {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Connection / Cross-reference */
.connections-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 32px;
}
.connections-section h4 {
  color: var(--accent-jade);
  margin-bottom: 12px;
  font-size: 0.95rem;
}
.connections-section .conn-group {
  margin-bottom: 16px;
}
.connections-section .conn-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.connections-section .conn-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.connections-section .conn-link {
  font-size: 0.82rem;
  padding: 4px 12px;
  background: var(--bg-accent);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.connections-section .conn-link:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* Chapter Navigation (Prev/Next) */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin: 48px 0;
  padding: 24px 0;
  border-top: 1px solid var(--border-subtle);
}
.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  flex: 1;
  transition: all var(--transition);
  max-width: 48%;
}
.chapter-nav a:hover {
  border-color: var(--border-gold);
  background: var(--bg-card-hover);
}
.chapter-nav .nav-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.chapter-nav .nav-title {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text-primary);
}
.chapter-nav .next { text-align: right; margin-left: auto; }

/* ============================================
   Overview / Book Info Section
   ============================================ */
.book-intro {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  padding: 48px 0;
  align-items: center;
}
.book-intro .book-text h2 { margin-bottom: 16px; }
.book-intro .book-text p {
  color: var(--text-secondary);
  line-height: 1.9;
  margin-bottom: 16px;
}
.book-intro .book-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
}
.stat-card .stat-num {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--accent-gold);
  font-weight: 700;
}
.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Core Concepts Grid */
.concepts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 48px;
}
.concept-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--transition);
}
.concept-chip:hover {
  border-color: var(--border-gold);
  background: var(--bg-card-hover);
}
.concept-chip .chip-icon {
  font-size: 1.4rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gold-dim);
  border-radius: 50%;
  flex-shrink: 0;
}
.concept-chip .chip-label {
  font-size: 0.85rem;
  color: var(--text-primary);
}
.concept-chip .chip-chapters {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ============================================
   Footer
   ============================================ */
.site-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 40px 24px;
  text-align: center;
  margin-top: 60px;
}
.footer-links {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.footer-links a {
  color: var(--text-muted);
  font-size: 0.82rem;
}
.footer-links a:hover { color: var(--accent-gold); }
.footer-copy {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================
   Language Switcher (top-right)
   ============================================ */
.lang-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 2px;
  border: 1px solid var(--border-subtle);
}
.lang-bar a {
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-radius: 4px;
  transition: all var(--transition);
}
.lang-bar a:hover { color: var(--text-primary); }
.lang-bar a.active {
  background: var(--accent-gold-dim);
  color: var(--accent-gold);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 1024px) {
  .book-intro { grid-template-columns: 1fr; gap: 24px; }
  .chapters-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

@media (max-width: 768px) {
  .hero h1 { font-size: 2.2rem; }
  .hero .hero-meta { gap: 20px; }
  .nav-main { display: none; }
  .nav-main.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-subtle);
    padding: 16px 24px;
    gap: 16px;
  }
  .nav-toggle { display: block; }
  .header-inner { position: relative; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav a { max-width: 100%; }
  .misconception-grid { grid-template-columns: 1fr; }
  .concepts-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .original-text { font-size: 1.1rem; padding: 20px; }
  h1 { font-size: 2rem; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 1.8rem; }
  .chapters-grid { grid-template-columns: 1fr; }
  .chapter-card { flex-direction: column; gap: 12px; }
  .chapter-card .card-icon { width: 100%; height: 48px; border-radius: var(--radius-sm); }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  .site-header, .site-footer, .content-tabs, .chapter-nav, .lang-bar { display: none; }
  body { background: #fff; color: #222; }
  .tab-panel { display: block !important; }
  .original-text { border: 1px solid #ccc; background: #fafafa; }
}

/* ============================================
   Utility
   ============================================ */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.text-gold { color: var(--accent-gold); }
.text-jade { color: var(--accent-jade); }
.mt-4 { margin-top: 32px; }
.mb-4 { margin-bottom: 32px; }
