:root {
  --td: "TD-1";
  --bg: #fafaf9; --panel: #fff; --fg: #1c1917; --mute: #57534e; --rule: #e7e5e4;
  --accent: #1f5fbf; --accent-fg: #fff; --sel: #e7effb; --sel-rule: #9db8e3;
  --warn-bg: #fff6e0; --warn-fg: #6b4a00; --chip: #f5f5f4; --danger: #b42318;
  --target: 24px;
  --row: 40px; --radius: 8px;
}
@media (pointer: coarse) { :root { --target: 44px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; } }
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12100e; --panel: #1c1a17; --fg: #e7e5e4; --mute: #b3ada7; --rule: #292524;
    --accent: #5b93e6; --accent-fg: #0b0d10; --sel: #1d2a3d; --sel-rule: #3d5a85;
    --warn-bg: #3a2f12; --warn-fg: #f3d58a; --chip: #26221f; --danger: #f97066;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 1rem/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
.wrap { max-width: 1400px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 18px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 13px; margin: 0 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--mute); }
button { font: inherit; color: inherit; }

.top { background: var(--panel); border-bottom: 1px solid var(--rule); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.lang { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.lang button { border: 0; background: transparent; padding: 5px 10px; cursor: pointer; color: var(--mute); min-height: var(--target); }
.lang button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }

.btn { border: 1px solid var(--rule); background: var(--panel); border-radius: var(--radius); padding: 7px 12px; cursor: pointer; white-space: nowrap; min-height: var(--target); min-width: var(--target); }
.btn:hover { border-color: var(--mute); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 8px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.stats > div { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; min-width: 0; }
.stats b { font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats .fresh b { font-size: 15px; padding-top: 4px; white-space: normal; }
.stats span { color: var(--mute); font-size: 13px; }

.notice { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; color: var(--mute); }
.notice.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: transparent; }
.notice.err { color: var(--danger); }

.help { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.help ul { margin: 0; padding-left: 18px; color: var(--fg); }
.help li { margin: 2px 0; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.1fr); gap: 12px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px; min-width: 0; }
.panel-head { display: block; font-weight: 600; margin-bottom: 8px; }
.panel-head.row { display: flex; justify-content: space-between; align-items: center; }
.cur { color: var(--accent); font-weight: 600; }
input[type="search"] { min-height: var(--target); width: 100%; padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--bg); color: var(--fg); font: inherit; }
.list-meta { color: var(--mute); font-size: 13px; margin: 6px 2px; min-height: 17px; }

.vlist { position: relative; height: min(60vh, 560px); overflow-y: auto; border: 1px solid var(--rule); border-radius: var(--radius); contain: strict; }
.vlist .spacer { position: absolute; top: 0; left: 0; width: 1px; }
.vlist .item, .vlist .group { position: absolute; left: 0; right: 0; height: var(--row); display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--rule); }
.vlist .item { cursor: pointer; }
.vlist .item:hover { background: var(--chip); }
.vlist .item.active { box-shadow: inset 3px 0 0 var(--accent); }
.vlist .item.selected { background: var(--sel); }
.vlist .group { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--mute); background: var(--bg); }
.vlist .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vlist .raw { color: var(--mute); font-size: 13px; margin-left: 6px; }
.vlist .count { font-size: 13px; color: var(--mute); font-variant-numeric: tabular-nums; }
.vlist .check { width: 16px; height: 16px; border: 1.5px solid var(--mute); border-radius: 4px; flex: none; display: grid; place-items: center; font-size: 13px; line-height: 1; }
.vlist .item.selected .check { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.vlist .empty { padding: 16px; color: var(--mute); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: min(52vh, 480px); overflow-y: auto; align-content: flex-start; min-height: 60px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--chip); border: 1px solid var(--rule); border-radius: 999px; padding: 3px 4px 3px 10px; max-width: 100%; }
.chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.chip .k { font-size: 13px; color: var(--mute); }
.chip.missing { border-style: dashed; }
.chip.missing .t::after { content: " ⚠"; color: var(--warn-fg); }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--mute); width: 24px; height: 24px; border-radius: 50%; font-size: 15px; line-height: 1; }
.chip button:hover { background: var(--rule); color: var(--fg); }
.chips .empty { color: var(--mute); }
.io { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.hint { color: var(--mute); font-size: 13px; margin: 10px 0 0; }

dialog { border: 1px solid var(--rule); border-radius: 12px; background: var(--panel); color: var(--fg); max-width: min(520px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { text-transform: none; letter-spacing: 0; font-size: 16px; color: var(--fg); }
.details { color: var(--mute); padding-left: 18px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); max-width: calc(100vw - 32px); z-index: 10; }
.foot { color: var(--mute); font-size: 13px; padding-top: 16px; padding-bottom: 24px; }
.foot p { margin: 4px 0; }

@media (max-width: 1100px) {
  .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .selected-panel { grid-column: 1 / -1; }
  .help { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .grid, .help { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .vlist { height: 50vh; }
}
