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

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-hover: #1c2333;
  --bg-code: #1a1f2e;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --accent-dim: #1f6feb33;
  --green: #3fb950;
  --green-dim: #23863633;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #bc8cff;
  --radius: 8px;
  --max-w: 900px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* === Header === */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  white-space: nowrap;
}
.logo:hover { text-decoration: none; color: var(--accent); }
#breadcrumb {
  color: var(--text-dim);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
#breadcrumb a { color: var(--text-dim); }
#breadcrumb a:hover { color: var(--accent); }
#breadcrumb .sep { margin: 0 0.4rem; }

/* === Search === */
.search-wrapper {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}
#search-input {
  width: 200px;
  padding: 0.35rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.8rem;
  outline: none;
  transition: border-color 0.15s, width 0.2s;
}
#search-input:focus {
  border-color: var(--accent);
  width: 280px;
}
#search-input::placeholder { color: var(--text-dim); }
.search-results {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  width: 360px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.search-results.open { display: block; }
.search-result-item {
  display: block;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-hover); text-decoration: none; }
.search-result-item .sr-course { font-size: 0.7rem; color: var(--accent); }
.search-result-item .sr-title { font-size: 0.85rem; font-weight: 500; }
.search-result-item .sr-snippet {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* === Layout === */
#layout {
  display: flex;
  min-height: calc(100vh - 49px);
}

/* === Sidebar === */
#sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 49px;
  height: calc(100vh - 49px);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition: transform 0.2s ease;
  z-index: 50;
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#sidebar-close {
  display: none;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  z-index: 51;
}
#sidebar-close:hover { color: var(--text); }

#sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.2rem;
  flex-shrink: 0;
}
#sidebar-toggle:hover { color: var(--accent); }

#sidebar-nav {
  padding: 0.75rem 0;
}

.sb-category {
  margin-bottom: 0.25rem;
}
.sb-cat-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4rem 0.75rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s;
}
.sb-cat-btn:hover { color: var(--text); }
.sb-cat-btn .sb-cat-icon { font-size: 0.9rem; }
.sb-cat-btn .sb-cat-arrow {
  margin-left: auto;
  font-size: 0.6rem;
  transition: transform 0.15s;
}
.sb-category.open .sb-cat-arrow { transform: rotate(90deg); }
.sb-cat-courses {
  display: none;
  padding: 0.15rem 0 0.25rem;
}
.sb-category.open .sb-cat-courses { display: block; }
.sb-course {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem 0.35rem 1.5rem;
  color: var(--text);
  font-size: 0.82rem;
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-course:hover { background: var(--bg-hover); text-decoration: none; }
.sb-course.active { color: var(--accent); background: var(--accent-dim); }
.sb-course .sb-icon { font-size: 0.85rem; flex-shrink: 0; }
.sb-course .sb-name { overflow: hidden; text-overflow: ellipsis; }
.sb-course .sb-progress {
  margin-left: auto;
  font-size: 0.65rem;
  color: var(--green);
  flex-shrink: 0;
}

/* Sidebar overlay for mobile */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}

/* === Main === */
main {
  flex: 1;
  min-width: 0;
  max-width: var(--max-w);
  padding: 2rem 1.5rem 4rem;
}

/* === Home: Course Grid === */
.home-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
}
.home-sub {
  color: var(--text-dim);
  margin-bottom: 2rem;
}
.category-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 2rem 0 0.75rem;
  color: var(--text-dim);
}
.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.75rem;
}
.course-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: block;
  color: var(--text);
}
.course-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  text-decoration: none;
}
.course-card .icon { font-size: 1.5rem; margin-bottom: 0.4rem; }
.course-card .name { font-weight: 600; font-size: 0.95rem; }
.course-card .desc {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.course-card .meta {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.course-card .progress-bar {
  margin-top: 0.5rem;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.course-card .progress-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.3s;
}

/* === Course: Lesson List === */
.course-header { margin-bottom: 2rem; }
.course-header h1 { font-size: 1.5rem; font-weight: 700; }
.course-header p { color: var(--text-dim); margin-top: 0.25rem; }

.part-group { margin-bottom: 1.5rem; }
.part-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.lesson-list { list-style: none; }
.lesson-item a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text);
  transition: background 0.15s;
}
.lesson-item a:hover { background: var(--bg-hover); text-decoration: none; }
.lesson-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}
.lesson-item.completed .lesson-num { background: var(--green-dim); color: var(--green); }
.lesson-title-text { font-size: 0.9rem; }

/* === Continue Learning Banner === */
.continue-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  margin-bottom: 2rem;
  color: var(--text);
  transition: background 0.15s;
}
.continue-banner:hover { background: var(--bg-hover); text-decoration: none; }
.continue-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  white-space: nowrap;
}
.continue-course { font-size: 0.9rem; font-weight: 500; }
.progress-text { color: var(--green); }

/* === Lesson Viewer === */
.lesson-header { margin-bottom: 2rem; }
.lesson-header h1 { font-size: 1.4rem; font-weight: 700; }
.lesson-header .desc { color: var(--text-dim); margin-top: 0.25rem; }

