:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --ink: #20231f;
  --muted: #6b7168;
  --line: #d9ddd2;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --bad: #b91c1c;
  --good: #15803d;
  --soft: #edf4f2;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: white;
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.ghost {
  background: transparent;
  color: var(--ink);
}

.topbar {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 32px;
  border-bottom: 1px solid var(--line);
  background: #fbfcf8;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.25;
}

h2 {
  font-size: 18px;
}

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

.student-badge {
  margin-top: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.gate {
  min-height: calc(100vh - 94px);
  display: grid;
  place-items: center;
  padding: 28px;
}

.gate-card {
  width: min(460px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 45px rgba(35, 40, 34, 0.08);
}

.gate-card h2 {
  font-size: 24px;
}

.gate-card .primary {
  width: 100%;
  margin-top: 16px;
}

.form-error {
  margin-top: 9px;
  color: var(--bad);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
  padding: 18px;
  max-width: 1440px;
  margin: 0 auto;
}

.panel,
.paper {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.controls {
  align-self: start;
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow: auto;
}

.controls section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.controls section:last-child {
  border-bottom: 0;
}

label {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}

.controls .primary {
  width: 100%;
  margin-top: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stat {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcf8;
}

.stat b {
  display: block;
  margin-top: 3px;
  font-size: 18px;
}

.stat.wide {
  grid-column: 1 / -1;
}

.outline {
  max-height: 260px;
  overflow: auto;
  margin-top: 12px;
  padding-right: 4px;
}

.outline p {
  padding: 7px 0;
  border-bottom: 1px solid #eef0ea;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.outline .chapter {
  color: var(--ink);
  font-weight: 700;
}

.paper {
  min-height: calc(100vh - 128px);
  overflow: hidden;
}

.paper-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
  background: #fbfcf8;
}

.paper-head-status {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.answer-progress {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.score {
  min-width: 160px;
  text-align: right;
}

.score strong {
  display: block;
  color: var(--accent);
  font-size: 30px;
  line-height: 1;
}

.question-list {
  padding: 0 22px 22px;
}

.question-list.empty {
  padding: 48px 22px;
  color: var(--muted);
}

.type-title {
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--ink);
  font-size: 17px;
}

.question {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.question h3 {
  font-size: 16px;
  line-height: 1.55;
}

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

.options {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.option {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.option input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
}

.option.correct {
  border-color: rgba(21, 128, 61, 0.45);
  background: #effaf2;
}

.option.wrong {
  border-color: rgba(185, 28, 28, 0.45);
  background: #fff1f1;
}

.analysis {
  display: none;
  margin-top: 12px;
  padding: 12px;
  border-left: 4px solid var(--accent);
  background: var(--soft);
  line-height: 1.65;
  white-space: pre-wrap;
}

.analysis.show {
  display: block;
}

.analysis b {
  color: var(--accent);
}

.result-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  color: #fff;
}

.result-tag.good {
  background: var(--good);
}

.result-tag.bad {
  background: var(--bad);
}

.submitbar {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 22px 22px;
  position: sticky;
  bottom: 0;
  z-index: 2;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.memory-layout {
  align-items: start;
}

.memory-surface {
  min-height: calc(100vh - 128px);
}

.memory-card-shell {
  padding: 22px;
}

.memory-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf8;
  padding: 18px;
}

.memory-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.memory-index {
  color: var(--muted);
  font-size: 12px;
}

.memory-prompt {
  margin-top: 6px;
  font-size: 22px;
  line-height: 1.5;
}

.memory-label {
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.memory-answer-box {
  margin-top: 8px;
  padding: 14px;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: var(--soft);
}

.memory-rating-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.memory-rate {
  min-height: 46px;
  font-weight: 700;
}

.bad-rate {
  background: var(--bad);
  border-color: var(--bad);
}

.warn-rate {
  background: #b45309;
  border-color: #b45309;
}

.good-rate {
  background: var(--good);
  border-color: var(--good);
}

.memory-answer {
  margin: 0;
  white-space: pre-wrap;
  font-family: inherit;
  line-height: 1.7;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.memory-tips {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .topbar,
  .paper-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .controls {
    position: static;
    max-height: none;
  }
}
