:root {
  --ink: #18211d;
  --ink-soft: #455049;
  --paper: #f4f0e6;
  --paper-deep: #e9e1d0;
  --white: #fffdf7;
  --teal: #176b63;
  --teal-light: #cbe1da;
  --rust: #c76538;
  --rust-light: #f2d4c3;
  --gold: #d6a638;
  --gold-light: #f0e2af;
  --blue: #315c72;
  --blue-light: #d5e3e9;
  --line: #c9c0ae;
  --muted: #786f62;
  --focus: #9a3f22;
  --display: Georgia, Cambria, "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", STSong, serif;
  --ui: "Trebuchet MS", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(rgba(24, 33, 29, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 33, 29, .025) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
  font-family: var(--display);
}

button,
input,
select {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(199, 101, 56, .45);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 100;
  padding: .7rem 1rem;
  color: var(--white);
  background: var(--ink);
}

.skip-link:focus {
  top: 1rem;
}

.masthead {
  display: grid;
  grid-template-columns: minmax(330px, 1.25fr) minmax(300px, .75fr) auto;
  align-items: end;
  min-height: 170px;
  padding: 26px 32px 18px;
  border-bottom: 1px solid var(--ink);
  background:
    radial-gradient(circle at 82% 8%, rgba(214, 166, 56, .18), transparent 28%),
    rgba(244, 240, 230, .94);
}

.title-block {
  position: relative;
}

.title-block::before {
  position: absolute;
  left: -32px;
  top: 27px;
  width: 15px;
  height: 74px;
  content: "";
  background: var(--rust);
}

.kicker {
  display: block;
  margin-bottom: 8px;
  color: var(--teal);
  font: 700 11px/1.2 var(--ui);
  letter-spacing: .16em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(34px, 4vw, 58px);
  font-weight: 500;
  line-height: .92;
  letter-spacing: -.045em;
}

h1 span {
  color: var(--rust);
  font-size: .46em;
  letter-spacing: .025em;
}

.course-note {
  max-width: 490px;
  padding: 0 28px 5px;
  border-left: 1px solid var(--line);
}

.course-note p {
  margin-bottom: 14px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.65;
}

.metric-strip {
  display: flex;
  gap: 18px;
  color: var(--muted);
  font: 11px/1.2 var(--ui);
  letter-spacing: .05em;
}

.metric-strip strong {
  color: var(--ink);
  font-size: 18px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 248px;
  border: 1px solid var(--ink);
}

.mode {
  min-height: 39px;
  padding: 8px 11px;
  border: 0;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  background: transparent;
  font: 700 12px/1 var(--ui);
}

.mode:nth-child(2n) {
  border-right: 0;
}

.mode:nth-child(n+3) {
  border-bottom: 0;
}

.mode:hover,
.mode.active {
  color: var(--white);
  background: var(--ink);
}

.atlas-entry {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 8px 11px;
  color: var(--white);
  background: var(--teal);
  font: 700 12px/1 var(--ui);
  text-decoration: none;
}

.atlas-entry:hover {
  color: var(--ink);
  background: var(--gold);
}

.workspace {
  display: grid;
  grid-template-columns: 292px minmax(500px, 1fr) 360px;
  height: min(760px, calc(100vh - 170px));
  min-height: 590px;
  border-bottom: 1px solid var(--ink);
}

.control-rail,
.detail-panel {
  min-width: 0;
  overflow: auto;
  background: rgba(255, 253, 247, .78);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.control-rail {
  border-right: 1px solid var(--ink);
}

.control-section {
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
}

.control-section label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font: 700 10px/1.2 var(--ui);
  letter-spacing: .07em;
  text-transform: uppercase;
}

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 13px;
  color: var(--teal);
  font: 700 10px/1 var(--ui);
  letter-spacing: .15em;
}

.search-wrap {
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 10px;
  top: 10px;
  width: 17px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.7;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--white);
  font: 13px/1.2 var(--ui);
}

.search-wrap input {
  padding-left: 36px;
  border-color: var(--ink);
}

