/* Scoped to the optional course players; exercise styles are unchanged. */
.sorting-demo {
  --sort-duration: 400ms;
  margin: 24px 0 30px;
  padding: 18px 0 20px;
  border-block: 1px solid var(--line);
  min-width: 0;
  text-align: left;
}
.article .sorting-demo h3 { margin: 0 0 6px; font-size: 19px; }
.sort-intro { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.sort-stage {
  position: relative;
  height: 172px;
  isolation: isolate;
  font-variant-numeric: tabular-nums;
}
.sort-stage--buffer { height: 352px; }
.sort-row-label, .sort-buffer-label {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 12px;
  color: var(--muted);
}
.sort-buffer-label { top: 180px; }
.sort-slots, .sort-buffer-slots { position: absolute; inset: 24px 0 auto; }
.sort-buffer-slots { top: 204px; }
.sort-slot {
  position: absolute;
  left: 0;
  top: 90px;
  width: calc(100% / var(--count));
  height: 32px;
  transform: translateX(calc(var(--x) * 100%));
  border: 1px solid var(--line);
  background: var(--bg);
}
.sort-slot.is-empty { border-style: dashed; }
.sort-slot > span { position: absolute; top: 34px; width: 100%; text-align: center; font-size: 11px; color: var(--muted); }
.sort-buffer-slots .sort-slot { background: transparent; border-style: dashed; }
.sort-piece {
  position: absolute;
  left: 0;
  top: 24px;
  width: calc(100% / var(--count));
  height: 124px;
  transform: translate(calc(var(--x) * 100%), var(--y));
  transition: transform var(--sort-duration) cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1;
}
.sort-stick {
  position: absolute;
  bottom: 34px;
  left: 16%;
  width: 68%;
  height: var(--bar);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 3px 3px 0 0;
}
.sort-number {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 4px;
  height: 29px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--accent);
  font-weight: 700;
  font-size: 17px;
  line-height: 1;
  padding-right: 8px;
}
.sort-identity {
  position: absolute;
  bottom: 12px;
  right: 8px;
  color: var(--ink);
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}
.sort-role {
  display: none;
  position: absolute;
  bottom: 35px;
  left: calc(50% - 8px);
  width: 16px;
  height: 16px;
  padding-top: 2px;
  text-align: center;
  font-size: 12px;
  line-height: 1;
  color: var(--panel);
  background: #62472f;
  border-radius: 2px;
  font-weight: 700;
}
.sort-piece.has-role .sort-role { display: block; }
.sort-piece.is-comparing .sort-number { outline: 2px dashed var(--ink); outline-offset: 1px; }
.sort-piece.has-role .sort-stick { background: #62472f; border-color: #62472f; }
.sort-piece.is-sorted .sort-stick { background: var(--accent-soft); border-color: var(--accent); }
.sort-piece.is-sorted .sort-role, .sort-piece.is-sorted .sort-identity { color: var(--ink); }
.sort-piece.is-sorted .sort-role { background: var(--accent-soft); }
.sort-piece.is-sorted .sort-number { border-bottom: 3px double var(--accent); }
.sort-message { min-height: 3.3em; margin: 10px 0 12px; font-size: 15px; line-height: 1.5; }
.sort-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sort-controls button, .sort-controls select {
  font: inherit;
  font-size: 14px;
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
}
.sort-controls button { cursor: pointer; }
.sort-controls button[data-action="play"] { background: var(--accent); color: #fff; min-width: 70px; }
.sort-controls button:hover:enabled { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.sort-controls button:disabled { cursor: default; opacity: 0.45; }
.sort-controls label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.sort-progress { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sort-legend, .sort-fallback { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.sort-live { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 400px) {
  .sort-controls { gap: 6px; }
  .sort-controls button { padding-inline: 8px; }
  .sort-identity { right: 5px; }
  .sort-number { left: 2px; right: 2px; font-size: 15px; }
  .sort-stick { left: 11%; width: 78%; }
}
@media (prefers-reduced-motion: reduce) {
  .sort-piece { transition: none; }
}
