/* Cyanotype cladogram. Light: Prussian ink on cool paper. Dark: pale lines on cyanotype blue. */
/* Cyanotype is the default; "paper" is the printed counterpart. */
:root {
  --paper: #173962;
  --paper-2: #12305a;
  --ink: #eef4fa;
  --ink-2: #a8c0da;
  --rule: #3a6290;
  --d-math-computing: #f2d27c;
  --d-physical-sciences: #93cdf5;
  --d-earth-environment: #86dccb;
  --d-life-sciences: #c6e27e;
  --d-health-medicine: #f6a99d;
  --d-engineering: #bcb6f7;
  --c: var(--ink);

  --serif: "Newsreader", "Noto Serif SC", Georgia, serif;
  --sans: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --bar-h: 56px;
  --stroke: 1.5px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --paper: #f1f4f6;
  --paper-2: #e2e9ef;
  --ink: #13305a;
  --ink-2: #4d6688;
  --rule: #b9c8d8;
  --d-math-computing: #a06a00;
  --d-physical-sciences: #1d6fb8;
  --d-earth-environment: #0f7d6c;
  --d-life-sciences: #557d10;
  --d-health-medicine: #b8473c;
  --d-engineering: #5b4ec4;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  height: var(--bar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand-mark { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; }
.brand-name { font: 600 19px/1 var(--serif); white-space: nowrap; }
.bar-tools { display: flex; align-items: center; gap: 10px; min-width: 0; }
.search input {
  width: min(320px, 40vw);
  padding: 7px 12px;
  border: 1px solid var(--rule); border-radius: 6px;
  background: var(--paper-2); color: var(--ink);
  font: inherit; font-size: 14px;
}
.search input::placeholder { color: var(--ink-2); }
.lang, .theme {
  border: 1px solid var(--rule); background: transparent; border-radius: 6px;
  padding: 6px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; flex: none;
}
.theme { display: grid; place-items: center; width: 34px; height: 32px; padding: 0; }
.theme svg { width: 16px; height: 16px; }
.lang[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.status { color: var(--ink-2); padding: 48px 24px; }

/* ---------- Home ---------- */
.home {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 24px;
  align-items: center;
  min-height: calc(100vh - var(--bar-h));
  padding: 24px 32px 32px;
}
.home-title {
  font: 500 46px/1.06 var(--serif);
  letter-spacing: -0.015em;
  margin: 0 0 18px;
  max-width: 12ch;
}
html[lang="zh-CN"] .home-title { font-size: 38px; line-height: 1.25; max-width: 11em; letter-spacing: 0.02em; }
.home-lede { font: 400 18px/1.6 var(--serif); color: var(--ink-2); margin: 0 0 28px; max-width: 36ch; }
.home-lede strong { color: var(--ink); font-weight: 500; }

.legend { list-style: none; margin: 0 0 28px; padding: 0; }
.legend a {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px;
  padding: 5px 0; text-decoration: none; font-size: 14px;
}
.legend a::before { content: ""; height: 0; border-top: 2px solid var(--c); }
.legend .n { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 13px; }
.legend a:hover .name, .legend a:focus-visible .name { text-decoration: underline; text-underline-offset: 3px; }
.home-note { font-size: 12.5px; color: var(--ink-2); max-width: 44ch; margin: 0; }

.radial-wrap { margin: 0; display: grid; justify-items: center; gap: 8px; min-width: 0; }
.radial { width: 100%; display: grid; place-items: center; }
.radial-hint { font-size: 13px; color: var(--ink-2); min-height: 1.5em; text-align: center; }

/* ---------- Radial tree (shared by home and locator) ---------- */
.tree-svg { display: block; max-width: 100%; height: auto; touch-action: manipulation; cursor: pointer; }
.tree-svg .link { fill: none; stroke: var(--c); stroke-width: 1; stroke-opacity: 0.75; transition: stroke-opacity 0.15s; }
.tree-svg .link.d1 { stroke-width: 2.2; }
.tree-svg .link.d2 { stroke-width: 1.6; }
.tree-svg .link.d3 { stroke-width: 1.15; }
.tree-svg .link.d4 { stroke-width: 0.8; }
.tree-svg .tip-dot { fill: var(--c); fill-opacity: 0.85; }
.tree-svg .band { fill: var(--c); fill-opacity: 0.9; }
.tree-svg .root-dot { fill: var(--ink); }
.tree-svg .label { fill: var(--ink); font: 400 11.5px var(--sans); }
html[lang="zh-CN"] .tree-svg .label { font-size: 12px; }
.tree-svg.focus .link:not(.lit) { stroke-opacity: 0.14; }
.tree-svg.focus .tip-dot:not(.lit) { fill-opacity: 0.15; }
.tree-svg.focus .label:not(.lit) { fill-opacity: 0.35; }
.tree-svg.focus .link.lit { stroke-opacity: 1; }
.tree-svg .label.lit { font-weight: 500; }

/* Growth: the only unprompted motion on the site. */
.tree-svg.grow .link { stroke-dasharray: 1; stroke-dashoffset: 1; animation: grow 0.7s cubic-bezier(0.3, 0.6, 0.3, 1) forwards; animation-delay: calc(var(--depth) * 0.32s); }
.tree-svg.grow .tip-dot, .tree-svg.grow .label, .tree-svg.grow .band { opacity: 0; animation: appear 0.5s ease forwards 1.5s; }
@keyframes grow { to { stroke-dashoffset: 0; } }
@keyframes appear { to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .tree-svg.grow .link, .tree-svg.grow .tip-dot, .tree-svg.grow .label, .tree-svg.grow .band { animation: none; opacity: 1; stroke-dashoffset: 0; }
}

.tip {
  position: fixed; z-index: 30; pointer-events: none;
  max-width: 280px; padding: 8px 11px;
  background: var(--ink); color: var(--paper);
  border-radius: 6px; font-size: 13px; line-height: 1.4;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
}
.tip .t { font: 500 15px/1.3 var(--serif); }
.tip .s { opacity: 0.75; font-size: 12px; margin-top: 2px; }

/* ---------- Branch pages ---------- */
.page {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 40px;
  padding: 32px 32px 80px;
  max-width: 1320px;
}
.side { position: sticky; top: calc(var(--bar-h) + 24px); align-self: start; }
.locator .tree-svg { width: 240px; }
.content { min-width: 0; max-width: 980px; }

.lineage { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; font-size: 13px; color: var(--ink-2); margin-bottom: 18px; }
.lineage a { text-decoration: none; }
.lineage a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.lineage a + a::before {
  content: ""; display: inline-block; width: 11px; height: 8px; margin: 0 7px 0 8px;
  border-left: var(--stroke) solid var(--rule); border-bottom: var(--stroke) solid var(--rule);
  transform: translateY(-3px);
}

.node-title { font: 500 40px/1.1 var(--serif); letter-spacing: -0.01em; margin: 0; }
.node-alt { font: 400 19px/1.4 var(--serif); font-style: italic; color: var(--ink-2); margin: 4px 0 16px; }
html[lang="zh-CN"] .node-alt { font-style: normal; }
.node-scope { font: 400 17px/1.6 var(--serif); max-width: 64ch; margin: 0 0 8px; }
.node-tally { font-size: 13.5px; color: var(--ink-2); margin: 0 0 32px; }
.node-tally::before { content: ""; display: inline-block; width: 20px; vertical-align: middle; margin-right: 8px; border-top: 2px solid var(--c); }

/* Cladogram: elbow connectors drawn with borders.
   Each li draws its share of the parent's spine (::before) and its own twig (::after). */
.clado { display: grid; grid-template-columns: 30px minmax(0, 1fr); align-items: center; }
.clado-root { position: relative; height: 0; border-top: var(--stroke) solid var(--c); }
.clado-root::before {
  content: ""; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--c);
}
.clade { list-style: none; margin: 0; padding: 0; }
.clade > li { position: relative; padding-left: 24px; --cy: 50%; }
.clade > li::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  border-left: var(--stroke) solid var(--c);
}
.clade > li:first-child::before { top: var(--cy); }
.clade > li:last-child::before { bottom: auto; height: var(--cy); }
.clade > li:only-child::before { display: none; }
.clade > li::after {
  content: ""; position: absolute; left: 0; top: var(--cy); width: 18px;
  border-top: var(--stroke) solid var(--c);
}