select {
  margin-bottom: 12px;
}

.split-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.text-button {
  padding: 0;
  border: 0;
  color: var(--rust);
  background: transparent;
  font: 700 10px/1 var(--ui);
}

.search-results {
  display: grid;
  gap: 3px;
  max-height: 166px;
  margin-top: 7px;
  overflow: auto;
}

.search-hit {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 7px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-left: 2px solid var(--rust);
  text-align: left;
  background: rgba(233, 225, 208, .66);
}

.search-hit small {
  color: var(--teal);
  font: 700 9px/1.3 var(--ui);
}

.search-hit span {
  font-size: 12px;
  line-height: 1.25;
}

.chain-section {
  display: grid;
  gap: 6px;
}

.chain-section .section-label {
  margin-bottom: 5px;
}

.chain-button {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  min-height: 38px;
  padding: 0;
  border: 1px solid transparent;
  text-align: left;
  background: transparent;
}

.chain-button b {
  display: grid;
  place-items: center;
  align-self: stretch;
  color: var(--white);
  background: var(--teal);
  font: 700 10px/1 var(--ui);
}

.chain-button span {
  padding: 8px 9px;
  font-size: 12px;
  line-height: 1.25;
}

.chain-button:hover,
.chain-button.active {
  border-color: var(--teal);
  background: var(--teal-light);
}

.chain-button.proof-chain b {
  background: var(--gold);
}

.chain-button.application-chain b {
  background: var(--rust);
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 6px;
  font: 10px/1.2 var(--ui);
}

.legend-grid span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.legend-shape {
  display: inline-block;
  width: 19px;
  height: 14px;
  border: 2px solid var(--ink);
  background: var(--white);
}

.legend-shape.theorem {
  border-radius: 7px;
  background: var(--teal-light);
}

.legend-shape.concept {
  border-radius: 50%;
  background: var(--gold-light);
}

.legend-shape.space {
  clip-path: polygon(15% 0, 85% 0, 100% 50%, 85% 100%, 15% 100%, 0 50%);
  background: var(--blue-light);
}

.legend-shape.counter {
  width: 14px;
  transform: rotate(45deg);
  background: var(--rust-light);
}

.legend-section p {
  margin: 12px 0 0;
  color: var(--muted);
  font: 10px/1.5 var(--ui);
}

.graph-stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent 49.8%, rgba(24, 33, 29, .035) 50%, transparent 50.2%),
    rgba(244, 240, 230, .52);
}

.graph-stage::after {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 0;
  width: 170px;
  height: 170px;
  content: "";
  border-left: 1px solid rgba(24, 33, 29, .12);
  border-top: 1px solid rgba(24, 33, 29, .12);
  transform: translate(70px, 70px) rotate(45deg);
  pointer-events: none;
}

.graph-toolbar {
  position: absolute;
  z-index: 4;
  left: 16px;
  top: 14px;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 38px;
  padding: 4px;
  border: 1px solid var(--ink);
  background: rgba(255, 253, 247, .94);
}

.graph-toolbar button {
  display: grid;
  width: 30px;
  height: 28px;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
}

.graph-toolbar button:hover {
  color: var(--white);
  background: var(--teal);
}

.graph-toolbar svg {
  width: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar-divider {
  width: 1px;
  height: 22px;
  margin: 0 3px;
  background: var(--line);
}

.canvas-status {
  min-width: 130px;
  padding: 0 8px;
  color: var(--muted);
  font: 10px/1.2 var(--ui);
}

.module-ruler {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  height: 8px;
  pointer-events: none;
}

.module-ruler i {
  flex: 1;
  background: var(--teal);
}

.module-ruler i:nth-child(2n) {
  background: var(--gold);
}

.module-ruler i:nth-child(3n) {
  background: var(--rust);
}

#graphSvg {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

#arrow path {
  fill: var(--ink-soft);
}

