:root {
  --base: #0E1822;      /* reading room */
  --panel: #152230;
  --raised: #1B2B3B;
  --line: #253649;
  --text: #DCE5EC;
  --muted: #8299AC;
  --amber: #F0A93B;     /* contrast agent: high scores and the active organ only */
  --amber-dim: #7A5A2A;
  --steel: #4F7894;     /* low scores */
  --danger: #E26D5C;
  --ok: #7FB59A;
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;
  --r-sm: 6px;
  --r-md: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column;
  background: var(--base);
  color: var(--text);
  font: 400 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand-logo { display: block; flex: none; padding-right: 16px; border-right: 1px solid var(--line); }
.brand-logo img { display: block; height: 40px; width: auto; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { margin: 0; color: var(--muted); font-size: 13px; }
.gpu-pill {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 13px; white-space: nowrap;
}
.gpu-dots { display: grid; grid-template-columns: repeat(8, 6px); gap: 3px; }
.gpu-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.gpu-dots i.free { background: var(--ok); }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 280px minmax(0, 1fr) 380px;
  flex: 1; min-height: 0;
}
.pane { min-height: 0; overflow: auto; padding: 18px; }
.studies { border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 18px; }
.findings { border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; }
.viewer { display: flex; flex-direction: column; padding: 12px 14px; gap: 10px; overflow: hidden; }
.pane-title { margin: 0; font-size: 15px; font-weight: 600; }

/* ---------- upload ---------- */
.drop {
  display: grid; justify-items: center; gap: 4px; text-align: center;
  padding: 20px 14px; border: 1.5px dashed var(--line); border-radius: var(--r-md);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.drop svg { width: 26px; height: 26px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.drop strong { font-weight: 600; }
.drop span { color: var(--muted); font-size: 13px; }
.drop .drop-warn { margin-top: 6px; color: var(--text); font-size: 12.5px; }
.drop:hover, .drop.over { border-color: var(--amber); background: rgba(240, 169, 59, .05); }
.progress { width: 100%; height: 4px; margin-top: 8px; border-radius: 2px; background: var(--line); overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--amber); transition: width .2s; }

/* ---------- library ---------- */
.library label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.library input {
  width: 100%; padding: 9px 11px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--panel);
}
.library input::placeholder { color: #5D7385; }
.lib-results { list-style: none; margin: 6px 0 0; padding: 0; }
.lib-results li button {
  width: 100%; display: flex; justify-content: space-between; gap: 8px; text-align: left;
  padding: 7px 10px; border: 0; border-radius: var(--r-sm); background: none; cursor: pointer;
}
.lib-results li button:hover { background: var(--raised); }
.lib-results small { color: var(--muted); }

/* ---------- scan list ---------- */
.scan-list { list-style: none; margin: -8px 0 0; padding: 0; display: grid; gap: 2px; }
.scan-list li { position: relative; }
.scan-list .item {
  width: 100%; display: grid; gap: 1px; text-align: left; padding: 8px 32px 8px 10px;
  border: 0; border-left: 2px solid transparent; border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: none; cursor: pointer;
}
.scan-list .item:hover { background: var(--panel); }
.scan-list .item.on { background: var(--raised); border-left-color: var(--amber); }
.scan-list .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-list .sub { font-size: 12.5px; color: var(--muted); }
.scan-list .del {
  position: absolute; right: 4px; top: 8px; width: 24px; height: 24px; border: 0; border-radius: 4px;
  background: none; color: var(--muted); cursor: pointer; opacity: 0;
}
.scan-list li:hover .del, .scan-list .del:focus-visible { opacity: 1; }
.scan-list .del:hover { color: var(--danger); background: var(--panel); }
.scan-list .empty-list { color: var(--muted); font-size: 13px; padding: 4px 10px; }

/* ---------- segmented control / switch ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-sm); background: var(--panel); border: 1px solid var(--line); }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 4px; cursor: pointer; color: var(--muted); font-size: 13.5px; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--raised); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg.small button { padding: 3px 9px; font-size: 13px; }
.viewer-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.overlay-ctl { display: flex; align-items: center; gap: 12px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 30px; height: 17px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 13px; height: 13px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.switch input:checked + span { background: var(--amber-dim); }
.switch input:checked + span::after { transform: translateX(13px); background: var(--amber); }
.switch input:focus-visible + span { outline: 2px solid var(--amber); outline-offset: 2px; }
.switch input:disabled + span { opacity: .4; }
input[type=range] { accent-color: var(--amber); width: 110px; }

/* ---------- stage / views ---------- */
.stage { position: relative; flex: 1; min-height: 0; }
.views {
  position: absolute; inset: 0; display: grid; gap: 8px;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); grid-template-rows: 1fr 1fr;
}
.view { position: relative; margin: 0; background: #000; border-radius: var(--r-sm); overflow: hidden; min-height: 0; }
.view.main { grid-row: 1 / 3; }
.view canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.view figcaption, .view .slice-no {
  position: absolute; top: 8px; font-size: 12.5px; color: var(--muted); pointer-events: none;
  text-shadow: 0 1px 2px #000;
}
.view figcaption { left: 10px; }
.view .slice-no { right: 10px; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; max-width: 46ch; margin: auto; color: var(--muted); }
.empty-title { color: var(--text); font-size: 17px; font-weight: 600; margin: 0 0 4px; }
.loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); background: rgba(14, 24, 34, .6); }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--amber); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.readout { display: flex; gap: 20px; flex-wrap: wrap; min-height: 21px; font-size: 13px; color: var(--muted); }
.readout #roOrgan { color: var(--amber); }

