:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-soft: #eff6ff;
  --ok: #15803d;
  --ok-bg: #ecfdf3;
  --bad: #b91c1c;
  --bad-bg: #fef2f2;
  --warn: #a16207;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.04);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

button,
input,
textarea {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.metrics {
  display: flex;
  gap: 12px;
  align-items: center;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 52px;
}

.metric strong {
  font-size: 1rem;
}

.metric span {
  color: var(--muted);
  font-size: 0.75rem;
}

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.rail,
.lesson-panel,
.editor-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.rail {
  padding: 14px;
  height: calc(100vh - 96px);
  position: sticky;
  top: 80px;
  overflow: auto;
}

.rail-head {
  margin-bottom: 12px;
}

.rail-head strong {
  font-size: 1.25rem;
}

.progress-track {
  margin-top: 8px;
  height: 8px;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}

#progressFill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #2563eb);
  transition: width 0.2s ease;
}

.path-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stage-block h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.lesson-btn {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.lesson-btn:hover:not(:disabled) {
  border-color: #bfdbfe;
  background: var(--brand-soft);
}

.lesson-btn.active {
  border-color: #93c5fd;
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 1px #bfdbfe;
}

.lesson-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  background: #fafafa;
}

.lesson-btn .title {
  font-size: 0.92rem;
}

.lesson-btn .tag {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.lesson-btn.done .tag {
  color: var(--ok);
}

.rail-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(320px, 1.2fr);
  gap: 16px;
  min-height: calc(100vh - 96px);
}

.lesson-panel {
  padding: 18px;
  overflow: auto;
}

.lesson-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 650;
}

.lesson-panel h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.goal {
  margin: 0 0 16px;
  color: #374151;
  line-height: 1.55;
}

.statement {
  margin: 0;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--sans);
  font-size: 0.92rem;
  line-height: 1.55;
  color: #1f2937;
}

.example-list,
.plain-list {
  margin: 0;
  padding-left: 1.15rem;
  color: #374151;
  line-height: 1.5;
}

.example-list li {
  margin-bottom: 8px;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.84rem;
}

.plain-list li {
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.block {
  margin-bottom: 14px;
}

.block h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0;
  margin: 0;
}

.chips li {
  background: #f3f4f6;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
}

.hints summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: 600;
}

.hints ol {
  margin: 8px 0 0;
  padding-left: 1.2rem;
  color: #374151;
  line-height: 1.5;
}

.answer-block pre {
  margin: 0;
  padding: 12px;
  background: #0b1220;
  color: #e5e7eb;
  border-radius: 10px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 9px;
  padding: 7px 12px;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  background: #f9fafb;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: #1d4ed8;
}

.btn.ghost {
  background: transparent;
}

.editor {
  min-height: 320px;
  height: 42vh;
  border-bottom: 1px solid var(--line);
}

.output-panel {
  padding: 12px;
  overflow: auto;
  flex: 1;
}

.output-tabs {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  flex-wrap: wrap;
}

.output-box {
  margin: 0 0 10px;
  min-height: 110px;
  max-height: 240px;
  overflow: auto;
  padding: 10px 12px;
  border-radius: 10px;
  background: #0b1220;
  color: #d1d5db;
  font-family: var(--mono);
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid #1f2937;
}

.output-box:empty::before {
  content: "print / 控制台输出会出现在这里";
  color: #6b7280;
}

.output-box.has-output {
  color: #e5e7eb;
}

.case-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.case-list li {
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  font-size: 0.86rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.case-list li.ok {
  background: var(--ok-bg);
  border-color: #bbf7d0;
  color: var(--ok);
}

.case-list li.bad {
  background: var(--bad-bg);
  border-color: #fecaca;
  color: var(--bad);
}

.muted {
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
    max-height: 280px;
  }

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

  .editor {
    height: 360px;
  }
}

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

  .metrics {
    width: 100%;
    justify-content: space-between;
  }
}

/* --- v4: knowledge base + mode switch + kind pills --- */
.mode-switch {
  display: flex;
  gap: 6px;
  background: #f3f4f6;
  padding: 4px;
  border-radius: 999px;
}

.mode-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
}

.mode-btn.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

.pill.soft {
  background: #f3f4f6;
  color: #4b5563;
}

.pill.read {
  background: #ecfeff;
  color: #0e7490;
}

.pill.agent {
  background: #f5f3ff;
  color: #6d28d9;
}

.chips li {
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.chips li:hover,
.chips li.linkable:hover {
  border-color: #bfdbfe;
  background: var(--brand-soft);
  color: var(--brand);
}

.chips li.linkable {
  cursor: pointer;
}

.lesson-btn .tag.kind-read {
  color: #0e7490;
}

.lesson-btn .tag.kind-agent {
  color: #6d28d9;
}

.kb-shell {
  grid-template-columns: 320px 1fr;
}

.kb-search {
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
}

.kb-tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.kb-tag {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
}

.kb-tag.active {
  background: var(--brand-soft);
  border-color: #93c5fd;
  color: var(--brand);
}

.kb-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.kb-item {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.kb-item:hover,
.kb-item.active {
  border-color: #93c5fd;
  background: var(--brand-soft);
}

.kb-item strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.kb-item span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.kb-main {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  min-height: calc(100vh - 96px);
  overflow: auto;
}

.kb-article h2 {
  margin: 0 0 8px;
  font-size: 1.4rem;
}

.kb-article .kb-summary {
  color: #374151;
  margin: 0 0 14px;
  line-height: 1.55;
}

.kb-article .kb-body {
  white-space: pre-wrap;
  line-height: 1.6;
  color: #1f2937;
  margin: 0 0 16px;
  font-size: 0.95rem;
}

.kb-article pre {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: #0b1220;
  color: #e5e7eb;
  border-radius: 10px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.45;
}

.kb-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.kb-links button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.84rem;
}

.kb-links button:hover {
  background: var(--brand-soft);
  border-color: #93c5fd;
  color: var(--brand);
}

.kb-section-title {
  margin: 18px 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 650;
}

@media (max-width: 980px) {
  .kb-shell {
    grid-template-columns: 1fr;
  }

  .mode-switch {
    order: 3;
  }
}
