:root {
  color-scheme: dark;
  --page-bg: #090b12;
  --surface-1: #10131d;
  --surface-2: #141824;
  --surface-3: #191e2c;
  --border: #282e3f;
  --border-bright: #3c4560;
  --text: #f5f7ff;
  --text-soft: #aeb5c8;
  --text-muted: #737c93;
  --violet: #8b75ff;
  --violet-bright: #a893ff;
  --cyan: #4dd9e8;
  --amber: #ffbd59;
  --pink: #ff6fae;
  --green: #5ce0a0;
  --danger: #ff7588;
  --step-duration: 340ms;
  --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-lg: 0 24px 70px rgb(0 0 0 / 0.34);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -15%, rgb(72 59 132 / 0.18), transparent 34rem),
    var(--page-bg);
  font-size: 16px;
  line-height: 1.5;
}

button,
input,
output {
  font: inherit;
}

button,
input[type="range"] {
  touch-action: manipulation;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgb(77 217 232 / 0.78);
  outline-offset: 3px;
}

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

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  color: #090b12;
  background: var(--cyan);
  border-radius: 8px;
  font-weight: 500;
  transform: translateY(-160%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.page-glow {
  position: fixed;
  z-index: -1;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(130px);
  opacity: 0.08;
  pointer-events: none;
}

.page-glow--violet {
  top: 17%;
  left: -260px;
  background: var(--violet);
}

.page-glow--cyan {
  top: 55%;
  right: -300px;
  background: var(--cyan);
}

.app-shell {
  width: min(1480px, calc(100% - 48px));
  margin: 0 auto;
  padding: 42px 0 28px;
}

.site-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding-bottom: 36px;
}

.brand-mark {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  padding: 13px;
  background: linear-gradient(145deg, #7861f4, #5144b7);
  border: 1px solid rgb(255 255 255 / 0.14);
  border-radius: 17px;
  box-shadow: 0 15px 36px rgb(103 80 229 / 0.24);
}

.brand-mark span {
  width: 5px;
  background: #fff;
  border-radius: 4px 4px 2px 2px;
  opacity: 0.96;
}

.brand-mark span:nth-child(1) {
  height: 10px;
}

.brand-mark span:nth-child(2) {
  height: 20px;
}

.brand-mark span:nth-child(3) {
  height: 14px;
}

.brand-mark span:nth-child(4) {
  height: 29px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--violet-bright);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 3px;
  font-size: clamp(1.55rem, 3vw, 2.25rem);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.18rem, 2vw, 1.5rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.header-subtitle {
  margin-bottom: 0;
  color: var(--text-soft);
}

.algorithm-section {
  margin-bottom: 22px;
}

.section-heading-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 15px;
}

.section-hint {
  margin-bottom: 2px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.algorithm-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.algorithm-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 10px 8px;
  min-height: 91px;
  padding: 14px 15px;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition:
    transform 180ms var(--ease-smooth),
    border-color 180ms ease,
    background-color 180ms ease,
    box-shadow 180ms ease;
}

.algorithm-card:hover:not(:disabled) {
  z-index: 1;
  transform: translateY(-2px);
  background: var(--surface-2);
  border-color: var(--border-bright);
}

.algorithm-card[aria-pressed="true"],
.algorithm-card.is-selected {
  background:
    linear-gradient(135deg, rgb(139 117 255 / 0.17), transparent 74%),
    var(--surface-2);
  border-color: rgb(139 117 255 / 0.8);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.05),
    0 10px 28px rgb(82 64 181 / 0.17);
}

.algorithm-card[aria-pressed="true"]::before,
.algorithm-card.is-selected::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  content: "";
  background: linear-gradient(var(--violet), var(--cyan));
}

.algorithm-number {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
}

