/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --text-primary: #292929;
  --text-secondary: #757575;
  --text-link: #1a8917;
  --bg-primary: #fff;
  --border-color: #e6e6e6;
  --max-width: 680px;
}

html {
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: charter, Georgia, Cambria, "Times New Roman", Times, serif;
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.7;
}

/* Header */
.site-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-color);
}

.site-header nav {
  max-width: var(--max-width);
  margin: 0 auto;
}

.site-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
}

/* Main Content */
main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 3rem 2rem;
}

/* Typography */
h1, h2, h3, h4 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 2rem;
  margin-bottom: 0.5rem;
}

h1 { font-size: 2.5rem; letter-spacing: -0.02em; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.375rem; }

p {
  margin-bottom: 1.5rem;
}

a {
  color: var(--text-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

blockquote {
  border-left: 3px solid var(--text-primary);
  padding-left: 1.5rem;
  margin: 2rem 0;
  font-style: italic;
  color: var(--text-secondary);
}

code {
  font-family: Menlo, Monaco, "Courier New", monospace;
  font-size: 0.875rem;
  background: #f7f7f7;
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

pre {
  background: #f7f7f7;
  padding: 1.25rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 2rem 0;
}

pre code {
  background: none;
  padding: 0;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 2rem auto;
}

hr {
  border: none;
  text-align: center;
  margin: 3rem 0;
}

hr::before {
  content: "...";
  font-size: 1.5rem;
  letter-spacing: 1em;
  color: var(--text-secondary);
}

/* Post Styles */
.post-header {
  margin-bottom: 2rem;
}

.post-title {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.post-meta {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.reading-time {
  color: var(--text-secondary);
}

/* Home Page */
.home-header {
  margin-bottom: 3rem;
}

.home-title {
  margin-top: 0;
}

.home-description {
  font-size: 1.25rem;
  color: var(--text-secondary);
}

.post-list {
  list-style: none;
}

.post-list-item {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.post-list-item:first-child {
  padding-top: 0;
}

.post-list-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1.375rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
}

.post-list-title a {
  color: var(--text-primary);
}

.post-list-title a:hover {
  color: var(--text-link);
  text-decoration: none;
}

.post-list-meta {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.post-list-excerpt {
  margin-top: 0.5rem;
  color: var(--text-secondary);
}

/* Table of Contents */
.toc-list {
  list-style: none;
  counter-reset: chapter;
  padding-left: 0;
}

.toc-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
  counter-increment: chapter;
}

.toc-item::before {
  content: counter(chapter) ". ";
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  color: var(--text-secondary);
}

.toc-item a {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--text-primary);
}

.toc-item a:hover {
  color: var(--text-link);
  text-decoration: none;
}

/* Footer */
.site-footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem;
  border-top: 1px solid var(--border-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 300px;
  height: 100vh;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 1000;
  overflow-y: auto;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 999;
}

.sidebar-overlay.open {
  opacity: 1;
  visibility: visible;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0;
  line-height: 1;
}

.sidebar-close:hover {
  color: var(--text-primary);
}

.sidebar-nav {
  padding: 1rem 0;
}

.sidebar-chapters {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: sidebar-chapter;
}

.sidebar-chapter {
  counter-increment: sidebar-chapter;
}

.sidebar-chapter a {
  display: block;
  padding: 0.625rem 1.5rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.9rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: background 0.15s ease;
}

.sidebar-chapter a::before {
  content: counter(sidebar-chapter) ". ";
  color: var(--text-secondary);
}

.sidebar-chapter a:hover {
  background: #f7f7f7;
}

.sidebar-chapter.active a {
  color: var(--text-link);
  background: rgba(26, 137, 23, 0.08);
}

.sidebar-chapter.active a::before {
  color: var(--text-link);
}

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

.sidebar-links a {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.sidebar-links a:hover {
  color: var(--text-link);
}

/* Menu Toggle Button */
.menu-toggle {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 24px;
  height: 18px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-right: 1rem;
}

.menu-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
}

.menu-toggle:hover span {
  background: var(--text-link);
}

.site-header nav {
  display: flex;
  align-items: center;
}

/* Responsive */
@media (max-width: 600px) {
  html {
    font-size: 16px;
  }

  h1 {
    font-size: 2rem;
  }

  main {
    padding: 2rem 1.25rem;
  }

  .sidebar {
    width: 280px;
  }
}
