/* SkeleTrace algorithm lab. Copyright (C) 2026 whispr.dev. Builds on /assets/site.css: the same tokens, IBM Plex faces and type scale.
   Layout: the site's contents column lists the demos on the left; the bench on the right holds one demo at a time,
   drawn large in a well, with its controls under the drawing and every step narrated beneath. */
:root {
  --edge: #97a3af;
  --well: var(--code);
  --soft: #d6e4ea;
  --now: var(--ochre);
  --now-soft: #f3e7d3;
  --cut: #b4363c;
  --cut-soft: #f6dcdc;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s1-soft: #dbe8fa;
  --s2-soft: #fbe2d8;
  --s3-soft: #d5f2e7;
  --s4-soft: #fbedc9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --edge: #52657a;
    --soft: #20343f;
    --now-soft: #3a3122;
    --cut: #ff8a8a;
    --cut-soft: #3e1f25;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s1-soft: #15283f;
    --s2-soft: #3a1f14;
    --s3-soft: #0f2e24;
    --s4-soft: #33270b;
  }
}

/* bench */
.lab [hidden] { display: none !important; }
.lab-picker { display: none; align-items: center; gap: 10px; margin: 0 0 18px; color: var(--ink-2); }
.lab-toc h2 { margin: 18px 0 8px; }
.lab-toc h2:first-child { margin-top: 4px; }
.lab-toc a[aria-current="page"] { color: var(--ink); border-left-color: var(--ink); font-weight: 600; }
.lab-stage { min-width: 0; }
.lab-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.lab-title h2 { margin: 0; font: 400 28px/1.2 var(--serif); text-wrap: balance; }
.cost { font: 600 13px/1 var(--sans); color: var(--ink-2); border: 1px solid var(--rule-strong); border-radius: 3px; padding: 4px 7px; white-space: nowrap; }
.lab-call { margin: 8px 0 0; }
.lab-call code { overflow-wrap: anywhere; }
.lab-idea { margin: 12px 0 18px; color: var(--ink-2); max-width: var(--measure); }
.lab-inputs { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 0 0 14px; font-size: 15px; }
.lab-inputs:empty { display: none; }
.field { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); }
.hint { color: var(--ink-3); font-size: 14.5px; }
.lab select, .lab input[type="number"], .lab input[type="text"], .lab input[type="time"] {
  font: inherit; font-size: 15px; line-height: 1.3; color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule-strong); border-radius: 4px; padding: 6px 10px; max-width: 100%;
}
.lab input[type="number"] { width: 5.5em; }
.lab input[type="text"] { width: min(22em, 100%); }
.lab input[type="range"], .lab input[type="checkbox"] { accent-color: var(--accent); }
.lab input[type="checkbox"] { width: 16px; height: 16px; margin: 0; }
.lab button { font: inherit; line-height: 1.25; cursor: pointer; }
.lab button:disabled { opacity: .45; cursor: default; }
.btn { display: inline-block; padding: 9px 16px; border: 1px solid var(--rule-strong); border-radius: 4px; background: transparent; color: var(--ink); font-weight: 600; font-size: 15.5px; }
.btn:hover:not(:disabled) { border-color: var(--ink-2); }
.lab .button { font-size: 15.5px; }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 4px; overflow: hidden; }
.seg button { border: 0; border-right: 1px solid var(--rule-strong); background: transparent; color: var(--ink-2); font-weight: 600; font-size: 14.5px; padding: 7px 12px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--paper); }

