:root {
  --brand: #2f6df6;
  --brand-dark: #1f54cc;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1f2533;
  --muted: #6b7488;
  --border: #e4e8f0;
  --green: #2bb673;
  --red: #e25555;
  --yellow: #ffe28a;
  --green-hl: #b8f0c8;
  --blue-hl: #b6d4ff;
  --shadow: 0 6px 24px rgba(31, 37, 51, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--brand); }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding-top: max(10px, env(safe-area-inset-top));
}
.topbar .logo { font-weight: 700; font-size: 18px; color: var(--brand); margin-right: auto; }
.topbar .logo small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.nav-btn {
  border: none; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 10px; font-size: 15px; font-weight: 600;
}
.nav-btn.active { background: var(--brand); color: #fff; }
.icon-btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 10px; padding: 8px 12px; font-size: 14px; font-weight: 600;
}
.icon-btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.icon-btn.danger { color: var(--red); border-color: #f3c5c5; }

/* 容器 */
.container { max-width: 820px; margin: 0 auto; padding: 18px 16px 60px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* 卡片 */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 13px; }

/* 表单 */
input, textarea, select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); }
textarea { resize: vertical; min-height: 160px; line-height: 1.6; }
label { font-size: 13px; color: var(--muted); display: block; margin: 10px 0 4px; font-weight: 600; }

