:root {
  --bg: #f1f1ef;
  --paper: rgba(250, 249, 245, 0.92);
  --paper-strong: #ffffff;
  --ink: #143d56;
  --ink-soft: #5b6f7f;
  --line: rgba(20, 61, 86, 0.12);
  --shadow: 0 22px 48px rgba(21, 37, 46, 0.08);
  --teal: #227b73;
  --blue: #2f7ec6;
  --orange: #de823f;
  --berry: #a14874;
  --moss: #7b9350;
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(222, 130, 63, 0.14), transparent 24rem),
    radial-gradient(circle at left 15%, rgba(34, 123, 115, 0.1), transparent 18rem),
    linear-gradient(180deg, #f5f4f1 0%, #eeece8 100%);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
a {
  font: inherit;
}

.graph-shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px 18px 32px;
}

.graph-topbar,
.learning-console,
.scope-strip,
.graph-stage,
.detail-panel,
.legend-card,
.detail-card {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.learning-console {
  display: grid;
  grid-template-columns: minmax(18rem, 0.9fr) minmax(22rem, 1.5fr);
  gap: 22px;
  align-items: center;
  margin-bottom: 16px;
  padding: 18px 20px;
  border-radius: var(--radius-xl);
}

.progress-copy h2 {
  margin: 0 0 6px;
  font-size: 1.18rem;
}

.progress-copy p:last-child,
.progress-stats span,
.teaching-note {
  color: var(--ink-soft);
}

.progress-copy p:last-child {
  margin: 0;
  line-height: 1.55;
}

.progress-main {
  display: grid;
  grid-template-columns: auto minmax(8rem, 1fr) auto;
  gap: 14px;
  align-items: center;
}

.progress-stats {
  display: grid;
  min-width: 6.6rem;
}

.progress-stats strong {
  font-size: 1.18rem;
}

.progress-stats span {
  font-size: 0.78rem;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(20, 61, 86, 0.1);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--blue));
  transition: width 220ms ease;
}

.progress-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.primary-button {
  border: 0;
  border-radius: 999px;
  padding: 0.76rem 1rem;
  color: #fff;
  background: var(--ink);
  cursor: pointer;
}

.graph-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  padding: 20px 22px;
  border-radius: var(--radius-xl);
  margin-bottom: 16px;
}

.topbar-main {
  display: flex;
  gap: 18px;
  align-items: flex-start;
}

.back-link,
.action-button,
.scope-button,
.drawer-toggle,
.neighbor-button,
.detail-action,
.quiz-button {
  border: 1px solid rgba(20, 61, 86, 0.12);
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  border-radius: 999px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease,
    color 160ms ease;
}

.back-link,
.action-button,
.scope-button,
.drawer-toggle,
.detail-action,
.quiz-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  padding: 0.74rem 1rem;
}

.back-link:hover,
.action-button:hover,
.scope-button:hover,
.drawer-toggle:hover,
.neighbor-button:hover,
.detail-action:hover,
.quiz-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(20, 61, 86, 0.1);
}

.back-link {
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--orange);
}

.graph-topbar h1,
.graph-stage h2,
.detail-panel h2 {
  margin: 0;
  letter-spacing: -0.03em;
}

.graph-topbar h1 {
  font-size: clamp(1.7rem, 3vw, 2.5rem);
}

.topbar-text {
  margin: 10px 0 0;
  max-width: 48rem;
  color: var(--ink-soft);
  line-height: 1.7;
}

.topbar-meta {
  display: grid;
  gap: 10px;
  min-width: 16rem;
}

.meta-card {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(20, 61, 86, 0.08);
}

.meta-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.scope-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-xl);
  margin-bottom: 16px;
}

.scope-tabs,
.canvas-actions,
.legend-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.scope-button.active {
  color: #ffffff;
  border-color: transparent;
  background: var(--ink);
}

.action-button.active {
  color: #ffffff;
  border-color: transparent;
  background: var(--orange);
}

.graph-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(20rem, 27rem);
  gap: 18px;
  align-items: start;
}

