/* =========================================================
   SORT/CODE LAB — C sorting algorithm visual companion
   Visual system: dark instrument panel, phosphor accents
   ========================================================= */

:root {
  --bg: #070a0b;
  --bg-deep: #050708;
  --panel: rgba(11, 17, 17, 0.88);
  --panel-solid: #0c1212;
  --panel-raised: #101818;
  --panel-soft: rgba(17, 25, 24, 0.62);
  --line: rgba(201, 231, 213, 0.115);
  --line-mid: rgba(201, 231, 213, 0.2);
  --line-strong: rgba(201, 231, 213, 0.34);
  --text: #eef4e9;
  --text-soft: #c9d4c9;
  --muted: #84938b;
  --faint: #5a6861;
  --acid: #c9ff72;
  --acid-deep: #89b84d;
  --mint: #7ef3c5;
  --amber: #ffc477;
  --coral: #ff8f78;
  --violet: #c5a9ff;
  --blue: #8bc9ff;
  --danger: #ff786c;
  --font-display: "Bahnschrift", "DIN Alternate", "Arial Narrow", "Microsoft YaHei", sans-serif;
  --font-body: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "Cascadia Code", "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  --font-code: Consolas, "Cascadia Mono", "SFMono-Regular", "Liberation Mono", monospace;
  --radius: 3px;
  --shadow-panel: 0 18px 60px rgba(0, 0, 0, 0.28);
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 46% -10%, rgba(81, 137, 96, 0.09), transparent 62%),
    radial-gradient(1000px 900px at 105% 35%, rgba(55, 89, 82, 0.08), transparent 60%),
    var(--bg);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overflow-x: clip;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 1px solid var(--acid);
  outline-offset: 3px;
}

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

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  margin: 0;
  padding: 0;
}

p,
h1,
h2,
h3 {
  margin: 0;
}

::selection {
  color: #0a100c;
  background: var(--acid);
}

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

/* ---------- atmosphere ---------- */

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.atmosphere-grid {
  position: absolute;
  inset: 0;
  opacity: 0.45;
  background-image:
    linear-gradient(rgba(173, 206, 184, 0.032) 1px, transparent 1px),
    linear-gradient(90deg, rgba(173, 206, 184, 0.032) 1px, transparent 1px);
  background-size: 76px 76px;
  mask-image: radial-gradient(ellipse at 50% 40%, black, transparent 82%);
}

.atmosphere-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
}

.atmosphere-glow-a {
  width: 560px;
  height: 560px;
  left: -220px;
  top: 24%;
  background: radial-gradient(circle, rgba(166, 226, 112, 0.055), transparent 66%);
}

.atmosphere-glow-b {
  width: 720px;
  height: 720px;
  right: -260px;
  top: -100px;
  background: radial-gradient(circle, rgba(100, 220, 177, 0.045), transparent 65%);
}

.noise {
  position: absolute;
  inset: 0;
  opacity: 0.15;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.23'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.035) 0,
    rgba(0, 0, 0, 0.035) 1px,
    transparent 1px,
    transparent 4px
  );
  opacity: 0.6;
}

/* ---------- topbar ---------- */

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: 68px;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(6, 9, 10, 0.78);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-mid);
  border-radius: 50%;
  color: var(--acid);
  transition: border-color 180ms ease, transform 220ms ease;
}

.brand:hover .brand-mark {
  border-color: var(--acid);
  transform: rotate(-5deg);
}

.brand-mark svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-copy strong {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.055em;
  line-height: 1;
}

.brand-copy span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.16em;
}

.topbar-mode {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  white-space: nowrap;
}

.topbar-mode i {
  width: 1px;
  height: 10px;
  background: var(--line-mid);
}

.live-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--acid);
  box-shadow: 0 0 10px rgba(201, 255, 114, 0.7);
  animation: livePulse 3s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-left: auto;
}

.topbar-location {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.12em;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line-mid);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-soft);
  font-size: 11px;
  transition: border-color 180ms ease, color 180ms ease, background 180ms ease;
}

.ghost-button:hover {
  border-color: var(--acid);
  color: var(--text);
  background: rgba(201, 255, 114, 0.04);
}

.ghost-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
}

.sound-toggle .sound-off {
  display: none;
}

.sound-toggle.is-muted .sound-on {
  display: none;
}

.sound-toggle.is-muted .sound-off {
  display: block;
}

.sound-toggle.is-muted {
  color: var(--faint);
}

.sound-toggle.is-muted:hover {
  color: var(--text-soft);
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border: 1px solid var(--line-mid);
  border-bottom-color: var(--line-strong);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8px;
  line-height: 1;
}

/* ---------- app grid ---------- */

.app {
  position: relative;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 382px;
  align-items: start;
  gap: 18px;
  width: min(100%, 1780px);
  margin: 0 auto;
  padding: 22px 26px 28px;
}

/* ---------- shared type ---------- */

.eyebrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 400;
  letter-spacing: 0.15em;
  line-height: 1.3;
  text-transform: uppercase;
}

.accent-dot {
  color: var(--acid);
}

/* ---------- sidebar ---------- */

.sidebar {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 4px 0 0;
}

.side-heading h2 {
  margin: 14px 0 9px;
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.16;
}

.side-heading > p {
  max-width: 245px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

.algorithm-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}

.algo-item {
  position: relative;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 10px 11px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  text-align: left;
  transition: color 180ms ease, background 180ms ease, padding 180ms ease;
}

.algo-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 2px;
  height: 0;
  background: var(--acid);
  transform: translateY(-50%);
  transition: height 200ms var(--ease-out);
}

.algo-item:hover {
  color: var(--text);
  background: rgba(201, 255, 114, 0.025);
}

.algo-item.is-active {
  color: var(--text);
  background: linear-gradient(90deg, rgba(201, 255, 114, 0.075), transparent 82%);
  padding-left: 12px;
}

.algo-item.is-active::before {
  height: 26px;
}

