/* Vector space: the map is the far plane and fills the stage; everything else floats over it.
   Rail (probe, keyword index) · map · wide rail (marked, inspector, axes). */

.vec {
  --l: var(--rail);
  --r: var(--rail-wide);
  --mid-l: calc(var(--gutter) + var(--l) + var(--s5));
  --mid-r: calc(var(--gutter) + var(--r) + var(--s5));
  position: relative;
  height: 100%;
  overflow: hidden;
}
.vec-map {
  position: absolute;
  inset: 0;
}
.vec-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
.vec-canvas:active {
  cursor: grabbing;
}
.vec-canvas.is-over {
  cursor: pointer;
}
.vec-canvas.is-area,
.vec-canvas.is-area:active {
  cursor: crosshair;
  touch-action: none;
}
.vec-canvas:focus-visible {
  outline-offset: -4px;
}
.vec-tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 4;
  display: grid;
  gap: var(--s1);
  max-width: min(300px, calc(100% - var(--s4)));
  padding: var(--s2) var(--s3);
  background: var(--near);
  border: var(--hair) solid var(--line-3);
  pointer-events: none;
}
.tip-title {
  font: 400 var(--t-small) / 1.3 var(--f-read);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tip-meta {
  font: 400 var(--t-micro) / 1 var(--f-mono);
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* What lies over the middle of the map when there is no map to show. */
.vec-note {
  position: absolute;
  inset: 0 var(--mid-r) 0 var(--mid-l);
  z-index: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.vec-note > * {
  max-width: 44ch;
  padding: var(--s4);
  background: var(--plane-a);
  border: var(--hair) solid var(--line);
  pointer-events: auto;
}
.vec-note .btn {
  text-decoration: none;
}

.vec-left,
.vec-right {
  position: absolute;
  top: var(--s5);
  bottom: var(--s5);
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  pointer-events: none;
}
.vec-left {
  left: var(--gutter);
  width: var(--l);
}
.vec-right {
  right: var(--gutter);
  width: var(--r);
}
.vec-left > *,
.vec-right > * {
  pointer-events: auto;
}

/* ---------------------------------------------------------------- title */
.vec-title {
  position: absolute;
  left: var(--mid-l);
  right: var(--mid-r);
  top: var(--s5);
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s1);
  justify-items: start;
  pointer-events: none;
}
.vec-count {
  font: 500 var(--t-ui) / 1.3 var(--f-display);
  letter-spacing: 0.02em;
}
.vec-count .mono {
  font-size: var(--t-small);
}
.vec-model {
  display: flex;
  align-items: baseline;
  gap: 0.5ch;
  max-width: 100%;
  font-size: var(--t-mini);
  color: var(--ink-3);
  white-space: nowrap;
}
.vec-model .mono {
  font-size: var(--t-mini);
  color: var(--ink-2);
}
.vec-model-id {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vec-few {
  max-width: 46ch;
  font-size: var(--t-small);
  color: var(--ink-2);
}
/* The probe's "nearest" line: the closest piece and its similarity, in gold beside the map. */
.vec-nearest {
  display: flex;
  align-items: center;
  gap: var(--s3);
  max-width: 100%;
  margin-top: var(--s1);
}
.vec-nearest-hit {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  min-width: 0;
  min-height: 28px;
  padding: 0 var(--s1);
  border-bottom: var(--hair) solid var(--gold-line);
  color: var(--ink);
  pointer-events: auto;
}
.vec-nearest-hit:hover {
  border-bottom-color: var(--gold);
}
.vec-nearest-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 400 var(--t-small) / 1.3 var(--f-read);
}
.vec-nearest-score {
  font: 400 var(--t-small) / 1 var(--f-mono);
  color: var(--gold);
}
.vec.is-waiting .vec-title > p,
.vec.is-waiting .vec-hud {
  visibility: hidden;
}

/* ---------------------------------------------------------------- probe */
.vec-probe {
  flex: none;
}
.probe-form {
  display: flex;
  gap: var(--s2);
}
.probe-help {
  margin-top: var(--s2);
  font-size: var(--t-mini);
  line-height: 1.45;
  color: var(--ink-3);
}
.probe-field {
  flex: 1;
  min-width: 0;
}
.probe-field input:disabled {
  opacity: 0.5;
}
.probe-out:empty {
  display: none;
}
.probe-out {
  margin-top: var(--s3);
  padding-top: var(--s2);
  border-top: var(--hair) solid var(--gold-line);
}
.probe-out.is-busy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
}
.probe-out.is-busy .wait-label {
  letter-spacing: 0.06em;
}
.probe-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.probe-stale {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding-top: var(--s2);
  border-top: var(--hair) solid var(--line);
}
.probe-stale .probe-help {
  flex: 1;
  margin: 0;
}
.label.is-warm {
  color: var(--gold);
}

/* ---------------------------------------------------------------- keyword index */
.vec-terms {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  min-height: 132px;
}
.vec-terms.is-all {
  flex: 1 1 0;
}
.terms-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}
.terms-head {
  display: flex;
  justify-content: space-between;
  padding-bottom: var(--s2);
  border-bottom: var(--hair) solid var(--line);
}
.terms {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-content: start;
  gap: 0 var(--s5);
  min-height: 0;
  overflow: auto;
  margin-bottom: var(--s2);
}
.term {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 4px var(--s2);
  padding: var(--s2) 0 var(--s1);
  color: inherit;
  text-decoration: none;
}
.term-word {
  font: 400 var(--t-small) / 1.2 var(--f-read);
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.term:hover .term-word {
  color: var(--cyan);
}
.term:focus-visible {
  outline-offset: -2px;
}
.term-n {
  font: 400 var(--t-mini) / 1 var(--f-mono);
  color: var(--ink-3);
}
.term .meter {
  grid-column: 1 / -1;
}
.terms-more {
  align-self: flex-start;
  margin-left: calc(var(--s3) * -1);
}

/* ---------------------------------------------------------------- legend and view controls */
.vec-hud {
  position: absolute;
  left: var(--mid-l);
  right: var(--mid-r);
  bottom: var(--s5);
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s2);
  pointer-events: none;
}
.vec-hud button,
.vec-hud .seg-ctl {
  pointer-events: auto;
}
.vec-legend {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s1);
}
.vec.is-empty .vec-legend,
.vec.is-empty .hud-area {
  display: none;
}
.hud-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s3);
  min-height: 32px;
}
.hud-age {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-left: var(--s2);
}
.hud-end {
  font: 400 var(--t-mini) / 1 var(--f-mono);
  color: var(--ink-3);
  white-space: nowrap;
}
.ramp {
  display: flex;
  gap: var(--bold);
}
.ramp-step {
  width: 14px;
  height: 6px;
}
.hud-shape {
  flex-wrap: nowrap;
  align-items: flex-start;
}
.hud-shape > .label {
  flex: none;
  line-height: 28px;
}
.hud-sources {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 0 var(--s1);
  min-width: 0;
}
.hud-src {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 28px;
  padding: 0 var(--s2);
  border: var(--hair) solid transparent;
  font-size: var(--t-mini);
  color: var(--ink-3);
}
.hud-src:hover {
  border-color: var(--line-2);
}
.hud-src[aria-pressed="true"] {
  border-color: var(--line-3);
  background: var(--cyan-fill);
  color: var(--ink);
}
.hud-src[aria-pressed="true"] .src {
  color: var(--ink);
}
/* A source's mark, drawn as its points are on the map. */
.vmark {
  flex: none;
  color: var(--cyan);
  overflow: visible;
}
.vmark * {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}
.vmark .is-solid {
  fill: currentColor;
  stroke: none;
}
.vmark .is-bar {
  stroke-width: 2.4;
}
.hud-area[aria-pressed="true"] {
  --edge: var(--gold);
  background: linear-gradient(var(--gold-fill), var(--gold-fill)), var(--far);
  color: var(--gold);
}
.hud-readout {
  display: flex;
  gap: var(--s3);
  margin-left: var(--s2);
  font: 400 var(--t-mini) / 1 var(--f-mono);
  color: var(--ink-3);
  white-space: nowrap;
}
.hud-readout b {
  font-weight: 400;
  color: var(--ink-2);
}

