:root {
  --ink: #17233a;
  --ink-soft: #4f5d70;
  --navy: #0f1d33;
  --navy-2: #172b48;
  --paper: #f4f1e9;
  --card: #fffdf8;
  --line: #d7d4cb;
  --line-dark: #9ea5ad;
  --orange: #e66a2c;
  --orange-soft: #fff0e5;
  --blue: #2976ad;
  --blue-soft: #eaf4fb;
  --green: #208264;
  --green-soft: #e7f5ef;
  --red: #b63f3f;
  --red-soft: #fbecec;
  --shadow: 0 16px 36px rgba(28, 38, 54, .09);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(41, 118, 173, .24);
  outline-offset: 2px;
}

.hero {
  position: relative;
  min-height: 310px;
  overflow: hidden;
  color: #fff;
  background: var(--navy);
  border-bottom: 6px solid var(--orange);
}

.hero::before {
  position: absolute;
  inset: 0;
  content: "";
  opacity: .12;
  background-image:
    linear-gradient(#fff 1px, transparent 1px),
    linear-gradient(90deg, #fff 1px, transparent 1px);
  background-size: 52px 52px;
}

.hero__inner {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  padding: 58px 0 52px;
}

.eyebrow,
.section-kicker {
  color: var(--orange);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .17em;
}

.eyebrow {
  display: flex;
  align-items: center;
  color: #f7a275;
}

.eyebrow span {
  width: 32px;
  height: 2px;
  margin-right: 10px;
  background: var(--orange);
}

.hero h1 {
  max-width: 820px;
  margin: 16px 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(54px, 7.2vw, 92px);
  font-weight: 600;
  line-height: .98;
  letter-spacing: -.055em;
}

.hero h1 i {
  color: var(--orange);
  font-weight: 400;
}

.hero p {
  max-width: 660px;
  margin: 18px 0 22px;
  color: #c6d0de;
  font-size: 17px;
  line-height: 1.8;
}

.hero__facts {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.hero__facts span {
  padding: 7px 11px;
  color: #dce3ec;
  border: 1px solid #3c4d65;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.hero__mark {
  position: absolute;
  right: max(2vw, calc((100vw - 1240px) / 2));
  bottom: -58px;
  color: rgba(255, 255, 255, .045);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 300px;
  font-weight: 700;
  line-height: 1;
  user-select: none;
}

.page-shell {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 80px;
}

.control-deck,
.visualizer-card,
.inspector-card,
.concept-card,
.comparison-section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.control-deck {
  position: relative;
  z-index: 2;
  margin-top: -70px;
  overflow: hidden;
}

.control-deck__top {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  min-height: 100px;
  border-bottom: 1px solid var(--line);
}

.tree-switch {
  display: flex;
  flex: 1;
}

.tree-switch__button {
  display: flex;
  min-width: 280px;
  align-items: center;
  gap: 15px;
  padding: 20px 28px;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
  cursor: pointer;
  text-align: left;
  transition: background .2s ease, box-shadow .2s ease;
}

.tree-switch__button:hover {
  background: #f8f6f0;
}

.tree-switch__button.is-active {
  color: #fff;
  background: var(--navy);
  box-shadow: inset 0 -4px 0 var(--orange);
}

.tree-switch__index {
  color: var(--orange);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
}

.tree-switch__button strong,
.tree-switch__button small {
  display: block;
}

.tree-switch__button strong {
  margin-bottom: 5px;
  font-size: 18px;
}

.tree-switch__button small {
  color: #778394;
  font-size: 12px;
}

.tree-switch__button.is-active small {
  color: #afbdce;
}

.degree-control {
  display: flex;
  min-width: 244px;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 18px 25px;
}

.degree-control > span,
.value-field > span,
.sequence-field > span,
.speed-control > span {
  color: #667283;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.degree-control b {
  color: var(--orange);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
}

select,
input {
  color: var(--ink);
  background: #fff;
  border: 1px solid #bec4ca;
  border-radius: 9px;
}

select {
  padding: 10px 34px 10px 11px;
  cursor: pointer;
}

input {
  padding: 11px 13px;
}

.operation-bar {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  padding: 22px 26px;
}

.value-field {
  display: flex;
  width: 160px;
  flex-direction: column;
  gap: 7px;
}

.value-field input {
  width: 100%;
  font-size: 20px;
  font-weight: 750;
}

.action-group {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(3, minmax(118px, 1fr));
  gap: 10px;
}

.action-button,
.text-button,
.icon-button,
.canvas-tools button {
  border: 0;
  cursor: pointer;
  transition: transform .16s ease, opacity .16s ease, background .16s ease;
}

.action-button:active,
.text-button:active,
.icon-button:active,
.canvas-tools button:active {
  transform: translateY(1px);
}

.action-button:disabled,
.text-button:disabled,
.icon-button:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.action-button {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 17px;
  color: #fff;
  border-radius: 9px;
  font-weight: 800;
}

.action-button svg,
.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.action-button--search {
  background: var(--blue);
}

.action-button--insert {
  background: var(--green);
}

.action-button--delete {
  background: var(--red);
}

.action-button:hover {
  filter: brightness(.93);
}

.history-actions {
  display: flex;
  gap: 7px;
}

.icon-button {
  display: grid;
  width: 46px;
  height: 48px;
  place-items: center;
  color: #4b5868;
  background: #eeece6;
  border-radius: 9px;
}

.icon-button:hover {
  background: #e1ded6;
}

.dataset-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 18px 26px;
  background: #f0eee7;
  border-top: 1px solid var(--line);
}

.sequence-field {
  display: flex;
  min-width: 250px;
  flex: 1;
  flex-direction: column;
  gap: 7px;
}

.sequence-field input {
  width: 100%;
  font-size: 13px;
}

.text-button {
  min-height: 42px;
  padding: 9px 16px;
  color: #354254;
  background: transparent;
  border: 1px solid #aeb5bd;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 750;
}

.text-button:hover {
  background: #fff;
}

.text-button--dark {
  color: #fff;
  background: var(--navy-2);
  border-color: var(--navy-2);
}

.text-button--dark:hover {
  background: var(--navy);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  margin-top: 22px;
}

.visualizer-card,
.inspector-card {
  overflow: hidden;
}

.panel-heading,
.inspector-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 23px 26px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2,
.inspector-card h2,
.concept-card h2,
.comparison-section h2 {
  margin: 5px 0 0;
  font-family: Georgia, "Noto Serif SC", "Songti SC", serif;
  line-height: 1.25;
}

.panel-heading h2,
.inspector-card h2 {
  font-size: 24px;
}

.metric-row {
  display: flex;
}

.metric-row > div {
  min-width: 65px;
  padding: 0 14px;
  text-align: center;
  border-left: 1px solid var(--line);
}

.metric-row strong,
.metric-row span {
  display: block;
}

.metric-row strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 600;
}

.metric-row span {
  color: #6f7a87;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
}

.canvas-stage {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  background-color: #fbfaf6;
  background-image: radial-gradient(#ccd0cd 1px, transparent 1px);
  background-size: 20px 20px;
}

#treeCanvas {
  display: block;
  width: 100%;
  height: 520px;
  user-select: none;
}

.tree-edge {
  fill: none;
  stroke: #a7afb8;
  stroke-width: 2;
}

.leaf-link {
  fill: none;
  stroke: var(--orange);
  stroke-dasharray: 7 5;
  stroke-width: 2;
}

.leaf-link-arrow {
  fill: var(--orange);
}

.tree-node {
  filter: drop-shadow(0 6px 7px rgba(20, 31, 48, .12));
}

.tree-node__body {
  fill: #fff;
  stroke: #667588;
  stroke-width: 2;
  transition: fill .2s ease, stroke .2s ease, stroke-width .2s ease;
}

.tree-node__divider {
  stroke: #d3d8dd;
  stroke-width: 1;
}

.tree-node__key {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 800;
  pointer-events: none;
  text-anchor: middle;
}

.tree-node__tag {
  fill: #798493;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
  text-anchor: middle;
}

.tree-node.is-leaf .tree-node__body {
  fill: #fffaf2;
  stroke: #ad855d;
}

.tree-node.is-active .tree-node__body {
  fill: var(--blue-soft);
  stroke: var(--blue);
  stroke-width: 4;
}

.tree-node.is-found .tree-node__body {
  fill: var(--green-soft);
  stroke: var(--green);
  stroke-width: 4;
}

.tree-node.is-changed .tree-node__body {
  fill: var(--orange-soft);
  stroke: var(--orange);
  stroke-width: 4;
}

.tree-node__key.is-key-active {
  fill: var(--orange);
  font-size: 17px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #77818d;
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

.empty-state__symbol {
  display: grid;
  width: 70px;
  height: 70px;
  margin-bottom: 13px;
  place-items: center;
  color: #9ca4ad;
  border: 2px dashed #c8cccf;
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 36px;
}

.empty-state strong {
  color: #4a5664;
  font-size: 18px;
}

.empty-state span {
  margin-top: 8px;
  font-size: 13px;
}

.canvas-tools {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 5px 14px rgba(20, 31, 48, .11);
}

.canvas-tools button {
  min-width: 38px;
  height: 35px;
  color: #455161;
  background: #fff;
  border-right: 1px solid var(--line);
  font-size: 16px;
  font-weight: 800;
}

.canvas-tools button:last-child {
  border-right: 0;
}

.canvas-tools #fitButton {
  padding: 0 10px;
  font-size: 11px;
}

.canvas-tools button:hover {
  background: #f0eee8;
}

.legend {
  display: flex;
  min-height: 49px;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  padding: 10px 26px;
  color: #657181;
  border-top: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
}

.legend__dot {
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border: 2px solid;
  border-radius: 50%;
}

.legend__dot--active {
  background: var(--blue-soft);
  border-color: var(--blue);
}

.legend__dot--found {
  background: var(--green-soft);
  border-color: var(--green);
}

.legend__dot--changed {
  background: var(--orange-soft);
  border-color: var(--orange);
}

.legend__line {
  width: 20px;
  margin-right: 6px;
  border-top: 2px dashed var(--orange);
}

.inspector-card {
  min-height: 646px;
}

.inspector-card__head {
  padding-right: 18px;
}

.speed-control {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 5px;
}

.speed-control select {
  padding: 6px 27px 6px 8px;
  font-size: 11px;
}

.status-banner {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 18px;
  padding: 13px;
  border: 1px solid #d2d8df;
  border-radius: 10px;
}

.status-banner--idle {
  color: #4b5a6b;
  background: #f1f4f7;
}

.status-banner--working {
  color: #245a80;
  background: var(--blue-soft);
  border-color: #b6d7eb;
}

.status-banner--success {
  color: #17664d;
  background: var(--green-soft);
  border-color: #addcc9;
}

.status-banner--warning {
  color: #8f552d;
  background: var(--orange-soft);
  border-color: #f0c3a8;
}

.status-banner--error {
  color: #963838;
  background: var(--red-soft);
  border-color: #e7b5b5;
}

.status-banner__icon {
  display: grid;
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  place-items: center;
  color: #fff;
  background: #687789;
  border-radius: 50%;
  font-family: Georgia, serif;
  font-weight: 700;
}

.status-banner--working .status-banner__icon {
  background: var(--blue);
}

.status-banner--success .status-banner__icon {
  background: var(--green);
}

.status-banner--warning .status-banner__icon {
  background: var(--orange);
}

.status-banner--error .status-banner__icon {
  background: var(--red);
}

.status-banner strong,
.status-banner small {
  display: block;
}

.status-banner strong {
  font-size: 13px;
}

.status-banner small {
  margin-top: 3px;
  color: inherit;
  font-size: 10px;
  line-height: 1.45;
  opacity: .8;
}

.trace-list {
  max-height: 390px;
  min-height: 280px;
  margin: 0;
  padding: 0 18px 12px;
  overflow-y: auto;
  list-style: none;
  counter-reset: trace;
}

.trace-list li {
  position: relative;
  margin-left: 13px;
  padding: 11px 10px 11px 30px;
  color: #657181;
  border-left: 1px solid #d2d6db;
  font-size: 12px;
  line-height: 1.55;
  counter-increment: trace;
}

.trace-list li::before {
  position: absolute;
  top: 11px;
  left: -11px;
  display: grid;
  width: 20px;
  height: 20px;
  content: counter(trace);
  place-items: center;
  color: #fff;
  background: #9aa4af;
  border: 2px solid var(--card);
  border-radius: 50%;
  font-size: 9px;
  font-weight: 800;
}

.trace-list li.is-current {
  color: var(--ink);
  background: #f3f6f8;
  border-left-color: var(--blue);
  font-weight: 750;
}

.trace-list li.is-current::before {
  background: var(--blue);
}

.trace-list li.is-done::before {
  background: var(--green);
}

.trace-list li.trace-list__placeholder {
  margin: 18px 0;
  padding: 35px 10px;
  color: #98a0a9;
  border: 1px dashed #ccd0d5;
  border-radius: 9px;
  text-align: center;
  counter-increment: none;
}

.trace-list li.trace-list__placeholder::before {
  display: none;
}

.invariant-box {
  margin: 5px 18px 18px;
  padding: 13px;
  background: #f8f7f3;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.invariant-box__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
}

.invariant-box__title strong {
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 9px;
  letter-spacing: .1em;
}

.invariant-box__title strong.is-valid {
  color: var(--green);
  background: var(--green-soft);
}

.invariant-box__title strong.is-invalid {
  color: var(--red);
  background: var(--red-soft);
}

.invariant-box p {
  margin: 8px 0 0;
  color: #747e89;
  font-size: 10px;
  line-height: 1.6;
}

.explanation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, .55fr);
  gap: 20px;
  margin-top: 22px;
}

