:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e5e9f2;
  --text: #1d2333;
  --muted: #7a8499;
  --primary: #4f6ef2;
  --primary-dark: #3d57d8;
  --primary-soft: #eef1fe;
  --success: #16a34a;
  --success-soft: #e9f9ef;
  --danger: #dc2626;
  --danger-soft: #fdeeee;
  --warn: #d97706;
  --warn-soft: #fef6e7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(23, 33, 68, .06), 0 6px 20px rgba(23, 33, 68, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }

/* ---------- 布局 ---------- */
.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px 40px; }

header.top {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
header.top .inner {
  max-width: 960px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.logo { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo span { font-size: 22px; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.userbox .uname { color: var(--text); font-weight: 600; }

nav.tabs {
  max-width: 960px; margin: 0 auto; padding: 0 16px;
  display: flex; gap: 4px; overflow-x: auto;
}
nav.tabs a {
  padding: 9px 14px; color: var(--muted); font-size: 14px; font-weight: 500;
  border-radius: 10px 10px 0 0; white-space: nowrap; border-bottom: 2px solid transparent;
}
nav.tabs a.active { color: var(--primary); background: var(--primary-soft); border-bottom-color: var(--primary); }
nav.tabs a .badge {
  display: inline-block; background: var(--danger); color: #fff; font-size: 11px;
  border-radius: 99px; padding: 0 6px; margin-left: 4px; line-height: 17px;
}
/* 桌面端只显示顶部导航，隐藏底部导航 */
nav.tabs.bottom-nav { display: none; }

main { padding: 20px 0; }
.hide { display: none !important; }

/* ---------- 通用组件 ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 16px;
}
.card h2 { font-size: 17px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card h3 { font-size: 14px; margin: 14px 0 8px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  padding: 9px 18px; border-radius: 10px; font-size: 14px; font-weight: 600;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.gray { background: #eef1f6; color: var(--text); }
.btn.gray:hover { background: #e2e7ef; }
.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; font-family: var(--font); background: #fbfcfe; color: var(--text);
  outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,110,242,.15); }
textarea { resize: vertical; min-height: 180px; line-height: 1.7; }
label.field { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); font-weight: 600; }
label.field input, label.field textarea, label.field select { margin-top: 6px; font-weight: 400; }

.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.space-between { justify-content: space-between; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; } .mb12 { margin-bottom: 12px; }
.grow { flex: 1; }

.chip {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 99px; background: #eef1f6; color: var(--muted);
}
.chip.blue { background: var(--primary-soft); color: var(--primary); }
.chip.green { background: var(--success-soft); color: var(--success); }
.chip.orange { background: var(--warn-soft); color: var(--warn); }
.chip.red { background: var(--danger-soft); color: var(--danger); }

/* ---------- 登录 ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(160deg, #eef1fe 0%, #f4f6fb 45%, #e9f9ef 100%);
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card .logo { justify-content: center; font-size: 22px; margin-bottom: 6px; }
.auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.auth-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; text-align: center; }

/* ---------- 首页仪表盘 ---------- */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, #6f8bff 100%);
  color: #fff; border-radius: var(--radius); padding: 26px 24px; margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  box-shadow: 0 8px 24px rgba(79,110,242,.25);
}
.hero h1 { font-size: 20px; margin-bottom: 4px; }
.hero .muted { color: rgba(255,255,255,.85); }
.hero .big { font-size: 34px; font-weight: 800; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-align: center; box-shadow: var(--shadow);
}
.stat .num { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat .num.green { color: var(--success); }
.stat .num.orange { color: var(--warn); }
.stat .lab { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- 词表 ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.toolbar > * { flex-shrink: 0; }
.toolbar input[type=text] { flex: 1 1 200px; min-width: 0; }
.toolbar select { flex: 0 0 auto; }

table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.list td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list tr:last-child td { border-bottom: none; }
table.list td.ops { white-space: nowrap; }
.w { font-weight: 700; font-size: 15px; word-break: break-word; }
.pho { color: var(--muted); font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.tr { color: var(--muted); font-size: 13px; max-width: 320px; }
.tr.clamp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 移动端：词表改为卡片式堆叠，避免横向滚动难读 */
.words-cards { display: none; }
@media (max-width: 720px) {
  .words-table { display: none; }
  .words-cards { display: block; }
  .wc {
    background: var(--card); border: 1px solid var(--border); border-radius: 12px;
    padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow);
  }
  .wc .wc-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
  .wc .wc-tr { color: var(--muted); font-size: 13px; margin-top: 4px; word-break: break-word; }
  .wc .wc-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
  .wc .wc-ops { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
  .wc .wc-ops .btn { flex: 1 1 auto; }
}

/* ---------- 学习卡片 ---------- */
.study-stage {
  max-width: 640px; margin: 0 auto; text-align: center;
}
.flash-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow); padding: 36px 28px; margin-bottom: 18px; min-height: 280px;
  display: flex; flex-direction: column; justify-content: center;
}
.flash-card .word { font-size: 40px; font-weight: 800; letter-spacing: .5px; word-break: break-word; overflow-wrap: anywhere; line-height: 1.15; }
@media (max-width: 720px) { .flash-card .word { font-size: 32px; } }
.flash-card .pho { font-size: 17px; margin-top: 6px; }
.flash-card .speaker {
  margin-top: 10px; background: var(--primary-soft); border: none; cursor: pointer;
  width: 44px; height: 44px; border-radius: 50%; font-size: 20px; color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
}
.flash-card .speaker:hover { background: #dfe6fd; }
.flash-card .answer-part { margin-top: 18px; animation: fadein .25s ease; }
.flash-card .answer-part .cn { font-size: 19px; font-weight: 600; color: var(--text); white-space: pre-wrap; }
.flash-card .answer-part .ctx {
  margin-top: 12px; background: #f8faff; border-left: 3px solid var(--primary);
  border-radius: 8px; padding: 10px 14px; text-align: left; font-size: 13.5px; color: #45506b;
}
.rate-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate-btns .btn { padding: 12px 4px; font-size: 13px; flex-direction: column; border-radius: 12px; }
.rate-btns .btn b { font-size: 16px; }
.btn.rate0 { background: var(--danger-soft); color: var(--danger); }
.btn.rate0:hover { background: #fbdcdc; }
.btn.rate3 { background: var(--warn-soft); color: var(--warn); }
.btn.rate3:hover { background: #fdeccd; }
.btn.rate4 { background: var(--success-soft); color: var(--success); }
.btn.rate4:hover { background: #d8f3e3; }
.btn.rate5 { background: var(--primary-soft); color: var(--primary); }
.btn.rate5:hover { background: #dfe6fd; }

.progress-bar { height: 6px; background: #e8ecf5; border-radius: 99px; overflow: hidden; margin: 14px 0; }
.progress-bar i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s; }

/* ---------- 练习 ---------- */
.practice-q { max-width: 640px; margin: 0 auto; }
.q-stem {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px; margin-bottom: 14px; text-align: center; box-shadow: var(--shadow);
  font-size: 19px; font-weight: 600; line-height: 1.7;
}
.q-options { display: grid; gap: 10px; }
.q-opt {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 13px 16px; font-size: 15px; text-align: left; cursor: pointer;
  transition: all .12s; box-shadow: var(--shadow);
}
.q-opt:hover { border-color: var(--primary); transform: translateY(-1px); }
.q-opt.correct { background: var(--success-soft); border-color: var(--success); color: var(--success); font-weight: 700; }
.q-opt.wrong { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.q-opt:disabled { cursor: default; transform: none; }
.q-feedback { text-align: center; margin-top: 12px; font-weight: 600; min-height: 24px; }

/* ---------- 选择列表（候选词） ---------- */
.cand { display: flex; align-items: flex-start; gap: 10px; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.cand:last-child { border-bottom: none; }
.cand input[type=checkbox] { margin-top: 5px; width: 16px; height: 16px; accent-color: var(--primary); flex-shrink: 0; }
.cand .c-word { font-weight: 700; }
.cand .c-ctx { font-size: 12.5px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- 统计 ---------- */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.chart .bar { flex: 1; background: var(--primary-soft); border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.chart .bar.reviewed { background: var(--primary); }
.chart .bar.new { background: var(--success); }
.chart-x { display: flex; gap: 3px; font-size: 10px; color: var(--muted); }
.chart-x span { flex: 1; text-align: center; overflow: hidden; }

/* ---------- 弹层 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 28, 51, .45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--card); border-radius: 16px; max-width: 640px; width: 100%;
  max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal .m-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 700; display: flex; align-items: center; }
.modal .m-head .x { margin-left: auto; cursor: pointer; color: var(--muted); font-size: 20px; background: none; border: none; }
.modal .m-body { padding: 16px 20px; overflow-y: auto; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
@media (max-width: 720px) {
  .modal { max-height: 82vh; }
  .modal-mask { padding: 8px; align-items: flex-end; }
  .modal { max-width: 100%; border-radius: 16px 16px 0 0; }
}
.modal .m-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Toast ---------- */
#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1d2333; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: fadein .2s ease; max-width: 90vw;
}
.toast.ok { background: var(--success); }
.toast.err { background: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty .e-icon { font-size: 40px; margin-bottom: 8px; }

@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 移动端 ---------- */
@media (max-width: 720px) {
  /* 移动端隐藏顶部 tab，仅保留底部固定导航 */
  nav.tabs.top-nav { display: none; }
  nav.tabs.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; background: var(--card);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; z-index: 60; border-radius: 0;
    max-width: none; margin: 0;
  }
  nav.tabs a { padding: 6px 10px; font-size: 12px; border-radius: 10px; border-bottom: none; display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1 1 0; }
  nav.tabs a.active { background: var(--primary-soft); }
  nav.tabs a .tab-ic { font-size: 18px; }
  nav.tabs a .badge { margin-left: 2px; }
  main { padding: 14px 0 84px; }
  .wrap { padding: 0 12px 20px; }
  table.list { display: block; overflow-x: auto; }
  .rate-btns { grid-template-columns: repeat(2, 1fr); }
  /* 素材页两栏在移动端纵向堆叠 */
  .row.responsive > .grow { flex: 1 1 100%; min-width: 0 !important; }
  /* 工具栏在移动端更紧凑 */
  .toolbar { gap: 6px; }
  .toolbar .grow { flex-basis: 100%; }
  .btn.block { font-size: 15px; }
  .hero { padding: 20px 18px; }
  .hero .big { font-size: 28px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px 10px; }
  .stat .num { font-size: 22px; }
}