:root {
  --bg: #efe5d6;
  --bg-gradient-1: rgba(191, 149, 106, 0.28);
  --bg-gradient-2: rgba(143, 168, 145, 0.22);
  --sidebar-bg: rgba(248, 242, 233, 0.78);
  --brand-bg: linear-gradient(180deg, rgba(255, 251, 245, 0.98), rgba(242, 231, 215, 0.84));
  --panel: rgba(255, 250, 243, 0.82);
  --panel-strong: rgba(255, 252, 247, 0.94);
  --panel-muted: rgba(239, 228, 213, 0.72);
  --topbar-bg: rgba(248, 242, 233, 0.82);
  --section-bg: rgba(241, 233, 221, 0.76);
  --text: #34291f;
  --text-strong: #251b12;
  --muted: #74624f;
  --accent: #9f6740;
  --accent-soft: rgba(159, 103, 64, 0.14);
  --accent-ring: rgba(159, 103, 64, 0.26);
  --danger: #b45c52;
  --warning-bg: rgba(180, 92, 82, 0.12);
  --warning-border: rgba(180, 92, 82, 0.26);
  --border: rgba(114, 92, 72, 0.18);
  --border-strong: rgba(114, 92, 72, 0.3);
  --divider: rgba(114, 92, 72, 0.12);
  --button-bg: rgba(255, 252, 247, 0.88);
  --button-hover: rgba(255, 255, 255, 0.96);
  --button-secondary: rgba(234, 222, 206, 0.8);
  --button-border: rgba(114, 92, 72, 0.18);
  --input-bg: rgba(255, 252, 248, 0.94);
  --input-border: rgba(114, 92, 72, 0.22);
  --drop-bg: rgba(255, 251, 246, 0.82);
  --drop-border: rgba(114, 92, 72, 0.28);
  --status-bg: rgba(247, 239, 228, 0.84);
  --status-border: rgba(114, 92, 72, 0.18);
  --surface: rgba(255, 249, 241, 0.74);
  --surface-strong: rgba(247, 238, 224, 0.82);
  --shadow: 0 18px 44px rgba(96, 75, 49, 0.12);
  --plot-canvas-bg: rgba(249, 243, 234, 0.98);
  --plot-frame: rgba(99, 80, 61, 0.24);
  --plot-point: rgba(75, 59, 41, 0.42);
  --review-point: rgba(159, 103, 64, 0.58);
  --plot-text: rgba(66, 53, 39, 0.72);
  --plot-gate: rgba(82, 64, 44, 0.34);
  --plot-gate-selected: rgba(159, 103, 64, 0.95);
  --plot-drag: rgba(82, 64, 44, 0.74);
  --plot-loading: rgba(82, 64, 44, 0.12);
  --density-accent-rgb: 159 103 64;
  --density-peak-rgb: 63 46 29;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* Ensure [hidden] attribute always hides elements, even when display is set by other rules */
[hidden] { display: none !important; }

body[data-theme="dark"] {
  --bg: #0b1020;
  --bg-gradient-1: rgba(110, 168, 255, 0.25);
  --bg-gradient-2: rgba(255, 110, 186, 0.12);
  --sidebar-bg: rgba(0, 0, 0, 0.2);
  --brand-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.08);
  --panel-muted: rgba(255, 255, 255, 0.04);
  --topbar-bg: rgba(0, 0, 0, 0.15);
  --section-bg: rgba(0, 0, 0, 0.08);
  --text: rgba(255, 255, 255, 0.92);
  --text-strong: rgba(255, 255, 255, 0.97);
  --muted: rgba(255, 255, 255, 0.68);
  --accent: #6ea8ff;
  --accent-soft: rgba(110, 168, 255, 0.14);
  --accent-ring: rgba(110, 168, 255, 0.24);
  --danger: #ff6e6e;
  --warning-bg: rgba(255, 110, 110, 0.12);
  --warning-border: rgba(255, 110, 110, 0.35);
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.2);
  --divider: rgba(255, 255, 255, 0.1);
  --button-bg: rgba(255, 255, 255, 0.08);
  --button-hover: rgba(255, 255, 255, 0.12);
  --button-secondary: rgba(0, 0, 0, 0.18);
  --button-border: rgba(255, 255, 255, 0.18);
  --input-bg: rgba(0, 0, 0, 0.25);
  --input-border: rgba(255, 255, 255, 0.18);
  --drop-bg: rgba(255, 255, 255, 0.04);
  --drop-border: rgba(255, 255, 255, 0.25);
  --status-bg: rgba(0, 0, 0, 0.2);
  --status-border: rgba(255, 255, 255, 0.15);
  --surface: rgba(0, 0, 0, 0.16);
  --surface-strong: rgba(0, 0, 0, 0.24);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --plot-canvas-bg: rgba(6, 10, 16, 0.94);
  --plot-frame: rgba(255, 255, 255, 0.16);
  --plot-point: rgba(255, 255, 255, 0.55);
  --review-point: rgba(110, 168, 255, 0.65);
  --plot-text: rgba(255, 255, 255, 0.74);
  --plot-gate: rgba(255, 255, 255, 0.3);
  --plot-gate-selected: rgba(110, 168, 255, 0.95);
  --plot-drag: rgba(255, 255, 255, 0.75);
  --plot-loading: rgba(255, 255, 255, 0.1);
  --density-accent-rgb: 110 168 255;
  --density-peak-rgb: 255 255 255;
}

