:root {
  --bg: #f6f7f9;
  --fg: #212529;
  --muted: #6c757d;
  --border: #dee2e6;
  --card: #fff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #7c3aed;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--fg); line-height: 1.5; }
.container { max-width: 72rem; margin: 0 auto; padding: 0 1rem; }

header { background: linear-gradient(135deg, #1e3a8a, #7c3aed); color: white; padding: 2rem 0 1.5rem; }
header h1 { margin: 0; font-size: 2.2rem; letter-spacing: -0.02em; }
header p { margin: 0.25rem 0 1rem; opacity: 0.9; font-size: 1.1rem; }
header nav { display: flex; gap: 1.5rem; }
header nav a { color: white; text-decoration: none; opacity: 0.85; }
header nav a:hover { opacity: 1; text-decoration: underline; }

.status-bar { padding: 0.75rem 1rem; border-radius: var(--radius); margin: 1.5rem 0; background: #e0f2fe; color: #075985; }
.status-bar:empty { display: none; }
.status-bar.error { background: #fee2e2; color: #991b1b; }
.status-bar.success { background: #dcfce7; color: #166534; }

.step { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.04); overflow: hidden; }
.step-header { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 1.25rem; background: #f8fafc; border-bottom: 1px solid var(--border); }
.step-header h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.step-num { display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; border-radius: 50%; background: var(--primary); color: white; font-weight: 700; font-size: 0.9rem; }
.step-status { font-size: 0.8rem; padding: 0.2rem 0.6rem; border-radius: 1rem; background: #e2e8f0; color: #475569; }
.step-status.done { background: #dcfce7; color: #166534; }
.step-status.running { background: #fef3c7; color: #92400e; }
.step-body { padding: 1.25rem; }

.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tabs button { padding: 0.6rem 1rem; border: none; background: transparent; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-panel { padding: 0.5rem 0; }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2.5rem; text-align: center; cursor: pointer; transition: all 0.2s; }
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: #eff6ff; }
.dropzone input { display: none; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.5rem; }

textarea, pre.preview { width: 100%; min-height: 10rem; font-family: var(--mono); font-size: 0.85rem; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; background: #f8fafc; resize: vertical; }
pre.preview { max-height: 16rem; overflow: auto; white-space: pre; margin: 0.75rem 0 0; }

.row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; margin-bottom: 0.75rem; }
.row label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.row input[type="text"], .row input[type="number"], .row select { padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: 0.9rem; color: var(--fg); background: white; }
.row input[type="range"] { width: 8rem; }
.label-value { font-family: var(--mono); font-size: 0.85rem; color: var(--fg); }

.checkbox { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; margin-bottom: 0.75rem; }

/* Any enabled .btn is an actionable control, so make it blue. Disabled
   controls (e.g. Build tree before an alignment exists) stay neutral gray. */
.btn { padding: 0.55rem 1.1rem; font: inherit; font-size: 0.9rem; border: 1px solid var(--primary); background: var(--primary); border-radius: 6px; cursor: pointer; color: white; font-weight: 600; }
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.primary { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.primary:hover { background: #1e40af; border-color: #1e40af; }
.btn:disabled { background: #e2e8f0; border-color: var(--border); color: #64748b; opacity: 0.75; cursor: not-allowed; font-weight: 400; }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

.sequence-summary { margin-top: 1rem; padding: 0.75rem; background: #f0fdf4; border-radius: 6px; font-size: 0.9rem; color: #166534; }
.sequence-summary:empty { display: none; }

.stats { display: flex; gap: 2rem; padding: 0.75rem 1rem; background: #f8fafc; border-radius: 6px; margin-top: 0.75rem; font-size: 0.9rem; }
.stat { display: flex; flex-direction: column; }
.stat-label { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-weight: 700; font-family: var(--mono); font-size: 1.1rem; }

.newick { width: 100%; background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; padding: 1rem; font-family: var(--mono); font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; max-height: 10rem; overflow: auto; }
#tree-svg { height: auto; border: 1px solid var(--border); border-radius: 6px; background: white; margin-top: 0.75rem; min-height: 200px; }

.metadata-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.metadata-table th, .metadata-table td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.metadata-table th { background: #f8fafc; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.metadata-table td { font-family: var(--mono); }
.metadata-table td:first-child { font-family: inherit; font-weight: 600; }

footer { padding: 2rem 1rem; color: var(--muted); font-size: 0.85rem; text-align: center; }
footer a { color: var(--primary); }

/* Hit selection table */
.hit-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; margin-top: 0.5rem; }
.hit-table th, .hit-table td { padding: 0.35rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border); }
.hit-table th { background: #f8fafc; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); position: sticky; top: 0; }
.hit-table td { font-family: var(--mono); }
.hit-table td:first-child { text-align: center; }
.hit-table tbody tr:hover { background: #f1f5f9; }
.hit-table tbody tr.filtered-out { opacity: 0.35; }
#hit-results { max-height: 22rem; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.hit-footer { padding: 0.5rem; align-items: center; }

/* Runtime timing strip */
.timing-strip { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.5rem 0.75rem; margin-bottom: 1rem;
  background: #f1f5f9; border: 1px solid var(--border); border-radius: 6px; font-size: 0.78rem; color: var(--muted); }
.timing-strip:empty { display: none; }
.timing-strip .timing-item { font-family: var(--mono); }
.timing-strip .timing-item strong { color: var(--fg); }

/* Inline step errors + always-visible debug log */
.error-box {
  margin-top: 0.75rem; padding: 0.75rem 1rem; border-radius: 6px;
  background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
  font-family: var(--mono); font-size: 0.8rem; white-space: pre-wrap; word-break: break-word;
}
.debug-panel {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 100;
  width: min(32rem, calc(100vw - 2rem)); max-height: 16rem;
  display: flex; flex-direction: column;
  background: #0f172aee; color: #e2e8f0; border: 1px solid #334155; border-radius: 8px;
  box-shadow: 0 8px 24px #0006; font-size: 0.72rem;
}
.debug-panel.collapsed { height: auto; max-height: none; }
.debug-panel.collapsed pre { display: none; }
.debug-header {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.4rem 0.6rem; border-bottom: 1px solid #334155;
}
.debug-header .hint { color: #94a3b8; flex: 1; }
.debug-header .btn.small { padding: 0.15rem 0.45rem; font-size: 0.68rem; }
.debug-panel pre {
  margin: 0; padding: 0.5rem 0.6rem; overflow: auto; flex: 1;
  font-family: var(--mono); line-height: 1.45; white-space: pre-wrap; word-break: break-word;
}

.hidden { display: none !important; }

@media (max-width: 640px) {
  .row { flex-direction: column; align-items: stretch; }
  .row label { width: 100%; }
  .row input, .row select { width: 100%; }
  header h1 { font-size: 1.6rem; }
}

/* ---- Sticky step tracker ------------------------------------------------ */
.stepper { position: sticky; top: 0; z-index: 50; display: flex; gap: 0.25rem; margin: 1rem 0 0;
  padding: 0.5rem; background: #ffffffee; backdrop-filter: blur(6px); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 2px 8px #0f172a0d; overflow-x: auto; }
.stepper a { flex: 1; min-width: 7.5rem; display: grid; grid-template-columns: auto 1fr; column-gap: 0.5rem;
  align-items: center; padding: 0.35rem 0.6rem; border-radius: 8px; color: var(--fg); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.stepper a:hover { background: #f1f5f9; }
.stepper .dot { grid-row: span 2; display: inline-flex; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  align-items: center; justify-content: center; background: #e2e8f0; color: #475569; font-size: 0.8rem; }
.stepper small { font-weight: 400; color: var(--muted); font-size: 0.72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper a.done .dot { background: var(--success); color: white; }
.stepper a.running .dot { background: #f59e0b; color: white; animation: pulse 1.2s ease-in-out infinite; }
.stepper a.error .dot { background: var(--danger); color: white; }
.stepper a.error small { color: var(--danger); }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px #f59e0b33; } }

.step-status.error { background: #fee2e2; color: #991b1b; }
.step-status.running::before { content: ''; display: inline-block; width: 0.6em; height: 0.6em; margin-right: 0.35em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -0.05em; }
@keyframes spin { to { transform: rotate(360deg); } }
.step { scroll-margin-top: 5rem; }

/* ---- Buttons ------------------------------------------------------------ */
.btn.ghost { background: white; color: var(--primary); border-color: #bfdbfe; }
.btn.ghost:hover { background: #eff6ff; border-color: var(--primary); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #b91c1c; border-color: #b91c1c; }
.checkbox.inline { display: inline-flex; margin: 0; font-size: 0.85rem; }
.running-timer { font-family: var(--mono); align-self: center; }
.badge { display: inline-block; min-width: 1.3rem; padding: 0 0.35rem; border-radius: 1rem; background: var(--danger);
  color: white; font-size: 0.68rem; text-align: center; }

/* ---- Alignment viewer --------------------------------------------------- */
.msa-view { margin-top: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); background: #fcfcfd; }
.msa-note { padding: 0.4rem 0.75rem; font-size: 0.78rem; color: var(--muted); border-bottom: 1px solid var(--border); }
.msa-scroll { overflow: auto; max-height: 20rem; }
.msa { font-family: var(--mono); font-size: 0.75rem; line-height: 1.25; padding: 0.4rem 0; width: max-content; }
.msa-row { display: flex; white-space: pre; }
.msa-name { position: sticky; left: 0; flex: 0 0 11rem; padding: 0 0.6rem; overflow: hidden; text-overflow: ellipsis;
  background: #fcfcfd; color: #334155; border-right: 1px solid var(--border); margin-right: 0.4rem; }
.msa-ruler { color: #94a3b8; }
.r-hyd { background: #dbeafe; } .r-pos { background: #fecaca; } .r-neg { background: #f5d0fe; }
.r-pol { background: #bbf7d0; } .r-gly { background: #fed7aa; } .r-pro { background: #fef08a; } .r-aro { background: #a5f3fc; }
.r-nA { background: #bbf7d0; } .r-nC { background: #bfdbfe; } .r-nG { background: #fde68a; } .r-nT { background: #fecaca; }

/* ---- Tree viewer -------------------------------------------------------- */
.tree-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; padding: 0.6rem 0.75rem;
  background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.tree-toolbar input[type="search"] { padding: 0.35rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: 0.85rem; width: 11rem; }
.tree-toolbar .spacer { flex: 1; }
.tree-scroll { overflow: auto; max-height: 75vh; border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); background: white; }
.tree-scroll #tree-svg { display: block; border: none; border-radius: 0; margin: 0; max-width: none; }
.newick-details { margin-top: 0.75rem; }
.newick-details summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; }

@media (max-width: 640px) {
  .stepper a { min-width: 5.5rem; font-size: 0.8rem; }
  .msa-name { flex-basis: 6rem; }
}

/* ---- Reference proteome search set ------------------------------------- */
.proteome-set-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem; margin-bottom: 0.75rem; background: #f8fafc; }
.proteome-set-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.proteome-set-head .hint { margin: 0; }
.proteome-set-head .spacer { flex: 1; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 0; padding: 0; }
.chips:empty { display: none; }
.chips li { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.2rem 0.3rem 0.2rem 0.65rem; border-radius: 1rem;
  background: white; border: 1px solid #bfdbfe; font-size: 0.8rem; }
.chips li small { color: var(--muted); font-family: var(--mono); }
.chips button { border: none; background: #e2e8f0; color: #475569; width: 1.3rem; height: 1.3rem; border-radius: 50%; cursor: pointer; line-height: 1; font-size: 0.85rem; }
.chips button:hover { background: var(--danger); color: white; }
.hint.warn { color: #b45309; }

/* Grouped BLAST hits: one row per protein, HSPs nested underneath */
.hit-table tr.hsp-row td { background: #f8fafc; color: var(--muted); font-size: 0.76rem; border-bottom-style: dashed; }
.hit-table tr.hsp-row td:nth-child(2) { padding-left: 1.4rem; }
.hsp-toggle { margin-left: 0.4rem; padding: 0.05rem 0.4rem; font: inherit; font-size: 0.7rem; border: 1px solid var(--border); border-radius: 999px; background: #eef2ff; color: #3730a3; cursor: pointer; }
.hsp-toggle:hover { background: #e0e7ff; }
.hsp-only { margin-left: 0.3rem; padding: 0 0.35rem; border-radius: 999px; font-size: 0.68rem; background: #fef3c7; color: #92400e; }

/* Tree annotation toolbar, legend, popup, export menu */
.tree-toolbar-2 { border-top: 1px dashed var(--border); border-radius: 0; }
.tree-toolbar label select { margin-left: 0.3rem; }
.tree-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.9rem; padding: 0.5rem 0.75rem;
  border: 1px solid var(--border); border-top: none; background: #fcfcfd; font-size: 0.8rem; }
.tree-legend strong { text-transform: capitalize; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.03em; }
.tree-legend .lg-item { display: inline-flex; align-items: center; gap: 0.3rem; }
.tree-legend .lg-item i { width: 0.8rem; height: 0.8rem; border-radius: 3px; display: inline-block; }
.tree-legend .lg-item small { color: var(--muted); }
.tree-legend .lg-note { color: var(--muted); font-style: italic; }
.tree-legend i.lg-dup { background: #dc2626; border-radius: 1px; }
.tree-legend i.lg-spec { background: #2563eb; border-radius: 50%; }
.tree-scroll { position: relative; }
.tree-popup { position: absolute; z-index: 5; width: min(24rem, calc(100% - 16px)); max-height: 26rem; overflow: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 0.9rem;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18); font-size: 0.84rem; line-height: 1.4; }
.popup-close { position: absolute; top: 0.3rem; right: 0.4rem; border: none; background: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); }
.pop-title { font-weight: 600; padding-right: 1.2rem; }
.pop-sub { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; word-break: break-all; }
.pop-species { margin-top: 0.35rem; }
.pop-lineage { margin-top: 0.2rem; font-size: 0.75rem; color: var(--muted); }
.pop-sec { margin-top: 0.6rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.pop-domains { display: block; max-width: 100%; height: auto; margin-top: 0.2rem; }
.pop-domlist { display: flex; flex-direction: column; gap: 0.1rem; font-size: 0.76rem; }
.pop-domlist i { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 2px; margin-right: 0.35rem; vertical-align: -1px; }
.pop-func { font-size: 0.78rem; }
.pop-foot { margin-top: 0.6rem; font-size: 0.72rem; color: var(--muted); }
.pop-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.export-menu { position: relative; }
.export-menu > summary { list-style: none; cursor: pointer; }
.export-menu > summary::-webkit-details-marker { display: none; }
.export-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 6; display: flex; flex-direction: column; align-items: stretch;
  min-width: 16rem; padding: 0.35rem; background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15); }
.export-list .btn { text-align: left; }
#tv-outgroup { max-width: 16rem; }

/* Tree step: load a tree / hand-off to IQ-TREE & RAxML-NG */
.tree-extra { align-items: flex-start; gap: 0.5rem 1rem; margin-top: 0.25rem; }
.file-btn { cursor: pointer; }
.handoff > summary { list-style: none; cursor: pointer; display: inline-block; }
.handoff > summary::-webkit-details-marker { display: none; }
.handoff[open] > summary { background: #eef2ff; }
.handoff-body { margin-top: 0.5rem; padding: 0.6rem 0.8rem; border: 1px solid var(--border); border-radius: 8px; background: #fcfcfd; max-width: 48rem; }
.handoff-body .row { gap: 0.5rem 1rem; align-items: center; }

/* Version badge in the header */
.version-badge { display: inline-block; vertical-align: middle; margin-left: 0.5rem; padding: 0.1rem 0.55rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0; color: #fff; background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.35); text-decoration: none; }
.version-badge:hover { background: rgba(255,255,255,0.28); }
