:root {
  --bg: #f5f6f7;
  --panel: #fff;
  --text: #1f2329;
  --muted: #646a73;
  --faint: #8f959e;
  --line: #e4e6e9;
  --accent: #8b4513;
  --primary: #3d8a7a;
  --chip: #f0f1f2;
  --hover: #eef0f2;
  --chip-on: #33373d;
  --chip-on-text: #fff;
  --shadow: 0 1px 2px rgba(31, 35, 41, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --panel: #212225;
    --text: #e8e9eb;
    --muted: #a6abb3;
    --faint: #7c818a;
    --line: #34363a;
    --accent: #c0743c;
    --primary: #4fa592;
    --chip: #2c2e32;
    --hover: #2a2c30;
    --chip-on: #e8e9eb;
    --chip-on-text: #17181a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.n { color: var(--faint); font-size: 12px; font-weight: 400; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 56px; padding: 0 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h1 { margin: 0; font-size: 18px; white-space: nowrap; }
.subtitle, .updated { color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.updated { flex-shrink: 0; }
.sections { display: flex; gap: 2px; min-width: 0; padding: 2px; border-radius: 8px; background: var(--chip); overflow-x: auto; }
.sections button { padding: 4px 12px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 13px; white-space: nowrap; }
.sections button:hover { color: var(--text); }
.sections button.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
  padding: 16px; background: var(--panel); border-right: 1px solid var(--line);
}
.content { width: 100%; max-width: 1120px; margin: 0 auto; padding: 16px 24px 48px; min-width: 0; }

#search { width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
#search:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.facet { padding: 14px 0; border-bottom: 1px solid var(--line); }
.facet:last-child { border-bottom: 0; }
.facet-head { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.facet-clear { padding: 0; border: 0; background: none; color: var(--muted); font-size: 12px; }
.facet-clear:hover { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border: 1px solid transparent; border-radius: 6px;
  background: var(--chip); font-size: 12px; line-height: 1.5; text-align: left;
}
.chip:hover { background: var(--hover); }
.chip .n { font-size: 11px; }
.chip.on { background: var(--chip-on); color: var(--chip-on-text); }
.chip.on .n { color: inherit; opacity: .75; }
.chip.zero { opacity: .45; }
.list { display: flex; flex-direction: column; gap: 2px; }
.list button { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border: 0; border-radius: 6px; background: none; text-align: left; }
.list button:hover { background: var(--hover); }
.list button.on { background: var(--accent); color: #fff; font-weight: 600; }
.list button.on .n { color: rgba(255, 255, 255, .8); }

.result-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; }
.match { color: var(--muted); }
.match b { color: var(--text); }
.result-actions { display: flex; align-items: center; gap: 12px; }
.result-actions select { height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.link-btn { padding: 0; border: 0; background: none; color: var(--primary); }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.active-filters:empty { display: none; }
.active-filters .chip { background: var(--panel); border-color: var(--line); }

.hint { margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; background: var(--chip); color: var(--muted); font-size: 12px; }
.hint b { color: var(--text); font-weight: 600; }
.legend { display: grid; gap: 14px; margin-top: 8px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 12px; }
.legend h3 { margin: 0 0 4px; color: var(--text); font-size: 13px; }
.legend p { margin: 0; }
.legend dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 0 0 6px; }
.legend dt { color: var(--text); font-weight: 600; }
.legend dd { margin: 0; }
.map { margin-bottom: 4px; }
#map { margin-bottom: 16px; }
.map summary { padding: 6px 0; font-weight: 600; cursor: pointer; list-style: none; }
.map summary::-webkit-details-marker { display: none; }
.map summary::before { content: "›"; display: inline-block; width: 16px; transition: transform .15s; }
.map[open] summary::before { transform: rotate(90deg); }
.map-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px;
  margin-top: 8px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.map-col h3 { margin: 0 0 6px; padding: 0 6px; font-size: 13px; }
.map-col ul { margin: 0; padding: 0; list-style: none; }
.map-col li button {
  display: flex; justify-content: space-between; gap: 8px; width: 100%;
  padding: 3px 6px; border: 0; border-radius: 5px; background: none; color: var(--muted); font-size: 12px; text-align: left;
}
.map-col li button:hover { background: var(--hover); color: var(--text); }
.map-col li button.on { background: var(--chip); color: var(--text); font-weight: 600; }

.card { margin-bottom: 12px; padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.card h2 { margin: 0; font-size: 16px; line-height: 1.45; }
.card h2 a { color: inherit; text-decoration: none; }
.card h2 a:hover { text-decoration: underline; }
.card-actions { display: flex; flex-shrink: 0; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; height: 28px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
  color: inherit; font-size: 12px; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary); filter: brightness(1.08); }
.meta { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.meta .award { color: var(--accent); font-weight: 600; }
.summary { margin: 8px 0 0; }
.rows { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 6px 10px; margin-top: 10px; }
.rows .k { padding-top: 2px; color: var(--muted); font-size: 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 1px 8px; border: 0; border-radius: 5px; background: var(--tag-bg); color: var(--tag-fg); font-size: 12px; line-height: 1.6; }
.tag:hover { filter: brightness(.96); }
.details { margin-top: 10px; }
.details summary { color: var(--muted); font-size: 12px; cursor: pointer; list-style: none; }
.details summary::-webkit-details-marker { display: none; }
.details summary::after { content: " ⌄"; }
.details[open] summary::after { content: " ⌃"; }
.note { margin-top: 10px; }
.note h4 { margin: 0 0 2px; color: var(--muted); font-size: 12px; font-weight: 600; }
.note p { margin: 0; white-space: pre-wrap; }

.pager { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; margin-top: 16px; }
.pager:empty { display: none; }
.pager button { min-width: 34px; height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.pager button:hover:not(:disabled) { background: var(--hover); }
.pager button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager span { margin-left: 8px; color: var(--muted); font-size: 12px; }
.empty { padding: 40px 0; color: var(--muted); text-align: center; }
.empty small { display: block; margin-top: 4px; color: var(--faint); font-size: 12px; }

.hue-Blue      { --tag-bg: #bacefd; --tag-fg: #245bdb; }
.hue-Wathet    { --tag-bg: #b1e8fc; --tag-fg: #037eaa; }
.hue-Turquoise { --tag-bg: #a9efe6; --tag-fg: #067365; }
.hue-Green     { --tag-bg: #b7edb1; --tag-fg: #237b19; }
.hue-Lime      { --tag-bg: #dfee96; --tag-fg: #5c7a00; }
.hue-Yellow    { --tag-bg: #f8e6ab; --tag-fg: #8f6b00; }
.hue-Orange    { --tag-bg: #fed4a4; --tag-fg: #b24a00; }
.hue-Red       { --tag-bg: #fbbfbc; --tag-fg: #c02a26; }
.hue-Carmine   { --tag-bg: #f9bbdc; --tag-fg: #b4237b; }
.hue-Purple    { --tag-bg: #cdb2fa; --tag-fg: #6425d0; }
.hue-Gray      { --tag-bg: #dee0e3; --tag-fg: #646a73; }
@media (prefers-color-scheme: dark) {
  .tag { background: color-mix(in srgb, var(--tag-fg) 22%, transparent); color: color-mix(in srgb, var(--tag-fg) 45%, #fff); }
}

.only-mobile, .scrim { display: none; }
@media (max-width: 860px) {
  .only-mobile { display: initial; }
  .topbar { padding: 0 16px; }
  .subtitle, .updated { display: none; }
  .icon-btn { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); white-space: nowrap; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; z-index: 30;
    width: min(320px, 86vw); height: auto;
    transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 16px rgba(0, 0, 0, .12);
  }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 56px 0 0; z-index: 25; background: rgba(0, 0, 0, .3); }
  .scrim.open { display: block; }
  .content { padding: 12px 16px 40px; }
  .card { padding: 14px 16px; }
  .card-head { flex-direction: column; gap: 10px; }
  .rows { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .rows .k { padding-top: 6px; }
  .legend dl { grid-template-columns: minmax(0, 1fr); }
  .legend dd { margin-bottom: 4px; }
}
@media (max-width: 480px) {
  .topbar h1 { display: none; }
  .sections button { padding: 4px 8px; }
  .sections .n { display: none; }
}