/* ── モード切替タブ ───────────────────────────────────── */
.mode-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 10px 0;
  background: var(--brand-bg);
  border-bottom: 1px solid var(--border);
}

.mode-tab {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: var(--button-secondary);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mode-tab:hover {
  background: var(--button-hover);
  color: var(--text);
}

.mode-tab.active {
  background: var(--panel-strong);
  color: var(--accent);
  border-color: var(--accent-ring);
  font-weight: 700;
}

.mode-panel {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 30% 20%, var(--bg-gradient-1), transparent 60%),
    radial-gradient(900px 700px at 70% 80%, var(--bg-gradient-2), transparent 60%),
    var(--bg);
}

body {
  transition: background-color 180ms ease, color 180ms ease;
}

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 360px 1fr;
}

.sidebar {
  padding: 14px;
  overflow: auto;
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  backdrop-filter: blur(16px);
}

.brand {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--brand-bg);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text-strong);
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.panel {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  backdrop-filter: blur(12px);
}

.panel h2 {
  margin: 0 0 4px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-strong);
}

.panel-subtitle {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.4;
}

.panel-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.drop-zone {
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--drop-border);
  background: var(--drop-bg);
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-title {
  font-weight: 700;
  color: var(--text-strong);
}

.drop-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

#fileInput {
  width: 100%;
  margin-top: 8px;
}

.btn {
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.btn:hover {
  border-color: var(--border-strong);
  background: var(--button-hover);
}

.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: var(--button-secondary);
}

.btn[disabled],
select:disabled,
input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.file-btn input[type="file"] {
  display: none;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.spacer {
  flex: 1;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field .label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

select,
input[type="number"] {
  width: 100%;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.warning {
  margin-top: 10px;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid var(--warning-border);
  background: var(--warning-bg);
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
}

.gate-edit,
.apply-box {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--divider);
}

.apply-box {
  display: grid;
  gap: 8px;
}

.progress {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-strong);
  border: 1px solid var(--border);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(var(--density-accent-rgb), 0.88), rgba(110, 255, 196, 0.72));
  transition: width 80ms linear;
}

.kv {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 4px 10px;
  margin-top: 10px;
  font-size: 12px;
}

.kv .k {
  color: var(--muted);
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
}

.details summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
  margin-bottom: 8px;
}

.status-box {
  margin-top: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--status-border);
  background: var(--status-bg);
  line-height: 1.35;
  word-break: break-word;
}

.comp-adjust-row {
  flex-wrap: wrap;
}

#compExactInput {
  width: 110px;
}

.param-list {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.param-item,
.param-item-empty,
.gate-tree-item {
  padding: 8px 10px;
  border-bottom: 1px solid var(--divider);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.param-item:last-child,
.param-item-empty:last-child,
.gate-tree-item:last-child {
  border-bottom: none;
}

.param-item-empty {
  color: var(--muted);
}

.gate-tree {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}

.gate-tree-item {
  display: block;
  cursor: pointer;
}

.gate-tree-item.selected {
  background: var(--accent-soft);
  color: var(--text-strong);
}

.comp-matrix-wrap {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.comp-matrix-caption {
  padding: 10px 12px;
  border-bottom: 1px solid var(--divider);
  background: var(--panel-muted);
}

.comp-matrix-table {
  overflow: auto;
  max-height: 320px;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

.matrix-table th,
.matrix-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--divider);
  border-right: 1px solid var(--divider);
  font-size: 12px;
  white-space: nowrap;
}

.matrix-table thead th {
  position: sticky;
  top: 0;
  background: var(--panel-strong);
  z-index: 3;
  text-align: left;
}

.matrix-table thead th:first-child {
  left: 0;
  z-index: 4;
}

.matrix-table tbody th {
  position: sticky;
  left: 0;
  background: var(--panel-strong);
  z-index: 2;
  text-align: left;
}

.matrix-table td {
  text-align: right;
  font-family: var(--mono);
}

.matrix-table td.nonzero {
  color: var(--text-strong);
}

.matrix-table td.active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-ring);
}

