:root {
  --ink: #2b2724;
  --ink-soft: #57504a;
  --paper: #f4efe5;
  --paper-deep: #ece5d6;
  --card: #fffdf8;
  --line: #e6dfd0;
  --cinnabar: #a63a2e;
  --cinnabar-soft: #f3e2de;
  --jade: #3d6b63;
  --green: #6ea35a;
  --gold: #b08a4a;
  --muted: #8a8178;
  --shadow: 0 2px 10px rgba(60, 48, 34, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "PingFang SC", "Songti SC", "Noto Serif SC", serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 登录 ---------- */
.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 28px 20px;
  background: radial-gradient(120% 60% at 50% 0%, #fbf6ea 0%, var(--paper) 60%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card);
  border: 1px solid var(--line); border-radius: 18px;
  padding: 34px 26px 26px; box-shadow: 0 12px 34px rgba(60, 48, 34, .08);
}
.login-brand { font-size: 26px; letter-spacing: 4px; font-weight: 600; }
.login-sub { color: var(--muted); font-size: 13px; margin: 4px 0 26px; letter-spacing: 1px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.login-card input {
  width: 100%; margin-top: 6px; padding: 12px 14px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
  font-family: inherit;
}
.login-card input:focus { outline: none; border-color: var(--gold); }
.btn-primary {
  width: 100%; padding: 13px; border: none; border-radius: 12px;
  background: var(--cinnabar); color: #fff; font-size: 16px; letter-spacing: 2px;
  font-family: inherit; cursor: pointer;
}
.btn-primary:disabled { opacity: .6; }
.login-err { color: var(--cinnabar); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- 外壳 ---------- */
.app { min-height: 100vh; padding-bottom: 72px; }
#views { max-width: 640px; margin: 0 auto; padding: 0 14px; }

.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px; height: 62px;
  display: flex; background: rgba(255, 253, 248, .96);
  border-top: 1px solid var(--line); backdrop-filter: blur(10px);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
.tab {
  flex: 1; border: none; background: transparent; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 13px; cursor: pointer;
}
.tab .ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--cinnabar); font-weight: 600; }

/* ---------- 首页头部 ---------- */
.page-head { padding: 18px 2px 6px; display: flex; align-items: center; gap: 10px; }
.page-head h1 { font-size: 20px; margin: 0; letter-spacing: 2px; font-weight: 600; flex: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); color: var(--ink-soft); font-size: 16px; cursor: pointer;
}

.today-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px 18px 8px; box-shadow: var(--shadow); margin: 10px 0 18px;
}
.today-top { display: flex; align-items: center; gap: 10px; }
.today-badge {
  width: 28px; height: 28px; border-radius: 8px; background: #f6e9c9; color: var(--gold);
  display: grid; place-items: center; font-size: 14px;
}
.today-date { font-size: 16px; letter-spacing: 1px; }
.today-link { margin-left: auto; color: var(--muted); font-size: 13px; }
.today-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 14px; }
.today-stat { text-align: center; padding: 4px 0 10px; }
.today-stat .v { font-size: 30px; font-weight: 600; font-family: Georgia, "Times New Roman", serif; line-height: 1.1; }
.today-stat .k { font-size: 13px; color: var(--muted); margin-top: 4px; letter-spacing: 1px; }
.today-stat.green .v { color: var(--green); }
.today-stat.warn .v { color: var(--cinnabar); }

/* ---------- 分组切换 ---------- */
.group-bar { display: flex; align-items: center; gap: 18px; overflow-x: auto; padding: 2px 2px 12px; }
.group-bar::-webkit-scrollbar { display: none; }
.group-item {
  border: none; background: transparent; font-family: inherit; font-size: 16px;
  color: var(--muted); white-space: nowrap; cursor: pointer; padding: 4px 0; position: relative;
}
.group-item span { font-size: 12px; margin-left: 3px; }
.group-item.active { color: var(--ink); font-weight: 600; }
.group-item.active::after {
  content: ''; position: absolute; left: 50%; transform: translateX(-50%);
  bottom: -4px; width: 18px; height: 3px; border-radius: 2px; background: var(--green);
}
.group-add {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--ink-soft);
  background: transparent; color: var(--ink); font-size: 18px; flex: none; margin-left: auto;
}

