:root {
  color-scheme: light;
  --bg: #f6f5f9;
  --surface: #ffffff;
  --surface-2: #f0eef6;
  --border: rgba(28, 28, 31, .10);
  --text: #1c1c1f;
  --text-2: #55536a;
  --text-3: #8a879c;
  --brand: #7b4fe0;
  --brand-2: #b980ff;
  --brand-soft: rgba(123, 79, 224, .12);
  --mf: #1baf7a;            /* confirmed mitotic figure */
  --non: #eb6834;           /* confirmed not a mitotic figure */
  --tie: #eda100;           /* needs a decision */
  --review: #6250d6;        /* in expert review */
  --extracted: #b8a6ec;     /* cropped, waiting */
  --todo: #dcd9e6;          /* not yet reached */
  --shadow: 0 1px 2px rgba(23, 25, 39, .06), 0 4px 18px rgba(23, 25, 39, .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #131217; --surface: #1c1b22; --surface-2: #26242f; --border: rgba(255, 255, 255, .10);
    --text: #f0eff5; --text-2: #bdbacd; --text-3: #8b8899;
    --brand: #a07df2; --brand-soft: rgba(160, 125, 242, .18);
    --mf: #199e70; --non: #d95926; --tie: #c98500; --review: #9085e9; --extracted: #5c4f8d; --todo: #34323f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 18px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131217; --surface: #1c1b22; --surface-2: #26242f; --border: rgba(255, 255, 255, .10);
  --text: #f0eff5; --text-2: #bdbacd; --text-3: #8b8899;
  --brand: #a07df2; --brand-soft: rgba(160, 125, 242, .18);
  --mf: #199e70; --non: #d95926; --tie: #c98500; --review: #9085e9; --extracted: #5c4f8d; --todo: #34323f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 18px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; color: var(--text-2); font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.muted { color: var(--text-3); }
.small { font-size: .85rem; }
.right { text-align: right; }
.hidden { display: none !important; }

/* header */
header.top {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.top-inner { max-width: 1240px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 22px; height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .dot { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: grid; place-items: center; color: #fff; font-size: .8rem; }
.brand span.sub { color: var(--text-3); font-weight: 500; }
nav.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
nav.tabs a {
  padding: 8px 13px; border-radius: 9px; color: var(--text-2); font-weight: 560; white-space: nowrap; display: flex; align-items: center; gap: 7px;
}
nav.tabs a .n { width: 19px; height: 19px; border-radius: 50%; background: var(--surface-2); font-size: .72rem; display: grid; place-items: center; color: var(--text-2); }
nav.tabs a:hover { background: var(--surface-2); text-decoration: none; }
nav.tabs a.active { background: var(--brand-soft); color: var(--brand); }
nav.tabs a.active .n { background: var(--brand); color: #fff; }
.top-right { display: flex; align-items: center; gap: 10px; }

main { max-width: 1240px; margin: 0 auto; padding: 26px 20px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.55rem; }
.page-head p { color: var(--text-2); max-width: 70ch; }

/* generic */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 18px; }
.grid > .card { margin-top: 0; }
.card > h2 + p, .card > h3 + p { margin-top: 4px; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 14px; }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 1px solid transparent; border-radius: 10px; padding: 8px 15px;
  background: var(--brand); color: #fff; display: inline-flex; align-items: center; gap: 7px; transition: filter .12s, transform .05s;
}
button:hover:not(:disabled), .btn:hover { filter: brightness(1.08); text-decoration: none; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost, .btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.ghost:hover:not(:disabled) { background: var(--surface-2); filter: none; }
button.small { padding: 4px 10px; font-size: .85rem; border-radius: 8px; }
button.good { background: var(--mf); } button.bad { background: var(--non); }
input[type=text], input[type=password], input[type=number], select {
  font: inherit; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
input:focus-visible, button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
label.field { display: grid; gap: 5px; font-weight: 560; font-size: .9rem; color: var(--text-2); }
label.field small { font-weight: 400; color: var(--text-3); }
label.check { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; }
label.check input { margin-top: 4px; accent-color: var(--brand); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 650; background: var(--surface-2); color: var(--text-2); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .7; }
.pill.ok { background: color-mix(in srgb, var(--mf) 16%, transparent); color: var(--mf); }
.pill.run { background: var(--brand-soft); color: var(--brand); }
.pill.run::before { animation: pulse 1.2s infinite; }
.pill.warn { background: color-mix(in srgb, var(--tie) 18%, transparent); color: var(--tie); }
.pill.err { background: color-mix(in srgb, var(--non) 16%, transparent); color: var(--non); }
@keyframes pulse { 50% { opacity: .2; } }

.notice { padding: 12px 15px; border-radius: 11px; background: var(--brand-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent); }
.notice.err { background: color-mix(in srgb, var(--non) 12%, transparent); border-color: color-mix(in srgb, var(--non) 35%, transparent); }
.notice.warn { background: color-mix(in srgb, var(--tie) 14%, transparent); border-color: color-mix(in srgb, var(--tie) 40%, transparent); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.sel { background: var(--brand-soft); }
.scroll { overflow: auto; max-height: 520px; border: 1px solid var(--border); border-radius: 11px; }
.scroll th { position: sticky; top: 0; background: var(--surface); z-index: 1; }

/* ---------- pipeline hero ---------- */
.hero { padding: 30px 22px 22px; }
.hero-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.pipeline { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; position: relative; }
.stage { position: relative; padding: 0 10px 0 0; }
.stage-card {
  display: block; color: inherit; height: 100%; border: 1px solid var(--border); border-radius: 14px; padding: 15px 15px 14px; background: var(--surface);
  transition: transform .12s, box-shadow .12s, border-color .12s; position: relative;
}
a.stage-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--brand); }
.stage.current .stage-card { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.stage .here { position: absolute; top: -11px; left: 14px; background: var(--brand); color: #fff; font-size: .68rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; letter-spacing: .04em; text-transform: uppercase; }
.stage-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.stage-no { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem; background: var(--surface-2); color: var(--text-2); }
.stage.done .stage-no { background: var(--mf); color: #fff; }
.stage.current .stage-no { background: var(--brand); color: #fff; }
.stage-title { font-weight: 650; font-size: .95rem; }
.stage-where { font-size: .75rem; color: var(--text-3); }
.stage-num { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; margin-top: 8px; font-variant-numeric: tabular-nums; }
.stage-sub { font-size: .82rem; color: var(--text-2); min-height: 2.5em; }
.ring { width: 54px; height: 54px; flex: none; }
.ring text { font: 700 14px -apple-system, system-ui, sans-serif; fill: var(--text); }
.ring .track { stroke: var(--todo); }
.ring .bar { stroke: var(--brand); transition: stroke-dashoffset .6s ease; }
.stage.done .ring .bar { stroke: var(--mf); }
.arrow { position: absolute; right: -4px; top: 50%; width: 18px; height: 18px; margin-top: -9px; z-index: 2; color: var(--text-3); display: grid; place-items: center; background: var(--bg); border-radius: 50%; }
.stage:last-child .arrow { display: none; }

.next { margin-top: 20px; display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 14px 18px; border-radius: 12px; background: var(--brand-soft); }
.next b { display: block; }
.next .why { color: var(--text-2); font-size: .9rem; }

/* ---------- bars ---------- */
.stackbar { display: flex; gap: 2px; height: 34px; border-radius: 8px; overflow: hidden; }
.stackbar > i { display: block; min-width: 2px; transition: flex-grow .5s; }
.stackbar.thin { height: 12px; border-radius: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; font-size: .86rem; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.legend b { color: var(--text); font-variant-numeric: tabular-nums; }
.hbar { display: grid; grid-template-columns: 88px 1fr 92px; gap: 12px; align-items: center; padding: 5px 0; font-size: .9rem; }
.hbar .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.meter { height: 10px; border-radius: 5px; background: var(--todo); overflow: hidden; display: flex; gap: 2px; }
.meter > i { display: block; height: 100%; }
.big { font-size: 2.2rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.kpi .lbl { color: var(--text-3); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.spark i { flex: 1; background: var(--brand-2); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.spark i:hover { opacity: 1; }
.axis { display: flex; justify-content: space-between; color: var(--text-3); font-size: .78rem; margin-top: 4px; }

/* gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.thumb { position: relative; border-radius: 10px; overflow: hidden; background: var(--surface-2); aspect-ratio: 1; cursor: zoom-in; border: 2px solid transparent; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; image-rendering: auto; }
.thumb .tag { position: absolute; left: 4px; bottom: 4px; font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff; }
.thumb.mf { border-color: var(--mf); } .thumb.non_mf { border-color: var(--non); } .thumb.tie { border-color: var(--tie); }
.lightbox { position: fixed; inset: 0; background: rgba(10, 10, 14, .78); z-index: 60; display: grid; place-items: center; padding: 20px; }
.lightbox .box { background: var(--surface); border-radius: 16px; padding: 18px; max-width: 520px; width: 100%; }
.lightbox img { width: 100%; image-rendering: pixelated; border-radius: 10px; background: var(--surface-2); }
.tiecard { display: grid; grid-template-columns: 150px 1fr auto; gap: 16px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.tiecard img { width: 150px; height: 150px; border-radius: 10px; }

/* modal login */
.modal { position: fixed; inset: 0; background: rgba(10, 10, 14, .55); z-index: 70; display: grid; place-items: center; padding: 20px; }
.modal .card { width: 100%; max-width: 380px; }

.tooltip { position: fixed; z-index: 100; pointer-events: none; background: #1c1c1f; color: #fff; padding: 6px 10px; border-radius: 8px; font-size: .8rem; max-width: 280px; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: grid; gap: 8px; }
.toast > div { background: var(--text); color: var(--bg); padding: 10px 15px; border-radius: 10px; box-shadow: var(--shadow); max-width: 420px; }
.toast > div.err { background: var(--non); color: #fff; }
.steps { counter-reset: s; display: grid; gap: 10px; }
.steps li { list-style: none; display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.steps li::before { counter-increment: s; content: counter(s); width: 24px; height: 24px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .8rem; display: grid; place-items: center; }
pre.code { background: var(--surface-2); padding: 12px 14px; border-radius: 10px; overflow: auto; font-size: .82rem; }

@media (max-width: 960px) {
  .pipeline { grid-template-columns: 1fr; gap: 14px; }
  .stage { padding: 0; }
  .arrow { display: none; }
  .tiecard { grid-template-columns: 1fr; }
  .grid.two { grid-template-columns: 1fr; }
  .top-inner { gap: 10px; }
  .brand .sub { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
