/* =========================================
   为自然立法：康德认识论十讲 — E-Book Styles
   ========================================= */

/* —— CSS Variables —— */
:root {
  --accent: #4a6b8a;
  --text: #1a1a1a;
  --text-light: #555;
  --text-muted: #888;
  --strong: #111;
  --page-bg: #F5F4F0;
  --outer-bg: #e8e6e0;
  --border: rgba(26, 26, 26, 0.1);
  --geo: #1a1a1a;
  --geo-rgb: 26, 26, 26;
  --nav-bg: rgba(245, 244, 240, 0.85);
  --nav-border: rgba(26, 26, 26, 0.06);
  --toc-hover: rgba(0,0,0,0.03);
  --toc-active-bg: rgba(0,0,0,0.04);
  --overlay: rgba(0,0,0,0.3);
  --blockquote-bg: rgba(0,0,0,0.02);
  --code-bg: rgba(0,0,0,0.05);
  --pre-bg: rgba(0,0,0,0.03);
  --cover-bg: #F5F4F0;
  --cover-shadow: 0 2px 40px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04);
  --cover-warmth: rgba(200,160,100,0.08);
  --toggle-hover: rgba(0,0,0,0.04);
  --drawer-shadow: 2px 0 20px rgba(0,0,0,0.08);
  --author: #777;
  --subtitle: #555;
  --eng-subtitle: #888;
  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', serif;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
  --content-width: 680px;
  --nav-height: 52px;
}

/* Dark mode */
[data-theme="dark"] {
  --accent: #7aafd2;
  --text: #ddd8cc;
  --text-light: #b0aa9e;
  --text-muted: #7a7568;
  --strong: #e8e2d4;
  --page-bg: #252420;
  --outer-bg: #1a1815;
  --border: rgba(255, 255, 255, 0.06);
  --geo: #ccc6b8;
  --geo-rgb: 204, 198, 184;
  --nav-bg: rgba(37, 36, 32, 0.88);
  --nav-border: rgba(255, 255, 255, 0.05);
  --toc-hover: rgba(255,255,255,0.03);
  --toc-active-bg: rgba(255,255,255,0.05);
  --overlay: rgba(0,0,0,0.5);
  --blockquote-bg: rgba(255,255,255,0.02);
  --code-bg: rgba(255,255,255,0.06);
  --pre-bg: rgba(255,255,255,0.04);
  --cover-bg: #2c2924;
  --cover-shadow: 0 2px 40px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.04);
  --cover-warmth: rgba(180,140,80,0.04);
  --toggle-hover: rgba(255,255,255,0.06);
  --drawer-shadow: 2px 0 20px rgba(0,0,0,0.25);
  --author: #7a7568;
  --subtitle: #b0aa9e;
  --eng-subtitle: #7a7568;
}

/* —— Reset —— */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.9;
  color: var(--text);
  background: var(--outer-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* —— Theme Toggle —— */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
  font-size: 16px;
  line-height: 1;
  color: var(--text-muted);
  margin-left: auto;
}
.theme-toggle:hover { background: var(--toggle-hover); }

/* —— Top Navigation —— */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  height: var(--nav-height);
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--nav-border);
  padding: 0 20px;
  gap: 14px;
}

.toc-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}
.toc-toggle:hover { background: var(--toggle-hover); }

.toc-icon {
  position: relative;
  width: 16px;
  height: 2px;
  background: var(--text);
}
.toc-icon::before, .toc-icon::after {
  content: '';
  position: absolute;
  left: 0;
  width: 16px;
  height: 2px;
  background: var(--text);
}
.toc-icon::before { top: -5px; }
.toc-icon::after { top: 5px; }

.nav-book-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.nav-chapter {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.08em;
}

/* —— Progress Bar —— */
.progress-bar {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  z-index: 99;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s linear;
}

/* —— TOC Overlay & Drawer —— */
.toc-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.toc-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.toc-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: var(--page-bg);
  z-index: 201;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  box-shadow: var(--drawer-shadow);
}
.toc-drawer.open { transform: translateX(0); }

.toc-header {
  padding: 28px 24px 20px;
  border-bottom: 1px solid var(--border);
}
.toc-book {
  display: block;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.06em;
  color: var(--text);
}
.toc-subtitle {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  margin-top: 4px;
}

.toc-list {
  list-style: none;
  padding: 12px 0;
}
.toc-list li { margin: 0; }

