:root {
  --bg: #ffffff;
  --bg-sub: #f6f8fa;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #59636e;
  --border: #d1d9e0;
  --accent: #0969da;
  --accent-bg: #ddf4ff;
  --btn-bg: #f6f8fa;
  --btn-hover: #eaeef2;
  --primary: #1f883d;
  --primary-text: #fff;
  --err: #cf222e;
  --err-bg: #ffebe9;
  --add-bg: #dafbe1;
  --add-fg: #116329;
  --del-bg: #ffebe9;
  --del-fg: #82071e;
  --hunk-bg: #ddf4ff;
  --sel-bg: #fff8c5;
  --merged: #8250df;
  --tok-kw: #8250df;
  --tok-str: #0a3069;
  --tok-com: #6e7781;
  --tok-num: #0550ae;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --tap: 44px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg-sub: #151b23;
    --panel: #0d1117;
    --text: #e6edf3;
    --muted: #9198a1;
    --border: #3d444d;
    --accent: #4493f8;
    --accent-bg: #1a2a40;
    --btn-bg: #212830;
    --btn-hover: #2a313c;
    --primary: #2ea043;
    --err: #ff7b72;
    --err-bg: #3b1d1f;
    --add-bg: #12261e;
    --add-fg: #7ee787;
    --del-bg: #2d1517;
    --del-fg: #ffa198;
    --hunk-bg: #121d2f;
    --sel-bg: #3a3000;
    --merged: #ab7df8;
    --tok-kw: #d2a8ff;
    --tok-str: #a5d6ff;
    --tok-com: #8b949e;
    --tok-num: #79c0ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-sub: #151b23;
  --panel: #0d1117;
  --text: #e6edf3;
  --muted: #9198a1;
  --border: #3d444d;
  --accent: #4493f8;
  --accent-bg: #1a2a40;
  --btn-bg: #212830;
  --btn-hover: #2a313c;
  --primary: #2ea043;
  --err: #ff7b72;
  --err-bg: #3b1d1f;
  --add-bg: #12261e;
  --add-fg: #7ee787;
  --del-bg: #2d1517;
  --del-fg: #ffa198;
  --hunk-bg: #121d2f;
  --sel-bg: #3a3000;
  --merged: #ab7df8;
  --tok-kw: #d2a8ff;
  --tok-str: #a5d6ff;
  --tok-com: #8b949e;
  --tok-num: #79c0ff;
  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 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-wrap: anywhere;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.skip { position: absolute; left: -999px; top: 0; background: var(--panel); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
.pad { padding: 12px 16px; }
.h2 { font-size: 18px; margin: 8px 0; }
.sep { color: var(--muted); margin: 0 4px; }
.error { color: var(--err); min-height: 1.4em; margin: 0; }
.name { font-weight: 600; }

input, select, button, textarea { font: inherit; font-size: 16px; color: inherit; }
input[type="search"], input[type="password"], input[type="text"], select {
  min-height: var(--tap);
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-width: 100%;
}
.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 6px 14px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover, button:hover { background: var(--btn-hover); text-decoration: none; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: transparent; }
.btn.disabled { opacity: 0.5; pointer-events: none; }
button:disabled { opacity: 0.6; cursor: default; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--bg-sub); border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: 100%; max-width: 380px; display: grid; gap: 10px; }
.card h1 { margin: 0; font-size: 22px; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--bg-sub); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { white-space: nowrap; font-weight: 700; color: var(--text); min-height: var(--tap); display: inline-flex; align-items: center; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }

.box { border: 1px solid var(--border); border-radius: 6px; background: var(--panel); margin: 12px 0; overflow: hidden; }
.box-title { margin: 0; padding: 10px 16px; font-size: 14px; background: var(--bg-sub); border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; }
.toolbar > input[type="search"] { flex: 1 1 200px; }
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); padding: 24px 0; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.alert { border: 1px solid var(--err); background: var(--err-bg); border-radius: 6px; padding: 12px 16px; margin: 12px 0; }
.alert p { margin: 6px 0; }
.notice { padding: 16px; margin: 0; color: var(--muted); }

