:root {
  --bg: #f6f4ee;
  --surface: #fdfcf8;
  --ink: #1d211e;
  --muted: #5c645e;
  --line: #d9d6cb;
  --faint: #ebe8df;
  --accent: #2f5d46;
  --accent-ink: #ffffff;
  --term-bg: #1b201c;
  --term-ink: #d8e2d9;
  --term-dim: #8a978d;
  --match: #2f7d55;
  --sub: #c07a12;
  --ins: #2f6fb0;
  --del: #b8433a;
  --path: #d0461e;
  --ramp-0: #dcebe1;
  --ramp-1: #2f5d46;
  --serif: "Newsreader", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151916;
    --surface: #1c211d;
    --ink: #e9ebe5;
    --muted: #a0a89f;
    --line: #333a34;
    --faint: #252b26;
    --accent: #8fc7a6;
    --accent-ink: #12261b;
    --term-bg: #0f1310;
    --match: #6cc595;
    --sub: #e3a54a;
    --ins: #73a9e0;
    --del: #e5796f;
    --path: #ff8a5c;
    --ramp-0: #26382d;
    --ramp-1: #a6dcbc;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.6 var(--sans);
}

a { color: var(--accent); text-underline-offset: 0.18em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, p, ul, dl, dd { margin: 0; }
code { font: 500 0.92em var(--mono); }

.top, main, .foot { width: min(74rem, 100% - 2rem); margin-inline: auto; }

.top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 1.5rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9375rem;
}
.brand { color: var(--ink); text-decoration: none; font-weight: 600; }
.top nav { display: flex; gap: 1.25rem; align-items: center; }
.top nav a { color: var(--muted); text-decoration: none; }
.top nav a:hover { color: var(--accent); }
.lang-toggle {
  font: 600 0.8125rem var(--mono);
  color: var(--ink);
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
}

main { display: grid; gap: 1.25rem; padding: 2.25rem 0 2rem; }

.intro { max-width: 46rem; padding-bottom: 0.5rem; }
.eyebrow { color: var(--muted); font-size: 0.875rem; letter-spacing: 0.02em; }
h1 {
  font: 500 clamp(1.9rem, 4vw, 2.75rem)/1.12 var(--serif);
  margin: 0.4rem 0 0.8rem;
  letter-spacing: -0.01em;
}
.lede { color: var(--muted); font-size: 1.0625rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.1rem 1.25rem 1.25rem;
  min-width: 0;
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-bottom: 0.9rem;
}
h2 { font: 600 1rem var(--sans); }
.num {
  display: inline-grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  margin-right: 0.3rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 0.75rem var(--mono);
  vertical-align: 0.1em;
}
.meta { color: var(--muted); font-size: 0.875rem; }

/* input */
.input-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; }
.field-col { display: grid; grid-template-columns: 9.5rem auto; justify-content: start; gap: 0.75rem; align-content: start; }
.field-col .field:first-child { grid-column: 1 / -1; }
.field { display: grid; gap: 0.3rem; font-size: 0.875rem; color: var(--muted); }
.field small { font-size: 0.8125rem; }
textarea, input[type="text"], input[type="number"], select {
  font: 500 0.9375rem var(--mono);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  width: 100%;
  letter-spacing: 0.04em;
}
textarea { resize: vertical; min-height: 6.5rem; }
.preset { display: flex; gap: 0.5rem; align-items: center; font-size: 0.875rem; color: var(--muted); }
.preset select { width: auto; font: 500 0.875rem var(--sans); letter-spacing: 0; }
#run { align-self: end; }
.error { margin-top: 0.75rem; color: var(--del); font-size: 0.875rem; }

.button {
  font: 600 0.875rem var(--sans);
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.5rem 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}
.button.ghost { color: var(--ink); background: transparent; border-color: var(--line); }
.button:hover { filter: brightness(1.08); }
.button:disabled { opacity: 0.45; cursor: default; filter: none; }

