.algorithm-lab {
  --lab-bg: #fff;
  --lab-ink: #192b40;
  --lab-border: #cbd5e1;
  --lab-soft: #f0f5fa;
  color: var(--lab-ink);
}
[data-theme="dark"] .algorithm-lab {
  --lab-bg: #182332;
  --lab-ink: #e3edf7;
  --lab-border: #516175;
  --lab-soft: #223247;
}
.lab-eyebrow {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: #227a80;
}
.algorithm-lab h1 {
  font-size: clamp(2rem, 5vw, 3.6rem);
  font-weight: 800;
  letter-spacing: -0.04em;
}
.lab-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 24px;
  margin-top: 32px;
}
.lab-panel {
  background: var(--lab-bg);
  border: 1px solid var(--lab-border);
  border-radius: 16px;
  padding: 24px;
  min-width: 0;
}
.lab-panel h2 {
  font-size: 1.4rem;
}
.algorithm-lab label {
  display: block;
  font-weight: 600;
  margin: 12px 0 6px;
}
.algorithm-lab input,
.algorithm-lab select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--lab-border);
  border-radius: 7px;
  background: var(--lab-bg);
  color: var(--lab-ink);
}
#algorithm-select {
  min-height: 330px;
}
#algorithm-select option {
  padding: 8px;
}
.algorithm-lab button {
  padding: 10px 16px;
  border: 1px solid var(--lab-border);
  border-radius: 7px;
  background: var(--lab-soft);
  color: var(--lab-ink);
  min-height: 44px;
}
.algorithm-lab button:disabled {
  opacity: 0.5;
}
.algorithm-lab #play {
  background: #17656a;
  color: white;
}
.lab-input-row,
.lab-controls,
.lab-heading {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.lab-input-row input {
  flex: 1;
  min-width: 160px;
}
.lab-controls label {
  margin: 0;
}
.lab-controls select {
  width: auto;
}
.lab-heading {
  justify-content: space-between;
}
.lab-badge {
  padding: 7px 12px;
  border-radius: 20px;
  background: var(--lab-soft);
  font-family: monospace;
}
.lab-stage {
  display: flex;
  gap: 6px;
  align-items: end;
  justify-content: center;
  min-height: 260px;
  padding: 24px 8px;
  flex-wrap: wrap;
  background: var(--lab-soft);
  border-radius: 12px;
  margin-top: 16px;
}
.lab-cell {
  display: flex;
  flex-direction: column;
  justify-content: end;
  align-items: center;
  min-width: 34px;
  flex: 1;
  max-width: 75px;
  gap: 6px;
}
.lab-bar {
  width: 100%;
  background: #237a92;
  border: 2px solid transparent;
  border-radius: 5px 5px 0 0;
  min-height: 8px;
}
.lab-cell.active .lab-bar {
  background: #a65b0b;
  border-color: var(--lab-ink);
}
.lab-cell.active {
  font-weight: bold;
}
.lab-cell small {
  font-size: 0.65rem;
}
.lab-stage svg {
  width: 100%;
  max-height: 310px;
}
.lab-stage .node {
  fill: #237a92;
  stroke: var(--lab-ink);
  stroke-width: 2;
}
.lab-stage .visited {
  fill: #a65b0b;
}
.lab-stage text {
  fill: var(--lab-ink);
  font-size: 14px;
}
.lab-stage .node-label {
  fill: white;
  font-weight: bold;
}
.lab-stage line {
  stroke: var(--lab-border);
  stroke-width: 3;
}
.lab-stage .chosen {
  stroke: #a65b0b;
  stroke-width: 5;
}
.lab-grid {
  display: grid;
  gap: 4px;
  max-width: 100%;
  overflow-x: auto;
}
.lab-square {
  padding: 8px;
  background: var(--lab-bg);
  border: 1px solid var(--lab-border);
  text-align: center;
}
.lab-square.active {
  background: #a65b0b;
  color: white;
}
#algorithm-error {
  color: #b13a32;
}
#step-description {
  min-height: 3em;
  padding: 12px 0;
}
.algorithm-lab pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--lab-soft);
  padding: 16px;
  border-radius: 8px;
  color: var(--lab-ink);
}
.algorithm-lab details {
  margin-top: 16px;
}
.algorithm-lab [hidden] {
  display: none !important;
}
.lab-view-controls {
  margin-top: 12px;
}
.lab-3d-viewport {
  position: relative;
  height: clamp(300px, 47vw, 470px);
  overflow: hidden;
  border-radius: 12px;
  background: #090e18;
}
#algorithm-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: pan-y;
  cursor: grab;
}
#algorithm-canvas:active {
  cursor: grabbing;
}
.lab-3d-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.lab-3d-label {
  position: absolute;
  transform: translate(-50%, -100%);
  max-width: 150px;
  padding: 2px 5px;
  color: #edf6ff;
  background: #101c2ee8;
  border: 1px solid #516175;
  border-radius: 4px;
  font:
    11px/1.4 ui-monospace,
    monospace;
  white-space: nowrap;
}
.lab-3d-label.is-active {
  color: #ffe6ac;
  border: 2px solid #ffb337;
  font-weight: 700;
  z-index: 2;
}
.lab-camera-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.lab-camera-controls label {
  font-size: 0.85rem;
}
.lab-camera-controls output {
  font-weight: 400;
}
.algorithm-lab .lab-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.algorithm-lab .lab-checkbox input {
  width: auto;
}
.algorithm-lab :focus-visible {
  outline: 3px solid #b47313;
  outline-offset: 3px;
}
@media (max-width: 850px) {
  .lab-layout {
    grid-template-columns: 1fr;
  }
  #algorithm-select {
    min-height: 160px;
    height: 200px;
  }
  .lab-panel {
    padding: 16px;
  }
  .lab-stage {
    gap: 3px;
  }
  .lab-cell {
    min-width: 22px;
    font-size: 0.8rem;
  }
}
