/* ============================================================
   Interactive topic blocks.

   Built on the tokens in styles.css + theme.css — no hex values
   here. Two things are deliberate rather than decorative:

   1. Every block is a distinct surface with real vertical
      separation. The old page was one wall of prose; the point
      of the format is that a learner can SEE there are five
      things to do, not four paragraphs to skim.
   2. Interactive controls are sized for a thumb. WCAG 2.2
      SC 2.5.8 wants 24px; 44px is what actually works on a
      phone, which is where a lot of this will be read.
   ============================================================ */

.blocks { display: flex; flex-direction: column; gap: 18px; }

/* --- progress rail --- */
.blocks-progress {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  backdrop-filter: blur(6px);
}
.blocks-progress .progress-track { flex: 1 1 auto; }
.blocks-progress-label {
  flex: none;
  font-size: var(--fs-2xs, 12px);
  color: var(--text-faint);
  white-space: nowrap;
}

/* --- the block surface --- */
.block {
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius, 12px);
}
/* Prose is connective tissue, not a thing to do — it gets no box, so the
   blocks that ARE things to do stand out by contrast rather than by shouting. */
.block-prose {
  padding: 0 2px;
  background: none;
  border: 0;
}
.block-head { margin-bottom: 12px; }
.block-kicker {
  display: block;
  font-size: var(--fs-2xs, 12px);
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--accent-text, var(--accent));
  margin-bottom: 4px;
}
.block-title { margin: 0; font-size: var(--fs-md, 17px); line-height: 1.35; }
.block-lede { color: var(--text-dim); margin: 0 0 14px; font-size: var(--fs-sm, 14px); }
.block-actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.block-already { margin: 12px 0 0; display: flex; align-items: center; gap: 6px; font-size: var(--fs-2xs, 12px); }

/* A block answered correctly keeps a quiet marker. Loud green everywhere
   turns a finished page into a christmas tree. */
