/* suan-pwa · 口算宝 v0.4.0（在线练习 + 打印双模式） */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #fdf6ec;
  color: #2b2118;
}

.shell { max-width: 860px; margin: 0 auto; padding: 32px 16px 64px; }

.view[hidden] { display: none; }

/* ---------- 头部 ---------- */
.hero { text-align: center; }
.hero h1 { margin: 0; font-size: 34px; }
.hero p { margin: 8px 0 0; color: rgba(43,33,24,.7); }
.ver { display: inline-block; margin-top: 8px; font-size: 12px; opacity: .6; }

/* ---------- 首页模式卡片 ---------- */
.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 36px;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  border: 2px solid #e5d5b8;
  border-radius: 20px;
  background: #fff;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.mode-card:hover { border-color: #f59e0b; transform: translateY(-2px); }
.mode-card.primary-mode { border-color: #f59e0b; background: #fff8ec; }
.mode-emoji { font-size: 44px; }
.mode-name { font-size: 20px; font-weight: 700; }
.mode-desc { font-size: 13px; color: rgba(43,33,24,.6); }

/* ---------- 选年级 ---------- */
.view-title { text-align: center; font-size: 22px; margin: 8px 0 24px; }
.grade-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.grade-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 24px 12px;
  border: 2px solid #e5d5b8;
  border-radius: 18px;
  background: #fff;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.grade-card:hover { border-color: #f59e0b; transform: translateY(-2px); }
.grade-card:active { transform: scale(.97); }
.grade-emoji { font-size: 34px; }
.grade-name { font-size: 18px; font-weight: 700; }
.grade-desc { font-size: 13px; color: rgba(43,33,24,.6); }

.back-btn { display: block; margin: 24px auto 0; max-width: 240px; }

/* ---------- 在线练习 ---------- */
.p-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.btn-quit {
  width: 36px; height: 36px;
  border: 1.5px solid #e5d5b8;
  border-radius: 10px;
  background: #fff;
  font-size: 16px;
  cursor: pointer;
  color: #6b5a44;
  flex-shrink: 0;
}
.p-progress-wrap { flex: 1; }
.p-progress { font-size: 14px; color: rgba(43,33,24,.7); margin-bottom: 6px; }
.p-bar {
  height: 8px;
  background: #efe3cc;
  border-radius: 999px;
  overflow: hidden;
}
.p-bar-fill {
  height: 100%;
  background: #f59e0b;
  border-radius: 999px;
  transition: width .3s;
}
.p-timer {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: rgba(43,33,24,.7);
  flex-shrink: 0;
}

.p-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px 24px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(43,33,24,.08);
}
.p-question {
  font-size: 40px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-bottom: 28px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.p-answer {
  width: 100%;
  max-width: 220px;
  padding: 14px;
  font-size: 28px;
  text-align: center;
  font-weight: 600;
  border: 2px solid #e5d5b8;
  border-radius: 14px;
  background: #faf3e6;
  color: #2b2118;
  font-family: inherit;
}
.p-answer:focus { outline: none; border-color: #f59e0b; }
.p-answer.shake { animation: shake .35s; border-color: #ef4444; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}
.p-feedback {
  min-height: 28px;
  margin-top: 16px;
  font-size: 18px;
  font-weight: 600;
}
.p-feedback.good { color: #16a34a; }
.p-feedback.bad { color: #ef4444; }
.p-next { margin-top: 12px; max-width: 220px; width: 100%; }

/* ---------- 成绩 ---------- */
.result-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px 24px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(43,33,24,.08);
}
.result-emoji { font-size: 56px; }
.result-title { margin: 12px 0 24px; font-size: 22px; }
.result-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 24px;
}
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-num { font-size: 26px; font-weight: 700; color: #b45309; }
.stat-label { font-size: 13px; color: rgba(43,33,24,.6); }

.wrong-list {
  text-align: left;
  background: #fef2f2;
  border-radius: 14px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
.wrong-list h3 { margin: 0 0 12px; font-size: 15px; color: #b91c1c; }
.wrong-item {
  font-size: 15px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  padding: 6px 0;
  color: #7f1d1d;
  border-bottom: 1px dashed #fecaca;
}
.wrong-item:last-child { border-bottom: none; }

.result-actions { display: flex; flex-direction: column; gap: 10px; }
.result-actions .btn { width: 100%; max-width: 280px; margin: 0 auto; }

/* ---------- 配置面板（打印模式） ---------- */
.config-panel {
  margin-top: 8px;
  padding: 24px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(43,33,24,.08);
}
.config-panel h2 { margin: 0 0 16px; font-size: 18px; }

.cfg-group { margin-bottom: 16px; }
.cfg-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: rgba(43,33,24,.75);
}
.cfg-row { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 16px; }
.cfg-item { min-width: 130px; }
.cfg-item.grow { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 14px;
  font-size: 14px;
  border: 1.5px solid #e5d5b8;
  border-radius: 999px;
  background: #faf3e6;
  color: #5b4a36;
  cursor: pointer;
  transition: all .15s;
  user-select: none;
  font-family: inherit;
}
.chip:hover { border-color: #f59e0b; }
.chip.active { background: #f59e0b; border-color: #f59e0b; color: #fff; font-weight: 600; }

select, input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 14px;
  border: 1.5px solid #e5d5b8;
  border-radius: 10px;
  background: #faf3e6;
  color: #2b2118;
  font-family: inherit;
}
input[type="text"] { max-width: 260px; }

.toggles { gap: 20px; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; user-select: none; }
.toggle input { accent-color: #f59e0b; width: 16px; height: 16px; }

.actions { display: flex; gap: 12px; margin-top: 20px; }
.btn {
  flex: 1;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  border: 1.5px solid #e5d5b8;
  border-radius: 12px;
  background: #faf3e6;
  color: #5b4a36;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.btn:hover { border-color: #f59e0b; color: #b45309; }
.btn.primary { background: #f59e0b; border-color: #f59e0b; color: #fff; }
.btn.primary:hover { background: #d97706; }

.print-hint { font-size: 13px; color: #b45309; margin: 12px 0 0; }

/* ---------- 题卡 ---------- */
.sheet-area { margin-top: 24px; }
.sheet {
  background: #fff;
  border-radius: 8px;
  padding: 28px 32px;
  box-shadow: 0 2px 16px rgba(43,33,24,.1);
  margin-bottom: 24px;
  max-width: 794px;
  margin-left: auto;
  margin-right: auto;
}
.sheet-title { text-align: center; font-size: 22px; margin: 0 0 8px; letter-spacing: 2px; }
.sheet-meta {
  text-align: center;
  font-size: 14px;
  color: #6b5a44;
  margin: 0 0 20px;
  letter-spacing: 1px;
}
.problems {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), 1fr);
  gap: 14px 20px;
}
.q {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: 16px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  white-space: nowrap;
}
.q-num { font-size: 12px; color: #a08c6f; min-width: 24px; }
.q-text { font-weight: 500; }
.q-time { flex: 1; max-width: 48px; margin-left: 8px; border-bottom: 1px dashed #c9b691; min-height: 18px; }

.answer-grid { gap: 10px 20px; }
.answer-grid .q { color: #4a7c59; font-size: 14px; }

/* ---------- 页脚 ---------- */
.foot { margin-top: 24px; text-align: center; font-size: 14px; }
.foot a { color: #b45309; text-decoration: none; }

/* ---------- 手机适配 ---------- */
@media (max-width: 560px) {
  .mode-cards { grid-template-columns: 1fr; }
  .p-question { font-size: 34px; }
  .cfg-item { min-width: calc(50% - 8px); }
}

/* ---------- 打印 ---------- */
@page { size: A4; margin: 14mm; }

@media print {
  body { background: #fff; }
  .no-print, .hero, .mode-cards, .p-head, .p-card,
  #viewHome, #viewPracticeSetup, #viewPractice, #viewResult,
  .btn, .back-btn, .print-hint { display: none !important; }
  #viewPrint { display: block !important; }
  .shell { max-width: none; padding: 0; }
  .sheet-area { margin-top: 0; }
  .sheet {
    box-shadow: none;
    border-radius: 0;
    margin: 0 auto;
    max-width: none;
    padding: 0;
  }
  .sheet.answers { page-break-before: always; }
  .q-time { border-bottom-color: #999; }
}