.graph-edge {
  fill: none;
  stroke: #7f887f;
  stroke-width: 1.35;
  opacity: .58;
  marker-end: url(#arrow);
}

.graph-edge.semantic {
  stroke-dasharray: 5 4;
  opacity: .42;
}

.graph-edge.chain-highlight {
  stroke: var(--rust);
  stroke-width: 3.6;
  stroke-dasharray: none;
  opacity: 1;
}

.graph-edge.neighbor-highlight {
  stroke: var(--teal);
  stroke-width: 2.8;
  opacity: 1;
}

.graph-node {
  cursor: grab;
  filter: url(#paperLift);
}

.graph-node:active {
  cursor: grabbing;
}

.graph-node .node-shape {
  fill: var(--white);
  stroke: var(--ink);
  stroke-width: 1.15;
  transition: stroke-width .15s, fill .15s;
}

.graph-node .node-accent {
  fill: var(--gold);
}

.graph-node.type-Theorem .node-shape,
.graph-node.type-Lemma .node-shape {
  fill: var(--teal-light);
}

.graph-node.type-Theorem .node-accent,
.graph-node.type-Lemma .node-accent {
  fill: var(--teal);
}

.graph-node.type-Space .node-shape {
  fill: var(--blue-light);
}

.graph-node.type-Space .node-accent {
  fill: var(--blue);
}

.graph-node.type-Counterexample .node-shape,
.graph-node.type-Misconception .node-shape {
  fill: var(--rust-light);
}

.graph-node.type-Counterexample .node-accent,
.graph-node.type-Misconception .node-accent {
  fill: var(--rust);
}

.graph-node.type-ProofTool .node-shape {
  fill: var(--gold-light);
}

.graph-node.type-Application .node-shape {
  fill: #e7d8cb;
}

.graph-node:hover .node-shape,
.graph-node.selected .node-shape,
.graph-node.chain-highlight .node-shape {
  stroke: var(--rust);
  stroke-width: 3;
}

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

.node-title {
  fill: var(--ink);
  font: 600 12px/1 var(--display);
  pointer-events: none;
}

.node-subtitle {
  fill: var(--muted);
  font: 9px/1 var(--ui);
  pointer-events: none;
}

.node-type-label {
  fill: var(--white);
  font: 700 8px/1 var(--ui);
  letter-spacing: .04em;
  pointer-events: none;
}

.node-difficulty {
  fill: var(--ink-soft);
  font: 700 8px/1 var(--ui);
  pointer-events: none;
}

.mobile-graph {
  display: none;
}

.empty-state {
  position: absolute;
  z-index: 5;
  inset: 0;
  place-content: center;
  text-align: center;
  background: rgba(244, 240, 230, .92);
}

.empty-state:not([hidden]) {
  display: grid;
}

.empty-state button {
  margin: 14px auto;
  padding: 9px 14px;
  border: 1px solid var(--ink);
  background: var(--white);
}

.detail-panel {
  border-left: 1px solid var(--ink);
}

.detail-empty {
  padding: 34px 28px;
}

.detail-index {
  color: var(--rust);
  font: 700 10px/1 var(--ui);
  letter-spacing: .14em;
}

.detail-empty h2 {
  margin: 52px 0 15px;
  font-size: 30px;
  font-weight: 500;
}

.detail-empty p {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.7;
}

.detail-prompt-lines {
  display: grid;
  gap: 14px;
  margin-top: 50px;
}

.detail-prompt-lines i {
  display: block;
  height: 1px;
  background: var(--line);
}

.detail-prompt-lines i:nth-child(2) {
  width: 82%;
}

.detail-prompt-lines i:nth-child(3) {
  width: 92%;
}

.detail-prompt-lines i:nth-child(4) {
  width: 64%;
}

#detailContent {
  padding: 0 0 30px;
}

.detail-head {
  position: sticky;
  z-index: 2;
  top: 0;
  padding: 22px 25px 19px;
  color: var(--white);
  background: var(--ink);
}

.detail-head .eyebrow {
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
  color: var(--gold-light);
  font: 700 9px/1 var(--ui);
  letter-spacing: .08em;
}

.detail-head h2 {
  margin-bottom: 5px;
  font-size: 27px;
  font-weight: 500;
  line-height: 1.12;
}

.detail-head .english-name {
  margin: 0;
  color: #d6d7d2;
  font-size: 13px;
  font-style: italic;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 15px;
}

.tag {
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, .35);
  color: var(--white);
  font: 700 9px/1 var(--ui);
}

