:root {
  --ink: #1f2328;
  --muted: #667085;
  --line: #e6e1d8;
  --paper: #f7f4ee;
  --card: #fffdf9;
  --red: #9f2d2d;
  --red-soft: #fdecec;
  --green: #1f7a45;
  --green-soft: #e8f6ee;
  --amber: #9a6700;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; }
button, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 16px;
  background: #7f1d1d;
  color: #fff;
}
.back, .text-button {
  color: #fff;
  background: transparent;
  border: 0;
  padding: 8px 0;
  font-size: 14px;
}
.top-actions {
  justify-self: end;
  display: flex;
  gap: 12px;
  align-items: center;
}
.text-button { font-weight: 650; }
.brand { font-weight: 700; letter-spacing: 0.04em; }

.app {
  width: min(800px, 100%);
  margin: 0 auto;
  padding: 16px 16px 40px;
}
.loading, .empty { color: var(--muted); line-height: 1.6; }

.intro h1 { margin: 8px 0 6px; font-size: 26px; }
.intro p { margin: 0 0 16px; color: var(--muted); line-height: 1.6; }

.chapter-list, .wrong-list { display: grid; gap: 12px; }
.chapter, .panel, .option, .result, .summary {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.chapter, .panel { padding: 14px 14px 12px; }
.chapter h2, .panel h2 { margin: 0; font-size: 17px; }
.meta { margin: 8px 0 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.meta b { color: var(--ink); font-weight: 650; }
.actions, .row { display: flex; flex-wrap: wrap; gap: 8px; }
.primary, .secondary {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid transparent;
}
.primary { color: #fff; background: var(--red); }
.secondary { color: var(--ink); background: #fff; border-color: #ddd4c8; }
.wide { width: 100%; }

.progress-line {
  height: 6px;
  margin: 8px 0 14px;
  border-radius: 99px;
  background: #efe8dc;
  overflow: hidden;
}
.progress-line span {
  display: block;
  height: 100%;
  background: var(--red);
}
.kicker { margin: 0; color: var(--muted); font-size: 13px; }
.tags { display: flex; gap: 6px; margin: 8px 0; }
.tag {
  padding: 2px 8px;
  border-radius: 99px;
  background: #f3eadb;
  color: var(--amber);
  font-size: 12px;
}
.case {
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 12px;
  background: #f6f1e7;
  color: #3f3a34;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
}
.prompt { margin: 0 0 12px; font-size: 17px; line-height: 1.7; white-space: pre-wrap; }
.options { display: grid; gap: 8px; }
.option {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 12px;
  text-align: left;
  line-height: 1.55;
  color: var(--ink);
}
.option .key {
  flex: 0 0 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f3eee6;
  font-weight: 700;
}
.option.selected { border-color: #c9a27a; background: #fff8ef; }
.option.selected .key { background: #9f2d2d; color: #fff; }
.option.correct { border-color: #8dcea8; background: var(--green-soft); }
.option.correct .key { background: var(--green); color: #fff; }
.option.wrong { border-color: #f0b4b4; background: var(--red-soft); }
.option.wrong .key { background: var(--red); color: #fff; }
.option:disabled { opacity: 1; }

.result { margin-top: 12px; padding: 12px 14px; line-height: 1.7; }
.result.ok { border-color: #b7e0c6; background: var(--green-soft); }
.result.bad { border-color: #f3c3c3; background: var(--red-soft); }
.result p { margin: 6px 0 0; white-space: pre-wrap; }
.foot { margin-top: 14px; }

.summary { padding: 18px; }
.summary h1 { margin: 0 0 8px; font-size: 24px; }
.summary p { margin: 0 0 16px; line-height: 1.6; }

.filter { margin-bottom: 12px; }
.filter select, .check {
  min-height: 42px;
}
.filter select {
  width: 100%;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.wrong-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.wrong-item input { width: 18px; height: 18px; margin-top: 3px; }
.wrong-item small { color: var(--muted); }
.wrong-item p { margin: 4px 0 0; line-height: 1.5; }

.bank-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 16px;
}
.bank-tab {
  min-height: 42px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 650;
}
.bank-tab.active {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 650;
}
.form-error {
  margin: 10px 0 0;
  color: var(--red);
  font-size: 14px;
  line-height: 1.5;
}

.sync-panel { margin-bottom: 12px; }
.sync-token {
  margin: 10px 0;
  padding: 12px;
  border-radius: 10px;
  background: #f6f1e7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  letter-spacing: 0.06em;
  word-break: break-all;
}
.sync-input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
}

@media (min-width: 800px) {
  .app { padding-top: 28px; }
  .chapter { display: grid; grid-template-columns: 1fr auto; align-items: center; }
  .chapter .meta { margin-bottom: 0; }
  .actions { justify-content: flex-end; }
}
