:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --ink: #2b2b2b;
  --ink-soft: #6b6b6b;
  --line: #e6e4df;
  --accent: #4a6fa5;
  --accent-soft: #e8eef7;
  --rep-low: #b3541e;
  --rep-low-bg: #fdf1e7;
  --rep-mid: #2e6da4;
  --rep-high: #2b2b2b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.8;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 760px; margin: 0 auto; padding: 14px 20px;
}
.brand { font-size: 20px; font-weight: 700; color: var(--ink); text-decoration: none; }
.topbar nav a { color: var(--ink-soft); text-decoration: none; margin-left: 16px; font-size: 14px; }
.topbar nav a:hover { color: var(--accent); }
main { max-width: 760px; margin: 0 auto; padding: 10px 20px 60px; }

/* 登录 */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 40px 36px; width: 320px; text-align: center;
}
.login-card h1 { font-size: 26px; margin-bottom: 6px; }
.login-card p { color: var(--ink-soft); font-size: 14px; margin-bottom: 22px; }
.login-card input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 15px; margin-bottom: 12px;
}
.login-card button {
  width: 100%; padding: 11px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
}
.login-error { color: #b03a2e; font-size: 14px; margin-bottom: 12px; }

/* 首页 */
.upload-card, .doc-list {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px 28px; margin-top: 18px;
}
.upload-card h2, .doc-list h2 { font-size: 18px; margin-bottom: 8px; }
.hint { color: var(--ink-soft); font-size: 14px; margin-bottom: 18px; }
.form-row { display: flex; gap: 10px; margin-bottom: 12px; }
.form-row input[type=text] {
  flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.form-row select {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; background: #fff;
}
.file-drop {
  display: block; border: 2px dashed var(--line); border-radius: 10px;
  padding: 30px; text-align: center; color: var(--ink-soft);
  cursor: pointer; margin-bottom: 16px; font-size: 14px;
}
.file-drop:hover { border-color: var(--accent); color: var(--accent); }
.file-drop input { display: none; }
button.primary {
  width: 100%; padding: 12px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
}
.doc-list ul { list-style: none; }
.doc-list li a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 4px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--ink);
}
.doc-list li a:hover strong { color: var(--accent); }
.doc-list .meta { color: var(--ink-soft); font-size: 13px; }
.empty { color: var(--ink-soft); font-size: 14px; padding: 12px 0; }

/* 阅读页 */
.reader-header { margin-bottom: 24px; }
.reader-header h1 { font-size: 26px; line-height: 1.4; }
.reader-header .meta { color: var(--ink-soft); font-size: 13px; margin-top: 6px; }
.reader .block { margin: 14px 0; font-size: 18px; }
.reader h2.block { font-size: 23px; margin-top: 28px; }
.reader h3.block, .reader h4.block { font-size: 20px; margin-top: 24px; }
.reader blockquote.block {
  border-left: 3px solid var(--line); padding-left: 14px; color: var(--ink-soft);
}
.reader .list-item { padding-left: 22px; position: relative; }
.reader .list-item::before { content: "•"; position: absolute; left: 6px; color: var(--ink-soft); }

