:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --ink: #1c1917;
  --muted: #57534e;
  --line: #e7e5e4;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --sidebar-w: 280px;
  --max-prose: 44rem;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.06), 0 8px 24px rgba(28, 25, 23, 0.04);
  --font-sans: "SF Pro Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.55;
  min-height: 100%;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover { color: #115e59; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: #1c1917;
  color: #fafaf9;
  padding: 1rem 0.85rem 2rem;
  border-right: 1px solid #292524;
}

.brand {
  display: block;
  color: #fafaf9;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  padding: 0.35rem 0.5rem 0.75rem;
  border-bottom: 1px solid #44403c;
  margin-bottom: 0.75rem;
}
.brand span {
  display: block;
  font-weight: 400;
  font-size: 0.75rem;
  color: #a8a29e;
  margin-top: 0.2rem;
}

.search {
  width: 100%;
  border: 1px solid #44403c;
  background: #292524;
  color: #fafaf9;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-size: 0.85rem;
  margin-bottom: 0.85rem;
}
.search::placeholder { color: #a8a29e; }
.search:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.nav-section { margin-bottom: 0.85rem; }
.nav-section h2 {
  margin: 0.4rem 0.5rem 0.25rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a8a29e;
  font-weight: 600;
}
.nav-section a {
  display: block;
  color: #e7e5e4;
  text-decoration: none;
  font-size: 0.84rem;
  padding: 0.32rem 0.55rem;
  border-radius: 6px;
  line-height: 1.3;
}
.nav-section a:hover {
  background: #292524;
  color: #fff;
}
.nav-section a.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.nav-section a[hidden] { display: none; }

/* Main */
.main-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 245, 241, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.menu-btn {
  display: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  font: inherit;
  cursor: pointer;
}

.crumbs {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

.content {
  flex: 1;
  padding: 1.5rem 1.5rem 3rem;
}

.article {
  max-width: var(--max-prose);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem 1.9rem 2.25rem;
}

.article > :first-child { margin-top: 0; }

.article h1, .article h2, .article h3, .article h4 {
  font-family: var(--font-serif);
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.article h1 { font-size: 1.85rem; margin: 0 0 1rem; }
.article h2 {
  font-size: 1.35rem;
  margin: 1.75rem 0 0.65rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--line);
}
.article h2:first-of-type { border-top: 0; padding-top: 0; }
.article h3 { font-size: 1.1rem; margin: 1.25rem 0 0.45rem; }
.article p, .article li { font-size: 1.02rem; }
.article p { margin: 0.7rem 0; color: #292524; }
.article li { margin: 0.25rem 0; }
.article blockquote {
  margin: 1rem 0;
  padding: 0.15rem 0 0.15rem 1rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-family: var(--font-serif);
}
.article code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: #f5f5f4;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
.article pre {
  overflow: auto;
  background: #1c1917;
  color: #fafaf9;
  border-radius: 8px;
  padding: 0.9rem 1rem;
  font-size: 0.88rem;
  line-height: 1.45;
}
.article pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.article table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin: 1rem 0;
  display: block;
  overflow-x: auto;
}
.article th, .article td {
  border: 1px solid var(--line);
  padding: 0.45rem 0.6rem;
  text-align: left;
  vertical-align: top;
}
.article th { background: #f5f5f4; font-weight: 600; }
.article hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.5rem 0;
}
.article .wikilink-missing {
  color: #b45309;
  text-decoration: underline dotted;
}

.path-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--max-prose);
  margin: 0 auto 1rem;
}
.path-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
}
.path-nav a:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.path-nav .spacer { flex: 1; }

.footer-meta {
  max-width: var(--max-prose);
  margin: 1rem auto 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.not-found {
  max-width: var(--max-prose);
  margin: 2rem auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
}

/* Mobile */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, var(--sidebar-w));
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 20;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 23, 0.4);
    z-index: 15;
  }
  .menu-btn { display: inline-flex; }
  .content { padding: 1rem 0.85rem 2.5rem; }
  .article { padding: 1.25rem 1.1rem 1.75rem; }
}