.algo-number {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.08em;
}

.algo-item.is-active .algo-number {
  color: var(--acid);
}

.algo-item-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.algo-item-name strong {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.algo-item-name span {
  overflow: hidden;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.12em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.algo-item.is-active .algo-item-name span {
  color: var(--muted);
}

.algo-badge {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.04em;
  text-align: right;
  white-space: nowrap;
}

.algo-item.is-active .algo-badge {
  color: var(--mint);
}

/* ---------- data panel ---------- */

.data-panel {
  position: relative;
  padding: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(17, 25, 23, 0.8), rgba(8, 13, 13, 0.5));
}

.data-panel::before,
.data-panel::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  border-color: var(--line-strong);
  border-style: solid;
}

.data-panel::before {
  left: -1px;
  top: -1px;
  border-width: 1px 0 0 1px;
}

.data-panel::after {
  right: -1px;
  bottom: -1px;
  border-width: 0 1px 1px 0;
}

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

.panel-heading h3 {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.data-length {
  color: var(--acid);
  font-family: var(--font-mono);
  font-size: 8px;
}

.array-field {
  display: flex;
  gap: 5px;
}

.array-preview {
  display: none;
}

.array-field input {
  min-width: 0;
  width: 100%;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line-mid);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.24);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.03em;
  transition: border-color 180ms ease, background 180ms ease;
}

.array-field input:hover,
.array-field input:focus {
  border-color: var(--line-strong);
  background: rgba(0, 0, 0, 0.35);
}

.array-field input.is-error {
  border-color: var(--danger);
}

.apply-button {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(201, 255, 114, 0.4);
  border-radius: 2px;
  background: rgba(201, 255, 114, 0.11);
  color: var(--acid);
  font-size: 10px;
  transition: background 180ms ease, color 180ms ease;
}

.apply-button:hover {
  background: var(--acid);
  color: #101a0b;
}

.field-hint {
  margin-top: 7px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.06em;
}

.field-hint.is-error {
  color: var(--danger);
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 12px;
}

.preset-button {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-size: 8px;
  transition: border-color 160ms ease, color 160ms ease;
}

.preset-button:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.shuffle-button {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  margin-top: 11px;
  padding: 8px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 9px;
  text-align: left;
  transition: color 160ms ease;
}

.shuffle-button:hover {
  color: var(--acid);
}

.shuffle-button svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
}

.shuffle-button span {
  flex: 1;
}

.keyboard-note {
  display: grid;
  gap: 6px;
  padding-top: 2px;
}

.keyboard-note .eyebrow {
  justify-content: flex-start;
  margin-bottom: 3px;
}

.keyboard-note > div {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--faint);
  font-size: 8px;
}

.keyboard-note > div span {
  margin-left: 4px;
}

/* ---------- workspace ---------- */

.workspace {
  min-width: 0;
}

.algo-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 18px;
  border-bottom: 1px solid var(--line);
}

.algo-heading {
  flex: 1 1 420px;
  min-width: 0;
}

.algo-title-line {
  display: flex;
  align-items: flex-start;
  gap: 13px;
}

.algo-index {
  color: var(--acid);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.09em;
  line-height: 1.8;
  padding-top: 4px;
}

.algo-en {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  line-height: 1.2;
}

.algo-title-line h1 {
  margin-top: 2px;
  font-family: var(--font-display);
  font-size: clamp(38px, 3.7vw, 58px);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1;
}

.algo-summary {
  max-width: 620px;
  margin-top: 13px;
  padding-left: 34px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.algo-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
  max-width: 345px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.meta-chip b {
  color: var(--text-soft);
  font-weight: 500;
}

.meta-chip.is-accent {
  border-color: rgba(201, 255, 114, 0.26);
  color: var(--acid);
}

.meta-chip.is-accent b {
  color: var(--acid);
}

/* ---------- stage ---------- */

.stage-panel {
  position: relative;
  margin-top: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(150deg, rgba(15, 23, 22, 0.86), rgba(7, 11, 12, 0.76));
  box-shadow: var(--shadow-panel);
}

.stage-panel::before {
  content: "";
  position: absolute;
  pointer-events: none;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 0%, rgba(140, 219, 163, 0.05), transparent 58%);
}

.stage-topline {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 43px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.phase-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 128px;
  color: var(--acid);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.phase-spark {
  width: 5px;
  height: 5px;
  border: 1px solid var(--acid);
  transform: rotate(45deg);
  box-shadow: 0 0 9px rgba(201, 255, 114, 0.4);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.04em;
}

.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.legend-dot {
  width: 5px;
  height: 5px;
  border-radius: 1px;
  background: var(--muted);
}

.legend-dot.is-default { background: #77847e; }
.legend-dot.is-compare { background: var(--amber); }
.legend-dot.is-swap { background: var(--coral); }
.legend-dot.is-pivot { background: var(--violet); }
.legend-dot.is-sorted { background: var(--acid); }

.stage-metrics {
  display: flex;
  align-items: center;
  gap: 13px;
}

.stage-metrics > span {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.stage-metrics b {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
}

.stage-metrics small {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
}

.stage {
  position: relative;
  z-index: 2;
  height: clamp(330px, 38vh, 445px);
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(4, 7, 7, 0.25), rgba(3, 6, 6, 0.42)),
    repeating-linear-gradient(90deg, transparent 0, transparent 59px, rgba(196, 231, 208, 0.026) 60px);
}

.gridlines {
  position: absolute;
  inset: 42px 17px 31px 30px;
  pointer-events: none;
}

.gridlines span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--line);
  border-top: 1px dashed rgba(188, 222, 201, 0.08);
}

.y-axis {
  position: absolute;
  left: 7px;
  top: 52px;
  bottom: 31px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  text-align: right;
  opacity: 0.6;
}

