:root {
  --fg: #1e1e1e; --muted: #777; --line: #e2e2e2; --bg: #fbfbfa; --card: #fff;
  --accent: #d62728; --blue: #2c6fb0;
}
* { box-sizing: border-box; }
/* The `hidden` attribute must win over author display rules (e.g. .clusterlist{display:flex});
   the UA [hidden] rule alone loses to them. */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
header { padding: 1.2rem 1.5rem 0.4rem; max-width: 2100px; margin: 0 auto; }
h1 { margin: 0 0 .2rem; font-size: 1.3rem; }
.sub { color: var(--muted); margin: .2rem 0 0; max-width: 70ch; }

main { padding: 1rem 1.5rem 4rem; max-width: 2100px; margin: 0 auto; }

.toolbar {
  display: flex; flex-direction: column; gap: .5rem; margin-bottom: .6rem;
}
.toolbar-row {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.toolbar select, .toolbar button {
  font: inherit; padding: 3px 9px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--card); cursor: pointer;
}
.toolbar select.active { border-color: #d62728; box-shadow: 0 0 0 1px #d62728; }  /* the live colour scheme */
#colortoggle { font-size: 1rem; line-height: 1; }
.count { font-variant-numeric: tabular-nums; font-weight: 600; }
.ckptinfo { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: .85rem; margin-left: auto; }

.extra { margin-bottom: .6rem; font-size: .9rem; }
.extra summary { cursor: pointer; color: var(--muted); width: fit-content; }
.extra-body { display: flex; flex-wrap: wrap; align-items: center; gap: .85rem; margin-top: .4rem;
  width: fit-content; max-width: 100%;   /* hug the controls, don't stretch to window width */
  padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.extra-body input { font: inherit; padding: 1px 5px; border: 1px solid var(--line);
  border-radius: 5px; background: var(--bg); }
.extra-body input[type=number] { width: 5.4em; }   /* room for 4 digits clear of the spin buttons */
.extra-body .hint { margin-left: 0; }

.canvas-wrap {
  position: relative;
  width: 620px; max-width: 100%; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
canvas#tsne { display: block; width: 100%; height: auto; cursor: grab; border-radius: 10px; }

/* Selection controls overlaid on the canvas, bottom-left. */
.canvas-overlay {
  position: absolute; left: 10px; bottom: 10px;
  display: flex; align-items: center; gap: .5rem;
  pointer-events: none;                     /* only the button itself intercepts */
}
.canvas-overlay button {
  pointer-events: auto; font: inherit; padding: 3px 9px;
  border: 1px solid var(--line); border-radius: 6px;
  background: rgba(255,255,255,.9); cursor: pointer;
}
.canvas-overlay .count {
  background: rgba(255,255,255,.82); padding: 2px 7px; border-radius: 6px;
}
.canvas-overlay.right { left: auto; right: 10px; }
.canvas-overlay .ov-chip {          /* a white pill for a control sitting over the canvas */
  pointer-events: auto; background: rgba(255,255,255,.9); padding: 2px 7px;
  border-radius: 6px; font-size: .85rem;
}
.canvas-overlay .nn-chip input {
  width: 4.2em; font: inherit; padding: 1px 3px 1px 5px; border: 1px solid var(--line); border-radius: 4px;
}

/* Top-right of the canvas: a loading pill (shown while a run's map is (re)building) beside the
   t-SNE options disclosure; a flex row so the two never overlap. */
.canvas-topright {
  position: absolute; top: 8px; right: 8px; z-index: 25;
  display: flex; align-items: flex-start; gap: .5rem; max-width: calc(100% - 16px);
}
.loadind {
  display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap;
  background: rgba(255, 255, 255, .92); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 9px; color: var(--blue); font-size: .82rem;
}
.loadind .spin {
  width: 11px; height: 11px; border: 2px solid var(--line);
  border-top-color: var(--blue); border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* colour-scale legend (zebrafish explorer), top-right of the canvas */
.leg { background: rgba(255, 255, 255, .92); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 7px 5px; font-size: .72rem; color: var(--muted); width: 200px; }
.leg-title { display: block; font-weight: 600; color: var(--fg); font-size: .74rem; margin-bottom: 3px; }
.leg-bar { height: 9px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .12); }
.leg-ticks { display: flex; justify-content: space-between; margin-top: 2px;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
/* t-SNE options: a disclosure anchored top-right of the canvas; its body floats over the map. */
.canvas-extra {
  position: relative; margin: 0; font-size: .82rem;
}
.canvas-extra > summary {
  list-style: none; cursor: pointer; width: fit-content; margin-left: auto;
  background: rgba(255,255,255,.9); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 9px; color: var(--muted);
}
.canvas-extra > summary::-webkit-details-marker { display: none; }
.canvas-extra[open] > summary { background: #fff; color: var(--fg); }
.canvas-extra .extra-body {
  position: absolute; top: calc(100% + 4px); right: 0; margin-top: 0;
  flex-direction: column; align-items: flex-start; gap: .5rem;
  width: max-content; max-width: 240px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .14);
}

canvas#tsne.pick { cursor: pointer; }     /* over a marker: click selects */
canvas#tsne.lasso { cursor: crosshair; }   /* while Shift is held: lasso mode */

.tsne-row { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.qi-pane { width: 220px; max-width: 100%; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  max-height: 620px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.qi-head { display: flex; align-items: center; justify-content: space-between; gap: .4rem;
  padding: .45rem .6rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.qi-head input { width: 3.4em; font: inherit; padding: 1px 4px; border: 1px solid var(--line);
  border-radius: 5px; background: var(--bg); }
.qilist { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }

/* Per-run code diff, right of the QI list (collapsed by default, like the extra t-SNE panel). */
.diff-pane { flex: 1 1 320px; min-width: 240px; max-width: 100%; }
.rundiff > summary { cursor: pointer; color: var(--muted); width: fit-content; font-size: .9rem; }
.rundiff-body { margin-top: .4rem; max-height: 600px; overflow: auto;
  border: 1px solid var(--line); border-radius: 6px; padding: .4rem .5rem; background: var(--card); }
.rundiff .df-trans { font-weight: 600; font-size: .82rem; margin: .5rem 0 .15rem; }
.rundiff .df-trans:first-child { margin-top: 0; }
.rundiff .df-file { color: var(--muted); font-size: .78rem; margin: .35rem 0 .1rem; font-variant: small-caps; }
.rundiff .df-none { color: var(--muted); font-size: .8rem; }
.rundiff .df-note { font-size: .85rem; line-height: 1.4; margin: 0; }
.rundiff pre { font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; margin: .1rem 0 .3rem;
  white-space: pre; }
.rundiff pre .add { background: #e6ffed; }
.rundiff pre .del { background: #ffeef0; }
.rundiff pre .hunk { color: #8250df; }
.rundiff pre .meta { color: var(--muted); }
.qi-row { display: flex; justify-content: space-between; gap: .5rem; padding: 2px 8px;
  cursor: pointer; font-variant-numeric: tabular-nums; font-size: .82rem; border-bottom: 1px solid #f2f2f2; }
.qi-row:hover { background: #eef4fb; }
.qi-row.active { background: #ffe4bf; font-weight: 600; }
/* the frog QI list sits left of the canvas (first in .tsne-row); drop it when horizontal space is tight */
@media (max-width: 1400px) { #qi-pane { display: none; } }
.qi-search { flex: 1; min-width: 0; width: auto; }

/* colour-by-properties filter panel (in the freed QI-pane space) */
.props-pane { width: 300px; max-width: 100%; display: flex; flex-direction: column; gap: .5rem;
  font-size: .82rem; }
.props-head { display: flex; align-items: center; justify-content: space-between; gap: .4rem; flex-wrap: wrap; }
.props-head b { font-size: .9rem; }
.props-block select, .prop-field { font: inherit; }
.props-combine { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; color: #555; }
.props-count { margin-left: auto; font-weight: 600; color: #8856a7; }
.prop-conditions { display: flex; flex-direction: column; gap: .45rem; }
.prop-cond { border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px;
  display: flex; flex-direction: column; gap: 4px; position: relative; background: #fafbfc; }
.prop-cond .prop-field { width: 100%; }
.prop-vals { display: flex; flex-wrap: wrap; gap: 3px; }
.prop-chip { font: inherit; font-size: .72rem; border: 1px solid var(--line); background: #fff;
  color: #45505f; border-radius: 10px; padding: 1px 8px; cursor: pointer; }
.prop-chip:hover { background: #eef4fb; }
.prop-chip.on { background: #8856a7; color: #fff; border-color: #8856a7; }
.prop-rm { position: absolute; top: 3px; right: 4px; border: 0; background: transparent;
  color: #b3bcc6; cursor: pointer; font-size: .95rem; line-height: 1; }
.prop-rm:hover { color: #d64545; }
.prop-add { align-self: flex-start; font: inherit; font-size: .78rem; padding: 3px 9px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
.prop-add:hover { background: #eef4fb; }
.props-hint { margin: .2rem 0 0; font-size: .72rem; color: #8a94a0; line-height: 1.35; }
.props-controls { display: flex; flex-direction: column; gap: .4rem; }
.props-controls label { display: flex; align-items: center; gap: .4rem; font-size: .82rem; }
.props-controls select { font: inherit; flex: 1; }
.props-legend { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .74rem; color: #555; }
.props-legend .lg-title { font-weight: 600; color: #333; width: 100%; }
.props-legend .lg-bar { height: 10px; flex: 1; min-width: 90px; border-radius: 3px;
  background: linear-gradient(to right, #042333, #3c339f, #87518e, #ce6971, #fb9c3e, #e8fa5b); }
.props-legend .lg-ends { color: #888; }
.qi-cid { color: var(--muted); }
.qi-rank { color: #b9b9b9; margin-right: .35rem; }

.linkbtn { font: inherit; color: #2c6fb0; background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.linkbtn:hover { color: #1a4f87; }
.chip-mode { display: inline-flex; align-items: center; font-size: .85rem; margin-top: .6rem; color: var(--muted); }
.chip-mode select { font: inherit; padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.clusterlist { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: .35rem; max-width: 930px; }
.cl-hint { color: var(--muted); font-size: .82rem; margin-right: .2rem; }
.cl-chip { font: inherit; font-size: .8rem; color: #fff; border: 1px solid rgba(0,0,0,.2);
  border-radius: 5px; padding: 2px 9px; cursor: pointer; font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 1px rgba(0,0,0,.45); }
.cl-chip:hover { outline: 2px solid var(--fg); outline-offset: 1px; }
.cl-chip.selected {   /* this cluster's cells are all in the current selection */
  box-shadow: 0 0 0 2px var(--fg), inset 0 0 0 1px rgba(255,255,255,.7);
  font-weight: 700;
}
.cl-chip .cl-coh {    /* per-cluster response cohesion, set off from the label (no backing pill) */
  margin-left: 6px; padding-left: 6px; border-left: 1px solid rgba(255,255,255,.55);
  font-size: .72rem; font-weight: 700; font-variant-numeric: tabular-nums;
}

.fig-pane { margin-top: 1.4rem; }
.fig-controls { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .55rem; }
.fig-controls-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.fig-controls .lbl { font-weight: 600; }
.fig-controls label { cursor: pointer; }
.rmode-group {
  display: inline-flex; align-items: center; gap: .8rem;
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 9px 2px 7px;
}
.rmode-grouplbl { font-size: .78rem; font-weight: 600; color: var(--muted); }
.status { color: var(--muted); font-size: .9rem; }
.rfcount { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }

.notes { max-width: 2100px; margin: 0 auto; padding: 1rem 1.5rem 3.5rem; color: #444;
  border-top: 1px solid var(--line); font-size: .9rem; }
.notes h2 { font-size: 1rem; margin: .8rem 0 .5rem; }
.notes ul { max-width: 88ch; padding-left: 1.1rem; }
.notes li { margin: .25rem 0; }
.status.busy { color: var(--blue); }
.fig-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); }
#fig { display: block; max-width: none; height: auto; }
#fig:not([src]) { display: none; }

/* Hover popup: 64px-checker RF panel for cells drawn as × (cells with a receptive field). */
.rfpop {
  position: fixed;
  z-index: 60;
  background: #fff;
  border: 1px solid #c7c7c7;
  border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  padding: 3px;
  pointer-events: none;      /* never intercept clicks on the canvas */
}
.rfpop img { width: 340px; height: auto; display: block; }
