:root {
  --bg: #f6f5f1;
  --paper: #ffffff;
  --ink: #1f1d1b;
  --muted: #6c6862;
  --accent: #b3261e;
  --accent-soft: #f6dada;
  --good: #2e7d32;
  --good-soft: #d8efd9;
  --bad: #c62828;
  --bad-soft: #fadcdc;
  --line: #e5e2dc;
  --hint: #fdf6dd;
  --radius: 10px;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}

.topbar {
  background: linear-gradient(180deg, var(--accent), #8d1c17);
  color: #fff;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  gap: 32px;
  flex-wrap: wrap;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar p { margin: 2px 0 0; font-size: 12px; color: rgba(255,255,255,0.85); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

.tabs { display: flex; gap: 8px; margin-left: auto; }
.tab {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 14px;
}
.tab:hover { background: rgba(255,255,255,0.22); }
.tab.active { background: #fff; color: var(--accent); border-color: #fff; font-weight: 600; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.view { display: none; }
.view.active { display: block; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}
.controls label { font-size: 14px; color: var(--muted); }
select, input[type="search"] {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
}
input[type="search"] { flex: 1; min-width: 200px; }

.pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 13px;
}

.card {
  background: var(--paper);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 22px 24px 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.tag {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.stem {
  font-size: 16px;
  margin-bottom: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.option {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
  transition: background 0.15s, border 0.15s;
}
.option:hover { background: #faf9f6; }
.option .lbl {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 13px;
}
.option.correct { background: var(--good-soft); border-color: var(--good); }
.option.correct .lbl { background: var(--good); color: #fff; }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); }
.option.wrong .lbl { background: var(--bad); color: #fff; }
.option.disabled { cursor: default; }

.answer {
  background: var(--hint);
  border-left: 4px solid #d8b500;
  padding: 12px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  word-break: break-word;
}
.answer.good { background: var(--good-soft); border-left-color: var(--good); }
.answer.bad  { background: var(--bad-soft);  border-left-color: var(--bad); }
.answer.hidden { display: none; }
.answer .label { font-weight: 700; color: #8b6d00; display: block; margin-bottom: 4px; }
.answer.good .label { color: var(--good); }
.answer.bad .label  { color: var(--bad); }

/* blank rendering inside choice stems */
.stem .blank {
  display: inline-block;
  min-width: 70px;
  border-bottom: 1.5px solid var(--ink);
  color: transparent;
  vertical-align: 1px;
  margin: 0 2px;
}
.stem.inline-stem { line-height: 2.2; }
.blank-input {
  border: 0;
  border-bottom: 1.5px solid var(--accent);
  background: #fff7f7;
  padding: 2px 6px;
  font-size: 16px;
  font-family: inherit;
  margin: 0 4px;
  min-width: 80px;
  outline: none;
  border-radius: 0;
}
.blank-input:focus { background: #fff; }

/* short answer textarea */
.short-area {
  width: 100%;
  min-height: 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  background: #fff;
}
.short-area:focus { outline: none; border-color: var(--accent); }

/* diff display */
.diff-block { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.diff-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.diff-row:last-child { border-bottom: 0; }
.diff-label { font-weight: 600; margin-bottom: 6px; }
.diff-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.diff-col .diff-cap { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.diff-user, .diff-ans {
  padding: 8px 10px;
  background: #fbfaf6;
  border-radius: 6px;
  min-height: 24px;
  line-height: 1.8;
  word-break: break-word;
}
.d-eq  { color: var(--ink); }
.d-del { color: var(--bad);  text-decoration: line-through; background: var(--bad-soft); padding: 0 1px; }
.d-ins { color: var(--good); background: var(--good-soft); padding: 0 1px; font-weight: 600; }
.d-miss { color: var(--muted); opacity: 0.4; }

/* history panel */
.history { background: var(--paper); border: 1px dashed var(--line); border-radius: 8px; padding: 12px; margin-top: 14px; }
.history.hidden { display: none; }
.history h3 { font-size: 14px; margin: 0 0 10px; color: var(--muted); }
.history-item { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.history-item:last-child { border-bottom: 0; }
.history-item .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.history-item .txt { white-space: pre-wrap; word-break: break-word; font-size: 14px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn-good { background: var(--good); }
.btn-bad { background: var(--bad); }
.hidden { display: none !important; }

.hint { margin-top: 8px; }

/* Browse */
.browse-list { display: flex; flex-direction: column; gap: 10px; }
.browse-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}
.browse-item .head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.browse-item .stem { font-size: 15px; }
.browse-item details > summary { cursor: pointer; color: var(--accent); margin-top: 8px; font-size: 13px; }
.browse-item .options-mini { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.browse-item .options-mini .row.correct { color: var(--good); font-weight: 600; }
.browse-item .answer-block { background: var(--hint); padding: 10px 12px; border-radius: 6px; margin-top: 8px; white-space: pre-wrap; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-box {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.stat-box .v { font-size: 24px; font-weight: 700; color: var(--accent); }
.stat-box .l { color: var(--muted); font-size: 13px; }
.mastery { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }
.mastery .bucket {
  flex: 1 1 120px;
  padding: 12px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  text-align: center;
}
.mastery .bucket .v { font-size: 22px; font-weight: 700; }
.recent { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; margin-bottom: 18px; }
.recent .item {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  display: flex; justify-content: space-between;
}
.recent .item.good { color: var(--good); }
.recent .item.bad { color: var(--bad); }

h2 { font-size: 16px; margin-bottom: 10px; }

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .tabs { margin-left: 0; width: 100%; overflow-x: auto; }
  main { padding: 16px; }
}
