:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #eef4f2;
  --text: #172124;
  --muted: #68777b;
  --line: #d9e1e3;
  --accent: #0b6f6a;
  --accent-strong: #07524f;
  --accent-soft: #dff2ef;
  --warning: #a86605;
  --danger: #b33a3a;
  --danger-soft: #f8e6e6;
  --success: #167048;
  --success-soft: #e4f4ea;
  --focus: #f1b84b;
  --shadow: 0 14px 36px rgba(21, 34, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select,
input,
textarea,
.file-button {
  border: 1px solid var(--line);
  border-radius: 6px;
}

button,
.file-button {
  min-height: 40px;
  padding: 0 14px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
.file-button:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button.active,
button.primary,
#submitAnswer {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.active:hover,
button.primary:hover,
#submitAnswer:hover {
  background: var(--accent-strong);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: #163033;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

#sourceStatus {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(160px, 240px) minmax(130px, 180px) minmax(220px, 1fr) auto;
  gap: 12px;
  padding: 14px 24px;
  background: #fbfcfc;
  border-bottom: 1px solid var(--line);
}

.toolbar select,
.toolbar input {
  min-height: 40px;
  width: 100%;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
}

.mode-tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, 68px);
  gap: 6px;
}

.mode-tabs button {
  min-width: 0;
  padding: 0 10px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
  padding: 18px;
  background: #e9eff0;
  border-right: 1px solid var(--line);
}

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

.stats div {
  min-height: 70px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats span {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.stats small {
  color: var(--muted);
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.list-head button {
  min-height: 34px;
  padding: 0 12px;
}

.question-list {
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.question-list li + li {
  margin-top: 8px;
}

.question-list button {
  width: 100%;
  min-height: 62px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  text-align: left;
  background: var(--panel);
}

.question-list button.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.q-index {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.q-title {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.q-state {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
}

.q-state.correct {
  background: var(--success);
}

.q-state.wrong {
  background: var(--danger);
}

.q-state.review {
  background: var(--warning);
}

.practice {
  min-width: 0;
  min-height: 0;
  padding: 24px;
  overflow: auto;
}

.question-panel,
.empty-state {
  max-width: 980px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.question-panel {
  padding: 24px;
}

.empty-state {
  padding: 42px 24px;
  text-align: center;
}

.empty-state p {
  margin-top: 8px;
  color: var(--muted);
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.question-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
}

#questionTitle {
  margin-bottom: 16px;
  font-size: 24px;
  line-height: 1.35;
}

.markdown-body {
  overflow-wrap: anywhere;
}

.markdown-body p {
  margin: 10px 0;
}

.markdown-body pre {
  margin: 14px 0;
  padding: 14px;
  overflow: auto;
  border-radius: 8px;
  background: #132225;
  color: #eef8f6;
}

.markdown-body code {
  font-family: Consolas, "Courier New", monospace;
}

.markdown-body :not(pre) > code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #eef1f2;
  color: #1a3436;
}

.markdown-body table {
  width: 100%;
  margin: 14px 0;
  border-collapse: collapse;
  font-size: 15px;
}

.markdown-body th,
.markdown-body td {
  padding: 9px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: var(--panel-soft);
}

.answer-form {
  margin-top: 24px;
}

.answer-input {
  display: grid;
  gap: 10px;
}

.choice-option {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  cursor: pointer;
}

.choice-option:hover {
  border-color: var(--accent);
}

.choice-option input {
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  accent-color: var(--accent);
}

.choice-option strong {
  margin-right: 6px;
}

.text-answer,
.long-answer {
  width: 100%;
  padding: 12px;
  background: #fbfcfc;
  color: var(--text);
  resize: vertical;
}

.text-answer {
  min-height: 48px;
}

.long-answer {
  min-height: 170px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.action-spacer {
  flex: 1 1 auto;
}

.feedback {
  margin-top: 20px;
  padding: 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfcfc;
}

.feedback.correct {
  border-color: #9ed5b8;
  background: var(--success-soft);
}

.feedback.wrong {
  border-color: #e3a4a4;
  background: var(--danger-soft);
}

.feedback.review {
  border-color: #ddb56f;
  background: #fff5df;
}

.feedback-status {
  margin-bottom: 10px;
  font-weight: 800;
}

.manual-review {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

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

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

  .toolbar input,
  .mode-tabs {
    grid-column: 1 / -1;
  }

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

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

  .sidebar {
    max-height: 360px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  .topbar,
  .toolbar,
  .practice,
  .sidebar {
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .toolbar input,
  .mode-tabs {
    grid-column: auto;
  }

  .question-panel {
    padding: 18px;
  }

  #questionTitle {
    font-size: 21px;
  }

  .form-actions button {
    flex: 1 1 calc(50% - 8px);
  }

  .action-spacer {
    display: none;
  }
}