.algorithm-card > [data-button-label] {
  align-self: end;
  overflow: hidden;
  font-size: 0.88rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.algorithm-card__arrow {
  align-self: end;
  color: var(--text-muted);
  transition:
    color 180ms ease,
    transform 180ms ease;
}

.algorithm-card[aria-pressed="true"] .algorithm-card__arrow,
.algorithm-card.is-selected .algorithm-card__arrow {
  color: var(--cyan);
  transform: translateX(2px);
}

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

.visualizer-card,
.complexity-card,
.comparison-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.visualizer-card {
  min-width: 0;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.visualizer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--border);
}

.visualizer-title-group {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  min-width: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  margin-top: 3px;
  padding: 6px 10px;
  color: var(--text-soft);
  background: #171b28;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.status-badge::before {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  content: "";
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgb(92 224 160 / 0.08);
}

.status-badge[data-tone="working"],
.status-badge[data-status="sorting"],
.status-badge.is-sorting {
  color: #e5deff;
  border-color: rgb(139 117 255 / 0.4);
}

.status-badge[data-tone="working"]::before,
.status-badge[data-status="sorting"]::before,
.status-badge.is-sorting::before {
  background: var(--violet-bright);
  box-shadow: 0 0 0 4px rgb(139 117 255 / 0.11);
  animation: status-pulse 1.15s ease-in-out infinite;
}

.status-badge[data-tone="moving"] {
  color: #c9fbff;
  border-color: rgb(77 217 232 / 0.34);
}

.status-badge[data-tone="moving"]::before {
  background: var(--cyan);
  box-shadow: 0 0 0 4px rgb(77 217 232 / 0.1);
}

.status-badge[data-tone="special"] {
  color: #ffe2ef;
  border-color: rgb(255 111 174 / 0.34);
}

.status-badge[data-tone="special"]::before {
  background: var(--pink);
  box-shadow: 0 0 0 4px rgb(255 111 174 / 0.1);
}

.status-badge[data-tone="paused"]::before,
.status-badge[data-status="paused"]::before,
.status-badge.is-paused::before {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgb(255 189 89 / 0.1);
}

.status-badge[data-tone="sorted"]::before,
.status-badge[data-status="complete"]::before,
.status-badge.is-complete::before {
  background: var(--green);
}

@keyframes status-pulse {
  50% {
    opacity: 0.48;
    transform: scale(0.78);
  }
}

.visualizer-title-group .section-kicker {
  margin-top: 1px;
}

.algorithm-description {
  max-width: 560px;
  margin: 5px 0 0;
  color: var(--text-soft);
  font-size: 0.86rem;
}

.stats-strip {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
  margin: 0;
}