/* ---------------------------------------------------------------- marked memories */
.vec-marked {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
  margin-right: var(--float);
  padding: var(--s2) var(--s2) var(--s2) var(--s4);
  background: var(--near-a);
  border: var(--hair) solid var(--gold-line);
  border-left: var(--bold) solid var(--gold);
}
.vec-marked-n {
  margin-right: auto;
  font: 500 var(--t-ui) / 1.2 var(--f-display);
  letter-spacing: 0.02em;
  color: var(--gold);
}

/* ---------------------------------------------------------------- inspector */
.vec-inspector-wrap {
  flex: 1 1 0;
}
.vec-inspector-wrap.is-idle {
  flex: none;
}
.vec-inspector {
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}
.is-idle > .vec-inspector {
  padding-bottom: var(--s4);
}
.insp-keys {
  margin-top: var(--s2);
  padding-top: var(--s3);
  border-top: var(--hair) solid var(--line);
  font-size: var(--t-mini);
  line-height: 1.5;
  color: var(--ink-3);
}
.insp-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: calc(var(--s2) * -1) calc(var(--s2) * -1) calc(var(--s2) * -1) 0;
  color: var(--ink-3);
}
.insp-close:hover {
  color: var(--ink);
}
.insp-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 0 calc(var(--s4) * -1);
  padding: 0 var(--s4) var(--s4);
}
.insp-title {
  font: 500 var(--t-read) / 1.3 var(--f-display);
  letter-spacing: 0.02em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.insp-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s4);
  margin-top: var(--s2);
  font: 400 var(--t-mini) / 1.2 var(--f-mono);
  color: var(--ink-3);
}
.insp-pos {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s4);
  margin-top: var(--s2);
  font: 400 var(--t-mini) / 1.2 var(--f-mono);
}
.insp-pos div {
  display: flex;
  gap: var(--s2);
}
.insp-pos dt {
  color: var(--ink-3);
}
.insp-pos dd {
  color: var(--ink-2);
}
.insp-textbox {
  margin-top: var(--s3);
}
.insp-text {
  padding: var(--s1) 0 var(--s1) var(--s3);
  border-left: var(--bold) solid var(--cyan);
  font: 400 var(--t-ui) / 1.6 var(--f-read);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* Clipped to seven lines until asked for, so the numbers and the neighbours stay within reach. */
.insp-text.is-clipped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 7;
  line-clamp: 7;
  overflow: hidden;
}
.insp-more {
  min-height: 32px;
  margin-top: var(--s1);
  padding-left: calc(var(--s3) + var(--bold));
}
.insp-open {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-top: var(--s3);
}
.insp-open .btn {
  text-decoration: none;
}
.insp-open .icon {
  color: var(--cyan);
}
.insp-id {
  font-size: var(--t-mini);
  color: var(--ink-3);
}
.insp-sec {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin-top: var(--s4);
  padding: var(--s3) 0 var(--s2);
  border-top: var(--hair) solid var(--line);
}
.insp-sec-read {
  font: 400 var(--t-mini) / 1 var(--f-mono);
  color: var(--ink-3);
  white-space: nowrap;
}
.insp-none {
  font-size: var(--t-small);
  color: var(--ink-3);
}

