/* ===========================================================================
   slide-widgets.css — styling for the schemaVersion 2 interactive blocks.

   Loaded eagerly by slide-runner.html (beat 0 paints immediately, so a lazily
   styled placeholder would flash). Uses only the runner's existing design
   tokens, so a deck's `theme` override recolours widgets for free.

   Everything here is scoped under .blk-widget. Deliberately avoids the class
   names the runner sweeps card-wide on every beat reveal — .beat, .code-line —
   because those get cleared out from under us.
   =========================================================================== */

.blk-widget {
  margin: 14px 0;
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}
/* Once mounted the live widget replaces the static fallback entirely. */
.blk-widget[data-mounted] > .widget-fallback { display: none; }
.blk-widget .w-sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- shared chrome ---- */
.w-kicker {
  font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; margin: 0 0 8px;
}
.w-ask { font-size: 18px; line-height: 1.55; margin: 0 0 14px; }
.w-ask strong { color: var(--accent); }
.w-hint { font-size: 14px; color: var(--muted); margin: 0 0 12px; }
.w-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.w-btn {
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: 9px; cursor: pointer;
  background: var(--accent); color: #06202c; border: 1px solid var(--accent);
  transition: filter .15s ease;
}
.w-btn:hover:not(:disabled) { filter: brightness(1.12); }
.w-btn:disabled { opacity: .45; cursor: default; }
.w-btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.w-btn:focus-visible, .w-chip:focus-visible, .w-bucket:focus-visible,
.w-cell:focus-visible, .w-blank:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.w-input, .w-area {
  font: inherit; font-size: 16px; width: 100%; box-sizing: border-box;
  padding: 10px 12px; border-radius: 9px; resize: vertical;
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line);
}
.w-area { min-height: 92px; line-height: 1.5; }
.w-input:focus, .w-area:focus { outline: none; border-color: var(--accent); }

.w-verdict {
  margin-top: 14px; padding: 12px 14px; border-radius: 10px;
  font-size: 15px; line-height: 1.55;
  border: 1px solid var(--line); background: var(--bg-2);
}
.w-verdict.good { border-color: var(--good); }
.w-verdict.bad  { border-color: var(--warn); }
.w-verdict .w-head { font-weight: 700; display: block; margin-bottom: 4px; }
.w-verdict.good .w-head { color: var(--good); }
.w-verdict.bad  .w-head { color: var(--warn); }
.w-why { margin: 8px 0 0; padding-left: 18px; font-size: 14px; color: var(--muted); }
.w-why li { margin: 4px 0; }

/* ---- selectable items (sort / order / match) ---- */
.w-chip {
  font: inherit; font-size: 15px; text-align: left; cursor: pointer;
  padding: 9px 13px; border-radius: 9px; margin: 0;
  background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line);
  transition: border-color .15s ease, background .15s ease;
  touch-action: none; /* pointer-drag skin owns the gesture */
}
.w-chip:hover:not(:disabled) { border-color: rgba(var(--accent-rgb), .55); }
.w-chip[aria-pressed="true"] { border-color: var(--accent); background: rgba(var(--accent-rgb), .14); }
.w-chip.correct { border-color: var(--good); }
.w-chip.wrong   { border-color: var(--bad); }
.w-chip.dragging { opacity: .5; }
.w-pool { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 14px; }
.w-pool:empty::after {
  content: "all placed"; color: var(--muted); font-size: 13px; font-style: italic;
}