.detail-section {
  padding: 19px 24px;
  border-bottom: 1px solid var(--line);
}

.detail-section h3 {
  margin-bottom: 10px;
  color: var(--teal);
  font: 700 10px/1.2 var(--ui);
  letter-spacing: .13em;
  text-transform: uppercase;
}

.detail-section p,
.detail-section li {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.68;
}

.detail-section p:last-child {
  margin-bottom: 0;
}

.intuition-callout {
  padding: 14px 15px;
  border-left: 4px solid var(--gold);
  color: var(--ink) !important;
  background: var(--gold-light);
  font-size: 14px !important;
}

.formula {
  display: block;
  overflow-wrap: anywhere;
  padding: 12px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--white);
  font: 13px/1.5 Cambria, Georgia, serif;
  white-space: pre-wrap;
}

.theorem-grid {
  display: grid;
  gap: 10px;
}

.theorem-grid div {
  padding-left: 10px;
  border-left: 2px solid var(--teal);
}

.theorem-grid b {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font: 700 10px/1.2 var(--ui);
}

.evidence-pair {
  display: grid;
  gap: 9px;
}

.evidence-pair p {
  padding: 11px;
  background: rgba(233, 225, 208, .58);
}

.evidence-pair p:last-child {
  border-left: 3px solid var(--rust);
  background: var(--rust-light);
}

.neighbor-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.node-chip {
  padding: 5px 7px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--white);
  font: 10px/1.25 var(--ui);
}

.node-chip:hover {
  border-color: var(--teal);
  background: var(--teal-light);
}

.teacher-only {
  border-left: 4px solid var(--rust);
}

body[data-mode="student"] .teacher-only {
  display: none;
}

.path-finder {
  display: grid;
  grid-template-columns: .72fr 1.05fr;
  gap: 22px 54px;
  padding: 42px 6vw 38px;
  color: var(--white);
  background:
    linear-gradient(115deg, rgba(214, 166, 56, .09), transparent 48%),
    var(--ink);
}

.path-finder h2 {
  max-width: 600px;
  margin-bottom: 0;
  font-size: clamp(25px, 3vw, 41px);
  font-weight: 500;
  line-height: 1.12;
}

.path-controls {
  display: grid;
  grid-template-columns: 1fr 22px 1fr auto;
  align-items: end;
  gap: 12px;
}

.path-controls label {
  color: #c9cec9;
  font: 10px/1.2 var(--ui);
  letter-spacing: .08em;
}

.path-controls select {
  margin: 7px 0 0;
  color: var(--ink);
}

.path-controls button {
  min-height: 38px;
  padding: 8px 15px;
  border: 1px solid var(--gold);
  color: var(--ink);
  background: var(--gold);
  font: 700 12px/1 var(--ui);
}

.path-arrow {
  padding-bottom: 11px;
  color: var(--gold);
  font-size: 22px;
}

.path-result {
  grid-column: 1 / -1;
  min-height: 68px;
  padding-top: 18px;
  border-top: 1px solid #58605b;
}

.path-result p {
  margin-bottom: 0;
  color: #c9cec9;
  font-size: 13px;
}

.path-steps {
  display: flex;
  align-items: stretch;
  gap: 0;
  overflow-x: auto;
  padding-bottom: 6px;
}

.path-node {
  min-width: 155px;
  padding: 11px 12px;
  color: var(--ink);
  background: var(--paper);
}

.path-node b {
  display: block;
  font-size: 13px;
}

.path-node small {
  color: var(--muted);
  font: 9px/1.2 var(--ui);
}

.path-relation {
  display: grid;
  min-width: 110px;
  place-items: center;
  padding: 7px;
  color: var(--gold-light);
  font: 9px/1.25 var(--ui);
  text-align: center;
}

