/* ============================================================
 * 宁韵英语 · 南京初中首字母/完形专项训练
 * ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-900: #113c33;
  --green-700: #17715f;
  --green-600: #1d8a71;
  --green-100: #e3f4ee;
  --green-50:  #f2faf7;
  --orange:    #e8862e;
  --orange-100:#fdeedd;
  --red:       #d9534f;
  --red-100:   #fdeceb;
  --gold:      #f5b301;
  --ink:       #22333f;
  --muted:     #7b8a94;
  --bg:        #f4f7f6;
  --card:      #ffffff;
  --line:      #e2ebe7;
  --shadow:    0 4px 18px rgba(23, 60, 51, .08);
  --radius:    16px;
}

html { scroll-behavior: smooth; }

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ================= 顶栏 ================= */

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(120deg, #113c33 0%, #1d8a71 100%);
  color: #fff;
  box-shadow: 0 2px 14px rgba(17, 60, 51, .28);
}
.topbar-inner {
  max-width: 980px; margin: 0 auto;
  padding: 13px 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 46px; height: 46px; border-radius: 13px;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .3);
  display: flex; align-items: center; justify-content: center;
  font-size: 23px; font-weight: 700;
}
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: .5px; }
.brand p  { font-size: 12px; opacity: .85; margin-top: 1px; }

