/* Taxonova web app. Colour tokens first; light and dark are both chosen. */
:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --border: #dddcd6;
  --border-strong: #c5c4bd;
  --text: #161615;
  --text-2: #4d4c48;
  --muted: #6b6a64;
  --accent: #1f5fbf;
  --accent-hover: #184c99;
  --accent-soft: #e8f0fb;
  --on-accent: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn-soft: #fff6e0;
  --warn-border: #e8c766;
  --focus: #1f5fbf;
  --shadow: 0 1px 2px rgba(20, 20, 18, 0.06), 0 1px 1px rgba(20, 20, 18, 0.03);
  /* Chart series. Checked under simulated deuteranopia, protanopia and
     tritanopia (Machado 2009): every pair, including against Other and
     Unclassified, differs by CIELAB delta E of 11 or more. Other is also
     hatched, so it never relies on colour alone. No name (labelled Unknown:
     no name in the reference) is a solid grey, darker than Other in the
     light theme and lighter in the dark ones. */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #c43d7a; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --s-other: #bdbcb5; --s-unclassified: #e2e1db; --s-noname: #85847b; --hatch: rgba(255, 255, 255, 0.75);
  --grid: #e7e6e1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1b1b1a; --surface-2: #242422; --border: #33332f; --border-strong: #46463f;
    --text: #f0efec; --text-2: #c9c8be; --muted: #a3a298; --accent: #6aa5f2; --accent-hover: #8dbaf5;
    --accent-soft: #1d2b3f; --on-accent: #0b0b0b; --danger: #f2877d; --danger-soft: #3a1d1a;
    --warn-soft: #33290f; --warn-border: #7a6420; --focus: #8dbaf5; --shadow: none;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #e0609a; --s6: #008300; --s7: #b9aef7; --s8: #e66767;
    --s-other: #5f5e58; --s-unclassified: #34342f; --s-noname: #9e9d94; --hatch: rgba(0, 0, 0, 0.45); --grid: #2c2c29;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1b1b1a; --surface-2: #242422; --border: #33332f; --border-strong: #46463f;
  --text: #f0efec; --text-2: #c9c8be; --muted: #a3a298; --accent: #6aa5f2; --accent-hover: #8dbaf5;
  --accent-soft: #1d2b3f; --on-accent: #0b0b0b; --danger: #f2877d; --danger-soft: #3a1d1a;
  --warn-soft: #33290f; --warn-border: #7a6420; --focus: #8dbaf5; --shadow: none;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #e0609a; --s6: #008300; --s7: #b9aef7; --s8: #e66767;
  --s-other: #5f5e58; --s-unclassified: #34342f; --s-noname: #9e9d94; --hatch: rgba(0, 0, 0, 0.45); --grid: #2c2c29;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  display: flex; flex-direction: column; min-height: 100vh;
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 16px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 21px; }
h3 { font-size: 15px; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a { color: var(--text-2); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: 14px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.icon-btn { background: none; border: 1px solid transparent; color: var(--text-2); width: 34px; height: 34px; border-radius: 6px; cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }

/* intro */
.intro { padding: 32px 0 20px; }
.lede { margin: 8px 0 0; color: var(--text-2); font-size: 16px; max-width: 70ch; }

/* cards and form */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.input-card { padding: 20px; }
.input-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; }
.label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.label-sm { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }
.optional { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 4px; }
.field { margin-bottom: 18px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.field-actions { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.sep { width: 1px; height: 14px; background: var(--border-strong); }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.hint .suggest { color: var(--text-2); }
.form-error { margin: 10px 0 0; padding: 8px 10px; border-radius: 6px; background: var(--danger-soft); color: var(--danger); font-size: 14px; }

.dropzone { position: relative; }
textarea {
  width: 100%; min-height: 260px; resize: vertical; padding: 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 13px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
textarea::placeholder { color: var(--muted); }
textarea:disabled { background: var(--surface-2); color: var(--muted); }
.drop-overlay { display: none; position: absolute; inset: 0; border: 2px dashed var(--accent); border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 600; place-items: center; }
.dropzone.dragging .drop-overlay { display: grid; }
.file-chip { position: absolute; left: 12px; right: 12px; top: 12px; display: flex; align-items: center; gap: 8px; background: var(--accent-soft); color: var(--text); padding: 8px 10px; border-radius: 6px; font-size: 14px; }
.file-chip.small { position: static; padding: 4px 8px; font-size: 13px; }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chip-x { background: none; border: 0; color: var(--text-2); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px; border-radius: 4px; }
.counts-box { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

select, input[type="search"], input[type="number"] {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 6px; padding: 7px 8px;
}
#reference, #model { width: 100%; }
.btn-primary {
  width: 100%; font: inherit; font-weight: 600; font-size: 15px; padding: 11px 16px; border-radius: 8px; border: 0;
  background: var(--accent); color: var(--on-accent); cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }
.btn-secondary {
  font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-secondary:disabled { opacity: 0.5; cursor: default; }
.btn-link { font: inherit; font-size: 14px; background: none; border: 0; padding: 2px 0; color: var(--accent); cursor: pointer; }
.btn-link:hover { color: var(--accent-hover); text-decoration: underline; }
.file-label { cursor: pointer; }
.file-label:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

.advanced { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 10px 0; margin-bottom: 18px; }
.advanced summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.adv-body { padding-top: 10px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.gates { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.gates th { text-align: left; font-weight: 600; }
.gates td { padding: 2px 0; }
.gates td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.gates input { width: 72px; padding: 2px 6px; font-size: 13px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.tmode { border: 0; margin: 0 0 4px; padding: 0; display: grid; gap: 6px; }
.tmode .check { align-items: flex-start; line-height: 1.35; }
.tmode input { margin-top: 2px; }

/* progress */
.progress-card { padding: 16px 20px; margin-top: 16px; }
.progress-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }

/* results */
#results { margin-top: 28px; }
#main { width: 100%; padding-bottom: 48px; }
.results-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 12px; }
.results-head p { margin: 0; font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.stat .p { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.warnings { list-style: none; margin: 0 0 16px; padding: 10px 14px; background: var(--warn-soft); border: 1px solid var(--warn-border); border-radius: 8px; font-size: 14px; }
.warnings li + li { margin-top: 4px; }

.downloads { padding: 16px 20px; margin-bottom: 16px; }
.dl-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.dl { display: inline-flex; flex-direction: column; text-decoration: none; color: var(--text); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 12px; min-width: 180px; }
.dl:hover { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.dl b { font-size: 14px; font-weight: 600; }
.dl span { font-size: 12px; color: var(--muted); }
.snippets { margin-top: 14px; }
.snippets summary { cursor: pointer; font-size: 14px; color: var(--text-2); }
.code { margin: 8px 0 0; padding: 12px; background: var(--surface-2); border-radius: 8px; overflow-x: auto; font: 12.5px/1.5 ui-monospace, Menlo, Consolas, monospace; }
.copy-btn { margin-left: auto; }

.viz { padding: 0 0 12px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 12px; overflow-x: auto; }
.tabs.small { padding: 0; margin-top: 10px; align-items: center; }
.tab { font: inherit; font-size: 14px; background: none; border: 0; border-bottom: 2px solid transparent; padding: 12px 12px 10px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tabs.small .tab { padding: 6px 10px; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab:hover { color: var(--text); }
.panel { padding: 12px 20px 0; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; font-size: 14px; color: var(--text-2); }
.controls label { display: inline-flex; align-items: center; gap: 6px; }
.grow { flex: 1; }
.exports { display: inline-flex; gap: 10px; align-items: baseline; font-size: 13px; color: var(--muted); white-space: nowrap; }
.caption { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.caption-inline { font-size: 13px; color: var(--muted); }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0 0; padding: 0; font-size: 12px; color: var(--text-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.chart { width: 100%; height: 440px; margin-top: 4px; }
.chart.tall { height: 560px; }

.table-wrap { overflow: auto; max-height: 70vh; margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; }
.results-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.results-table th, .results-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
.results-table th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.results-table th:first-child, .results-table td:first-child { position: sticky; left: 0; background: var(--surface); box-shadow: 1px 0 0 var(--border); }
.results-table th:first-child { z-index: 2; background: var(--surface-2); }
.results-table tbody tr:hover td:first-child { background: var(--surface-2); }
.results-table th button { font: inherit; background: none; border: 0; color: inherit; cursor: pointer; padding: 0; display: inline-flex; gap: 4px; align-items: center; }
.results-table th[aria-sort="ascending"] button::after { content: "\2191"; }
.results-table th[aria-sort="descending"] button::after { content: "\2193"; }
.results-table tbody tr:hover { background: var(--surface-2); }
.results-table td.id { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; max-width: 220px; overflow-wrap: anywhere; }
.results-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.results-table .conf { margin-left: 6px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.results-table td.taxon { white-space: normal; min-width: 120px; max-width: 280px; }
.results-table td.lineage { white-space: normal; min-width: 240px; color: var(--text-2); font-size: 12px; }
.results-table .na { color: var(--muted); }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); margin-left: 4px; font-family: system-ui, sans-serif; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 12px 0 4px; font-size: 14px; }

/* footer */
.footer { margin-top: auto; border-top: 1px solid var(--border); border-top: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--text-2); }
.footer-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; padding-top: 20px; padding-bottom: 24px; }
.footer p { margin: 0 0 6px; }
.footer-meta { text-align: right; }

@media (max-width: 860px) {
  .input-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .footer-grid { grid-template-columns: 1fr; }
  .footer-meta { text-align: left; }
}
@media (max-width: 560px) {
  h1 { font-size: 23px; }
  .intro { padding: 22px 0 14px; }
  .input-card { padding: 14px; }
  .nav a { padding: 6px 6px; font-size: 13px; }
  .brand span { font-size: 16px; }
  .panel { padding: 10px 12px 0; }
  .chart { height: 380px; }
  .chart.tall { height: 400px; }
  .stat .v { font-size: 22px; }
  .dl { min-width: 0; flex: 1 1 100%; }
  .tabs { padding: 0 4px; }
  .results-table th, .results-table td { padding: 6px 8px; }
  .results-table td.taxon { min-width: 0; max-width: 140px; }
  .results-table td.id { max-width: 96px; }
  .tab { padding: 10px 8px 8px; font-size: 13px; }
  textarea { min-height: 150px; }
  .opt-col .hint { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { .bar span { transition: none; } }
