/* forge — hand-written styles, no framework. */
:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --fg: #1f2328;
  --muted: #656d76;
  --border: #d0d7de;
  --accent: #0969da;
  --accent-fg: #ffffff;
  --ok: #1a7f37;
  --ok-bg: #dafbe1;
  --bad: #cf222e;
  --bad-bg: #ffebe9;
  --merged: #8250df;
  --add-bg: #e6ffec;
  --del-bg: #ffebe9;
  --hunk-bg: #ddf4ff;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-soft: #161b22;
    --fg: #e6edf3;
    --muted: #8d96a0;
    --border: #30363d;
    --accent: #4493f8;
    --ok: #3fb950;
    --ok-bg: #12261e;
    --bad: #f85149;
    --bad-bg: #2d1214;
    --merged: #a371f7;
    --add-bg: #12261e;
    --del-bg: #2d1214;
    --hunk-bg: #121d2f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }
code, .mono, pre, textarea.mono { font-family: var(--mono); font-size: 0.875rem; }
pre { overflow-x: auto; }
hr { border: 0; border-top: 1px solid var(--border); }

/* layout */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.6rem 1rem; background: var(--bg-soft); border-bottom: 1px solid var(--border);
}
.topbar nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--fg); }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
footer { text-align: center; padding: 2rem 1rem; font-size: 0.85rem; }
.narrow { max-width: 480px; margin: 2rem auto; }
.narrow-left { max-width: 720px; }
.center { text-align: center; }
.spacer { flex: 1; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.pad { padding: 1rem; }
.inline { display: inline; margin: 0; }
.bar { display: flex; align-items: center; gap: 1rem; justify-content: space-between; flex-wrap: wrap; }
.scroll { overflow-x: auto; }

/* text */
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.plus { color: var(--ok); }
.minus { color: var(--bad); }
.danger-text { color: var(--bad); }
.sha { font-size: 0.8rem; }

/* forms */
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.45rem 0.6rem; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[disabled] { background: var(--bg-soft); color: var(--muted); }
textarea { width: 100%; resize: vertical; }
.stack { display: flex; flex-direction: column; gap: 0.8rem; margin-bottom: 1rem; }
.stack label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; }
.stack label.check { flex-direction: row; align-items: center; font-weight: normal; }
.row-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0 0 1rem; }
.row-form input[type=search], .row-form input[type=email] { flex: 1; min-width: 12rem; }
label.check { display: inline-flex; gap: 0.35rem; align-items: center; }
input.wide, .wide { width: 100%; }
.small-input { width: 12rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); display: flex; gap: 1rem; flex-wrap: wrap; }

/* buttons */
.btn, button {
  display: inline-block; font: inherit; font-size: 0.9rem; line-height: 1.2;
  padding: 0.45rem 0.9rem; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--fg);
}
.btn:hover, button:hover { text-decoration: none; filter: brightness(0.97); }
.btn.primary, button.primary { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger, button.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad); color: #fff; }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); }

/* flashes, badges */
.flash { padding: 0.6rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-soft); }
.flash.error { background: var(--bad-bg); border-color: var(--bad); }
.flash.ok { background: var(--ok-bg); border-color: var(--ok); }
.badge {
  display: inline-block; font-size: 0.75rem; padding: 0.05rem 0.5rem;
  border: 1px solid var(--border); border-radius: 2rem; color: var(--muted); vertical-align: middle;
}
.pill { display: inline-block; padding: 0.2rem 0.75rem; border-radius: 2rem; color: #fff; font-weight: 600; font-size: 0.85rem; }
.pill.open { background: var(--ok); }
.pill.closed { background: var(--bad); }
.pill.merged { background: var(--merged); }
.state-dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; flex: none; margin-top: 0.45rem; }
.state-dot.open { background: var(--ok); }
.state-dot.closed { background: var(--merged); }

/* cards and lists */
.card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; }
.card.flush { padding: 0; }
.card-head {
  display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap;
  padding: 0.6rem 1rem; background: var(--bg-soft); border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}