/* The heat grid: 48 cells a row, the row labels beside it, the real minimum and maximum under it. */
.heat-wrap {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--s2);
}
.heat-rows {
  display: flex;
  flex-direction: column;
  min-width: 3ch;
  font: 400 var(--t-micro) / 1 var(--f-mono);
  color: var(--ink-3);
  text-align: right;
}
.heat-rows span {
  height: calc(var(--cell, 6px) * var(--rows, 4));
}
.heat-stage {
  position: relative;
  min-width: 0;
}
.heat {
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: pan-y;
}
.heat:focus-visible {
  outline-offset: 3px;
}
.heat-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--cell, 6px) - 1px);
  height: calc(var(--cell, 6px) - 1px);
  outline: var(--hair) solid var(--ink);
  outline-offset: 1px;
  pointer-events: none;
}
.heat-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s2);
  margin-top: var(--s2);
  font: 400 var(--t-micro) / 1.3 var(--f-mono);
  color: var(--ink-3);
}
.heat-ramp {
  width: 72px;
  height: 6px;
}
.heat-end {
  color: var(--ink-2);
}
.heat-read {
  margin-left: auto;
  color: var(--ink);
  white-space: pre;
}

/* Nearest pieces: the similarity as a figure and a bar, the title, which piece, how it begins. */
.near {
  display: grid;
}
.near-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--s1) var(--s3);
  width: 100%;
  min-height: 44px;
  padding: var(--s2) 0;
  border-top: var(--hair) solid var(--line);
  text-align: left;
  cursor: pointer;
}
.near li:first-child .near-row {
  border-top: 0;
}
.near-score {
  grid-row: 1;
  grid-column: 1;
  font: 400 var(--t-small) / 1 var(--f-mono);
  color: var(--ink);
}
.near.is-warm .near-score {
  color: var(--gold);
}
.near-title {
  grid-row: 1;
  grid-column: 2;
  font: 400 var(--t-small) / 1.3 var(--f-read);
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.near-piece {
  grid-row: 1;
  grid-column: 3;
  font: 400 var(--t-micro) / 1 var(--f-mono);
  color: var(--ink-3);
}
.near-row .meter {
  grid-row: 2;
  grid-column: 1;
  align-self: center;
}
.near-snip {
  grid-row: 2;
  grid-column: 2 / -1;
  font: 400 var(--t-mini) / 1.3 var(--f-read);
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.near-row:hover .near-title,
.near-row:focus-visible .near-title {
  color: var(--ink);
}
.near-row:focus-visible {
  outline-offset: -2px;
}

/* ---------------------------------------------------------------- axes */
.vec-axes {
  flex: none;
}
.axes {
  display: grid;
  gap: var(--s2);
}
.axis {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 52px;
  align-items: center;
  gap: var(--s3);
  font: 400 var(--t-small) / 1 var(--f-mono);
}
.axis-name {
  color: var(--ink-2);
}
.axis-share {
  color: var(--ink);
  text-align: right;
}
.axes-note {
  margin-top: var(--s3);
  font-size: var(--t-mini);
  line-height: 1.5;
  color: var(--ink-3);
}

/* ---------------------------------------------------------------- medium widths */
@media (max-width: 1240px) and (min-width: 1041px) {
  .vec {
    --l: 280px;
    --r: 340px;
    --mid-l: calc(var(--gutter) + var(--l) + var(--s4));
    --mid-r: calc(var(--gutter) + var(--r) + var(--s4));
  }
  .hud-colour > .label {
    display: none;
  }
}
/* A short window: the axes keep their bars and let the sentence go. */
@media (min-width: 1041px) and (max-height: 700px) {
  .axes-note {
    display: none;
  }
}

/* ---------------------------------------------------------------- stacked: the map on top, then
   the view controls and legend, the inspector, the probe, the keyword index, the axes. The page scrolls. */
@media (max-width: 1040px) {
  .vec {
    display: flex;
    flex-direction: column;
    gap: var(--s3);
    height: auto;
    overflow: visible;
    padding: var(--s3) var(--gutter) var(--s5);
  }
  .vec-title {
    position: static;
    order: 0;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: baseline;
    gap: var(--s1) var(--s3);
  }
  .vec-model,
  .vec-few,
  .vec-nearest {
    grid-column: 1 / -1;
  }
  .vec-map {
    position: relative;
    inset: auto;
    order: 1;
    height: 42vh;
    min-height: 280px;
    margin: 0 calc(var(--gutter) * -1);
  }
  /* A swipe across turns the map; a swipe up or down scrolls the page. */
  .vec-canvas {
    touch-action: pan-y;
  }
  .vec-note {
    inset: 0;
    padding: 0 var(--gutter);
  }
  .vec-hud {
    position: relative;
    inset: auto;
    order: 2;
  }
  .hud-view {
    order: -1;
    min-height: 40px;
  }
  /* The view's readout lies over the bottom corner of the map. */
  .hud-readout {
    position: absolute;
    left: 0;
    bottom: calc(100% + var(--s3) + var(--s2));
    margin: 0;
    pointer-events: none;
  }
  /* The legend: its sources in one row that scrolls sideways, its colours in one row. */
  .hud-shape {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }
  .hud-shape > .label {
    line-height: 1.6;
  }
  .hud-sources {
    flex: none;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 calc(var(--gutter) * -1) 0 calc(var(--s2) * -1);
    padding-right: var(--gutter);
  }
  .hud-src {
    flex: none;
  }
  .hud-colour {
    flex-wrap: nowrap;
  }
  .hud-colour > .label {
    display: none;
  }
  .hud-age {
    display: grid;
    grid-template-columns: auto auto auto;
    justify-content: start;
    gap: var(--s1) var(--s2);
    margin-left: 0;
  }
  .hud-age .label {
    grid-column: 1 / -1;
  }
  .vec-left,
  .vec-right {
    display: contents;
  }
  .vec-marked {
    order: 3;
    margin-right: 0;
    pointer-events: auto;
  }
  .vec-inspector-wrap,
  .vec-inspector-wrap.is-idle {
    order: 4;
    flex: none;
    pointer-events: auto;
  }
  .vec-inspector {
    padding-bottom: var(--s4);
  }
  .insp-scroll {
    overflow: visible;
    padding-bottom: 0;
  }
  .vec-probe {
    order: 5;
    pointer-events: auto;
  }
  .vec-terms,
  .vec-terms.is-all {
    order: 6;
    flex: none;
    pointer-events: auto;
  }
  .terms {
    overflow: visible;
  }
  .vec-axes {
    order: 7;
    pointer-events: auto;
  }
  .insp-close,
  .hud-src {
    min-width: 40px;
    min-height: 40px;
  }
  .hud-reset {
    width: 40px;
    padding: 0;
  }
  .hud-reset .btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .ramp-step {
    width: 10px;
  }
}
@media (max-width: 420px) {
  .vec-model {
    display: none;
  }
}
@media (pointer: coarse) {
  .term {
    min-height: 44px;
    align-content: center;
  }
  .insp-more,
  .vec-nearest-hit {
    min-height: 40px;
  }
}