.graph-stage {
  border-radius: var(--radius-xl);
  padding: 18px;
}

.stage-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
}

.stage-note {
  margin: 0;
  max-width: 30rem;
  color: var(--ink-soft);
  line-height: 1.6;
  text-align: right;
}

.graph-canvas-shell {
  position: relative;
  min-height: 70vh;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(20, 61, 86, 0.1);
  background:
    linear-gradient(90deg, rgba(20, 61, 86, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(20, 61, 86, 0.04) 1px, transparent 1px),
    radial-gradient(circle at top, rgba(255, 255, 255, 0.8), rgba(248, 247, 243, 0.9));
  background-size: 28px 28px, 28px 28px, auto;
}

#graph-svg {
  display: block;
  width: 100%;
  height: 70vh;
  min-height: 70vh;
  touch-action: none;
}

.graph-loading {
  position: absolute;
  inset: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: rgba(250, 249, 245, 0.88);
  color: var(--ink-soft);
  z-index: 3;
}

.graph-loading.hidden {
  display: none;
}

.legend-card {
  margin-top: 14px;
  padding: 16px;
  border-radius: var(--radius-lg);
}

.legend-group + .legend-group {
  margin-top: 14px;
}

.legend-group h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.52rem 0.8rem;
  border-radius: 999px;
  background: rgba(20, 61, 86, 0.06);
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.legend-pill::before {
  content: "";
  width: 14px;
  height: 14px;
  display: inline-block;
  border: 2px solid currentColor;
}

.shape-topic::before {
  border-radius: 999px;
}

.shape-concept::before {
  border-radius: 999px;
  width: 12px;
  height: 12px;
}