/* 替换词 */
.rep { border-radius: 4px; padding: 0 2px; cursor: pointer; transition: background .15s; }
.rep-low { color: var(--rep-low); background: var(--rep-low-bg); font-weight: 600; }
.rep-low:hover { background: #fbe3cf; }
.rep-mid { color: var(--rep-mid); border-bottom: 1px dashed var(--rep-mid); }
.rep-mid:hover { background: var(--accent-soft); }
.rep-high { color: var(--rep-high); border-bottom: 1px dotted #b9b9b9; }
.rep-high:hover { background: #efefef; }
.gloss { color: var(--ink-soft); font-size: 0.82em; font-style: normal; }

/* 查词浮层 */
.tooltip {
  position: fixed; z-index: 50; background: #2b2b2b; color: #fff;
  border-radius: 10px; padding: 12px 16px; max-width: 280px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 14px;
}
.tooltip-zh { font-size: 18px; font-weight: 700; }
.tooltip-en { color: #c9c9c9; margin-top: 2px; }
.tooltip-actions { margin-top: 10px; display: flex; gap: 8px; }
.tooltip-actions button {
  border: 1px solid #555; background: transparent; color: #ddd;
  border-radius: 6px; padding: 4px 10px; font-size: 13px; cursor: pointer;
}
.tooltip-actions button:hover { background: #3d3d3d; }
.tooltip-gloss { margin-top: 8px; color: #e8e8e8; font-size: 13px; line-height: 1.6; }
.tooltip-gloss .pos { color: #9db8d9; font-style: italic; }
.tooltip-gloss .example { margin-top: 6px; color: #c9d6e8; }
.tooltip-gloss .example-zh { color: #9a9a9a; font-size: 12px; }
button.secondary {
  padding: 10px 18px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); font-size: 14px; cursor: pointer;
}
button.secondary:hover { border-color: var(--accent); color: var(--accent); }

@media (max-width: 640px) {
  .reader .block { font-size: 17px; }
  .reader-header h1 { font-size: 22px; }
}

/* 章节目录 */
.toc {
  position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 40;
  background: var(--card); border-right: 1px solid var(--line);
  padding: 18px; overflow-y: auto;
}
.toc-header { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 12px; }
.toc-header button { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--ink-soft); }
.toc ul { list-style: none; }
.toc li a {
  display: block; padding: 8px 10px; border-radius: 8px; font-size: 14px;
  color: var(--ink); text-decoration: none;
}
.toc li a:hover { background: var(--accent-soft); }
.toc li a.active { background: var(--accent); color: #fff; }
.toc-toggle {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; margin-bottom: 10px;
}
.ch-title { color: var(--ink-soft); font-size: 0.7em; font-weight: 400; }
.chapter-pager {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 30px; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 14px; color: var(--ink-soft);
}
.chapter-pager a { color: var(--accent); text-decoration: none; }

/* 难度版本切换 */
.level-switch { display: flex; align-items: center; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.level-label { font-size: 13px; color: var(--ink-soft); }
.level-switch button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 4px 12px; font-size: 13px; cursor: pointer; color: var(--ink-soft);
}
.level-switch button:hover { border-color: var(--accent); color: var(--accent); }
.level-switch button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.level-tip { font-size: 12px; color: #b0aca4; margin-left: 4px; }

/* 对话面板 */
.chat-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 45;
  border: none; border-radius: 999px; padding: 12px 20px;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
  box-shadow: 0 6px 18px rgba(74,111,165,.4);
}
.chat-panel {
  position: fixed; right: 22px; bottom: 80px; z-index: 46;
  width: 340px; max-width: calc(100vw - 44px); height: 460px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  display: flex; flex-direction: column; box-shadow: 0 12px 32px rgba(0,0,0,.15);
}
.chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700;
}
.chat-header button { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--ink-soft); }
.chat-messages { flex: 1; overflow-y: auto; padding: 14px; }
.chat-msg {
  max-width: 88%; padding: 9px 12px; border-radius: 12px;
  margin-bottom: 10px; font-size: 14px; line-height: 1.6; white-space: pre-wrap;
}
.chat-user { background: var(--accent); color: #fff; margin-left: auto; }
.chat-agent { background: var(--accent-soft); color: var(--ink); }
.chat-sys { background: none; color: var(--ink-soft); font-size: 12px; text-align: center; max-width: 100%; }
.chat-changes { margin-top: 8px; padding-left: 18px; font-size: 12px; color: var(--ink-soft); }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-input input {
  flex: 1; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px;
}
.chat-input button {
  border: none; border-radius: 8px; padding: 9px 16px;
  background: var(--accent); color: #fff; font-size: 14px; cursor: pointer;
}
