/* ========== 全域 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0c0b0e;
  --surface: #1a181d;
  --surface-light: #2a2730;
  --border: #3a3841;
  --text: #f0eef2;
  --text-muted: #9e9aa8;
  --accent: #c9a96b;
  --accent-dark: #a88955;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Serif TC', 'Inter', serif;
  line-height: 1.6;
  min-height: 100vh;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--surface);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-dark);
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.line-clamp-1 {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ========== 經文區塊 ========== */
.verse-block {
  border-left: 3px solid transparent;
  transition: all 0.2s;
  scroll-margin-top: 1rem;
  cursor: pointer;
}
.verse-block.highlighted {
  border-left-color: #ffeb3b;
  background: rgba(255, 235, 59, 0.1);
}
.verse-block.selected {
  border: 2px solid var(--accent);
}
.highlight-text {
  background-color: #ffeb3b;
  color: #000;
  padding: 0 2px;
  border-radius: 2px;
}

e {
  font-style: italic;
  color: var(--accent);
  border-bottom: 1px dotted var(--accent);
  cursor: help;
}

/* ========== 浮動工具列 ========== */
.floating-tools {
  position: fixed;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(26, 24, 29, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 2rem;
  padding: 0.75rem;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 40;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  cursor: default;
}
.floating-tools.hidden {
  opacity: 0;
  pointer-events: none;
}
.floating-tools.folded .tools-content {
  display: none;
}
.floating-tools.folded .tools-minimized {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.floating-tools .tools-minimized {
  display: none;
}
.floating-tools:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.drag-handle {
  cursor: move;
  width: 100%;
  height: 1rem;
  background: var(--border);
  border-radius: 2rem 2rem 0 0;
  margin-bottom: 0.25rem;
}
.tool-btn {
  width: 2.5rem;
  height: 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
}
.tool-btn:hover {
  border-color: var(--accent);
  background: var(--surface-light);
  transform: scale(1.1);
}
.tool-btn.active {
  background: var(--accent);
  color: var(--bg);
}
@media (max-width: 640px) {
  .floating-tools {
    background: rgba(26, 24, 29, 0.95);
  }
  .tool-btn {
    width: 2rem;
    height: 2rem;
  }
}

/* ========== 筆記面板 ========== */
.notes-panel {
  position: fixed;
  top: 0;
  right: -400px;
  width: 350px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  transition: right 0.3s ease;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.notes-panel.open {
  right: 0;
}
@media (max-width: 640px) {
  .notes-panel {
    width: 100%;
  }
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}
.note-item, .bookmark-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  margin-bottom: 0.8rem;
}

/* ========== Modal ========== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

/* ========== AI 聊天 ========== */
.msg {
  animation: fadeIn 0.3s ease;
}
.msg.user {
  display: flex;
  justify-content: flex-end;
}
.msg.bot {
  display: flex;
  justify-content: flex-start;
}
.bubble {
  max-width: 90%;
  padding: 0.6rem 1rem;
  border-radius: 1rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.user .bubble {
  background: var(--accent);
  color: var(--bg);
  border-top-right-radius: 0;
}
.msg.bot .bubble {
  background: var(--surface-light);
  color: var(--text);
  border-top-left-radius: 0;
}
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background-color: var(--accent);
  margin-left: 2px;
  animation: blink 1s infinite;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 高亮區塊更明顯 */
.verse-block.highlighted {
  border-left: 4px solid #ffeb3b;
  background: rgba(255, 235, 59, 0.08);
  transition: all 0.2s;
}

/* AI 訊息內的程式碼區塊（若有）保持可讀 */
.msg.bot .bubble pre {
  background: #0c0b0e;
  border-radius: 8px;
  padding: 0.5rem;
  overflow-x: auto;
  font-size: 0.8rem;
}

/* 管理後台表格在手機上適當縮小 */
@media (max-width: 640px) {
  .table-container {
    max-height: 60vh;
  }
}