:root {
  color-scheme: light;
  --blue: #1769e0;
  --blue-2: #1d9bf0;
  --ink: #172033;
  --muted: #6b778c;
  --line: #dce6f5;
  --bg: #f4f7fb;
  --ok: #1f9d55;
  --bad: #d64545;
  --warn: #c46a00;
}

body.dark {
  --ink: #edf2f7;
  --muted: #a9b4c2;
  --line: #313b49;
  --bg: #101418;
}

* {
  box-sizing: border-box;
}

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

body.dark .card,
body.dark .subject,
body.dark .question-card,
body.dark .feedback,
body.dark .wrong-card {
  background: #171d24;
}

body.dark .chapter,
body.dark .option {
  background: #202733;
}

body.dark .option.disabled {
  background: #171d24;
}

body.font-small .question,
body.font-small .analysis,
body.font-small .option {
  font-size: 16px;
}

body.font-large .question {
  font-size: 25px;
}

body.font-large .analysis,
body.font-large .option {
  font-size: 19px;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.hero {
  padding: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  color: #fff;
}

.hero h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 44px);
  letter-spacing: 0;
}

.hero p {
  margin: 10px 0 0;
  color: rgba(255, 255, 255, 0.84);
}

.hero-progress {
  margin-top: 20px;
}

.progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.24);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #ffffff;
  transition: width 180ms ease;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 20px 0 28px;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 28px;
}

.quick-card {
  min-height: 76px;
  padding: 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
}

.quick-icon {
  display: block;
  margin-bottom: 8px;
  font-size: 20px;
}

.quick-title {
  display: block;
  font-weight: 800;
}

.quick-sub {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.subject-tabs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  margin-bottom: 16px;
}

.upload-panel {
  padding: 20px;
  margin-bottom: 18px;
}

.upload-grid {
  display: grid;
  gap: 14px;
}

.field-label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.field-input,
.field-textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

.field-textarea {
  min-height: 220px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}

.format-box {
  padding: 14px;
  border-radius: 8px;
  background: #f7faff;
  color: #42526e;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.55;
}

body.dark .format-box {
  background: #202733;
  color: var(--muted);
}

.upload-result {
  padding: 14px;
  border-radius: 8px;
  background: #e8f7ef;
  color: #11713b;
  font-weight: 800;
}

.subject-tab {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-radius: 8px;
  background: #e8f1ff;
  color: var(--blue);
  font-weight: 800;
}

.subject-tab.active {
  background: var(--blue);
  color: #fff;
}

.primary,
.secondary,
.danger {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 8px;
  font-weight: 700;
}

.primary {
  background: var(--blue);
  color: #fff;
}

.secondary {
  background: #e8f1ff;
  color: var(--blue);
}

.danger {
  background: #fff0f0;
  color: #b4232a;
}

.section-head,
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 20px 0 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 22px;
}

.meta,
.pill {
  color: var(--muted);
  font-size: 14px;
}

.pill {
  padding: 7px 12px;
  border-radius: 8px;
  background: #e8f1ff;
  color: var(--blue);
  font-weight: 700;
}

.timer {
  background: #fff3e0;
  color: var(--warn);
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(31, 42, 61, 0.06);
}

.subject {
  margin-bottom: 16px;
  padding: 20px;
}

.subject h3 {
  margin: 0 0 14px;
  font-size: 19px;
}

.chapter-list,
.option-list,
.wrong-list {
  display: grid;
  gap: 12px;
}

.chapter {
  min-height: 72px;
  padding: 12px 16px;
  border-radius: 8px;
  background: #f7faff;
  color: var(--ink);
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chapter-main {
  min-width: 0;
  flex: 1;
}

.chapter-title {
  display: block;
  font-weight: 700;
}

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

.chapter-status {
  margin-left: auto;
  padding: 3px 7px;
  border-radius: 6px;
  background: #edf4ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.stars {
  color: #f59e0b;
  font-size: 12px;
}

.chapter-progress {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.chapter-progress .progress-track {
  height: 6px;
  background: #dbe8fa;
}

.chapter-progress .progress-fill {
  background: var(--blue);
}

.chapter-progress-text {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.question-card {
  padding: 22px;
}

.question-meta {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.question {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.65;
}

.practice-toolbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.tool-button {
  min-height: 42px;
  border-radius: 8px;
  background: #edf4ff;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
}

.tool-button.active {
  background: var(--blue);
  color: #fff;
}

.settings-panel,
.note-panel {
  margin: 0 0 14px;
  padding: 16px;
}

.setting-row {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.setting-row:last-child {
  border-bottom: 0;
}

.segmented {
  display: flex;
  gap: 6px;
}

.segment {
  padding: 7px 10px;
  border-radius: 8px;
  background: #edf4ff;
  color: var(--blue);
  font-weight: 800;
}

.segment.active {
  background: var(--blue);
  color: #fff;
}

.switch {
  width: 48px;
  height: 26px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
}

.switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 160ms ease;
}

.switch.on {
  background: var(--blue);
}

.switch.on::after {
  transform: translateX(22px);
}

.note-input {
  width: 100%;
  min-height: 130px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
  font: inherit;
}

.practice-progress {
  margin: 0 0 16px;
}

.practice-progress .progress-track {
  background: #dbe8fa;
}

.practice-progress .progress-fill {
  background: var(--blue);
}

.option {
  width: 100%;
  min-height: 54px;
  padding: 14px 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  line-height: 1.5;
}

.option.selected {
  border-color: var(--blue);
  background: #e8f1ff;
  color: var(--blue);
  font-weight: 700;
}

.option.correct {
  border-color: var(--ok);
  background: #e8f7ef;
  color: #11713b;
  font-weight: 700;
}

.option.wrong {
  border-color: var(--bad);
  background: #fff0f0;
  color: #b4232a;
  font-weight: 700;
}

.option.disabled {
  background: #f8fafc;
  color: var(--muted);
}

.feedback,
.wrong-card {
  margin-top: 16px;
  padding: 18px;
}

.feedback-title {
  margin-bottom: 8px;
  font-size: 19px;
  font-weight: 800;
}

.answer-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.summary-box {
  padding: 10px;
  border-radius: 8px;
  background: #f7faff;
  color: var(--muted);
}

.answer-tabs {
  display: flex;
  gap: 8px;
  margin: 14px 0 10px;
  border-bottom: 1px solid var(--line);
}

.answer-tab {
  padding: 9px 6px;
  color: var(--muted);
  font-weight: 800;
  border-bottom: 2px solid transparent;
}

.answer-tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.answer-line {
  margin: 8px 0;
  color: var(--blue);
  font-weight: 700;
}

.analysis {
  white-space: pre-wrap;
  color: #42526e;
  line-height: 1.65;
}

.score-panel {
  padding: 32px 20px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  text-align: center;
}

.score {
  font-size: 76px;
  font-weight: 900;
  line-height: 1;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 640px) {
  .app-shell {
    padding: 16px;
  }

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

  .quick-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .question {
    font-size: 19px;
  }

  .practice-toolbar {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}
