:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d6dde8;
  --primary: #1e40af;
  --reset: #374151;
  --nav: #475569;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top, #e8f0ff, var(--bg) 38%);
}

.layout {
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 26px rgba(30, 41, 59, 0.08);
}

.controls { padding: 16px; }
.visual { min-height: 860px; overflow: auto; }

h1 { margin: 0; font-size: 1.26rem; }
h2 { margin: 14px 0 8px; font-size: 0.95rem; }
h3 { margin: 0; font-size: 0.95rem; }

.muted {
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

label {
  display: block;
  font-size: 0.86rem;
  margin-bottom: 6px;
  font-weight: 600;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.92rem;
  margin-bottom: 8px;
}

.actions, .step-nav {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.actions.one-col { grid-template-columns: 1fr; }
.actions.two-col, .step-nav { grid-template-columns: 1fr 1fr; }

.btn {
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 600;
  padding: 8px 10px;
  cursor: pointer;
}

.btn-primary { background: var(--primary); }
.btn-reset { background: var(--reset); }
.btn-nav { background: var(--nav); }

.status {
  margin-top: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.86rem;
  background: #f9fbff;
}

.pseudocode {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafc;
  padding: 8px;
  min-height: 190px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.8rem;
}

.code-line {
  padding: 6px 7px;
  border-radius: 6px;
}

.code-line.active {
  background: #ffefad;
  border: 1px solid #f6cf5f;
}

#treeSvg {
  width: 100%;
  min-height: 600px;
  display: block;
}

.tree-head {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.node rect {
  fill: #b3e5fc;
  stroke: #455a64;
  stroke-width: 1.2;
  rx: 3;
  ry: 3;
}

.node.leaf rect {
  fill: #b9f6ca;
}

.node.highlight rect {
  fill: #fff59d;
  stroke: #ef6c00;
  stroke-width: 1.8;
  stroke-dasharray: none;
}

.node text {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  fill: #1f2937;
}

.link {
  fill: none;
  stroke: #607d8b;
  stroke-width: 1.2;
}

.leaf-link {
  fill: none;
  stroke: #94a3b8;
  stroke-width: 1.2;
  stroke-dasharray: 6 5;
  marker-end: url(#leafArrow);
}

.key-cell {
  fill: #ffffff;
  stroke: #78909c;
  stroke-width: 0.8;
}

.key-cell.highlighted {
  fill: #ffcdd2;
  stroke: #d32f2f;
  stroke-width: 1.2;
}

.records-wrap {
  border-top: 1px solid var(--line);
  padding: 12px 14px 16px;
}

.records-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.name-index-head {
  margin-top: 14px;
}

.table-tabs {
  display: flex;
  gap: 6px;
}

.tab-btn {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: #334155;
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  background: #1e40af;
  color: #fff;
  border-color: #1e40af;
}

.records-table-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: auto;
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.records-table th,
.records-table td {
  border-bottom: 1px solid #edf2f7;
  padding: 9px 10px;
  text-align: left;
}

.records-table thead th {
  background: #f8fafc;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}

.records-empty {
  color: #64748b;
  font-style: italic;
}

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