:root {
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e2e2e2;
  --bg: #ffffff;
  --bg-soft: #f7f7f5;
  --accent: #8c1515;          /* Stanford cardinal */
  --accent-soft: #f4e9e9;
  --radius: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}

header { flex: 0 0 auto; border-bottom: 1px solid var(--line); background: var(--bg); }
.masthead { display: flex; align-items: baseline; gap: 14px; padding: 12px 20px 8px; flex-wrap: wrap; }
.masthead h1 { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.masthead .cite { font-size: 13px; color: var(--muted); }
.masthead .cite a { color: var(--muted); }

nav { display: flex; gap: 2px; padding: 0 14px; }
nav a {
  padding: 8px 14px; font-size: 14px; text-decoration: none; color: var(--muted);
  border-bottom: 2px solid transparent; border-radius: var(--radius) var(--radius) 0 0;
}
nav a:hover { background: var(--bg-soft); color: var(--ink); }
nav a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.panel { height: 100%; overflow: auto; }
.panel[hidden] { display: none; }
#rna-panel { overflow: hidden; }

/* Gene expression tab (js/rna.js): sidebar + WebGL UMAP. */
.rna-layout { display: flex; height: 100%; min-height: 480px; }
.rna-sidebar { flex: 0 0 380px; overflow-y: auto; padding: 14px 14px 24px;
  border-right: 1px solid var(--line); font-size: 13px; }
.rna-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.rna-search { position: relative; }
.rna-search input { width: 100%; box-sizing: border-box; padding: 6px 8px; font-size: 14px;
  border: 1px solid #c8c8c8; border-radius: var(--radius); }
.rna-suggestions { position: absolute; z-index: 5; left: 0; right: 0; margin: 2px 0 0; padding: 0;
  list-style: none; background: #fff; border: 1px solid #c8c8c8; border-radius: var(--radius);
  max-height: 260px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.rna-suggestions li { padding: 4px 8px; cursor: pointer; }
.rna-suggestions li:hover, .rna-suggestions li.active { background: var(--accent-soft); }
.rna-gene-status { min-height: 22px; margin: 4px 0; color: var(--muted); }
.rna-error { color: var(--accent); }
.rna-sidebar button { font-size: 12px; padding: 1px 7px; border: 1px solid #c8c8c8;
  background: #fff; border-radius: 4px; cursor: pointer; color: var(--ink); }
.rna-sidebar button:hover { background: var(--bg-soft); }
.rna-legend { margin: 4px 0 14px; }
.rna-legend-note { color: #333; margin-bottom: 6px; }
.rna-colorbar { display: flex; gap: 6px; height: 12px; margin-top: 8px; }
.rna-colorbar-zero { flex: 0 0 14px; background: rgb(208,208,208); border-radius: 2px; }
.rna-colorbar-ramp { position: relative; flex: 1 1 auto; border-radius: 2px; }
.rna-tick { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,.8); }
.rna-colorbar-labels { display: flex; gap: 6px; height: 16px; font-size: 11px; color: #333; }
.rna-colorbar-zero-label { flex: 0 0 14px; text-align: center; }
.rna-colorbar-axis { position: relative; flex: 1 1 auto; }
.rna-colorbar-axis span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.rna-colorbar-axis span:first-child { transform: none; }
.rna-colorbar-axis span:last-child { transform: translateX(-100%); }
.rna-colorbar-units { font-size: 11px; color: var(--muted); }
.rna-celltype-head { display: flex; align-items: baseline; justify-content: space-between;
  border-top: 1px solid var(--line); padding-top: 10px; }
.rna-hide-toggle { display: block; margin: 4px 0 8px; color: #333; }
.rna-group summary, .rna-type { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.rna-group summary { cursor: pointer; font-weight: 600; }
.rna-type { padding-left: 22px; }
.rna-swatch { flex: 0 0 10px; height: 10px; border-radius: 2px; }
.rna-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rna-count { color: var(--muted); font-size: 11px; font-weight: 400; }
.rna-sidebar .rna-only { padding: 0 5px; font-size: 11px; font-weight: 400; }
.rna-sidebar .rna-only.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.rna-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.rna-plot { position: relative; flex: 1 1 auto; min-width: 0; min-height: 300px; }
.rna-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab;
  touch-action: none; }
.rna-canvas:active { cursor: grabbing; }
.rna-plot-actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 3; }
.rna-plot-actions button { font-size: 12px; padding: 3px 9px;
  border: 1px solid #c8c8c8; background: #fff; border-radius: 4px; cursor: pointer; }
.rna-plot-actions button:hover { background: var(--bg-soft); }
.rna-export { position: relative; }
.rna-export-menu { position: absolute; right: 0; top: calc(100% + 3px); display: flex; flex-direction: column;
  background: #fff; border: 1px solid #c8c8c8; border-radius: 4px; box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  white-space: nowrap; }
.rna-export-menu[hidden] { display: none; }
.rna-export-menu button { border: 0; border-radius: 0; text-align: left; padding: 5px 12px; }
.rna-dotplot { position: relative; flex: 0 0 auto; border-top: 1px solid var(--line); padding: 6px 10px 4px; }
.rna-dotplot-head { font-size: 12px; color: #333; margin-bottom: 2px; }
.rna-dotplot-head span { color: var(--muted); }
.rna-dotplot-body { overflow-x: auto; }
.rna-dotplot-body svg { display: block; }
.rna-dotplot-body [data-code] { cursor: pointer; }
.rna-dotplot-body [data-code]:hover { fill: rgba(140, 21, 21, 0.06); }
.rna-plot-note { position: absolute; bottom: 8px; right: 12px; font-size: 11px; color: var(--muted); }
@media (max-width: 760px) {
  #rna-panel { overflow: auto; }
  .rna-layout { flex-direction: column; height: auto; }
  .rna-sidebar { flex: none; border-right: 0; border-bottom: 1px solid var(--line); max-height: 45vh; }
  .rna-plot { flex: none; height: 70vh; }
}

.prose { max-width: 62rem; padding: 22px 26px 40px; }
.prose h2 { font-size: 16px; margin: 26px 0 8px; }
.prose h2:first-child { margin-top: 0; }
.prose p, .prose li { font-size: 14px; color: #333; }
.prose code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg-soft); padding: 1px 5px; border-radius: 3px;
  /* Long unbreakable URLs otherwise crush the neighbouring column to one word per
     line and push the table past .prose's max-width. */
  overflow-wrap: anywhere; }
.prose table { border-collapse: collapse; font-size: 13px; margin: 10px 0 18px; width: 100%; }
.prose th, .prose td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line);
  vertical-align: top; }
.prose td:first-child, .prose th:first-child { min-width: 11rem; }
.prose th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.04em; }
.prose .note { background: var(--accent-soft); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 0 var(--radius) var(--radius) 0; margin: 14px 0; font-size: 13.5px; }

/* ---- ATAC tab ---- */
.atac { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; height: 100%; }
.atac-controls { border-right: 1px solid var(--line); overflow: auto; padding: 16px 18px 32px; }

/* The embedded igv.js browser. min-width:0 so the grid column, not igv's canvas, wins. */
.atac-viewer { display: flex; flex-direction: column; height: 100%; min-width: 0; }
.viewer-bar { flex: 0 0 auto; padding: 8px 14px; background: var(--bg-soft);
  border-bottom: 1px solid var(--line); }
.viewer-row { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; }
.viewer-status { font-size: 12.5px; color: var(--muted); }
.viewer-status code { font-size: 11.5px; }
.viewer-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.viewer-bar .warn { margin: 8px 0 0; }
.viewer-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.viewer-hint[hidden] { display: none; }
.field { margin-bottom: 18px; }
.field > label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); margin-bottom: 6px; }
/* A label wrapping a control is an option, not a section heading. */
.field > label.option { font-size: 13.5px; font-weight: 400; text-transform: none;
  letter-spacing: 0; color: var(--ink); display: flex; align-items: center; gap: 7px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
input[type="text"], input[type="search"], select {
  width: 100%; padding: 7px 9px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
/* accent-soft is almost white: as an outline it silently removed the focus ring the
   browser would otherwise draw. Keyboard users need this to be visible. */
input:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input:focus, select:focus { border-color: var(--accent); }

.ct-search { margin-bottom: 8px; }
.ct-list { border: 1px solid var(--line); border-radius: var(--radius); max-height: 300px;
  overflow: auto; background: var(--bg); }
.ct-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); padding: 7px 10px 3px; position: sticky; top: 0; background: var(--bg); }
.ct-row { display: flex; align-items: center; gap: 8px; padding: 4px 10px; font-size: 13.5px; }
.ct-row:hover { background: var(--bg-soft); }
.ct-row input { margin: 0; flex: 0 0 auto; }
.ct-row .swatch { width: 11px; height: 11px; border-radius: 2px; flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,0.15); }
.ct-row label { flex: 1 1 auto; cursor: pointer; }
.ct-row .id { color: var(--muted); font: 11.5px ui-monospace, monospace; }
.ct-row .dyn { font-size: 11px; color: var(--muted); }

/* Class-scoped, not a bare `button` rule: igv.js injects its own buttons into this page
   and a global rule would repaint them cardinal. */
.btn {
  font: 600 12.5px inherit; padding: 6px 11px; border-radius: var(--radius);
  border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer;
}
.btn:hover:not(:disabled) { background: #6d1010; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.secondary { background: var(--bg); color: var(--accent); }
.btn.secondary:hover:not(:disabled) { background: var(--accent-soft); }
.warn { font-size: 13px; color: #8a5a00; background: #fff8e1; border-left: 3px solid #d9a300;
  padding: 9px 12px; border-radius: 0 var(--radius) var(--radius) 0; margin: 12px 0; }
.loading { padding: 30px 26px; color: var(--muted); font-size: 14px; }
.error { padding: 20px 26px; color: #8c1515; font-size: 14px; }

/* ---- Narrow viewports ----
   The chromatin tab is a two-column grid by default. Below this width the genome
   browser gets too little room to be readable, so stack instead: controls first,
   browser under them, each scrolling with the page. */
@media (max-width: 900px) {
  body { overflow: auto; height: auto; min-height: 100vh; }
  main { overflow: visible; }
  .panel { height: auto; overflow: visible; }
  #rna-panel { height: 80vh; }
  .atac { grid-template-columns: 1fr; height: auto; }
  .atac-controls { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .atac-viewer { height: auto; }
  .viewer-body { overflow: visible; }
  .viewer-row { align-items: flex-start; }
}

/* RNA plot overlays: on-plot cell-type labels, the hover tooltip, the label-mode picker. */
.rna-plot-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.rna-plot-labels span { position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 11px;
  font-weight: 600; color: #222; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff; }
.rna-tooltip { position: absolute; pointer-events: none; background: rgba(255,255,255,0.96);
  border: 1px solid #ccc; border-radius: 4px; padding: 5px 8px; font-size: 12px; line-height: 1.4;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15); max-width: 280px; z-index: 2; }
.rna-tooltip span { color: var(--muted); }
.rna-label-mode { position: absolute; top: 10px; left: 10px; font-size: 12px; color: var(--muted); }
.rna-label-mode select { font-size: 12px; }

/* Cell types tab */
#celltype-panel { overflow: hidden; }
.ctx-sidebar { flex-basis: 260px; font-size: 13px; }
.ctx-group summary { display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; padding: 3px 0; }
.ctx-type { display: block; padding: 2px 0 2px 22px; color: var(--ink); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-type:hover { background: var(--bg-soft); }
.ctx-type.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ctx-main { flex: 1 1 auto; overflow-y: auto; max-width: none; }
.ctx-main > * { max-width: 62rem; }
.ctx-head h2 { display: flex; align-items: center; gap: 8px; font-size: 20px; margin: 0 0 4px; }
.ctx-head .rna-swatch { flex-basis: 14px; height: 14px; }
.ctx-meta { color: var(--muted); font-size: 13px; }
.ctx-links { margin-top: 6px; font-size: 13px; }
.ctx-umaps { display: flex; gap: 18px; flex-wrap: wrap; margin: 14px 0 6px; }
.ctx-umaps figure { margin: 0; }
.ctx-umap { width: 320px; height: 320px; border: 1px solid var(--line); border-radius: var(--radius); }
.ctx-umaps figcaption { font-size: 12px; color: var(--muted); text-align: center; }
.ctx-main section { margin-top: 18px; }
.ctx-main h3 { font-size: 15px; margin: 0 0 6px; border-bottom: 1px solid var(--line); padding-bottom: 3px; }
.ctx-main h4 { font-size: 13px; margin: 12px 0 4px; }
.ctx-sub, .ctx-empty { color: var(--muted); font-size: 13px; }
.ctx-chip { display: inline-block; padding: 1px 7px; margin: 1px 0; border: 1px solid #c8c8c8;
  border-radius: 10px; font-size: 12.5px; color: var(--ink); text-decoration: none; }
.ctx-chip:hover { border-color: var(--accent); color: var(--accent); }
.ctx-table { font-size: 13px; }
.ctx-table td, .ctx-table th { padding: 3px 10px 3px 0; }
.ctx-narrow { width: auto; }
.ctx-genes { font-size: 12px; color: #333; }
.ctx-sig td { font-weight: 600; }
.ctx-bars { max-width: 34rem; }
.ctx-bar-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 2px 0; }
.ctx-bar-label { flex: 0 0 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-bar { flex: 1 1 auto; height: 10px; background: var(--bg-soft); border-radius: 2px; }
.ctx-bar span { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.ctx-bar-value { flex: 0 0 3.5rem; text-align: right; color: var(--muted); }
.ctx-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: #333; margin: 12px 0 0; }
.ctx-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.ctx-logo-cell { padding-right: 12px; } .ctx-logo { display: block; }
.ctx-density-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin: 4px 0 6px; }
.ctx-density { margin: 0; max-width: 420px; }
.ctx-density img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.ctx-density figcaption { font-size: 12px; color: var(--muted); text-align: center; }
