:root {
  --bg: #fafaf9;
  --side: #f3f2f0;
  --fg: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --hover: #e9e7e4;
  --code-bg: #efeeeb;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0d;
    --side: #131312;
    --fg: #e7e5e4;
    --muted: #8a8580;
    --line: #232221;
    --hover: #1c1b1a;
    --code-bg: #1a1918;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 17px/1.7 var(--sans);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }

a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  transition: color .15s, background .15s;
}
a:hover { color: var(--accent); }

.num {
  font: 400 0.75rem var(--mono);
  color: var(--accent);
}

/* ── Layout ───────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* ── Sidebar explorer ─────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 32px 16px;
  background: var(--side);
  border-right: 1px solid var(--line);
  font-family: var(--mono);
}

.brand {
  display: block;
  padding: 0 8px;
  margin-bottom: 40px;
  font: 700 1rem/1.3 var(--sans);
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand span { color: var(--accent); }

.label {
  margin: 0 0 8px;
  padding: 0 8px;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.tree { font-size: 0.82rem; }
.tree a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  border-left: 2px solid transparent;
}
.tree a:hover { background: var(--hover); color: var(--fg); }
.tree a.active {
  background: var(--hover);
  color: var(--fg);
  border-left-color: var(--accent);
}
.tree .dir { color: var(--fg); gap: 6px; }
.caret { font-size: 0.7rem; color: var(--muted); }
.tree ul { list-style: none; margin: 2px 0 0; padding: 0 0 0 14px; }
.tree .num { font-size: 0.68rem; opacity: .8; }

.links {
  list-style: none;
  margin: auto 0 0;
  padding: 24px 8px 0;
  font-size: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}
.links a { color: var(--muted); text-decoration: none; }
.links a:hover { color: var(--accent); }

/* ── Main column ──────────────────────── */
.main {
  width: 100%;
  max-width: 720px;
  padding: 96px 48px 48px;
  animation: rise .5s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .main { animation: none; }
}

/* Home */
.hero h1 {
  font-size: clamp(2.2rem, 6vw, 3.2rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin: 0 0 16px;
}
.hero h1 span { color: var(--accent); }
.tagline {
  color: var(--muted);
  font-size: 1.15rem;
  margin: 0 0 56px;
  max-width: 34em;
}

.index { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.index a {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: baseline;
  column-gap: 8px;
  padding: 18px 4px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.index .t { font-weight: 500; }
.index .s { grid-column: 2; color: var(--muted); font-size: 0.92rem; }
.index .arrow { grid-column: 3; grid-row: 1; color: var(--muted); transition: transform .15s, color .15s; }
.index a:hover .arrow { transform: translateX(4px); color: var(--accent); }
.index a:hover .t { color: var(--accent); }

/* Section page */
.crumb {
  margin: 0 0 12px;
  font: 400 0.78rem var(--mono);
  color: var(--muted);
}
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--accent); }

.page h1 {
  font-size: clamp(1.9rem, 5vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin: 0 0 32px;
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.pager a { text-decoration: none; font-weight: 500; }
.pager small {
  display: block;
  font: 400 0.72rem var(--mono);
  color: var(--muted);
}
.pager .next { text-align: right; margin-left: auto; }

/* ── Markdown content ─────────────────── */
.content h2 { font-size: 1.3rem; letter-spacing: -0.02em; margin: 40px 0 12px; }
.content h3 { font-size: 1.05rem; margin: 32px 0 4px; }
.content > :first-child { margin-top: 0; }
.content p, .content ul, .content ol { margin: 0 0 16px; }
.content ul, .content ol { padding-left: 1.2em; }
.content li { margin-bottom: 6px; }
.content li::marker { color: var(--accent); }
.content strong { font-weight: 600; }
.content hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
.content img { max-width: 100%; height: auto; border-radius: 8px; }
.content blockquote {
  margin: 0 0 16px;
  padding-left: 16px;
  border-left: 2px solid var(--accent);
  color: var(--muted);
}
.content code {
  font: 0.85em var(--mono);
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
}
.content pre {
  background: var(--code-bg);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
}
.content pre code { background: none; padding: 0; }
.content table { width: 100%; border-collapse: collapse; font-size: 0.95em; margin-bottom: 16px; }
.content th, .content td { text-align: left; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); }

/* "*label*" on the line right under a ### heading becomes a small grey tag */
.content h3 + p > em:first-child {
  display: block;
  color: var(--muted);
  font: normal 0.8rem/1.6 var(--mono);
  margin-bottom: 2px;
}

footer {
  margin-top: 80px;
  font: 400 0.75rem var(--mono);
  color: var(--muted);
}
footer p { margin: 0; }

/* ── Small screens: explorer moves to the top ── */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .shell { display: block; }
  .sidebar {
    position: static;
    height: auto;
    padding: 20px 16px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { margin-bottom: 16px; }
  .label { display: none; }
  .tree { display: flex; flex-wrap: wrap; gap: 2px; }
  .tree ul { display: contents; }
  .tree .caret { display: none; }
  .tree a { border-left: 0; border-bottom: 2px solid transparent; border-radius: 4px; }
  .tree a.active { border-bottom-color: var(--accent); }
  .links { margin-top: 12px; padding-top: 0; }
  .main { padding: 40px 16px 32px; }
}