/* ---------- findings ---------- */
.findings-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.scan-meta { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.run {
  flex: none; padding: 9px 16px; border: 0; border-radius: var(--r-sm); cursor: pointer;
  background: var(--amber); color: #1A1206; font-weight: 700;
}
.run:hover { filter: brightness(1.07); }
.run:disabled { background: var(--raised); color: var(--muted); cursor: not-allowed; filter: none; }

.steps { list-style: none; margin: 0; padding: 12px 14px; border-radius: var(--r-md); background: var(--panel); display: grid; gap: 7px; font-size: 13.5px; }
.steps li { display: flex; align-items: center; gap: 10px; color: #5D7385; }
.steps li::before { content: ""; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid currentColor; flex: none; }
.steps li.done { color: var(--muted); }
.steps li.done::before { background: var(--muted); border-color: var(--muted); }
.steps li.now { color: var(--text); }
.steps li.now::before { border-color: var(--amber); background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
.steps li .t { margin-left: auto; color: var(--muted); }
@keyframes pulse { 50% { opacity: .35; } }
.job-error { margin: 0; padding: 10px 12px; border-radius: var(--r-sm); background: rgba(226, 109, 92, .12); color: #F2B1A7; font-size: 13px; white-space: pre-wrap; max-height: 200px; overflow: auto; }

.sort { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.timing { font-size: 12.5px; color: var(--muted); }

.finding-list { list-style: none; margin: 0; padding: 0; display: grid; }
.finding-list .group { padding: 12px 4px 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.finding {
  display: grid; grid-template-columns: minmax(0, 1fr) 46px; gap: 3px 10px; align-items: center;
  padding: 8px 8px; border-radius: var(--r-sm); cursor: default;
}
.finding.has-organ { cursor: pointer; }
.finding:hover, .finding.pinned { background: var(--panel); }
.finding.pinned { box-shadow: inset 2px 0 0 var(--amber); }
.finding .fname { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finding .fscore { text-align: right; font-weight: 600; }
.finding .bar { grid-column: 1 / 2; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.finding .bar i { display: block; height: 100%; border-radius: 2px; }
.finding .where { grid-column: 1 / 3; display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }
.finding .swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.chip { padding: 0 7px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; }
.chip.positive { border-color: var(--amber-dim); color: var(--amber); }
.chip.negative { color: var(--muted); }
.finding.high .fscore { color: var(--amber); }

.report { border-top: 1px solid var(--line); padding-top: 10px; }
.report summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.report p { white-space: pre-wrap; font-size: 13.5px; max-width: 60ch; }
.note { margin: auto 0 0; padding-top: 12px; font-size: 12.5px; color: var(--muted); max-width: 52ch; }

.lib-results { max-height: 232px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; }
.lib-results:empty { display: none; }
.lib-results .empty-list { color: var(--muted); font-size: 13px; padding: 6px 10px; list-style: none; }

.credits {
  flex: none; padding: 8px 20px 10px; border-top: 1px solid var(--line);
  font-size: 12px; line-height: 1.5; color: var(--muted);
}
.credits p { margin: 0; max-width: 150ch; }
.credits a { color: var(--text); text-decoration-color: var(--line); text-underline-offset: 2px; }
.credits a:hover { text-decoration-color: var(--amber); }

.tooltip { position: fixed; z-index: 10; pointer-events: none; padding: 3px 8px; border-radius: 4px; background: var(--raised); border: 1px solid var(--line); font-size: 12.5px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  body { display: block; height: auto; }
  .layout { grid-template-columns: 240px minmax(0, 1fr); grid-template-rows: auto auto; }
  .viewer { height: 72vh; }
  .findings { grid-column: 1 / 3; border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  .brand-sub { display: none; }
  .brand { gap: 12px; }
  .brand-logo img { height: 28px; }
  .brand-logo { padding-right: 12px; }
  .brand h1 { font-size: 15px; line-height: 1.2; }
  .gpu-pill { padding: 6px 10px; }
  #gpuText { display: none; }
  .layout { grid-template-columns: 1fr; }
  .studies { border-right: 0; border-bottom: 1px solid var(--line); }
  .findings { grid-column: auto; }
  .pane { padding: 16px; }
  .viewer { height: 80vh; padding: 10px 16px; }
  .views { grid-template-columns: 1fr 1fr; grid-template-rows: 2fr 1fr; }
  .view.main { grid-row: auto; grid-column: 1 / 3; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
