:root {
  --bg: #fbfaf7; --fg: #1d1c1a; --quiet: #6b6760; --line: #dcd8cf; --panel: #f1eee7;
  --link: #1b5aa6; --bad: #b3261e; --bad-bg: #fbe9e7; --tag: #e6e1d6;
  --sel: #dfe9f7; --cursor: #1b5aa6; --staged: #1b5aa6; --ok: #2d6a3e; --add-bg: #e3f2e6; --del-bg: #fbe4e1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513; --fg: #e8e5de; --quiet: #9a958b; --line: #34312c; --panel: #1f1d1a;
    --link: #7fb0ec; --bad: #ff8a80; --bad-bg: #3a1f1c; --tag: #2b2824;
    --sel: #26364d; --cursor: #7fb0ec; --staged: #7fb0ec; --ok: #7fcf96; --add-bg: #1c3324; --del-bg: #3a1f1c;
  }
}
:root[data-theme="dark"] {
  --bg: #161513; --fg: #e8e5de; --quiet: #9a958b; --line: #34312c; --panel: #1f1d1a;
  --link: #7fb0ec; --bad: #ff8a80; --bad-bg: #3a1f1c; --tag: #2b2824;
  --sel: #26364d; --cursor: #7fb0ec; --staged: #7fb0ec; --ok: #7fcf96; --add-bg: #1c3324; --del-bg: #3a1f1c;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { display: flex; flex-direction: column; margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 system-ui, sans-serif; }
a { color: var(--link); }
code { font-family: ui-monospace, monospace; }
header { display: flex; gap: 16px; align-items: baseline; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); }
header .repo, header .git { color: var(--quiet); }
header nav { margin-left: auto; display: flex; gap: 4px; }
.tab { padding: 4px 12px; border-radius: 6px; text-decoration: none; color: var(--fg); }
.tab.on { background: var(--panel); border: 1px solid var(--line); }
main { flex: 1; min-height: 0; overflow: auto; padding: 12px 16px; }
main.fill { overflow: hidden; display: flex; flex-direction: column; }
main.fill > .split { flex: 1; min-height: 0; }
.quiet { color: var(--quiet); }
.fail, .bad { color: var(--bad); }
.split { display: flex; gap: 20px; align-items: flex-start; }
aside { flex: 0 0 200px; position: sticky; top: 8px; }
aside ul, ul.plain { list-style: none; margin: 0; padding: 0; }
aside li { padding: 3px 8px; border-radius: 6px; display: flex; gap: 6px; align-items: baseline; }
aside li.on { background: var(--panel); }
aside a { flex: 1; color: var(--fg); text-decoration: none; }
.n { color: var(--quiet); font-size: 12px; }
.n.bad { color: var(--bad); }
section { flex: 1; min-width: 0; }
.filter { width: min(420px, 100%); padding: 6px 8px; margin: 4px 0 10px; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid var(--line); }
thead th { position: sticky; top: 0; background: var(--panel); font-size: 12px; text-transform: none; white-space: nowrap; }
td { min-width: 120px; max-width: 420px; }
td.id { min-width: 160px; font-family: ui-monospace, monospace; font-size: 13px; }
td.file { color: var(--quiet); font-size: 12px; white-space: nowrap; }
td.bad, tr.bad td { background: var(--bad-bg); }
.text { white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
table.detail .text { display: block; -webkit-line-clamp: unset; }
.list { margin: 0; padding-left: 16px; }
.refs { display: flex; flex-wrap: wrap; gap: 4px 8px; }
a.ref { font-family: ui-monospace, monospace; font-size: 12px; }
a.ref.dangling { color: var(--bad); text-decoration: line-through; }
.why { margin: 4px 0 0; padding-left: 14px; color: var(--bad); font-size: 12px; }
table.detail th { width: 160px; font-weight: 600; white-space: nowrap; }
.chat { max-width: 820px; }
.msg { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0 0 8px; background: var(--panel); }
.msg .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; color: var(--quiet); }
.msg .meta strong { color: var(--fg); }
.msg .when { margin-left: auto; font-size: 12px; }
.tag { background: var(--tag); border-radius: 4px; padding: 0 6px; font-size: 12px; }
.msg .body { white-space: pre-wrap; margin-top: 4px; }
@media (max-width: 720px) {
  .split { flex-direction: column; }
  aside { position: static; flex-basis: auto; width: 100%; }
}
.mode { margin: 0; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); color: var(--quiet); }
header button, .editor button, .changes button, .connect button, section button { font: inherit; background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; cursor: pointer; }
header button:disabled, .changes button:disabled { opacity: 0.5; cursor: default; }
button.small { padding: 0 8px; font-size: 12px; }
td.staged, tr.staged td, tr.staged th { box-shadow: inset 3px 0 0 var(--link); }
.edit { margin-top: 4px; }
.editor { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.editbox { width: min(560px, 100%); font: inherit; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.newrow { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; background: var(--panel); }
.newrow .field { display: flex; flex-direction: column; gap: 2px; width: 100%; }
.filter.wide { width: min(720px, 100%); }
.changes ol { padding-left: 20px; }
.done { border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px; background: var(--panel); }
.connect { max-width: 680px; }
.connect label { display: inline-block; margin: 4px 0; }

/* Keyboard focus is always visible. */
:focus-visible { outline: 2px solid var(--cursor); outline-offset: 1px; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }
header { align-items: center; }
header .tools { display: flex; gap: 6px; align-items: center; }
header nav { margin-left: 8px; }
.mode.past { border-left: 3px solid var(--staged); }
.subtabs { display: flex; gap: 4px; margin: 0 0 10px; }
.subtab { padding: 3px 10px; border-radius: 6px; text-decoration: none; color: var(--fg); border: 1px solid transparent; }
.subtab.on { background: var(--panel); border-color: var(--line); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 6px; }
.toolbar h2 { margin: 0 8px 0 0; font-size: 17px; }
.toolbar .filter { margin: 0; width: min(260px, 100%); }
.toolbar .count, .statusbar .note { color: var(--quiet); font-size: 12px; }
.check { font-size: 13px; color: var(--quiet); display: inline-flex; gap: 4px; align-items: center; }
.badn { color: var(--bad); }

/* The grid. */
.gridwrap { flex: 1; min-height: 0; display: flex; gap: 12px; }
.gridcol { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sheet { flex: 1; min-height: 120px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; position: relative; background: var(--bg); font-size: 13px; }
.sheet:focus-visible { outline: 2px solid var(--cursor); outline-offset: 0; }
.sheet .content { position: relative; }
.sheet .row { position: absolute; left: 0; display: flex; height: 24px; }
.sheet .headrow { top: 0; z-index: 3; position: sticky; height: 24px; }
.sheet .filterrow { position: sticky; z-index: 3; height: 24px; }
.sheet .cell { height: 24px; line-height: 23px; padding: 0 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--bg); position: relative; user-select: none; }
.sheet .cell.mono { font-size: 12px; }
.sheet .cell .t { pointer-events: none; }
.sheet .cell.frozen { position: sticky; z-index: 2; box-shadow: 1px 0 0 var(--line); }
.sheet .cell.rownum { position: sticky; left: 0; z-index: 2; text-align: right; color: var(--quiet); background: var(--panel); font-size: 11px; padding: 0 4px; }
.sheet .cell.rownum.cur, .sheet .cell.head.cur { color: var(--fg); font-weight: 600; background: var(--sel); }
.sheet .cell.head { background: var(--panel); font-weight: 600; font-size: 12px; display: flex; align-items: center; gap: 4px; cursor: default; }
.sheet .cell.head .label { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.sheet .cell.head .sort { all: unset; cursor: pointer; font-size: 10px; color: var(--quiet); padding: 0 3px; border-radius: 3px; }
.sheet .cell.head .sort:hover { background: var(--line); color: var(--fg); }
.sheet .cell.head .grip { position: absolute; right: 0; top: 0; bottom: 0; width: 5px; cursor: col-resize; }
.sheet .cell.head .grip:hover { background: var(--cursor); }
.sheet .cell.filter { padding: 0; background: var(--panel); }
.sheet .colfilter { width: 100%; height: 100%; border: 0; padding: 0 6px; background: transparent; color: var(--fg); font: inherit; font-size: 12px; }
.sheet .cell.sel { background: var(--sel); }
.sheet .cell.bad { background: var(--bad-bg); color: var(--bad); }
.sheet .cell.sel.bad { background: var(--sel); color: var(--bad); }
.sheet .cell.staged { box-shadow: inset 3px 0 0 var(--staged); }
.sheet .cell.cursor { outline: 2px solid var(--cursor); outline-offset: -2px; z-index: 1; overflow: visible; }
.sheet .cell.cursor.frozen { z-index: 2; }
.sheet .empty { position: absolute; left: 16px; color: var(--quiet); margin: 0; }
.editor { position: relative; }
.sheet .editor { position: absolute; left: -2px; top: -2px; z-index: 6; min-width: calc(100% + 4px); }
.sheet .editbox { width: 100%; min-width: 220px; margin: 0; font: inherit; font-size: 13px; padding: 2px 6px; background: var(--bg); color: var(--fg); border: 2px solid var(--cursor); border-radius: 0; resize: vertical; white-space: pre; line-height: 18px; }
.sheet .editor textarea.editbox[rows="1"] { height: 28px; resize: none; overflow: hidden; }
.editerr { background: var(--bad-bg); color: var(--bad); border: 1px solid var(--bad); padding: 2px 6px; font-size: 12px; white-space: normal; max-width: 420px; line-height: 1.3; }
.statusbar { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; padding: 3px 4px; font-size: 12px; color: var(--quiet); min-height: 24px; }
.statusbar .addr { color: var(--fg); }
.panel { flex: 0 0 min(420px, 40%); overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; background: var(--panel); }
.panelhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.panel table.detail th { width: 110px; white-space: normal; }

/* Lists with a keyboard cursor. */
.keylist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 6px; max-height: none; }
.keylist:focus-visible { outline-offset: 0; }
.keylist .item { display: flex; gap: 10px; align-items: baseline; padding: 4px 10px; border-bottom: 1px solid var(--line); }
.keylist .item:last-child { border-bottom: 0; }
.keylist .item.active { background: var(--sel); box-shadow: inset 3px 0 0 var(--cursor); }
.keylist .main { flex: 1; min-width: 0; }
.keylist .main a { color: var(--fg); text-decoration: none; font-weight: 500; }
.keylist .main a:hover { text-decoration: underline; }
.keylist .badge { flex: 0 0 auto; min-width: 56px; font-size: 11px; color: var(--quiet); }
.keylist .meta { flex: 0 0 auto; font-size: 12px; color: var(--quiet); }
.keylist .snippet { font-size: 12px; color: var(--quiet); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.keylist .item.bad .main a, .keylist .item.bad .badge { color: var(--bad); }
.keylist .item.ok .badge { color: var(--ok); }
mark { background: var(--sel); color: var(--fg); border-bottom: 2px solid var(--cursor); }
.cards { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.card { display: flex; flex-direction: column; min-width: 130px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; color: var(--fg); background: var(--panel); }
.card .big { font-size: 22px; font-weight: 600; }
.cratelist { max-height: 40vh; overflow: auto; }
aside h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--quiet); margin: 12px 8px 4px; }
aside .filter { width: 100%; }
.crumbs { margin: 0 0 8px; }

/* Documents. */
article.doc { max-width: 880px; }
article.doc pre.code, pre.raw { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; overflow: auto; font-size: 12px; white-space: pre; }
pre.raw { white-space: pre-wrap; }
.tablewrap { overflow: auto; margin: 8px 0; }
table.doc { width: auto; font-size: 13px; }
table.doc td, table.doc th { max-width: 520px; }
.deadlink { border-bottom: 1px dotted var(--quiet); }
.tests li.bad { color: var(--bad); }
td.num { text-align: right; }

/* The structure graph. */
.graphscroll { overflow: auto; border: 1px solid var(--line); border-radius: 6px; max-height: 70vh; background: var(--bg); }
.graph .node rect { fill: var(--panel); stroke: var(--quiet); stroke-width: 1; }
.graph .node text { fill: var(--fg); font-size: 11px; font-family: ui-monospace, monospace; pointer-events: none; }
.graph .node.planned rect { stroke-dasharray: 4 3; }
.graph .node.dim { opacity: .3; }
.graph .node.focus rect { stroke: var(--cursor); stroke-width: 2; fill: var(--sel); }
.graph a:hover .node rect { stroke: var(--cursor); }
.graph .edge { fill: none; stroke: var(--quiet); stroke-width: 1; opacity: .5; }
.graph .edge.dim { opacity: .08; }
.graph .edge.hot { stroke: var(--cursor); opacity: 1; stroke-width: 1.5; }

/* Diffs. */
.filediff { border: 1px solid var(--line); border-radius: 6px; margin: 6px 0; }
.filediff summary { padding: 4px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; background: var(--panel); }
.filediff .counts { color: var(--quiet); font-size: 12px; }
.filediff > p { margin: 4px 10px; }
.diff { overflow: auto; font-family: ui-monospace, monospace; font-size: 12px; }
.dl { display: flex; white-space: pre; min-width: max-content; }
.dl .sign { flex: 0 0 18px; text-align: center; color: var(--quiet); user-select: none; }
.dl.add { background: var(--add-bg); }
.dl.del { background: var(--del-bg); }
.dl.hunk { color: var(--quiet); background: var(--panel); }

/* Overlays. */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; z-index: 50; }
.dialog { background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.3); width: min(640px, 94vw); max-height: 70vh; overflow: auto; padding: 10px 12px; }
.dialog.help { width: min(900px, 94vw); max-height: 80vh; }
.dialog .filter { width: 100%; margin: 0 0 6px; }
.palette ul { list-style: none; margin: 0; padding: 0; }
.palette li { display: flex; gap: 10px; padding: 4px 8px; border-radius: 4px; cursor: pointer; align-items: baseline; }
.palette li.chosen { background: var(--sel); }
.palette .group { flex: 0 0 70px; font-size: 11px; color: var(--quiet); }
.palette .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette .hint { font-size: 11px; color: var(--quiet); }
.help .sections { columns: 2 320px; column-gap: 24px; }
.help section { break-inside: avoid; }
.help h3 { margin: 8px 0 2px; font-size: 13px; }
.help td.keys { white-space: nowrap; color: var(--quiet); padding-right: 12px; }
@media (max-width: 720px) {
  .gridwrap { flex-direction: column; }
  .panel { flex-basis: 40%; }
}
main.fill > .split { align-items: stretch; }
main.fill .regbody { display: flex; flex-direction: column; min-height: 0; }
main.fill aside { position: static; overflow: auto; }
