/* ============ 全局 ============ */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2733;
  --muted: #69748a;
  --line: #e3e8f0;
  --brand: #3b6ef0;
  --brand-dark: #2c54c2;
  --good: #1ea672;
  --bad: #e0584f;
  --shadow: 0 2px 10px rgba(31, 39, 51, .07);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 880px; margin: 0 auto; padding: 0 20px 60px; }

/* ============ 顶栏 ============ */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar .inner {
  max-width: 880px; margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; gap: 14px;
}
.logo { font-weight: 800; font-size: 20px; color: var(--ink); }
.logo span { color: var(--brand); }
.topbar .spacer { flex: 1; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 9px; cursor: pointer;
  font-size: 14px; font-weight: 600; transition: .15s;
}
.btn:hover { border-color: #c8d2e4; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #f3cdca; }
.btn.danger:hover { background: #fdeceb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* ============ 卡片集列表 ============ */
.page-head { margin: 28px 0 18px; display: flex; align-items: center; gap: 12px; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head .spacer { flex: 1; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }

.set-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.set-card h3 { margin: 0 0 6px; font-size: 17px; }
.set-card .desc { color: var(--muted); font-size: 13px; margin: 0 0 10px; min-height: 18px; }
.set-card .count { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.set-card .row { display: flex; gap: 8px; margin-top: auto; flex-wrap: wrap; }

.empty {
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 40px; text-align: center; color: var(--muted);
}

/* ============ 编辑页 ============ */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.input, .textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 9px; font-size: 14px; font-family: inherit; background: #fff;
}
.input:focus, .textarea:focus { outline: none; border-color: var(--brand); }
.textarea { resize: vertical; min-height: 64px; }

.card-row {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px;
  align-items: start; margin-bottom: 10px;
}
.card-row .idx {
  width: 26px; text-align: center; color: var(--muted); font-size: 13px; padding-top: 10px;
}
.card-rows-head { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px;
  color: var(--muted); font-size: 13px; margin: 18px 0 8px; font-weight: 600; }

/* ============ 学习页 ============ */
.study-head { margin: 24px 0 10px; }
.study-head h1 { margin: 0; font-size: 22px; }
.study-head .meta { color: var(--muted); font-size: 14px; }

.modes { display: flex; gap: 8px; margin: 16px 0 22px; }
.mode-tab {
  padding: 8px 16px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; font-size: 14px;
}
.mode-tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.progress { color: var(--muted); font-size: 14px; margin-bottom: 12px; text-align: center; }

/* 翻卡 */
.flip {
  perspective: 1200px; height: 320px; margin-bottom: 18px; cursor: pointer;
}
.flip-inner {
  position: relative; width: 100%; height: 100%; transition: transform .5s;
  transform-style: preserve-3d;
}
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center;
  padding: 30px; text-align: center; font-size: 24px; font-weight: 600;
}
.flip-face .tag { position: absolute; top: 14px; left: 18px; font-size: 12px; color: var(--muted); font-weight: 600; }
.flip-face.back { transform: rotateY(180deg); color: var(--brand-dark); }

.controls { display: flex; gap: 10px; justify-content: center; }

/* 测验 */
.quiz-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 28px; margin-bottom: 18px;
}
.quiz-q { font-size: 20px; font-weight: 600; margin-bottom: 20px; text-align: center; }
.options { display: grid; gap: 10px; }
.option {
  text-align: left; padding: 12px 16px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; cursor: pointer; font-size: 15px; transition: .12s;
}
.option:hover { border-color: #c8d2e4; }
.option.correct { background: #e7f7f0; border-color: var(--good); color: #11724f; }
.option.wrong { background: #fdeceb; border-color: var(--bad); color: #a4322b; }
.option:disabled { cursor: default; }

.result {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 40px; text-align: center;
}
.result .score { font-size: 44px; font-weight: 800; color: var(--brand); }

/* ============ 弹窗 ============ */
.modal-bg {
  position: fixed; inset: 0; background: rgba(20, 26, 38, .45);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-bg.show { display: flex; }
.modal {
  background: var(--card); border-radius: 14px; padding: 24px; width: 100%; max-width: 460px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal h3 { margin: 0 0 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 6px; }
