.lab-main {
  padding: 4rem 0 1rem;
}
.lab-heading {
  max-width: 700px;
}
.lab-heading h1 {
  margin: 0 0 1rem;
}
.lab-heading > p:last-child,
.algorithm-summary > p {
  color: var(--muted);
  line-height: 1.65;
}
.algorithm-tabs {
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 1.2rem;
  margin-top: 3.5rem;
  overflow-x: auto;
}
.algorithm-tabs button {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 0.9rem;
  font-weight: 750;
  padding: 0 0 0.85rem;
}
.algorithm-tabs button[aria-selected="true"] {
  border-color: var(--brand);
  color: var(--brand);
}
.lab-workspace {
  padding: 2rem 0 5rem;
}
.algorithm-summary {
  align-items: end;
  display: flex;
  gap: 2rem;
  justify-content: space-between;
}
.algorithm-summary h2 {
  font-size: clamp(1.65rem, 3vw, 2.35rem);
  margin: 0;
}
.algorithm-summary > p {
  margin: 0;
  max-width: 420px;
}
.framework {
  background: var(--soft);
  border-left: 4px solid var(--brand);
  border-radius: 0 10px 10px 0;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(3, 1fr);
  margin: 1.8rem 0 1.2rem;
  padding: 1rem;
}
.framework div {
  background: #fff;
  border-radius: 7px;
  padding: 0.75rem 0.85rem;
}
.framework strong {
  color: var(--brand);
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
}
.framework span {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}
.workspace {
  display: grid;
  gap: 1.2rem;
  grid-template-columns: 1.2fr 0.8fr;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.panel-title {
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.11em;
  margin: 0 0 1.3rem;
  padding-bottom: 0.8rem;
  text-transform: uppercase;
}
.array-container {
  align-items: flex-end;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: clamp(0.4rem, 2vw, 0.9rem);
  height: 190px;
  justify-content: center;
  padding: 2.3rem 0 2rem;
}
.bar-wrapper {
  align-items: center;
  display: flex;
  flex-direction: column;
  min-width: 36px;
  position: relative;
  width: 13%;
}
.bar {
  align-items: flex-start;
  background: #7ac6ff;
  border-radius: 5px 5px 0 0;
  color: #09223d;
  display: flex;
  font-size: 0.85rem;
  font-weight: 850;
  height: var(--bar-height);
  justify-content: center;
  padding-top: 0.25rem;
  transition:
    background 0.2s,
    height 0.25s;
  width: 100%;
}
.bar.sorted {
  background: #70d6a5;
}
.bar.comparing {
  background: #ffd86c;
}
.bar.minimum {
  background: #c4a7ff;
}
.bar.target {
  background: #ff9d92;
}
.bar.key {
  background: #ffb778;
}
.index-label {
  bottom: -1.45rem;
  color: #829ab1;
  font:
    0.73rem ui-monospace,
    monospace;
  position: absolute;
}
.pointer {
  border-radius: 4px;
  color: #08213d;
  font-size: 0.66rem;
  font-weight: 850;
  padding: 0.14rem 0.32rem;
  position: absolute;
  top: -1.72rem;
}
.pointer.primary {
  background: #ffb778;
}
.pointer.secondary {
  background: #ffd86c;
  transform: translateX(1rem);
}
.variables {
  background: var(--soft);
  border-radius: 9px;
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(3, 1fr);
  margin: 1rem 0;
  padding: 0.7rem;
}
.variables div {
  text-align: center;
}
.variables dt {
  color: var(--muted);
  font:
    0.72rem ui-monospace,
    monospace;
}
.variables dd {
  color: var(--brand);
  font:
    800 1rem ui-monospace,
    monospace;
  margin: 0.25rem 0 0;
}
.thought-box {
  background: #f8fbff;
  border: 1px solid #d9e7f7;
  border-left: 3px solid var(--brand);
  border-radius: 7px;
  min-height: 104px;
  padding: 0.9rem 1rem;
}
.thought-title {
  color: var(--brand);
  font-size: 0.69rem;
  font-weight: 850;
  letter-spacing: 0.11em;
  margin: 0 0 0.45rem;
  text-transform: uppercase;
}
.thought-text {
  line-height: 1.55;
  margin: 0;
}
.controls {
  align-items: center;
  display: flex;
  gap: 0.7rem;
  justify-content: space-between;
  margin-top: 1rem;
}
.controls > p {
  color: var(--muted);
  font:
    0.75rem ui-monospace,
    monospace;
  margin: 0;
}
.controls > div {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.button {
  border-radius: 7px;
  font-size: 0.83rem;
  padding: 0.57rem 0.76rem;
}
.button:disabled {
  background: #d9e2ec;
  border-color: #d9e2ec;
  color: #829ab1;
  cursor: not-allowed;
  transform: none;
}
.button.subtle {
  background: #fff;
  border-color: #9fb3c8;
  color: var(--ink);
}
.button.subtle:hover:not(:disabled) {
  background: var(--soft);
}
.code-panel {
  display: flex;
  flex-direction: column;
}
.code-panel pre {
  background: #0b2444;
  border-radius: 8px;
  color: #d9e9fa;
  flex-grow: 1;
  font:
    clamp(0.7rem, 1.6vw, 0.83rem)/1.7 ui-monospace,
    SFMono-Regular,
    Consolas,
    monospace;
  margin: 0;
  overflow-x: auto;
  padding: 0.9rem;
}
.code-line {
  border-left: 3px solid transparent;
  display: block;
  padding: 0 0.35rem;
  white-space: pre;
}
.code-line.active {
  background: #16436f;
  border-left-color: #ffd86c;
  color: #fff;
}
.key-hint {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 1rem 0 0;
}
kbd {
  background: var(--soft);
  border: 1px solid #c9d7e6;
  border-radius: 3px;
  color: var(--ink);
  padding: 0.05rem 0.25rem;
}
.compare {
  border-top: 1px solid var(--line);
  padding: 5rem 0 0;
}
.compare > div:first-child {
  display: flex;
  justify-content: space-between;
}
.compare h2 {
  margin: 0 0 1.8rem;
}
.compare-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(3, 1fr);
}
.compare-grid article {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.1rem;
}
.compare-grid h3 {
  margin: 0 0 0.45rem;
}
.compare-grid p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}
.compare-grid strong {
  color: var(--brand);
  font:
    0.76rem ui-monospace,
    monospace;
}
@media (max-width: 820px) {
  .algorithm-summary,
  .workspace {
    grid-template-columns: 1fr;
  }
  .algorithm-summary {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.6rem;
  }
  .framework {
    grid-template-columns: 1fr;
  }
  .workspace {
    display: grid;
  }
  .compare-grid {
    grid-template-columns: 1fr;
  }
}

