:root {
  --paper: #f7f8f3;
  --panel: #ffffff;
  --ink: #17211f;
  --muted: #66736d;
  --line: #d7ded8;
  --soft-line: #ecf0ed;
  --teal: #0f8b7a;
  --teal-soft: #dff3ef;
  --red: #df4a3f;
  --red-soft: #ffe3dd;
  --blue: #2f68c8;
  --blue-soft: #e3ecff;
  --amber: #c48a1b;
  --amber-soft: #fff0ca;
  --violet: #6c5aa8;
  --shadow: 0 18px 45px rgba(28, 42, 38, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 33, 31, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 33, 31, 0.045) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
  backdrop-filter: blur(18px);
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--amber-soft);
  box-shadow: 5px 5px 0 var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1;
}

h3 {
  font-size: 16px;
}

.algorithm-list {
  display: grid;
  gap: 10px;
}

.algorithm-tab {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  border-radius: var(--radius);
  padding: 14px;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.algorithm-tab:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(28, 42, 38, 0.08);
}

.algorithm-tab.active {
  border-color: var(--ink);
  background: var(--teal-soft);
  box-shadow: 4px 4px 0 var(--ink);
}

.algorithm-tab strong {
  display: block;
  font-size: 16px;
  margin-bottom: 5px;
}

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

.requirement-card {
  margin-top: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
}

.requirement-card ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.75;
  font-size: 14px;
}

.workspace {
  padding: 30px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
}

.status-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

.status-strip span,
.pill,
#logCount {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  padding: 5px 11px;
  color: var(--muted);
  font-size: 13px;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1.15fr) minmax(260px, 0.9fr) minmax(260px, 0.9fr);
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.input-panel,
.theory-panel,
.controls-panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.input-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 86px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--ink);
  background: #fbfcfa;
  outline: none;
}

textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 139, 122, 0.13);
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.error-text {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--red);
  font-weight: 700;
  font-size: 13px;
}

