* { margin: 0; padding: 0; box-sizing: border-box !important; }
html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f4f7fa;
  color: #333;
  font-size: 15px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
:root {
  --main: #2d7d9a;
  --main-light: #4a99b5;
  --main-dark: #1f5a6e;
  --green: #2e8b57;
  --red: #d9534f;
  --orange: #f0ad4e;
  --bg-card: #ffffff;
  --border: #e1e8ed;
  --text-secondary: #6c7a89;
}
/* 顶部头部 */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, var(--main) 0%, var(--main-dark) 100%);
  color: #fff;
  padding: 12px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}
.tab-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.tab-btn {
  flex: 1;
  max-width: 160px;
  padding: 8px 14px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn.active {
  background: #fff;
  color: var(--main);
  font-weight: 600;
}
.tab-btn:hover:not(.active) { background: rgba(255,255,255,0.25); }

/* 统计面板 */
.stat-panel {
  background: var(--bg-card);
  margin: 12px;
  padding: 12px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.stat-title {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 600;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat-item {
  background: #f8fafc;
  border-radius: 6px;
  padding: 8px 6px;
  text-align: center;
  border: 1px solid var(--border);
}
.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--main);
}
.stat-value.error { color: var(--orange); }
.stat-value.rate { color: var(--green); }

/* 主容器 */
.container {
  padding: 0 12px 140px;
  max-width: 820px;
  margin: 0 auto;
}
.panel { display: none; }
.panel.active { display: block; }

/* 题目卡片 */
.question-card {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 18px 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.q-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.q-num {
  background: var(--main);
  color: #fff;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
}
.q-num.error-mark {
  background: var(--orange);
}
.q-title {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
  line-height: 1.7;
  margin-bottom: 14px;
  word-break: break-word;
}
.option-list { list-style: none; }
.option-item {
  padding: 12px 12px;
  margin-bottom: 8px;
  background: #f8fafc;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  word-break: break-word;
}
.option-item:hover { background: #eef4f7; border-color: var(--main-light); }
.option-item.selected {
  background: #e3f2f8;
  border-color: var(--main);
}
.option-item.correct {
  background: #e8f6ee;
  border-color: var(--green);
}
.option-item.wrong {
  background: #fdecea;
  border-color: var(--red);
}
.option-marker {
  font-weight: 700;
  color: var(--main);
  flex-shrink: 0;
}
.option-item.correct .option-marker { color: var(--green); }
.option-item.wrong .option-marker { color: var(--red); }
.option-text { flex: 1; }

/* 答案区 */
.answer-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  display: none;
}
.answer-box.show { display: block; }
.answer-box.right {
  background: #e8f6ee;
  border: 1px solid var(--green);
}
.answer-box.wrong {
  background: #fdecea;
  border: 1px solid var(--red);
}
.ans-text {
  font-size: 14px;
  font-weight: 600;
}
.ans-text.right { color: var(--green); }
.ans-text.wrong { color: var(--red); }
.count-tip {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 700;
}
.count-tip.right { color: var(--green); }
.count-tip.wrong { color: var(--red); }

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
  white-space: nowrap;
}
.btn-primary {
  background: var(--main);
  color: #fff;
}
.btn-primary:hover { background: var(--main-dark); }
.btn-secondary {
  background: #fff;
  color: var(--main);
  border: 1px solid var(--main);
}
.btn-secondary:hover { background: #eef4f7; }
.btn-danger {
  background: #fff;
  color: var(--red);
  border: 1px solid var(--red);
}
.btn-danger:hover { background: #fdecea; }
.btn-warn {
  background: var(--orange);
  color: #fff;
}
.btn-warn:hover { background: #ec971f; }

/* 底部操作栏 */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  z-index: 90;
  padding: 10px 12px;
}
.bottom-inner {
  max-width: 820px;
  margin: 0 auto;
}
.nav-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.nav-row .btn { flex: 1; min-width: 70px; }
.config-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.config-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}
.config-input {
  width: 60px !important;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
  box-sizing: border-box !important;
  outline: none;
}
.config-input:focus { border-color: var(--main); }
.jump-input {
  width: 70px !important;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  text-align: center;
  box-sizing: border-box !important;
  outline: none;
}
.jump-input:focus { border-color: var(--main); }
.switch-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
}
.switch-label input { cursor: pointer; }

/* 错题本 */
.error-list {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.error-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.error-count {
  font-size: 14px;
  color: var(--text-secondary);
}
.error-count strong { color: var(--orange); font-size: 16px; }
.error-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 8px;
}
.error-chip {
  background: #fff5e6;
  border: 1px solid var(--orange);
  color: #b06d00;
  padding: 8px 4px;
  text-align: center;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s;
}
.error-chip:hover { background: var(--orange); color: #fff; }
.empty-tip {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 14px;
}
.empty-tip .icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* 响应式 */
@media (max-width: 600px) {
  body { font-size: 14px; }
  .header { padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .header-title { font-size: 15px; margin-bottom: 8px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-item { padding: 6px 4px; }
  .stat-value { font-size: 14px; }
  .stat-label { font-size: 10px; }
  .q-title { font-size: 15px; }
  .config-row { justify-content: space-between; }
  .config-item { flex: 0 0 auto; font-size: 12px; }
  .nav-row .btn { font-size: 13px; padding: 8px 10px; }
  .nav-row { gap: 6px; }
  .error-grid { grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); }
  .question-card { padding: 14px 12px; }
  .option-item { padding: 10px 10px; font-size: 13px; }
  .bottom-bar { padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
}

/* 超窄屏：iPhone 5/SE1 (320px)、Galaxy Fold (280px) */
@media (max-width: 360px) {
  body { font-size: 13px; }
  .header-title { font-size: 14px; }
  .header { padding-left: 8px; padding-right: 8px; }
  .tab-btn { padding: 6px 8px; font-size: 12px; }
  .q-title { font-size: 14px; line-height: 1.6; }
  .question-card { padding: 12px 10px; }
  .option-item { padding: 8px 8px; font-size: 12px; gap: 6px; }
  .option-marker { font-size: 12px; }
  .stat-panel { padding: 8px; margin: 8px; }
  .stat-item { padding: 5px 3px; }
  .stat-value { font-size: 13px; }
  .stat-label { font-size: 10px; }
  .btn { padding: 7px 8px; font-size: 12px; }
  .nav-row { gap: 4px; margin-bottom: 6px; }
  .nav-row .btn { font-size: 12px; padding: 7px 6px; min-width: 56px; }
  .jump-input { width: 56px !important; padding: 6px 4px; font-size: 12px; }
  .config-row { gap: 4px; }
  .config-item { font-size: 11px; gap: 2px; }
  .config-input { width: 48px !important; padding: 5px 4px; font-size: 12px; }
  .switch-label { font-size: 11px; }
  .container { padding-left: 8px; padding-right: 8px; padding-bottom: 200px; }
  .error-grid { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
  .error-chip { padding: 6px 2px; font-size: 12px; }
}

/* iPhone 横屏及短屏 */
@media (max-width: 900px) and (max-height: 480px) {
  .header { padding: 6px 12px; }
  .header-title { font-size: 14px; margin-bottom: 6px; }
  .stat-grid { grid-template-columns: repeat(6, 1fr); }
  .stat-value { font-size: 13px; }
  .stat-label { font-size: 10px; }
  .container { padding-bottom: 160px; }
}

/* iPad 平板及以上 */
@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(6, 1fr); }
  .stat-value { font-size: 18px; }
  .error-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
  .q-title { font-size: 17px; }
}

/* 大屏桌面 */
@media (min-width: 1200px) {
  body { font-size: 16px; }
  .q-title { font-size: 18px; }
  .option-item { font-size: 15px; }
  .stat-value { font-size: 20px; }
}

/* 工具提示 */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 9999;
  display: none;
  max-width: 80%;
  text-align: center;
}
.toast.show { display: block; animation: fadeIn 0.2s; }
@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -45%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

/* ====== 移动端紧凑栏 ====== */
.stat-compact {
  display: none;
  background: var(--bg-card);
  margin: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.stat-compact .compact-time {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.stat-compact .compact-time strong {
  color: var(--main);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.stat-compact .compact-progress {
  flex: 1;
  height: 4px;
  background: #e1e8ed;
  border-radius: 2px;
  overflow: hidden;
  margin: 0 8px;
}
.stat-compact .compact-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--main), var(--main-light));
  transition: width 0.3s;
  width: 0%;
}
.stat-compact .compact-actions {
  display: flex;
  gap: 6px;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
  position: relative;
}
.icon-btn:hover { background: var(--main); color: #fff; border-color: var(--main); }
.icon-btn .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--orange);
  color: #fff;
  font-size: 10px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  font-weight: 700;
}

/* ====== 模态弹窗 ====== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  display: none;
  align-items: flex-end;
  justify-content: center;
  animation: fadeOverlay 0.2s;
}
.modal-overlay.show { display: flex; }
@keyframes fadeOverlay {
  from { background: rgba(0,0,0,0); }
  to { background: rgba(0,0,0,0.5); }
}
.modal {
  background: var(--bg-card);
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--main);
}
.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: #f8fafc;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.modal-close:hover { background: var(--red); color: #fff; }
.modal-body {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-body .stat-grid {
  grid-template-columns: repeat(2, 1fr);
}
.modal-body .error-list {
  box-shadow: none;
  padding: 0;
}
.modal-settings .config-row {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}
.modal-settings .config-item,
.modal-settings .switch-label {
  width: 100%;
  justify-content: space-between;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 8px;
  font-size: 14px;
}
.modal-settings .config-input {
  width: 70px !important;
}

/* ====== 移动端：紧凑栏 + 弹窗模式 ====== */
@media (max-width: 767px) {
  /* 隐藏 PC 端完整统计面板、配置行、错题本 tab */
  .stat-panel { display: none; }
  .stat-compact { display: flex; }
  .config-row { display: none; }
  .tab-bar { display: none; }
  .header { padding-bottom: 10px; }
  /* 顶部错题入口移到紧凑栏的图标按钮 */
}
@media (max-width: 360px) {
  .stat-compact { margin: 8px; padding: 8px 10px; }
  .icon-btn { width: 32px; height: 32px; font-size: 14px; }
  .stat-compact .compact-time strong { font-size: 14px; }
}

/* PC 端：保持原样 */
@media (min-width: 768px) {
  .stat-compact { display: none; }
  .modal-overlay { align-items: center; }
  .modal { border-radius: 14px; max-height: 80vh; }
}
