/* === CSS Custom Properties for Light/Dark Mode === */
:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-code: #f1f5f9;
  --bg-heading: #3b82f6;
  --bg-blockquote: #e2e8f0;
  --text-primary: #334155;
  --text-secondary: #475569;
  --text-heading: #ffffff;
  --text-strong: #111827;
  --text-code: #228b22;
  --text-link: #3b82f6;
  --text-link-hover: #2563eb;
  --border-color: #e2e8f0;
  --border-table: #cbd5e1;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --nav-bg: #ffffff;
  --nav-border: #e2e8f0;
  --card-bg: #ffffff;
  --mermaid-bg: #ffffff;
  --mermaid-border: #e2e8f0;
  --mermaid-node-fill: #f8fafc;
  --mermaid-node-stroke: #94a3b8;
  --mermaid-edge: #475569;
  --mermaid-text: #1f2937;
  --mermaid-cluster: #f1f5f9;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-code: #1e293b;
  --bg-heading: #1e3a5f;
  --bg-blockquote: #1e293b;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-heading: #e2e8f0;
  --text-strong: #f1f5f9;
  --text-code: #4ade80;
  --text-link: #60a5fa;
  --text-link-hover: #93bbfd;
  --border-color: #334155;
  --border-table: #475569;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  --nav-bg: #1e293b;
  --nav-border: #334155;
  --card-bg: #1e293b;
  --mermaid-bg: #1e293b;
  --mermaid-border: #334155;
  --mermaid-node-fill: #0f172a;
  --mermaid-node-stroke: #475569;
  --mermaid-edge: #94a3b8;
  --mermaid-text: #e2e8f0;
  --mermaid-cluster: #1e293b;
}

/* === Reset (trimmed) === */
*, *::before, *::after { box-sizing: border-box; }

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend, table, caption,
tbody, tfoot, thead, tr, th, td, article, aside,
canvas, details, embed, figure, figcaption, footer,
header, hgroup, menu, nav, output, ruby, section,
summary, time, mark, audio, video {
  margin: 0; padding: 0; border: 0;
  font-size: 100%; font: inherit; vertical-align: baseline;
}

article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section { display: block; }

/* === Base === */
body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  transition: background-color 0.3s, color 0.3s;
}

.page-wrapper {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
}