.badge { display: inline-block; padding: 0 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; line-height: 20px; color: var(--muted); white-space: nowrap; }
.badge.open, .badge.public { color: var(--add-fg); border-color: currentColor; }
.badge.closed { color: var(--err); border-color: currentColor; }
.badge.merged { color: var(--merged); border-color: currentColor; }
.badge.warn { color: #9a6700; border-color: currentColor; }
.label { display: inline-block; padding: 0 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; margin-left: 4px; }
.label.colored { border-color: var(--label); }
.avatar { border-radius: 50%; vertical-align: middle; flex: none; background: var(--bg-sub); }
.avatar-empty { display: inline-block; width: 20px; height: 20px; }
.icon { display: inline-flex; vertical-align: middle; color: var(--muted); flex: none; }
.lang-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.add-n { color: var(--add-fg); font-weight: 600; }
.del-n { color: var(--del-fg); font-weight: 600; }

.repo-list { list-style: none; padding: 0; }
.repo-list li { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.repo-list li:last-child { border-bottom: 0; }
.repo-row-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.repo-row-top .name { font-size: 17px; min-height: 28px; display: inline-flex; align-items: center; }
.repo-row .desc { margin: 4px 0; color: var(--muted); }
.repo-row-meta, .repo-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }

.repo-head { margin-bottom: 8px; }
.repo-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.repo-title h1 { font-size: 20px; margin: 0; font-weight: 400; }
.repo-title h1 a:last-child { font-weight: 700; }
.repo-head .desc { margin: 6px 0; }
.tabs-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); margin-top: 12px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1 1 auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 14px; color: var(--text); white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a:hover { background: var(--btn-hover); text-decoration: none; }
.tabs a[aria-current="page"] { border-bottom-color: #fd8c73; font-weight: 600; }
.tab-search { flex: 0 1 260px; padding-bottom: 4px; }
.tab-search input { width: 100%; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; min-width: 0; }
.crumbs a, .crumbs strong { padding: 2px 0; }

.picker { position: relative; }
.ref-btn { max-width: 100%; }
.ref-btn span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.popover { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; width: min(340px, 90vw); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); padding: 8px; display: grid; gap: 8px; }
.popover-top { display: flex; gap: 8px; }
.popover-top input { flex: 1; min-width: 0; }
.popover-close { display: none; }
.segs { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg { border: 0; border-radius: 0; background: var(--btn-bg); color: var(--text); min-height: 36px; padding: 0 12px; display: inline-flex; align-items: center; }
.seg.on { background: var(--accent-bg); font-weight: 600; color: var(--accent); }
a.seg:hover { text-decoration: none; }
.ref-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.ref-list a { display: block; padding: 10px 8px; color: var(--text); border-radius: 4px; }
.ref-list a:hover, .ref-list a[aria-current] { background: var(--accent-bg); text-decoration: none; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; z-index: 30; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; min-width: 200px; display: grid; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); }
.menu-pop a { padding: 12px 16px; color: var(--text); }

.tree-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; padding: 10px 16px; background: var(--bg-sub); border-bottom: 1px solid var(--border); font-size: 14px; min-height: 44px; }
.box > .tree-head:first-child { margin: 0; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree li { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 2fr) 70px 110px; gap: 12px; align-items: center; border-top: 1px solid var(--border); }
.tree li:first-child { border-top: 0; }
.tree-link { display: flex; gap: 8px; align-items: center; min-height: var(--tap); padding: 0 16px; color: var(--text); min-width: 0; }
.tree-link:hover { text-decoration: none; }
.tree-link:hover .name { color: var(--accent); text-decoration: underline; }
.tree-link .name { font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.row-msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.size, .row-when { font-size: 13px; text-align: right; white-space: nowrap; }
.row-when { padding-right: 16px; }
li > .row-when:empty { padding: 0; }
.tree-head + .box, .box .tree-head { border-radius: 0; }
.tree .icon-folder { color: #54aeff; }

.lang-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin: 12px 0 8px; background: var(--border); }
.lang-seg { display: block; height: 100%; }
.lang-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 0; margin: 0 0 16px; font-size: 13px; }

.viewer-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-sub); border-bottom: 1px solid var(--border); }
.file-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.viewer-body { min-width: 0; }
.code-wrap { overflow-x: auto; }
table.code { border-collapse: collapse; font: 13px/20px var(--mono); width: max-content; min-width: 100%; }
table.code td { padding: 0 12px; vertical-align: top; }
td.ln { position: sticky; left: 0; text-align: right; user-select: none; background: var(--panel); min-width: 3.5em; padding: 0 10px; border-right: 1px solid var(--border); }
td.ln a { color: var(--muted); display: block; min-width: 2em; }
td.lc { white-space: pre; tab-size: 4; }
tr.sel td { background: var(--sel-bg); }
tr.sel td.ln { background: var(--sel-bg); }
.tok-kw { color: var(--tok-kw); }
.tok-str { color: var(--tok-str); }
.tok-com { color: var(--tok-com); font-style: italic; }
.tok-num { color: var(--tok-num); }
.image-view { padding: 16px; text-align: center; background: var(--bg-sub); }
.image-view img { max-width: 100%; height: auto; }
.md-pad { padding: 8px 24px 16px; }

