:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #b42318;
  --shadow: 0 8px 28px rgba(15, 23, 42, .07);
  --radius: 16px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #111827;
  --surface-soft: #1f2937;
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #93c5fd;
  --accent-soft: #172554;
  --shadow: 0 8px 28px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
}
.nav-wrap {
  width: min(920px, calc(100% - 24px));
  height: 58px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}
.brand strong, .brand small { display: block; }
.brand strong { line-height: 1; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.nav-actions { display: flex; gap: 8px; align-items: center; }

main {
  width: min(920px, calc(100% - 24px));
  margin: 0 auto 48px;
}
.hero {
  padding: 28px 0 14px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}
.eyebrow {
  display: inline-flex;
  margin-bottom: 10px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}
h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 6px;
  font-size: clamp(36px, 7vw, 60px);
  line-height: .95;
  letter-spacing: -.05em;
}
.hero p { margin: 0; color: var(--muted); line-height: 1.55; }
.mini-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 13px;
}
.mini-stats span {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  white-space: nowrap;
}
.mini-stats b { color: var(--text); }

.finder-card,
.category-panel,
.results-toolbar,
.results-panel,
.tree-panel,
.data-panel,
.detail-dialog {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.finder-card {
  padding: 16px;
  position: sticky;
  top: 70px;
  z-index: 10;
}
.search-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.search-box { position: relative; }
.search-box input {
  width: 100%;
  height: 58px;
  padding: 0 48px 0 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 18px;
}
.search-box input:focus { border-color: var(--accent); background: var(--surface); }
.search-box button {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 22px;
}
.simple-filters {
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr 1fr auto;
  gap: 9px;
  margin-top: 12px;
  align-items: end;
}
.simple-filters label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.simple-filters select {
  min-width: 0;
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}
.quick-tags,
.level-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}
.level-chips { margin-top: 8px; }
.tag-btn,
.level-chip,
.tab-btn,
.primary-btn,
.ghost-btn,
.small-btn,
.file-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}
.tag-btn,
.level-chip { color: var(--muted); }
.level-chip.active,
.tab-btn.active,
.tag-btn:hover,
.level-chip:hover,
.ghost-btn:hover,
.small-btn:hover,
.file-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.primary-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.reset-btn { height: 40px; border-radius: 11px; }

.category-panel {
  margin-top: 12px;
  overflow: hidden;
  box-shadow: none;
}
.category-panel summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 15px;
  cursor: pointer;
  font-weight: 900;
}
.category-panel summary b {
  min-width: 32px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
}
.all-category-btn {
  margin: 0 12px 10px;
  width: calc(100% - 24px);
  border-radius: 12px;
  text-align: left;
}
.all-category-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.category-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 12px 12px;
  max-height: 320px;
  overflow: auto;
}
.category-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}
.category-item:hover,
.category-item.active { border-color: var(--accent); background: var(--accent-soft); }
.category-code {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--surface-soft);
  color: var(--accent);
  font-weight: 900;
}
.category-item span:nth-child(2) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}
.category-item small { display: none; }
.category-item .count { color: var(--muted); }

.workspace { margin-top: 12px; }
.results-toolbar {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  box-shadow: none;
}
.results-toolbar h2 { margin-bottom: 2px; font-size: 20px; }
.results-toolbar p { margin: 0; color: var(--muted); font-size: 13px; }
.toolbar-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.view-panel[hidden] { display: none; }
.results-panel,
.tree-panel { padding: 12px; }
.results-list { display: grid; gap: 9px; }
.result-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.result-card:hover { border-color: var(--accent); }
.result-code {
  display: inline-flex;
  padding: 7px 9px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 900;
  letter-spacing: .02em;
}
.result-title {
  margin: 0 0 5px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.3;
}
.result-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.result-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}
.card-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.small-btn { padding: 7px 10px; }
.breadcrumb-line { display: none; }
.child-summary {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}
.child-summary span { display: none; }
.empty-state {
  padding: 26px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
}
.empty-state strong { color: var(--text); }
mark { background: color-mix(in srgb, var(--accent) 20%, transparent); color: inherit; border-radius: 4px; padding: 0 2px; }

