/* 学习路线图 · 算法可视化图谱（原创样式；:root 变量体系与 site.css 保持一致） */

:root {
  color-scheme: light;
  --bg: #f3f6f4;
  --surface: #fff;
  --ink: #17201e;
  --muted: #65716d;
  --line: #d7dfdb;
  --dark: #15211f;
  --dark-2: #1d2d29;
  --teal: #0d8490;
  --amber: #c7811d;
  --coral: #c95649;
  --green: #3b8c63;
  --violet: #725ca8;
  --shadow: 0 10px 28px rgba(20, 35, 31, 0.08);
  --mono: "Cascadia Code", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Consolas, "SF Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Cascadia Code", "JetBrains Mono", "Fira Code", ui-monospace, Consolas, "SF Mono", Menlo, "Microsoft YaHei", monospace;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ---------- 页头 ---------- */

.site-header {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 max(24px, calc((100% - 1240px) / 2));
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--teal);
  border-radius: 5px;
  color: var(--teal);
  font: 600 11px/1 var(--mono);
}

.brand b {
  display: block;
  font-size: 15px;
  font-weight: 600;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font: 500 9px/1.2 var(--mono);
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.site-header nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.site-header nav a:hover {
  color: var(--teal);
}

svg {
  width: 16px;
  height: 16px;
  flex: none;
}

/* ---------- 页面骨架 ---------- */

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 30px 24px 90px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 26px;
  align-items: end;
}

.kicker {
  margin: 0 0 8px;
  color: var(--teal);
  font: 600 11px/1 var(--mono);
  letter-spacing: 0.18em;
}

.hero h1 {
  margin: 0 0 10px;
  font-size: 30px;
  line-height: 1.25;
}

.hero-sub {
  margin: 0;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.85;
  max-width: 62ch;
}

.hero-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

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

.progress-label {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-size: 13.5px;
  color: var(--muted);
}

.progress-label b {
  color: var(--teal);
  font: 700 22px/1 var(--mono);
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  transition: color 0.15s, border-color 0.15s;
}

.ghost-btn:hover {
  color: var(--coral);
  border-color: var(--coral);
}

.ghost-btn svg {
  width: 13px;
  height: 13px;
}

.progress-track {
  height: 6px;
  margin-top: 12px;
  border-radius: 999px;
  background: rgba(23, 32, 30, 0.08);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--green));
  transition: width 0.35s ease;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12.5px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-done {
  margin-left: auto;
}

/* 难度配色：基础=green 进阶=amber 高级=coral */

