:root {
  --bg: #faf7f0;
  --card: #ffffff;
  --ink: #2b2b2b;
  --muted: #8a8578;
  --accent: #b45309;
  --accent-soft: #fde8cd;
  --border: #e8e2d4;
  --shadow: 0 2px 12px rgba(90, 70, 30, 0.08);
  --serif: Georgia, "Times New Roman", "Noto Serif SC", serif;
  --sans: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  min-height: 100vh;
}
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px;
  background: rgba(250, 247, 240, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; cursor: pointer; }
.topbar nav { display: flex; gap: 6px; }
.nav-btn {
  border: none; background: none; padding: 8px 14px;
  border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--ink);
}
.nav-btn:hover { background: var(--accent-soft); }
.nav-btn.active { background: var(--accent); color: #fff; }
.nav-btn:disabled { opacity: 0.4; cursor: default; }
.badge {
  background: var(--accent); color: #fff; border-radius: 10px;
  padding: 1px 7px; font-size: 11px; vertical-align: 1px;
}
.nav-btn.active .badge { background: #fff; color: var(--accent); }

.view { max-width: 900px; margin: 0 auto; padding: 24px; }

/* ---------- 书架 ---------- */
.upload-zone {
  border: 2px dashed var(--border); border-radius: 16px;
  background: var(--card); text-align: center; padding: 36px 20px;
  transition: border-color 0.2s, background 0.2s;
}
.upload-zone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.upload-icon { font-size: 42px; }
.hint { color: var(--muted); font-size: 13px; }
.hint select { font-size: 13px; padding: 3px 6px; }

.book-list { margin-top: 24px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.book-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform 0.15s;
  position: relative;
}
.book-card:hover { transform: translateY(-2px); }
.book-card h3 { margin: 0 0 6px; font-size: 16px; padding-right: 28px; }
.book-card .meta { color: var(--muted); font-size: 12px; }
.book-card .progress-bar {
  height: 5px; background: var(--border); border-radius: 3px; margin-top: 12px; overflow: hidden;
}
.book-card .progress-bar > div { height: 100%; background: var(--accent); }
.book-del {
  position: absolute; top: 12px; right: 12px;
  border: none; background: none; cursor: pointer; color: var(--muted); font-size: 14px;
}
.book-del:hover { color: #c0392b; }
.empty-tip { color: var(--muted); text-align: center; grid-column: 1/-1; padding: 30px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block; border: 1px solid var(--border); background: var(--card);
  border-radius: 8px; padding: 8px 16px; cursor: pointer; font-size: 14px; color: var(--ink);
}
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.icon-btn { border: none; background: none; cursor: pointer; font-size: 15px; color: var(--muted); }
.icon-btn:hover { color: var(--ink); }

/* ---------- 阅读器 ---------- */
#view-reader { max-width: 780px; }
.reader-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-bottom: 14px; flex-wrap: wrap;
}
#chapterSelect { max-width: 320px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); }
.reader-tools { display: flex; gap: 6px; }
.reader-content {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px 48px; box-shadow: var(--shadow);
  font-family: var(--serif); font-size: 19px; line-height: 1.9;
}
.reader-content h2.ch-title { font-size: 24px; margin-top: 0; }
.reader-content p { margin: 0 0 1em; }
.w { cursor: pointer; border-radius: 3px; padding: 0 1px; }
.w:hover { background: var(--accent-soft); }
.w.active { background: var(--accent); color: #fff; }
.w.known { border-bottom: 2px solid #e2b04a; }

.selection-bar {
  position: fixed; z-index: 90;
  background: #2b2b2b; border-radius: 10px; padding: 4px;
  display: flex; gap: 2px; box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.selection-bar button {
  border: none; background: none; color: #fff; padding: 7px 12px;
  cursor: pointer; font-size: 13px; border-radius: 7px;
}
.selection-bar button:hover { background: rgba(255,255,255,0.15); }

/* ---------- 侧边卡片 ---------- */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 400px; max-width: 92vw;
  background: var(--card); border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(90,70,30,0.12); z-index: 100;
  display: flex; flex-direction: column;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.panel-body { padding: 18px; overflow-y: auto; flex: 1; font-size: 14px; }

.wc-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.wc-word { font-size: 26px; font-weight: 700; font-family: var(--serif); }
.wc-phonetic { color: var(--muted); }
.wc-emoji { font-size: 22px; }
.wc-pos { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 8px; font-size: 12px; margin: 6px 0; }
.wc-translation { font-size: 17px; font-weight: 600; margin: 6px 0 2px; }
.wc-section { margin-top: 14px; }
.wc-section h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); letter-spacing: 1px; }
.wc-example { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.wc-example .ex-text { font-family: var(--serif); }
.wc-example .ex-trans { color: var(--muted); font-size: 13px; margin-top: 3px; }
.wc-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.wc-context { font-style: italic; color: var(--muted); font-size: 13px; }
.mnemonic { background: #fdf6e3; border-left: 3px solid #e2b04a; padding: 10px 12px; border-radius: 0 10px 10px 0; }
.cache-tip { font-size: 12px; color: var(--muted); margin-top: 12px; }
.cache-tip a { color: var(--accent); cursor: pointer; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.loading .spinner {
  width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; margin: 0 auto 12px; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: #fdeaea; color: #b03a2e; border-radius: 10px; padding: 12px; }

/* ---------- 生词本 ---------- */
.vocab-toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
#vocabSearch { flex: 1; min-width: 180px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); }
.check { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.vocab-list { display: flex; flex-direction: column; gap: 12px; }
.vocab-item {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.vocab-item .vi-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.vocab-item .vi-word { font-size: 18px; font-weight: 700; font-family: var(--serif); }
.vocab-item .vi-phonetic { color: var(--muted); font-size: 13px; }
.vocab-item .vi-trans { margin: 4px 0; }
.hide-meaning .vi-trans, .hide-meaning .vi-context { filter: blur(5px); cursor: pointer; }
.hide-meaning .vi-trans.revealed, .hide-meaning .vi-context.revealed { filter: none; }
.vocab-item .vi-context { color: var(--muted); font-size: 13px; font-style: italic; }
.vocab-item .vi-actions { margin-top: 8px; display: flex; gap: 6px; }

/* ---------- 设置 ---------- */
.settings-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; max-width: 560px; margin: 0 auto; box-shadow: var(--shadow);
}
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: var(--bg);
}
.settings-actions { display: flex; gap: 10px; align-items: center; }
#testResult { font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #2b2b2b; color: #fff; padding: 10px 20px; border-radius: 10px;
  font-size: 14px; z-index: 200; box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

@media (max-width: 600px) {
  .reader-content { padding: 22px 18px; font-size: 17px; }
  .view { padding: 14px; }
  .topbar { padding: 8px 12px; }
  .nav-btn { padding: 7px 9px; font-size: 13px; }
}