footer {
  display: flex;
  justify-content: space-between;
  padding: 17px 32px;
  color: var(--muted);
  background: var(--paper-deep);
  font: 10px/1.3 var(--ui);
}

footer p {
  margin: 0;
}

@media (max-width: 1180px) {
  .masthead {
    grid-template-columns: 1fr auto;
  }

  .course-note {
    display: none;
  }

  .workspace {
    grid-template-columns: 260px minmax(420px, 1fr) 320px;
  }
}

@media (max-width: 900px) {
  .masthead {
    grid-template-columns: 1fr;
    gap: 18px;
    padding: 22px 20px;
  }

  .mode-switch {
    width: 100%;
  }

  .workspace {
    display: block;
    height: auto;
    min-height: 0;
    border-bottom: 0;
  }

  .control-rail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--ink);
  }

  .chain-section,
  .legend-section {
    display: none;
  }

  .graph-stage {
    min-height: 680px;
    overflow: visible;
    border-bottom: 1px solid var(--ink);
  }

  .graph-stage::after {
    display: none;
  }

  #graphSvg,
  .module-ruler,
  .graph-toolbar {
    display: none;
  }

  .mobile-graph {
    display: grid;
    gap: 0;
    padding: 0;
  }

  .mobile-module {
    border-bottom: 1px solid var(--ink);
  }

  .mobile-module h2 {
    position: sticky;
    z-index: 2;
    top: 0;
    margin: 0;
    padding: 12px 18px;
    color: var(--white);
    background: var(--ink);
    font: 700 11px/1.2 var(--ui);
    letter-spacing: .07em;
  }

  .mobile-node {
    display: grid;
    grid-template-columns: 44px 1fr;
    width: 100%;
    min-height: 88px;
    padding: 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    text-align: left;
    background: rgba(255, 253, 247, .84);
  }

  .mobile-node .mobile-index {
    display: grid;
    place-items: center;
    align-self: stretch;
    color: var(--white);
    background: var(--teal);
    font: 700 9px/1 var(--ui);
  }

  .mobile-node.type-Counterexample .mobile-index,
  .mobile-node.type-Misconception .mobile-index {
    background: var(--rust);
  }

  .mobile-node.type-Space .mobile-index {
    background: var(--blue);
  }

  .mobile-node.type-ProofTool .mobile-index {
    color: var(--ink);
    background: var(--gold);
  }

  .mobile-copy {
    padding: 13px 15px;
  }

  .mobile-copy strong {
    display: block;
    margin-bottom: 3px;
    font-size: 15px;
  }

  .mobile-copy em {
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
  }

  .mobile-copy p {
    margin: 8px 0 0;
    color: var(--ink-soft);
    font: 11px/1.45 var(--ui);
  }

  .mobile-copy small {
    display: block;
    margin-top: 7px;
    color: var(--teal);
    font: 9px/1.35 var(--ui);
  }

  .detail-panel {
    max-height: none;
    border-left: 0;
    border-bottom: 1px solid var(--ink);
  }

  .detail-empty {
    display: none;
  }

  .path-finder {
    grid-template-columns: 1fr;
    padding: 34px 20px;
  }

  .path-controls {
    grid-template-columns: 1fr;
  }

  .path-arrow {
    display: none;
  }

  .path-result {
    grid-column: auto;
  }
}

@media (max-width: 560px) {
  .masthead {
    min-height: 0;
  }

  h1 {
    font-size: 39px;
  }

  .metric-strip {
    flex-wrap: wrap;
  }

  .control-rail {
    grid-template-columns: 1fr;
  }

  .control-section:nth-child(2) {
    padding-bottom: 7px;
  }

  .graph-stage {
    min-height: 520px;
  }

  .path-steps {
    display: grid;
    gap: 3px;
  }

  .path-relation {
    min-width: 0;
    min-height: 30px;
  }

  footer {
    display: grid;
    gap: 7px;
    padding: 17px 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
