:root {
  --bg: #0f1419;
  --bg-panel: #171e26;
  --bg-hover: #1e2833;
  --border: #2a3743;
  --text: #d6dee6;
  --text-dim: #8296a8;
  --accent: #4fb3ff;
  --accent-dim: #1a4a6e;
  --ok: #4fd18b;
  --ok-dim: #17402c;
  --warn: #f0b64a;
  --warn-dim: #4a3a17;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 4.5rem; }

body {
  margin: 0;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

code, pre { font-family: var(--mono); font-size: 0.9em; }
code {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
}
pre {
  background: #0a0e12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  line-height: 1.5;
}
pre code { background: none; border: none; padding: 0; }
pre .c { color: var(--text-dim); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.5rem); }
.wrap.wide { max-width: 1320px; }

/* header */
header.site {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(23, 30, 38, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
header.site .wrap { display: flex; align-items: center; gap: 1.5rem; padding-top: 0.6rem; padding-bottom: 0.6rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; color: var(--accent); }
.brand img { height: 28px; width: auto; }
header.site nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
header.site nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.92rem;
}
header.site nav a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.repo-link { margin-left: auto; color: var(--text-dim); text-decoration: none; white-space: nowrap; }
.repo-link:hover { color: var(--accent); }

/* hero */
.hero { padding: clamp(3rem, 8vw, 6rem) 0 clamp(2.5rem, 6vw, 4rem); }
.hero .wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2.5rem; align-items: center; }
.hero img { width: clamp(120px, 18vw, 200px); height: auto; filter: drop-shadow(0 0 32px rgba(79, 179, 255, 0.25)); }
.eyebrow {
  margin: 0 0 0.6rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hero h1 { margin: 0 0 1rem; font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.05; }
.hero .lead { max-width: 640px; color: var(--text-dim); font-size: 1.15rem; margin: 0 0 1.6rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.7rem; }
.button {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  text-decoration: none;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--bg-panel);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.button:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.button.primary { background: var(--accent); color: #06111c; border-color: var(--accent); }
.button.primary:hover { background: #79c6ff; color: #06111c; }

.stats { display: flex; flex-wrap: wrap; gap: 0.6rem 2rem; margin-top: 2rem; }
.stats div { display: flex; flex-direction: column; }
.stats strong { font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats span { color: var(--text-dim); font-size: 0.85rem; }

/* sections */
section { padding: clamp(2.5rem, 6vw, 4.5rem) 0; border-top: 1px solid var(--border); }
section h2 { margin: 0 0 0.5rem; font-size: clamp(1.5rem, 3vw, 2.1rem); line-height: 1.15; }
section > .wrap > p.sub { margin: 0 0 2rem; color: var(--text-dim); max-width: 720px; }

/* badges + chips */
.badges { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.badge {
  display: inline-block;
  padding: 0.08rem 0.5rem;
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.78rem;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-dim); color: var(--ok); }
.badge.warn { background: var(--warn-dim); color: var(--warn); }
.badge.dim { background: var(--bg-hover); color: var(--text-dim); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.1rem 0.6rem;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  white-space: nowrap;
}
.chip button {
  background: none;
  border: none;
  color: var(--text-dim);
  font: inherit;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.chip button:hover { color: var(--accent); }
.muted { color: var(--text-dim); }
.mono { font-family: var(--mono); font-size: 0.85em; }

/* browse toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.8rem;
}
.toolbar input[type="search"] { flex: 1 1 260px; min-width: 180px; }
.toolbar input, .toolbar select {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font: inherit;
  font-size: 0.92rem;
}
.toolbar select { max-width: 220px; }
.toolbar input:focus, .toolbar select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.toolbar .button.small { padding: 0.45rem 0.8rem; font-size: 0.88rem; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg-panel); }
.seg button {
  background: none;
  border: none;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { color: var(--text); background: var(--bg-hover); }
.seg button.active { background: var(--accent-dim); color: var(--accent); }

.status-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.8rem;
  margin-bottom: 0.6rem;
  color: var(--text-dim);
  font-size: 0.88rem;
  min-height: 1.6rem;
}
.status-line .count { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.status-line .clear { background: none; border: none; color: var(--accent); font: inherit; font-size: 0.85rem; cursor: pointer; padding: 0; }
.status-line .clear:hover { text-decoration: underline; }

/* table + map panels */
.view { display: none; }
.view.active { display: block; }

.table-wrap {
  overflow: auto;
  max-height: min(72vh, 900px);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-panel);
}
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.88rem; }
table.data th, table.data td { padding: 0.5rem 0.8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-panel);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  user-select: none;
}
table.data th[data-sort] { cursor: pointer; }
table.data th[data-sort]:hover { color: var(--accent); }
table.data th.sorted-asc::after { content: " ▲"; font-size: 0.7em; }
table.data th.sorted-desc::after { content: " ▼"; font-size: 0.7em; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--bg-hover); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.num { font-family: var(--mono); font-size: 0.85em; }
table.data td.name { font-weight: 600; }
table.data td.name.derived { font-weight: 400; color: var(--text-dim); font-family: var(--mono); font-size: 0.82em; }
table.data td.notes { max-width: 340px; color: var(--text-dim); font-size: 0.82rem; }
table.data td.src { font-size: 0.82rem; }
table.data td.src a { color: var(--text-dim); text-decoration: none; }
table.data td.src a:hover { color: var(--accent); }
table.data .empty td { padding: 2rem; text-align: center; color: var(--text-dim); }

#map {
  height: min(72vh, 900px);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  overflow: hidden;
}
.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg-panel); color: var(--text); }
.leaflet-popup-content { font: 13px/1.4 inherit; margin: 0.8rem 1rem; }
.popup-title { font-weight: 600; margin-bottom: 0.3rem; }
.popup-chan { font-family: var(--mono); font-size: 12px; }
.popup-more { color: var(--text-dim); font-size: 12px; margin-top: 0.2rem; }
.leaflet-control-attribution { background: rgba(23, 30, 38, 0.85) !important; color: var(--text-dim) !important; }
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-bar a { background: var(--bg-panel) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-bar a:hover { background: var(--bg-hover) !important; }

/* library */
.lib-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1.2rem; }
.lib-toolbar input[type="search"] {
  flex: 1 1 240px;
  min-width: 180px;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font: inherit;
  font-size: 0.92rem;
}
.lib-toolbar input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.group { margin-top: 2.2rem; }
.group:first-child { margin-top: 0; }
.group > h3 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.group > p { margin: 0 0 1rem; color: var(--text-dim); font-size: 0.92rem; }
.subgroup { margin-top: 1.2rem; }
.subgroup > h4 {
  margin: 0 0 0.7rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 1rem; }
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.card:hover { border-color: #3a4d5f; }
.card h4 { margin: 0; font-size: 1.05rem; }
.card h4 a { color: var(--text); text-decoration: none; }
.card h4 a:hover { color: var(--accent); }
.card .region { color: var(--text-dim); font-size: 0.82rem; }
.card dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.8rem; font-size: 0.85rem; }
.card dt { color: var(--text-dim); }
.card dd { margin: 0; font-variant-numeric: tabular-nums; }
.card dd a { color: var(--text-dim); }
.card dd a:hover { color: var(--accent); }
.card .links { margin-top: auto; padding-top: 0.4rem; font-size: 0.85rem; display: flex; gap: 0.9rem; flex-wrap: wrap; }
.card .links a, .card .links button {
  color: var(--accent);
  background: none;
  border: none;
  font: inherit;
  font-size: 0.85rem;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
}
.card .links a:hover, .card .links button:hover { text-decoration: underline; }
.empty { padding: 1.2rem; color: var(--text-dim); font-size: 0.92rem; border: 1px dashed var(--border); border-radius: 10px; }

