:root {
  --bg: #fbfaf7;
  --fg: #26292e;
  --muted: #737880;
  --line: #e6e2d8;
  --side-bg: #f4f2ec;
  --hover: #ebe7dd;
  --accent: #1f5fbf;
  --code-bg: #f1eee6;
  --mark: #fff1a8;

  --hl-keyword: #a3336b;
  --hl-string: #2f7a3b;
  --hl-number: #a55a00;
  --hl-comment: #8a8f96;
  --hl-title: #3d5fb8;
  --hl-attr: #7a4fb0;

  --fs: 19px;
  --side-w: 290px;
  --font-read: Charter, "Bitstream Charter", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181b; --fg: #d9d7d1; --muted: #8b9098; --line: #2a2c31; --side-bg: #1c1d21;
    --hover: #26282d; --accent: #82aaff; --code-bg: #202227; --mark: #5a4d12;
    --hl-keyword: #e38bb5; --hl-string: #8fc97f; --hl-number: #e0a35e; --hl-comment: #6f757d;
    --hl-title: #8fb0ff; --hl-attr: #c4a2f0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17181b; --fg: #d9d7d1; --muted: #8b9098; --line: #2a2c31; --side-bg: #1c1d21;
  --hover: #26282d; --accent: #82aaff; --code-bg: #202227; --mark: #5a4d12;
  --hl-keyword: #e38bb5; --hl-string: #8fc97f; --hl-number: #e0a35e; --hl-comment: #6f757d;
  --hl-title: #8fb0ff; --hl-attr: #c4a2f0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-read); overflow: hidden; }
::selection { background: var(--mark); }

/* ---------- sidebar ---------- */
#sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w);
  display: flex; flex-direction: column;
  background: var(--side-bg); border-right: 1px solid var(--line);
  font: 13.5px/1.45 var(--font-ui);
  transition: transform .2s ease;
}
body.side-hidden #sidebar { transform: translateX(-100%); }

#filter {
  margin: 14px 12px 8px; padding: 7px 10px;
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; outline: none;
}
#filter:focus { border-color: var(--accent); }

#tree { flex: 1; overflow-y: auto; padding: 4px 6px 24px; }
#tree ul { list-style: none; margin: 0; padding: 0; }
#tree ul ul { padding-left: 12px; margin-left: 9px; border-left: 1px solid var(--line); }
#tree a, #tree summary {
  display: block; padding: 4px 8px; border-radius: 5px;
  color: var(--fg); text-decoration: none; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#tree a { color: var(--muted); }
#tree a.md { color: var(--fg); }
#tree a:hover, #tree summary:hover { background: var(--hover); }
#tree a.active { background: var(--hover); color: var(--accent); font-weight: 600; }
#tree a.done:not(.active)::after { content: " ✓"; color: var(--muted); font-size: 11px; }
#tree a.other { box-shadow: inset 2px 0 var(--accent); }

#tree li { position: relative; }
#tree .split-btn {
  position: absolute; top: 2px; right: 4px; display: none;
  border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer;
  font: 11px/1 var(--font-ui); padding: 4px 6px; border-radius: 4px;
}
#tree li:hover > .split-btn { display: block; }
#tree .split-btn:hover { color: var(--accent); border-color: var(--accent); }
@media (max-width: 820px) { #tree .split-btn { display: none !important; } }
#tree summary { list-style: none; font-weight: 600; }
#tree summary::-webkit-details-marker { display: none; }
#tree summary::before { content: "›"; display: inline-block; width: 12px; color: var(--muted); transition: transform .15s; }
#tree details[open] > summary::before { transform: rotate(90deg); }
#tree .hint { padding: 8px; color: var(--muted); }

#side-foot {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
#repo-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: inherit; text-decoration: none; }
#repo-name:hover { color: var(--accent); }
body:not(.web) .web-only { display: none; }
.settings-btn {
  font: inherit; color: var(--muted); background: none; cursor: pointer;
  border: 1px solid var(--line); border-radius: 4px; padding: 1px 7px;
}
.settings-btn:hover { color: var(--accent); border-color: var(--accent); }
.settings-btn.link { border: 0; padding: 0; color: var(--accent); }

/* ---------- main ---------- */
#main {
  position: fixed; inset: 0 0 0 var(--side-w); display: flex;
  transition: left .2s ease;
}
body.side-hidden #main { left: 0; }