/* Table of Contents */
.lesson-toc {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 2rem;
}
.toc-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}
.lesson-toc ol {
  list-style: decimal;
  padding-left: 1.25rem;
  font-size: 0.85rem;
  columns: 2;
  column-gap: 1.5rem;
}
.lesson-toc li { margin-bottom: 0.2rem; break-inside: avoid; }
.lesson-toc a { color: var(--accent); }
.lesson-toc a:hover { text-decoration: underline; }

.objectives {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.75rem 1rem;
  margin-bottom: 2rem;
}
.objectives h3 { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.4rem; }
.objectives ul { list-style: disc; padding-left: 1.25rem; font-size: 0.85rem; }
.objectives li { margin-bottom: 0.2rem; }

.section { margin-bottom: 2rem; }
.section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}
.section .content {
  font-size: 0.9rem;
  white-space: pre-wrap;
  margin-bottom: 0.75rem;
}

/* Code blocks */
.code-block {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 0.75rem;
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--border);
  padding: 0.2rem 0.6rem;
}
.code-block .lang-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}
.copy-btn {
  background: transparent;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
/* Inline code */
.inline-code {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.85em;
}
.code-block pre {
  margin: 0;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.5;
  background: transparent !important;
}
.code-block code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  background: transparent !important;
}

/* Notes */
.note {
  border-left: 3px solid var(--accent);
  padding: 0.6rem 0.85rem;
  margin: 0.75rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.85rem;
}
.note.tip { border-color: var(--green); background: var(--green-dim); }
.note.warning { border-color: var(--yellow); background: #d2992222; }
.note.important { border-color: var(--red); background: #f8514922; }
.note.info { border-color: var(--accent); background: var(--accent-dim); }
.note-label { font-weight: 600; margin-bottom: 0.2rem; text-transform: uppercase; font-size: 0.75rem; }

/* Takeaways */
.takeaways {
  background: var(--green-dim);
  border-left: 3px solid var(--green);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.75rem 1rem;
  margin: 2rem 0;
}
.takeaways h3 { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.4rem; }
.takeaways ul { list-style: disc; padding-left: 1.25rem; font-size: 0.85rem; }
.takeaways li { margin-bottom: 0.2rem; }

/* Exercises */
.exercises { margin: 2rem 0; }
.exercises h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.75rem; }
.exercise-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.exercise-card h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.4rem; }
.exercise-card .prompt { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.5rem; }
.toggle-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
}
.toggle-btn:hover { background: var(--accent-dim); }
.solution { display: none; margin-top: 0.5rem; }
.solution.show { display: block; }

/* Quiz */
.quiz { margin: 2rem 0; }
.quiz h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.75rem; }
.quiz-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.quiz-card .question { font-size: 0.9rem; font-weight: 500; margin-bottom: 0.6rem; }
.quiz-options { list-style: none; }
.quiz-option {
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.3rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s;
}
.quiz-option:hover { background: var(--bg-hover); }
.quiz-option.selected { border-color: var(--accent); background: var(--accent-dim); }
.quiz-option.correct { border-color: var(--green); background: var(--green-dim); }
.quiz-option.wrong { border-color: var(--red); background: #f8514922; }
.quiz-option.disabled { pointer-events: none; }
.quiz-explanation {
  display: none;
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--accent-dim);
  border-radius: var(--radius);
  font-size: 0.8rem;
}
.quiz-explanation.show { display: block; }

.quiz-input-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.quiz-input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
}
.quiz-input:focus { outline: none; border-color: var(--accent); }
.quiz-submit {
  padding: 0.4rem 0.8rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}
.quiz-submit:hover { opacity: 0.9; }
.quiz-result { font-size: 0.85rem; font-weight: 600; margin-top: 0.3rem; }
.quiz-result.correct { color: var(--green); }
.quiz-result.wrong { color: var(--red); }

/* Navigation */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.nav-btn:hover { background: var(--bg-hover); text-decoration: none; }
.nav-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.nav-btn.primary:hover { opacity: 0.9; }
.complete-btn { background: var(--green); color: #fff; border-color: var(--green); }
.complete-btn:hover { opacity: 0.9; }
.complete-btn.done { opacity: 0.6; cursor: default; }
.nav-btn .kbd {
  font-size: 0.65rem;
  padding: 0.1rem 0.3rem;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  margin-left: 0.2rem;
}

/* Loading */
.loading { text-align: center; padding: 4rem 0; color: var(--text-dim); }

/* Responsive */
@media (max-width: 900px) {
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    z-index: 200;
    padding-top: 0.5rem;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-close { display: block; }
  #sidebar-toggle { display: block; }
  #sidebar-overlay.open { display: block; }
}
@media (max-width: 640px) {
  header {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }
  .logo { font-size: 0.95rem; }
  #breadcrumb { font-size: 0.75rem; }
  #search-input { width: 140px; }
  #search-input:focus { width: 180px; }
  .search-results { width: calc(100vw - 1.5rem); right: -0.75rem; }
  main { padding: 1rem; }
  .home-title { font-size: 1.4rem; }
  .course-grid { grid-template-columns: 1fr; }
  .lesson-nav { justify-content: center; }
  .nav-btn .kbd { display: none; }
}