.stage-caption {
  position: absolute;
  top: 12px;
  right: 18px;
  left: 34px;
  z-index: 4;
  overflow: hidden;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.02em;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.bar-plot {
  position: absolute;
  left: 30px;
  right: 18px;
  top: 36px;
  bottom: 29px;
  display: flex;
  align-items: stretch;
  gap: 2px;
  transition: bottom 260ms var(--ease-out);
}

.bar-slot {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 1px;
  transition: background 180ms ease;
}

.bar-slot.is-in-range {
  background: linear-gradient(180deg, rgba(201, 255, 114, 0.038), transparent 60%);
}

.bar-slot.is-in-range::before {
  content: "";
  position: absolute;
  top: 0;
  left: 1px;
  right: 1px;
  height: 1px;
  background: rgba(201, 255, 114, 0.2);
}

.bar-value {
  position: relative;
  z-index: 2;
  margin-bottom: 5px;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: clamp(8px, 0.72vw, 10px);
  line-height: 1;
  transition: color 160ms ease, transform 160ms ease;
}

.bar {
  position: relative;
  width: min(74%, 38px);
  height: var(--h, 20%);
  min-height: 9px;
  border: 1px solid rgba(208, 235, 218, 0.18);
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
  background:
    linear-gradient(180deg, rgba(205, 224, 208, 0.7), rgba(96, 112, 102, 0.8) 45%, rgba(45, 56, 52, 0.9));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.025),
    0 8px 22px rgba(0, 0, 0, 0.16);
  transform-origin: 50% 100%;
  transition:
    height 300ms var(--ease-out),
    background 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease;
}

.bar::after {
  content: "";
  position: absolute;
  left: 15%;
  right: 15%;
  top: 4px;
  height: 1px;
  background: rgba(255, 255, 255, 0.25);
  opacity: 0.55;
}

.bar-slot.is-in-range .bar {
  border-color: rgba(201, 255, 114, 0.2);
}

.bar-slot.is-compare .bar {
  border-color: rgba(255, 196, 119, 0.72);
  background: linear-gradient(180deg, #ffe1a8, #d48c42 68%, #8c562e);
  box-shadow: 0 0 18px rgba(255, 196, 119, 0.16), inset 0 0 0 1px rgba(255, 244, 211, 0.08);
  animation: barCompare 900ms ease-in-out infinite;
}

.bar-slot.is-compare .bar-value {
  color: var(--amber);
}

@keyframes barCompare {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.12); }
}

