/* Keep the featured demo's layout and styles inside the Workbench panel. */
#algorithm-explorer:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr);
  gap: 16px;
}

#algorithm-explorer .workspace {
  min-width: 0;
  padding: clamp(14px, 2vw, 24px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}

#algorithm-explorer .section-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px 12px;
  margin-bottom: 14px;
}

#algorithm-explorer .workspace > h4 { margin: 0 0 14px; }
#algorithm-explorer .section-header h4 { margin: 0; }
#algorithm-explorer :is(.field small, .legend, .count span, .results span) {
  color: var(--muted);
  font-size: .8rem;
}

#algorithm-explorer :is(.algorithm-tabs, .actions, .legend) {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#algorithm-explorer :is(button, input) {
  min-width: 0;
  min-height: 44px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--ink);
  font: inherit;
}

#algorithm-explorer button { cursor: pointer; }
#algorithm-explorer button:disabled { opacity: .55; cursor: default; }
#algorithm-explorer button:is(:hover:not(:disabled), [aria-pressed="true"], .primary) {
  border-color: var(--accent);
}

#algorithm-explorer button:is([aria-pressed="true"], .primary) { color: var(--accent); }

#algorithm-explorer :is(button, input, .array-scroll):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#algorithm-explorer .form-grid {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

#algorithm-explorer .field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

#algorithm-explorer .field[hidden] { display: none; }
#algorithm-explorer .field label { font-size: .9rem; }
#algorithm-explorer input { width: 100%; font: 1rem ui-monospace, monospace; }
#algorithm-explorer [aria-invalid="true"] { border-color: #ffb8ac; }
#algorithm-explorer .feedback { color: #ffb8ac; margin: 10px 0 0; font-size: .9rem; }
#algorithm-explorer .feedback:empty { margin: 0; }

#algorithm-explorer .count {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: ui-monospace, monospace;
}

#algorithm-explorer .legend { gap: 4px 12px; margin: 0 0 12px; }
#algorithm-explorer .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 3px;
  border-radius: 50%;
}

#algorithm-explorer .active-dot { background: var(--accent); }
#algorithm-explorer .min-dot { background: #efd48c; }
#algorithm-explorer .done-dot { background: #3c8b60; }

#algorithm-explorer .array-scroll {
  overflow-x: auto;
  max-width: 100%;
  margin-bottom: 12px;
}

#algorithm-explorer .array {
  position: relative;
  display: flex;
  gap: 6px;
  padding: 3px 2px 8px;
}

#algorithm-explorer .cell {
  display: grid;
  flex: 0 0 auto;
  align-content: center;
  justify-items: center;
  gap: 3px;
  min-width: 58px;
  min-height: 58px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  font: .95rem ui-monospace, monospace;
}

#algorithm-explorer .cell small { color: var(--muted); font-size: .65rem; }
#algorithm-explorer .cell.active { border-color: var(--accent); }
#algorithm-explorer .cell.minimum { box-shadow: inset 0 -3px #efd48c; }
#algorithm-explorer .cell.sorted { background: #183b2d; }
#algorithm-explorer .array-empty { color: var(--muted); font-size: .9rem; }

#algorithm-explorer .trace-note {
  min-height: 3em;
  padding: 8px 10px;
  border-left: 2px solid var(--line);
  background: var(--soft);
  font-size: .9rem;
}

#algorithm-explorer .results {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 14px;
  margin-top: 12px;
}

#algorithm-explorer .results div { display: grid; gap: 3px; min-width: 0; }
#algorithm-explorer .results strong { overflow-wrap: anywhere; font-size: .9rem; }
#algorithm-explorer .visualization .actions { margin-top: 12px; }

@media (max-width: 900px) {
  #algorithm-explorer:not([hidden]) { grid-template-columns: minmax(0, 1fr); }
}

/* What Changed keeps both search traces on one screen at desktop widths. */
#algorithm-search-comparison :is(.algorithm-compare-toolbar, .algorithm-compare-controls) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-block: 12px;
}

#algorithm-search-comparison :is(button, select) {
  min-height: 44px;
  max-width: 100%;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--ink);
  font: inherit;
}

#algorithm-search-comparison select { font-size: 1rem; }
#algorithm-search-comparison button { cursor: pointer; }
#algorithm-search-comparison button[aria-disabled="true"] { opacity: .55; cursor: default; }
#algorithm-search-comparison button:is(.algorithm-compare-next, :hover):not([aria-disabled="true"]) {
  border-color: var(--accent);
  color: var(--accent);
}
#algorithm-search-comparison :is(button, select):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#algorithm-search-comparison .algorithm-compare-lanes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

#algorithm-search-comparison .algorithm-compare-lane {
  min-width: 0;
  padding: clamp(10px, 1.6vw, 18px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

#algorithm-search-comparison .algorithm-compare-lane header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: start;
  gap: 4px 10px;
}

#algorithm-search-comparison :is(.algorithm-compare-kicker, .algorithm-compare-count) {
  margin: 0;
  color: var(--accent);
  font: .75rem/1.5 ui-monospace, monospace;
}

#algorithm-search-comparison .algorithm-compare-lane h4 { margin: 2px 0; font-size: 1.1rem; }
#algorithm-search-comparison :is(.algorithm-compare-note, .algorithm-compare-detail, .algorithm-compare-position) {
  color: var(--muted);
  font-size: .86rem;
}

#algorithm-search-comparison .algorithm-compare-array {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

#algorithm-search-comparison .algorithm-compare-cell {
  display: grid;
  min-height: 44px;
  align-content: center;
  justify-items: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--soft);
  font: .875rem/1.25 ui-monospace, monospace;
}

#algorithm-search-comparison .algorithm-compare-cell[data-outside="true"] {
  border-style: dashed;
  background: transparent;
  color: var(--muted);
}

#algorithm-search-comparison .algorithm-compare-cell[data-probe="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  color: var(--ink);
}

#algorithm-search-comparison .algorithm-compare-index { color: var(--muted); font-size: .7rem; }
#algorithm-search-comparison .algorithm-compare-detail { min-height: 3em; }
#algorithm-search-comparison .algorithm-compare-result { margin-top: 4px; }
#algorithm-search-comparison .algorithm-compare-position { margin: 0 0 0 auto; }

@media (max-width: 675px) {
  #algorithm-search-comparison .algorithm-compare-lanes { grid-template-columns: minmax(0, 1fr); }
  #algorithm-search-comparison .algorithm-compare-detail { min-height: 0; }
}
