:root {
  --bg: #f7f7f8;
  --panel-bg: #ffffff;
  --border: #e3e3e6;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #6366f1;
  --accent-bg: #eef0ff;
  --code-bg: #f2f2f5;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  padding: 20px 28px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.3rem; }
.topbar .subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: 0.9rem; }

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

.sidebar {
  width: 300px;
  flex-shrink: 0;
  height: calc(100vh - 78px);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 16px;
  position: sticky;
  top: 0;
}

.chapter-list .loading { color: var(--text-muted); font-size: 0.9rem; }

details.chapter {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel-bg);
}
details.chapter summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 0.92rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
details.chapter summary::-webkit-details-marker { display: none; }
details.chapter summary .count {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.8rem;
}
details.chapter[open] summary { border-bottom: 1px solid var(--border); }

.exercise-list { list-style: none; margin: 0; padding: 6px; }
.exercise-list li { margin: 2px 0; }
.exercise-list a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.87rem;
}
.exercise-list a:hover { background: var(--accent-bg); }
.exercise-list a.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.exercise-list .badge {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.content {
  flex: 1;
  min-width: 0;
  padding: 28px 40px 80px;
}

.welcome { color: var(--text-muted); }
.welcome .hint { font-size: 0.9rem; }

.content article {
  max-width: 780px;
}

.content h1 { font-size: 1.5rem; margin-top: 0; }
.content h2 { font-size: 1.15rem; margin-top: 1.8em; border-top: 1px solid var(--border); padding-top: 1em; }
.content h3 { font-size: 1rem; }
.content p { line-height: 1.65; }
.content code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
}
.content pre {
  background: var(--code-bg);
  padding: 12px 14px;
  border-radius: var(--radius);
  overflow-x: auto;
}
.content pre code { background: none; padding: 0; }
.content table { border-collapse: collapse; width: 100%; }
.content th, .content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }

.error { color: #b42318; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    max-height: 40vh;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content { padding: 20px; }
}