.block.is-correct { border-color: var(--green, #1E7A34); box-shadow: inset 3px 0 0 var(--green, #1E7A34); }
.block.is-wrong { border-color: var(--amber, #B06A00); }

/* --- feedback --- */
.block-feedback {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.block-feedback.ok { border-color: var(--green, #1E7A34); }
.block-feedback.bad { border-color: var(--amber, #B06A00); }
.fb-verdict {
  display: flex; align-items: center; gap: 7px;
  margin: 0 0 8px; font-weight: 700; font-size: var(--fs-sm, 14px);
}
.block-feedback.ok .fb-verdict { color: var(--green-text, var(--green)); }
.block-feedback.bad .fb-verdict { color: var(--amber-text, var(--amber)); }
.fb-reveal { font-size: var(--fs-sm, 14px); }
.fb-reveal > :first-child { margin-top: 0; }
.fb-reveal > :last-child { margin-bottom: 0; }
.fb-solution {
  margin: 12px 0 0;
  padding: 12px;
  background: var(--surface-3);
  border-radius: 6px;
  overflow-x: auto;
  font-size: var(--fs-2xs, 12px);
}

/* --- choice blocks: predict + checkpoint --- */
.choice-opts { display: flex; flex-direction: column; gap: 8px; }
.choice-opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 12px 14px;
  text-align: left;
  font: inherit;
  font-size: var(--fs-sm, 14px);
  color: var(--text);
  background: var(--surface-2);
  /* --border is ~1.35:1 against the surface: fine for a divider, but these are
     the answer buttons and at 200% zoom they had no perceivable edge at all.
     WCAG 2.2 SC 1.4.11 wants 3:1 on a control boundary. */
  border: 1px solid var(--border-strong, var(--border));
  border-radius: var(--radius-sm, 8px);
  cursor: pointer;
  transition: border-color var(--motion-fast, 120ms) ease, background var(--motion-fast, 120ms) ease;
}
.choice-opt:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-3); }
.choice-opt:disabled { cursor: default; }
.choice-key {
  flex: none;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text-faint);
}
.choice-text { flex: 1 1 auto; }
/* Right and wrong are marked by an icon-weight border AND a label colour, not
   colour alone — about 1 in 12 men cannot rely on the red/green difference. */
.choice-opt.is-right { border-color: var(--green, #1E7A34); border-width: 2px; }
.choice-opt.is-right .choice-key { background: var(--green, #1E7A34); color: var(--on-fill, #fff); }
.choice-opt.is-right .choice-key::after { content: ' ✓'; }
.choice-opt.is-wrong { border-color: var(--red, #B3261E); border-width: 2px; }
.choice-opt.is-wrong .choice-key { background: var(--red, #B3261E); color: var(--on-fill, #fff); }
.choice-opt.is-wrong .choice-key::after { content: ' ✕'; }
.choice-opt.is-chosen { box-shadow: 0 0 0 2px var(--accent); }

/* --- ordering --- */
.ord-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ord-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  font-size: var(--fs-sm, 14px);
}
.ord-pos {
  flex: none; width: 24px; height: 24px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-faint);
}
.ord-text { flex: 1 1 auto; }
.ord-moves { flex: none; display: flex; gap: 4px; }
.ord-moves button {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
}
.ord-moves button:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text); }
.ord-moves button:disabled { opacity: .35; cursor: default; }
/* Right/wrong here was hue alone — a red border against a green one, which is
   about 1.2:1 apart for a red-green colour deficiency and indistinguishable.
   The choice block already solved this with a glyph; ordering now matches, and
   the position number is replaced rather than merely recoloured so the signal
   survives greyscale, forced-colours and print. */
.ord-item.is-right { border-color: var(--green, #1E7A34); border-left-width: 3px; }
.ord-item.is-right .ord-pos { background: var(--green, #1E7A34); color: var(--on-fill, #fff); font-size: 0; }
.ord-item.is-right .ord-pos::after { content: '✓'; font-size: 13px; }
.ord-item.is-wrong { border-color: var(--red, #B3261E); border-left-width: 3px; border-left-style: dashed; }
.ord-item.is-wrong .ord-pos { background: var(--red, #B3261E); color: var(--on-fill, #fff); font-size: 0; }
.ord-item.is-wrong .ord-pos::after { content: '✕'; font-size: 13px; }

/* --- build --- */
.build-prompt { font-size: var(--fs-sm, 14px); margin-bottom: 16px; }
.build-fields { display: flex; flex-direction: column; gap: 16px; }
.build-label { display: block; font-weight: 650; font-size: var(--fs-sm, 14px); margin-bottom: 4px; }
.build-hint { margin: 0 0 6px; font-size: var(--fs-2xs, 12px); }
.build-input { width: 100%; font-family: var(--font-mono, ui-monospace, monospace); font-size: 13px; }
.build-err { margin: 6px 0 0; font-size: var(--fs-2xs, 12px); color: var(--red-text, var(--red)); }
.build-field.is-bad .build-input { border-color: var(--red, #B3261E); }

/* --- figure --- */
.fig-wrap { display: grid; gap: 16px; }
@media (min-width: 900px) { .fig-wrap { grid-template-columns: 1.4fr 1fr; align-items: start; } }
.fig-canvas { position: relative; background: var(--surface-2); border-radius: var(--radius-sm, 8px); padding: 14px; }
.fig-canvas svg { display: block; width: 100%; height: auto; }
.fig-spot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 44px; height: 44px;           /* SC 2.5.8 — the dot is 26px, the target is 44 */
  display: grid; place-items: center;
  background: none; border: 0; padding: 0;
  cursor: pointer;
}
.fig-dot {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 12px; font-weight: 700;
  background: var(--accent); color: var(--on-fill, #fff);
  border: 2px solid var(--surface);
  transition: transform var(--motion-fast, 120ms) ease;
}
.fig-spot:hover .fig-dot, .fig-spot.is-active .fig-dot { transform: scale(1.18); }
.fig-spot.is-active .fig-dot { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 28%, transparent); }
.fig-reveal {
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  font-size: var(--fs-sm, 14px);
  min-height: 90px;
}
.fig-reveal-title { margin: 0 0 6px; font-size: var(--fs-sm, 14px); color: var(--accent-text, var(--accent)); }
.fig-caption { margin: 10px 0 0; font-size: var(--fs-2xs, 12px); color: var(--text-faint); }

/* --- flow (steppable workflow) --- */
.flow-rail {
  list-style: none; margin: 0 0 16px; padding: 0 0 4px;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin;
}
.flow-pip { flex: 0 0 auto; }
.flow-pip-btn {
  display: flex; align-items: center; gap: 7px;
  min-height: 36px; padding: 6px 12px;
  font: inherit; font-size: var(--fs-2xs, 12px);
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer; white-space: nowrap;
}
.flow-pip.is-seen .flow-pip-btn { color: var(--text-dim); }
.flow-pip.is-current .flow-pip-btn {
  color: var(--accent-text, var(--accent));
  border-color: var(--accent);
  background: var(--surface);
  font-weight: 650;
}
.flow-pip-n {
  width: 18px; height: 18px; display: grid; place-items: center;
  border-radius: 50%; font-size: 10px; font-weight: 700;
  background: var(--surface-3);
}
.flow-pip.is-current .flow-pip-n { background: var(--accent); color: var(--on-fill, #fff); }
.flow-stage {
  padding: 16px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  min-height: 140px;
}
.flow-stage-title { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; font-size: var(--fs-sm, 14px); }
.flow-stage-n { font-size: 11px; font-weight: 700; color: var(--text-faint); letter-spacing: .04em; }
.flow-stage .prose { font-size: var(--fs-sm, 14px); }
.flow-code, .cmp-code, .term-out {
  margin: 12px 0 0; padding: 12px;
  background: var(--surface-3); border-radius: 6px;
  overflow-x: auto; font-size: 12px; line-height: 1.6;
}
.flow-state { margin: 14px 0 0; width: 100%; border-collapse: collapse; font-size: 12px; }
.flow-state th, .flow-state td { padding: 6px 8px; text-align: left; border-top: 1px solid var(--border); }
.flow-state th { color: var(--text-faint); font-weight: 600; width: 34%; }
.flow-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.flow-nav .btn { min-height: 40px; }

/* --- terminal --- */
.term { border: 1px solid var(--border); border-radius: var(--radius-sm, 8px); overflow: hidden; }
.term-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--text-faint);
}
.term-dots { width: 36px; height: 8px; border-radius: 999px; background: var(--border-strong); opacity: .5; }
.term-body {
  padding: 14px;
  background: var(--surface-3);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12.5px; line-height: 1.65;
  max-height: 420px; overflow-y: auto;
}
.term-body:empty::after {
  content: 'Nothing has run yet. Press the button below to execute the first command.';
  display: block; font-family: var(--font-ui, system-ui); color: var(--text-faint); font-size: 13px;
}
.term-step + .term-step { margin-top: 14px; }
.term-cmd { display: flex; gap: 8px; color: var(--text); }
.term-prompt { color: var(--green-text, var(--green)); font-weight: 700; }
.term-out { margin: 6px 0 0; background: none; padding: 0; color: var(--text-dim); }
.term-note {
  display: flex; align-items: flex-start; gap: 6px;
  margin: 8px 0 0; padding: 8px 10px;
  font-family: var(--font-ui, system-ui); font-size: 12px;
  color: var(--text-dim);
  background: var(--surface); border-radius: 6px;
}
.term-foot { display: flex; gap: 10px; padding: 10px 12px; background: var(--surface-2); border-top: 1px solid var(--border); }
.term-foot .btn { min-height: 40px; font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; }

/* --- compare --- */
.cmp-grid { display: grid; gap: 14px; }
@media (min-width: 760px) { .cmp-grid { grid-template-columns: 1fr 1fr; } }
.cmp-side { padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm, 8px); }
.cmp-title { margin: 0 0 2px; font-size: var(--fs-sm, 14px); }
.cmp-sub { margin: 0 0 8px; font-size: var(--fs-2xs, 12px); }
.cmp-left { border-left: 3px solid var(--red, #B3261E); }
.cmp-right { border-left: 3px solid var(--green, #1E7A34); }
.cmp-diffs { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cmp-diffs li { display: flex; align-items: flex-start; gap: 8px; font-size: var(--fs-sm, 14px); color: var(--text-dim); }

/* --- video (always last) --- */
.block-video { padding: 0; background: none; border: 0; }

@media (max-width: 640px) {
  .block { padding: 16px 14px; }
  .blocks-progress { padding: 9px 12px; }
  .block-actions .btn, .flow-nav .btn { flex: 1 1 auto; justify-content: center; }
  .fig-spot { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .choice-opt, .fig-dot { transition: none; }
  .fig-spot:hover .fig-dot, .fig-spot.is-active .fig-dot { transform: none; }
}

@media print {
  .blocks-progress, .block-actions, .flow-nav, .term-foot, .ord-moves { display: none !important; }
  .block { break-inside: avoid; border: 1px solid #ccc; }
}

/* The terminal body is a scroll container the learner must be able to reach:
   Chrome does not make overflow containers focusable on its own, so earlier
   commands were unreachable by keyboard once the session scrolled. */
.term-body:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Focus moves into the feedback panel when a block is answered, because the
   control that was just used gets disabled. Make that landing visible. */
.block-feedback:focus-visible,
.fig-reveal:focus-visible,
.ord-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- explain: say it in your own words --- */
.explain-input {
  width: 100%;
  font: inherit;
  font-size: var(--fs-sm, 14px);
  line-height: 1.65;
  resize: vertical;
  min-height: 140px;
}
.explain-meter {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 6px;
  font-size: var(--fs-2xs, 12px);
  color: var(--text-faint);
}
/* The count turns positive once the floor is met — encouragement, not a gate:
   the learner can submit early and is told they have not finished, rather than
   being blocked by a disabled button with no explanation. */
.block-explain.is-ready .explain-count { color: var(--green-text, var(--green)); font-weight: 650; }
.explain-privacy {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 12px 0 0;
  font-size: var(--fs-2xs, 12px);
}
.explain-concepts { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.explain-concepts li { display: flex; align-items: flex-start; gap: 7px; font-size: var(--fs-sm, 14px); }
.explain-concepts li.hit { color: var(--green-text, var(--green)); }
/* A missed concept is not "wrong" — it is the next thing to say. Neutral ink,
   not red, so a partial answer does not read as a failure. */
.explain-concepts li.miss { color: var(--text-dim); }
.fb-sub { margin: 0 0 4px; font-size: var(--fs-sm, 14px); }
.explain-review {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm, 14px);
}
.explain-review p { margin: 0 0 8px; }
.explain-flag { display: flex; align-items: flex-start; gap: 6px; color: var(--amber-text, var(--amber)); }
.explain-model { font-size: var(--fs-2xs, 12px); margin: 10px 0 0 !important; }
.explain-sample { margin-top: 14px; }
.explain-sample summary {
  cursor: pointer;
  font-size: var(--fs-sm, 14px);
  font-weight: 650;
  color: var(--accent-text, var(--accent));
  min-height: 32px;
  display: flex;
  align-items: center;
}
.explain-sample .prose { margin-top: 8px; font-size: var(--fs-sm, 14px); }

/* --- instructor: bring your own problem --- */
.chat-attach-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
}
.chat-attach-preview img {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.chat-attach-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--fs-2xs, 12px);
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* The label IS the control — the file input itself is visually hidden, so the
   label has to carry the full target size and its own focus ring. */
.chat-attach {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  cursor: pointer;
}
#chat-image:focus-visible + .chat-attach {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
