:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --border: #d0d7de;
  --code-bg: #f6f8fa;
  --add: #1a7f37;
  --del: #cf222e;
  --warn: #9a6700;
  --attn: #8250df;
  --mark: rgba(212, 167, 44, 0.2);
}
/* Dark palette applies on OS preference unless overridden to light,
   or when explicitly chosen; keep both blocks in sync. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --fg: #e6edf3;
    --muted: #8b949e;
    --accent: #58a6ff;
    --border: #30363d;
    --code-bg: #161b22;
    --add: #3fb950;
    --del: #f85149;
    --warn: #d29922;
    --attn: #a371f7;
    --mark: rgba(210, 153, 34, 0.16);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --border: #30363d;
  --code-bg: #161b22;
  --add: #3fb950;
  --del: #f85149;
  --warn: #d29922;
  --attn: #a371f7;
  --mark: rgba(210, 153, 34, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, sans-serif;
  /* stop iOS Safari inflating wide <pre> code/diff blocks past their
     neighbours (line numbers, commit message) */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
header nav, main {
  max-width: 60rem;
  margin: 0 auto;
  padding: 0.75rem 1rem;
}
main { padding-bottom: 3rem; }
main:focus { outline: none; } /* programmatic target of the skip link */

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

a:focus-visible, button:focus-visible, summary:focus-visible,
input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Visually hidden, still read by assistive tech (captions, headings). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Keyboard-only skip link, revealed on focus. */
.skip {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 30;
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 1rem;
}
.skip:focus { top: 0.5rem; }

nav.navbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem; /* row-gap when wrapped, column-gap between items */
}
nav.navbar a { color: var(--muted); }
nav.navbar a:hover { color: var(--fg); text-decoration: none; }
a.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--fg);
  font-weight: 600;
}
a.brand img { width: 20px; height: 20px; }
.spacer { flex: 1; }
button.theme {
  background: none;
  border: none;
  padding: 0.25rem 0.4rem;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}
button.theme:hover { color: var(--fg); }

h1 { font-size: 1.4rem; }
h1.repo-name a { color: var(--fg); }
h1.repo-name a.org { color: var(--muted); font-weight: 400; }
h1.repo-name a.org:hover { color: var(--fg); }
h2.org { margin: 0; font-size: 1.1rem; }
h2.org a { color: var(--fg); }
tr.orghead td {
  border-bottom: none;
  padding: 1.75rem 0 0.25rem;
}
table.repos td.idle { text-align: right; }
/* Auto-layout sizes the column to the longest name; long
   descriptions wrap instead of squeezing names. */
table.repos td.name { white-space: nowrap; }
.site-desc, .desc, .muted { color: var(--muted); }

.repo-title {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0.75rem 0 0.5rem;
}
.repo-title h1 { margin: 0; }
.repo-title .desc { margin: 0; }

