* { margin: 0; padding: 0; box-sizing: border-box; outline: none; }

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --text: #222;
  --text-secondary: #555;
  --muted: #888;
  --faint: #bbb;
  --link: #0366d6;
  --bg: #fff;
  --bg-subtle: #f6f8fa;
  --border: #eee;
  --input-bg: #fff;
  --input-border: #ddd;
  --highlight: #fff3b0;
  --error: #d00;
  --radius: 3px;
  --input-padding: 0.3rem 0.5rem;
  --input-font: 0.85rem;
  --pill-font: 0.7rem;
  --pill-padding: 0.1em 0.5em;
  --callout-note: #0366d6;
  --callout-tip: #28a745;
  --callout-warning: #d29922;
  --callout-important: #6f42c1;
  --callout-caution: #d73a49;
}

[data-theme="dark"] {
  --text: #d4d4d4;
  --text-secondary: #999;
  --muted: #777;
  --faint: #555;
  --link: #6db3f2;
  --bg: #1e1e1e;
  --bg-subtle: #2a2a2a;
  --border: #333;
  --input-bg: #252525;
  --input-border: #444;
  --highlight: #4a4020;
  --error: #f55;
  --callout-note: #6db3f2;
  --callout-tip: #3fb950;
  --callout-warning: #d29922;
  --callout-important: #a371f7;
  --callout-caution: #f85149;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: #d4d4d4;
    --text-secondary: #999;
    --muted: #777;
    --faint: #555;
    --link: #6db3f2;
    --bg: #1e1e1e;
    --bg-subtle: #2a2a2a;
    --border: #333;
    --input-bg: #252525;
    --input-border: #444;
    --highlight: #4a4020;
    --error: #f55;
    --callout-note: #6db3f2;
    --callout-tip: #3fb950;
    --callout-warning: #d29922;
    --callout-important: #a371f7;
    --callout-caution: #f85149;
  }
}

/* --- Layout --- */

html { min-height: 100%; scrollbar-gutter: stable; }

body {
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

/* --- Shared input/button --- */

input, button {
  font-family: var(--font);
  font-size: var(--input-font);
  padding: var(--input-padding);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
}

button {
  cursor: pointer;
  white-space: nowrap;
}

button:hover { background: var(--bg-subtle); }

/* --- Nav --- */

header nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: var(--input-font);
}

header nav a { color: var(--text-secondary); text-decoration: none; white-space: nowrap; }
header nav a:hover { color: var(--text); }
.nav-brand { font-weight: 600; }

.nav-search { display: flex; align-items: center; gap: 0.4rem; flex: 1; }
.nav-search input { flex: 1; min-width: 0; }
.clear-search { color: var(--faint); }
.clear-search:hover { color: var(--error); }

.nav-actions { display: flex; align-items: center; gap: 0.6rem; white-space: nowrap; }

.theme-toggle {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  padding: 0;
  line-height: 1;
}

.theme-toggle:hover { color: var(--text); background: none; }

/* --- Breadcrumbs --- */

.breadcrumbs {
  font-size: var(--input-font);
  color: var(--muted);
  margin-bottom: 1rem;
}

.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--link); }
.breadcrumbs span { color: var(--text-secondary); }

/* --- Table of Contents --- */

.toc {
  margin-bottom: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg-subtle);
  border-radius: var(--radius);
  font-size: var(--input-font);
}

.toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc li { padding: 0.15rem 0; }
.toc li a { color: var(--text-secondary); text-decoration: none; }
.toc li a:hover { color: var(--link); }

.toc .toc-h3 { padding-left: 1rem; }
.toc .toc-h4 { padding-left: 2rem; }

/* --- Headings --- */

h1 { font-size: 1.3rem; margin-bottom: 1rem; font-weight: 600; }

/* --- Article / document --- */

article h1 { font-size: 1.6rem; margin: 1.5rem 0 1rem; }
article h2 { font-size: 1.3rem; margin: 1.3rem 0 0.8rem; }
article h3 { font-size: 1.1rem; margin: 1rem 0 0.6rem; }
article p { margin-bottom: 1rem; }
article ul, article ol { margin: 0 0 1rem 1.5rem; }
article a { color: var(--link); }
article img { max-width: 100%; }

/* Heading anchor links */
article h1, article h2, article h3, article h4, article h5, article h6 {
  position: relative;
}

article h1:hover::before, article h2:hover::before, article h3:hover::before,
article h4:hover::before, article h5:hover::before, article h6:hover::before {
  content: "#";
  position: absolute;
  left: -1.2em;
  color: var(--faint);
  font-weight: 400;
}

