:root {
  color-scheme: light;
  --paper: #efede6;
  --paper-deep: #e5e2d9;
  --panel: #fbfaf6;
  --ink: #171922;
  --muted: #6a6b72;
  --line: #d7d3c9;
  --stage: #10131b;
  --stage-raised: #181c27;
  --stage-line: #2b3141;
  --stage-text: #f5f4ed;
  --compare: #55e6d2;
  --moving: #ff7a8a;
  --candidate: #ffd166;
  --sorted: #b9ef72;
  --default-bar: #69748f;
  --algorithm-accent: #55e6c1;
  --shadow: 0 22px 60px rgba(30, 32, 40, 0.1);
  --radius-large: 24px;
  --radius-medium: 17px;
  --font-ui:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 2%, rgba(255, 255, 255, 0.82), transparent 27rem),
    var(--paper);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input[type="range"] {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: inherit;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  color: white;
  background: var(--ink);
  transform: translateY(-160%);
}

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

.app-shell {
  width: min(100%, 1680px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 48px) 24px;
}

.topbar {
  min-height: 84px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  width: max-content;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 3px;
  padding: 8px;
  border-radius: 13px;
  background: var(--ink);
  box-shadow: 0 8px 18px rgba(23, 25, 34, 0.16);
}

.brand-mark i {
  width: 5px;
  border-radius: 3px 3px 1px 1px;
  background: var(--algorithm-accent);
}

.brand-mark i:nth-child(1) {
  height: 45%;
}

.brand-mark i:nth-child(2) {
  height: 82%;
}

.brand-mark i:nth-child(3) {
  height: 60%;
}

.brand-mark i:nth-child(4) {
  height: 100%;
}

.brand-copy {
  display: grid;
  line-height: 1;
}

.brand-copy strong {
  font-size: 1.08rem;
  letter-spacing: -0.025em;
}

.brand-copy small {
  margin-top: 5px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar-thesis {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.source-link {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.source-link:hover {
  border-color: var(--ink);
  background: var(--panel);
  transform: translateY(-1px);
}

main {
  padding-top: 20px;
}

.control-deck {
  display: grid;
  grid-template-columns: minmax(210px, 0.75fr) minmax(0, 2.25fr);
  align-items: center;
  gap: clamp(22px, 3vw, 52px);
  padding: 20px clamp(20px, 2.4vw, 34px);
  border: 1px solid var(--line);
  border-radius: var(--radius-large);
  background: rgba(251, 250, 246, 0.78);
  box-shadow: 0 10px 30px rgba(35, 36, 42, 0.05);
  backdrop-filter: blur(12px);
}

.deck-heading {
  display: flex;
  align-items: center;
  gap: 16px;
}

.deck-index {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.61rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.deck-heading h1 {
  margin: 0;
  font-size: clamp(1.2rem, 1.8vw, 1.55rem);
  letter-spacing: -0.035em;
}

.deck-heading p {
  max-width: 29rem;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.control-fields {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.75fr 0.75fr 1.25fr 0.65fr auto;
  align-items: end;
  gap: 12px;
}

.field {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field output {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0;
  text-transform: none;
}

select {
  width: 100%;
  height: 43px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background-color: white;
  font-size: 0.82rem;
  font-weight: 680;
}

#detail {
  padding-right: 27px;
  font-size: 0.74rem;
}

.number-input,
#custom-data {
  width: 100%;
  height: 43px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: white;
  font-size: 0.82rem;
  font-weight: 680;
}

.range-field {
  padding-bottom: 7px;
}

input[type="range"] {
  width: 100%;
  height: 10px;
  margin: 6px 0;
  appearance: none;
  border-radius: 999px;
  outline: none;
  background: var(--paper-deep);
}

input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  appearance: none;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 6px rgba(23, 25, 34, 0.2);
}

input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 6px rgba(23, 25, 34, 0.2);
}

.new-data-button {
  height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid var(--ink);
  border-radius: 11px;
  color: white;
  background: var(--ink);
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 8px 18px rgba(23, 25, 34, 0.13);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease;
}

.new-data-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(23, 25, 34, 0.18);
}

.button-spark {
  color: var(--algorithm-accent);
  font-size: 0.95rem;
}

.control-extras {
  grid-column: 2;
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.secondary-button,
.focus-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: white;
  font-size: 0.7rem;
  font-weight: 800;
}

.secondary-button.active,
.secondary-button[aria-pressed="true"] {
  border-color: var(--ink);
  color: white;
  background: var(--ink);
}

.compare-field {
  width: min(240px, 100%);
}

.share-status {
  min-width: 8rem;
  color: var(--muted);
  font-size: 0.68rem;
}

.custom-data-panel {
  grid-column: 2;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  align-items: end;
  gap: 10px 12px;
  margin-top: 12px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
}

.custom-error {
  grid-column: 1 / -1;
  min-height: 1em;
  margin: 0;
  color: #aa3141;
  font-size: 0.68rem;
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(240px, 0.78fr) minmax(520px, 2.1fr) minmax(230px, 0.78fr);
  grid-template-areas: "code theater learn";
  align-items: start;
  gap: clamp(14px, 1.6vw, 24px);
  margin-top: 20px;
}

.panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-large);
  background: var(--panel);
}

.panel-heading,
.theater-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading h2,
.theater-heading h2 {
  margin: 3px 0 0;
  font-size: clamp(1.1rem, 1.5vw, 1.35rem);
  letter-spacing: -0.035em;
}

