:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1d1f24;
  --muted: #676b75;
  --border: #dcd9d0;
  --accent: #1f4e8c;
  --accent-text: #ffffff;
  --star: #c98a00;
  --ins-bg: #d8f3dc;
  --ins-text: #0f5132;
  --del-bg: #fbdcdc;
  --del-text: #842029;
  --changed: #8a5a00;
  --changed-bg: #fff1cf;
  --new: #0b6b3a;
  --new-bg: #d9f5e5;
  --removed: #9b1c1c;
  --removed-bg: #fde4e4;
  --mark: #fff0a8;
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1d2026;
    --surface-2: #252932;
    --text: #e6e7ea;
    --muted: #9aa0ab;
    --border: #343944;
    --accent: #7aa7e6;
    --accent-text: #0e1420;
    --star: #f0b429;
    --ins-bg: #173d29;
    --ins-text: #a7e3bd;
    --del-bg: #4a1f24;
    --del-text: #f4b8bd;
    --changed: #f0c36b;
    --changed-bg: #3d3115;
    --new: #8fe0b0;
    --new-bg: #173d29;
    --removed: #f4a3a3;
    --removed-bg: #4a1f24;
    --mark: #5b4d12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2em 0 .4em; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; }
h3 { font-size: 1rem; margin: 1.2em 0 .5em; }
code { font-family: var(--mono); font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }

/* ---- layout ---- */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .55rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; letter-spacing: .01em; }
.topbar nav { display: flex; gap: .15rem; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); padding: .3rem .6rem; border-radius: 6px; }
.topbar nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topbar nav a.on { color: var(--text); background: var(--surface-2); font-weight: 600; }
.topsearch { flex: 1; min-width: 180px; max-width: 360px; margin-left: auto; }
.topsearch input { width: 100%; }
.me { display: flex; gap: .75rem; align-items: center; }
.me form { margin: 0; }
main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1.25rem 3rem; }
main.narrow { max-width: 560px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1.25rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card { margin-top: 1.25rem; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.pagehead-actions { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.crumbs { margin: 0; color: var(--muted); font-size: .9rem; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .15rem 0; }

/* ---- forms ---- */
input, select, button, textarea { font: inherit; color: inherit; }
input:not([type=checkbox]), select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .35rem .55rem; min-height: 2.1rem;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .35rem .8rem; cursor: pointer; min-height: 2.1rem;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.linkish { background: none; border: none; padding: 0; min-height: 0; color: var(--accent); cursor: pointer; }
button.linkish:hover { text-decoration: underline; }
button.danger, .danger { color: var(--removed); }
.filters { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: flex-end; margin: .5rem 0 1rem; }
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); }
.filters label.grow { flex: 1 1 280px; }
.memo-edit { display: flex; gap: .4rem; align-items: flex-end; }
.memo-edit textarea { min-width: 12rem; flex: 1; font: inherit; resize: vertical; }
details.memo summary { cursor: pointer; }
details.memo[open] summary { margin-bottom: .5rem; }
.filters label.check, label.check { flex-direction: row; align-items: center; gap: .4rem; color: var(--text); font-size: .9rem; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.stack label { display: flex; flex-direction: column; gap: .25rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .9rem .8rem; display: flex; flex-direction: column; gap: .6rem; }
legend { padding: 0 .3rem; font-weight: 600; }
.watcher-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem 1rem; }
.watcher-form label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.watcher-form .buttons { grid-column: 1 / -1; display: flex; gap: .75rem; align-items: center; }
.login { margin-top: 12vh; }

/* ---- tables ---- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
.card table { background: transparent; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
table.compact td, table.compact th { padding: .3rem .5rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.actions { white-space: nowrap; }
td.actions form, td.actions a { display: inline-block; margin-right: .6rem; }
tr.removed td, tr.disabled td { opacity: .6; }
tr.future td:first-child a { font-weight: 600; }
tr.hasnew td { background: var(--new-bg); }
tr.sel td { background: var(--surface-2); }
tr.sub td { background: var(--surface-2); }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

/* ---- badges ---- */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .05rem .45rem; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.badge.changed { background: var(--changed-bg); color: var(--changed); }
.badge.new { background: var(--new-bg); color: var(--new); }
.badge.removed { background: var(--removed-bg); color: var(--removed); }
.badge.ok { background: var(--new-bg); color: var(--new); }
a.badge:hover { text-decoration: none; filter: brightness(.95); }
.chip { display: inline-block; font-size: .8rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 .5rem; margin: .1rem 0; }
.flash { padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; background: var(--new-bg); color: var(--new); }
.flash.error { background: var(--removed-bg); color: var(--removed); }

/* ---- notes ---- */
.note { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1.1rem 1rem; margin-bottom: .9rem; scroll-margin-top: 4.5rem; }
.note:target { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.note.removed { opacity: .65; }
.note.removed .note-body, .note.removed .htitle { text-decoration: line-through; text-decoration-color: var(--muted); }
.note-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: .1rem .45rem; font-size: 1.02rem; }
.note-head .item { font-weight: 700; min-width: 2.2rem; }
.case { font-family: var(--mono); font-weight: 600; font-size: .95em; }
.ctype { color: var(--muted); font-weight: 400; font-size: .9em; }
.ctype-sm { color: var(--muted); font-size: .78em; display: block; }
.note-meta { color: var(--muted); font-size: .88rem; margin: .1rem 0 .4rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.htitle { font-size: .88rem; font-weight: 600; margin: .3rem 0 .5rem; letter-spacing: .01em; }
pre.note-body { font-family: var(--sans); white-space: pre-wrap; word-wrap: break-word; margin: 0; font-size: .95rem; line-height: 1.5; tab-size: 4; }
pre.note-body.diff, .sbs td { font-family: var(--sans); }
ins { background: var(--ins-bg); color: var(--ins-text); text-decoration: none; border-radius: 3px; }
del { background: var(--del-bg); color: var(--del-text); border-radius: 3px; }
.diff-caption, .history-link { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; }
.history-link { margin: -.5rem 0 .9rem .2rem; }
.sbs { table-layout: fixed; }
.sbs td { white-space: pre-wrap; word-wrap: break-word; font-size: .92rem; width: 50%; }
.sbs tr.equal td { color: var(--muted); }
.matter-title { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.result { padding: .7rem 0; border-bottom: 1px solid var(--border); }
.result .htitle { margin: .2rem 0; }
.snippet { margin: .2rem 0 0; font-size: .92rem; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }

/* ---- favorites star ---- */
.star-form { display: inline; margin: 0; }
.star { background: none; border: none; padding: 0 .15rem; min-height: 0; font-size: 1.2rem; line-height: 1; color: var(--muted); cursor: pointer; }
.star.on { color: var(--star); }
.star:hover { color: var(--star); }

/* ---- diff toggle ---- */
.toggle { display: inline-flex; align-items: center; gap: .5rem; color: var(--text); font-size: .9rem; user-select: none; }
.toggle:hover { text-decoration: none; }
.toggle .knob { width: 2.2rem; height: 1.25rem; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; flex: none; }
.toggle .knob::after { content: ""; position: absolute; top: .15rem; left: .15rem; width: .95rem; height: .95rem; border-radius: 50%; background: var(--surface); transition: left .15s; }
.toggle.on .knob { background: var(--accent); }
.toggle.on .knob::after { left: 1.1rem; }
.daynav { display: flex; gap: 1rem; }

@media (max-width: 760px) {
  main { padding: 1rem 16px 2.5rem; }
  .topbar { padding: .5rem 16px; gap: .5rem; }
  .topsearch { order: 5; max-width: none; flex-basis: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  td.clip { max-width: 180px; }
  .note { padding: .7rem .8rem; }
}
