:root {
  --bg: #ffffff;
  --bg-alt: #f6f8fa;
  --fg: #1f2328;
  --fg-muted: #636c76;
  --accent: #0969da;
  --border: #d0d7de;
  --code-bg: #f6f8fa;
  --nav-bg: #24292f;
  --nav-fg: #ffffff;
  --max-width: 860px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-alt: #161b22;
    --fg: #e6edf3;
    --fg-muted: #8b949e;
    --accent: #58a6ff;
    --border: #30363d;
    --code-bg: #161b22;
    --nav-bg: #010409;
    --nav-fg: #e6edf3;
  }
}

/* Manual light theme (soft grey, easy on eyes) */
[data-theme="light"] {
  --bg: #d8dce0;
  --bg-alt: #cdd2d7;
  --fg: #1f2328;
  --fg-muted: #636c76;
  --accent: #0969da;
  --border: #d0d7de;
  --code-bg: #cdd2d7;
  --nav-bg: #24292f;
  --nav-fg: #ffffff;
}

/* Manual dark theme */
[data-theme="dark"] {
  --bg: #0d1117;
  --bg-alt: #161b22;
  --fg: #e6edf3;
  --fg-muted: #8b949e;
  --accent: #58a6ff;
  --border: #30363d;
  --code-bg: #161b22;
  --nav-bg: #010409;
  --nav-fg: #e6edf3;
}

.theme-toggle {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--nav-fg);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  margin-left: auto;
  white-space: nowrap;
}

.theme-toggle:hover { border-color: rgba(255,255,255,0.6); }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

nav {
  background: var(--nav-bg);
  color: var(--nav-fg);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

nav .logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--nav-fg);
  text-decoration: none;
}

nav a {
  color: var(--nav-fg);
  text-decoration: none;
  opacity: 0.8;
  font-size: 0.9rem;
}

nav a:hover { opacity: 1; }

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--nav-fg);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}

.layout {
  display: flex;
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.sidebar {
  width: 240px;
  min-width: 240px;
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--border);
  background: var(--bg-alt);
  position: sticky;
  top: 49px;
  height: calc(100vh - 49px);
  overflow-y: auto;
}

.sidebar h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  margin-bottom: 0.5rem;
}

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

.sidebar li { margin: 0; }

.sidebar a {
  display: block;
  padding: 0.35rem 0.5rem;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.875rem;
  border-radius: 4px;
}

.sidebar a:hover { background: var(--border); }
.sidebar a.active { background: var(--accent); color: #fff; font-weight: 600; }

main {
  max-width: var(--max-width);
  padding: 2rem 2rem;
  width: 100%;
  flex: 1;
  min-width: 0;
}

article h1 { font-size: 2rem; margin-bottom: 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
article h2 { font-size: 1.5rem; margin-top: 2rem; margin-bottom: 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
article h3 { font-size: 1.25rem; margin-top: 1.5rem; margin-bottom: 0.5rem; }
article h4 { font-size: 1rem; margin-top: 1.25rem; margin-bottom: 0.25rem; }

article p { margin: 0.75rem 0; }

article a { color: var(--accent); text-decoration: none; }
article a:hover { text-decoration: underline; }

article ul, article ol { margin: 0.75rem 0; padding-left: 2rem; }
article li { margin: 0.25rem 0; }

article blockquote {
  border-left: 4px solid var(--accent);
  padding: 0.5rem 1rem;
  margin: 1rem 0;
  background: var(--bg-alt);
  color: var(--fg-muted);
}

article code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 4px;
}

article pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
}

article pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
  line-height: 1.5;
}

article table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  overflow-x: auto;
  display: block;
}

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

article th { background: var(--bg-alt); font-weight: 600; }
article tr:nth-child(even) { background: var(--bg-alt); }

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

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

footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--fg-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  .sidebar-toggle { display: block; }
  .sidebar {
    position: fixed;
    left: -260px;
    top: 49px;
    height: calc(100vh - 49px);
    z-index: 99;
    transition: left 0.2s ease;
    border-right: 1px solid var(--border);
    box-shadow: none;
  }
  .sidebar-open .sidebar {
    left: 0;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
  }
  main { padding: 1rem; }
  article h1 { font-size: 1.5rem; }
  article pre { font-size: 0.8em; }
}