/* ---------- 卡包列表 ---------- */
.deck-list { display: flex; flex-direction: column; gap: 14px; }
.deck-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer;
}
.deck-main { display: flex; align-items: center; gap: 14px; }
.deck-cover {
  width: 56px; height: 56px; border-radius: 14px; flex: none;
  display: grid; place-items: center; font-size: 22px; color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
.deck-title { flex: 1; min-width: 0; }
.deck-name {
  font-size: 16px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.deck-counts { display: flex; gap: 10px; font-size: 12px; margin-top: 5px; }
.deck-counts .new { color: var(--green); }
.deck-counts .due { color: var(--cinnabar); }
.deck-arrow { color: var(--muted); font-size: 16px; }
.deck-progress { margin-top: 12px; display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 6px; border-radius: 4px; background: #e9e2d3; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 4px; }
.bar b { font-weight: 400; font-size: 12px; color: var(--muted); }

.empty-tip { text-align: center; color: var(--muted); font-size: 14px; padding: 46px 0; }

.fab {
  position: fixed; right: 18px; bottom: 84px; width: 52px; height: 52px; border-radius: 50%;
  border: none; background: var(--cinnabar); color: #fff; font-size: 26px;
  box-shadow: 0 8px 20px rgba(166, 58, 46, .28); cursor: pointer; z-index: 29;
}

/* ---------- 卡包详情 ---------- */
.detail-head { padding: 18px 2px 10px; }
.back { border: none; background: transparent; color: var(--muted); font-size: 14px; padding: 0; cursor: pointer; }
.detail-title { font-size: 22px; font-weight: 600; margin: 10px 0 4px; letter-spacing: 1px; }
.detail-sub { color: var(--muted); font-size: 13px; }
.detail-actions { display: flex; gap: 10px; margin: 14px 0 18px; }
.btn { flex: 1; padding: 11px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-family: inherit; font-size: 14px; cursor: pointer; }
.btn.primary { background: var(--cinnabar); border-color: var(--cinnabar); color: #fff; }

.tree { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.tree-row {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid #f2ecdf; cursor: pointer;
}
.tree-row:last-child { border-bottom: none; }
.tree-row .caret { width: 14px; color: var(--muted); font-size: 12px; }
.tree-row .name { flex: 1; font-size: 15px; }
.tree-row .meta { font-size: 12px; color: var(--muted); }
.tree-row.child { padding-left: 38px; background: #fffdf8; }
.tree-row.child2 { padding-left: 62px; }

.card-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.mini-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 10px;
}
.mini-card .t { flex: 1; }
.mini-card .t b { display: block; font-size: 15px; font-weight: 600; }
.mini-card .t span { font-size: 12px; color: var(--muted); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #f0ece2; color: var(--ink-soft); white-space: nowrap; }

/* ---------- 学习页 ---------- */
.study { max-width: 640px; margin: 0 auto; padding: 12px 14px 20px; min-height: calc(100vh - 62px); display: flex; flex-direction: column; }
.ratings { margin-top: 16px; }
.study-top { display: flex; align-items: center; gap: 12px; padding: 6px 2px 10px; }
.study-top .progress { flex: 1; font-size: 13px; color: var(--muted); }
.study-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 10px 30px rgba(60, 48, 34, .08); flex: 0 0 auto; min-height: 340px;
  padding: 22px 20px; display: flex; flex-direction: column; cursor: pointer; position: relative;
}
.card-type { font-size: 11px; letter-spacing: 2px; color: var(--cinnabar); background: var(--cinnabar-soft); border-radius: 10px; padding: 2px 10px; align-self: flex-start; }
.study-card h2 { font-size: 30px; margin: 16px 0 6px; letter-spacing: 3px; font-weight: 600; }
.pinyin { color: var(--muted); font-size: 13px; letter-spacing: 1px; }
.alias { color: var(--muted); font-size: 12px; margin-top: 6px; }
.back-area { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 16px; overflow-y: auto; }
.summary { font-size: 16px; font-weight: 600; margin-bottom: 10px; line-height: 1.7; }
.fld { display: flex; gap: 10px; padding: 6px 0; font-size: 14px; border-bottom: 1px solid #f4efe4; }
.fld:last-child { border-bottom: none; }
.fld .k { color: var(--muted); width: 68px; flex: none; font-size: 13px; }
.fld .v { flex: 1; line-height: 1.7; }
.detail { margin-top: 12px; font-size: 14px; line-height: 1.85; color: var(--ink-soft); white-space: pre-wrap; }
.source { margin-top: 12px; font-size: 12px; color: var(--muted); }
.tap-hint { position: absolute; bottom: 16px; left: 0; right: 0; text-align: center; color: var(--muted); font-size: 12px; }

.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.rating {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 10px 4px; font-family: inherit; cursor: pointer; display: flex; flex-direction: column; gap: 2px; align-items: center;
}
.rating b { font-size: 14px; font-weight: 600; }
.rating span { font-size: 11px; color: var(--muted); }
.rating.r1 { border-color: #e9cbc5; } .rating.r1 b { color: var(--cinnabar); }
.rating.r2 { border-color: #ecd9b8; } .rating.r2 b { color: #b07c26; }
.rating.r3 { border-color: #cfe0cd; } .rating.r3 b { color: var(--green); }
.rating.r4 { border-color: #cbdde0; } .rating.r4 b { color: var(--jade); }

.done { text-align: center; padding: 60px 20px; }
.done h2 { font-size: 22px; letter-spacing: 2px; }
.done p { color: var(--muted); margin: 8px 0 24px; }

/* ---------- 资源库 / 我的 ---------- */
.section-title { font-size: 15px; color: var(--muted); margin: 18px 2px 10px; letter-spacing: 1px; }
.lib-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; display: flex; align-items: center; gap: 12px; margin-bottom: 10px; cursor: pointer;
}
.lib-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.lib-item .n { flex: 1; font-size: 15px; }
.lib-item .c { font-size: 12px; color: var(--muted); }

.me-head { display: flex; align-items: center; gap: 14px; padding: 22px 2px 8px; }
.avatar {
  width: 58px; height: 58px; border-radius: 50%; background: var(--cinnabar-soft);
  color: var(--cinnabar); display: grid; place-items: center; font-size: 20px; font-weight: 600;
}
.me-name { font-size: 18px; font-weight: 600; }
.me-sub { color: var(--muted); font-size: 12px; }
.me-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.me-stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-align: center; }
.me-stat .v { font-size: 22px; font-weight: 600; font-family: Georgia, serif; }
.me-stat .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.levels { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-top: 14px; }
.level-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.level-row .n { width: 56px; font-size: 13px; }
.level-row .bar { height: 8px; }
.level-row .v { width: 32px; text-align: right; font-size: 13px; color: var(--muted); }
.week { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; height: 90px; margin-top: 8px; }
.week-col { flex: 0 0 auto; width: 12%; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.week-col i { display: block; width: 100%; background: var(--green); border-radius: 4px; min-height: 3px; }
.week-col i.nil { background: #e6dfd4; }
.week-col span { font-size: 11px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  background: rgba(43, 39, 36, .9); color: #fff; padding: 9px 16px; border-radius: 20px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 60;
}
.toast.show { opacity: 1; }

[hidden] { display: none !important; }

/* ---------- 底部弹层 / 分组管理 ---------- */
.sheet-mask { position: fixed; inset: 0; background: rgba(35, 28, 20, .38); display: flex; align-items: flex-end; justify-content: center; z-index: 60; }
.sheet { width: 100%; max-width: 640px; background: var(--card); border-radius: 20px 20px 0 0; padding: 8px 16px 18px; max-height: 82vh; display: flex; flex-direction: column; animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: .7; } to { transform: none; opacity: 1; } }
.sheet-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px 10px; }
.sheet-bar b { font-size: 16px; letter-spacing: 1px; }
.sheet-body { overflow-y: auto; }
.f-label { display: block; font-size: 13px; color: var(--muted); margin: 10px 2px 6px; }
.f-input { width: 100%; padding: 12px 14px; font-size: 15px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); font-family: inherit; }
.f-input:focus { outline: none; border-color: var(--gold); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.on { border-color: var(--ink); }
.btn-primary { margin-top: 16px; }
.btn-ghost { width: 100%; margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--cinnabar); font-family: inherit; font-size: 15px; cursor: pointer; }
.add-deck { width: 100%; margin-top: 12px; padding: 14px; border: 1px dashed var(--line); border-radius: 14px; background: transparent; color: var(--ink-soft); font-family: inherit; font-size: 15px; cursor: pointer; }
.add-deck:active { background: var(--paper-deep); }
.pick-sub { font-size: 13px; color: var(--muted); margin: 14px 2px 6px; letter-spacing: 1px; }
.pick-row { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick-row .deck-cover { width: 42px; height: 42px; font-size: 16px; flex: 0 0 auto; }
.pick-main { flex: 1; min-width: 0; }
.pick-main p { margin: 0; font-size: 15px; }
.pick-main span { font-size: 12px; color: var(--muted); }
.pick-act { font-size: 13px; color: var(--cinnabar); }
.pick-row.used { opacity: .55; }
.pick-row.used .pick-act { color: var(--muted); }
.manage-row { display: flex; align-items: center; gap: 10px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.manage-row .n { flex: 1; font-size: 15px; }
.manage-row .c { font-size: 12px; color: var(--muted); }
.mini { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 10px; font-size: 12px; color: var(--ink-soft); font-family: inherit; cursor: pointer; }
