:root {
  --header-h: 84px;
  --sidebar-w: 280px;
  --brand-1: #159957;
  --brand-2: #155799;
  --line: #e5e7eb;
  --muted: #6b7280;
  --code-bg: #f5f7fa;
  --pill-bg: #e5edf5;
  --pill-text: #155799;
  --card-shadow: 0 1px 2px rgba(15, 23, 42, .06);

  /* Semantic surface tokens (light values identical to the originals below;
     redefined by role in the dark block at the end of this file). */
  --page-bg: #fafafa;
  --fg: #111827;
  --surface: #ffffff;
  --hover-bg: #f3f4f6;
  --subtle-bg: #f6f8fa;
  --sel-bg: #eaf5ee;
  --input-bg: #ffffff;
  --strong-fg: #111827;
  --header-grad-a: #159957;
  --header-grad-b: #155799;
  --strong-2: #155799;
  --axis-accent: #159957;
  --axis-border: #d0d7de;
  --axis-span: #57606a;
  --landing-fg: #374151;
  --info-bg: #f6f8fa;
  --info-border: #eaecef;
  --info-color: #57606a;
  --info-icon: #0969da;
  --ex-bg: #fafbfd;
  --pill-axis-bg: #e6fffa; --pill-axis-text: #087f5b;
  --pill-src-bg: #fef3c7;  --pill-src-text: #92400e;
  --pill-sta-bg: #ede9fe;  --pill-sta-text: #5b21b6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: #111827;
  background: #fafafa;
  line-height: 1.5;
}

code, .mono {
  font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .92em;
}

/* --- header --- */
.page-header {
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: #fff;
  padding: 1rem 1.5rem;
}
.page-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.brand {
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  font-size: 1.15rem;
}
.page-header nav {
  margin-left: auto;
  display: flex;
  gap: 1rem;
}
.page-header nav a {
  color: #f1f5f9;
  text-decoration: none;
  font-size: .95rem;
}
.page-header nav a:hover { text-decoration: underline; }
.tag {
  background: rgba(255, 255, 255, .18);
  color: #f8fafc;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .78rem;
}

/* --- layout --- */
.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