.bar-slot.is-swap .bar {
  border-color: rgba(255, 143, 120, 0.82);
  background: linear-gradient(180deg, #ffb7a4, #d55d4c 62%, #833d34);
  box-shadow: 0 0 22px rgba(255, 143, 120, 0.2), inset 0 0 0 1px rgba(255, 220, 211, 0.1);
  animation: barSwap 620ms var(--ease-out) 1;
}

.bar-slot.is-swap .bar-value {
  color: var(--coral);
}

@keyframes barSwap {
  0% { transform: translateY(0) scaleX(1); }
  38% { transform: translateY(-5px) scaleX(1.04); }
  100% { transform: translateY(0) scaleX(1); }
}

.bar-slot.is-pivot .bar {
  border-color: rgba(197, 169, 255, 0.8);
  background: linear-gradient(180deg, #e0d1ff, #9d80df 65%, #5e4d8d);
  box-shadow: 0 0 22px rgba(197, 169, 255, 0.18);
}

.bar-slot.is-pivot .bar-value {
  color: var(--violet);
}

.bar-slot.is-key .bar {
  border-color: rgba(139, 201, 255, 0.75);
  background: linear-gradient(180deg, #c3e7ff, #679fc9 64%, #3a5a75);
  box-shadow: 0 0 18px rgba(139, 201, 255, 0.16);
}

.bar-slot.is-key .bar-value {
  color: var(--blue);
}

.bar-slot.is-sorted .bar {
  border-color: rgba(201, 255, 114, 0.44);
  background: linear-gradient(180deg, rgba(218, 255, 162, 0.88), rgba(132, 177, 83, 0.9) 62%, rgba(70, 99, 49, 0.95));
  box-shadow: 0 0 16px rgba(201, 255, 114, 0.09);
}

.bar-slot.is-sorted .bar-value {
  color: var(--acid);
}

.bar-slot.is-dim .bar {
  opacity: 0.45;
}

.bar-slot.is-active .bar-value {
  color: var(--text);
}

.bar-slot.is-write .bar {
  animation: barWrite 500ms var(--ease-out) 1;
}

@keyframes barWrite {
  0% { transform: translateY(-4px); opacity: 0.55; }
  100% { transform: translateY(0); opacity: 1; }
}

.pointer-row {
  position: absolute;
  left: 30px;
  right: 18px;
  bottom: 27px;
  z-index: 4;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 20px;
  pointer-events: none;
}

.pointer-slot {
  position: relative;
  flex: 1 1 0;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.pointer {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 2px 4px;
  border: 1px solid rgba(201, 255, 114, 0.35);
  border-radius: 2px;
  background: #111b14;
  color: var(--acid);
  font-family: var(--font-mono);
  font-size: 7px;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
}

.pointer::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 50%;
  width: 1px;
  height: 4px;
  background: rgba(201, 255, 114, 0.5);
}

.pointer.is-j {
  border-color: rgba(255, 196, 119, 0.46);
  color: var(--amber);
}

.pointer.is-pivot {
  border-color: rgba(197, 169, 255, 0.5);
  color: var(--violet);
}

.pointer.is-key {
  border-color: rgba(139, 201, 255, 0.5);
  color: var(--blue);
}

.axis-row {
  position: absolute;
  left: 30px;
  right: 18px;
  bottom: 8px;
  z-index: 3;
  display: flex;
  gap: 2px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  text-align: center;
}

.axis-slot {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}

/* auxiliary temp array for merge sort */

.aux-panel {
  position: absolute;
  left: 34px;
  right: 18px;
  bottom: 47px;
  z-index: 5;
  padding: 7px 8px 8px;
  border: 1px solid rgba(139, 201, 255, 0.18);
  background: rgba(6, 13, 16, 0.72);
  backdrop-filter: blur(4px);
}

.aux-title,
.tree-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 5px;
  color: var(--blue);
  font-family: var(--font-mono);
  font-size: 6px;
  letter-spacing: 0.12em;
}

.aux-title small,
.tree-title small {
  color: var(--faint);
  font-family: var(--font-body);
  font-size: 8px;
  letter-spacing: 0;
}

.aux-cells {
  display: flex;
  gap: 2px;
}

.aux-cell {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1 1 0;
  min-width: 0;
  height: 27px;
  border: 1px solid rgba(139, 201, 255, 0.14);
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1;
}

.aux-cell.is-written {
  border-color: rgba(139, 201, 255, 0.55);
  background: rgba(139, 201, 255, 0.1);
  color: var(--blue);
}

.aux-cell.is-source {
  border-color: rgba(255, 196, 119, 0.4);
  color: var(--amber);
}

.stage.has-aux .bar-plot {
  bottom: 132px;
}

.stage.has-aux .pointer-row {
  bottom: 119px;
}

.stage.has-aux .gridlines {
  bottom: 132px;
}

.stage.has-aux .y-axis {
  bottom: 132px;
}

.stage.has-aux .stage-caption {
  max-width: 58%;
}

/* heap tree */

.tree-panel {
  position: absolute;
  left: 34px;
  right: 18px;
  bottom: 43px;
  z-index: 5;
  padding: 7px 8px 5px;
  border: 1px solid rgba(197, 169, 255, 0.16);
  background: rgba(10, 10, 17, 0.78);
  backdrop-filter: blur(4px);
}

.tree-panel svg {
  display: block;
  width: 100%;
  height: 86px;
  overflow: visible;
}

.tree-edge {
  stroke: rgba(197, 169, 255, 0.28);
  stroke-width: 1.1;
}

.tree-node circle {
  fill: #10131a;
  stroke: rgba(197, 169, 255, 0.28);
  stroke-width: 1;
}

.tree-node text {
  fill: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 8.8px;
  font-weight: 500;
  text-anchor: middle;
  dominant-baseline: central;
}

.tree-node.is-active circle,
.tree-node.is-active text {
  fill: var(--violet);
}

.tree-node.is-active text {
  fill: #171022;
}

.tree-node.is-compare circle {
  stroke: var(--amber);
  stroke-width: 1.4;
}

.stage.has-tree .bar-plot {
  bottom: 158px;
}

.stage.has-tree .pointer-row {
  bottom: 145px;
}

.stage.has-tree .gridlines {
  bottom: 158px;
}

.stage.has-tree .y-axis {
  bottom: 158px;
}

/* ---------- transport ---------- */

.transport {
  position: relative;
  z-index: 4;
  padding: 12px 16px 13px;
  border-top: 1px solid var(--line);
  background: rgba(8, 13, 13, 0.52);
}

.timeline-row {
  display: flex;
  align-items: center;
  gap: 13px;
}

.step-counter {
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.step-counter span:first-child {
  color: var(--muted);
}

.step-counter b {
  color: var(--acid);
  font-size: 11px;
  font-weight: 500;
}

.step-counter em {
  color: var(--faint);
  font-style: normal;
}

.timeline-wrap {
  position: relative;
  flex: 1 1 auto;
  height: 22px;
  display: flex;
  align-items: center;
}

.timeline-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  overflow: hidden;
  background: rgba(201, 231, 213, 0.12);
}

.timeline-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--acid);
  box-shadow: 0 0 9px rgba(201, 255, 114, 0.5);
  transition: width 140ms linear;
}

#timeline {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 22px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: ew-resize;
}

#timeline::-webkit-slider-runnable-track {
  height: 22px;
  background: transparent;
}

#timeline::-webkit-slider-thumb {
  appearance: none;
  width: 7px;
  height: 15px;
  margin-top: 3px;
  border: 1px solid #eaffc6;
  border-radius: 1px;
  background: var(--acid);
  box-shadow: 0 0 7px rgba(201, 255, 114, 0.4);
}

#timeline::-moz-range-track {
  height: 22px;
  background: transparent;
}

#timeline::-moz-range-thumb {
  width: 7px;
  height: 15px;
  border: 1px solid #eaffc6;
  border-radius: 1px;
  background: var(--acid);
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  white-space: nowrap;
}

.speed-control input {
  width: 58px;
  height: 18px;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.speed-control input::-webkit-slider-runnable-track {
  height: 1px;
  background: var(--line-mid);
}

.speed-control input::-webkit-slider-thumb {
  appearance: none;
  width: 5px;
  height: 9px;
  margin-top: -4px;
  border-radius: 1px;
  background: var(--muted);
}

.speed-control input::-moz-range-track {
  height: 1px;
  background: var(--line-mid);
}

.speed-control input::-moz-range-thumb {
  width: 5px;
  height: 9px;
  border: 0;
  border-radius: 1px;
  background: var(--muted);
}

.speed-control b {
  min-width: 24px;
  color: var(--text-soft);
  font-weight: 500;
}

.transport-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
}

.button-cluster {
  display: flex;
  align-items: center;
  gap: 5px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 33px;
  height: 33px;
  padding: 0;
  border: 1px solid var(--line-mid);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.015);
  color: var(--muted);
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.icon-button:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(201, 255, 114, 0.045);
}

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

.icon-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button.small {
  width: 26px;
  height: 26px;
}

.icon-button.small svg {
  width: 12px;
  height: 12px;
}

.play-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 33px;
  padding: 0 13px;
  border: 1px solid rgba(201, 255, 114, 0.58);
  border-radius: 2px;
  background: var(--acid);
  color: #121c0c;
  font-size: 10px;
  font-weight: 600;
  transition: background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.play-button:hover {
  background: #dcffa1;
  box-shadow: 0 0 22px rgba(201, 255, 114, 0.14);
}