.case-row,
.action-row,
.transport {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.case-row {
  margin-top: 12px;
}

.primary-button,
.ghost-button,
.plain-button,
.icon-button {
  border-radius: var(--radius);
  border: 1px solid var(--ink);
  min-height: 38px;
  padding: 8px 12px;
  color: var(--ink);
  background: var(--panel);
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.primary-button {
  background: var(--ink);
  color: #fff;
  min-width: 106px;
}

.ghost-button {
  border-color: var(--line);
  background: var(--teal-soft);
}

.plain-button {
  border-color: var(--line);
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 28px;
  line-height: 1;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(28, 42, 38, 0.12);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.switch input {
  accent-color: var(--teal);
}

#algorithmSummary {
  min-height: 68px;
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.65;
}

.complexity-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.complexity-list div {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  background: #fbfcfa;
}

.complexity-list dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.complexity-list dd {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
}

.controls-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.speed-control {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.visual-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
  gap: 14px;
  min-height: 470px;
}

.visual-panel,
.step-panel {
  padding: 16px;
}

.visual-stage {
  position: relative;
  min-height: 390px;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  overflow: hidden;
  background:
    radial-gradient(circle at 20px 20px, rgba(15, 139, 122, 0.08) 2px, transparent 3px),
    #fbfcfa;
  background-size: 28px 28px;
}

.bar-stage {
  height: 390px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
  padding: 22px;
}

.bars {
  display: flex;
  align-items: end;
  gap: 10px;
  min-height: 285px;
}

.bar-wrap {
  flex: 1;
  min-width: 18px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  align-items: end;
}

.bar {
  display: flex;
  align-items: start;
  justify-content: center;
  width: 100%;
  min-height: 18px;
  border: 1px solid rgba(23, 33, 31, 0.2);
  border-radius: 6px 6px 2px 2px;
  background: var(--blue-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  padding-top: 6px;
  transition: height 220ms ease, background 220ms ease, transform 220ms ease;
}

.bar.compare {
  background: var(--amber-soft);
  transform: translateY(-8px);
}

.bar.pivot {
  background: var(--red-soft);
  outline: 2px solid var(--red);
}

.bar.swap {
  background: var(--teal-soft);
  outline: 2px solid var(--teal);
}

.bar.sorted {
  background: #d9f1d0;
}

.bar-label {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.explain-box {
  border-left: 4px solid var(--teal);
  background: var(--teal-soft);
  border-radius: var(--radius);
  padding: 12px;
  line-height: 1.55;
  color: #123b35;
}

.graph-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
  padding: 14px;
  height: 390px;
}

.graph-canvas {
  width: 100%;
  height: 100%;
  min-height: 330px;
}

.edge {
  stroke: #8d9893;
  stroke-width: 3;
}

.edge.active {
  stroke: var(--amber);
  stroke-width: 5;
}

.edge.path {
  stroke: var(--teal);
  stroke-width: 5;
}

.edge-label {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 5;
}

.node-circle {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 2;
}

.node-circle.current {
  fill: var(--amber-soft);
  stroke: var(--amber);
  stroke-width: 4;
}

.node-circle.done {
  fill: var(--teal-soft);
  stroke: var(--teal);
}

.node-circle.path {
  fill: #d9f1d0;
  stroke: var(--teal);
  stroke-width: 4;
}

.node-text {
  fill: var(--ink);
  font-size: 16px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
}

.table-box {
  overflow: auto;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--soft-line);
  padding: 8px;
  text-align: left;
}

th {
  background: #f1f5f2;
  color: var(--muted);
}

.maze-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 14px;
  padding: 18px;
  align-items: center;
  min-height: 390px;
}

.maze-grid {
  width: min(100%, 430px);
  aspect-ratio: 1;
  display: grid;
  gap: 4px;
  margin: 0 auto;
}

.cell {
  border: 1px solid rgba(23, 33, 31, 0.08);
  border-radius: 4px;
  background: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
}

.cell.wall {
  background: var(--ink);
}

.cell.start {
  background: var(--blue-soft);
  color: var(--blue);
}

.cell.end {
  background: var(--red-soft);
  color: var(--red);
}

.cell.visited {
  background: var(--amber-soft);
}

.cell.current {
  outline: 3px solid var(--amber);
  background: #fff7df;
}

.cell.path {
  background: var(--teal-soft);
  outline: 2px solid var(--teal);
}

.legend {
  display: grid;
  gap: 9px;
  align-content: start;
  font-size: 13px;
  color: var(--muted);
}

.legend-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: center;
}

.swatch {
  width: 18px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.swatch.wall {
  background: var(--ink);
}

.swatch.visited {
  background: var(--amber-soft);
}

.swatch.path {
  background: var(--teal-soft);
}

.swatch.current {
  background: #fff7df;
  border-color: var(--amber);
}

.step-list {
  height: 390px;
  overflow: auto;
  margin: 0;
  padding: 0 4px 0 26px;
}

.step-list li {
  margin: 0 0 9px;
  padding: 10px 10px 10px 4px;
  border-bottom: 1px solid var(--soft-line);
  color: var(--muted);
  line-height: 1.45;
}

.step-list li.active {
  color: var(--ink);
  font-weight: 800;
}

.step-list li.active::marker {
  color: var(--teal);
}

.empty-state {
  min-height: 390px;
  display: grid;
  place-items: center;
  padding: 30px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .algorithm-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .requirement-card {
    margin-top: 0;
  }

  .control-grid,
  .visual-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

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

  .status-strip {
    justify-content: start;
  }

  .algorithm-list {
    grid-template-columns: 1fr;
  }

  .graph-stage,
  .maze-stage {
    grid-template-columns: 1fr;
    height: auto;
  }

  .visual-stage,
  .step-list {
    min-height: 340px;
  }
}