/* === Typography === */
h1, h2, h3, h4 {
  font-weight: 700;
  background-color: var(--bg-heading);
  color: var(--text-heading);
  margin: 1.5rem 0 1rem;
  padding: 0.75rem 1rem;
  line-height: 1.3;
  border-radius: 6px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

h1 { font-size: 1.75rem; text-align: center; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1.05rem; }

strong { font-weight: 700; color: var(--text-strong); }

p {
  margin: 0.75rem 0;
  padding: 0 1rem;
}

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

h1 a, h2 a, h3 a, h4 a { color: var(--text-heading) !important; text-decoration: underline; }
h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover { color: #FFE4B5 !important; }

/* === Lists === */
ol, ul { margin-left: 2rem; padding: 0.25rem 0; }
ol li { list-style-type: decimal; padding: 0.35rem 0; }
ul li { list-style-type: disc; padding: 0.35rem 0; }
ul li ul li { margin-left: 0; }
dl, dd { margin-left: 1.5rem; }
dd { padding-bottom: 0.5rem; }

/* === Code === */
code, pre {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', 'Courier New', monospace;
  background-color: var(--bg-code);
  color: var(--text-code);
  border-radius: 4px;
}
code { padding: 0.15em 0.4em; font-size: 0.92em; }
pre {
  padding: 1rem;
  margin: 1rem 0;
  overflow-x: auto;
  line-height: 1.5;
  border: 1px solid var(--border-color);
  border-radius: 6px;
}
pre code { padding: 0; background: none; }

.code-comment { color: #0891b2; font-style: italic; }
.comment-block {
  border-left: 4px solid #3b82f6;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  border-radius: 0 5px 5px 0;
  background: var(--bg-code);
}

/* === Tables === */
table {
  margin: 1rem auto;
  border-collapse: collapse;
  width: auto;
  max-width: 100%;
  overflow-x: auto;
  display: table;
}
table, td, tr, th {
  border: 1px solid var(--border-table);
  padding: 0.5rem 0.75rem;
  text-align: center;
}
th { background-color: var(--bg-heading); color: var(--text-heading); font-weight: 700; }

/* === Blockquote === */
blockquote {
  margin: 1rem 2rem;
  background-color: var(--bg-blockquote);
  color: var(--text-primary);
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--text-link);
  border-radius: 0 6px 6px 0;
}

/* === Images & SVG === */
img { max-width: 100%; height: auto; border-radius: 6px; }
div img { max-width: 80%; }
svg { display: block; margin: 1rem auto; max-width: 100%; }
canvas { display: block; margin: 1rem auto; max-width: 100%; }
.svg-container { display: flex; justify-content: center; align-items: center; }

sup { font-size: 0.75em; vertical-align: super; }
sub { font-size: 0.75em; vertical-align: sub; }

footer { padding-bottom: 1.25rem; text-align: left; }

/* === Mermaid Diagrams === */
.mermaid_container, .mermaid-diagram, .mermaid {
  margin: 1.5rem auto;
  padding: 1.25rem;
  background-color: var(--mermaid-bg);
  color: var(--text-primary);
  border: 1px solid var(--mermaid-border);
  border-radius: 8px;
  max-width: 90%;
  text-align: center;
}
.mermaid svg { margin: 0 auto; display: block; }
.mermaid .node rect, .mermaid .node circle, .mermaid .node ellipse,
.mermaid .node polygon, .mermaid .node path {
  fill: var(--mermaid-node-fill); stroke: var(--mermaid-node-stroke);
}
.mermaid .edgePath .path { stroke: var(--mermaid-edge); }
.mermaid .label, .mermaid .label text, .mermaid text,
.mermaid .flowchart-label text, .mermaid .mindmap-node text,
.mermaid .mindmap-node .nodeText, .mermaid .nodeLabel {
  fill: var(--mermaid-text) !important; color: var(--mermaid-text) !important;
}
.mermaid .cluster rect { fill: var(--mermaid-cluster); stroke: var(--mermaid-node-stroke); }

/* === Site Nav Bar === */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.25rem;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 0.5rem;
}
.site-nav a {
  color: var(--text-link);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  transition: background 0.2s;
}
.site-nav a:hover {
  background: var(--bg-code);
  text-decoration: none;
}
.site-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}
.site-nav .nav-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  white-space: nowrap;
}

/* Dark Mode Toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text-primary);
  transition: background 0.2s, border-color 0.2s;
}
.theme-toggle:hover {
  background: var(--bg-code);
}

/* === Prev/Next Navigation === */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 2rem 0 1rem;
  padding: 1rem 0;
  border-top: 1px solid var(--border-color);
  gap: 1rem;
  flex-wrap: wrap;
}
.lesson-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  background: var(--bg-heading);
  color: var(--text-heading);
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: opacity 0.2s;
  text-shadow: none;
}
.lesson-nav a:hover { opacity: 0.85; text-decoration: none; color: var(--text-heading); }
.lesson-nav .nav-spacer { flex: 1; }

/* === Site Footer === */
.site-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  margin-top: 2rem;
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.site-footer a { color: var(--text-link); }
.site-footer .footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

/* === Hero Section (index) === */
.hero-section {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 3rem 1.5rem;
  text-align: center;
  border-radius: 0 0 1rem 1rem;
}
.hero-section h1, .hero-section p {
  color: white !important; background: none !important; text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
  margin: 0; padding: 0;
}
.hero-section h1 { font-size: 2.2rem; margin-bottom: 0.75rem; border-radius: 0; }
.hero-subtitle { font-size: 1.2rem; margin-bottom: 1rem; opacity: 0.95; }
.hero-description { font-size: 1rem; max-width: 700px; margin: 0 auto; line-height: 1.6; opacity: 0.9; }