.w-buckets { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.w-bucket {
  display: block; width: 100%; text-align: left; font: inherit; cursor: pointer;
  padding: 12px; border-radius: 11px; min-height: 92px;
  background: var(--bg-2); color: var(--ink);
  border: 1px dashed var(--line);
}
.w-bucket:hover, .w-bucket.over { border-color: var(--accent); }
.w-bucket > h4 {
  margin: 0 0 9px; font-size: 12px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted);
}
.w-bucket .w-drop { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- order ---- */
.w-order { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.w-order li { display: flex; align-items: center; gap: 10px; }
.w-order .w-rank {
  flex: 0 0 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: rgba(var(--accent-rgb), .16); color: var(--accent);
}
/* the ordered item is a label div, not a control — the arrows do the moving */
.w-order .w-chip { flex: 1; cursor: default; }
.w-order .w-chip:hover { border-color: var(--line); }
.w-move { display: flex; flex-direction: column; gap: 2px; }
.w-move button {
  font: inherit; font-size: 11px; line-height: 1; padding: 3px 7px; cursor: pointer;
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 5px;
}
.w-move button:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.w-move button:disabled { opacity: .3; cursor: default; }

/* ---- match ---- */
.w-match { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.w-match .w-col { display: grid; gap: 9px; align-content: start; }
.w-match .w-chip[data-paired="1"] { border-color: var(--accent); }
.w-pairnum {
  font-size: 11px; font-weight: 700; color: var(--accent);
  margin-left: 8px; opacity: .85;
}

/* ---- cloze ---- */
.w-cloze {
  font-family: ui-monospace, Consolas, monospace; font-size: 15px;
  line-height: 2.1; white-space: pre-wrap; word-break: break-word;
  padding: 14px; border-radius: 10px;
  background: var(--bg-2); border: 1px solid var(--line);
}
.w-cloze.prose { font-family: inherit; line-height: 1.9; white-space: normal; }
.w-blank {
  font: inherit; font-size: 14px; width: 11ch; text-align: center;
  padding: 3px 7px; border-radius: 6px; margin: 0 2px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--accent);
}
/* A blank typeset inside a math-mode cloze: sits on the formula's baseline and
   scales with the KaTeX around it rather than with the widget's 14px. */
.w-cloze-math { overflow-x: auto; text-align: center; font-size: 1.35em; line-height: 2.1; }
.w-cloze-math .w-blank-math {
  font-family: inherit; font-size: 0.8em; padding: 1px 4px; margin: 0 0.15em;
  vertical-align: middle; min-width: 3ch; box-sizing: content-box;
}
.w-blank.correct { border-color: var(--good); }
.w-blank.wrong   { border-color: var(--bad); }

/* ---- eliminate ---- */
.w-elim { display: grid; gap: 9px; }
.w-elim .w-opt {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 11px 13px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.w-elim .w-opt.out { opacity: .5; }
.w-elim .w-opt.out .w-opt-text { text-decoration: line-through; }
.w-elim .w-opt.kept { border-color: var(--good); }
.w-elim .w-opt.misfire { border-color: var(--bad); }
.w-elim .w-opt-text { flex: 1; font-size: 15px; line-height: 1.5; }
.w-elim .w-why-line { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }

/* ---- matrix ---- */
.w-matrix { width: 100%; overflow-x: auto; }
.w-matrix table { width: 100%; border-collapse: collapse; font-size: 15px; }
.w-matrix th, .w-matrix td {
  text-align: left; padding: 9px 11px; border: 1px solid var(--line); vertical-align: top;
}
.w-matrix th { color: var(--muted); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.w-cell { width: 100%; box-sizing: border-box; font: inherit; font-size: 14px;
  padding: 6px 8px; border-radius: 6px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--accent); }
.w-cell.correct { border-color: var(--good); }
.w-cell.wrong   { border-color: var(--bad); }

/* ---- annotate ---- */
.w-annotate .w-target {
  padding: 14px; border-radius: 10px; margin-bottom: 12px;
  background: var(--bg-2); border: 1px solid var(--line); overflow-x: auto;
}
.w-annotate .w-src {
  font-family: ui-monospace, Consolas, monospace; font-size: 14px;
  line-height: 1.75; white-space: pre; margin: 0;
}
/* deliberately NOT .code-line — the runner clears that class card-wide */
.w-annotate .w-srcline { display: block; padding: 0 4px; border-radius: 4px; }
.w-annotate .w-srcline.lit { background: rgba(var(--accent-rgb), .18); }
.w-notes { display: grid; gap: 8px; }
.w-note {
  display: flex; gap: 11px; align-items: flex-start; width: 100%;
  font: inherit; font-size: 15px; text-align: left; cursor: pointer;
  padding: 10px 12px; border-radius: 9px;
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
}
.w-note:hover, .w-note[aria-expanded="true"] { border-color: var(--accent); }
.w-note .w-num {
  flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  background: rgba(var(--accent-rgb), .18); color: var(--accent);
}

/* ---- slider ---- */
.w-params { display: grid; gap: 14px; margin-bottom: 14px; }
.w-param { display: grid; gap: 6px; }
.w-param .w-label { display: flex; justify-content: space-between; font-size: 14px; }
.w-param .w-val { font-family: ui-monospace, Consolas, monospace; color: var(--accent); }
.w-param input[type="range"] { width: 100%; accent-color: var(--accent); }
.w-plot { width: 100%; display: block; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); }
.w-readout { margin-top: 10px; text-align: center; }

/* ---- canvas ---- */
.w-canvas-wrap { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--bg-2); }
.w-canvas { display: block; width: 100%; touch-action: none; cursor: crosshair; }
.w-canvas-tools { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.w-canvas-note { font-size: 13px; color: var(--muted); }

/* ---- stepper ---- */
.w-stepper .w-stage {
  min-height: 130px; padding: 16px; border-radius: 10px; margin-bottom: 12px;
  background: var(--bg-2); border: 1px solid var(--line); overflow-x: auto;
}
.w-cells { display: flex; gap: 6px; flex-wrap: wrap; }
.w-cellbox {
  min-width: 44px; padding: 10px 8px; border-radius: 8px; text-align: center;
  font-family: ui-monospace, Consolas, monospace; font-size: 15px;
  background: var(--panel); border: 1px solid var(--line);
}
.w-cellbox.on { border-color: var(--accent); background: rgba(var(--accent-rgb), .16); }
.w-cellbox.done { border-color: var(--good); }
.w-cellbox .w-idx { display: block; font-size: 10px; color: var(--muted); margin-top: 4px; }
.w-stepbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.w-stepbar .w-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.w-caption { margin-top: 10px; font-size: 15px; line-height: 1.55; }
.w-nodes { display: flex; gap: 14px; flex-wrap: wrap; }
.w-node {
  min-width: 40px; padding: 9px 12px; border-radius: 999px; text-align: center;
  font-size: 14px; background: var(--panel); border: 1px solid var(--line);
}
.w-node.on { border-color: var(--accent); background: rgba(var(--accent-rgb), .16); }
.w-node.done { border-color: var(--good); }

/* ---- media (pre-rendered Manim) ---- */
.w-media figure { margin: 0; }
.w-media .w-frame {
  position: relative; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--line); background: var(--bg-2);
  box-shadow: 0 18px 40px rgba(0,0,0,.34);
}
.w-media video, .w-media img.w-poster { display: block; width: 100%; height: auto; }
.w-media .w-play {
  position: absolute; inset: 0; display: grid; place-items: center;
  /* Light scrim only. For a `steps` clip the poster IS the content — the last
     frame of the worked example — so dimming it to signal "not playing" would
     hide the very thing the slide is there to show. */
  background: rgba(5,13,24,.14); border: 0; cursor: pointer; color: var(--ink);
  transition: background .15s ease;
}
.w-media .w-play:hover { background: rgba(5,13,24,.30); }
.w-media .w-play span {
  padding: 11px 20px; border-radius: 999px; font: inherit; font-weight: 600; font-size: 15px;
  background: var(--accent); color: #06202c;
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
.w-media figcaption { margin-top: 9px; font-size: 14px; color: var(--muted); }
.w-media .w-takeaway { margin-top: 10px; font-size: 16px; line-height: 1.55; }
.w-media .w-scrub { width: 100%; margin-top: 9px; accent-color: var(--accent); }
.w-media .w-unavailable { padding: 22px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---- reveal ---- */
.w-reveal-body { margin-top: 12px; }

@media (max-width: 720px) {
  .blk-widget { padding: 14px; }
  .w-match { grid-template-columns: 1fr; }
  .w-buckets { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .blk-widget, .blk-widget * { transition: none !important; animation: none !important; }
}