/* 阅读器 */
.reader-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.reader-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.article-title { font-size: 24px; font-weight: 700; margin: 8px 0 14px; color: var(--text); line-height: 1.4; word-wrap: break-word; padding: 0 24px; }
.article {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: var(--shadow); font-size: 18px; line-height: 1.9;
  word-wrap: break-word;
}
.article h1, .article h2, .article h3 { line-height: 1.4; margin: 1.2em 0 .5em; }
.article p { margin: 0 0 1em; }
.article code { background: #eef1f7; padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.article .word { cursor: pointer; border-bottom: 1px dotted #b9c2d6; transition: background .15s; }
.article .word:hover { background: #fff4d6; }
mark.hl { border-radius: 3px; padding: 0 1px; cursor: pointer; color: inherit; }
mark.hl.yellow { background: var(--yellow); }
mark.hl.green { background: var(--green-hl); }
mark.hl.blue { background: var(--blue-hl); }
mark.clip { background: rgba(47,109,246,0.08); color: inherit; cursor: pointer; text-decoration: underline; text-decoration-color: var(--brand); text-decoration-thickness: 2px; text-underline-offset: 2px; border-radius: 2px; }

/* 划词弹窗 */
.word-pop {
  position: absolute; z-index: 50; max-width: 320px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 12px 14px; font-size: 14px;
}
.word-pop .wp-word { font-size: 18px; font-weight: 700; }
.word-pop .wp-phon { color: var(--muted); margin: 2px 0 6px; }
.word-pop .wp-tran { color: var(--text); }
.word-pop .wp-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.word-pop .wp-note { color: var(--muted); font-size: 12px; margin-top: 4px; }
.mini-btn { border: 1px solid var(--border); background: #f7f9fc; border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; }
.mini-btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.swatch { width: 22px; height: 22px; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); }
.swatch.yellow { background: var(--yellow); }
.swatch.green { background: var(--green-hl); }
.swatch.blue { background: var(--blue-hl); }

/* 竖排右键菜单 */
.ctx-menu {
  position: absolute; z-index: 80; min-width: 184px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 34px rgba(20,26,40,.18); padding: 6px; font-size: 14px;
  animation: fadein .12s;
}
.ctx-header {
  padding: 8px 12px; color: var(--muted); font-size: 12px; line-height: 1.5;
  border-bottom: 1px solid var(--border); margin-bottom: 4px; white-space: normal; max-width: 260px;
}
.ctx-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; font-weight: 600;
  color: var(--text); white-space: nowrap; user-select: none;
}
.ctx-item:hover { background: #f1f5fd; }
.ctx-item.danger { color: var(--red); }
.ctx-item.danger:hover { background: #fdeaea; }
.ctx-item.disabled { color: var(--muted); cursor: default; }

.note-body { font-size: 15px; color: var(--text); }

/* 生词卡片 */
.flashcard {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 30px 24px; text-align: center; margin-bottom: 14px;
}
.flashcard .fc-word { font-size: 34px; font-weight: 800; }
.flashcard .fc-phon { color: var(--muted); margin: 6px 0 14px; }
.flashcard .fc-tran { font-size: 19px; }
.grade-row { display: flex; gap: 8px; margin-top: 18px; }
.grade-btn { flex: 1; border: none; border-radius: 10px; padding: 12px 4px; font-weight: 700; color: #fff; }
.grade-btn.again { background: #e25555; }
.grade-btn.hard { background: #e8a33d; }
.grade-btn.good { background: #2f6df6; }
.grade-btn.easy { background: #2bb673; }

/* 句子卡片 */
.flashcard .fc-sentence {
  font-size: 22px; font-weight: 600; line-height: 1.7;
  text-align: left; word-break: break-word; margin-bottom: 12px;
}
.flashcard .fc-note {
  font-size: 17px; text-align: left; color: var(--text);
  background: #f3f6fc; border-left: 3px solid var(--brand);
  padding: 10px 14px; border-radius: 8px; line-height: 1.7;
}

/* 列表 */
.list-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; }
.list-item .li-sub { color: var(--muted); font-size: 13px; }
.list-item .li-actions { display: flex; gap: 6px; flex-shrink: 0; }
.list-item .li-actions .clip-toggle { min-width: 28px; font-weight: 600; opacity: .5; }
.list-item .li-actions .clip-toggle.on { opacity: 1; color: var(--primary); }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20,26,40,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 520px;
  max-height: 86vh; overflow: auto; padding: 20px; box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* Toast */
#toast-root {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: #1f2533; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow); animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* 认证屏 */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--border); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 4px; font-size: 24px; color: var(--brand); }
.auth-card p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.tag { display: inline-block; font-size: 12px; background: #eef1f7; color: var(--muted); border-radius: 6px; padding: 2px 8px; }
.tag.due { background: #ffe9e9; color: var(--red); }

/* 个人导航首页 */
.home { max-width: 760px; margin: 0 auto; padding: 8px 4px 40px; }
.home-head { text-align: center; margin: 18px 0 14px; }
.home-head h1 { font-size: 30px; margin: 0; color: var(--brand); letter-spacing: 1px; }
.home-sub { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
.home-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px;
}
.home-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 14px; text-align: center; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.home-card:hover { transform: translateY(-3px); border-color: var(--brand); box-shadow: 0 10px 30px rgba(47,109,246,.18); }
.home-icon { font-size: 34px; margin-bottom: 8px; }
.home-title { font-weight: 700; font-size: 16px; }
.home-desc { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* 登录屏（全站密码门） */
.auth-input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px; box-sizing: border-box; outline: none; background: var(--panel); margin-top: 12px;
}
.auth-input:focus { border-color: var(--brand); }
.auth-card input:first-of-type { margin-top: 14px; }
.auth-captcha { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.auth-captcha-q { font-weight: 600; white-space: nowrap; }
.auth-err { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 10px; }
.auth-submit { width: 100%; margin-top: 14px; padding: 11px; font-size: 15px; }

/* 首页底部操作栏 */
.home-bottom { display: flex; gap: 12px; justify-content: center; margin-top: 26px; flex-wrap: wrap; }

/* 导航首页：顶部返回 + 编辑行 */
.home-head-top { display: flex; justify-content: space-between; align-items: center; max-width: 560px; margin: 0 auto 6px; padding: 0 2px; }
.home-card.editing { border-style: dashed; border-color: var(--brand); }
.home-card .home-del {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; line-height: 20px;
  border: none; border-radius: 50%; background: rgba(192,57,43,.12); color: var(--red);
  font-size: 13px; cursor: pointer;
}
.home-card { position: relative; }
.home-card.add { border-style: dashed; color: var(--muted); display: flex; flex-direction: column; justify-content: center; }
.home-card.add .home-icon { opacity: .6; }

/* 暂存：统一输入区 */
.stash-input-area {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 10px;
  transition: border-color .2s, background .15s;
}
.stash-input-area.drag-over {
  border-color: var(--brand); background: rgba(47,109,246,.04);
}
.stash-input-area.has-content {
  border-style: solid; border-color: var(--brand);
}
.stash-file-row {
  display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap;
}
.stash-file-preview {
  font-size: 13px; color: var(--text); max-width: 220px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

@media (max-width: 600px) {
  .article { font-size: 17px; padding: 18px 16px; }
  .topbar .logo small { display: none; }
  .home-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
}