.stat-item {
  min-width: 92px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.stat-item dt {
  margin-bottom: 2px;
  color: var(--text-muted);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat-item dd {
  margin: 0;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.stage-frame {
  position: relative;
  padding: 20px 24px 0;
  background:
    radial-gradient(circle at 50% 100%, rgb(77 217 232 / 0.035), transparent 45%),
    #0d1018;
}

.bars-stage {
  --stage-bottom: 24px;
  position: relative;
  height: clamp(350px, 38vw, 540px);
  min-height: 350px;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #222838;
  border-radius: 15px 15px 8px 8px;
  background:
    linear-gradient(to right, rgb(255 255 255 / 0.025) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(255 255 255 / 0.034) 1px, transparent 1px),
    linear-gradient(180deg, #0f131d 0%, #0c0f17 100%);
  background-size: 8.3333% 100%, 100% 25%, 100% 100%;
}

.bars-stage::before {
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  content: "";
  background: radial-gradient(circle at 50% 104%, rgb(139 117 255 / 0.09), transparent 48%);
}

.bars-stage::after {
  position: absolute;
  z-index: 1;
  right: 14px;
  bottom: var(--stage-bottom);
  left: 14px;
  height: 1px;
  pointer-events: none;
  content: "";
  background: linear-gradient(90deg, transparent, #414a61 8%, #414a61 92%, transparent);
  box-shadow: 0 1px 12px rgb(77 217 232 / 0.08);
}

/* Bars keep their identity while `left` changes, making swaps glide horizontally. */
.array-bar {
  --bar-color-top: #9b88ff;
  --bar-color-bottom: #5f54d7;
  position: absolute;
  z-index: 2;
  bottom: calc(var(--stage-bottom) + 1px);
  left: 0;
  width: var(--bar-width, 24px);
  height: var(--bar-height, 40%);
  min-height: 3px;
  overflow: visible;
  background: linear-gradient(180deg, var(--bar-color-top), var(--bar-color-bottom));
  border: 1px solid rgb(255 255 255 / 0.16);
  border-bottom: 0;
  border-radius: 7px 7px 2px 2px;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.18),
    0 7px 18px rgb(84 68 187 / 0.18);
  transform: translate3d(var(--bar-x, 0px), var(--bar-y, 0px), 0);
  transform-origin: 50% 100%;
  will-change: left, width, transform, height;
  transition:
    left var(--step-duration) var(--ease-smooth),
    width var(--step-duration) var(--ease-smooth),
    transform var(--step-duration) var(--ease-smooth),
    height var(--step-duration) var(--ease-smooth),
    background var(--step-duration) ease,
    border-color var(--step-duration) ease,
    box-shadow var(--step-duration) ease,
    filter var(--step-duration) ease,
    opacity var(--step-duration) ease;
  animation: bar-enter 420ms var(--ease-smooth) var(--entry-delay, 0ms) both;
}

.bars-stage.is-instant .array-bar {
  transition-duration: 0ms;
}

.bars-stage.is-dense .bar-value {
  opacity: 0;
}

.bars-stage.is-dense .array-bar:is(
    .is-comparing,
    .is-swapping,
    .is-pivot,
    .is-minimum,
    .is-current,
    .is-heap-root
  ) .bar-value {
  opacity: 1;
}

.merge-divider {
  position: absolute;
  z-index: 7;
  top: 15px;
  bottom: calc(var(--stage-bottom) + 9px);
  width: 1px;
  pointer-events: none;
  background: linear-gradient(transparent, rgb(255 255 255 / 0.34), transparent);
  box-shadow: 0 0 15px rgb(77 217 232 / 0.18);
  transition: left var(--step-duration) var(--ease-smooth);
}

.array-bar.is-left-section:not(.is-comparing, .is-swapping, .is-current) {
  border-top-color: rgb(77 217 232 / 0.48);
}

.array-bar.is-right-section:not(.is-comparing, .is-swapping, .is-current) {
  border-top-color: rgb(255 111 174 / 0.46);
}

@keyframes bar-enter {
  from {
    opacity: 0;
    clip-path: inset(100% 0 0 0);
  }

  to {
    opacity: 1;
    clip-path: inset(0 0 0 0);
  }
}

.bars-stage.is-instant .array-bar {
  animation: none;
  transition: none;
}

.array-bar::after {
  position: absolute;
  inset: -5px;
  pointer-events: none;
  content: "";
  border: 2px solid transparent;
  border-radius: 10px 10px 4px 4px;
  transition:
    border-color var(--step-duration) ease,
    box-shadow var(--step-duration) ease;
}

.array-bar .bar-value,
.array-bar .array-bar__value {
  position: absolute;
  right: 50%;
  bottom: calc(100% + 7px);
  color: var(--text-soft);
  font-size: clamp(0.58rem, 0.75vw, 0.72rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transform: translateX(50%);
  transition: color var(--step-duration) ease;
}

.array-bar.is-comparing {
  --bar-color-top: #ffd77e;
  --bar-color-bottom: #d7892d;
  z-index: 4;
  box-shadow: 0 8px 24px rgb(255 189 89 / 0.23);
}

.array-bar.is-comparing::after {
  border-color: rgb(255 215 126 / 0.7);
}

.array-bar.is-swapping {
  --bar-color-top: #6ef1ef;
  --bar-color-bottom: #278ab8;
  z-index: 5;
  box-shadow: 0 10px 29px rgb(77 217 232 / 0.3);
}

.array-bar.is-swapping::after {
  border-color: rgb(77 217 232 / 0.86);
  box-shadow: 0 0 18px rgb(77 217 232 / 0.18);
}

.array-bar.is-pivot {
  --bar-color-top: #ff91c5;
  --bar-color-bottom: #c74986;
  z-index: 6;
  box-shadow: 0 10px 30px rgb(255 111 174 / 0.3);
}

.array-bar.is-pivot::after {
  border-color: var(--pink);
  box-shadow: 0 0 18px rgb(255 111 174 / 0.2);
}

.array-bar.is-minimum {
  --bar-color-top: #76f1f0;
  --bar-color-bottom: #2997bd;
  z-index: 6;
}

.array-bar.is-minimum::after {
  border-color: var(--cyan);
  box-shadow: 0 0 18px rgb(77 217 232 / 0.2);
}

.array-bar.is-current {
  --bar-color-top: #ffca72;
  --bar-color-bottom: #db7751;
  z-index: 6;
}

.array-bar.is-current::after {
  border-color: var(--amber);
  box-shadow: 0 0 18px rgb(255 189 89 / 0.2);
}

.array-bar.is-heap-root {
  --bar-color-top: #ff96a5;
  --bar-color-bottom: #c74d63;
  z-index: 6;
}

.array-bar.is-heap-root::after {
  border-color: var(--danger);
  box-shadow: 0 0 18px rgb(255 117 136 / 0.2);
}

.array-bar.is-sorted {
  --bar-color-top: #7cebb2;
  --bar-color-bottom: #299868;
  z-index: 3;
  box-shadow: 0 7px 21px rgb(92 224 160 / 0.21);
}

.array-bar.is-sorted::after {
  border-color: rgb(92 224 160 / 0.38);
}

/* A live teaching cue stays visible even when it sits inside a sorted section. */
.array-bar.is-sorted.is-current {
  --bar-color-top: #ffca72;
  --bar-color-bottom: #db7751;
  z-index: 6;
}

.array-bar.is-sorted.is-current::after {
  border-color: var(--amber);
  box-shadow: 0 0 18px rgb(255 189 89 / 0.2);
}

.array-bar.is-sorted.is-pivot {
  --bar-color-top: #ff91c5;
  --bar-color-bottom: #c74986;
  z-index: 6;
}

.array-bar.is-sorted.is-pivot::after {
  border-color: var(--pink);
  box-shadow: 0 0 18px rgb(255 111 174 / 0.2);
}

.array-bar.is-outside-range,
.array-bar.is-outside-heap {
  z-index: 1;
  opacity: 0.3;
  filter: saturate(0.35);
}

.array-bar.is-sorted:is(.is-outside-range, .is-outside-heap) {
  opacity: 0.82;
  filter: saturate(0.9);
}

.heap-indicator {
  position: absolute;
  z-index: 8;
  top: 32px;
  right: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  color: var(--text-soft);
  background: rgb(14 17 26 / 0.92);
  border: 1px solid var(--border-bright);
  border-radius: 999px;
  font-size: 0.72rem;
}

.heap-indicator::before {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  content: "";
  background: var(--danger);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgb(255 117 136 / 0.09);
}

.array-readout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 12px 24px;
  background: #0d1018;
  border-top: 1px solid rgb(255 255 255 / 0.035);
  border-bottom: 1px solid var(--border);
}

.array-readout__heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 92px;
  color: var(--text-soft);
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.array-count {
  color: var(--violet-bright);
  font-size: 0.65rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  text-transform: none;
}

.array-values-scroll {
  min-width: 0;
  padding: 3px 1px 5px;
  overflow-x: auto;
  scrollbar-color: var(--border-bright) transparent;
  scrollbar-width: thin;
}

.array-values-scroll:focus-visible {
  outline: 2px solid rgb(77 217 232 / 0.7);
  outline-offset: 3px;
  border-radius: 7px;
}

.array-values-list {
  display: flex;
  align-items: center;
  gap: 6px;
  width: max-content;
  min-width: 100%;
  padding: 0;
  margin: 0;
  list-style: none;
}

.array-values-list::before,
.array-values-list::after {
  color: var(--text-muted);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 1rem;
}

.array-values-list::before {
  content: "[";
}

.array-values-list::after {
  content: "]";
}

.array-value-chip {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 28px;
  padding: 0 8px;
  color: #dcd7ff;
  background: rgb(139 117 255 / 0.1);
  border: 1px solid rgb(139 117 255 / 0.2);
  border-radius: 7px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  transition:
    color var(--step-duration) ease,
    background-color var(--step-duration) ease,
    border-color var(--step-duration) ease,
    box-shadow var(--step-duration) ease;
}

.array-value-chip.is-comparing {
  color: #fff0c9;
  background: rgb(255 189 89 / 0.13);
  border-color: rgb(255 189 89 / 0.5);
}

.array-value-chip.is-moving {
  color: #cefffe;
  background: rgb(77 217 232 / 0.13);
  border-color: rgb(77 217 232 / 0.55);
}

.array-value-chip.is-special {
  color: #ffe0ef;
  background: rgb(255 111 174 / 0.13);
  border-color: rgb(255 111 174 / 0.55);
}

.array-value-chip.is-sorted {
  color: #d8ffeb;
  background: rgb(92 224 160 / 0.12);
  border-color: rgb(92 224 160 / 0.43);
}

.stage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 64px;
  padding: 12px 24px;
  background: #0d1018;
  border-bottom: 1px solid var(--border);
}

.step-message {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-message::before {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin: 0 9px 2px 0;
  content: "";
  background: var(--violet-bright);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgb(139 117 255 / 0.08);
}

.visual-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex: 0 0 auto;
  padding: 0;
  margin: 0;
  list-style: none;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 0.67rem;
  white-space: nowrap;
}

.legend-swatch {
  width: 7px;
  height: 14px;
  border-radius: 3px 3px 1px 1px;
}

.legend-swatch--default {
  background: linear-gradient(#9b88ff, #5f54d7);
}

.legend-swatch--comparing {
  background: linear-gradient(#ffd77e, #d7892d);
}

.legend-swatch--moving {
  background: linear-gradient(#6ef1ef, #278ab8);
}

.legend-swatch--special {
  background: linear-gradient(#ff91c5, #c74986);
}

.legend-swatch--sorted {
  background: linear-gradient(#7cebb2, #299868);
}

.controls-panel {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  gap: 26px;
  align-items: end;
  padding: 20px 24px 23px;
  background: var(--surface-1);
}

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

.range-control {
  display: block;
  min-width: 0;
  cursor: pointer;
}

.range-label-row,
.range-extents {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.range-label-row {
  margin-bottom: 9px;
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 500;
}

.range-label-row output {
  min-width: 42px;
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.range-control input[type="range"] {
  display: block;
  width: 100%;
  height: 5px;
  margin: 0;
  cursor: pointer;
  appearance: none;
  background: #2b3142;
  border-radius: 999px;
  accent-color: var(--violet);
}

.range-control input[type="range"]::-webkit-slider-thumb {
  width: 17px;
  height: 17px;
  appearance: none;
  background: #f4f1ff;
  border: 4px solid var(--violet);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgb(139 117 255 / 0.11);
}

.range-control input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  background: #f4f1ff;
  border: 4px solid var(--violet);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgb(139 117 255 / 0.11);
}

.range-control input[type="range"]:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.range-extents {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.62rem;
}

.action-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 8px;
}

.control-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 13px;
  cursor: pointer;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  transition:
    transform 160ms var(--ease-smooth),
    background-color 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

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

.control-button:active:not(:disabled) {
  transform: translateY(0);
}

.control-button svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.control-button .resume-icon {
  display: none;
}

#pauseBtn.is-resume .pause-icon {
  display: none;
}

#pauseBtn.is-resume .resume-icon {
  display: block;
}

.control-button--primary {
  color: #fff;
  background: linear-gradient(135deg, #8168f4, #5b4bcb);
  border: 1px solid #9782fb;
  box-shadow: 0 9px 24px rgb(93 73 202 / 0.27);
}

.control-button--primary:hover:not(:disabled) {
  box-shadow: 0 11px 28px rgb(93 73 202 / 0.36);
}

.control-button--secondary {
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--border-bright);
}

.control-button--secondary:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-3);
  border-color: #515c77;
}

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

.control-button--ghost:hover:not(:disabled) {
  color: var(--text-soft);
  background: rgb(255 255 255 / 0.025);
  border-color: var(--border-bright);
}

.complexity-card {
  position: relative;
  padding: 23px;
  overflow: hidden;
  background:
    radial-gradient(circle at 115% -5%, rgb(139 117 255 / 0.14), transparent 43%),
    var(--surface-1);
}

.complexity-card::after {
  position: absolute;
  right: -40px;
  bottom: -70px;
  width: 170px;
  height: 170px;
  pointer-events: none;
  content: "";
  background: radial-gradient(circle, rgb(77 217 232 / 0.06), transparent 70%);
}

.complexity-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 25px;
}

.complexity-icon {
  display: grid;
  place-items: center;
  width: 39px;
  height: 39px;
  color: var(--violet-bright);
  background: rgb(139 117 255 / 0.1);
  border: 1px solid rgb(139 117 255 / 0.28);
  border-radius: 11px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.92rem;
}

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

.complexity-list > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 45px;
  padding: 8px 11px;
  background: rgb(255 255 255 / 0.025);
  border: 1px solid rgb(255 255 255 / 0.045);
  border-radius: 10px;
}

.complexity-list dt {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.complexity-list dd {
  margin: 0;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.84rem;
  font-weight: 500;
  text-align: right;
}

.complexity-divider {
  height: 1px;
  margin: 19px 0;
  background: var(--border);
}

.complexity-list--secondary .stability-value {
  color: var(--green);
  font-family: inherit;
}

.complexity-list--secondary .stability-value[data-stable="false"] {
  color: var(--pink);
}

.complexity-note {
  position: relative;
  z-index: 1;
  padding: 12px 13px;
  margin: 18px 0 0;
  color: var(--text-soft);
  background: rgb(139 117 255 / 0.065);
  border-left: 2px solid var(--violet);
  border-radius: 4px 9px 9px 4px;
  font-size: 0.76rem;
}

.comparison-section {
  padding: 23px 24px 18px;
  margin-top: 18px;
  overflow: hidden;
}

.comparison-heading {
  margin-bottom: 18px;
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 13px;
  scrollbar-color: var(--border-bright) transparent;
}

table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
  font-size: 0.83rem;
}

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

thead th {
  color: var(--text-muted);
  background: #0d1018;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

tbody th {
  color: var(--text);
  font-weight: 500;
}

tbody td {
  color: var(--text-soft);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

tbody tr {
  transition: background-color 160ms ease;
}

tbody tr:hover {
  background: rgb(139 117 255 / 0.045);
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr.is-selected,
tbody tr[data-active="true"] {
  background: rgb(139 117 255 / 0.07);
}

.table-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 10px 1px 0;
  background: #596177;
  border-radius: 50%;
}

tbody tr.is-selected .table-dot,
tbody tr[data-active="true"] .table-dot {
  background: var(--violet-bright);
  box-shadow: 0 0 0 4px rgb(139 117 255 / 0.09);
}

.table-note {
  margin: 12px 4px 0;
  color: var(--text-muted);
  font-size: 0.72rem;
}

footer {
  padding: 21px 8px 0;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-align: center;
}

footer p {
  margin-bottom: 0;
}

@media (max-width: 1220px) {
  .algorithm-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .algorithm-card {
    min-height: 78px;
  }

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

  .stats-strip {
    width: 100%;
  }

  .stat-item {
    flex: 1;
  }

  .stage-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .visual-legend {
    justify-content: flex-start;
    width: 100%;
  }

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

  .action-controls {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

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

  .complexity-card {
    display: grid;
    grid-template-columns: minmax(190px, 0.75fr) 1fr 1fr;
    gap: 20px;
    align-items: start;
  }

  .complexity-heading {
    margin-bottom: 0;
  }

  .complexity-divider {
    display: none;
  }

  .complexity-list--secondary {
    align-self: stretch;
  }

  .complexity-note {
    grid-column: 1 / -1;
    margin-top: 0;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 28px, 1480px);
    padding-top: 28px;
  }

  .site-header {
    padding-bottom: 28px;
  }

  .brand-mark {
    width: 51px;
    height: 51px;
    padding: 11px;
    border-radius: 15px;
  }

  .brand-mark span:nth-child(4) {
    height: 27px;
  }

  .section-heading-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

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

  .visualizer-card,
  .complexity-card,
  .comparison-section {
    border-radius: 18px;
  }

  .visualizer-header,
  .stage-frame,
  .array-readout,
  .stage-footer,
  .controls-panel {
    padding-right: 16px;
    padding-left: 16px;
  }

  .visualizer-title-group {
    flex-direction: column;
    gap: 10px;
  }

  .status-badge {
    margin-top: 0;
  }

  .bars-stage {
    height: 390px;
    min-height: 330px;
    background-size: 16.6667% 100%, 100% 25%, 100% 100%;
  }

  .visual-legend {
    display: grid;
    grid-template-columns: repeat(3, max-content);
  }

  .array-readout {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .array-readout__heading {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
  }

  .slider-controls {
    grid-template-columns: 1fr;
    gap: 17px;
  }

  .action-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .complexity-card {
    grid-template-columns: 1fr 1fr;
    padding: 20px;
  }

  .complexity-heading {
    grid-column: 1 / -1;
  }
}

@media (max-width: 460px) {
  body {
    font-size: 15px;
  }

  .app-shell {
    width: calc(100% - 20px);
  }

  .site-header {
    align-items: flex-start;
  }

  .eyebrow {
    display: none;
  }

  .header-subtitle {
    font-size: 0.86rem;
  }

  .algorithm-card {
    min-height: 72px;
    padding: 11px 12px;
  }

  .algorithm-card > [data-button-label] {
    font-size: 0.78rem;
  }

  .visualizer-header {
    padding-top: 18px;
  }

  .stats-strip {
    gap: 5px;
  }

  .stat-item {
    min-width: 0;
    padding: 9px 8px;
  }

  .stat-item dt {
    font-size: 0.57rem;
  }

  .stat-item dd {
    font-size: 0.92rem;
  }

  .stage-frame {
    padding-top: 14px;
  }

  .bars-stage {
    height: 345px;
  }

  .array-bar .bar-value,
  .array-bar .array-bar__value {
    display: none;
  }

  .array-value-chip {
    min-width: 31px;
    height: 26px;
    padding-inline: 7px;
    font-size: 0.68rem;
  }

  .visual-legend {
    grid-template-columns: repeat(2, max-content);
    gap: 8px 13px;
  }

  .step-message {
    width: 100%;
    overflow: visible;
    line-height: 1.35;
    text-overflow: clip;
    white-space: normal;
  }

  .control-button {
    min-height: 44px;
    padding-inline: 9px;
    font-size: 0.74rem;
  }

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

  .complexity-heading,
  .complexity-note {
    grid-column: auto;
  }

  .comparison-section {
    padding-right: 14px;
    padding-left: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
