/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, input, select, textarea { font-family: inherit; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
  background: #F1F5F9;
  color: #1E293B;
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== Navigation ===== */
#navbar {
  background: #fff;
  border-bottom: 1px solid #E2E8F0;
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}
#navbar.hidden { display: none; }

.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: #2563EB;
  flex: 1;
}

.nav-links button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.95rem;
  color: #475569;
  transition: background 0.15s, color 0.15s;
}
.nav-links button:hover { background: #EFF6FF; color: #2563EB; }

/* ===== Layout ===== */
main {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* ===== Views ===== */
.view { display: block; }
.view.hidden { display: none; }

/* ===== Cards ===== */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.section-title {
  font-size: 1.02rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 18px;
}

/* ===== Home View ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  text-align: center;
}
.stat-item { padding: 8px 0; }
.stat-num {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: #2563EB;
  line-height: 1.2;
}
.stat-label { font-size: 0.82rem; color: #64748B; margin-top: 2px; }

.mode-card { }
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.mode-btn {
  padding: 14px 12px;
  border: 2px solid #E2E8F0;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.93rem;
  color: #334155;
  text-align: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.mode-btn:hover { border-color: #2563EB; color: #2563EB; background: #EFF6FF; }
.mode-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.mode-btn:disabled:hover {
  border-color: #E2E8F0;
  color: #334155;
  background: #fff;
}

/* Wrong-practice button: subtle red tint to distinguish from regular modes */
.mode-btn-wrong {
  border-color: #FECACA;
  color: #DC2626;
}
.mode-btn-wrong:not(:disabled):hover {
  border-color: #DC2626;
  background: #FFF5F5;
  color: #DC2626;
}

.count-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid #F1F5F9;
}
.count-label { font-size: 0.9rem; color: #64748B; }
.count-row select, .count-row input {
  padding: 6px 10px;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  font-size: 0.9rem;
  color: #334155;
  outline: none;
}
.count-row input { width: 100px; }

.empty-tip { text-align: center; color: #94A3B8; padding: 20px 0; font-size: 0.95rem; }
.empty-tip a { color: #2563EB; text-decoration: none; }
.empty-tip a:hover { text-decoration: underline; }

/* ===== Library View ===== */
.library-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #F1F5F9;
  font-size: 0.9rem;
  color: #475569;
}
.filter-bar select {
  padding: 5px 10px;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  font-size: 0.88rem;
  color: #334155;
}

.question-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid #F8FAFC;
  font-size: 0.88rem;
}
.question-item:last-child { border-bottom: none; }
.q-index { color: #CBD5E1; min-width: 32px; font-size: 0.8rem; }
.q-text  { flex: 1; color: #475569; }
.q-answer { color: #94A3B8; font-size: 0.8rem; white-space: nowrap; }

/* ===== Type Badges ===== */
.q-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.76rem;
  font-weight: 500;
  white-space: nowrap;
}
.type-single { background: #DBEAFE; color: #1D4ED8; }
.type-multi  { background: #D1FAE5; color: #065F46; }
.type-judge  { background: #FEF3C7; color: #92400E; }

.import-result {
  font-size: 0.88rem;
  border-radius: 6px;
  min-height: 4px;
  white-space: pre-wrap;
  transition: padding 0.2s;
}
.import-result.success { background: #D1FAE5; color: #065F46; padding: 10px 12px; }
.import-result.error   { background: #FEE2E2; color: #991B1B; padding: 10px 12px; }

/* ===== Buttons ===== */
.btn-primary {
  background: #2563EB;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary:hover { background: #1D4ED8; }
.btn-primary:disabled { background: #93C5FD; cursor: not-allowed; }

.btn-secondary {
  background: #fff;
  color: #475569;
  border: 1px solid #CBD5E1;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  transition: border-color 0.15s, color 0.15s;
}
.btn-secondary:hover { border-color: #2563EB; color: #2563EB; }

.btn-danger {
  background: #fff;
  color: #DC2626;
  border: 1px solid #FECACA;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  transition: background 0.15s;
}
.btn-danger:hover { background: #FEE2E2; }

/* ===== Quiz View ===== */
.quiz-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: #64748B;
}

.quiz-card { }

.type-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.83rem;
  font-weight: 500;
  margin-bottom: 14px;
}

.question-text {
  font-size: 1.05rem;
  line-height: 1.75;
  color: #1E293B;
  margin-bottom: 22px;
}

/* Single-choice option buttons */
.option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 8px;
  border: 1.5px solid #E2E8F0;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font-size: 0.95rem;
  color: #334155;
  transition: border-color 0.12s, background 0.12s;
}
.option-btn:hover:not(:disabled) { border-color: #2563EB; background: #EFF6FF; }
.option-btn:disabled { cursor: default; }

/* Multi-choice checkbox labels */
.option-checkbox {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 8px;
  border: 1.5px solid #E2E8F0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  color: #334155;
  transition: border-color 0.12s, background 0.12s;
}
.option-checkbox:hover { border-color: #2563EB; background: #EFF6FF; }
.option-checkbox input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: #2563EB;
  cursor: pointer;
  flex-shrink: 0;
}

/* Option key circle (A/B/C/D) */
.opt-key {
  min-width: 28px; height: 28px;
  border-radius: 50%;
  background: #F1F5F9;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.83rem;
  color: #475569;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}

/* Judgment buttons */
.judge-btn {
  padding: 15px 36px;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  margin-right: 12px;
  transition: background 0.15s, transform 0.1s;
}
.judge-btn:hover:not(:disabled) { transform: translateY(-1px); }
.judge-btn:disabled { cursor: default; }
.judge-true  { background: #D1FAE5; color: #065F46; border-color: #6EE7B7; }
.judge-false { background: #FEE2E2; color: #991B1B; border-color: #FCA5A5; }

/* Answer state highlights */
.opt-correct {
  border-color: #16A34A !important;
  background: #DCFCE7 !important;
}
.opt-correct .opt-key { background: #16A34A; color: #fff; }

.opt-wrong {
  border-color: #DC2626 !important;
  background: #FEE2E2 !important;
}
.opt-wrong .opt-key { background: #DC2626; color: #fff; }

/* Feedback area */
.feedback-area { margin-top: 18px; }
.feedback-area.hidden { display: none; }
.feedback-correct { color: #16A34A; font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.feedback-wrong   { color: #DC2626; font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; }
.correct-answer-tip { color: #64748B; font-size: 0.9rem; }
.correct-answer-tip strong { color: #1E293B; font-size: 1rem; }

/* Quiz actions (next button) */
.quiz-actions { margin-top: 18px; text-align: right; }
.confirm-btn  { margin-top: 12px; width: 100%; padding: 13px; font-size: 1rem; }

/* End-quiz button in progress bar */
.btn-end-quiz {
  background: none;
  color: #DC2626;
  border: 1px solid #FECACA;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.83rem;
  transition: background 0.15s;
  margin-left: auto;  /* push to far right, score stays left of it */
}
.btn-end-quiz:hover { background: #FEE2E2; }

/* ===== Result View ===== */
.result-summary {
  display: flex;
  justify-content: space-around;
  text-align: center;
  padding: 28px 24px;
}
.score-big {
  font-size: 2.8rem;
  font-weight: 700;
  color: #2563EB;
  line-height: 1;
}
.score-sep { font-size: 1.8rem; color: #CBD5E1; }
.score-label { font-size: 0.82rem; color: #94A3B8; margin-top: 6px; }
.accuracy-pct { font-size: 2.8rem; font-weight: 700; line-height: 1; }
.accuracy-pct.pass { color: #16A34A; }
.accuracy-pct.fail { color: #DC2626; }

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
.result-table th {
  background: #F8FAFC;
  padding: 10px 8px;
  text-align: left;
  color: #64748B;
  font-weight: 500;
  border-bottom: 2px solid #E2E8F0;
}
.result-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #F1F5F9;
  vertical-align: middle;
  color: #475569;
}
.result-table .row-wrong td { background: #FFF8F8; }
.q-text-cell { max-width: 240px; }

.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 8px 0 16px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: #1E293B;
  color: #fff;
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 999;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  white-space: nowrap;
}
.toast.hidden { display: none; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .mode-grid  { grid-template-columns: 1fr; }
  .library-actions { flex-direction: column; }
  .result-summary { flex-direction: column; gap: 20px; }
  .judge-btn { padding: 14px 24px; }
}