/* === Progress Tracker === */
.progress-tracker {
  background: linear-gradient(135deg, #ffd89b 0%, #19547b 100%);
  color: white;
  padding: 2rem 1.5rem;
  border-radius: 12px;
  text-align: center;
  margin: 2rem 0;
}
.progress-tracker h2, .progress-tracker div, .progress-tracker p {
  color: white !important; background: none !important; text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
  margin: 0; padding: 0;
}
.progress-title { font-size: 1.5rem; margin-bottom: 1rem !important; }
.learning-path {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 1rem; margin-top: 1rem;
}
.path-step {
  background: rgba(255,255,255,0.2); padding: 0.75rem 1.25rem;
  border-radius: 8px; backdrop-filter: blur(10px); min-width: 100px;
}
.step-number { font-size: 1.75rem; font-weight: 700; }
.step-label { font-size: 0.95rem; }

/* === Course Grid === */
.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin: 2rem 0;
}
.course-category {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: transform 0.2s, box-shadow 0.2s;
}
.course-category:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}
.category-title {
  font-size: 1.2rem;
  color: var(--text-primary);
  background: none;
  padding: 0;
  margin: 0 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  text-shadow: none;
}
.category-emoji { font-size: 1.5rem; }
.course-list { list-style: none; margin: 0; padding: 0; }
.course-list li {
  list-style: none;
  margin: 0.5rem 0;
  padding-left: 1.25rem;
  position: relative;
}
.course-list li::before {
  content: "▸"; position: absolute; left: 0;
  color: var(--text-link); font-weight: 700;
}
.course-list a {
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: color 0.2s;
}
.course-list a:hover { color: var(--text-link); }

/* === Quick Stats === */
.quick-stats {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 1rem; margin: 2rem 0;
}
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 1.25rem;
  border-radius: 8px;
  text-align: center;
  flex: 1;
  min-width: 130px;
}
.stat-number { font-size: 2rem; color: var(--text-link); font-weight: 700; }
.stat-label { font-size: 0.9rem; color: var(--text-secondary); margin-top: 0.25rem; }

/* === CTA Section === */
.cta-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 2rem 1.5rem;
  text-align: center;
  margin: 2rem 0;
}
.cta-section h2 {
  background: none; color: var(--text-primary); padding: 0; margin: 0 0 0.75rem;
  text-shadow: none;
}
.cta-buttons {
  display: flex; justify-content: center; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.25rem;
}
.cta-btn {
  color: white; padding: 0.7rem 1.5rem; border-radius: 8px;
  text-decoration: none; font-size: 1rem; font-weight: 600;
  display: inline-block; transition: opacity 0.2s;
}
.cta-btn:hover { opacity: 0.85; color: white; text-decoration: none; }

/* === Features Grid === */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin: 2rem 0;
}
.feature-card {
  text-align: center; padding: 1.25rem;
  background: var(--card-bg); border: 1px solid var(--border-color);
  border-radius: 10px;
}
.feature-card h3 {
  background: none; color: var(--text-primary); padding: 0;
  margin: 0.5rem 0; font-size: 1.05rem; text-shadow: none;
}
.feature-card p { margin: 0; text-align: center; padding: 0; font-size: 0.9rem; color: var(--text-secondary); }
.feature-emoji { font-size: 2.5rem; margin-bottom: 0.5rem; }

/* Footer Section (index) */
.footer-section {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 2rem 1.5rem;
  text-align: center;
  margin-top: 2rem;
  border-radius: 1rem 1rem 0 0;
}
.footer-section p { color: var(--text-secondary); text-shadow: none; }
.footer-section a { color: var(--text-link); }

/* === Mobile === */
@media (max-width: 640px) {
  .hero-section h1 { font-size: 1.5rem; }
  .hero-subtitle { font-size: 1rem; }
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1.05rem; }
  .course-grid { grid-template-columns: 1fr; }
  .site-nav { padding: 0.5rem 0.75rem; }
  .site-nav .nav-brand { font-size: 0.85rem; }
  .site-nav a { font-size: 0.8rem; padding: 0.25rem 0.4rem; }
  p { padding: 0 0.5rem; }
  ol, ul { margin-left: 1.25rem; }
  blockquote { margin: 0.75rem; }
  .lesson-nav { flex-direction: column; align-items: stretch; }
  .lesson-nav a { justify-content: center; }
  table { font-size: 0.85rem; }
  table, td, tr, th { padding: 0.3rem 0.4rem; }
}
