:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #667085;
  --line: #d7dde8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --good: #10835a;
  --bad: #c43d3d;
  --soft-blue: #eaf1ff;
  --soft-red: #fff0f0;
  --soft-green: #ecfdf5;
  --shadow: 0 14px 36px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 18px 14px calc(24px + env(safe-area-inset-bottom));
}

.view {
  display: block;
}

.hidden {
  display: none !important;
}

.topbar,
.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.topbar h1,
.result-panel h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 13px;
}

.bank-count {
  min-width: 74px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
  color: var(--primary);
  font-weight: 700;
}

.panel,
.question-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
}

.segment {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segment.active {
  background: var(--panel);
  color: var(--primary);
  box-shadow: 0 2px 10px rgba(31, 41, 55, 0.08);
}

.count-grid {
  display: grid;
  gap: 10px;
}

.chapter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.chapter-choice {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 8px;
  align-items: start;
  min-height: 66px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.chapter-choice input {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--primary);
}

.chapter-choice strong {
  display: block;
  font-size: 14px;
  line-height: 1.3;
}

.chapter-choice small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.chapter-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.count-row {
  display: grid;
  grid-template-columns: 74px 1fr 76px;
  align-items: center;
  gap: 10px;
}

.count-row input {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
}

.count-row small {
  color: var(--muted);
  text-align: right;
}

.quick-actions,
.result-actions,
.manage-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.manage-actions {
  grid-template-columns: 1fr 1fr;
}

.sync-panel {
  border-color: rgba(37, 99, 235, 0.32);
}

.sync-row {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 8px;
}

.sync-row input {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sync-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.sync-panel.sync-on {
  border-color: rgba(16, 131, 90, 0.5);
  background: #f7fffb;
}

.ghost,
.secondary,
.primary,
.icon-text {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.primary {
  width: 100%;
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.primary:active {
  background: var(--primary-dark);
}

.secondary {
  background: #f8fafc;
}

.switch-row {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.switch-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
}

.muted {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.quiz-head {
  position: sticky;
  top: 0;
  z-index: 4;
  padding: 10px 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
}

.icon-text {
  min-width: 58px;
  padding: 0 10px;
}

.progress-wrap {
  flex: 1;
  min-width: 0;
}

.progress-text {
  margin-bottom: 6px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.progress-track div {
  width: 0%;
  height: 100%;
  background: var(--primary);
  transition: width 160ms ease;
}

.question-card {
  padding: 18px;
  margin-bottom: 88px;
}

.meta-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.tag-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.type-tag,
.source-tag,
.difficulty-tag {
  color: var(--muted);
  font-size: 13px;
}

.type-tag {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--soft-blue);
  color: var(--primary);
  font-weight: 700;
}

.difficulty-tag {
  padding: 3px 8px;
  border-radius: 999px;
  background: #fff7ed;
  color: #b45309;
  font-weight: 800;
  letter-spacing: 0;
}

#questionStem {
  margin: 0 0 16px;
  font-size: 19px;
  line-height: 1.65;
}

.options {
  display: grid;
  gap: 10px;
}

.option {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: start;
  gap: 10px;
  min-height: 54px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  text-align: left;
}

.option .letter {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #edf2f7;
  color: var(--muted);
  font-weight: 800;
}

.option.selected {
  border-color: var(--primary);
  background: var(--soft-blue);
}

.option.selected .letter {
  background: var(--primary);
  color: #ffffff;
}

.option.correct {
  border-color: rgba(16, 131, 90, 0.5);
  background: var(--soft-green);
}

.option.wrong {
  border-color: rgba(196, 61, 61, 0.5);
  background: var(--soft-red);
}

.option[disabled] {
  cursor: default;
}

.feedback {
  margin-top: 16px;
  padding: 14px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.feedback.good {
  border-color: rgba(16, 131, 90, 0.45);
  background: var(--soft-green);
}

.feedback.bad {
  border-color: rgba(196, 61, 61, 0.45);
  background: var(--soft-red);
}

.feedback h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.feedback p {
  margin: 6px 0 0;
}

.enhanced-explain {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.explain-block {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: #374151;
}

.explain-block strong {
  color: var(--ink);
}

.enhanced-explain.compact {
  gap: 6px;
  margin-top: 10px;
}

.enhanced-explain.compact .explain-block {
  padding: 9px 10px;
}

.bottom-actions {
  position: fixed;
  right: max(14px, calc((100vw - 820px) / 2 + 14px));
  bottom: 0;
  left: max(14px, calc((100vw - 820px) / 2 + 14px));
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 8px;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(10px);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-grid div {
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

.stat-grid strong {
  display: block;
  font-size: 22px;
}

.stat-grid span {
  color: var(--muted);
  font-size: 13px;
}

.review-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.review-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.review-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 1.55;
}

.review-card .answer-line {
  margin: 6px 0;
  font-weight: 700;
}

.review-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
}

.review-actions {
  margin-top: 12px;
}

.review-actions button {
  width: 100%;
}

.review-card .explain {
  margin-top: 10px;
  color: #374151;
}

@media (max-width: 520px) {
  .app-shell {
    padding: 14px 10px calc(20px + env(safe-area-inset-bottom));
  }

  .topbar h1 {
    font-size: 25px;
  }

  .count-row {
    grid-template-columns: 68px 1fr 60px;
  }

  .chapter-grid {
    grid-template-columns: 1fr;
  }

  .quick-actions {
    grid-template-columns: repeat(3, 1fr);
  }

  .question-card {
    padding: 15px;
  }

  #questionStem {
    font-size: 18px;
  }

  .bottom-actions {
    left: 10px;
    right: 10px;
    grid-template-columns: 0.9fr 1.15fr 0.9fr;
  }
}
