:root {
  --paper: #F5EFFC;
  --paper-2: #FFFFFF;
  --ink: #2C2140;
  --ink-2: #5B4E7A;
  --muted: #8F84AB;
  --line: #E7DCF7;
  --accent: #7A45C0;
  --accent-2: #A87BE8;
  --accent-soft: #F1E7FD;
  --pink: #C2417E;
  --green: #3C6E5B;
  --blue: #4C63B8;
  --gold: #B4801F;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 34, 96, .06), 0 10px 26px -18px rgba(60, 34, 96, .34);
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --serif: "Songti SC", "Noto Serif SC", "STSong", Georgia, serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
}

body {
  background-image: radial-gradient(circle at 12% 6%, rgba(122, 69, 192, .12), transparent 46%),
    radial-gradient(circle at 88% 2%, rgba(194, 65, 126, .09), transparent 42%),
    radial-gradient(circle at 50% 100%, rgba(168, 123, 232, .10), transparent 55%);
  background-attachment: fixed;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: #C2334D; font-size: 13px; min-height: 18px; margin: 8px 0 0; }

/* ---------- 登录 ---------- */
.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px 26px;
  box-shadow: var(--shadow);
  text-align: center;
}
.brand-mark {
  width: 46px;
  height: 46px;
  line-height: 46px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  color: #fff;
  font-family: var(--serif);
  font-size: 24px;
}
.login-card h1 { font-family: var(--serif); font-size: 24px; margin: 0 0 4px; letter-spacing: .06em; }
.login-card p { margin: 0 0 20px; }