.concept-card {
  padding: 28px;
}

.concept-card--primary {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, .8fr);
  gap: 25px 34px;
  overflow: hidden;
}

.concept-card__number {
  position: absolute;
  top: -18px;
  right: 12px;
  color: rgba(23, 35, 58, .055);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 150px;
  font-weight: 700;
  line-height: 1;
}

.concept-card h2,
.comparison-section h2 {
  font-size: 28px;
}

.concept-card p {
  position: relative;
  color: #657181;
  font-size: 13px;
  line-height: 1.8;
}

.rule-list {
  position: relative;
  display: grid;
  align-content: start;
  gap: 9px;
  margin-top: 9px;
}

.rule-list div {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  color: #475363;
  background: #f4f2ec;
  border-left: 3px solid var(--orange);
  font-size: 11px;
  font-weight: 700;
}

.rule-list b {
  color: var(--orange);
  font-family: Georgia, serif;
  font-size: 17px;
}

.complexity-list {
  margin-top: 19px;
  border-top: 2px solid var(--ink);
}

.complexity-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.complexity-list span {
  color: #5d6978;
  font-size: 12px;
}

.complexity-list strong {
  color: var(--orange);
  font-family: Georgia, serif;
  font-size: 17px;
}

.complexity-note {
  font-size: 10px !important;
}