/* Device-first refinements */
@media (hover: none), (pointer: coarse) {
  .algorithm-tabs button,
  .controls .button {
    min-height: 44px;
  }

  .algorithm-tabs {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .algorithm-tabs::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 520px) {
  .lab-heading > p:last-child {
    font-size: 0.96rem;
  }

  .algorithm-tabs {
    gap: 0.85rem;
    margin-inline: calc((100vw - min(100vw - 32px, 1160px)) / -2);
    padding-inline: 16px;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--paper);
  }

  .lab-workspace {
    padding-top: 1.4rem;
  }

  .array-container {
    height: 176px;
    padding-top: 2.1rem;
  }

  .variables {
    gap: 0.25rem;
    padding: 0.6rem 0.3rem;
  }

  .variables dt {
    font-size: 0.67rem;
  }

  .controls > div {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .controls .button {
    min-height: 44px;
    width: 100%;
  }

  .algorithm-tabs button {
    min-height: 44px;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .lab-main {
    padding-top: 1.75rem;
  }

  .lab-heading {
    display: none;
  }

  .algorithm-tabs {
    margin-top: 0;
  }

  .array-container {
    height: 135px;
  }
}

/* A focused workspace that still works well on narrower devices. */
.lab-workspace:fullscreen {
  background: var(--paper);
  box-sizing: border-box;
  min-height: 100%;
  overflow: auto;
  padding: clamp(1rem, 3vw, 2.5rem);
  width: 100%;
}

.lab-workspace:fullscreen .workspace {
  margin: 0 auto;
  max-width: 1320px;
}

.lab-workspace:fullscreen .array-container {
  height: min(31vh, 290px);
}

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

  .lab-workspace:fullscreen .code-panel pre {
    max-height: 245px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
.@media (max-width: 520px) {
  .lab-main {
    padding-top: 2.5rem;
  }
  .array-container {
    gap: 0.3rem;
  }
  .bar-wrapper {
    min-width: 29px;
  }
  .bar {
    font-size: 0.72rem;
  }
  .controls {
    align-items: flex-start;
    flex-direction: column;
  }
  .pointer.secondary {
    transform: translateX(0.6rem);
  }
}
