/* CMSC 441 readings: step-through figures, matrices, Try-it cards. Colors are
   tokens so everything follows the light/dark toggle. */
[data-md-color-scheme] {
  --k-path: #2f6fdb;      /* the augmenting path / current cell / accepted */
  --k-back: #c26a1b;      /* residual back edges */
  --k-cancel: #c93a3a;    /* cancellation, rejection */
  --k-chg: #2e9e6a;       /* entries that just changed */
  --k-hl: rgba(47, 111, 219, 0.12);
  --k-chg-bg: rgba(46, 158, 106, 0.16);
  --k-cur-bg: rgba(47, 111, 219, 0.22);
  --k-card: var(--md-code-bg-color);
}

[data-md-color-scheme="slate"] {
  --k-path: #6fa0ff;
  --k-back: #f0a35e;
  --k-cancel: #f07a7a;
  --k-chg: #5cc996;
  --k-hl: rgba(111, 160, 255, 0.16);
  --k-chg-bg: rgba(92, 201, 150, 0.2);
  --k-cur-bg: rgba(111, 160, 255, 0.3);
}

/* ---------- steppers ---------- */

.stepper {
  margin: 1.4em 0;
  padding: 0.8em 1em 0.9em;
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 8px;
  background: var(--k-card);
  outline: none;
}
.stepper:focus-visible { border-color: var(--k-path); }
.stepper.static { background: none; border: none; padding: 0; }

.st-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1em;
  font-size: 0.75rem;
  margin-bottom: 0.5em;
}
.st-title { font-weight: 700; }
.st-count { color: var(--md-default-fg-color--light); white-space: nowrap; }

.st-body { overflow-x: auto; }
.st-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6em 1.2em;
}
.st-op { font-size: 1.1rem; color: var(--md-default-fg-color--light); }

.st-caption {
  margin-top: 0.7em;
  font-size: 0.72rem;
  line-height: 1.6;
  min-height: 3.2em;
}

.st-controls {
  display: flex;
  align-items: center;
  gap: 0.8em;
  margin-top: 0.6em;
}
.st-controls input[type="range"] { flex: 1; accent-color: var(--k-path); }

.stepper button,
.tryit button {
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.35em 0.9em;
  border-radius: 6px;
  border: 1px solid var(--md-default-fg-color--lighter);
  background: var(--md-default-bg-color);
  color: var(--md-default-fg-color);
  cursor: pointer;
}
.stepper button:hover:not(:disabled),
.tryit button:hover { border-color: var(--k-path); color: var(--k-path); }
.stepper button:disabled { opacity: 0.4; cursor: default; }

.st-error { color: var(--k-cancel); font-weight: 600; }

/* ---------- graphs ---------- */

.sg { text-align: center; flex: 1 1 380px; max-width: 560px; }
/* Matrix steppers keep the graph small beside the tables. */
.st-row > .sg:has(+ .mx), .st-row > .sg:has(+ table) { flex: 0 1 260px; }
.sg-heading { font-size: 0.68rem; font-weight: 600; color: var(--md-default-fg-color--light); margin-bottom: 0.2em; }
.sg svg { width: 100%; height: auto; display: block; margin: 0 auto; min-width: 240px; font-family: var(--md-text-font-family); }

.sg-edge { fill: none; stroke: var(--md-default-fg-color--light); stroke-width: 1.6; }
.sg-head { fill: var(--md-default-fg-color--light); }
.sg-label {
  font-size: 13px;
  text-anchor: middle;
  fill: var(--md-default-fg-color);
  paint-order: stroke;
  stroke: var(--k-card);
  stroke-width: 4px;
  stroke-linejoin: round;
}
.stepper.static .sg-label { stroke: var(--md-default-bg-color); }

.sg-edge.back { stroke: var(--k-back); }
.sg-head.back, .sg-label.back { fill: var(--k-back); }
.sg-edge.sat { stroke: var(--md-default-fg-color); stroke-width: 2.2; }
.sg-head.sat { fill: var(--md-default-fg-color); }
.sg-edge.flow { stroke: var(--md-default-fg-color); stroke-width: 3; }
.sg-head.flow { fill: var(--md-default-fg-color); }
.sg-edge.path { stroke: var(--k-path); stroke-width: 3.2; }
.sg-head.path { fill: var(--k-path); }
.sg-label.path { fill: var(--k-path); font-weight: 700; }
.sg-edge.cancel { stroke: var(--k-cancel); stroke-width: 3; }
.sg-head.cancel { fill: var(--k-cancel); }
.sg-label.cancel { fill: var(--k-cancel); font-weight: 700; }
.sg-edge.dashed { stroke-dasharray: 5 4; }
.sg-delta { font-weight: 700; font-size: 12px; }
.sg-delta.up { fill: var(--k-path); }
.sg-delta.down { fill: var(--k-cancel); }