.tabs { display: flex; gap: 8px; }
.tab {
  border: none; cursor: pointer;
  background: rgba(255, 255, 255, .13);
  color: #fff; font-size: 14.5px;
  padding: 9px 18px; border-radius: 999px;
  transition: background .2s;
  display: inline-flex; align-items: center;
}
.tab:hover { background: rgba(255, 255, 255, .25); }
.tab.active { background: #fff; color: var(--green-900); font-weight: 700; }
.tab-badge {
  margin-left: 6px;
  background: #ff5f52; color: #fff;
  font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 1px 7px;
  min-width: 18px; text-align: center;
}

/* ================= 主体 ================= */

main { max-width: 980px; margin: 0 auto; padding: 22px 20px 70px; }

/* ---------- 年级选择 ---------- */

.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.grade-panel {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.panel-label { font-size: 14.5px; font-weight: 700; color: var(--green-900); white-space: nowrap; }

.seg { display: inline-flex; background: var(--green-50); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg-btn {
  border: none; cursor: pointer; background: transparent;
  padding: 8px 18px; border-radius: 9px;
  font-size: 14.5px; color: var(--muted);
  transition: all .2s;
}
.seg-btn.active { background: var(--green-600); color: #fff; font-weight: 700; box-shadow: 0 2px 8px rgba(29, 138, 113, .35); }
.seg-btn:not(.active):hover { color: var(--green-700); }

/* ---------- 生成按钮 ---------- */

.gen-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.gen-btn {
  border: none; cursor: pointer; text-align: left;
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex; align-items: center; gap: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  transition: transform .18s, box-shadow .18s;
  position: relative; overflow: hidden;
}
.gen-btn::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
}
.gen-first::before { background: var(--green-600); }
.gen-cloze::before { background: var(--orange); }
.gen-btn:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(23, 60, 51, .14); }
.gen-btn:active { transform: translateY(-1px); }

.gen-ico {
  width: 48px; height: 48px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
.gen-first .gen-ico { background: var(--green-100); }
.gen-cloze .gen-ico { background: var(--orange-100); }

.gen-btn b { display: block; font-size: 16.5px; color: var(--ink); }
.gen-btn small { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.gen-btn .go { margin-left: auto; font-size: 20px; color: var(--muted); transition: transform .2s; }
.gen-btn:hover .go { transform: translateX(4px); color: var(--green-600); }

/* ---------- 空提示 ---------- */

.empty-tip {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 46px 20px;
  text-align: center; color: var(--muted);
  background: rgba(255, 255, 255, .6);
}
.empty-emoji { font-size: 40px; margin-bottom: 10px; }
.empty-tip.in-book { background: var(--card); }

/* ---------- 练习卡片 ---------- */

.passage-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 26px 22px;
  box-shadow: var(--shadow);
  animation: fadeUp .35s ease both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.pc-head { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 14px; }
.pc-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pc-title h3 { font-size: 19px; color: var(--green-900); }

.ptag {
  font-size: 12px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  white-space: nowrap;
}
.ptag.t-first { background: var(--green-100); color: var(--green-700); }
.ptag.t-cloze { background: var(--orange-100); color: #b45309; }

.pc-meta { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--muted); }
.pc-meta .stars { color: var(--gold); letter-spacing: 2px; font-weight: 400; }
.pc-style { margin-top: 6px; font-size: 12.5px; color: var(--green-700); background: var(--green-50); display: inline-block; padding: 3px 10px; border-radius: 8px; }

.pc-tip { font-size: 13.5px; color: var(--muted); margin-bottom: 14px; }

/* 短文正文 */
.pc-text p {
  font-size: 16.5px; line-height: 2.15;
  margin: 10px 0;
  text-align: justify;
  color: #2c3e4a;
}

/* 首字母空 */
.blank { white-space: nowrap; }
.bnum { font-size: 11px; color: #9fb1ab; margin-right: 1px; }
.blank-first .bletter { font-weight: 700; color: var(--green-700); font-size: 16.5px; margin-right: 1px; }

.fill-input {
  width: 92px; border: none;
  border-bottom: 2px solid #a8c0b9;
  background: #f4faf8;
  border-radius: 7px 7px 0 0;
  padding: 2px 8px; margin: 0 2px;
  font-size: 15.5px; font-weight: 600;
  text-align: center; color: var(--ink);
  font-family: inherit;
  outline: none;
  transition: border-color .2s, background .2s;
}
.fill-input:focus { border-bottom-color: var(--green-600); background: var(--green-100); }

/* 完形空 */
.fill-select {
  margin: 0 2px;
  padding: 4px 8px;
  border-radius: 9px;
  border: 1.5px solid #c9d8d3;
  background: #fbfefd;
  font-size: 14.5px; color: var(--ink);
  font-family: inherit;
  outline: none; cursor: pointer;
  transition: border-color .2s;
  max-width: 150px;
}
.fill-select:focus { border-color: var(--green-600); }

/* 批改后的状态 */
.fill-input.ok, .fill-select.ok { border-color: var(--green-600); background: var(--green-100); }
.fill-input.bad, .fill-select.bad { border-color: var(--red); background: var(--red-100); }

.mark { font-weight: 700; font-size: 15px; margin-left: 3px; }
.mark-ok { color: var(--green-600); }
.mark-bad { color: var(--red); }

.fix {
  background: var(--orange-100); color: #b45309;
  border-radius: 7px; padding: 1px 9px;
  font-size: 13px; font-weight: 600;
  margin-left: 5px; white-space: nowrap;
}

/* 操作按钮 */
.pc-actions { display: flex; gap: 12px; margin-top: 20px; flex-wrap: wrap; }

.btn {
  border: none; cursor: pointer;
  border-radius: 11px;
  padding: 10px 22px;
  font-size: 15px; font-family: inherit;
  transition: all .2s;
}
.btn.primary {
  background: linear-gradient(120deg, var(--green-700), var(--green-600));
  color: #fff; font-weight: 700;
  box-shadow: 0 4px 12px rgba(29, 138, 113, .35);
}
.btn.primary:hover { transform: translateY(-2px); box-shadow: 0 7px 18px rgba(29, 138, 113, .4); }
.btn.primary:disabled { background: #b7d8cd; box-shadow: none; cursor: default; transform: none; }
.btn.ghost {
  background: #fff; color: var(--green-700);
  border: 1.5px solid var(--green-600);
}
.btn.ghost:hover { background: var(--green-50); }
.btn.danger-ghost {
  background: #fff; color: var(--red);
  border: 1.5px solid #f0b6b4;
  padding: 7px 14px; font-size: 13px;
}
.btn.danger-ghost:hover { background: var(--red-100); }

/* 结果面板 */
.pc-result {
  margin-top: 18px;
  background: var(--green-50);
  border: 1px solid #cfe9df;
  border-radius: 14px;
  padding: 18px 20px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  animation: fadeUp .3s ease both;
}
.res-score { font-size: 44px; font-weight: 800; color: var(--green-700); line-height: 1; }
.res-score span { font-size: 20px; color: var(--muted); font-weight: 500; }
.res-info { flex: 1; min-width: 220px; }
.res-rate { font-size: 14px; color: var(--muted); }
.res-comment { font-size: 15.5px; font-weight: 700; color: var(--green-900); margin-top: 3px; }
.res-note { font-size: 13px; color: #b45309; margin-top: 4px; }
.res-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* ================= 错题本 ================= */

.book-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--card); border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.stat-card b { font-size: 22px; color: var(--green-700); line-height: 1.25; }
.stat-card span { font-size: 12px; color: var(--muted); }
.stat-weak b { font-size: 14.5px; line-height: 1.45; }

.book-tools {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.fchip {
  border: 1.5px solid var(--line); background: #fff;
  border-radius: 999px; padding: 5px 14px;
  font-size: 13px; color: var(--muted); cursor: pointer;
  transition: all .18s; font-family: inherit;
}
.fchip:hover { border-color: var(--green-600); color: var(--green-700); }
.fchip.active { background: var(--green-600); border-color: var(--green-600); color: #fff; font-weight: 600; }
.book-tools .danger-ghost { margin-left: auto; }

/* 错题卡片 */
.book-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 14px;
  border-left: 5px solid var(--green-600);
  animation: fadeUp .3s ease both;
}
.book-card.b-first { border-left-color: var(--green-600); }
.book-card.b-cloze { border-left-color: var(--orange); }

.bk-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.bk-tags { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gtag { font-size: 12px; background: #eef2f4; color: #5a6b76; padding: 3px 10px; border-radius: 999px; }
.bk-title { font-size: 13.5px; color: var(--muted); }
.bk-head-r { display: flex; align-items: center; gap: 10px; }
.count-chip { font-size: 12px; color: var(--red); background: var(--red-100); padding: 2px 9px; border-radius: 999px; font-weight: 700; }
.bk-date { font-size: 12px; color: var(--muted); }
.btn-mini {
  border: 1.5px solid var(--line); background: #fff;
  color: var(--green-700); font-size: 12.5px;
  border-radius: 999px; padding: 4px 12px; cursor: pointer;
  transition: all .18s; font-family: inherit; white-space: nowrap;
}
.btn-mini:hover { background: var(--green-600); border-color: var(--green-600); color: #fff; }

.bk-sentence {
  font-size: 15.5px; line-height: 1.9; color: #2c3e4a;
  background: #f8fbfa; border-radius: 10px;
  padding: 10px 14px;
}
.sblank { color: var(--green-700); font-weight: 700; }
.sblank i { font-style: normal; letter-spacing: 1px; color: #9fb1ab; }
.bk-options { font-size: 13.5px; color: var(--muted); margin-top: 6px; padding: 0 14px; }

/* 答案行 */
.ans-line {
  display: flex; gap: 14px; flex-wrap: wrap;
  margin: 12px 0 4px;
}
.ans-item { display: flex; align-items: center; gap: 8px; }
.ans-label { font-size: 13px; color: var(--muted); }
.ans-val {
  font-weight: 700; font-size: 15px;
  color: var(--red); background: var(--red-100);
  padding: 3px 14px; border-radius: 9px;
}
.ans-box {
  font-weight: 700; font-size: 15px;
  color: var(--green-700);
  background: var(--green-100);
  border: 1px dashed var(--green-600);
  padding: 2px 16px; border-radius: 9px;
  cursor: pointer; position: relative;
  user-select: none;
  transition: all .2s;
  min-width: 88px; text-align: center;
}
.ans-box:hover { box-shadow: 0 2px 10px rgba(29, 138, 113, .2); }
/* 遮盖态：点击移开显示 */
.ans-box.covered {
  color: transparent;
  background: #3d4a57;
  border: 1px solid #3d4a57;
}
.ans-box.covered::after {
  content: "👁 点击显示";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12.5px; font-weight: 500;
  letter-spacing: 1px;
}

/* 错误分析 */
.analysis {
  margin-top: 12px;
  display: grid; gap: 8px;
}
.ana-block {
  display: flex; gap: 10px; align-items: flex-start;
  border-radius: 10px; padding: 9px 13px;
  font-size: 14px; line-height: 1.75;
}
.ana-block .ana-t { font-weight: 700; white-space: nowrap; font-size: 13.5px; padding-top: 1px; }
.ana-block p { color: #3c4f5c; }
.ana-block.why  { background: #fdf3ef; }
.ana-block.why .ana-t  { color: #c05621; }
.ana-block.weak { background: #eef4ff; }
.ana-block.weak .ana-t { color: #2f6bd8; }
.ana-block.ext  { background: var(--green-50); }
.ana-block.ext .ana-t  { color: var(--green-700); }

.chip {
  display: inline-block;
  background: #dde8fb; color: #2f6bd8;
  font-size: 12px; font-weight: 700;
  border-radius: 999px; padding: 1px 10px;
  margin-right: 8px;
}

/* ================= 其他 ================= */

.footer {
  text-align: center;
  font-size: 12.5px; color: var(--muted);
  padding: 18px 20px 26px;
}

.toast {
  position: fixed; left: 50%; bottom: 30px;
  transform: translateX(-50%) translateY(16px);
  background: #2b3a36; color: #fff;
  font-size: 14px;
  padding: 11px 24px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  opacity: 0; pointer-events: none;
  transition: all .3s; z-index: 999;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================= AI 出题面板 ================= */

.ai-panel {
  background: linear-gradient(135deg, #f6f3ff 0%, #eef4ff 100%);
  border: 1px solid #ded9f7;
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.ai-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}

.ai-tag {
  background: linear-gradient(120deg, #6d5ef0, #8a7bff);
  color: #fff; font-size: 13px; font-weight: 700;
  padding: 4px 14px; border-radius: 999px;
  letter-spacing: .5px;
}

.ai-note { font-size: 12.5px; color: #6b6f8e; }

.ai-gen { border: 1.5px solid #c9c2f5; }
.ai-gen .gen-icon { background: #efeaff; }
.ai-gen:hover { box-shadow: 0 8px 22px rgba(109, 94, 240, .18); }

.gen-btn.loading { opacity: .65; cursor: wait; }
.gen-btn.loading .gen-icon { animation: pulse 1s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

.ai-status {
  margin-top: 12px; padding: 11px 16px;
  border-radius: 12px; font-size: 14px;
  display: flex; align-items: center; gap: 10px;
  line-height: 1.7;
}

.ai-status.loading {
  background: #fff; border: 1px dashed #b9b1ef; color: #55507a;
}

.ai-status.success {
  background: var(--green-50); border: 1px solid #bfe5d5; color: var(--green-700);
}

.ai-status.error {
  background: #fff6f5; border: 1px solid #f2c9c6; color: #a33c38;
}

.ai-spin {
  flex: none; width: 18px; height: 18px;
  border: 3px solid #ded9f7; border-top-color: #6d5ef0;
  border-radius: 50%; animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.ptag.t-ai {
  background: linear-gradient(120deg, #6d5ef0, #8a7bff);
  color: #fff;
}

.empty-sub { font-size: 12.5px; color: var(--muted); }

/* ================= 响应式 ================= */

@media (max-width: 640px) {
  .gen-row { grid-template-columns: 1fr; }
  .book-stats { grid-template-columns: repeat(2, 1fr); }
  .stat-weak { grid-column: span 2; }
  .passage-card { padding: 18px 16px; }
  .pc-text p { font-size: 15.5px; line-height: 2.05; }
  /* 16px 防止 iOS 聚焦自动放大 */
  .fill-input { width: 76px; font-size: 16px; }
  .fill-select { max-width: 132px; font-size: 16px; }
  .seg { width: 100%; }
  .seg-btn { flex: 1; padding: 11px 6px; font-size: 14px; }
  .gen-btn { padding: 15px 16px; }
  .gen-text b { font-size: 15.5px; }
  .pc-result { flex-direction: column; align-items: flex-start; }
  .book-tools .danger-ghost { margin-left: 0; }
  .book-tools { flex-direction: column; align-items: stretch; }
  .filter-group { justify-content: flex-start; }
  .tab { padding: 9px 14px; font-size: 13.5px; }
  .pc-actions .btn { padding: 12px 18px; font-size: 15px; }
}
