/* Visualizations — playback chrome + stage renderers.
 *
 * Reuses the design tokens from variables.css; no new color system. The
 * cell/graph states are semantic: default / active / done / highlight / out /
 * match / frontier / visited. These are the states the 12 definitions emit, so
 * they must all have a visual treatment that reads in both light and dark themes.
 */

.viz-player {
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-primary);
  box-shadow: var(--shadow);
  padding: var(--spacing-md);
  margin: 0 auto;
  max-width: 640px;
}

/* ---- Header ------------------------------------------------------------- */

.viz-header {
  margin-bottom: var(--spacing-md);
}

.viz-title {
  margin: 0 0 var(--spacing-xs);
  font-size: var(--font-size-lg);
  color: var(--text-primary);
}

.viz-desc {
  margin: 0 0 var(--spacing-xs);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

.viz-example {
  margin: 0;
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
}

/* ---- Controls ----------------------------------------------------------- */

.viz-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-md);
}

.viz-controls .btn {
  margin: 0;
}

.viz-speed {
  vertical-align: middle;
  margin-left: var(--spacing-xs);
}

.viz-speed-label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-left: var(--spacing-sm);
}

.viz-speed-value {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  min-width: 1.5ch;
  text-align: right;
}

.viz-progress {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: var(--spacing-sm);
}

/* ---- Stage -------------------------------------------------------------- */

.viz-stage {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
}

.viz-status {
  margin-top: var(--spacing-sm);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  min-height: 1.2em;
  text-align: center;
}

.viz-error {
  color: var(--danger-color);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  white-space: pre-wrap;
}

/* ---- Cell row (arrays, windows, stacks, queues, lists, DP tables) ------ */

.viz-cells {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
}

/* A stack renders top-first (vertical) so the top sits on top. */
.viz-cells[data-kind="stack"] {
  flex-direction: column;
}

.viz-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: var(--spacing-sm);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--bg-primary);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-lg);
  color: var(--text-primary);
  transition: var(--transition);
}

.viz-cell-label {
  font-family: var(--font-family-base);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* State treatments. */
.viz-cell-active {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px var(--primary-color);
}

.viz-cell-done {
  border-color: var(--success-color);
  color: var(--success-color);
}

.viz-cell-highlight {
  border-color: var(--warning-color);
  box-shadow: 0 0 0 2px var(--warning-color);
}

.viz-cell-match {
  border-color: var(--success-color);
  box-shadow: 0 0 0 2px var(--success-color);
  color: var(--success-color);
}

.viz-cell-out {
  opacity: 0.4;
  border-style: dashed;
}

/* In-window elements of a sliding window read as "active"; the best window
 * reads as "match" (above). */

/* ---- Visited strip under the tree -------------------------------------- */

.viz-cells.viz-visited {
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-primary);
}

.viz-strip-label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.viz-cell.viz-chip {
  min-width: 0;
  padding: 0 var(--spacing-sm);
  border-radius: 999px;
  font-size: var(--font-size-sm);
}

/* ---- Graph / tree (SVG) ------------------------------------------------- */

.viz-svg {
  max-width: 100%;
  height: auto;
  background: var(--bg-primary);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
}

.viz-edge {
  stroke: var(--secondary-color);
  stroke-width: 2;
}

.viz-node-dot {
  fill: var(--bg-primary);
  stroke: var(--secondary-color);
  stroke-width: 2;
}

.viz-node-label {
  font-family: var(--font-family-mono);
  font-size: 16px;
  fill: var(--text-primary);
}

.viz-node-active .viz-node-dot {
  stroke: var(--primary-color);
  fill: var(--primary-color);
}
.viz-node-active .viz-node-label { fill: #ffffff; }

.viz-node-done .viz-node-dot {
  stroke: var(--success-color);
  fill: var(--success-color);
}
.viz-node-done .viz-node-label { fill: #ffffff; }

/* BFS frontier = queued-but-not-processed. */
.viz-node-frontier .viz-node-dot {
  stroke: var(--warning-color);
  fill: var(--warning-color);
}
.viz-node-frontier .viz-node-label { fill: #ffffff; }

/* BFS visited = processed. */
.viz-node-visited .viz-node-dot {
  stroke: var(--success-color);
  fill: var(--success-color);
}
.viz-node-visited .viz-node-label { fill: #ffffff; }

/* ---- Selector ----------------------------------------------------------- */

.viz-select-wrap {
  margin: 0 auto var(--spacing-md);
  max-width: 640px;
  text-align: center;
}

.viz-select-wrap label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-right: var(--spacing-sm);
}

/* ---- Per-problem visualization (inline in the detail view) -------------- */

/* The section wrapper in the problem detail view. It sits between the
 * description/examples and the "Solve This Problem" editor. The <h3> heading
 * survives VizPlayer.mount() (which wipes its inner #problem-viz-mount). */
.problem-viz {
  margin: var(--spacing-lg) 0;
}

.problem-viz h3 {
  margin: 0 0 var(--spacing-sm);
  font-size: var(--font-size-lg);
  color: var(--text-primary);
}

/* Chip strip appended under a cell row (a "seen" set, a stack, an
 * accumulator…). Reuses the cell chip treatment from the visited strip. */
.viz-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-primary);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
}

/* ---- Bars (Trapping Rain Water) ---------------------------------------- */

.viz-bar {
  fill: var(--secondary-color);
  transition: var(--transition);
}

.viz-bar-active {
  fill: var(--primary-color);
}

.viz-bar-done {
  fill: var(--success-color);
}

.viz-bar-water {
  fill: var(--primary-color);
  opacity: 0.35;
}

.viz-bar-label {
  font-family: var(--font-family-mono);
  font-size: 12px;
  fill: var(--text-secondary);
}

/* ---- Generic example-walkthrough fallback ------------------------------ */

/* Used only when a problem has no bespoke viz: walk its own examples
 * (input → output) so EVERY problem still shows something. */
.viz-generic {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  width: 100%;
}

.viz-generic-row {
  display: flex;
  align-items: baseline;
  gap: var(--spacing-sm);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
}

.viz-generic-label {
  min-width: 4.5em;
  color: var(--text-secondary);
}

.viz-generic-value {
  color: var(--text-primary);
}

.viz-generic-note {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}