.play-button:active {
  transform: translateY(1px);
}

.play-button svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
  stroke: none;
}

.play-button .icon-pause {
  display: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.play-button.is-playing .icon-play {
  display: none;
}

.play-button.is-playing .icon-pause {
  display: block;
}

.transport-hint {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.02em;
}

.hint-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 5px rgba(126, 243, 197, 0.4);
}

/* ---------- learning cards ---------- */

.learning-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.27fr) minmax(0, 0.73fr);
  gap: 16px;
  margin-top: 16px;
}

.step-card,
.mental-card {
  position: relative;
  min-height: 235px;
  padding: 17px;
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(14, 21, 20, 0.86), rgba(8, 12, 12, 0.7));
}

.step-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 17px;
  width: 55px;
  height: 1px;
  background: var(--acid);
  opacity: 0.6;
}

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

.card-heading h2 {
  margin-top: 5px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.card-heading.compact {
  margin-bottom: 10px;
}

.card-heading.compact h2 {
  font-size: 13px;
}

.step-chip {
  flex: 0 0 auto;
  padding: 4px 6px;
  border: 1px solid rgba(201, 255, 114, 0.26);
  border-radius: 2px;
  color: var(--acid);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.1em;
}

.step-note {
  min-height: 42px;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.72;
}

.why-block {
  margin-top: 14px;
  padding: 10px 11px;
  border-left: 1px solid rgba(201, 255, 114, 0.45);
  background: rgba(201, 255, 114, 0.035);
}

.why-label {
  display: block;
  margin-bottom: 4px;
  color: var(--acid);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.12em;
}

.why-block p {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

.watch-block {
  margin-top: 14px;
}

.watch-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin-top: 7px;
}

.watch-item {
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.12);
}

.watch-item span {
  display: block;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.06em;
}

.watch-item b {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.watch-item.is-accent {
  border-color: rgba(201, 255, 114, 0.22);
}

.watch-item.is-accent b {
  color: var(--acid);
}

.watch-empty {
  grid-column: 1 / -1;
  padding: 8px 0;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 8px;
}

.mental-card {
  background:
    radial-gradient(120% 130% at 100% 0%, rgba(126, 243, 197, 0.04), transparent 58%),
    linear-gradient(145deg, rgba(12, 19, 18, 0.9), rgba(8, 12, 12, 0.72));
}

.mental-glyph {
  width: 28px;
  height: 28px;
  color: var(--faint);
}

.mental-glyph svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 0.8;
  opacity: 0.7;
}

.invariant {
  min-height: 47px;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.7;
}

.takeaway-block {
  margin-top: 14px;
}

.takeaway-block ul {
  display: grid;
  gap: 5px;
  margin-top: 7px;
  list-style: none;
}

.takeaway-block li {
  position: relative;
  padding-left: 12px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.takeaway-block li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  width: 3px;
  height: 3px;
  border: 1px solid var(--acid-deep);
  transform: rotate(45deg);
}

.complexity-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 14px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}

.complexity-strip span {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
}

.complexity-strip b {
  margin-left: 3px;
  color: var(--text-soft);
  font-weight: 500;
}

/* ---------- code rail ---------- */

.code-rail {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.code-panel {
  position: relative;
  border: 1px solid var(--line);
  background: #090e0e;
  box-shadow: var(--shadow-panel);
}

.code-panel::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(201, 255, 114, 0.32), transparent);
  opacity: 0.45;
}

.code-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 15px 10px;
}

.code-heading h2 {
  margin-top: 5px;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.code-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.c-badge {
  padding: 3px 5px;
  border: 1px solid rgba(139, 201, 255, 0.3);
  color: var(--blue);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.08em;
}

.code-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 15px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.06em;
}

#activeLineLabel {
  color: var(--acid);
}

.code-scroll {
  max-height: 530px;
  overflow: auto;
  scrollbar-color: rgba(201, 231, 213, 0.22) transparent;
  scrollbar-width: thin;
}

.code-scroll::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.code-scroll::-webkit-scrollbar-thumb {
  background: rgba(201, 231, 213, 0.2);
}

.code-view {
  margin: 0;
  padding: 8px 0 12px;
  counter-reset: code-line;
  font-family: var(--font-code);
  font-size: 11px;
  line-height: 1.65;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0, "dlig" 0;
  tab-size: 4;
  white-space: pre;
}

.code-line {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(max-content, 1fr);
  min-width: max-content;
  padding: 1px 15px 1px 0;
  border-left: 1px solid transparent;
  color: #c0ccc1;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.code-line:hover {
  background: rgba(201, 255, 114, 0.035);
}

.code-line.is-active {
  border-left-color: var(--acid);
  background: linear-gradient(90deg, rgba(201, 255, 114, 0.09), rgba(201, 255, 114, 0.025));
}

.code-line.is-active .line-number {
  color: var(--acid);
}

.line-number {
  padding-right: 9px;
  color: #4f5d56;
  font-size: 8px;
  text-align: right;
  user-select: none;
}

.line-code {
  padding-left: 9px;
  border-left: 1px solid rgba(201, 231, 213, 0.065);
}

.code-line.is-active .line-code {
  border-left-color: rgba(201, 255, 114, 0.26);
}

