/* ReadBook Universal Theme & Design System */
:root {
  --bg-primary: #0a0f1d;
  --bg-secondary: #121b2d;
  --bg-card: #182338;
  --bg-subcard: #0d1525;
  --border-color: #24324d;
  --border-hover: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-cyan: #38bdf8;
  --accent-blue: #3b82f6;
  --accent-indigo: #6366f1;
  --accent-gold: #f59e0b;
  --danger-red: #f43f5e;
  --warning-amber: #fbbf24;
  --safe-green: #10b981;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "Fira Code", "Cascadia Code", Consolas, Monaco, monospace;
}

body.light-theme {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: #ffffff;
  --bg-subcard: #f8fafc;
  --border-color: #cbd5e1;
  --border-hover: #0284c7;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent-cyan: #0284c7;
  --accent-blue: #2563eb;
  --accent-indigo: #4f46e5;
  --accent-gold: #b45309;
  --danger-red: #e11d48;
  --warning-amber: #d97706;
  --safe-green: #059669;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-size: 16.5px;
  line-height: 1.8;
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-cyan);
  text-decoration: none;
  transition: color 0.15s ease, opacity 0.15s ease;
}
a:hover { opacity: 0.85; }

/* Sticky Header */
header.site-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 10px 20px;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}
.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  color: var(--text-main);
  text-decoration: none;
}
.brand-icon { font-size: 22px; }
.header-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.nav-btn:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}
.nav-btn.active {
  background: var(--accent-cyan);
  color: #fff;
  border-color: var(--accent-cyan);
}

/* Breadcrumb Sub-bar */
.subnav-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 20px;
  font-size: 13px;
}
.subnav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent-cyan); }
.breadcrumb-sep { opacity: 0.5; }

/* Article Container */
.article-container {
  max-width: 900px;
  margin: 30px auto;
  padding: 0 20px;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-main);
  font-weight: 700;
  margin-top: 1.8em;
  margin-bottom: 0.6em;
  line-height: 1.35;
}
h1 { font-size: 28px; border-bottom: 2px solid var(--border-color); padding-bottom: 12px; margin-top: 0.5em; }
h2 { font-size: 23px; border-left: 4px solid var(--accent-cyan); padding-left: 14px; }
h3 { font-size: 19px; color: var(--accent-cyan); }
body.light-theme h3 { color: #0284c7; }
h4 { font-size: 17px; }

p { margin-bottom: 1.2em; text-align: justify; }

strong { color: var(--text-main); font-weight: 700; }
em { color: var(--accent-gold); font-style: normal; font-weight: 600; }

hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 2.2em 0;
}

ul, ol {
  margin: 1em 0 1.4em 1.6em;
  padding-left: 0.5em;
}
li { margin-bottom: 0.5em; }

blockquote {
  border-left: 4px solid var(--border-color);
  background: var(--bg-subcard);
  padding: 14px 18px;
  margin: 1.5em 0;
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
}
blockquote p { margin-bottom: 0; }

/* Obsidian Callouts */
.callout {
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-cyan);
  background: var(--bg-card);
  border-radius: 8px;
  margin: 1.6em 0;
  overflow: hidden;
}
.callout-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  font-weight: 700;
  font-size: 14.5px;
  border-bottom: 1px solid var(--border-color);
}
.callout-icon { font-size: 16px; }
.callout-body {
  padding: 14px 18px;
  font-size: 15.5px;
}
.callout-body p:last-child { margin-bottom: 0; }
.callout-summary { border-left-color: var(--accent-cyan); }
.callout-tip { border-left-color: var(--safe-green); }
.callout-tip .callout-title { color: var(--safe-green); }
.callout-important { border-left-color: var(--accent-gold); }
.callout-important .callout-title { color: var(--accent-gold); }
.callout-warning { border-left-color: var(--warning-amber); }
.callout-caution { border-left-color: var(--danger-red); }

/* Math blocks */
.math-block {
  overflow-x: auto;
  padding: 14px 18px;
  background: var(--bg-subcard);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin: 1.5em 0;
  text-align: center;
}
.math-inline { padding: 1px 4px; }

/* Mermaid */
.mermaid-box {
  overflow-x: auto;
  background: var(--bg-subcard);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  margin: 1.8em 0;
  text-align: center;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
  margin: 1.6em 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  text-align: left;
}
.data-table th, .data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
}
.data-table th {
  background: var(--bg-secondary);
  color: var(--text-main);
  font-weight: 700;
  white-space: nowrap;
}
.data-table tr:hover {
  background: var(--bg-subcard);
}

/* Images */
.img-figure {
  margin: 2em 0;
  text-align: center;
}
.img-figure img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
}
.img-figure figcaption {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Wikilinks */
.wikilink {
  color: var(--accent-cyan);
  border-bottom: 1px dashed var(--accent-cyan);
  text-decoration: none;
}
.wikilink:hover {
  border-bottom-style: solid;
}

/* Chapter Footer Nav */
.chapter-bottom-nav {
  margin-top: 50px;
  padding-top: 25px;
  border-top: 2px solid var(--border-color);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}
.bottom-nav-card {
  display: flex;
  flex-direction: column;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  text-decoration: none;
  transition: all 0.2s;
}
.bottom-nav-card:hover {
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.bottom-nav-card.prev { text-align: left; }
.bottom-nav-card.next { text-align: right; }
.bottom-nav-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.bottom-nav-card.next .bottom-nav-label { justify-content: flex-end; }
.bottom-nav-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Drawer TOC (Mobile & PC) */
.toc-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
  backdrop-filter: blur(4px);
}
.toc-overlay.open {
  opacity: 1;
  visibility: visible;
}
.toc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 85vw;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  z-index: 2001;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}
.toc-drawer.open {
  transform: translateX(0);
}
.toc-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.toc-header h3 { margin: 0; font-size: 17px; color: var(--text-main); }
.toc-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}
.toc-body {
  padding: 15px;
  overflow-y: auto;
  flex: 1;
}
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-item { margin-bottom: 6px; }
.toc-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 14px;
  text-decoration: none;
  transition: all 0.15s;
}
.toc-link:hover {
  background: var(--bg-card);
  color: var(--accent-cyan);
}
.toc-link.active {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  font-weight: 700;
  border-left: 3px solid var(--accent-cyan);
}
.toc-num {
  font-family: var(--font-mono);
  font-size: 12px;
  opacity: 0.7;
}

/* Floating Actions */
.fab-container {
  position: fixed;
  bottom: 25px;
  right: 25px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 999;
}
.fab-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.2s;
}
.fab-btn:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  transform: scale(1.08);
}

/* Responsive */
@media (max-width: 768px) {
  body { font-size: 15.5px; }
  h1 { font-size: 23px; }
  h2 { font-size: 19px; }
  .header-inner { gap: 8px; }
  .brand-title { display: none; }
  .chapter-bottom-nav { grid-template-columns: 1fr; }
  .article-container { padding: 0 15px; margin: 20px auto; }
}
