/* Book Reader Layout */
.book-page {
  background: var(--color-bg);
}

.book-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: rgba(250, 250, 250, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color var(--transition);
  flex-shrink: 0;
}

.back-link:hover {
  color: var(--color-text);
}

.book-header-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-toggle {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 4px;
  transition: color var(--transition);
  flex-shrink: 0;
}

.toc-toggle:hover {
  color: var(--color-text);
}

/* Layout */
.book-layout {
  display: flex;
  margin-top: 52px;
  min-height: calc(100vh - 52px);
}

/* Sidebar */
.book-sidebar {
  position: fixed;
  top: 52px;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
  transition: transform 0.3s ease;
}

.book-sidebar.hidden {
  transform: translateX(-100%);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 12px;
}

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-secondary);
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 2px;
  display: none;
}

/* TOC */
.toc-part {
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-secondary);
  padding: 16px 20px 4px;
}

.toc-chapter {
  display: block;
  padding: 6px 20px;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  text-decoration: none;
  line-height: 1.4;
  transition: color var(--transition), background var(--transition);
  border-left: 2px solid transparent;
}

.toc-chapter:hover {
  color: var(--color-text);
  background: rgba(0, 0, 0, 0.02);
}

.toc-chapter.active {
  color: var(--color-text);
  font-weight: 500;
  border-left-color: var(--color-accent);
  background: rgba(0, 0, 0, 0.02);
}

/* Content */
.book-content {
  flex: 1;
  margin-left: 280px;
  max-width: 720px;
  padding: 48px 40px 120px;
  transition: margin-left 0.3s ease;
}

.book-content.full-width {
  margin-left: 0;
  margin-right: auto;
  margin-left: auto;
}

/* Markdown Prose */
.book-content h1 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 8px;
  color: var(--color-text);
}

.book-content h2 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
  margin-top: 48px;
  margin-bottom: 16px;
  color: var(--color-text);
}

.book-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--color-text);
}

.book-content p {
  font-size: 0.95rem;
  line-height: 1.75;
  margin-bottom: 16px;
  color: #374151;
}

.book-content blockquote {
  border-left: 3px solid var(--color-border);
  padding: 4px 0 4px 20px;
  margin: 20px 0;
  color: var(--color-text-secondary);
  font-style: italic;
}

.book-content blockquote p {
  color: inherit;
}

.book-content ul, .book-content ol {
  margin: 12px 0;
  padding-left: 24px;
}

.book-content li {
  font-size: 0.95rem;
  line-height: 1.75;
  margin-bottom: 4px;
  color: #374151;
}

.book-content code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.85em;
  background: var(--color-lang-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.book-content pre {
  background: #1e293b;
  border-radius: 8px;
  padding: 20px;
  overflow-x: auto;
  margin: 20px 0;
}

.book-content pre code {
  background: none;
  padding: 0;
  color: #e2e8f0;
  font-size: 0.85rem;
  line-height: 1.6;
}

.book-content hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 40px 0;
}

.book-content strong {
  font-weight: 600;
}

.book-content a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.book-content a:hover {
  color: var(--color-text);
}

.book-content sup {
  font-size: 0.7rem;
  color: var(--color-text-secondary);
  vertical-align: super;
  line-height: 0;
}

/* Chapter Nav */
.chapter-nav {
  position: fixed;
  bottom: 0;
  left: 280px;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(250, 250, 250, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--color-border);
  z-index: 100;
  transition: left 0.3s ease;
}

.chapter-nav.expanded {
  left: 0;
}

.chapter-nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-main);
}

.chapter-nav-btn:hover:not(:disabled) {
  border-color: var(--color-accent);
  color: var(--color-text);
}

.chapter-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Loading */
.book-content .loading {
  text-align: center;
  padding: 80px 0;
  color: var(--color-text-secondary);
  font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 900px) {
  .book-sidebar {
    transform: translateX(-100%);
  }

  .book-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
  }

  .sidebar-close {
    display: block;
  }

  .book-content {
    margin-left: 0;
    padding: 32px 20px 120px;
  }

  .chapter-nav {
    left: 0;
  }
}