.clado > .clade > li {
  display: grid; grid-template-columns: minmax(200px, 300px) minmax(0, 1fr); align-items: center;
  padding-block: 7px;
}
.clado > .clade > li > .node::after {
  content: ""; flex: 1 1 16px; min-width: 16px; margin-left: 12px;
  border-top: var(--stroke) solid var(--c);
}
.clade .clade > li { padding-block: 1px; }

.node { display: flex; align-items: center; min-width: 0; }
.node a {
  display: flex; align-items: baseline; gap: 8px; min-width: 0;
  padding: 4px 8px; margin-left: -2px; border-radius: 5px;
  text-decoration: none;
}
.node a:hover, .node a:focus-visible { background: var(--paper-2); }
.node .name { overflow-wrap: anywhere; }
.node .n { color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.node.major .name { font: 500 18px/1.3 var(--serif); }
.node.major .alt { display: block; font-size: 12.5px; color: var(--ink-2); }
.node.minor a { font-size: 14px; padding-block: 3px; }
.node.minor.problem-title .name { font-family: var(--serif); font-style: italic; font-size: 15px; }
.clado-key { font-size: 12.5px; color: var(--ink-2); margin: 0 0 12px 30px; }

/* Subfield page: problems hang off the spine. */
.clado > .clade.problems > li { display: block; --cy: 54px; padding-block: 10px; }
.problem { padding: 14px 4px 6px 6px; max-width: 70ch; }
.problem-rank { font-size: 12.5px; color: var(--ink-2); margin: 0 0 2px; }
.problem h2 { font: 500 23px/1.3 var(--serif); margin: 0 0 8px; }
.problem .statement { font: 400 17.5px/1.65 var(--serif); margin: 0 0 10px; }
.problem .significance { font-size: 14.5px; line-height: 1.6; color: var(--ink-2); margin: 0; }
.problem .significance b { color: var(--ink); font-weight: 500; }

/* ---------- Search ---------- */
.results { max-width: 860px; padding: 32px 32px 80px; margin-left: max(0px, calc((100vw - 1320px) / 2 + 280px)); }
.results h1 { font: 500 30px/1.2 var(--serif); margin: 0 0 20px; }
.result { display: block; padding: 12px 0 12px 16px; border-left: 2px solid var(--c); margin-bottom: 10px; text-decoration: none; }
.result:hover .result-title { text-decoration: underline; text-underline-offset: 3px; }
.result-path { font-size: 12px; color: var(--ink-2); }
.result-title { font: 500 17px/1.35 var(--serif); }
.result-snippet { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.result mark { background: color-mix(in srgb, var(--c) 28%, transparent); color: inherit; border-radius: 2px; }
.empty { color: var(--ink-2); }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .page { grid-template-columns: 1fr; gap: 0; }
  .side { display: none; }
  .results { margin-left: 0; }
}
@media (max-width: 860px) {
  .home { grid-template-columns: 1fr; padding: 24px 16px 40px; min-height: 0; }
  .home-title { font-size: 36px; }
  .radial-wrap { order: -1; }
}
@media (max-width: 720px) {
  .bar { padding: 0 16px; }
  .brand-name { font-size: 17px; }
  .search input { width: 44vw; }
  .page, .results { padding: 24px 16px 56px; }
  .node-title { font-size: 31px; }
  .clado { grid-template-columns: 18px minmax(0, 1fr); }
  .clado > .clade > li { display: block; --cy: 22px; }
  .clado > .clade > li > .node::after { display: none; }
  .clado > .clade > li > .clade { margin-left: 14px; }
  .clado-key { margin-left: 18px; }
  .problem h2 { font-size: 20px; }
}
@media (max-width: 420px) {
  .brand-name { display: none; }
  .search input { width: 58vw; }
}
