@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin-ext.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --accent: #0e7480;
  --accent-hover: #0a5d67;
  --accent-soft: #e3f1f2;
  --bg: #eef1f1;
  --surface: #ffffff;
  --border: #dde3e4;
  --border-strong: #c6cfd1;
  --text: #1c2328;
  --muted: #5e6b72;
  --danger: #b93a32;
  --sure: #22a55a;
  --unsure: #d98a0b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 45, 50, 0.06), 0 4px 14px rgba(20, 45, 50, 0.06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
a { color: var(--accent); }
.error { color: var(--danger); font-weight: 500; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd {
  font: 0.82em inherit;
  font-weight: 600;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:hover { background: #f3f6f6; border-color: #b3bec0; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #e4e9ea; border-color: transparent; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.brand-mark { width: 22px; height: 22px; flex: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- upload page ---------- */

.site-header { max-width: 1120px; margin: 0 auto; padding: 22px 24px 0; }

.upload-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  grid-template-areas: "intro drop" "details drop";
  column-gap: 56px;
  row-gap: 8px;
  align-items: center;
  max-width: 1120px;
  margin: 0 auto;
  padding: 64px 24px 56px;
}
.intro h1 {
  font-size: clamp(2rem, 3.6vw, 2.9rem);
  line-height: 1.08;
  letter-spacing: -0.025em;
  font-weight: 650;
  text-wrap: balance;
}
.intro { grid-area: intro; align-self: end; }
.details { grid-area: details; align-self: start; }
.drop-area { grid-area: drop; }
.subtitle { margin: 18px 0 20px; max-width: 46ch; color: var(--muted); font-size: 1.06rem; text-wrap: pretty; }

.steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0 0 30px;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.steps li { counter-increment: step; display: grid; grid-template-columns: 26px 1fr; column-gap: 10px; font-size: 0.95rem; color: var(--muted); }
.steps li::before {
  content: counter(step);
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1.5px solid var(--accent);
  border-radius: 7px;
  color: var(--accent-hover);
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.steps li strong { color: var(--text); font-weight: 600; }

.privacy-note { max-width: 50ch; margin: 0; color: var(--muted); font-size: 0.84rem; }

/* The drop zone is drawn as a gel casting tray: wells on top, lanes below.
   Dragging lights the bands; while uploading they run down the lanes. */
.tray {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 22px 26px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}
.tray:hover, .tray.dragging { border-color: var(--accent); }
.tray.dragging { background: #f6fbfb; }
.tray.busy { cursor: progress; border-style: solid; border-color: var(--accent); }
.tray input { display: none; }
.tray:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 3px; }

.tray-gel { display: block; width: 100%; height: auto; border-radius: 10px; }
.tray-gel .slab { fill: #16282c; }
.tray-gel .well { fill: #0b1719; stroke: #33484d; stroke-width: 1; }
.tray-gel .lane { fill: #1c3237; }
.tray-gel .band { fill: #6fd3d9; opacity: 0.55; transition: opacity 0.25s; }
.tray.dragging .band, .tray:hover .band { opacity: 0.95; }
.tray.busy .band { opacity: 0.95; animation: run 1.6s ease-in infinite; }
.tray.busy .band:nth-child(3n+1) { animation-delay: -0.4s; }
.tray.busy .band:nth-child(3n+2) { animation-delay: -0.9s; }
@keyframes run {
  from { transform: translateY(-14px); opacity: 0; }
  60% { opacity: 0.95; }
  to { transform: translateY(0); opacity: 0.95; }
}

.dropzone-idle, .dropzone-busy { display: flex; flex-direction: column; gap: 4px; }
.dropzone-title { font-size: 1.12rem; font-weight: 600; }
.dropzone-title u { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.dropzone-hint { color: var(--muted); font-size: 0.88rem; }
.drop-area .error { margin: 12px 4px 0; }

.site-footer {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px 32px;
  color: var(--muted);
  font-size: 0.82rem;
}
.site-footer a { color: inherit; }

/* ---------- project page ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: ""; border: 4px solid transparent; border-top-color: currentColor; margin-top: 4px; }
.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 260px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
}
.menu-items a {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
}
.menu-items a:hover { background: var(--bg); }
.menu-items small { color: var(--muted); font-size: 0.8rem; }

.gel-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 20px 0;
  overflow-x: auto;
}
.gel-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 240px;
  padding: 6px 12px 6px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.gel-tab:hover { border-color: var(--border-strong); }
.gel-tab.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.gel-tab img { width: 44px; height: 34px; object-fit: cover; border-radius: 5px; background: #111; flex: none; }
.gel-tab-label { display: flex; flex-direction: column; min-width: 0; }
.gel-tab-name { font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gel-tab small { color: var(--muted); font-size: 0.78rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.2);
}
.toast.toast-ok { background: #1f2937; }

#workspace { padding: 16px 20px 48px; }
.load-error { color: var(--danger); }

.gel-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}
.gel-panel.working .stage { opacity: 0.55; pointer-events: none; transition: opacity 0.2s; }
.gel-main { min-width: 0; display: flex; flex-direction: column; gap: 10px; }

.summary-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.summary { margin: 0; font-size: 1.05rem; font-weight: 600; }
.gel-warning {
  margin: 0;
  padding: 2px 10px;
  border-radius: 6px;
  background: #fff7e6;
  color: #8a5a00;
  font-size: 0.85rem;
}

.hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #0a4f57;
  font-size: 0.9rem;
}

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.slider-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.82rem;
  color: var(--muted);
}
.slider-field input { width: 140px; accent-color: var(--accent); }
.legend { display: flex; align-items: center; gap: 6px; margin-left: auto; font-size: 0.82rem; color: var(--muted); }
.swatch { width: 18px; height: 10px; border-radius: 2px; border: 2px solid var(--sure); }
.swatch-unsure { border-color: var(--unsure); border-style: dashed; margin-left: 8px; }

.adjust-drawer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.88rem;
}
.adjust-drawer label { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.adjust-drawer input[type="number"] { width: 64px; padding: 4px 6px; font: inherit; border: 1px solid var(--border-strong); border-radius: 6px; }
.adjust-drawer input[type="range"] { width: 120px; accent-color: var(--accent); }
.drawer-actions { display: flex; gap: 6px; margin-left: auto; }
.drawer-note { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 0.8rem; }

.mode-hint {
  margin: 0;
  padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  font-size: 0.88rem;
}

.stage-wrap {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.stage { position: relative; width: fit-content; max-width: 100%; margin: 0 auto; }
.lane-header { position: relative; height: 30px; margin-bottom: 4px; }
.lane-slot { position: absolute; top: 0; bottom: 0; padding: 0 2px; }
.lane-name {
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  font: inherit;
  font-size: 0.78rem;
  text-align: center;
  text-overflow: ellipsis;
}
.lane-name::placeholder { color: #98a2b3; }
.lane-name:hover { border-color: var(--border-strong); }
.lane-name:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.lane-remove {
  position: absolute;
  top: -7px;
  right: -4px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  line-height: 18px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}
.lane-slot:hover .lane-remove, .lane-slot:focus-within .lane-remove, .lane-remove:focus-visible { opacity: 1; }
.lane-slot.is-ladder .lane-name { background: #fff7e6; border-color: #f3d19c; }

.editor-stage { position: relative; }
.gel-image {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 290px);
  min-height: 240px;
  user-select: none;
  transition: filter 0.1s;
}
.gel-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.gel-overlay.adding { cursor: copy; }
.gel-overlay.cropping { cursor: crosshair; }

.band-box {
  fill: rgba(34, 197, 94, 0.06);
  stroke: var(--sure);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  cursor: move;
}
.band-box.low-confidence { stroke: var(--unsure); stroke-dasharray: 5 3; fill: rgba(245, 158, 11, 0.06); }
.band-box:hover, .band-box.hovered { stroke-width: 2.5; fill: rgba(255, 255, 255, 0.12); }
.band-box.selected { stroke: #fff; stroke-width: 2.5; stroke-dasharray: none; fill: rgba(14, 116, 128, 0.18); }

.band-handle { fill: #fff; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; cursor: nwse-resize; }
.band-delete { cursor: pointer; }
.band-delete circle { fill: var(--danger); stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.band-delete text { fill: #fff; text-anchor: middle; dominant-baseline: central; font-weight: 700; pointer-events: none; }

.lane-divider { stroke: rgba(148, 163, 184, 0.55); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.lane-divider-hit { stroke: transparent; stroke-width: 12; vector-effect: non-scaling-stroke; cursor: ew-resize; }
.lane-divider-hit:hover { stroke: rgba(14, 116, 128, 0.35); }

.crop-rect {
  fill: rgba(14, 116, 128, 0.12);
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 5 3;
  vector-effect: non-scaling-stroke;
}

/* ---------- results panel ---------- */

.results {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 88px);
  overflow-y: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.results h2 { font-size: 1rem; }
.results-note { margin: 4px 0 12px; color: var(--muted); font-size: 0.8rem; }
.lanes-list { display: flex; flex-direction: column; gap: 10px; }

.lane-card { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lane-card-head { display: flex; align-items: baseline; gap: 8px; padding: 6px 10px; background: var(--bg); font-size: 0.85rem; }
.lane-num { font-weight: 600; flex: none; }
.lane-card-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lane-card-name.muted { color: #98a2b3; font-style: italic; }
.lane-count { color: var(--muted); font-size: 0.78rem; flex: none; }
.lane-card-remove {
  flex: none;
  padding: 0 4px;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0;
}
.lane-card:hover .lane-card-remove, .lane-card-remove:focus-visible { opacity: 1; }
.lane-card-remove:hover { color: var(--danger); text-decoration: underline; }

.band-rows { list-style: none; margin: 0; padding: 4px 0; }
.band-row {
  display: grid;
  grid-template-columns: 18px 1fr 48px 64px;
  align-items: center;
  gap: 8px;
  padding: 3px 10px;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.band-rows.with-kda .band-row { grid-template-columns: 18px 1fr 48px 60px 72px; }
.band-row:hover { background: var(--bg); }
.band-row.selected { background: var(--accent-soft); }
.band-idx { color: var(--muted); text-align: right; }
.bar { height: 6px; border-radius: 3px; background: #eef0f3; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--sure); border-radius: 3px; }
.band-row.unsure .bar i { background: var(--unsure); }
.band-pct { text-align: right; font-weight: 600; }
.band-int { text-align: right; color: var(--muted); }
.band-kda { text-align: right; color: var(--muted); }

.calibration { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; font-size: 0.88rem; }
.calibration summary { cursor: pointer; font-weight: 600; }
.optional { color: var(--muted); font-weight: 400; font-size: 0.8rem; margin-left: 4px; }
.calibration-hint { color: var(--muted); font-size: 0.82rem; }
.ladder-pick { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.ladder-pick select { flex: 1; padding: 5px; font: inherit; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); }
.ladder-bands { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px; margin-bottom: 10px; }
.ladder-band-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; color: var(--muted); font-size: 0.82rem; }
.ladder-band-row input { width: 72px; padding: 3px 6px; font: inherit; border: 1px solid var(--border-strong); border-radius: 6px; }

@media (max-width: 960px) {
  .gel-panel { grid-template-columns: 1fr; }
  .results { position: static; max-height: none; }
  .gel-image { max-height: none; }
}

@media (max-width: 860px) {
  .upload-page { grid-template-columns: 1fr; grid-template-areas: "intro" "drop" "details"; row-gap: 28px; padding-top: 32px; }
}

@media (max-width: 600px) {
  .site-header, .upload-page, .site-footer { padding-left: 16px; padding-right: 16px; }
  .topbar, .gel-tabs, #workspace { padding-left: 16px; padding-right: 16px; }
  .legend { margin-left: 0; }
  .slider-field input { width: 100px; }
  .hint { flex-direction: column; align-items: flex-start; }
}