/* the drawing */
.lab-canvas { margin: 0; overflow-x: auto; background: var(--well); border: 1px solid var(--rule); border-radius: 4px; }
.lab-canvas > svg { display: block; width: 100%; height: auto; }
.lab-canvas > svg.wide { min-width: 640px; }
.lab-cap { margin: 8px 0 0; font-size: 14.5px; color: var(--ink-3); max-width: var(--measure); }
.lab-transport { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.stepno { font: 400 13.5px/1 var(--mono); color: var(--ink-3); min-width: 10ch; }
.speed { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; color: var(--ink-3); font-size: 14.5px; }
.say { margin: 14px 0 0; padding: 10px 14px; border-left: 3px solid var(--now); background: var(--well); border-radius: 0 4px 4px 0; min-height: 3.6em; color: var(--ink); }
.lab-state { margin-top: 14px; display: grid; gap: 8px; }
.lab-state:empty { display: none; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lbl { font-weight: 600; font-size: 14px; color: var(--ink-3); min-width: 11.5em; }
.chip { font: 400 13px/1.3 var(--mono); padding: 3px 7px; border: 1px solid var(--rule); border-radius: 3px; background: var(--paper); color: var(--ink); }
.chip.done { background: var(--soft); border-color: transparent; }
.chip.cut { border-color: var(--cut); background: var(--cut-soft); }
.chip.g1 { border-color: var(--s1); background: var(--s1-soft); }
.chip.g2 { border-color: var(--s2); background: var(--s2-soft); }
.chip.g3 { border-color: var(--s3); background: var(--s3-soft); }
.chip.g4 { border-color: var(--s4); background: var(--s4-soft); }
.none { color: var(--ink-3); font-size: 14px; font-style: italic; }
.evidence { margin: 4px 0 0; padding-left: 1.4em; display: grid; gap: 3px; font-size: 15px; }
.evidence li.done { color: var(--ink-3); }
.evidence li.now { color: var(--ink); font-weight: 600; }
.evidence li.next { color: var(--ink-2); }
.lab-use { margin: 22px 0 0; padding-top: 14px; border-top: 1px solid var(--rule); color: var(--ink-2); max-width: var(--measure); }
.lab-use b { color: var(--ink); font-weight: 600; }
.lab-foot { margin: 44px 0 0; padding-top: 14px; border-top: 1px solid var(--rule); color: var(--ink-3); font-size: 14.5px; max-width: 80ch; }

/* the sorting race and the playground */
.race { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 10px; }
.lanebox { background: var(--paper); border: 1px solid var(--rule); border-radius: 4px; padding: 8px 10px 6px; min-width: 0; }
.lanebox h3 { margin: 0 0 2px; font: 600 16px/1.3 var(--sans); }
.lanebox .meta { font: 400 12.5px/1.4 var(--mono); color: var(--ink-3); }
.lanebox.fin h3 { color: var(--accent); }
.lanebox svg { display: block; width: 100%; height: auto; margin-top: 4px; }
.lab-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card { border: 1px solid var(--rule); border-radius: 4px; padding: 14px 16px; min-width: 0; }
.card h3 { margin: 0 0 6px; font: 600 17px/1.3 var(--sans); }
.card code { font-size: 12.5px; overflow-wrap: anywhere; }
.card p { margin: 8px 0 10px; color: var(--ink-2); font-size: 15px; }
.card .lab-inputs { margin-bottom: 10px; }
.out { font: 400 13.5px/1.6 var(--mono); overflow-wrap: anywhere; color: var(--ink); }
.out .on { color: var(--accent); }
.out mark { background: var(--now-soft); color: var(--ink); border-radius: 2px; padding: 0 1px; }
.out .chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0; }

/* drawings */
.lab-canvas svg text { font-family: var(--mono); font-size: 11.5px; fill: var(--ink); }
.lab-canvas svg .val { font-family: var(--sans); font-weight: 600; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.lab-canvas svg .tiny { font-size: 10px; }
.lab-canvas svg .lane, .lab-canvas svg .axis, .lab-canvas svg .idx, .lab-canvas svg .tag { fill: var(--ink-3); font-size: 11px; }
.lab-canvas svg .heading { fill: var(--ink-2); font-family: var(--sans); font-size: 13px; }
.lab-canvas svg .marker { fill: var(--now); font-family: var(--sans); font-weight: 600; font-size: 12px; }
.lab-canvas svg .normal { fill: var(--ink-2); font-family: var(--sans); font-size: 12px; }
.e { stroke: var(--edge); stroke-width: 1.6; fill: none; }
.e.tree, .e.done { stroke: var(--accent); stroke-width: 2.4; }
.e.hot { stroke: var(--now); stroke-width: 3.2; }
.e.path { stroke: var(--accent); stroke-width: 4.5; }
.e.bridge, .e.cut { stroke: var(--cut); stroke-width: 3; stroke-dasharray: 7 4; }
.e.gone { stroke-opacity: .2; stroke-dasharray: 2 4; }
.ah { fill: var(--edge); }
.ah.hot { fill: var(--now); }
.ah.cut { fill: var(--cut); }
.ah.done { fill: var(--accent); }
.n rect, .n circle { fill: var(--paper); stroke: var(--edge); stroke-width: 1.4; }
.n.queued rect, .n.queued circle { fill: var(--soft); stroke: var(--accent); stroke-dasharray: 4 3; }
.n.seen rect, .n.seen circle { fill: var(--soft); stroke: var(--accent); }
.n.path rect { stroke: var(--accent); stroke-width: 3.2; stroke-dasharray: none; }
.n.now rect, .n.now circle { fill: var(--now-soft); stroke: var(--now); stroke-width: 2.8; stroke-dasharray: none; }
.n.cut rect { fill: var(--cut-soft); stroke: var(--cut); stroke-width: 2.6; }
.n.gone { opacity: .28; }
.n.g1 rect { fill: var(--s1-soft); stroke: var(--s1); stroke-width: 2.2; }
.n.g2 rect { fill: var(--s2-soft); stroke: var(--s2); stroke-width: 2.2; }
.n.g3 rect { fill: var(--s3-soft); stroke: var(--s3); stroke-width: 2.2; }
.n.g4 rect { fill: var(--s4-soft); stroke: var(--s4); stroke-width: 2.2; }
.n.g1.now rect, .n.g2.now rect, .n.g3.now rect, .n.g4.now rect { stroke: var(--now); stroke-width: 2.8; }
.n.uf { transition: transform .45s ease; }
.badge circle { fill: var(--ink); stroke: var(--paper); stroke-width: 1.5; }
.lab-canvas svg .badge text { fill: var(--paper); font-family: var(--sans); font-weight: 600; font-size: 10.5px; }
.badge.ord circle { fill: var(--accent); }
.clickable .n, .clickable .act, .clickable .place { cursor: pointer; }
.cell rect { fill: var(--paper); stroke: var(--edge); stroke-width: 1.2; }
.cell.empty rect { fill: none; stroke-dasharray: 3 3; }
.cell.live rect { stroke: var(--accent); }
.cell.out { opacity: .35; }
.cell.seen rect { fill: var(--soft); stroke: var(--accent); }
.cell.span rect { fill: var(--now-soft); }
.cell.now rect { fill: var(--now-soft); stroke: var(--now); stroke-width: 2.4; }
.cell.answer rect { fill: var(--accent); stroke: var(--accent); }
.lab-canvas svg .cell.answer text { fill: var(--paper); }
.box rect { fill: var(--paper); stroke: var(--edge); stroke-width: 1.2; }
.box.s1 rect { fill: var(--s1-soft); stroke: var(--s1); }
.box.s2 rect { fill: var(--s2-soft); stroke: var(--s2); }
.box.s3 rect { fill: var(--s3-soft); stroke: var(--s3); }
.box.spent { opacity: .3; }
.box.inheap rect { stroke-width: 2.6; }
.box.now rect { stroke: var(--now); stroke-width: 3; }
.tray { fill: none; stroke: var(--edge); stroke-dasharray: 5 4; }
.bar { fill: var(--ink-3); }
.bar.hl { fill: var(--now); }
.bar.fixed { fill: var(--accent); fill-opacity: .55; }
.fin .bar { fill: var(--accent); fill-opacity: 1; }
.post { fill: var(--ink-3); fill-opacity: .45; }
.post.seen { fill-opacity: 1; }
.post.best { fill: var(--accent); fill-opacity: 1; }
.post.now { stroke: var(--now); stroke-width: 3; }
.gridline { stroke: var(--rule); stroke-width: 1; }
.baseline { stroke: var(--ink-2); stroke-width: 1.6; stroke-dasharray: 6 4; }
.act rect { fill: var(--paper); stroke: var(--rule-strong); }
.act.on rect { fill: var(--accent); stroke: var(--accent); }
.lab-canvas svg .act.on text { fill: var(--paper); }
.place rect { stroke-width: 1.2; }
.place.H rect { fill: var(--s1-soft); stroke: var(--s1); }
.place.W rect { fill: var(--s2-soft); stroke: var(--s2); }
.place.T rect { fill: var(--s3-soft); stroke: var(--s3); }
.place.pending { opacity: .4; }
.outline { fill: none; stroke: var(--now); stroke-width: 3.5; }
.outline.sq { stroke-dasharray: 7 4; }
.pt { fill: var(--ink); }
.pt.dim { fill-opacity: .25; }
.pt.pick { fill: var(--accent); }
.split { stroke: var(--ink-2); stroke-dasharray: 5 5; stroke-width: 1.2; }
.strip { fill: var(--now-soft); fill-opacity: .8; }
.try { stroke: var(--now); stroke-width: 2.2; stroke-dasharray: 4 3; }
.bestline { stroke: var(--accent); stroke-width: 3.5; }

/* text sweeps: the tree of terms, its failure links and the matches under the text */
.tn circle { fill: var(--paper); stroke: var(--edge); stroke-width: 1.4; }
.tn.root circle { fill: var(--ink-2); stroke: var(--ink-2); }
.tn.end circle { stroke: var(--accent); stroke-width: 3; }
.tn.hot circle { fill: var(--now-soft); stroke: var(--now); stroke-width: 2.6; }
.tn.tried circle { fill: var(--cut-soft); stroke: var(--cut); stroke-width: 2.2; }
.tn.now circle { fill: var(--now-soft); stroke: var(--now); stroke-width: 3.2; }
.fail { fill: none; stroke: var(--ink-3); stroke-width: 1.1; stroke-dasharray: 4 3; stroke-opacity: .7; }
.fail.hot { stroke: var(--now); stroke-width: 2.4; stroke-dasharray: none; stroke-opacity: 1; }
.hitbar { fill: var(--accent); }
.hitbar.fresh { fill: var(--now); }

/* the strongest chain: confidences on the links */
.conf rect { fill: var(--paper); stroke: var(--rule); }

/* geofences */
.fencepoly { fill: var(--s1-soft); fill-opacity: .7; stroke: none; }
.fedge { stroke: var(--s1); stroke-width: 2; }
.fedge.crossed { stroke: var(--now); stroke-width: 4; }
.fedge.on { stroke: var(--cut); stroke-width: 4; }
.ray { stroke: var(--now); stroke-width: 1.8; stroke-dasharray: 6 4; }
.pt.edgept { fill: var(--paper); stroke: var(--now); stroke-width: 2.6; }
.pt.todo { fill: var(--paper); stroke: var(--ink-3); stroke-width: 1.5; }
.pt.dropped { fill: var(--cut-soft); stroke: var(--cut); stroke-width: 3; }
.pt.current { stroke: var(--now); stroke-width: 3; }
.hullpoly { fill: var(--now-soft); fill-opacity: .55; stroke: var(--now); stroke-width: 3; }

@media (max-width: 920px) {
  .lab-toc { display: none; }
  .lab-picker { display: flex; }
}
@media (max-width: 560px) {
  .race, .lab-cards { grid-template-columns: minmax(0, 1fr); }
  .lab-title h2 { font-size: 24px; }
  .speed { margin-left: 0; }
  .lbl { min-width: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .n.uf { transition: none; }
}
@media print {
  .lab-picker, .lab-transport, .lab-inputs { display: none; }
}