.dot {
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.diff-1 .dot,
i.dot.diff-1 {
  background: var(--green);
}

.diff-2 .dot,
i.dot.diff-2 {
  background: var(--amber);
}

.diff-3 .dot,
i.dot.diff-3 {
  background: var(--coral);
}

.chip-check {
  display: none;
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font: 600 11px/16px var(--mono);
  text-align: center;
}

.chip-check.demo {
  display: inline-block;
}

/* ---------- 工具条 ---------- */

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 26px 0 16px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1 1 320px;
  max-width: 520px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-box:focus-within {
  border-color: var(--teal);
  box-shadow: 0 4px 14px rgba(13, 132, 144, 0.14);
}

.search-box svg {
  color: var(--muted);
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
}

.search-hint {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 四列阶段布局 ---------- */

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.stage-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.stage-col[data-stage="1"] {
  --stage-accent: var(--teal);
  --stage-accent-soft: rgba(13, 132, 144, 0.1);
}

.stage-col[data-stage="2"] {
  --stage-accent: var(--amber);
  --stage-accent-soft: rgba(199, 129, 29, 0.1);
}

.stage-col[data-stage="3"] {
  --stage-accent: var(--violet);
  --stage-accent-soft: rgba(114, 92, 168, 0.1);
}

.stage-col[data-stage="4"] {
  --stage-accent: var(--coral);
  --stage-accent-soft: rgba(201, 86, 73, 0.1);
}

.stage-head {
  position: sticky;
  z-index: 4;
  top: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(243, 246, 244, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(8px);
}

.stage-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: var(--stage-accent);
  background: var(--stage-accent-soft);
}

.stage-title {
  min-width: 0;
}

.stage-en {
  display: block;
  color: var(--muted);
  font: 600 9.5px/1.2 var(--mono);
  letter-spacing: 0.14em;
}

.stage-title h2 {
  margin: 2px 0 0;
  font-size: 15.5px;
  line-height: 1.3;
}

.stage-count {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  margin-left: auto;
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.stage-count b {
  color: var(--stage-accent);
  font: 700 16px/1 var(--mono);
}

.stage-blurb {
  margin: -6px 4px 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

/* 组卡片：不建立层叠上下文，保证连线绘制在卡片之上、节点之下 */

.group {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.group-name {
  font-size: 13.5px;
  font-weight: 600;
}

.group-count {
  margin-left: auto;
  color: var(--muted);
  font: 500 11px/1 var(--mono);
}

.group-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.node {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chip {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  text-align: left;
  font-size: 13.5px;
  line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.chip:hover {
  border-color: var(--teal);
  box-shadow: 0 4px 14px rgba(13, 132, 144, 0.14);
}

.chip-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.chip.done {
  border-color: rgba(59, 140, 99, 0.55);
  background: rgba(59, 140, 99, 0.1);
}

.chip.done .dot {
  display: none;
}

.chip.done .chip-check {
  display: block;
}

.chip-linked {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(13, 132, 144, 0.18);
}

.search-dim {
  opacity: 0.15;
  filter: grayscale(0.7);
}

.node-prereqs {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding-left: 4px;
}

.prereq-label {
  color: var(--muted);
  font-size: 11px;
}

.prereq-mini {
  padding: 2px 7px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.prereq-mini:hover {
  color: var(--teal);
  border-color: var(--teal);
}

/* ---------- 先修连线 ---------- */

.edges {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

.edge {
  fill: none;
  stroke: rgba(13, 132, 144, 0.26);
  stroke-width: 1.4;
  stroke-linecap: round;
}

.edge.edge-active {
  stroke: var(--teal);
  stroke-width: 2.2;
}

.edge.edge-dim {
  opacity: 0.07;
}

.board-empty {
  grid-column: 1 / -1;
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- 详情抽屉 ---------- */

.drawer-backdrop {
  position: fixed;
  z-index: 55;
  inset: 0;
  background: rgba(21, 33, 31, 0.44);
}

.drawer {
  position: fixed;
  z-index: 60;
  top: 0;
  right: 0;
  bottom: 0;
  display: none;
  flex-direction: column;
  width: 380px;
  max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(20, 35, 31, 0.18);
}

.drawer.open {
  display: flex;
  animation: drawer-in 0.26s ease;
}

@keyframes drawer-in {
  from {
    transform: translateX(105%);
  }
  to {
    transform: none;
  }
}

.drawer-close {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.drawer-close:hover {
  color: var(--ink);
  border-color: var(--muted);
}

.drawer-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 20px;
}

.drawer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-right: 36px;
}

.meta-chip {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
}

.meta-chip.diff-1 {
  color: var(--green);
  border-color: rgba(59, 140, 99, 0.4);
  background: rgba(59, 140, 99, 0.08);
}

.meta-chip.diff-2 {
  color: var(--amber);
  border-color: rgba(199, 129, 29, 0.4);
  background: rgba(199, 129, 29, 0.08);
}

.meta-chip.diff-3 {
  color: var(--coral);
  border-color: rgba(201, 86, 73, 0.4);
  background: rgba(201, 86, 73, 0.08);
}

.drawer h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.drawer-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(13, 132, 144, 0.08);
  color: var(--teal);
  font-size: 12px;
}

.drawer-summary {
  margin: 0;
  font-size: 14px;
  line-height: 1.75;
}

.drawer-block {
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.block-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.block-label svg {
  width: 13px;
  height: 13px;
}

.block-empty {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.rel-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.rel-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  text-align: left;
  transition: border-color 0.15s, color 0.15s;
}

.rel-chip:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.rel-chip.done {
  border-color: rgba(59, 140, 99, 0.5);
  background: rgba(59, 140, 99, 0.08);
}

.rel-chip .chip-name {
  flex: 0 1 auto;
}

.rel-done {
  color: var(--green);
  font: 700 12px/1 var(--mono);
}

.drawer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  text-align: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.action:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.action svg {
  width: 14px;
  height: 14px;
}

.action-primary {
  background: var(--dark);
  border-color: var(--dark);
  color: #fff;
}

.action-primary:hover {
  background: var(--dark-2);
  border-color: var(--dark-2);
  color: #fff;
}

.action-mark.is-done {
  border-color: rgba(59, 140, 99, 0.5);
  background: rgba(59, 140, 99, 0.08);
  color: var(--green);
}

.action-mark.is-done:hover {
  color: var(--coral);
  border-color: rgba(201, 86, 73, 0.5);
}

/* ---------- 学习主线视图 ---------- */

.view-switch {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.view-btn svg {
  width: 14px;
  height: 14px;
}

.view-btn[aria-pressed="true"] {
  background: var(--dark);
  color: #fff;
}

.view-btn[aria-pressed="false"]:hover {
  color: var(--teal);
}

.progress-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.path-view {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.path-stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.path-stage[data-stage="1"] {
  --stage-accent: var(--teal);
  --stage-accent-soft: rgba(13, 132, 144, 0.1);
}

.path-stage[data-stage="2"] {
  --stage-accent: var(--amber);
  --stage-accent-soft: rgba(199, 129, 29, 0.1);
}

.path-stage[data-stage="3"] {
  --stage-accent: var(--violet);
  --stage-accent-soft: rgba(114, 92, 168, 0.1);
}

.path-stage[data-stage="4"] {
  --stage-accent: var(--coral);
  --stage-accent-soft: rgba(201, 86, 73, 0.1);
}

.path-stage .stage-head {
  position: sticky;
  top: 64px;
  z-index: 4;
}

.path-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.path-node {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  padding: 7px 10px 7px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.path-node:hover {
  border-color: var(--stage-accent, var(--teal));
  box-shadow: 0 4px 14px rgba(20, 35, 31, 0.1);
  transform: translateY(-1px);
}

.node-order {
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 22px;
  padding: 0 5px;
  border-radius: 7px;
  color: var(--stage-accent, var(--teal));
  background: var(--stage-accent-soft, rgba(13, 132, 144, 0.1));
  font: 700 12px/1 var(--mono);
  font-variant-numeric: tabular-nums;
}

.path-node .chip-name {
  font-size: 13px;
  font-weight: 600;
}

.path-node .chip-check {
  display: none;
}

.path-node.done {
  border-color: rgba(59, 140, 99, 0.55);
  background: rgba(59, 140, 99, 0.08);
}

.path-node.done .node-order {
  color: var(--green);
  background: rgba(59, 140, 99, 0.14);
}

.path-node.done .chip-name {
  color: var(--muted);
}

.path-node.done .chip-check {
  display: inline;
  color: var(--green);
  font-weight: 700;
}

/* 扩展主题折叠区 */

.path-ext {
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
}

.path-ext summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.path-ext summary::-webkit-details-marker {
  display: none;
}

.path-ext summary::before {
  content: '▸';
  color: var(--muted);
  transition: transform 0.15s;
}

.path-ext[open] summary::before {
  transform: rotate(90deg);
}

.path-ext summary .ext-count {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(23, 32, 30, 0.07);
  font: 600 11px/1.4 var(--mono);
}

.path-ext summary small {
  margin-left: auto;
  color: var(--muted);
  font-weight: 400;
  font-size: 11.5px;
}

.path-ext-body {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 14px 14px;
}

.path-ext-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s, border-color 0.15s;
}

.path-ext-chip:hover {
  color: var(--ink);
  border-color: var(--teal);
}

.path-ext-chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.path-ext-chip .dot {
  flex: none;
}

.path-ext-chip .chip-check {
  display: none;
}

.path-ext-chip.done {
  border-color: rgba(59, 140, 99, 0.5);
  color: var(--ink);
}

.path-ext-chip.done .chip-check {
  display: inline;
  color: var(--green);
  font-weight: 700;
}

.path-ext-chip.done .chip-name {
  color: var(--muted);
}

@media (max-width: 640px) {
  .view-switch {
    margin-left: 0;
  }

  .path-node {
    flex: 1 1 auto;
  }

  .path-ext summary small {
    display: none;
  }
}

@media (max-width: 440px) {
  /* 纵向工具条里 flex-basis 会变成高度，恢复由内容撑开 */
  .search-box {
    flex: 0 0 auto;
  }
}

/* ---------- 响应式 ---------- */

@media (max-width: 1288px) {
  .page {
    padding: 26px 20px 80px;
  }

  .board {
    gap: 12px;
  }

  .chip {
    font-size: 13px;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr) 320px;
  }
}

@media (max-width: 980px) {
  .hero {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .hero-panel {
    max-width: 560px;
  }

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

  .edges {
    display: none;
  }

  .node-prereqs {
    display: flex;
  }
}

@media (max-width: 760px) {
  .site-header nav {
    gap: 16px;
  }

  .site-header nav .nav-label {
    display: none;
  }

  .hero h1 {
    font-size: 25px;
  }

  .drawer {
    width: 100%;
    border-left: none;
  }
}

@media (max-width: 759px) {
  body.drawer-lock {
    overflow: hidden;
  }
}

@media (max-width: 440px) {
  .page {
    padding: 20px 14px 64px;
  }

  .site-header {
    padding: 0 14px;
  }

  .hero-panel {
    padding: 14px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: none;
  }

  .drawer-actions {
    grid-template-columns: 1fr;
  }

  .legend-done {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
