/* ==========================================================================
   TOC & MODAL DRAWER STYLES —— 全部由主题变量驱动，浅色/深色主题自动协调
   ========================================================================== */

/* Backdrop Overlay */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  cursor: pointer;
  animation: fadeIn 0.16s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalPopIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Modal Panel (Desktop: Clean Dialog / Mobile: Bottom Sheet) */
.toc-modal-panel {
  width: 100%;
  max-width: 580px;
  max-height: 80vh;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  border-radius: 22px;
  padding: 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.45);
  animation: modalPopIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: default;
  overflow: hidden;
}

/* Sheet Top Handle */
.sheet-handle {
  display: block;
  width: 38px;
  height: 4.5px;
  border-radius: 999px;
  background: var(--border-medium);
  margin: 10px auto 4px auto;
  flex-shrink: 0;
  opacity: 0.85;
}

/* Header */
.toc-pop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.toc-pop-title-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.toc-pop-title {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "HarmonyOS Sans SC", sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.toc-pop-badge {
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  color: var(--accent-gold);
  background: var(--accent-gold-subtle);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--accent-gold-border);
  white-space: nowrap;
  flex-shrink: 0;
}

.toc-pop-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toc-pop-btn {
  height: 30px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.toc-pop-btn:hover {
  border-color: var(--accent-gold-border);
  color: var(--accent-gold);
}
.toc-pop-btn svg { width: 13px; height: 13px; }

.toc-pop-close {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
}
.toc-pop-close:hover {
  color: var(--accent-gold);
  border-color: var(--accent-gold-border);
}
.toc-pop-close svg { width: 15px; height: 15px; }

/* Search Bar */
.toc-pop-search-bar {
  position: relative;
  padding: 10px 18px 8px 18px;
  background: var(--bg-surface);
  flex-shrink: 0;
}

.toc-search-ic {
  position: absolute;
  left: 33px;
  top: 29px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  opacity: 0.55;
  pointer-events: none;
}
.toc-search-ic svg {
  width: 15px;
  height: 15px;
}

.toc-pop-input {
  width: 100%;
  height: 38px;
  border-radius: 11px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 13px;
  padding: 0 34px 0 37px;
  outline: none;
  transition: all 0.15s ease;
}
.toc-pop-input::placeholder {
  color: var(--text-muted);
}
.toc-pop-input:focus {
  border-color: var(--accent-gold-border);
  background-color: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--accent-gold-subtle);
}

/* List Wrap */
.toc-pop-list-wrap {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 6px 14px calc(20px + env(safe-area-inset-bottom, 0px)) 14px;
  background: var(--bg-surface);
  scrollbar-width: thin;
  scrollbar-color: var(--border-medium) transparent;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.toc-pop-list-wrap::-webkit-scrollbar {
  width: 5px;
}
.toc-pop-list-wrap::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 999px;
}

.toc-pop-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* 章节行 */
.rc-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  min-height: 47px;
  box-sizing: border-box;
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
  text-decoration: none;
  color: var(--text-secondary);
  -webkit-tap-highlight-color: transparent;
}
.rc-row:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
}
.rc-row:active {
  transform: scale(0.99);
}

.rc-row__no {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
  width: 30px;
  flex-shrink: 0;
  white-space: nowrap;
  text-align: right;
}

.rc-row__nm {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.rc-row__acc {
  flex-shrink: 0;
  margin-left: 8px;
  font-size: 10.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-muted);
  white-space: nowrap;
}

/* 当前行：金色微底 + 左侧竖条 */
.rc-row.cur {
  background: var(--accent-gold-subtle);
}
.rc-row.cur::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 999px;
  background: var(--accent-gold);
}
.rc-row.cur .rc-row__nm {
  color: var(--accent-gold);
  font-weight: 700;
}
.rc-row.cur .rc-row__no,
.rc-row.cur .rc-row__acc {
  color: var(--accent-gold);
  opacity: 0.85;
}

/* ==========================================================================
   MOBILE BOTTOM SHEET (iOS NATIVE REFINED LOOK)
   ========================================================================== */
@media (max-width: 640px) {
  #tocDrawer, #voiceSheet {
    align-items: flex-end !important;
    justify-content: center !important;
    padding: 0 !important;
  }

  #tocDrawer .toc-modal-panel, #voiceSheet .toc-modal-panel, #voiceSheet .voice-modal-panel {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 74vh !important;
    border-radius: 22px 22px 0 0 !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
    border-top: 1px solid var(--border-medium) !important;
    animation: slideInUp 0.26s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  /* 底部安全区交给 list-wrap 内边距处理（见 .toc-pop-list-wrap） */
  #tocDrawer .toc-modal-panel, #voiceSheet .toc-modal-panel, #voiceSheet .voice-modal-panel {
    padding-bottom: 0 !important;
  }
}

/* Voice Modal Panel Adjustments */
.voice-modal-panel {
  max-width: 620px;
}
.vs-modal-body {
  padding: 16px 20px 24px;
  overflow-y: auto;
  flex: 1;
}