.tok-comment { color: #54665c; font-style: italic; }
.tok-preproc { color: #b6a3de; }
.tok-keyword { color: #d5ff86; }
.tok-type { color: #8bc9ff; }
.tok-number { color: #ffc477; }
.tok-string { color: #9fe0bf; }
.tok-op { color: #c0aacb; }
.tok-fn { color: #d8e9da; }

.code-footer {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.03em;
}

.pulse-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 8px rgba(126, 243, 197, 0.55);
}

.code-footer span:nth-child(3) {
  margin-left: auto;
}

.code-notes,
.legend-card {
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(11, 17, 17, 0.65);
}

.note-index {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
}

#codeTips {
  display: grid;
  gap: 9px;
  list-style: none;
}

#codeTips li {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 7px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.55;
}

#codeTips li span {
  color: var(--acid-deep);
  font-family: var(--font-mono);
  font-size: 7px;
}

#codeTips strong {
  display: block;
  margin-bottom: 1px;
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 500;
}

.legend-card .eyebrow {
  margin-bottom: 10px;
}

.protocol-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(201, 231, 213, 0.055);
  color: var(--muted);
  font-size: 9px;
}

.protocol-row code {
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 8px;
}

.legend-card > p {
  margin-top: 9px;
  color: var(--faint);
  font-size: 9px;
  line-height: 1.6;
}

/* ---------- footer ---------- */

.site-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(100%, 1780px);
  margin: 0 auto;
  padding: 0 26px 28px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.04em;
}

.footer-rule {
  flex: 0 0 35px;
  height: 1px;
  background: var(--line-mid);
}

.footer-version {
  margin-left: auto;
}

/* ---------- guide modal ---------- */

.guide-modal {
  width: min(calc(100% - 36px), 970px);
  max-height: calc(100vh - 36px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-mid);
  border-radius: 2px;
  background: transparent;
  color: var(--text);
  box-shadow: 0 35px 120px rgba(0, 0, 0, 0.75);
  overflow: auto;
}

.guide-modal::backdrop {
  background: rgba(2, 5, 5, 0.78);
  backdrop-filter: blur(9px);
}

.guide-modal[open] {
  animation: modalIn 260ms var(--ease-out);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.guide-sheet {
  padding: 23px;
  background:
    radial-gradient(90% 80% at 100% 0%, rgba(126, 243, 197, 0.05), transparent 55%),
    #0a1010;
}

.guide-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.guide-top .eyebrow {
  justify-content: flex-start;
}

.guide-sheet h2 {
  margin-top: 17px;
  font-family: var(--font-display);
  font-size: clamp(32px, 4vw, 52px);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.guide-lead {
  max-width: 680px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.75;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin-top: 22px;
  border: 1px solid var(--line);
  background: var(--line);
}

.guide-grid article {
  min-height: 140px;
  padding: 16px;
  background: #0c1312;
}

.guide-grid article > span {
  color: var(--acid);
  font-family: var(--font-mono);
  font-size: 8px;
}

.guide-grid h3 {
  margin-top: 12px;
  font-size: 14px;
  font-weight: 500;
}

.guide-grid p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.65;
}

.guide-key {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 7px;
}

.guide-sfx {
  margin-top: 10px !important;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--faint) !important;
  font-size: 9px !important;
  line-height: 1.55;
}

.guide-sfx kbd {
  min-width: 15px;
  height: 15px;
  font-size: 7px;
}

.guide-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 18px;
  margin-top: 17px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 8px;
}

.guide-shortcuts span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.guide-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.guide-footer > span {
  color: var(--faint);
  font-size: 9px;
}

.start-button {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  padding: 9px 14px;
  border: 1px solid var(--acid);
  background: var(--acid);
  color: #111a0d;
  font-size: 11px;
  font-weight: 600;
  transition: background 160ms ease;
}

.start-button:hover {
  background: #ddffa5;
}

.start-button span {
  font-family: var(--font-mono);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  right: 24px;
  bottom: 22px;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(calc(100vw - 36px), 380px);
  padding: 9px 12px;
  border: 1px solid var(--line-mid);
  background: rgba(12, 19, 17, 0.95);
  color: var(--text-soft);
  font-size: 10px;
  line-height: 1.4;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-error {
  border-color: rgba(255, 120, 108, 0.45);
}

.toast-dot {
  flex: 0 0 auto;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--acid);
}

.toast.is-error .toast-dot {
  background: var(--danger);
}

body.guide-open {
  overflow: hidden;
}

/* ---------- responsive ---------- */

@media (max-width: 1500px) {
  .app {
    grid-template-columns: 248px minmax(0, 1fr) 360px;
    gap: 15px;
    padding-right: 20px;
    padding-left: 20px;
  }

  .site-footer {
    padding-right: 20px;
    padding-left: 20px;
  }

  .algo-meta {
    max-width: 300px;
  }

  .stage-topline {
    gap: 9px;
  }

  .legend {
    gap: 7px;
  }
}

@media (max-width: 1280px) {
  .app {
    grid-template-columns: 232px minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 14px;
  }

  .code-rail {
    position: static;
    grid-column: 2;
    display: grid;
    grid-template-columns: minmax(0, 1.18fr) minmax(270px, 0.82fr);
    align-items: start;
  }

  .code-panel {
    grid-row: span 2;
  }

  .code-scroll {
    max-height: 470px;
  }

  .legend-card {
    min-height: 0;
  }

  .site-footer {
    padding-top: 0;
  }
}

