:root {
  --bg: #282828; --bg0: #1d2021; --bg1: #3c3836; --bg2: #504945; --cl: #32302f;
  --fg: #ebdbb2; --fg2: #d5c4a1; --dim: #7c6f64; --gray: #928374;
  --red: #fb4934; --green: #b8bb26; --yellow: #fabd2f; --blue: #83a598;
  --purple: #d3869b; --aqua: #8ec07c; --orange: #fe8019;
  --sa: #a89984; --sb: #504945; --sc: #3c3836;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-padding-top: 64px; scrollbar-width: none; overscroll-behavior: none; }
html::-webkit-scrollbar { display: none; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.75 'JetBrains Mono', ui-monospace, Menlo, monospace;
  padding-bottom: 56px;
  overflow-x: clip; overscroll-behavior: none;
}
::selection { background: var(--bg2); }
a { color: var(--blue); text-decoration: underline; text-underline-offset: 3px; }
a:hover { background: var(--blue); color: var(--bg); text-decoration: none; }

/* bufferline + winbar */
.bufferline {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: stretch;
  background: var(--bg0); font-size: 13px; line-height: 30px;
}
.buf { padding: 0 16px; color: var(--gray); text-decoration: none; border-right: 1px solid var(--bg); }
.buf:hover { background: var(--bg1); color: var(--fg); }
.buf.on { background: var(--bg); color: var(--fg); box-shadow: inset 0 2px var(--orange); }
.ic { margin-right: 8px; color: var(--blue); font-size: 11px; font-weight: 700; }
.ic.pdf { color: var(--red); font-size: 13px; }
.fill { flex: 1; }
.tabnr { background: var(--sa); color: var(--bg); padding: 0 12px; font-weight: 700; }
.winbar {
  position: sticky; top: 30px; z-index: 2; background: var(--bg);
  font-size: 13px; color: var(--gray); padding: 2px 0 2px calc(8ch + 8px);
  box-shadow: 0 8px 0 var(--bg);
}
.winbar b { color: var(--fg2); font-weight: 400; }
.winbar .sep { color: var(--dim); margin: 0 .8ch; }

/* buffer */
.buffer { padding: 8px 0 24px; }
.l { display: grid; grid-template-columns: 5ch 2ch minmax(0, 92ch); column-gap: 1ch; min-height: 1.75em; cursor: text; }
.l.cur { background: var(--cl); }
.n { color: var(--dim); text-align: right; user-select: none; }
.l.cur .n { color: var(--yellow); font-weight: 700; }
.sc { text-align: center; user-select: none; }
.sg-info { color: var(--aqua); }
.t { padding-right: 16px; }
.mk { color: var(--dim); font-weight: 400; }
.h1 .t { color: var(--orange); font-weight: 700; }
.h2 .t { color: var(--yellow); font-weight: 700; }
.h3 .t { color: var(--aqua); font-weight: 700; }
.em .t { color: var(--purple); font-style: italic; }
.tag { color: var(--green); }
.win { color: var(--bg); background: var(--yellow); font-style: normal; font-weight: 700; padding: 0 .6ch; border-radius: 3px; }
.q .t { color: var(--green); }
.li .t { padding-left: 2ch; text-indent: -2ch; }
.li .t > .mk:first-child { color: var(--red); }
.ref .t { padding-left: 2ch; text-indent: -2ch; }
.ref .t > .mk:first-child { color: var(--aqua); }
.key { color: var(--fg2); }
.vt { color: var(--aqua); opacity: .75; font-style: italic; font-weight: 400; margin-left: 3ch; font-size: 13px; }
.eob { color: var(--bg2); padding-left: calc(8ch + 8px); }

/* statusline + cmdline */
footer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; font-size: 13px; }
.statusline { display: flex; align-items: stretch; background: var(--sc); line-height: 24px; white-space: nowrap; }
.seg { padding: 0 12px; }
.seg.a { background: var(--sa); color: var(--bg); font-weight: 700; }
.seg.b { background: var(--sb); color: var(--fg2); }
.seg.c { background: var(--sc); color: var(--fg2); }
.sep { width: 12px; background: var(--r); position: relative; flex: none; }
.sep::before { content: ""; position: absolute; inset: 0; background: var(--l); clip-path: polygon(0 0, 100% 50%, 0 100%); }
.sep.rev { background: var(--l); }
.sep.rev::before { background: var(--r); clip-path: polygon(100% 0, 0 50%, 100% 100%); }
.cmdline { display: flex; gap: 0; background: var(--bg); color: var(--gray); padding: 0 12px; line-height: 24px; min-height: 24px; }
.touch { display: none; }
.cmdline { cursor: text; }
.cmdline b { color: var(--fg2); font-weight: 400; }
.cmdline .err { color: var(--red); }
.prompt { color: var(--fg); }
.showcmd { margin-left: auto; padding-left: 2ch; min-width: 12ch; color: var(--fg); white-space: pre; }
#cmd { flex: 1; background: none; border: 0; outline: 0; color: var(--fg); font: inherit; caret-color: var(--fg); }

