:root {
  /* base */
  --paper: #ffffff;
  --ink: #111111;
  --ink-2: #666666;
  --rule: #dddddd;
  --tree: #cfcfcf;
  --absent: #f4f4f4;

  /* ClassyFire superclass */
  --sc-lipids: #d08c2b;
  --sc-acids: #3f7f9e;
  --sc-phenylpropanoids: #8a5a44;
  --sc-benzenoids: #5e9c56;
  --sc-organoheterocyclic: #9c7bb5;
  --sc-nitrogen: #2f4b8a;
  --sc-oxygen: #c2504a;
  --sc-nucleosides: #4fa3a0;
  --sc-alkaloids: #d47fa6;
  --sc-unclassified: #333333; /* drawn as a hollow ring */

  /* MS2Query confidence, single-hue sequential */
  --conf-lo: #e9e4d4;
  --conf-hi: #0d3b4c;

  /* type + spacing */
  --font: -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-title: "Source Serif 4", Charter, Georgia, serif;
  --mono: ui-monospace, Menlo, Consolas, monospace;
  --fs-note: 11px;
  --fs-ui: 12px;
  --fs-panel: 13px;
  --fs-title: 15px;
  --u: 8px;
  --gutter: 16px;

}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: var(--fs-ui);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--paper);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  padding: 0 var(--gutter);
}
a { color: inherit; }

/* ---------- header: one provenance line ---------- */
.prov {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px;
  padding: var(--u) 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-2);
}
.prov h1 { font-family: var(--font-title); font-size: var(--fs-title); font-weight: 600; margin: 0; color: var(--ink); }

/* ---------- figure: A | (B / C), separated by rules only ---------- */
.fig { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); min-height: 0; }
.col-right { display: grid; grid-template-rows: minmax(0, 1fr) 180px; min-height: 0; border-left: 1px solid var(--rule); }
#panel-a { padding: var(--gutter) var(--gutter) var(--gutter) 0; }
#panel-b { padding: var(--gutter) 0 var(--gutter) var(--gutter); border-bottom: 1px solid var(--rule); }
#panel-c { padding: var(--gutter) 0 var(--gutter) var(--gutter); }

.panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--u); padding-bottom: var(--u); }
.panel-head h2 { font-size: var(--fs-panel); font-weight: 600; margin: 0; }
.fig-letter { display: inline-block; width: 1.4em; }
.panel-tools { display: flex; align-items: baseline; gap: 6px; color: var(--ink-2); }
.panel-body { position: relative; flex: 1; min-height: 0; overflow: hidden; }

#map-canvas, #map-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#map-overlay { cursor: grab; }
#map-overlay:active { cursor: grabbing; }
.zoom-ctl { position: absolute; top: 0; left: 0; display: flex; gap: 10px; align-items: baseline; color: var(--ink-2); background: var(--paper); padding: 0 6px 2px 0; }
.zoom-ctl button { min-width: 8px; }
.caption { margin: var(--u) 0 0; font-size: var(--fs-note); font-style: italic; color: var(--ink-2); }
#matrix { display: block; width: 100%; height: 100%; }

/* ---------- footer ---------- */
.colophon {
  display: flex; justify-content: space-between; gap: var(--gutter);
  padding: var(--u) 0;
  border-top: 1px solid var(--rule);
  font-size: var(--fs-note); color: var(--ink-2);
}

#help.flash { color: var(--ink); }

/* ---------- narrow: stack A, B, C ---------- */
@media (max-width: 900px) {
  html, body { height: auto; }
  .fig { grid-template-columns: 1fr; }
  .col-right { grid-template-rows: auto auto; border-left: 0; border-top: 1px solid var(--rule); }
  #panel-a { padding-right: 0; }
  #panel-a .panel-body { height: min(90vw, 560px); flex: none; }
  #panel-b, #panel-c { padding-left: 0; }
  #panel-b .panel-body { height: 520px; flex: none; }
  .colophon { flex-direction: column; gap: 4px; }
}

/* ---------- text controls ---------- */
button.link, .segmented button, .enc-switch button {
  font: inherit; color: var(--ink-2);
  background: none; border: 0; padding: 0; margin: 0;
  cursor: pointer;
}
button.link:hover, .segmented button:hover, .enc-switch button:hover { color: var(--ink); }
.segmented { display: inline-flex; gap: 4px; }
.segmented button[aria-checked="true"] { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
button:focus-visible { outline: 1px dotted var(--ink); outline-offset: 2px; }

/* ---------- panel C: colour key ---------- */
/* two-state switch: square, 1px ink frame, active half filled */
.enc-switch { display: inline-flex; border: 1px solid var(--ink); }
.enc-switch button { padding: 2px 10px; color: var(--ink); line-height: 16px; }
.enc-switch button + button { border-left: 1px solid var(--ink); }
.enc-switch button:hover { background: var(--absent); }
.enc-switch button[aria-checked="true"] { background: var(--ink); color: var(--paper); cursor: default; }
.enc-mark { display: none; }

.keys { display: grid; grid-template-columns: minmax(0, 440px) 180px; justify-content: space-between; gap: var(--gutter); min-height: 0; }
.key { cursor: pointer; transition: opacity 0.1s; }
.key.inactive { opacity: 0.4; }
.key.inactive:hover { opacity: 0.7; }
@media (max-width: 900px) { .keys { grid-template-columns: 1fr; } }

.swatches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px var(--gutter); }
.swatch { display: flex; align-items: center; gap: 6px; min-width: 0; }
.swatch i { width: 8px; height: 8px; flex-shrink: 0; }
.swatch i.hollow { border: 1px solid var(--sc-unclassified); }
.swatch .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch .count { margin-left: auto; color: var(--ink-2); }

.ramp { display: block; overflow: visible; }
.ramp text { font-size: var(--fs-note); fill: var(--ink-2); font-family: var(--font); }
.ramp .tick line { stroke: var(--ink-2); }
.ramp .bracket { fill: none; stroke: var(--ink); stroke-width: 1; }

/* ---------- marks ---------- */
.feature-dot { stroke: var(--paper); cursor: pointer; }
.feature-dot.hollow { stroke: var(--sc-unclassified); }
.feature-dot.dim { opacity: 0.25; }
.col-label { font-size: var(--fs-ui); font-weight: 600; fill: var(--ink); }
.col-sub { font-size: var(--fs-note); fill: var(--ink-2); }
.track { fill: var(--absent); }
.cell.unclassified { stroke: var(--sc-unclassified); stroke-width: 0.6; }
.map-flag { fill: var(--ink); }
.col-head { font-size: var(--fs-ui); }
.hover-ring, .sel-ring { fill: none; stroke: var(--ink); pointer-events: none; }
.sel-tick { fill: var(--ink); pointer-events: none; }
.row-highlight { fill: none; stroke: var(--ink); stroke-width: 1; pointer-events: none; }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; z-index: 50; width: 300px;
  padding: var(--u);
  background: var(--paper); border: 1px solid var(--ink);
  pointer-events: none; font-size: var(--fs-note);
}
.tooltip h3 { font-size: var(--fs-ui); font-weight: 600; margin: 0 0 4px; line-height: 1.3; }
.tooltip dl { display: grid; grid-template-columns: auto 1fr; gap: 1px var(--u); margin: 0; }
.tooltip dt { color: var(--ink-2); }
.tooltip dd { margin: 0; word-break: break-word; }
.tooltip .structure { display: block; margin: 4px auto 0; }
.tooltip .tip-foot { margin-top: 4px; color: var(--ink-2); }