.sg-node circle { fill: var(--md-default-bg-color); stroke: var(--md-default-fg-color); stroke-width: 1.6; }
.sg-node text { font-size: 14px; font-weight: 700; text-anchor: middle; fill: var(--md-default-fg-color); }
.sg-node.st circle { fill: var(--k-hl); }
.sg-node.hl circle { stroke: var(--k-path); stroke-width: 2.6; }

/* ---------- matrices ---------- */

.md-typeset table.mx {
  display: table;
  border-collapse: collapse;
  font-size: 0.7rem;
  margin: 0;
  border: none;
  box-shadow: none;
  background: none;
  font-variant-numeric: tabular-nums;
}
.md-typeset table.mx caption { caption-side: top; font-weight: 600; padding-bottom: 0.25em; }
.md-typeset table.mx th,
.md-typeset table.mx td {
  padding: 0.25em 0.55em;
  min-width: 2.2em;
  text-align: center;
  border: 1px solid var(--md-default-fg-color--lightest);
  background: var(--md-default-bg-color);
}
.md-typeset table.mx th { color: var(--md-default-fg-color--light); font-weight: 600; background: none; border-color: transparent; }
.md-typeset table.mx td.hl-row,
.md-typeset table.mx td.hl-col { background: var(--k-hl); }
.md-typeset table.mx td.chg { background: var(--k-chg-bg); color: var(--k-chg); font-weight: 700; }
.md-typeset table.mx td.cur { background: var(--k-cur-bg); font-weight: 700; outline: 2px solid var(--k-path); outline-offset: -2px; }

/* ---------- Gale-Shapley preference lists ---------- */

.prefs-wrap { display: flex; flex-wrap: wrap; gap: 0.4em 1.6em; justify-content: center; }
.md-typeset table.prefs { display: table; border: none; box-shadow: none; background: none; font-size: 0.72rem; margin: 0; }
.md-typeset table.prefs caption { caption-side: top; font-weight: 600; font-size: 0.68rem; color: var(--md-default-fg-color--light); }
.md-typeset table.prefs th, .md-typeset table.prefs td { border: none; padding: 0.15em 0.4em; background: none; }
.md-typeset table.prefs th { font-weight: 700; }
.prefs td span { display: inline-block; min-width: 1.4em; text-align: center; border-radius: 4px; }
.prefs td span.struck { text-decoration: line-through; color: var(--md-default-fg-color--lighter); }
.prefs td span.held { outline: 1.5px solid var(--md-default-fg-color); font-weight: 700; }
.prefs td span.cur { background: var(--k-cur-bg); color: var(--k-path); font-weight: 700; }

/* ---------- Try-it cards ---------- */

.md-typeset .tryit {
  margin: 1.4em 0;
  padding: 0.7em 1em;
  border-left: 4px solid var(--k-chg);
  background: var(--k-card);
  border-radius: 0 8px 8px 0;
}
.md-typeset .tryit > p:first-child::before {
  content: "Try it";
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--k-chg);
  margin-bottom: 0.2em;
}
.md-typeset .tryit-step {
  border-top: 1px dashed var(--md-default-fg-color--lighter);
  margin-top: 0.6em;
  padding-top: 0.4em;
}
.tryit-bar { display: flex; gap: 0.6em; margin: 0.6em 0 0.2em; }
.tryit-hide { opacity: 0.7; }

/* Legend chips used in captions and text. */
.k-back { color: var(--k-back); font-weight: 600; }
.k-cancel { color: var(--k-cancel); font-weight: 600; }
.k-path { color: var(--k-path); font-weight: 600; }
.k-chg { color: var(--k-chg); font-weight: 600; }

/* Small worked matrices written by hand in the text. */
.md-typeset table.small { display: table; font-size: 0.7rem; }

.md-content__inner { margin-bottom: 10vh; }

/* Hand-written matrices in Try-it cards: compact, not full width. */
.md-typeset .tryit table:not([class]) ,
.md-typeset table.small { font-size: 0.7rem; }
.md-typeset .tryit .md-typeset__table { display: inline-block; }
.md-typeset .tryit table th,
.md-typeset .tryit table td { padding: 0.3em 0.9em; min-width: 0; }

/* Gale-Shapley: keep the drawing small and the lists readable. */
.st-row > .sg:has(+ .prefs-wrap) { flex: 0 1 220px; }
.md-typeset table.prefs { font-size: 0.85rem; }