.panel-kicker {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.61rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.outline-chip {
  padding: 6px 9px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--algorithm-accent);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.code-panel {
  grid-area: code;
  position: sticky;
  top: 16px;
  overflow: hidden;
  color: #f1f0e9;
  border-color: #2b303d;
  background: #171a23;
  box-shadow: 0 18px 45px rgba(16, 19, 27, 0.14);
}

.code-panel .panel-kicker {
  color: #8d93a4;
}

.pseudocode {
  display: grid;
  gap: 5px;
  margin: 23px -8px 0;
  padding: 0;
  list-style: none;
}

.pseudocode li {
  position: relative;
  min-height: 38px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #aeb3c2;
  transition:
    color 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease,
    transform 180ms ease;
}

.pseudocode li::before {
  content: "";
  position: absolute;
  left: -5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 0 transparent;
}

.pseudocode li[data-active="true"] {
  color: white;
  border-color: color-mix(in srgb, var(--algorithm-accent) 42%, transparent);
  background: color-mix(in srgb, var(--algorithm-accent) 13%, transparent);
  transform: translateX(3px);
}

.pseudocode li[data-active="true"]::before {
  background: var(--algorithm-accent);
  box-shadow: 0 0 14px var(--algorithm-accent);
}

.code-line-number {
  color: #626a7d;
  font-family: var(--font-mono);
  font-size: 0.61rem;
}

.pseudocode code {
  min-width: 0;
  padding-left: calc(var(--depth) * 11px);
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: clamp(0.67rem, 0.74vw, 0.76rem);
  line-height: 1.4;
  white-space: pre-wrap;
}

.invariant-card {
  margin-top: 24px;
  padding: 15px;
  border: 1px solid #303645;
  border-radius: 13px;
  background: #11141c;
}

.invariant-card span {
  color: var(--algorithm-accent);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.invariant-card p {
  margin: 8px 0 0;
  color: #b7bdca;
  font-size: 0.73rem;
  line-height: 1.55;
}

.theater {
  grid-area: theater;
  min-width: 0;
}

.theater-heading {
  align-items: end;
  padding: 2px 4px 14px;
}

.theater-heading-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.focus-button {
  min-height: 34px;
  color: var(--muted);
  background: transparent;
}

.focus-button[aria-pressed="true"] {
  color: white;
  border-color: var(--ink);
  background: var(--ink);
}

.trace-position {
  display: grid;
  justify-items: end;
  gap: 4px;
}

.trace-position span {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.trace-position output {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
}

.stage-shell {
  position: relative;
  overflow: hidden;
  padding: clamp(15px, 2vw, 22px);
  border: 1px solid #2a303e;
  border-radius: var(--radius-large);
  color: var(--stage-text);
  background: var(--stage);
  box-shadow: var(--shadow);
}

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

.stage-grid[data-compare="true"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stage-grid[data-compare="true"] .bars {
  height: clamp(300px, 26vw, 390px);
}

.stage-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.operation-state {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-orb {
  position: relative;
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--algorithm-accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--algorithm-accent) 14%, transparent);
}

body:not([data-operation="idle"]):not([data-operation="done"]) .status-orb::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 1px solid var(--algorithm-accent);
  border-radius: 50%;
  animation: signal 1.5s ease-out infinite;
}

.operation-state div {
  display: grid;
  gap: 2px;
}

.operation-state div span {
  color: #8e95a7;
  font-family: var(--font-mono);
  font-size: 0.57rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.operation-state strong {
  font-size: 0.76rem;
}

#range-readout {
  padding: 6px 9px;
  border: 1px solid #343a49;
  border-radius: 999px;
  color: #aab0bf;
  font-family: var(--font-mono);
  font-size: 0.62rem;
}

.inspection {
  min-height: 86px;
  display: grid;
  place-items: center;
  margin-top: 14px;
  padding: 10px 14px;
  border: 1px solid #2a3040;
  border-radius: 15px;
  background: var(--stage-raised);
}

.inspection > p {
  margin: 0;
  color: #969dad;
  font-size: 0.72rem;
  line-height: 1.5;
  text-align: center;
}

.inspection-equation {
  display: none;
  grid-template-columns: minmax(70px, 1fr) 32px minmax(70px, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: min(100%, 420px);
}

.inspection[data-active="true"] > p {
  display: none;
}

.inspection[data-active="true"] .inspection-equation {
  display: grid;
}

.operand {
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 8px 10px;
  border: 1px solid #353c4d;
  border-radius: 11px;
  background: #11151e;
}

.operand span {
  color: #858d9f;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.operand strong {
  color: var(--compare);
  font-family: var(--font-mono);
  font-size: 1.1rem;
}

.operator {
  color: #d7d9df;
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 800;
  text-align: center;
}

.comparison-result {
  min-width: 54px;
  padding: 8px 10px;
  border-radius: 9px;
  color: #11141b;
  background: var(--moving);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.comparison-result[data-truth="false"] {
  color: #d5d8e0;
  background: #313747;
}

.native-visual {
  height: 172px;
  margin-top: 14px;
  padding: 12px;
  overflow: auto;
  border: 1px solid #293040;
  border-radius: 15px;
  color: #dfe3ec;
  background: #111620;
  scrollbar-color: #3d4659 transparent;
}

.native-visual.compact {
  height: 164px;
  margin-top: 12px;
}

.native-heading {
  position: sticky;
  z-index: 4;
  top: -12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: max-content;
  margin: -12px -12px 10px;
  padding: 9px 12px;
  border-bottom: 1px solid #293040;
  background: rgba(17, 22, 32, 0.96);
}

.native-label,
.native-phase,
.buffer-label,
.native-footnote {
  font-family: var(--font-mono);
}

.native-label {
  color: #8f98aa;
  font-size: 0.57rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.native-phase {
  color: var(--algorithm-accent);
  font-size: 0.58rem;
  font-weight: 750;
  text-transform: capitalize;
}

.merge-buffers,
.quick-partitions {
  min-width: 340px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.quick-partitions {
  min-width: 460px;
  grid-template-columns: 1fr 1.2fr 0.65fr;
}

.merge-buffer,
.partition-group,
.gap-lane {
  min-width: 0;
  padding: 8px;
  border: 1px solid #2e3647;
  border-radius: 10px;
  background: #0d1119;
}

.partition-group[data-partition="accepted"] {
  border-color: color-mix(in srgb, var(--compare) 46%, #2e3647);
}

.partition-group[data-partition="pivot"] {
  border-color: color-mix(in srgb, var(--candidate) 55%, #2e3647);
}

.buffer-label {
  display: block;
  margin-bottom: 7px;
  color: #7f889b;
  font-size: 0.52rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.buffer-values,
.output-slots {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
}

.buffer-values {
  overflow-x: auto;
}

.native-chip {
  min-width: 29px;
  height: 28px;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  padding: 0 5px;
  border: 1px solid #394255;
  border-radius: 7px;
  color: #c6cbd6;
  background: #171d29;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 800;
}

.native-chip[data-active="true"] {
  border-color: var(--compare);
  color: #071411;
  background: repeating-linear-gradient(135deg, var(--compare) 0 5px, #86f5e5 5px 8px);
  box-shadow: 0 0 14px color-mix(in srgb, var(--compare) 35%, transparent);
}

.native-chip[data-consumed="true"] {
  opacity: 0.35;
  text-decoration: line-through;
}

.native-chip[data-role="moving"] {
  border-color: var(--moving);
  color: white;
  background: repeating-linear-gradient(-45deg, #c6485e 0 5px, var(--moving) 5px 9px);
}

.native-chip[data-role="candidate"] {
  border-color: var(--candidate);
  color: #1a160a;
  background: repeating-linear-gradient(90deg, var(--candidate) 0 4px, #ffe39a 4px 7px);
}

.native-footnote {
  margin: 8px 0 0;
  color: #777f91;
  font-size: 0.53rem;
}

.heap-tree,
.heap-tree ol {
  position: relative;
  display: flex;
  justify-content: center;
  margin: 0;
  padding: 0;
  list-style: none;
}

.heap-tree {
  min-width: max-content;
  padding: 2px 10px 12px;
}

.heap-branch {
  position: relative;
  padding: 8px 2px 0;
  text-align: center;
}

.heap-children > .heap-branch::before,
.heap-children > .heap-branch::after {
  content: "";
  position: absolute;
  top: 2px;
  width: 50%;
  height: 6px;
  border-top: 1px solid #4b566b;
}

.heap-children > .heap-branch::before {
  right: 50%;
}

.heap-children > .heap-branch::after {
  left: 50%;
  border-left: 1px solid #4b566b;
}

.heap-children > .heap-branch:only-child::before,
.heap-children > .heap-branch:only-child::after {
  width: 0;
}

.heap-node {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #455067;
  border-radius: 50%;
  background: #171d29;
  font-family: var(--font-mono);
}

.heap-node strong {
  font-size: 0.55rem;
}

.heap-node small {
  margin-top: -6px;
  color: #70798c;
  font-size: 0.36rem;
}

.heap-node[data-role="compare"],
.heap-node[data-role="focus"] {
  border-color: var(--compare);
  color: #071411;
  background: repeating-linear-gradient(135deg, var(--compare) 0 5px, #8af4e5 5px 8px);
}

.heap-node[data-role="candidate"] {
  border-color: var(--candidate);
  color: #1a160a;
  background: var(--candidate);
}

.heap-node[data-role="moving"] {
  border-color: var(--moving);
  color: white;
  background: repeating-linear-gradient(-45deg, var(--moving) 0 5px, #c94d61 5px 9px);
}

.gap-lanes {
  min-width: max-content;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(105px, auto);
  gap: 8px;
}

.count-table,
.output-slots {
  min-width: max-content;
  display: flex;
  gap: 5px;
}

.count-cell {
  min-width: 40px;
  display: grid;
  overflow: hidden;
  border: 1px solid #354056;
  border-radius: 8px;
  text-align: center;
}

.count-cell[data-active="true"] {
  border-color: var(--compare);
  box-shadow: 0 0 12px color-mix(in srgb, var(--compare) 30%, transparent);
}

.count-value,
.count-total {
  padding: 4px;
  font-family: var(--font-mono);
  font-size: 0.54rem;
}

.count-value {
  color: #8a93a5;
  background: #0d1119;
}

.count-total {
  color: var(--algorithm-accent);
  background: #1a2030;
}

.output-slots {
  margin-top: 8px;
}

.radix-buckets {
  min-width: 520px;
  display: grid;
  grid-template-columns: repeat(10, minmax(46px, 1fr));
  gap: 5px;
}

.radix-bucket {
  min-height: 79px;
  padding: 5px;
  border: 1px solid #313a4d;
  border-radius: 8px;
  background: #0d1119;
}

.radix-bucket[data-active="true"] {
  border-color: var(--candidate);
}

.bucket-digit {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  margin: 0 auto 5px;
  border-radius: 6px;
  color: #11151d;
  background: var(--algorithm-accent);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 900;
}

.bucket-stack {
  display: grid;
  justify-content: center;
  gap: 3px;
}

.bucket-stack .native-chip {
  min-width: 25px;
  height: 22px;
  font-size: 0.5rem;
}

.bars {
  --partition-x: 50%;
  isolation: isolate;
  position: relative;
  height: clamp(300px, 31vw, 450px);
  display: flex;
  align-items: stretch;
  gap: var(--bar-gap);
  margin-top: 14px;
  padding: 42px clamp(8px, 1.2vw, 18px) 27px;
  border: 1px solid #252b39;
  border-radius: 16px;
  background-color: #0c0f16;
  overflow: hidden;
}

.bars::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background-image:
    linear-gradient(rgba(92, 103, 132, 0.11) 1px, transparent 1px),
    linear-gradient(90deg, rgba(92, 103, 132, 0.08) 1px, transparent 1px);
  background-size: 100% 25%, 10% 100%;
  pointer-events: none;
}

.bars::after {
  content: "";
  position: absolute;
  z-index: 0;
  top: 12px;
  bottom: 24px;
  left: var(--partition-x);
  width: 1px;
  opacity: 0;
  background: repeating-linear-gradient(
    to bottom,
    color-mix(in srgb, var(--algorithm-accent) 62%, transparent) 0 5px,
    transparent 5px 10px
  );
  transition: opacity 180ms ease;
  pointer-events: none;
}

.bars[data-partitioned="true"]::after {
  opacity: 1;
}

.bar-item {
  position: relative;
  z-index: 1;
  min-width: 0;
  height: 100%;
  flex: 1 1 0;
  opacity: 1;
  translate: 0 0;
  transition:
    opacity 220ms ease,
    translate 220ms ease;
}

.bar-item[data-in-range="false"] {
  opacity: 0.26;
}

.bar-column {
  position: absolute;
  right: 9%;
  bottom: 21px;
  left: 9%;
  height: var(--bar-height);
  min-height: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px 7px 3px 3px;
  background: var(--default-bar);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.13);
  transition:
    height 240ms ease,
    background-color 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.bar-value {
  position: absolute;
  right: 50%;
  bottom: calc(var(--bar-height) + 27px);
  color: #aeb5c5;
  font-family: var(--font-mono);
  font-size: clamp(0.55rem, 0.68vw, 0.67rem);
  font-weight: 700;
  transform: translateX(50%);
  transition:
    color 180ms ease,
    bottom 240ms ease;
}

.bar-position {
  position: absolute;
  right: 50%;
  bottom: 0;
  color: #596174;
  font-family: var(--font-mono);
  font-size: 0.5rem;
  transform: translateX(50%);
}

.bars[data-values="hide"] .bar-value,
.bars[data-positions="hide"] .bar-position {
  opacity: 0;
}

.bar-item[data-role="compare"] {
  translate: 0 -8px;
}

.bar-item[data-role="compare"] .bar-column {
  border-color: var(--compare);
  background: var(--compare);
  box-shadow:
    0 0 22px color-mix(in srgb, var(--compare) 55%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.bar-item[data-role="compare"] .bar-value {
  color: var(--compare);
}

.bar-item[data-role="moving"] {
  translate: 0 -13px;
}

.bar-item[data-role="moving"] .bar-column {
  border-color: var(--moving);
  background: var(--moving);
  box-shadow:
    0 0 25px color-mix(in srgb, var(--moving) 52%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.bar-item[data-role="moving"] .bar-value {
  color: var(--moving);
}

.bar-item[data-role="candidate"] .bar-column {
  border-color: var(--candidate);
  background: var(--candidate);
  box-shadow: 0 0 19px color-mix(in srgb, var(--candidate) 36%, transparent);
}

.bar-item[data-role="candidate"] .bar-value {
  color: var(--candidate);
}

.bar-item[data-role="key"] .bar-column {
  border-color: var(--moving);
  background:
    repeating-linear-gradient(
      -45deg,
      var(--moving) 0 7px,
      color-mix(in srgb, var(--moving) 68%, #11151e) 7px 12px
    );
  box-shadow: 0 0 20px color-mix(in srgb, var(--moving) 42%, transparent);
}

.bar-item[data-role="key"] .bar-value {
  color: var(--moving);
}

.bar-item[data-role="sorted"] .bar-column {
  border-color: var(--sorted);
  background: color-mix(in srgb, var(--sorted) 84%, #5b667c);
  box-shadow: 0 0 16px color-mix(in srgb, var(--sorted) 28%, transparent);
}

.bar-item[data-role="sorted"] .bar-value {
  color: var(--sorted);
}

.bar-item[data-role="focus"] .bar-column {
  border-color: var(--algorithm-accent);
  background: var(--algorithm-accent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--algorithm-accent) 36%, transparent);
}

.bar-item[data-role="focus"] .bar-value {
  color: var(--algorithm-accent);
}

/* Pattern as well as color keeps every state distinguishable. */
.bar-item[data-role="compare"] .bar-column {
  background: repeating-linear-gradient(135deg, var(--compare) 0 7px, #8df5e6 7px 11px);
}

.bar-item[data-role="moving"] .bar-column {
  background: repeating-linear-gradient(-45deg, var(--moving) 0 7px, #ca4d61 7px 12px);
}

.bar-item[data-role="candidate"] .bar-column {
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.26) 25%, transparent 25% 75%, rgba(255, 255, 255, 0.26) 75%),
    var(--candidate);
  background-size: 10px 10px;
}

.bar-item[data-role="sorted"] .bar-column {
  background: repeating-linear-gradient(90deg, var(--sorted) 0 6px, #91c95c 6px 9px);
}

.stage-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding-top: 13px;
  color: #828a9b;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stage-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.compare-stage {
  min-width: 0;
  padding: clamp(15px, 2vw, 22px);
  overflow: hidden;
  border: 1px solid #2a303e;
  border-radius: var(--radius-large);
  color: var(--stage-text);
  background: #151923;
  box-shadow: var(--shadow);
}

.compare-stage-heading {
  min-height: 43px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.compare-stage-heading p,
.compare-stage-heading h3 {
  margin: 0;
}

.compare-stage-heading p {
  color: #858d9f;
  font-family: var(--font-mono);
  font-size: 0.54rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.compare-stage-heading h3 {
  margin-top: 4px;
  font-size: 0.96rem;
}

.compare-stage-heading output {
  color: #9ba3b4;
  font-family: var(--font-mono);
  font-size: 0.62rem;
}

.compare-bars {
  height: clamp(300px, 26vw, 390px);
  display: flex;
  align-items: end;
  gap: clamp(3px, 0.5vw, 7px);
  margin-top: 12px;
  padding: 28px 8px 12px;
  overflow: hidden;
  border: 1px solid #293040;
  border-radius: 15px;
  background:
    linear-gradient(rgba(92, 103, 132, 0.1) 1px, transparent 1px),
    #0c0f16;
  background-size: 100% 25%;
}

.compare-bar {
  height: var(--bar-height);
  min-width: 2px;
  flex: 1 1 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px 5px 2px 2px;
  background: var(--default-bar);
}

.compare-bar[data-role="compare"],
.compare-bar[data-role="focus"] {
  border-color: var(--compare);
  background: repeating-linear-gradient(135deg, var(--compare) 0 5px, #8df5e6 5px 8px);
}

.compare-bar[data-role="moving"],
.compare-bar[data-role="key"] {
  border-color: var(--moving);
  background: repeating-linear-gradient(-45deg, var(--moving) 0 5px, #ca4d61 5px 9px);
}

.compare-bar[data-role="candidate"] {
  border-color: var(--candidate);
  background: var(--candidate);
}

.compare-bar[data-role="sorted"] {
  border-color: var(--sorted);
  background: repeating-linear-gradient(90deg, var(--sorted) 0 5px, #91c95c 5px 8px);
}

.compare-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 12px 0 0;
  overflow: hidden;
  border: 1px solid #303748;
  border-radius: 10px;
}

.compare-metrics div {
  padding: 8px 5px;
  text-align: center;
}

.compare-metrics div + div {
  border-left: 1px solid #303748;
}

.compare-metrics dt {
  color: #7e879a;
  font-size: 0.46rem;
  font-weight: 800;
  text-transform: uppercase;
}

.compare-metrics dd {
  margin: 4px 0 0;
  color: var(--algorithm-accent);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 850;
}

.legend-dot {
  width: 7px;
  height: 7px;
  display: inline-block;
  border-radius: 50%;
  background: var(--default-bar);
}

.legend-dot.compare {
  border-radius: 2px;
  background: repeating-linear-gradient(135deg, var(--compare) 0 3px, #8df5e6 3px 5px);
}

.legend-dot.moving {
  border-radius: 1px 5px 1px 5px;
  background: repeating-linear-gradient(-45deg, var(--moving) 0 3px, #ca4d61 3px 5px);
}

.legend-dot.candidate {
  border-radius: 0;
  background: var(--candidate);
  transform: rotate(45deg);
}

.legend-dot.sorted {
  border-radius: 1px;
  background: repeating-linear-gradient(90deg, var(--sorted) 0 3px, #91c95c 3px 5px);
}

.narration {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 16px;
  margin-top: 14px;
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-medium);
  background: var(--panel);
}

.narration-index {
  width: 45px;
  height: 45px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: var(--ink);
  background: var(--algorithm-accent);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 900;
}

.step-title {
  margin: 1px 0 0;
  font-size: 0.9rem;
  font-weight: 820;
  letter-spacing: -0.015em;
}

.status-copy {
  margin: 5px 0 0;
  color: #4e5059;
  font-size: 0.78rem;
  line-height: 1.45;
}

.step-detail {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.69rem;
  line-height: 1.45;
}

.transport {
  display: grid;
  grid-template-columns: auto minmax(170px, 1fr);
  align-items: center;
  gap: 20px;
  margin-top: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-medium);
  background: rgba(251, 250, 246, 0.8);
}

.transport-buttons {
  display: flex;
  align-items: center;
  gap: 7px;
}

.icon-button,
.play-button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: white;
  font-weight: 800;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    opacity 150ms ease;
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 1rem;
}

.play-button {
  min-width: 124px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-color: var(--ink);
  color: white;
  background: var(--ink);
  font-size: 0.72rem;
}

.play-button span:first-child {
  color: var(--algorithm-accent);
  font-family: var(--font-mono);
}

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

.icon-button:hover:not(:disabled) {
  border-color: var(--ink);
}

.icon-button:disabled {
  opacity: 0.36;
}

.timeline-field {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.timeline-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.timeline-label output {
  color: var(--ink);
  font-family: var(--font-mono);
}

#timeline {
  height: 7px;
  background:
    linear-gradient(
      to right,
      var(--algorithm-accent) 0 var(--timeline-progress),
      var(--paper-deep) var(--timeline-progress) 100%
    );
}

#timeline::-webkit-slider-thumb {
  border-color: var(--algorithm-accent);
}

#timeline::-moz-range-thumb {
  border-color: var(--algorithm-accent);
}

.keyboard-hint {
  margin: 10px 0 0;
  color: #85858b;
  font-size: 0.58rem;
  text-align: center;
}

.keyboard-hint kbd {
  min-width: 20px;
  display: inline-grid;
  place-items: center;
  margin: 0 2px;
  padding: 2px 5px;
  border: 1px solid #cbc8c0;
  border-bottom-width: 2px;
  border-radius: 5px;
  color: #55565d;
  background: #f9f8f4;
  font-family: var(--font-mono);
  font-size: 0.54rem;
}

.learn-panel {
  grid-area: learn;
  position: sticky;
  top: 16px;
}

.algorithm-description {
  margin: 20px 0 0;
  color: #585a62;
  font-size: 0.76rem;
  line-height: 1.58;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 20px 0 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  overflow: hidden;
}

.metrics div {
  min-width: 0;
  padding: 12px 7px;
  text-align: center;
  background: white;
}

.metrics div + div {
  border-left: 1px solid var(--line);
}

.metrics dt {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-overflow: ellipsis;
  text-transform: uppercase;
}

.metrics dd {
  margin: 5px 0 0;
  font-family: var(--font-mono);
  font-size: 1.02rem;
  font-weight: 850;
}

.complexity-card {
  margin-top: 16px;
  padding: 15px;
  border-radius: 14px;
  background: var(--ink);
}

.subheading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.subheading-row h3 {
  margin: 0;
  color: white;
  font-size: 0.75rem;
}

.status-chip {
  padding: 4px 7px;
  border-radius: 999px;
  color: #ffbdc5;
  background: rgba(255, 122, 138, 0.13);
  font-size: 0.53rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-chip[data-positive="true"] {
  color: var(--sorted);
  background: rgba(185, 239, 114, 0.11);
}

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

.complexity-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #303541;
}

.complexity-list div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.complexity-list dt {
  color: #8e95a5;
  font-size: 0.64rem;
}

.complexity-list dd {
  margin: 0;
  color: var(--algorithm-accent);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 800;
}

.property-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 14px;
}

.property-row span {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: white;
  font-size: 0.58rem;
  font-weight: 750;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 4px 0;
  color: var(--muted);
  font-size: 0.64rem;
}

footer > span {
  color: var(--ink);
  font-weight: 850;
}

footer p {
  margin: 0;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--algorithm-accent) 62%, transparent);
  outline-offset: 3px;
}

@keyframes signal {
  from {
    opacity: 0.8;
    transform: scale(0.65);
  }
  to {
    opacity: 0;
    transform: scale(1.55);
  }
}

body[data-focus-mode="true"] .topbar,
body[data-focus-mode="true"] .control-deck,
body[data-focus-mode="true"] .code-panel,
body[data-focus-mode="true"] .learn-panel,
body[data-focus-mode="true"] footer,
body[data-focus-mode="true"] .keyboard-hint {
  display: none;
}

body[data-focus-mode="true"] .app-shell {
  width: min(100%, 1500px);
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

body[data-focus-mode="true"] main {
  padding-top: 0;
}

body[data-focus-mode="true"] .workspace {
  display: block;
  margin-top: 0;
}

body[data-focus-mode="true"] .theater-heading {
  position: sticky;
  z-index: 30;
  top: 0;
  padding: 8px 4px 10px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(14px);
}

body[data-focus-mode="true"] .bars,
body[data-focus-mode="true"] .compare-bars {
  height: clamp(360px, 54vh, 650px);
}

body[data-focus-mode="true"] .transport {
  position: sticky;
  z-index: 25;
  bottom: max(8px, env(safe-area-inset-bottom));
  box-shadow: 0 16px 45px rgba(23, 25, 34, 0.22);
  backdrop-filter: blur(16px);
}

@media (max-width: 1260px) {
  .control-deck {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .deck-index {
    writing-mode: horizontal-tb;
    transform: none;
  }

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

  .control-extras,
  .custom-data-panel {
    grid-column: 1;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-template-areas:
      "theater learn"
      "code code";
  }

  .code-panel,
  .learn-panel {
    position: static;
  }

  .code-panel {
    display: grid;
    grid-template-columns: minmax(200px, 0.62fr) minmax(0, 1.38fr);
    gap: 22px;
    align-items: start;
  }

  .code-panel .pseudocode {
    grid-row: span 2;
    margin-top: 0;
  }

  .code-panel .invariant-card {
    margin-top: 4px;
  }
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .topbar-thesis {
    display: none;
  }

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

  .new-data-button {
    grid-column: 2;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "theater"
      "code"
      "learn";
  }

  .learn-panel {
    display: grid;
    grid-template-columns: minmax(190px, 0.8fr) minmax(320px, 1.2fr);
    gap: 16px 24px;
  }

  .learn-panel .panel-heading,
  .learn-panel .algorithm-description {
    grid-column: 1;
  }

  .learn-panel .algorithm-description {
    margin-top: 0;
  }

  .learn-panel .metrics,
  .learn-panel .complexity-card {
    grid-column: 2;
  }

  .learn-panel .metrics {
    grid-row: 1;
    margin-top: 0;
  }

  .learn-panel .complexity-card {
    grid-row: 2 / span 2;
    margin-top: 0;
  }

  .learn-panel .property-row {
    grid-column: 1;
    margin-top: 0;
  }

  .stage-grid[data-compare="true"] {
    grid-template-columns: 1fr;
  }

  .compare-bars,
  .stage-grid[data-compare="true"] .bars {
    height: clamp(285px, 54vw, 390px);
  }
}

@media (max-width: 660px) {
  .app-shell {
    padding-inline: 12px;
  }

  .topbar {
    min-height: 72px;
  }

  .brand-copy small,
  .source-link span:first-child {
    display: none;
  }

  .source-link {
    width: 38px;
    height: 38px;
    justify-content: center;
    padding: 0;
  }

  .control-deck {
    padding: 17px;
  }

  .deck-heading {
    align-items: flex-start;
  }

  .control-fields {
    grid-template-columns: 1fr;
  }

  .new-data-button {
    grid-column: auto;
  }

  .control-extras {
    align-items: stretch;
  }

  .control-extras .secondary-button,
  .compare-field {
    width: 100%;
  }

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

  .custom-error {
    grid-column: 1;
  }

  .panel {
    padding: 17px;
  }

  .code-panel {
    display: block;
  }

  .code-panel .pseudocode {
    margin-top: 22px;
  }

  .code-panel .invariant-card {
    margin-top: 20px;
  }

  .learn-panel {
    display: block;
  }

  .learn-panel .algorithm-description,
  .learn-panel .metrics,
  .learn-panel .complexity-card,
  .learn-panel .property-row {
    margin-top: 16px;
  }

  .stage-shell {
    padding: 13px;
  }

  .theater-heading-actions {
    gap: 7px;
  }

  .focus-button {
    width: 35px;
    padding: 0;
  }

  .focus-button #focus-label {
    display: none;
  }

  .inspection {
    height: 112px;
  }

  .inspection-equation {
    grid-template-columns: 1fr 25px 1fr;
    gap: 7px;
  }

  .comparison-result {
    grid-column: 1 / -1;
    justify-self: center;
    padding: 5px 12px;
  }

  .bars {
    height: clamp(265px, 78vw, 370px);
    padding-inline: 7px;
  }

  .native-visual,
  .native-visual.compact {
    height: 158px;
  }

  .compare-bars,
  .stage-grid[data-compare="true"] .bars {
    height: clamp(265px, 78vw, 370px);
  }

  .stage-legend {
    gap: 9px;
  }

  .narration {
    grid-template-columns: 40px minmax(0, 1fr);
    align-items: start;
    gap: 12px;
    min-height: 176px;
    padding: 15px;
  }

  .step-title {
    min-height: 2.4em;
  }

  .status-copy,
  .step-detail {
    min-height: 4.35em;
  }

  .narration-index {
    width: 38px;
    height: 38px;
    border-radius: 11px;
  }

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

  body[data-focus-mode="true"] .bars,
  body[data-focus-mode="true"] .compare-bars {
    height: min(42vh, 360px);
  }

  body[data-focus-mode="true"] .narration {
    min-height: 164px;
  }

  .transport-buttons {
    justify-content: center;
  }

  .timeline-field {
    padding-inline: 4px;
  }

  .keyboard-hint {
    line-height: 2;
  }

  footer {
    align-items: flex-start;
  }

  footer p {
    text-align: right;
  }
}

@media (max-width: 410px) {
  .play-button {
    min-width: 105px;
    padding-inline: 10px;
  }

  .icon-button {
    width: 36px;
  }

  .metrics dt {
    font-size: 0.46rem;
  }

  .bar-column {
    right: 5%;
    left: 5%;
  }
}

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

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

.code-heading-tools {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.compact-select select {
  max-width: 118px;
  min-height: 30px;
  padding: 4px 25px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: white;
  font-family: var(--font-mono);
  font-size: 0.58rem;
}

.variable-card,
.lesson-card,
.stability-result {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
}

.variable-card h3,
.lesson-card h3,
.stability-result h3 {
  margin: 0;
  font-size: 0.72rem;
}

.variable-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 12px 0 0;
}

.variable-grid div {
  min-width: 0;
  padding: 8px;
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  border-radius: 9px;
  background: white;
}

.variable-grid dt {
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.49rem;
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.variable-grid dd {
  overflow: hidden;
  margin: 4px 0 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variable-grid div[data-tone="accent"] dd {
  color: color-mix(in srgb, var(--algorithm-accent) 72%, var(--ink));
}

.variable-grid div[data-tone="candidate"] dd {
  color: #a66a00;
}

.call-stack-heading {
  margin-top: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.call-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.call-stack li {
  padding: 5px 7px;
  border-radius: 7px;
  color: var(--muted);
  background: var(--paper);
  font-family: var(--font-mono);
  font-size: 0.53rem;
}

.call-stack li:last-child {
  color: var(--ink);
  background: color-mix(in srgb, var(--algorithm-accent) 18%, white);
}

.race-status {
  min-height: 2.7em;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.62rem;
  line-height: 1.35;
}

.prediction-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 13px 18px;
  margin-top: 12px;
  padding: 16px 18px;
  border: 1px solid color-mix(in srgb, var(--algorithm-accent) 44%, var(--line));
  border-radius: 16px;
  background: color-mix(in srgb, var(--algorithm-accent) 9%, white);
  box-shadow: 0 12px 35px rgba(23, 25, 34, 0.08);
}

.prediction-card h3 {
  margin: 3px 0 0;
  font-size: 1rem;
}

.prediction-card p:not(.panel-kicker) {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.prediction-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.prediction-answer {
  min-width: 70px;
  min-height: 40px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  color: var(--ink);
  background: white;
  font-weight: 850;
}

.prediction-answer:hover,
.prediction-answer:focus-visible {
  color: white;
  background: var(--ink);
}

#prediction-feedback {
  grid-column: 1 / -1;
  min-height: 1em;
  font-size: 0.7rem;
  font-weight: 800;
}

#prediction-feedback[data-correct="true"] {
  color: #327300;
}

#prediction-feedback[data-correct="false"] {
  color: #aa3141;
}

.lesson-card {
  margin-top: 14px;
  background: color-mix(in srgb, var(--algorithm-accent) 7%, white);
}

.lesson-card > p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.67rem;
  line-height: 1.5;
}

#lesson-progress {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 800;
}

.lesson-checkpoints {
  display: grid;
  gap: 7px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.lesson-checkpoints li {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.61rem;
}

.lesson-checkpoints li::before {
  content: "";
  width: 17px;
  height: 17px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: white;
}

.lesson-checkpoints li[data-complete="true"] {
  color: var(--ink);
  font-weight: 750;
}

.lesson-checkpoints li[data-complete="true"]::before {
  content: "✓";
  display: grid;
  place-items: center;
  border-color: color-mix(in srgb, var(--sorted) 70%, var(--ink));
  color: #264f00;
  background: var(--sorted);
  font-size: 0.65rem;
  font-weight: 900;
}

.prediction-score {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.6rem;
}

.prediction-score strong {
  color: var(--ink);
  font-family: var(--font-mono);
}

.stability-result p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.64rem;
  line-height: 1.5;
}

.bar-identity {
  display: inline-grid;
  min-width: 1.25em;
  place-items: center;
  margin-left: 2px;
  border-radius: 4px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  font-family: var(--font-mono);
  font-size: 0.58em;
  font-weight: 900;
}

.footer-button {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: white;
  font-size: 0.62rem;
  font-weight: 800;
}

.lab-dialog {
  width: min(94vw, 900px);
  max-height: min(92vh, 900px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 34px 90px rgba(12, 15, 25, 0.32);
}

.lab-dialog::backdrop {
  background: rgba(9, 12, 19, 0.68);
  backdrop-filter: blur(5px);
}

.compact-dialog {
  width: min(94vw, 660px);
}

.dialog-shell {
  padding: clamp(18px, 3vw, 30px);
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.dialog-heading h2 {
  margin: 5px 0 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
  letter-spacing: -0.04em;
}

.dialog-heading p:not(.panel-kicker) {
  max-width: 660px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.5;
}

.dialog-close {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: white;
  font-size: 1.3rem;
}

.lab-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 12px;
  margin-top: 22px;
}

.complexity-summary {
  min-height: 1.4em;
  margin-top: 17px;
  color: var(--muted);
  font-size: 0.7rem;
}

.complexity-chart {
  width: 100%;
  margin-top: 12px;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}

.chart-grid {
  stroke: #e5e2d9;
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke: var(--algorithm-accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line.comparison {
  stroke: var(--moving);
}

.chart-guide {
  fill: none;
  stroke: #8c93a7;
  stroke-width: 2;
  stroke-dasharray: 6 6;
}

.chart-dot {
  fill: white;
  stroke: var(--algorithm-accent);
  stroke-width: 3;
}

.chart-dot.comparison {
  stroke: var(--moving);
}

.chart-label {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
}

.table-scroll {
  margin-top: 15px;
  overflow-x: auto;
}

.lab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.68rem;
}

.lab-table th,
.lab-table td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.lab-table th:first-child,
.lab-table td:first-child {
  text-align: left;
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 22px;
}

.export-option {
  min-height: 124px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: white;
  text-align: left;
}

.export-option:hover {
  border-color: var(--ink);
  transform: translateY(-2px);
}

.export-option strong {
  font-size: 0.78rem;
}

.export-option span {
  color: var(--muted);
  font-size: 0.62rem;
  line-height: 1.45;
}

.export-status {
  display: block;
  min-height: 1.3em;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.68rem;
}

.quick-three-partitions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.partition-group[data-partition="greater"] {
  border-color: color-mix(in srgb, var(--moving) 45%, var(--stage-line));
}

.strategy-track {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 11px;
}

.strategy-card {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--stage-line);
  border-radius: 10px;
  color: #8d95aa;
  background: #111620;
}

.strategy-card[data-active="true"] {
  border-color: var(--algorithm-accent);
  color: var(--stage-text);
  background: color-mix(in srgb, var(--algorithm-accent) 13%, #111620);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--algorithm-accent) 38%, transparent);
}

.strategy-card strong {
  font-size: 0.7rem;
}

.strategy-card span {
  font-size: 0.5rem;
}

.depth-budget {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 9px 10px;
  overflow: hidden;
  border: 1px solid var(--stage-line);
  border-radius: 9px;
}

.depth-budget::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--depth-progress);
  background: color-mix(in srgb, var(--algorithm-accent) 16%, transparent);
}

.depth-budget > * {
  position: relative;
}

.depth-budget strong {
  color: var(--stage-text);
  font-family: var(--font-mono);
  font-size: 0.65rem;
}

.run-stack {
  display: flex;
  align-items: stretch;
  gap: 7px;
  margin-top: 12px;
  overflow-x: auto;
}

.run-card {
  min-width: 70px;
  flex: var(--run-share) 1 0;
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--stage-line);
  border-radius: 10px;
  color: #8d95aa;
  background: #111620;
}

.run-card[data-active="true"] {
  border-color: var(--algorithm-accent);
  color: var(--stage-text);
}

.run-card strong {
  color: var(--stage-text);
  font-size: 0.68rem;
}

.run-card small {
  font-family: var(--font-mono);
  font-size: 0.5rem;
}

.native-empty {
  margin: 14px 0 0;
  color: #8d95aa;
  font-size: 0.65rem;
}

.value-buckets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.value-bucket {
  min-width: 0;
  padding: 7px;
  border: 1px solid var(--stage-line);
  border-radius: 9px;
  background: #111620;
}

.value-bucket[data-active="true"] {
  border-color: var(--algorithm-accent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--algorithm-accent) 22%, transparent);
}

.network-lanes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(32px, 1fr));
  gap: 5px;
  margin-top: 12px;
}

.network-lane {
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 7px 3px;
  border: 1px solid var(--stage-line);
  border-radius: 8px;
  color: #8d95aa;
  background: #111620;
}

.network-lane[data-active="true"] {
  border-color: var(--compare);
  color: var(--stage-text);
  background: color-mix(in srgb, var(--compare) 13%, #111620);
}

.network-lane small {
  font-family: var(--font-mono);
  font-size: 0.46rem;
}

.network-lane strong {
  font-size: 0.62rem;
}

@media (max-width: 1260px) {
  .code-panel .variable-card {
    margin-top: 4px;
  }

  .code-panel .panel-heading {
    grid-column: 1;
  }
}

@media (max-width: 920px) {
  .learn-panel .lesson-card,
  .learn-panel .stability-result {
    grid-column: 1;
  }
}

@media (max-width: 660px) {
  .code-heading-tools {
    max-width: 120px;
  }

  .variable-card,
  .lesson-card,
  .stability-result {
    margin-top: 16px;
  }

  .prediction-card {
    grid-template-columns: 1fr;
    padding: 15px;
  }

  .prediction-actions {
    width: 100%;
  }

  .prediction-answer {
    flex: 1;
  }

  #prediction-feedback {
    grid-column: 1;
  }

  .lab-controls,
  .export-grid {
    grid-template-columns: 1fr;
  }

  .lab-controls .new-data-button {
    grid-column: 1;
  }

  .export-option {
    min-height: 88px;
  }

  .dialog-shell {
    padding: 17px;
  }

  footer {
    flex-wrap: wrap;
  }

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

  .strategy-card {
    padding: 8px 5px;
  }

  .network-lanes {
    grid-template-columns: repeat(8, minmax(25px, 1fr));
  }
}