nav.tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  position: sticky;
  top: 3rem; /* tucks just under the sticky header */
  z-index: 10;
  background: var(--bg);
}
nav.tabs a {
  color: var(--muted);
  padding: 0.35rem 0.75rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
nav.tabs a:hover { color: var(--fg); text-decoration: none; }
nav.tabs a.active { color: var(--fg); border-bottom-color: var(--accent); }
nav.tabs .right {
  position: relative;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
/* Secondary tools show inline on wide screens; the mobile breakpoint
   collapses them behind the ☰.  A checkbox toggle (not <details>) so
   CSS fully controls visibility across browsers. */
.more-toggle, .more-summary, .more-backdrop { display: none; }
.more-panel { display: flex; align-items: center; gap: 0.5rem; }
/* Branch and clone menus share one dropdown style. */
details.refmenu, details.clone-menu { position: relative; }
details.refmenu > summary, details.clone-menu > summary {
  list-style: none;
  cursor: pointer;
  background: var(--code-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.1rem 0.55rem;
  font-size: 0.875rem;
}
/* Clone is the primary action — a filled green button, GitHub-style. */
details.clone-menu > summary {
  background: var(--add);
  border-color: var(--add);
  color: var(--bg); /* contrast-safe on the green in both themes */
}
details.refmenu > summary::-webkit-details-marker,
details.clone-menu > summary::-webkit-details-marker { display: none; }
details.refmenu > summary::after,
details.clone-menu > summary::after { content: " \25be"; color: var(--muted); }
details.clone-menu > summary::after { color: var(--bg); }

/* Floating-panel chrome, shared by the desktop ref/clone dropdowns and
   the mobile ☰ panels.  The :checked selectors are inert on desktop —
   the toggles are display:none there, so they never match. */
.ref-panel, .clone-panel, .more-toggle:checked ~ .more-panel, .menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 15;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  font-size: 0.875rem;
  text-align: left;
}
.clone-panel { width: 24rem; max-width: 90vw; padding: 0.25rem 0.75rem 0.75rem; }
.ref-panel {
  display: flex;
  flex-direction: column;
  min-width: 9rem;
  max-height: 20rem;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
}
.ref-panel strong {
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  margin-top: 0.5rem;
}
.ref-panel strong:first-child { margin-top: 0; }
.ref-panel a { color: var(--fg); padding: 0.12rem 0; }
.ref-panel a.current { color: var(--accent); font-weight: 600; }
.ref-panel a:hover { color: var(--accent); text-decoration: none; }
.clone-panel label {
  display: block;
  margin: 0.5rem 0 0.2rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.copyrow { display: flex; gap: 0.25rem; }
.copyrow input {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  background: var(--code-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
}
.copyrow button {
  background: var(--code-bg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.copyrow button:hover { color: var(--fg); }
.clone-panel a.dl { display: inline-block; margin-top: 0.6rem; }

table { border-collapse: collapse; width: 100%; }
td {
  padding: 0.4rem 0.75rem 0.4rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: baseline;
}
td.subject { width: 100%; }
td.idle, td.author {
  color: var(--muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

/* Ref decorations (tags/branch heads) shown next to commits. */
.ref {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-right: 0.4rem;
  padding: 0 0.45rem;
  border: 1px solid;
  border-color: color-mix(in srgb, var(--c) 40%, var(--border));
  border-radius: 999px;
  font-size: 0.72rem;
  line-height: 1.55;
  white-space: nowrap;
  vertical-align: middle;
  color: var(--c);
}
.ref.tag { --c: var(--warn); }
.ref.branch { --c: var(--accent); }
.ref:hover { text-decoration: none; border-color: currentColor; }

code, pre, .sha, td.mode, kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
}

kbd {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
}

.keyhelp {
  position: fixed;
  inset: 0;
  z-index: 40; /* above the sticky header (20) and skip link (30) */
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}
.keyhelp > div {
  min-width: 22rem;
  padding: 1rem 1.5rem 1.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.keyhelp h2 { margin: 0 0 0.5rem; }
.keyhelp p.muted { margin: 0.75rem 0 0.25rem; }
.keyhelp table { width: auto; }
.keyhelp td { border: none; padding: 0.2rem 1rem 0.2rem 0; }

table.log tr.cur td { background: var(--code-bg); }
table.log tr.cur td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
table.log tr[hidden] { display: none; }

.readme, .fileframe {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-wrap: break-word;
}
.readme { margin-top: 1.5rem; }
.fileframe { margin-top: 1rem; }
.filehead {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: relative; /* anchor for the file menu dropdown */
  background: var(--code-bg);
  border-bottom: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  padding: 0.4rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
}
.filehead a { color: var(--muted); }
.filehead a:hover { color: var(--fg); text-decoration: none; }
.filehead a.active { color: var(--fg); font-weight: 600; }
.doc-title { color: var(--fg); font-weight: 600; }
.filesize { color: var(--muted); }
/* File-actions menu (README box + blob/blame frames): one ☰ dropdown of
   doc switches and source/raw/blame actions, at every width. */
.filemenu { position: relative; margin-left: auto; }
.filemenu > summary {
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  padding: 0 0.25rem;
  font-size: 1.1rem;
}
.filemenu > summary::-webkit-details-marker { display: none; }
.filemenu > summary:hover, .filemenu[open] > summary { color: var(--fg); }
.menu-panel {
  display: flex;
  flex-direction: column;
  min-width: 10rem;
  max-width: calc(100vw - 1.5rem);
  padding: 0.3rem 0;
}
.menu-panel a { padding: 0.4rem 0.9rem; color: var(--fg); }
.menu-panel a:hover { color: var(--accent); text-decoration: none; }
.menu-panel a.active { color: var(--accent); font-weight: 600; }
.menu-panel hr { border: 0; border-top: 1px solid var(--border); margin: 0.3rem 0; }
/* Blob/blame frame: the code/blame table joins the header seamlessly. */
.fileframe .scrollx { border: none; border-radius: 0 0 6px 6px; }
.fileframe .filebody { padding: 0.75rem 1rem; }
.readme .filebody { padding: 0.5rem 2rem 1rem; }
.readme img { max-width: 100%; }
.readme pre {
  background: var(--code-bg);
  padding: 0.75rem;
  border-radius: 6px;
  overflow-x: auto;
}
.readme code {
  background: var(--code-bg);
  padding: 0.15em 0.3em;
  border-radius: 4px;
}
.readme pre code { background: none; padding: 0; }
.readme blockquote {
  border-left: 3px solid var(--border);
  margin-left: 0;
  padding-left: 1rem;
  color: var(--muted);
}

/* GitHub alerts: > [!NOTE] etc. */
blockquote.alert { color: var(--fg); }
blockquote.alert::before {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.alert-note { border-left-color: var(--accent); }
.alert-note::before { content: "ℹ️ Note"; color: var(--accent); }
.alert-tip { border-left-color: var(--add); }
.alert-tip::before { content: "💡 Tip"; color: var(--add); }
.alert-important { border-left-color: var(--attn); }
.alert-important::before { content: "📣 Important"; color: var(--attn); }
.alert-warning { border-left-color: var(--warn); }
.alert-warning::before { content: "⚠️ Warning"; color: var(--warn); }
.alert-caution { border-left-color: var(--del); }
.alert-caution::before { content: "🛑 Caution"; color: var(--del); }
.readme table { width: auto; }
.readme th, .readme td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
}

h2 { font-size: 1.1rem; }
.pager { display: flex; margin-top: 1rem; }
.pager a.older { margin-left: auto; }

.logsearch {
  margin-left: auto;
  position: relative;
}
.logsearch input {
  width: 20rem;
  max-width: 100%;
  font: inherit;
  font-size: 0.875rem;
  background: var(--code-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 1.6rem 0.25rem 0.6rem;
}
.logsearch a.clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.8rem;
}
.logsearch a.clear:hover { color: var(--fg); text-decoration: none; }
.logsearch a.clear.idle { opacity: 0.35; pointer-events: none; }

td.mode {
  color: var(--muted);
  width: 1%;
  white-space: nowrap;
}
td.size {
  color: var(--muted);
  font-size: 0.875rem;
  text-align: right;
  white-space: nowrap;
}

/* Wide content scrolls inside its own box; the page column never
   grows past main's max-width. */
.scrollx {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  position: relative;
}
.linemark {
  position: absolute;
  left: 0;
  background: var(--mark);
  pointer-events: none;
}

table.blob td { border-bottom: none; vertical-align: top; }
table.blob pre { margin: 0; line-height: 1.45; }
td.nums {
  padding: 0.5rem 0.25rem 0.5rem 0.75rem;
  text-align: right;
  user-select: none;
}
td.nums a { color: var(--muted); }
td.nums a:target, td.nums a.sel { color: var(--accent); font-weight: 600; }
td.code { width: 100%; padding: 0.5rem 0.75rem; }
td.code pre code { background: none; padding: 0; }

table.blame { font-size: 0.875rem; }
table.blame td {
  border-bottom: none;
  padding: 0 0.5rem;
  line-height: 1.45;
  vertical-align: top;
}
table.blame tr.grp td { border-top: 1px solid var(--border); }
table.blame tr:first-child td { border-top: none; }
table.blame td.who { white-space: nowrap; }
table.blame td.nums {
  text-align: right;
  user-select: none;
}
table.blame td.nums a { color: var(--muted); }
table.blame td.nums a:target { color: var(--accent); font-weight: 600; }
table.blame td.line {
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  width: 100%;
}

/* Commit view: subject + message in a bounding box with a metadata
   footer; the body wraps so long lines don't overflow on mobile. */
.commitbox {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 1.5rem 0 1rem;
  overflow-wrap: break-word;
}
.commitbox .subject { margin: 0; padding: 0.75rem 1rem 0.5rem; font-size: 1.1rem; }
.commitbox .body {
  margin: 0;
  padding: 0 1rem 0.75rem;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.commitmeta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--code-bg);
  border-radius: 0 0 6px 6px;
  color: var(--muted);
  font-size: 0.875rem;
}
pre.diff {
  background: var(--code-bg);
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.45;
}
.diff .file { font-weight: 600; }
.diff .meta { color: var(--muted); }
.diff .hunk { color: var(--accent); }
.diff .add { color: var(--add); }
.diff .del { color: var(--del); }

/* Mobile: wrap the nav rows and the search onto their own lines
   instead of forcing a page-wide horizontal scroll. */
@media (max-width: 40rem) {
  /* keep the base padding-bottom (footer gap); only trim the rest */
  header nav, main {
    padding-top: 0.6rem;
    padding-left: 0.8rem;
    padding-right: 0.8rem;
  }
  .spacer { display: none; }
  /* Nav ☰ mechanics: a visually-hidden but focusable checkbox, a label
     acting as the ☰ button, an opened column panel, and a full-viewport
     backdrop to tap-close (no JS). */
  .more-toggle {
    position: absolute; /* off-screen but focusable for keyboard */
    width: 1px;
    height: 1px;
    opacity: 0;
  }
  .more-summary {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--muted);
    padding: 0.35rem 0.5rem;
  }
  .more-toggle:focus-visible + .more-summary {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .more-toggle:checked + .more-summary { color: var(--fg); }
  /* Opened panel: a uniform column that fits its contents (chrome comes
     from the shared floating-panel rule). */
  .more-toggle:checked ~ .more-panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: max-content; /* fits what's shown; grows when a section opens */
    max-width: calc(100vw - 1.5rem);
    padding: 0.25rem 0;
  }
  .more-toggle:checked ~ .more-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 14; /* tap-close layer: below the panel (z 15), above the page */
  }

  /* Nav "more" menu: the branch/clone <details> flatten into accordion
     sections rather than the desktop's bordered dropdowns. */
  .more-panel { display: none; }
  .more-toggle:checked ~ .more-panel { max-height: 75vh; overflow-y: auto; font-size: 0.9rem; }
  .more-panel > a,
  .more-panel details > summary { padding: 0.5rem 0.9rem; color: var(--fg); }
  .more-panel details { position: static; }
  .more-panel details > summary {
    display: block;
    background: none;
    border: none;
    border-radius: 0;
    font-size: inherit;
  }
  .more-panel details > summary::after { content: " \25b8"; color: var(--muted); }
  .more-panel details[open] > summary::after { content: " \25be"; }
  /* Section body: indented plain rows, no inner box or scrollbar —
     the whole menu scrolls as one. */
  .more-panel .ref-panel,
  .more-panel .clone-panel {
    position: static;
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: none;
    overflow: visible;
    background: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0 0.9rem 0.4rem 1.5rem; /* indent sub-items */
  }
  .more-panel .ref-panel a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .more-panel .clone-panel a.dl { display: block; margin-top: 0.4rem; }
  /* let the URL field shrink so the copy button stays on-screen */
  .more-panel .copyrow input { min-width: 0; }
  .logsearch { margin-left: 0; width: 100%; }
  .logsearch input { width: 100%; }
  .keyhelp > div { min-width: 0; width: calc(100% - 2rem); }
  /* Commit list: drop author/date and keep the subject to one
     clamped line — tap the commit for the full details. */
  table.log td.author, table.log td.idle { display: none; }
  table.log td.subject {
    max-width: 0; /* shrink-to-fit so the cell clips and ellipsizes */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
