:root {
  --paper: #f5f1e8;
  --paper-deep: #ebe4d7;
  --card: #fffdf8;
  --ink: #17221b;
  --muted: #657069;
  --line: #d9d3c7;
  --green: #1e6b4d;
  --green-dark: #164e3a;
  --green-soft: #dcecdf;
  --amber: #c88a32;
  --amber-soft: #f3e4c6;
  --red: #a64b3c;
  --shadow: 0 18px 50px rgba(39, 45, 34, 0.09);
  --radius-lg: 22px;
  --radius-md: 14px;
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  --serif: "Source Han Serif SC", "Songti SC", "SimSun", serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  background:
    radial-gradient(circle at 10% 0%, rgba(255, 255, 255, 0.9), transparent 30%),
    linear-gradient(180deg, var(--paper), #f8f6f1 50%, var(--paper));
  min-height: 100vh;
}

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

button {
  color: inherit;
}

.page-shell {
  width: min(1480px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 30px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 4px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  color: #fff;
  font-family: Georgia, serif;
  font-size: 19px;
  letter-spacing: 0.05em;
  background: var(--green-dark);
  border-radius: 50%;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
  letter-spacing: 0.02em;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.student-id {
  padding: 7px 11px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid var(--line);
  border-radius: 999px;
  letter-spacing: 0.06em;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  padding: 6px;
  background: rgba(255, 253, 248, 0.66);
  border: 1px solid rgba(217, 211, 199, 0.9);
  border-radius: 16px;
  backdrop-filter: blur(10px);
}

.tab {
  flex: 1;
  padding: 13px 18px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 11px;
  cursor: pointer;
  transition: 160ms ease;
}

.tab span {
  margin-right: 9px;
  color: var(--amber);
  font-family: Georgia, serif;
  font-size: 12px;
}

.tab:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.76);
}

.tab.is-active {
  color: #fff;
  background: var(--green-dark);
  box-shadow: 0 8px 22px rgba(22, 78, 58, 0.2);
}

.panel {
  display: none;
  animation: rise 320ms ease both;
}

.panel.is-active {
  display: block;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin: 34px 8px 24px;
}

.section-heading h1 {
  max-width: 880px;
  margin: 5px 0 10px;
  font-family: var(--serif);
  font-size: clamp(30px, 4vw, 50px);
  font-weight: 600;
  line-height: 1.14;
  letter-spacing: -0.035em;
}

.section-heading p:not(.eyebrow) {
  max-width: 820px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.85;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-family: Georgia, serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.control-card,
.canvas-card,
.info-card,
.traversal-card,
.about-card,
.checklist-card {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.control-card {
  position: sticky;
  top: 18px;
  padding: 24px;
  border-radius: var(--radius-lg);
}

.card-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 23px;
}

.card-heading.compact {
  align-items: center;
  justify-content: space-between;
  margin: 0 0 16px;
}

.card-heading h2,
.traversal-head h2,
.about-card h2,
.checklist-card h2 {
  margin: 2px 0 0;
  font-size: 18px;
  line-height: 1.3;
}

.card-heading p:not(.eyebrow) {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.step-number {
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  height: 32px;
  color: #fff;
  font-family: Georgia, serif;
  background: var(--green);
  border-radius: 50%;
}

.field {
  display: block;
  margin-bottom: 18px;
}

.field > span {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field textarea {
  width: 100%;
  padding: 12px 13px;
  color: var(--ink);
  background: #fbfaf6;
  border: 1px solid #cfc8bb;
  border-radius: 10px;
  outline: none;
  resize: vertical;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.field input {
  height: 44px;
}

.field textarea {
  min-height: 158px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(30, 107, 77, 0.12);
}

.field small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 6px 0 20px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.switch-row strong,
.switch-row small {
  display: block;
}

.switch-row strong {
  font-size: 13px;
}

.switch-row small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-row i {
  position: relative;
  flex: 0 0 44px;
  width: 44px;
  height: 24px;
  background: #c9c7bf;
  border-radius: 999px;
  transition: 160ms ease;
}

.switch-row i::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  content: "";
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: 160ms ease;
}

.switch-row input:checked + i {
  background: var(--green);
}

.switch-row input:checked + i::after {
  transform: translateX(20px);
}

.button {
  min-height: 40px;
  padding: 9px 15px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 9px;
  cursor: pointer;
  transition:
    background 150ms ease,
    transform 150ms ease,
    opacity 150ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.button-primary {
  width: 100%;
  color: #fff;
  background: var(--green);
  border: 1px solid var(--green);
}

.button-primary:hover:not(:disabled) {
  background: var(--green-dark);
}

.button-ghost {
  flex: 0 0 auto;
  color: var(--green-dark);
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid #b8c9bd;
}

.button-dark {
  color: #fff;
  background: var(--green-dark);
  border: 1px solid var(--green-dark);
}

.button-outline {
  color: var(--green-dark);
  background: transparent;
  border: 1px solid #8daf99;
}

.button-text {
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
}

.message {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--red);
  font-size: 11px;
  line-height: 1.55;
}

.results {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.canvas-card {
  min-width: 0;
  padding: 22px 24px 18px;
  border-radius: var(--radius-lg);
}

.pill {
  padding: 6px 10px;
  color: var(--green-dark);
  font-size: 10px;
  font-weight: 700;
  background: var(--green-soft);
  border-radius: 999px;
}

.graph-stage,
.tree-stage {
  position: relative;
  min-height: 430px;
  overflow: hidden;
  background-color: #fbfaf6;
  background-image: radial-gradient(#cbc7bc 0.75px, transparent 0.75px);
  background-size: 18px 18px;
  border: 1px solid #e1ddd3;
  border-radius: 16px;
}

.graph-stage svg,
.tree-stage svg {
  display: block;
  width: 100%;
  height: 440px;
}

.edge-line {
  stroke: #a6aca7;
  stroke-width: 2;
  transition: 180ms ease;
}

.edge-line.is-visited {
  stroke: var(--amber);
  stroke-width: 4;
}

.edge-weight {
  fill: var(--muted);
  font-family: Georgia, serif;
  font-size: 12px;
  paint-order: stroke;
  stroke: #fbfaf6;
  stroke-width: 5px;
}

.graph-node,
.tree-node {
  cursor: default;
  transition: 220ms ease;
}

.graph-node circle,
.tree-node circle {
  fill: #fffdf8;
  stroke: var(--green);
  stroke-width: 2.5;
}

.graph-node text,
.tree-node text {
  fill: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
}

.graph-node.is-visited circle,
.tree-node.is-visited circle {
  fill: var(--amber-soft);
  stroke: var(--amber);
}

.graph-node.is-active circle,
.tree-node.is-active circle {
  fill: var(--green);
  stroke: var(--green-dark);
  stroke-width: 5px;
}

.graph-node.is-active text,
.tree-node.is-active text {
  fill: #fff;
}

.tree-edge {
  stroke: #a6aca7;
  stroke-width: 2;
  transition: 180ms ease;
}

.tree-edge.is-visited {
  stroke: var(--amber);
  stroke-width: 4;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 18px;
}

.info-card {
  min-width: 0;
  padding: 20px;
  border-radius: var(--radius-md);
}

.matrix-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  text-align: center;
}

.matrix-table th,
.matrix-table td {
  min-width: 31px;
  padding: 7px 6px;
  border: 1px solid #e2ddd2;
}

.matrix-table th {
  color: var(--green-dark);
  font-weight: 700;
  background: #edf4ee;
}

.matrix-table th:first-child {
  color: var(--muted);
  background: #f6f3eb;
}

.matrix-table td.has-edge {
  color: #fff;
  font-weight: 700;
  background: var(--green);
}

.adjacency-list {
  display: grid;
  gap: 7px;
  max-height: 220px;
  overflow: auto;
}

.adjacency-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  background: #faf8f2;
  border: 1px solid #e4dfd5;
  border-radius: 8px;
  font-size: 11px;
}

.adjacency-row strong {
  flex: 0 0 24px;
  color: var(--green-dark);
}

.adjacency-row span {
  color: var(--muted);
}

.traversal-card {
  padding: 22px;
  border-radius: var(--radius-lg);
}

.traversal-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.traversal-actions,
.tree-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 7px;
}

.traversal-actions label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}

.traversal-actions select {
  height: 40px;
  padding: 0 28px 0 10px;
  background: #fff;
  border: 1px solid #cfc8bb;
  border-radius: 8px;
}

.traversal-body {
  padding-top: 18px;
}

.sequence-label {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 34px;
}

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

.sequence-label strong {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.step-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 44px;
  margin: 14px 0;
}

.step-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 54px;
  padding: 8px 9px;
  color: var(--muted);
  font-size: 10px;
  background: #f4f1e9;
  border: 1px solid #dfdace;
  border-radius: 8px;
  opacity: 0.38;
}

.step-chip b {
  color: var(--green-dark);
  font-family: Georgia, serif;
  font-size: 13px;
}

.step-chip.is-visible {
  opacity: 1;
}

.step-chip.is-current {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.step-chip.is-current b {
  color: #fff;
}

.explanation {
  margin: 0;
  padding-top: 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
  border-top: 1px dashed #ddd7ca;
}

.rule-note {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.rule-note strong {
  font-size: 12px;
}

.rule-note p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.75;
}

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

.about-card {
  position: relative;
  min-height: 230px;
  padding: 28px;
  overflow: hidden;
  border-radius: var(--radius-lg);
}

.about-index {
  color: var(--amber);
  font-family: Georgia, serif;
  font-size: 12px;
}

.about-card h2 {
  margin: 28px 0 12px;
  font-family: var(--serif);
  font-size: 25px;
}

.about-card p {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.9;
}

.about-card code {
  display: inline-block;
  padding: 7px 10px;
  color: var(--green-dark);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 10px;
  background: var(--green-soft);
  border-radius: 6px;
}

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

.checklist-card h2 {
  margin: 0 0 15px;
}

.checklist-card ul {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 32px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.checklist-card li {
  position: relative;
  padding-left: 24px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.75;
}

.checklist-card li::before {
  position: absolute;
  top: 0.4em;
  left: 0;
  display: grid;
  place-items: center;
  width: 15px;
  height: 15px;
  color: #fff;
  font-size: 9px;
  content: "✓";
  background: var(--green);
  border-radius: 50%;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 32px;
  padding: 20px 4px 0;
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 9px;
  letter-spacing: 0.12em;
  border-top: 1px solid var(--line);
}

@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: 290px minmax(0, 1fr);
  }

  .two-column {
    grid-template-columns: 1fr;
  }

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

  .traversal-actions,
  .tree-buttons {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100% - 24px, 1480px);
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand small {
    display: none;
  }

  .identity {
    align-items: flex-end;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    margin-top: 24px;
  }

  .section-heading h1 {
    font-size: 32px;
  }

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

  .control-card {
    position: static;
  }

  .graph-stage,
  .tree-stage {
    min-height: 320px;
  }

  .graph-stage svg,
  .tree-stage svg {
    height: 330px;
  }

  .about-grid,
  .checklist-card ul {
    grid-template-columns: 1fr;
  }

  .about-card {
    min-height: auto;
  }

  .traversal-actions .button,
  .tree-buttons .button {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