.single-stain-list {
  display: grid;
  gap: 8px;
  margin: 10px 0 12px;
}

.single-stain-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.single-stain-item.selected {
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.single-stain-file {
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

.single-stain-file-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.single-stain-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.single-stain-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--panel-muted);
}

.single-stain-badge.low {
  border-color: rgba(199, 144, 64, 0.35);
  background: rgba(199, 144, 64, 0.12);
  color: var(--text);
}

.single-stain-badge.high {
  border-color: rgba(86, 160, 118, 0.35);
  background: rgba(86, 160, 118, 0.12);
}

.main {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
}

.topbar {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
}

.single-stain-section {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: var(--section-bg);
  display: grid;
  gap: 12px;
}

.single-stain-header {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.single-stain-title {
  font-size: 14px;
  font-weight: 700;
}

.single-stain-review {
  display: grid;
  gap: 12px;
}

.single-stain-intro,
.single-stain-empty {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  line-height: 1.4;
  font-size: 12px;
}

.single-stain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.single-stain-plot {
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  border-radius: 14px;
  padding: 10px;
  display: grid;
  gap: 10px;
}

.single-stain-plot.selected {
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.single-stain-focus {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
  cursor: pointer;
}

.single-stain-plot-title {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.single-stain-canvas {
  width: 100%;
  height: 220px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--plot-canvas-bg);
}

.single-stain-plot-footer {
  font-size: 11px;
  color: var(--muted);
}

.single-stain-slider-wrap {
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--divider);
}

.single-stain-slider-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.single-stain-slider-label {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.single-stain-slider-value {
  min-width: 48px;
  text-align: right;
}

.single-stain-edit-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.single-stain-number {
  width: 100%;
}

.single-stain-nudge {
  min-width: 62px;
}

.plots {
  padding: 14px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 14px;
  align-content: start;
  align-items: start;
}

.plot-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 360px;
  max-height: 560px;
}

.plot-card.active {
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 1px var(--accent-soft), var(--shadow);
}

.plot-header {
  padding: 10px;
  border-bottom: 1px solid var(--divider);
  background: var(--panel-muted);
  display: grid;
  grid-template-columns: 1fr 1fr auto auto auto;
  gap: 8px;
  align-items: end;
}

/* ── plotCard layout ─────────────────────────────────────────── */

/* plot-body: Y軸 + canvas の横並び */
.plot-body {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 0;
}

/* ── Y軸: スライダー列(左) + selectラベル列(右) ──────────────── */
.plot-axis-y {
  flex-shrink: 0;
  display: flex;
  flex-direction: row;
  border-right: 1px solid var(--divider);
}

.y-slider-col {
  width: 30px;
  display: flex;
  flex-direction: column;
}

.y-slider-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 2px;
  gap: 2px;
}

/* 縦型スライダー: writing-mode で実現 */
.y-axis-slider {
  writing-mode: vertical-lr;
  direction: rtl;            /* 上 = max, 下 = min */
  -webkit-appearance: slider-vertical;
  width: 18px;
  flex: 1;
  min-height: 30px;
  accent-color: var(--accent);
  cursor: pointer;
  touch-action: none;        /* スクロール干渉を防ぎ pointer events を確実に捕捉 */
  position: relative;
  z-index: 3;                /* axis-select-y (z-index:2) より上に配置 */
}

/* comp モードのレンジ端ラベル ("+1.00" / 現在値) */
.y-comp-edge {
  font-size: 9px;
  color: var(--muted);
  text-align: center;
  line-height: 1.2;
  flex-shrink: 0;
  word-break: break-all;
}

/* Y チャンネル select: 縦回転 */
.axis-select-y-wrap {
  width: 26px;
  position: relative;
  overflow: visible;
  flex-shrink: 0;
}

