:root {
  --bg: #f4f3ee;
  --paper: #ffffff;
  --ink: #20242a;
  --muted: #62676f;
  --line: #d8d6ce;
  --soft: #ebeae4;
  --code-bg: #16181e;
  --code-ink: #e8e6e0;
  --ok: #166534;
  --warn: #9a3412;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 292px;
  display: flex;
  flex-direction: column;
  background: #fbfaf7;
  border-right: 1px solid var(--line);
  z-index: 20;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 8px;
  background: #243447;
  color: #f6f0d8;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-text {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  padding: 4px 10px;
}

.nav-close {
  display: none;
  margin-left: auto;
}

.search-box {
  padding: 4px 14px 12px;
}

.search-box input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  padding: 6px 12px;
}

.search-box input:focus {
  outline: 2px solid #d49a5a;
  outline-offset: 0;
}

.side-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 12px;
  scrollbar-width: thin;
}

.nav-group {
  margin: 8px 0 16px;
}

.nav-group-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}

.nav-group-title::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot, #8d9299);
  transform: translateY(-1px);
}

.nav-topic {
  display: block;
  width: 100%;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--ink);
  padding: 7px 10px 7px 14px;
  text-align: left;
  border-radius: 0 6px 6px 0;
  line-height: 1.4;
}

.nav-topic:hover {
  background: var(--soft);
}