.toc-home a {
  font-weight: 600;
  letter-spacing: 0.12em;
  font-size: 14px;
}
.toc-home {
  padding-bottom: 12px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.toc-list a {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 24px;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0.04em;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}
.toc-list a:hover { background: var(--toc-hover); }
.toc-list .active a {
  background: var(--toc-active-bg);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.toc-num {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 16px;
}
.toc-list .active .toc-num { color: var(--accent); }

/* Desktop: fixed TOC sidebar */
@media (min-width: 1200px) {
  .toc-toggle { display: none; }
  .toc-overlay { display: none; }
  .toc-drawer {
    transform: translateX(0);
    width: 240px;
    box-shadow: none;
    border-right: 1px solid var(--border);
  }
  .chapter-page {
    margin-left: 240px;
  }
  .top-nav { margin-left: 240px; }
  .progress-bar { left: 240px; }
  .toc-drawer .toc-header { padding-top: 32px; }
}

/* —— Chapter Page —— */
.chapter-page {
  padding-bottom: 120px;
}

/* —— Chapter Cover (full viewport) —— */
.chapter-cover {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.chapter-cover-inner {
  position: relative;
  width: 750px;
  max-width: 90vw;
  aspect-ratio: 3 / 4;
  max-height: 90vh;
  background: var(--cover-bg);
  box-shadow: var(--cover-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.cc-top-line {
  position: absolute;
  top: 8%;
  left: 10.7%;
  right: 10.7%;
  height: 1px;
  background: var(--text);
  opacity: 0.15;
}
.cc-bottom-line {
  position: absolute;
  bottom: 8%;
  left: 10.7%;
  right: 10.7%;
  height: 1px;
  background: var(--text);
  opacity: 0.12;
}
.cc-warmth {
  position: absolute;
  top: -40px; right: -60px;
  width: 260px; height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--cover-warmth) 0%, transparent 70%);
  pointer-events: none;
}

/* Chapter cover geometry — full size */
.chapter-cover .geo-stage {
  position: relative;
  width: 360px;
  height: 360px;
  margin-bottom: 40px;
  overflow: visible;
}
.chapter-cover .geo-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1.0);
  transform-origin: center center;
}

/* Chapter cover title */
.cc-title-group {
  position: absolute;
  bottom: 13%;
  left: 10.7%;
  right: 10.7%;
  text-align: center;
}
.cc-num {
  font-size: clamp(11px, 1.6vw, 13px);
  letter-spacing: 0.35em;
  color: var(--accent);
  margin-bottom: 16px;
  font-weight: 500;
}
.cc-title {
  font-size: clamp(24px, 5.5vw, 42px);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text);
  line-height: 1.35;
}

/* —— Chapter Content —— */
.chapter-content {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 24px;
}

.chapter-content h2 {
  font-size: 22px;
  font-weight: 700;
  margin: 48px 0 18px;
  letter-spacing: 0.04em;
  color: var(--text);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.chapter-content h3 {
  font-size: 19px;
  font-weight: 600;
  margin: 32px 0 12px;
  letter-spacing: 0.03em;
  color: var(--text-light);
}

.chapter-content p {
  margin: 0 0 16px;
  text-align: justify;
}

.chapter-content strong {
  font-weight: 600;
  color: var(--strong);
}

.chapter-content em {
  font-style: italic;
}

.chapter-content hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 40px auto;
  width: 30%;
  max-width: 120px;
}

.chapter-content blockquote {
  margin: 24px 0;
  padding: 16px 20px;
  border-left: 3px solid var(--accent);
  background: var(--blockquote-bg);
  border-radius: 0 6px 6px 0;
}
.chapter-content blockquote p {
  margin: 0;
  font-size: 17px;
  line-height: 1.85;
  color: var(--text-light);
}

.chapter-content ul,
.chapter-content ol {
  margin: 12px 0 20px;
  padding-left: 24px;
}

.chapter-content li {
  margin-bottom: 8px;
  line-height: 1.8;
}

.chapter-content li > ul,
.chapter-content li > ol {
  margin: 4px 0 4px;
}

.chapter-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chapter-content code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
}

.chapter-content pre {
  background: var(--pre-bg);
  padding: 16px 20px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 16px 0;
}
.chapter-content pre code {
  background: none;
  padding: 0;
}

/* —— Chapter Footer Navigation —— */
.chapter-footer {
  max-width: var(--content-width);
  margin: 60px auto 0;
  padding: 0 24px;
}

.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
}