/* player */
.player {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.speed { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; font-size: 0.875rem; color: var(--muted); }
.speed input { accent-color: var(--accent); width: 8rem; }
.speed output { font: 500 0.8125rem var(--mono); min-width: 2.5rem; color: var(--ink); }
.stages { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0; margin: 0; list-style: none; counter-reset: st; }
.stages li {
  counter-increment: st;
  font-size: 0.8125rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.7rem 0.1rem 0.45rem;
}
.stages li::before { content: counter(st) " "; font: 600 0.75rem var(--mono); opacity: 0.7; }
.stages li.done { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.stages li.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.caption { font-size: 0.9375rem; min-height: 1.6em; }
.caption code { color: var(--accent); }

/* graph + terminal */
.stage-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 1.25rem; }
.reads-view { display: grid; gap: 0.2rem; margin-bottom: 0.5rem; font: 500 0.9375rem var(--mono); letter-spacing: 0.12em; }
.reads-view .read { white-space: nowrap; overflow-x: auto; color: var(--muted); }
.reads-view .read b { font-weight: 500; }
.reads-view .read .win { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--ink); border-radius: 2px; }
.reads-view .lbl { font: 400 0.75rem var(--sans); letter-spacing: 0; margin-right: 0.6rem; }

.dbg { width: 100%; height: auto; display: block; overflow: visible; }
.dbg .edge { fill: none; stroke: var(--line); stroke-width: 1.6; transition: stroke 0.25s, opacity 0.3s; }
.dbg .edge.on { stroke: var(--muted); }
.dbg .edge.walk { stroke: var(--path); stroke-width: 2.6; }
.dbg .node rect { fill: var(--surface); stroke: var(--muted); stroke-width: 1.3; transition: fill 0.25s, stroke 0.25s; }
.dbg .node text { font: 600 13px var(--mono); fill: var(--ink); text-anchor: middle; dominant-baseline: central; letter-spacing: 0.06em; }
.dbg .node.flash rect { fill: color-mix(in srgb, var(--accent) 30%, var(--surface)); stroke: var(--accent); }
.dbg .node.walk rect { stroke: var(--path); stroke-width: 2.2; }
.dbg .node.current rect { fill: var(--path); stroke: var(--path); }
.dbg .node.current text { fill: #fff; }
.dbg .node .order { font: 500 10px var(--mono); fill: var(--path); }
.dbg .hidden { opacity: 0; }
.dbg .appear { animation: pop 0.35s ease-out; }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
.dbg .node { transform-box: fill-box; transform-origin: center; }

.terminal-panel { display: flex; flex-direction: column; }
.terminal {
  flex: 1;
  margin: 0;
  min-height: 14rem;
  max-height: 22rem;
  overflow: auto;
  padding: 0.85rem 1rem;
  background: var(--term-bg);
  color: var(--term-ink);
  border-radius: 8px;
  font: 400 0.8125rem/1.55 var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
}
.terminal .prompt { color: #8fc7a6; }
.terminal .dim { color: var(--term-dim); }
.terminal .hl { color: #ffd38a; }
.terminal .cursor { display: inline-block; width: 0.55em; height: 1.1em; background: var(--term-ink); vertical-align: -0.2em; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; margin-top: 0.9rem; }
.stats div { border-top: 1px solid var(--line); padding-top: 0.35rem; }
.stats dt { font-size: 0.75rem; color: var(--muted); }
.stats dd { font: 600 1.05rem var(--mono); font-variant-numeric: tabular-nums; }

/* multilayer grid */
.ml-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; font-size: 0.8125rem; color: var(--muted); margin-bottom: 0.6rem; align-items: center; }
.ml-legend > span { display: inline-flex; align-items: center; gap: 0.35rem; }
.ramp { display: inline-block; width: 5rem; height: 0.7rem; border-radius: 3px; background: linear-gradient(90deg, var(--ramp-0), var(--ramp-1)); }
.sw { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 3px; }
.sw-match { background: var(--match); }
.sw-sub { background: var(--sub); }
.sw-ins { background: var(--ins); }
.sw-del { background: var(--del); }
.ml-wrap { overflow-x: auto; padding-bottom: 0.25rem; }
.ml { display: block; }
.ml .cell { fill: transparent; stroke: var(--faint); stroke-width: 1; transition: fill 0.2s; }
.ml .row-hidden { opacity: 0; }
.ml .row-in { animation: fade 0.3s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.ml .dist { font: 500 9px var(--mono); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.ml .head-base { font: 600 11px var(--mono); fill: var(--muted); text-anchor: middle; }
.ml .head-kmer { font: 500 10px var(--mono); fill: var(--muted); text-anchor: middle; letter-spacing: 0.04em; }
.ml .head-kmer.walk { fill: var(--path); font-weight: 600; }
.ml .bracket { stroke: var(--line); stroke-width: 1; fill: none; }
.ml .row-label { font: 600 12px var(--mono); fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.ml .row-idx { font: 400 9px var(--mono); fill: var(--muted); text-anchor: end; dominant-baseline: central; }
.ml .row-label.cur { fill: var(--path); }
.ml .start-mark { fill: var(--muted); }
.ml .endpoint circle { fill: var(--surface); stroke: var(--muted); stroke-width: 1.3; }
.ml .endpoint text { font: 600 10px var(--mono); fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.ml .endpoint.done circle { fill: var(--path); stroke: var(--path); }
.ml .endpoint.done text { fill: #fff; }
.ml .latest { fill: none; stroke: var(--path); stroke-width: 2; }
.ml .path-line { fill: none; stroke: var(--path); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.ml .path-dot { stroke: var(--surface); stroke-width: 1.5; }
.ml .dummy-col { fill: var(--faint); opacity: 0.6; }

.explain { margin-top: 0.9rem; font-size: 0.9375rem; color: var(--muted); }
.explain summary { cursor: pointer; color: var(--ink); font-weight: 500; }
.explain div { display: grid; gap: 0.5rem; margin-top: 0.6rem; max-width: 52rem; }
.explain ul { padding-left: 1.2rem; list-style: disc; }
.t-sub { color: var(--sub); }
.t-del { color: var(--del); }
.t-ins { color: var(--ins); }

/* result */
.cost { font-size: 0.875rem; color: var(--muted); }
.cost strong { font: 600 1.6rem var(--mono); color: var(--path); margin-left: 0.3rem; vertical-align: -0.1em; }
.align-wrap { overflow-x: auto; }
.align { display: inline-grid; grid-auto-flow: column; grid-template-rows: auto auto auto; gap: 2px 3px; font: 600 1.05rem var(--mono); padding-bottom: 0.3rem; min-height: 6.5rem; }
.align .lab { font: 500 0.75rem var(--sans); color: var(--muted); align-self: center; padding-right: 0.6rem; white-space: nowrap; }
.align .c { width: 1.7rem; height: 1.8rem; display: grid; place-items: center; border-radius: 4px; }
.align .c.gap { color: var(--muted); }
.align .mark { font-size: 0.75rem; height: 1.2rem; }
.align .op-match.g { background: color-mix(in srgb, var(--match) 16%, transparent); }
.align .op-sub { background: color-mix(in srgb, var(--sub) 26%, transparent); }
.align .op-ins { background: color-mix(in srgb, var(--ins) 24%, transparent); }
.align .op-del { background: color-mix(in srgb, var(--del) 24%, transparent); }
.align .mark.op-match, .align .mark.op-sub, .align .mark.op-ins, .align .mark.op-del { background: none; }
.align .mark.op-match { color: var(--match); }
.align .mark.op-sub { color: var(--sub); }
.align .mark.op-ins { color: var(--ins); }
.align .mark.op-del { color: var(--del); }
.align .k { font: 500 0.625rem var(--mono); color: var(--muted); height: 1rem; }
.align .new { animation: fade 0.3s ease-out; }
.walk { margin-top: 0.8rem; font-size: 0.9375rem; color: var(--muted); }
.walk code { color: var(--path); }

.foot { padding: 1.25rem 0 2.5rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.875rem; }

@media (max-width: 860px) {
  .stage-grid, .input-grid { grid-template-columns: 1fr; }
  .speed { margin-left: 0; }
  .player { position: static; }
}

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