/* The sorting robot (Coding, Years 5 and 6): site/js/science/code-sort.js. The program on
   one side (a loop around if, else if and else rows, the questions and bins to put in them,
   ▶ Run), the belt and the bins on the other; stacked when the iPad stands up, and on a
   phone the step scrolls. */

.sorter-act .map-ask { font-size: 24px; }
.sorter-act { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px; height: 100%; min-height: 0; container-type: size; }
.so-in { display: grid; grid-template-rows: auto auto; align-content: start; gap: 12px; min-height: 0; }

/* ---- The program ---- */

.so-code { display: grid; align-content: start; gap: 6px; padding: 10px 12px; border-radius: 22px; background: #fff; box-shadow: var(--shadow); }
.so-loop { display: flex; align-items: center; gap: 8px; min-height: 52px; color: var(--subject-dark, var(--accent)); font: 700 18px/1.2 var(--ks-brand-font, var(--ui)); }
.so-loop-e { font: 24px/1 var(--emoji); }
.so-now { display: flex; justify-content: flex-end; flex: 1; min-height: 40px; }
.so-loop .so-run { flex: none; min-width: 120px; min-height: 52px; padding: 0 18px; font-size: 21px; }
.so-now .card { min-width: 0; padding: 2px 8px; }
.so-now .card-emoji { font-size: 26px; }
.so-now .card-label { font-size: 13px; }
.so-rows { display: grid; gap: 4px; margin-left: 10px; padding-left: 12px; border-left: 4px solid color-mix(in srgb, var(--subject, var(--accent)) 55%, #fff); }
.so-row { display: grid; grid-template-columns: 70px minmax(0, 1fr) 22px minmax(0, 1fr) 22px; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 14px; transition: background-color 0.15s; }
.so-row.checking { background: #fff4c2; }
.so-row.checking.yes { background: var(--right-soft); }
.so-key { color: var(--subject-dark, var(--accent)); font: 800 18px/1 var(--ui); text-align: right; white-space: nowrap; }
.so-then { color: var(--muted); font: 800 18px/1 var(--ui); text-align: center; }
.so-mark { font: 800 20px/1 var(--ui); text-align: center; }
.so-row.yes .so-mark { color: var(--right); }
.so-row.no .so-mark { color: var(--wrong); }
.so-slot {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 46px;
  padding: 2px 8px;
  border: 3px dashed var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: 400 17px/1.15 var(--book);
  text-align: left;
  touch-action: manipulation;
}
.so-slot:not(.empty) { border-style: solid; background: var(--subject-soft, var(--accent-soft)); }
.so-slot.empty { color: var(--muted); }
.so-slot.picked { border: 3px solid var(--subject-dark, var(--accent)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--subject, var(--accent)) 30%, transparent); }
.so-slot-e { flex: none; font: 26px/1 var(--emoji); }
.so-slot-l { min-width: 0; overflow-wrap: anywhere; }
.so-swap { justify-self: center; width: 40px; height: 26px; margin: -4px 0 -4px 80px; padding: 0; border: 2px solid var(--line); border-radius: 999px; background: #fff; font: 700 18px/1 var(--ui); }
.so-swap:active, .so-slot:active { transform: scale(0.95); }
.so-palette-title { margin: 2px 0 0; color: var(--muted); font: 600 15px/1.2 var(--ui); }
.so-palette { display: flex; flex-wrap: wrap; gap: 8px; min-height: 60px; }
.so-palette .card { min-width: 0; padding: 4px 10px; }
.so-palette .card-emoji { font-size: 28px; }
.so-palette .card-label { font-size: 16px; }

/* ---- The belt and the bins ---- */

.so-floor { display: grid; align-content: start; gap: 8px; min-width: 0; }
.so-belt-wrap {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 2px 8px;
  padding: 6px 10px;
  border-radius: 18px;
  background: repeating-linear-gradient(90deg, #cfd5de 0 18px, #c1c8d3 18px 20px);
  box-shadow: inset 0 -5px 0 #9aa3b2;
}
.so-robot { font: 44px/1 var(--emoji); }
.so-belt { display: flex; flex-wrap: wrap; gap: 6px; min-height: 64px; align-content: center; }
.so-count { grid-column: 1 / -1; color: #3a4252; font: 600 14px/1.2 var(--ui); text-align: right; }
.so-bins { display: grid; grid-template-columns: repeat(var(--bins, 3), minmax(0, 1fr)); gap: 8px; }
.so-bins .so-bin { min-height: 100px; padding: 6px 4px; border-radius: 18px; }
.so-bin .bin-head { flex-direction: column; gap: 2px; }
.so-bin .bin-emoji { font-size: 32px; }
.so-bin .bin-label { font-size: 17px; text-align: center; }
.so-thing.card { min-width: 0; padding: 2px 6px; box-shadow: none; }
.so-thing .card-emoji { font-size: 28px; }
.so-thing .card-label { font-size: 13px; }
.so-tray { gap: 4px; padding-top: 4px; }
.so-thing.right { border-color: var(--right); }
.so-thing.wrong { border-color: var(--wrong); background: #ffecec; }
.so-note { margin: 0; min-height: 1.3em; font: 400 20px/1.3 var(--book); text-align: center; }

/* ---- iPad on its side: the program on the left, the belt on the right ---- */

@container (min-aspect-ratio: 4 / 3) {
  .so-in { grid-template-rows: none; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}

/* ---- Phones: one column, and the step scrolls ---- */

@media (max-width: 600px), (max-height: 500px) {
  .sorter-act { height: auto; container-type: normal; }
  .so-code { padding: 8px; }
  .so-row { grid-template-columns: 52px minmax(0, 1fr) 16px minmax(0, 1fr) 16px; gap: 4px; }
  .so-key { font-size: 15px; }
  .so-slot { min-height: 44px; padding: 2px 5px; font-size: 14px; gap: 4px; }
  .so-slot-e { font-size: 20px; }
  .so-swap { margin-left: 60px; }
  .so-palette .card-emoji { font-size: 24px; }
  .so-palette .card-label { font-size: 14px; }
  .so-robot { font-size: 32px; }
  .so-bin .bin-label { font-size: 14px; }
  .so-note { font-size: 17px; }
  .sorter-act .map-ask { font-size: 20px; }
  .so-loop { font-size: 15px; }
  .so-loop .so-run { min-width: 96px; min-height: 46px; font-size: 18px; }
}

/* A phone on its side: the program and the belt side by side. */
@media (max-height: 500px) {
  .so-in { grid-template-rows: none; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}
