:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #52606d;
  --border: #e4e7eb;
  --primary: #2f6fed;
  --primary-hover: #2359c9;
  --accent: #0f172a;
  --success: #10b981;
  --danger: #ef4444;
  --code-bg: #212121;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 6px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

.brand { display: flex; align-items: baseline; gap: 12px; }
.brand .logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.3px;
}
.brand .sub {
  font-size: 13px;
  color: var(--muted);
}

.status {
  font-size: 13px;
  color: var(--muted);
  background: #eef2ff;
  padding: 6px 10px;
  border-radius: 6px;
}
.status.ready { background: #ecfdf5; color: #047857; }
.status.error { background: #fef2f2; color: #b91c1c; }

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

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}

.sidebar-title {
  padding: 0 20px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.topics {
  list-style: none;
  margin: 0;
  padding: 0;
}
.topics li {
  padding: 10px 20px;
  cursor: pointer;
  font-size: 14px;
  color: #334155;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.topics li:hover { background: #f8fafc; }
.topics li.active {
  background: #eef2ff;
  border-left-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}
.topics li .num {
  display: inline-block;
  width: 22px;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}
.topics li.active .num { color: var(--primary); }

.sidebar-foot {
  padding: 20px;
  color: #94a3b8;
  font-size: 11px;
}

.content {
  padding: 28px 36px 48px;
  max-width: 1100px;
}

.lesson-head {
  margin-bottom: 20px;
}
.lesson-head h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}
.lesson-sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.lesson-intro {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 20px;
  line-height: 1.7;
  font-size: 14px;
  color: #334155;
  box-shadow: var(--shadow);
}
.lesson-intro p { margin: 0 0 10px; }
.lesson-intro p:last-child { margin-bottom: 0; }
.lesson-intro code {
  background: #f1f5f9;
  color: #0f172a;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
}
.lesson-intro ul { margin: 8px 0 8px 20px; padding: 0; }
.lesson-intro li { margin-bottom: 4px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.panel-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
}
.panel-actions { display: flex; gap: 8px; }

.editor-wrap { background: var(--code-bg); }
.editor-wrap .CodeMirror {
  height: auto;
  min-height: 220px;
  font-size: 13.5px;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
}

.output {
  margin: 0;
  padding: 16px 18px;
  background: #0f172a;
  color: #e2e8f0;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  min-height: 120px;
  max-height: 480px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.output .placeholder { color: #64748b; }
.output .stdout { color: #e2e8f0; }
.output .stderr { color: #fca5a5; }
.output .info { color: #7dd3fc; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: #334155;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn:hover { background: #f1f5f9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.solution-body {
  padding: 18px 20px;
  line-height: 1.7;
  font-size: 14px;
  color: #334155;
}
.solution-body h3 {
  margin: 16px 0 8px;
  font-size: 15px;
  color: var(--accent);
}
.solution-body h3:first-child { margin-top: 0; }
.solution-body p { margin: 0 0 10px; }
.solution-body ul { margin: 6px 0 10px 22px; padding: 0; }
.solution-body li { margin-bottom: 3px; }
.solution-body pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: 6px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.6;
  margin: 8px 0 14px;
}
.solution-body code {
  background: #f1f5f9;
  color: #0f172a;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content { padding: 20px; }
}