.nav-prev, .nav-next {
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.03em;
  transition: color 0.2s;
  line-height: 1.4;
  max-width: 40%;
}
.nav-prev:hover, .nav-next:hover { color: var(--accent); }

.nav-toc-link {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.1em;
  white-space: nowrap;
  transition: color 0.2s;
}
.nav-toc-link:hover { color: var(--accent); }

/* Floating theme toggle for index page */
.theme-float {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  font-size: 18px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.theme-float:hover { background: var(--toggle-hover); }

/* =========================================
   Landing Page (index.html)
   ========================================= */

.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

/* —— Cover Section —— */
.cover-section {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  width: 100%;
  padding: 80px 20px 60px;
  gap: 40px;
}

.cover-section .geometry {
  position: relative;
  width: min(420px, 70vw);
  max-height: 50vh;
}
.cover-section .geometry svg {
  width: 100%;
  height: auto;
  display: block;
  color: var(--geo);
}

.title-group {
  text-align: center;
}
.main-title {
  font-size: clamp(28px, 7vw, 56px);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  line-height: 1.3;
}
.subtitle {
  font-size: clamp(12px, 2.5vw, 18px);
  font-weight: 400;
  letter-spacing: 0.25em;
  color: var(--subtitle);
  margin-top: 18px;
}
.english-subtitle {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: clamp(11px, 1.8vw, 13px);
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0.06em;
  color: var(--eng-subtitle);
  margin-top: 12px;
}
.author {
  text-align: center;
  font-size: clamp(11px, 1.8vw, 14px);
  letter-spacing: 0.2em;
  color: var(--author);
  margin-top: 12px;
}
/* —— Home Section —— */
.home-section {
  width: 100%;
  max-width: var(--content-width);
  padding: 0 24px 120px;
  margin: 0 auto;
}

.home-divider {
  text-align: center;
  padding: 60px 0 48px;
}
.home-divider span {
  display: inline-block;
  width: 60px;
  height: 1px;
  background: var(--text);
  opacity: 0.12;
}

.chapter-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chapter-list-item a {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 16px 0;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: all 0.2s;
}

.chapter-list-item a:hover {
  padding-left: 8px;
}

.chapter-list-item .cl-num {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 28px;
  letter-spacing: 0.05em;
}

.chapter-list-item .cl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.chapter-list-item .cl-title {
  font-size: 17px;
  font-weight: 400;
  color: var(--text);
  letter-spacing: 0.04em;
  line-height: 1.5;
}

.chapter-list-item a:hover .cl-title {
  opacity: 0.7;
}

/* —— Animations (shared) —— */
@keyframes slowSpin {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to   { transform: translate(-50%, -50%) rotate(360deg); }
}
@keyframes breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.02); }
}
@keyframes pulse-h {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.35; }
}
@keyframes pulse-v {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.35; }
}
@keyframes dotPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.6); opacity: 0.5; }
}

/* =========================================
   Responsive
   ========================================= */

@media (max-width: 640px) {
  body { font-size: 16px; }
  .chapter-cover .geo-stage { width: 260px; height: 260px; margin-bottom: 28px; }
  .chapter-cover .geo-inner { transform: translate(-50%, -50%) scale(0.72); }
  .chapter-content h2 { font-size: 19px; margin: 36px 0 14px; }
  .chapter-content h3 { font-size: 17px; margin: 24px 0 10px; }
  .chapter-content { padding: 0 16px; }
  .chapter-footer { padding: 0 16px; }
  .chapter-nav { flex-wrap: wrap; gap: 10px; }
  .nav-toc-link { order: -1; width: 100%; text-align: center; }
  .nav-prev, .nav-next { max-width: 48%; font-size: 14px; }
  .home-section { padding: 0 16px 80px; }
  .chapter-content blockquote { padding: 12px 16px; font-size: 15px; }
}

@media (min-width: 641px) and (max-width: 1199px) {
  .chapter-content { padding: 0 32px; }
  .chapter-footer { padding: 0 32px; }
}

/* =========================================
   Print
   ========================================= */

@media print {
  .top-nav, .progress-bar, .toc-overlay, .toc-drawer,
  .chapter-footer, .chapter-cover { display: none !important; }
  body { font-size: 13pt; background: #fff; color: #000; }
  .chapter-page { margin-left: 0 !important; padding: 0; }
  .chapter-content { max-width: 100%; padding: 0; }
  .chapter-content h2 { break-after: avoid; }
  .chapter-content p { widows: 2; orphans: 2; }
}