.comparison-section {
  margin-top: 22px;
  padding: 29px;
}

.comparison-section h2 {
  margin-bottom: 22px;
}

.comparison-table-wrap {
  overflow-x: auto;
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
}

.comparison-table th,
.comparison-table td {
  padding: 14px 17px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.comparison-table th {
  color: #fff;
  background: var(--navy);
  font-size: 12px;
  letter-spacing: .04em;
}

.comparison-table td {
  color: #596676;
  font-size: 12px;
}

.comparison-table td:first-child {
  color: var(--ink);
  font-weight: 800;
}

.comparison-table tr:last-child td {
  border-bottom: 0;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px max(20px, calc((100% - 1240px) / 2));
  color: #8d9bad;
  background: var(--navy);
  border-top: 4px solid var(--orange);
  font-size: 11px;
}

footer span {
  color: #fff;
  font-weight: 800;
  letter-spacing: .13em;
}

.toast-region {
  position: fixed;
  z-index: 20;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 9px;
  pointer-events: none;
}

.toast {
  min-width: 250px;
  padding: 12px 15px;
  color: #fff;
  background: var(--navy);
  border-left: 4px solid var(--orange);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(15, 29, 51, .28);
  font-size: 12px;
  animation: toast-in .23s ease both;
}

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

@media (max-width: 980px) {
  .control-deck__top {
    flex-direction: column;
  }

  .degree-control {
    width: 100%;
    min-width: 0;
    border-top: 1px solid var(--line);
  }

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

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

  .trace-list {
    min-height: 160px;
  }

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

@media (max-width: 720px) {
  .hero {
    min-height: 280px;
  }

  .hero__inner {
    width: min(100% - 28px, 1240px);
    padding-top: 45px;
  }

  .hero p {
    font-size: 14px;
  }

  .page-shell {
    width: min(100% - 20px, 1240px);
  }

  .tree-switch {
    flex-direction: column;
  }

  .tree-switch__button {
    width: 100%;
    min-width: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .operation-bar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .value-field {
    width: 100%;
  }

  .action-group {
    flex-basis: 100%;
    grid-template-columns: 1fr;
  }

  .history-actions {
    width: 100%;
  }

  .history-actions .icon-button {
    flex: 1;
  }

  .dataset-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .sequence-field {
    min-width: 0;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 18px;
  }

  .metric-row {
    width: 100%;
  }

  .metric-row > div {
    flex: 1;
  }

  #treeCanvas,
  .canvas-stage {
    height: 430px;
    min-height: 430px;
  }

  .concept-card--primary {
    grid-template-columns: 1fr;
  }

  .comparison-section {
    padding: 22px 16px;
  }

  footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }
}

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