/* Layout: a two-step control rail beside a large embedding stage; the selected
   subset reads underneath. Neutrals are cool slate so the data colours carry. */
/* House style of timvieira.github.io (blog.css + the steering-embeddings post):
   warm paper, EB Garamond for reading text, small system sans for controls,
   near-monochrome: ink for controls, grey for points, one red accent for the
   selected subset. Light only, like the blog. */
:root {
  color-scheme: light;
  --bg: #f6f1ea;
  --surface: #fbfaf8;
  --surface-2: #f1ede7;
  --border: #e2ddd5;
  --text: #333333;
  --text-2: #555555;
  --muted: #999999;
  --ink: #555555;          /* slider, checkbox */
  --ink-fg: #ffffff;
  --btn: #ebe6de;          /* quiet filled controls */
  --btn-hover: #e1dbd1;
  --btn-line: #d3cbbf;
  --focus: #333333;
  --accent: #c8473c;       /* the selected subset, its vectors and volume */
  --series-1: var(--accent);
  --series-2: var(--accent);
  --series-3: var(--accent);
  --ramp-lo: #c3bdb3;      /* unlikely completions */
  --ramp-hi: #2a2a2a;      /* likely completions */
  --ghost: #c9c1b4;
  --grid: #e6dfd4;
  --shadow: none;
  --display: "EB Garamond", "PT Serif", Georgia, serif;
  --serif: "EB Garamond", "PT Serif", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  --r: 6px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
sub { font-size: .72em; line-height: 0; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
.serif { font-family: var(--serif); }
.shell { max-width: 1360px; margin: 0 auto; padding-block: 12px 32px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 12px; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
h1, h2 { font-family: var(--display); text-wrap: balance; margin: 0; }

/* ---------- header ---------- */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.top .brand { min-width: 0; }
.links { flex: none; padding-top: 6px; }
.brand { display: flex; align-items: center; gap: 10px; }
h1 { font-size: 34px; font-weight: 575; line-height: 1.15; }
.tag { margin: 2px 0 0; color: var(--text-2); font: italic 17px/1.35 var(--serif); }
.tag a { color: inherit; }
.links { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.links a { color: var(--text-2); text-underline-offset: 2px; }
.links a:hover { color: var(--text); text-decoration: underline; }
.chip-quiet { font-size: 12px; color: var(--muted); }

/* work-in-progress note, styled like the blog's draft banner */
.wip { margin: 0; background: #fff3cd; border-left: 4px solid #ffc107; border-radius: var(--r); padding: 9px 14px; font: 15.5px/1.4 var(--serif); color: #5c4a00; }

/* ---------- app grid ---------- */
.app { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 12px; align-items: start; }
.controls { display: flex; flex-direction: column; gap: 10px; position: sticky; top: max(12px, env(safe-area-inset-top, 0px)); }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
.step h2 { font-size: 19px; font-weight: 575; display: flex; align-items: center; gap: 8px; }
.step h2 .num { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font: 500 12px/1 var(--sans); color: var(--text-2); border: 1px solid var(--btn-line); }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.lab { font-size: 12px; color: var(--muted); }
.lab.row { display: flex; justify-content: space-between; align-items: baseline; }
.val { font: 12.5px var(--mono); color: var(--text); padding: 0; font-variant-numeric: tabular-nums; }
input[type=number], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid #ddd; border-radius: 4px; padding: 6px 9px; min-width: 0;
}
input[type=number] { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
textarea { resize: vertical; min-height: 64px; font: 17px/1.4 var(--serif); background: #fff; }
input[type=number] { background: #fff; }
input:focus, textarea:focus { outline: none; border-color: var(--focus); }
input:hover, textarea:hover { border-color: #c8c8c8; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.actions { display: flex; gap: 8px; }
.row-between { display: flex; align-items: end; justify-content: space-between; gap: 12px; }

.btn { font: 14px var(--sans); color: var(--text-2); background: transparent; border: 1px solid #ddd; border-radius: 4px; padding: 6px 14px; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { background: rgba(0,0,0,.04); color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--btn); color: var(--text); border-color: var(--btn-line); flex: 1; }
.btn.primary:hover { background: var(--btn-hover); color: var(--text); }
.btn.icon { width: 32px; padding: 6px 0; font-size: 16px; line-height: 1; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper input { width: 52px; text-align: center; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { display: none; }
button.link { border: 0; background: none; padding: 0; font: inherit; color: var(--text); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }


/* step 1: header with the examples dropdown; settings + Generate on one row */
.step-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.btn.primary { flex: none; padding-inline: 18px; }

/* prompt composer: text on top, chips at bottom left, round send button at bottom right */
.step-1 { background: none; border: 0; padding: 0; box-shadow: none; gap: 6px; }
.composer { background: #fff; border: 1px solid var(--border); border-radius: var(--r); padding: 10px 10px 8px 14px; display: flex; flex-direction: column; gap: 6px; box-shadow: 0 1px 3px rgb(0 0 0 / .04); }
.composer:focus-within { border-color: #cfc7ba; }
.composer textarea { border: 0; padding: 2px 0; background: transparent; resize: none; min-height: 48px; }
.composer textarea:focus { outline: none; }
.comp-row { display: flex; align-items: center; gap: 6px; }
.comp-row .grow { flex: 1; }
.chip { font: 12.5px var(--sans); color: var(--text-2); background: var(--surface-2); border: 0; border-radius: 999px; padding: 5px 11px; cursor: pointer; max-width: 150px; }
.chip:hover { color: var(--text); background: var(--btn-hover); }
.chipmenu { position: relative; }
.chipmenu summary { list-style: none; white-space: nowrap; }
summary.chip { max-width: none; overflow: hidden; text-overflow: ellipsis; display: block; }
.comp-row .chipmenu { min-width: 0; }
.chipmenu summary::-webkit-details-marker { display: none; }
.chipmenu .menu { position: absolute; left: 0; top: calc(100% + 6px); z-index: 60; display: grid; grid-template-columns: repeat(3, 84px); gap: 8px; padding: 10px; background: #fff; border: 1px solid var(--border); border-radius: var(--r); box-shadow: 0 6px 20px rgb(0 0 0 / .1); }
.plusbtn { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--text-2); cursor: pointer; list-style: none; }
.plusbtn::-webkit-details-marker { display: none; }
.plusbtn:hover, [open] > .plusbtn { background: var(--btn-hover); color: var(--text); }
.plusbtn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.chipmenu .menu.list { display: flex; flex-direction: column; gap: 0; padding: 6px; width: min(300px, calc(100vw - 48px)); }
.menu-head { font: 600 11px var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 4px 8px 6px; }
.menu.list button { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; border: 0; background: none; padding: 7px 8px; border-radius: 6px; cursor: pointer; color: var(--text); }
.menu.list button:hover { background: var(--surface-2); }
.menu.list button[aria-current] { background: var(--surface-2); }
.menu.list button b { font: 600 13px var(--sans); }
.menu.list button span { font: 14px/1.3 var(--serif); color: var(--text-2); }
.model-field { grid-column: 1 / -1; }
#model, #embedder { font: 13px var(--sans); color: var(--text); background: #fff; border: 1px solid #ddd; border-radius: 4px; padding: 5px 6px; width: 100%; }
.cache-row button.link { font-size: 12px; color: var(--text-2); }
.menu-note { grid-column: 1 / -1; margin: 0 0 2px; font: 12px var(--sans); color: var(--muted); }
.chip::after { content: " ▾"; font-size: 10px; color: var(--muted); }
.sendbtn { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--accent); color: #fff; cursor: pointer; padding: 0; transition: opacity .15s, filter .15s; }
.sendbtn:hover { filter: brightness(.94); }
.sendbtn:disabled { opacity: .35; cursor: default; filter: none; }
.sendbtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.sendbtn.stop { background: var(--text); }
.sendbtn.stop svg { fill: currentColor; stroke: none; }
.step-1 .status, .step-1 .progress { padding-inline: 6px; }

/* step 2: T slider with its two ends inline */
.mode-row { display: flex; align-items: center; gap: 8px; }
.mode-row .seg { flex: none; }
/* Subset controls: compact everywhere. */
.step-2 { gap: 8px; }
.step-2 .seg { padding: 2px; gap: 2px; grid-auto-columns: auto; }
.step-2 .seg span { padding: 2px 10px; font-size: 12.5px; white-space: nowrap; }
.step-2 .btn.icon { width: 28px; min-height: 28px; padding: 0; font-size: 15px; }
.step-2 .stepper input { width: 38px; min-height: 28px; padding-block: 2px; }
.step-2 #resample { padding: 4px 12px; font-size: 13px; }
.kfield { flex-direction: row; align-items: center; gap: 8px; }
.kfield .lab { font: 500 13px var(--sans); color: var(--text-2); }
.step-2 .row-between { align-items: center; }
/* T on one row: label, ?, value, then quality ━━●━━ diversity */
.tfield { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 10px; row-gap: 0; }
.tfield .ends { grid-column: 2; display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; line-height: 1.1; margin-top: -3px; }
.tlab { display: inline-flex; align-items: center; gap: 4px; font: 500 13px var(--sans); color: var(--text-2); white-space: nowrap; }
.tlab .val { min-width: 3.2em; }
.tfield input[type=range] { margin: 0; }

/* "?" explainer buttons and their popover */
.xbtn { display: inline-grid; place-items: center; width: 16px; height: 16px; padding: 0; margin: 0 1px; vertical-align: 1px; border: 1px solid #c9c2b6; border-radius: 50%; background: #fff; color: var(--muted); font: 600 10px/1 var(--sans); cursor: pointer; position: relative; flex: none; }
.xbtn:hover, .xbtn[aria-expanded=true] { color: var(--text); border-color: var(--text-2); }
.xbtn::after { content: ""; position: absolute; inset: -10px; }
.xpop { position: absolute; z-index: 100; background: #fff; color: var(--text); border: 1px solid var(--border); border-left: 3px solid var(--text-2); border-radius: var(--r); box-shadow: 0 6px 22px rgb(0 0 0 / .14); padding: 10px 34px 10px 14px; font: 15.5px/1.45 var(--serif); }
.xpop p { margin: .4em 0; }
.xpop ul { margin: .3em 0; padding-left: 1.2em; }
.xpop li { margin: .15em 0; }
.xpop .katex-display { margin: .5em 0; overflow-x: auto; overflow-y: hidden; }
.xpop .katex { font-size: 1.02em; }
.xp-title { font: 600 11px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); margin-bottom: 2px; }
.xp-close { position: absolute; top: 2px; right: 2px; width: 32px; height: 32px; border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; border-radius: 4px; }
.xp-close:hover { background: rgba(0,0,0,.05); color: var(--text); }

/* segmented control */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: rgba(0,0,0,.04); border-radius: 4px; padding: 3px; gap: 4px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 5px 12px; border-radius: 3px; font-size: 13px; color: var(--muted); }
.seg label:hover span { color: var(--text); }
.seg input:checked + span { background: #fff; color: var(--text); box-shadow: 0 0 0 1px var(--btn-line); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
.seg.small span { padding: 3px 11px; font-size: 12.5px; }

input[type=range] { width: 100%; accent-color: var(--ink); margin: 4px 0 0; }

.status { margin: 0; color: var(--muted); font-size: 12px; }
.progress { display: flex; flex-direction: column; gap: 6px; }
.progress .bar { height: 6px; background: #eee; border-radius: 99px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--text-2); transition: width .3s; }
.progress .last { margin: 0; font: italic 15px var(--serif); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- stage ---------- */
.stage { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.stage-bar, .stage-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 7px 12px; }
.stage-bar { border-top: 1px solid var(--border); padding-block: 5px; }
.stage-foot { border-top: 1px solid var(--border); justify-content: space-between; }
.note { color: var(--muted); font-size: 12px; }
.stage-bar .note { flex: 1; min-width: 0; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); cursor: pointer; }
.toggle input { accent-color: var(--ink); margin: 0; }
.plot-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 58px; gap: 4px; padding: 4px 10px 4px 4px; }
.plot { position: relative; width: 100%; height: min(66vh, 620px); min-height: 300px; min-width: 0; }
.plot svg, .plot canvas { display: block; width: 100%; height: 100%; }
.plot canvas { cursor: grab; }
.plot canvas:active { cursor: grabbing; }
.eigbars { display: flex; flex-direction: column; justify-content: center; gap: 4px; font: 11px var(--mono); color: var(--muted); }
.eigbars .cap { font: 500 10.5px var(--sans); letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.eigbars .bar { display: grid; grid-template-columns: 12px 1fr; align-items: center; gap: 4px; padding: 1px 0; border-radius: 3px; }
.eigbars .bar[role=button] { cursor: pointer; }
.eigbars .bar .fill { height: 10px; background: var(--ghost); border-radius: 0 3px 3px 0; min-width: 2px; opacity: .7; }
.eigbars .bar.on .fill { background: var(--text-2); opacity: 1; }
.eigbars .bar[role=button]:hover .fill { opacity: 1; }
.eigbars .pct { margin-top: 4px; color: var(--text-2); line-height: 1.3; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--text-2); font-size: 12px; align-items: center; }
.lg { display: inline-flex; gap: 6px; align-items: center; }
.sw { display: inline-block; width: 11px; height: 11px; border-radius: 50%; }
.sw.ramp { background: linear-gradient(90deg, var(--ramp-lo), var(--ramp-hi)); border-radius: 3px; width: 26px; height: 8px; }
.sw.sel { border: 2.5px solid var(--accent); }
.sw-vol path { fill: color-mix(in srgb, var(--text) 8%, transparent); stroke: var(--text-2); stroke-width: 1; }
.readout { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.stat { display: flex; align-items: baseline; gap: 6px; font-size: 12px; color: var(--muted); }
.stat .v { font: 500 13px var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }

/* View menu on the plot toolbar */
.viewmenu { position: relative; margin-left: auto; }
.viewmenu summary { list-style: none; cursor: pointer; font-size: 12.5px; color: var(--text-2); padding: 3px 10px; border-radius: 4px; border: 1px solid transparent; }
.viewmenu summary::-webkit-details-marker { display: none; }
.viewmenu summary::after { content: " ▾"; color: var(--muted); font-size: 10px; }
.viewmenu summary:hover, .viewmenu[open] summary { border-color: var(--btn-line); background: #fff; }
.viewmenu .menu { position: absolute; right: 0; bottom: calc(100% + 4px); z-index: 20; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; background: #fff; border: 1px solid var(--border); border-radius: var(--r); box-shadow: 0 4px 16px rgb(0 0 0 / .08); white-space: nowrap; }

/* labels on the selected points */
.plot-box { position: relative; min-width: 0; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; max-width: 190px; padding: 0 2px; font: italic 13.5px/1.2 var(--serif); color: var(--text); pointer-events: auto; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  /* no box: a thin halo in the plot's background colour keeps the text legible over points */
  text-shadow: 0 0 2px var(--surface), 0 0 2px var(--surface), 0 0 3px var(--surface), 0 0 4px var(--surface); }
.lbl:hover { color: var(--accent); }
.lbl span { display: inline; }
.labels.anim .lbl { transition: transform .45s cubic-bezier(.33,1,.68,1); }
@media (max-width: 600px) { .lbl { max-width: 130px; font-size: 12.5px; } }

/* inspector: the tapped point, pinned under the plot */
.plot-wrap { position: relative; }
.inspect { position: absolute; left: 12px; right: 12px; bottom: 10px; max-height: 48%; overflow-y: auto; padding: 10px 40px 10px 14px; background: rgb(255 255 255 / .96); border: 1px solid var(--border); border-radius: var(--r); box-shadow: 0 2px 12px rgb(0 0 0 / .1); z-index: 5; }
.ins-txt { font: 17px/1.4 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }
.ins-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 6px; font: 12px var(--sans); color: var(--muted); }
.pill { color: #fff; border-radius: 3px; padding: 1px 6px; font-size: 11px; }
.ins-close { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; border-radius: 4px; }
.ins-close:hover { background: rgba(0,0,0,.05); color: var(--text); }
.card { cursor: pointer; }

/* ---------- subset ---------- */
.subset { display: flex; flex-direction: column; gap: 10px; }
.subset-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.subset h2 { font-size: 24px; font-weight: 575; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 14px 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; transition: border-color .15s, box-shadow .15s; }
.card .txt { white-space: pre-wrap; overflow-wrap: anywhere; font: 17px/1.4 var(--serif); color: var(--text); }
.card .meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font: 11.5px var(--sans); margin-top: auto; }
.card .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.card.hl { border-color: var(--text-2); box-shadow: var(--shadow); }
.card.cut .txt::after { content: " …"; color: var(--muted); }

/* ---------- table ---------- */
.pool-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 4px 14px; }
.pool-table summary { cursor: pointer; padding: 8px 0; color: var(--text-2); }
.pool-table table { width: 100%; min-width: 560px; border-collapse: collapse; font: 15px/1.35 var(--serif); }
.pool-table th, .pool-table td { text-align: left; padding: 6px; border-top: 1px solid var(--border); vertical-align: top; }
.pool-table th { color: #555; font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: .5px; cursor: pointer; white-space: nowrap; position: sticky; top: 0; background: var(--surface); border-top: 0; }
.pool-table td.num { font: 12px var(--mono); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-2); }
.pool-table tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.pool-table .wrap { max-height: 480px; overflow: auto; margin-bottom: 10px; -webkit-overflow-scrolling: touch; }
.pool-table td:nth-child(2) { min-width: 220px; }

.foot { color: var(--muted); font: 15px/1.45 var(--serif); max-width: 75ch; }
.foot p { margin: 0; }

/* chart text used by the 2D plot */
.direct-label { font: 11px var(--sans); fill: var(--muted); }

.tooltip { position: fixed; z-index: 10; pointer-events: none; max-width: 360px; background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: var(--r); padding: 8px 11px; font: 16px/1.35 var(--serif); box-shadow: 0 2px 10px rgb(0 0 0 / .08); box-shadow: var(--shadow); white-space: pre-wrap; overflow-wrap: anywhere; }
.tooltip .meta { font: 11.5px var(--sans); color: var(--text-2); margin-top: 6px; white-space: normal; }

@media (max-width: 900px) {
  h1 { font-size: 26px; }
  .tag { font-size: 15px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  /* Phones: prompt first, then the plot, then the subset controls. */
  .controls { display: contents; }
  .step-1 { order: 0; }
  .stage { order: 1; }
  .step-2 { order: 2; }
  .stage-bar { flex-wrap: nowrap; align-items: flex-start; }
  .plot { height: 58vh; }
  .plot-wrap { grid-template-columns: minmax(0, 1fr) 46px; }
}
/* Phones: each pool row becomes a short block, text first, numbers on one line. */
@media (max-width: 600px) {
  .pool-table table { min-width: 0; }
  .pool-table thead { display: none; }
  .pool-table tr { display: flex; flex-wrap: wrap; gap: 2px 12px; padding: 8px 0; border-top: 1px solid var(--border); }
  .pool-table td { border: 0; padding: 0; }
  .pool-table td.str { flex-basis: 100%; order: -1; }
  .pool-table td:nth-child(2) { min-width: 0; }
  .pool-table td.num { font: 11.5px var(--sans); color: var(--muted); text-align: left; }
  .pool-table td.num::before { content: attr(data-k) " "; }
  .pool-table tr.sel td:first-child { box-shadow: none; }
  .pool-table tr.sel { box-shadow: inset 3px 0 0 var(--accent); padding-left: 8px; }
}
/* ---------- touch screens: finger-sized targets, no zoom-on-focus ---------- */
@media (pointer: coarse), (max-width: 600px) {
  input[type=number], textarea { font-size: 16px; }
  input[type=number] { min-height: 34px; padding-block: 4px; }
  .btn { min-height: 34px; padding-block: 5px; }
  .btn.icon { width: 34px; font-size: 17px; }
  .stepper input { width: 48px; }
  .seg span { padding: 7px 10px; font-size: 13.5px; }
  .seg.small span { padding: 5px 11px; font-size: 12.5px; }
    .xbtn { width: 18px; height: 18px; font-size: 11px; }
  .chip { font-size: 14px; }
  .chipmenu .menu { grid-template-columns: repeat(3, minmax(0, 1fr)); width: min(320px, calc(100vw - 48px)); }
  .viewmenu summary { padding: 5px 10px; font-size: 13px; }
  .viewmenu .menu { gap: 0; padding: 4px 6px; }
  .viewmenu .menu .toggle { padding: 10px 6px; font-size: 14px; }
  .toggle input { width: 20px; height: 20px; }
  input[type=range] { height: 32px; margin: 0; }
  .pool-table summary { padding: 12px 0; }
  .ins-close { width: 36px; height: 36px; top: 0; right: 0; }
}

/* ---------- phones ---------- */
@media (max-width: 600px) {

  /* "Pick a subset" docks to the bottom of the screen while the plot is in view,
     so T and K can be changed while watching the selection move. */
  .step-2 {
    position: sticky; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "seg k" "t t" "r r";
    gap: 8px 10px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    margin: 0 -16px; border-radius: var(--r) var(--r) 0 0; border-bottom: 0;
    box-shadow: 0 -6px 20px rgb(0 0 0 / .08);
  }
  .step-2 > h2 { display: none; }
  .step-2 .seg span { padding: 3px 10px; font-size: 12.5px; }
  .step-2 .btn.icon { width: 28px; min-height: 28px; padding: 0; font-size: 15px; }
  .step-2 .stepper input { width: 36px; min-height: 28px; padding-block: 2px; }
  .step-2 { gap: 6px 8px; padding-block: 8px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .step-2 input[type=range] { height: 24px; }
  .step-2 .tlab { font-size: 12.5px; }
  .step-2 > .mode-row { grid-area: seg; align-self: center; }
  .step-2 > .tfield { grid-area: t; }
  .step-2 > .row-between { display: contents; }
  .step-2 > .row-between > .field { grid-area: k; align-self: end; }
  .step-2 > .row-between > .field > .lab { display: none; }
  .step-2 #resample { grid-area: r; }
  .step-2 #resample:disabled { display: none; }

}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* No pool for the current settings: show nothing but the note under the stage. */
body.empty .plot-wrap, body.empty .stage-foot, body.empty .subset, body.empty .pool-table, body.empty #viewmenu { display: none; }

/* Messages in the plot area: nothing yet, a run in progress, a failure. */
.stage { position: relative; }
.stage-msg { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 48px 24px; min-height: 260px; }
.stage-msg.over { position: absolute; inset: 0 0 auto 0; height: 100%; z-index: 25; background: rgb(251 250 248 / .88); min-height: 0; }
.stage-msg p { margin: 0; max-width: 46ch; }
.stage-msg .t { font: 500 18px var(--serif); color: var(--text); }
.stage-msg .d { font-size: 13.5px; color: var(--text-2); line-height: 1.45; }
.stage-msg .a { margin-top: 8px; display: flex; gap: 8px; }
.stage-msg.error .t { color: var(--accent); }
.stage-msg.error { box-shadow: inset 0 3px 0 var(--accent); }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .9s linear infinite; margin-bottom: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; border-top-color: var(--accent); } }
body.empty .stage { min-height: 0; }
