:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #e3e8ef;
  --brand: #2f6df0;
  --brand-soft: #e8f0fe;
  --green: #1ea672;
  --amber: #e8920c;
  --red: #e0524d;
  --code-bg: #1e2430;
  --code-ink: #e6edf3;
  --shadow: 0 6px 22px rgba(31, 41, 51, 0.08);
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 30px; }
.topbar h1 { font-size: 19px; margin: 0; }
.subtitle { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.status { font-size: 13px; padding: 6px 12px; border-radius: 999px; }
.status.loading { background: #fff4e0; color: var(--amber); }
.status.ready { background: #e4f7ef; color: var(--green); }
.status.error { background: #fde8e7; color: var(--red); }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 67px);
}

/* 侧边栏 */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 14px;
  overflow-y: auto;
}
.search-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}
.search-box input:focus { border-color: var(--brand); }

nav#categories { margin-top: 14px; }
.cat-group { margin-bottom: 10px; }
.cat-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 12px 4px 6px;
}
.ex-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s;
}
.ex-item:hover { background: var(--brand-soft); }
.ex-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.ex-item .ex-done { color: var(--green); font-size: 13px; }
.ex-item .ex-num { color: var(--muted); font-size: 12px; min-width: 22px; }

.progress-card {
  margin-top: 18px;
  padding: 14px;
  background: var(--bg);
  border-radius: 12px;
}
.progress-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.progress-bar { height: 8px; background: #dde3ec; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--green); transition: width .3s; }

/* 主内容 */
.content { padding: 24px 28px; overflow-y: auto; }
.hidden { display: none !important; }

.welcome {
  background: var(--panel);
  border-radius: 16px;
  padding: 28px 30px;
  box-shadow: var(--shadow);
  max-width: 720px;
}
.welcome h2 { margin-top: 0; }
.tips { color: var(--muted); line-height: 1.9; font-size: 14px; }

.exercise {
  background: var(--panel);
  border-radius: 16px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
}
.exercise-head { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 16px; }
.exercise-head h2 { margin: 8px 0 0; }
.badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eef1f6;
  color: var(--muted);
  margin-right: 6px;
}
.badge.cat { background: var(--brand-soft); color: var(--brand); }

.exercise-body { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 920px) { .exercise-body { grid-template-columns: 1fr; } }

.problem h3, .editor-pane .editor-head, .output-head {
  font-size: 14px;
  margin: 0 0 10px;
  color: var(--ink);
}
.desc { font-size: 14px; line-height: 1.8; color: #374151; white-space: pre-wrap; }

.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.ghost { background: #eef1f6; color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.hint, .solution {
  background: var(--bg);
  border-left: 3px solid var(--amber);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.7;
  margin-top: 8px;
}
.solution { border-left-color: var(--brand); }
.solution pre { margin: 8px 0 0; }
.solution code, .output {
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
}

.editor-pane {
  display: flex;
  flex-direction: column;
}
.editor-head { display: flex; justify-content: space-between; align-items: center; }
.run-state { font-size: 12px; color: var(--muted); }
.run-state.ok { color: var(--green); }
.run-state.err { color: var(--red); }

#code {
  width: 100%;
  min-height: 240px;
  background: var(--code-bg);
  color: var(--code-ink);
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  tab-size: 4;
}
.output-head { margin-top: 14px; }
.output {
  background: var(--code-bg);
  color: var(--code-ink);
  border-radius: 10px;
  padding: 14px;
  min-height: 90px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.output .muted { color: #7c8794; }
.output .err { color: #ff8a80; }
