:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #6b7280;
  --link: #1a73e8;
  --link-hover: #0b57d0;
  --border: #e5e7eb;
  --sidebar-bg: #f8fafc;
  --card-bg: #f8fafc;
  --accent: #2563eb;
  --max-content: 760px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  font-size: 16px;
  line-height: 1.7;
}

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

/* ===== Header ===== */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header .brand {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--fg);
}
.breadcrumb {
  font-size: 0.9rem;
  color: var(--muted);
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--link); }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  align-items: start;
}

.sidebar {
  padding: 1.5rem 1rem;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 3rem;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  font-size: 0.9rem;
}
.sidebar h3 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 1rem 0 0.4rem;
}
.sidebar h3:first-child { margin-top: 0; }
.sidebar ul {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
}
.sidebar li { margin: 0.15rem 0; }
.sidebar a { display: block; padding: 0.2rem 0.4rem; border-radius: 4px; }
.sidebar a:hover { background: #e2e8f0; text-decoration: none; }
.sidebar a.active {
  background: #dbeafe;
  color: var(--link);
  font-weight: 500;
}

.content {
  padding: 2rem 2.5rem 4rem;
  max-width: calc(var(--max-content) + 2rem);
}
.content h1 {
  font-size: 1.8rem;
  margin: 0 0 0.5rem;
  line-height: 1.3;
}
.content h2 {
  font-size: 1.3rem;
  margin-top: 2.2rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}
.content h3 { font-size: 1.05rem; margin-top: 1.5rem; }
.meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1.5rem;
}
.page-foot {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
.todo {
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  padding: 0.6rem 1rem;
  margin: 1rem 0;
  border-radius: 4px;
  color: #92400e;
}

figure {
  margin: 1.5rem 0;
  text-align: center;
}
figure img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}
figcaption {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

/* ===== Top-level index cards ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0 2rem;
}
.card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem;
  color: var(--fg);
  transition: border-color 0.15s;
}
.card:hover {
  border-color: var(--accent);
  text-decoration: none;
}
.card h2 {
  font-size: 1.15rem;
  margin: 0 0 0.4rem;
  border: none;
  padding: 0;
}
.card p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.subpage-list {
  list-style: none;
  padding: 0;
}
.subpage-list li {
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--border);
}
.subpage-list li:last-child { border-bottom: none; }
.subpage-list .num {
  display: inline-block;
  min-width: 2.2rem;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", monospace;
}
.subpage-list .status-todo { color: #b45309; font-size: 0.85rem; margin-left: 0.5rem; }
.subpage-list .status-done { color: #15803d; font-size: 0.85rem; margin-left: 0.5rem; }

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content { padding: 1.5rem 1rem 3rem; }
  .site-header { padding: 0.6rem 1rem; }
}

/* ===== Print ===== */
@media print {
  .sidebar, .site-header { display: none; }
  .content { max-width: 100%; padding: 0; }
}