:root {
  --accent: #c15f3c;
  --accent-soft: #f3e7e0;
  --bg: #ffffff;
  --bg-sidebar: #faf8f6;
  --text: #1f2328;
  --text-muted: #6b7280;
  --border: #e6e3df;
  --code-bg: #f6f7f9;
  --sidebar-w: 290px;
  --maxw: 780px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

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

/* ---------- Top bar (mobile) ---------- */
.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 30;
}
.topbar .brand { font-weight: 700; color: var(--text); }
#menuToggle {
  font-size: 20px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  line-height: 1;
}

/* ---------- Layout ---------- */
.layout { display: flex; align-items: flex-start; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  padding: 26px 20px 40px;
}

.brand-desktop {
  display: block;
  font-weight: 800;
  font-size: 20px;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 26px;
  letter-spacing: -0.01em;
}
.brand-desktop span { color: var(--accent); }

.nav .nav-group {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin: 22px 0 6px;
  font-weight: 700;
}
.nav-level {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  vertical-align: 1px;
  white-space: nowrap;
}
.lvl-beginner { background: #e6f0ea; color: #3f7d5c; }
.lvl-core { background: var(--accent-soft); color: var(--accent); }
.lvl-comfortable { background: #f5ecd6; color: #9a6b16; }
.lvl-optional { background: #eceef1; color: #6b7280; }
.nav ul { list-style: none; margin: 0 0 4px; padding: 0; }
.nav li { margin: 1px 0; }
.nav a {
  display: block;
  padding: 6px 10px;
  border-radius: 7px;
  color: var(--text);
  font-size: 14.5px;
}
.nav a:hover { background: var(--accent-soft); text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; font-weight: 600; }

.backdrop { display: none; }

/* ---------- Content ---------- */
.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 48px 56px 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.markdown { width: 100%; max-width: var(--maxw); }

/* ---------- Markdown typography ---------- */
.markdown h1 {
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 18px;
}
.markdown h2 {
  font-size: 23px;
  margin: 40px 0 14px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}
.markdown h3 { font-size: 18px; margin: 28px 0 10px; }
.markdown p { margin: 14px 0; }
.markdown ul, .markdown ol { padding-left: 24px; margin: 14px 0; }
.markdown li { margin: 5px 0; }
.markdown li > p { margin: 6px 0; }
.markdown strong { font-weight: 650; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 34px 0; }

.markdown a { font-weight: 500; }

/* code */
.markdown code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1.5px 5px;
  font-size: 0.875em;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
.markdown pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 16px 0;
}
.markdown pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13.5px;
  line-height: 1.55;
}

/* blockquote (used heavily for tips/warnings) */
.markdown blockquote {
  margin: 18px 0;
  padding: 2px 18px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  color: #4a3b34;
}
.markdown blockquote p { margin: 12px 0; }

/* tables */
.markdown table {
  border-collapse: collapse;
  width: 100%;
  margin: 18px 0;
  font-size: 14.5px;
  display: block;
  overflow-x: auto;
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 9px 12px;
  text-align: left;
  vertical-align: top;
}
.markdown thead th { background: var(--bg-sidebar); font-weight: 650; }
.markdown tbody tr:nth-child(even) { background: #fbfafa; }

/* ---------- Prev / Next ---------- */
.prevnext {
  width: 100%;
  max-width: var(--maxw);
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 48px;
}
.pn {
  flex: 1 1 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.pn span { font-size: 12px; color: var(--text-muted); }
.pn strong { color: var(--text); font-size: 15px; }
.pn:hover { border-color: var(--accent); text-decoration: none; }
.pn.next { text-align: right; }
.pn.empty { visibility: hidden; }

.page-footer {
  width: 100%;
  max-width: var(--maxw);
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Accessibility: skip link & focus ---------- */
.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 60;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 8px; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.nav a:focus-visible { outline-offset: -2px; }

/* ---------- Heading permalink anchors ---------- */
.markdown h2, .markdown h3 { scroll-margin-top: 16px; }
.markdown h2 .anchor, .markdown h3 .anchor {
  margin-left: 8px;
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.12s ease;
  text-decoration: none;
}
.markdown h2:hover .anchor, .markdown h3:hover .anchor,
.markdown .anchor:focus-visible { opacity: 1; }

/* ---------- On-this-page TOC ---------- */
details.toc {
  margin: 18px 0 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-sidebar);
  padding: 4px 16px;
  font-size: 14px;
}
details.toc summary {
  cursor: pointer;
  font-weight: 650;
  padding: 8px 0;
  color: var(--text);
  list-style-position: inside;
}
details.toc[open] summary { margin-bottom: 4px; }
details.toc ul { list-style: none; margin: 0 0 8px; padding: 0; }
details.toc li { margin: 2px 0; }
details.toc li.lvl-3 { padding-left: 16px; }
details.toc a { color: var(--text-muted); font-weight: 500; }
details.toc a:hover, details.toc a.active { color: var(--accent); text-decoration: none; }
details.toc a.active { font-weight: 650; }

/* ---------- Sidebar tools: search ---------- */
.sidebar-tools { position: relative; margin-bottom: 14px; }
.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
.search-input::placeholder { color: var(--text-muted); }
.search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 50;
  padding: 4px;
}
.search-results a {
  display: block;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--text);
}
.search-results a:hover { background: var(--accent-soft); text-decoration: none; }
.search-results a strong { display: block; font-size: 14px; color: var(--text); }
.search-results a span { display: block; font-size: 12.5px; color: var(--text-muted); line-height: 1.4; }
.search-results .no-results { margin: 0; padding: 10px; font-size: 13px; color: var(--text-muted); }

/* ---------- Progress ---------- */
.progress { margin: 4px 0 18px; }
.progress-track {
  height: 7px;
  background: var(--accent-soft);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-label { margin: 7px 0 0; font-size: 12px; color: var(--text-muted); }

.nav a.lesson.done { color: var(--text-muted); }
.nav a.lesson.done::after {
  content: " ✓";
  color: #3f7e3f;
  font-weight: 700;
}
.nav a.active.done::after { color: #fff; }

/* per-lesson complete button */
.lesson-complete {
  width: 100%;
  max-width: var(--maxw);
  margin-top: 40px;
}
.complete-btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 11px 18px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--accent);
  transition: background 0.15s ease, color 0.15s ease;
}
.complete-btn:hover { background: var(--accent-soft); }
.complete-btn.done {
  background: #eef6ef;
  border-color: #3f7e3f;
  color: #2f6b3a;
}

/* ---------- Code: copy button ---------- */
.code-wrap { position: relative; }
.code-wrap pre { margin-top: 16px; }
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.code-wrap:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover { color: var(--text); border-color: var(--text-muted); }
.copy-btn.copied { color: #2f6b3a; border-color: #3f7e3f; opacity: 1; }
@media (hover: none) {
  .copy-btn { opacity: 1; }
}

/* ---------- Syntax highlighting (build-time highlight.js) ---------- */
.hljs-comment, .hljs-quote { color: #9a958f; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section, .hljs-link { color: #b8442a; }
.hljs-string, .hljs-attr, .hljs-meta .hljs-string, .hljs-bullet, .hljs-addition { color: #3f7e3f; }
.hljs-number, .hljs-symbol, .hljs-deletion { color: #9a6a00; }
.hljs-title, .hljs-name, .hljs-selector-id, .hljs-selector-class, .hljs-function .hljs-title { color: #5a4eb8; }
.hljs-built_in, .hljs-type, .hljs-attribute, .hljs-tag { color: #2c6f8c; }
.hljs-meta, .hljs-comment.hljs-doctag { color: #9a8f86; }
.hljs-variable, .hljs-template-variable, .hljs-params, .hljs-property { color: var(--text); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 40;
  }
  .sidebar.open { transform: translateX(0); }
  .brand-desktop { display: none; }
  .backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 35;
  }
  .content { padding: 28px 20px 70px; }
  .markdown h1 { font-size: 27px; }
}