/* Each pane scrolls independently. */
.pane { flex: 1 1 0; min-width: 0; overflow-y: auto; position: relative; scroll-padding-top: 24px; }
.pane[hidden] { display: none; }
.pane + .pane { border-left: 1px solid var(--line); }
.pane-body { padding: 56px 48px 120px; }
.pane-body > * { max-width: calc(var(--fs) * 40); margin-left: auto; margin-right: auto; }

.progress {
  position: sticky; top: 0; height: 2px; margin-bottom: -2px; z-index: 2;
  background: var(--accent); opacity: .7; transform: scaleX(0); transform-origin: left;
}

.crumb {
  display: flex; align-items: center; gap: 8px;
  font: 12.5px var(--font-ui); color: var(--muted); margin-bottom: 28px;
}
.crumb-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb .close {
  display: none; border: 0; background: none; color: var(--muted); cursor: pointer;
  font: 18px/1 var(--font-ui); padding: 2px 6px; border-radius: 4px;
}
.crumb .close:hover { background: var(--hover); color: var(--fg); }

/* Split mode: the active pane gets a dot in its breadcrumb, the other pane is dimmed. */
body.split .crumb .close { display: block; }
body.split .pane.active .crumb-text::before { content: "● "; color: var(--accent); }
body.split .pane:not(.active) .pane-body { opacity: .8; }
body.split .pane-body { padding: 44px 36px 120px; }

.doc { font-size: var(--fs); line-height: 1.72; overflow-wrap: break-word; }
.doc > :first-child { margin-top: 0; }
.doc h1, .doc h2, .doc h3, .doc h4 { line-height: 1.25; margin: 2em 0 .6em; font-weight: 700; }
.doc h1 { font-size: 2em; margin-top: 0; letter-spacing: -.01em; }
.doc h2 { font-size: 1.45em; padding-bottom: .25em; border-bottom: 1px solid var(--line); }
.doc h3 { font-size: 1.2em; }
.doc h4 { font-size: 1em; }
.doc p, .doc ul, .doc ol, .doc blockquote, .doc table, .doc pre { margin: 0 0 1.1em; }
.doc li + li { margin-top: .25em; }
.doc a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.doc strong { font-weight: 700; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 2.5em 0; }
.doc img { max-width: 100%; border-radius: 4px; }
.doc blockquote { margin-left: 0; padding: .1em 1.1em; border-left: 3px solid var(--line); color: var(--muted); }

.doc code {
  font-family: var(--font-mono); font-size: .82em;
  background: var(--code-bg); padding: .12em .35em; border-radius: 4px;
}
.doc pre {
  position: relative; background: var(--code-bg); border-radius: 8px;
  padding: 16px 18px; overflow-x: auto; line-height: 1.55;
}
.doc pre code { background: none; padding: 0; font-size: .8em; }
.doc pre .copy {
  position: absolute; top: 8px; right: 8px; opacity: 0;
  font: 11px var(--font-ui); color: var(--muted); background: var(--bg);
  border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; cursor: pointer;
}
.doc pre:hover .copy { opacity: 1; }

.doc .table-wrap { overflow-x: auto; margin-bottom: 1.1em; }
.doc table { border-collapse: collapse; font-size: .86em; margin: 0; }
.doc th, .doc td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; vertical-align: top; }
.doc th { background: var(--code-bg); }

.doc .folder-list { list-style: none; padding: 0; }
.doc .folder-list a { text-decoration: none; }
.doc .notice { color: var(--muted); font-family: var(--font-ui); font-size: 15px; }

/* code file view */
.doc.code-file pre { font-size: 15px; }

