:root {
  color-scheme: light dark;
  --bg: #fdfdfc;
  --fg: #1c1b19;
  --muted: #6b6a66;
  --rule: #e2e0db;
  --panel: #f5f4f1;
  --accent: #2f5d8f;
  --broken: #a8322a;
  --mark-bg: #fbe6a2;
  --mark-fg: #241f10;
  --shadow: 0 8px 24px rgb(0 0 0 / 12%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --fg: #e6e5e1;
    --muted: #9b9a95;
    --rule: #2e3033;
    --panel: #1e2023;
    --accent: #8fb6e0;
    --broken: #e08b83;
    --mark-bg: #5a4a1c;
    --mark-fg: #f6efdc;
    --shadow: 0 8px 24px rgb(0 0 0 / 45%);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1.2rem;
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
}

.brand {
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--fg);
}

.session { display: flex; align-items: center; gap: 0.7rem; margin: 0; }
.who { color: var(--muted); font-size: 0.9rem; }

.search { position: relative; flex: 1 1 auto; max-width: 34rem; }

.search-icon {
  position: absolute;
  top: 50%;
  left: 0.7rem;
  width: 1rem;
  height: 1rem;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  pointer-events: none;
}

.search input {
  font: inherit;
  width: 100%;
  padding: 0.4rem 2.2rem 0.4rem 2.2rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  appearance: none;
}

.search input::-webkit-search-cancel-button { appearance: none; }

.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.search-hint {
  position: absolute;
  top: 50%;
  right: 0.6rem;
  padding: 0.05rem 0.4rem;
  transform: translateY(-50%);
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  pointer-events: none;
}

/* Only worth showing while the box sits idle and empty. */
.search input:focus ~ .search-hint,
.search input:not(:placeholder-shown) ~ .search-hint { display: none; }

.search-results {
  position: absolute;
  z-index: 10;
  top: calc(100% + 0.4rem);
  left: 0;
  right: 0;
  max-height: min(70vh, 32rem);
  overflow-y: auto;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

/* One row per document, three columns, each cut on its own. The list is meant
   to be scanned down the left edge, so the title column keeps a fixed width
   whatever the snippets do. */
.hit {
  display: grid;
  grid-template-columns: minmax(0, 14rem) minmax(0, 1fr) auto;
  gap: 0 0.9rem;
  align-items: center;
  padding: 0.38rem 0.85rem;
  border-bottom: 1px solid var(--rule);
  color: inherit;
  text-decoration: none;
}

.hit > * { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hit:last-child { border-bottom: none; }
.hit:hover, .hit.current { background: var(--panel); }

.hit-name { font-weight: 600; color: var(--accent); }

.hit-snippet { color: var(--muted); font-size: 0.84rem; }

.hit-count {
  min-width: 1.5em;
  text-align: right;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

mark { padding: 0 0.12em; border-radius: 2px; background: var(--mark-bg); color: var(--mark-fg); }

.search-notice { margin: 0; padding: 0.7rem 0.8rem; color: var(--muted); font-size: 0.85rem; }

button {
  font: inherit;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: minmax(200px, 260px) minmax(0, 1fr);
  align-items: start;
}

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--rule); }
  .topbar { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  /* Too narrow for three columns; the snippet takes a line of its own. */
  .hit { grid-template-columns: minmax(0, 1fr) auto; }
  .hit-snippet { grid-column: 1 / -1; }
}

.sidebar {
  padding: 1rem 1.2rem;
  border-right: 1px solid var(--rule);
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}

.sidebar a { text-decoration: none; }
.sidebar a:hover { text-decoration: underline; }

/* One step of indentation per level, drawn on the nested list rather than the
   item, so a folder's own row stays flush with its siblings. */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 0.55rem; padding-left: 0.6rem; border-left: 1px solid var(--rule); }
.tree li { margin: 0.15rem 0; }
.tree a { text-decoration: none; }
.tree a:hover { text-decoration: underline; }
.tree li.current > a, .tree a.current { font-weight: 600; color: var(--fg); }

.tree-folder > .folder-name {
  display: block;
  margin-top: 0.5rem;
  font-weight: 600;
}

/* No gap above the very first row; the repository's front page starts the list. */
.tree > .tree-folder:first-child > .folder-name { margin-top: 0; }

.tree-folder > span.folder-name { color: var(--muted); }

.tree-page { max-width: 34rem; font-size: 1rem; }
.tree-page ul { margin-left: 0.7rem; padding-left: 0.9rem; }
.tree-page li { margin: 0.25rem 0; }

.sidebar-foot {
  margin: 1.4rem 0 0;
  padding-top: 0.7rem;
  border-top: 1px solid var(--rule);
  font-size: 0.82rem;
}

main { padding: 1.5rem 2rem 4rem; min-width: 0; }

.doc { max-width: 46rem; }
.doc h1 { margin-top: 0; line-height: 1.25; }
.doc .meta { color: var(--muted); font-size: 0.85rem; }
.doc pre {
  overflow-x: auto;
  padding: 0.8rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--panel);
}
.doc :not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--panel);
  font-size: 0.9em;
}
.doc blockquote {
  margin: 1rem 0;
  padding: 0.2rem 1rem;
  border-left: 3px solid var(--rule);
  color: var(--muted);
}
.doc table { border-collapse: collapse; display: block; overflow-x: auto; }
.doc th, .doc td { padding: 0.4rem 0.7rem; border: 1px solid var(--rule); }
.doc img { max-width: 100%; }

.broken {
  color: var(--broken);
  text-decoration: underline dotted;
  cursor: help;
}

.doclist { list-style: none; margin: 1rem 0; padding: 0; }
.doclist li { padding: 0.4rem 0; border-bottom: 1px solid var(--rule); }

.signin { max-width: 22rem; margin: 3rem auto; }
.signin div { margin-bottom: 0.8rem; }
.signin input { font: inherit; width: 100%; padding: 0.4rem; border: 1px solid var(--rule); border-radius: 6px; }
.error { color: var(--broken); }
.empty { color: var(--muted); }
