:root {
  color-scheme: light dark;
  --fg: #1c1c1c;
  --bg: #fdfdfc;
  --muted: #6b6b6b;
  --border: #e3e1dc;
  --accent: #a8481f;
  --accent-soft: #a8481f1a;
  --code-bg: #f1efe9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #ececec;
    --bg: #16151a;
    --muted: #96938e;
    --border: #2c2b32;
    --accent: #e8825a;
    --accent-soft: #e8825a26;
    --code-bg: #201f26;
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font: 17px/1.65 "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

.wrap {
  display: flex;
  max-width: 960px;
  margin: 0 auto;
  align-items: flex-start;
}

.sidebar {
  flex: 0 0 230px;
  padding: 2.25rem 1.5rem 2rem 0;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}

.nav-toggle {
  display: none;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.home {
  display: block;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  margin-bottom: 1.5rem;
  color: var(--fg);
  text-decoration: none;
}

.hamburger {
  display: none;
}

.toc-label {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

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

.toc li {
  counter-increment: item;
  margin: 0;
}

.toc a {
  display: flex;
  gap: 0.5em;
  padding: 0.3rem 0.5rem;
  margin: 0 -0.5rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  line-height: 1.4;
}

.toc a::before {
  content: counter(item);
  color: var(--muted);
  opacity: 0.6;
  font-variant-numeric: tabular-nums;
  min-width: 1.1em;
}

.toc a:hover {
  background: var(--accent-soft);
  color: var(--fg);
}

.toc li.current a {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.github {
  display: block;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}

.github:hover {
  color: var(--accent);
}

main {
  flex: 1;
  min-width: 0;
  padding: 2.5rem 1.75rem 5rem;
  border-left: 1px solid var(--border);
}

article {
  max-width: 640px;
}

article h1 {
  margin-top: 0;
  font-size: 1.9rem;
  letter-spacing: -0.01em;
}

article h2 {
  font-size: 1.3rem;
  margin-top: 2.5rem;
}

article h3 {
  font-size: 1.05rem;
}

article p, article li {
  color: var(--fg);
}

article ul, article ol {
  padding-left: 1.3rem;
}

article blockquote {
  margin: 1.5rem 0;
  padding: 0.25rem 1.25rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

article code {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
}

article pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1em;
  overflow-x: auto;
}

article pre code {
  display: block;
  background: none;
  padding: 0;
  border-radius: 0;
}

article table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
  width: 100%;
  max-width: 100%;
  font-size: 0.92rem;
}

article th, article td {
  border: 1px solid var(--border);
  padding: 0.45em 0.7em;
  text-align: left;
  white-space: nowrap;
}

article th {
  background: var(--code-bg);
}

article img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

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

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: 640px;
  margin-top: 3.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.95rem;
}

.pager a {
  text-decoration: none;
  color: var(--fg);
  font-weight: 500;
}

.pager a:hover {
  color: var(--accent);
}

.pager .next {
  margin-left: auto;
  text-align: right;
}

@media (max-width: 760px) {
  .wrap {
    flex-direction: column;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    max-height: none;
    flex: none;
    width: 100%;
    padding: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }

  .sidebar-top {
    padding: 1rem 1.25rem;
  }

  .home {
    margin-bottom: 0;
  }

  .hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 28px;
    height: 28px;
    cursor: pointer;
  }

  .hamburger span {
    display: block;
    height: 2px;
    background: var(--fg);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .toc {
    max-height: 0;
    overflow: hidden;
    padding: 0 1.25rem;
    transition: max-height 0.2s ease, padding 0.2s ease;
  }

  .toc-label {
    margin: 1rem 0 0.5rem;
  }

  .nav-toggle:checked ~ .wrap .toc {
    max-height: 70vh;
    overflow-y: auto;
    padding: 0 1.25rem 1rem;
  }

  .nav-toggle:checked ~ .wrap .hamburger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }
  .nav-toggle:checked ~ .wrap .hamburger span:nth-child(2) {
    opacity: 0;
  }
  .nav-toggle:checked ~ .wrap .hamburger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  .toc a {
    padding: 0.55rem 0.6rem;
    font-size: 1rem;
  }

  main {
    border-left: none;
    padding: 1.75rem 1.25rem 3rem;
  }

  article {
    max-width: 100%;
  }

  .pager {
    flex-direction: column;
    gap: 0.6rem;
    max-width: 100%;
  }

  .pager .next {
    margin-left: 0;
    text-align: left;
  }
}

@media (max-width: 420px) {
  body { font-size: 16px; }
  article h1 { font-size: 1.6rem; }
}
