/* Reset & base */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #fafaf8;
  --color-text: #1a1a1a;
  --color-muted: #6b6560;
  --color-border: #e4e0dc;
  --color-link: #2b52a4;
  --color-link-hover: #1a3a7a;
  --color-accent-bg: #f4f3f0;
  --color-nav-bg: #2c2c3a;
  --color-nav-text: #f0f0f0;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  --max-width: 1100px;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  font-size: 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-to-main {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 1rem;
  background: var(--color-link);
  color: #fff;
}

.skip-to-main:focus {
  left: 0;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.25;
}

h1 {
  letter-spacing: -0.02em;
}

a {
  color: var(--color-link);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

a:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

/* Nav */
nav {
  background: var(--color-nav-bg);
  color: var(--color-nav-text);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

nav a {
  color: var(--color-nav-text);
  transition: color 0.15s ease;
}

nav a:hover {
  color: #fff;
  text-decoration: underline;
}

nav a:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.2rem;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
}

/* Main */
main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
}

/* Hero */
.hero {
  text-align: center;
  padding: 2.5rem 0;
}

.hero h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.intro {
  font-size: 1.1rem;
  color: var(--color-muted);
  margin-bottom: 2rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.intro a {
  color: var(--color-link);
}

.stats {
  display: flex;
  justify-content: center;
  gap: 3rem;
  margin-bottom: 2rem;
  padding: 1.5rem 2rem;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-number {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.9rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn {
  display: inline-block;
  background: var(--color-link);
  color: #fff;
  padding: 0.75rem 2rem;
  border-radius: 6px;
  font-weight: 500;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  background: var(--color-link-hover);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.btn:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* Family list (homepage & taxonomy) */
.families-preview {
  margin-top: 3rem;
}

.families-preview h2 {
  margin-bottom: 1rem;
}

.family-list,
.taxonomy-terms,
.org-list {
  list-style: none;
}

.family-list li,
.taxonomy-terms li,
.org-list li {
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  transition: background 0.15s ease;
  border-radius: 3px;
}

.family-list li:last-child,
.taxonomy-terms li:last-child,
.org-list li:last-child {
  border-bottom: none;
}

.family-list li:hover,
.taxonomy-terms li:hover,
.org-list li:hover {
  background: var(--color-accent-bg);
}

.count {
  font-size: 0.85rem;
  color: var(--color-muted);
}

.count::before {
  content: "(";
}

.count::after {
  content: ")";
}

.abbr {
  font-size: 0.9rem;
  color: var(--color-muted);
}

/* Table view */
.table-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.table-controls input,
.table-controls select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.95rem;
  font-family: var(--font-sans);
  transition: border-color 0.15s ease;
}

.table-controls input {
  flex: 1;
  min-width: 200px;
}

.table-controls input:focus-visible,
.table-controls select:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 0;
  border-color: var(--color-link);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead {
  background: var(--color-accent-bg);
  position: sticky;
  top: 0;
}

th {
  text-align: left;
  padding: 0.7rem 0.75rem;
  border-bottom: 2px solid var(--color-border);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  font-weight: 600;
  transition: background 0.15s ease;
}

th:hover {
  background: #e8e5e0;
}

th::after {
  content: "";
  display: inline-block;
  margin-left: 0.4rem;
  width: 0;
  height: 0;
}

th.sort-asc::after {
  content: "\25B2";
  font-size: 0.65rem;
}

th.sort-desc::after {
  content: "\25BC";
  font-size: 0.65rem;
}

td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

tr {
  transition: background 0.15s ease;
}

tr:hover {
  background: var(--color-accent-bg);
}

tr.hidden {
  display: none;
}

.table-count {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--color-muted);
}

/* Detail page */
.org-detail h1 {
  margin-bottom: 0.25rem;
}

.abbreviation {
  font-size: 1.2rem;
  color: var(--color-muted);
  margin-bottom: 1.5rem;
}

.detail-section {
  margin-bottom: 2.5rem;
}

.detail-section h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.4rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

dl {
  display: grid;
  grid-template-columns: minmax(140px, auto) 1fr;
  gap: 0.5rem 1.25rem;
}

dt {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-muted);
}

dd {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.external-links {
  list-style: none;
}

.external-links li {
  padding: 0.3rem 0;
}

.back-link {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

/* Taxonomy */
.taxonomy-list h1,
.term-page h1 {
  margin-bottom: 1rem;
}

.term-page p {
  margin-bottom: 1rem;
  color: var(--color-muted);
}

/* Footer */
footer {
  text-align: center;
  padding: 2.5rem 1.5rem;
  font-size: 0.85rem;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
  margin-top: 4rem;
}

/* Responsive */
@media (max-width: 640px) {
  .hero h1 {
    font-size: 1.75rem;
  }

  .stats {
    gap: 1.5rem;
  }

  .stat-number {
    font-size: 1.75rem;
  }

  dl {
    grid-template-columns: 1fr;
  }

  dt {
    margin-top: 0.5rem;
  }

  nav {
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .table-controls {
    flex-direction: column;
  }

  .btn {
    padding: 0.65rem 1.5rem;
  }
}