.list { list-style: none; margin: 0 0 1rem; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); }
.row { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.7rem 1rem; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.title { font-weight: 600; color: var(--fg); }
.danger-zone { border-color: var(--bad); }

/* repo header and tabs */
.repo-head h1 { font-weight: normal; margin-bottom: 0.25rem; }
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin: 0.75rem 0 1rem; overflow-x: auto; }
.tabs a { padding: 0.5rem 0.9rem; color: var(--fg); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { border-bottom-color: #fd8c73; font-weight: 600; }
.tabs a:hover { text-decoration: none; background: var(--bg-soft); }
.tabs.sub { border-bottom: 0; margin-top: 0; }
.toolbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.75rem; }
.toolbar h2 { margin: 0.5rem 0; }
.crumbs { font-size: 1rem; }
.pager { display: flex; gap: 0.5rem; justify-content: center; margin: 1rem 0; }

/* dropdowns built on <details> */
details.menu, details.clone { position: relative; }
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
.dropdown {
  position: absolute; z-index: 10; right: 0; margin-top: 0.25rem; min-width: 14rem; max-height: 22rem; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 0.5rem; display: flex; flex-direction: column; gap: 0.25rem;
}
details.menu:first-child .dropdown { left: 0; right: auto; }
.dropdown a { padding: 0.3rem 0.5rem; border-radius: 4px; color: var(--fg); }
.dropdown a.active { font-weight: 700; }
.dropdown a:hover { background: var(--bg-soft); text-decoration: none; }
.dropdown label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--muted); }
.dropdown input { width: 22rem; max-width: 70vw; }
details.card > summary { font-weight: 600; }

/* file tree */
table { border-collapse: collapse; width: 100%; }
.files td { padding: 0.45rem 1rem; border-top: 1px solid var(--border); }
.files tr:first-child td { border-top: 0; }
.icon { display: inline-block; width: 1rem; height: 0.8rem; margin-right: 0.5rem; border-radius: 2px; vertical-align: -1px; }
.icon.dir { background: #54aeff; }
.icon.file { border: 1px solid var(--muted); }
.icon.sub { background: var(--muted); }
.grid th, .grid td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid form.row-form { margin: 0; }

/* code and diffs */
.code { font-family: var(--mono); font-size: 0.82rem; line-height: 1.45; }
.code td { padding: 0 0.75rem; vertical-align: top; }
.code .num {
  width: 1%; min-width: 3rem; text-align: right; color: var(--muted); user-select: none; white-space: nowrap;
  border-right: 1px solid var(--border);
}
.code .num a { color: var(--muted); }
.code .src { white-space: pre; }
.code tr:target { background: #fff8c5; }
@media (prefers-color-scheme: dark) { .code tr:target { background: #3b2e00; } }
.diff tr.add { background: var(--add-bg); }
.diff tr.del { background: var(--del-bg); }
.diff tr.hunk { background: var(--hunk-bg); color: var(--muted); }
.diff tr.note { color: var(--muted); font-style: italic; }
.diff tr.add .src::before { content: "+"; }
.diff tr.del .src::before { content: "-"; }
.diff tr.ctx .src::before { content: " "; }
.file-diff { border: 1px solid var(--border); border-radius: var(--radius); margin: 1rem 0; overflow: hidden; }
.file-head { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; padding: 0.5rem 1rem; background: var(--bg-soft); border-bottom: 1px solid var(--border); }
.file-head .stat { margin-left: auto; font-size: 0.85rem; }
.status { font-size: 0.7rem; text-transform: uppercase; padding: 0.05rem 0.4rem; border-radius: 4px; border: 1px solid var(--border); }
.status.added { color: var(--ok); }
.status.deleted { color: var(--bad); }
.status.renamed { color: var(--merged); }
pre.plain { white-space: pre-wrap; word-break: break-word; margin: 0.5rem 0; }
pre.snippet { margin: 0.2rem 0 0; color: var(--muted); }
img.preview { max-width: 100%; }

/* markdown */
.readme .markdown { padding: 0 1.5rem 1rem; }
.markdown { overflow-wrap: break-word; }
.markdown pre { background: var(--bg-soft); padding: 0.8rem; border-radius: var(--radius); }
.markdown code { background: var(--bg-soft); padding: 0.1rem 0.3rem; border-radius: 4px; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote { margin: 0; padding: 0 1rem; color: var(--muted); border-left: 0.25rem solid var(--border); }

/* issues */
.issue-head h2 { font-size: 1.6rem; font-weight: normal; margin-bottom: 0.25rem; }
.comment { border: 1px solid var(--border); border-radius: var(--radius); margin: 1rem 0; }
.comment header { padding: 0.5rem 1rem; background: var(--bg-soft); border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.comment .markdown { padding: 0 1rem; }
.comment-form { margin-top: 1rem; }
.event { padding-left: 1rem; }
.mergebox.clean { border-color: var(--ok); }
.mergebox.conflict { border-color: var(--bad); }
.mergebox.merged { border-color: var(--merged); }

@media (max-width: 640px) {
  main { padding: 0.75rem; }
  .topbar { gap: 0.6rem; }
  .small-input { width: 100%; }
  .toolbar .spacer { display: none; }
}
