/* ===== 学习刷题 · 全局样式（iPhone 优先，移动端触屏） ===== */
:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --primary-soft: #eef2ff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

input, textarea, select {
  font: inherit;
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  width: 100%;
}

input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* ===== 顶栏 ===== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: 1px; }
.top-actions { display: flex; gap: 8px; }
.top-actions button {
  background: rgba(255, 255, 255, .18);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
}
.top-actions button:active { background: rgba(255, 255, 255, .3); }

/* ===== 主区 ===== */
main {
  position: fixed;
  top: 0; bottom: 0; left: 0; right: 0;
  padding: calc(56px + var(--safe-top)) 12px calc(64px + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.view { display: none; }
.view.active { display: block; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== 底部导航 ===== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  font-size: 11px;
  color: var(--muted);
}
.tabbar button .ico { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--primary); font-weight: 600; }

/* ===== 通用组件 ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card h3 { font-size: 15px; margin-bottom: 8px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  background: var(--primary);
  color: #fff;
  width: 100%;
}
.btn:active { background: var(--primary-dark); }
.btn.ghost { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: var(--red); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 9px; width: auto; }
.btn:disabled { opacity: .5; pointer-events: none; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge.single { background: #dbeafe; color: #1d4ed8; }
.badge.multi { background: #ede9fe; color: #6d28d9; }
.badge.fill { background: #fef3c7; color: #b45309; }
.badge.card { background: #dcfce7; color: #15803d; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
}
.empty .big { font-size: 42px; margin-bottom: 10px; }

/* ===== 题库视图 ===== */
.chapter-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  cursor: pointer;
}
.chapter-head .arrow { transition: transform .15s; color: var(--muted); }
.chapter-head.open .arrow { transform: rotate(90deg); }
.chapter-head .count { color: var(--muted); font-size: 12px; }

.qitem {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin: 0 0 8px 14px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.qitem .text { flex: 1; min-width: 0; }
.qitem .stem {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 14px;
}
.qitem .del { color: var(--muted); padding: 4px 6px; font-size: 16px; }
.qitem .del:active { color: var(--red); }

/* ===== 刷题视图 ===== */
.quiz-setup label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  min-height: 44px;
}
.quiz-setup input[type="checkbox"], .quiz-setup input[type="radio"] { width: 18px; height: 18px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: #fff;
  font-size: 13px;
  color: var(--muted);
}
.chip.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.progress { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.progress .bar { flex: 1; height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .2s; }

.qstem { font-size: 16px; font-weight: 600; line-height: 1.7; margin-bottom: 14px; white-space: pre-wrap; }

.opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: #fff;
  margin-bottom: 8px;
  min-height: 48px;
  font-size: 15px;
}
.opt .key {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.opt.selected { border-color: var(--primary); background: var(--primary-soft); }
.opt.correct { border-color: var(--green); background: var(--green-soft); }
.opt.wrong { border-color: var(--red); background: var(--red-soft); }
.opt.disabled { pointer-events: none; opacity: .85; }
.opt .key.correct { background: var(--green); color: #fff; }
.opt .key.wrong { background: var(--red); color: #fff; }

.feedback {
  border-radius: 12px;
  padding: 14px;
  margin-top: 4px;
  font-size: 14px;
}
.feedback.ok { background: var(--green-soft); color: #14532d; }
.feedback.no { background: var(--red-soft); color: #7f1d1d; }
.feedback .exp { margin-top: 8px; color: inherit; opacity: .85; }

.fill-input { font-size: 16px; padding: 12px; margin-bottom: 10px; }
.fill-blanks { margin: 6px 0; }
.fill-blank { display: inline-block; }
.fill-part { display: inline-block; padding: 2px 8px; border-radius: 6px; margin: 2px; font-weight: 600; }
.fill-part.ok { background: var(--green-soft); color: var(--green); }
.fill-part.no { background: var(--red-soft); color: var(--red); }
.fill-part.miss { background: var(--amber-soft); color: var(--amber); }

.quiz-end { text-align: center; padding: 24px 0; }
.quiz-end .score { font-size: 48px; font-weight: 800; color: var(--primary); }
.quiz-end .sub { color: var(--muted); margin: 6px 0 20px; }

/* ===== 卡片视图 ===== */
.card-face {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 18px;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 18px;
  line-height: 1.8;
  cursor: pointer;
  margin-bottom: 14px;
}
.card-face .hint { color: var(--muted); font-size: 13px; margin-top: 14px; }
.rate-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate-btn { min-height: 52px; border-radius: 12px; font-weight: 600; font-size: 13px; }
.rate-btn.r0 { background: #fee2e2; color: #b91c1c; }
.rate-btn.r1 { background: #fef3c7; color: #b45309; }
.rate-btn.r2 { background: #dcfce7; color: #15803d; }
.rate-btn.r3 { background: #dbeafe; color: #1d4ed8; }
.rate-btn:active { filter: brightness(.92); }

/* ===== 错题视图 ===== */
.wrong-item {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.wrong-item .meta { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }

/* ===== 统计视图 ===== */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-cell {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 8px;
  text-align: center;
}
.stat-cell .num { font-size: 22px; font-weight: 800; color: var(--primary); }
.stat-cell .lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat-cell.span3 { grid-column: span 3; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.bar-row .name { width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none; }
.bar-row .track { flex: 1; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--primary); border-radius: 999px; }
.bar-row .val { width: 42px; text-align: right; color: var(--muted); flex: none; }
.week { display: flex; gap: 6px; align-items: flex-end; height: 70px; padding: 8px 0; }
.week .day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.week .col { width: 100%; background: var(--primary-soft); border-radius: 4px 4px 0 0; min-height: 2px; }
.week .lbl { font-size: 10px; color: var(--muted); }

/* ===== 弹窗 ===== */
.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(17, 24, 39, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-mask.hidden { display: none; }
.modal {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(16px + var(--safe-bottom));
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal h2 { font-size: 16px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.modal h2 .close { color: var(--muted); font-size: 20px; padding: 2px 8px; }
.mtab { display: flex; gap: 8px; margin-bottom: 10px; }
.mtab button {
  flex: 1;
  padding: 9px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.mtab button.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.import-area { margin-bottom: 10px; }
.import-area textarea { min-height: 160px; resize: vertical; }
.preview-box {
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  margin: 10px 0;
  font-size: 13px;
  max-height: 220px;
  overflow-y: auto;
}
.preview-box .err { color: var(--red); }
.preview-box .ok-line { color: var(--green); }

/* ===== Toast ===== */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%) translateY(10px);
  background: rgba(17, 24, 39, .92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: all .25s;
  max-width: 86vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden { display: none !important; }
