:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #14181f;
  --muted: #5c6675;
  --line: #dfe3e9;
  --accent: #2b5bd7;
  --accent-ink: #ffffff;
  --official: #16794c;
  --internal: #4a5568;
  --bespoke: #a83232;
  --draft: #9a6400;
  --mark: #ffe9a8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319; --panel: #171c24; --ink: #e7eaef; --muted: #9aa4b2;
    --line: #2a323d; --accent: #6f9bff; --accent-ink: #0b0f14;
    --official: #4ecb8f; --internal: #a2adbd; --bespoke: #ff8080; --draft: #f0b429;
    --mark: #6b5510; --shadow: none;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
h1, h2, h3, h4 { margin: 0; font-weight: 620; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.hidden { display: none !important; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .8rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand h1 { font-size: 1.05rem; letter-spacing: -.01em; }
.brand .sub { font-size: .8rem; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: .75rem; }
.whoami { font-size: .78rem; color: var(--muted); }

.btn {
  font: inherit; font-size: .87rem; padding: .45rem .85rem; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; }
.btn.small { font-size: .8rem; padding: .3rem .6rem; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }

.banner {
  padding: .6rem 1.25rem; font-size: .85rem; background: #eef3ff;
  border-bottom: 1px solid var(--line); color: var(--ink);
}
.banner.warn { background: #fff6e5; }
@media (prefers-color-scheme: dark) {
  .banner { background: #1b2436; } .banner.warn { background: #33290f; }
}
.progress { height: 4px; background: var(--line); border-radius: 3px; margin-top: .4rem; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

main { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1.25rem; padding: 1.25rem; align-items: start; }
@media (max-width: 820px) { main { grid-template-columns: 1fr; } }

.filters {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem; box-shadow: var(--shadow); position: sticky; top: 68px;
}
.filter-group { margin-bottom: 1rem; }
.filter-label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .4rem; }
.check { display: flex; align-items: center; gap: .45rem; font-size: .88rem; padding: .12rem 0; cursor: pointer; }
.check .cnt { margin-left: auto; color: var(--muted); font-size: .78rem; }
.bespoke-toggle { color: var(--bespoke); font-weight: 560; }
.hint { font-size: .74rem; color: var(--muted); margin: .35rem 0 0; }
.filters select, .filters input[type=number], .filters input[type=date] {
  width: 100%; font: inherit; font-size: .85rem; padding: .35rem .45rem;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink);
}
.row { display: flex; gap: .4rem; }

.searchbar { display: flex; gap: .5rem; }
#q {
  flex: 1; font: inherit; font-size: 1rem; padding: .6rem .8rem;
  border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--ink);
}
#q:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#sort { font: inherit; font-size: .85rem; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--ink); padding: 0 .5rem; }
.searchhint { font-size: .74rem; color: var(--muted); margin: .4rem 0 .2rem; }
.result-meta { font-size: .82rem; color: var(--muted); margin: .5rem 0; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: .85rem 1rem; margin-bottom: .6rem; box-shadow: var(--shadow);
}
.card h3 { font-size: 1rem; margin-bottom: .25rem; }
.card h3 a { color: inherit; text-decoration: none; cursor: pointer; }
.card h3 a:hover { text-decoration: underline; }
.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin: .3rem 0; }
.badge {
  font-size: .7rem; font-weight: 640; letter-spacing: .02em; text-transform: uppercase;
  padding: .12rem .45rem; border-radius: 5px; border: 1px solid currentColor;
}
.badge.official { color: var(--official); }
.badge.internal { color: var(--internal); }
.badge.bespoke  { color: var(--bespoke); background: color-mix(in srgb, var(--bespoke) 12%, transparent); }
.badge.draft    { color: var(--draft); background: color-mix(in srgb, var(--draft) 15%, transparent); }
.badge.plain    { color: var(--muted); }
.badge.broken   { color: var(--bespoke); }
.snippet { font-size: .88rem; color: var(--ink); margin: .35rem 0 .2rem; }
.snippet .where { color: var(--muted); font-size: .8rem; display: block; margin-bottom: .1rem; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 .1em; }
.card .meta { font-size: .76rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .8rem; margin-top: .35rem; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty h2 { font-size: 1.1rem; color: var(--ink); margin-bottom: .5rem; }
.pager { display: flex; align-items: center; gap: .8rem; justify-content: center; padding: .8rem; font-size: .82rem; color: var(--muted); }

.detail { padding: 1.25rem; max-width: 900px; margin: 0 auto; }
.detail .back { margin-bottom: .8rem; }
.detail .head { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.15rem; box-shadow: var(--shadow); }
.detail h2 { font-size: 1.35rem; }
.detail .prose { font-size: .92rem; }
.detail .prose p { margin: .5rem 0; }
.detail section { margin-top: 1.1rem; }
.detail h3 { font-size: .95rem; margin-bottom: .5rem; }
.inject { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .9rem 1.05rem; margin-bottom: .7rem; box-shadow: var(--shadow); }
.inject .ord { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.inject h4 { font-size: .98rem; margin: .1rem 0 .4rem; }
.option { border-left: 3px solid var(--line); padding: .4rem 0 .4rem .7rem; margin: .5rem 0; }
.option .otitle { font-weight: 600; font-size: .9rem; }
.option .feedback { font-size: .84rem; color: var(--muted); margin-top: .2rem; }
.option .target { font-size: .76rem; color: var(--muted); margin-top: .2rem; }
.feeditem { font-size: .84rem; border-top: 1px dashed var(--line); padding-top: .4rem; margin-top: .4rem; }
.feeditem .fmeta { color: var(--muted); font-size: .76rem; }
details.feedwrap { margin-top: .5rem; }
details.feedwrap > summary { cursor: pointer; font-size: .8rem; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; font-size: .85rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
ul.plain { margin: .3rem 0; padding-left: 1.1rem; font-size: .9rem; }

/* ---- AI layer ---- */
.mode-switch { display: inline-flex; gap: .2rem; padding: .2rem; margin-bottom: .5rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.mode-btn { font: inherit; font-size: .82rem; padding: .3rem .7rem; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; }
.mode-btn.active { background: var(--accent); color: var(--accent-ink); font-weight: 560; }
.ai-interp { font-size: .84rem; color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: .55rem .75rem; margin: .5rem 0; }
.ai-interp strong { color: var(--ink); }
.ai-interp .plan { display: block; margin-top: .3rem; font-size: .76rem; }
.badge.kw { color: var(--internal); }
.badge.sem { color: var(--accent); }
.badge.both { color: var(--official); }
.snippet .where .semlabel { font-style: italic; }
.ai-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: .95rem 1.1rem; box-shadow: var(--shadow); }
.ai-panel .pitch { font-size: .98rem; }
.ai-panel h4 { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin: .9rem 0 .3rem; }
.ai-panel ul { margin: .2rem 0; padding-left: 1.1rem; font-size: .9rem; }
.ai-panel .chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.ai-panel .chip { font-size: .74rem; padding: .12rem .5rem; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); }
.ai-panel .prov { font-size: .74rem; color: var(--muted); margin-top: .8rem;
  border-top: 1px solid var(--line); padding-top: .5rem; }
.ai-panel .caution { color: var(--draft); }
.spinner { display: inline-block; width: .8em; height: .8em; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -.1em; margin-right: .4rem; }
@keyframes spin { to { transform: rotate(360deg); } }

.why { font-size: .86rem; margin: .45rem 0 .1rem; padding: .4rem .6rem; border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border-left: 3px solid var(--accent); }
.why .lab { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 660; margin-right: .4rem; }
.why.strong  { border-left-color: var(--official); background: color-mix(in srgb, var(--official) 8%, transparent); }
.why.strong .lab  { color: var(--official); }
.why.partial { border-left-color: var(--draft);   background: color-mix(in srgb, var(--draft) 9%, transparent); }
.why.partial .lab { color: var(--draft); }
.why.weak    { border-left-color: var(--line);    background: transparent; color: var(--muted); }
.why.weak .lab    { color: var(--muted); }