/* ---------- 顶部 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  background: rgba(245, 239, 252, .88);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.title { display: flex; align-items: baseline; gap: 8px; }
.title-main { font-family: var(--serif); font-size: 20px; letter-spacing: .08em; }
.term-pill {
  font-size: 11.5px;
  color: var(--ink-2);
  background: #EBE1FA;
  border-radius: 999px;
  padding: 2px 9px;
}

.content {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 16px 96px;
}

/* ---------- 按钮 ---------- */
.btn {
  font-family: inherit;
  font-size: 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  padding: 9px 15px;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { font-size: 13px; padding: 7px 12px; border-radius: 10px; }
.btn.block { width: 100%; margin-top: 12px; padding: 12px; }
.btn.danger-btn { background: #C2334D; border-color: #C2334D; color: #fff; }
.icon-btn {
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 8px;
}

/* ---------- 筛选 ---------- */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font-size: 13px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .78);
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #FBF7FF; }
.chip .cnt { opacity: .55; margin-left: 4px; font-size: 11.5px; }

.search-row { display: flex; gap: 8px; }
input[type="text"], input[type="password"], input[type="search"], input[type="date"], select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #C6B0E8; box-shadow: 0 0 0 3px rgba(122, 69, 192, .14); }
.search-row input { flex: 1; }
.search-row select { width: 150px; flex: none; }

.list-meta { font-size: 12.5px; color: var(--muted); margin: 4px 2px 10px; }

/* ---------- 错题卡片 ---------- */
.mistake-list { display: flex; flex-direction: column; gap: 10px; }
.m-card {
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  gap: 11px;
}
.m-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 3px;
  background: var(--c, var(--accent));
}
.m-card[data-subject="数学"] { --c: #7A45C0; }
.m-card[data-subject="语文"] { --c: #C2417E; }
.m-card[data-subject="英语"] { --c: #4C63B8; }
.m-card.selected { border-color: #B98BE6; background: #FBF7FF; }
.m-check {
  flex: none;
  margin-top: 3px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1.5px solid #DCCBF3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
  background: #fff;
}
.m-card.selected .m-check { background: var(--accent); border-color: var(--accent); }
.m-main { flex: 1; min-width: 0; }
.m-top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 5px; }
.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #F3EDFC;
  color: var(--ink-2);
}
.tag.kp { background: var(--accent-soft); color: #6B34B5; }
.tag.variant { background: #E9E2F6; color: #4B3A6E; }
.tag.status-new { background: #FDE8F1; color: #C2417E; }
.tag.status-reviewing { background: #FDF2DF; color: #9A6A16; }
.tag.status-mastered { background: #E7F2EA; color: #3C6E5B; }
.m-stem {
  font-size: 14.5px;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.m-sub { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }

.empty { text-align: center; padding: 56px 24px; }
.empty-title { font-family: var(--serif); font-size: 18px; margin: 0 0 6px; }

/* ---------- 统计 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.stat {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
}
.stat-num { font-family: var(--serif); font-size: 24px; line-height: 1.2; }
.stat-label { font-size: 11.5px; color: var(--muted); }

.card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card.danger { border-color: #F0C9DA; }
.card input, .card textarea, .card select { margin-bottom: 9px; }
.section-title { font-family: var(--serif); font-size: 15px; margin: 0 0 10px; letter-spacing: .04em; }

.kp-block { margin-bottom: 18px; }
.kp-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.kp-subject { font-family: var(--serif); font-size: 16px; }
.kp-row {
  display: grid;
  grid-template-columns: 1fr 66px;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px dashed #EBE1FA;
  font-size: 13.5px;
}
.kp-row:last-child { border-bottom: none; }
.kp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kp-bar { height: 5px; border-radius: 3px; background: #EBE1FA; overflow: hidden; margin-top: 4px; }
.kp-bar i { display: block; height: 100%; background: var(--accent); }
.kp-count { font-size: 12px; color: var(--muted); text-align: right; }

/* ---------- 组卷 ---------- */
.paper-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.paper-candidates { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow: auto; padding-right: 2px; }
.paper-settings { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.check { font-size: 13px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; }
.check input { width: auto; margin: 0; }

.paper-preview { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 26px; }
.paper-head { text-align: center; margin-bottom: 18px; }
.paper-head h1 { font-family: var(--serif); font-size: 20px; margin: 0 0 8px; }
.paper-meta { font-size: 12px; color: var(--muted); }
.paper-q { margin-bottom: 18px; page-break-inside: avoid; }
.paper-q-title { font-size: 14.5px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.paper-q-img { max-width: 100%; max-height: 240px; margin-top: 6px; border-radius: 6px; border: 1px solid #eee; }
.paper-space { height: 56px; border-bottom: 1px dashed #E3D8F5; margin-top: 10px; }
.paper-answer-title { page-break-before: always; margin-top: 28px; }
.paper-a { font-size: 13.5px; margin-bottom: 10px; line-height: 1.7; white-space: pre-wrap; }
.paper-a b { color: var(--accent); }

/* ---------- 弹层 ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet-mask { position: absolute; inset: 0; background: rgba(44, 33, 64, .42); backdrop-filter: blur(2px); }
.sheet-body {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 92dvh;
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  animation: sheetUp .22s ease;
}
@keyframes sheetUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-family: var(--serif); font-size: 16px; margin: 0; }
.sheet-content { padding: 14px 16px 30px; overflow-y: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
.sheet-content .form-actions { position: sticky; bottom: -1px; background: var(--paper); padding-top: 10px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.field .row { display: flex; gap: 8px; }
.field .row > * { flex: 1; }
textarea { resize: vertical; }
.form-actions { display: flex; gap: 8px; margin-top: 6px; }
.form-actions .btn { flex: 1; }

.detail-stem {
  font-size: 15.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px;
}
.detail-imgs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.detail-imgs img { width: 100%; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; }
.kv { display: grid; grid-template-columns: 76px 1fr; gap: 6px 10px; font-size: 13.5px; margin-top: 12px; }
.kv dt { color: var(--muted); font-size: 12.5px; }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.thumb-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.thumb { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%;
  border: none; background: rgba(0, 0, 0, .55); color: #fff; font-size: 11px; line-height: 1; cursor: pointer;
}
.upload-line { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.upload-line label { font-size: 13px; color: var(--accent); cursor: pointer; white-space: nowrap; }
.upload-line .btn { flex: none; white-space: nowrap; }
.upload-line input { flex: 1; margin-bottom: 0; }

.kp-hint { font-size: 12px; color: var(--muted); margin-top: 5px; min-height: 16px; }
.kp-hint.auto { color: #6B34B5; }

.drop-zone {
  margin-top: 8px;
  padding: 12px;
  border: 1.5px dashed #DCCBF3;
  border-radius: 12px;
  background: rgba(255, 255, 255, .6);
  transition: border-color .15s, background .15s;
}
.drop-zone.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-tip { font-size: 12px; color: var(--muted); line-height: 1.5; }
.drop-zone .upload-line { margin-top: 8px; flex-wrap: wrap; }
.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--accent) !important;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.upload-btn:active { background: #E6D8FB; }
.rec-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.rec-row .btn[disabled] { opacity: .55; }
.rec-tip { font-size: 12px; color: var(--muted); line-height: 1.5; flex: 1; min-width: 140px; }

/* ---------- 底栏 ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: rgba(245, 239, 252, .96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 0 9px;
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font-family: inherit;
}
.tab-ico { font-size: 15px; line-height: 1; }
.tab.active { color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translate(-50%, 12px);
  background: rgba(44, 33, 64, .94);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 90;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .content { padding-bottom: 40px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .tabbar {
    position: sticky;
    bottom: 0;
    max-width: 1080px;
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
  }
  .tab { font-size: 13px; padding: 11px 0; }
  .tab-ico { display: none; }
}

/* ---------- 打印 ---------- */
@media print {
  @page { size: A4; margin: 16mm 14mm; }
  html, body { background: #fff !important; }
  .topbar, .tabbar, .no-print, .sheet, .toast { display: none !important; }
  .content { padding: 0 !important; max-width: none; }
  .paper-preview { border: none; padding: 0; border-radius: 0; }
  .paper-q-img { max-height: 70mm; }
  .paper-space { height: 22mm; }
  .paper-a { page-break-inside: avoid; }
}
