:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  --seq-0: #cde2fb; --seq-1: #86b6ef; --seq-2: #3987e5; --seq-3: #1c5cab; --seq-4: #0d366b;
  --accent: #2a78d6;
  --mark: rgba(42, 120, 214, 0.18);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10); --wash: rgba(255, 255, 255, 0.06);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --seq-0: #1d2a3a; --seq-1: #184f95; --seq-2: #2a78d6; --seq-3: #6da7ec; --seq-4: #cde2fb;
    --accent: #3987e5; --mark: rgba(57, 135, 229, 0.28);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10); --wash: rgba(255, 255, 255, 0.06);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --seq-0: #1d2a3a; --seq-1: #184f95; --seq-2: #2a78d6; --seq-3: #6da7ec; --seq-4: #cde2fb;
  --accent: #3987e5; --mark: rgba(57, 135, 229, 0.28);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
button, select, input { font: inherit; color: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1440px; margin: 0 auto; padding: 24px 24px 8px;
}
.top h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; }
.top p { margin: 2px 0 0; }
.ghost {
  background: none; border: 1px solid var(--ring); border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.ghost:hover { background: var(--wash); }

.filters {
  position: sticky; top: 0; z-index: 5; background: var(--page);
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start;
  max-width: 1440px; margin: 0 auto; padding: 12px 24px; border-bottom: 1px solid var(--ring);
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.field.grow { flex: 1; min-width: 0; }
.field select {
  background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 6px 8px; min-width: 140px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px;
  border: 1px solid var(--ring); background: var(--surface); cursor: pointer; font-size: 13px; color: var(--ink);
}
.chip img, .chip .dot { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; background: var(--grid); }
.chip.all { padding-left: 10px; }
.chip:hover { background: var(--wash); }
.chip[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chip .key { width: 12px; height: 3px; border-radius: 2px; }

.tabs {
  display: flex; gap: 4px; overflow-x: auto; max-width: 1440px; margin: 0 auto; padding: 12px 24px 0;
}
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer;
  color: var(--ink-2); white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

main { max-width: 1440px; margin: 0 auto; padding: 16px 24px 32px; }
[data-panel] { display: none; }
[data-panel].on { display: block; }
main.loading .card { opacity: 0.55; transition: opacity 0.15s; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 12px 14px; }
.tile .v { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.tile .k { font-size: 13px; color: var(--ink-2); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 560px), 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 14px 16px 12px;
  min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.card > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card h3 { margin: 0; font-size: 15px; }
.card .sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.card .tools { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.card .tools button, .card .tools select {
  background: none; border: 1px solid var(--ring); border-radius: 6px; padding: 2px 8px; font-size: 12px; cursor: pointer;
  color: var(--ink-2);
}
.card .tools select { background: var(--surface); }
.chart { width: 100%; height: 360px; margin-top: 8px; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }
.tablewrap { max-height: 420px; overflow: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 600; cursor: pointer; user-select: none; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: var(--wash); }

.sigs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 10px; }
.sig { border: 1px solid var(--grid); border-radius: 10px; padding: 10px; }
.sig h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 14px; }
.sig h4 img { width: 24px; height: 24px; border-radius: 50%; }
.sig .w { display: inline-block; margin: 0 4px 4px 0; padding: 1px 8px; border-radius: 999px; background: var(--wash); font-size: 13px; }

.search { display: flex; gap: 8px; margin-bottom: 6px; }
.search input { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--ring); border-radius: 10px; background: var(--surface); }
.search button { padding: 9px 16px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; cursor: pointer; }
.kwic { list-style: none; margin: 8px 0 0; padding: 0; max-height: 560px; overflow: auto; }
.kwic li { padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.kwic .meta { font-size: 12px; color: var(--muted); }
.kwic mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }

.hovercard { font-size: 13px; line-height: 1.4; }
.hovercard b { font-size: 14px; }

footer { max-width: 1440px; margin: 0 auto; padding: 0 24px 32px; }

@media (max-width: 640px) {
  .top, .filters, .tabs, main, footer { padding-left: 16px; padding-right: 16px; }
  .filters { position: static; }
  .chart { height: 320px; }
  .tile .v { font-size: 22px; }
}
@media (forced-colors: active) {
  .chip[aria-pressed="true"] { outline: 2px solid CanvasText; }
}