.markdown { padding: 16px 24px; line-height: 1.6; overflow-wrap: anywhere; min-width: 0; }
.md-pad .markdown { padding: 0; }
.markdown img { max-width: 100%; height: auto; }
.markdown pre { overflow-x: auto; background: var(--bg-sub); padding: 12px; border-radius: 6px; font: 13px/1.5 var(--mono); }
.markdown code { font: 0.9em var(--mono); background: var(--bg-sub); padding: 0.15em 0.35em; border-radius: 4px; }
.markdown pre code { background: none; padding: 0; }
.markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 12px; }
.markdown blockquote { margin: 0; padding: 0 1em; color: var(--muted); border-left: 4px solid var(--border); }
.markdown h1, .markdown h2 { border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown hr { border: 0; border-top: 1px solid var(--border); }
.readme .markdown { padding-top: 8px; }

.commit-list, .ref-rows, .issue-list, .results { list-style: none; padding: 0; }
.commit-list li, .ref-rows li, .issue-list li, .results li { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--border); min-height: var(--tap); }
.commit-list li:first-child, .ref-rows li:first-child, .issue-list li:first-child, .results li:first-child { border-top: 0; }
.commit-main, .issue-main { flex: 1; min-width: 0; }
.commit-msg { color: var(--text); font-weight: 600; }
.sha { font: 13px var(--mono); padding: 8px; border: 1px solid var(--border); border-radius: 6px; }
.commit-line { display: flex; gap: 8px; align-items: center; }
.commit-body { white-space: pre-wrap; font: 13px/1.5 var(--mono); color: var(--muted); margin: 8px 0; }
.commit-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; margin: 6px 0; }
.tree-head .commit-msg { font-weight: 400; max-width: 100%; }
.ref-rows li { flex-wrap: wrap; }
.ref-main { display: flex; gap: 8px; align-items: center; min-width: 0; flex: 1 1 200px; }
.ref-commit { flex: 2 1 200px; min-width: 0; }
.ref-actions { display: flex; gap: 6px; }
.issue-title { font-weight: 600; color: var(--text); }
.issue-head .meta-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.comment-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 16px; background: var(--bg-sub); border-bottom: 1px solid var(--border); }
.fragment { margin: 6px 0 0; padding: 8px; background: var(--bg-sub); border-radius: 6px; font: 12px/1.5 var(--mono); overflow-x: auto; white-space: pre; max-width: 100%; }
.results li { display: block; }
.pager { display: flex; justify-content: center; align-items: center; gap: 16px; margin: 16px 0; }
.compare-form label { display: flex; gap: 6px; align-items: center; }
.compare-form select { max-width: 42vw; }

.file-diff { border: 1px solid var(--border); border-radius: 6px; margin: 12px 0; background: var(--panel); }
.file-diff summary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; background: var(--bg-sub); cursor: pointer; min-height: var(--tap); }
.fname { font: 13px var(--mono); flex: 1 1 200px; min-width: 0; }
.diff { overflow-x: auto; }
.diff-table { border-collapse: collapse; width: max-content; min-width: 100%; font: 12px/20px var(--mono); }
.diff-table td { padding: 0 8px; white-space: pre; }
.diff-table td.mark { width: 1.5em; text-align: center; user-select: none; color: var(--muted); }
.diff-table tr.add { background: var(--add-bg); }
.diff-table tr.del { background: var(--del-bg); }
.diff-table tr.hunk { background: var(--hunk-bg); color: var(--muted); }
.diff-table tr.add .mark { color: var(--add-fg); }
.diff-table tr.del .mark { color: var(--del-fg); }

dialog.finder { width: min(640px, 94vw); max-height: 80vh; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); }
dialog.finder::backdrop { background: rgba(0, 0, 0, 0.5); }
.finder-top { display: flex; gap: 8px; }
.finder-top input { flex: 1; min-width: 0; }
.finder-list { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; max-height: 55vh; font: 13px var(--mono); }
.finder-list a { display: block; padding: 12px 8px; color: var(--text); }
.finder-list li.on a, .finder-list a:hover { background: var(--accent-bg); text-decoration: none; }

@media (max-width: 720px) {
  main { padding: 12px; }
  .tree li { grid-template-columns: minmax(0, 1fr) auto; }
  .tree .row-msg, .tree .row-when { display: none; }
  .tree .size { padding-right: 16px; }
  .tab-search { flex: 1 1 100%; }
  .topbar .owner { display: none; }
  .md-pad, .markdown { padding-left: 12px; padding-right: 12px; }
  .commit-list li, .issue-list li { flex-wrap: wrap; }
  .toolbar > .crumbs { flex: 1 1 100%; order: 5; }
  .popover {
    position: fixed;
    inset: 0;
    width: 100%;
    max-height: none;
    border-radius: 0;
    padding: 16px calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    align-content: start;
    grid-template-rows: auto auto minmax(0, 1fr);
  }
  .ref-list { max-height: none; }
  .popover-close { display: inline-flex; }
  .menu-pop { right: auto; left: 0; }
  dialog.finder { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .finder-list { max-height: none; }
}