.tree-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.tree-panel-head h2 { margin-bottom: 2px; font-size: 20px; }
.tree-panel-head p { margin: 0; color: var(--muted); font-size: 13px; }
.tree-panel-head span {
  height: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.tree-help { display: none; }
.tree-list {
  display: grid;
  gap: 7px;
  max-height: 680px;
  overflow: auto;
  padding-right: 2px;
}
.tree-node { margin-left: calc(var(--depth, 0) * 10px); }
.tree-node summary,
.tree-leaf > button {
  width: 100%;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  padding: 8px;
}
.tree-node summary { list-style: none; cursor: pointer; }
.tree-node summary::-webkit-details-marker { display: none; }
.tree-node summary::before { content: "▸"; color: var(--muted); }
.tree-node[open] > summary::before { transform: rotate(90deg); }
.tree-code {
  min-width: 34px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  border-radius: 9px;
  background: var(--surface-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}
.tree-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
}
.tree-node small,
.tree-leaf small {
  grid-column: 3 / -1;
  color: var(--muted);
  font-size: 11px;
}
.tree-node summary > button {
  grid-column: 4;
  grid-row: 1 / 3;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 900;
}
.tree-leaf > button { grid-template-columns: auto minmax(0, 1fr); cursor: pointer; }
.tree-leaf .tree-title { grid-column: 2; }
.tree-leaf small { grid-column: 2; }
.tree-node summary:hover,
.tree-leaf > button:hover { border-color: var(--accent); }
.tree-children { margin-top: 7px; display: grid; gap: 7px; }
.tree-empty { padding: 14px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); background: var(--surface-soft); font-size: 13px; }

.data-panel {
  margin-top: 14px;
  overflow: hidden;
  box-shadow: none;
}
.data-panel summary {
  padding: 13px 15px;
  font-weight: 900;
  cursor: pointer;
}
.data-panel-body {
  border-top: 1px solid var(--line);
  padding: 14px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.data-panel p { margin: 0; color: var(--muted); line-height: 1.5; font-size: 13px; }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.file-btn { position: relative; overflow: hidden; display: inline-flex; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.import-help { display: none; }

.detail-dialog {
  width: min(780px, calc(100% - 24px));
  max-height: min(86vh, 820px);
  overflow: auto;
  color: var(--text);
  padding: 18px;
}
.detail-dialog::backdrop { background: rgba(2, 6, 23, .58); backdrop-filter: blur(4px); }
.dialog-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#closeDialog {
  border: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 24px;
}
.detail-code { font-size: 40px; line-height: 1; margin: 14px 0 7px; color: var(--accent); font-weight: 900; }
.detail-title { margin-bottom: 10px; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 14px 0;
}
.detail-grid div { border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.detail-grid span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; margin-bottom: 4px; }
.detail-section { margin-top: 14px; }
.detail-section h3 { margin-bottom: 6px; }
.detail-section p,
.detail-section li { color: var(--muted); line-height: 1.6; }
.lineage-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lineage-list button,
.lineage-list strong {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 9px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
.lineage-list button { color: var(--accent); font-weight: 900; }
.lineage-list span { color: var(--muted); }
.related-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }
.related-list button { border: 1px solid var(--line); border-radius: 999px; background: var(--surface); padding: 8px 10px; color: var(--accent); }
.mini-tree ul { list-style: none; margin: 8px 0 0 12px; padding-left: 12px; border-left: 1px solid var(--line); }
.mini-tree li { margin: 7px 0; }
.mini-tree button {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 9px;
  text-align: left;
}
.mini-tree button:hover { border-color: var(--accent); }
.mini-tree button span { border-radius: 9px; background: var(--accent-soft); color: var(--accent); padding: 5px 7px; font-weight: 900; }
.mini-tree button small { color: var(--muted); }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 760px) {
  main, .nav-wrap { width: min(100% - 18px, 920px); }
  .hero { display: block; }
  .mini-stats { justify-content: flex-start; margin-top: 12px; }
  .finder-card { position: static; }
  .simple-filters { grid-template-columns: 1fr 1fr; }
  .sort-control { display: none !important; }
  .reset-btn { height: 40px; }
  .quick-tags { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .quick-tags button { white-space: nowrap; }
  .category-list { grid-template-columns: 1fr; }
  .results-toolbar,
  .data-panel-body { align-items: stretch; flex-direction: column; }
  .toolbar-actions { justify-content: flex-start; }
  .result-card { grid-template-columns: 1fr; }
  .card-actions { justify-content: flex-start; }
  .detail-grid { grid-template-columns: 1fr; }
  .tree-node { margin-left: calc(var(--depth, 0) * 7px); }
  .tree-node summary > button { display: none; }
}

@media (max-width: 460px) {
  .brand small { display: none; }
  .nav-actions a { display: none; }
  h1 { font-size: 38px; }
  .search-box input { height: 54px; font-size: 16px; }
  .simple-filters { grid-template-columns: 1fr; }
}