/* modes (lualine gruvbox colours) */
body[data-mode="insert"] { --sa: var(--blue); }
body[data-mode="visual"] { --sa: var(--yellow); }
body[data-mode="command"] { --sa: var(--green); }
.cmdline .warn { color: var(--yellow); }
body.nonu .l { grid-template-columns: 0 2ch minmax(0, 92ch); }
body.nonu .n { visibility: hidden; }
body.nonu .winbar, body.nonu .eob { padding-left: calc(3ch + 8px); }

/* search, visual selection, yank flash */
mark { background: var(--yellow); color: var(--bg); border-radius: 2px; }
mark.cm { background: var(--orange); }
.l.vis, .l.vis.cur { background: var(--bg2); }
.l.yank { background: var(--orange) !important; transition: none; }
.l.yank * { color: var(--bg) !important; }
.l { transition: background .25s; }

/* neo-tree */
.tree {
  position: fixed; top: 30px; bottom: 48px; left: 0; width: 34ch; z-index: 2;
  background: var(--bg0); border-right: 1px solid var(--bg1); font-size: 13px; line-height: 1.9;
  padding: 6px 0; overflow: auto; scrollbar-width: none;
}
.tree-head { color: var(--bg); background: var(--sa); font-weight: 700; padding: 0 12px; margin: -6px 0 6px; line-height: 26px; }
.node { display: block; padding: 0 12px; color: var(--fg2); text-decoration: none; white-space: pre; }
a.node:hover { background: var(--bg1); color: var(--fg); }
.node.on { background: var(--bg1); color: var(--fg); }
.node.root { color: var(--blue); font-weight: 700; }
.node.dir { color: var(--blue); }
.guide { color: var(--dim); }
.tree-foot { color: var(--dim); padding: 12px; white-space: normal; }
.tree-foot b { color: var(--fg2); font-weight: 400; }
body.tree-open .buffer { margin-left: 34ch; }
body.tree-open .winbar, body.tree-open .eob { margin-left: 34ch; }

