/* ===========================================================================
   Codes.Live — challenge.css
   The "Mark as done" check (core/challenge.js): its popups, the "Your move"
   panel that takes the code's place in the sidebar, and the quiz.
   Right / wrong use the viz palette's done (emerald) and swap (rose) hues;
   brand green stays for progress and the primary action.
   ========================================================================== */

/* ------------------------------------------------------------------ Popup */
.chal-scrim {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .16s var(--ease);
}
.chal-scrim.is-on { opacity: 1; }
.chal-modal {
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 18px; border-radius: var(--r-lg);
  border: 1px solid var(--border-strong); background: var(--elevated); color: var(--text);
  box-shadow: 0 24px 60px -26px rgba(0,0,0,.65), 0 2px 8px -4px rgba(0,0,0,.3);
  animation: pop .18s var(--ease);
}
.chal-modal__head { display: flex; align-items: flex-start; gap: 11px; }
.chal-modal__icon {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--indigo) 14%, transparent); color: var(--indigo);
}
.chal-modal__icon svg { width: 18px; height: 18px; }
.chal-modal.is-fail .chal-modal__icon { background: var(--surface-2); color: var(--text-dim); }
.chal-modal__titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding-top: 1px; }
.chal-modal__title { font-size: 16px; font-weight: 700; line-height: 1.25; letter-spacing: -.01em; }
.chal-modal__sub { font-size: 12.5px; color: var(--muted); }
.chal-modal__x {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  color: var(--muted); transition: background var(--dur), color var(--dur);
}
.chal-modal__x:hover { background: var(--surface-2); color: var(--text); }
.chal-modal__x svg { width: 14px; height: 14px; }
.chal-modal__body { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.chal-modal__foot { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.chal-modal__foot:empty { display: none; }

/* Small: the start and result popups — one line of text, small buttons. */
.chal-modal--sm { width: min(380px, 100%); padding: 14px 16px; }
.chal-modal--sm .chal-modal__head { align-items: center; gap: 10px; }
.chal-modal--sm .chal-modal__icon { width: 30px; height: 30px; border-radius: 9px; }
.chal-modal--sm .chal-modal__icon svg { width: 16px; height: 16px; }
.chal-modal--sm .chal-modal__title { font-size: 15px; }
.chal-modal--sm .chal-modal__sub { font-size: 12px; }
.chal-modal--sm .chal-modal__body { margin-top: 12px; gap: 4px; }
.chal-modal--sm .chal-text { font-size: 14px; line-height: 1.5; }
.chal-modal--sm .chal-modal__foot { margin-top: 14px; }

.chal-text { margin: 0; font-size: 14.5px; line-height: 1.55; color: var(--text); }
.chal-note {
  margin: 0; padding: 9px 12px; border-radius: var(--r-md); background: var(--surface-2);
  font-size: 13px; line-height: 1.5; color: var(--text-dim);
}
.chal-meta { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.chal-modal code, .chal-side code { font-family: var(--font-mono); font-size: .92em; }

/* ------------------------------------------------ Be the algorithm: page */
/* The player's controls and narration step aside for a one-line hint (or
   the panel itself, when the sidebar is hidden); the toolbar and stage
   stop taking input; the code panel makes way for "Your move". */
.viz--challenge .transport > :not(.chal-hint):not(.chal-side) { display: none; }
.viz--challenge .toolbar { pointer-events: none; opacity: .45; }
.viz--challenge .stage { pointer-events: none; }
.viz--challenge .side [data-role="code"] { display: none; }
.viz .side [data-role="challenge"] { order: 2; }
.chal-hint { flex: 0 0 100%; padding: 4px 6px; text-align: center; font-size: 15px; line-height: 1.4; color: var(--text-dim); }
.chal-hint b { color: var(--text); }

/* The "Your move" panel */
.chal-side { border-color: color-mix(in srgb, var(--indigo) 45%, var(--border)); background: var(--surface); }
.viz .side .chal-side > .panel__head { color: var(--text); gap: 10px; }
.chal-side--under { flex: 0 0 100%; }
.chal-progress { display: flex; align-items: center; gap: 10px; }
.chal-pips { flex: 1; min-width: 0; display: flex; gap: 3px; }
.chal-pips i {
  flex: 1; max-width: 22px; height: 6px; border-radius: 999px; background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border-strong); transition: background var(--dur);
}
.chal-pips i.is-now { background: var(--c-primary); box-shadow: none; }
.chal-pips i.is-right { background: var(--c-sorted); box-shadow: none; }
.chal-pips i.is-wrong { background: var(--c-swap); box-shadow: none; }
.chal-count { margin-left: auto; white-space: nowrap; font-size: 11.5px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.chal-side .panel__body { display: flex; flex-direction: column; gap: 10px; }
/* The question, big; the facts to answer it, in a quiet box under it. */
.chal-prompt { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.4; letter-spacing: -.005em; color: var(--text); }
.chal-prompt.is-wait { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.chal-prompt b { color: var(--indigo); }
.chal-where {
  margin: 0; padding: 8px 11px; border-radius: var(--r-md); background: var(--surface-2);
  font-size: 13.5px; line-height: 1.5; color: var(--text-dim);
}
.chal-where:empty { display: none; }
.chal-where b { color: var(--text); font-weight: 700; }
.chal-choices { display: flex; flex-direction: column; gap: 6px; }
.chal-choices:empty { display: none; }
.chal-choice {
  display: flex; align-items: flex-start; gap: 9px; width: 100%; padding: 9px 11px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); text-align: left;
  font-size: 13.5px; font-weight: 600; line-height: 1.4; transition: border-color var(--dur), background var(--dur);
}
.chal-choice:hover:not(:disabled) { border-color: var(--indigo); background: var(--surface); }
.chal-choice:focus-visible { outline: 2px solid var(--indigo); outline-offset: 1px; }
.chal-choice:disabled { cursor: default; opacity: .6; }
.chal-choice.is-right { opacity: 1; border-color: var(--c-sorted); background: color-mix(in srgb, var(--c-sorted) 14%, transparent); }
.chal-choice.is-wrong { opacity: 1; border-color: var(--c-swap); background: color-mix(in srgb, var(--c-swap) 12%, transparent); }
.chal-choice__no {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 11px; font-weight: 700; background: var(--surface); color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--border);
}
.chal-feedback { font-size: 13px; line-height: 1.5; color: var(--text-dim); }
.chal-feedback:empty { display: none; }
.chal-feedback.is-right, .chal-feedback.is-wrong {
  padding: 8px 11px; border-radius: var(--r-md); background: var(--surface-2); border-left: 3px solid var(--c-sorted);
}
.chal-feedback.is-right { font-weight: 700; color: var(--text); }
.chal-feedback.is-wrong { border-left-color: var(--c-swap); }
.chal-feedback b { color: var(--text); }
.chal-feedback__why { display: block; margin-top: 5px; font-size: 12.5px; color: var(--muted); }
.chal-feedback__why b { color: var(--text-dim); }
.chal-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chal-foot__next:empty { display: none; }
.chal-foot .btn--ghost { margin-left: auto; }
.chal-meter { flex: 0 0 auto; white-space: nowrap; font-size: 11.5px; color: var(--muted); }
.chal-meter.is-last { color: var(--c-swap); font-weight: 600; }

/* ------------------------------------------------------- Why it works */
.chal-q { margin: 0; font-size: 16px; line-height: 1.45; font-weight: 700; color: var(--text); }
.chal-opts { display: flex; flex-direction: column; gap: 7px; }
.chal-opt {
  text-align: left; padding: 10px 13px; border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13.5px; line-height: 1.45;
  transition: border-color var(--dur), background var(--dur);
}
.chal-opt:hover:not(:disabled) { border-color: var(--indigo); }
.chal-opt:disabled { cursor: default; opacity: .7; }
.chal-opt.is-right { opacity: 1; border-color: var(--c-sorted); background: color-mix(in srgb, var(--c-sorted) 12%, transparent); }
.chal-opt.is-wrong { opacity: 1; border-color: var(--c-swap); background: color-mix(in srgb, var(--c-swap) 12%, transparent); }
.chal-why {
  margin: 0; padding: 10px 12px; border-radius: var(--r-md); background: var(--surface-2);
  font-size: 13.5px; line-height: 1.5; color: var(--text-dim);
}
.chal-why b, .chal-why code { color: var(--text); }

@media (max-width: 720px) {
  .chal-scrim { place-items: end center; padding: 0; }
  .chal-modal { border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 88vh; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { .chal-modal { animation: none; } .chal-scrim { transition: none; } }