.shape-metric::before {
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

.shape-phenomenon::before {
  transform: rotate(45deg);
  border-radius: 2px;
}

.shape-material::before,
.shape-space::before {
  border-radius: 4px;
}

.detail-panel {
  border-radius: var(--radius-xl);
  padding: 18px;
  position: sticky;
  top: 18px;
}

.detail-header,
.detail-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.drawer-toggle {
  display: none;
}

.detail-body {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.detail-card {
  padding: 14px;
  border-radius: var(--radius-lg);
}

.detail-card h3,
.detail-summary-title {
  margin: 0 0 8px;
}

.detail-card p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.65;
}

.detail-meta,
.detail-alias,
.detail-source {
  margin-top: 8px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.count-badge {
  min-width: 2rem;
  padding: 0.34rem 0.56rem;
  border-radius: 999px;
  background: rgba(20, 61, 86, 0.08);
  color: var(--ink-soft);
  font-size: 0.82rem;
  text-align: center;
}

.neighbor-list,
.chunk-list,
.quiz-list,
.prerequisite-list,
.micro-check-list {
  display: grid;
  gap: 10px;
}

.teaching-note {
  margin: 0 0 10px !important;
}

.learning-state {
  padding: 0.34rem 0.62rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: rgba(20, 61, 86, 0.08);
}

.learning-state.state-exposed {
  color: #2f65a0;
  background: rgba(47, 126, 198, 0.12);
}

.learning-state.state-developing {
  color: #17665e;
  background: rgba(34, 123, 115, 0.14);
}

.learning-state.state-misconception {
  color: #9b4e18;
  background: rgba(222, 130, 63, 0.16);
}

.prerequisite-button {
  width: 100%;
  border: 1px solid rgba(20, 61, 86, 0.1);
  border-radius: var(--radius-md);
  padding: 0.72rem 0.82rem;
  text-align: left;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  cursor: pointer;
}

.prerequisite-button small {
  display: block;
  margin-top: 4px;
  color: var(--ink-soft);
}

.micro-check {
  padding: 12px;
  border: 1px solid rgba(20, 61, 86, 0.1);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.78);
}

.micro-check h4 {
  margin: 0 0 10px;
  font-size: 0.98rem;
  line-height: 1.5;
}

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

.micro-option {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 0.72rem;
  border: 1px solid rgba(20, 61, 86, 0.1);
  border-radius: 10px;
  cursor: pointer;
}

.micro-option:has(input:checked) {
  border-color: rgba(34, 123, 115, 0.55);
  background: rgba(34, 123, 115, 0.08);
}

.micro-submit {
  width: 100%;
  margin-top: 10px;
  border: 0;
  border-radius: 10px;
  padding: 0.76rem;
  color: #fff;
  background: var(--ink);
  cursor: pointer;
}

.micro-feedback {
  display: none;
  margin-top: 10px !important;
  padding: 10px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.micro-feedback.visible {
  display: block;
}

.micro-feedback.correct {
  color: #17665e;
  background: rgba(34, 123, 115, 0.12);
}

.micro-feedback.incorrect {
  color: #8d4718;
  background: rgba(222, 130, 63, 0.14);
}

.neighbor-button {
  width: 100%;
  text-align: left;
  padding: 0.88rem 0.96rem;
  border-radius: var(--radius-md);
}

.neighbor-button strong,
.chunk-card h4,
.quiz-card h4 {
  display: block;
  margin-bottom: 4px;
}

.neighbor-button small,
.chunk-card p,
.quiz-card p {
  color: var(--ink-soft);
}

.chunk-card,
.quiz-card {
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(20, 61, 86, 0.08);
}

.chunk-card h4,
.quiz-card h4 {
  margin: 0 0 6px;
  font-size: 0.98rem;
}

.chunk-card p,
.quiz-card p {
  margin: 0;
  line-height: 1.55;
}

.empty-card {
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(20, 61, 86, 0.05);
  color: var(--ink-soft);
}

.graph-edge {
  stroke: rgba(20, 61, 86, 0.18);
  stroke-width: 1.4px;
  transition: opacity 160ms ease, stroke-width 160ms ease, stroke 160ms ease;
}

.graph-edge.dimmed {
  opacity: 0.12;
}

.graph-edge.active {
  opacity: 1;
  stroke: rgba(20, 61, 86, 0.62);
  stroke-width: 2.6px;
}

.graph-edge.prerequisite-edge {
  stroke: rgba(222, 130, 63, 0.72);
  stroke-width: 2.2px;
}

.graph-edge.prerequisite-edge.strength-suggested {
  stroke: rgba(222, 130, 63, 0.48);
  stroke-dasharray: 7 6;
}

#learning-arrow path {
  fill: #de823f;
}

.graph-node {
  cursor: pointer;
  transition: opacity 160ms ease;
}

.graph-node.dimmed {
  opacity: 0.2;
}

.graph-node-shape {
  stroke-width: 2px;
}

.graph-node.active .graph-node-shape {
  stroke-width: 3px;
  filter: drop-shadow(0 8px 18px rgba(20, 61, 86, 0.22));
}

.graph-node.state-exposed .graph-node-shape {
  stroke-dasharray: 5 4;
}

.graph-node.state-developing .graph-node-shape {
  stroke: #17665e;
  stroke-width: 3px;
}

.graph-node.state-misconception .graph-node-shape {
  stroke: #de823f;
  stroke-width: 3px;
  filter: drop-shadow(0 5px 10px rgba(222, 130, 63, 0.24));
}

.graph-node-label {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}

.graph-node-subline {
  fill: rgba(20, 61, 86, 0.58);
  font-size: 10px;
}

@media (max-width: 1120px) {
  .learning-console,
  .graph-layout {
    grid-template-columns: 1fr;
  }

  .progress-main {
    grid-template-columns: auto minmax(8rem, 1fr);
  }

  .progress-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 860px) {
  .graph-topbar {
    grid-template-columns: 1fr;
  }

  .topbar-main {
    flex-direction: column;
  }

  .progress-main {
    grid-template-columns: 1fr;
  }

  .progress-actions {
    grid-column: auto;
  }

  .stage-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .stage-note {
    text-align: left;
  }

  .drawer-toggle {
    display: inline-flex;
  }

  .detail-panel.collapsed .detail-body {
    display: none;
  }

  #graph-svg,
  .graph-canvas-shell {
    min-height: 54vh;
    height: 54vh;
  }
}