/* floating windows */
.overlay { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .45); display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 16px; }
.overlay[hidden], .tree[hidden], .wk[hidden], .pum[hidden] { display: none; }
.box { position: relative; border: 1px solid var(--gray); border-radius: 6px; background: var(--bg); }
.box > .title { position: absolute; top: -.85em; left: 1.5ch; padding: 0 1ch; background: var(--bg); color: var(--fg); font-size: 13px; line-height: 1.6; }
.tele { width: min(1100px, 100%); height: min(640px, 82vh); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.tl-left { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 14px; min-height: 0; min-width: 0; }
.results { min-height: 0; display: flex; flex-direction: column; justify-content: flex-end; padding: 14px 0 6px; }
#tres { list-style: none; display: flex; flex-direction: column-reverse; overflow: auto; scrollbar-width: none; }
#tres li { padding: 0 1.5ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
#tres li.sel { background: var(--bg1); }
#tres li.sel::before { content: "> "; color: var(--red); }
#tres li:not(.sel)::before { content: "  "; }
#tres .k { color: var(--dim); display: inline-block; width: 3ch; }
#tres .d { color: var(--dim); margin-left: 1.5ch; font-size: 13px; }
#tres em { font-style: normal; color: var(--orange); font-weight: 700; }
.prompt-box { display: flex; align-items: center; gap: 1ch; padding: 10px 1.5ch 8px; }
.pfx { color: var(--red); }
#tq { flex: 1; background: none; border: 0; outline: 0; color: var(--fg); font: inherit; caret-color: var(--fg); }
.tcount { color: var(--dim); font-size: 13px; }
.preview { min-height: 0; display: flex; flex-direction: column; padding: 16px 0 12px 2ch; }
#tprev { flex: 1; overflow: auto; scrollbar-width: none; padding-right: 2ch; white-space: pre-wrap; color: var(--fg2); font-size: 14px; }
#tprev .ph { color: var(--aqua); font-weight: 700; }
#tprev .pe { color: var(--purple); font-style: italic; }
#tprev .pu { color: var(--blue); }
.helpbox { width: min(760px, 100%); max-height: 84vh; display: flex; padding: 18px 0 14px 2.5ch; }
.helpbox pre { overflow: auto; scrollbar-width: none; padding-right: 2.5ch; }
.helpbox pre { font: inherit; font-size: 14px; color: var(--fg2); white-space: pre-wrap; }
.ht { color: var(--orange); font-weight: 700; }
.hh { color: var(--yellow); font-weight: 700; }
.hc { color: var(--aqua); }

/* which-key */
.wk { position: fixed; left: 0; right: 0; bottom: 48px; z-index: 4; background: var(--bg0); border-top: 1px solid var(--bg2); padding: 10px 16px 12px; font-size: 13.5px; }
.wk-title { color: var(--orange); margin-bottom: 6px; }
.wk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(30ch, 1fr)); gap: 2px 3ch; color: var(--fg2); }
.wk-grid b { color: var(--orange); font-weight: 400; }

/* command-line completion popup */
.pum { position: fixed; left: 12px; bottom: 26px; z-index: 5; list-style: none; background: var(--bg1); min-width: 22ch; max-height: 50vh; overflow: auto; font-size: 13px; line-height: 1.8; scrollbar-width: none; }
.pum li { padding: 0 1.5ch; color: var(--fg2); }
.pum li.sel { background: var(--bg2); color: var(--fg); }

/* gruvbox light (:set bg=light) */
:root[data-theme="light"] {
  --bg: #fbf1c7; --bg0: #f2e5bc; --bg1: #ebdbb2; --bg2: #d5c4a1; --cl: #f2e5bc;
  --fg: #3c3836; --fg2: #504945; --dim: #a89984; --gray: #928374;
  --red: #9d0006; --green: #79740e; --yellow: #b57614; --blue: #076678;
  --purple: #8f3f71; --aqua: #427b58; --orange: #af3a03;
  --sa: #7c6f64; --sb: #d5c4a1; --sc: #ebdbb2;
}
:root[data-theme="light"] .overlay { background: rgba(60, 56, 54, .25); }

@media (max-width: 640px) {
  .tele { grid-template-columns: minmax(0, 1fr); height: 78vh; }
  .preview { display: none; }
  .tree { width: 100%; }
  body.tree-open .buffer, body.tree-open .winbar, body.tree-open .eob { margin-left: 0; }
  .wk-grid { grid-template-columns: 1fr; }
  body { font-size: 13px; }
  .l { grid-template-columns: 3ch 1.5ch minmax(0, 1fr); column-gap: .5ch; }
  .winbar, .eob { padding-left: calc(5ch + 4px); }
  .vt { display: none; }
  .desk { display: none; }
  .touch { display: inline; }
  .hide-s { display: none; }
  .cmdline #cmdmsg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