article h1 a[id], article h2 a[id], article h3 a[id],
article h4 a[id], article h5 a[id], article h6 a[id] {
  text-decoration: none;
  color: inherit;
}

article pre {
  background: var(--bg-subtle);
  padding: 1rem;
  overflow-x: auto;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: var(--input-font);
}

article code {
  font-family: var(--mono);
  font-size: 0.85em;
}

article p code, article li code {
  background: var(--bg-subtle);
  padding: 0.2em 0.4em;
  border-radius: var(--radius);
}

article blockquote {
  border-left: 3px solid var(--input-border);
  padding-left: 1rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

article table {
  border-collapse: collapse;
  margin-bottom: 1rem;
  width: 100%;
}

article th, article td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  text-align: left;
}

article th {
  background: var(--bg-subtle);
  font-weight: 600;
}

/* --- Callout / Admonition blocks --- */

.callout {
  border-left-width: 4px;
  border-left-style: solid;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  background: var(--bg-subtle);
}

.callout::before {
  display: block;
  font-weight: 600;
  font-size: var(--input-font);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.3rem;
}

.callout-note { border-left-color: var(--callout-note); }
.callout-note::before { content: "Note"; color: var(--callout-note); }

.callout-tip { border-left-color: var(--callout-tip); }
.callout-tip::before { content: "Tip"; color: var(--callout-tip); }

.callout-warning { border-left-color: var(--callout-warning); }
.callout-warning::before { content: "Warning"; color: var(--callout-warning); }

.callout-important { border-left-color: var(--callout-important); }
.callout-important::before { content: "Important"; color: var(--callout-important); }

.callout-caution { border-left-color: var(--callout-caution); }
.callout-caution::before { content: "Caution"; color: var(--callout-caution); }

.callout p:last-child { margin-bottom: 0; }

/* --- Footnotes --- */

.footnotes {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: var(--input-font);
  color: var(--text-secondary);
}

.footnotes hr { display: none; }
.footnotes ol { padding-left: 1.5rem; }
.footnotes li { margin-bottom: 0.3rem; }

sup a { color: var(--link); text-decoration: none; font-size: 0.8em; }
sup a:hover { text-decoration: underline; }

.footnote-backref { text-decoration: none; margin-left: 0.2em; }

/* --- Listing --- */

.listing { list-style: none; }
.listing li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.listing li a { color: var(--link); text-decoration: none; font-weight: 500; font-size: 0.95rem; }
.listing li a:hover { text-decoration: underline; }

.entry-meta { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.15rem; flex-wrap: wrap; }

.snippet { font-size: var(--input-font); color: var(--text-secondary); margin-top: 0.15rem; }
.snippet mark { background: var(--highlight); padding: 0.05em 0.1em; border-radius: 2px; }

/* --- Pills: date, badge, tag --- */

.date { font-size: var(--pill-font); color: var(--muted); }

.badge {
  font-size: var(--pill-font);
  padding: var(--pill-padding);
  border-radius: var(--radius);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--muted);
}

.tag {
  font-size: var(--pill-font);
  padding: var(--pill-padding);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--muted);
  text-decoration: none;
}

a.tag:hover {
  color: var(--link);
}

/* --- Document footer --- */

.doc-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* --- Backlinks --- */

.backlinks {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.backlinks h3 {
  font-size: var(--input-font);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.5rem;
}

.backlinks ul {
  list-style: none;
  padding: 0;
}

.backlinks li { padding: 0.2rem 0; }
.backlinks a { color: var(--link); text-decoration: none; font-size: var(--input-font); }
.backlinks a:hover { text-decoration: underline; }

/* --- Login --- */

.login { margin-top: 4rem; text-align: center; }
.login input { width: 250px; font-size: 0.95rem; padding: 0.4rem 0.6rem; }
.login button { font-size: 0.95rem; padding: 0.4rem 0.8rem; margin-left: 0.5rem; }
.error { color: var(--error); margin-bottom: 1rem; font-size: var(--input-font); }

/* --- Site footer --- */

.site-footer {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: var(--pill-font);
  color: var(--muted);
  text-align: center;
}

.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); }

/* --- Mobile --- */

@media (max-width: 600px) {
  body { padding: 1rem 0.75rem; }

  header nav {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .nav-search { order: 3; flex-basis: 100%; }

  .login input { width: 100%; }
  .login button { margin-left: 0; margin-top: 0.5rem; width: 100%; }

  article pre { padding: 0.75rem; font-size: 0.8rem; }

  article h1:hover::before, article h2:hover::before, article h3:hover::before,
  article h4:hover::before, article h5:hover::before, article h6:hover::before {
    content: none;
  }
}