/* features / ecosystem */
.features { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.features article { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; }
.features h3 { margin: 0 0 0.35rem; font-size: 1rem; color: var(--text); }
.features p { margin: 0; color: var(--text-dim); font-size: 0.9rem; }

.eco { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.eco a.card { display: block; color: var(--text); text-decoration: none; }
.eco a.card:hover { border-color: var(--accent); text-decoration: none; }
.eco a.card h3 { margin: 0 0 0.3rem; font-size: 1rem; color: var(--accent); }
.eco a.card p { margin: 0; color: var(--text-dim); font-size: 0.9rem; }

/* quick start */
.start { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 1rem; }
.start h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.start pre { margin: 0; font-size: 0.82rem; }
.start p { margin: 0.5rem 0 0; color: var(--text-dim); font-size: 0.88rem; }

/* detail pages */
.crumbs { display: flex; flex-wrap: wrap; gap: 0.4rem; color: var(--text-dim); font-size: 0.85rem; margin: 2rem 0 0.8rem; }
.crumbs a { color: var(--text-dim); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.detail-hero { padding: 0 0 2rem; }
.detail-hero h1 { margin: 0 0 0.6rem; font-size: clamp(1.7rem, 4vw, 2.6rem); line-height: 1.1; }
.detail-hero .meta { color: var(--text-dim); margin: 0 0 1rem; }
.detail-hero .badges { margin-bottom: 1.2rem; }
.detail section { padding: clamp(1.8rem, 4vw, 3rem) 0; }
.detail section h2 { font-size: clamp(1.25rem, 2.4vw, 1.6rem); }
.detail .table-wrap { max-height: none; }
.detail #map { height: 360px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 0.8rem; }
.kv article { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; padding: 0.9rem 1.1rem; }
.kv h3 { margin: 0 0 0.3rem; font-size: 1rem; }
.kv p { margin: 0; color: var(--text-dim); font-size: 0.88rem; }
.sources { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.sources li { color: var(--text-dim); font-size: 0.92rem; }

footer.site { border-top: 1px solid var(--border); padding: 2rem 0 3rem; color: var(--text-dim); font-size: 0.88rem; }
footer.site .wrap { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; justify-content: space-between; }
footer.site a { color: var(--text-dim); }
footer.site a:hover { color: var(--accent); }

.error { margin: 1rem 0; padding: 1rem 1.2rem; border: 1px solid #7a2e2e; border-radius: 10px; background: #2a1517; color: #f5b5b5; }

@media (max-width: 720px) {
  .hero .wrap { grid-template-columns: 1fr; }
  .hero img { order: -1; width: 110px; }
  header.site nav { display: none; }
  table.data td.notes, table.data th.notes { display: none; }
  .toolbar select { max-width: none; flex: 1 1 45%; }
}