/* --- sidebar --- */
.sidebar {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .8rem;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
}
.search-box input {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: .95rem;
}
.facet-scroll {
  margin-top: .8rem;
  overflow-y: auto;
  padding-right: .3rem;
}
.facet-group { margin-bottom: .9rem; }
.facet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 0 0 .35rem 0;
  cursor: pointer;
  user-select: none;
}
.facet-head:hover { color: #111827; }
.facet-head > span::before {
  content: "▸";
  display: inline-block;
  margin-right: .35rem;
  font-size: .7em;
  transition: transform .12s ease;
}
.facet-group.expanded .facet-head > span::before { transform: rotate(90deg); }
.facet-toggle {
  background: none;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 7px;
  font-size: .68rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  text-transform: none;
  letter-spacing: 0;
}
.facet-toggle:hover { background: #f3f4f6; color: #111827; }
/* Collapsed by default: hide every non-selected value; selected ones stay. */
.facet-group:not(.expanded) .facet-item:not(.is-selected) { display: none; }
/* Values with no matches in the current filtered subset are hidden entirely,
   whether the group is collapsed or expanded (kept only if selected). */
.facet-item.is-empty { display: none; }

.facet-info {
  display: flex; align-items: flex-start; gap: .4rem;
  margin: 0 0 .7rem; padding: .45rem .55rem;
  font-size: .74rem; line-height: 1.35; color: #57606a;
  background: #f6f8fa; border: 1px solid #eaecef; border-radius: 6px;
}
.facet-info-icon {
  cursor: help; color: #0969da; font-size: .95rem; line-height: 1;
  flex: 0 0 auto; margin-top: -1px;
}
.facet-info-text { flex: 1; }

/* Landing view (lazy loading — nothing loaded yet) */
.landing { padding: 1rem .25rem; color: #374151; }
.landing p { max-width: 46rem; line-height: 1.5; }
.axis-cards { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.axis-card {
  display: flex; flex-direction: column; gap: .1rem; min-width: 120px;
  padding: .7rem .9rem; border: 1px solid #d0d7de; border-left: 4px solid #159957;
  border-radius: 8px; background: #fff; color: inherit; text-decoration: none;
}
.axis-card:hover { background: #f6f8fa; }
.axis-card strong { font-size: 1.3rem; line-height: 1.1; color: #155799; }
.axis-card span { font-size: .8rem; color: #57606a; }
.facet-item {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: .9rem;
  cursor: pointer;
}
.facet-item:hover { background: #f3f4f6; }
.facet-item.is-selected { background: #eaf5ee; }
.facet-item input { margin: 0; }
.facet-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet-item .count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: .82rem;
}
.facet-toolbar {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  margin-top: .3rem;
  padding-top: .5rem;
  border-top: 1px solid var(--line);
}
.facet-toolbar button {
  background: none;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: .82rem;
  color: var(--muted);
}
.facet-toolbar button:hover { background: #f3f4f6; color: #111827; }

/* --- results --- */
.results {
  min-height: calc(100vh - 3rem);
}
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: .8rem;
  gap: .5rem;
  flex-wrap: wrap;
}
.results-header .summary {
  color: var(--muted);
  font-size: .9rem;
}
.results-header .paging {
  display: flex;
  gap: .3rem;
  align-items: center;
  font-size: .88rem;
}
.results-header .paging button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
}
.results-header .paging button:disabled { opacity: .4; cursor: default; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: .7rem;
}
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .8rem .9rem;
  box-shadow: var(--card-shadow);
  transition: box-shadow .15s ease, transform .1s ease;
  overflow: hidden;
}
.card:hover {
  box-shadow: 0 6px 14px rgba(15, 23, 42, .08);
  transform: translateY(-1px);
}
.card-main {
  display: block;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.card .cid {
  font-family: SFMono-Regular, Consolas, monospace;
  color: var(--brand-2);
  font-size: .78rem;
  word-break: break-all;
  margin-bottom: 4px;
}
.card h3 {
  font-size: .98rem;
  margin: 0 0 .25rem 0;
  line-height: 1.25;
}
.card p {
  color: var(--muted);
  font-size: .85rem;
  margin: 0 0 .35rem 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: .3rem;
}
.pill {
  background: var(--pill-bg);
  color: var(--pill-text);
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: SFMono-Regular, Consolas, monospace;
  text-decoration: none;
  cursor: pointer;
  transition: filter .1s ease, box-shadow .1s ease;
}
a.pill:hover {
  filter: brightness(.94);
  box-shadow: inset 0 0 0 1px currentColor;
}
.pill.axis { background: #e6fffa; color: #087f5b; }
.pill.src  { background: #fef3c7; color: #92400e; }
.pill.sta  { background: #ede9fe; color: #5b21b6; }

/* --- detail view --- */
.detail {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.2rem 1.5rem;
  box-shadow: var(--card-shadow);
}
.detail .breadcrumb {
  font-size: .88rem;
  color: var(--muted);
  margin-bottom: .8rem;
}
.detail .breadcrumb a {
  color: var(--brand-2);
  text-decoration: none;
}
.detail .breadcrumb a:hover { text-decoration: underline; }
.detail h1 {
  font-size: 1.35rem;
  margin: 0 0 .3rem 0;
  line-height: 1.25;
}
.detail .cid {
  font-family: SFMono-Regular, Consolas, monospace;
  color: var(--brand-2);
  font-size: .95rem;
  word-break: break-all;
  margin-bottom: .8rem;
}
.detail .pills { margin-bottom: 1rem; }
.detail dl {
  margin: 0;
}
.detail dl > div {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 1rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--line);
}
.detail dl > div:last-child { border-bottom: none; }
.detail dt {
  font-weight: 600;
  color: var(--muted);
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.detail dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
}
.detail dd.pre {
  background: var(--code-bg);
  padding: .5rem .75rem;
  border-radius: 6px;
  font-family: SFMono-Regular, Consolas, monospace;
  font-size: .9rem;
  overflow-x: auto;
}
.detail .xref-list, .detail .canonical-list, .detail .evidence-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.detail .xref-list li a,
.detail .evidence-list li a {
  color: var(--brand-2);
  text-decoration: none;
  font-family: SFMono-Regular, Consolas, monospace;
  font-size: .9rem;
}
.detail .xref-list li a:hover { text-decoration: underline; }
.detail .xref-list .map-src { color: #94a3b8; font-size: 0.82em; font-style: italic; }
/* Resolved label shown after an id everywhere (`<CURIE> — <label>`). */
.curie-label { color: var(--muted); font-size: 0.86em;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }

/* --- example proteins list --- */
.detail .ex-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.detail .ex-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .6rem .75rem;
  background: #fafbfd;
}
.detail .ex-head {
  display: flex;
  gap: .5rem;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: .95rem;
}
.detail .ex-id a {
  color: var(--brand-2);
  text-decoration: none;
  font-family: SFMono-Regular, Consolas, monospace;
  font-weight: 600;
}
.detail .ex-id a:hover { text-decoration: underline; }
.detail .ex-label { color: var(--fg); }
.detail .ex-tax {
  color: var(--muted);
  font-size: .85rem;
  margin-top: .15rem;
  font-style: italic;
}
.detail .ex-badges {
  margin-top: .35rem;
  display: flex;
  gap: .3rem;
  flex-wrap: wrap;
}
.detail .ex-families {
  margin-top: .4rem;
  font-family: SFMono-Regular, Consolas, monospace;
  font-size: .8rem;
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
}
.detail .ex-families a {
  color: var(--brand-2);
  text-decoration: none;
}
.detail .ex-families a:hover { text-decoration: underline; }

/* --- sequence viewer --- */
.detail .ex-seq {
  margin-top: .6rem;
  border-top: 1px dashed var(--line);
  padding-top: .5rem;
}
.detail .ex-seq summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .85rem;
  user-select: none;
}
.detail .ex-seq summary:hover { color: var(--fg); }

.detail .ex-seq-loading {
  margin-top: .6rem;
  padding-top: .5rem;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: .85rem;
  font-style: italic;
}

.detail .slegend {
  margin: .5rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  font-size: .8rem;
  color: var(--muted);
}
.detail .sleg { display: inline-flex; align-items: center; gap: .35rem; }
.detail .sswatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  vertical-align: middle;
}
.detail .sleg b { color: var(--fg); font-weight: 600; }

.detail .sviewer {
  font-family: SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  line-height: 1.25;
  overflow-x: auto;
}
.detail .srow {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: 2px 0;
}
.detail .sn {
  color: var(--muted);
  font-size: 11px;
  padding-top: 2px;
  min-width: 4ch;
  text-align: right;
  user-select: none;
}
.detail .sr {
  display: inline-flex;
}
.detail .rcell {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  width: 10px;
}
.detail .rletter {
  display: block;
  text-align: center;
  width: 100%;
  color: var(--fg);
  line-height: 1;
}
.detail .rstrips {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 6px;
  margin-top: 1px;
  overflow: hidden;
  border-radius: 1px;
}
.detail .rstrip {
  display: block;
  width: 100%;
  min-height: 1px;
}

.loading { padding: 2rem; text-align: center; color: var(--muted); }
.empty   { padding: 2rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; }

/* --- footer --- */
.page-footer {
  border-top: 1px solid var(--line);
  padding: 1rem 1.5rem;
  color: var(--muted);
  text-align: center;
  font-size: .85rem;
}
.page-footer a { color: var(--brand-2); }

/* --- responsive --- */
/* Keep facets in a left column down to true-mobile widths; only stack them
   above the results on narrow phones. */
@media (max-width: 560px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
  }
  .facet-scroll {
    max-height: 320px;
  }
}

/* ============================================================
   Dark theme + reduced-motion (additive; light stays identical)
   ============================================================ */

/* Route the hardcoded light surfaces through the semantic tokens above.
   In light these resolve to the SAME values as the original rules; the dark
   block only re-points the tokens, so the light appearance is unchanged. */
body { background: var(--page-bg); color: var(--fg); }
.page-header { background: linear-gradient(120deg, var(--header-grad-a), var(--header-grad-b)); }
.sidebar { background: var(--surface); }
.card { background: var(--surface); }
.detail { background: var(--surface); }
.axis-card { background: var(--surface); border-color: var(--axis-border); border-left-color: var(--axis-accent); }
.axis-card:hover { background: var(--subtle-bg); }
.axis-card strong { color: var(--strong-2); }
.axis-card span { color: var(--axis-span); }
.landing { color: var(--landing-fg); }
.facet-head:hover { color: var(--strong-fg); }
.facet-toggle:hover { background: var(--hover-bg); color: var(--strong-fg); }
.facet-item:hover { background: var(--hover-bg); }
.facet-item.is-selected { background: var(--sel-bg); }
.facet-toolbar button:hover { background: var(--hover-bg); color: var(--strong-fg); }
.search-box input { background: var(--input-bg); }
.results-header .paging button { background: var(--surface); }
.facet-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info-color); }
.facet-info-icon { color: var(--info-icon); }
.ex-item { background: var(--ex-bg); }
.pill.axis { background: var(--pill-axis-bg); color: var(--pill-axis-text); }
.pill.src  { background: var(--pill-src-bg);  color: var(--pill-src-text); }
.pill.sta  { background: var(--pill-sta-bg);  color: var(--pill-sta-text); }

/* ---- Dark theme (OS default; superseded by the toggle) ---- */
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --line: #253230;
    --muted: #9bb0aa;
    --code-bg: #17201e;
    --pill-bg: #223042;
    --pill-text: #9cc4ec;
    --brand-2: #7fb0e8;          /* legible link/id blue on dark (header uses its own tokens) */
    --card-shadow: 0 1px 2px rgba(0, 0, 0, .5);
    --page-bg: #0f1615;
    --fg: #e8efec;
    --surface: #17201e;
    --hover-bg: rgba(255, 255, 255, .06);
    --subtle-bg: #1b2523;
    --sel-bg: rgba(72, 194, 184, .16);
    --input-bg: #0f1615;
    --strong-fg: #e8efec;
    --header-grad-a: #123d2f;
    --header-grad-b: #123047;
    --strong-2: #9cc4ec;
    --axis-accent: #48c2b8;
    --axis-border: #253230;
    --axis-span: #9bb0aa;
    --landing-fg: #c3d0cb;
    --info-bg: #1b2523;
    --info-border: #253230;
    --info-color: #9bb0aa;
    --info-icon: #7fb0e8;
    --ex-bg: #1b2523;
    --pill-axis-bg: rgba(72, 194, 184, .16); --pill-axis-text: #6fd6c8;
    --pill-src-bg: rgba(251, 191, 36, .16);  --pill-src-text: #fbbf24;
    --pill-sta-bg: rgba(180, 153, 240, .18); --pill-sta-text: #c4b0f5;
  }
  :root:not([data-theme="light"]) .search-box input { color: var(--fg); }
}
:root[data-theme="dark"]{
  --line: #253230;
  --muted: #9bb0aa;
  --code-bg: #17201e;
  --pill-bg: #223042;
  --pill-text: #9cc4ec;
  --brand-2: #7fb0e8;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, .5);
  --page-bg: #0f1615;
  --fg: #e8efec;
  --surface: #17201e;
  --hover-bg: rgba(255, 255, 255, .06);
  --subtle-bg: #1b2523;
  --sel-bg: rgba(72, 194, 184, .16);
  --input-bg: #0f1615;
  --strong-fg: #e8efec;
  --header-grad-a: #123d2f;
  --header-grad-b: #123047;
  --strong-2: #9cc4ec;
  --axis-accent: #48c2b8;
  --axis-border: #253230;
  --axis-span: #9bb0aa;
  --landing-fg: #c3d0cb;
  --info-bg: #1b2523;
  --info-border: #253230;
  --info-color: #9bb0aa;
  --info-icon: #7fb0e8;
  --ex-bg: #1b2523;
  --pill-axis-bg: rgba(72, 194, 184, .16); --pill-axis-text: #6fd6c8;
  --pill-src-bg: rgba(251, 191, 36, .16);  --pill-src-text: #fbbf24;
  --pill-sta-bg: rgba(180, 153, 240, .18); --pill-sta-text: #c4b0f5;
}
:root[data-theme="dark"] .search-box input { color: var(--fg); }

/* ---- Reduced-motion guard ---- */
@media (prefers-reduced-motion: reduce){
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