/* syntax highlight */
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-type, .hljs-literal { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-variable.constant_ { color: var(--hl-number); }
.hljs-comment, .hljs-quote, .hljs-meta { color: var(--hl-comment); font-style: italic; }
.hljs-title, .hljs-section, .hljs-name { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-params { color: var(--hl-attr); }
.hljs-deletion { color: var(--hl-keyword); }

/* ---------- pager ---------- */
.pager { display: flex; gap: 16px; margin-top: 72px; font-family: var(--font-ui); }
.pager a {
  flex: 1; display: block; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px;
  color: var(--fg); text-decoration: none; min-width: 0;
}
.pager a:hover { border-color: var(--accent); }
.pager a.next { text-align: right; }
.pager small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.pager span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; }

/* ---------- landing ---------- */
#landing { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); padding: 16px; }
#landing[hidden] { display: none; }
#open-form { width: min(560px, 100%); font-family: var(--font-ui); }
#open-form h1 { font-family: var(--font-read); font-weight: 600; margin: 0 0 16px; }
#repo-input {
  width: 100%; padding: 12px 14px; font: 16px var(--font-ui); color: var(--fg);
  background: var(--side-bg); border: 1px solid var(--line); border-radius: 8px; outline: none;
}
#repo-input:focus { border-color: var(--accent); }
#open-form p { color: var(--muted); font-size: 13px; }
body.landing #sidebar, body.landing #main { display: none; }
#recent { margin-top: 28px; }
#recent h2 { font: 600 12px var(--font-ui); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
#recent-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
#recent-list li { display: flex; align-items: center; border-radius: 6px; }
#recent-list li:hover { background: var(--hover); }
#recent-list a { flex: 1; min-width: 0; padding: 8px 10px; color: var(--fg); text-decoration: none; }
#recent-list .recent-name { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#recent-list small { display: block; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-remove {
  visibility: hidden; margin-right: 6px; padding: 2px 8px; font: 16px var(--font-ui);
  color: var(--muted); background: none; border: 0; border-radius: 4px; cursor: pointer;
}
#recent-list li:hover .recent-remove, .recent-remove:focus-visible { visibility: visible; }
.recent-remove:hover { color: var(--fg); }
@media (hover: none) { .recent-remove { visibility: visible; } }

/* ---------- help + toast ---------- */
kbd {
  font: 11.5px var(--font-mono); padding: 1px 6px; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px; background: var(--side-bg);
}
#help {
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg);
  font: 14px/1.5 var(--font-ui); padding: 20px 26px; min-width: 340px;
}
#help::backdrop, #settings::backdrop { background: rgb(0 0 0 / .25); }
#settings {
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg);
  font: 14px/1.5 var(--font-ui); padding: 20px 26px; width: min(440px, calc(100vw - 32px));
}
#settings h2 { margin: 0 0 12px; font-size: 16px; }
#settings input {
  width: 100%; box-sizing: border-box; padding: 8px 10px; font: 14px var(--font-mono); color: var(--fg);
  background: var(--side-bg); border: 1px solid var(--line); border-radius: 6px; outline: none;
}
#settings input:focus { border-color: var(--accent); }
#settings p { color: var(--muted); font-size: 13px; }
/* Save comes first in the markup so Enter saves; shown on the right. */
#settings .actions { display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 8px; }
#settings button {
  font: inherit; padding: 5px 14px; border-radius: 6px; cursor: pointer;
  color: var(--fg); background: var(--side-bg); border: 1px solid var(--line);
}
#settings button[value="save"] { color: #fff; background: var(--accent); border-color: var(--accent); }
#help h2 { margin: 0 0 12px; font-size: 16px; }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 0; }
#help dd { margin: 0; color: var(--muted); }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 8px);
  font: 13px var(--font-ui); background: var(--fg); color: var(--bg);
  padding: 8px 14px; border-radius: 6px; opacity: 0; pointer-events: none; transition: .2s;
}
#toast.show { opacity: .92; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  #sidebar { z-index: 5; box-shadow: 0 0 24px rgb(0 0 0 / .15); }
  #main { left: 0; }
  .pane-body, body.split .pane-body { padding: 40px 16px 96px; }
  .pager { flex-direction: column; }
}
