/* ========== Book Page Extra ========== */
/* 书籍布局：内容 + 右侧目录 */
.book-layout {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  gap: 0;
  flex: 1;
}

.book-content {
  flex: 1;
  min-width: 0;
  padding-right: 24px;
}

/* ========== 右侧目录面板 ========== */
.toc-panel {
  width: 260px;
  flex-shrink: 0;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all var(--transition);
}

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: #faf8f4;
  flex-shrink: 0;
}

.toc-title {
  font-size: 13px;
  font-weight: 600;
  color: #444;
  font-family: "Noto Sans SC", sans-serif;
}

.toc-toggle {
  width: 24px;
  height: 24px;
  border: none;
  background: #eee;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: #888;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.toc-toggle:hover {
  background: #ddd;
  color: #444;
}

.toc-nav {
  overflow-y: auto;
  padding: 8px 6px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.toc-item {
  display: block;
  padding: 4px 10px;
  font-size: 12.5px;
  color: #666;
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
  line-height: 1.5;
  font-family: "Noto Sans SC", sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-item:hover {
  background: #f3f0e8;
  color: #c0392b;
}

.toc-item.toc-h2 {
  font-weight: 500;
  color: #333;
}

.toc-item.toc-h3 {
  padding-left: 20px;
  font-weight: 400;
}

.toc-item.active {
  background: #fef3c7;
  color: #92400e;
  font-weight: 500;
}

/* 收起状态（桌面） */
.toc-panel.collapsed {
  width: 36px;
}

.toc-panel.collapsed .toc-header {
  flex-direction: column;
  padding: 8px;
}

.toc-panel.collapsed .toc-title {
  display: none;
}

.toc-panel.collapsed .toc-toggle {
  width: 20px;
  height: 20px;
  font-size: 14px;
}

.toc-panel.collapsed .toc-nav {
  display: none;
}

/* ========== 平板 ========== */
@media (max-width: 1024px) {
  .book-layout {
    padding: 24px 16px 60px;
  }
  .toc-panel {
    width: 200px;
  }
}

/* ========== 手机：目录改为浮动面板 ========== */
.toc-fab {
  display: none;
}

@media (max-width: 768px) {
  .book-layout {
    flex-direction: column;
    padding: 16px 12px 40px;
  }
  .book-content {
    padding-right: 0;
  }

  /* 桌面版目录隐藏 */
  .toc-panel {
    display: none;
  }

  /* 浮动按钮 */
  .toc-fab {
    display: flex;
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 44px;
    height: 44px;
    background: #c0392b;
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2);
    z-index: 100;
    transition: transform 0.2s;
  }
  .toc-fab:active {
    transform: scale(0.9);
  }

  /* 手机浮动目录面板 */
  .toc-mobile-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 200;
  }
  .toc-mobile-overlay.open {
    display: block;
  }

  .toc-mobile-panel {
    position: fixed;
    right: 0; top: 0; bottom: 0;
    width: 280px;
    max-width: 80vw;
    background: #fff;
    z-index: 201;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 16px rgba(0,0,0,0.1);
  }
  .toc-mobile-panel.open {
    transform: translateX(0);
  }

  .toc-mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e5e5;
    background: #faf8f4;
    flex-shrink: 0;
  }
  .toc-mobile-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #333;
  }
  .toc-mobile-close {
    width: 28px;
    height: 28px;
    border: none;
    background: #eee;
    border-radius: 4px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
  }

  .toc-mobile-nav {
    overflow-y: auto;
    padding: 8px 8px;
    flex: 1;
    -webkit-overflow-scrolling: touch;
  }
}