.nav-topic.active {
  border-left-color: var(--phase, #6b7280);
  background: color-mix(in srgb, var(--phase, #6b7280) 10%, white);
  font-weight: 700;
}

.nav-topic .nav-status {
  margin-left: 6px;
  color: var(--ok);
  font-size: 12px;
}

.side-footer {
  border-top: 1px solid var(--line);
  padding: 10px 14px 14px;
  color: var(--muted);
  font-size: 13px;
}

.main-wrap {
  margin-left: 292px;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 22px;
  background: rgba(244, 243, 238, 0.95);
  border-bottom: 1px solid var(--line);
}

.crumb {
  flex: 1;
  color: var(--muted);
  font-size: 14px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-btn {
  display: none;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  font-size: 13px;
}

.text-btn:hover {
  color: var(--ink);
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 26px 26px 60px;
  outline: none;
}

.site-footer {
  margin-left: 292px;
  border-top: 1px solid var(--line);
  padding: 14px 26px;
  color: var(--muted);
  font-size: 13px;
}

.road-title {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.3;
  letter-spacing: 0;
}

.road-sub {
  max-width: 860px;
  margin: 0 0 20px;
  color: var(--muted);
}

.progress-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 0 24px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
}

.progress-track {
  flex: 1;
  height: 10px;
  overflow: hidden;
  background: var(--soft);
  border-radius: 99px;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--ok);
  border-radius: 99px;
  transition: width 0.2s ease;
}

.progress-num {
  min-width: 86px;
  text-align: right;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.phase-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.phase-card {
  display: flex;
  flex-direction: column;
  min-height: 218px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
  overflow: hidden;
}

.phase-top {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px 10px;
}

.phase-no {
  display: grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--phase, #6b7280);
  color: #fff;
  font-weight: 800;
}

.phase-head h2 {
  margin: 0 0 2px;
  font-size: 19px;
  line-height: 1.35;
  letter-spacing: 0;
}

.phase-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.phase-goal {
  padding: 0 18px 10px;
  color: var(--ink);
  font-size: 14px;
}

.phase-count {
  margin-top: auto;
  padding: 10px 18px 12px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px dashed var(--line);
}

.topic-title {
  margin: 8px 0 6px;
  font-size: 30px;
  line-height: 1.25;
  letter-spacing: 0;
}

.topic-summary {
  max-width: 920px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 16px;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 20px;
}

.phase-chip,
.topic-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--paper);
  font-size: 13px;
}

.phase-chip {
  border-color: color-mix(in srgb, var(--phase, #6b7280) 40%, var(--line));
  color: color-mix(in srgb, var(--phase, #6b7280) 78%, black);
  font-weight: 700;
}

.topic-section {
  margin: 0 0 24px;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.sec-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.sec-no {
  color: var(--warn);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.sec-head h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.35;
  letter-spacing: 0;
}

.topic-section p {
  margin: 0 0 10px;
}

.topic-section ul,
.topic-section ol {
  margin: 0 0 10px;
  padding-left: 22px;
}

.topic-section li {
  margin: 4px 0;
}

.sample-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.sample-box {
  border: 1px solid var(--line);
  background: #faf9f5;
  border-radius: 8px;
  overflow: hidden;
}

.sample-label {
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.sample-value {
  margin: 0;
  padding: 10px 12px;
  white-space: pre-wrap;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
}

.constraint-list {
  margin: 12px 0 0;
  padding: 10px 14px;
  border-left: 4px solid #d49a5a;
  background: #faf7ef;
  font-size: 14px;
}

.deriv-item {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  padding: 0 0 18px;
  position: relative;
}

.deriv-item::before {
  content: "";
  position: absolute;
  left: 22px;
  top: 44px;
  bottom: 0;
  width: 2px;
  background: var(--line);
}

.deriv-item:last-child::before {
  display: none;
}

.deriv-step {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #243447;
  color: #fff;
  font-weight: 800;
  z-index: 1;
}

.deriv-body h3 {
  margin: 2px 0 6px;
  font-size: 17px;
  line-height: 1.4;
  letter-spacing: 0;
}

.quote-line {
  margin: 12px 0 0;
  padding: 12px 16px;
  border-left: 4px solid var(--ok);
  background: #f0f6f1;
  color: #243c2c;
  font-weight: 600;
}

.tree-chain {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
}

.chain-node {
  min-width: 150px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf9f5;
}

.chain-node.current {
  border-color: var(--phase, #6b7280);
  border-width: 2px;
  background: color-mix(in srgb, var(--phase, #6b7280) 12%, white);
}

.chain-node .chain-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.chain-node strong {
  display: block;
  font-size: 14px;
}

.chain-node .chain-link {
  font-size: 13px;
  color: var(--warn);
}

.chain-arrow {
  align-self: center;
  color: var(--muted);
  font-size: 20px;
  font-weight: 700;
}

.empty-note {
  color: var(--muted);
  font-size: 14px;
  padding: 8px 0;
}

.mind-map {
  display: grid;
  grid-template-columns: minmax(190px, 0.8fr) 1.3fr;
  gap: 16px;
}

.mind-center {
  align-self: start;
  padding: 16px;
  border: 2px solid var(--phase, #6b7280);
  border-radius: 8px;
  background: color-mix(in srgb, var(--phase, #6b7280) 10%, white);
}

.mind-center strong {
  display: block;
  font-size: 18px;
}

.mind-center span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.mind-branches {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.mind-branch {
  padding: 12px 14px 6px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--phase, #6b7280);
  border-radius: 8px;
  background: #fcfbf8;
}

.mind-branch h4 {
  margin: 0 0 6px;
  font-size: 15px;
}

.mind-branch ul {
  margin: 0;
  padding-left: 18px;
}

.mind-branch li {
  font-size: 14px;
}

.flow-list {
  display: grid;
  gap: 0;
}

.flow-step {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  position: relative;
  padding: 0 0 16px;
}

.flow-step::before {
  content: "";
  position: absolute;
  left: 22px;
  top: 42px;
  bottom: -2px;
  width: 2px;
  background: var(--line);
}

.flow-step:last-child::before {
  display: none;
}

.flow-dot {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 2px solid var(--phase, #6b7280);
  color: var(--phase, #6b7280);
  background: white;
  font-weight: 800;
  z-index: 1;
}

.flow-body h3 {
  margin: 3px 0 5px;
  font-size: 16px;
}

.flow-body p {
  margin: 0 0 5px;
}

.code-hint {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.code-block-wrap {
  position: relative;
  border: 1px solid #30343d;
  border-radius: 8px;
  overflow: hidden;
  background: var(--code-bg);
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: #22252d;
  color: #c9c7c0;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.copy-btn {
  border: 1px solid #4b515c;
  border-radius: 5px;
  background: transparent;
  color: #e5e3dc;
  padding: 3px 10px;
  font-size: 12px;
}

.copy-btn:hover {
  background: #3a3f49;
}

.code-block {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  color: var(--code-ink);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.65;
}

.tok-kw {
  color: #f0a868;
}

.tok-cm {
  color: #7f9487;
  font-style: italic;
}

.tok-num {
  color: #b9c6ff;
}

.tok-str {
  color: #a3d9a5;
}

.tok-pre {
  color: #e4b6e6;
}

.tok-type {
  color: #8fd6d4;
}

.code-note {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.walk-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

.walk-table th {
  background: #f4f2ec;
  white-space: nowrap;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pitfall-grid {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.pitfall-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
  padding: 10px 14px;
  border-left: 4px solid #d97706;
  background: #fdf6ec;
}

.pitfall-name {
  font-weight: 700;
  color: #7c2d12;
}

.term-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  padding: 8px 2px;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}

.term-name {
  font-weight: 700;
}

.quiz-item {
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}

.quiz-q {
  margin: 0 0 10px;
  font-weight: 700;
}

.quiz-options {
  display: grid;
  gap: 8px;
}

.quiz-choice {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 7px 12px;
  font-size: 14px;
}

.quiz-choice:hover {
  background: #f2f1ec;
}

.quiz-choice.selected {
  border-color: var(--ok);
  background: #eef6ef;
}

.quiz-choice.correct {
  border-color: var(--ok);
  background: #dff0e2;
}

.quiz-choice.wrong {
  border-color: #b91c1c;
  background: #fdecec;
}

.quiz-result {
  display: none;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 7px;
  background: #f1f5f3;
  color: #243c2c;
  font-size: 14px;
}

.quiz-result.show {
  display: block;
}

.search-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.result-link {
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.result-link strong {
  display: block;
  margin-bottom: 4px;
}

.result-link span {
  color: var(--muted);
  font-size: 13px;
}

.status-btn {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  padding: 7px 14px;
}

.status-btn.done {
  border-color: #2e7d4f;
  background: #e7f2ea;
  color: #14532d;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(20, 22, 26, 0.45);
}

.skip {
  position: absolute;
  left: -9999px;
  z-index: 50;
}

.skip:focus {
  left: 8px;
  top: 8px;
  background: white;
  padding: 6px 10px;
}

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

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 24px rgba(20, 22, 26, 0.15);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .nav-close,
  .menu-btn {
    display: inline-flex;
  }

  .main-wrap,
  .site-footer {
    margin-left: 0;
  }

  main {
    padding: 18px 16px 48px;
  }

  .topic-section {
    padding: 18px 14px;
  }

  .mind-map {
    grid-template-columns: 1fr;
  }

  .mind-branches {
    grid-template-columns: 1fr;
  }

  .pitfall-row,
  .term-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .road-title,
  .topic-title {
    font-size: 24px;
  }
}

@media (max-width: 560px) {
  .sample-grid,
  .phase-grid {
    grid-template-columns: 1fr;
  }

  .deriv-item {
    grid-template-columns: 38px 1fr;
  }

  .deriv-step,
  .flow-dot {
    width: 36px;
    height: 36px;
    font-size: 14px;
  }

  .deriv-item::before {
    left: 18px;
  }

  .flow-step::before {
    left: 18px;
  }

  .chain-node {
    min-width: 100%;
  }

  .chain-arrow {
    display: none;
  }
}