.axis-select-y {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  width: 130px;
  font-size: 10px;
  padding: 3px 4px;
  z-index: 2;
}

/* ── X軸: select行 + コントロール行 (flex-column) ─────────────── */
.plot-axis-x {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 8px 8px;
  border-top: 1px solid var(--divider);
  background: var(--panel-muted);
}

.x-sel-row {
  display: flex;
  justify-content: center;
}

.axis-select-x {
  min-width: 100px;
  max-width: 240px;
  font-size: 11px;
}

/* range / comp コントロール行 */
.x-ctrl-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.x-range-slider,
.x-comp-slider {
  flex: 1;
  min-width: 30px;
  accent-color: var(--accent);
}

.x-comp-label {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.x-comp-val {
  font-size: 11px;
  flex-shrink: 0;
  min-width: 44px;
  text-align: right;
}

/* Auto / Reset ボタン */
.axis-auto-btn {
  flex-shrink: 0;
  padding: 4px 8px !important;
  font-size: 11px !important;
}

/* Max 直接入力ボックス */
.axis-max-input {
  width: 70px;
  font-size: 11px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--input-bg, var(--card));
  color: var(--text);
  flex-shrink: 0;
  /* Chrome の数値スピナーを非表示 */
  -moz-appearance: textfield;
}
.axis-max-input::-webkit-outer-spin-button,
.axis-max-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.axis-max-input:focus {
  outline: 1px solid var(--accent-ring, var(--accent));
}

/* Max ラベル ("X:" / "Y:") */
.axis-max-label {
  font-size: 11px;
  opacity: 0.65;
  flex-shrink: 0;
  margin-left: 4px;
  user-select: none;
}

/* ⚡ Comp ボタン active 状態 */
.btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-ring);
  color: var(--accent);
  font-weight: 700;
}

/* PNG Save ボタン */
.save-png-btn {
  padding: 2px 6px !important;
  font-size: 12px !important;
}

/* Canvas wrap */
.plot-canvas-wrap {
  flex: 1;
  position: relative;
  padding: 8px;
  min-width: 0;
  min-height: 220px;
}

/* ── Single-stain review プロットの軸ラベル ─────────────────── */
.ss-plot-body {
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

/* Y-axis comp slider column (left of canvas) */
.ss-y-slider-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 26px;
  flex-shrink: 0;
  padding: 4px 2px;
  gap: 3px;
}

.ss-y-comp-slider {
  writing-mode: vertical-lr;
  direction: rtl;
  -webkit-appearance: slider-vertical;
  width: 16px;
  flex: 1;
  min-height: 30px;
  accent-color: var(--accent);
  cursor: pointer;
  touch-action: none;        /* スクロール干渉を防ぎ pointer events を確実に捕捉 */
}

/* X-axis comp slider row (below canvas) */
.ss-x-ctrl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px 2px;
}

.ss-x-comp-slider {
  flex: 1;
  min-width: 30px;
  accent-color: var(--accent);
}

/* Coefficient value label for both sliders */
.ss-slider-val {
  font-size: 9px;
  font-family: var(--mono);
  color: var(--muted);
  text-align: center;
  min-width: 34px;
  flex-shrink: 0;
}

.ss-y-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  padding: 0 3px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 220px;
}

.ss-x-label {
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  padding: 2px 4px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

canvas {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  background: var(--plot-canvas-bg);
  border: 1px solid var(--border);
}

.plot-overlay {
  position: absolute;
  left: 18px;
  top: 16px;
  right: 18px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  color: var(--plot-text);
  font-size: 12px;
}

/* .plot-footer is no longer used — replaced by .plot-axis-x + .plot-range-panel */

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100%;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 50vh;
  }

  .plots {
    grid-template-columns: 1fr;
  }

  .single-stain-header {
    align-items: flex-start;
  }

  .plot-header,
  .plot-footer {
    grid-template-columns: 1fr 1fr;
  }
}

.ss-empty-hint { padding: 40px; text-align: center; color: var(--muted); font-size: 13px; }
.ss-empty-hint p:first-child { font-size: 16px; font-weight: 600; margin-bottom: 8px; }

.gate-stats-table {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.gate-stats-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) repeat(3, minmax(72px, 0.8fr));
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 12px;
}

.gate-stats-row.header {
  font-weight: 700;
  background: var(--panel);
}

.gate-stats-cell.mono {
  text-align: right;
}