@media (max-width: 1080px) {
  .app {
    grid-template-columns: 216px minmax(0, 1fr);
  }

  .side-heading h2 {
    font-size: 24px;
  }

  .algo-summary {
    padding-left: 0;
  }

  .algo-meta {
    justify-content: flex-start;
    max-width: none;
  }

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

  .step-card,
  .mental-card {
    min-height: 0;
  }

  .code-rail {
    grid-template-columns: 1fr;
  }

  .code-panel {
    grid-row: auto;
  }

  .code-notes {
    display: none;
  }

  .legend-card {
    display: none;
  }

  .code-scroll {
    max-height: 420px;
  }

  .stage-topline {
    flex-wrap: wrap;
  }

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

@media (max-width: 860px) {
  .topbar {
    height: 60px;
    padding: 0 15px;
  }

  .topbar-mode,
  .topbar-location {
    display: none;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .brand-mark svg {
    width: 23px;
    height: 23px;
  }

  .brand-copy strong {
    font-size: 14px;
  }

  .brand-copy span {
    font-size: 6px;
  }

  .ghost-button {
    padding: 7px;
  }

  .ghost-button span {
    display: none;
  }

  .app {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 15px;
    padding: 15px 15px 22px;
  }

  .sidebar {
    position: static;
    width: 100%;
    gap: 14px;
  }

  .side-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(185px, 0.7fr);
    align-items: end;
    gap: 14px;
  }

  .side-heading .eyebrow {
    grid-column: 1 / -1;
  }

  .side-heading h2 {
    margin: 0;
    font-size: 24px;
  }

  .side-heading > p {
    max-width: none;
    font-size: 10px;
  }

  .algorithm-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .algo-item {
    border-top: 1px solid var(--line);
    border-bottom: 0;
    padding: 9px 8px;
  }

  .algo-item:nth-child(odd) {
    border-right: 1px solid var(--line);
  }

  .algo-item.is-active {
    padding-left: 8px;
  }

  .algo-item::before {
    left: -1px;
  }

  .algorithm-list .algo-item:last-child {
    grid-column: 1 / -1;
  }

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

  .data-panel .panel-heading {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }

  .data-panel .shuffle-button {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

  .preset-row {
    margin-top: 0;
  }

  .keyboard-note {
    display: none;
  }

  .workspace {
    width: 100%;
  }

  .algo-header {
    padding-top: 4px;
  }

  .algo-title-line h1 {
    font-size: 45px;
  }

  .algo-meta {
    justify-content: flex-start;
  }

  .stage-topline {
    padding: 9px 11px;
  }

  .stage {
    height: 340px;
  }

  .stage-metrics {
    gap: 9px;
    margin-left: auto;
  }

  .stage-metrics small {
    display: none;
  }

  .transport {
    padding: 10px 11px;
  }

  .timeline-row {
    gap: 8px;
  }

  .speed-control {
    gap: 4px;
  }

  .speed-control span {
    display: none;
  }

  .transport-controls {
    flex-wrap: wrap;
    gap: 10px;
  }

  .transport-hint {
    display: none;
  }

  .learning-grid {
    gap: 12px;
  }

  .code-rail {
    width: 100%;
  }

  .site-footer {
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 15px 22px;
    font-size: 6px;
  }

  .footer-rule,
  .site-footer > span:nth-child(3) {
    display: none;
  }

  .footer-version {
    margin-left: auto;
  }

  .guide-sheet {
    padding: 18px;
  }

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

  .guide-grid article {
    min-height: 0;
  }

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

@media (max-width: 560px) {
  .brand-copy span {
    display: none;
  }

  .topbar-actions {
    gap: 7px;
  }

  .side-heading {
    display: block;
  }

  .side-heading .eyebrow {
    margin-bottom: 10px;
  }

  .side-heading h2 {
    font-size: 25px;
  }

  .side-heading > p {
    margin-top: 7px;
  }

  .data-panel {
    display: block;
    padding: 12px;
  }

  .data-panel .panel-heading {
    margin-bottom: 10px;
  }

  .preset-row {
    margin-top: 9px;
  }

  .shuffle-button {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
  }

  .algo-header {
    gap: 12px;
  }

  .algo-title-line {
    gap: 8px;
  }

  .algo-title-line h1 {
    font-size: 42px;
  }

  .algo-summary {
    margin-top: 10px;
    font-size: 11px;
  }

  .algo-meta {
    gap: 4px;
  }

  .meta-chip {
    font-size: 6px;
    padding: 4px 5px;
  }

  .stage {
    height: 315px;
  }

  .stage-topline {
    min-height: 39px;
  }

  .phase-label {
    min-width: 100px;
    font-size: 7px;
  }

  .legend {
    gap: 6px;
    font-size: 6px;
  }

  .legend-dot {
    width: 4px;
    height: 4px;
  }

  .stage-metrics b {
    font-size: 10px;
  }

  .bar-value {
    font-size: 8px;
    margin-bottom: 3px;
  }

  .bar-plot.is-dense {
    gap: 0;
  }

  .bar-plot.is-dense .bar-slot {
    padding: 0;
  }

  .bar-plot.is-dense .bar-value {
    margin-bottom: 2px;
    font-size: 8px;
    letter-spacing: -0.03em;
  }

  .bar-plot.is-dense .bar-slot:nth-child(even) .bar-value {
    visibility: hidden;
  }

  .bar-plot.is-dense .bar-slot.is-compare .bar-value,
  .bar-plot.is-dense .bar-slot.is-swap .bar-value,
  .bar-plot.is-dense .bar-slot.is-pivot .bar-value,
  .bar-plot.is-dense .bar-slot.is-key .bar-value,
  .bar-plot.is-dense .bar-slot.is-write .bar-value,
  .bar-plot.is-dense .bar-slot.is-pointed .bar-value {
    visibility: visible;
  }

  .bar-plot.is-dense .bar {
    width: 82%;
  }

  .bar-plot,
  .pointer-row,
  .axis-row {
    left: 26px;
    right: 10px;
  }

  .bar-plot {
    gap: 1px;
  }

  .axis-row.is-dense {
    font-size: 5.5px;
  }

  .axis-row.is-dense .axis-slot:nth-child(even) {
    visibility: hidden;
  }

  .gridlines {
    left: 26px;
    right: 10px;
  }

  .stage-caption {
    left: 26px;
    right: 10px;
    font-size: 6px;
  }

  .bar-slot {
    padding: 0;
  }

  .bar {
    width: 82%;
  }

  .axis-row {
    font-size: 6px;
  }

  .pointer {
    padding: 1px 2px;
    font-size: 6px;
  }

  .stage.has-aux .bar-plot {
    bottom: 127px;
  }

  .stage.has-aux .pointer-row {
    bottom: 114px;
  }

  .stage.has-aux .gridlines,
  .stage.has-aux .y-axis {
    bottom: 127px;
  }

  .aux-panel {
    left: 26px;
    right: 10px;
    bottom: 41px;
    padding: 6px;
  }

  .aux-cell {
    height: 21px;
    font-size: 7px;
  }

  .tree-panel {
    left: 26px;
    right: 10px;
  }

  .tree-panel svg {
    height: 66px;
  }

  .stage.has-tree .bar-plot {
    bottom: 134px;
  }

  .stage.has-tree .pointer-row {
    bottom: 121px;
  }

  .stage.has-tree .gridlines,
  .stage.has-tree .y-axis {
    bottom: 134px;
  }

  .timeline-row {
    flex-wrap: wrap;
  }

  .timeline-wrap {
    order: 3;
    flex-basis: 100%;
    margin-top: 2px;
  }

  .speed-control {
    margin-left: auto;
  }

  .button-cluster {
    width: 100%;
    justify-content: space-between;
  }

  .play-button {
    flex: 1;
    justify-content: center;
  }

  .transport-controls {
    margin-top: 8px;
  }

  .step-card,
  .mental-card {
    padding: 14px;
  }

  .step-note,
  .invariant {
    min-height: 0;
    font-size: 11px;
  }

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

  .card-heading h2 {
    font-size: 15px;
  }

  .code-scroll {
    max-height: 360px;
  }

  .code-view {
    font-size: 10px;
  }

  .code-line {
    grid-template-columns: 26px minmax(max-content, 1fr);
  }

  .guide-modal {
    width: calc(100% - 18px);
    max-height: calc(100vh - 18px);
  }

  .guide-sheet {
    padding: 14px;
  }

  .guide-sheet h2 {
    font-size: 32px;
  }

  .guide-lead {
    font-size: 11px;
  }

  .toast {
    right: 12px;
    bottom: 12px;
  }
}

/* ---------- mobile touch layout ---------- */

@media (max-width: 560px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 80;
    background: rgba(8, 11, 13, 0.94);
    border-bottom: 1px solid var(--line);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }

  .topbar-actions {
    gap: 6px;
  }

  .ghost-button {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    padding: 0;
    justify-content: center;
  }

  .ghost-button kbd {
    display: none;
  }

  .side-heading > p {
    display: none;
  }

  .side-heading .eyebrow {
    margin-bottom: 7px;
  }

  .side-heading h2 {
    font-size: 24px;
    line-height: 1.06;
  }

  .algo-item {
    grid-template-columns: 20px minmax(0, 1fr);
    gap: 7px;
    min-height: 38px;
    padding: 8px 7px;
  }

  .algo-item.is-active {
    padding-left: 9px;
  }

  .algo-item.is-active::before {
    height: 22px;
  }

  .algo-item-name strong {
    font-size: 11.5px;
    line-height: 1.2;
    white-space: nowrap;
  }

  .algo-item-name span {
    display: none;
  }

  .algo-badge {
    display: none;
  }

  .data-panel {
    padding: 12px;
  }

  .data-panel .panel-heading {
    margin-bottom: 9px;
  }

  .array-field input {
    height: 38px;
    font-size: 16px;
    padding: 0 8px;
  }

  .apply-button {
    height: 38px;
    padding: 0 10px;
  }

  .array-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 7px;
  }

  .array-preview span {
    min-width: 24px;
    padding: 3px 4px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: rgba(201, 255, 114, 0.035);
    color: var(--text-soft);
    font-family: var(--font-mono);
    font-size: 9px;
    line-height: 1.2;
    text-align: center;
  }

  .preset-button {
    min-width: 34px;
    min-height: 34px;
    padding: 4px 7px;
  }

  .shuffle-button {
    display: none;
  }

  .preset-row {
    margin-top: 8px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .icon-button.small {
    width: 34px;
    height: 34px;
  }

  .play-button {
    height: 38px;
  }

  .algo-title-line h1 {
    font-size: 38px;
  }

  .algo-summary {
    margin-top: 7px;
  }

  .stage {
    height: 330px;
  }

  .stage-caption {
    display: none;
  }

  .bar-value {
    font-size: 8.5px;
  }

  .legend {
    gap: 4px 7px;
    font-size: 5.5px;
  }

  .stage-topline {
    min-height: 38px;
  }

  .workspace,
  .code-rail,
  .code-panel,
  .code-scroll {
    min-width: 0;
  }

  .code-rail,
  .code-panel {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  .code-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
  }

  .guide-modal {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
    overflow: hidden;
  }

  .guide-sheet {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 14px;
    overflow: hidden;
  }

  .guide-sheet h2 {
    margin-top: 10px;
    font-size: clamp(26px, 7vw, 32px);
  }

  .guide-lead {
    margin-top: 8px;
    font-size: 10.5px;
  }

  .guide-grid {
    flex: 1 1 auto;
    min-height: 0;
    margin-top: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .guide-grid article {
    min-height: 0;
    padding: 12px 13px;
  }

  .guide-grid h3 {
    margin-top: 8px;
    font-size: 13px;
  }

  .guide-grid p {
    font-size: 9.5px;
  }

  .guide-shortcuts {
    display: none;
  }

  .guide-footer {
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
  }

  .guide-footer > span {
    font-size: 8px;
  }

  .start-button {
    width: 100%;
    min-height: 40px;
    justify-content: center;
  }

  .ghost-button,
  .algo-item,
  .preset-button,
  .apply-button,
  .play-button,
  .icon-button,
  .code-line {
    touch-action: manipulation;
  }
}

@media (max-width: 380px) {
  .brand-copy strong {
    font-size: 13px;
  }

  .side-heading h2 {
    font-size: 23px;
  }

  .algo-item {
    grid-template-columns: 20px minmax(0, 1fr);
  }

  .algo-badge {
    display: none;
  }

  .algo-item-name strong {
    font-size: 10.5px;
  }

  .algo-title-line h1 {
    font-size: 35px;
  }

  .stage {
    height: 320px;
  }

  .array-preview span {
    min-width: 22px;
    padding: 3px;
    font-size: 8.5px;
  }
}

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