:root {
  --bg: #ffffff;
  --fg: #222222;
  --muted: #666666;
  --line: #d9d9d9;
  --head: #f4f4f4;
  --link: #1a5a96;
  --accent: #2c6e49;
  --sea: #dfe9f2;
  --land: #f6f4ef;
  --border: #b9b2a5;
  --highlight: #fff6d6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17191c;
    --fg: #e6e6e6;
    --muted: #9a9a9a;
    --line: #34383d;
    --head: #22262a;
    --link: #8ab8e6;
    --accent: #7cc49a;
    --sea: #1d2733;
    --land: #2a2b2c;
    --border: #575049;
    --highlight: #3a3420;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17191c;
  --fg: #e6e6e6;
  --muted: #9a9a9a;
  --line: #34383d;
  --head: #22262a;
  --link: #8ab8e6;
  --accent: #7cc49a;
  --sea: #1d2733;
  --land: #2a2b2c;
  --border: #575049;
  --highlight: #3a3420;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; font-weight: 600; margin: 0.4rem 0 0.8rem; }
h2 { font-size: 1.2rem; font-weight: 600; margin: 1.6rem 0 0.6rem; }
h3 { font-size: 1rem; font-weight: 600; margin: 1.2rem 0 0.4rem; }
.muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }

header.site { border-bottom: 1px solid var(--line); background: var(--head); position: sticky; top: 0; z-index: 1000; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 1.2rem; padding: 0.5rem 16px; max-width: 1200px; margin: 0 auto; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--fg); }
nav { display: flex; flex-wrap: wrap; gap: 0.2rem 1rem; }
nav a { color: var(--fg); padding: 0.1rem 0; border-bottom: 2px solid transparent; }
nav a.active { border-bottom-color: var(--accent); }
.threshold { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.7rem; padding: 0.35rem 16px 0.5rem; max-width: 1200px; margin: 0 auto; font-size: 0.92rem; }
.threshold input[type="range"] { flex: 1 1 200px; max-width: 420px; }
.threshold input[type="number"] { width: 5.5rem; }
input, select, button {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 3px; padding: 0.2rem 0.45rem;
}
button { cursor: pointer; background: var(--head); }
button:hover { border-color: var(--muted); }

main { max-width: 1200px; margin: 0 auto; padding: 0.5rem 16px 2rem; }
footer.site { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.85rem; padding: 0.8rem 16px; display: flex; flex-direction: column; gap: 0.2rem; max-width: 1200px; margin: 0 auto; }

.definition { border-left: 3px solid var(--accent); background: var(--head); padding: 0.6rem 0.9rem; margin: 0.8rem 0; }
.stats { display: flex; flex-wrap: wrap; gap: 0.6rem 2rem; margin: 0.8rem 0; }
.stats div b { display: block; font-size: 1.4rem; font-weight: 600; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0.6rem 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.8rem; margin: 0.6rem 0; }
.controls input[type="search"] { flex: 1 1 220px; max-width: 360px; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.3rem 0.55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--head); font-weight: 600; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable::after { content: " ↕"; color: var(--muted); font-weight: 400; }
th.asc::after { content: " ↑"; color: var(--fg); }
th.desc::after { content: " ↓"; color: var(--fg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.current td { background: var(--highlight); }
.more { margin: 0.6rem 0; }

.swatch { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 2px; vertical-align: -0.05em; margin-right: 0.35em; border: 1px solid rgba(0,0,0,0.25); }
.badge { display: inline-block; font-size: 0.78rem; padding: 0 0.4em; border-radius: 3px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.genus { border-color: var(--accent); color: var(--accent); }
.note { font-size: 0.88rem; color: var(--muted); }

.map { height: 460px; border: 1px solid var(--line); background: var(--sea); }
.map.large { height: calc(100vh - 260px); min-height: 380px; }
.leaflet-container { background: var(--sea); font: inherit; }
.leaflet-popup-content { font-size: 0.9rem; line-height: 1.4; }
.legend { font-size: 0.85rem; }

ul.tree, ul.tree ul { list-style: none; margin: 0; padding-left: 1.1rem; }
ul.tree { padding-left: 0; }
ul.tree li { margin: 0.12rem 0; }
ul.tree details > summary { cursor: pointer; }
ul.tree .val { color: var(--muted); font-size: 0.85rem; margin-left: 0.4rem; }
ul.tree .over { color: var(--muted); }
ul.tree .isgenus { font-weight: 600; }

.cols { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 900px) { .cols { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) {
  .stats div b { font-size: 1.15rem; }
  .map { height: 340px; }
  dl.facts { grid-template-columns: 1fr; }
  dl.facts dt { margin-top: 0.3rem; }
}
.cols > div { min-width: 0; }
dl.facts dd { min-width: 0; overflow-wrap: anywhere; }
.leaflet-bar a.world { width: auto; padding: 0 6px; font-size: 12px; font-weight: 600; }

dialog#notice { max-width: 34rem; width: calc(100% - 32px); border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); padding: 1rem 1.3rem; }
dialog#notice::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog#notice h2 { margin-top: 0.2rem; }
dialog#notice form { text-align: right; margin-top: 0.8rem; }
.definition-text { max-width: 52rem; }
.definition-text math[display="block"] { display: block; overflow-x: auto; margin: 0.8rem 0; }
.definition-text h3 { margin-top: 1.4rem; }
.definition-text .csl-entry { margin: 0.3rem 0 0.3rem 1.5rem; text-indent: -1.5rem; font-size: 0.9rem; }

.about-figure { margin: 1.2em 0; }
.about-figure img { display: block; width: 100%; max-width: 720px; height: auto; border: 1px solid var(--line); background: #fff; }
.about-figure figcaption { max-width: 720px; margin-top: 0.4em; font-size: 0.9em; color: var(--muted); }
